mirror of
https://github.com/eliasstepanik/big_space_with_trim.git
synced 2026-01-12 02:28:28 +00:00
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>
41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
//! Contains tools for debugging the floating origin.
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use crate::{precision::GridPrecision, FloatingOrigin, FloatingOriginSettings, GridCell};
|
|
|
|
/// This plugin will render the bounds of occupied grid cells.
|
|
#[derive(Default)]
|
|
pub struct FloatingOriginDebugPlugin<P: GridPrecision>(PhantomData<P>);
|
|
impl<P: GridPrecision> Plugin for FloatingOriginDebugPlugin<P> {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(
|
|
PostUpdate,
|
|
update_debug_bounds::<P>
|
|
.after(crate::recenter_transform_on_grid::<P>)
|
|
.before(crate::update_global_from_grid::<P>),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Update the rendered debug bounds to only highlight occupied [`GridCell`]s.
|
|
pub fn update_debug_bounds<P: GridPrecision>(
|
|
mut gizmos: Gizmos,
|
|
settings: Res<FloatingOriginSettings>,
|
|
occupied_cells: Query<&GridCell<P>, Without<FloatingOrigin>>,
|
|
origin_cells: Query<&GridCell<P>, With<FloatingOrigin>>,
|
|
) {
|
|
let origin_cell = origin_cells.single();
|
|
for cell in occupied_cells.iter() {
|
|
let cell = cell - origin_cell;
|
|
let scale = Vec3::splat(settings.grid_edge_length * 0.999);
|
|
let translation = settings.grid_position(&cell, &Transform::IDENTITY);
|
|
gizmos.cuboid(
|
|
Transform::from_translation(translation).with_scale(scale),
|
|
Color::GREEN,
|
|
)
|
|
}
|
|
}
|