-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[GUI] Support gui.fps_limit and reduce idle power consumption #1611
Changes from 2 commits
6ed785f
24b5af7
46f63d4
559d96e
d2ef53f
cc2a876
879e715
dd63547
57bb8dd
f1fa416
af718a8
b38abf6
55619b0
574a621
015e818
a2e70c6
9d0abd6
726786a
ca6b011
ca623c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,24 @@ void Time::sleep(double s) { | |
Time::usleep(s * 1e6_f64); | ||
} | ||
|
||
void Time::wait_until(double t) { | ||
double dt; | ||
if (t < Time::get_time()) { | ||
return; | ||
} | ||
do { // use system-provided sleep for large scale sleeping: | ||
dt = (t - Time::get_time()) * 0.5; | ||
if (dt <= 0) { | ||
return; | ||
} | ||
Time::sleep(dt * 1e-3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We set the precision as 100us. But relatively , There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the unit of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} while (dt > 1e-4_f64); // until dt <= 100us | ||
|
||
// use an EBFE loop for small scale waiting: | ||
while (Time::get_time() < t - 1e-6_f64) | ||
; // until dt <= 1us | ||
} | ||
|
||
double Time::Timer::get_time() { | ||
return Time::get_time(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a mush more accurate milliseconds level sleep implementation instead of
Sleep(DWORD(us * 1e-3))
on windows .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds cool! But is that possible to sleep for microseconds (us) on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sad truth that sleep accuracy can not be guaranteed when delay time is lower than 1ms :(
The only possible approach is to use high resolution clock to continually counting in a for loop , but it 's unable to release CPU time slice ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related problem : is-there-a-windows-equivalent-of-nanosleep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sleeping for us seems tricky on win, how about just:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1ms is more accurate ( 1/60 = 16.6 ms , 1/120 = 8.3ms , 1/40 = 25 ms )