You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Objective
`WinitSettings::update_mode` setting `UpdateMode::Reactive` is
documented as setting the time "from the start of one update to the
next". currently it sets the winit wake time to the wait time after the
start of the current tick, which shifts each frame by whatever
additional latency exists before the frame is triggered.
also, redraws only seem to trigger every 2 wakeups.
in wasm this is the only way to cap framerates below default
refresh-rate (on native we can just sleep), but this issue manifests on
both native and wasm.
## Solution
solve 1 by recording scheduled start time and setting the next wakeup as
scheduled + wait time.
solve 2 by setting redraw_requested explicitly when wait time elapses
## Testing
```rs
const FPS: u32 = 10;
#[wasm_bindgen]
pub fn engine_run() {
#[cfg(target_arch="wasm32")]
let _ = console_log::init_with_level(log::Level::Info);
App::new()
.insert_resource(WinitSettings {
focused_mode: UpdateMode::Reactive {
wait: Duration::from_micros((1.0 / (FPS as f32) * 1000000.0) as u64),
react_to_device_events: false,
react_to_user_events: false,
react_to_window_events: false,
},
unfocused_mode: UpdateMode::Reactive {
wait: Duration::from_micros((1.0 / (FPS as f32) * 1000000.0) as u64),
react_to_device_events: false,
react_to_user_events: false,
react_to_window_events: false,
},
..Default::default()
})
.add_plugins(DefaultPlugins)
.add_plugins(FrameTimeDiagnosticsPlugin::default())
.add_plugins(LogDiagnosticsPlugin::default())
.run();
}
```
0 commit comments