From d358c71f827a9eab124ff82fc37d59c8db336d38 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 26 Aug 2020 09:10:14 +1000 Subject: [PATCH] - Blood: Migrate to GZDoom time code like Duke, SW and Exhumed. --- source/blood/src/animatesprite.cpp | 6 +++--- source/blood/src/blood.cpp | 15 ++++++++++----- source/blood/src/choke.cpp | 8 ++++---- source/blood/src/controls.cpp | 6 +++--- source/blood/src/d_menu.cpp | 11 ++++++----- source/blood/src/endgame.cpp | 2 +- source/blood/src/fire.cpp | 4 ++-- source/blood/src/globals.cpp | 2 ++ source/blood/src/globals.h | 2 ++ source/blood/src/loadsave.cpp | 7 ++++--- source/blood/src/network.cpp | 3 ++- source/blood/src/nnexts.cpp | 4 ++-- source/blood/src/sbar.cpp | 12 ++++++------ source/blood/src/sectorfx.cpp | 2 +- source/blood/src/sfx.cpp | 2 +- source/blood/src/view.cpp | 22 +++++++++++----------- source/blood/src/weapon.cpp | 4 ++-- 17 files changed, 62 insertions(+), 50 deletions(-) diff --git a/source/blood/src/animatesprite.cpp b/source/blood/src/animatesprite.cpp index 0ebf6a4a1..656b32319 100644 --- a/source/blood/src/animatesprite.cpp +++ b/source/blood/src/animatesprite.cpp @@ -559,7 +559,7 @@ void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t) pTSprite->picnum = voxelIndex[pTSprite->picnum]; if ((picanm[nTile].extra&7) == 7) { - pTSprite->ang = ((int)totalclock<<3)&2047; + pTSprite->ang = (gameclock<<3)&2047; } } } @@ -588,7 +588,7 @@ void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t) int const nVoxel = tiletovox[pTSprite->picnum]; if (nVoxel != -1 && ((voxrotate[nVoxel>>3]&pow2char[nVoxel&7]) != 0 || (picanm[nRootTile].extra&7) == 7)) - pTSprite->ang = (pTSprite->ang+((int)totalclock<<3))&2047; + pTSprite->ang = (pTSprite->ang+(gameclock<<3))&2047; } if ((pTSprite->cstat&48) != 48 && hw_models && !(spriteext[nSprite].flags&SPREXT_NOTMD)) @@ -603,7 +603,7 @@ void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t) pTSprite->xoffset += tileLeftOffset(nAnimTile); if ((picanm[nRootTile].extra&7) == 7) - pTSprite->ang = (pTSprite->ang+((int)totalclock<<3))&2047; + pTSprite->ang = (pTSprite->ang+(gameclock<<3))&2047; } } diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 5dca2a61b..e91c18105 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -320,7 +320,6 @@ void PreloadTiles(void) void PreloadCache(void) { PreloadTiles(); - ClockTicks clock = totalclock; int cnt = 0; int percentDisplayed = -1; @@ -511,7 +510,8 @@ void StartLevel(MapRecord *level) // viewSetMessage(""); viewSetErrorMessage(""); netWaitForEveryone(0); - totalclock = 0; + gameclock = 0; + lastTic = -1; paused = 0; ready2send = 1; levelTryPlayMusic(); @@ -791,12 +791,17 @@ static void gameTicker() } if (numplayers == 1) gBufferJitter = 0; - while (totalclock >= gNetFifoClock && ready2send) + + int const currentTic = I_GetTime(); + gameclock = I_GetBuildTime(); + + while (currentTic - lastTic >= 1 && ready2send) { gNetInput = gInput; gInput = {}; netGetInput(); - gNetFifoClock += 4; + lastTic = currentTic; + gNetFifoClock = gameclock; while (gNetFifoHead[myconnectindex] - gNetFifoTail > gBufferJitter && !gStartNewGame && !gQuitGame) { int i; @@ -849,7 +854,7 @@ static void commonTicker() auto completion = [=](bool = false) { StartLevel(sng); - gNetFifoClock = gFrameClock = totalclock; + gNetFifoClock = gFrameClock = gameclock; gamestate = GS_LEVEL; }; diff --git a/source/blood/src/choke.cpp b/source/blood/src/choke.cpp index c2b44ee11..6f05d25ea 100644 --- a/source/blood/src/choke.cpp +++ b/source/blood/src/choke.cpp @@ -57,11 +57,11 @@ void CChoke::sub_84110(int x, int y) if (!at8) return; ClockTicks v4 = gFrameClock; - gFrameClock = totalclock; + gFrameClock = gameclock; at8->x = x; at8->y = y; - int vd = (int)totalclock-at10; - at10 = (int)totalclock; + int vd = gameclock-at10; + at10 = gameclock; atc -= vd; if (atc <= 0 || atc > at8->at10) atc = at8->at10; @@ -76,7 +76,7 @@ void CChoke::sub_84110(int x, int y) void CChoke::sub_84218() { atc = at8->at10; - at10 = (int)totalclock; + at10 = gameclock; } void sub_84230(PLAYER *pPlayer) diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 023fe8961..94fdcfa53 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -60,7 +60,7 @@ int32_t mouseyaxismode = -1; int32_t GetTime(void) { - return (int32_t)totalclock; + return gameclock; } fix16_t gViewLook, gViewAngle; @@ -262,13 +262,13 @@ void ctrlGetInput(void) static int32_t turnHeldTime; static int32_t lastInputClock; // MED - int32_t const elapsedTics = (int32_t)totalclock - lastInputClock; + int32_t const elapsedTics = gameclock - lastInputClock; // Blood's q16mlook scaling is different from the other games, therefore use the below constant to attenuate // the speed to match the other games. float const mlookScale = 3.25f; - lastInputClock = (int32_t) totalclock; + lastInputClock = gameclock; if (turnLeft || turnRight) turnHeldTime += elapsedTics; diff --git a/source/blood/src/d_menu.cpp b/source/blood/src/d_menu.cpp index ef1d93710..751537b19 100644 --- a/source/blood/src/d_menu.cpp +++ b/source/blood/src/d_menu.cpp @@ -73,7 +73,7 @@ CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widesc data->y = m_nY; data->Preload(); at2c = data->at10; - lastTick = (int)totalclock; + lastTick = I_GetBuildTime(); } } } @@ -87,9 +87,10 @@ void CGameMenuItemQAV::Draw(void) { auto data = (QAV*)raw.Data(); ClockTicks backFC = gFrameClock; - gFrameClock = totalclock; - int nTicks = (int)totalclock - lastTick; - lastTick = (int)totalclock; + int currentclock = I_GetBuildTime(); + gFrameClock = currentclock; + int nTicks = currentclock - lastTick; + lastTick = currentclock; at2c -= nTicks; if (at2c <= 0 || at2c > data->at10) { @@ -207,7 +208,7 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double xpos, doub if (!text) return; int shade = (state != NIT_InactiveState) ? 32 : 48; int pal = (state != NIT_InactiveState) ? 5 : 5; - if (state == NIT_SelectedState) shade = 32 - ((int)totalclock & 63); + if (state == NIT_SelectedState) shade = 32 - (I_GetBuildTime() & 63); auto gamefont = fontnum == NIT_BigFont ? BigFont : fontnum == NIT_SmallFont ? SmallFont : SmallFont2; if (flags & LMF_Centered) diff --git a/source/blood/src/endgame.cpp b/source/blood/src/endgame.cpp index 83fc22494..4c54f1e4f 100644 --- a/source/blood/src/endgame.cpp +++ b/source/blood/src/endgame.cpp @@ -112,7 +112,7 @@ void CEndGameMgr::Draw(void) DrawMenuCaption(GStrings("TXTB_FRAGSTATS")); gKillMgr.Draw(); } - if (/*dword_28E3D4 != 1 && */((int)totalclock&32)) + if (/*dword_28E3D4 != 1 && */(gameclock&32)) { viewDrawText(3, GStrings("PRESSKEY"), 160, 134, -128, 0, 1, 1); } diff --git a/source/blood/src/fire.cpp b/source/blood/src/fire.cpp index f20245c22..0abe2cd05 100644 --- a/source/blood/src/fire.cpp +++ b/source/blood/src/fire.cpp @@ -99,10 +99,10 @@ void FireInit(void) void FireProcess(void) { static ClockTicks lastUpdate; - if (totalclock < lastUpdate || lastUpdate + 2 < totalclock) + if (gameclock < lastUpdate || lastUpdate + 2 < gameclock) { DoFireFrame(); - lastUpdate = totalclock; + lastUpdate = gameclock; TileFiles.InvalidateTile(2342); } } diff --git a/source/blood/src/globals.cpp b/source/blood/src/globals.cpp index a90db211b..17de115c7 100644 --- a/source/blood/src/globals.cpp +++ b/source/blood/src/globals.cpp @@ -35,6 +35,8 @@ BEGIN_BLD_NS bool bVanilla = false; ClockTicks gFrameClock; ClockTicks gFrameTicks; +int gameclock; +int lastTic; int gFrame; //int volatile gGameClock; int gFrameRate; diff --git a/source/blood/src/globals.h b/source/blood/src/globals.h index 26cb015b9..d73273dc1 100644 --- a/source/blood/src/globals.h +++ b/source/blood/src/globals.h @@ -32,6 +32,8 @@ BEGIN_BLD_NS extern ClockTicks gFrameClock; extern ClockTicks gFrameTicks; +extern int gameclock; +extern int lastTic; extern int gFrame; //extern ClockTicks gGameClock; extern int gFrameRate; diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 1ea2e4ae2..103bc60ef 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -525,7 +525,8 @@ bool GameInterface::LoadGame(FSaveGameNode* node) gFrameTicks = 0; gFrame = 0; gFrameRate = 0; - totalclock = 0; + gameclock = 0; + lastTic = -1; paused = 0; ready2send = 1; gamestate = GS_LEVEL; @@ -618,7 +619,7 @@ void MyLoadSave::Load(void) Read(&gFrameClock, sizeof(gFrameClock)); Read(&gFrameTicks, sizeof(gFrameTicks)); Read(&gFrame, sizeof(gFrame)); - Read(&totalclock, sizeof(totalclock)); + Read(&gameclock, sizeof(gameclock)); Read(&gLevelTime, sizeof(gLevelTime)); Read(&paused, sizeof(paused)); Read(baseWall, sizeof(baseWall[0])*numwalls); @@ -709,7 +710,7 @@ void MyLoadSave::Save(void) Write(&gFrameClock, sizeof(gFrameClock)); Write(&gFrameTicks, sizeof(gFrameTicks)); Write(&gFrame, sizeof(gFrame)); - ClockTicks nGameClock = totalclock; + ClockTicks nGameClock = gameclock; Write(&nGameClock, sizeof(nGameClock)); Write(&gLevelTime, sizeof(gLevelTime)); Write(&paused, sizeof(paused)); diff --git a/source/blood/src/network.cpp b/source/blood/src/network.cpp index d7a9e1545..9d4cc1352 100644 --- a/source/blood/src/network.cpp +++ b/source/blood/src/network.cpp @@ -78,7 +78,8 @@ void netResetToSinglePlayer(void) void netReset(void) { - gNetFifoClock = gFrameClock = totalclock = 0; + gNetFifoClock = gFrameClock = gameclock = 0; + lastTic = -1; gNetFifoMasterTail = 0; gPredictTail = 0; gNetFifoTail = 0; diff --git a/source/blood/src/nnexts.cpp b/source/blood/src/nnexts.cpp index 94a880bef..2fc612d8c 100644 --- a/source/blood/src/nnexts.cpp +++ b/source/blood/src/nnexts.cpp @@ -4802,10 +4802,10 @@ void playerQavSceneDraw(PLAYER* pPlayer, int a2, double a3, double a4, int a5) { if (pQavScene->qavResrc != NULL) { QAV* pQAV = pQavScene->qavResrc; - int v4 = (pPlayer->weaponTimer == 0) ? (int)totalclock % pQAV->at10 : pQAV->at10 - pPlayer->weaponTimer; + int v4 = (pPlayer->weaponTimer == 0) ? gameclock % pQAV->at10 : pQAV->at10 - pPlayer->weaponTimer; int flags = 2; int nInv = powerupCheck(pPlayer, kPwUpShadowCloak); - if (nInv >= 120 * 8 || (nInv != 0 && ((int)totalclock & 32))) { + if (nInv >= 120 * 8 || (nInv != 0 && (gameclock & 32))) { a2 = -128; flags |= 1; } diff --git a/source/blood/src/sbar.cpp b/source/blood/src/sbar.cpp index ed419a138..bd5a1bef9 100644 --- a/source/blood/src/sbar.cpp +++ b/source/blood/src/sbar.cpp @@ -280,7 +280,7 @@ private: if (powerups[i].remainingDuration) { int remainingSeconds = powerups[i].remainingDuration / 100; - if (remainingSeconds > warningTime || ((int)totalclock & 32)) + if (remainingSeconds > warningTime || (gameclock & 32)) { DrawStatMaskedSprite(powerups[i].nTile, x, y + powerups[i].yOffset, 0, 0, 256, (int)(65536 * powerups[i].nScaleRatio), DI_SCREEN_LEFT_CENTER); } @@ -450,7 +450,7 @@ private: { FString gTempStr; int x = 1, y = 1; - if (dword_21EFD0[0] == 0 || ((int)totalclock & 8)) + if (dword_21EFD0[0] == 0 || (gameclock & 8)) { SBar_DrawString(this, &smallf, GStrings("TXT_COLOR_BLUE"), x, y, 0, CR_LIGHTBLUE, 1., -1, -1, 1, 1); dword_21EFD0[0] = dword_21EFD0[0] - arg; @@ -460,7 +460,7 @@ private: SBar_DrawString(this, &smallf, gTempStr, x, y + 10, 0, CR_LIGHTBLUE, 1., -1, -1, 1, 1); } x = -2; - if (dword_21EFD0[1] == 0 || ((int)totalclock & 8)) + if (dword_21EFD0[1] == 0 || (gameclock & 8)) { SBar_DrawString(this, &smallf, GStrings("TXT_COLOR_RED"), x, y, DI_TEXT_ALIGN_RIGHT, CR_BRICK, 1., -1, -1, 1, 1); dword_21EFD0[1] = dword_21EFD0[1] - arg; @@ -481,7 +481,7 @@ private: { dassert(0 == team || 1 == team); // 0: blue, 1: red - if (dword_21EFD0[team] == 0 || ((int)totalclock & 8)) + if (dword_21EFD0[team] == 0 || (gameclock & 8)) { dword_21EFD0[team] = dword_21EFD0[team] - arg; if (dword_21EFD0[team] < 0) @@ -558,7 +558,7 @@ private: DrawStatMaskedSprite(2200, 160, 200, 0, nPalette, RS_CENTERBOTTOM); DrawPackItemInStatusBar(pPlayer, 265, 186, 260, 172); - if (pXSprite->health >= 16 || ((int)totalclock & 16) || pXSprite->health == 0) + if (pXSprite->health >= 16 || (gameclock & 16) || pXSprite->health == 0) { DrawStatNumber("%3d", pXSprite->health >> 4, 2190, 86, 183, 0, 0); } @@ -632,7 +632,7 @@ private: BeginHUD(320, 200, 1); DrawStatSprite(2201, 34, 187 - 200, 16, nPalette); - if (pXSprite->health >= 16 || ((int)totalclock & 16) || pXSprite->health == 0) + if (pXSprite->health >= 16 || (gameclock & 16) || pXSprite->health == 0) { DrawStatNumber("%3d", pXSprite->health >> 4, 2190, 8, 183 - 200, 0, 0); } diff --git a/source/blood/src/sectorfx.cpp b/source/blood/src/sectorfx.cpp index dc7ea8678..11f283e86 100644 --- a/source/blood/src/sectorfx.cpp +++ b/source/blood/src/sectorfx.cpp @@ -168,7 +168,7 @@ void DoSectorLighting(void) { t2 = mulscale16(t2, pXSector->busy); } - int v4 = GetWaveValue(t1, pXSector->phase*8+pXSector->freq*(int)totalclock, t2); + int v4 = GetWaveValue(t1, pXSector->phase*8+pXSector->freq*gameclock, t2); if (pXSector->shadeFloor) { sector[nSector].floorshade = ClipRange(sector[nSector].floorshade+v4, -128, 127); diff --git a/source/blood/src/sfx.cpp b/source/blood/src/sfx.cpp index 9a9c0f7d4..9e6a9e4f3 100644 --- a/source/blood/src/sfx.cpp +++ b/source/blood/src/sfx.cpp @@ -137,7 +137,7 @@ void sfxUpdate3DSounds(void) listener.ListenerObject = gMe->pSprite; soundEngine->SetListener(listener); - soundEngine->UpdateSounds((int)totalclock); + soundEngine->UpdateSounds(gameclock); } FSoundID getSfx(FSoundID soundId, float &attenuation, int &pitch, int &relvol) diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index c5ed1bf5c..8255faf49 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -393,8 +393,8 @@ void CalcOtherPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsec *pX += mulscale16(vX, othercameradist); *pY += mulscale16(vY, othercameradist); *pZ += mulscale16(vZ, othercameradist); - othercameradist = ClipHigh(othercameradist+(((int)(totalclock-othercameraclock))<<10), 65536); - othercameraclock = (int)totalclock; + othercameradist = ClipHigh(othercameradist+((gameclock-othercameraclock)<<10), 65536); + othercameraclock = gameclock; dassert(*vsectnum >= 0 && *vsectnum < kMaxSectors); FindSector(*pX, *pY, *pZ, vsectnum); pSprite->cstat = bakCstat; @@ -439,8 +439,8 @@ void CalcPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, *pX += mulscale16(vX, cameradist); *pY += mulscale16(vY, cameradist); *pZ += mulscale16(vZ, cameradist); - cameradist = ClipHigh(cameradist+(((int)(totalclock-cameraclock))<<10), 65536); - cameraclock = (int)totalclock; + cameradist = ClipHigh(cameradist+((gameclock-cameraclock)<<10), 65536); + cameraclock = gameclock; dassert(*vsectnum >= 0 && *vsectnum < kMaxSectors); FindSector(*pX, *pY, *pZ, vsectnum); pSprite->cstat = bakCstat; @@ -653,15 +653,15 @@ void viewDrawScreen(bool sceneonly) #ifdef USE_OPENGL polymostcenterhoriz = defaultHoriz; #endif - ClockTicks delta = totalclock - lastUpdate; + ClockTicks delta = gameclock - lastUpdate; if (delta < 0) delta = 0; - lastUpdate = totalclock; + lastUpdate = gameclock; if (!paused && (!M_Active() || gGameOptions.nGameType != 0)) { - gInterpolate = CalcSmoothRatio(totalclock, gNetFifoClock - 4, 30); + gInterpolate = I_GetTimeFrac() * MaxSmoothRatio; } - else gInterpolate = 65536; + else gInterpolate = MaxSmoothRatio; if (cl_interpolate) { @@ -782,7 +782,7 @@ void viewDrawScreen(bool sceneonly) } cZ += fix16_to_int(q16horiz * 10); cameradist = -1; - cameraclock = (int)totalclock; + cameraclock = gameclock; } else { @@ -806,7 +806,7 @@ void viewDrawScreen(bool sceneonly) else if (v4 && gNetPlayers > 1) { #if 0 // needs to be redone for pure hardware rendering. - int tmp = ((int)totalclock / 240) % (gNetPlayers - 1); + int tmp = (gameclock / 240) % (gNetPlayers - 1); int i = connecthead; while (1) { @@ -895,7 +895,7 @@ void viewDrawScreen(bool sceneonly) } else { - othercameraclock = (int)totalclock; + othercameraclock = gameclock; } if (!bDelirium) diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 2372b9b2c..33a2001c7 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -240,14 +240,14 @@ void WeaponDraw(PLAYER *pPlayer, int a2, double a3, double a4, int a5) QAV * pQAV = weaponQAV[pPlayer->weaponQav]; int v4; if (pPlayer->weaponTimer == 0) - v4 = (int)totalclock % pQAV->at10; + v4 = gameclock % pQAV->at10; else v4 = pQAV->at10 - pPlayer->weaponTimer; pQAV->x = int(a3); pQAV->y = int(a4); int flags = 2; int nInv = powerupCheck(pPlayer, kPwUpShadowCloak); - if (nInv >= 120 * 8 || (nInv != 0 && ((int)totalclock & 32))) + if (nInv >= 120 * 8 || (nInv != 0 && (gameclock & 32))) { a2 = -128; flags |= 1;