Skip to content

Comments

smoother timing in frame limiter#1415

Draft
water111 wants to merge 2 commits intomasterfrom
w/frame-limiter-tweaks
Draft

smoother timing in frame limiter#1415
water111 wants to merge 2 commits intomasterfrom
w/frame-limiter-tweaks

Conversation

@water111
Copy link
Collaborator

@water111 water111 commented Jun 4, 2022

No description provided.

@water111 water111 marked this pull request as ready for review June 4, 2022 17:51
@water111
Copy link
Collaborator Author

water111 commented Jun 4, 2022

This should fix some of the issues we were having with the framelimiter and sets it as the default.

@water111
Copy link
Collaborator Author

water111 commented Jun 9, 2022

this has a math bug in the windows sleep

#define NOMINMAX
#include <Windows.h>

void sleep_us(u64 us) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have two different implementations of sleep_us?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One is for linux and the other is for Windows.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, yeah. I meant why not use

void sleep_us(u64 us) {
  std::this_thread::sleep_for(std::chrono::microseconds(us))
}

for both platforms?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need sleeps that are accurate to a few ms for this to work, but the default windows timer resolution is (sometimes) ~15 ms. that's almost a whole frame long, so it becomes impossible to sleep for the right amount of time. The solution is to use the windows API to request a higher timer resolution and do the sleeps manually.

The C++ standard library sleeps are kinda weird too, they have very poorly specified behavior:
"The standard recommends that a steady clock is used to measure the duration. If an implementation uses a system clock instead, the wait time may also be sensitive to clock adjustments."

and we definitely wouldn't want the frame limiter to be affected by somebody changing their system time...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I did not realise that the std sleeps were so poorly defined. I always assumed they were a steady clock, because as you said, if they're not that's hugely problematic.

@xTVaser xTVaser added the jak1 label Oct 11, 2022
@xTVaser xTVaser marked this pull request as draft March 26, 2023 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants