@@ -851,6 +851,12 @@ pub fn init_colliders(
851
851
let context = & mut * context;
852
852
let physics_scale = context. physics_scale ;
853
853
854
+ let colliders = colliders. iter ( ) ;
855
+ #[ cfg( feature = "enhanced-determinism" ) ]
856
+ let mut colliders: Vec < ( ColliderComponents , Option < & GlobalTransform > ) > = colliders. collect ( ) ;
857
+ #[ cfg( feature = "enhanced-determinism" ) ]
858
+ colliders. sort_unstable_by_key ( |f| f. 0 . 0 ) ;
859
+
854
860
for (
855
861
(
856
862
entity,
@@ -868,7 +874,7 @@ pub fn init_colliders(
868
874
disabled,
869
875
) ,
870
876
global_transform,
871
- ) in colliders. iter ( )
877
+ ) in colliders
872
878
{
873
879
let mut scaled_shape = shape. clone ( ) ;
874
880
scaled_shape. set_scale ( shape. scale / physics_scale, config. scaled_shape_subdivision ) ;
@@ -968,6 +974,12 @@ pub fn init_rigid_bodies(
968
974
) {
969
975
let physics_scale = context. physics_scale ;
970
976
977
+ let rigid_bodies = rigid_bodies. iter ( ) ;
978
+ #[ cfg( feature = "enhanced-determinism" ) ]
979
+ let mut rigid_bodies: Vec < RigidBodyComponents > = rigid_bodies. collect ( ) ;
980
+ #[ cfg( feature = "enhanced-determinism" ) ]
981
+ rigid_bodies. sort_unstable_by_key ( |f| f. 0 ) ;
982
+
971
983
for (
972
984
entity,
973
985
rb,
@@ -983,7 +995,7 @@ pub fn init_rigid_bodies(
983
995
sleep,
984
996
damping,
985
997
disabled,
986
- ) in rigid_bodies. iter ( )
998
+ ) in rigid_bodies
987
999
{
988
1000
let mut builder = RigidBodyBuilder :: new ( ( * rb) . into ( ) ) ;
989
1001
builder = builder. enabled ( disabled. is_none ( ) ) ;
@@ -1114,7 +1126,13 @@ pub fn init_joints(
1114
1126
let context = & mut * context;
1115
1127
let scale = context. physics_scale ;
1116
1128
1117
- for ( entity, joint) in impulse_joints. iter ( ) {
1129
+ let impulse_joints = impulse_joints. iter ( ) ;
1130
+ #[ cfg( feature = "enhanced-determinism" ) ]
1131
+ let mut impulse_joints: Vec < ( Entity , & ImpulseJoint ) > = impulse_joints. collect ( ) ;
1132
+ #[ cfg( feature = "enhanced-determinism" ) ]
1133
+ impulse_joints. sort_unstable_by_key ( |f| f. 0 ) ;
1134
+
1135
+ for ( entity, joint) in impulse_joints {
1118
1136
let mut target = None ;
1119
1137
let mut body_entity = entity;
1120
1138
while target. is_none ( ) {
@@ -1138,7 +1156,13 @@ pub fn init_joints(
1138
1156
}
1139
1157
}
1140
1158
1141
- for ( entity, joint) in multibody_joints. iter ( ) {
1159
+ let multibody_joints = multibody_joints. iter ( ) ;
1160
+ #[ cfg( feature = "enhanced-determinism" ) ]
1161
+ let mut multibody_joints: Vec < ( Entity , & MultibodyJoint ) > = multibody_joints. collect ( ) ;
1162
+ #[ cfg( feature = "enhanced-determinism" ) ]
1163
+ multibody_joints. sort_unstable_by_key ( |f| f. 0 ) ;
1164
+
1165
+ for ( entity, joint) in multibody_joints {
1142
1166
let target = context. entity2body . get ( & entity) ;
1143
1167
1144
1168
if let ( Some ( target) , Some ( source) ) = ( target, context. entity2body . get ( & joint. parent ) ) {
@@ -1220,7 +1244,13 @@ pub fn sync_removals(
1220
1244
/*
1221
1245
* Collider removal detection.
1222
1246
*/
1223
- for entity in removed_colliders. read ( ) {
1247
+ let removed_colliders = removed_colliders. read ( ) ;
1248
+ #[ cfg( feature = "enhanced-determinism" ) ]
1249
+ let mut removed_colliders: Vec < Entity > = removed_colliders. collect ( ) ;
1250
+ #[ cfg( feature = "enhanced-determinism" ) ]
1251
+ removed_colliders. sort_unstable ( ) ;
1252
+
1253
+ for entity in removed_colliders {
1224
1254
if let Some ( parent) = context. collider_parent ( entity) {
1225
1255
mass_modified. send ( parent. into ( ) ) ;
1226
1256
}
@@ -1233,7 +1263,13 @@ pub fn sync_removals(
1233
1263
}
1234
1264
}
1235
1265
1236
- for entity in orphan_colliders. iter ( ) {
1266
+ let orphan_colliders = orphan_colliders. iter ( ) ;
1267
+ #[ cfg( feature = "enhanced-determinism" ) ]
1268
+ let mut orphan_colliders: Vec < Entity > = orphan_colliders. collect ( ) ;
1269
+ #[ cfg( feature = "enhanced-determinism" ) ]
1270
+ orphan_colliders. sort_unstable ( ) ;
1271
+
1272
+ for entity in orphan_colliders {
1237
1273
if let Some ( parent) = context. collider_parent ( entity) {
1238
1274
mass_modified. send ( parent. into ( ) ) ;
1239
1275
}
0 commit comments