diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aeb3612..8a6945b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,10 @@ jobs: steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy - name: Install alsa and udev - run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev - name: check run: cargo check - name: examples diff --git a/Cargo.toml b/Cargo.toml index 63e6aca..8151c0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,10 @@ webgl2 = ["bevy/webgl2"] webgpu = ["bevy/webgpu"] [dependencies.bevy] -version = "0.16.0" +version = "0.17.0" default-features = false features = ["bevy_render"] [dev-dependencies.bevy] -version = "0.16.0" +version = "0.17.0" default-features = true diff --git a/examples/states.rs b/examples/states.rs index f41c1a1..0d9c7bd 100644 --- a/examples/states.rs +++ b/examples/states.rs @@ -11,31 +11,31 @@ enum GameState { // This value should be found experimentally by logging `PipelinesReady` in your app // during normal use and noting the maximum value. #[cfg(not(target_arch = "wasm32"))] -const EXPECTED_PIPELINES: usize = 29; +const EXPECTED_PIPELINES: usize = 35; // The value will likely differ on the web due to different implementations of some // render features. #[cfg(all(target_arch = "wasm32", feature = "webgpu", not(feature = "webgl2")))] -const EXPECTED_PIPELINES: usize = 14; +const EXPECTED_PIPELINES: usize = 20; // Note: These features can be simplified if your app only builds for one of either // webgpu or webgl2. Simply use `#[cfg(target_arch = "wasm32")]`. If your app builds // for both, you must add these features (or similar) to your app. See `Cargo.toml`. #[cfg(all(target_arch = "wasm32", feature = "webgl2", not(feature = "webgpu")))] const EXPECTED_PIPELINES: usize = 6; +// You may want to wait an additional period of time or number of frames. +// +// In my experience, Bevy's framerate seems to take a few seconds to fully recover after +// pipelines are compiled when running in Firefox. +const ADDITIONAL_WAIT_FRAMES: u32 = 10; + fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(PipelinesReadyPlugin) .init_state::() - .enable_state_scoped_entities::() .add_systems(Startup, setup_loading_screen) .add_systems(Update, print.run_if(resource_changed::)) - .add_systems( - Update, - transition - .run_if(in_state(GameState::Loading)) - .run_if(resource_changed::), - ) + .add_systems(Update, transition.run_if(in_state(GameState::Loading))) .run(); } @@ -48,7 +48,7 @@ fn setup_loading_screen( ) { commands.spawn(( Text::new("Pipelines loading...".to_string()), - StateScoped(GameState::Loading), + DespawnOnExit(GameState::Loading), )); commands.spawn(( @@ -81,13 +81,20 @@ fn print(ready: Res) { info!("Pipelines Ready: {}/{}", ready.get(), EXPECTED_PIPELINES); } -fn transition(ready: Res, mut next_state: ResMut>) { - if ready.get() >= EXPECTED_PIPELINES { - // Note: you may want to wait an additional period of time or number - // of frames after this. - // - // In my experience, Bevy's framerate seems to take a few seconds to - // fully recover after pipelines are compiled when running in Firefox. - next_state.set(GameState::Ready); +fn transition( + ready: Res, + mut next_state: ResMut>, + mut frames_since_pipelines_ready: Local, +) { + if ready.get() < EXPECTED_PIPELINES { + return; + } + + *frames_since_pipelines_ready += 1; + + if *frames_since_pipelines_ready < ADDITIONAL_WAIT_FRAMES { + return; } + + next_state.set(GameState::Ready); }