Skip to content

Commit

Permalink
better fps limit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Nov 24, 2023
1 parent 75c9cc9 commit 8e06e68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
12 changes: 0 additions & 12 deletions source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,6 @@ void Player::render() {
ImGui::RenderPlatformWindowsDefault();
}
}

// limit fps while player idle
static double time = 0;
double targetDelta = 1.0f / config->Data.Interface.Fps;
if (idle || mpv->pause) {
double delta = time - ImGui::GetTime();
if (delta > 0 && delta < targetDelta)
std::this_thread::sleep_for(std::chrono::duration<double>(delta));
else
time = ImGui::GetTime();
}
time += targetDelta;
}

void Player::renderVideo() {
Expand Down
9 changes: 9 additions & 0 deletions source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ void Window::run() {

render();
updateCursor();

static double time = 0;
double targetDelta = 1.0f / config->Data.Interface.Fps;
double delta = time - ImGui::GetTime();
if (delta > 0 && delta < targetDelta)
glfwWaitEventsTimeout(delta);
else
time = ImGui::GetTime();
time += targetDelta;
}

shutdown = true;
Expand Down

0 comments on commit 8e06e68

Please sign in to comment.