Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ub.io into feature/docsmigration
  • Loading branch information
SimonDarksideJ committed May 29, 2024
2 parents f34fa5c + ad4b325 commit bb7ab08
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 47 deletions.
76 changes: 38 additions & 38 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Build Documentation
name: Build and Deploy Documentation
on:
push:
branches:
- 'main'
push:
branches:
- 'main'

workflow_dispatch:
workflow_dispatch:

permissions:
contents: read
Expand All @@ -18,36 +18,36 @@ concurrency:
cancel-in-progress: false

jobs:
build:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dotnet tools
run: dotnet tool restore

- name: Run Build
run: dotnet docfx docfx.json

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '_site'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
build:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dotnet tools
run: dotnet tool restore

- name: Run Build
run: dotnet docfx docfx.json

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '_site'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
47 changes: 47 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Test Build Documentation

on:
pull_request:
branches:
- 'main'

workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
test:
runs-on: ubuntu-latest
concurrency: ci-${{ github.ref }}
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dotnet tools
run: dotnet tool restore

- name: Run Build
run: dotnet docfx docfx.json

complete:
runs-on: ubuntu-latest
needs: test
name: Test completion task
steps:
- run: echo "Tests Complete"
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ With your environment setup properly, the following explains how to build from s
git clone https://github.com/MonoGame/monogame.github.io.git
```

2. Install npm dependencies
2. Install DotNet dependencies

```sh
npm install
dotnet tool restore
```

3. Optional Steps
Expand All @@ -29,10 +29,13 @@ With your environment setup properly, the following explains how to build from s

`git submodule update --init --recursive`

4. Run a local build and serve it with hot reloading. The site is full DocFX now so a single build command will do:
4. Run a local build and serve it. The site is full DocFX now so a single build command will do:

`dotnet docfx docfx.json --serve`

> [!NOTE]
> Docfx hosting does not support hot reload, so to refresh the hosted site you will need to stop the agent (ctrl-c) and run the above command again to refresh pages

## Document styling

The use of DocFX with the updated MonoGame docs site has afforded the use of some custom stylings to improve consistency and more stylized docs:
Expand All @@ -53,6 +56,9 @@ The use of DocFX with the updated MonoGame docs site has afforded the use of som

As an example of a document written using the above notes, please refer to the [HowTo: Create a Render Target tutorial](https://github.com/MonoGame/docs.monogame.github.io/blob/feature/docsmigration/articles/monogame/howto/graphics/HowTo_Create_a_RenderTarget.md)

> [!TIP]
> No additional text is needed at the bottom of document pages as the licenses and requirements are automatically added by the DocFX build system

## LICENSE

The MonoGame project is under the Microsoft Public License except for a few portions of the code. See the [LICENSE](LICENSE) file for more details.
2 changes: 1 addition & 1 deletion api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Welcome to the **MonoGame** reference documentation!

This area provides detailed information on each class and method in the API.

Please view the [documentation](../articles/) for how to get started and step-by-step guidance.
Please view the [documentation](../articles/index.md) for how to get started and step-by-step guidance.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sudo apt install wine64 p7zip-full curl
Create wine prefix:

```sh
wget -qO- https://raw.githubusercontent.com/MonoGame/MonoGame/master/Tools/MonoGame.Effect.Compiler/mgfxc_wine_setup.sh | bash
wget -qO- https://monogame.net/downloads/net6_mgfxc_wine_setup.sh | bash
```

If you ever need to undo the script, simply delete the `.winemonogame` folder in your home directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ When installing Visual Studio, the following workloads are required depending on
![Visual Studio optional components](images/1_installer_vs_components.png)

> [!WARNING]
> Targeting Windows
> **Targeting Windows**
>
> If you are targeting the standard Windows DirectX backend, you will also need [the DirectX June 2010 runtime](https://www.microsoft.com/en-us/download/details.aspx?id=8109) for audio and gamepads to work properly.
### Install MonoGame extension for Visual Studio 2022
Expand Down
119 changes: 119 additions & 0 deletions articles/preparing_for_consoles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: Preparing for consoles
description: How to get your game ready to run on consoles.
---

# Preparing for consoles

If you would like to port your game to consoles, there are some best practices to follow if you want to avoid running into issues while porting.

MonoGame for gaming consoles uses a dedicated .NET runtime that is not maintained by Microsoft. Therefore, a 100% accuracy and reliability is not guaranteed. Moreover, the console runtime makes use of `ahead-of-time` native compilation (AOT), which means that some .NET features will not, and cannot work on consoles.

This article explains the most common pitfalls and suggested guidelines to optimize your chances of having a smoother porting experience.

> [!NOTE]
> *Gaming consoles are restricted to registered developers and are not publicly available nor publicly documented. To get access to those platforms, please contact your console account manager(s). MonoGame documentation for closed platforms is available in their respective repositories.*
## No use of runtime reflection

The main show stopper when it comes to porting a .NET game to consoles, is the use of runtime [reflection](https://learn.microsoft.com/en-us/dotnet/fundamentals/reflection/reflection).

Reflection is, at large, unsupported in an AOT context. Which means that anywhere you or a third party library uses reflection, your game will crash.

In order to make sure that your game abides to that rule, you can try to publish an AOT'd version of it for desktop computers and verify how it fares.

To publish with AOT:

- Add `<PublishAot>true</PublishAot>` to your `.csproj`.
- Then run `dotnet publish` from the command-line/terminal.

This will nativily compile your game in a fashion similar to consoles. The output executable will be in your output folder, within a sub-folder nammed `publish`.

From there, you can try running this executable. If it does not start or crashes later on, you likely are using reflection or another unsupported feature in a AOT runtime.

Native executables can debugged by:

- Starting an empty Visual Studio with no code.
- Opening the compiled exe.
- Then hitting "Start debugging".

It should show you on which C# lines it crashed.

It is important to note that you should test every aspect of your game, and not just if it starts. Run through all the menus/screens, scene transitions and gameplay.

Another way to make sure that everything is safe is to enable `<EnableTrimAnalyzer>true</EnableTrimAnalyzer>` in your `.csproj`, and then **rebuild** (not just build) your game and check the build output for AOT warnings. Those warnings will tell you which parts of your code might trigger crashes or unexecpted results when running on AOT compilation. You should seek to resolve all of them.

## No runtime compilation / IL emit

Generating code at runtime is a scenario that is also not supported in AOT contexts, it is also forbidden by console manufacturers.

Like reflection, trying to make a `PublishAot` build is a good way to verify that your game is compliant because any use of IL emit will crash.

## No use of dynamic assembly loading

Loading assemblies at runtime with `Assembly.Load()` is not supported.

## Third party libraries

Many third party libraries heavily rely on using reflection or IL emit, this is a common practice for JSON or XML parsers for example (and they are the most common source of third party incompatibilities).

It is advised to choose very carefully the libraries that you are using when porting to consoles. If you do not select them with this in mind, you might run into a situation in which you will have to rewrite entire chunks of data handling.

The best way to make sure if they will work, is to search if they are **"AOT-compatible"**, or try to compile with the `<EnableTrimAnalyzer>true</EnableTrimAnalyzer>` setting in your `.csproj` and check if there are any warnings related to those libraries.

For example, here are some parsing libraries known for their compliance with AOT compilation and good handling of memrory:

- [TurboXML](https://github.com/xoofx/TurboXml)
- [TinyJSON](https://github.com/zanders3/json)

On the contrary, Newtonsoft JSON is known to be unsupported (there are modified forks around, but we overall recommend to not use it for games).

## Native libraries

If you are using native libraries, make sure that they provide builds for consoles, or make sure that you can compile and run them on consoles yourself.

Even though a library might be open-source, it is unlikely they will just compile and run on consoles.

It is suggested to only use native libraries that have been proven to run on consoles.

## LINQ

While LINQ mostly works on consoles, it should be noted that due to AOT compilation, LINQ queries can not be optimized and performance can be very slow.

Moreover, LINQ is very garbage-prone and if your game has stuttering issues you might want to reduce your usage of LINQ.

## Avoiding garbage generation

Even though your game has good performance on PC and does not show stutters, you might want to be very cautious about how your game handles memory.

The garbage collector is slower on consoles and if your game generates a lot of garbage memory, there will be visible stutters.

To verify that your game is not too garbage-prone, you can run Visual Studio's Perfomance Profiler (`Debug/Performance Profiler...`) and check the **".NET Object Allocation Tracking"** tool.

From there, you can check which parts of your code generate garbage and you can pinpoint where to optimize.

In order to avoid garbage, here are some best practices:

- Only use strings as const. Do not use strings dynamically (e.g. string concatenation, patterns...), this is the most common source of garbage.
- Avoid allocating anything with the `new` keyword during your game loop, e.g. pre-allocate everything ahead of using them during gameplay.
- Pool your dynamic objects, e.g. do not destroy your projectiles or particles, instead place them into another "unused" list and reuse them instead of creating new instances when needed.
- Avoid using LINQ.
- If you are using collections, initialize them with a large enough capacity to avoid their internal data structure being silently recreated.
- Mind your foreach loops, depending on the data you are looping on, the loop might create garbage when duplicating an item. Or better yet, use a for loop for tigher control.

## Do not rely on system calls

If your game calls directly to system functions, like kernel, win32 or unix commands, you might want to get rid of them.

## Consider I/O to be asynchronous

Saving player data/settings, or unlocking achievements are operations that should be considered asynchronous.

Most, if not all consoles, consider system accesses to be asynchronous. Even though it is not on PC, you should prepare your game to handle asynchronous operation (e.g. consider saving game data in a thread which will not block the game).

If you consider all your I/O and system operations as asynchronous, you will likely be spared some headache.

## Suggestions

If you have other tips or suggestions when building for consoles, then let the MonoGame team know by raising an issue and we will improve this article even further over time.

4 changes: 3 additions & 1 deletion articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
href: migrate_xna.md
- name: Packaging
href: packaging_games.md
- name: Preparing for consoles
href: preparing_for_consoles.md
- name: Samples and Demos
href: samples.md
- name: Community Tutorials
href: tutorials.md
- name: Help and Support
href: help_and_support.md
- name: Contributing to documentation
href: contributing
href: contributing.md
- name: MonoGame
href: monogame/Index.md
9 changes: 8 additions & 1 deletion docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"EnumSortOrder": "alphabetic"
}
],
"rules": {
"InvalidFileLink": "error",
"InvalidBookmark": "error",
"UidNotFound": "error",
"ReferencedXrefPropertyNotString": "error"
},
"build": {
"content": [
{
Expand All @@ -34,7 +40,8 @@
"foundation/**/*.md",
"toc.yml",
"*.md"
]
],
"exclude": [ "_site/**", "README.md" ]
}
],
"resource": [
Expand Down
2 changes: 1 addition & 1 deletion external/MonoGame
Submodule MonoGame updated 58 files
+1 −1 MonoGame.Framework/BoundingBox.cs
+2 −2 MonoGame.Framework/Content/ContentManager.cs
+21 −0 MonoGame.Framework/Content/ResourceContentManager.cs
+20 −24 MonoGame.Framework/Curve.cs
+18 −0 MonoGame.Framework/CurveKeyCollection.cs
+22 −2 MonoGame.Framework/DrawableGameComponent.cs
+15 −0 MonoGame.Framework/ExitingEventArgs.cs
+30 −24 MonoGame.Framework/Game.cs
+13 −0 MonoGame.Framework/GameComponent.cs
+3 −3 MonoGame.Framework/GameComponentCollection.cs
+7 −0 MonoGame.Framework/GameWindow.cs
+38 −3 MonoGame.Framework/Graphics/Effect/Effect.cs
+22 −2 MonoGame.Framework/Graphics/Effect/EffectAnnotation.cs
+14 −2 MonoGame.Framework/Graphics/Effect/EffectMaterial.cs
+219 −26 MonoGame.Framework/Graphics/Effect/EffectParameter.cs
+14 −1 MonoGame.Framework/Graphics/Effect/EffectPass.cs
+70 −26 MonoGame.Framework/Graphics/Effect/EffectTechnique.cs
+13 −2 MonoGame.Framework/Graphics/Effect/IEffectMatrices.cs
+4 −1 MonoGame.Framework/Graphics/Effect/SkinnedEffect.cs
+3 −0 MonoGame.Framework/Graphics/GraphicsDebug.cs
+186 −5 MonoGame.Framework/Graphics/GraphicsDevice.cs
+28 −4 MonoGame.Framework/Graphics/GraphicsResource.cs
+40 −49 MonoGame.Framework/Graphics/ModelBone.cs
+48 −74 MonoGame.Framework/Graphics/ModelMesh.cs
+37 −1 MonoGame.Framework/Graphics/ModelMeshPart.cs
+3 −0 MonoGame.Framework/Graphics/OcclusionQuery.cs
+6 −0 MonoGame.Framework/Graphics/PresentationParameters.cs
+13 −5 MonoGame.Framework/Graphics/SpriteFont.cs
+122 −1 MonoGame.Framework/Graphics/States/SamplerState.cs
+119 −39 MonoGame.Framework/Graphics/Vertices/DynamicIndexBuffer.cs
+54 −23 MonoGame.Framework/Graphics/Vertices/VertexBuffer.cs
+20 −6 MonoGame.Framework/GraphicsDeviceManager.cs
+6 −1 MonoGame.Framework/Input/GamePadButtons.cs
+4 −1 MonoGame.Framework/Input/GamePadDPad.cs
+6 −0 MonoGame.Framework/Input/GamePadThumbSticks.cs
+6 −0 MonoGame.Framework/Input/KeyboardInput.cs
+7 −1 MonoGame.Framework/Input/MessageBox.cs
+5 −1 MonoGame.Framework/Input/MouseCursor.cs
+54 −8 MonoGame.Framework/Input/Touch/TouchLocation.cs
+19 −6 MonoGame.Framework/Input/Touch/TouchPanel.cs
+5 −2 MonoGame.Framework/Input/Touch/TouchPanelCapabilities.cs
+13 −0 MonoGame.Framework/Input/Touch/TouchPanelState.cs
+6 −0 MonoGame.Framework/Platform/Graphics/IWindowInfo.OpenGL.cs
+1 −0 MonoGame.Framework/Platform/Graphics/OcclusionQuery.OpenGL.cs
+1 −0 MonoGame.Framework/Platform/Graphics/RenderTarget2D.OpenGL.cs
+1 −0 MonoGame.Framework/Platform/Graphics/RenderTargetCube.OpenGL.cs
+1 −0 MonoGame.Framework/Platform/Graphics/Texture.OpenGL.cs
+1 −0 MonoGame.Framework/Platform/Graphics/Vertices/IndexBuffer.OpenGL.cs
+1 −0 MonoGame.Framework/Platform/Graphics/Vertices/VertexBuffer.OpenGL.cs
+3 −0 MonoGame.Framework/Platform/Input/GamePad.SDL.cs
+19 −3 MonoGame.Framework/Platform/SDL/SDLGamePlatform.cs
+4 −0 MonoGame.Framework/Platform/SDL/SDLGameWindow.cs
+7 −0 MonoGame.Framework/Platform/Windows/WinFormsGameWindow.cs
+7 −0 MonoGame.Framework/Quaternion.cs
+1 −1 README.md
+1 −1 REQUIREMENTS.md
+1 −1 Tests/Framework/GameTest.cs
+1 −1 Tools/MonoGame.Content.Builder.Editor/MainWindow.cs

0 comments on commit bb7ab08

Please sign in to comment.