diff --git a/src/OVGA.cpp b/src/OVGA.cpp --- a/src/OVGA.cpp +++ b/src/OVGA.cpp @@ -30,6 +30,9 @@ #include #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif DBGLOG_DEFAULT_CHANNEL(Vga); @@ -80,6 +83,14 @@ init_dpi(); #endif +#ifdef __EMSCRIPTEN__ + // In the browser the page scales the canvas and owns full screen: always open the game's native + // 800x600 window. + config_adv.vga_full_screen = 0; + config_adv.vga_full_screen_desktop = 0; + config_adv.vga_allow_highdpi = 0; +#endif + win_grab_forced = 0; win_grab_user_mode = 0; mouse_mode = MOUSE_INPUT_ABS; @@ -358,6 +369,17 @@ { SDL_Event event; +#ifdef __EMSCRIPTEN__ + // The game runs its own busy loops; hand control back to the browser (Asyncify) every ~10 ms so + // the canvas is presented and input and audio events are delivered. + static double last_yield = 0; + if( emscripten_get_now() - last_yield >= 10 ) + { + emscripten_sleep(0); + last_yield = emscripten_get_now(); + } +#endif + while( SDL_PollEvent(&event) ) { switch (event.type) @@ -640,6 +662,9 @@ // mode 1: full screen without display mode change (stretched to desktop) void Vga::set_full_screen_mode(int mode) { +#ifdef __EMSCRIPTEN__ + return; // the page's own full screen button handles this +#endif int result, mouse_x, mouse_y; uint32_t flags = config_adv.vga_full_screen_desktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;