FPS Counter and debug overlay CVAR

This commit is contained in:
SirMangler 2021-01-03 19:00:32 +00:00
parent 9d78305360
commit 7fb4c45046
3 changed files with 28 additions and 0 deletions

View File

@ -66,6 +66,9 @@ void ViewManager::TestGameView::think() {
if (m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean()) if (m_cvarCommons.m_debugOverlayShowFrameCounter->toBoolean())
overlayText += fmt::format(FMT_STRING("Frame: {}\n"), g_StateManager->GetUpdateFrameIndex()); overlayText += fmt::format(FMT_STRING("Frame: {}\n"), g_StateManager->GetUpdateFrameIndex());
if (m_cvarCommons.m_debugOverlayShowFramerate->toBoolean())
overlayText += fmt::format(FMT_STRING("FPS: {}\n"), urde::CGraphics::GetFPS());
if (m_cvarCommons.m_debugOverlayShowInGameTime->toBoolean()) { if (m_cvarCommons.m_debugOverlayShowInGameTime->toBoolean()) {
double igt = g_GameState->GetTotalPlayTime(); double igt = g_GameState->GetTotalPlayTime();
u32 ms = u64(igt * 1000) % 1000; u32 ms = u64(igt * 1000) % 1000;

View File

@ -34,6 +34,9 @@ SViewport g_Viewport = {
0, 0, 640, 480, 640 / 2.f, 480 / 2.f, 0.0f, 0, 0, 640, 480, 640 / 2.f, 480 / 2.f, 0.0f,
}; };
u32 CGraphics::g_FrameCounter = 0; u32 CGraphics::g_FrameCounter = 0;
u32 CGraphics::g_Framerate = 0;
u32 CGraphics::g_FramesPast = 0;
frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now();
const std::array<zeus::CMatrix3f, 6> CGraphics::skCubeBasisMats{{ const std::array<zeus::CMatrix3f, 6> CGraphics::skCubeBasisMats{{
/* Right */ /* Right */
@ -126,6 +129,8 @@ void CGraphics::EndScene() {
CLineRenderer::UpdateBuffers(); CLineRenderer::UpdateBuffers();
++g_FrameCounter; ++g_FrameCounter;
UpdateFPSCounter();
} }
void CGraphics::SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1) {} void CGraphics::SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1) {}
@ -444,6 +449,18 @@ void CGraphics::TickRenderTimings() {
g_DefaultSeconds = g_RenderTimings / 60.f; g_DefaultSeconds = g_RenderTimings / 60.f;
} }
static constexpr u64 FPS_REFRESH_RATE = 1000;
void CGraphics::UpdateFPSCounter() {
++g_FramesPast;
std::chrono::duration<double, std::milli> timeElapsed = frame_clock::now() - g_FrameStartTime;
if (timeElapsed.count() > FPS_REFRESH_RATE) {
g_Framerate = g_FramesPast;
g_FrameStartTime = frame_clock::now();
g_FramesPast = 0;
}
}
boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null; boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null;
boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr; boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr; boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;

View File

@ -2,6 +2,7 @@
#include <array> #include <array>
#include <vector> #include <vector>
#include <chrono>
#include "Runtime/RetroTypes.hpp" #include "Runtime/RetroTypes.hpp"
@ -18,6 +19,8 @@
#include <zeus/CVector2i.hpp> #include <zeus/CVector2i.hpp>
#include <zeus/CVector2f.hpp> #include <zeus/CVector2f.hpp>
using frame_clock = std::chrono::high_resolution_clock;
namespace urde { namespace urde {
extern hecl::CVar* g_disableLighting; extern hecl::CVar* g_disableLighting;
class CLight; class CLight;
@ -309,7 +312,12 @@ public:
static float GetSecondsMod900(); static float GetSecondsMod900();
static void TickRenderTimings(); static void TickRenderTimings();
static u32 g_FrameCounter; static u32 g_FrameCounter;
static u32 g_Framerate;
static u32 g_FramesPast;
static frame_clock::time_point g_FrameStartTime;
static u32 GetFrameCounter() { return g_FrameCounter; } static u32 GetFrameCounter() { return g_FrameCounter; }
static u32 GetFPS() { return g_Framerate; }
static void UpdateFPSCounter();
static boo::IGraphicsDataFactory::Platform g_BooPlatform; static boo::IGraphicsDataFactory::Platform g_BooPlatform;
static const boo::SystemChar* g_BooPlatformName; static const boo::SystemChar* g_BooPlatformName;