From 0907ec1d94290ec292360db7e4775632b206c2cf Mon Sep 17 00:00:00 2001 From: atomicbeef Date: Fri, 10 Nov 2023 09:55:23 +0200 Subject: [PATCH] Use a SystemSet for system ordering (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I ran into an issue when trying to add the transform propagation systems to a schedule more than once. The app would panic because there was more than one instance of `propagate_transforms::

` and `recenter_transform_on_grid::

` in the system graph, so Bevy didn't know how to actually resolve the dependencies. By using a `SystemSet`, we can avoid this issue nicely. Unfortunately, I couldn't come up with a good name for the set, so I decided to stick the definition inside the `build()` method itself. That way at least the poor naming won't be exposed 😛. It still feels a little icky to me though. --------- Co-authored-by: Aevyrie Co-authored-by: Pyxrs --- .github/workflows/rust.yml | 9 ++++---- Cargo.toml | 9 ++++---- README.md | 1 + src/camera.rs | 2 +- src/debug.rs | 3 +-- src/lib.rs | 44 +++++++++++++++++++------------------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7d3dd44..31faeae 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,7 +12,6 @@ jobs: run: sudo apt-get update -yq - name: Install dependencies run: sudo apt-get install -yq --no-install-recommends libudev-dev libasound2-dev libxcb-composite0-dev - format: runs-on: ubuntu-latest needs: [setup] @@ -30,7 +29,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo check --all-features --all-targets + - run: cargo check --all-features check-no-defaults: runs-on: ubuntu-latest @@ -39,7 +38,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo check --no-default-features --all-targets + - run: cargo check --no-default-features clippy: runs-on: ubuntu-latest @@ -49,7 +48,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - run: rustup component add clippy - - run: cargo clippy --all-features --all-targets -- -D warnings + - run: cargo clippy --all-features -- -D warnings doc: runs-on: ubuntu-latest @@ -69,4 +68,4 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.7.0 - - run: cargo test --all-features --all-targets + - run: cargo test --all-features diff --git a/Cargo.toml b/Cargo.toml index 33c07b8..81618c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "big_space" -version = "0.3.0" +version = "0.4.0" edition = "2021" description = "A floating origin plugin for bevy" license = "MIT OR Apache-2.0" @@ -11,7 +11,7 @@ documentation = "https://docs.rs/crate/big_space/latest" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = { version = "0.11", default_features = false } +bevy = { version = "0.12", default_features = false } [dev-dependencies] bevy = { version = "0.12", default-features = false, features = [ @@ -25,6 +25,7 @@ bevy = { version = "0.12", default-features = false, features = [ bevy_framepace = { version = "0.14", default-features = false } [features] -default = ["debug", "camera"] +default = ["debug", "camera", "bevy_render"] debug = ["bevy/bevy_gizmos"] -camera = ["bevy/bevy_render"] +bevy_render = ["bevy/bevy_render"] +camera = ["bevy_render"] diff --git a/README.md b/README.md index 4b55b91..ba625ee 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ I intend to track the `main` branch of Bevy. PRs supporting this are welcome! | bevy | big_space | | ---- | --------- | +| 0.12 | 0.4 | | 0.11 | 0.3 | | 0.10 | 0.2 | | 0.9 | 0.1 | diff --git a/src/camera.rs b/src/camera.rs index ff6c648..49221b1 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -164,7 +164,7 @@ pub fn default_camera_inputs( keyboard .pressed(KeyCode::ShiftLeft) .then(|| cam.boost = true); - if let Some(total_mouse_motion) = mouse_move.iter().map(|e| e.delta).reduce(|sum, i| sum + i) { + if let Some(total_mouse_motion) = mouse_move.read().map(|e| e.delta).reduce(|sum, i| sum + i) { cam.pitch += total_mouse_motion.y as f64 * -0.1; cam.yaw += total_mouse_motion.x as f64 * -0.1; } diff --git a/src/debug.rs b/src/debug.rs index e8c8f2d..cb3cd7d 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -20,8 +20,7 @@ impl Plugin for FloatingOriginDebugPlugin

{ } } -/// Update the rendered debug bounds to only highlight occupied [`GridCell`]s. [`DebugBounds`] are -/// spawned or hidden as needed. +/// Update the rendered debug bounds to only highlight occupied [`GridCell`]s. pub fn update_debug_bounds( mut gizmos: Gizmos, settings: Res, diff --git a/src/lib.rs b/src/lib.rs index 450ab3a..432a5da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,6 +133,9 @@ impl FloatingOriginPlugin

{ impl Plugin for FloatingOriginPlugin

{ fn build(&self, app: &mut App) { + #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] + struct RootGlobalTransformUpdates; + app.insert_resource(FloatingOriginSettings::new( self.grid_edge_length, self.switching_threshold, @@ -144,28 +147,20 @@ impl Plugin for FloatingOri .add_systems( PostStartup, ( - recenter_transform_on_grid::

, - sync_simple_transforms::

- .after(recenter_transform_on_grid::

) - .before(propagate_transforms::

), - update_global_from_grid::

- .after(recenter_transform_on_grid::

) - .before(propagate_transforms::

), - propagate_transforms::

, + recenter_transform_on_grid::

.before(RootGlobalTransformUpdates), + (sync_simple_transforms::

, update_global_from_grid::

) + .in_set(RootGlobalTransformUpdates), + propagate_transforms::

.after(RootGlobalTransformUpdates), ) .in_set(TransformSystem::TransformPropagate), ) .add_systems( PostUpdate, ( - recenter_transform_on_grid::

, - sync_simple_transforms::

- .after(recenter_transform_on_grid::

) - .before(propagate_transforms::

), - update_global_from_grid::

- .after(recenter_transform_on_grid::

) - .before(propagate_transforms::

), - propagate_transforms::

, + recenter_transform_on_grid::

.before(RootGlobalTransformUpdates), + (sync_simple_transforms::

, update_global_from_grid::

) + .in_set(RootGlobalTransformUpdates), + propagate_transforms::

.after(RootGlobalTransformUpdates), ) .in_set(TransformSystem::TransformPropagate), ); @@ -272,9 +267,14 @@ impl FloatingOriginSettings { #[derive(Bundle, Default)] pub struct FloatingSpatialBundle { /// The visibility of the entity. + #[cfg(feature = "bevy_render")] pub visibility: Visibility, - /// The computed visibility of the entity. - pub computed: ComputedVisibility, + /// The inherited visibility of the entity. + #[cfg(feature = "bevy_render")] + pub inherited: InheritedVisibility, + /// The view visibility of the entity. + #[cfg(feature = "bevy_render")] + pub view: ViewVisibility, /// The transform of the entity. pub transform: Transform, /// The global transform of the entity. @@ -296,7 +296,7 @@ pub fn recenter_transform_on_grid( ) { query .par_iter_mut() - .for_each_mut(|(mut grid_pos, mut transform)| { + .for_each(|(mut grid_pos, mut transform)| { if transform.as_ref().translation.abs().max_element() > settings.maximum_distance_from_origin { @@ -326,14 +326,14 @@ pub fn update_global_from_grid( let mut all_entities = entities.p1(); all_entities .par_iter_mut() - .for_each_mut(|(local, global, entity_cell)| { + .for_each(|(local, global, entity_cell)| { update_global_from_cell_local(&settings, entity_cell, &origin_cell, local, global); }); } else { let mut moved_cell_entities = entities.p0(); moved_cell_entities .par_iter_mut() - .for_each_mut(|(local, global, entity_cell)| { + .for_each(|(local, global, entity_cell)| { update_global_from_cell_local(&settings, entity_cell, &origin_cell, local, global); }); } @@ -368,7 +368,7 @@ pub fn sync_simple_transforms( ) { query .par_iter_mut() - .for_each_mut(|(transform, mut global_transform)| { + .for_each(|(transform, mut global_transform)| { *global_transform = GlobalTransform::from(*transform); }); }