diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 1cef2ad57..1c057ad1d 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -254,7 +254,7 @@ void NewLevel(MapRecord *sng, int skill) gSkill = skill; cheatReset(); StartLevel(sng); - gamestate = GS_LEVEL; + gameaction = ga_level; }; bool startedCutscene = false; @@ -485,7 +485,7 @@ void GameInterface::Startup() if (!userConfig.nologo && gGameOptions.nGameType == 0) playlogos(); else { - startmainmenu(); + gameaction = ga_mainmenu; } } } diff --git a/source/blood/src/credits.cpp b/source/blood/src/credits.cpp index 6b8b48a45..868cba1fc 100644 --- a/source/blood/src/credits.cpp +++ b/source/blood/src/credits.cpp @@ -94,10 +94,8 @@ void playlogos() jobs[job++] = { Create(2518, DScreenJob::fadein) }; RunScreenJob(jobs, job, [](bool) { - gamestate = GS_MENUSCREEN; - M_StartControlPanel(false); - M_SetMenu(NAME_Mainmenu); - }, true, true); + gameaction = ga_mainmenu; + }, true, true); } void playSmk(const char *smk, const char *wav, int wavid, CompletionFunc func) diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 5527dfd73..b63803baa 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -506,7 +506,6 @@ bool GameInterface::LoadGame(FSaveGameNode* node) viewSetErrorMessage(""); Net_ClearFifo(); paused = 0; - gamestate = GS_LEVEL; bVanilla = false; diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index ba3f37b43..9984a033e 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1179,15 +1179,6 @@ CCMD(taunt) // //--------------------------------------------------------------------------- -void startmainmenu() -{ - gamestate = GS_MENUSCREEN; - M_StartControlPanel(false); - M_SetMenu(NAME_Mainmenu); - FX_StopAllSounds(); -} - - void GameInterface::FreeLevelData() { // Make sure that there is no more level to toy around with. diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 91d97baf2..13d96e031 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -55,7 +55,6 @@ extern FStringCVar* const CombatMacros[]; void CONFIG_ReadCombatMacros(); int GameMain(); -void startmainmenu(); int GetAutomapZoom(int gZoom); void DrawCrosshair(int deftile, int health, double xdelta, double scale, PalEntry color = 0xffffffff); void updatePauseStatus(); diff --git a/source/core/gamestate.h b/source/core/gamestate.h index a09c986c6..a18921542 100644 --- a/source/core/gamestate.h +++ b/source/core/gamestate.h @@ -24,8 +24,13 @@ enum gamestate_t : int enum gameaction_t : int { ga_nothing, + ga_level, // Switch to play mode without any initialization + ga_intro, + ga_intermission, + ga_startup, // go back to intro after uninitializing the game state ga_mainmenu, // go back to main menu after uninitializing the game state + ga_mainmenunostopsound, // Same but doesn't stop playing sounds. ga_creditsmenu, // go to the credits menu after uninitializing the game state ga_newgame, // start a new game ga_recordgame, // start a new demo recording (later) diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index f09c1ee5e..263c243a3 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -140,6 +140,7 @@ static void GameTicker() FX_SetReverb(0); gi->FreeLevelData(); C_ClearMessages(); + gameaction = ga_level; gi->NewGame(g_nextmap, -1); break; @@ -150,16 +151,19 @@ static void GameTicker() { // if the same level is restarted, skip any progression stuff like summary screens or cutscenes. gi->FreeLevelData(); - gamestate = GS_LEVEL; + gameaction = ga_level; gi->NextLevel(g_nextmap, g_nextskill); } else + { gi->LevelCompleted(g_nextmap, g_nextskill); + assert(gameaction != ga_nothing); + } break; case ga_nextlevel: gi->FreeLevelData(); - gamestate = GS_LEVEL; + gameaction = ga_level; gi->NextLevel(g_nextmap, g_nextskill); break; @@ -168,23 +172,32 @@ static void GameTicker() FX_SetReverb(0); gi->FreeLevelData(); C_ClearMessages(); - gamestate = GS_LEVEL; + gameaction = ga_level; gi->NewGame(g_nextmap, g_nextskill); break; case ga_startup: + Mus_Stop(); + FX_StopAllSounds(); gi->FreeLevelData(); gamestate = GS_STARTUP; break; case ga_mainmenu: + FX_StopAllSounds(); + case ga_mainmenunostopsound: gi->FreeLevelData(); - startmainmenu(); + gamestate = GS_MENUSCREEN; + M_StartControlPanel(false); + M_SetMenu(NAME_Mainmenu); break; case ga_creditsmenu: + FX_StopAllSounds(); gi->FreeLevelData(); - startmainmenu(); + gamestate = GS_MENUSCREEN; + M_StartControlPanel(false); + M_SetMenu(NAME_Mainmenu); M_SetMenu(NAME_CreditsMenu); break; @@ -194,7 +207,19 @@ static void GameTicker() break; case ga_autosave: - M_Autosave(); + if (gamestate == GS_LEVEL) M_Autosave(); + break; + + case ga_level: + gamestate = GS_LEVEL; + break; + + case ga_intro: + gamestate = GS_INTRO; + break; + + case ga_intermission: + gamestate = GS_INTERMISSION; break; // for later diff --git a/source/core/menu/savegamemanager.cpp b/source/core/menu/savegamemanager.cpp index 8fc642e16..396102c15 100644 --- a/source/core/menu/savegamemanager.cpp +++ b/source/core/menu/savegamemanager.cpp @@ -66,7 +66,7 @@ void FSavegameManager::LoadGame(FSaveGameNode* node) { if (gi->LoadGame(node)) { - gamestate = GS_LEVEL; + gameaction = ga_level; } else { diff --git a/source/core/screenjob.cpp b/source/core/screenjob.cpp index 6a9765b64..82ccf0589 100644 --- a/source/core/screenjob.cpp +++ b/source/core/screenjob.cpp @@ -729,7 +729,11 @@ void RunScreenJob(JobDesc* jobs, int count, CompletionFunc completion, bool clea if (count) { runner = new ScreenJobRunner(jobs, count, completion, clearbefore); - gamestate = blockingui? GS_INTRO : GS_INTERMISSION; + gameaction = blockingui? ga_intro : ga_intermission; + } + else + { + completion(false); } } diff --git a/source/exhumed/src/2d.cpp b/source/exhumed/src/2d.cpp index d634287c2..6a48fcdcc 100644 --- a/source/exhumed/src/2d.cpp +++ b/source/exhumed/src/2d.cpp @@ -1283,7 +1283,7 @@ void DoGameOverScene(bool finallevel) PlayGameOverSound(); job = { Create(tileGetTexture(kTile3591), DScreenJob::fadein | DScreenJob::fadeout, 0x7fffffff) }; } - RunScreenJob(&job, 1, [](bool) { gamestate = GS_STARTUP; }); + RunScreenJob(&job, 1, [](bool) { gameaction = ga_startup; }); } diff --git a/source/exhumed/src/gameloop.cpp b/source/exhumed/src/gameloop.cpp index 2597bf1a7..f23d5be5e 100644 --- a/source/exhumed/src/gameloop.cpp +++ b/source/exhumed/src/gameloop.cpp @@ -221,7 +221,7 @@ void GameInterface::NewGame(MapRecord *map, int skill) void GameInterface::LevelCompleted(MapRecord *map, int skill) { - if (currentLevel->levelNumber == 0) startmainmenu(); + if (currentLevel->levelNumber == 0) gameaction = ga_mainmenu; else Intermission(currentLevel, map); } @@ -247,8 +247,8 @@ void GameInterface::Startup() } else { - if (!userConfig.nologo) DoTitle([](bool) { startmainmenu(); }); - else startmainmenu(); + if (!userConfig.nologo) DoTitle([](bool) { gameaction = ga_mainmenu; }); + else gameaction = ga_mainmenu; } } diff --git a/source/games/duke/src/2d_r.cpp b/source/games/duke/src/2d_r.cpp index 95f546746..92e39f3a7 100644 --- a/source/games/duke/src/2d_r.cpp +++ b/source/games/duke/src/2d_r.cpp @@ -640,56 +640,5 @@ void PrintLevelName_r(double alpha) BigText(160, 114, currentLevel->DisplayName(), 0, alpha); } -// Utility for testing the above screens -CCMD(testrscreen) -{ - JobDesc jobs[10]; - int job = 0; - C_HideConsole(); - FX_StopAllSounds(); - Mus_Stop(); - - auto gs = gamestate; - auto completion = [=](bool) - { - if (gs == GS_LEVEL || gs == GS_MENUSCREEN) gamestate = gs; - else gamestate = GS_STARTUP; - }; - - if (argv.argc() > 1) - { - int screen = strtol(argv[1], nullptr, 0); - switch (screen) - { - case 0: - case 1: - if (!isRRRA()) - { - bonussequence_r(screen, jobs, job); - RunScreenJob(jobs, job, completion); - } - break; - - case 2: - jobs[job++] = { Create(6) }; - RunScreenJob(jobs, job, completion); - break; - - case 3: - jobs[job++] = { Create() }; - RunScreenJob(jobs, job, completion); - break; - - case 4: - jobs[job++] = { Create() }; - RunScreenJob(jobs, job, completion); - break; - - default: - break; - } - } -} - END_DUKE_NS diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 282d296ac..5e9a381ba 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -133,8 +133,8 @@ void GameInterface::Startup() } else { - if (!userConfig.nologo) fi.ShowLogo([](bool) { startmainmenu(); }); - else startmainmenu(); + if (!userConfig.nologo) fi.ShowLogo([](bool) { gameaction = ga_mainmenu; }); + else gameaction = ga_mainmenu; } } diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index bde70e2d7..2694241bb 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -1017,7 +1017,7 @@ void startnewgame(MapRecord* map, int skill) { if (enterlevel(map, 0)) { - startmainmenu(); + gameaction = ga_mainmenu; } else { @@ -1025,7 +1025,7 @@ void startnewgame(MapRecord* map, int skill) setlocalplayerinput(&ps[myconnectindex]); PlayerColorChanged(); inputState.ClearAllInput(); - gamestate = GS_LEVEL; + gameaction = ga_level; } }); } @@ -1087,7 +1087,7 @@ void exitlevel(MapRecord *nextlevel) // Clear potentially loaded per-map ART only after the bonus screens. artClearMapArt(); - gamestate = GS_LEVEL; + gameaction = ga_level; if (endofgame) { if (ud.multimode < 2) diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 990fa4c45..a3f69fc59 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -486,7 +486,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) if (arc.isReading()) { screenpeek = myconnectindex; - gamestate = GS_LEVEL; ud.recstat = 0; ud.m_player_skill = ud.player_skill; diff --git a/source/sw/src/d_menu.cpp b/source/sw/src/d_menu.cpp index 938ff6929..639194bfa 100644 --- a/source/sw/src/d_menu.cpp +++ b/source/sw/src/d_menu.cpp @@ -149,11 +149,7 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double xpos, doub void GameInterface::QuitToTitle() { Mus_Stop(); - TerminateLevel(); - currentLevel = nullptr; - M_StartControlPanel(false); - M_SetMenu(NAME_Mainmenu); - gamestate = GS_MENUSCREEN; + gameaction = ga_mainmenu; } diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 887b65227..8677365af 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -678,9 +678,7 @@ void GameInterface::Startup() { if (!userConfig.nologo) Logo([](bool) { - gamestate = GS_MENUSCREEN; - M_StartControlPanel(false); - M_SetMenu(NAME_Mainmenu); + gameaction = ga_mainmenunostopsound; }); else gameaction = ga_mainmenu; }