Refactor replay saving handler for later use

This commit is contained in:
fickleheart 2019-03-24 21:55:08 -05:00
parent 4b7d2aea84
commit b2cbe3ed6d
6 changed files with 48 additions and 17 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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

View file

@ -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.
{

View file

@ -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();

View file

@ -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