aboutsummaryrefslogtreecommitdiff
path: root/src/pipeline/user_changes.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-04-20 12:29:57 +0200
committerSébastien Crozet <sebastien@crozet.re>2022-04-20 19:02:49 +0200
commitf108520b5a110cf59864abac7ac6a37e2b5a1dd9 (patch)
tree3ed03fbce2128e5eb04ca29d25b42717987eb424 /src/pipeline/user_changes.rs
parent2b1374c596957ac8cabe085859be3b823a1ba0c6 (diff)
downloadrapier-f108520b5a110cf59864abac7ac6a37e2b5a1dd9.tar.gz
rapier-f108520b5a110cf59864abac7ac6a37e2b5a1dd9.tar.bz2
rapier-f108520b5a110cf59864abac7ac6a37e2b5a1dd9.zip
Finalize refactoring
Diffstat (limited to 'src/pipeline/user_changes.rs')
-rw-r--r--src/pipeline/user_changes.rs57
1 files changed, 23 insertions, 34 deletions
diff --git a/src/pipeline/user_changes.rs b/src/pipeline/user_changes.rs
index b999f0f..69f29d9 100644
--- a/src/pipeline/user_changes.rs
+++ b/src/pipeline/user_changes.rs
@@ -1,6 +1,6 @@
use crate::dynamics::{
IslandManager, RigidBodyActivation, RigidBodyChanges, RigidBodyHandle, RigidBodyIds,
- RigidBodyPosition, RigidBodySet, RigidBodyType,
+ RigidBodySet, RigidBodyType,
};
use crate::geometry::{ColliderChanges, ColliderHandle, ColliderPosition, ColliderSet};
use parry::utils::hashmap::HashMap;
@@ -17,15 +17,13 @@ pub(crate) fn handle_user_changes_to_colliders(
for handle in modified_colliders {
// NOTE: we use `get` because the collider may no longer
// exist if it has been removed.
- if let Some(co) = colliders.get(*handle) {
+ if let Some(co) = colliders.get_mut_internal(*handle) {
if co.changes.contains(ColliderChanges::PARENT) {
if let Some(co_parent) = co.parent {
- let parent_pos: &RigidBodyPosition = bodies.index(co_parent.handle.0);
+ let parent_rb = &bodies[co_parent.handle];
- let new_pos = parent_pos.position * co_parent.pos_wrt_parent;
- let new_changes = co.changes | ColliderChanges::POSITION;
- colliders.set_internal(handle.0, ColliderPosition(new_pos));
- colliders.set_internal(handle.0, new_changes);
+ co.pos = ColliderPosition(parent_rb.pos.position * co_parent.pos_wrt_parent);
+ co.changes |= ColliderChanges::POSITION;
}
}
@@ -38,18 +36,12 @@ pub(crate) fn handle_user_changes_to_colliders(
}
for (to_update, _) in mprops_to_update {
- let rb = &bodies[to_update];
- let position = rb.position();
- // FIXME: remove the clone once we remove the ComponentSets.
- let attached_colliders = rb.colliders().clone();
-
- bodies.map_mut_internal(to_update.0, |rb_mprops| {
- rb_mprops.recompute_mass_properties_from_colliders(
- colliders,
- &attached_colliders,
- &position,
- )
- });
+ let rb = bodies.index_mut_internal(to_update);
+ rb.mprops.recompute_mass_properties_from_colliders(
+ colliders,
+ &rb.colliders,
+ &rb.pos.position,
+ );
}
}
@@ -73,7 +65,7 @@ pub(crate) fn handle_user_changes_to_rigid_bodies(
continue;
}
- let rb = &bodies[handle];
+ let rb = bodies.index_mut_internal(*handle);
let mut changes = rb.changes;
let mut ids: RigidBodyIds = rb.ids;
let mut activation: RigidBodyActivation = rb.activation;
@@ -83,7 +75,7 @@ pub(crate) fn handle_user_changes_to_rigid_bodies(
// it is on the correct active set.
if let Some(islands) = islands.as_deref_mut() {
if changes.contains(RigidBodyChanges::TYPE) {
- match rb.status {
+ match rb.body_type {
RigidBodyType::Dynamic => {
// Remove from the active kinematic set if it was there.
if islands.active_kinematic_set.get(ids.active_set_id) == Some(handle) {
@@ -162,20 +154,19 @@ pub(crate) fn handle_user_changes_to_rigid_bodies(
|| changes.contains(RigidBodyChanges::TYPE)
{
for handle in rb.colliders.0.iter() {
- colliders.map_mut_internal(handle.0, |co_changes: &mut ColliderChanges| {
- if !co_changes.contains(ColliderChanges::MODIFIED) {
- modified_colliders.push(*handle);
- }
+ let co = colliders.index_mut_internal(*handle);
+ if !co.changes.contains(ColliderChanges::MODIFIED) {
+ modified_colliders.push(*handle);
+ }
- *co_changes |=
- ColliderChanges::MODIFIED | ColliderChanges::PARENT_EFFECTIVE_DOMINANCE;
- });
+ co.changes |=
+ ColliderChanges::MODIFIED | ColliderChanges::PARENT_EFFECTIVE_DOMINANCE;
}
}
- bodies.set_internal(handle.0, RigidBodyChanges::empty());
- bodies.set_internal(handle.0, ids);
- bodies.set_internal(handle.0, activation);
+ rb.changes = RigidBodyChanges::empty();
+ rb.ids = ids;
+ rb.activation = activation;
}
// Adjust some ids, if needed.
@@ -187,9 +178,7 @@ pub(crate) fn handle_user_changes_to_rigid_bodies(
};
if id < active_set.len() {
- bodies.map_mut_internal(active_set[id].0, |ids2: &mut RigidBodyIds| {
- ids2.active_set_id = id;
- });
+ bodies.index_mut_internal(active_set[id]).ids.active_set_id = id;
}
}
}