cache ProgressToNextGameTick and update it only once before rendering
This commit is contained in:
parent
c7b9ffec1f
commit
9fbe139f64
4 changed files with 18 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1533,6 +1533,8 @@ void DrawAndBlit()
|
|||
lock_buf(0);
|
||||
CelOutputBuffer out = GlobalBackBuffer();
|
||||
|
||||
nthread_UpdateProgressToNextGameTick();
|
||||
|
||||
DrawView(out, ViewX, ViewY);
|
||||
if (ctrlPan) {
|
||||
DrawCtrlPan(out);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue