From 326e560329f07c3d3f6b75c140f0c9e54a7c6c80 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 18 Mar 2024 01:02:48 -0700 Subject: [PATCH] Attract: fix attract demos end handling Fixes two bugs: - Attract mode carrying over to gameplay if an attract demo is allowed to finish without interrupting it - Credits ending after the first replay ends --- src/d_main.cpp | 2 ++ src/d_netcmd.c | 11 +++++++++-- src/g_game.c | 1 - src/k_credits.cpp | 1 + src/menus/transient/pause-replay.c | 23 ++++++++--------------- src/p_setup.cpp | 4 +++- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 473cd1fa3..cabcab3d2 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1131,6 +1131,8 @@ static boolean g_deferredtitle = false; // void D_StartTitle(void) { + demo.attract = DEMO_ATTRACT_OFF; + Music_StopAll(); D_ClearState(); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f5d5fd5b8..48c1c30c8 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -71,6 +71,7 @@ #include "k_roulette.h" #include "k_bans.h" #include "k_director.h" +#include "k_credits.h" #ifdef SRB2_CONFIG_ENABLE_WEBM_MOVIES #include "m_avrecorder.h" @@ -6374,14 +6375,20 @@ void Command_ExitGame_f(void) if (!modeattacking) { - if (restoreMenu == NULL) + // YES, this is where demo.attract gets cleared! + if (demo.attract == DEMO_ATTRACT_CREDITS) { - D_StartTitle(); + F_ContinueCredits(); // <-- clears demo.attract + } + else if (restoreMenu == NULL) // this is true for attract demos too! + { + D_StartTitle(); // <-- clears demo.attract } else { D_ClearState(); M_StartControlPanel(); + demo.attract = DEMO_ATTRACT_OFF; // shouldn't ever happen, but let's keep the code symmetrical } } } diff --git a/src/g_game.c b/src/g_game.c index 10edfc6af..b0c83dd86 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1348,7 +1348,6 @@ boolean G_Responder(event_t *ev) { // stop the title demo G_CheckDemoStatus(); - demo.attract = DEMO_ATTRACT_OFF; return true; } } diff --git a/src/k_credits.cpp b/src/k_credits.cpp index 83219e60d..d7e0502b9 100644 --- a/src/k_credits.cpp +++ b/src/k_credits.cpp @@ -430,6 +430,7 @@ void F_ContinueCredits(void) { G_SetGamestate(GS_CREDITS); F_CreditsReset(); + demo.attract = DEMO_ATTRACT_OFF; // Returning from playing a demo. // Go to the next slide. diff --git a/src/menus/transient/pause-replay.c b/src/menus/transient/pause-replay.c index 04d3ba545..6b2b87815 100644 --- a/src/menus/transient/pause-replay.c +++ b/src/menus/transient/pause-replay.c @@ -94,8 +94,12 @@ void M_EndModeAttackRun(void) // - Now we need to clear the rest of the gamestate ourself! } - // Playback: modeattacking is always false, so calling this returns to the menu. - // Recording: modeattacking is still true and this function call preserves that. + // Playback: + // - modeattacking is always false, so calling this returns to the menu. + // - Because modeattacking is false, also clears demo.attract. + // + // Recording: + // - modeattacking is still true and this function call preserves that. Command_ExitGame_f(); if (!modeattacking) @@ -123,19 +127,8 @@ void M_EndModeAttackRun(void) modeattacking = ATTACKING_NONE; // Return to the menu. - if (demo.attract == DEMO_ATTRACT_TITLE) - { - D_SetDeferredStartTitle(true); - } - else if (demo.attract == DEMO_ATTRACT_CREDITS) - { - F_ContinueCredits(); - } - else - { - D_ClearState(); - M_StartControlPanel(); - } + D_ClearState(); + M_StartControlPanel(); } // Replay Playback Menu diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 812815984..e2bce602a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -8342,8 +8342,10 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) P_InitLevelSettings(); - if (demo.attract != DEMO_ATTRACT_TITLE) + if (demo.attract != DEMO_ATTRACT_TITLE && gamestate != GS_TITLESCREEN) { + // Stop titlescreen music from overriding level music. + // Except on the title screen, where an attract demo or title map may be used. Music_Stop("title"); }