diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 20ccf76c8..b55e356d4 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -24,6 +24,7 @@ bool sgbThreadIsRunning; DWORD gdwLargestMsgSize; DWORD gdwNormalMsgSize; int last_tick; +float gfProgressToNextGameTick = 0.0f; /* data */ static SDL_Thread *sghThread = NULL; @@ -242,21 +243,23 @@ bool nthread_has_500ms_passed() return ticksElapsed >= 0; } -float nthread_GetProgressToNextGameTick() +void nthread_UpdateProgressToNextGameTick() { if (!gbRunGame || PauseMode || (!gbIsMultiplayer && gmenu_is_active())) // if game is not running or paused there is no next gametick in the near future - return 0.0f; + return; int currentTickCount = SDL_GetTicks(); int ticksElapsed = last_tick - currentTickCount; - if (ticksElapsed <= 0) - return 1.0f; // game tick is due + if (ticksElapsed <= 0) { + gfProgressToNextGameTick = 1.0f; // game tick is due + return; + } int ticksAdvanced = gnTickDelay - ticksElapsed; - float percent = (float)ticksAdvanced / (float)gnTickDelay; - if (percent > 1.0f) - return 1.0f; - if (percent < 0.0f) - return 0.0f; - return percent; + float fraction = (float)ticksAdvanced / (float)gnTickDelay; + if (fraction > 1.0f) + gfProgressToNextGameTick = 1.0f; + if (fraction < 0.0f) + gfProgressToNextGameTick = 0.0f; + gfProgressToNextGameTick = fraction; } } // namespace devilution diff --git a/Source/nthread.h b/Source/nthread.h index 5631da1e3..76227e4eb 100644 --- a/Source/nthread.h +++ b/Source/nthread.h @@ -14,6 +14,7 @@ extern DWORD gdwTurnsInTransit; extern uintptr_t glpMsgTbl[MAX_PLRS]; extern DWORD gdwLargestMsgSize; extern DWORD gdwNormalMsgSize; +extern float gfProgressToNextGameTick; // the progress as a fraction (0.0f to 1.0f) in time to the next game tick void nthread_terminate_game(const char *pszFcn); DWORD nthread_send_and_recv_turn(DWORD cur_turn, int turn_delta); @@ -27,6 +28,6 @@ bool nthread_has_500ms_passed(); * @brief Calculates the progress in time to the next game tick * @return Progress as a fraction (0.0f to 1.0f) */ -float nthread_GetProgressToNextGameTick(); +void nthread_UpdateProgressToNextGameTick(); } diff --git a/Source/player.cpp b/Source/player.cpp index ffb21d0d3..62a698dec 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3681,7 +3681,7 @@ Sint32 GetFrameToUseForPlayerRendering(const PlayerStruct* pPlayer) } else { relevantAnimationLength = pPlayer->_pAnimLen; } - float progressToNextGameTick = nthread_GetProgressToNextGameTick(); + float progressToNextGameTick = gfProgressToNextGameTick; float totalGameTicksForCurrentAnimationSequence = progressToNextGameTick + (float)pPlayer->_pAnimGameTicksSinceSequenceStarted; // we don't use the processed game ticks alone but also the fragtion of the next game tick (if a rendering happens between game ticks). This helps to smooth the animations. int animationMaxGameTickets = relevantAnimationLength; if (pPlayer->_pAnimDelay > 1) diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index d823e24ce..7bf9488f6 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1533,6 +1533,8 @@ void DrawAndBlit() lock_buf(0); CelOutputBuffer out = GlobalBackBuffer(); + nthread_UpdateProgressToNextGameTick(); + DrawView(out, ViewX, ViewY); if (ctrlPan) { DrawCtrlPan(out);