Skip to content

Commit bb24328

Browse files
committed
chore: remove redundant active_set_offset field
1 parent 4ec377f commit bb24328

File tree

11 files changed

+34
-56
lines changed

11 files changed

+34
-56
lines changed

src/dynamics/island_manager/island.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ impl IslandManager {
7777
);
7878
rb.ids.active_island_id = new_island_id;
7979
rb.ids.active_set_id = id;
80-
rb.ids.active_set_offset = id as u32;
8180

8281
new_island.additional_solver_iterations = new_island
8382
.additional_solver_iterations
@@ -87,7 +86,6 @@ impl IslandManager {
8786
if let Some(moved_handle) = source_island.bodies.get(id_to_remove).copied() {
8887
let moved_rb = bodies.index_mut_internal(moved_handle);
8988
moved_rb.ids.active_set_id = id_to_remove;
90-
moved_rb.ids.active_set_offset = id_to_remove as u32;
9189
}
9290
}
9391

@@ -147,7 +145,6 @@ impl IslandManager {
147145
rb.wake_up(false);
148146
rb.ids.active_island_id = to_keep;
149147
rb.ids.active_set_id = target_island.bodies.len();
150-
rb.ids.active_set_offset = (target_island.bodies.len()) as u32;
151148
target_island.bodies.push(*handle);
152149
target_island.additional_solver_iterations = target_island
153150
.additional_solver_iterations

src/dynamics/island_manager/manager.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ impl IslandManager {
6767
};
6868

6969
let swapped_handle = island.bodies.last().copied().unwrap_or(removed_handle);
70-
island
71-
.bodies
72-
.swap_remove(removed_ids.active_set_offset as usize);
70+
island.bodies.swap_remove(removed_ids.active_set_id);
7371

7472
// Remap the active_set_id of the body we moved with the `swap_remove`.
7573
if swapped_handle != removed_handle {
7674
let swapped_body = bodies
7775
.get_mut(swapped_handle)
7876
.expect("Internal error: bodies must be removed from islands on at a times");
79-
swapped_body.ids.active_set_offset = removed_ids.active_set_offset;
8077
swapped_body.ids.active_set_id = removed_ids.active_set_id;
8178
}
8279

@@ -187,7 +184,6 @@ impl IslandManager {
187184

188185
rb.ids.active_island_id = id;
189186
rb.ids.active_set_id = target_island.bodies.len();
190-
rb.ids.active_set_offset = target_island.bodies.len() as u32;
191187
target_island.bodies.push(handle);
192188
} else {
193189
let mut new_island = Island::singleton(handle, rb);
@@ -201,7 +197,6 @@ impl IslandManager {
201197
self.islands.insert(id, new_island);
202198
rb.ids.active_island_id = id;
203199
rb.ids.active_set_id = 0;
204-
rb.ids.active_set_offset = 0;
205200
}
206201
}
207202

src/dynamics/island_manager/validation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ impl IslandManager {
2626
assert_eq!(rb.is_sleeping(), island.is_sleeping());
2727
// The body’s island id must match the island id.
2828
assert_eq!(rb.ids.active_island_id, island_id);
29-
// The body’s offset must match its handle’s position in island.bodies.
30-
assert_eq!(body_id, rb.ids.active_set_offset as usize);
29+
// The body’s active set id must match its handle’s position in island.bodies.
3130
assert_eq!(body_id, rb.ids.active_set_id);
3231
}
3332
}

src/dynamics/rigid_body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl RigidBody {
665665
// to all the fixed bodies active set offsets?
666666
pub fn effective_active_set_offset(&self) -> u32 {
667667
if self.is_dynamic_or_kinematic() {
668-
self.ids.active_set_offset
668+
self.ids.active_set_id as u32
669669
} else {
670670
u32::MAX
671671
}

src/dynamics/rigid_body_components.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,6 @@ impl RigidBodyCcd {
10291029
pub struct RigidBodyIds {
10301030
pub(crate) active_island_id: usize,
10311031
pub(crate) active_set_id: usize,
1032-
pub(crate) active_set_offset: u32,
10331032
pub(crate) active_set_timestamp: u32,
10341033
}
10351034

@@ -1038,7 +1037,6 @@ impl Default for RigidBodyIds {
10381037
Self {
10391038
active_island_id: usize::MAX,
10401039
active_set_id: usize::MAX,
1041-
active_set_offset: u32::MAX,
10421040
active_set_timestamp: 0,
10431041
}
10441042
}

src/dynamics/solver/contact_constraint/contact_with_coulomb_friction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ impl ContactWithCoulombFrictionBuilder {
5252
&& manifold_id[ii] != usize::MAX
5353
{
5454
let handle = manifolds[ii].data.rigid_body1.unwrap(); // Can unwrap thanks to the dominance check.
55-
bodies[handle].ids.active_set_offset
55+
bodies[handle].ids.active_set_id as u32
5656
} else {
5757
u32::MAX
5858
}];
5959
let ids2: [u32; SIMD_WIDTH] = array![|ii| if manifolds[ii].data.relative_dominance >= 0
6060
&& manifold_id[ii] != usize::MAX
6161
{
6262
let handle = manifolds[ii].data.rigid_body2.unwrap(); // Can unwrap thanks to the dominance check.
63-
bodies[handle].ids.active_set_offset
63+
bodies[handle].ids.active_set_id as u32
6464
} else {
6565
u32::MAX
6666
}];

src/dynamics/solver/contact_constraint/contact_with_twist_friction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ impl ContactWithTwistFrictionBuilder {
5959
&& manifold_id[ii] != usize::MAX
6060
{
6161
let handle = manifolds[ii].data.rigid_body1.unwrap(); // Can unwrap thanks to the dominance check.
62-
bodies[handle].ids.active_set_offset
62+
bodies[handle].ids.active_set_id as u32
6363
} else {
6464
u32::MAX
6565
}];
6666
let ids2: [u32; SIMD_WIDTH] = array![|ii| if manifolds[ii].data.relative_dominance >= 0
6767
&& manifold_id[ii] != usize::MAX
6868
{
6969
let handle = manifolds[ii].data.rigid_body2.unwrap(); // Can unwrap thanks to the dominance check.
70-
bodies[handle].ids.active_set_offset
70+
bodies[handle].ids.active_set_id as u32
7171
} else {
7272
u32::MAX
7373
}];

src/dynamics/solver/contact_constraint/generic_contact_constraint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ impl GenericContactConstraintBuilder {
6868
multibody1
6969
.map(|mb| mb.0.solver_id)
7070
.unwrap_or(if type1.is_dynamic_or_kinematic() {
71-
rb1.ids.active_set_offset
71+
rb1.ids.active_set_id as u32
7272
} else {
7373
u32::MAX
7474
});
7575
let solver_vel2 =
7676
multibody2
7777
.map(|mb| mb.0.solver_id)
7878
.unwrap_or(if type2.is_dynamic_or_kinematic() {
79-
rb2.ids.active_set_offset
79+
rb2.ids.active_set_id as u32
8080
} else {
8181
u32::MAX
8282
});

src/dynamics/solver/interaction_groups.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,26 @@ impl ParallelInteractionGroups {
117117
(false, false) => {
118118
let rb1 = &bodies[body_pair.0.unwrap()];
119119
let rb2 = &bodies[body_pair.1.unwrap()];
120-
let color_mask = bcolors[rb1.ids.active_set_offset as usize]
121-
| bcolors[rb2.ids.active_set_offset as usize];
120+
let color_mask =
121+
bcolors[rb1.ids.active_set_id] | bcolors[rb2.ids.active_set_id];
122122
*color = (!color_mask).trailing_zeros() as usize;
123123
color_len[*color] += 1;
124-
bcolors[rb1.ids.active_set_offset as usize] |= 1 << *color;
125-
bcolors[rb2.ids.active_set_offset as usize] |= 1 << *color;
124+
bcolors[rb1.ids.active_set_id] |= 1 << *color;
125+
bcolors[rb2.ids.active_set_id] |= 1 << *color;
126126
}
127127
(true, false) => {
128128
let rb2 = &bodies[body_pair.1.unwrap()];
129-
let color_mask = bcolors[rb2.ids.active_set_offset as usize];
129+
let color_mask = bcolors[rb2.ids.active_set_id];
130130
*color = 127 - (!color_mask).leading_zeros() as usize;
131131
color_len[*color] += 1;
132-
bcolors[rb2.ids.active_set_offset as usize] |= 1 << *color;
132+
bcolors[rb2.ids.active_set_id] |= 1 << *color;
133133
}
134134
(false, true) => {
135135
let rb1 = &bodies[body_pair.0.unwrap()];
136-
let color_mask = bcolors[rb1.ids.active_set_offset as usize];
136+
let color_mask = bcolors[rb1.ids.active_set_id];
137137
*color = 127 - (!color_mask).leading_zeros() as usize;
138138
color_len[*color] += 1;
139-
bcolors[rb1.ids.active_set_offset as usize] |= 1 << *color;
139+
bcolors[rb1.ids.active_set_id] |= 1 << *color;
140140
}
141141
(true, true) => unreachable!(),
142142
}
@@ -270,18 +270,10 @@ impl InteractionGroups {
270270
}
271271

272272
let ijoint = interaction.data.locked_axes.bits() as usize;
273-
let i1 = rb1.ids.active_set_offset;
274-
let i2 = rb2.ids.active_set_offset;
275-
let conflicts = self
276-
.body_masks
277-
.get(i1 as usize)
278-
.copied()
279-
.unwrap_or_default()
280-
| self
281-
.body_masks
282-
.get(i2 as usize)
283-
.copied()
284-
.unwrap_or_default()
273+
let i1 = rb1.ids.active_set_id;
274+
let i2 = rb2.ids.active_set_id;
275+
let conflicts = self.body_masks.get(i1).copied().unwrap_or_default()
276+
| self.body_masks.get(i2).copied().unwrap_or_default()
285277
| joint_type_conflicts[ijoint];
286278
let conflictfree_targets = !(conflicts & occupied_mask); // The & is because we consider empty buckets as free of conflicts.
287279
let conflictfree_occupied_targets = conflictfree_targets & occupied_mask;
@@ -420,17 +412,15 @@ impl InteractionGroups {
420412
continue;
421413
}
422414

423-
let (status1, active_set_offset1) = if let Some(rb1) = interaction.data.rigid_body1
424-
{
415+
let (status1, active_set_id1) = if let Some(rb1) = interaction.data.rigid_body1 {
425416
let rb1 = &bodies[rb1];
426-
(rb1.body_type, rb1.ids.active_set_offset)
417+
(rb1.body_type, rb1.ids.active_set_id as u32)
427418
} else {
428419
(RigidBodyType::Fixed, u32::MAX)
429420
};
430-
let (status2, active_set_offset2) = if let Some(rb2) = interaction.data.rigid_body2
431-
{
421+
let (status2, active_set_id2) = if let Some(rb2) = interaction.data.rigid_body2 {
432422
let rb2 = &bodies[rb2];
433-
(rb2.body_type, rb2.ids.active_set_offset)
423+
(rb2.body_type, rb2.ids.active_set_id as u32)
434424
} else {
435425
(RigidBodyType::Fixed, u32::MAX)
436426
};
@@ -443,8 +433,8 @@ impl InteractionGroups {
443433
continue;
444434
}
445435

446-
let i1 = active_set_offset1;
447-
let i2 = active_set_offset2;
436+
let i1 = active_set_id1;
437+
let i2 = active_set_id2;
448438
let mask1 = if !is_fixed1 {
449439
self.body_masks[i1 as usize]
450440
} else {

src/dynamics/solver/joint_constraint/joint_constraint_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ impl JointConstraintBuilderSimd {
119119
let rb2 = array![|ii| &bodies[joint[ii].body2]];
120120

121121
let body1 = array![|ii| if rb1[ii].is_dynamic_or_kinematic() {
122-
rb1[ii].ids.active_set_offset
122+
rb1[ii].ids.active_set_id as u32
123123
} else {
124124
u32::MAX
125125
}];
126126
let body2 = array![|ii| if rb2[ii].is_dynamic_or_kinematic() {
127-
rb2[ii].ids.active_set_offset
127+
rb2[ii].ids.active_set_id as u32
128128
} else {
129129
u32::MAX
130130
}];

0 commit comments

Comments
 (0)