Skip to content

Conversation

@ThomasFarstrike
Copy link
Contributor

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.

Otherwise it collides before actually overlapping it
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.
@ThomasFarstrike
Copy link
Contributor Author

Note that it required a bugfix in the upstream lvgl_micropython so make sure you do a:

cd lvgl_micropython
git pull
cd ..
./scripts/build_mpos.sh # rebuild for your esp32 and/or desktop system

@QuasiKili QuasiKili merged commit 7f40348 into QuasiKili:main Nov 7, 2025
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.

2 participants