From daa862240d2794fe7b2789cb0e76e3b8523a8a6d Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 29 May 2020 11:20:40 +1000 Subject: [PATCH] Blood: Amend how game pauses. --- source/blood/src/blood.cpp | 10 ++++------ source/blood/src/blood.h | 1 - source/blood/src/controls.cpp | 33 +++++++++++++++++++-------------- source/blood/src/loadsave.cpp | 6 +++--- source/blood/src/view.cpp | 4 ++-- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 180c04048..fe6ba1829 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -104,7 +104,6 @@ double g_gameUpdateAvgTime = 0.001; bool gQuitGame; int gQuitRequest; -bool gPaused; enum gametokens { @@ -663,7 +662,7 @@ void StartLevel(GAMEOPTIONS *gameOptions) gGameMessageMgr.SetCoordinates(gViewX0S+1,gViewY0S+15); netWaitForEveryone(0); totalclock = 0; - gPaused = 0; + paused = 0; gGameStarted = 1; ready2send = 1; } @@ -823,8 +822,7 @@ void ProcessFrame(void) if (gPlayer[i].input.keyFlags.pause) { gPlayer[i].input.keyFlags.pause = 0; - gPaused = !gPaused; - if (gPaused && gGameOptions.nGameType > 0 && numplayers > 1) + if (paused && gGameOptions.nGameType > 0 && numplayers > 1) { sprintf(buffer,"%s paused the game",gProfile[i].name); viewSetMessage(buffer); @@ -834,7 +832,7 @@ void ProcessFrame(void) viewClearInterpolations(); if (!gDemo.at1) { - if (gPaused || gEndGameMgr.at0 || (gGameOptions.nGameType == 0 && M_Active())) + if (paused || gEndGameMgr.at0 || (gGameOptions.nGameType == 0 && M_Active())) return; if (gDemo.at0) gDemo.Write(gFifoInput[(gNetFifoTail-1)&255]); @@ -1214,7 +1212,7 @@ RESTART: { char gameUpdate = false; double const gameUpdateStartTime = timerGetHiTicks(); - while (gPredictTail < gNetFifoHead[myconnectindex] && !gPaused) + while (gPredictTail < gNetFifoHead[myconnectindex] && !paused) { viewUpdatePrediction(&gFifoInput[gPredictTail&255][myconnectindex]); } diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index e01449c1f..75cd1cfc2 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -121,7 +121,6 @@ extern double g_gameUpdateTime, g_gameUpdateAndDrawTime; extern double g_gameUpdateAvgTime; extern int blood_globalflags; -extern bool gPaused; extern bool gSavingGame; extern bool gQuitGame; extern int gQuitRequest; diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 6a245c23e..9c78f6c48 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -78,8 +78,17 @@ int gViewLookRecenter; void ctrlGetInput(void) { + int prevPauseState = paused; ControlInfo info; + static double lastInputTicks; + auto const currentHiTicks = timerGetHiTicks(); + double const elapsedInputTicks = currentHiTicks - lastInputTicks; + + lastInputTicks = currentHiTicks; + + auto scaleAdjustmentToInterval = [=](double x) { return x * kTicsPerSec / (1000.0 / elapsedInputTicks); }; + if (!gGameStarted || gInputMode != kInputGame) { gInput = {}; @@ -87,14 +96,16 @@ void ctrlGetInput(void) return; } + updatePauseStatus(); + if (paused != prevPauseState) + { + gInput.keyFlags.pause = 1; + } + + if (paused) + return; + GINPUT input = {}; - static double lastInputTicks; - auto const currentHiTicks = timerGetHiTicks(); - double const elapsedInputTicks = currentHiTicks - lastInputTicks; - - lastInputTicks = currentHiTicks; - - auto scaleAdjustmentToInterval = [=](double x) { return x * kTicsPerSec / (1000.0 / elapsedInputTicks); }; D_ProcessEvents(); @@ -366,12 +377,6 @@ void ctrlGetInput(void) if (!in_mouseflip) input.q16mlook = -input.q16mlook; - if (inputState.GetKeyStatus(sc_Pause)) // 0xc5 in disassembly - { - gInput.keyFlags.pause = 1; - inputState.ClearKeyStatus(sc_Pause); - } - if (!gViewMap.bFollowMode && gViewMode == 4) { gViewMap.turn += input.q16turn<<2; @@ -385,7 +390,7 @@ void ctrlGetInput(void) gInput.strafe = clamp(gInput.strafe + input.strafe, -2048, 2048); gInput.q16turn = fix16_sadd(gInput.q16turn, input.q16turn); gInput.q16mlook = fix16_clamp(fix16_sadd(gInput.q16mlook, input.q16mlook), fix16_from_int(-127)>>2, fix16_from_int(127)>>2); - if (gMe && gMe->pXSprite->health != 0 && !gPaused) + if (gMe && gMe->pXSprite->health != 0 && !paused) { int upAngle = 289; int downAngle = -347; diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 7d2229ea2..a6abbd752 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -561,7 +561,7 @@ bool GameInterface::LoadGame(FSaveGameNode* node) gFrame = 0; gFrameRate = 0; totalclock = 0; - gPaused = 0; + paused = 0; gGameStarted = 1; bVanilla = false; @@ -662,7 +662,7 @@ void MyLoadSave::Load(void) Read(&totalclock, sizeof(totalclock)); totalclock = nGameClock; Read(&gLevelTime, sizeof(gLevelTime)); - Read(&gPaused, sizeof(gPaused)); + Read(&paused, sizeof(paused)); Read(baseWall, sizeof(baseWall[0])*numwalls); Read(baseSprite, sizeof(baseSprite[0])*nNumSprites); Read(baseFloor, sizeof(baseFloor[0])*numsectors); @@ -755,7 +755,7 @@ void MyLoadSave::Save(void) ClockTicks nGameClock = totalclock; Write(&nGameClock, sizeof(nGameClock)); Write(&gLevelTime, sizeof(gLevelTime)); - Write(&gPaused, sizeof(gPaused)); + Write(&paused, sizeof(paused)); Write(baseWall, sizeof(baseWall[0])*numwalls); Write(baseSprite, sizeof(baseSprite[0])*nNumSprites); Write(baseFloor, sizeof(baseFloor[0])*numsectors); diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index 9ce0f2444..0cd46ce6b 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -3088,7 +3088,7 @@ void viewDrawScreen(bool sceneonly) if (delta < 0) delta = 0; lastUpdate = totalclock; - if (!gPaused && (!M_Active() || gGameOptions.nGameType != 0)) + if (!paused && (!M_Active() || gGameOptions.nGameType != 0)) { gInterpolate = ((totalclock-gNetFifoClock)+4).toScale16()/4; } @@ -3558,7 +3558,7 @@ void viewDrawScreen(bool sceneonly) viewDrawMapTitle(); viewDrawAimedPlayerName(); - if (gPaused) + if (paused) { viewDrawText(1, GStrings("TXTB_PAUSED"), 160, 10, 0, 0, 1, 0); }