Elegantly simplify and improve #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use mpos.ui.th.add_event_cb(...) that gets called by lvgl_micropython's
task_handler.py periodically.
This eliminates the need for a separate thread that launches
the "while True" game loop, which is good because threads are
limited on low-RAM devices.
It also removes the need for time.sleep_ms() to prevent too many
lv.async_call() operations from causing memory corruption and segfaulting
on desktop systems.
Actually, since the task handler runs as part of LVGL's main UI thread
instead of a separate one, there's no more need to use lv.async_call()
to ensure thread safety, so no need for update_ui_threadsafe_if_foreground.
The self.running variable also is no longer needed, just mpos.ui.th.remove_event_cb(...)
in the onPause(), called when the Activity gets backgrounded.
The game currently runs at a smooth 17.5 FPS on an ESP32-S3,
without looking into further optimizations.
Also in this pull request: slightly smaller than the bird's square image, otherwise it collides before actually overlapping it.