From 61f5247b71a097999cc4cbac2fa7b1875e31c3a8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Jul 2020 22:46:26 +0200 Subject: [PATCH] -let's hope this will solve the pausing problem for good. The checks for game pause were totally inconsistent, so now there is a utility function that tells whether the game is supposed to run or not. pause can also take 3 values now - 0 for no pause, 1 for pause from opening the menu or console or 2 for hitting the pause button. --- source/core/gamecontrol.cpp | 11 ++++++----- source/core/gamecontrol.h | 1 + source/games/duke/src/constants.h | 1 - source/games/duke/src/d_menu.cpp | 7 ------- source/games/duke/src/game.cpp | 3 ++- source/games/duke/src/game_misc.cpp | 24 ++++++++++-------------- source/games/duke/src/gameexec.cpp | 1 - source/games/duke/src/gameloop.cpp | 17 ++++++++++------- source/games/duke/src/inlines.h | 8 ++++++-- source/games/duke/src/input.cpp | 1 - source/games/duke/src/render.cpp | 6 +++--- source/games/duke/src/savegame.cpp | 2 ++ source/games/duke/src/sounds.cpp | 2 +- 13 files changed, 41 insertions(+), 43 deletions(-) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 4f4e8fd0f..199359eb2 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1103,11 +1103,12 @@ bool CheckCheatmode(bool printmsg) void updatePauseStatus() { bool GUICapture = System_WantGuiCapture(); - if ( GUICapture) + if (M_Active() || ConsoleState != c_up) { paused = 1; + return; } - else if ((!M_Active() || !GUICapture) && !pausedWithKey) + else if (!pausedWithKey) { paused = 0; } @@ -1115,7 +1116,7 @@ void updatePauseStatus() if (inputState.GetKeyStatus(sc_Pause)) { inputState.ClearKeyStatus(sc_Pause); - paused = !paused; + paused = pausedWithKey ? 0 : 2; if (paused) { @@ -1123,10 +1124,10 @@ void updatePauseStatus() } else { - S_ResumeSound(paused); + S_ResumeSound(!!paused); } - pausedWithKey = paused; + pausedWithKey = !!paused; } } diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 8e99d26b7..6a3894d2d 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -202,6 +202,7 @@ enum PAUSESFX_CONSOLE = 2 }; +bool UIActive(); void updatePauseStatus(); void updatePauseStatus(bool state, bool multiplayer); extern int paused; diff --git a/source/games/duke/src/constants.h b/source/games/duke/src/constants.h index 7e07cb55f..2deb53c85 100644 --- a/source/games/duke/src/constants.h +++ b/source/games/duke/src/constants.h @@ -483,7 +483,6 @@ enum EFlamethrowerState }; enum gamemode_t { - MODE_MENU = 0x00000001, MODE_DEMO = 0x00000002, MODE_GAME = 0x00000004, MODE_EOL = 0x00000008, diff --git a/source/games/duke/src/d_menu.cpp b/source/games/duke/src/d_menu.cpp index cf8ba2426..f7e409474 100644 --- a/source/games/duke/src/d_menu.cpp +++ b/source/games/duke/src/d_menu.cpp @@ -221,12 +221,6 @@ void GameInterface::MenuOpened() totalclock = ototalclock; screenpeek = myconnectindex; } - - auto& gm = ps[myconnectindex].gm; - if (gm & MODE_GAME) - { - gm |= MODE_MENU; - } } void GameInterface::MenuSound(EMenuSounds snd) @@ -260,7 +254,6 @@ void GameInterface::MenuClosed() if (gm & MODE_GAME) { // The following lines are here so that you cannot close the menu when no game is running. - gm &= ~MODE_MENU; if (ud.multimode < 2 && ud.recstat != 2) { diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 671fae7fb..abfd9937f 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -40,6 +40,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "i_interface.h" #include "prediction.h" #include "glbackend/glbackend.h" +#include "gamestate.h" BEGIN_DUKE_NS @@ -282,7 +283,7 @@ static void ticker(void) S_Update(); // we need CONTROL_GetInput in order to pick up joystick button presses - if (!(ps[myconnectindex].gm & MODE_GAME) || (paused && !System_WantGuiCapture())) + if (gamestate != GS_LEVEL || (paused && !System_WantGuiCapture())) { ControlInfo noshareinfo; CONTROL_GetInput(&noshareinfo); diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index d14eaed41..657e4a072 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -174,17 +174,13 @@ void FTA(int q, struct player_struct* p) void drawbackground(void) { - if ((ps[myconnectindex].gm & MODE_GAME) == 0 && ud.recstat != 2) - { - twod->ClearScreen(); - auto tex = tileGetTexture(TILE_MENUSCREEN); - PalEntry color = 0xff808080; - if (!hud_bgstretch) - DrawTexture(twod, tex, 0, 0, DTA_FullscreenEx, 3, DTA_Color, color, TAG_DONE); - else - DrawTexture(twod, tex, 0, 0, DTA_VirtualWidth, twod->GetWidth(), DTA_VirtualHeight, twod->GetHeight(), DTA_KeepRatio, true, DTA_Color, color, TAG_DONE); - return; - } + twod->ClearScreen(); + auto tex = tileGetTexture(TILE_MENUSCREEN); + PalEntry color = 0xff808080; + if (!hud_bgstretch) + DrawTexture(twod, tex, 0, 0, DTA_FullscreenEx, 3, DTA_Color, color, TAG_DONE); + else + DrawTexture(twod, tex, 0, 0, DTA_VirtualWidth, twod->GetWidth(), DTA_VirtualHeight, twod->GetHeight(), DTA_KeepRatio, true, DTA_Color, color, TAG_DONE); } //--------------------------------------------------------------------------- @@ -304,7 +300,7 @@ void displayrest(int smoothratio) if (ud.scrollmode == 0) { - if (pp->newowner == -1 && !paused) + if (pp->newowner == -1 && playrunning()) { if (screenpeek == myconnectindex && numplayers > 1) { @@ -328,7 +324,7 @@ void displayrest(int smoothratio) } else { - if (!paused) + if (playrunning()) { ud.fola += ud.folavel >> 3; ud.folx += (ud.folfvel * sintable[(512 + 2048 - ud.fola) & 2047]) >> 14; @@ -371,7 +367,7 @@ void displayrest(int smoothratio) } } - if (paused == 1 && (ps[myconnectindex].gm & MODE_MENU) == 0) + if (paused == 2) fi.PrintPaused(); } diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 02e62518c..4b8e635ce 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -961,7 +961,6 @@ int ParseState::parse(void) #if 0 if( lastsavedpos >= 0 && ud.recstat != 2 ) { - ps[g_p].gm = MODE_MENU; KB_ClearKeyDown(sc_Space); cmenu(15000); } diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index 2b25fc9b1..4229a2a59 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -233,7 +233,7 @@ int domovethings() //if(ud.recstat == 1) record(); - if (paused == 0) + if (playrunning()) { global_random = krand(); movedummyplayers();//ST 13 @@ -241,7 +241,7 @@ int domovethings() for (i = connecthead; i >= 0; i = connectpoint2[i]) { - if (paused == 0) + if (playrunning()) { auto p = &ps[i]; if (p->pals.a > 0) @@ -253,7 +253,7 @@ int domovethings() } } - if (paused == 0) + if (playrunning()) { if (levelTextTime > 0) levelTextTime--; @@ -317,12 +317,11 @@ bool GameTicker() gameupdatetime.Reset(); gameupdatetime.Clock(); - while ((!(ps[myconnectindex].gm & (MODE_MENU | MODE_DEMO))) && (int)(totalclock - ototalclock) >= TICSPERFRAME) + while (playrunning() && (int)(totalclock - ototalclock) >= TICSPERFRAME) { ototalclock += TICSPERFRAME; GetInput(); - // this is where we fill the input_t struct that is actually processed by P_ProcessInput() auto const pPlayer = &ps[myconnectindex]; auto const q16ang = fix16_to_int(pPlayer->q16ang); auto& input = nextinput(myconnectindex); @@ -338,12 +337,15 @@ bool GameTicker() advancequeue(myconnectindex); - if (((!System_WantGuiCapture() && (ps[myconnectindex].gm & MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (ud.multimode > 1)) && - (ps[myconnectindex].gm & MODE_GAME)) + if (playrunning()) { moveloop(); } } + if (!playrunning()) + { + ototalclock = totalclock - 1; + } gameUpdate = true; gameupdatetime.Unclock(); @@ -394,6 +396,7 @@ void app_loop() while (true) { handleevents(); + updatePauseStatus(); switch (gamestate) { default: diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 9af66d1c9..47a1af372 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -164,10 +164,14 @@ inline void SetPlayerPal(player_struct* p, PalEntry pe) p->pals = pe; } +inline bool playrunning() +{ + return (paused == 0 || (paused == 1 && (ud.recstat == 2 || ud.multimode > 1))); +} + inline int calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk) { - if (!((ud.multimode < 2 && ((ps[myconnectindex].gm & MODE_MENU) == 0)) || - ud.multimode > 1 || ud.recstat == 2) || paused) + if (!playrunning()) { return 65536; } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 4d5071122..953660137 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -1227,7 +1227,6 @@ void GetInput() { double elapsedInputTicks; auto const p = &ps[myconnectindex]; - updatePauseStatus(); auto now = I_msTimeF(); // do not let this become too large - it would create overflows resulting in undefined behavior. The very first tic must not use the timer difference at all because the timer has not been set yet. diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 85d77d3e7..839d7db40 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -293,9 +293,9 @@ void animatecamsprite(int smoothRatio) void setdrugmode(player_struct *p, int oyrepeat) { - if (!paused) + if (playrunning()) { - if (p->DrugMode > 0 && !(p->gm & MODE_TYPE) && !paused) + if (p->DrugMode > 0 && !(p->gm & MODE_TYPE)) { int var_8c; if (p->drug_stat[0] == 0) @@ -491,7 +491,7 @@ void displayrooms(int snum, int smoothratio) videoSetCorrectedAspect(); smoothratio = min(max(smoothratio, 0), 65536); - if (paused || ps[snum].on_crane > -1) smoothratio = 65536; + if (!playrunning() || ps[snum].on_crane > -1) smoothratio = 65536; sect = p->cursectnum; if (sect < 0 || sect >= MAXSECTORS) return; diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 55c2a390d..83f728425 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -29,6 +29,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "serializer.h" #include "mapinfo.h" #include "duke3d.h" +#include "gamestate.h" BEGIN_DUKE_NS @@ -483,6 +484,7 @@ void GameInterface::SerializeGameState(FSerializer& arc) { screenpeek = myconnectindex; ps[myconnectindex].gm = MODE_GAME; + gamestate = GS_LEVEL; ud.recstat = 0; ud.m_player_skill = ud.player_skill; diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index bb03eadc5..6e04aadb1 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -375,7 +375,7 @@ void S_Update(void) int S_PlaySound3D(int sndnum, int spriteNum, const vec3_t* pos, int channel, EChanFlags flags) { auto const pl = &ps[myconnectindex]; - if (!soundEngine->isValidSoundId(sndnum+1) || !SoundEnabled() || (unsigned)spriteNum >= MAXSPRITES || (pl->gm & MODE_MENU) || + if (!soundEngine->isValidSoundId(sndnum+1) || !SoundEnabled() || (unsigned)spriteNum >= MAXSPRITES || !playrunning() || (pl->timebeforeexit > 0 && pl->timebeforeexit <= REALGAMETICSPERSEC * 3)) return -1; int userflags = S_GetUserFlags(sndnum);