Commit 661883a5 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

Duke3d: fix extra counters shown with r_showfps values greater than 1 to...

Duke3d: fix extra counters shown with r_showfps values greater than 1 to account for frames being rendered in places where they previously weren't
parent 7304811f
......@@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "duke3d.h"
#include "microprofile.h"
#include "screens.h"
#if KRANDDEBUG
# define ACTOR_STATIC
......@@ -9117,8 +9118,8 @@ static void G_DoEventGame(int const nEventID)
void G_MoveWorld(void)
{
extern double g_moveActorsTime, g_moveWorldTime;
const double worldTime = timerGetFractionalTicks();
double worldTime = timerGetFractionalTicks();
auto framecnt = g_frameCounter;
MICROPROFILE_SCOPEI("Game", "MoveWorld", MP_YELLOW);
......@@ -9159,14 +9160,20 @@ void G_MoveWorld(void)
G_MoveMisc(); //ST 5
}
const double actorsTime = timerGetFractionalTicks();
double actorsTime = timerGetFractionalTicks();
auto framecnt2 = framecnt;
{
MICROPROFILE_SCOPEI("MoveWorld", "MoveActors", MP_YELLOW4);
G_MoveActors(); //ST 1
}
g_moveActorsTime = (1-0.033)*g_moveActorsTime + 0.033*(timerGetFractionalTicks()-actorsTime);
actorsTime = timerGetFractionalTicks() - actorsTime;
if (framecnt2 != framecnt)
actorsTime -= (double)g_lastFrameDuration2 * 1000.0 / (double)timerGetNanoTickRate();
g_moveActorsTime = (1-0.033)*g_moveActorsTime + 0.033*actorsTime;
// XXX: Has to be before effectors, in particular movers?
// TODO: lights in moving sectors ought to be interpolated
......@@ -9195,5 +9202,10 @@ void G_MoveWorld(void)
G_MoveFX(); //ST 11
}
g_moveWorldTime = (1-0.033)*g_moveWorldTime + 0.033*(timerGetFractionalTicks()-worldTime);
worldTime = timerGetFractionalTicks() - worldTime;
if (g_frameCounter != framecnt)
worldTime -= (double)g_lastFrameDuration2 * 1000.0 / (double)timerGetNanoTickRate();
g_moveWorldTime = (1-0.033)*g_moveWorldTime + 0.033*worldTime;
}
......@@ -6398,6 +6398,8 @@ static void drawframe_entry(mco_coro *co)
videoNextPage();
S_Update();
g_lastFrameEndTime2 = timerGetNanoTicks();
g_lastFrameDuration2 = g_lastFrameEndTime2 - g_lastFrameStartTime;
mco_yield(co);
} while (1);
}
......@@ -6985,6 +6987,7 @@ MAIN_LOOP_RESTART:
bool gameUpdate = false;
double gameUpdateStartTime = timerGetFractionalTicks();
auto framecnt = g_frameCounter;
if (((g_netClient || g_netServer) || (myplayer.gm & (MODE_MENU|MODE_DEMO)) == 0) && (int32_t)(totalclock - ototalclock) >= TICSPERFRAME)
{
......@@ -7017,12 +7020,18 @@ MAIN_LOOP_RESTART:
gameUpdate = true;
g_gameUpdateTime = timerGetFractionalTicks() - gameUpdateStartTime;
if (g_frameCounter != framecnt)
g_gameUpdateTime -= (double)g_lastFrameDuration * 1000.0 / (double)timerGetNanoTickRate();
if (g_gameUpdateAvgTime <= 0.0)
g_gameUpdateAvgTime = g_gameUpdateTime;
g_gameUpdateAvgTime
= ((GAMEUPDATEAVGTIMENUMSAMPLES - 1.f) * g_gameUpdateAvgTime + g_gameUpdateTime) / ((float)GAMEUPDATEAVGTIMENUMSAMPLES);
} while (0);
if (gameUpdate)
g_gameUpdateAndDrawTime = g_gameUpdateTime + (double)g_lastFrameDuration * 1000.0 / (double)timerGetNanoTickRate();
}
G_DoCheats();
......@@ -7055,9 +7064,6 @@ MAIN_LOOP_RESTART:
}
g_switchRoutine(co_drawframe);
if (gameUpdate)
g_gameUpdateAndDrawTime = timerGetFractionalTicks()-gameUpdateStartTime;
}
// handle CON_SAVE and CON_SAVENN
......
......@@ -166,6 +166,7 @@ G_EXTERN double g_gameUpdateAvgTime;
G_EXTERN mco_coro *co_drawframe;
G_EXTERN bool g_frameJustDrawn;
G_EXTERN uint64_t g_lastFrameStartTime, g_lastFrameEndTime, g_lastFrameDuration;
G_EXTERN uint64_t g_lastFrameEndTime2, g_lastFrameDuration2;
G_EXTERN uint32_t g_frameCounter;
G_EXTERN int g_restartFrameRoutine;
......
......@@ -781,9 +781,9 @@ static void G_ShowCacheLocks(void)
}
}
}
#define LOW_FPS ((videoGetRenderMode() == REND_CLASSIC) ? 35 : 50)
#define SLOW_FRAME_TIME 20
#define LOW_FPS (min<unsigned>((unsigned)(r_maxfps - 1), 59))
#define SLOW_VM_TIME 5
#define SLOW_FRAME_TIME (1000.0 / LOW_FPS - SLOW_VM_TIME)
#if defined GEKKO
# define FPS_YOFFSET 16
......@@ -848,17 +848,17 @@ static void G_PrintFPS(void)
printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+40+FPS_YOFFSET,
FPS_COLOR(maxGameUpdate >= SLOW_FRAME_TIME), -1, tempbuf, x);
chars = Bsprintf(tempbuf, "G_MoveActors(): %.3e ms", g_moveActorsTime);
chars = Bsprintf(tempbuf, "G_MoveActors(): %.3f ms", g_moveActorsTime);
printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+50+2+FPS_YOFFSET, 0, -1, tempbuf, x);
printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+50+FPS_YOFFSET,
COLOR_WHITE, -1, tempbuf, x);
FPS_COLOR(g_moveActorsTime >= SLOW_VM_TIME), -1, tempbuf, x);
chars = Bsprintf(tempbuf, "G_MoveWorld(): %.3e ms", g_moveWorldTime);
chars = Bsprintf(tempbuf, "G_MoveWorld(): %.3f ms", g_moveWorldTime);
printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+60+2+FPS_YOFFSET, 0, -1, tempbuf, x);
printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+60+FPS_YOFFSET,
COLOR_WHITE, -1, tempbuf, x);
FPS_COLOR(g_moveWorldTime >= SLOW_VM_TIME), -1, tempbuf, x);
}
// lag meter
......
......@@ -42,5 +42,6 @@ extern sprstat_t g_spriteStat;
extern int32_t dr_yxaspect, dr_viewingrange;
extern int32_t g_noLogoAnim, g_noLogo;
extern double g_moveActorsTime, g_moveWorldTime;
extern void G_FadePalette(int32_t r, int32_t g, int32_t b, int32_t e);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment