diff --git a/source/exhumed/src/2d.cpp b/source/exhumed/src/2d.cpp index 9375625a2..d9388e0a4 100644 --- a/source/exhumed/src/2d.cpp +++ b/source/exhumed/src/2d.cpp @@ -165,9 +165,10 @@ enum void menu_DoPlasma() { int ptile = nPlasmaTile; - if (totalclock >= nextPlasmaTic || !PlasmaBuffer) + int pclock = I_GetBuildTime(); + if (pclock >= nextPlasmaTic || !PlasmaBuffer) { - nextPlasmaTic = (int)totalclock + 4; + nextPlasmaTic = pclock + 4; if (!nLogoTile) nLogoTile = EXHUMED ? kExhumedLogo : kPowerslaveLogo; @@ -366,7 +367,7 @@ void menu_DoPlasma() DrawRel(nLogoTile, 160, 40); // draw the fire urn/lamp thingies - int dword_9AB5F = ((int)totalclock / 16) & 3; + int dword_9AB5F = (pclock / 16) & 3; DrawRel(kTile3512 + dword_9AB5F, 50, 150); DrawRel(kTile3512 + ((dword_9AB5F + 2) & 3), 270, 150); @@ -683,7 +684,7 @@ public: { for (int j = 0; j < MapLevelFires[i].nFires; j++) { - int nFireFrame = (((int)totalclock >> 4) & 3); + int nFireFrame = ((totalclock >> 4) & 3); assert(nFireFrame >= 0 && nFireFrame < 4); int nFireType = MapLevelFires[i].fires[j].nFireType; @@ -699,7 +700,7 @@ public: } } - int t = ((((int)totalclock & 16) >> 4)); + int t = (((totalclock & 16) >> 4)); int nTile = mapNamePlaques[i].tiles[t].nTile; @@ -713,7 +714,7 @@ public: if (nLevelNew == i) { - shade = (Sin(16 * (int)totalclock) + 31) >> 8; + shade = (Sin(16 * totalclock) + 31) >> 8; } else if (nLevelBest >= i) { @@ -733,7 +734,7 @@ public: // scroll the map every couple of ms if (totalclock - runtimer >= (kTimerTicks / 32)) { curYPos += var_2C; - runtimer = (int)totalclock; + runtimer = totalclock; } if (inputState.CheckAllInput()) @@ -878,12 +879,12 @@ void TextOverlay::DisplayText() } } -bool TextOverlay::AdvanceCinemaText(int totalclock) +bool TextOverlay::AdvanceCinemaText(int gameclock) { if (nHeight + nCrawlY > 0 || CDplaying()) { - nCrawlY-= (totalclock - lastclock) / 15.; // do proper interpolation. - lastclock = totalclock; + nCrawlY-= (gameclock - lastclock) / 15.; // do proper interpolation. + lastclock = gameclock; return true; } @@ -1144,7 +1145,7 @@ private: nStringTypeOn++; if (nStringTypeOn >= screentext.Size()) { - nextclock = (kTimerTicks * (screentext.Size() + 2)) + (int)totalclock; + nextclock = (kTimerTicks * (screentext.Size() + 2)) + totalclock; phase = 3; } @@ -1153,7 +1154,7 @@ private: DisplayPhase2(); if (skiprequest) { - nextclock = (kTimerTicks * (screentext.Size() + 2)) + (int)totalclock; + nextclock = (kTimerTicks * (screentext.Size() + 2)) + totalclock; phase = 3; } break; diff --git a/source/exhumed/src/d_menu.cpp b/source/exhumed/src/d_menu.cpp index 69c328f2c..62e855813 100644 --- a/source/exhumed/src/d_menu.cpp +++ b/source/exhumed/src/d_menu.cpp @@ -96,7 +96,7 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double xpos, doub if (state == NIT_SelectedState) { // currently selected menu item - shade = Sin((int)totalclock << 4) >> 9; + shade = Sin(I_GetBuildTime() << 4) >> 9; } else if (state == NIT_ActiveState) { shade = 0; diff --git a/source/exhumed/src/engine.h b/source/exhumed/src/engine.h index a27649b89..b692edfe5 100644 --- a/source/exhumed/src/engine.h +++ b/source/exhumed/src/engine.h @@ -60,8 +60,8 @@ enum { kSectLava = 0x4000, }; -extern ClockTicks ototalclock; - +extern int ogameclock, gameclock; +extern int lastTic; extern int initx; extern int inity; extern int initz; diff --git a/source/exhumed/src/enginesubs.cpp b/source/exhumed/src/enginesubs.cpp index 3f637d43a..9da49b062 100644 --- a/source/exhumed/src/enginesubs.cpp +++ b/source/exhumed/src/enginesubs.cpp @@ -29,7 +29,9 @@ BEGIN_PS_NS void resettiming() { - totalclock = 0; + ogameclock = -1; + gameclock = 0; + lastTic = -1; } void doTileLoad(int i) diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 28bb23822..6822bd7d2 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -71,12 +71,7 @@ PlayerInput localInput; void ResetEngine() { EraseScreen(-1); - resettiming(); - - totalclock = 0; - ototalclock = totalclock; - localclock = (int)totalclock; } void InstallEngine() @@ -158,7 +153,6 @@ short nCodeIndex = 0; //short nScreenHeight = 200; int moveframes; int flash; -int localclock; int totalmoves; short nCurBodyNum = 0; @@ -190,8 +184,6 @@ int nTimeLimit; int bVanilla = 0; -ClockTicks tclocks; - void DebugOut(const char *fmt, ...) { #ifdef _DEBUG @@ -392,12 +384,12 @@ void DrawClock() DoEnergyTile(); } -double calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk) +double calc_smoothratio() { if (bRecord || bPlayback || nFreeze != 0 || bCamera || paused) - return 65536; + return MaxSmoothRatio; - return CalcSmoothRatio(totalclk, ototalclk, 30); + return I_GetTimeFrac() * MaxSmoothRatio; } FString GameInterface::statFPS() @@ -489,18 +481,20 @@ void GameTicker() { bInMove = true; + int const currentTic = I_GetTime(); + gameclock = I_GetBuildTime(); + if (paused) { - tclocks = totalclock - 4; buttonMap.ResetButtonStates(); } else { - while ((totalclock - ototalclock) >= 1 || !bInMove) + while ((gameclock - ogameclock) >= 1 || !bInMove) { - ototalclock = ototalclock + 1; + ogameclock = I_GetBuildTime(); - if (!((int)ototalclock & 3) && moveframes < 4) + if (!((int)ogameclock & 3) && moveframes < 4) moveframes++; GetLocalInput(); @@ -527,9 +521,9 @@ void GameTicker() sPlayerInput[nLocalPlayer].horizon = PlayerList[nLocalPlayer].q16horiz; - while (!EndLevel && totalclock >= tclocks + 4) + while (!EndLevel && currentTic - lastTic >= 1) { - tclocks += 4; + lastTic = currentTic; leveltime++; GameMove(); } @@ -759,9 +753,6 @@ static SavegameHelper sgh("exhumed", SV(nBodyTotal), SV(bSnakeCam), SV(bSlipMode), - SV(localclock), - SV(tclocks), - SV(totalclock), SV(leveltime), nullptr); diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index c54f7a32a..37599599c 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -149,8 +149,6 @@ extern char sHollyStr[]; extern int selectedlevelnew; extern int GameAction; -extern int localclock; - extern int moveframes; extern int nNetPlayerCount; @@ -249,7 +247,7 @@ public: void ComputeCinemaText(); void ReadyCinemaText(uint16_t nVal); void DisplayText(); - bool AdvanceCinemaText(int totalclock); + bool AdvanceCinemaText(int gameclock); }; diff --git a/source/exhumed/src/gameloop.cpp b/source/exhumed/src/gameloop.cpp index a26fadcce..b9a937eba 100644 --- a/source/exhumed/src/gameloop.cpp +++ b/source/exhumed/src/gameloop.cpp @@ -55,12 +55,11 @@ static int32_t nonsharedtimer; int GameAction=-1; extern uint8_t nCinemaSeen; -extern ClockTicks tclocks; void RunCinemaScene(int num); void GameMove(void); void DrawClock(); -double calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk); +double calc_smoothratio(); void DoTitle(CompletionFunc completion); static int FinishLevel(TArray &jobs) @@ -83,8 +82,8 @@ static int FinishLevel(TArray &jobs) { // There's really no choice but to enter an active wait loop here to make the sound play out. PlayLocalSound(StaticSound[59], 0, true, CHANF_UI); - int nTicks = totalclock + 12; - while (nTicks > (int)totalclock) { HandleAsync(); } + int nTicks = gameclock + 12; + while (nTicks > gameclock) { HandleAsync(); } } } else nPlayerLives[0] = 0; @@ -117,9 +116,7 @@ static void GameDisplay(void) DrawClock(); } - double smoothRatio = calc_smoothratio(totalclock, tclocks); - - DrawView(smoothRatio); + DrawView(calc_smoothratio()); DrawStatusBar(); if (paused && !M_Active()) { @@ -152,7 +149,7 @@ void startmainmenu() void drawmenubackground() { auto nLogoTile = EXHUMED ? kExhumedLogo : kPowerslaveLogo; - int dword_9AB5F = ((int)totalclock / 16) & 3; + int dword_9AB5F = (I_GetBuildTime() / 16) & 3; twod->ClearScreen(); @@ -226,7 +223,6 @@ void CheckProgression() gamestate = GS_LEVEL; InitLevel(selectedlevelnew); - tclocks = totalclock; #if 0 // this would be the place to autosave upon level start if (!bInDemo && selectedlevelnew > nBestLevel && selectedlevelnew != 0 && selectedlevelnew <= kMap20) { @@ -274,8 +270,7 @@ void GameInterface::RunGameFrame() { default: case GS_STARTUP: - totalclock = 0; - ototalclock = 0; + resettiming(); GameAction = -1; EndLevel = false; diff --git a/source/exhumed/src/init.cpp b/source/exhumed/src/init.cpp index 9fd2f7607..e6a33f234 100644 --- a/source/exhumed/src/init.cpp +++ b/source/exhumed/src/init.cpp @@ -38,7 +38,9 @@ enum kTagRamses = 61, }; -ClockTicks ototalclock = 0; +int ogameclock = 0; +int gameclock = 0; +int lastTic; int initx, inity, initz; short inita, initsect; diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index a2ca1970e..a64b1912c 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -160,7 +160,7 @@ void CheckKeys2() { if (automapMode != am_off) { - int const timerOffset = ((int)totalclock - nonsharedtimer); + int const timerOffset = (gameclock - nonsharedtimer); nonsharedtimer += timerOffset; if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) diff --git a/source/exhumed/src/map.cpp b/source/exhumed/src/map.cpp index 54e677e7c..72c4fd99c 100644 --- a/source/exhumed/src/map.cpp +++ b/source/exhumed/src/map.cpp @@ -434,7 +434,7 @@ static void G_DrawOverheadMap(int32_t cposx, int32_t cposy, int32_t czoom, int16 if (p == screenpeek || GTFLAGS(GAMETYPE_OTHERPLAYERSINMAP)) { if (pSprite->xvel > 16 && pPlayer->on_ground) - i = APLAYERTOP+(((int32_t) totalclock>>4)&3); + i = APLAYERTOP+(((int32_t) gameclock>>4)&3); else i = APLAYERTOP; diff --git a/source/exhumed/src/move.cpp b/source/exhumed/src/move.cpp index 8cdcba7fd..ae1dc1359 100644 --- a/source/exhumed/src/move.cpp +++ b/source/exhumed/src/move.cpp @@ -194,7 +194,6 @@ void MoveThings() void ResetMoveFifo() { - localclock = (int)totalclock; movefifoend = 0; movefifopos = 0; } diff --git a/source/exhumed/src/object.cpp b/source/exhumed/src/object.cpp index 1d0028913..452395cc6 100644 --- a/source/exhumed/src/object.cpp +++ b/source/exhumed/src/object.cpp @@ -1529,20 +1529,20 @@ void DoFinale() { StopLocalSound(); PlayLocalSound(StaticSound[kSound76], 0); - dword_1542FC = (int)totalclock + 120; + dword_1542FC = gameclock + 120; nFinaleStage++; } } else if (nFinaleStage <= 2) { - if ((int)totalclock >= dword_1542FC) + if (gameclock >= dword_1542FC) { PlayLocalSound(StaticSound[kSound77], 0); nFinaleStage++; - dword_1542FC = (int)totalclock + 360; + dword_1542FC = gameclock + 360; } } - else if (nFinaleStage == 3 && (int)totalclock >= dword_1542FC) + else if (nFinaleStage == 3 && gameclock >= dword_1542FC) { EndLevel = true; } @@ -1706,7 +1706,7 @@ void ExplodeEnergyBlock(int nSprite) else { nFinaleSpr = nSprite; - lFinaleStart = (int)totalclock; + lFinaleStart = gameclock; if (!lFinaleStart) { lFinaleStart = lFinaleStart + 1; diff --git a/source/exhumed/src/ramses.cpp b/source/exhumed/src/ramses.cpp index dc3b9036b..6c6c39242 100644 --- a/source/exhumed/src/ramses.cpp +++ b/source/exhumed/src/ramses.cpp @@ -127,7 +127,7 @@ void InitSpiritHead() sprite[nSpiritSprite].cstat &= 0x7FFF; - nHeadTimeStart = (int)totalclock; + nHeadTimeStart = gameclock; memset(Worktile, TRANSPARENT_INDEX, WorktileSize); TileFiles.InvalidateTile(kTileRamsesWorkTile); @@ -152,8 +152,8 @@ void InitSpiritHead() StartSwirlies(); sprintf(filename, "LEV%d.PUP", currentLevel->levelNumber); - lNextStateChange = (int)totalclock; - lHeadStartClock = (int)totalclock; + lNextStateChange = gameclock; + lHeadStartClock = gameclock; auto headfd = fileSystem.OpenFileReader(filename); if (!headfd.isOpen()) @@ -219,7 +219,7 @@ int DoSpiritHead() if (nHeadStage < 2 || nHeadStage != 5) { - nPixelsToShow = ((int)totalclock - nHeadTimeStart) * 15; + nPixelsToShow = (gameclock - nHeadTimeStart) * 15; if (nPixelsToShow > nPixels) { nPixelsToShow = nPixels; @@ -242,10 +242,10 @@ int DoSpiritHead() if (!nHeadStage) { - if (((int)totalclock - nHeadTimeStart) > 480) + if ((gameclock - nHeadTimeStart) > 480) { nHeadStage = 1; - nHeadTimeStart = (int)totalclock + 480; + nHeadTimeStart = gameclock + 480; } for (int i = 0; i < nPixelsToShow; i++) @@ -426,7 +426,7 @@ int DoSpiritHead() Worktile[kSpiritX + ecx] = pixelval[i]; } - if (((int)totalclock - lHeadStartClock) > 600) + if ((gameclock - lHeadStartClock) > 600) { CopyHeadToWorkTile(kTileRamsesGold); } @@ -467,7 +467,7 @@ int DoSpiritHead() } else { - if (lNextStateChange <= (int)totalclock) + if (lNextStateChange <= gameclock) { if (nPupData) { diff --git a/source/exhumed/src/save.cpp b/source/exhumed/src/save.cpp index c3c5f7e55..59c4747fc 100644 --- a/source/exhumed/src/save.cpp +++ b/source/exhumed/src/save.cpp @@ -60,7 +60,7 @@ bool GameInterface::LoadGame(FSaveGameNode* sv) pSky->yscale = 65536; parallaxtype = 2; g_visibility = 2048; - ototalclock = totalclock; + ogameclock = gameclock; GameAction = 1000; if (currentLevel->levelNumber > 15) diff --git a/source/exhumed/src/sound.cpp b/source/exhumed/src/sound.cpp index cf9f4b11a..91fcece6b 100644 --- a/source/exhumed/src/sound.cpp +++ b/source/exhumed/src/sound.cpp @@ -447,7 +447,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], else if (type == SOURCE_Swirly) { int which = *(int*)source; - float phase = ((int)totalclock << (4 + which)) * (M_PI / 1024); + float phase = (gameclock << (4 + which)) * (M_PI / 1024); pos->X = fcampos.X + 256 * cos(phase); pos->Z = fcampos.Z + 256 * sin(phase); } @@ -522,7 +522,7 @@ void UpdateSounds() soundEngine->SetListener(listener); - soundEngine->UpdateSounds((int)totalclock); + soundEngine->UpdateSounds(gameclock); soundEngine->EnumerateChannels([](FSoundChan* chan) { if (!(chan->ChanFlags & (CHANF_UI|CHANF_FORGETTABLE))) diff --git a/source/exhumed/src/status.cpp b/source/exhumed/src/status.cpp index 5e71a3ddb..1886a4237 100644 --- a/source/exhumed/src/status.cpp +++ b/source/exhumed/src/status.cpp @@ -676,7 +676,7 @@ private: int shade; - if ((int)totalclock / kTimerTicks & 1) { + if (gameclock / kTimerTicks & 1) { shade = -100; } else { @@ -694,14 +694,14 @@ private: if (word_9AD54[i] == nScore) { int v9 = dword_9AD64[i]; - if (v9 && v9 <= (int)totalclock) { + if (v9 && v9 <= gameclock) { dword_9AD64[i] = 0; } } else { word_9AD54[i] = nScore; - dword_9AD64[i] = (int)totalclock + 30; + dword_9AD64[i] = gameclock + 30; } DrawGraphic(tileGetTexture(nTile), x, 7, DI_ITEM_CENTER, 1, -1, -1, 1, 1); diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index b28bef83f..c8cffb9b1 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -434,7 +434,7 @@ void DrawView(double smoothRatio, bool sceneonly) if (bSubTitles) { - subtitleOverlay.Start(totalclock); + subtitleOverlay.Start(gameclock); if (currentLevel->levelNumber == 1) subtitleOverlay.ReadyCinemaText(1); else @@ -443,7 +443,7 @@ void DrawView(double smoothRatio, bool sceneonly) } else if (nHeadStage == 6) { - if ((bSubTitles && !subtitleOverlay.AdvanceCinemaText(totalclock)) || inputState.CheckAllInput()) + if ((bSubTitles && !subtitleOverlay.AdvanceCinemaText(gameclock)) || inputState.CheckAllInput()) { inputState.ClearAllInput(); EndLevel = 2;