echo docs hot_reload.md
1.1 kB · 25 lines
Markdown
at main

Hot Reload #

Hot reload is implemented by compiling src/game as a dynamic library and running a separate loader executable from src/lib/hot_reload.

How it works #

  1. just build-game builds build/hot_reload/game.{dylib,so,dll}.
  2. The loader copies that file to a versioned path such as game_0.dylib.
  3. The loader uses core:dynlib to load exported symbols with the game_ prefix.
  4. When the canonical game library changes, the loader copies and loads the new version.
  5. If size_of(Game_Memory) is unchanged, the old memory pointer is passed to game_hot_reloaded.
  6. If the size changed, the loader shuts down the old game memory and initializes fresh memory.

Rules of thumb #

  • Keep persistent game state in Game_Memory or reachable from it.
  • Temporary per-frame allocations should use context.temp_allocator and be cleared each frame.
  • Changing the size of Game_Memory restarts memory automatically.
  • Do not store function pointers from the hot-loaded library in persistent memory unless you manage their lifetime carefully.

Controls #

  • F5: force a reload
  • F6: force a memory restart
  • Esc: quit