More optimizations to coordinate/position sync.

This commit is contained in:
Nolan Darilek 2021-07-20 11:36:09 -05:00
parent 2abeb3b08c
commit e6af8f7618

View File

@ -550,7 +550,11 @@ fn copy_coordinates_to_transform(
config: Res<CoreConfig>, config: Res<CoreConfig>,
mut query: Query< mut query: Query<
(&Coordinates, &mut Transform), (&Coordinates, &mut Transform),
(Without<RigidBodyPosition>, Without<ColliderPosition>), (
Changed<Transform>,
Without<RigidBodyPosition>,
Without<ColliderPosition>,
),
>, >,
) { ) {
for (coordinates, mut transform) in query.iter_mut() { for (coordinates, mut transform) in query.iter_mut() {
@ -578,6 +582,22 @@ fn copy_rigid_body_position_to_coordinates(
} }
} }
fn copy_collider_position_to_coordinates(
mut query: Query<
(&mut Coordinates, &ColliderPosition),
(Without<RigidBodyPosition>, Changed<ColliderPosition>),
>,
) {
for (mut coordinates, position) in query.iter_mut() {
if coordinates.0 .0 != position.translation.x {
coordinates.0 .0 = position.translation.x;
}
if coordinates.0 .1 != position.translation.y {
coordinates.0 .1 = position.translation.y;
}
}
}
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct CoreConfig { pub struct CoreConfig {
pub pixels_per_unit: u8, pub pixels_per_unit: u8,
@ -607,6 +627,10 @@ impl Plugin for CorePlugin {
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
copy_rigid_body_position_to_coordinates.system(), copy_rigid_body_position_to_coordinates.system(),
)
.add_system_to_stage(
CoreStage::PostUpdate,
copy_collider_position_to_coordinates.system(),
); );
} }
} }