Skip to content

Commit

Permalink
Assume bootstrapping is useful for all consoles
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo authored Jan 16, 2025
1 parent 8805a12 commit ebda355
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions docs/appendix/Appendix-B:-FNA-on-Consoles.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ While the runtimes require a console NDA, there are some things you can do to ma

All console builds use NativeAOT as the runtime. If you want a solid head-start, you should read Appendix A. Don't underestimate this step, especially if your game heavily depends on .NET's reflection features!

### Bootstrapping

For non-PC builds it is generally a good idea to assume that platform-specific bootstrapping is needed - in FNA's case we make use of SDL3's `SDL_RunApp` functionality; your code should be able to stay the same except for the Main function:

```
[STAThread]
static void Main(string[] args)
#if NET
{
Environment.SetEnvironmentVariable("FNA_PLATFORM_BACKEND", "SDL3");
realArgs = args;
SDL3.SDL.SDL_main_func mainFunction = FakeMain;
SDL3.SDL.SDL_RunApp(0, IntPtr.Zero, mainFunction, IntPtr.Zero);
}
static string[] realArgs;
static int FakeMain(int argc, IntPtr argv)
{
RealMain(realArgs);
return 0;
}
static void RealMain(string[] args)
#endif
{
// blah blah blah
}
```

### Window Size Changes
Even if your window is not resizable, operating systems (including Windows!) may forcibly change the window size for a multitude of reasons, and so the graphics device will reset.

Expand Down Expand Up @@ -83,34 +112,6 @@ To load files, use `TitleContainer.OpenStream` instead. Save data should be hand
## Xbox GDK
GDK support is now available to ID@Xbox licensees. All of the source code is fully public except for the NativeAOT toolchain; developers can request NativeAOT-GDKX access via Discord once they have signed the GDK agreements with Microsoft.

### Code Differences
Your code should be able to stay the same except for the Main function:

```
[STAThread]
static void Main(string[] args)
#if GDK
{
Environment.SetEnvironmentVariable("FNA_PLATFORM_BACKEND", "SDL3");
realArgs = args;
SDL3.SDL.SDL_main_func mainFunction = FakeMain;
SDL3.SDL.SDL_RunApp(0, IntPtr.Zero, mainFunction, IntPtr.Zero);
}
static string[] realArgs;
static int FakeMain(int argc, IntPtr argv)
{
RealMain(realArgs);
return 0;
}
static void RealMain(string[] args)
#endif
{
// blah blah blah
}
```

## Nintendo Switch

While there is no special code needed for Nintendo Switch support (100% of the platform code is in SDL and NativeAOT, two separate projects), all consulting and documentation is private, per NDA requirements. If you are a licensed developer, please get access to SDL-switch (search the licensee forums) and then get in touch with flibit on Discord. If you are NOT a licensed developer, you're on your own. None of us are able to get you hooked up, so please only get in touch AFTER you have Switch SDK access.
Expand Down

0 comments on commit ebda355

Please sign in to comment.