@series-inc/rundot-syncplay 6.0.0-rc.60 → 6.0.0-rc.62
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.
- package/core/native/physics/constraint_rows.cpp +40 -7
- package/core/native/physics/constraint_rows.hpp +3 -0
- package/core/native/physics/physics.cpp +552 -69
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +5 -5
- package/core/src/physics/physics-wasm-module.generated.mjs +5 -5
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +1 -1
- package/dist/networked-client.d.ts +45 -0
- package/dist/networked-client.js +89 -9
- package/dist/runner.d.ts +23 -0
- package/dist/runner.js +17 -3
- package/dist/runtime-session.d.ts +35 -1
- package/dist/runtime-session.js +30 -3
- package/dist/sdk-session.d.ts +7 -1
- package/dist/sdk-session.js +9 -1
- package/package.json +3 -3
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include <algorithm>
|
|
5
5
|
#include <cmath>
|
|
6
|
+
#include <cstdlib>
|
|
6
7
|
#include <stdexcept>
|
|
7
8
|
|
|
8
9
|
namespace rundot::kinetix::physics {
|
|
@@ -552,17 +553,25 @@ bool finiteSixDofValues(const std::array<double, Size>& values) {
|
|
|
552
553
|
});
|
|
553
554
|
}
|
|
554
555
|
|
|
555
|
-
|
|
556
|
+
// Every row field except the accumulated impulse.
|
|
557
|
+
bool validSixDofPreparedRowFields(const ConstraintRow6& row) {
|
|
556
558
|
const auto& scalar = row.scalar;
|
|
557
559
|
return finiteSixDofValues(row.jacobianA) && finiteSixDofValues(row.jacobianB)
|
|
558
560
|
&& finiteSixDofValues(row.angularResponseA) && finiteSixDofValues(row.angularResponseB)
|
|
559
561
|
&& std::isfinite(scalar.effectiveMass) && std::isfinite(scalar.bias)
|
|
560
562
|
&& std::isfinite(scalar.massScale) && std::isfinite(scalar.impulseScale)
|
|
561
|
-
&& std::isfinite(scalar.accumulatedImpulse)
|
|
562
563
|
&& !std::isnan(scalar.lower) && !std::isnan(scalar.upper)
|
|
563
564
|
&& scalar.lower <= scalar.upper;
|
|
564
565
|
}
|
|
565
566
|
|
|
567
|
+
bool validSixDofPreparedRow(const ConstraintRow6& row) {
|
|
568
|
+
return validSixDofPreparedRowFields(row) && std::isfinite(row.scalar.accumulatedImpulse);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
SixDofResponseStatus recordSixDofConstraintImpulseChecked(
|
|
572
|
+
SixDofConstraintImpulseHistory& history, const ConstraintRow6& row,
|
|
573
|
+
const SixDofConstraintRowMetadata& metadata, double appliedImpulse, bool rowFieldsValid);
|
|
574
|
+
|
|
566
575
|
} // namespace
|
|
567
576
|
|
|
568
577
|
SixDofResponseStatus sixDofReactionMagnitudes(
|
|
@@ -659,9 +668,23 @@ SixDofResponseStatus refreshSixDofConstraintRows(
|
|
|
659
668
|
SixDofResponseStatus recordSixDofConstraintImpulse(
|
|
660
669
|
SixDofConstraintImpulseHistory& history, const ConstraintRow6& row,
|
|
661
670
|
const SixDofConstraintRowMetadata& metadata, double appliedImpulse) {
|
|
671
|
+
return recordSixDofConstraintImpulseChecked(history, row, metadata, appliedImpulse,
|
|
672
|
+
validSixDofPreparedRowFields(row));
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
namespace {
|
|
676
|
+
|
|
677
|
+
// The solve loop records every row on every iteration, and the full row check was most of the
|
|
678
|
+
// record cost. rowFieldsValid is validSixDofPreparedRowFields(row), computed once per rebuild.
|
|
679
|
+
SixDofResponseStatus recordSixDofConstraintImpulseChecked(
|
|
680
|
+
SixDofConstraintImpulseHistory& history, const ConstraintRow6& row,
|
|
681
|
+
const SixDofConstraintRowMetadata& metadata, double appliedImpulse, bool rowFieldsValid) {
|
|
682
|
+
#if defined(RUNDOT_PHYSICS_DEBUG_INVARIANTS)
|
|
683
|
+
if (rowFieldsValid != validSixDofPreparedRowFields(row)) std::abort();
|
|
684
|
+
#endif
|
|
662
685
|
const std::uint32_t slot = sixDofHistorySlot(metadata);
|
|
663
686
|
if (slot == history.rows.size()) return SixDofResponseStatus::InvalidState;
|
|
664
|
-
if (!std::isfinite(appliedImpulse) || !
|
|
687
|
+
if (!std::isfinite(appliedImpulse) || !rowFieldsValid || !std::isfinite(row.scalar.accumulatedImpulse)) {
|
|
665
688
|
return SixDofResponseStatus::Unrepresentable;
|
|
666
689
|
}
|
|
667
690
|
// Stage only the values that change; `history` stays untouched on every failure path.
|
|
@@ -687,6 +710,8 @@ SixDofResponseStatus recordSixDofConstraintImpulse(
|
|
|
687
710
|
return SixDofResponseStatus::Success;
|
|
688
711
|
}
|
|
689
712
|
|
|
713
|
+
} // namespace
|
|
714
|
+
|
|
690
715
|
SixDofSubstepParticipant::SixDofSubstepParticipant(
|
|
691
716
|
std::span<const SixDofConstraint> constraints,
|
|
692
717
|
std::span<SixDofConstraintOutput> outputs, bool eventCapable)
|
|
@@ -696,6 +721,8 @@ SixDofSubstepParticipant::SixDofSubstepParticipant(
|
|
|
696
721
|
}
|
|
697
722
|
rows_.reserve(constraints.size() * kMaxSixDofRows);
|
|
698
723
|
metadata_.reserve(constraints.size() * kMaxSixDofRows);
|
|
724
|
+
// Preparation must not allocate (a retry after an allocation failure keeps no orphan rows).
|
|
725
|
+
rowFieldsValid_.reserve(constraints.size() * kMaxSixDofRows);
|
|
699
726
|
ranges_.resize(constraints.size());
|
|
700
727
|
stagedOutputs_.resize(constraints.size());
|
|
701
728
|
if (eventCapable) {
|
|
@@ -753,6 +780,7 @@ std::int32_t SixDofSubstepParticipant::invoke(SubstepConstraintPhase phase,
|
|
|
753
780
|
for (auto& row : state.rows_) {
|
|
754
781
|
if (!prepareConstraintRow(row, context.mobility)) return 3;
|
|
755
782
|
}
|
|
783
|
+
state.rowFieldsValid_.assign(state.rows_.size(), 0);
|
|
756
784
|
state.phase_ = Phase::Ready;
|
|
757
785
|
return 0;
|
|
758
786
|
case SubstepConstraintPhase::RefreshEventGeometry:
|
|
@@ -778,6 +806,7 @@ std::int32_t SixDofSubstepParticipant::invoke(SubstepConstraintPhase phase,
|
|
|
778
806
|
state.rows_.swap(state.stagedRows_);
|
|
779
807
|
state.metadata_.swap(state.stagedMetadata_);
|
|
780
808
|
state.ranges_.swap(state.stagedRanges_);
|
|
809
|
+
state.rowFieldsValid_.assign(state.rows_.size(), 0);
|
|
781
810
|
state.geometryRefreshed_ = true;
|
|
782
811
|
return 0;
|
|
783
812
|
case SubstepConstraintPhase::SolveIteration:
|
|
@@ -792,8 +821,10 @@ std::int32_t SixDofSubstepParticipant::invoke(SubstepConstraintPhase phase,
|
|
|
792
821
|
const double applied = solveConstraintRow(row, context.bodies, context.mobility);
|
|
793
822
|
if (!std::isfinite(row.scalar.accumulatedImpulse)) return 3;
|
|
794
823
|
if (state.eventCapable_) {
|
|
795
|
-
|
|
796
|
-
|
|
824
|
+
auto& known = state.rowFieldsValid_[offset];
|
|
825
|
+
if (known == 0) known = validSixDofPreparedRowFields(row) ? 1 : 2;
|
|
826
|
+
const auto status = recordSixDofConstraintImpulseChecked(
|
|
827
|
+
state.histories_[index], row, state.metadata_[offset], applied, known == 1);
|
|
797
828
|
if (status != SixDofResponseStatus::Success) {
|
|
798
829
|
return status == SixDofResponseStatus::Unrepresentable ? 7 : 3;
|
|
799
830
|
}
|
|
@@ -826,8 +857,10 @@ std::int32_t SixDofSubstepParticipant::invoke(SubstepConstraintPhase phase,
|
|
|
826
857
|
const double adjustment = row.scalar.accumulatedImpulse - previous;
|
|
827
858
|
applyConstraintRowImpulse(row, context.bodies, context.mobility, adjustment);
|
|
828
859
|
if (state.eventCapable_) {
|
|
829
|
-
|
|
830
|
-
|
|
860
|
+
auto& known = state.rowFieldsValid_[offset];
|
|
861
|
+
if (known == 0) known = validSixDofPreparedRowFields(row) ? 1 : 2;
|
|
862
|
+
const auto status = recordSixDofConstraintImpulseChecked(
|
|
863
|
+
state.histories_[index], row, metadata, adjustment, known == 1);
|
|
831
864
|
if (status != SixDofResponseStatus::Success) {
|
|
832
865
|
return status == SixDofResponseStatus::Unrepresentable ? 7 : 3;
|
|
833
866
|
}
|
|
@@ -186,6 +186,9 @@ class SixDofSubstepParticipant {
|
|
|
186
186
|
std::vector<std::array<std::uint32_t, 2>> ranges_, stagedRanges_;
|
|
187
187
|
std::vector<SixDofConstraintImpulseHistory> histories_;
|
|
188
188
|
std::vector<SixDofConstraintOutput> stagedOutputs_;
|
|
189
|
+
// Per row: 0 not checked, 1 valid, 2 invalid, for every field except the accumulated impulse
|
|
190
|
+
// (the only field a solve iteration changes). Reset when the rows are rebuilt.
|
|
191
|
+
std::vector<std::uint8_t> rowFieldsValid_;
|
|
189
192
|
double duration_ = 0.0;
|
|
190
193
|
std::uint32_t substep_ = 0;
|
|
191
194
|
bool eventCapable_ = false;
|