mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
Remove last vestiges of input latency from Duke3D and RR main game loops.
- Hack code to break loop early removed. If game code is running slow, that's not the fix. - Get input and fill the input_t struct in same loop as G_DoMoveThings(). - Remove unnecessary do/while (0) loop.
This commit is contained in:
parent
1a2663f7ac
commit
2cbbe9ec61
2 changed files with 45 additions and 94 deletions
|
@ -5906,77 +5906,53 @@ MAIN_LOOP_RESTART:
|
||||||
|
|
||||||
OSD_DispatchQueued();
|
OSD_DispatchQueued();
|
||||||
|
|
||||||
static bool frameJustDrawn;
|
|
||||||
bool gameUpdate = false;
|
bool gameUpdate = false;
|
||||||
double gameUpdateStartTime = timerGetHiTicks();
|
double gameUpdateStartTime = timerGetHiTicks();
|
||||||
|
|
||||||
auto beforeMoveClock = ototalclock;
|
|
||||||
|
|
||||||
if (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU|MODE_DEMO)) == 0) && totalclock >= ototalclock+TICSPERFRAME)
|
if (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU|MODE_DEMO)) == 0) && totalclock >= ototalclock+TICSPERFRAME)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (g_networkMode != NET_DEDICATED_SERVER)
|
ototalclock += TICSPERFRAME;
|
||||||
|
|
||||||
|
P_GetInput(myconnectindex);
|
||||||
|
|
||||||
|
// this is where we fill the input_t struct that is actually processed by P_ProcessInput()
|
||||||
|
auto const pPlayer = g_player[myconnectindex].ps;
|
||||||
|
auto const q16ang = fix16_to_int(pPlayer->q16ang);
|
||||||
|
auto & input = inputfifo[0][myconnectindex];
|
||||||
|
|
||||||
|
input = localInput;
|
||||||
|
input.fvel = mulscale9(localInput.fvel, sintable[(q16ang + 2560) & 2047]) +
|
||||||
|
mulscale9(localInput.svel, sintable[(q16ang + 2048) & 2047]);
|
||||||
|
input.svel = mulscale9(localInput.fvel, sintable[(q16ang + 2048) & 2047]) +
|
||||||
|
mulscale9(localInput.svel, sintable[(q16ang + 1536) & 2047]);
|
||||||
|
|
||||||
|
if (!FURY)
|
||||||
{
|
{
|
||||||
if (!frameJustDrawn)
|
input.fvel += pPlayer->fric.x;
|
||||||
break;
|
input.svel += pPlayer->fric.y;
|
||||||
|
|
||||||
frameJustDrawn = false;
|
|
||||||
|
|
||||||
P_GetInput(myconnectindex);
|
|
||||||
|
|
||||||
// this is where we fill the input_t struct that is actually processed by P_ProcessInput()
|
|
||||||
auto const pPlayer = g_player[myconnectindex].ps;
|
|
||||||
auto const q16ang = fix16_to_int(pPlayer->q16ang);
|
|
||||||
auto & input = inputfifo[0][myconnectindex];
|
|
||||||
|
|
||||||
input = localInput;
|
|
||||||
input.fvel = mulscale9(localInput.fvel, sintable[(q16ang + 2560) & 2047]) +
|
|
||||||
mulscale9(localInput.svel, sintable[(q16ang + 2048) & 2047]);
|
|
||||||
input.svel = mulscale9(localInput.fvel, sintable[(q16ang + 2048) & 2047]) +
|
|
||||||
mulscale9(localInput.svel, sintable[(q16ang + 1536) & 2047]);
|
|
||||||
|
|
||||||
if (!FURY)
|
|
||||||
{
|
|
||||||
input.fvel += pPlayer->fric.x;
|
|
||||||
input.svel += pPlayer->fric.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
localInput = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
localInput = {};
|
||||||
|
|
||||||
|
if (((!GUICapture && (myplayer.gm & MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (g_netServer || ud.multimode > 1))
|
||||||
|
&& (myplayer.gm & MODE_GAME))
|
||||||
{
|
{
|
||||||
if (ready2send == 0)
|
Net_GetPackets();
|
||||||
break;
|
G_DoMoveThings();
|
||||||
|
|
||||||
ototalclock += TICSPERFRAME;
|
|
||||||
|
|
||||||
auto const moveClock = totalclock;
|
|
||||||
|
|
||||||
if (((!GUICapture && (myplayer.gm & MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (g_netServer || ud.multimode > 1))
|
|
||||||
&& (myplayer.gm & MODE_GAME))
|
|
||||||
{
|
|
||||||
Net_GetPackets();
|
|
||||||
G_DoMoveThings();
|
|
||||||
}
|
|
||||||
|
|
||||||
// computing a tic is taking too long.
|
|
||||||
// rather than tightly spinning here, go draw a frame since we're fucked anyway
|
|
||||||
if ((int)(totalclock - moveClock) >= (TICSPERFRAME >> 1))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
while (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU | MODE_DEMO)) == 0) && (int)(totalclock - ototalclock) >= TICSPERFRAME);
|
}
|
||||||
|
while (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU | MODE_DEMO)) == 0) && (int)(totalclock - ototalclock) >= TICSPERFRAME);
|
||||||
|
|
||||||
gameUpdate = true;
|
gameUpdate = true;
|
||||||
g_gameUpdateTime = timerGetHiTicks() - gameUpdateStartTime;
|
g_gameUpdateTime = timerGetHiTicks() - gameUpdateStartTime;
|
||||||
|
|
||||||
if (g_gameUpdateAvgTime <= 0.0)
|
if (g_gameUpdateAvgTime <= 0.0)
|
||||||
g_gameUpdateAvgTime = g_gameUpdateTime;
|
g_gameUpdateAvgTime = g_gameUpdateTime;
|
||||||
|
|
||||||
g_gameUpdateAvgTime
|
g_gameUpdateAvgTime
|
||||||
= ((GAMEUPDATEAVGTIMENUMSAMPLES - 1.f) * g_gameUpdateAvgTime + g_gameUpdateTime) / ((float)GAMEUPDATEAVGTIMENUMSAMPLES);
|
= ((GAMEUPDATEAVGTIMENUMSAMPLES - 1.f) * g_gameUpdateAvgTime + g_gameUpdateTime) / ((float)GAMEUPDATEAVGTIMENUMSAMPLES);
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
G_DoCheats();
|
G_DoCheats();
|
||||||
|
@ -6011,8 +5987,6 @@ MAIN_LOOP_RESTART:
|
||||||
|
|
||||||
if (gameUpdate)
|
if (gameUpdate)
|
||||||
g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime;
|
g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime;
|
||||||
|
|
||||||
frameJustDrawn = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle CON_SAVE and CON_SAVENN
|
// handle CON_SAVE and CON_SAVENN
|
||||||
|
|
|
@ -7411,17 +7411,13 @@ MAIN_LOOP_RESTART:
|
||||||
|
|
||||||
OSD_DispatchQueued();
|
OSD_DispatchQueued();
|
||||||
|
|
||||||
static bool frameJustDrawn;
|
|
||||||
char gameUpdate = false;
|
char gameUpdate = false;
|
||||||
double const gameUpdateStartTime = timerGetHiTicks();
|
double const gameUpdateStartTime = timerGetHiTicks();
|
||||||
if (((g_netClient || g_netServer) || !(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO))) && totalclock >= ototalclock+TICSPERFRAME)
|
if (((g_netClient || g_netServer) || !(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO))) && totalclock >= ototalclock+TICSPERFRAME)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!frameJustDrawn)
|
ototalclock += TICSPERFRAME;
|
||||||
break;
|
|
||||||
|
|
||||||
frameJustDrawn = false;
|
|
||||||
|
|
||||||
if (RRRA && g_player[myconnectindex].ps->on_motorcycle)
|
if (RRRA && g_player[myconnectindex].ps->on_motorcycle)
|
||||||
P_GetInputMotorcycle(myconnectindex);
|
P_GetInputMotorcycle(myconnectindex);
|
||||||
|
@ -7446,36 +7442,19 @@ MAIN_LOOP_RESTART:
|
||||||
|
|
||||||
g_player[myconnectindex].movefifoend++;
|
g_player[myconnectindex].movefifoend++;
|
||||||
|
|
||||||
do
|
if (((!GUICapture && (g_player[myconnectindex].ps->gm&MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (g_netServer || ud.multimode > 1)) &&
|
||||||
{
|
(g_player[myconnectindex].ps->gm&MODE_GAME))
|
||||||
if (ready2send == 0) break;
|
{
|
||||||
|
G_MoveLoop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (((g_netClient || g_netServer) || !(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO))) && (int)(totalclock - ototalclock) >= TICSPERFRAME);
|
||||||
|
|
||||||
ototalclock += TICSPERFRAME;
|
gameUpdate = true;
|
||||||
|
g_gameUpdateTime = timerGetHiTicks()-gameUpdateStartTime;
|
||||||
int const moveClock = (int) totalclock;
|
if (g_gameUpdateAvgTime < 0.f)
|
||||||
|
g_gameUpdateAvgTime = g_gameUpdateTime;
|
||||||
if (((!GUICapture && (g_player[myconnectindex].ps->gm&MODE_MENU) != MODE_MENU) || ud.recstat == 2 || (g_netServer || ud.multimode > 1)) &&
|
g_gameUpdateAvgTime = ((GAMEUPDATEAVGTIMENUMSAMPLES-1.f)*g_gameUpdateAvgTime+g_gameUpdateTime)/((float) GAMEUPDATEAVGTIMENUMSAMPLES);
|
||||||
(g_player[myconnectindex].ps->gm&MODE_GAME))
|
|
||||||
{
|
|
||||||
G_MoveLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalclock - moveClock >= TICSPERFRAME)
|
|
||||||
{
|
|
||||||
// computing a tic takes longer than 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) || !(g_player[myconnectindex].ps->gm & (MODE_MENU|MODE_DEMO))) && totalclock >= ototalclock+TICSPERFRAME);
|
|
||||||
|
|
||||||
gameUpdate = true;
|
|
||||||
g_gameUpdateTime = timerGetHiTicks()-gameUpdateStartTime;
|
|
||||||
if (g_gameUpdateAvgTime < 0.f)
|
|
||||||
g_gameUpdateAvgTime = g_gameUpdateTime;
|
|
||||||
g_gameUpdateAvgTime = ((GAMEUPDATEAVGTIMENUMSAMPLES-1.f)*g_gameUpdateAvgTime+g_gameUpdateTime)/((float) GAMEUPDATEAVGTIMENUMSAMPLES);
|
|
||||||
} while(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
G_DoCheats();
|
G_DoCheats();
|
||||||
|
@ -7515,8 +7494,6 @@ MAIN_LOOP_RESTART:
|
||||||
g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime;
|
g_gameUpdateAndDrawTime = g_beforeSwapTime/* timerGetHiTicks()*/ - gameUpdateStartTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
frameJustDrawn = true;
|
|
||||||
|
|
||||||
if (DEER)
|
if (DEER)
|
||||||
sub_5A02C();
|
sub_5A02C();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue