Run your favorite games everywhere with WASM: the BlazorDoom use case by Yassine Benabbas

Learn how to port C# games to browsers using WebAssembly through a hands-on Doom engine example. Explore technical challenges, interop patterns, and modern web standards.

Key takeaways
  • WebAssembly enables porting existing games to run directly in web browsers while maintaining good performance (60 FPS possible)

  • The Doom engine was successfully ported from C# to WebAssembly with minimal code changes, as 70% of the code was immediately compatible

  • Game porting can be done through either complete reimplementation or adapting existing source code for the target platform

  • Key technical challenges included:

    • Converting the game’s color palette system to RGB values for browser canvas
    • Implementing proper audio playback using Web Audio API
    • Replacing native platform loops with requestAnimationFrame
    • Handling interop between C# and JavaScript
  • WebAssembly and JavaScript need to work together since not all browser APIs are directly available to WASM code

  • The game loop pattern needs adaptation when porting to browser:

    • Replace infinite loops with recursive requestAnimationFrame calls
    • Handle frame pacing appropriately
    • Manage state updates between WASM and JavaScript
  • Modern web standards like Canvas API and Audio Context make it possible to implement complex game features

  • .NET 7+ provides improved JavaScript interop capabilities when targeting WebAssembly

  • Game porting is an effective way to learn programming concepts while working with familiar content

  • WAD file support allows running different Doom game content without changing the engine code