@series-inc/rundot-syncplay 6.0.0-rc.55 → 6.0.0-rc.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -215,6 +215,24 @@ inline void checkpointRecordSchemaGuard(const CheckpointBodyTable& value) noexce
215
215
  [[maybe_unused]] const auto& [tileValues, valueCount, tiles, tileAllocationBytes,
216
216
  selfAllocationBytes, totalAllocatedBytes] = value;
217
217
  }
218
+ inline void checkpointRecordSchemaGuard(const CheckpointStaticSlab& value) noexcept {
219
+ [[maybe_unused]] const auto& [
220
+ totalAllocatedBytes,
221
+ stampedAllocatedBytes,
222
+ bodyMaterialsOffset,
223
+ bodyMaterialsCount,
224
+ topologyBodyIdsOffset,
225
+ topologyBodyIdsCount,
226
+ topologyJointsOffset,
227
+ topologyJointsCount,
228
+ topologyFluidIdsOffset,
229
+ topologyFluidIdsCount,
230
+ bodyDefinitionSignaturesOffset,
231
+ bodyDefinitionSignaturesCount,
232
+ jointDefinitionSignaturesOffset,
233
+ jointDefinitionSignaturesCount
234
+ ] = value;
235
+ }
218
236
  inline void checkpointRecordSchemaGuard(const BodyId& value) noexcept {
219
237
  [[maybe_unused]] const auto& [id] = value;
220
238
  }
@@ -243,6 +261,7 @@ inline void checkpointDataSchemaGuard(const CheckpointData& data) noexcept {
243
261
  const auto& [
244
262
  world,
245
263
  bodies,
264
+ staticSlab,
246
265
  geometryRoot,
247
266
  pose,
248
267
  profile,
@@ -269,8 +288,6 @@ inline void checkpointDataSchemaGuard(const CheckpointData& data) noexcept {
269
288
  fluidsCount,
270
289
  surfaceVelocitiesOffset,
271
290
  surfaceVelocitiesCount,
272
- bodyMaterialsOffset,
273
- bodyMaterialsCount,
274
291
  bodyMaterialFramesOffset,
275
292
  bodyMaterialFramesCount,
276
293
  jointWarmStateOffset,
@@ -283,16 +300,6 @@ inline void checkpointDataSchemaGuard(const CheckpointData& data) noexcept {
283
300
  jointBreakEventsCount,
284
301
  fluidInteractionsOffset,
285
302
  fluidInteractionsCount,
286
- topologyBodyIdsOffset,
287
- topologyBodyIdsCount,
288
- topologyJointsOffset,
289
- topologyJointsCount,
290
- topologyFluidIdsOffset,
291
- topologyFluidIdsCount,
292
- bodyDefinitionSignaturesOffset,
293
- bodyDefinitionSignaturesCount,
294
- jointDefinitionSignaturesOffset,
295
- jointDefinitionSignaturesCount,
296
303
  geometryForm,
297
304
  strongMemoState,
298
305
  strongMemoLimits,
@@ -300,6 +307,7 @@ inline void checkpointDataSchemaGuard(const CheckpointData& data) noexcept {
300
307
  ] = data;
301
308
  static_cast<void>(world);
302
309
  static_cast<void>(bodies);
310
+ static_cast<void>(staticSlab);
303
311
  static_cast<void>(geometryRoot);
304
312
  static_cast<void>(pose);
305
313
  static_cast<void>(profile);
@@ -326,8 +334,6 @@ inline void checkpointDataSchemaGuard(const CheckpointData& data) noexcept {
326
334
  static_cast<void>(fluidsCount);
327
335
  static_cast<void>(surfaceVelocitiesOffset);
328
336
  static_cast<void>(surfaceVelocitiesCount);
329
- static_cast<void>(bodyMaterialsOffset);
330
- static_cast<void>(bodyMaterialsCount);
331
337
  static_cast<void>(bodyMaterialFramesOffset);
332
338
  static_cast<void>(bodyMaterialFramesCount);
333
339
  static_cast<void>(jointWarmStateOffset);
@@ -340,16 +346,6 @@ inline void checkpointDataSchemaGuard(const CheckpointData& data) noexcept {
340
346
  static_cast<void>(jointBreakEventsCount);
341
347
  static_cast<void>(fluidInteractionsOffset);
342
348
  static_cast<void>(fluidInteractionsCount);
343
- static_cast<void>(topologyBodyIdsOffset);
344
- static_cast<void>(topologyBodyIdsCount);
345
- static_cast<void>(topologyJointsOffset);
346
- static_cast<void>(topologyJointsCount);
347
- static_cast<void>(topologyFluidIdsOffset);
348
- static_cast<void>(topologyFluidIdsCount);
349
- static_cast<void>(bodyDefinitionSignaturesOffset);
350
- static_cast<void>(bodyDefinitionSignaturesCount);
351
- static_cast<void>(jointDefinitionSignaturesOffset);
352
- static_cast<void>(jointDefinitionSignaturesCount);
353
349
  static_cast<void>(geometryForm);
354
350
  static_cast<void>(strongMemoState);
355
351
  static_cast<void>(strongMemoLimits);
@@ -3881,6 +3881,22 @@ struct SolverStorage {
3881
3881
  std::vector<double> contactCacheOutput;
3882
3882
  std::vector<std::uint8_t> contactSupported;
3883
3883
  std::vector<std::uint8_t> movingFoundation;
3884
+ struct RestingSubstepPairCacheEntry {
3885
+ std::uint64_t pairKey = 0;
3886
+ std::uint32_t outputIndex = 0;
3887
+ std::uint32_t newConstraintCount = 0;
3888
+ std::uint32_t lower = 0;
3889
+ std::uint32_t upper = 0;
3890
+ std::uint8_t hit = 0;
3891
+ std::uint8_t alignedSupport = 0;
3892
+ };
3893
+ std::vector<RestingSubstepPairCacheEntry> restingSubstepPairCache;
3894
+ std::uint32_t restingSubstepPairCount = 0;
3895
+ std::uint32_t restingSubstepPairCursor = 0;
3896
+ bool firstSubstepOfTick = false;
3897
+ std::vector<std::uint8_t> componentHasJoint;
3898
+ std::vector<std::uint8_t> componentHasActive;
3899
+ bool sweepPairsReady = false;
3884
3900
  std::vector<std::uint32_t> contactSolvePairBegin;
3885
3901
  std::vector<std::uint32_t> contactSolvePairEnd;
3886
3902
  std::vector<std::uint32_t> contactSolveTelemetryIndex;
@@ -4433,6 +4449,7 @@ void SolverStorage::invalidate() noexcept {
4433
4449
  broadphasePairCount = 0;
4434
4450
  broadphasePairOverflow = false;
4435
4451
  broadphasePairOwner = BroadphasePairOwner::None;
4452
+ sweepPairsReady = false;
4436
4453
  contactTelemetryCount = 0;
4437
4454
  worldContactOutputCount = 0;
4438
4455
  contactConstraintCount = 0;
@@ -4440,6 +4457,12 @@ void SolverStorage::invalidate() noexcept {
4440
4457
  contactCacheOutput.clear();
4441
4458
  contactSupported.clear();
4442
4459
  movingFoundation.clear();
4460
+ restingSubstepPairCache.clear();
4461
+ restingSubstepPairCount = 0;
4462
+ restingSubstepPairCursor = 0;
4463
+ firstSubstepOfTick = false;
4464
+ componentHasJoint.clear();
4465
+ componentHasActive.clear();
4443
4466
  contactSolvePairCount = 0;
4444
4467
  contactSolvePairBegin.clear();
4445
4468
  contactSolvePairEnd.clear();
@@ -4494,6 +4517,9 @@ std::uint64_t SolverStorage::retainedBytes() const noexcept {
4494
4517
  + retainedVectorBytes(contactCacheOutput)
4495
4518
  + retainedVectorBytes(contactSupported)
4496
4519
  + retainedVectorBytes(movingFoundation)
4520
+ + retainedVectorBytes(restingSubstepPairCache)
4521
+ + retainedVectorBytes(componentHasJoint)
4522
+ + retainedVectorBytes(componentHasActive)
4497
4523
  + retainedVectorBytes(contactSolvePairBegin)
4498
4524
  + retainedVectorBytes(contactSolvePairEnd)
4499
4525
  + retainedVectorBytes(contactSolveTelemetryIndex)
@@ -4568,6 +4594,13 @@ void prepareStepStorage(SolverStorage& storage, std::uint32_t bodyCount, std::ui
4568
4594
  storage.contactConstraints.clear();
4569
4595
  storage.contactSupported.resize(bodyCount);
4570
4596
  storage.movingFoundation.resize(bodyCount);
4597
+ storage.restingSubstepPairCache.resize(pairCapacity);
4598
+ storage.restingSubstepPairCount = 0;
4599
+ storage.restingSubstepPairCursor = 0;
4600
+ storage.firstSubstepOfTick = false;
4601
+ storage.componentHasJoint.resize(bodyCount);
4602
+ storage.componentHasActive.resize(bodyCount);
4603
+ storage.sweepPairsReady = false;
4571
4604
  storage.contactSolvePairBegin.resize(pairCapacity);
4572
4605
  storage.contactSolvePairEnd.resize(pairCapacity);
4573
4606
  storage.contactSolveTelemetryIndex.resize(pairCapacity);
@@ -4700,6 +4733,7 @@ void collectSweepPairs(SolverOperation& operation, const Body* bodies, std::uint
4700
4733
  operation.storage.broadphasePairCount = 0;
4701
4734
  operation.storage.broadphasePairOverflow = false;
4702
4735
  operation.storage.broadphasePairOwner = BroadphasePairOwner::Sweep;
4736
+ operation.storage.sweepPairsReady = true;
4703
4737
  for (std::uint32_t leftOrder = 0; leftOrder < bodyCount; leftOrder += 1) {
4704
4738
  const std::uint32_t left = operation.storage.broadphaseOrder[leftOrder];
4705
4739
  const bool leftStatic = !bodies[left].dynamic && !bodies[left].kinematic;
@@ -10278,46 +10312,53 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10278
10312
  const bool solveVelocity = policy.solveVelocity;
10279
10313
  const bool isSmallCandidateWorld = bodyCount <= 16 && operation.proxyHook == nullptr;
10280
10314
  if (beginSubstep) {
10281
- operation.storage.sleepPairCount = 0;
10282
- if (firstTickSubstep) {
10283
- operation.storage.contactConstraints.clear();
10284
- if (isSmallCandidateWorld) {
10285
- operation.storage.contactConstraintCount = 0;
10286
- }
10287
- } else {
10288
- if (isSmallCandidateWorld) {
10289
- if (solveVelocity) {
10315
+ operation.storage.contactConstraintOverflow = false;
10316
+ if (pass != ContactPass::OwnedPositionCorrection) {
10317
+ operation.storage.sleepPairCount = 0;
10318
+ if (firstTickSubstep) {
10319
+ operation.storage.contactConstraints.clear();
10320
+ if (isSmallCandidateWorld) {
10321
+ operation.storage.contactConstraintCount = 0;
10322
+ }
10323
+ } else {
10324
+ if (isSmallCandidateWorld) {
10325
+ if (solveVelocity) {
10326
+ operation.storage.contactConstraints.erase(
10327
+ std::remove_if(
10328
+ operation.storage.contactConstraints.begin(),
10329
+ operation.storage.contactConstraints.end(),
10330
+ [](const ContactConstraintBlock& constraint) {
10331
+ if (constraint.preserveForCache) return false;
10332
+ if (!constraint.activeForVelocityPhase) return true;
10333
+ return std::abs(constraint.normal[1]) < 0.7;
10334
+ }),
10335
+ operation.storage.contactConstraints.end());
10336
+ for (auto& constraint : operation.storage.contactConstraints) {
10337
+ constraint.activeForVelocityPhase = false;
10338
+ }
10339
+ }
10340
+ } else {
10290
10341
  operation.storage.contactConstraints.erase(
10291
10342
  std::remove_if(
10292
10343
  operation.storage.contactConstraints.begin(),
10293
10344
  operation.storage.contactConstraints.end(),
10294
10345
  [](const ContactConstraintBlock& constraint) {
10295
- if (constraint.preserveForCache) return false;
10296
- if (!constraint.activeForVelocityPhase) return true;
10297
- return std::abs(constraint.normal[1]) < 0.7;
10346
+ return !constraint.preserveForCache;
10298
10347
  }),
10299
10348
  operation.storage.contactConstraints.end());
10300
- for (auto& constraint : operation.storage.contactConstraints) {
10301
- constraint.activeForVelocityPhase = false;
10302
- }
10303
10349
  }
10304
- } else {
10305
- operation.storage.contactConstraints.erase(
10306
- std::remove_if(
10307
- operation.storage.contactConstraints.begin(),
10308
- operation.storage.contactConstraints.end(),
10309
- [](const ContactConstraintBlock& constraint) {
10310
- return !constraint.preserveForCache;
10311
- }),
10312
- operation.storage.contactConstraints.end());
10313
- }
10314
- }
10315
- operation.storage.contactConstraintCount = static_cast<std::uint32_t>(
10316
- operation.storage.contactConstraints.size());
10317
- operation.storage.contactSolvePairCount = 0;
10318
- std::fill(operation.storage.contactSupported.begin(),
10319
- operation.storage.contactSupported.end(), 0);
10320
- operation.storage.contactConstraintOverflow = false;
10350
+ }
10351
+ operation.storage.contactConstraintCount = static_cast<std::uint32_t>(
10352
+ operation.storage.contactConstraints.size());
10353
+ operation.storage.contactSolvePairCount = 0;
10354
+ std::fill(operation.storage.contactSupported.begin(),
10355
+ operation.storage.contactSupported.end(), 0);
10356
+ operation.storage.firstSubstepOfTick = firstTickSubstep;
10357
+ if (firstTickSubstep) {
10358
+ operation.storage.restingSubstepPairCount = 0;
10359
+ }
10360
+ operation.storage.restingSubstepPairCursor = 0;
10361
+ }
10321
10362
  }
10322
10363
  if (firstTickSubstep) {
10323
10364
  initializeContactTickOutputs(operation.storage);
@@ -10553,9 +10594,12 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10553
10594
  if (operation.materialMotionEpochs == nullptr && !pairHasJoint) return;
10554
10595
  if (resolveContactPair(operation, bodies[first], bodies[second], options,
10555
10596
  nullptr, nullptr, nullptr, nullptr, nullptr, true,
10556
- applyPositionCorrection, false) && updateConstraintMobility) {
10557
- operation.storage.constraintMobility[first] = constraintBodyMobility(bodies[first]);
10558
- operation.storage.constraintMobility[second] = constraintBodyMobility(bodies[second]);
10597
+ applyPositionCorrection, false)) {
10598
+ operation.storage.sweepPairsReady = false;
10599
+ if (updateConstraintMobility) {
10600
+ operation.storage.constraintMobility[first] = constraintBodyMobility(bodies[first]);
10601
+ operation.storage.constraintMobility[second] = constraintBodyMobility(bodies[second]);
10602
+ }
10559
10603
  }
10560
10604
  return;
10561
10605
  }
@@ -10625,16 +10669,109 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10625
10669
  Body& secondBody = bodies[second];
10626
10670
  if ((firstBody.mask & secondBody.layer) == 0
10627
10671
  || (secondBody.mask & firstBody.layer) == 0) return;
10672
+ const bool isRestingBox = restingBoxPair(operation, first, second);
10673
+ const std::uint64_t pairKey =
10674
+ (static_cast<std::uint64_t>(first) << 32) | static_cast<std::uint64_t>(second);
10675
+ if (!operation.storage.firstSubstepOfTick && isRestingBox) {
10676
+ const std::uint32_t cacheCount = operation.storage.restingSubstepPairCount;
10677
+ auto& cache = operation.storage.restingSubstepPairCache;
10678
+ std::uint32_t& cursor = operation.storage.restingSubstepPairCursor;
10679
+ const SolverStorage::RestingSubstepPairCacheEntry* matched = nullptr;
10680
+ if (cursor < cacheCount && cache[cursor].pairKey == pairKey) {
10681
+ matched = &cache[cursor];
10682
+ cursor += 1;
10683
+ } else {
10684
+ while (cursor < cacheCount && cache[cursor].pairKey < pairKey) {
10685
+ cursor += 1;
10686
+ }
10687
+ if (cursor < cacheCount && cache[cursor].pairKey == pairKey) {
10688
+ matched = &cache[cursor];
10689
+ cursor += 1;
10690
+ } else {
10691
+ const auto beginIt = cache.begin();
10692
+ const auto endIt = beginIt + cacheCount;
10693
+ const auto foundIt = std::lower_bound(
10694
+ beginIt, endIt, pairKey,
10695
+ [](const SolverStorage::RestingSubstepPairCacheEntry& entry, std::uint64_t key) {
10696
+ return entry.pairKey < key;
10697
+ });
10698
+ if (foundIt != endIt && foundIt->pairKey == pairKey) {
10699
+ matched = &*foundIt;
10700
+ cursor = static_cast<std::uint32_t>((foundIt - beginIt) + 1);
10701
+ }
10702
+ }
10703
+ }
10704
+ if (matched != nullptr) {
10705
+ if (matched->hit == 0) return;
10706
+ if (matched->outputIndex == std::numeric_limits<std::uint32_t>::max()) {
10707
+ operation.storage.contactConstraintOverflow = true;
10708
+ return;
10709
+ }
10710
+ if (firstBody.sensorLike || secondBody.sensorLike
10711
+ || (!firstBody.dynamic && !secondBody.dynamic)) return;
10712
+ if (operation.storage.contactSolvePairCount
10713
+ >= operation.storage.contactSolvePairBegin.size()) {
10714
+ operation.storage.contactConstraintOverflow = true;
10715
+ return;
10716
+ }
10717
+ const std::uint32_t solveOrder = operation.storage.contactSolvePairCount++;
10718
+ operation.storage.contactSolvePairBegin[solveOrder] = 0;
10719
+ operation.storage.contactSolvePairEnd[solveOrder] = 0;
10720
+ operation.storage.contactSolveTelemetryIndex[solveOrder] =
10721
+ std::numeric_limits<std::uint32_t>::max();
10722
+ operation.storage.contactSolveOutputIndex[solveOrder] = matched->outputIndex;
10723
+ if (matched->alignedSupport != 0) {
10724
+ if ((!bodies[matched->lower].dynamic || bodies[matched->lower].kinematic
10725
+ || operation.storage.contactSupported[supportIndex(matched->lower)] != 0)
10726
+ && bodies[matched->upper].dynamic) {
10727
+ operation.storage.contactSupported[supportIndex(matched->upper)] = 1;
10728
+ }
10729
+ }
10730
+ if (operation.storage.contactConstraintCount + matched->newConstraintCount
10731
+ > operation.storage.maximumContactConstraintCount) {
10732
+ operation.storage.contactConstraintOverflow = true;
10733
+ return;
10734
+ }
10735
+ return;
10736
+ }
10737
+ }
10738
+ const auto recordRestingCache = [&](std::uint32_t outputIndex,
10739
+ std::uint32_t newConstraintCount,
10740
+ std::uint32_t lower,
10741
+ std::uint32_t upper,
10742
+ std::uint8_t hit,
10743
+ std::uint8_t alignedSupport) {
10744
+ if (!operation.storage.firstSubstepOfTick || !isRestingBox) return;
10745
+ if (operation.storage.restingSubstepPairCount
10746
+ >= operation.storage.restingSubstepPairCache.size()) return;
10747
+ operation.storage.restingSubstepPairCache[
10748
+ operation.storage.restingSubstepPairCount++] = {
10749
+ pairKey,
10750
+ outputIndex,
10751
+ newConstraintCount,
10752
+ lower,
10753
+ upper,
10754
+ hit,
10755
+ alignedSupport,
10756
+ };
10757
+ };
10628
10758
  const Collision contact = collide(operation, bodies[first], bodies[second]);
10629
- if (!contact.hit) return;
10759
+ if (!contact.hit) {
10760
+ recordRestingCache(0, 0, 0, 0, 0, 0);
10761
+ return;
10762
+ }
10630
10763
  const std::uint32_t outputIndex = recordWorldContactOutput(
10631
10764
  operation, first, second, contact);
10632
10765
  if (outputIndex == std::numeric_limits<std::uint32_t>::max()) {
10766
+ recordRestingCache(outputIndex, 0, 0, 0, 1, 0);
10633
10767
  operation.storage.contactConstraintOverflow = true;
10634
10768
  return;
10635
10769
  }
10636
10770
  if (firstBody.sensorLike || secondBody.sensorLike
10637
- || (!firstBody.dynamic && !secondBody.dynamic)) return;
10771
+ || (!firstBody.dynamic && !secondBody.dynamic)) {
10772
+ recordRestingCache(outputIndex, 0, 0, 0, 1, 0);
10773
+ return;
10774
+ }
10638
10775
  if (operation.storage.contactSolvePairCount
10639
10776
  >= operation.storage.contactSolvePairBegin.size()) {
10640
10777
  operation.storage.contactConstraintOverflow = true;
@@ -10646,6 +10783,9 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10646
10783
  operation.storage.contactSolveTelemetryIndex[solveOrder] =
10647
10784
  std::numeric_limits<std::uint32_t>::max();
10648
10785
  operation.storage.contactSolveOutputIndex[solveOrder] = outputIndex;
10786
+ bool alignedSupport = false;
10787
+ std::uint32_t supportLower = first;
10788
+ std::uint32_t supportUpper = second;
10649
10789
  {
10650
10790
  const Vec3 normal{contact.nx, contact.ny, contact.nz};
10651
10791
  const Vec3 gravity{options.gravityX, options.gravityY, options.gravityZ};
@@ -10653,12 +10793,13 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10653
10793
  const double supportAlignment = dotVec3(normal, gravity);
10654
10794
  if (gravityLengthSquared > 1e-18
10655
10795
  && supportAlignment * supportAlignment >= gravityLengthSquared * 0.25) {
10656
- const std::uint32_t lower = supportAlignment < 0.0 ? first : second;
10657
- const std::uint32_t upper = supportAlignment < 0.0 ? second : first;
10658
- if ((!bodies[lower].dynamic || bodies[lower].kinematic
10659
- || operation.storage.contactSupported[supportIndex(lower)] != 0)
10660
- && bodies[upper].dynamic) {
10661
- operation.storage.contactSupported[supportIndex(upper)] = 1;
10796
+ alignedSupport = true;
10797
+ supportLower = supportAlignment < 0.0 ? first : second;
10798
+ supportUpper = supportAlignment < 0.0 ? second : first;
10799
+ if ((!bodies[supportLower].dynamic || bodies[supportLower].kinematic
10800
+ || operation.storage.contactSupported[supportIndex(supportLower)] != 0)
10801
+ && bodies[supportUpper].dynamic) {
10802
+ operation.storage.contactSupported[supportIndex(supportUpper)] = 1;
10662
10803
  }
10663
10804
  }
10664
10805
  }
@@ -10668,6 +10809,13 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10668
10809
  if (findConstraint(first, second, contactFeatureId(contact, pointIndex),
10669
10810
  seededConstraintCount) == nullptr) newConstraintCount += 1;
10670
10811
  }
10812
+ recordRestingCache(
10813
+ outputIndex,
10814
+ newConstraintCount,
10815
+ supportLower,
10816
+ supportUpper,
10817
+ 1,
10818
+ static_cast<std::uint8_t>(alignedSupport ? 1 : 0));
10671
10819
  if (operation.storage.contactConstraintCount + newConstraintCount
10672
10820
  > operation.storage.maximumContactConstraintCount) {
10673
10821
  operation.storage.contactConstraintOverflow = true;
@@ -10675,7 +10823,7 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10675
10823
  }
10676
10824
  // Keep contact output, support order, capacity checks, and warm impulses.
10677
10825
  // Neither box can wake the other or receive a contact response here.
10678
- if (restingBoxPair(operation, first, second)) return;
10826
+ if (isRestingBox) return;
10679
10827
  bool corrected = false;
10680
10828
  double normalImpulse = 0.0;
10681
10829
  double tangentImpulse1 = 0.0;
@@ -10748,6 +10896,23 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10748
10896
  const ProxyBodySync proxySync{proxyHook, bodies, first, second};
10749
10897
  solveBodyPair(first, second, initialize, stabilizeSupported, preparedBegin, preparedEnd);
10750
10898
  };
10899
+ const auto finalizeRestingCacheOrder = [&]() {
10900
+ if (!operation.storage.firstSubstepOfTick) return;
10901
+ const std::uint32_t count = operation.storage.restingSubstepPairCount;
10902
+ if (count > 1) {
10903
+ auto beginIt = operation.storage.restingSubstepPairCache.begin();
10904
+ auto endIt = beginIt + count;
10905
+ const auto lessPairKey = [](
10906
+ const SolverStorage::RestingSubstepPairCacheEntry& left,
10907
+ const SolverStorage::RestingSubstepPairCacheEntry& right) {
10908
+ return left.pairKey < right.pairKey;
10909
+ };
10910
+ if (!std::is_sorted(beginIt, endIt, lessPairKey)) {
10911
+ std::sort(beginIt, endIt, lessPairKey);
10912
+ }
10913
+ }
10914
+ operation.storage.firstSubstepOfTick = false;
10915
+ };
10751
10916
  const auto indexPreparedPairs = [&]() {
10752
10917
  std::uint32_t begin = 0;
10753
10918
  while (begin < operation.storage.contactConstraintCount) {
@@ -10783,7 +10948,14 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10783
10948
  }
10784
10949
  };
10785
10950
  if (!operation.storage.dynamicTreeEnabled || bodyCount < kDynamicTreeThreshold) {
10786
- if (beginSubstep) collectSweepPairs(operation, bodies, bodyCount);
10951
+ if (beginSubstep) {
10952
+ if (!operation.storage.sweepPairsReady
10953
+ || pass == ContactPass::StandaloneFirstTick
10954
+ || pass == ContactPass::StandaloneLaterSubstep) {
10955
+ collectSweepPairs(operation, bodies, bodyCount);
10956
+ }
10957
+ }
10958
+
10787
10959
  for (std::uint32_t iteration = 0; iteration < velocityIterations; iteration += 1) {
10788
10960
  auto solveCollectedPair = [&](std::uint32_t first, std::uint32_t second) {
10789
10961
  solvePair(first, second,
@@ -10808,6 +10980,7 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10808
10980
  || (left.bodyB == right.bodyB && left.featureId < right.featureId)));
10809
10981
  });
10810
10982
  indexPreparedPairs();
10983
+ finalizeRestingCacheOrder();
10811
10984
  }
10812
10985
  }
10813
10986
  return;
@@ -10818,6 +10991,7 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10818
10991
  collectTreePairs(operation, bodies);
10819
10992
  }
10820
10993
  }
10994
+
10821
10995
  for (std::uint32_t iteration = 0; iteration < velocityIterations; iteration += 1) {
10822
10996
  auto solveCollectedPair = [&](std::uint32_t first, std::uint32_t second) {
10823
10997
  solvePair(first, second,
@@ -10843,6 +11017,7 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
10843
11017
  || (left.bodyB == right.bodyB && left.featureId < right.featureId)));
10844
11018
  });
10845
11019
  indexPreparedPairs();
11020
+ finalizeRestingCacheOrder();
10846
11021
  }
10847
11022
  }
10848
11023
  }
@@ -11107,22 +11282,21 @@ void updateSleepingStates(SolverOperation& operation,
11107
11282
  body.sleepTime = quantizeDistance(body.sleepTime + sleepStep);
11108
11283
  if (body.sleepTime < sleepDelay) operation.storage.sleepCanSleep[root] = false;
11109
11284
  }
11110
- for (std::uint32_t index = 0; index < bodyCount; index += 1) {
11111
- if (sleepFind(operation, index) != index || !operation.storage.sleepHasDynamic[index]
11112
- || !operation.storage.sleepCanSleep[index] || operation.storage.sleepHasKinematic[index]) continue;
11113
- for (std::uint32_t bodyIndex = 0; bodyIndex < bodyCount; bodyIndex += 1) {
11114
- if (sleepFind(operation, bodyIndex) != index) continue;
11115
- Body& body = bodies[bodyIndex];
11116
- if (!body.dynamic) continue;
11117
- if (body.sleeping) continue;
11118
- body.sleeping = true;
11119
- body.vx = 0.0;
11120
- body.vy = 0.0;
11121
- body.vz = 0.0;
11122
- body.angularVelX = 0.0;
11123
- body.angularVelY = 0.0;
11124
- body.angularVelZ = 0.0;
11125
- }
11285
+ for (std::uint32_t bodyIndex = 0; bodyIndex < bodyCount; bodyIndex += 1) {
11286
+ const std::uint32_t root = sleepFind(operation, bodyIndex);
11287
+ if (!operation.storage.sleepHasDynamic[root]
11288
+ || !operation.storage.sleepCanSleep[root]
11289
+ || operation.storage.sleepHasKinematic[root]) continue;
11290
+ Body& body = bodies[bodyIndex];
11291
+ if (!body.dynamic) continue;
11292
+ if (body.sleeping) continue;
11293
+ body.sleeping = true;
11294
+ body.vx = 0.0;
11295
+ body.vy = 0.0;
11296
+ body.vz = 0.0;
11297
+ body.angularVelX = 0.0;
11298
+ body.angularVelY = 0.0;
11299
+ body.angularVelZ = 0.0;
11126
11300
  }
11127
11301
  }
11128
11302
 
@@ -11198,8 +11372,10 @@ void updateJointIslandMembership(SolverOperation& operation,
11198
11372
  }
11199
11373
  }
11200
11374
 
11201
- std::vector<std::uint8_t> componentHasJoint(bodyCount, 0);
11202
- std::vector<std::uint8_t> componentHasActive(bodyCount, 0);
11375
+ auto& componentHasJoint = operation.storage.componentHasJoint;
11376
+ auto& componentHasActive = operation.storage.componentHasActive;
11377
+ std::fill_n(componentHasJoint.begin(), bodyCount, 0);
11378
+ std::fill_n(componentHasActive.begin(), bodyCount, 0);
11203
11379
 
11204
11380
  for (std::uint32_t i = 0; i < bodyCount; ++i) {
11205
11381
  if (bodies[i].dynamic && (!bodies[i].sleeping || bodies[i].vx != 0.0 || bodies[i].vy != 0.0 || bodies[i].vz != 0.0)) {
@@ -22403,6 +22579,7 @@ std::int32_t solveStartingConstraints(SolverOperation& operation,
22403
22579
  ~ProxyScope() { operation.proxyHook = nullptr; }
22404
22580
  } proxyScope{operation};
22405
22581
  operation.proxyHook = hook.proxySources.empty() ? nullptr : &hook;
22582
+ operation.storage.sweepPairsReady = false;
22406
22583
  if (completion.capture) completion.capture->beginSolve(bodyCount, substepOptions, substep);
22407
22584
  std::optional<StartingVelocitySnapshot> incoming;
22408
22585
  if (operation.materialMotionEpochs != nullptr || std::any_of(operation.storage.soaBodies.begin(), operation.storage.soaBodies.end(),
@@ -22965,6 +23142,14 @@ std::int32_t stepSoAWithJointsInternal(
22965
23142
  }
22966
23143
  }
22967
23144
  const auto materialMotionPairsSupported = [&] {
23145
+ bool hasBullet = false;
23146
+ for (std::uint32_t index = 0; index < bodyCount; ++index) {
23147
+ if (operation.storage.soaBodies[index].bullet) {
23148
+ hasBullet = true;
23149
+ break;
23150
+ }
23151
+ }
23152
+ if (!hasBullet) return true;
22968
23153
  for (std::uint32_t first = 0; first < bodyCount; ++first) {
22969
23154
  for (std::uint32_t second = first + 1; second < bodyCount; ++second) {
22970
23155
  const auto& a = operation.storage.soaBodies[first];