From d7a47b2f3a2546bfe4299391d258b72454d41521 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 22 May 2021 13:02:34 +0200 Subject: [PATCH] - route all accesses to gameaction from the backend through the sysCallbacks. gameactions are frontend specific so this needs to be decoupled. --- source/common/console/c_console.cpp | 5 ++- source/common/cutscenes/screenjob.cpp | 3 +- source/common/engine/gamestate.h | 29 +++++++++++++++ source/common/engine/i_interface.h | 2 ++ source/core/console/d_event.cpp | 2 +- source/core/gamecontrol.cpp | 14 +++++++- source/core/gamecontrol.h | 27 ++++++++++++++ source/core/gamestate.h | 52 --------------------------- source/core/mainloop.cpp | 8 ++--- wadsrc/static/zscript/engine/base.zs | 11 +++--- 10 files changed, 87 insertions(+), 66 deletions(-) create mode 100644 source/common/engine/gamestate.h delete mode 100644 source/core/gamestate.h diff --git a/source/common/console/c_console.cpp b/source/common/console/c_console.cpp index 48c7b86de..5cafbb080 100644 --- a/source/common/console/c_console.cpp +++ b/source/common/console/c_console.cpp @@ -592,8 +592,7 @@ void C_DrawConsole () oldbottom = ConBottom; - if (ConsoleState == c_up && gamestate != GS_INTRO && gamestate != GS_INTERMISSION && - gamestate != GS_FULLCONSOLE && gamestate != GS_MENUSCREEN) + if (ConsoleState == c_up && gamestate == GS_LEVEL) { if (NotifyStrings) NotifyStrings->Draw(); return; @@ -731,7 +730,7 @@ void C_ToggleConsole () } if (gamestate == GS_MENUSCREEN) { - gameaction = ga_fullconsole; + if (sysCallbacks.ToggleFullConsole) sysCallbacks.ToggleFullConsole(); togglestate = c_down; } else if (!chatmodeon && (ConsoleState == c_up || ConsoleState == c_rising) && menuactive == MENU_Off) diff --git a/source/common/cutscenes/screenjob.cpp b/source/common/cutscenes/screenjob.cpp index b983c3e81..a3978298e 100644 --- a/source/common/cutscenes/screenjob.cpp +++ b/source/common/cutscenes/screenjob.cpp @@ -50,6 +50,7 @@ #include "c_dispatch.h" #include "s_music.h" #include "m_argv.h" +#include "i_interface.h" CVAR(Bool, inter_subtitles, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); @@ -316,7 +317,7 @@ bool StartCutscene(CutsceneDef& cs, int flags, const CompletionFunc& completion_ } if (flags & SJ_DELAY) intermissiondelay = 10; // need to wait a bit at the start to let the timer catch up. else intermissiondelay = 0; - gameaction = (flags & SJ_BLOCKUI) ? ga_intro : ga_intermission; + if (sysCallbacks.StartCutscene) sysCallbacks.StartCutscene(flags & SJ_BLOCKUI); } catch (...) { diff --git a/source/common/engine/gamestate.h b/source/common/engine/gamestate.h new file mode 100644 index 000000000..edea03a69 --- /dev/null +++ b/source/common/engine/gamestate.h @@ -0,0 +1,29 @@ +#pragma once + +// The current state of the game: whether we are +// playing, gazing at the intermission screen, +// the game final animation, or a demo. +enum gamestate_t : int +{ + GS_LEVEL, + GS_INTERMISSION, + GS_FINALE, + GS_DEMOSCREEN, + GS_FULLCONSOLE, // [RH] Fullscreen console + GS_HIDECONSOLE, // [RH] The menu just did something that should hide fs console + GS_STARTUP, // [RH] Console is fullscreen, and game is just starting + GS_TITLELEVEL, // [RH] A combination of GS_LEVEL and GS_DEMOSCREEN + GS_INTRO, + GS_CUTSCENE, + + GS_MENUSCREEN = GS_DEMOSCREEN, + + GS_FORCEWIPE = -1, + GS_FORCEWIPEFADE = -2, + GS_FORCEWIPEBURN = -3, + GS_FORCEWIPEMELT = -4 +}; + + +extern gamestate_t gamestate; +extern int intermissiondelay; diff --git a/source/common/engine/i_interface.h b/source/common/engine/i_interface.h index b66bfc67e..a8d0dbdee 100644 --- a/source/common/engine/i_interface.h +++ b/source/common/engine/i_interface.h @@ -32,6 +32,8 @@ struct SystemCallbacks void (*ConsoleToggled)(int state); bool (*PreBindTexture)(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader); void (*FontCharCreated)(FGameTexture* base, FGameTexture* untranslated, FGameTexture* translated); + void (*ToggleFullConsole)(); + void (*StartCutscene)(bool blockui); }; extern SystemCallbacks sysCallbacks; diff --git a/source/core/console/d_event.cpp b/source/core/console/d_event.cpp index 007d0c46d..35cabc841 100644 --- a/source/core/console/d_event.cpp +++ b/source/core/console/d_event.cpp @@ -54,7 +54,7 @@ bool G_Responder (event_t *ev) { - if (gamestate == GS_INTRO || gamestate == GS_INTERMISSION) + if (gamestate == GS_INTRO || gamestate == GS_CUTSCENE) { return ScreenJobResponder(ev); } diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index e4539ce5a..e831f8897 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -511,6 +511,16 @@ void CheckFrontend(int flags) } } +static void System_ToggleFullConsole() +{ + gameaction = ga_fullconsole; +} + +static void System_StartCutscene(bool blockui) +{ + gameaction = blockui ? ga_intro : ga_intermission; +} + void I_StartupJoysticks(); void I_ShutdownInput(); int RunGame(); @@ -545,7 +555,9 @@ int GameMain() nullptr, nullptr, PreBindTexture, - FontCharCreated + FontCharCreated, + System_ToggleFullConsole, + System_StartCutscene, }; try diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 9b07c862f..67317518f 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -220,3 +220,30 @@ extern int lastTic; extern int PlayClock; +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) + ga_loadgame, // load a savegame and resume play. + ga_loadgameplaydemo, // load a savegame and play a demo. + ga_autoloadgame, // load last autosave and resume play. + ga_savegame, // save the game + ga_autosave, // autosave the game (for triggering a save from within the game.) + ga_completed, // Level was exited. + ga_nextlevel, // Actually start the next level. + ga_loadgamehidecon, + ga_newgamenostopsound, // start a new game + ga_endscreenjob, + + ga_fullconsole, +}; +extern gameaction_t gameaction; diff --git a/source/core/gamestate.h b/source/core/gamestate.h deleted file mode 100644 index 431eac31c..000000000 --- a/source/core/gamestate.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -// The current state of the game: whether we are -// playing, gazing at the intermission screen, -// the game final animation, or a demo. -enum gamestate_t : int -{ - GS_LEVEL, - GS_INTRO, - GS_INTERMISSION, - GS_FINALE, - GS_MENUSCREEN, - GS_FULLCONSOLE, // [RH] Fullscreen console - GS_HIDECONSOLE, // [RH] The menu just did something that should hide fs console - GS_STARTUP, // [RH] Console is fullscreen, and game is just starting - GS_TITLELEVEL, // [RH] A combination of GS_LEVEL and GS_MENUSCREEN - - GS_FORCEWIPE = -1, - GS_FORCEWIPEFADE = -2, - GS_FORCEWIPEBURN = -3, - GS_FORCEWIPEMELT = -4 -}; - -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) - ga_loadgame, // load a savegame and resume play. - ga_loadgameplaydemo, // load a savegame and play a demo. - ga_autoloadgame, // load last autosave and resume play. - ga_savegame, // save the game - ga_autosave, // autosave the game (for triggering a save from within the game.) - ga_completed, // Level was exited. - ga_nextlevel, // Actually start the next level. - ga_loadgamehidecon, - ga_newgamenostopsound, // start a new game - ga_endscreenjob, - - ga_fullconsole, -}; -extern gamestate_t gamestate; -extern gameaction_t gameaction; -extern int intermissiondelay; diff --git a/source/core/mainloop.cpp b/source/core/mainloop.cpp index 7ea245007..24e1c65fd 100644 --- a/source/core/mainloop.cpp +++ b/source/core/mainloop.cpp @@ -280,7 +280,7 @@ static void GameTicker() break; case ga_intermission: - gamestate = GS_INTERMISSION; + gamestate = GS_CUTSCENE; break; case ga_fullconsole: @@ -370,7 +370,7 @@ static void GameTicker() case GS_MENUSCREEN: case GS_FULLCONSOLE: break; - case GS_INTERMISSION: + case GS_CUTSCENE: case GS_INTRO: if (intermissiondelay > 0) { @@ -419,7 +419,7 @@ void Display() break; case GS_INTRO: - case GS_INTERMISSION: + case GS_CUTSCENE: // screen jobs are not bound by the game ticker so they need to be ticked in the display loop. if (intermissiondelay <= 0) ScreenJobDraw(); break; @@ -515,7 +515,7 @@ void TryRunTics (void) // If paused, do not eat more CPU time than we need, because it // will all be wasted anyway. - bool doWait = (cl_capfps || pauseext || (r_NoInterpolate && !M_IsAnimated() && gamestate != GS_INTERMISSION && gamestate != GS_INTRO)); + bool doWait = (cl_capfps || pauseext || (r_NoInterpolate && !M_IsAnimated() && gamestate != GS_CUTSCENE && gamestate != GS_INTRO)); // get real tics if (doWait) diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 53b87e9ed..0937cd93c 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -76,11 +76,14 @@ enum EGameState GS_INTERMISSION, GS_FINALE, GS_DEMOSCREEN, + GS_FULLCONSOLE, // [RH] Fullscreen console + GS_HIDECONSOLE, // [RH] The menu just did something that should hide fs console + GS_STARTUP, // [RH] Console is fullscreen, and game is just starting + GS_TITLELEVEL, // [RH] A combination of GS_LEVEL and GS_DEMOSCREEN + GS_INTRO, + GS_CUTSCENE, + GS_MENUSCREEN = GS_DEMOSCREEN, - GS_FULLCONSOLE, - GS_HIDECONSOLE, - GS_STARTUP, - GS_TITLELEVEL, } const TEXTCOLOR_BRICK = "\034A";