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

Examples consume a lot of CPU time when not visible on macOS #174

Open
parasyte opened this issue Jun 7, 2021 · 2 comments
Open

Examples consume a lot of CPU time when not visible on macOS #174

parasyte opened this issue Jun 7, 2021 · 2 comments
Labels
bug Something isn't working examples A bug or improvement for an example

Comments

@parasyte
Copy link
Owner

parasyte commented Jun 7, 2021

macOS has an unusual behavior that it will not wait for V-Blank when the window is not visible. That can happen e.g. when the window is minimized or it is entirely covered by another window. While the issue is limited to examples, it's still bad because the examples are how people learn to use this crate.

@parasyte parasyte added bug Something isn't working examples A bug or improvement for an example labels Jun 7, 2021
@parasyte
Copy link
Owner Author

Just so I don't forget later, here are some examples of how this is currently handled in the wild:

@parasyte
Copy link
Owner Author

parasyte commented Jan 8, 2022

This is fixed in the invaders example with a fixed time step and sleeping the main thread to cap the frame rate:

// Sleep the main thread to limit drawing to the fixed time step.
// See: https://github.com/parasyte/pixels/issues/174
let dt = TIME_STEP.as_secs_f64() - Time::now().sub(&g.current_instant());
if dt > 0.0 {
std::thread::sleep(Duration::from_secs_f64(dt));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working examples A bug or improvement for an example
Projects
None yet
Development

No branches or pull requests

1 participant