diff --git a/src/doom/g_game.c b/src/doom/g_game.c index f23586b..3b41a5a 100644 --- a/src/doom/g_game.c +++ b/src/doom/g_game.c @@ -736,12 +736,27 @@ boolean G_Responder(event_t *ev) // G_Ticker // Make ticcmd_ts for the players. // +#ifdef __EMSCRIPTEN__ +// wasmga.me: the slot of the Resume snapshot (see wg_snapshot below). +#define WG_SNAPSHOT_SLOT 7 +static boolean wg_resume_pending; +#endif + void G_Ticker(void) { int i; int buf; ticcmd_t *cmd; +#ifdef __EMSCRIPTEN__ + // wasmga.me: a snapshot asked for while the game was still starting + // loads once it runs, after the title screen has been set up. + if (wg_resume_pending && gameaction == ga_nothing) { + wg_resume_pending = false; + G_LoadGame(P_SaveGameFile(WG_SNAPSHOT_SLOT)); + } +#endif + // do player reborns if needed for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && players[i].playerstate == PST_REBORN) G_DoReborn(i); @@ -2059,3 +2074,34 @@ boolean G_CheckDemoStatus(void) return false; } + +#ifdef __EMSCRIPTEN__ +#include + +// wasmga.me: the play page keeps one snapshot of the game to resume from, as +// an ordinary savegame in a slot the menus don't show. Both are called +// between frames. + +// Writes the snapshot when the game is in a level it could save from the +// menu, without the "game saved." message. Returns whether it wrote one. +EMSCRIPTEN_KEEPALIVE int wg_snapshot(void) +{ + char *message = players[consoleplayer].message; + + if (!usergame || gamestate != GS_LEVEL || netgame || demoplayback || gameaction != ga_nothing + || players[consoleplayer].playerstate == PST_DEAD) { + return 0; + } + savegameslot = WG_SNAPSHOT_SLOT; + M_StringCopy(savedescription, "RESUME", sizeof(savedescription)); + G_DoSaveGame(); + players[consoleplayer].message = message; + return 1; +} + +// Loads the snapshot on the next tic the game runs. +EMSCRIPTEN_KEEPALIVE void wg_resume(void) +{ + wg_resume_pending = true; +} +#endif