imgui: move fps updater functions into imgui ui class

This commit is contained in:
RadWolfie 2021-06-30 14:32:30 -05:00
parent b11cb57b0b
commit e1a8391170
5 changed files with 41 additions and 39 deletions

View File

@ -45,6 +45,11 @@ bool ImGuiUI::Initialize()
g_EmuShared->GetOverlaySettings(&m_settings);
g_EmuShared->GetFlagsLLE(&m_lle_flags);
// Internal initialize (when necessary, move into its own function.)
fps_counter = 30.0f;
// Miscs
m_audio.Initialize();
m_video.Initialize();
@ -76,6 +81,36 @@ void ImGuiUI::ToggleImGui()
g_EmuShared->SetImGuiFocusFlag(m_is_focus);
}
static clock_t g_DeltaTime = 0; // Used for benchmarking/fps count
static unsigned int g_Frames = 0;
// ******************************************************************
// * update the current milliseconds per frame
// ******************************************************************
void ImGuiUI::UpdateCurrentMSpFAndFPS() {
if (g_EmuShared) {
fps_counter = (float)(g_Frames * 0.5 + fps_counter * 0.5);
g_EmuShared->SetCurrentFPS(&fps_counter);
}
}
void ImGuiUI::UpdateFPSCounter()
{
static clock_t lastDrawFunctionCallTime = 0;
clock_t currentDrawFunctionCallTime = clock();
g_DeltaTime += currentDrawFunctionCallTime - lastDrawFunctionCallTime;
lastDrawFunctionCallTime = currentDrawFunctionCallTime;
g_Frames++;
if (g_DeltaTime >= CLOCKS_PER_SEC) {
UpdateCurrentMSpFAndFPS();
g_Frames = 0;
g_DeltaTime -= CLOCKS_PER_SEC;
}
}
void ImGuiUI::DrawMenu()
{
if (!m_is_focus) {
@ -116,9 +151,6 @@ void ImGuiUI::DrawWidgets()
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing)) {
if (m_settings.fps) {
float fps_counter;
g_EmuShared->GetCurrentFPS(&fps_counter);
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "FPS: %.2f MS / F : %.2f", fps_counter, (float)(1000.0 / fps_counter));
}

View File

@ -28,6 +28,7 @@ public:
void ToggleImGui();
bool IsImGuiFocus();
void UpdateFPSCounter();
void DrawMenu();
void DrawWidgets();
@ -48,6 +49,8 @@ protected:
callback(this, arg);
}
void UpdateCurrentMSpFAndFPS();
std::mutex m_imgui_mutex;
ImGuiContext* m_imgui_context;
char m_file_path[FILENAME_MAX+1];
@ -57,6 +60,7 @@ protected:
ImGuiVideo m_video;
overlay_settings m_settings;
unsigned int m_lle_flags;
float fps_counter;
// Make them as settings storage.
/*bool m_show_fps;
bool m_show_LLE_stats;

View File

@ -223,8 +223,6 @@ static inline void EmuVerifyResourceIsRegistered(xbox::X_D3DRes
static void UpdateCurrentMSpFAndFPS(); // Used for benchmarking/fps count
static void CxbxImpl_SetRenderTarget(xbox::X_D3DSurface *pRenderTarget, xbox::X_D3DSurface *pNewZStencil);
extern void UpdateFPSCounter();
#define CXBX_D3DCOMMON_IDENTIFYING_MASK (X_D3DCOMMON_TYPE_MASK | X_D3DCOMMON_D3DCREATED)
@ -5483,7 +5481,7 @@ xbox::dword_xt WINAPI xbox::EMUPATCH(D3DDevice_Swap)
frameStartTime = std::chrono::steady_clock::now();
UpdateFPSCounter();
g_renderbase->UpdateFPSCounter();
if (Flags == CXBX_SWAP_PRESENT_FORWARD) // Only do this when forwarded from Present
{

View File

@ -2055,34 +2055,3 @@ void CxbxKrnlPanic()
{
CxbxKrnlCleanup("Kernel Panic!");
}
static clock_t g_DeltaTime = 0; // Used for benchmarking/fps count
static unsigned int g_Frames = 0;
// ******************************************************************
// * update the current milliseconds per frame
// ******************************************************************
static void UpdateCurrentMSpFAndFPS() {
if (g_EmuShared) {
static float currentFPSVal = 30;
currentFPSVal = (float)(g_Frames*0.5 + currentFPSVal * 0.5);
g_EmuShared->SetCurrentFPS(&currentFPSVal);
}
}
void UpdateFPSCounter()
{
static clock_t lastDrawFunctionCallTime = 0;
clock_t currentDrawFunctionCallTime = clock();
g_DeltaTime += currentDrawFunctionCallTime - lastDrawFunctionCallTime;
lastDrawFunctionCallTime = currentDrawFunctionCallTime;
g_Frames++;
if (g_DeltaTime >= CLOCKS_PER_SEC) {
UpdateCurrentMSpFAndFPS();
g_Frames = 0;
g_DeltaTime -= CLOCKS_PER_SEC;
}
}

View File

@ -1040,7 +1040,6 @@ void cxbx_gl_render_overlays(NV2AState *d)
}
}
extern void UpdateFPSCounter();
void NV2ADevice::UpdateHostDisplay(NV2AState *d)
{
PGRAPHState *pg = &d->pgraph;
@ -1096,7 +1095,7 @@ void NV2ADevice::UpdateHostDisplay(NV2AState *d)
// glo_set_current(NULL);
UpdateFPSCounter();
g_renderbase->UpdateFPSCounter();
}
// TODO: Fix this properly