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

Use tb_poll_event instead of tb_peek_event #320

Merged
merged 2 commits into from
Apr 25, 2022

Conversation

jakobrs
Copy link
Contributor

@jakobrs jakobrs commented Nov 13, 2021

Reduces CPU usage noticeably on my system, from 14% to nearly 0%. There is an issue where the cursor doesn't get positioned correctly on startup, this is because the cursor position is set in input_handles[active_input] on line 144 (which calls tb_set_cursor), before position_inputs has been called. It is not enough to just call position_inputs before line 144, because position_inputs itself requires that draw_box has been called,

There are other issues with this approach as well, if I can't find a solution for them it might be easier to just increase the default min_refresh_delta.

@jakobrs jakobrs changed the title Don't process empty events Use tb_poll_event instead of tb_peek_event Nov 13, 2021
@nullgemm
Copy link
Collaborator

This is definitely a step in the right direction, however it breaks animations: we should decide which method to use depending on the current configuration. If the animations are enabled, we should peek events. If not, then we can poll. If you can make these changes I will merge this asap :)

@nullgemm nullgemm added ok This issue or pull request was confirmed/reviewed wip This issue or pull request is a draft labels Apr 24, 2022
@jakobrs jakobrs marked this pull request as ready for review April 24, 2022 12:12
@jakobrs
Copy link
Contributor Author

jakobrs commented Apr 24, 2022

I added a call to *input_handles[active_input] in the if (update) block, as this seems to fix the cursor positioning issues. Alternatively *input_handles[active_input] could be called every time the cursor position is updated.

draw_box and position_input are called because they need to be called
before *input_handles[active_input] for the cursor to be positioned
correctly.
@nullgemm nullgemm merged commit c0366fe into fairyglade:master Apr 25, 2022
@nullgemm
Copy link
Collaborator

thanks a lot!

@jakobrs jakobrs deleted the patch-1 branch May 16, 2022 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok This issue or pull request was confirmed/reviewed wip This issue or pull request is a draft
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants