@@ -734,6 +734,12 @@ pub fn init_colliders(
734
734
let context = & mut * context;
735
735
let physics_scale = context. physics_scale ;
736
736
737
+ let colliders = colliders. iter ( ) ;
738
+ #[ cfg( feature = "enhanced-determinism" ) ]
739
+ let mut colliders: Vec < ColliderComponents > = colliders. collect ( ) ;
740
+ #[ cfg( feature = "enhanced-determinism" ) ]
741
+ colliders. sort_unstable_by_key ( |f| f. 0 ) ;
742
+
737
743
for (
738
744
entity,
739
745
shape,
@@ -747,7 +753,7 @@ pub fn init_colliders(
747
753
collision_groups,
748
754
solver_groups,
749
755
contact_force_event_threshold,
750
- ) in colliders. iter ( )
756
+ ) in colliders
751
757
{
752
758
let mut scaled_shape = shape. clone ( ) ;
753
759
scaled_shape. set_scale ( shape. scale / physics_scale, config. scaled_shape_subdivision ) ;
@@ -851,6 +857,12 @@ pub fn init_rigid_bodies(
851
857
) {
852
858
let physics_scale = context. physics_scale ;
853
859
860
+ let rigid_bodies = rigid_bodies. iter ( ) ;
861
+ #[ cfg( feature = "enhanced-determinism" ) ]
862
+ let mut rigid_bodies: Vec < RigidBodyComponents > = rigid_bodies. collect ( ) ;
863
+ #[ cfg( feature = "enhanced-determinism" ) ]
864
+ rigid_bodies. sort_unstable_by_key ( |f| f. 0 ) ;
865
+
854
866
for (
855
867
entity,
856
868
rb,
@@ -865,7 +877,7 @@ pub fn init_rigid_bodies(
865
877
dominance,
866
878
sleep,
867
879
damping,
868
- ) in rigid_bodies. iter ( )
880
+ ) in rigid_bodies
869
881
{
870
882
let mut builder = RigidBodyBuilder :: new ( ( * rb) . into ( ) ) ;
871
883
if let Some ( transform) = transform {
@@ -994,7 +1006,13 @@ pub fn init_joints(
994
1006
let context = & mut * context;
995
1007
let scale = context. physics_scale ;
996
1008
997
- for ( entity, joint) in impulse_joints. iter ( ) {
1009
+ let impulse_joints = impulse_joints. iter ( ) ;
1010
+ #[ cfg( feature = "enhanced-determinism" ) ]
1011
+ let mut impulse_joints: Vec < ( Entity , & ImpulseJoint ) > = impulse_joints. collect ( ) ;
1012
+ #[ cfg( feature = "enhanced-determinism" ) ]
1013
+ impulse_joints. sort_unstable_by_key ( |f| f. 0 ) ;
1014
+
1015
+ for ( entity, joint) in impulse_joints {
998
1016
let mut target = None ;
999
1017
let mut body_entity = entity;
1000
1018
while target. is_none ( ) {
@@ -1018,7 +1036,13 @@ pub fn init_joints(
1018
1036
}
1019
1037
}
1020
1038
1021
- for ( entity, joint) in multibody_joints. iter ( ) {
1039
+ let multibody_joints = multibody_joints. iter ( ) ;
1040
+ #[ cfg( feature = "enhanced-determinism" ) ]
1041
+ let mut multibody_joints: Vec < ( Entity , & MultibodyJoint ) > = multibody_joints. collect ( ) ;
1042
+ #[ cfg( feature = "enhanced-determinism" ) ]
1043
+ multibody_joints. sort_unstable_by_key ( |f| f. 0 ) ;
1044
+
1045
+ for ( entity, joint) in multibody_joints {
1022
1046
let target = context. entity2body . get ( & entity) ;
1023
1047
1024
1048
if let ( Some ( target) , Some ( source) ) = ( target, context. entity2body . get ( & joint. parent ) ) {
@@ -1096,7 +1120,13 @@ pub fn sync_removals(
1096
1120
/*
1097
1121
* Collider removal detection.
1098
1122
*/
1099
- for entity in removed_colliders. iter ( ) {
1123
+ let removed_colliders = removed_colliders. iter ( ) ;
1124
+ #[ cfg( feature = "enhanced-determinism" ) ]
1125
+ let mut removed_colliders: Vec < Entity > = removed_colliders. collect ( ) ;
1126
+ #[ cfg( feature = "enhanced-determinism" ) ]
1127
+ removed_colliders. sort_unstable ( ) ;
1128
+
1129
+ for entity in removed_colliders {
1100
1130
if let Some ( handle) = context. entity2collider . remove ( & entity) {
1101
1131
context
1102
1132
. colliders
@@ -1105,7 +1135,13 @@ pub fn sync_removals(
1105
1135
}
1106
1136
}
1107
1137
1108
- for entity in orphan_colliders. iter ( ) {
1138
+ let orphan_colliders = orphan_colliders. iter ( ) ;
1139
+ #[ cfg( feature = "enhanced-determinism" ) ]
1140
+ let mut orphan_colliders: Vec < Entity > = orphan_colliders. collect ( ) ;
1141
+ #[ cfg( feature = "enhanced-determinism" ) ]
1142
+ orphan_colliders. sort_unstable ( ) ;
1143
+
1144
+ for entity in orphan_colliders {
1109
1145
if let Some ( handle) = context. entity2collider . remove ( & entity) {
1110
1146
context
1111
1147
. colliders
0 commit comments