Skip to content

Adaptive main loop: sleep on real events when idle - #26

Open
jajarom82 wants to merge 1 commit into
ealang:masterfrom
jajarom82:adaptive-main-loop
Open

jajarom82 wants to merge 1 commit into
ealang:masterfrom
jajarom82:adaptive-main-loop

Conversation

@jajarom82

Copy link
Copy Markdown

The main loop polls at a fixed TARGET_FPS (20Hz) forever via SDL_PollEvent + a fixed-rate delay, even when the app is fully idle on a static page with nothing held or animating. Rendering is already change-driven, but the wake cadence was not, so the CPU (and battery) paid for 20 wakeups a second regardless of whether anything was happening.

Adds View::on_tick()/wants_continuous_render() (a view opts in to mean "keep ticking at full rate even with no input", for a future animated view such as auto-scroll - unused by any current view, so no behavior change yet) and HeldKeyTracker::any_held(). When nothing is held and the active view does not need continuous rendering, the loop blocks on the next real input event instead of polling, using a small local poll_event_with_timeout() rather than SDL_WaitEventTimeout itself, since that symbol is not declared in this toolchain's SDL1.2 headers.

No behavior change while input is active or a view opts into continuous rendering; the only difference is fewer wakeups while a book just sits on screen. Verified this still compiles and links against the real Miyoo Mini cross-compile toolchain.

The main loop polls at a fixed TARGET_FPS (20Hz) forever via
SDL_PollEvent + a fixed-rate delay, even when the app is fully idle on
a static page with nothing held or animating. Rendering is already
change-driven, but the wake cadence was not, so the CPU (and battery)
paid for 20 wakeups a second regardless of whether anything was
happening.

Adds View::on_tick()/wants_continuous_render() (a view opts in to mean
"keep ticking at full rate even with no input", for a future animated
view such as auto-scroll - unused by any current view, so no behavior
change yet) and HeldKeyTracker::any_held(). When nothing is held and
the active view does not need continuous rendering, the loop blocks on
the next real input event instead of polling, using a small local
poll_event_with_timeout() rather than SDL_WaitEventTimeout itself,
since that symbol is not declared in this toolchain's SDL1.2 headers.

No behavior change while input is active or a view opts into continuous
rendering; the only difference is fewer wakeups while a book just sits
on screen. Verified this still compiles and links against the real
Miyoo Mini cross-compile toolchain.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant