mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 17:01:51 +00:00
- Unify stat fps
for all games.
This commit is contained in:
parent
59a964bb83
commit
e32cd81cc7
16 changed files with 86 additions and 196 deletions
|
@ -76,9 +76,6 @@ int gNetPlayers;
|
|||
|
||||
int gChokeCounter = 0;
|
||||
|
||||
double g_gameUpdateTime, g_gameUpdateAndDrawTime;
|
||||
double g_gameUpdateAvgTime = 0.001;
|
||||
|
||||
bool gQuitGame;
|
||||
int gQuitRequest;
|
||||
|
||||
|
@ -572,11 +569,19 @@ void ProcessFrame(void)
|
|||
if (paused || gEndGameMgr.at0 || (gGameOptions.nGameType == 0 && M_Active()))
|
||||
return;
|
||||
}
|
||||
|
||||
thinktime.Reset();
|
||||
thinktime.Clock();
|
||||
|
||||
actortime.Reset();
|
||||
actortime.Clock();
|
||||
for (int i = connecthead; i >= 0; i = connectpoint2[i])
|
||||
{
|
||||
viewBackupView(i);
|
||||
playerProcess(&gPlayer[i]);
|
||||
}
|
||||
actortime.Unclock();
|
||||
|
||||
trProcessBusy();
|
||||
evProcess(gFrameClock);
|
||||
seqProcess(4);
|
||||
|
@ -602,6 +607,9 @@ void ProcessFrame(void)
|
|||
gChokeCounter -= COUNTRATE;
|
||||
}
|
||||
}
|
||||
|
||||
thinktime.Unclock();
|
||||
|
||||
gLevelTime++;
|
||||
gFrameCount++;
|
||||
gFrameClock += 4;
|
||||
|
@ -792,6 +800,9 @@ static void gameTicker()
|
|||
int const currentTic = I_GetTime();
|
||||
gameclock = I_GetBuildTime();
|
||||
|
||||
gameupdatetime.Reset();
|
||||
gameupdatetime.Clock();
|
||||
|
||||
while (currentTic - lastTic >= 1 && ready2send)
|
||||
{
|
||||
gNetInput = gInput;
|
||||
|
@ -810,21 +821,19 @@ static void gameTicker()
|
|||
gameUpdate = true;
|
||||
}
|
||||
}
|
||||
if (gameUpdate)
|
||||
{
|
||||
g_gameUpdateTime = I_msTimeF() - gameUpdateStartTime;
|
||||
if (g_gameUpdateAvgTime < 0.f)
|
||||
g_gameUpdateAvgTime = g_gameUpdateTime;
|
||||
g_gameUpdateAvgTime = ((GAMEUPDATEAVGTIMENUMSAMPLES - 1.f) * g_gameUpdateAvgTime + g_gameUpdateTime) / ((float)GAMEUPDATEAVGTIMENUMSAMPLES);
|
||||
}
|
||||
|
||||
gameupdatetime.Unclock();
|
||||
|
||||
if (gQuitRequest && gQuitGame)
|
||||
videoClearScreen(0);
|
||||
else
|
||||
{
|
||||
netCheckSync();
|
||||
auto beforeSwapTime = I_msTimeF();
|
||||
|
||||
drawtime.Reset();
|
||||
drawtime.Clock();
|
||||
viewDrawScreen();
|
||||
g_gameUpdateAndDrawTime = beforeSwapTime/* I_msTimeF()*/ - gameUpdateStartTime;
|
||||
drawtime.Unclock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,9 +84,6 @@ extern INICHAIN *pINIChain;
|
|||
extern short BloodVersion;
|
||||
extern int gNetPlayers;
|
||||
extern bool gRestartGame;
|
||||
#define GAMEUPDATEAVGTIMENUMSAMPLES 100
|
||||
extern double g_gameUpdateTime, g_gameUpdateAndDrawTime;
|
||||
extern double g_gameUpdateAvgTime;
|
||||
extern int blood_globalflags;
|
||||
|
||||
extern bool gSavingGame;
|
||||
|
@ -110,7 +107,6 @@ struct GameInterface : ::GameInterface
|
|||
void RunGameFrame() override;
|
||||
bool GenerateSavePic() override;
|
||||
void FreeGameData() override;
|
||||
FString statFPS() override;
|
||||
FSavegameInfo GetSaveSig() override;
|
||||
void MenuOpened() override;
|
||||
void MenuClosed() override;
|
||||
|
|
|
@ -1089,86 +1089,6 @@ bool GameInterface::GenerateSavePic()
|
|||
# define FPS_YOFFSET 0
|
||||
#endif
|
||||
|
||||
FString GameInterface::statFPS(void)
|
||||
{
|
||||
FString output;
|
||||
static int32_t frameCount;
|
||||
static double cumulativeFrameDelay;
|
||||
static double lastFrameTime;
|
||||
static float lastFPS, minFPS = FLT_MAX, maxFPS;
|
||||
static double minGameUpdate = DBL_MAX, maxGameUpdate;
|
||||
|
||||
double frameTime = I_msTimeF();
|
||||
double frameDelay = frameTime - lastFrameTime;
|
||||
cumulativeFrameDelay += frameDelay;
|
||||
|
||||
if (frameDelay >= 0)
|
||||
{
|
||||
int32_t x = (xdim <= 640);
|
||||
|
||||
//if (r_showfps)
|
||||
{
|
||||
output.AppendFormat("%.1f ms, %5.1f fps\n", frameDelay, lastFPS);
|
||||
|
||||
if (r_showfps > 1)
|
||||
{
|
||||
output.AppendFormat("max: %5.1f fps\n", maxFPS);
|
||||
output.AppendFormat("min: %5.1f fps\n", minFPS);
|
||||
}
|
||||
if (r_showfps > 2)
|
||||
{
|
||||
if (g_gameUpdateTime > maxGameUpdate) maxGameUpdate = g_gameUpdateTime;
|
||||
if (g_gameUpdateTime < minGameUpdate) minGameUpdate = g_gameUpdateTime;
|
||||
|
||||
output.AppendFormat("Game Update: %2.2f ms + draw: %2.2f ms\n", g_gameUpdateTime, g_gameUpdateAndDrawTime - g_gameUpdateTime);
|
||||
output.AppendFormat("GU min/max/avg: %5.2f/%5.2f/%5.2f ms\n", minGameUpdate, maxGameUpdate, g_gameUpdateAvgTime);
|
||||
|
||||
output.AppendFormat("bufferjitter: %i\n", gBufferJitter);
|
||||
#if 0
|
||||
output.AppendFormat("G_MoveActors(): %.3f ms\n", g_moveActorsTime);
|
||||
output.AppendFormat("G_MoveWorld(): %.3f ms\n", g_moveWorldTime);
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
// lag meter
|
||||
if (g_netClientPeer)
|
||||
{
|
||||
output.AppendFormat("%d +- %d ms\n", (g_netClientPeer->lastRoundTripTime + g_netClientPeer->roundTripTime)/2,
|
||||
(g_netClientPeer->lastRoundTripTimeVariance + g_netClientPeer->roundTripTimeVariance)/2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (cumulativeFrameDelay >= 1000.0)
|
||||
{
|
||||
lastFPS = 1000.f * frameCount / cumulativeFrameDelay;
|
||||
g_frameRate = Blrintf(lastFPS);
|
||||
frameCount = 0;
|
||||
cumulativeFrameDelay = 0.0;
|
||||
|
||||
if (r_showfps > 1)
|
||||
{
|
||||
if (lastFPS > maxFPS) maxFPS = lastFPS;
|
||||
if (lastFPS < minFPS) minFPS = lastFPS;
|
||||
|
||||
static int secondCounter;
|
||||
|
||||
if (++secondCounter >= r_showfpsperiod)
|
||||
{
|
||||
maxFPS = (lastFPS + maxFPS) * .5f;
|
||||
minFPS = (lastFPS + minFPS) * .5f;
|
||||
maxGameUpdate = (g_gameUpdateTime + maxGameUpdate) * 0.5;
|
||||
minGameUpdate = (g_gameUpdateTime + minGameUpdate) * 0.5;
|
||||
secondCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
frameCount++;
|
||||
}
|
||||
lastFrameTime = frameTime;
|
||||
return output;
|
||||
}
|
||||
|
||||
FString GameInterface::GetCoordString()
|
||||
{
|
||||
return "Player pos is unknown"; // todo: output at least something useful.
|
||||
|
|
|
@ -927,6 +927,12 @@ static void updatePauseStatus()
|
|||
paused ? S_PauseSound(!pausedWithKey, !paused) : S_ResumeSound(paused);
|
||||
}
|
||||
|
||||
static void checkTimerActive()
|
||||
{
|
||||
FStat *stat = FStat::FindStat("fps");
|
||||
glcycle_t::active = (stat != NULL && stat->isActive());
|
||||
}
|
||||
|
||||
|
||||
void app_loop()
|
||||
{
|
||||
|
@ -944,6 +950,7 @@ void app_loop()
|
|||
handleevents();
|
||||
updatePauseStatus();
|
||||
D_ProcessEvents();
|
||||
checkTimerActive();
|
||||
|
||||
gi->RunGameFrame();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m
|
|||
#include <stdint.h>
|
||||
#include "vectors.h"
|
||||
#include "engineerrors.h"
|
||||
#include "stats.h"
|
||||
|
||||
struct GameStats
|
||||
{
|
||||
|
@ -53,6 +54,8 @@ struct ReservedSpace
|
|||
|
||||
enum EMenuSounds : int;
|
||||
|
||||
extern glcycle_t drawtime, actortime, thinktime, gameupdatetime;
|
||||
|
||||
struct GameInterface
|
||||
{
|
||||
virtual const char* Name() { return "$"; }
|
||||
|
@ -64,7 +67,6 @@ struct GameInterface
|
|||
virtual void UpdateScreenSize() {}
|
||||
virtual void FreeGameData() {}
|
||||
virtual void PlayHudSound() {}
|
||||
virtual FString statFPS() { return "FPS display not available"; }
|
||||
virtual GameStats getStats() { return {}; }
|
||||
virtual void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) {}
|
||||
virtual void MainMenuOpened() {}
|
||||
|
@ -91,6 +93,17 @@ struct GameInterface
|
|||
virtual void ExitFromMenu() { throw CExitEvent(0); }
|
||||
virtual ReservedSpace GetReservedScreenSpace(int viewsize) { return { 0, 0 }; }
|
||||
virtual void ResetFollowPos(bool) {}
|
||||
virtual FString statFPS()
|
||||
{
|
||||
FString output;
|
||||
|
||||
output.AppendFormat("Actor think time: %.3f ms\n", actortime.TimeMS());
|
||||
output.AppendFormat("Total think time: %.3f ms\n", thinktime.TimeMS());
|
||||
output.AppendFormat("Game Update: %.3f ms\n", gameupdatetime.TimeMS());
|
||||
output.AppendFormat("Draw time: %.3f ms\n", drawtime.TimeMS());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -382,36 +382,6 @@ double calc_smoothratio()
|
|||
return I_GetTimeFrac() * MaxSmoothRatio;
|
||||
}
|
||||
|
||||
FString GameInterface::statFPS()
|
||||
{
|
||||
FString out;
|
||||
static int32_t frameCount;
|
||||
static double cumulativeFrameDelay;
|
||||
static double lastFrameTime;
|
||||
static float lastFPS; // , minFPS = std::numeric_limits<float>::max(), maxFPS;
|
||||
//static double minGameUpdate = std::numeric_limits<double>::max(), maxGameUpdate;
|
||||
|
||||
double frameTime = I_msTimeF();
|
||||
double frameDelay = frameTime - lastFrameTime;
|
||||
cumulativeFrameDelay += frameDelay;
|
||||
|
||||
if (frameDelay >= 0)
|
||||
{
|
||||
out.Format("%.1f ms, %5.1f fps", frameDelay, lastFPS);
|
||||
|
||||
if (cumulativeFrameDelay >= 1000.0)
|
||||
{
|
||||
lastFPS = 1000.f * frameCount / cumulativeFrameDelay;
|
||||
// g_frameRate = Blrintf(lastFPS);
|
||||
frameCount = 0;
|
||||
cumulativeFrameDelay = 0.0;
|
||||
}
|
||||
frameCount++;
|
||||
}
|
||||
lastFrameTime = frameTime;
|
||||
return out;
|
||||
}
|
||||
|
||||
void GameMove(void)
|
||||
{
|
||||
FixPalette();
|
||||
|
@ -477,6 +447,9 @@ void GameTicker()
|
|||
}
|
||||
else
|
||||
{
|
||||
gameupdatetime.Reset();
|
||||
gameupdatetime.Clock();
|
||||
|
||||
while (!EndLevel && currentTic - lastTic >= 1)
|
||||
{
|
||||
lastTic = currentTic;
|
||||
|
@ -487,8 +460,7 @@ void GameTicker()
|
|||
nPlayerDAng = fix16_sadd(nPlayerDAng, localInput.q16avel);
|
||||
inita &= kAngleMask;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
lPlayerXVel += localInput.fvel * Cos(inita) + localInput.svel * Sin(inita);
|
||||
lPlayerYVel += localInput.fvel * Sin(inita) - localInput.svel * Cos(inita);
|
||||
|
@ -513,6 +485,9 @@ void GameTicker()
|
|||
leveltime++;
|
||||
GameMove();
|
||||
}
|
||||
|
||||
gameupdatetime.Unclock();
|
||||
|
||||
if (nPlayerLives[nLocalPlayer] <= 0) {
|
||||
startmainmenu();
|
||||
}
|
||||
|
|
|
@ -291,7 +291,6 @@ struct GameInterface : ::GameInterface
|
|||
void clearlocalinputstate() override;
|
||||
void QuitToTitle() override;
|
||||
|
||||
FString statFPS() override;
|
||||
::GameStats getStats() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -114,6 +114,9 @@ static void showmap(short nLevel, short nLevelNew, short nLevelBest, TArray<JobD
|
|||
|
||||
static void GameDisplay(void)
|
||||
{
|
||||
drawtime.Reset();
|
||||
drawtime.Clock();
|
||||
|
||||
if (currentLevel->levelNumber == kMap20)
|
||||
{
|
||||
DoEnergyTile();
|
||||
|
@ -128,6 +131,8 @@ static void GameDisplay(void)
|
|||
int nStringWidth = SmallFont->StringWidth(tex);
|
||||
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
|
||||
}
|
||||
|
||||
drawtime.Unclock();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -160,6 +160,9 @@ signed int lsqrt(int a1)
|
|||
|
||||
void MoveThings()
|
||||
{
|
||||
thinktime.Reset();
|
||||
thinktime.Clock();
|
||||
|
||||
UndoFlashes();
|
||||
DoLights();
|
||||
|
||||
|
@ -171,8 +174,11 @@ void MoveThings()
|
|||
}
|
||||
else
|
||||
{
|
||||
actortime.Reset();
|
||||
actortime.Clock();
|
||||
runlist_ExecObjects();
|
||||
runlist_CleanRunRecs();
|
||||
actortime.Unclock();
|
||||
}
|
||||
|
||||
MoveStatus();
|
||||
|
@ -190,6 +196,8 @@ void MoveThings()
|
|||
BendAmbientSound();
|
||||
}
|
||||
}
|
||||
|
||||
thinktime.Unclock();
|
||||
}
|
||||
|
||||
void ResetMoveFifo()
|
||||
|
|
|
@ -19,11 +19,8 @@
|
|||
#include "rts.h"
|
||||
#include "sounds.h"
|
||||
#include "soundefs.h"
|
||||
#include "stats.h"
|
||||
#include "binaryangle.h"
|
||||
|
||||
extern glcycle_t drawtime, actortime, thinktime, gameupdatetime;
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
extern FFont* IndexFont;
|
||||
|
@ -37,7 +34,6 @@ struct GameInterface : public ::GameInterface
|
|||
void clearlocalinputstate() override;
|
||||
bool GenerateSavePic() override;
|
||||
void PlayHudSound() override;
|
||||
FString statFPS() override;
|
||||
GameStats getStats() override;
|
||||
void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override;
|
||||
void MenuOpened() override;
|
||||
|
|
|
@ -74,24 +74,6 @@ GameStats GameInterface::getStats()
|
|||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
FString GameInterface::statFPS()
|
||||
{
|
||||
FString output;
|
||||
|
||||
output.AppendFormat("Actor think time: %.3f ms\n", actortime.TimeMS());
|
||||
output.AppendFormat("Total think time: %.3f ms\n", thinktime.TimeMS());
|
||||
output.AppendFormat("Game Update: %.3f ms\n", gameupdatetime.TimeMS());
|
||||
output.AppendFormat("Draw time: %.3f ms\n", drawtime.TimeMS());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
|
|
|
@ -296,18 +296,6 @@ int moveloop()
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static void checkTimerActive()
|
||||
{
|
||||
FStat *stat = FStat::FindStat("fps");
|
||||
glcycle_t::active = (stat != NULL && stat->isActive());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool GameTicker()
|
||||
{
|
||||
if (ps[myconnectindex].gm == MODE_DEMO)
|
||||
|
@ -319,7 +307,6 @@ bool GameTicker()
|
|||
//Net_GetPackets();
|
||||
|
||||
nonsharedkeys();
|
||||
checkTimerActive();
|
||||
|
||||
gameupdatetime.Reset();
|
||||
gameupdatetime.Clock();
|
||||
|
@ -353,8 +340,6 @@ bool GameTicker()
|
|||
}
|
||||
}
|
||||
|
||||
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
|
||||
|
||||
gameupdatetime.Unclock();
|
||||
|
||||
if (ps[myconnectindex].gm & (MODE_EOL | MODE_RESTART))
|
||||
|
@ -367,9 +352,11 @@ bool GameTicker()
|
|||
GetInput();
|
||||
}
|
||||
|
||||
S_Update();
|
||||
|
||||
drawtime.Reset();
|
||||
drawtime.Clock();
|
||||
S_Update();
|
||||
double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio;
|
||||
displayrooms(screenpeek, smoothRatio);
|
||||
displayrest(smoothRatio);
|
||||
drawtime.Unclock();
|
||||
|
|
|
@ -1189,28 +1189,6 @@ CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nq16ang, short horiz)
|
|||
*nq16ang = fix16_from_int(ang);
|
||||
}
|
||||
|
||||
FString GameInterface::statFPS()
|
||||
{
|
||||
#define AVERAGEFRAMES 16
|
||||
static int frameval[AVERAGEFRAMES], framecnt = 0;
|
||||
int i;
|
||||
|
||||
FString out;
|
||||
//if (LocationInfo)
|
||||
{
|
||||
|
||||
i = gameclock;
|
||||
if (i != frameval[framecnt])
|
||||
{
|
||||
out.AppendFormat("FPS: %d\n", ((120 * AVERAGEFRAMES) / (i - frameval[framecnt])) + f_c);
|
||||
frameval[framecnt] = i;
|
||||
}
|
||||
|
||||
framecnt = ((framecnt + 1) & (AVERAGEFRAMES - 1));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
FString GameInterface::GetCoordString()
|
||||
{
|
||||
PLAYERp pp = Player + myconnectindex;
|
||||
|
|
|
@ -776,6 +776,9 @@ void GameTicker(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
gameupdatetime.Reset();
|
||||
gameupdatetime.Clock();
|
||||
|
||||
while (ready2send && currentTic - lastTic >= 1)
|
||||
{
|
||||
lastTic = currentTic;
|
||||
|
@ -784,14 +787,20 @@ void GameTicker(void)
|
|||
MoveTicker();
|
||||
}
|
||||
|
||||
smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
|
||||
gameupdatetime.Unclock();
|
||||
|
||||
// Get input again to update q16ang/q16horiz.
|
||||
if (!PedanticMode)
|
||||
getinput(&loc, TRUE);
|
||||
|
||||
smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
|
||||
}
|
||||
|
||||
drawtime.Reset();
|
||||
drawtime.Clock();
|
||||
drawscreen(Player + screenpeek, smoothratio);
|
||||
drawtime.Unclock();
|
||||
|
||||
ready2send = 0;
|
||||
}
|
||||
if (ExitLevel)
|
||||
|
|
|
@ -2308,7 +2308,6 @@ struct GameInterface : ::GameInterface
|
|||
void QuitToTitle() override;
|
||||
void ResetFollowPos(bool message) override;
|
||||
|
||||
FString statFPS() override;
|
||||
GameStats getStats() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -7666,6 +7666,9 @@ domovethings(void)
|
|||
|
||||
PlayClock += synctics;
|
||||
|
||||
thinktime.Reset();
|
||||
thinktime.Clock();
|
||||
|
||||
DoAnim(synctics);
|
||||
|
||||
// should pass pnum and use syncbits
|
||||
|
@ -7681,6 +7684,8 @@ domovethings(void)
|
|||
|
||||
SpriteControl();
|
||||
|
||||
actortime.Reset();
|
||||
actortime.Clock();
|
||||
TRAVERSE_CONNECT(pnum)
|
||||
{
|
||||
extern short screenpeek;
|
||||
|
@ -7743,13 +7748,15 @@ domovethings(void)
|
|||
DoPlayerSectorUpdatePostMove(pp);
|
||||
PlayerGlobal(pp);
|
||||
}
|
||||
|
||||
actortime.Unclock();
|
||||
|
||||
MultiPlayLimits();
|
||||
|
||||
//if (MoveSkip8 == 0) // 8=5x 4=10x, 2=20x, 0=40x per second
|
||||
DoUpdateSounds();
|
||||
|
||||
thinktime.Unclock();
|
||||
|
||||
CorrectPrediction(movefifoplc - 1);
|
||||
|
||||
if (FinishTimer)
|
||||
|
|
Loading…
Reference in a new issue