--- a/Game/src/game.c +++ b/Game/src/game.c @@ -27,6 +27,11 @@ #include #include #include + +#ifdef __EMSCRIPTEN__ +#include +#include +#endif #ifdef _WIN32 #include @@ -2389,6 +2394,32 @@ } } + +#ifdef __EMSCRIPTEN__ +/* A confirmed browser-menu exit skips DOS end screens and native net waits. + * The shell owns the relay leave and save sync after the single onExit event. */ +void dukeBrowserMenuExit(int toTitle) +{ + static int exiting = 0; + if (exiting || (toTitle && numplayers > 1)) return; + exiting = 1; + ready2send = 0; + gamequit = 0; + KB_FlushKeyboardQueue(); + dukeTournamentStop(); + if (ud.recstat == 1) closedemowrite(); + if (frecfilep != NULL) + { + fclose(frecfilep); + frecfilep = NULL; + } + Shutdown(); + uninitgroupfile(); + SDL_Quit(); + EM_ASM({ Module['dukeExitReason'] = $0 ? 'title' : 'quit'; }, toTitle); + emscripten_force_exit(EXIT_SUCCESS); +} +#endif void gameexit(char *msg) { --- a/Game/src/menues.c +++ b/Game/src/menues.c @@ -34,6 +34,9 @@ extern void dukeTournamentStart(int,int,int); extern void dukeTournamentStop(void); extern void dukeTournamentKill(int,int); +#ifdef __EMSCRIPTEN__ +extern void dukeBrowserMenuExit(int toTitle); +#endif #include "audiolib/fx_man.h" #include "audiolib/music.h" #include "animlib.h" @@ -3517,14 +3520,27 @@ gametext(c,90,"Are you sure you want to quit?",0,2+8+16); gametext(c,99,"(Y/N)",0,2+8+16); +#ifdef __EMSCRIPTEN__ + gametext(c,114,"UNSAVED PROGRESS WILL BE LOST",0,2+8+16); + if (numplayers > 1) + gametext(c,126,"MATCH WILL END FOR EVERYONE",0,2+8+16); +#endif _handle_events(); if( KB_KeyPressed(sc_Space) || KB_KeyPressed(sc_Enter) || KB_KeyPressed(sc_kpad_Enter) || KB_KeyPressed(sc_Y) || LMB ) { - gameexitanycase(); - } - +#ifdef __EMSCRIPTEN__ + dukeBrowserMenuExit(0); +#else + gameexitanycase(); +#endif + } + +#ifdef __EMSCRIPTEN__ + x = probe(186,145,0,0); +#else x = probe(186,124,0,0); +#endif if(x == -1 || KB_KeyPressed(sc_N) || RMB) { KB_ClearKeyDown(sc_N); @@ -3543,10 +3559,16 @@ c = 320>>1; gametext(c,90,"Quit to Title?",0,2+8+16); gametext(c,99,"(Y/N)",0,2+8+16); +#ifdef __EMSCRIPTEN__ + gametext(c,114,"UNSAVED PROGRESS WILL BE LOST",0,2+8+16); +#endif _handle_events(); if( KB_KeyPressed(sc_Space) || KB_KeyPressed(sc_Enter) || KB_KeyPressed(sc_kpad_Enter) || KB_KeyPressed(sc_Y) || LMB ) { +#ifdef __EMSCRIPTEN__ + dukeBrowserMenuExit(1); +#else KB_FlushKeyboardQueue(); ps[myconnectindex].gm = MODE_DEMO; if(ud.recstat == 1) @@ -3555,9 +3577,14 @@ dobonus(1); ud.last_level = -1; cmenu(0); - } - +#endif + } + +#ifdef __EMSCRIPTEN__ + x = probe(186,137,0,0); +#else x = probe(186,124,0,0); +#endif if(x == -1 || KB_KeyPressed(sc_N) || RMB) {