Skip to content

Conversation

@narodnik
Copy link
Contributor

Currently in my app I have a task scheduling updates continuously but this introduces latency and uneeded cpu usage. Instead we can make the receiver optionally call .recv_timeout() inside the main event loop. In fact all native platforms in miniquad should use an FPS by default instead of continuous drawing.

            // For animations do periodic refresh every 40 ms
            self.refresh_task = Some(self.ex.spawn(async move {
                loop {
                    system::msleep(40).await;
                    miniquad::window::schedule_update();
                }
            }));

(on android you dont want to continuous draw() or else it will drain battery. In fact you dont want to do this on most platforms)

/// continuously drawing without having to continuously schedule updates that can
/// choke the receiver queue.
///
/// Currently supported only on Android.
Copy link
Owner

@not-fl3 not-fl3 Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe reuse swap_interval for this? I am concerned that users will try to use fps to set target fps on other platforms.

If not swap_interval - I would name it something among the android_perioidical_wakeup_timer lines - to make it very explicit that its a very special setting, not a general way to set target fps to 60 on web.

Copy link
Contributor Author

@narodnik narodnik Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap_interval is for vsync and is not correct here. In fact I think this code should be added to the android EGL init in src/native/android.rs but that is a separate commit:

        if (libegl.eglSwapInterval)(egl_display, conf.platform.swap_interval.unwrap_or(1)) == 0 {
            eprintln!("eglSwapInterval failed");
        }

I didn't do it yet since the only meaningful values on Android are 0 or 1 and we generally want 1 anyway.

Secondly, my plan is actually to make FPS a setting for all platforms where possible to conserve battery/system resources. So I think its best to conserve it in the general platform settings unless you prefer to later deprecate the android specific setting and introduce a global one later.

@narodnik
Copy link
Contributor Author

Should I rename fps to target_fps maybe?

Also if you prefer, we can put sleep_interval_ms instead of fps.

@not-fl3
Copy link
Owner

not-fl3 commented Dec 26, 2025

sleep_interval_ms

I do prefer sleep_interval_ms here.

…ng) when blocking_event_loop is enabled. Currently in my app I have a task scheduling updates continuously but this introduces latency and uneeded cpu usage. Instead we can make the receiver optionally call .recv_timeout() inside the main event loop. In fact all native platforms in miniquad should support `sleep_interval_ms` by default instead of continuous drawing.
@narodnik
Copy link
Contributor Author

ok done, force pushed renamed the setting to sleep_interval_ms.

@not-fl3 not-fl3 merged commit d7da594 into not-fl3:master Dec 30, 2025
11 checks passed
@not-fl3
Copy link
Owner

not-fl3 commented Dec 30, 2025

Thanks for PR!

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