Wait to run G_MoveLoop() until a frame has just been rendered

This should give G_MoveLoop() a better chance to not run past the time when another frame is to be drawn.

git-svn-id: https://svn.eduke32.com/eduke32@8195 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-10-19 23:45:49 +00:00 committed by Christoph Oelckers
parent 9fadf6032d
commit ca789dc4d0
2 changed files with 55 additions and 42 deletions

View file

@ -6321,7 +6321,7 @@ int G_FPSLimit(void)
uint64_t const elapsedTime = frameTicks - lastFrameTicks;
double const dElapsedTime = elapsedTime;
if (dElapsedTime >= floor(nextPageDelay))
if (dElapsedTime >= nextPageDelay)
{
if (dElapsedTime <= nextPageDelay+g_frameDelay)
nextPageDelay += g_frameDelay-dElapsedTime;
@ -6859,26 +6859,36 @@ MAIN_LOOP_RESTART:
OSD_DispatchQueued();
char gameUpdate = false;
double const gameUpdateStartTime = timerGetHiTicks();
static bool frameJustDrawn;
bool gameUpdate = false;
double gameUpdateStartTime = timerGetHiTicks();
if (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU|MODE_DEMO)) == 0) && totalclock >= ototalclock+TICSPERFRAME)
{
do
{
if (g_networkMode != NET_DEDICATED_SERVER)
{
if (!frameJustDrawn)
break;
frameJustDrawn = false;
P_GetInput(myconnectindex);
inputfifo[0][myconnectindex] = localInput;
}
do
{
if (ready2send == 0) break;
if (ready2send == 0)
break;
ototalclock += TICSPERFRAME;
int const moveClock = (int) totalclock;
int const moveClock = (int)totalclock;
if (((ud.show_help == 0 && (myplayer.gm & MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (g_netServer || ud.multimode > 1)) &&
(myplayer.gm & MODE_GAME))
if (((ud.show_help == 0 && (myplayer.gm & MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (g_netServer || ud.multimode > 1))
&& (myplayer.gm & MODE_GAME))
{
G_MoveLoop();
S_Update();
@ -6891,21 +6901,24 @@ MAIN_LOOP_RESTART:
#endif
}
if (totalclock - moveClock >= TICSPERFRAME)
if (totalclock - moveClock >= (TICSPERFRAME>>1))
{
// computing a tic takes longer than a tic, so we're slowing
// computing a tic takes longer than half a tic, so we're slowing
// the game down. rather than tightly spinning here, go draw
// a frame since we're fucked anyway
break;
}
}
while (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU|MODE_DEMO)) == 0) && totalclock >= ototalclock+TICSPERFRAME);
} while (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU | MODE_DEMO)) == 0) && totalclock >= ototalclock + TICSPERFRAME);
gameUpdate = true;
g_gameUpdateTime = timerGetHiTicks()-gameUpdateStartTime;
if (g_gameUpdateAvgTime < 0.f)
g_gameUpdateTime = timerGetHiTicks() - gameUpdateStartTime;
if (g_gameUpdateAvgTime <= 0.0)
g_gameUpdateAvgTime = g_gameUpdateTime;
g_gameUpdateAvgTime = ((GAMEUPDATEAVGTIMENUMSAMPLES-1.f)*g_gameUpdateAvgTime+g_gameUpdateTime)/((float) GAMEUPDATEAVGTIMENUMSAMPLES);
g_gameUpdateAvgTime
= ((GAMEUPDATEAVGTIMENUMSAMPLES - 1.f) * g_gameUpdateAvgTime + g_gameUpdateTime) / ((float)GAMEUPDATEAVGTIMENUMSAMPLES);
} while (0);
}
G_DoCheats();
@ -6934,9 +6947,9 @@ MAIN_LOOP_RESTART:
videoNextPage();
if (gameUpdate)
{
g_gameUpdateAndDrawTime = timerGetHiTicks()-gameUpdateStartTime;
}
frameJustDrawn = true;
}
// handle CON_SAVE and CON_SAVENN

View file

@ -92,7 +92,7 @@ int32_t g_gametypeFlags[MAXGAMETYPES] =
GAMETYPE_TDMSPAWN,
};
double g_gameUpdateAvgTime = 0.001;
double g_gameUpdateAvgTime;
int32_t g_actorRespawnTime = 768;
int32_t g_bouncemineRadius = 2500;