mirror of
https://github.com/eliasstepanik/big_space_with_trim.git
synced 2026-01-11 09:18:27 +00:00
Use a SystemSet for system ordering (#5)
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::<P>` and
`recenter_transform_on_grid::<P>` 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 <aevyrie@gmail.com>
Co-authored-by: Pyxrs <simplycmd00@gmail.com>
This commit is contained in:
parent
5dacfd8507
commit
0907ec1d94
9
.github/workflows/rust.yml
vendored
9
.github/workflows/rust.yml
vendored
@ -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
|
||||
|
||||
@ -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"]
|
||||
|
||||
@ -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 |
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -20,8 +20,7 @@ impl<P: GridPrecision> Plugin for FloatingOriginDebugPlugin<P> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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<P: GridPrecision>(
|
||||
mut gizmos: Gizmos,
|
||||
settings: Res<FloatingOriginSettings>,
|
||||
|
||||
44
src/lib.rs
44
src/lib.rs
@ -133,6 +133,9 @@ impl<P: GridPrecision> FloatingOriginPlugin<P> {
|
||||
|
||||
impl<P: GridPrecision + Reflect + FromReflect + TypePath> Plugin for FloatingOriginPlugin<P> {
|
||||
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<P: GridPrecision + Reflect + FromReflect + TypePath> Plugin for FloatingOri
|
||||
.add_systems(
|
||||
PostStartup,
|
||||
(
|
||||
recenter_transform_on_grid::<P>,
|
||||
sync_simple_transforms::<P>
|
||||
.after(recenter_transform_on_grid::<P>)
|
||||
.before(propagate_transforms::<P>),
|
||||
update_global_from_grid::<P>
|
||||
.after(recenter_transform_on_grid::<P>)
|
||||
.before(propagate_transforms::<P>),
|
||||
propagate_transforms::<P>,
|
||||
recenter_transform_on_grid::<P>.before(RootGlobalTransformUpdates),
|
||||
(sync_simple_transforms::<P>, update_global_from_grid::<P>)
|
||||
.in_set(RootGlobalTransformUpdates),
|
||||
propagate_transforms::<P>.after(RootGlobalTransformUpdates),
|
||||
)
|
||||
.in_set(TransformSystem::TransformPropagate),
|
||||
)
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(
|
||||
recenter_transform_on_grid::<P>,
|
||||
sync_simple_transforms::<P>
|
||||
.after(recenter_transform_on_grid::<P>)
|
||||
.before(propagate_transforms::<P>),
|
||||
update_global_from_grid::<P>
|
||||
.after(recenter_transform_on_grid::<P>)
|
||||
.before(propagate_transforms::<P>),
|
||||
propagate_transforms::<P>,
|
||||
recenter_transform_on_grid::<P>.before(RootGlobalTransformUpdates),
|
||||
(sync_simple_transforms::<P>, update_global_from_grid::<P>)
|
||||
.in_set(RootGlobalTransformUpdates),
|
||||
propagate_transforms::<P>.after(RootGlobalTransformUpdates),
|
||||
)
|
||||
.in_set(TransformSystem::TransformPropagate),
|
||||
);
|
||||
@ -272,9 +267,14 @@ impl FloatingOriginSettings {
|
||||
#[derive(Bundle, Default)]
|
||||
pub struct FloatingSpatialBundle<P: GridPrecision> {
|
||||
/// 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<P: GridPrecision>(
|
||||
) {
|
||||
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<P: GridPrecision>(
|
||||
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<P: GridPrecision>(
|
||||
) {
|
||||
query
|
||||
.par_iter_mut()
|
||||
.for_each_mut(|(transform, mut global_transform)| {
|
||||
.for_each(|(transform, mut global_transform)| {
|
||||
*global_transform = GlobalTransform::from(*transform);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user