Skip to content

Commit 9246295

Browse files
committed
Formatting, etc.
1 parent 5b35b85 commit 9246295

File tree

2 files changed

+61
-35
lines changed

2 files changed

+61
-35
lines changed

src/plugin/plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ where
7373
.after(systems::update_character_controls)
7474
.in_set(RapierTransformPropagateSet),
7575
systems::init_async_colliders.after(RapierTransformPropagateSet),
76-
systems::collect_collider_hierarchy_changes.before(systems::apply_collider_user_changes),
76+
systems::collect_collider_hierarchy_changes
77+
.before(systems::apply_collider_user_changes),
7778
apply_deferred.after(systems::collect_collider_hierarchy_changes),
7879
systems::apply_scale.after(systems::init_async_colliders),
7980
systems::apply_collider_user_changes.after(systems::apply_scale),

src/plugin/systems.rs

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,18 @@ pub fn collect_collider_hierarchy_changes(
181181
};
182182

183183
for event in hierarchy_events.iter() {
184-
println!("event: {:?}", event);
185184
match event {
186185
HierarchyEvent::ChildAdded { child, .. } | HierarchyEvent::ChildMoved { child, .. } => {
187-
println!("child add/moved");
188186
let colliders = child_colliders(*child);
189187
let Some(rigid_body) = parent_rigid_body(*child) else {
190-
println!("no rigid body parent");
191188
continue;
192189
};
193190

194-
println!("- updating colliders");
195191
for collider in colliders {
196-
println!("- collider: {:?}", collider);
197192
let new_collider_parent = ColliderParent(rigid_body);
198193
if let Ok(mut collider_parent) = collider_parents.get_mut(collider) {
199-
println!(" - update existing");
200194
*collider_parent = new_collider_parent;
201195
} else {
202-
println!(" - insert new");
203196
commands.entity(collider).insert(new_collider_parent);
204197
}
205198
}
@@ -224,10 +217,10 @@ pub fn apply_collider_user_changes(
224217
(&RapierColliderHandle, &GlobalTransform),
225218
(Without<RapierRigidBodyHandle>, Changed<GlobalTransform>),
226219
>,
227-
(changed_collider_parents, test_query): (Query<
228-
(&RapierColliderHandle, &ColliderParent, Entity),
220+
changed_collider_parents: Query<
221+
(&RapierColliderHandle, &ColliderParent),
229222
Changed<ColliderParent>,
230-
>, Query<Entity, With<ColliderParent>>),
223+
>,
231224
changed_shapes: Query<(&RapierColliderHandle, &Collider), Changed<Collider>>,
232225
changed_active_events: Query<(&RapierColliderHandle, &ActiveEvents), Changed<ActiveEvents>>,
233226
changed_active_hooks: Query<(&RapierColliderHandle, &ActiveHooks), Changed<ActiveHooks>>,
@@ -266,23 +259,14 @@ pub fn apply_collider_user_changes(
266259
}
267260
}
268261

269-
270-
for entity in &test_query {
271-
println!("entity {:?} has a cparent", entity);
272-
}
273-
274-
println!("checking changes");
275-
for (handle, collider_parent, collider_entity) in changed_collider_parents.iter() {
276-
println!("changed collider: {:?}", collider_entity);
262+
for (handle, collider_parent) in changed_collider_parents.iter() {
277263
if let Some(body_handle) = context.entity2body.get(&collider_parent.0).copied() {
278-
println!("body parent: {:?}", collider_parent.0);
279264
let RapierContext {
280265
ref mut colliders,
281266
ref mut bodies,
282267
..
283268
} = *context;
284269
colliders.set_parent(handle.0, Some(body_handle), bodies);
285-
println!("collider parent: {:?}", context.collider_parent(collider_entity));
286270
}
287271
}
288272

@@ -1883,8 +1867,19 @@ mod tests {
18831867
colliders: Query<(Entity, Option<&ColliderParent>), With<Collider>>,
18841868
parents: Query<&Parent>,
18851869
bodies: Query<(), With<RigidBody>>,
1886-
names: Query<DebugName>,
1870+
names: Query<&Name>,
18871871
) {
1872+
let row_length = 60;
1873+
let column_length = row_length / 4;
1874+
let column = |collider: &str, rapier: &str, component: &str, hierarchal: &str| {
1875+
println!(
1876+
"{:<column_length$}| {:<column_length$}| {:<column_length$}| {:<column_length$}",
1877+
collider, rapier, component, hierarchal,
1878+
);
1879+
};
1880+
1881+
column("collider", "rapier", "component", "hierarchal");
1882+
println!("{}", "-".repeat(row_length));
18881883
for (collider_entity, collider_parent) in &colliders {
18891884
let rapier_parent = ctx.collider_parent(collider_entity);
18901885
let collider_parent = collider_parent.map(|parent| parent.get());
@@ -1901,12 +1896,21 @@ mod tests {
19011896
entity = parent.get();
19021897
}
19031898

1904-
let disp = |entity: Option<Entity>| -> String {
1905-
entity.map(|entity| format!("{:?}", names.get(entity).unwrap())).unwrap_or("None".to_owned())
1899+
let named = |entity: Option<Entity>| -> String {
1900+
entity
1901+
.map(|entity| {
1902+
names
1903+
.get(entity)
1904+
.map(|name| name.as_str().to_owned())
1905+
.unwrap_or(format!("{:?}", entity))
1906+
})
1907+
.unwrap_or("None".to_owned())
19061908
};
1907-
println!(
1908-
"Collider {}: {} = {} = {}",
1909-
disp(Some(collider_entity)), disp(rapier_parent), disp(collider_parent), disp(hierarchal_parent),
1909+
column(
1910+
&named(Some(collider_entity)),
1911+
&named(rapier_parent),
1912+
&named(collider_parent),
1913+
&named(hierarchal_parent),
19101914
);
19111915

19121916
assert_eq!(rapier_parent, collider_parent);
@@ -1917,36 +1921,58 @@ mod tests {
19171921
fn frame(mut frame: Local<u32>) {
19181922
*frame += 1;
19191923
println!("-- frame {} -----------", *frame);
1924+
println!();
19201925
}
19211926

19221927
app.add_systems(Last, (frame, verify_collider_parent).chain());
19231928

1924-
app
1929+
let self_parented = app
19251930
.world
1926-
.spawn((Name::new("Self-parented"), TransformBundle::default(), RigidBody::Dynamic, Collider::default()));
1931+
.spawn((
1932+
Name::new("Self-parented"),
1933+
TransformBundle::default(),
1934+
RigidBody::Dynamic,
1935+
Collider::default(),
1936+
))
1937+
.id();
19271938

19281939
let parent1 = app
19291940
.world
1930-
.spawn((Name::new("Parent 1"), TransformBundle::default(), RigidBody::Dynamic))
1941+
.spawn((
1942+
Name::new("Parent 1"),
1943+
TransformBundle::default(),
1944+
RigidBody::Dynamic,
1945+
))
19311946
.id();
19321947

19331948
let parent2 = app
19341949
.world
1935-
.spawn((Name::new("Parent 2"), TransformBundle::default(), RigidBody::Dynamic))
1950+
.spawn((
1951+
Name::new("Parent 2"),
1952+
TransformBundle::default(),
1953+
RigidBody::Dynamic,
1954+
))
19361955
.id();
19371956

1938-
let inbetween = app.world.spawn((Name::new("Inbetween"), TransformBundle::default(),)).id();
1957+
let inbetween = app
1958+
.world
1959+
.spawn((Name::new("Inbetween"), TransformBundle::default()))
1960+
.id();
19391961

19401962
let child = app
19411963
.world
1942-
.spawn((Name::new("Child collider"), TransformBundle::default(), Collider::default()))
1964+
.spawn((
1965+
Name::new("Child collider"),
1966+
TransformBundle::default(),
1967+
Collider::default(),
1968+
))
19431969
.id();
19441970

19451971
// Unnested
19461972
app.update();
1973+
app.world.entity_mut(self_parented).despawn_recursive();
19471974
app.world.entity_mut(child).set_parent(parent1);
19481975
app.update();
1949-
/*
19501976
app.world.entity_mut(child).set_parent(parent2);
19511977
app.update();
19521978
app.world.entity_mut(child).remove_parent();
@@ -1965,7 +1991,6 @@ mod tests {
19651991
app.world.entity_mut(inbetween).set_parent(parent1);
19661992
app.world.entity_mut(child).remove_parent();
19671993
app.update();
1968-
*/
19691994
}
19701995

19711996
// Allows run tests for systems containing rendering related things without GPU

0 commit comments

Comments
 (0)