From af1d6877580e981361c5ae465c30b232e37ae991 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 27 Jul 2021 21:50:49 +0200 Subject: [PATCH] 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 --- plugins/builtin/source/content/footer_items.cpp | 2 +- source/window.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/builtin/source/content/footer_items.cpp b/plugins/builtin/source/content/footer_items.cpp index 5bd38ed18..39862a75c 100644 --- a/plugins/builtin/source/content/footer_items.cpp +++ b/plugins/builtin/source/content/footer_items.cpp @@ -7,7 +7,7 @@ namespace hex::plugin::builtin { ContentRegistry::Interface::addFooterItem([] { static float framerate = 0; if (ImGui::HasSecondPassed()) { - framerate = ImGui::GetIO().Framerate; + framerate = 1.0F / ImGui::GetIO().DeltaTime; } ImGui::TextUnformatted(hex::format("FPS {0:.2f}", framerate).c_str()); diff --git a/source/window.cpp b/source/window.cpp index 70ce8b5c4..980fdfaac 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -187,8 +187,9 @@ namespace hex { while (!glfwWindowShouldClose(this->m_window)) { if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED)) glfwWaitEvents(); + else + glfwWaitEventsTimeout(this->m_lastFrameTime - glfwGetTime() + 1 / 5.0); - glfwPollEvents(); this->frameBegin(); this->frame(); @@ -407,7 +408,7 @@ namespace hex { 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(); } @@ -661,7 +662,6 @@ namespace hex { EventManager::post(window); }); - glfwSetWindowSizeLimits(this->m_window, 720, 480, GLFW_DONT_CARE, GLFW_DONT_CARE); if (gladLoadGL() == 0)