@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21
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/README.md +133 -0
- package/core/deterministic-math.d.ts +75 -1
- package/core/native/instance_ledger.hpp +1095 -0
- package/core/native/legacy_checkpoint_ids.hpp +107 -0
- package/core/native/physics/abi.cpp +39 -211
- package/core/native/physics/abi.hpp +2 -6
- package/core/native/physics/articulation.cpp +1434 -0
- package/core/native/physics/articulation.hpp +279 -0
- package/core/native/physics/buoyancy.cpp +1588 -0
- package/core/native/physics/buoyancy.hpp +254 -0
- package/core/native/physics/capsule_triangle.cpp +168 -0
- package/core/native/physics/capsule_triangle.hpp +40 -0
- package/core/native/physics/capsule_triangle_native.inc +291 -0
- package/core/native/physics/certified_sum.hpp +218 -0
- package/core/native/physics/character.cpp +638 -0
- package/core/native/physics/character.hpp +169 -0
- package/core/native/physics/checkpoint_schema.hpp +379 -0
- package/core/native/physics/cloth.cpp +1401 -0
- package/core/native/physics/cloth.hpp +357 -0
- package/core/native/physics/constraint_rows.cpp +363 -2
- package/core/native/physics/constraint_rows.hpp +72 -1
- package/core/native/physics/deformable_query.cpp +1630 -0
- package/core/native/physics/deformable_query.hpp +578 -0
- package/core/native/physics/distance.cpp +1166 -0
- package/core/native/physics/distance.hpp +151 -0
- package/core/native/physics/exact/exact-applied.cpp +101 -0
- package/core/native/physics/exact/exact-applied.hpp +112 -0
- package/core/native/physics/exact/exact-dyadic.cpp +691 -0
- package/core/native/physics/exact/exact-dyadic.hpp +58 -0
- package/core/native/physics/exact/exact-operation.hpp +51 -0
- package/core/native/physics/exact/word-core.hpp +262 -0
- package/core/native/physics/extended_abi.cpp +1242 -0
- package/core/native/physics/extended_abi.hpp +355 -0
- package/core/native/physics/extended_abi_characters.cpp +261 -0
- package/core/native/physics/extended_abi_characters.hpp +434 -0
- package/core/native/physics/extended_abi_core_features.cpp +713 -0
- package/core/native/physics/extended_abi_core_features.hpp +226 -0
- package/core/native/physics/extended_abi_deformables.cpp +448 -0
- package/core/native/physics/extended_abi_deformables.hpp +867 -0
- package/core/native/physics/extended_abi_vehicles.cpp +411 -0
- package/core/native/physics/extended_abi_vehicles.hpp +222 -0
- package/core/native/physics/fracture.cpp +1981 -0
- package/core/native/physics/fracture.hpp +460 -0
- package/core/native/physics/gear.cpp +563 -0
- package/core/native/physics/gear.hpp +158 -0
- package/core/native/physics/geometry_memory.hpp +476 -0
- package/core/native/physics/geometry_store.cpp +547 -0
- package/core/native/physics/geometry_store.hpp +134 -0
- package/core/native/physics/lag_compensation.cpp +1626 -0
- package/core/native/physics/lag_compensation.hpp +405 -0
- package/core/native/physics/mass_properties.cpp +449 -0
- package/core/native/physics/mass_properties.hpp +23 -0
- package/core/native/physics/material_pose.hpp +988 -0
- package/core/native/physics/particles.cpp +1065 -0
- package/core/native/physics/particles.hpp +261 -0
- package/core/native/physics/path_joint.cpp +781 -0
- package/core/native/physics/path_joint.hpp +154 -0
- package/core/native/physics/physics.cpp +13043 -1065
- package/core/native/physics/physics.hpp +184 -8
- package/core/native/physics/planar_deformable.cpp +2433 -0
- package/core/native/physics/planar_deformable.hpp +889 -0
- package/core/native/physics/platformer_2d.cpp +1353 -0
- package/core/native/physics/platformer_2d.hpp +340 -0
- package/core/native/physics/powered_ragdoll.cpp +1100 -0
- package/core/native/physics/powered_ragdoll.hpp +279 -0
- package/core/native/physics/powertrain.cpp +586 -0
- package/core/native/physics/powertrain.hpp +180 -0
- package/core/native/physics/pulley.cpp +311 -0
- package/core/native/physics/pulley.hpp +121 -0
- package/core/native/physics/ragdoll.cpp +586 -0
- package/core/native/physics/ragdoll.hpp +221 -0
- package/core/native/physics/rope.cpp +692 -0
- package/core/native/physics/rope.hpp +215 -0
- package/core/native/physics/rounded_convex.cpp +1229 -0
- package/core/native/physics/rounded_convex.hpp +287 -0
- package/core/native/physics/sdf_geometry.cpp +1821 -0
- package/core/native/physics/sdf_geometry.hpp +474 -0
- package/core/native/physics/soft_body.cpp +1449 -0
- package/core/native/physics/soft_body.hpp +328 -0
- package/core/native/physics/soft_collision.cpp +1862 -0
- package/core/native/physics/soft_collision.hpp +561 -0
- package/core/native/physics/surface_velocity.cpp +366 -0
- package/core/native/physics/surface_velocity.hpp +243 -0
- package/core/native/physics/topology.cpp +357 -39
- package/core/native/physics/topology.hpp +97 -6
- package/core/native/physics/tracks.cpp +1179 -0
- package/core/native/physics/tracks.hpp +404 -0
- package/core/native/physics/vehicle.cpp +629 -0
- package/core/native/physics/vehicle.hpp +191 -0
- package/core/native/physics/voxel_cooking.cpp +1929 -0
- package/core/native/physics/voxel_cooking.hpp +395 -0
- package/core/native/physics/world.cpp +5290 -854
- package/core/native/physics/world.hpp +796 -24
- package/core/native/physics/world_abi.cpp +3840 -306
- package/core/native/physics/world_abi.hpp +530 -10
- package/core/native/physics/world_digest_visitor.hpp +277 -0
- package/core/native/physics/world_strong_digest.hpp +557 -0
- package/core/native/physics2d/ccd.cpp +1302 -0
- package/core/native/physics2d/ccd.hpp +141 -0
- package/core/native/physics2d/checkpoint_memory.hpp +349 -0
- package/core/native/physics2d/clock_primitives.hpp +138 -0
- package/core/native/physics2d/commands.cpp +174 -28
- package/core/native/physics2d/commands.hpp +3 -1
- package/core/native/physics2d/compound.cpp +581 -0
- package/core/native/physics2d/compound.hpp +248 -0
- package/core/native/physics2d/contour.cpp +325 -0
- package/core/native/physics2d/contour.hpp +143 -0
- package/core/native/physics2d/frame_scope.hpp +124 -0
- package/core/native/physics2d/joint_phases.hpp +93 -0
- package/core/native/physics2d/joints.cpp +587 -150
- package/core/native/physics2d/joints.hpp +5 -0
- package/core/native/physics2d/memory_private.hpp +125 -0
- package/core/native/physics2d/owned_abi.cpp +1354 -879
- package/core/native/physics2d/owned_abi.hpp +190 -52
- package/core/native/physics2d/phase_test_hooks.hpp +17 -0
- package/core/native/physics2d/physics2d.cpp +2073 -120
- package/core/native/physics2d/physics2d.hpp +154 -2
- package/core/native/physics2d/queries.cpp +1055 -79
- package/core/native/physics2d/queries.hpp +71 -5
- package/core/native/physics2d/world.cpp +1313 -353
- package/core/native/physics2d/world.hpp +124 -13
- package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
- package/core/native/sha256/sha256_fips_constants.hpp +24 -0
- package/core/native/sha256/sha256_length.hpp +56 -0
- package/core/native/sha256/sha256_memo.hpp +48 -0
- package/core/native/sha256/sha256_sink.hpp +234 -0
- package/core/physics2d-owned.d.ts +466 -126
- package/core/runtime.d.ts +192 -19
- package/core/scripts/build-native.mjs +34 -0
- package/core/scripts/build-wasm-physics.mjs +272 -23
- package/core/scripts/extended-physics-profile.mjs +634 -0
- package/core/scripts/generate-physics2d-vectors.mjs +59 -0
- package/core/src/kinetix-deterministic-math.d.ts +2 -0
- package/core/src/kinetix-deterministic-math.mjs +513 -27
- package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
- package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
- package/core/src/kinetix-runtime-contract.mjs +55 -9
- package/core/src/kinetix-runtime-identity.mjs +12 -1
- package/core/src/kinetix-session-config.mjs +7 -2
- package/core/src/kinetix-state-report.mjs +36 -0
- package/core/src/physics/abi-constants.mjs +5 -4
- package/core/src/physics/articulation.d.mts +194 -0
- package/core/src/physics/articulation.mjs +1141 -0
- package/core/src/physics/buoyancy.d.mts +143 -0
- package/core/src/physics/buoyancy.mjs +268 -0
- package/core/src/physics/cloth.d.mts +314 -0
- package/core/src/physics/cloth.mjs +1156 -0
- package/core/src/physics/deformable-query.d.mts +217 -0
- package/core/src/physics/deformable-query.mjs +1412 -0
- package/core/src/physics/distance.d.mts +160 -0
- package/core/src/physics/distance.mjs +175 -0
- package/core/src/physics/extended-wasm-instance.d.mts +5 -0
- package/core/src/physics/extended-wasm-instance.mjs +48 -0
- package/core/src/physics/feature-api.d.mts +74 -0
- package/core/src/physics/feature-api.mjs +98 -0
- package/core/src/physics/fracture.d.mts +133 -0
- package/core/src/physics/fracture.mjs +1324 -0
- package/core/src/physics/gear.d.mts +585 -0
- package/core/src/physics/gear.mjs +955 -0
- package/core/src/physics/lag-compensation.d.mts +101 -0
- package/core/src/physics/lag-compensation.mjs +1100 -0
- package/core/src/physics/mass-properties.d.mts +114 -0
- package/core/src/physics/mass-properties.mjs +137 -468
- package/core/src/physics/particles.d.mts +177 -0
- package/core/src/physics/particles.mjs +758 -0
- package/core/src/physics/path-joint.d.mts +171 -0
- package/core/src/physics/path-joint.mjs +1231 -0
- package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
- package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
- package/core/src/physics/powered-ragdoll.d.mts +188 -0
- package/core/src/physics/powered-ragdoll.mjs +1043 -0
- package/core/src/physics/powertrain.d.mts +260 -0
- package/core/src/physics/powertrain.mjs +621 -0
- package/core/src/physics/pulley.d.mts +98 -0
- package/core/src/physics/pulley.mjs +686 -0
- package/core/src/physics/ragdoll.d.mts +289 -0
- package/core/src/physics/ragdoll.mjs +1323 -0
- package/core/src/physics/rope.d.mts +241 -0
- package/core/src/physics/rope.mjs +319 -0
- package/core/src/physics/rounded-convex.d.mts +328 -0
- package/core/src/physics/rounded-convex.mjs +1404 -0
- package/core/src/physics/sdf-geometry.d.mts +117 -0
- package/core/src/physics/sdf-geometry.mjs +1204 -0
- package/core/src/physics/soft-body.d.mts +144 -0
- package/core/src/physics/soft-body.mjs +1285 -0
- package/core/src/physics/soft-collision.d.mts +651 -0
- package/core/src/physics/soft-collision.mjs +1883 -0
- package/core/src/physics/surface-velocity.d.mts +156 -0
- package/core/src/physics/surface-velocity.mjs +722 -0
- package/core/src/physics/tracks.d.mts +411 -0
- package/core/src/physics/tracks.mjs +1074 -0
- package/core/src/physics/vehicle.d.mts +3 -0
- package/core/src/physics/vehicle.mjs +172 -0
- package/core/src/physics/voxel-cooking.d.mts +219 -0
- package/core/src/physics/voxel-cooking.mjs +1499 -0
- package/core/src/physics/voxel-swept-quad.mjs +110 -0
- package/core/src/physics/wasm-instance.mjs +160 -23
- package/core/src/physics/world.d.mts +62 -0
- package/core/src/physics/world.mjs +1947 -152
- package/core/src/physics2d/body-state.mjs +218 -15
- package/core/src/physics2d/collision.d.mts +52 -0
- package/core/src/physics2d/collision.mjs +234 -0
- package/core/src/physics2d/compound.mjs +454 -0
- package/core/src/physics2d/contour-state.mjs +771 -0
- package/core/src/physics2d/feature-api.d.mts +211 -0
- package/core/src/physics2d/feature-api.mjs +3 -0
- package/core/src/physics2d/fluid-state.mjs +145 -0
- package/core/src/physics2d/joint-state.mjs +1 -1
- package/core/src/physics2d/owned-queries.mjs +3 -1
- package/core/src/physics2d/owned-transport.mjs +268 -122
- package/core/src/physics2d/owned-world.mjs +353 -230
- package/core/src/physics2d/particle-fluid.d.mts +152 -0
- package/core/src/physics2d/particle-fluid.mjs +233 -0
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
- package/core/src/physics2d/query-codec.mjs +61 -13
- package/core/src/physics2d/submerged-geometry.d.mts +51 -0
- package/core/src/physics2d/submerged-geometry.mjs +186 -0
- package/core/src/runtime.mjs +23 -0
- package/core/src/shared/bytes.d.mts +2 -0
- package/core/src/shared/bytes.mjs +33 -0
- package/core/src/shared/sha256.d.mts +3 -0
- package/core/src/shared/sha256.mjs +72 -22
- package/core/units.d.ts +50 -0
- package/core/world.d.ts +253 -5
- package/dist/authority-room.d.ts +9 -0
- package/dist/authority-room.js +45 -16
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +4 -3
- package/dist/cadence.d.ts +7 -0
- package/dist/cadence.js +19 -0
- package/dist/canonical.d.ts +1 -0
- package/dist/canonical.js +3 -0
- package/dist/checksum-policy.d.ts +10 -0
- package/dist/checksum-policy.js +14 -0
- package/dist/collider-cooking-hull.d.ts +18 -0
- package/dist/collider-cooking-hull.js +248 -0
- package/dist/collider-cooking.d.ts +140 -0
- package/dist/collider-cooking.js +794 -0
- package/dist/compat/v5.d.ts +121 -0
- package/dist/compat/v5.js +479 -0
- package/dist/creator.d.ts +7 -6
- package/dist/creator.js +4 -3
- package/dist/game-byte-section.d.ts +36 -0
- package/dist/game-byte-section.js +350 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/instant-replay.d.ts +27 -2
- package/dist/instant-replay.js +91 -16
- package/dist/lag-compensation3d.js +11 -10
- package/dist/match-log.d.ts +21 -4
- package/dist/match-log.js +92 -9
- package/dist/math.d.ts +2 -0
- package/dist/math.js +1 -0
- package/dist/modules/character-3d.d.ts +16 -1
- package/dist/modules/character-3d.js +42 -5
- package/dist/modules/combat.js +6 -5
- package/dist/movement3d-revision1.d.ts +2 -0
- package/dist/movement3d-revision1.js +973 -0
- package/dist/movement3d.d.ts +53 -3
- package/dist/movement3d.js +917 -247
- package/dist/networked-client.d.ts +15 -0
- package/dist/networked-client.js +378 -105
- package/dist/node.d.ts +3 -2
- package/dist/node.js +2 -1
- package/dist/physics/2d.d.ts +38 -4
- package/dist/physics/2d.js +57 -36
- package/dist/physics/3d.d.ts +755 -111
- package/dist/physics/3d.js +2355 -158
- package/dist/physics/edit-result-graph.d.ts +36 -0
- package/dist/physics/edit-result-graph.js +141 -0
- package/dist/physics/game-codec3d.d.ts +41 -0
- package/dist/physics/game-codec3d.js +544 -0
- package/dist/physics/installed-checkpoint3d.d.ts +13 -0
- package/dist/physics/installed-checkpoint3d.js +120 -0
- package/dist/physics/installed-runtime3d.d.ts +51 -0
- package/dist/physics/installed-runtime3d.js +372 -0
- package/dist/physics/installed-state-commitment3d.d.ts +2 -0
- package/dist/physics/installed-state-commitment3d.js +24 -0
- package/dist/physics/units.d.ts +38 -0
- package/dist/physics/units.js +56 -0
- package/dist/physics/vehicle-state3d.d.ts +93 -0
- package/dist/physics/vehicle-state3d.js +1191 -0
- package/dist/physics/voxel-body-state.d.ts +61 -0
- package/dist/physics/voxel-body-state.js +410 -0
- package/dist/r3f-render-adapter.d.ts +59 -1
- package/dist/r3f-render-adapter.js +137 -2
- package/dist/replay.d.ts +13 -0
- package/dist/replay.js +95 -70
- package/dist/run-room-transport.js +5 -1
- package/dist/runner.d.ts +17 -2
- package/dist/runner.js +472 -84
- package/dist/runtime-cleanup.d.ts +54 -0
- package/dist/runtime-cleanup.js +266 -0
- package/dist/runtime-lease.d.ts +11 -1
- package/dist/runtime-lease.js +23 -10
- package/dist/runtime-room-metadata.d.ts +2 -8
- package/dist/runtime-room-metadata.js +11 -14
- package/dist/runtime-session.d.ts +8 -0
- package/dist/runtime-session.js +222 -58
- package/dist/schema-codegen.js +3 -0
- package/dist/schema-dsl-binary.d.ts +10 -4
- package/dist/schema-dsl-binary.js +375 -76
- package/dist/scratch-pool.d.ts +32 -0
- package/dist/scratch-pool.js +60 -0
- package/dist/sdk-session.d.ts +1 -0
- package/dist/sdk-session.js +4 -0
- package/dist/secret-config.js +2 -60
- package/dist/secret-crypto.js +70 -36
- package/dist/session-snapshot.d.ts +15 -4
- package/dist/session-snapshot.js +35 -33
- package/dist/session-wire.js +14 -22
- package/dist/sparse-set.d.ts +1 -0
- package/dist/sparse-set.js +22 -0
- package/dist/spatial/spatial-grid-3d.d.ts +41 -0
- package/dist/spatial/spatial-grid-3d.js +115 -0
- package/dist/synctest.d.ts +9 -0
- package/dist/synctest.js +106 -17
- package/dist/testing-network.d.ts +2 -0
- package/dist/testing-network.js +122 -18
- package/dist/testing.d.ts +27 -6
- package/dist/testing.js +297 -56
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.js +3 -2
- package/dist/tools/module-certification.d.ts +6 -0
- package/dist/tools/module-certification.js +26 -2
- package/package.json +18 -5
- package/core/scripts/run-box3d-benchmark.mjs +0 -350
- package/core/src/physics/index.mjs +0 -3169
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "checkpoint_schema.hpp"
|
|
4
|
+
#include "sha256/sha256_memo.hpp"
|
|
5
|
+
#include "sha256/sha256_sink.hpp"
|
|
6
|
+
|
|
7
|
+
#include <array>
|
|
8
|
+
#include <cstring>
|
|
9
|
+
#include <limits>
|
|
10
|
+
#include <span>
|
|
11
|
+
|
|
12
|
+
namespace rundot::kinetix::physics {
|
|
13
|
+
|
|
14
|
+
inline WorldError strongDigestError(const char* detail) {
|
|
15
|
+
return WorldError{WorldErrorCode::InvalidState, detail};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
inline bool strongStatusOk(rundot::sha256::SinkStatus status) noexcept {
|
|
19
|
+
return status == rundot::sha256::SinkStatus::Ok;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
inline rundot::sha256::SinkStatus writeRawDoubles(
|
|
23
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
24
|
+
std::span<const double> values) noexcept {
|
|
25
|
+
if (values.empty()) return rundot::sha256::SinkStatus::Ok;
|
|
26
|
+
if (values.data() == nullptr) return rundot::sha256::SinkStatus::InvalidInput;
|
|
27
|
+
if (values.size() > std::numeric_limits<std::size_t>::max() / sizeof(double)) {
|
|
28
|
+
return rundot::sha256::SinkStatus::LengthOverflow;
|
|
29
|
+
}
|
|
30
|
+
return writer.bytes(std::span<const std::uint8_t>(
|
|
31
|
+
reinterpret_cast<const std::uint8_t*>(values.data()), values.size() * sizeof(double)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
inline rundot::sha256::SinkStatus writeCountedDoubles(
|
|
35
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
36
|
+
std::span<const double> values) noexcept {
|
|
37
|
+
const auto status = writer.u64(values.size());
|
|
38
|
+
if (!strongStatusOk(status)) return status;
|
|
39
|
+
return writeRawDoubles(writer, values);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
inline rundot::sha256::SinkStatus strongTileLeaf(
|
|
43
|
+
const double* data,
|
|
44
|
+
std::uint64_t length,
|
|
45
|
+
std::array<std::uint8_t, 32>& out) noexcept {
|
|
46
|
+
rundot::sha256::Sha256Sink sink;
|
|
47
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink> writer(sink);
|
|
48
|
+
auto status = writer.domainLiteral(kStrongTileDomain);
|
|
49
|
+
if (!strongStatusOk(status)) return status;
|
|
50
|
+
status = writer.u64(length);
|
|
51
|
+
if (!strongStatusOk(status)) return status;
|
|
52
|
+
if (length > 0) {
|
|
53
|
+
if (data == nullptr) return rundot::sha256::SinkStatus::InvalidInput;
|
|
54
|
+
if (length > std::numeric_limits<std::size_t>::max() / sizeof(double)) {
|
|
55
|
+
return rundot::sha256::SinkStatus::LengthOverflow;
|
|
56
|
+
}
|
|
57
|
+
status = writer.bytes(std::span<const std::uint8_t>(
|
|
58
|
+
reinterpret_cast<const std::uint8_t*>(data), static_cast<std::size_t>(length) * sizeof(double)));
|
|
59
|
+
if (!strongStatusOk(status)) return status;
|
|
60
|
+
}
|
|
61
|
+
const auto result = sink.final();
|
|
62
|
+
if (result.status != rundot::sha256::SinkStatus::Ok) return result.status;
|
|
63
|
+
out = result.bytes;
|
|
64
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
65
|
+
rundot::sha256::gStrongTileLeafFills.fetch_add(1, std::memory_order_relaxed);
|
|
66
|
+
#endif
|
|
67
|
+
return rundot::sha256::SinkStatus::Ok;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
inline rundot::sha256::SinkStatus publishedTileLeaf(const BodyTile& tile, std::array<std::uint8_t, 32>& out) noexcept {
|
|
71
|
+
if (rundot::sha256::memoIsReady(tile.memoState)) {
|
|
72
|
+
if (tile.memoLength != tile.logicalCount) return rundot::sha256::SinkStatus::InvalidInput;
|
|
73
|
+
out = tile.memo;
|
|
74
|
+
return rundot::sha256::SinkStatus::Ok;
|
|
75
|
+
}
|
|
76
|
+
const double* data = bodyTileDoubles(tile);
|
|
77
|
+
std::array<std::uint8_t, 32> local{};
|
|
78
|
+
const auto status = strongTileLeaf(data, tile.logicalCount, local);
|
|
79
|
+
if (!strongStatusOk(status)) return status;
|
|
80
|
+
rundot::sha256::tryPublishMemo(tile.memoState, [&]() noexcept {
|
|
81
|
+
tile.memo = local;
|
|
82
|
+
tile.memoLength = tile.logicalCount;
|
|
83
|
+
return true;
|
|
84
|
+
});
|
|
85
|
+
out = local;
|
|
86
|
+
return rundot::sha256::SinkStatus::Ok;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
inline rundot::sha256::SinkStatus strongMaterialLeaf(
|
|
90
|
+
const material_motion_private::Root<3>& root,
|
|
91
|
+
std::array<std::uint8_t, 32>& out) noexcept {
|
|
92
|
+
if (rundot::sha256::memoIsReady(root.strongMemoState())) {
|
|
93
|
+
out = root.strongMemoBytes();
|
|
94
|
+
return rundot::sha256::SinkStatus::Ok;
|
|
95
|
+
}
|
|
96
|
+
rundot::sha256::Sha256Sink sink;
|
|
97
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink> writer(sink);
|
|
98
|
+
auto status = writer.domainLiteral(kStrongMaterialDomain);
|
|
99
|
+
if (!strongStatusOk(status)) return status;
|
|
100
|
+
bool wordFailed = false;
|
|
101
|
+
const auto words = root.forEachCanonicalWord([&](std::uint64_t word) noexcept {
|
|
102
|
+
if (!strongStatusOk(writer.u64(word))) {
|
|
103
|
+
wordFailed = true;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
});
|
|
108
|
+
if (words != exact_dyadic::Status::Ok || wordFailed) return rundot::sha256::SinkStatus::InvalidInput;
|
|
109
|
+
const auto result = sink.final();
|
|
110
|
+
if (result.status != rundot::sha256::SinkStatus::Ok) return result.status;
|
|
111
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
112
|
+
rundot::sha256::gStrongMaterialStreamFills.fetch_add(1, std::memory_order_relaxed);
|
|
113
|
+
#endif
|
|
114
|
+
rundot::sha256::tryPublishMemo(root.strongMemoState(), [&]() noexcept {
|
|
115
|
+
root.strongMemoBytes() = result.bytes;
|
|
116
|
+
return true;
|
|
117
|
+
});
|
|
118
|
+
out = result.bytes;
|
|
119
|
+
return rundot::sha256::SinkStatus::Ok;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
inline WorldError writeStrongProfile(
|
|
123
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
124
|
+
const WorldProfile& profile) {
|
|
125
|
+
if (!strongStatusOk(writer.u32(profile.abiVersion))
|
|
126
|
+
|| !strongStatusOk(writer.u32(profile.numericProfile))
|
|
127
|
+
|| !strongStatusOk(writer.u32(static_cast<std::uint32_t>(profile.id.size())))
|
|
128
|
+
|| !strongStatusOk(writer.bytes(std::span<const std::uint8_t>(
|
|
129
|
+
reinterpret_cast<const std::uint8_t*>(profile.id.data()), profile.id.size())))
|
|
130
|
+
|| !strongStatusOk(writer.bytes(profile.geometryDigest))) {
|
|
131
|
+
return strongDigestError("strong profile digest failed");
|
|
132
|
+
}
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
inline WorldError writeStrongProfile(
|
|
137
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
138
|
+
const CheckpointProfile& profile) {
|
|
139
|
+
if (profile.idLength > kWorldMaxProfileIdBytes) {
|
|
140
|
+
return strongDigestError("checkpoint profile id is invalid");
|
|
141
|
+
}
|
|
142
|
+
if (!strongStatusOk(writer.u32(profile.abiVersion))
|
|
143
|
+
|| !strongStatusOk(writer.u32(profile.numericProfile))
|
|
144
|
+
|| !strongStatusOk(writer.u32(profile.idLength))
|
|
145
|
+
|| !strongStatusOk(writer.bytes(std::span<const std::uint8_t>(
|
|
146
|
+
reinterpret_cast<const std::uint8_t*>(profile.id.data()), profile.idLength)))
|
|
147
|
+
|| !strongStatusOk(writer.bytes(profile.geometryDigest))) {
|
|
148
|
+
return strongDigestError("strong profile digest failed");
|
|
149
|
+
}
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
inline WorldError writeStrongLimits(
|
|
154
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
155
|
+
const WorldLimits& limits) {
|
|
156
|
+
if (!strongStatusOk(writer.u32(limits.maxBodies))
|
|
157
|
+
|| !strongStatusOk(writer.u32(limits.maxJoints))
|
|
158
|
+
|| !strongStatusOk(writer.u32(limits.maxFluids))
|
|
159
|
+
|| !strongStatusOk(writer.u32(limits.maxFluidInteractions))
|
|
160
|
+
|| !strongStatusOk(writer.u64(limits.maxGeometryValues))
|
|
161
|
+
|| !strongStatusOk(writer.u64(limits.maxContactCacheValues))
|
|
162
|
+
|| !strongStatusOk(writer.u64(limits.maxForceValues))
|
|
163
|
+
|| !strongStatusOk(writer.u32(limits.maxSupportRecords))) {
|
|
164
|
+
return strongDigestError("strong limits digest failed");
|
|
165
|
+
}
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
inline WorldError writeStrongBodies(
|
|
170
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
171
|
+
const CheckpointBodyTable* table,
|
|
172
|
+
std::span<const double> liveBodies) {
|
|
173
|
+
const std::uint64_t valueCount = table != nullptr ? table->valueCount : liveBodies.size();
|
|
174
|
+
const std::uint32_t tileValues = table != nullptr ? table->tileValues : checkpointTileValues(liveBodies.size());
|
|
175
|
+
const std::size_t tileCount = (valueCount == 0 || tileValues == 0)
|
|
176
|
+
? 0
|
|
177
|
+
: static_cast<std::size_t>((valueCount + tileValues - 1) / tileValues);
|
|
178
|
+
if (table != nullptr && table->tiles.size() != tileCount) {
|
|
179
|
+
return strongDigestError("checkpoint body table tile count mismatch");
|
|
180
|
+
}
|
|
181
|
+
if (!strongStatusOk(writer.u64(valueCount))
|
|
182
|
+
|| !strongStatusOk(writer.u32(tileValues))
|
|
183
|
+
|| !strongStatusOk(writer.u64(tileCount))) {
|
|
184
|
+
return strongDigestError("strong body section failed");
|
|
185
|
+
}
|
|
186
|
+
for (std::size_t index = 0; index < tileCount; ++index) {
|
|
187
|
+
const std::size_t logical = checkpointTileLogicalLength(valueCount, tileValues, index);
|
|
188
|
+
std::array<std::uint8_t, 32> leaf{};
|
|
189
|
+
if (table != nullptr) {
|
|
190
|
+
const auto& tile = table->tiles[index];
|
|
191
|
+
if (!tile || !tile->values || tile->logicalCount != logical
|
|
192
|
+
|| tile->physicalCount < tile->logicalCount) {
|
|
193
|
+
return strongDigestError("checkpoint body tile length is invalid");
|
|
194
|
+
}
|
|
195
|
+
if (!strongStatusOk(publishedTileLeaf(*tile, leaf))) {
|
|
196
|
+
return strongDigestError("checkpoint body tile digest is stale or invalid");
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
if (liveBodies.data() == nullptr && logical > 0) {
|
|
200
|
+
return strongDigestError("live body tile is missing");
|
|
201
|
+
}
|
|
202
|
+
const std::size_t offset = index * static_cast<std::size_t>(tileValues);
|
|
203
|
+
if (!strongStatusOk(strongTileLeaf(liveBodies.data() + offset, logical, leaf))) {
|
|
204
|
+
return strongDigestError("live body tile digest failed");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (!strongStatusOk(writer.bytes(leaf))) return strongDigestError("strong body leaf write failed");
|
|
208
|
+
}
|
|
209
|
+
return {};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
inline WorldError writeStrongGeometry(
|
|
213
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
214
|
+
std::uint8_t form,
|
|
215
|
+
const geometry_private::GeometryRootOwner* root,
|
|
216
|
+
std::span<const double> legacy) {
|
|
217
|
+
if (form == kStrongGeometryLegacy) {
|
|
218
|
+
if (!strongStatusOk(writer.u8(form)) || !strongStatusOk(writeCountedDoubles(writer, legacy))) {
|
|
219
|
+
return strongDigestError("strong legacy geometry digest failed");
|
|
220
|
+
}
|
|
221
|
+
return {};
|
|
222
|
+
}
|
|
223
|
+
if (form != kStrongGeometryRecord || root == nullptr || !(*root) || !(*root)->strongSealed()) {
|
|
224
|
+
return strongDigestError("record geometry root is null or unsealed");
|
|
225
|
+
}
|
|
226
|
+
if (!strongStatusOk(writer.u8(form)) || !strongStatusOk(writer.bytes((*root)->strongLeaf()))) {
|
|
227
|
+
return strongDigestError("strong geometry root leaf write failed");
|
|
228
|
+
}
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
inline WorldError writeStrongSupports(
|
|
233
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
234
|
+
std::span<const WorldSupportSpring> springs,
|
|
235
|
+
std::span<const WorldSupportForce> forces) {
|
|
236
|
+
const bool present = !springs.empty() || !forces.empty();
|
|
237
|
+
if (!strongStatusOk(writer.u8(present ? 1 : 0))) {
|
|
238
|
+
return strongDigestError("strong support presence failed");
|
|
239
|
+
}
|
|
240
|
+
if (!present) return {};
|
|
241
|
+
if (!strongStatusOk(writer.u64(springs.size()))) return strongDigestError("strong support count failed");
|
|
242
|
+
for (const WorldSupportSpring& spring : springs) {
|
|
243
|
+
if (!strongStatusOk(writer.u64(spring.body.value))
|
|
244
|
+
|| !strongStatusOk(writer.u64(spring.support.value))
|
|
245
|
+
|| !strongStatusOk(writeRawDoubles(writer, spring.bodyLocalPoint))
|
|
246
|
+
|| !strongStatusOk(writeRawDoubles(writer, spring.supportLocalPoint))
|
|
247
|
+
|| !strongStatusOk(writeRawDoubles(writer, spring.supportLocalNormal))
|
|
248
|
+
|| !strongStatusOk(writer.f64(spring.compression))
|
|
249
|
+
|| !strongStatusOk(writer.f64(spring.travel))
|
|
250
|
+
|| !strongStatusOk(writer.f64(spring.stiffness))
|
|
251
|
+
|| !strongStatusOk(writer.f64(spring.damping))) {
|
|
252
|
+
return strongDigestError("strong support spring digest failed");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (!strongStatusOk(writer.u64(forces.size()))) return strongDigestError("strong support force count failed");
|
|
256
|
+
for (const WorldSupportForce& force : forces) {
|
|
257
|
+
if (!strongStatusOk(writer.u64(force.body.value))
|
|
258
|
+
|| !strongStatusOk(writer.u64(force.support.value))
|
|
259
|
+
|| !strongStatusOk(writeRawDoubles(writer, force.force))
|
|
260
|
+
|| !strongStatusOk(writeRawDoubles(writer, force.bodyLocalPoint))
|
|
261
|
+
|| !strongStatusOk(writeRawDoubles(writer, force.supportLocalPoint))
|
|
262
|
+
|| !strongStatusOk(writer.u8(force.supportReceivesReaction))) {
|
|
263
|
+
return strongDigestError("strong support force digest failed");
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
inline WorldError writeStrongPose(
|
|
270
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer,
|
|
271
|
+
const WorldPose& pose) {
|
|
272
|
+
if (std::holds_alternative<NativeWorldPose>(pose)) {
|
|
273
|
+
if (!strongStatusOk(writer.u8(0))) return strongDigestError("strong pose presence failed");
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
const auto& root = std::get<std::shared_ptr<const material_motion_private::Root<3>>>(pose);
|
|
277
|
+
if (!root) return strongDigestError("material pose root is null");
|
|
278
|
+
std::array<std::uint8_t, 32> leaf{};
|
|
279
|
+
if (!strongStatusOk(strongMaterialLeaf(*root, leaf))) {
|
|
280
|
+
return strongDigestError("material pose digest failed");
|
|
281
|
+
}
|
|
282
|
+
if (!strongStatusOk(writer.u8(1)) || !strongStatusOk(writer.bytes(leaf))) {
|
|
283
|
+
return strongDigestError("strong pose leaf write failed");
|
|
284
|
+
}
|
|
285
|
+
return {};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
template <typename View>
|
|
289
|
+
WorldError writeStrongField(
|
|
290
|
+
CheckpointField field,
|
|
291
|
+
const View& view,
|
|
292
|
+
const WorldLimits& limits,
|
|
293
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink>& writer) {
|
|
294
|
+
using rundot::sha256::SinkStatus;
|
|
295
|
+
switch (field) {
|
|
296
|
+
case CheckpointField::StrongRevision:
|
|
297
|
+
if (!strongStatusOk(writer.u32(kWorldStrongDigestAlgorithmRevision))) {
|
|
298
|
+
return strongDigestError("strong revision digest failed");
|
|
299
|
+
}
|
|
300
|
+
return {};
|
|
301
|
+
case CheckpointField::WorldLimits:
|
|
302
|
+
return writeStrongLimits(writer, limits);
|
|
303
|
+
case CheckpointField::Profile:
|
|
304
|
+
if (const WorldProfile* live = view.strongLiveProfile()) return writeStrongProfile(writer, *live);
|
|
305
|
+
if (const CheckpointProfile* saved = view.strongSavedProfile()) return writeStrongProfile(writer, *saved);
|
|
306
|
+
return strongDigestError("strong profile is missing");
|
|
307
|
+
case CheckpointField::Frame:
|
|
308
|
+
if (!strongStatusOk(writer.u64(view.frame()))) return strongDigestError("strong frame digest failed");
|
|
309
|
+
return {};
|
|
310
|
+
case CheckpointField::TopologyCounters:
|
|
311
|
+
if (!strongStatusOk(writer.u64(view.nextBodyId().value))
|
|
312
|
+
|| !strongStatusOk(writer.u64(view.nextJointId().value))
|
|
313
|
+
|| !strongStatusOk(writer.u64(view.nextFluidId().value))) {
|
|
314
|
+
return strongDigestError("strong topology counters failed");
|
|
315
|
+
}
|
|
316
|
+
return {};
|
|
317
|
+
case CheckpointField::TopologyIds: {
|
|
318
|
+
const auto bodyIds = view.bodyIds();
|
|
319
|
+
const auto joints = view.jointsTopology();
|
|
320
|
+
const auto fluidIds = view.fluidIds();
|
|
321
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::TopologyIds)))
|
|
322
|
+
|| !strongStatusOk(writer.u64(bodyIds.size()))) {
|
|
323
|
+
return strongDigestError("strong topology ids failed");
|
|
324
|
+
}
|
|
325
|
+
for (const BodyId id : bodyIds) {
|
|
326
|
+
if (!strongStatusOk(writer.u64(id.value))) return strongDigestError("strong body id failed");
|
|
327
|
+
}
|
|
328
|
+
if (!strongStatusOk(writer.u64(joints.size()))) return strongDigestError("strong joint id count failed");
|
|
329
|
+
for (const JointIdentity& joint : joints) {
|
|
330
|
+
if (!strongStatusOk(writer.u64(joint.id.value))
|
|
331
|
+
|| !strongStatusOk(writer.u64(joint.bodyA.value))
|
|
332
|
+
|| !strongStatusOk(writer.u64(joint.bodyB.value))) {
|
|
333
|
+
return strongDigestError("strong joint id failed");
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!strongStatusOk(writer.u64(fluidIds.size()))) return strongDigestError("strong fluid id count failed");
|
|
337
|
+
for (const FluidId id : fluidIds) {
|
|
338
|
+
if (!strongStatusOk(writer.u64(id.value))) return strongDigestError("strong fluid id failed");
|
|
339
|
+
}
|
|
340
|
+
return {};
|
|
341
|
+
}
|
|
342
|
+
case CheckpointField::Bodies:
|
|
343
|
+
return writeStrongBodies(writer, view.strongBodyTable(), view.strongLiveBodies());
|
|
344
|
+
case CheckpointField::Joints:
|
|
345
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::Joints)))
|
|
346
|
+
|| !strongStatusOk(writeCountedDoubles(writer, view.jointsData()))) {
|
|
347
|
+
return strongDigestError("strong joint digest failed");
|
|
348
|
+
}
|
|
349
|
+
return {};
|
|
350
|
+
case CheckpointField::Geometry:
|
|
351
|
+
return writeStrongGeometry(
|
|
352
|
+
writer, view.strongGeometryForm(), view.strongGeometryRoot(), view.strongLegacyGeometry());
|
|
353
|
+
case CheckpointField::ContactCache:
|
|
354
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::ContactCache)))
|
|
355
|
+
|| !strongStatusOk(writeCountedDoubles(writer, view.contactCache()))) {
|
|
356
|
+
return strongDigestError("strong contact cache digest failed");
|
|
357
|
+
}
|
|
358
|
+
return {};
|
|
359
|
+
case CheckpointField::Forces:
|
|
360
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::Forces)))
|
|
361
|
+
|| !strongStatusOk(writeCountedDoubles(writer, view.forces()))) {
|
|
362
|
+
return strongDigestError("strong force digest failed");
|
|
363
|
+
}
|
|
364
|
+
return {};
|
|
365
|
+
case CheckpointField::TickForces:
|
|
366
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::TickForces)))
|
|
367
|
+
|| !strongStatusOk(writeCountedDoubles(writer, view.tickForces()))) {
|
|
368
|
+
return strongDigestError("strong tick force digest failed");
|
|
369
|
+
}
|
|
370
|
+
return {};
|
|
371
|
+
case CheckpointField::Supports:
|
|
372
|
+
return writeStrongSupports(writer, view.supportSprings(), view.supportForces());
|
|
373
|
+
case CheckpointField::Fluids:
|
|
374
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::Fluids)))
|
|
375
|
+
|| !strongStatusOk(writeCountedDoubles(writer, view.fluids()))) {
|
|
376
|
+
return strongDigestError("strong fluid digest failed");
|
|
377
|
+
}
|
|
378
|
+
return {};
|
|
379
|
+
case CheckpointField::SurfaceVelocities:
|
|
380
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::SurfaceVelocities)))
|
|
381
|
+
|| !strongStatusOk(writeCountedDoubles(writer, view.surfaceVelocities()))) {
|
|
382
|
+
return strongDigestError("strong surface velocity digest failed");
|
|
383
|
+
}
|
|
384
|
+
return {};
|
|
385
|
+
case CheckpointField::JointWarm: {
|
|
386
|
+
const auto warm = view.jointWarmState();
|
|
387
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::JointWarm)))
|
|
388
|
+
|| !strongStatusOk(writer.u64(warm.size()))) {
|
|
389
|
+
return strongDigestError("strong warm header failed");
|
|
390
|
+
}
|
|
391
|
+
for (const JointWarmState3D& state : warm) {
|
|
392
|
+
if (!strongStatusOk(writer.u64(state.jointId))
|
|
393
|
+
|| !strongStatusOk(writer.u64(state.signature))
|
|
394
|
+
|| !strongStatusOk(writer.f64(state.previousSubstepDuration))
|
|
395
|
+
|| !strongStatusOk(writer.u64(state.rowFeatureKeys))
|
|
396
|
+
|| !strongStatusOk(writeRawDoubles(writer, state.accumulatedImpulse))) {
|
|
397
|
+
return strongDigestError("strong warm record failed");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return {};
|
|
401
|
+
}
|
|
402
|
+
case CheckpointField::ContactEvents: {
|
|
403
|
+
const auto events = view.contactEvents();
|
|
404
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::ContactEvents)))
|
|
405
|
+
|| !strongStatusOk(writer.u64(events.size()))) {
|
|
406
|
+
return strongDigestError("strong contact header failed");
|
|
407
|
+
}
|
|
408
|
+
for (const WorldContactEvent& event : events) {
|
|
409
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(event.type)))
|
|
410
|
+
|| !strongStatusOk(writer.u64(event.bodyA.value))
|
|
411
|
+
|| !strongStatusOk(writer.u64(event.bodyB.value))
|
|
412
|
+
|| !strongStatusOk(writer.u8(event.trigger ? 1 : 0))
|
|
413
|
+
|| !strongStatusOk(writer.u8(event.sensor ? 1 : 0))
|
|
414
|
+
|| !strongStatusOk(writer.f64(event.normalImpulse))
|
|
415
|
+
|| !strongStatusOk(writer.f64(event.tangentImpulse1))
|
|
416
|
+
|| !strongStatusOk(writer.f64(event.tangentImpulse2))
|
|
417
|
+
|| !strongStatusOk(writeRawDoubles(writer, event.point))
|
|
418
|
+
|| !strongStatusOk(writeRawDoubles(writer, event.normal))
|
|
419
|
+
|| !strongStatusOk(writer.f64(event.penetration))
|
|
420
|
+
|| !strongStatusOk(writer.f64(event.closingSpeed))) {
|
|
421
|
+
return strongDigestError("strong contact event failed");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return {};
|
|
425
|
+
}
|
|
426
|
+
case CheckpointField::JointReactions: {
|
|
427
|
+
const auto reactions = view.jointReactions();
|
|
428
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::JointReactions)))
|
|
429
|
+
|| !strongStatusOk(writer.u64(reactions.size()))) {
|
|
430
|
+
return strongDigestError("strong reaction header failed");
|
|
431
|
+
}
|
|
432
|
+
for (const WorldJointReaction& reaction : reactions) {
|
|
433
|
+
if (!strongStatusOk(writer.u64(reaction.joint.value))
|
|
434
|
+
|| !strongStatusOk(writer.u64(reaction.bodyA.value))
|
|
435
|
+
|| !strongStatusOk(writer.u64(reaction.bodyB.value))
|
|
436
|
+
|| !strongStatusOk(writeRawDoubles(writer, reaction.force))
|
|
437
|
+
|| !strongStatusOk(writeRawDoubles(writer, reaction.torque))) {
|
|
438
|
+
return strongDigestError("strong reaction record failed");
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return {};
|
|
442
|
+
}
|
|
443
|
+
case CheckpointField::JointBreaks: {
|
|
444
|
+
const auto breaks = view.jointBreakEvents();
|
|
445
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::JointBreaks)))
|
|
446
|
+
|| !strongStatusOk(writer.u64(breaks.size()))) {
|
|
447
|
+
return strongDigestError("strong break header failed");
|
|
448
|
+
}
|
|
449
|
+
for (const WorldJointBreakEvent& event : breaks) {
|
|
450
|
+
if (!strongStatusOk(writer.u64(event.joint.value)) || !strongStatusOk(writer.u32(event.reasonBits))) {
|
|
451
|
+
return strongDigestError("strong break record failed");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return {};
|
|
455
|
+
}
|
|
456
|
+
case CheckpointField::FluidInteractions: {
|
|
457
|
+
const auto interactions = view.fluidInteractions();
|
|
458
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::FluidInteractions)))
|
|
459
|
+
|| !strongStatusOk(writer.u64(interactions.size()))) {
|
|
460
|
+
return strongDigestError("strong fluid interaction header failed");
|
|
461
|
+
}
|
|
462
|
+
for (const WorldFluidInteraction& interaction : interactions) {
|
|
463
|
+
if (!strongStatusOk(writer.u64(interaction.body.value))
|
|
464
|
+
|| !strongStatusOk(writer.u64(interaction.fluid.value))
|
|
465
|
+
|| !strongStatusOk(writer.f64(interaction.submergedVolume))
|
|
466
|
+
|| !strongStatusOk(writeRawDoubles(writer, interaction.centerOfBuoyancy))
|
|
467
|
+
|| !strongStatusOk(writeRawDoubles(writer, interaction.totalForce))
|
|
468
|
+
|| !strongStatusOk(writeRawDoubles(writer, interaction.totalTorque))
|
|
469
|
+
|| !strongStatusOk(writeRawDoubles(writer, interaction.relativeVelocity))
|
|
470
|
+
|| !strongStatusOk(writer.u8(interaction.shouldWake ? 1 : 0))) {
|
|
471
|
+
return strongDigestError("strong fluid interaction failed");
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return {};
|
|
475
|
+
}
|
|
476
|
+
case CheckpointField::DefinitionSignatures: {
|
|
477
|
+
const auto bodySigs = view.bodyDefinitionSignatures();
|
|
478
|
+
const auto jointSigs = view.jointDefinitionSignatures();
|
|
479
|
+
if (!strongStatusOk(writer.u32(static_cast<std::uint32_t>(StrongSection::DefinitionSignatures)))
|
|
480
|
+
|| !strongStatusOk(writer.u64(bodySigs.size()))) {
|
|
481
|
+
return strongDigestError("strong definition header failed");
|
|
482
|
+
}
|
|
483
|
+
for (const std::uint64_t sig : bodySigs) {
|
|
484
|
+
if (!strongStatusOk(writer.u64(sig))) return strongDigestError("strong body signature failed");
|
|
485
|
+
}
|
|
486
|
+
if (!strongStatusOk(writer.u64(jointSigs.size()))) {
|
|
487
|
+
return strongDigestError("strong joint signature count failed");
|
|
488
|
+
}
|
|
489
|
+
for (const std::uint64_t sig : jointSigs) {
|
|
490
|
+
if (!strongStatusOk(writer.u64(sig))) return strongDigestError("strong joint signature failed");
|
|
491
|
+
}
|
|
492
|
+
return {};
|
|
493
|
+
}
|
|
494
|
+
case CheckpointField::Pose:
|
|
495
|
+
return writeStrongPose(writer, view.pose());
|
|
496
|
+
case CheckpointField::Count:
|
|
497
|
+
return strongDigestError("checkpoint field list is invalid");
|
|
498
|
+
}
|
|
499
|
+
return strongDigestError("checkpoint field list is invalid");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
template <typename View>
|
|
503
|
+
WorldError strongDigestView(
|
|
504
|
+
const View& view,
|
|
505
|
+
const WorldLimits& limits,
|
|
506
|
+
std::array<std::uint8_t, 32>& out,
|
|
507
|
+
const CheckpointData* memo) {
|
|
508
|
+
if (memo != nullptr && rundot::sha256::memoIsReady(memo->strongMemoState)
|
|
509
|
+
&& sameWorldLimits(memo->strongMemoLimits, limits)) {
|
|
510
|
+
out = memo->strongMemo;
|
|
511
|
+
return {};
|
|
512
|
+
}
|
|
513
|
+
rundot::sha256::Sha256Sink sink;
|
|
514
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink> writer(sink);
|
|
515
|
+
if (!strongStatusOk(writer.domainLiteral(kStrongCheckpointDomain))) {
|
|
516
|
+
return strongDigestError("strong checkpoint domain failed");
|
|
517
|
+
}
|
|
518
|
+
for (const CheckpointField field : kStrongFieldOrder) {
|
|
519
|
+
const WorldError step = writeStrongField(field, view, limits, writer);
|
|
520
|
+
if (!step.ok()) return step;
|
|
521
|
+
}
|
|
522
|
+
const auto result = sink.final();
|
|
523
|
+
if (result.status != rundot::sha256::SinkStatus::Ok) {
|
|
524
|
+
return strongDigestError("strong checkpoint digest failed");
|
|
525
|
+
}
|
|
526
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
527
|
+
rundot::sha256::gStrongCheckpointPayloadFills.fetch_add(1, std::memory_order_relaxed);
|
|
528
|
+
#endif
|
|
529
|
+
if (memo != nullptr) {
|
|
530
|
+
rundot::sha256::tryPublishMemo(memo->strongMemoState, [&]() noexcept {
|
|
531
|
+
memo->strongMemoLimits = limits;
|
|
532
|
+
memo->strongMemo = result.bytes;
|
|
533
|
+
return true;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
out = result.bytes;
|
|
537
|
+
return {};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
inline WorldError strongGeometryProbe(
|
|
541
|
+
const geometry_private::GeometryRootOwner& root,
|
|
542
|
+
std::uint8_t form,
|
|
543
|
+
std::array<std::uint8_t, 32>& out) {
|
|
544
|
+
rundot::sha256::Sha256Sink sink;
|
|
545
|
+
rundot::sha256::LeFieldWriter<rundot::sha256::Sha256Sink> writer(sink);
|
|
546
|
+
std::span<const double> legacy;
|
|
547
|
+
const WorldError status = writeStrongGeometry(writer, form, &root, legacy);
|
|
548
|
+
if (!status.ok()) return status;
|
|
549
|
+
const auto result = sink.final();
|
|
550
|
+
if (result.status != rundot::sha256::SinkStatus::Ok) {
|
|
551
|
+
return strongDigestError("strong geometry probe failed");
|
|
552
|
+
}
|
|
553
|
+
out = result.bytes;
|
|
554
|
+
return {};
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
} // namespace rundot::kinetix::physics
|