1
0
mirror of synced 2024-11-12 10:10:53 +01:00

fix: ImHex using way too much resources still

Now frames are rendered at only 5 FPS if no input events are being processed. Thanks a lot to @Tey. Properly fixes #189 now
This commit is contained in:
WerWolv 2021-07-27 21:50:49 +02:00
parent d4e484e982
commit af1d687758
2 changed files with 4 additions and 4 deletions

View File

@ -7,7 +7,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Interface::addFooterItem([] { ContentRegistry::Interface::addFooterItem([] {
static float framerate = 0; static float framerate = 0;
if (ImGui::HasSecondPassed()) { if (ImGui::HasSecondPassed()) {
framerate = ImGui::GetIO().Framerate; framerate = 1.0F / ImGui::GetIO().DeltaTime;
} }
ImGui::TextUnformatted(hex::format("FPS {0:.2f}", framerate).c_str()); ImGui::TextUnformatted(hex::format("FPS {0:.2f}", framerate).c_str());

View File

@ -187,8 +187,9 @@ namespace hex {
while (!glfwWindowShouldClose(this->m_window)) { while (!glfwWindowShouldClose(this->m_window)) {
if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED)) if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED))
glfwWaitEvents(); glfwWaitEvents();
else
glfwWaitEventsTimeout(this->m_lastFrameTime - glfwGetTime() + 1 / 5.0);
glfwPollEvents();
this->frameBegin(); this->frameBegin();
this->frame(); this->frame();
@ -407,7 +408,7 @@ namespace hex {
glfwSwapBuffers(this->m_window); glfwSwapBuffers(this->m_window);
std::this_thread::sleep_for(std::chrono::milliseconds(u64((this->m_lastFrameTime + 1 / (ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow) ? this->m_targetFps : 5.0) - glfwGetTime()) * 1000))); std::this_thread::sleep_for(std::chrono::milliseconds(u64((this->m_lastFrameTime + 1 / this->m_targetFps - glfwGetTime()) * 1000)));
this->m_lastFrameTime = glfwGetTime(); this->m_lastFrameTime = glfwGetTime();
} }
@ -661,7 +662,6 @@ namespace hex {
EventManager::post<EventWindowClosing>(window); EventManager::post<EventWindowClosing>(window);
}); });
glfwSetWindowSizeLimits(this->m_window, 720, 480, GLFW_DONT_CARE, GLFW_DONT_CARE); glfwSetWindowSizeLimits(this->m_window, 720, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);
if (gladLoadGL() == 0) if (gladLoadGL() == 0)