comfy
comfy copied to clipboard
FPS for Wasm32 build is unbounded
Hi!
I have a game developed against comfy v0.3.1. When running cargo run, the FPS numbers show ~60. When I run it using trunk serve, my FPS numbers are ~1000. This is a problem, as it actually slows down the game by a bunch.
I have noticed this line of code in the main game loop:
#[cfg(not(target_arch = "wasm32"))]
loop_helper.loop_sleep();
For some reason the engine isn't sleeping for wasm32.
Finally, I wasn't able to reproduce this for comfy v0.4, as trunk build fails on some unrelated issue, with errors such as these:
error[E0599]: no method named `set_inner_size` found for mutable reference `&mut comfy_core::Window` in the current scope
--> /Users/cd/.cargo/registry/src/index.crates.io-6f17d22bba15001f/comfy-0.4.0/src/game_loop.rs:95:16
|
95 | window.set_inner_size(PhysicalSize::new(
However, the code for comfy v0.4 seems very similar with regards to the sleep behaviour.
Am I missing something with regards to the Wasm32 FPS?
My current hack is to have
#[cfg(target_arch = "wasm32")]
let start_time = web_sys::window().unwrap().performance().unwrap().now();
at the start of the update function and
// Hack to have lower FPS in wasm -- wait until 16 ms have passed since the beginning of update
#[cfg(target_arch = "wasm32")]
loop {
let current_time = web_sys::window().unwrap().performance().unwrap().now();
if current_time - start_time >= 16. {
break;
}
}
at the end of it. It's not nice, but it seems to work.