From 716b9527bf9a0966154688818f5b8041b8351f8c Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 21 Feb 2024 14:38:11 -0500 Subject: [PATCH 1/2] Add a -allowdesync parameter that will allow individual demos to desync. Warning is still shown, but player position will not be modified. --- src/d_main.c | 4 ++-- src/f_finale.c | 1 + src/g_demo.c | 20 ++++++++++++-------- src/g_demo.h | 5 +++-- src/m_menu.c | 1 + src/netcode/d_netcmd.c | 4 +++- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 83cb425c9..2bd9546bb 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1664,10 +1664,10 @@ void D_SRB2Main(void) if (M_CheckParm("-playdemo")) { singledemo = true; // quit after one demo - G_DeferedPlayDemo(tmp); + G_DeferedPlayDemo(tmp, M_CheckParm("-allowdemodesync") != 0); } else - G_TimeDemo(tmp); + G_TimeDemo(tmp, M_CheckParm("-allowdemodesync") != 0); G_SetGamestate(GS_NULL); wipegamestate = GS_NULL; diff --git a/src/f_finale.c b/src/f_finale.c index edeb08820..001f06137 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -3513,6 +3513,7 @@ void F_TitleScreenTicker(boolean run) titledemo = true; demofileoverride = DFILE_OVERRIDE_NONE; + demoallowdesync = false; G_DoPlayDemo(dname); } } diff --git a/src/g_demo.c b/src/g_demo.c index f64f34168..a35498e92 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -51,6 +51,7 @@ boolean demorecording; boolean demoplayback; boolean titledemo; // Title Screen demo can be cancelled by any key demo_file_override_e demofileoverride; +boolean demoallowdesync = false; // Allow demo files to de-sync static UINT8 *demobuffer = NULL; static UINT8 *demo_p, *demotime_p; static UINT8 *demoend; @@ -660,11 +661,14 @@ void G_ConsGhostTic(void) CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced!\n")); demosynced = false; - P_UnsetThingPosition(testmo); - testmo->x = oldghost.x; - testmo->y = oldghost.y; - P_SetThingPosition(testmo); - testmo->z = oldghost.z; + if (!demoallowdesync) + { + P_UnsetThingPosition(testmo); + testmo->x = oldghost.x; + testmo->y = oldghost.y; + P_SetThingPosition(testmo); + testmo->z = oldghost.z; + } } if (*demo_p == DEMOMARKER) @@ -1975,7 +1979,7 @@ UINT8 G_CmpDemoTime(char *oldname, char *newname) // // G_PlayDemo // -void G_DeferedPlayDemo(const char *name) +void G_DeferedPlayDemo(const char *name, boolean allowdesync) { COM_BufAddText("playdemo \""); COM_BufAddText(name); @@ -2633,7 +2637,7 @@ void G_FreeGhosts(void) // static INT32 restorecv_vidwait; -void G_TimeDemo(const char *name) +void G_TimeDemo(const char *name, boolean allowdesync) { nodrawers = M_CheckParm("-nodraw"); noblit = M_CheckParm("-noblit"); @@ -2644,7 +2648,7 @@ void G_TimeDemo(const char *name) singletics = true; framecount = 0; demostarttime = I_GetTime(); - G_DeferedPlayDemo(name); + G_DeferedPlayDemo(name, allowdesync); } void G_DoPlayMetal(void) diff --git a/src/g_demo.h b/src/g_demo.h index e8c0c8d95..19fbc80e2 100644 --- a/src/g_demo.h +++ b/src/g_demo.h @@ -35,6 +35,7 @@ typedef enum } demo_file_override_e; extern demo_file_override_e demofileoverride; +extern boolean demoallowdesync; // Quit after playing a demo from cmdline. extern boolean singledemo; @@ -94,9 +95,9 @@ void G_WriteMetalTic(mobj_t *metal); void G_SaveMetal(UINT8 **buffer); void G_LoadMetal(UINT8 **buffer); -void G_DeferedPlayDemo(const char *demo); +void G_DeferedPlayDemo(const char *demo, boolean allowdesync); void G_DoPlayDemo(char *defdemoname); -void G_TimeDemo(const char *name); +void G_TimeDemo(const char *name, boolean allowdesync); void G_AddGhost(char *defdemoname); void G_FreeGhosts(void); void G_DoPlayMetal(void); diff --git a/src/m_menu.c b/src/m_menu.c index 3c6ef0fe3..b18515842 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10529,6 +10529,7 @@ static void M_StartTimeAttackReplay(INT32 choice) { M_ClearMenus(true); modeattacking = ATTACKING_RECORD; // set modeattacking before G_DoPlayDemo so the map loader knows + demoallowdesync = false; G_DoPlayDemo(ra_demoname); } } diff --git a/src/netcode/d_netcmd.c b/src/netcode/d_netcmd.c index 66a30637f..bd3edc2b8 100644 --- a/src/netcode/d_netcmd.c +++ b/src/netcode/d_netcmd.c @@ -1596,6 +1596,8 @@ static void Command_Playdemo_f(void) demofileoverride = DFILE_OVERRIDE_SKIP; } + demoallowdesync = COM_CheckParm("-allowdesync"); + // Internal if no extension, external if one exists // If external, convert the file name to a path in SRB2's home directory if (FIL_CheckExtension(name)) @@ -1643,7 +1645,7 @@ static void Command_Timedemo_f(void) CONS_Printf(M_GetText("Timing demo '%s'.\n"), timedemo_name); - G_TimeDemo(timedemo_name); + G_TimeDemo(timedemo_name, COM_CheckParm("-allowdesync")); } // stop current demo From a407ff88999c7300a185e508d04a7005d491b631 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 21 Feb 2024 16:22:00 -0500 Subject: [PATCH 2/2] Zwip Zwap Zapony's suggestion to use a consvar --- src/d_main.c | 4 ++-- src/f_finale.c | 1 - src/g_demo.c | 11 ++++++----- src/g_demo.h | 6 +++--- src/m_menu.c | 1 - src/netcode/d_netcmd.c | 5 ++--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 2bd9546bb..83cb425c9 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1664,10 +1664,10 @@ void D_SRB2Main(void) if (M_CheckParm("-playdemo")) { singledemo = true; // quit after one demo - G_DeferedPlayDemo(tmp, M_CheckParm("-allowdemodesync") != 0); + G_DeferedPlayDemo(tmp); } else - G_TimeDemo(tmp, M_CheckParm("-allowdemodesync") != 0); + G_TimeDemo(tmp); G_SetGamestate(GS_NULL); wipegamestate = GS_NULL; diff --git a/src/f_finale.c b/src/f_finale.c index 001f06137..edeb08820 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -3513,7 +3513,6 @@ void F_TitleScreenTicker(boolean run) titledemo = true; demofileoverride = DFILE_OVERRIDE_NONE; - demoallowdesync = false; G_DoPlayDemo(dname); } } diff --git a/src/g_demo.c b/src/g_demo.c index a35498e92..ec3d223bd 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -51,7 +51,6 @@ boolean demorecording; boolean demoplayback; boolean titledemo; // Title Screen demo can be cancelled by any key demo_file_override_e demofileoverride; -boolean demoallowdesync = false; // Allow demo files to de-sync static UINT8 *demobuffer = NULL; static UINT8 *demo_p, *demotime_p; static UINT8 *demoend; @@ -68,6 +67,8 @@ static UINT8 *metalbuffer = NULL; static UINT8 *metal_p; static UINT16 metalversion; +consvar_t cv_resyncdemo = CVAR_INIT("resyncdemo", "On", 0, CV_OnOff, NULL); + // extra data stuff (events registered this frame while recording) static struct { UINT8 flags; // EZT flags @@ -661,7 +662,7 @@ void G_ConsGhostTic(void) CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced!\n")); demosynced = false; - if (!demoallowdesync) + if (cv_resyncdemo.value) { P_UnsetThingPosition(testmo); testmo->x = oldghost.x; @@ -1979,7 +1980,7 @@ UINT8 G_CmpDemoTime(char *oldname, char *newname) // // G_PlayDemo // -void G_DeferedPlayDemo(const char *name, boolean allowdesync) +void G_DeferedPlayDemo(const char *name) { COM_BufAddText("playdemo \""); COM_BufAddText(name); @@ -2637,7 +2638,7 @@ void G_FreeGhosts(void) // static INT32 restorecv_vidwait; -void G_TimeDemo(const char *name, boolean allowdesync) +void G_TimeDemo(const char *name) { nodrawers = M_CheckParm("-nodraw"); noblit = M_CheckParm("-noblit"); @@ -2648,7 +2649,7 @@ void G_TimeDemo(const char *name, boolean allowdesync) singletics = true; framecount = 0; demostarttime = I_GetTime(); - G_DeferedPlayDemo(name, allowdesync); + G_DeferedPlayDemo(name); } void G_DoPlayMetal(void) diff --git a/src/g_demo.h b/src/g_demo.h index 19fbc80e2..67f61f54d 100644 --- a/src/g_demo.h +++ b/src/g_demo.h @@ -35,7 +35,7 @@ typedef enum } demo_file_override_e; extern demo_file_override_e demofileoverride; -extern boolean demoallowdesync; +extern consvar_t cv_resyncdemo; // Quit after playing a demo from cmdline. extern boolean singledemo; @@ -95,9 +95,9 @@ void G_WriteMetalTic(mobj_t *metal); void G_SaveMetal(UINT8 **buffer); void G_LoadMetal(UINT8 **buffer); -void G_DeferedPlayDemo(const char *demo, boolean allowdesync); +void G_DeferedPlayDemo(const char *demo); void G_DoPlayDemo(char *defdemoname); -void G_TimeDemo(const char *name, boolean allowdesync); +void G_TimeDemo(const char *name); void G_AddGhost(char *defdemoname); void G_FreeGhosts(void); void G_DoPlayMetal(void); diff --git a/src/m_menu.c b/src/m_menu.c index b18515842..3c6ef0fe3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10529,7 +10529,6 @@ static void M_StartTimeAttackReplay(INT32 choice) { M_ClearMenus(true); modeattacking = ATTACKING_RECORD; // set modeattacking before G_DoPlayDemo so the map loader knows - demoallowdesync = false; G_DoPlayDemo(ra_demoname); } } diff --git a/src/netcode/d_netcmd.c b/src/netcode/d_netcmd.c index bd3edc2b8..f7aa2c6fa 100644 --- a/src/netcode/d_netcmd.c +++ b/src/netcode/d_netcmd.c @@ -675,6 +675,7 @@ void D_RegisterClientCommands(void) COM_AddCommand("timedemo", Command_Timedemo_f, 0); COM_AddCommand("stopdemo", Command_Stopdemo_f, COM_LUA); COM_AddCommand("playintro", Command_Playintro_f, COM_LUA); + CV_RegisterVar(&cv_resyncdemo); COM_AddCommand("resetcamera", Command_ResetCamera_f, COM_LUA); @@ -1596,8 +1597,6 @@ static void Command_Playdemo_f(void) demofileoverride = DFILE_OVERRIDE_SKIP; } - demoallowdesync = COM_CheckParm("-allowdesync"); - // Internal if no extension, external if one exists // If external, convert the file name to a path in SRB2's home directory if (FIL_CheckExtension(name)) @@ -1645,7 +1644,7 @@ static void Command_Timedemo_f(void) CONS_Printf(M_GetText("Timing demo '%s'.\n"), timedemo_name); - G_TimeDemo(timedemo_name, COM_CheckParm("-allowdesync")); + G_TimeDemo(timedemo_name); } // stop current demo