Extract GameEngine::doFrame() for Emscripten callback support

Refactors the main game loop to support both:
- Desktop: traditional blocking while(running) loop
- Browser: emscripten_set_main_loop_arg() callback (build-time conditional)

Changes:
- Add doFrame() method containing single-frame update logic
- Add isRunning() accessor for Emscripten callback
- run() now conditionally uses #ifdef __EMSCRIPTEN__ for loop selection
- Add emscriptenMainLoopCallback() static function

This is a prerequisite for Emscripten builds - browsers require
cooperative multitasking with callback-based frame updates.

Both normal and headless builds verified working.

Contributes to #158

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-01-30 23:51:35 -05:00
commit 8b6eb1e7ae
3 changed files with 193 additions and 137 deletions

View file

@ -235,6 +235,8 @@ public:
sf::RenderTarget & getRenderTarget();
sf::RenderTarget* getRenderTargetPtr() { return render_target; }
void run();
void doFrame(); // Single frame update - extracted for Emscripten callback support
bool isRunning() const { return running; } // Check if engine should continue running
void sUserInput();
void cleanup(); // Clean up Python references before destruction
void executeStartupScripts(); // Execute --exec scripts (called once after final engine setup)