From b2cbe3ed6dfb1a915f237c4dd4b8e36c2bbc0588 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sun, 24 Mar 2019 21:55:08 -0500 Subject: [PATCH] Refactor replay saving handler for later use --- src/d_netcmd.c | 2 +- src/g_game.c | 14 ++++++++++---- src/g_game.h | 1 - src/p_tick.c | 2 +- src/st_stuff.c | 19 ++++++++++++++++--- src/y_inter.c | 27 ++++++++++++++++++++------- 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index d4ffe27a..50f0a2e8 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2627,7 +2627,7 @@ static void Got_Mapcmd(UINT8 **cp, INT32 playernum) LUAh_MapChange(mapnumber); #endif*/ - demosaved = demodefersave = false; + demo.savemode = (cv_recordmultiplayerdemos.value == 2) ? DSM_WILLAUTOSAVE : DSM_NOTSAVING; demo.savebutton = 0; G_InitNew(pencoremode, mapname, resetplayer, skipprecutscene); if (demo.playback && !demo.timing) diff --git a/src/g_game.c b/src/g_game.c index ef8a4196..fc636537 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -288,7 +288,6 @@ UINT32 timesBeatenWithEmeralds; //@TODO put these all in a struct for namespacing purposes? static char demoname[128]; -boolean demosaved, demodefersave; static UINT8 *demobuffer = NULL; static UINT8 *demo_p, *demotime_p; static UINT8 *demoend; @@ -3325,7 +3324,7 @@ void G_ExitLevel(void) // Remove CEcho text on round end. HU_ClearCEcho(); - if (multiplayer && demo.recording && cv_recordmultiplayerdemos.value == 2) + if (multiplayer && demo.recording && (demo.savemode == DSM_WILLSAVE || demo.savemode == DSM_WILLAUTOSAVE)) G_SaveDemo(); } } @@ -3860,6 +3859,9 @@ void G_AfterIntermission(void) D_StartTitle(); return; } + else if (demo.recording && demo.savemode != DSM_NOTSAVING) + G_SaveDemo(); + if (modeattacking) // End the run. { M_EndModeAttackRun(); @@ -4004,6 +4006,9 @@ static void G_DoContinued(void) // when something new is added. void G_EndGame(void) { + if (demo.recording && demo.savemode != DSM_NOTSAVING) + G_SaveDemo(); + // Only do evaluation and credits in coop games. if (gametype == GT_COOP) { @@ -7665,13 +7670,14 @@ void G_SaveDemo(void) md5_buffer((char *)p+16, demo_p - (p+16), p); // make a checksum of everything after the checksum in the file. #endif - demosaved = FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer); // finally output the file. + if (FIL_WriteFile(va(pandf, srb2home, demoname), demobuffer, demo_p - demobuffer)) // finally output the file. + demo.savemode = DSM_SAVED; free(demobuffer); demo.recording = false; if (modeattacking != ATTACKING_RECORD) { - if (demosaved) + if (demo.savemode == DSM_SAVED) CONS_Printf(M_GetText("Demo %s recorded\n"), demoname); else CONS_Alert(CONS_WARNING, M_GetText("Demo %s not saved\n"), demoname); diff --git a/src/g_game.h b/src/g_game.h index ffe98d73..c9bcaf01 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -36,7 +36,6 @@ extern boolean playeringame[MAXPLAYERS]; // ====================================== // demoplaying back and demo recording -extern boolean demosaved, demodefersave; extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality; // Publicly-accessible demo vars diff --git a/src/p_tick.c b/src/p_tick.c index a9f78662..03ce05c3 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -733,7 +733,7 @@ void P_Ticker(boolean run) G_WriteAllGhostTics(); if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && InputDown(gc_lookback, 1)) - demodefersave = true; + demo.savemode = DSM_WILLSAVE; // DSM_TITLEENTRY } if (demo.playback) // Use Ghost data for consistency checks. { diff --git a/src/st_stuff.c b/src/st_stuff.c index 2dd045c1..dec7ee0c 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -2017,10 +2017,23 @@ static void ST_overlayDrawer(void) // Replay manual-save stuff if (demo.recording && multiplayer && demo.savebutton && demo.savebutton + 3*TICRATE < leveltime) { - if (demodefersave || cv_recordmultiplayerdemos.value == 2) - V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Replay will be saved."); - else + switch (demo.savemode) + { + case DSM_NOTSAVING: V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Look Backward: Save replay"); + break; + + case DSM_WILLAUTOSAVE: + V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Replay will be saved." /*" (Look Backward: Change title)"*/); + break; + + case DSM_WILLSAVE: + V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Replay will be saved."); + break; + + default: // Don't render anything + break; + } } ST_drawDebugInfo(); diff --git a/src/y_inter.c b/src/y_inter.c index 5a8791d4..1e6d945c 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -562,10 +562,20 @@ dotimer: string); } - if (demo.recording && cv_recordmultiplayerdemos.value == 1) - V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|hilicol, "Look Backward: Save replay"); - else if (demosaved && !demo.playback) - V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|hilicol, "Replay saved!"); + if ((demo.recording || demo.savemode == DSM_SAVED) && !demo.playback) + switch (demo.savemode) + { + case DSM_NOTSAVING: + V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|hilicol, "Look Backward: Save replay"); + break; + + case DSM_SAVED: + V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|hilicol, "Replay saved!"); + break; + + default: // Don't render any text here + break; + } // Make it obvious that scrambling is happening next round. if (cv_scrambleonchange.value && cv_teamscramble.value && (intertic/TICRATE % 2 == 0)) @@ -582,10 +592,13 @@ void Y_Ticker(void) if (intertype == int_none) return; - if (demo.recording && cv_recordmultiplayerdemos.value == 1 && (demodefersave || InputDown(gc_lookback, 1))) + if (demo.recording) { - demodefersave = false; - G_SaveDemo(); + if (demo.savemode == DSM_NOTSAVING && InputDown(gc_lookback, 1)) + demo.savemode = DSM_WILLSAVE; // DSM_TITLEENTRY + + if (demo.savemode == DSM_WILLSAVE || demo.savemode == DSM_WILLAUTOSAVE) + G_SaveDemo(); } // Check for pause or menu up in single player