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

Combine the render-loop wait with the button press wait #3

Merged

Conversation

carlosmn
Copy link

Instead of doing non-blocking read followed by some sleep, we can combine the
time we want to wait until the next render cycle with waiting for the button
presses.

This means that even with slow rates, aka long sleep times, we can still react
quickly to button presses.


Testing locally it does work though I don't know if there was some reason for the loop to be the way it is right now. Beyond the first iteration it shouldn't matter whether the button change detection is the first or last thing as the sequence is still going to be the same.

Instead of doing non-blocking read followed by some sleep, we can combine the
time we want to wait until the next render cycle with waiting for the button
presses.

This means that even with slow rates, aka long sleep times, we can still react
quickly to button presses.
@TheJebForge
Copy link
Collaborator

The loop was like that, because I didn't realize I could just wait with the timeout of read_buttons. It does have a consequence, where if a plugin uses frame counting or something like that, their thing will skip forward on a button press. But I think I'll just add to the docs that you shouldn't rely on anything, but elapsed time since start.

Using the timeout though makes the actions much more responsive, even if the pool rate is at 10. I think, I'll be able to decrease the pool rate to 100 now. I had it at 1000 apparently, so buttons would react instantly, and it didn't used much more CPU.

@TheJebForge
Copy link
Collaborator

I think I have no problems merging this, thanks!

@TheJebForge TheJebForge merged commit 5190eda into streamduck-org:master May 28, 2022
@carlosmn
Copy link
Author

Cool yeah, relying on cycle timings for animations causes issues for games etc as well.

@carlosmn carlosmn deleted the cmn/sleep-waiting-for-press branch May 28, 2022 10:55
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.

None yet

2 participants