logoalt Hacker News

anonymous908213yesterday at 9:55 AM0 repliesview on HN

To be clear, the framework I built is independent of the MonoGame framework. As for how it was built, it's relatively straightforward. There are three layers: platform layer, framework layer, and the game layer. On the platform layer, I started by implementing a basic hello world-tier game loop using Win32 window/messaging APIs, OpenGL for graphics rendering, and OpenAL for audio playback. Then I wrote tidy wrapper layer functions for calling into the platform layer, with better ergonomics/readability, which the game layer calls. Then, I began adding WASM APIs at the platform layer, with branching #if statements in the framework layer that control whether src\platform\win32 or src\platform\wasm functions are called based on build target. In this way, the game code remained unchanged but support for web was seamlessly added (with some pain in adjusting the wrapper APIs to handle the large differences in Win32 and web APIs). Then repeated this process for each additional platform. The primary csproj is set up to branch into different csprojs per build target, with one using the Microsoft.NET.Sdk.WebAssembly project SDK, etc. Over time, I expanded features of the platform layer and wrapper layer as they were needed.

For the game I had already made progress on when trying MonoGame, I had already written a wrapper layer over the MonoGame APIs even before I had started on my own framework. My new framework wrapper layer was designed as similarly as possible, so transitioning my game code to the new framework was mostly painless, and only required adjusting the shape of some rendering/audio/input calls here and there.