diff --git a/source/build/include/build.h b/source/build/include/build.h index 75999d0c1..1d6db2064 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -510,7 +510,7 @@ EXTERN char *palookup[MAXPALOOKUPS]; extern uint8_t *basepaltable[MAXBASEPALS]; EXTERN uint8_t paletteloaded; EXTERN char *blendtable[MAXBLENDTABS]; -EXTERN uint8_t whitecol, redcol; +EXTERN uint8_t whitecol, redcol, blackcol; EXTERN int32_t maxspritesonscreen; diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index c22fb15c5..578b6eb38 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -28,7 +28,6 @@ palette_t curpalette[256]; // the current palette, unadjusted for brightness o palette_t curpalettefaded[256]; // the current palette, adjusted for brightness and tint (ie. what gets sent to the card) palette_t palfadergb = { 0, 0, 0, 0 }; char palfadedelta = 0; -uint8_t blackcol; int32_t realmaxshade; float frealmaxshade; diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index c86ac9870..d3d90c9a6 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -2002,6 +2002,60 @@ static inline int32_t calc_smoothratio(ClockTicks totalclk, ClockTicks ototalclk return clamp(tabledivide64(65536*elapsedFrames*30, rfreq), 0, 65536); } +int r_showfps; + +#define COLOR_RED redcol +#define COLOR_WHITE whitecol + +#define LOW_FPS ((videoGetRenderMode() == REND_CLASSIC) ? 35 : 50) +#define SLOW_FRAME_TIME 20 + +#if defined GEKKO +# define FPS_YOFFSET 16 +#else +# define FPS_YOFFSET 0 +#endif + +#define FPS_COLOR(x) ((x) ? COLOR_RED : COLOR_WHITE) + +static void G_PrintFPS(void) +{ + static char tempbuf[256]; + static int32_t frameCount; + static double cumulativeFrameDelay; + static double lastFrameTime; + static float lastFPS, minFPS = std::numeric_limits::max(), maxFPS; + static double minGameUpdate = std::numeric_limits::max(), maxGameUpdate; + + double frameTime = timerGetHiTicks(); + double frameDelay = frameTime - lastFrameTime; + cumulativeFrameDelay += frameDelay; + + if (frameDelay >= 0) + { + int32_t x = (xdim <= 640); + + if (r_showfps) + { + int32_t chars = Bsprintf(tempbuf, "%.1f ms, %5.1f fps", frameDelay, lastFPS); + + printext256(windowxy2.x-(chars<<(3-x))+1, windowxy1.y+2+FPS_YOFFSET, blackcol, -1, tempbuf, x); + printext256(windowxy2.x-(chars<<(3-x)), windowxy1.y+1+FPS_YOFFSET, + FPS_COLOR(lastFPS < LOW_FPS), -1, tempbuf, x); + } + + if (cumulativeFrameDelay >= 1000.0) + { + lastFPS = 1000.f * frameCount / cumulativeFrameDelay; + // g_frameRate = Blrintf(lastFPS); + frameCount = 0; + cumulativeFrameDelay = 0.0; + } + frameCount++; + } + lastFrameTime = frameTime; +} + static void GameDisplay(void) { // End Section B @@ -2045,6 +2099,8 @@ static void GameDisplay(void) myprintext((320 - nLen) / 2, 100, "PAUSED", 0); } + G_PrintFPS(); + videoNextPage(); } diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index 083fc76a2..29bcd2b18 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -210,6 +210,7 @@ enum { }; extern char g_modDir[BMAX_PATH]; +extern int r_showfps; extern struct grpfile_t const* g_selectedGrp; diff --git a/source/exhumed/src/osdcmds.cpp b/source/exhumed/src/osdcmds.cpp index 648676dc9..c9ef98e42 100644 --- a/source/exhumed/src/osdcmds.cpp +++ b/source/exhumed/src/osdcmds.cpp @@ -615,7 +615,7 @@ int32_t registerosdcommands(void) //{ "r_camrefreshdelay", "minimum delay between security camera sprite updates, 120 = 1 second", (void *)&ud.camera_time, CVAR_INT, 1, 240 }, //{ "r_drawweapon", "enable/disable weapon drawing", (void *)&ud.drawweapon, CVAR_INT, 0, 2 }, - //{ "r_showfps", "show the frame rate counter", (void *)&ud.showfps, CVAR_INT, 0, 3 }, + { "r_showfps", "show the frame rate counter", (void *)&r_showfps, CVAR_INT, 0, 3 }, //{ "r_showfpsperiod", "time in seconds before averaging min and max stats for r_showfps 2+", (void *)&ud.frameperiod, CVAR_INT, 0, 5 }, //{ "r_shadows", "enable/disable sprite and model shadows", (void *)&ud.shadows, CVAR_BOOL, 0, 1 }, //{ "r_size", "change size of viewable area", (void *)&ud.screen_size, CVAR_INT|CVAR_FUNCPTR, 0, 64 },