Skip to content

Commit bb7ab08

Browse files
Merge branch 'main' of https://github.com/MonoGame/docs.monogame.github.io into feature/docsmigration
2 parents f34fa5c + ad4b325 commit bb7ab08

File tree

10 files changed

+229
-47
lines changed

10 files changed

+229
-47
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Build Documentation
1+
name: Build and Deploy Documentation
22
on:
3-
push:
4-
branches:
5-
- 'main'
3+
push:
4+
branches:
5+
- 'main'
66

7-
workflow_dispatch:
7+
workflow_dispatch:
88

99
permissions:
1010
contents: read
@@ -18,36 +18,36 @@ concurrency:
1818
cancel-in-progress: false
1919

2020
jobs:
21-
build:
22-
environment:
23-
name: github-pages
24-
url: ${{ steps.deployment.outputs.page_url }}
25-
runs-on: ubuntu-latest
26-
steps:
27-
- name: Clone Repository
28-
uses: actions/checkout@v4
29-
with:
30-
submodules: recursive
31-
32-
- name: Setup .NET SDK
33-
uses: actions/setup-dotnet@v4
34-
with:
35-
dotnet-version: '8.0.x'
36-
37-
- name: Restore dotnet tools
38-
run: dotnet tool restore
39-
40-
- name: Run Build
41-
run: dotnet docfx docfx.json
42-
43-
- name: Setup Pages
44-
uses: actions/configure-pages@v5
45-
46-
- name: Upload artifact
47-
uses: actions/upload-pages-artifact@v3
48-
with:
49-
path: '_site'
50-
51-
- name: Deploy to GitHub Pages
52-
id: deployment
53-
uses: actions/deploy-pages@v4
21+
build:
22+
environment:
23+
name: github-pages
24+
url: ${{ steps.deployment.outputs.page_url }}
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Clone Repository
28+
uses: actions/checkout@v4
29+
with:
30+
submodules: recursive
31+
32+
- name: Setup .NET SDK
33+
uses: actions/setup-dotnet@v4
34+
with:
35+
dotnet-version: '8.0.x'
36+
37+
- name: Restore dotnet tools
38+
run: dotnet tool restore
39+
40+
- name: Run Build
41+
run: dotnet docfx docfx.json
42+
43+
- name: Setup Pages
44+
uses: actions/configure-pages@v5
45+
46+
- name: Upload artifact
47+
uses: actions/upload-pages-artifact@v3
48+
with:
49+
path: '_site'
50+
51+
- name: Deploy to GitHub Pages
52+
id: deployment
53+
uses: actions/deploy-pages@v4

.github/workflows/pullrequest.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test Build Documentation
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'main'
7+
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
16+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
17+
concurrency:
18+
group: "pages"
19+
cancel-in-progress: false
20+
21+
jobs:
22+
test:
23+
runs-on: ubuntu-latest
24+
concurrency: ci-${{ github.ref }}
25+
steps:
26+
- name: Clone Repository
27+
uses: actions/checkout@v4
28+
with:
29+
submodules: recursive
30+
31+
- name: Setup .NET SDK
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: '8.0.x'
35+
36+
- name: Restore dotnet tools
37+
run: dotnet tool restore
38+
39+
- name: Run Build
40+
run: dotnet docfx docfx.json
41+
42+
complete:
43+
runs-on: ubuntu-latest
44+
needs: test
45+
name: Test completion task
46+
steps:
47+
- run: echo "Tests Complete"

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ With your environment setup properly, the following explains how to build from s
1717
git clone https://github.com/MonoGame/monogame.github.io.git
1818
```
1919

20-
2. Install npm dependencies
20+
2. Install DotNet dependencies
2121

2222
```sh
23-
npm install
23+
dotnet tool restore
2424
```
2525

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

3030
`git submodule update --init --recursive`
3131

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

3434
`dotnet docfx docfx.json --serve`
3535

36+
> [!NOTE]
37+
> 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
38+
3639
## Document styling
3740

3841
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:
@@ -53,6 +56,9 @@ The use of DocFX with the updated MonoGame docs site has afforded the use of som
5356

5457
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)
5558

59+
> [!TIP]
60+
> No additional text is needed at the bottom of document pages as the licenses and requirements are automatically added by the DocFX build system
61+
5662
## LICENSE
5763

5864
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.

api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Welcome to the **MonoGame** reference documentation!
77

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

10-
Please view the [documentation](../articles/) for how to get started and step-by-step guidance.
10+
Please view the [documentation](../articles/index.md) for how to get started and step-by-step guidance.

articles/getting_started/1_setting_up_your_development_environment_unix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sudo apt install wine64 p7zip-full curl
5858
Create wine prefix:
5959

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

6464
If you ever need to undo the script, simply delete the `.winemonogame` folder in your home directory.

articles/getting_started/1_setting_up_your_development_environment_windows.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ When installing Visual Studio, the following workloads are required depending on
2626
![Visual Studio optional components](images/1_installer_vs_components.png)
2727

2828
> [!WARNING]
29-
> Targeting Windows
29+
> **Targeting Windows**
30+
>
3031
> 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.
3132
3233
### Install MonoGame extension for Visual Studio 2022

articles/preparing_for_consoles.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: Preparing for consoles
3+
description: How to get your game ready to run on consoles.
4+
---
5+
6+
# Preparing for consoles
7+
8+
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.
9+
10+
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.
11+
12+
This article explains the most common pitfalls and suggested guidelines to optimize your chances of having a smoother porting experience.
13+
14+
> [!NOTE]
15+
> *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.*
16+
17+
## No use of runtime reflection
18+
19+
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).
20+
21+
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.
22+
23+
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.
24+
25+
To publish with AOT:
26+
27+
- Add `<PublishAot>true</PublishAot>` to your `.csproj`.
28+
- Then run `dotnet publish` from the command-line/terminal.
29+
30+
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`.
31+
32+
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.
33+
34+
Native executables can debugged by:
35+
36+
- Starting an empty Visual Studio with no code.
37+
- Opening the compiled exe.
38+
- Then hitting "Start debugging".
39+
40+
It should show you on which C# lines it crashed.
41+
42+
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.
43+
44+
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.
45+
46+
## No runtime compilation / IL emit
47+
48+
Generating code at runtime is a scenario that is also not supported in AOT contexts, it is also forbidden by console manufacturers.
49+
50+
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.
51+
52+
## No use of dynamic assembly loading
53+
54+
Loading assemblies at runtime with `Assembly.Load()` is not supported.
55+
56+
## Third party libraries
57+
58+
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).
59+
60+
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.
61+
62+
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.
63+
64+
For example, here are some parsing libraries known for their compliance with AOT compilation and good handling of memrory:
65+
66+
- [TurboXML](https://github.com/xoofx/TurboXml)
67+
- [TinyJSON](https://github.com/zanders3/json)
68+
69+
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).
70+
71+
## Native libraries
72+
73+
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.
74+
75+
Even though a library might be open-source, it is unlikely they will just compile and run on consoles.
76+
77+
It is suggested to only use native libraries that have been proven to run on consoles.
78+
79+
## LINQ
80+
81+
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.
82+
83+
Moreover, LINQ is very garbage-prone and if your game has stuttering issues you might want to reduce your usage of LINQ.
84+
85+
## Avoiding garbage generation
86+
87+
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.
88+
89+
The garbage collector is slower on consoles and if your game generates a lot of garbage memory, there will be visible stutters.
90+
91+
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.
92+
93+
From there, you can check which parts of your code generate garbage and you can pinpoint where to optimize.
94+
95+
In order to avoid garbage, here are some best practices:
96+
97+
- Only use strings as const. Do not use strings dynamically (e.g. string concatenation, patterns...), this is the most common source of garbage.
98+
- Avoid allocating anything with the `new` keyword during your game loop, e.g. pre-allocate everything ahead of using them during gameplay.
99+
- 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.
100+
- Avoid using LINQ.
101+
- If you are using collections, initialize them with a large enough capacity to avoid their internal data structure being silently recreated.
102+
- 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.
103+
104+
## Do not rely on system calls
105+
106+
If your game calls directly to system functions, like kernel, win32 or unix commands, you might want to get rid of them.
107+
108+
## Consider I/O to be asynchronous
109+
110+
Saving player data/settings, or unlocking achievements are operations that should be considered asynchronous.
111+
112+
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).
113+
114+
If you consider all your I/O and system operations as asynchronous, you will likely be spared some headache.
115+
116+
## Suggestions
117+
118+
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.
119+

articles/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@
5858
href: migrate_xna.md
5959
- name: Packaging
6060
href: packaging_games.md
61+
- name: Preparing for consoles
62+
href: preparing_for_consoles.md
6163
- name: Samples and Demos
6264
href: samples.md
6365
- name: Community Tutorials
6466
href: tutorials.md
6567
- name: Help and Support
6668
href: help_and_support.md
6769
- name: Contributing to documentation
68-
href: contributing
70+
href: contributing.md
6971
- name: MonoGame
7072
href: monogame/Index.md

docfx.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"EnumSortOrder": "alphabetic"
2020
}
2121
],
22+
"rules": {
23+
"InvalidFileLink": "error",
24+
"InvalidBookmark": "error",
25+
"UidNotFound": "error",
26+
"ReferencedXrefPropertyNotString": "error"
27+
},
2228
"build": {
2329
"content": [
2430
{
@@ -34,7 +40,8 @@
3440
"foundation/**/*.md",
3541
"toc.yml",
3642
"*.md"
37-
]
43+
],
44+
"exclude": [ "_site/**", "README.md" ]
3845
}
3946
],
4047
"resource": [

external/MonoGame

Submodule MonoGame updated 58 files

0 commit comments

Comments
 (0)