@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#include "topology.hpp"
|
|
2
2
|
|
|
3
3
|
#include <algorithm>
|
|
4
|
+
#include <bit>
|
|
4
5
|
#include <cmath>
|
|
5
6
|
#include <cstddef>
|
|
6
7
|
#include <limits>
|
|
@@ -41,6 +42,12 @@ std::size_t bodyIndex(const TopologyState& topology, BodyId id) {
|
|
|
41
42
|
return static_cast<std::size_t>(selected - topology.bodyIds.begin());
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
std::size_t fluidIndex(const TopologyState& topology, FluidId id) {
|
|
46
|
+
const auto selected = std::ranges::lower_bound(topology.fluidIds, id);
|
|
47
|
+
if (selected == topology.fluidIds.end() || *selected != id) return topology.fluidIds.size();
|
|
48
|
+
return static_cast<std::size_t>(selected - topology.fluidIds.begin());
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
TemporaryBodyIdentity* temporaryBody(TopologyWorkspace& workspace, TempBodyId id) {
|
|
45
52
|
const auto selected = std::ranges::lower_bound(workspace.temporaryBodies, id, {}, &TemporaryBodyIdentity::temp);
|
|
46
53
|
return selected == workspace.temporaryBodies.end() || selected->temp != id ? nullptr : &*selected;
|
|
@@ -51,6 +58,11 @@ TemporaryJointIdentity* temporaryJoint(TopologyWorkspace& workspace, TempJointId
|
|
|
51
58
|
return selected == workspace.temporaryJoints.end() || selected->temp != id ? nullptr : &*selected;
|
|
52
59
|
}
|
|
53
60
|
|
|
61
|
+
TemporaryFluidIdentity* temporaryFluid(TopologyWorkspace& workspace, TempFluidId id) {
|
|
62
|
+
const auto selected = std::ranges::lower_bound(workspace.temporaryFluids, id, {}, &TemporaryFluidIdentity::temp);
|
|
63
|
+
return selected == workspace.temporaryFluids.end() || selected->temp != id ? nullptr : &*selected;
|
|
64
|
+
}
|
|
65
|
+
|
|
54
66
|
bool liveBody(const TopologyWorkspace& workspace, BodyId id) {
|
|
55
67
|
const std::size_t index = bodyIndex(workspace.topology, id);
|
|
56
68
|
return index != workspace.topology.bodyIds.size() && workspace.liveBodies[index] != 0;
|
|
@@ -62,6 +74,11 @@ bool liveJoint(const TopologyWorkspace& workspace, std::size_t index) {
|
|
|
62
74
|
return liveBody(workspace, joint.bodyA) && liveBody(workspace, joint.bodyB);
|
|
63
75
|
}
|
|
64
76
|
|
|
77
|
+
bool liveFluid(const TopologyWorkspace& workspace, FluidId id) {
|
|
78
|
+
const std::size_t index = fluidIndex(workspace.topology, id);
|
|
79
|
+
return index != workspace.topology.fluidIds.size() && workspace.liveFluids[index] != 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
65
82
|
bool resolveBodyReference(
|
|
66
83
|
const TopologyWorkspace& workspace,
|
|
67
84
|
const BodyReference& reference,
|
|
@@ -94,12 +111,89 @@ bool resolveJointReference(
|
|
|
94
111
|
return liveJoint(workspace, identityIndex(workspace.topology.joints, output));
|
|
95
112
|
}
|
|
96
113
|
|
|
114
|
+
bool resolveFluidReference(
|
|
115
|
+
const TopologyWorkspace& workspace,
|
|
116
|
+
const FluidReference& reference,
|
|
117
|
+
FluidId& output) {
|
|
118
|
+
if (const auto* existing = std::get_if<ExistingFluidReference>(&reference)) {
|
|
119
|
+
output = existing->id;
|
|
120
|
+
} else {
|
|
121
|
+
const TempFluidId temp = std::get<CreatedFluidReference>(reference).id;
|
|
122
|
+
const auto selected = std::ranges::lower_bound(
|
|
123
|
+
workspace.temporaryFluids, temp, {}, &TemporaryFluidIdentity::temp);
|
|
124
|
+
if (selected == workspace.temporaryFluids.end() || selected->temp != temp || selected->id.value == 0) return false;
|
|
125
|
+
output = selected->id;
|
|
126
|
+
}
|
|
127
|
+
return liveFluid(workspace, output);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
bool validFluidRecord(const std::array<double, kFluidStride>& values) {
|
|
131
|
+
if (!finiteRecord(values)) return false;
|
|
132
|
+
for (std::size_t axis = 0; axis < 3; ++axis) {
|
|
133
|
+
if (!(values[axis] < values[axis + 3])) return false;
|
|
134
|
+
}
|
|
135
|
+
const double normalSquared = values[6] * values[6] + values[7] * values[7]
|
|
136
|
+
+ values[8] * values[8];
|
|
137
|
+
if (!(normalSquared > 0.0) || !(values[10] > 0.0)
|
|
138
|
+
|| values[11] < 0.0 || values[12] < 0.0) return false;
|
|
139
|
+
for (std::size_t index : {std::size_t{16}, std::size_t{17}, std::size_t{18}, std::size_t{19}}) {
|
|
140
|
+
if (values[index] < 0.0 || values[index] > static_cast<double>(std::numeric_limits<std::uint32_t>::max())
|
|
141
|
+
|| std::floor(values[index]) != values[index]) return false;
|
|
142
|
+
}
|
|
143
|
+
return (values[18] == 0.0 || values[18] == 1.0) && values[19] == 0.0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
bool fluidBoundsOverlap(std::span<const double> first, std::span<const double> second) {
|
|
147
|
+
return first[0] < second[3] && second[0] < first[3]
|
|
148
|
+
&& first[1] < second[4] && second[1] < first[4]
|
|
149
|
+
&& first[2] < second[5] && second[2] < first[5];
|
|
150
|
+
}
|
|
151
|
+
|
|
97
152
|
void copyBodyRecord(std::vector<double>& output, std::size_t index, const std::array<double, kBodyStride>& values) {
|
|
98
153
|
std::copy(values.begin(), values.end(), output.begin() + static_cast<std::ptrdiff_t>(index * kBodyStride));
|
|
99
154
|
}
|
|
100
155
|
|
|
101
|
-
|
|
102
|
-
std::
|
|
156
|
+
std::size_t jointRecordStride(double kind) {
|
|
157
|
+
if (!std::isfinite(kind) || kind < 1 || kind > 13 || std::floor(kind) != kind) return 0;
|
|
158
|
+
return kind == 10 ? 3 * kJointStride : kJointStride;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
bool validJointRecord(const JointRecord& record) {
|
|
162
|
+
const auto values = record.values();
|
|
163
|
+
return jointRecordStride(values[0]) == values.size()
|
|
164
|
+
&& std::ranges::all_of(values, [](double value) { return std::isfinite(value); });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
std::vector<std::size_t> jointRecordOffsets(std::span<const double> joints) {
|
|
168
|
+
std::vector<std::size_t> offsets;
|
|
169
|
+
for (std::size_t offset = 0; offset < joints.size();) {
|
|
170
|
+
offsets.push_back(offset);
|
|
171
|
+
offset += jointRecordStride(joints[offset]);
|
|
172
|
+
}
|
|
173
|
+
return offsets;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
JointRecord copyJointRecord(std::span<const double> values) {
|
|
177
|
+
JointRecord record = values.size() == 3 * kJointStride
|
|
178
|
+
? JointRecord{std::array<double, 3 * kJointStride>{}} : JointRecord{};
|
|
179
|
+
std::ranges::copy(values, record.values().begin());
|
|
180
|
+
return record;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void replaceJointRecord(TopologyWorkspace& workspace, std::size_t index, const JointRecord& record) {
|
|
184
|
+
const auto values = record.values();
|
|
185
|
+
const std::size_t offset = workspace.jointOffsets[index];
|
|
186
|
+
const std::size_t oldStride = jointRecordStride(workspace.joints[offset]);
|
|
187
|
+
if (oldStride == values.size()) {
|
|
188
|
+
std::ranges::copy(values, workspace.joints.begin() + static_cast<std::ptrdiff_t>(offset));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
auto first = workspace.joints.begin() + static_cast<std::ptrdiff_t>(offset);
|
|
192
|
+
first = workspace.joints.erase(first, first + static_cast<std::ptrdiff_t>(oldStride));
|
|
193
|
+
workspace.joints.insert(first, values.begin(), values.end());
|
|
194
|
+
for (std::size_t next = index + 1; next < workspace.jointOffsets.size(); ++next) {
|
|
195
|
+
workspace.jointOffsets[next] = workspace.jointOffsets[next] - oldStride + values.size();
|
|
196
|
+
}
|
|
103
197
|
}
|
|
104
198
|
|
|
105
199
|
TopologyError applyCommand(
|
|
@@ -142,7 +236,20 @@ TopologyError applyCommand(
|
|
|
142
236
|
if (!resolveBodyReference(workspace, command.body, id)) {
|
|
143
237
|
return failure(TopologyErrorCode::InvalidReference, "body edit reference is missing", commandIndex);
|
|
144
238
|
}
|
|
145
|
-
|
|
239
|
+
const std::size_t index = bodyIndex(workspace.topology, id);
|
|
240
|
+
if (std::holds_alternative<KeepBodyOrigin>(command.origin)) {
|
|
241
|
+
for (std::size_t axis = 0; axis < 3; ++axis) {
|
|
242
|
+
if (std::bit_cast<std::uint64_t>(command.values[axis])
|
|
243
|
+
!= std::bit_cast<std::uint64_t>(workspace.bodies[index * kBodyStride + axis])) {
|
|
244
|
+
return failure(TopologyErrorCode::InvalidCommand,
|
|
245
|
+
"body origin preservation requires unchanged origin values", commandIndex);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (std::holds_alternative<ReplaceBodyOrigin>(command.origin)) {
|
|
250
|
+
workspace.replacedBodyOrigins.push_back(id);
|
|
251
|
+
}
|
|
252
|
+
copyBodyRecord(workspace.bodies, index, command.values);
|
|
146
253
|
return {};
|
|
147
254
|
}
|
|
148
255
|
|
|
@@ -164,8 +271,8 @@ TopologyError applyCommand(
|
|
|
164
271
|
const CreateJointCommand& command,
|
|
165
272
|
std::uint32_t maxJoints,
|
|
166
273
|
std::uint32_t commandIndex) {
|
|
167
|
-
if (!
|
|
168
|
-
return failure(TopologyErrorCode::InvalidCommand, "joint record
|
|
274
|
+
if (!validJointRecord(command.values)) {
|
|
275
|
+
return failure(TopologyErrorCode::InvalidCommand, "joint record kind, stride, or values are invalid", commandIndex);
|
|
169
276
|
}
|
|
170
277
|
(void) maxJoints;
|
|
171
278
|
BodyId bodyA;
|
|
@@ -182,7 +289,9 @@ TopologyError applyCommand(
|
|
|
182
289
|
++workspace.topology.nextJointId.value;
|
|
183
290
|
workspace.topology.joints.push_back({id, bodyA, bodyB});
|
|
184
291
|
workspace.liveJoints.push_back(1);
|
|
185
|
-
workspace.
|
|
292
|
+
workspace.jointOffsets.push_back(workspace.joints.size());
|
|
293
|
+
const auto values = command.values.values();
|
|
294
|
+
workspace.joints.insert(workspace.joints.end(), values.begin(), values.end());
|
|
186
295
|
TemporaryJointIdentity* temporary = temporaryJoint(workspace, command.temp);
|
|
187
296
|
if (temporary == nullptr || temporary->id.value != 0) {
|
|
188
297
|
return failure(TopologyErrorCode::DuplicateTemporaryId, "joint temporary id is invalid", commandIndex);
|
|
@@ -197,8 +306,8 @@ TopologyError applyCommand(
|
|
|
197
306
|
const EditJointCommand& command,
|
|
198
307
|
std::uint32_t,
|
|
199
308
|
std::uint32_t commandIndex) {
|
|
200
|
-
if (!
|
|
201
|
-
return failure(TopologyErrorCode::InvalidCommand, "joint record
|
|
309
|
+
if (!validJointRecord(command.values)) {
|
|
310
|
+
return failure(TopologyErrorCode::InvalidCommand, "joint record kind, stride, or values are invalid", commandIndex);
|
|
202
311
|
}
|
|
203
312
|
JointId id;
|
|
204
313
|
BodyId bodyA;
|
|
@@ -210,7 +319,7 @@ TopologyError applyCommand(
|
|
|
210
319
|
}
|
|
211
320
|
const std::size_t index = identityIndex(workspace.topology.joints, id);
|
|
212
321
|
workspace.topology.joints[index] = {id, bodyA, bodyB};
|
|
213
|
-
|
|
322
|
+
replaceJointRecord(workspace, index, command.values);
|
|
214
323
|
return {};
|
|
215
324
|
}
|
|
216
325
|
|
|
@@ -227,11 +336,69 @@ TopologyError applyCommand(
|
|
|
227
336
|
return {};
|
|
228
337
|
}
|
|
229
338
|
|
|
339
|
+
TopologyError applyCommand(
|
|
340
|
+
TopologyWorkspace& workspace,
|
|
341
|
+
const CreateFluidCommand& command,
|
|
342
|
+
std::uint32_t,
|
|
343
|
+
std::uint32_t commandIndex) {
|
|
344
|
+
if (!validFluidRecord(command.values)) {
|
|
345
|
+
return failure(TopologyErrorCode::InvalidCommand, "fluid record is invalid", commandIndex);
|
|
346
|
+
}
|
|
347
|
+
if (workspace.topology.nextFluidId.value == 0
|
|
348
|
+
|| workspace.topology.nextFluidId.value == std::numeric_limits<std::uint64_t>::max()) {
|
|
349
|
+
return failure(TopologyErrorCode::IdOverflow, "fluid id allocator is exhausted", commandIndex);
|
|
350
|
+
}
|
|
351
|
+
const FluidId id = workspace.topology.nextFluidId;
|
|
352
|
+
++workspace.topology.nextFluidId.value;
|
|
353
|
+
workspace.topology.fluidIds.push_back(id);
|
|
354
|
+
workspace.liveFluids.push_back(1);
|
|
355
|
+
workspace.fluids.insert(workspace.fluids.end(), command.values.begin(), command.values.end());
|
|
356
|
+
TemporaryFluidIdentity* temporary = temporaryFluid(workspace, command.temp);
|
|
357
|
+
if (temporary == nullptr || temporary->id.value != 0) {
|
|
358
|
+
return failure(TopologyErrorCode::DuplicateTemporaryId, "fluid temporary id is invalid", commandIndex);
|
|
359
|
+
}
|
|
360
|
+
temporary->id = id;
|
|
361
|
+
workspace.result.fluids.push_back({command.temp, id});
|
|
362
|
+
return {};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
TopologyError applyCommand(
|
|
366
|
+
TopologyWorkspace& workspace,
|
|
367
|
+
const EditFluidCommand& command,
|
|
368
|
+
std::uint32_t,
|
|
369
|
+
std::uint32_t commandIndex) {
|
|
370
|
+
if (!validFluidRecord(command.values)) {
|
|
371
|
+
return failure(TopologyErrorCode::InvalidCommand, "fluid record is invalid", commandIndex);
|
|
372
|
+
}
|
|
373
|
+
FluidId id;
|
|
374
|
+
if (!resolveFluidReference(workspace, command.fluid, id)) {
|
|
375
|
+
return failure(TopologyErrorCode::InvalidReference, "fluid edit reference is missing", commandIndex);
|
|
376
|
+
}
|
|
377
|
+
const std::size_t index = fluidIndex(workspace.topology, id);
|
|
378
|
+
std::copy(command.values.begin(), command.values.end(),
|
|
379
|
+
workspace.fluids.begin() + static_cast<std::ptrdiff_t>(index * kFluidStride));
|
|
380
|
+
return {};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
TopologyError applyCommand(
|
|
384
|
+
TopologyWorkspace& workspace,
|
|
385
|
+
const RemoveFluidCommand& command,
|
|
386
|
+
std::uint32_t,
|
|
387
|
+
std::uint32_t commandIndex) {
|
|
388
|
+
FluidId id;
|
|
389
|
+
if (!resolveFluidReference(workspace, command.fluid, id)) {
|
|
390
|
+
return failure(TopologyErrorCode::InvalidReference, "fluid removal reference is missing", commandIndex);
|
|
391
|
+
}
|
|
392
|
+
workspace.liveFluids[fluidIndex(workspace.topology, id)] = 0;
|
|
393
|
+
return {};
|
|
394
|
+
}
|
|
395
|
+
|
|
230
396
|
TopologyError indexTemporaryIds(
|
|
231
397
|
std::span<const TopologyCommand> commands,
|
|
232
398
|
TopologyWorkspace& workspace) {
|
|
233
399
|
workspace.temporaryBodies.clear();
|
|
234
400
|
workspace.temporaryJoints.clear();
|
|
401
|
+
workspace.temporaryFluids.clear();
|
|
235
402
|
for (std::size_t index = 0; index < commands.size(); ++index) {
|
|
236
403
|
if (const auto* create = std::get_if<CreateBodyCommand>(&commands[index])) {
|
|
237
404
|
if (create->temp.value == 0) {
|
|
@@ -247,6 +414,13 @@ TopologyError indexTemporaryIds(
|
|
|
247
414
|
}
|
|
248
415
|
workspace.temporaryJoints.push_back({create->temp, {}, static_cast<std::uint32_t>(index)});
|
|
249
416
|
}
|
|
417
|
+
if (const auto* create = std::get_if<CreateFluidCommand>(&commands[index])) {
|
|
418
|
+
if (create->temp.value == 0) {
|
|
419
|
+
return failure(TopologyErrorCode::DuplicateTemporaryId,
|
|
420
|
+
"fluid temporary id is zero", static_cast<std::uint32_t>(index));
|
|
421
|
+
}
|
|
422
|
+
workspace.temporaryFluids.push_back({create->temp, {}, static_cast<std::uint32_t>(index)});
|
|
423
|
+
}
|
|
250
424
|
}
|
|
251
425
|
const auto order = [](const auto& first, const auto& second) {
|
|
252
426
|
return first.temp < second.temp
|
|
@@ -254,6 +428,7 @@ TopologyError indexTemporaryIds(
|
|
|
254
428
|
};
|
|
255
429
|
std::ranges::sort(workspace.temporaryBodies, order);
|
|
256
430
|
std::ranges::sort(workspace.temporaryJoints, order);
|
|
431
|
+
std::ranges::sort(workspace.temporaryFluids, order);
|
|
257
432
|
for (std::size_t index = 1; index < workspace.temporaryBodies.size(); ++index) {
|
|
258
433
|
if (workspace.temporaryBodies[index - 1].temp == workspace.temporaryBodies[index].temp) {
|
|
259
434
|
return failure(TopologyErrorCode::DuplicateTemporaryId,
|
|
@@ -266,6 +441,12 @@ TopologyError indexTemporaryIds(
|
|
|
266
441
|
"joint temporary id is duplicated", workspace.temporaryJoints[index].commandIndex);
|
|
267
442
|
}
|
|
268
443
|
}
|
|
444
|
+
for (std::size_t index = 1; index < workspace.temporaryFluids.size(); ++index) {
|
|
445
|
+
if (workspace.temporaryFluids[index - 1].temp == workspace.temporaryFluids[index].temp) {
|
|
446
|
+
return failure(TopologyErrorCode::DuplicateTemporaryId,
|
|
447
|
+
"fluid temporary id is duplicated", workspace.temporaryFluids[index].commandIndex);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
269
450
|
return {};
|
|
270
451
|
}
|
|
271
452
|
|
|
@@ -292,24 +473,46 @@ void compactBodies(TopologyWorkspace& workspace) {
|
|
|
292
473
|
|
|
293
474
|
void compactJoints(TopologyWorkspace& workspace) {
|
|
294
475
|
std::size_t write = 0;
|
|
476
|
+
std::size_t writeOffset = 0;
|
|
295
477
|
for (std::size_t read = 0; read < workspace.topology.joints.size(); ++read) {
|
|
296
478
|
const JointIdentity& identity = workspace.topology.joints[read];
|
|
297
479
|
if (workspace.liveJoints[read] == 0 || bodyIndex(workspace.topology, identity.bodyA) == workspace.topology.bodyIds.size()
|
|
298
480
|
|| bodyIndex(workspace.topology, identity.bodyB) == workspace.topology.bodyIds.size()) continue;
|
|
299
481
|
workspace.topology.joints[write] = identity;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
482
|
+
const std::size_t readOffset = workspace.jointOffsets[read];
|
|
483
|
+
const std::size_t stride = jointRecordStride(workspace.joints[readOffset]);
|
|
484
|
+
if (writeOffset != readOffset) {
|
|
485
|
+
std::copy_n(workspace.joints.begin() + static_cast<std::ptrdiff_t>(readOffset),
|
|
486
|
+
stride, workspace.joints.begin() + static_cast<std::ptrdiff_t>(writeOffset));
|
|
303
487
|
}
|
|
304
|
-
workspace.
|
|
305
|
-
workspace.joints[
|
|
488
|
+
workspace.jointOffsets[write] = writeOffset;
|
|
489
|
+
workspace.joints[writeOffset + 1] = static_cast<double>(bodyIndex(workspace.topology, identity.bodyA));
|
|
490
|
+
workspace.joints[writeOffset + 2] = static_cast<double>(bodyIndex(workspace.topology, identity.bodyB));
|
|
491
|
+
writeOffset += stride;
|
|
306
492
|
++write;
|
|
307
493
|
}
|
|
308
494
|
workspace.topology.joints.resize(write);
|
|
309
|
-
workspace.joints.resize(
|
|
495
|
+
workspace.joints.resize(writeOffset);
|
|
496
|
+
workspace.jointOffsets.resize(write);
|
|
310
497
|
workspace.liveJoints.resize(write);
|
|
311
498
|
}
|
|
312
499
|
|
|
500
|
+
void compactFluids(TopologyWorkspace& workspace) {
|
|
501
|
+
std::size_t write = 0;
|
|
502
|
+
for (std::size_t read = 0; read < workspace.topology.fluidIds.size(); ++read) {
|
|
503
|
+
if (workspace.liveFluids[read] == 0) continue;
|
|
504
|
+
workspace.topology.fluidIds[write] = workspace.topology.fluidIds[read];
|
|
505
|
+
if (write != read) {
|
|
506
|
+
std::copy_n(workspace.fluids.begin() + static_cast<std::ptrdiff_t>(read * kFluidStride),
|
|
507
|
+
kFluidStride, workspace.fluids.begin() + static_cast<std::ptrdiff_t>(write * kFluidStride));
|
|
508
|
+
}
|
|
509
|
+
++write;
|
|
510
|
+
}
|
|
511
|
+
workspace.topology.fluidIds.resize(write);
|
|
512
|
+
workspace.fluids.resize(write * kFluidStride);
|
|
513
|
+
workspace.liveFluids.resize(write);
|
|
514
|
+
}
|
|
515
|
+
|
|
313
516
|
void omitRemovedCreatedIds(TopologyWorkspace& workspace) {
|
|
314
517
|
std::erase_if(workspace.result.bodies, [&](const CreatedBodyIdentity& created) {
|
|
315
518
|
return bodyIndex(workspace.topology, created.id) == workspace.topology.bodyIds.size();
|
|
@@ -317,6 +520,9 @@ void omitRemovedCreatedIds(TopologyWorkspace& workspace) {
|
|
|
317
520
|
std::erase_if(workspace.result.joints, [&](const CreatedJointIdentity& created) {
|
|
318
521
|
return identityIndex(workspace.topology.joints, created.id) == workspace.topology.joints.size();
|
|
319
522
|
});
|
|
523
|
+
std::erase_if(workspace.result.fluids, [&](const CreatedFluidIdentity& created) {
|
|
524
|
+
return fluidIndex(workspace.topology, created.id) == workspace.topology.fluidIds.size();
|
|
525
|
+
});
|
|
320
526
|
}
|
|
321
527
|
|
|
322
528
|
} // namespace
|
|
@@ -324,30 +530,42 @@ void omitRemovedCreatedIds(TopologyWorkspace& workspace) {
|
|
|
324
530
|
TopologyError makeIdentityResetTopology(
|
|
325
531
|
std::span<const double> bodies,
|
|
326
532
|
std::span<const double> joints,
|
|
533
|
+
std::span<const double> fluids,
|
|
327
534
|
TopologyState& output) {
|
|
328
|
-
if (bodies.size() % kBodyStride != 0 || joints.size() % kJointStride != 0
|
|
329
|
-
|
|
535
|
+
if (bodies.size() % kBodyStride != 0 || joints.size() % kJointStride != 0
|
|
536
|
+
|| fluids.size() % kFluidStride != 0) {
|
|
537
|
+
return failure(TopologyErrorCode::InvalidState,
|
|
538
|
+
"encoded state does not match body, joint, or fluid stride");
|
|
330
539
|
}
|
|
331
540
|
const std::size_t bodyCount = bodies.size() / kBodyStride;
|
|
332
|
-
const std::size_t
|
|
541
|
+
const std::size_t fluidCount = fluids.size() / kFluidStride;
|
|
333
542
|
TopologyState candidate;
|
|
334
543
|
candidate.bodyIds.reserve(bodyCount);
|
|
335
|
-
candidate.joints.reserve(
|
|
544
|
+
candidate.joints.reserve(joints.size() / kJointStride);
|
|
545
|
+
candidate.fluidIds.reserve(fluidCount);
|
|
336
546
|
for (std::size_t index = 0; index < bodyCount; ++index) {
|
|
337
547
|
candidate.bodyIds.push_back(BodyId{index + 1});
|
|
338
548
|
}
|
|
339
|
-
for (std::size_t
|
|
340
|
-
const std::size_t
|
|
549
|
+
for (std::size_t offset = 0; offset < joints.size();) {
|
|
550
|
+
const std::size_t stride = jointRecordStride(joints[offset]);
|
|
551
|
+
if (stride == 0 || stride > joints.size() - offset) {
|
|
552
|
+
return failure(TopologyErrorCode::InvalidState, "encoded joint stride is invalid");
|
|
553
|
+
}
|
|
341
554
|
std::size_t bodyA = 0;
|
|
342
555
|
std::size_t bodyB = 0;
|
|
343
556
|
if (!encodedIndex(joints[offset + 1], bodyCount, bodyA)
|
|
344
557
|
|| !encodedIndex(joints[offset + 2], bodyCount, bodyB) || bodyA == bodyB) {
|
|
345
558
|
return failure(TopologyErrorCode::InvalidState, "encoded joint endpoints are invalid");
|
|
346
559
|
}
|
|
347
|
-
candidate.joints.push_back({JointId{
|
|
560
|
+
candidate.joints.push_back({JointId{candidate.joints.size() + 1}, candidate.bodyIds[bodyA], candidate.bodyIds[bodyB]});
|
|
561
|
+
offset += stride;
|
|
562
|
+
}
|
|
563
|
+
for (std::size_t index = 0; index < fluidCount; ++index) {
|
|
564
|
+
candidate.fluidIds.push_back(FluidId{index + 1});
|
|
348
565
|
}
|
|
349
566
|
candidate.nextBodyId = BodyId{bodyCount + 1};
|
|
350
|
-
candidate.nextJointId = JointId{
|
|
567
|
+
candidate.nextJointId = JointId{candidate.joints.size() + 1};
|
|
568
|
+
candidate.nextFluidId = FluidId{fluidCount + 1};
|
|
351
569
|
output = std::move(candidate);
|
|
352
570
|
return {};
|
|
353
571
|
}
|
|
@@ -355,10 +573,12 @@ TopologyError makeIdentityResetTopology(
|
|
|
355
573
|
TopologyError validateTopologyState(
|
|
356
574
|
const TopologyState& topology,
|
|
357
575
|
std::span<const double> bodies,
|
|
358
|
-
std::span<const double> joints
|
|
576
|
+
std::span<const double> joints,
|
|
577
|
+
std::span<const double> fluids) {
|
|
359
578
|
if (bodies.size() % kBodyStride != 0 || joints.size() % kJointStride != 0
|
|
579
|
+
|| fluids.size() % kFluidStride != 0
|
|
360
580
|
|| topology.bodyIds.size() != bodies.size() / kBodyStride
|
|
361
|
-
|| topology.
|
|
581
|
+
|| topology.fluidIds.size() != fluids.size() / kFluidStride) {
|
|
362
582
|
return failure(TopologyErrorCode::InvalidState, "topology count does not match encoded state");
|
|
363
583
|
}
|
|
364
584
|
BodyId previousBody;
|
|
@@ -369,7 +589,13 @@ TopologyError validateTopologyState(
|
|
|
369
589
|
previousBody = id;
|
|
370
590
|
}
|
|
371
591
|
JointId previousJoint;
|
|
592
|
+
std::size_t offset = 0;
|
|
372
593
|
for (std::size_t index = 0; index < topology.joints.size(); ++index) {
|
|
594
|
+
if (offset >= joints.size()) return failure(TopologyErrorCode::InvalidState, "joint record is missing");
|
|
595
|
+
const std::size_t stride = jointRecordStride(joints[offset]);
|
|
596
|
+
if (stride == 0 || stride > joints.size() - offset) {
|
|
597
|
+
return failure(TopologyErrorCode::InvalidState, "encoded joint stride is invalid");
|
|
598
|
+
}
|
|
373
599
|
const JointIdentity& identity = topology.joints[index];
|
|
374
600
|
if (identity.id.value == 0 || identity.id <= previousJoint || identity.id >= topology.nextJointId
|
|
375
601
|
|| identity.bodyA == identity.bodyB) {
|
|
@@ -377,33 +603,71 @@ TopologyError validateTopologyState(
|
|
|
377
603
|
}
|
|
378
604
|
const std::size_t bodyA = bodyIndex(topology, identity.bodyA);
|
|
379
605
|
const std::size_t bodyB = bodyIndex(topology, identity.bodyB);
|
|
380
|
-
const std::size_t offset = index * kJointStride;
|
|
381
606
|
if (bodyA == topology.bodyIds.size() || bodyB == topology.bodyIds.size()
|
|
382
607
|
|| joints[offset + 1] != static_cast<double>(bodyA)
|
|
383
608
|
|| joints[offset + 2] != static_cast<double>(bodyB)) {
|
|
384
609
|
return failure(TopologyErrorCode::InvalidState, "joint logical endpoints do not match encoded indices");
|
|
385
610
|
}
|
|
386
611
|
previousJoint = identity.id;
|
|
612
|
+
offset += stride;
|
|
387
613
|
}
|
|
614
|
+
if (offset != joints.size()) return failure(TopologyErrorCode::InvalidState, "topology count does not match joint records");
|
|
615
|
+
const TopologyError fluidState = validateFluidState(topology, fluids);
|
|
616
|
+
if (!fluidState.ok()) return fluidState;
|
|
388
617
|
if (topology.nextBodyId.value == 0 || topology.nextJointId.value == 0) {
|
|
389
618
|
return failure(TopologyErrorCode::InvalidState, "topology allocator is invalid");
|
|
390
619
|
}
|
|
391
620
|
return {};
|
|
392
621
|
}
|
|
393
622
|
|
|
623
|
+
TopologyError validateFluidState(
|
|
624
|
+
const TopologyState& topology,
|
|
625
|
+
std::span<const double> fluids) {
|
|
626
|
+
if (fluids.size() % kFluidStride != 0
|
|
627
|
+
|| topology.fluidIds.size() != fluids.size() / kFluidStride) {
|
|
628
|
+
return failure(TopologyErrorCode::InvalidState,
|
|
629
|
+
"fluid topology count does not match encoded state");
|
|
630
|
+
}
|
|
631
|
+
FluidId previousFluid;
|
|
632
|
+
for (std::size_t index = 0; index < topology.fluidIds.size(); ++index) {
|
|
633
|
+
const FluidId id = topology.fluidIds[index];
|
|
634
|
+
std::array<double, kFluidStride> record{};
|
|
635
|
+
std::copy_n(fluids.begin() + static_cast<std::ptrdiff_t>(index * kFluidStride),
|
|
636
|
+
kFluidStride, record.begin());
|
|
637
|
+
if (id.value == 0 || id <= previousFluid || id >= topology.nextFluidId
|
|
638
|
+
|| !validFluidRecord(record)) {
|
|
639
|
+
return failure(TopologyErrorCode::InvalidState, "fluid identities or records are invalid");
|
|
640
|
+
}
|
|
641
|
+
const std::span<const double> current{record};
|
|
642
|
+
for (std::size_t other = 0; other < index; ++other) {
|
|
643
|
+
if (fluidBoundsOverlap(current, fluids.subspan(other * kFluidStride, kFluidStride))) {
|
|
644
|
+
return failure(TopologyErrorCode::InvalidState, "fluid bounds overlap");
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
previousFluid = id;
|
|
648
|
+
}
|
|
649
|
+
if (topology.nextFluidId.value == 0) {
|
|
650
|
+
return failure(TopologyErrorCode::InvalidState, "fluid topology allocator is invalid");
|
|
651
|
+
}
|
|
652
|
+
return {};
|
|
653
|
+
}
|
|
654
|
+
|
|
394
655
|
TopologyError stageTopologyBatch(
|
|
395
656
|
const TopologyState& topology,
|
|
396
657
|
std::span<const double> bodies,
|
|
397
658
|
std::span<const double> joints,
|
|
659
|
+
std::span<const double> fluids,
|
|
398
660
|
std::span<const double> forces,
|
|
399
661
|
std::span<const TopologyCommand> commands,
|
|
400
662
|
std::uint32_t maxBodies,
|
|
401
663
|
std::uint32_t maxJoints,
|
|
664
|
+
std::uint32_t maxFluids,
|
|
402
665
|
TopologyWorkspace& workspace) {
|
|
666
|
+
workspace.replacedBodyOrigins.clear();
|
|
403
667
|
if (commands.size() > kWorldMaxTopologyCommands) {
|
|
404
668
|
return failure(TopologyErrorCode::CapacityExceeded, "topology batch exceeds the command limit");
|
|
405
669
|
}
|
|
406
|
-
const TopologyError current = validateTopologyState(topology, bodies, joints);
|
|
670
|
+
const TopologyError current = validateTopologyState(topology, bodies, joints, fluids);
|
|
407
671
|
if (!current.ok()) return current;
|
|
408
672
|
const std::size_t bodyCount = topology.bodyIds.size();
|
|
409
673
|
if (!forces.empty() && forces.size() != bodyCount * kForceStride) {
|
|
@@ -411,45 +675,64 @@ TopologyError stageTopologyBatch(
|
|
|
411
675
|
}
|
|
412
676
|
std::size_t bodyCreates = 0;
|
|
413
677
|
std::size_t jointCreates = 0;
|
|
678
|
+
std::size_t fluidCreates = 0;
|
|
414
679
|
for (const TopologyCommand& command : commands) {
|
|
415
680
|
if (std::holds_alternative<CreateBodyCommand>(command)) ++bodyCreates;
|
|
416
681
|
if (std::holds_alternative<CreateJointCommand>(command)) ++jointCreates;
|
|
682
|
+
if (std::holds_alternative<CreateFluidCommand>(command)) ++fluidCreates;
|
|
417
683
|
}
|
|
418
684
|
workspace.temporaryBodies.reserve(bodyCreates);
|
|
419
685
|
workspace.temporaryJoints.reserve(jointCreates);
|
|
686
|
+
workspace.temporaryFluids.reserve(fluidCreates);
|
|
420
687
|
const TopologyError temporaryError = indexTemporaryIds(commands, workspace);
|
|
421
688
|
if (!temporaryError.ok()) return temporaryError;
|
|
422
689
|
|
|
423
690
|
const TopologyState initialTopology = topology;
|
|
424
691
|
const std::vector<double> initialBodies(bodies.begin(), bodies.end());
|
|
425
692
|
const std::vector<double> initialJoints(joints.begin(), joints.end());
|
|
693
|
+
const std::vector<double> initialFluids(fluids.begin(), fluids.end());
|
|
426
694
|
const std::vector<double> initialForces(forces.begin(), forces.end());
|
|
427
695
|
|
|
428
696
|
workspace.topology = initialTopology;
|
|
429
697
|
workspace.bodies = initialBodies;
|
|
430
698
|
workspace.joints = initialJoints;
|
|
699
|
+
workspace.fluids = initialFluids;
|
|
700
|
+
const auto initialJointOffsets = jointRecordOffsets(initialJoints);
|
|
701
|
+
workspace.jointOffsets = initialJointOffsets;
|
|
431
702
|
workspace.forces = initialForces;
|
|
432
703
|
workspace.result.bodies.clear();
|
|
433
704
|
workspace.result.joints.clear();
|
|
705
|
+
workspace.result.fluids.clear();
|
|
434
706
|
workspace.liveBodies.assign(bodyCount, 1);
|
|
435
707
|
workspace.liveJoints.assign(initialTopology.joints.size(), 1);
|
|
708
|
+
workspace.liveFluids.assign(initialTopology.fluidIds.size(), 1);
|
|
436
709
|
const std::size_t bodyReserve = bodyCount + bodyCreates;
|
|
437
710
|
const std::size_t jointReserve = initialTopology.joints.size() + jointCreates;
|
|
711
|
+
const std::size_t fluidReserve = initialTopology.fluidIds.size() + fluidCreates;
|
|
438
712
|
workspace.topology.bodyIds.reserve(bodyReserve);
|
|
439
713
|
workspace.topology.joints.reserve(jointReserve);
|
|
714
|
+
workspace.topology.fluidIds.reserve(fluidReserve);
|
|
440
715
|
workspace.bodies.reserve(bodyReserve * kBodyStride);
|
|
441
|
-
workspace.joints.reserve(
|
|
716
|
+
workspace.joints.reserve(initialJoints.size() + jointCreates * 3 * kJointStride);
|
|
717
|
+
workspace.fluids.reserve(fluidReserve * kFluidStride);
|
|
718
|
+
workspace.jointOffsets.reserve(jointReserve);
|
|
442
719
|
if (!initialForces.empty()) workspace.forces.reserve(bodyReserve * kForceStride);
|
|
443
720
|
workspace.result.bodies.reserve(bodyCreates);
|
|
444
721
|
workspace.result.joints.reserve(jointCreates);
|
|
722
|
+
workspace.result.fluids.reserve(fluidCreates);
|
|
723
|
+
workspace.replacedBodyOrigins.reserve(commands.size());
|
|
445
724
|
|
|
446
725
|
auto rollbackOnFailure = [&]() {
|
|
447
726
|
workspace.topology = initialTopology;
|
|
448
727
|
workspace.bodies = initialBodies;
|
|
449
728
|
workspace.joints = initialJoints;
|
|
729
|
+
workspace.fluids = initialFluids;
|
|
730
|
+
workspace.jointOffsets = initialJointOffsets;
|
|
450
731
|
workspace.forces = initialForces;
|
|
451
732
|
workspace.result.bodies.clear();
|
|
452
733
|
workspace.result.joints.clear();
|
|
734
|
+
workspace.result.fluids.clear();
|
|
735
|
+
workspace.replacedBodyOrigins.clear();
|
|
453
736
|
};
|
|
454
737
|
|
|
455
738
|
for (std::size_t index = 0; index < commands.size(); ++index) {
|
|
@@ -459,8 +742,12 @@ TopologyError stageTopologyBatch(
|
|
|
459
742
|
|| std::is_same_v<Command, EditBodyCommand>
|
|
460
743
|
|| std::is_same_v<Command, RemoveBodyCommand>) {
|
|
461
744
|
return applyCommand(workspace, command, maxBodies, static_cast<std::uint32_t>(index));
|
|
462
|
-
} else
|
|
745
|
+
} else if constexpr (std::is_same_v<Command, CreateJointCommand>
|
|
746
|
+
|| std::is_same_v<Command, EditJointCommand>
|
|
747
|
+
|| std::is_same_v<Command, RemoveJointCommand>) {
|
|
463
748
|
return applyCommand(workspace, command, maxJoints, static_cast<std::uint32_t>(index));
|
|
749
|
+
} else {
|
|
750
|
+
return applyCommand(workspace, command, maxFluids, static_cast<std::uint32_t>(index));
|
|
464
751
|
}
|
|
465
752
|
}, commands[index]);
|
|
466
753
|
if (!result.ok()) {
|
|
@@ -471,17 +758,27 @@ TopologyError stageTopologyBatch(
|
|
|
471
758
|
|
|
472
759
|
const std::size_t liveBodyCount = static_cast<std::size_t>(std::ranges::count(workspace.liveBodies, std::uint8_t{1}));
|
|
473
760
|
std::size_t liveJointCount = 0;
|
|
761
|
+
const std::size_t liveFluidCount = static_cast<std::size_t>(std::ranges::count(workspace.liveFluids, std::uint8_t{1}));
|
|
474
762
|
for (std::size_t index = 0; index < workspace.topology.joints.size(); ++index) {
|
|
475
763
|
if (liveJoint(workspace, index)) ++liveJointCount;
|
|
476
764
|
}
|
|
477
|
-
if (liveBodyCount > maxBodies || liveJointCount > maxJoints) {
|
|
765
|
+
if (liveBodyCount > maxBodies || liveJointCount > maxJoints || liveFluidCount > maxFluids) {
|
|
478
766
|
rollbackOnFailure();
|
|
479
767
|
return failure(TopologyErrorCode::CapacityExceeded, "batch result exceeds world topology capacity");
|
|
480
768
|
}
|
|
481
769
|
compactBodies(workspace);
|
|
482
770
|
compactJoints(workspace);
|
|
771
|
+
compactFluids(workspace);
|
|
483
772
|
omitRemovedCreatedIds(workspace);
|
|
484
|
-
|
|
773
|
+
std::ranges::sort(workspace.replacedBodyOrigins);
|
|
774
|
+
workspace.replacedBodyOrigins.erase(
|
|
775
|
+
std::unique(workspace.replacedBodyOrigins.begin(), workspace.replacedBodyOrigins.end()),
|
|
776
|
+
workspace.replacedBodyOrigins.end());
|
|
777
|
+
std::erase_if(workspace.replacedBodyOrigins, [&](BodyId id) {
|
|
778
|
+
return !std::ranges::binary_search(workspace.topology.bodyIds, id);
|
|
779
|
+
});
|
|
780
|
+
const TopologyError stateValidation = validateTopologyState(
|
|
781
|
+
workspace.topology, workspace.bodies, workspace.joints, workspace.fluids);
|
|
485
782
|
if (!stateValidation.ok()) {
|
|
486
783
|
rollbackOnFailure();
|
|
487
784
|
return stateValidation;
|
|
@@ -489,6 +786,19 @@ TopologyError stageTopologyBatch(
|
|
|
489
786
|
return {};
|
|
490
787
|
}
|
|
491
788
|
|
|
789
|
+
TopologyError stageTopologyBatch(
|
|
790
|
+
const TopologyState& topology,
|
|
791
|
+
std::span<const double> bodies,
|
|
792
|
+
std::span<const double> joints,
|
|
793
|
+
std::span<const double> forces,
|
|
794
|
+
std::span<const TopologyCommand> commands,
|
|
795
|
+
std::uint32_t maxBodies,
|
|
796
|
+
std::uint32_t maxJoints,
|
|
797
|
+
TopologyWorkspace& workspace) {
|
|
798
|
+
return stageTopologyBatch(topology, bodies, joints, {}, forces, commands,
|
|
799
|
+
maxBodies, maxJoints, 0, workspace);
|
|
800
|
+
}
|
|
801
|
+
|
|
492
802
|
namespace {
|
|
493
803
|
|
|
494
804
|
struct TopoVec3 {
|
|
@@ -615,6 +925,8 @@ TopologyError planBoxFracture(
|
|
|
615
925
|
BodyId targetBodyId,
|
|
616
926
|
const FractureSplitOptions& options,
|
|
617
927
|
FracturePlan& plan) {
|
|
928
|
+
const TopologyError stateError = validateTopologyState(topology, bodies, joints);
|
|
929
|
+
if (!stateError.ok()) return stateError;
|
|
618
930
|
plan.targetBodyId = targetBodyId;
|
|
619
931
|
plan.fragments.clear();
|
|
620
932
|
plan.affectedJoints.clear();
|
|
@@ -800,14 +1112,15 @@ TopologyError planBoxFracture(
|
|
|
800
1112
|
plan.fragments.push_back(frag2);
|
|
801
1113
|
|
|
802
1114
|
std::vector<EditJointCommand> editJointCommands;
|
|
1115
|
+
const auto jointOffsets = jointRecordOffsets(joints);
|
|
803
1116
|
for (std::size_t jIdx = 0; jIdx < topology.joints.size(); ++jIdx) {
|
|
804
1117
|
const JointIdentity& joint = topology.joints[jIdx];
|
|
805
1118
|
if (joint.bodyA != targetBodyId && joint.bodyB != targetBodyId) continue;
|
|
806
1119
|
plan.affectedJoints.push_back(joint.id);
|
|
807
1120
|
|
|
808
|
-
const std::size_t jOffset = jIdx
|
|
809
|
-
|
|
810
|
-
|
|
1121
|
+
const std::size_t jOffset = jointOffsets[jIdx];
|
|
1122
|
+
auto jointRecord = copyJointRecord(joints.subspan(jOffset, jointRecordStride(joints[jOffset])));
|
|
1123
|
+
auto jointValues = jointRecord.values();
|
|
811
1124
|
|
|
812
1125
|
BodyReference newBodyA = ExistingBodyReference{joint.bodyA};
|
|
813
1126
|
BodyReference newBodyB = ExistingBodyReference{joint.bodyB};
|
|
@@ -836,7 +1149,7 @@ TopologyError planBoxFracture(
|
|
|
836
1149
|
ExistingJointReference{joint.id},
|
|
837
1150
|
newBodyA,
|
|
838
1151
|
newBodyB,
|
|
839
|
-
|
|
1152
|
+
jointRecord
|
|
840
1153
|
});
|
|
841
1154
|
}
|
|
842
1155
|
|
|
@@ -861,6 +1174,8 @@ TopologyError planMultiBoxFracture(
|
|
|
861
1174
|
double separationSpeed,
|
|
862
1175
|
TempBodyId tempBodyIdStart,
|
|
863
1176
|
FracturePlan& plan) {
|
|
1177
|
+
const TopologyError stateError = validateTopologyState(topology, bodies, joints);
|
|
1178
|
+
if (!stateError.ok()) return stateError;
|
|
864
1179
|
plan.targetBodyId = targetBodyId;
|
|
865
1180
|
plan.fragments.clear();
|
|
866
1181
|
plan.affectedJoints.clear();
|
|
@@ -1010,14 +1325,15 @@ TopologyError planMultiBoxFracture(
|
|
|
1010
1325
|
}
|
|
1011
1326
|
|
|
1012
1327
|
std::vector<EditJointCommand> editJointCommands;
|
|
1328
|
+
const auto jointOffsets = jointRecordOffsets(joints);
|
|
1013
1329
|
for (std::size_t jIdx = 0; jIdx < topology.joints.size(); ++jIdx) {
|
|
1014
1330
|
const JointIdentity& joint = topology.joints[jIdx];
|
|
1015
1331
|
if (joint.bodyA != targetBodyId && joint.bodyB != targetBodyId) continue;
|
|
1016
1332
|
plan.affectedJoints.push_back(joint.id);
|
|
1017
1333
|
|
|
1018
|
-
const std::size_t jOffset = jIdx
|
|
1019
|
-
|
|
1020
|
-
|
|
1334
|
+
const std::size_t jOffset = jointOffsets[jIdx];
|
|
1335
|
+
auto jointRecord = copyJointRecord(joints.subspan(jOffset, jointRecordStride(joints[jOffset])));
|
|
1336
|
+
auto jointValues = jointRecord.values();
|
|
1021
1337
|
|
|
1022
1338
|
BodyReference newBodyA = ExistingBodyReference{joint.bodyA};
|
|
1023
1339
|
BodyReference newBodyB = ExistingBodyReference{joint.bodyB};
|
|
@@ -1068,7 +1384,7 @@ TopologyError planMultiBoxFracture(
|
|
|
1068
1384
|
ExistingJointReference{joint.id},
|
|
1069
1385
|
newBodyA,
|
|
1070
1386
|
newBodyB,
|
|
1071
|
-
|
|
1387
|
+
jointRecord
|
|
1072
1388
|
});
|
|
1073
1389
|
}
|
|
1074
1390
|
|
|
@@ -1097,10 +1413,12 @@ TopologyError stageFracture(
|
|
|
1097
1413
|
workspace.topology,
|
|
1098
1414
|
workspace.bodies,
|
|
1099
1415
|
workspace.joints,
|
|
1416
|
+
workspace.fluids,
|
|
1100
1417
|
workspace.forces,
|
|
1101
1418
|
plan.commands,
|
|
1102
1419
|
maxBodies,
|
|
1103
1420
|
maxJoints,
|
|
1421
|
+
64,
|
|
1104
1422
|
workspace);
|
|
1105
1423
|
}
|
|
1106
1424
|
|