HyperRogue 13.1o: integration with the page that hosts the game at fredygames.com. - control.cpp: in the browser the main loop never ends, so a request to quit (F10, the quit menu) did nothing. It now does what finishAll() does on the desktop (save_if_needed: records the score and, with an Orb of Safety, saves the game to continue later) and calls Module.onQuit, with which the host page writes the files to IndexedDB and restarts; - hyperweb.cpp: when the page has a #this_wide element, the game uses all of its height too (before, outside fullscreen it took the window height minus 32 pixels, capped at 16:9). Part of the source of the build served at fredygames.com (GPL-2.0-or-later, like HyperRogue). --- a/control.cpp +++ b/control.cpp @@ -1652,12 +1652,26 @@ } #endif +#if ISWEB +/* fredygames.com: the browser has no "exit"; when the game asks to quit (F10, or the quit menu), + * do what finishAll() does on the desktop (record the score; with an Orb of Safety, save the game + * so that the next start continues it) and let the host page restart the game. */ +void web_mainloopiter() { + mainloopiter(); + if(quitmainloop) { + quitmainloop = false; + save_if_needed(); + EM_ASM({ if(Module.onQuit) Module.onQuit(); }); + } + } +#endif + EX void mainloop() { if(noGUI) return; lastt = 0; #if ISWEB initweb(); - emscripten_set_main_loop(mainloopiter, 0, true); + emscripten_set_main_loop(web_mainloopiter, 0, true); #else while(!quitmainloop) mainloopiter(); #endif --- a/hyperweb.cpp +++ b/hyperweb.cpp @@ -223,6 +223,12 @@ if(!d) return window.innerWidth; return d.clientHeight; }); + /* fredygames.com: the host page gives the whole frame to the game (#this_wide fills it) */ + else if(EM_ASM_INT({ return document.getElementById("this_wide") ? 1 : 0; })) { + vid.yscr = vid.yres = EM_ASM_INT({ + return document.getElementById("this_wide").clientHeight; + }); + } else { vid.xscr = vid.xres = vid.xres - 32; vid.yscr = vid.yres = EM_ASM_INT({