Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only sleep for the rest of the frame budget #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tekknolagi
Copy link

Previously, we were sleeping as long as the paint took. Now, we only sleep for the rest of the allotted budget (if any).

Thanks to @lgarbarini for helping debug.

Previously, we were sleeping as long as the paint took. Now, we only sleep for the rest of the allotted budget (if any).

Thanks to @lgarbarini for helping debug.
@daveth
Copy link

daveth commented Jan 14, 2025

I think this is still slightly off; it doesn't take into account the amount of time slept for and so each alternate loop sleeps for almost no time.

With the following test code I'd expect the printed delta to be ~1000000us each iteration (1 fps).

#include "fenster.h"
#include <chrono>
#include <iostream>

int main()
{
  Fenster window { 100, 100, "Window" };

  using std::chrono::steady_clock;
  using std::chrono::microseconds;
  using std::chrono::duration_cast;

  auto start = steady_clock::now();

  while (window.loop(1))
  {
    auto end = steady_clock::now();
    auto delta = end - start;
    start = end;

    std::cout << "delta: "
              << duration_cast<microseconds>(delta).count()
              << "us"
              << std::endl;
  }
}

However I actually get this:

$ ./a.out
delta: 999714us
delta: 65us
delta: 1000747us
delta: 56us
delta: 1000090us
delta: 59us
delta: 1000257us
delta: 56us
delta: 1000382us
delta: 57us

Which I fixed by changing fenster.h:359 from this->now = t; to this->now = fenster_time();.

$ ./a.out
delta: 999186us
delta: 1000195us
delta: 1000718us
delta: 1000742us
delta: 1000230us
delta: 1001481us
delta: 999216us
delta: 1000225us
delta: 1000308us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants