SDL: Add a shoddy FPS counter

This commit is contained in:
Connor McLaughlin 2019-09-26 21:44:02 +10:00
parent 2a63dbce64
commit e9bb3d79b8
3 changed files with 43 additions and 6 deletions

View File

@ -388,10 +388,12 @@ void SDLInterface::RenderDisplay()
void SDLInterface::RenderImGui()
{
RenderMainMenuBar();
RenderOSDMessages();
m_system->RenderUI();
RenderOSDMessages();
RenderFPS();
ImGui::Render();
}
@ -512,6 +514,27 @@ void SDLInterface::RenderOSDMessages()
}
}
void SDLInterface::RenderFPS()
{
// Position in the top-right corner of the screen.
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - 2.0f, 2.0f), ImGuiCond_Always, ImVec2(1.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::SetNextWindowSize(ImVec2(80.0f, 20.0f));
if (ImGui::Begin("FPS", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoBackground))
{
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "FPS: %.2f", m_fps);
}
ImGui::End();
ImGui::PopStyleVar(2);
}
void SDLInterface::DoLoadState(u32 index)
{
LoadState(GetSaveStateFilename(index));
@ -538,6 +561,19 @@ void SDLInterface::Run()
}
m_system->RunFrame();
// update fps counter
{
m_fps_counter++;
const double time = m_fps_timer.GetTimeSeconds();
if (time > 0.1)
{
m_fps = static_cast<float>(m_fps_counter / time);
m_fps_counter = 0;
m_fps_timer.Reset();
}
}
Render();
}
}

View File

@ -57,6 +57,7 @@ private:
void RenderDisplay();
void RenderMainMenuBar();
void RenderOSDMessages();
void RenderFPS();
SDL_Window* m_window = nullptr;
SDL_GLContext m_gl_context = nullptr;
@ -76,4 +77,8 @@ private:
std::mutex m_osd_messages_lock;
std::shared_ptr<DigitalController> m_controller;
float m_fps = 0.0f;
u32 m_fps_counter = 0;
Timer m_fps_timer;
};

View File

@ -753,11 +753,7 @@ bool GPU::HandleCopyRectangleVRAMToVRAMCommand()
return true;
}
void GPU::UpdateDisplay()
{
m_render_state.texture_changed = true;
m_system->IncrementFrameNumber();
}
void GPU::UpdateDisplay() {}
void GPU::ReadVRAM(u32 x, u32 y, u32 width, u32 height, void* buffer) {}