Skip to content

Commit

Permalink
fix: ImHex using way too much resources still
Browse files Browse the repository at this point in the history
Now frames are rendered at only 5 FPS if no input events are being processed. Thanks a lot to @Tey. Properly fixes #189 now
  • Loading branch information
WerWolv committed Jul 27, 2021
1 parent d4e484e commit af1d687
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/builtin/source/content/footer_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -661,7 +662,6 @@ namespace hex {
EventManager::post<EventWindowClosing>(window);
});


glfwSetWindowSizeLimits(this->m_window, 720, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);

if (gladLoadGL() == 0)
Expand Down

0 comments on commit af1d687

Please sign in to comment.