@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,15 +1,24 @@
|
|
|
1
1
|
#include "world_abi.hpp"
|
|
2
2
|
|
|
3
3
|
#include "world.hpp"
|
|
4
|
+
#include "checkpoint_schema.hpp"
|
|
5
|
+
#include "world_digest_visitor.hpp"
|
|
6
|
+
#include "../legacy_checkpoint_ids.hpp"
|
|
7
|
+
#include "../instance_ledger.hpp"
|
|
4
8
|
|
|
5
9
|
#include <algorithm>
|
|
6
10
|
#include <array>
|
|
7
11
|
#include <atomic>
|
|
12
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
13
|
+
#include <chrono>
|
|
14
|
+
#include <condition_variable>
|
|
15
|
+
#endif
|
|
8
16
|
#include <cmath>
|
|
9
17
|
#include <cstdlib>
|
|
10
18
|
#include <cstring>
|
|
11
19
|
#include <exception>
|
|
12
20
|
#include <limits>
|
|
21
|
+
#include <stdexcept>
|
|
13
22
|
#include <memory>
|
|
14
23
|
#include <mutex>
|
|
15
24
|
#include <new>
|
|
@@ -17,6 +26,10 @@
|
|
|
17
26
|
#include <string>
|
|
18
27
|
#include <vector>
|
|
19
28
|
|
|
29
|
+
#ifdef __EMSCRIPTEN__
|
|
30
|
+
#include <emscripten/heap.h>
|
|
31
|
+
#endif
|
|
32
|
+
|
|
20
33
|
namespace {
|
|
21
34
|
|
|
22
35
|
using rundot::kinetix::physics::StepOptions;
|
|
@@ -24,18 +37,26 @@ using rundot::kinetix::physics::BodyId;
|
|
|
24
37
|
using rundot::kinetix::physics::BodyReference;
|
|
25
38
|
using rundot::kinetix::physics::CreateBodyCommand;
|
|
26
39
|
using rundot::kinetix::physics::CreateJointCommand;
|
|
40
|
+
using rundot::kinetix::physics::CreateFluidCommand;
|
|
27
41
|
using rundot::kinetix::physics::CreatedBodyReference;
|
|
28
42
|
using rundot::kinetix::physics::CreatedJointReference;
|
|
43
|
+
using rundot::kinetix::physics::CreatedFluidReference;
|
|
29
44
|
using rundot::kinetix::physics::EditBodyCommand;
|
|
30
45
|
using rundot::kinetix::physics::EditJointCommand;
|
|
46
|
+
using rundot::kinetix::physics::EditFluidCommand;
|
|
31
47
|
using rundot::kinetix::physics::ExistingBodyReference;
|
|
32
48
|
using rundot::kinetix::physics::ExistingJointReference;
|
|
49
|
+
using rundot::kinetix::physics::ExistingFluidReference;
|
|
50
|
+
using rundot::kinetix::physics::FluidId;
|
|
51
|
+
using rundot::kinetix::physics::FluidReference;
|
|
33
52
|
using rundot::kinetix::physics::JointId;
|
|
34
53
|
using rundot::kinetix::physics::JointReference;
|
|
35
54
|
using rundot::kinetix::physics::RemoveBodyCommand;
|
|
36
55
|
using rundot::kinetix::physics::RemoveJointCommand;
|
|
56
|
+
using rundot::kinetix::physics::RemoveFluidCommand;
|
|
37
57
|
using rundot::kinetix::physics::TempBodyId;
|
|
38
58
|
using rundot::kinetix::physics::TempJointId;
|
|
59
|
+
using rundot::kinetix::physics::TempFluidId;
|
|
39
60
|
using rundot::kinetix::physics::TopologyBatchResult;
|
|
40
61
|
using rundot::kinetix::physics::TopologyCommand;
|
|
41
62
|
using rundot::kinetix::physics::World;
|
|
@@ -43,14 +64,21 @@ using rundot::kinetix::physics::WorldError;
|
|
|
43
64
|
using rundot::kinetix::physics::WorldErrorCode;
|
|
44
65
|
using rundot::kinetix::physics::WorldCheckpoint;
|
|
45
66
|
using rundot::kinetix::physics::WorldContactEvent;
|
|
67
|
+
using rundot::kinetix::physics::WorldJointBreakEvent;
|
|
68
|
+
using rundot::kinetix::physics::WorldJointReaction;
|
|
46
69
|
using rundot::kinetix::physics::WorldProfile;
|
|
70
|
+
using rundot::kinetix::physics::WorldLimits;
|
|
47
71
|
using rundot::kinetix::physics::WorldQueryHit;
|
|
48
72
|
using rundot::kinetix::physics::WorldQueryKind;
|
|
49
73
|
using rundot::kinetix::physics::WorldState;
|
|
74
|
+
using rundot::kinetix::physics::WorldBodyMobility;
|
|
75
|
+
using rundot::kinetix::physics::WorldSupportImpulse;
|
|
50
76
|
|
|
51
|
-
constexpr std::uint32_t kWorldAbiVersion =
|
|
77
|
+
constexpr std::uint32_t kWorldAbiVersion = 13;
|
|
52
78
|
constexpr std::uint32_t kMaxHandles = 64;
|
|
53
|
-
constexpr std::uint32_t
|
|
79
|
+
constexpr std::uint32_t kDefaultCheckpointsPerWorld = 64;
|
|
80
|
+
constexpr std::uint32_t kMaxCheckpointsPerWorld = 4096;
|
|
81
|
+
static_assert(kMaxCheckpointsPerWorld <= rundot::kinetix::checkpoint_private::kMaxLegacyTableSlots);
|
|
54
82
|
constexpr std::uint32_t kSlotMask = 0xff;
|
|
55
83
|
constexpr std::uint32_t kMaxGeneration = 0x00ffffff;
|
|
56
84
|
constexpr std::size_t kErrorCapacity = 512;
|
|
@@ -66,21 +94,78 @@ enum class AbiStatus : std::int32_t {
|
|
|
66
94
|
InternalFailure = -8,
|
|
67
95
|
CheckpointCapacity = -9,
|
|
68
96
|
InvalidCheckpoint = -10,
|
|
97
|
+
WorldAttached = -11,
|
|
98
|
+
InitialStateMismatch = -12,
|
|
99
|
+
CheckpointTokenExhausted = -13,
|
|
100
|
+
AttachmentMismatch = -14,
|
|
101
|
+
LedgerLive = -15,
|
|
102
|
+
BufferRejected = -16,
|
|
103
|
+
BufferBusy = -17,
|
|
69
104
|
};
|
|
70
105
|
|
|
106
|
+
// Checkpoint generations are 32-bit and are not recycled.
|
|
107
|
+
// Recovery after exhaustion is a new WASM module instance.
|
|
108
|
+
std::atomic<std::uint32_t> gNextCheckpointGeneration{1};
|
|
109
|
+
// Legacy IDs use the full nonzero uint32 range and a separate counter.
|
|
110
|
+
std::atomic<std::uint32_t> gNextLegacyGeneration{1};
|
|
111
|
+
using namespace rundot::kinetix::checkpoint_private;
|
|
112
|
+
|
|
113
|
+
bool reserveNextCheckpointGeneration(std::uint32_t& outGen) {
|
|
114
|
+
std::uint32_t current = gNextCheckpointGeneration.load(std::memory_order_relaxed);
|
|
115
|
+
while (true) {
|
|
116
|
+
if (current == std::numeric_limits<std::uint32_t>::max()) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (gNextCheckpointGeneration.compare_exchange_weak(
|
|
120
|
+
current, current + 1, std::memory_order_acq_rel, std::memory_order_relaxed)) {
|
|
121
|
+
outGen = current;
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
enum class CheckpointCredentialKind { Empty, Legacy, Token };
|
|
128
|
+
|
|
71
129
|
struct CheckpointSlot {
|
|
72
130
|
WorldCheckpoint checkpoint;
|
|
73
|
-
std::uint32_t
|
|
74
|
-
|
|
131
|
+
std::uint32_t generation = 0;
|
|
132
|
+
CheckpointCredentialKind kind = CheckpointCredentialKind::Empty;
|
|
133
|
+
std::uint32_t nextFree = 0;
|
|
75
134
|
};
|
|
76
135
|
|
|
77
136
|
struct Slot {
|
|
78
137
|
struct Control {
|
|
79
|
-
|
|
138
|
+
Control(WorldProfile profile, WorldLimits limits, std::uint32_t capacity)
|
|
139
|
+
: world(std::move(profile), limits),
|
|
140
|
+
checkpointCapacity(capacity) {
|
|
141
|
+
checkpoints.resize(capacity);
|
|
142
|
+
legacyIds.resize(legacyTableCapacity(capacity));
|
|
143
|
+
for (std::uint32_t i = 0; i < capacity; ++i) {
|
|
144
|
+
checkpoints[i].nextFree = (i + 1 < capacity) ? (i + 1) : kFreeListEnd;
|
|
145
|
+
}
|
|
146
|
+
firstFree = (capacity > 0) ? 0 : kFreeListEnd;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
~Control() {
|
|
150
|
+
for (auto& slot : checkpoints) {
|
|
151
|
+
if (slot.kind != CheckpointCredentialKind::Empty) {
|
|
152
|
+
slot.kind = CheckpointCredentialKind::Empty;
|
|
153
|
+
slot.checkpoint.clear();
|
|
154
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().releaseSlot();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
world.dropCaptureCache();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static constexpr std::uint32_t kFreeListEnd = 0xffffffffu;
|
|
80
161
|
|
|
81
162
|
std::mutex mutex;
|
|
82
163
|
World world;
|
|
83
|
-
std::
|
|
164
|
+
std::uint32_t checkpointCapacity = 64;
|
|
165
|
+
std::vector<CheckpointSlot, rundot::kinetix::physics::geometry_private::MetadataAllocator<CheckpointSlot>> checkpoints;
|
|
166
|
+
std::vector<LegacyIdEntry, rundot::kinetix::physics::geometry_private::MetadataAllocator<LegacyIdEntry>> legacyIds;
|
|
167
|
+
std::uint32_t firstFree = 0;
|
|
168
|
+
std::uint32_t liveCheckpointCount = 0;
|
|
84
169
|
bool retired = false;
|
|
85
170
|
};
|
|
86
171
|
|
|
@@ -91,7 +176,57 @@ struct Slot {
|
|
|
91
176
|
|
|
92
177
|
std::array<Slot, kMaxHandles> slots{};
|
|
93
178
|
std::mutex slotsMutex;
|
|
94
|
-
|
|
179
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
180
|
+
struct DestructionRaceTestState {
|
|
181
|
+
std::mutex mutex;
|
|
182
|
+
std::condition_variable changed;
|
|
183
|
+
bool pauseNextAttach = false;
|
|
184
|
+
bool attachPaused = false;
|
|
185
|
+
bool resumeAttach = false;
|
|
186
|
+
std::uint32_t destroyChecks = 0;
|
|
187
|
+
bool destroyObservedAttached = false;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
DestructionRaceTestState destructionRaceTestState;
|
|
191
|
+
thread_local bool gThrowAfterSlotClaim = false;
|
|
192
|
+
|
|
193
|
+
bool consumeThrowAfterSlotClaim() noexcept {
|
|
194
|
+
if (!gThrowAfterSlotClaim) return false;
|
|
195
|
+
gThrowAfterSlotClaim = false;
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
void pauseAttachForTest() {
|
|
200
|
+
std::unique_lock<std::mutex> lock(destructionRaceTestState.mutex);
|
|
201
|
+
if (!destructionRaceTestState.pauseNextAttach) return;
|
|
202
|
+
destructionRaceTestState.pauseNextAttach = false;
|
|
203
|
+
destructionRaceTestState.attachPaused = true;
|
|
204
|
+
destructionRaceTestState.changed.notify_all();
|
|
205
|
+
destructionRaceTestState.changed.wait(lock, [] {
|
|
206
|
+
return destructionRaceTestState.resumeAttach;
|
|
207
|
+
});
|
|
208
|
+
destructionRaceTestState.resumeAttach = false;
|
|
209
|
+
destructionRaceTestState.attachPaused = false;
|
|
210
|
+
destructionRaceTestState.changed.notify_all();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
void recordDestroyAttachmentForTest(bool attached) {
|
|
214
|
+
std::lock_guard<std::mutex> lock(destructionRaceTestState.mutex);
|
|
215
|
+
destructionRaceTestState.destroyChecks += 1;
|
|
216
|
+
destructionRaceTestState.destroyObservedAttached = attached;
|
|
217
|
+
destructionRaceTestState.changed.notify_all();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
struct ViewPinTestState {
|
|
221
|
+
std::mutex mutex;
|
|
222
|
+
std::condition_variable changed;
|
|
223
|
+
bool arm = false;
|
|
224
|
+
bool paused = false;
|
|
225
|
+
bool resume = false;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
ViewPinTestState viewPinTestState;
|
|
229
|
+
#endif
|
|
95
230
|
thread_local std::array<char, kErrorCapacity> lastError{};
|
|
96
231
|
thread_local std::uint32_t lastErrorSize = 0;
|
|
97
232
|
thread_local std::uint32_t lastErrorCommandIndex = std::numeric_limits<std::uint32_t>::max();
|
|
@@ -100,25 +235,13 @@ std::int32_t status(AbiStatus value) {
|
|
|
100
235
|
return static_cast<std::int32_t>(value);
|
|
101
236
|
}
|
|
102
237
|
|
|
103
|
-
std::uint32_t acquireCheckpointToken() {
|
|
104
|
-
std::uint32_t current = nextCheckpointToken.load(std::memory_order_relaxed);
|
|
105
|
-
while (current != 0) {
|
|
106
|
-
const std::uint32_t next = current == std::numeric_limits<std::uint32_t>::max()
|
|
107
|
-
? 0 : current + 1;
|
|
108
|
-
if (nextCheckpointToken.compare_exchange_weak(
|
|
109
|
-
current, next, std::memory_order_relaxed, std::memory_order_relaxed)) {
|
|
110
|
-
return current;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return 0;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
238
|
CheckpointSlot* findCheckpoint(Slot::Control& control, std::uint32_t token) {
|
|
117
239
|
if (token == 0) return nullptr;
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
240
|
+
const std::uint32_t slotIndex = legacySlot(control.legacyIds, token);
|
|
241
|
+
if (slotIndex >= control.checkpointCapacity) return nullptr;
|
|
242
|
+
CheckpointSlot& slot = control.checkpoints[slotIndex];
|
|
243
|
+
if (slot.kind != CheckpointCredentialKind::Legacy || slot.generation != token) return nullptr;
|
|
244
|
+
return &slot;
|
|
122
245
|
}
|
|
123
246
|
|
|
124
247
|
void clearError() {
|
|
@@ -136,6 +259,18 @@ std::int32_t fail(AbiStatus code, const char* detail) {
|
|
|
136
259
|
}
|
|
137
260
|
|
|
138
261
|
std::int32_t fail(const WorldError& error) {
|
|
262
|
+
if (error.code == WorldErrorCode::AllocationFailure) {
|
|
263
|
+
return fail(AbiStatus::AllocationFailure, error.detail.c_str());
|
|
264
|
+
}
|
|
265
|
+
if (error.code == WorldErrorCode::WorldAttached) {
|
|
266
|
+
return fail(AbiStatus::WorldAttached, error.detail.c_str());
|
|
267
|
+
}
|
|
268
|
+
if (error.code == WorldErrorCode::InitialStateMismatch) {
|
|
269
|
+
return fail(AbiStatus::InitialStateMismatch, error.detail.c_str());
|
|
270
|
+
}
|
|
271
|
+
if (error.code == WorldErrorCode::CheckpointTokenExhausted) {
|
|
272
|
+
return fail(AbiStatus::CheckpointTokenExhausted, error.detail.c_str());
|
|
273
|
+
}
|
|
139
274
|
fail(AbiStatus::InternalFailure, error.detail.c_str());
|
|
140
275
|
lastErrorCommandIndex = error.commandIndex;
|
|
141
276
|
return -100 - static_cast<std::int32_t>(error.code);
|
|
@@ -192,6 +327,27 @@ bool parseJointReference(
|
|
|
192
327
|
return false;
|
|
193
328
|
}
|
|
194
329
|
|
|
330
|
+
bool parseFluidReference(
|
|
331
|
+
std::uint32_t tag,
|
|
332
|
+
std::uint32_t low,
|
|
333
|
+
std::uint32_t high,
|
|
334
|
+
FluidReference& output) {
|
|
335
|
+
using rundot::kinetix::physics::WorldTopologyReferenceTag;
|
|
336
|
+
if (tag == static_cast<std::uint32_t>(WorldTopologyReferenceTag::CreatedFluid)
|
|
337
|
+
&& low != 0 && high == 0) {
|
|
338
|
+
output = CreatedFluidReference{TempFluidId{low}};
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
if (tag == static_cast<std::uint32_t>(WorldTopologyReferenceTag::ExistingFluid)) {
|
|
342
|
+
const FluidId id{joinU64(low, high)};
|
|
343
|
+
if (id.value != 0) {
|
|
344
|
+
output = ExistingFluidReference{id};
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
|
|
195
351
|
template <std::size_t Size>
|
|
196
352
|
bool copyRecord(
|
|
197
353
|
const double* values,
|
|
@@ -210,12 +366,32 @@ bool noReference(const std::uint32_t* fields) {
|
|
|
210
366
|
&& fields[1] == 0 && fields[2] == 0;
|
|
211
367
|
}
|
|
212
368
|
|
|
369
|
+
bool copyJointRecord(const double* records, std::uint32_t slotCount,
|
|
370
|
+
std::uint32_t index, rundot::kinetix::physics::JointRecord& output) {
|
|
371
|
+
using namespace rundot::kinetix::physics;
|
|
372
|
+
if (records == nullptr || index >= slotCount) return false;
|
|
373
|
+
const double* first = records + static_cast<std::size_t>(index) * kJointStride;
|
|
374
|
+
if (first[0] == 10) {
|
|
375
|
+
if (slotCount - index < 3) return false;
|
|
376
|
+
std::array<double, 3 * kJointStride> values;
|
|
377
|
+
std::copy_n(first, values.size(), values.begin());
|
|
378
|
+
output = values;
|
|
379
|
+
} else {
|
|
380
|
+
std::array<double, kJointStride> values;
|
|
381
|
+
std::copy_n(first, values.size(), values.begin());
|
|
382
|
+
output = values;
|
|
383
|
+
}
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
|
|
213
387
|
bool parseTopologyCommand(
|
|
214
388
|
const std::uint32_t* fields,
|
|
215
389
|
const double* bodyRecords,
|
|
216
390
|
std::uint32_t bodyRecordCount,
|
|
217
391
|
const double* jointRecords,
|
|
218
392
|
std::uint32_t jointRecordCount,
|
|
393
|
+
const double* fluidRecords,
|
|
394
|
+
std::uint32_t fluidRecordCount,
|
|
219
395
|
TopologyCommand& output) {
|
|
220
396
|
using rundot::kinetix::physics::WorldTopologyCommandTag;
|
|
221
397
|
using rundot::kinetix::physics::WorldTopologyReferenceTag;
|
|
@@ -225,6 +401,7 @@ bool parseTopologyCommand(
|
|
|
225
401
|
BodyReference bodyA;
|
|
226
402
|
BodyReference bodyB;
|
|
227
403
|
JointReference subjectJoint;
|
|
404
|
+
FluidReference subjectFluid;
|
|
228
405
|
if (tag == WorldTopologyCommandTag::CreateBody) {
|
|
229
406
|
std::array<double, rundot::kinetix::physics::kBodyStride> values{};
|
|
230
407
|
if (fields[1] != static_cast<std::uint32_t>(WorldTopologyReferenceTag::CreatedBody)
|
|
@@ -249,21 +426,21 @@ bool parseTopologyCommand(
|
|
|
249
426
|
return true;
|
|
250
427
|
}
|
|
251
428
|
if (tag == WorldTopologyCommandTag::CreateJoint) {
|
|
252
|
-
|
|
429
|
+
rundot::kinetix::physics::JointRecord values;
|
|
253
430
|
if (fields[1] != static_cast<std::uint32_t>(WorldTopologyReferenceTag::CreatedJoint)
|
|
254
431
|
|| fields[2] == 0 || fields[3] != 0
|
|
255
432
|
|| !parseBodyReference(fields[4], fields[5], fields[6], bodyA)
|
|
256
433
|
|| !parseBodyReference(fields[7], fields[8], fields[9], bodyB)
|
|
257
|
-
|| !
|
|
434
|
+
|| !copyJointRecord(jointRecords, jointRecordCount, fields[10], values)) return false;
|
|
258
435
|
output = CreateJointCommand{TempJointId{fields[2]}, bodyA, bodyB, values};
|
|
259
436
|
return true;
|
|
260
437
|
}
|
|
261
438
|
if (tag == WorldTopologyCommandTag::EditJoint) {
|
|
262
|
-
|
|
439
|
+
rundot::kinetix::physics::JointRecord values;
|
|
263
440
|
if (!parseJointReference(fields[1], fields[2], fields[3], subjectJoint)
|
|
264
441
|
|| !parseBodyReference(fields[4], fields[5], fields[6], bodyA)
|
|
265
442
|
|| !parseBodyReference(fields[7], fields[8], fields[9], bodyB)
|
|
266
|
-
|| !
|
|
443
|
+
|| !copyJointRecord(jointRecords, jointRecordCount, fields[10], values)) return false;
|
|
267
444
|
output = EditJointCommand{subjectJoint, bodyA, bodyB, values};
|
|
268
445
|
return true;
|
|
269
446
|
}
|
|
@@ -274,6 +451,30 @@ bool parseTopologyCommand(
|
|
|
274
451
|
output = RemoveJointCommand{subjectJoint};
|
|
275
452
|
return true;
|
|
276
453
|
}
|
|
454
|
+
if (tag == WorldTopologyCommandTag::CreateFluid) {
|
|
455
|
+
std::array<double, rundot::kinetix::physics::kFluidStride> values{};
|
|
456
|
+
if (fields[1] != static_cast<std::uint32_t>(WorldTopologyReferenceTag::CreatedFluid)
|
|
457
|
+
|| fields[2] == 0 || fields[3] != 0 || !noReference(fields + 4)
|
|
458
|
+
|| !noReference(fields + 7)
|
|
459
|
+
|| !copyRecord(fluidRecords, fluidRecordCount, fields[10], values)) return false;
|
|
460
|
+
output = CreateFluidCommand{TempFluidId{fields[2]}, values};
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
if (tag == WorldTopologyCommandTag::EditFluid) {
|
|
464
|
+
std::array<double, rundot::kinetix::physics::kFluidStride> values{};
|
|
465
|
+
if (!parseFluidReference(fields[1], fields[2], fields[3], subjectFluid)
|
|
466
|
+
|| !noReference(fields + 4) || !noReference(fields + 7)
|
|
467
|
+
|| !copyRecord(fluidRecords, fluidRecordCount, fields[10], values)) return false;
|
|
468
|
+
output = EditFluidCommand{subjectFluid, values};
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
if (tag == WorldTopologyCommandTag::RemoveFluid) {
|
|
472
|
+
if (!parseFluidReference(fields[1], fields[2], fields[3], subjectFluid)
|
|
473
|
+
|| !noReference(fields + 4) || !noReference(fields + 7)
|
|
474
|
+
|| fields[10] != std::numeric_limits<std::uint32_t>::max()) return false;
|
|
475
|
+
output = RemoveFluidCommand{subjectFluid};
|
|
476
|
+
return true;
|
|
477
|
+
}
|
|
277
478
|
return false;
|
|
278
479
|
}
|
|
279
480
|
|
|
@@ -441,15 +642,17 @@ void writeWarmStates(std::uint8_t* bytes,
|
|
|
441
642
|
}
|
|
442
643
|
|
|
443
644
|
bool parseTopologyState(const std::uint32_t* words, std::uint32_t wordCount,
|
|
444
|
-
std::uint32_t bodyCount, std::uint32_t jointCount,
|
|
645
|
+
std::uint32_t bodyCount, std::uint32_t jointCount, std::uint32_t fluidCount,
|
|
445
646
|
rundot::kinetix::physics::TopologyState& output) {
|
|
446
647
|
if (wordCount == 0) return true;
|
|
447
|
-
const std::uint64_t required =
|
|
648
|
+
const std::uint64_t required = 6ull + 2ull * bodyCount + 6ull * jointCount
|
|
649
|
+
+ 2ull * fluidCount;
|
|
448
650
|
if (words == nullptr || wordCount != required) return false;
|
|
449
651
|
output.nextBodyId = BodyId{joinU64(words[0], words[1])};
|
|
450
652
|
output.nextJointId = JointId{joinU64(words[2], words[3])};
|
|
653
|
+
output.nextFluidId = FluidId{joinU64(words[4], words[5])};
|
|
451
654
|
output.bodyIds.resize(bodyCount);
|
|
452
|
-
std::size_t offset =
|
|
655
|
+
std::size_t offset = 6;
|
|
453
656
|
for (BodyId& id : output.bodyIds) {
|
|
454
657
|
id = BodyId{joinU64(words[offset], words[offset + 1])};
|
|
455
658
|
offset += 2;
|
|
@@ -461,42 +664,62 @@ bool parseTopologyState(const std::uint32_t* words, std::uint32_t wordCount,
|
|
|
461
664
|
joint.bodyB = BodyId{joinU64(words[offset + 4], words[offset + 5])};
|
|
462
665
|
offset += 6;
|
|
463
666
|
}
|
|
667
|
+
output.fluidIds.resize(fluidCount);
|
|
668
|
+
for (FluidId& id : output.fluidIds) {
|
|
669
|
+
id = FluidId{joinU64(words[offset], words[offset + 1])};
|
|
670
|
+
offset += 2;
|
|
671
|
+
}
|
|
464
672
|
return true;
|
|
465
673
|
}
|
|
466
674
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
675
|
+
using Module3D = rundot::kinetix::memory::Physics3DModule;
|
|
676
|
+
using ScratchLeases3D = rundot::kinetix::memory::ScratchLeases<Module3D>;
|
|
677
|
+
using Pins3D = rundot::kinetix::memory::Pins<Module3D>;
|
|
678
|
+
using CallerRange = rundot::kinetix::memory::CallerRange;
|
|
679
|
+
using RangeRole = rundot::kinetix::memory::RangeRole;
|
|
471
680
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return
|
|
681
|
+
const char* admitStatusDetail(rundot::kinetix::memory::AdmitStatus status) noexcept {
|
|
682
|
+
switch (status) {
|
|
683
|
+
case rundot::kinetix::memory::AdmitStatus::Ok: return "Ok";
|
|
684
|
+
case rundot::kinetix::memory::AdmitStatus::TooManyRanges: return "TooManyRanges";
|
|
685
|
+
case rundot::kinetix::memory::AdmitStatus::InvalidRange: return "InvalidRange";
|
|
686
|
+
case rundot::kinetix::memory::AdmitStatus::UnknownLease: return "UnknownLease";
|
|
687
|
+
case rundot::kinetix::memory::AdmitStatus::Overlap: return "Overlap";
|
|
688
|
+
case rundot::kinetix::memory::AdmitStatus::Busy: return "Busy";
|
|
689
|
+
case rundot::kinetix::memory::AdmitStatus::PinOverflow: return "PinOverflow";
|
|
476
690
|
}
|
|
477
|
-
|
|
478
|
-
const std::uintptr_t begin = reinterpret_cast<std::uintptr_t>(pointer);
|
|
479
|
-
if (begin > std::numeric_limits<std::uintptr_t>::max() - static_cast<std::uintptr_t>(bytes)) return false;
|
|
480
|
-
output = {begin, begin + static_cast<std::uintptr_t>(bytes)};
|
|
481
|
-
return true;
|
|
691
|
+
return "UnknownAdmitStatus";
|
|
482
692
|
}
|
|
483
693
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (ranges[first].begin < ranges[second].end
|
|
490
|
-
&& ranges[second].begin < ranges[first].end) return false;
|
|
491
|
-
}
|
|
694
|
+
AbiStatus admitCall(std::span<const CallerRange> ranges, Pins3D& pins) noexcept {
|
|
695
|
+
const auto status = ScratchLeases3D::instance().admit(ranges, pins);
|
|
696
|
+
if (status != rundot::kinetix::memory::AdmitStatus::Ok) {
|
|
697
|
+
fail(AbiStatus::BufferRejected, admitStatusDetail(status));
|
|
698
|
+
return AbiStatus::BufferRejected;
|
|
492
699
|
}
|
|
493
|
-
return
|
|
700
|
+
return AbiStatus::Ok;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
std::uint32_t writeTopologyResult(const TopologyBatchResult& result, std::uint32_t* output) {
|
|
704
|
+
std::uint32_t written = 0;
|
|
705
|
+
const auto write = [&](std::uint32_t kind, std::uint32_t temp, std::uint64_t id) {
|
|
706
|
+
output[written] = kind;
|
|
707
|
+
output[written + 1] = temp;
|
|
708
|
+
splitU64(id, output + written + 2);
|
|
709
|
+
written += rundot::kinetix::physics::kWorldTopologyResultStride;
|
|
710
|
+
};
|
|
711
|
+
for (const auto& body : result.bodies) write(1, body.temp.value, body.id.value);
|
|
712
|
+
for (const auto& joint : result.joints) write(2, joint.temp.value, joint.id.value);
|
|
713
|
+
for (const auto& fluid : result.fluids) write(3, fluid.temp.value, fluid.id.value);
|
|
714
|
+
return written;
|
|
494
715
|
}
|
|
495
716
|
|
|
496
717
|
template <typename Action>
|
|
497
718
|
std::int32_t guard(Action action) noexcept {
|
|
498
719
|
try {
|
|
499
720
|
return action();
|
|
721
|
+
} catch (const rundot::kinetix::physics::geometry_private::AllocationCapacity& error) {
|
|
722
|
+
return fail(AbiStatus::AllocationFailure, error.what());
|
|
500
723
|
} catch (const std::bad_alloc&) {
|
|
501
724
|
return fail(AbiStatus::AllocationFailure, "world allocation failed");
|
|
502
725
|
} catch (const std::exception& error) {
|
|
@@ -506,12 +729,661 @@ std::int32_t guard(Action action) noexcept {
|
|
|
506
729
|
}
|
|
507
730
|
}
|
|
508
731
|
|
|
732
|
+
struct SlotClaimGuard {
|
|
733
|
+
bool active = true;
|
|
734
|
+
void dismiss() noexcept { active = false; }
|
|
735
|
+
~SlotClaimGuard() noexcept {
|
|
736
|
+
if (active) {
|
|
737
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().releaseSlot();
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
std::int32_t publishSnapshotBytes(
|
|
743
|
+
const rundot::kinetix::physics::World::Snapshot& snapshot,
|
|
744
|
+
std::uint8_t* output,
|
|
745
|
+
std::uint32_t output_capacity,
|
|
746
|
+
std::uint32_t* required_bytes) {
|
|
747
|
+
if (snapshot.size() > std::numeric_limits<std::uint32_t>::max()) {
|
|
748
|
+
return fail(AbiStatus::InvalidArgument, "snapshot size exceeds the output word");
|
|
749
|
+
}
|
|
750
|
+
const auto size = static_cast<std::uint32_t>(snapshot.size());
|
|
751
|
+
*required_bytes = size;
|
|
752
|
+
if (output_capacity < size) {
|
|
753
|
+
return fail(AbiStatus::ShortBuffer, "snapshot output buffer is too small");
|
|
754
|
+
}
|
|
755
|
+
if (size != 0) std::copy(snapshot.begin(), snapshot.end(), output);
|
|
756
|
+
return status(AbiStatus::Ok);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
using rundot::kinetix::physics::BodyTile;
|
|
760
|
+
using rundot::kinetix::physics::CheckpointBodyTable;
|
|
761
|
+
using rundot::kinetix::physics::CheckpointData;
|
|
762
|
+
using rundot::kinetix::physics::bodyTileDoubles;
|
|
763
|
+
using rundot::kinetix::physics::CheckpointProfile;
|
|
764
|
+
using rundot::kinetix::physics::WorldFluidInteraction;
|
|
765
|
+
using rundot::kinetix::physics::kBodyStride;
|
|
766
|
+
using rundot::kinetix::physics::kBodyStrideWide;
|
|
767
|
+
using rundot::kinetix::physics::kCheckpointBodyTileRows;
|
|
768
|
+
using rundot::kinetix::physics::kCheckpointViewInfoWords;
|
|
769
|
+
using rundot::kinetix::physics::kMotionHeaderWords;
|
|
770
|
+
using rundot::kinetix::physics::kMotionIdWordLimit;
|
|
771
|
+
using rundot::kinetix::physics::kMotionPoseStride;
|
|
772
|
+
using rundot::kinetix::physics::kMotionPoseValueLimit;
|
|
773
|
+
using rundot::kinetix::physics::kMotionStatusByteLimit;
|
|
774
|
+
using rundot::kinetix::physics::kMotionStatusVersion;
|
|
775
|
+
using rundot::kinetix::physics::kMotionVelocityStride;
|
|
776
|
+
using rundot::kinetix::physics::kMotionVelocityValueLimit;
|
|
777
|
+
using rundot::kinetix::physics::kWorldContactOutputMetadataStride;
|
|
778
|
+
using rundot::kinetix::physics::kWorldContactOutputValueStride;
|
|
779
|
+
using rundot::kinetix::physics::kWorldFluidInteractionMetadataStride;
|
|
780
|
+
using rundot::kinetix::physics::kWorldFluidInteractionValueStride;
|
|
781
|
+
using rundot::kinetix::physics::kWorldJointBreakMetadataStride;
|
|
782
|
+
using rundot::kinetix::physics::kWorldJointReactionMetadataStride;
|
|
783
|
+
using rundot::kinetix::physics::kWorldJointReactionValueStride;
|
|
784
|
+
using rundot::kinetix::physics::kWorldMaxBodies;
|
|
785
|
+
using rundot::kinetix::physics::kWorldMaxProfileIdBytes;
|
|
786
|
+
|
|
787
|
+
enum class SelectedCredentialMode { Legacy, Token };
|
|
788
|
+
|
|
789
|
+
struct SelectedCredential {
|
|
790
|
+
SelectedCredentialMode mode = SelectedCredentialMode::Legacy;
|
|
791
|
+
std::uint32_t checkpointId = 0;
|
|
792
|
+
std::uint32_t attachmentToken = 0;
|
|
793
|
+
std::uint32_t slotIndex = 0;
|
|
794
|
+
std::uint32_t generation = 0;
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
struct ViewFacts {
|
|
798
|
+
std::uint64_t frame = 0;
|
|
799
|
+
std::uint32_t bodyCount = 0;
|
|
800
|
+
std::uint32_t contactCount = 0;
|
|
801
|
+
std::uint32_t reactionCount = 0;
|
|
802
|
+
std::uint32_t breakCount = 0;
|
|
803
|
+
std::uint32_t fluidCount = 0;
|
|
804
|
+
std::uint32_t stride = 0;
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
struct LatestOutputLayout {
|
|
808
|
+
std::uint64_t contactValueAt = 0;
|
|
809
|
+
std::uint64_t reactionValueAt = 0;
|
|
810
|
+
std::uint64_t fluidValueAt = 0;
|
|
811
|
+
std::uint64_t contactMetaAt = 0;
|
|
812
|
+
std::uint64_t reactionMetaAt = 0;
|
|
813
|
+
std::uint64_t breakMetaAt = 0;
|
|
814
|
+
std::uint64_t fluidMetaAt = 0;
|
|
815
|
+
std::uint64_t bytes = 0;
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
void pauseCheckpointViewForTest() noexcept {
|
|
819
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
820
|
+
std::unique_lock<std::mutex> lock(viewPinTestState.mutex);
|
|
821
|
+
if (!viewPinTestState.arm) return;
|
|
822
|
+
viewPinTestState.arm = false;
|
|
823
|
+
viewPinTestState.paused = true;
|
|
824
|
+
viewPinTestState.changed.notify_all();
|
|
825
|
+
viewPinTestState.changed.wait(lock, [] {
|
|
826
|
+
return viewPinTestState.resume;
|
|
827
|
+
});
|
|
828
|
+
viewPinTestState.resume = false;
|
|
829
|
+
viewPinTestState.paused = false;
|
|
830
|
+
viewPinTestState.changed.notify_all();
|
|
831
|
+
#endif
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
bool addressBytesFit(std::uint64_t count, std::uint64_t elementBytes) noexcept {
|
|
835
|
+
return elementBytes == 0
|
|
836
|
+
|| count <= static_cast<std::uint64_t>(std::numeric_limits<std::size_t>::max()) / elementBytes;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
rundot::kinetix::memory::CallerRange countedCallerRange(
|
|
840
|
+
const void* data,
|
|
841
|
+
std::uint64_t count,
|
|
842
|
+
std::size_t elementBytes,
|
|
843
|
+
std::size_t alignment,
|
|
844
|
+
rundot::kinetix::memory::RangeRole role,
|
|
845
|
+
bool& overflow) noexcept {
|
|
846
|
+
using rundot::kinetix::memory::CallerRange;
|
|
847
|
+
CallerRange range{data, 0, alignment, role, count, static_cast<std::uint64_t>(elementBytes)};
|
|
848
|
+
std::size_t bytes = 0;
|
|
849
|
+
if (!rundot::kinetix::memory::detail::countedProduct(
|
|
850
|
+
count, static_cast<std::uint64_t>(elementBytes), bytes)) {
|
|
851
|
+
overflow = true;
|
|
852
|
+
return range;
|
|
853
|
+
}
|
|
854
|
+
range.bytes = bytes;
|
|
855
|
+
return range;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
std::int32_t resolveSelectedCheckpoint(
|
|
859
|
+
Slot::Control& control,
|
|
860
|
+
const SelectedCredential& credential,
|
|
861
|
+
WorldCheckpoint*& out) {
|
|
862
|
+
out = nullptr;
|
|
863
|
+
if (credential.mode == SelectedCredentialMode::Legacy) {
|
|
864
|
+
if (control.world.isAttached()) {
|
|
865
|
+
return fail(AbiStatus::WorldAttached, "cannot digest legacy checkpoint while attached");
|
|
866
|
+
}
|
|
867
|
+
CheckpointSlot* slot = findCheckpoint(control, credential.checkpointId);
|
|
868
|
+
if (slot == nullptr) {
|
|
869
|
+
return fail(AbiStatus::InvalidCheckpoint,
|
|
870
|
+
"checkpoint handle is stale or belongs to another world");
|
|
871
|
+
}
|
|
872
|
+
out = &slot->checkpoint;
|
|
873
|
+
return status(AbiStatus::Ok);
|
|
874
|
+
}
|
|
875
|
+
if (control.world.isAttached()) {
|
|
876
|
+
if (credential.attachmentToken == 0
|
|
877
|
+
|| credential.attachmentToken != control.world.attachmentToken()) {
|
|
878
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
879
|
+
}
|
|
880
|
+
} else if (credential.attachmentToken != 0) {
|
|
881
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
882
|
+
}
|
|
883
|
+
if (credential.slotIndex >= control.checkpointCapacity) {
|
|
884
|
+
return fail(AbiStatus::InvalidCheckpoint, "slot index out of range");
|
|
885
|
+
}
|
|
886
|
+
CheckpointSlot& slot = control.checkpoints[credential.slotIndex];
|
|
887
|
+
if (slot.kind != CheckpointCredentialKind::Token || slot.generation != credential.generation) {
|
|
888
|
+
return fail(AbiStatus::InvalidCheckpoint,
|
|
889
|
+
"checkpoint handle is stale or belongs to another world");
|
|
890
|
+
}
|
|
891
|
+
out = &slot.checkpoint;
|
|
892
|
+
return status(AbiStatus::Ok);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
std::int32_t bindCheckpointView(const World& world, const CheckpointData& data, ViewFacts& facts) {
|
|
896
|
+
if (data.world.value == 0 || data.world != world.ownerToken()) {
|
|
897
|
+
return fail(AbiStatus::InvalidCheckpoint, "checkpoint belongs to another world");
|
|
898
|
+
}
|
|
899
|
+
const WorldProfile& profile = world.profile();
|
|
900
|
+
const CheckpointProfile& saved = data.profile;
|
|
901
|
+
if (saved.idLength == 0
|
|
902
|
+
|| saved.idLength > kWorldMaxProfileIdBytes
|
|
903
|
+
|| saved.idLength != profile.id.size()
|
|
904
|
+
|| saved.abiVersion != profile.abiVersion
|
|
905
|
+
|| saved.numericProfile != profile.numericProfile
|
|
906
|
+
|| std::memcmp(saved.id.data(), profile.id.data(), saved.idLength) != 0
|
|
907
|
+
|| saved.geometryDigest != profile.geometryDigest) {
|
|
908
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint profile does not match the world");
|
|
909
|
+
}
|
|
910
|
+
if (!data.bodies) {
|
|
911
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint has no body table");
|
|
912
|
+
}
|
|
913
|
+
const auto fitCount = [](std::size_t count) {
|
|
914
|
+
return count <= std::numeric_limits<std::uint32_t>::max();
|
|
915
|
+
};
|
|
916
|
+
if (!fitCount(data.contactEvents().size())
|
|
917
|
+
|| !fitCount(data.jointReactions().size())
|
|
918
|
+
|| !fitCount(data.jointBreakEvents().size())
|
|
919
|
+
|| !fitCount(data.fluidInteractions().size())
|
|
920
|
+
|| !fitCount(data.topologyBodyIds().size())) {
|
|
921
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint output count exceeds the output word");
|
|
922
|
+
}
|
|
923
|
+
const std::size_t bodyCount = data.topologyBodyIds().size();
|
|
924
|
+
if (bodyCount > kWorldMaxBodies) {
|
|
925
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body count exceeds the native limit");
|
|
926
|
+
}
|
|
927
|
+
const CheckpointBodyTable& table = *data.bodies;
|
|
928
|
+
std::uint32_t stride = 0;
|
|
929
|
+
if (bodyCount == 0) {
|
|
930
|
+
if (table.valueCount != 0 || !table.tiles.empty()) {
|
|
931
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body table does not match topology");
|
|
932
|
+
}
|
|
933
|
+
} else {
|
|
934
|
+
if (table.tileValues == 0 || (table.tileValues % kCheckpointBodyTileRows) != 0) {
|
|
935
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body table tile shape is invalid");
|
|
936
|
+
}
|
|
937
|
+
stride = table.tileValues / kCheckpointBodyTileRows;
|
|
938
|
+
if (stride != kBodyStride && stride != kBodyStrideWide) {
|
|
939
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body table stride is invalid");
|
|
940
|
+
}
|
|
941
|
+
if (table.valueCount != static_cast<std::uint64_t>(bodyCount) * stride) {
|
|
942
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body table does not match topology");
|
|
943
|
+
}
|
|
944
|
+
const std::uint64_t tileValues = table.tileValues;
|
|
945
|
+
const std::uint64_t numTiles = (table.valueCount + tileValues - 1) / tileValues;
|
|
946
|
+
if (table.tiles.size() != numTiles) {
|
|
947
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body table tile count mismatch");
|
|
948
|
+
}
|
|
949
|
+
for (const auto& tile : table.tiles) {
|
|
950
|
+
if (!tile) {
|
|
951
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint body table has a null tile");
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
facts.frame = data.frame;
|
|
956
|
+
facts.bodyCount = static_cast<std::uint32_t>(bodyCount);
|
|
957
|
+
facts.contactCount = static_cast<std::uint32_t>(data.contactEvents().size());
|
|
958
|
+
facts.reactionCount = static_cast<std::uint32_t>(data.jointReactions().size());
|
|
959
|
+
facts.breakCount = static_cast<std::uint32_t>(data.jointBreakEvents().size());
|
|
960
|
+
facts.fluidCount = static_cast<std::uint32_t>(data.fluidInteractions().size());
|
|
961
|
+
facts.stride = stride;
|
|
962
|
+
return status(AbiStatus::Ok);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
template <typename CapCheck>
|
|
966
|
+
std::int32_t loadSelectedCheckpoint(
|
|
967
|
+
std::uint32_t handle,
|
|
968
|
+
const SelectedCredential& credential,
|
|
969
|
+
std::shared_ptr<const CheckpointData>& pinned,
|
|
970
|
+
ViewFacts& facts,
|
|
971
|
+
CapCheck capCheck) {
|
|
972
|
+
pinned.reset();
|
|
973
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
974
|
+
WorldCheckpoint* checkpoint = nullptr;
|
|
975
|
+
if (const auto err = resolveSelectedCheckpoint(control, credential, checkpoint)) return err;
|
|
976
|
+
if (checkpoint == nullptr || !checkpoint->data()) {
|
|
977
|
+
return fail(AbiStatus::InvalidCheckpoint, "checkpoint is empty or uncaptured");
|
|
978
|
+
}
|
|
979
|
+
ViewFacts local;
|
|
980
|
+
if (const auto err = bindCheckpointView(control.world, *checkpoint->data(), local)) return err;
|
|
981
|
+
if (const auto err = capCheck(local)) return err;
|
|
982
|
+
pinned = checkpoint->data();
|
|
983
|
+
facts = local;
|
|
984
|
+
return status(AbiStatus::Ok);
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
std::int32_t layoutLatestOutput(const ViewFacts& facts, LatestOutputLayout& layout) {
|
|
989
|
+
layout = {};
|
|
990
|
+
const auto section = [](std::uint64_t count, std::uint64_t stride, std::uint64_t element, std::uint64_t& bytes) {
|
|
991
|
+
if (stride != 0 && count > std::numeric_limits<std::uint64_t>::max() / stride) return false;
|
|
992
|
+
const std::uint64_t records = count * stride;
|
|
993
|
+
if (element != 0 && records > std::numeric_limits<std::uint64_t>::max() / element) return false;
|
|
994
|
+
bytes = records * element;
|
|
995
|
+
return true;
|
|
996
|
+
};
|
|
997
|
+
std::uint64_t contactValues = 0;
|
|
998
|
+
std::uint64_t reactionValues = 0;
|
|
999
|
+
std::uint64_t fluidValues = 0;
|
|
1000
|
+
std::uint64_t contactMeta = 0;
|
|
1001
|
+
std::uint64_t reactionMeta = 0;
|
|
1002
|
+
std::uint64_t breakMeta = 0;
|
|
1003
|
+
std::uint64_t fluidMeta = 0;
|
|
1004
|
+
if (!section(facts.contactCount, kWorldContactOutputValueStride, sizeof(double), contactValues)
|
|
1005
|
+
|| !section(facts.reactionCount, kWorldJointReactionValueStride, sizeof(double), reactionValues)
|
|
1006
|
+
|| !section(facts.fluidCount, kWorldFluidInteractionValueStride, sizeof(double), fluidValues)
|
|
1007
|
+
|| !section(facts.contactCount, kWorldContactOutputMetadataStride, sizeof(std::uint32_t), contactMeta)
|
|
1008
|
+
|| !section(facts.reactionCount, kWorldJointReactionMetadataStride, sizeof(std::uint32_t), reactionMeta)
|
|
1009
|
+
|| !section(facts.breakCount, kWorldJointBreakMetadataStride, sizeof(std::uint32_t), breakMeta)
|
|
1010
|
+
|| !section(facts.fluidCount, kWorldFluidInteractionMetadataStride, sizeof(std::uint32_t), fluidMeta)) {
|
|
1011
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint output packet size overflows");
|
|
1012
|
+
}
|
|
1013
|
+
std::uint64_t cursor = 0;
|
|
1014
|
+
const auto place = [&](std::uint64_t bytes, std::uint64_t& at) {
|
|
1015
|
+
at = cursor;
|
|
1016
|
+
if (bytes > std::numeric_limits<std::uint64_t>::max() - cursor) return false;
|
|
1017
|
+
cursor += bytes;
|
|
1018
|
+
return true;
|
|
1019
|
+
};
|
|
1020
|
+
if (!place(contactValues, layout.contactValueAt)
|
|
1021
|
+
|| !place(reactionValues, layout.reactionValueAt)
|
|
1022
|
+
|| !place(fluidValues, layout.fluidValueAt)
|
|
1023
|
+
|| !place(contactMeta, layout.contactMetaAt)
|
|
1024
|
+
|| !place(reactionMeta, layout.reactionMetaAt)
|
|
1025
|
+
|| !place(breakMeta, layout.breakMetaAt)
|
|
1026
|
+
|| !place(fluidMeta, layout.fluidMetaAt)) {
|
|
1027
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint output packet size overflows");
|
|
1028
|
+
}
|
|
1029
|
+
layout.bytes = cursor;
|
|
1030
|
+
return status(AbiStatus::Ok);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
bool packetLayoutAligned(const LatestOutputLayout& layout) noexcept {
|
|
1034
|
+
return layout.contactValueAt % alignof(double) == 0
|
|
1035
|
+
&& layout.reactionValueAt % alignof(double) == 0
|
|
1036
|
+
&& layout.fluidValueAt % alignof(double) == 0
|
|
1037
|
+
&& layout.contactMetaAt % alignof(std::uint32_t) == 0
|
|
1038
|
+
&& layout.reactionMetaAt % alignof(std::uint32_t) == 0
|
|
1039
|
+
&& layout.breakMetaAt % alignof(std::uint32_t) == 0
|
|
1040
|
+
&& layout.fluidMetaAt % alignof(std::uint32_t) == 0;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
const double* checkpointBody(
|
|
1044
|
+
const CheckpointBodyTable& table,
|
|
1045
|
+
std::uint32_t index,
|
|
1046
|
+
std::uint32_t stride) noexcept {
|
|
1047
|
+
if (stride == 0 || table.tileValues == 0) return nullptr;
|
|
1048
|
+
const std::uint64_t valueIndex = static_cast<std::uint64_t>(index) * stride;
|
|
1049
|
+
if (valueIndex > table.valueCount || table.valueCount - valueIndex < stride) return nullptr;
|
|
1050
|
+
const std::uint64_t tileValues = table.tileValues;
|
|
1051
|
+
const std::uint64_t tileIndex = valueIndex / tileValues;
|
|
1052
|
+
const std::uint64_t tileOffset = valueIndex % tileValues;
|
|
1053
|
+
if (tileIndex >= table.tiles.size() || !table.tiles[static_cast<std::size_t>(tileIndex)]) return nullptr;
|
|
1054
|
+
const BodyTile& tile = *table.tiles[static_cast<std::size_t>(tileIndex)];
|
|
1055
|
+
if (tileOffset > tile.logicalCount || tile.logicalCount - tileOffset < stride) return nullptr;
|
|
1056
|
+
const double* data = bodyTileDoubles(tile);
|
|
1057
|
+
if (data == nullptr) return nullptr;
|
|
1058
|
+
return data + static_cast<std::size_t>(tileOffset);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
std::int32_t projectCheckpointMotion(
|
|
1062
|
+
const CheckpointData& data,
|
|
1063
|
+
const ViewFacts& facts,
|
|
1064
|
+
double* pose,
|
|
1065
|
+
double* velocity,
|
|
1066
|
+
std::uint32_t* ids,
|
|
1067
|
+
std::uint8_t* statusBytes,
|
|
1068
|
+
std::uint32_t* header) {
|
|
1069
|
+
const auto bodyIds = data.topologyBodyIds();
|
|
1070
|
+
if (facts.bodyCount > 0) {
|
|
1071
|
+
if (!data.bodies || bodyIds.size() != facts.bodyCount || pose == nullptr
|
|
1072
|
+
|| velocity == nullptr || ids == nullptr || statusBytes == nullptr) {
|
|
1073
|
+
return fail(AbiStatus::InternalFailure, "checkpoint body table changed");
|
|
1074
|
+
}
|
|
1075
|
+
const CheckpointBodyTable& table = *data.bodies;
|
|
1076
|
+
for (std::uint32_t index = 0; index < facts.bodyCount; ++index) {
|
|
1077
|
+
const double* body = checkpointBody(table, index, facts.stride);
|
|
1078
|
+
if (body == nullptr) {
|
|
1079
|
+
return fail(AbiStatus::InternalFailure, "checkpoint body record is outside the table");
|
|
1080
|
+
}
|
|
1081
|
+
double scratch = body[0];
|
|
1082
|
+
scratch += body[1];
|
|
1083
|
+
scratch += body[2];
|
|
1084
|
+
scratch += body[3];
|
|
1085
|
+
scratch += body[4];
|
|
1086
|
+
scratch += body[5];
|
|
1087
|
+
scratch += body[9];
|
|
1088
|
+
scratch += body[19];
|
|
1089
|
+
scratch += body[20];
|
|
1090
|
+
scratch += body[21];
|
|
1091
|
+
scratch += body[22];
|
|
1092
|
+
scratch += body[23];
|
|
1093
|
+
scratch += body[24];
|
|
1094
|
+
scratch += body[25];
|
|
1095
|
+
volatile double sink = scratch;
|
|
1096
|
+
(void)sink;
|
|
1097
|
+
(void)bodyIds[index].value;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
header[0] = facts.bodyCount;
|
|
1101
|
+
header[1] = kMotionStatusVersion;
|
|
1102
|
+
splitU64(facts.frame, header + 2);
|
|
1103
|
+
header[4] = 0;
|
|
1104
|
+
header[5] = 0;
|
|
1105
|
+
for (std::uint32_t index = 0; index < facts.bodyCount; ++index) {
|
|
1106
|
+
const double* body = checkpointBody(*data.bodies, index, facts.stride);
|
|
1107
|
+
double* poseRow = pose + static_cast<std::size_t>(index) * kMotionPoseStride;
|
|
1108
|
+
poseRow[0] = body[0];
|
|
1109
|
+
poseRow[1] = body[1];
|
|
1110
|
+
poseRow[2] = body[2];
|
|
1111
|
+
poseRow[3] = body[22];
|
|
1112
|
+
poseRow[4] = body[23];
|
|
1113
|
+
poseRow[5] = body[24];
|
|
1114
|
+
poseRow[6] = body[25];
|
|
1115
|
+
double* velocityRow = velocity + static_cast<std::size_t>(index) * kMotionVelocityStride;
|
|
1116
|
+
velocityRow[0] = body[3];
|
|
1117
|
+
velocityRow[1] = body[4];
|
|
1118
|
+
velocityRow[2] = body[5];
|
|
1119
|
+
velocityRow[3] = body[19];
|
|
1120
|
+
velocityRow[4] = body[20];
|
|
1121
|
+
velocityRow[5] = body[21];
|
|
1122
|
+
splitU64(bodyIds[index].value, ids + static_cast<std::size_t>(index) * 2);
|
|
1123
|
+
statusBytes[index] = static_cast<std::uint8_t>(static_cast<std::uint32_t>(body[9]));
|
|
1124
|
+
}
|
|
1125
|
+
return status(AbiStatus::Ok);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
void storePacketU32(std::uint8_t* base, std::uint64_t offset, std::uint32_t value) {
|
|
1129
|
+
std::memcpy(base + static_cast<std::size_t>(offset), &value, sizeof(value));
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
void storePacketF64(std::uint8_t* base, std::uint64_t offset, double value) {
|
|
1133
|
+
std::memcpy(base + static_cast<std::size_t>(offset), &value, sizeof(value));
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
void storePacketId(std::uint8_t* base, std::uint64_t offset, std::uint64_t value) {
|
|
1137
|
+
storePacketU32(base, offset, static_cast<std::uint32_t>(value));
|
|
1138
|
+
storePacketU32(base, offset + sizeof(std::uint32_t), static_cast<std::uint32_t>(value >> 32));
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
std::int32_t writeCheckpointPacket(
|
|
1142
|
+
const CheckpointData& data,
|
|
1143
|
+
const ViewFacts& facts,
|
|
1144
|
+
std::uint8_t* packet) {
|
|
1145
|
+
LatestOutputLayout layout;
|
|
1146
|
+
if (const auto err = layoutLatestOutput(facts, layout)) return err;
|
|
1147
|
+
if (layout.bytes == 0) return status(AbiStatus::Ok);
|
|
1148
|
+
if (packet == nullptr || !packetLayoutAligned(layout)
|
|
1149
|
+
|| layout.bytes > std::numeric_limits<std::size_t>::max()) {
|
|
1150
|
+
return fail(AbiStatus::InternalFailure, "checkpoint output packet alignment failed");
|
|
1151
|
+
}
|
|
1152
|
+
const auto contacts = data.contactEvents();
|
|
1153
|
+
const auto reactions = data.jointReactions();
|
|
1154
|
+
const auto breaks = data.jointBreakEvents();
|
|
1155
|
+
const auto fluids = data.fluidInteractions();
|
|
1156
|
+
if (contacts.size() != facts.contactCount
|
|
1157
|
+
|| reactions.size() != facts.reactionCount
|
|
1158
|
+
|| breaks.size() != facts.breakCount
|
|
1159
|
+
|| fluids.size() != facts.fluidCount) {
|
|
1160
|
+
return fail(AbiStatus::InternalFailure, "checkpoint output count changed");
|
|
1161
|
+
}
|
|
1162
|
+
for (std::uint32_t index = 0; index < facts.contactCount; ++index) {
|
|
1163
|
+
const WorldContactEvent& event = contacts[index];
|
|
1164
|
+
const std::uint64_t valueAt = layout.contactValueAt
|
|
1165
|
+
+ static_cast<std::uint64_t>(index) * kWorldContactOutputValueStride * sizeof(double);
|
|
1166
|
+
storePacketF64(packet, valueAt, event.normalImpulse);
|
|
1167
|
+
storePacketF64(packet, valueAt + 8, event.tangentImpulse1);
|
|
1168
|
+
storePacketF64(packet, valueAt + 16, event.tangentImpulse2);
|
|
1169
|
+
storePacketF64(packet, valueAt + 24, event.point[0]);
|
|
1170
|
+
storePacketF64(packet, valueAt + 32, event.point[1]);
|
|
1171
|
+
storePacketF64(packet, valueAt + 40, event.point[2]);
|
|
1172
|
+
storePacketF64(packet, valueAt + 48, event.normal[0]);
|
|
1173
|
+
storePacketF64(packet, valueAt + 56, event.normal[1]);
|
|
1174
|
+
storePacketF64(packet, valueAt + 64, event.normal[2]);
|
|
1175
|
+
storePacketF64(packet, valueAt + 72, event.penetration);
|
|
1176
|
+
storePacketF64(packet, valueAt + 80, event.closingSpeed);
|
|
1177
|
+
const std::uint64_t metaAt = layout.contactMetaAt
|
|
1178
|
+
+ static_cast<std::uint64_t>(index) * kWorldContactOutputMetadataStride * sizeof(std::uint32_t);
|
|
1179
|
+
storePacketU32(packet, metaAt, static_cast<std::uint32_t>(event.type));
|
|
1180
|
+
storePacketId(packet, metaAt + 4, event.bodyA.value);
|
|
1181
|
+
storePacketId(packet, metaAt + 12, event.bodyB.value);
|
|
1182
|
+
storePacketU32(packet, metaAt + 20, (event.trigger ? 1u : 0u) | (event.sensor ? 2u : 0u));
|
|
1183
|
+
}
|
|
1184
|
+
for (std::uint32_t index = 0; index < facts.reactionCount; ++index) {
|
|
1185
|
+
const WorldJointReaction& reaction = reactions[index];
|
|
1186
|
+
const std::uint64_t valueAt = layout.reactionValueAt
|
|
1187
|
+
+ static_cast<std::uint64_t>(index) * kWorldJointReactionValueStride * sizeof(double);
|
|
1188
|
+
for (std::uint32_t axis = 0; axis < 3; ++axis) {
|
|
1189
|
+
storePacketF64(packet, valueAt + static_cast<std::uint64_t>(axis) * 8, reaction.force[axis]);
|
|
1190
|
+
storePacketF64(packet, valueAt + 24 + static_cast<std::uint64_t>(axis) * 8, reaction.torque[axis]);
|
|
1191
|
+
}
|
|
1192
|
+
const std::uint64_t metaAt = layout.reactionMetaAt
|
|
1193
|
+
+ static_cast<std::uint64_t>(index) * kWorldJointReactionMetadataStride * sizeof(std::uint32_t);
|
|
1194
|
+
storePacketId(packet, metaAt, reaction.joint.value);
|
|
1195
|
+
storePacketId(packet, metaAt + 8, reaction.bodyA.value);
|
|
1196
|
+
storePacketId(packet, metaAt + 16, reaction.bodyB.value);
|
|
1197
|
+
}
|
|
1198
|
+
for (std::uint32_t index = 0; index < facts.breakCount; ++index) {
|
|
1199
|
+
const std::uint64_t metaAt = layout.breakMetaAt
|
|
1200
|
+
+ static_cast<std::uint64_t>(index) * kWorldJointBreakMetadataStride * sizeof(std::uint32_t);
|
|
1201
|
+
storePacketId(packet, metaAt, breaks[index].joint.value);
|
|
1202
|
+
storePacketU32(packet, metaAt + 8, breaks[index].reasonBits);
|
|
1203
|
+
}
|
|
1204
|
+
for (std::uint32_t index = 0; index < facts.fluidCount; ++index) {
|
|
1205
|
+
const WorldFluidInteraction& interaction = fluids[index];
|
|
1206
|
+
const std::uint64_t valueAt = layout.fluidValueAt
|
|
1207
|
+
+ static_cast<std::uint64_t>(index) * kWorldFluidInteractionValueStride * sizeof(double);
|
|
1208
|
+
storePacketF64(packet, valueAt, interaction.submergedVolume);
|
|
1209
|
+
for (std::uint32_t axis = 0; axis < 3; ++axis) {
|
|
1210
|
+
storePacketF64(packet, valueAt + 8 + static_cast<std::uint64_t>(axis) * 8, interaction.centerOfBuoyancy[axis]);
|
|
1211
|
+
storePacketF64(packet, valueAt + 32 + static_cast<std::uint64_t>(axis) * 8, interaction.totalForce[axis]);
|
|
1212
|
+
storePacketF64(packet, valueAt + 56 + static_cast<std::uint64_t>(axis) * 8, interaction.totalTorque[axis]);
|
|
1213
|
+
storePacketF64(packet, valueAt + 80 + static_cast<std::uint64_t>(axis) * 8, interaction.relativeVelocity[axis]);
|
|
1214
|
+
}
|
|
1215
|
+
const std::uint64_t metaAt = layout.fluidMetaAt
|
|
1216
|
+
+ static_cast<std::uint64_t>(index) * kWorldFluidInteractionMetadataStride * sizeof(std::uint32_t);
|
|
1217
|
+
storePacketId(packet, metaAt, interaction.body.value);
|
|
1218
|
+
storePacketId(packet, metaAt + 8, interaction.fluid.value);
|
|
1219
|
+
storePacketU32(packet, metaAt + 16, interaction.shouldWake ? 1u : 0u);
|
|
1220
|
+
}
|
|
1221
|
+
return status(AbiStatus::Ok);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
std::int32_t publishCheckpointViewInfo(
|
|
1225
|
+
std::uint32_t handle,
|
|
1226
|
+
const SelectedCredential& credential,
|
|
1227
|
+
std::uint32_t* output,
|
|
1228
|
+
std::uint32_t output_words) {
|
|
1229
|
+
if (output_words > 0 && output == nullptr) {
|
|
1230
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint view buffer pointer is null");
|
|
1231
|
+
}
|
|
1232
|
+
if (!addressBytesFit(output_words, sizeof(std::uint32_t))) {
|
|
1233
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint view info length exceeds the address space");
|
|
1234
|
+
}
|
|
1235
|
+
bool rangeOverflow = false;
|
|
1236
|
+
const CallerRange ranges[] = {
|
|
1237
|
+
countedCallerRange(output, output_words, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
1238
|
+
};
|
|
1239
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
1240
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1241
|
+
Pins3D pins;
|
|
1242
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1243
|
+
auto outputView = pins.view<std::uint32_t>(0);
|
|
1244
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1245
|
+
std::shared_ptr<const CheckpointData> pinned;
|
|
1246
|
+
ViewFacts facts;
|
|
1247
|
+
const std::int32_t loaded = loadSelectedCheckpoint(
|
|
1248
|
+
handle, credential, pinned, facts, [&](const ViewFacts&) {
|
|
1249
|
+
if (output_words < kCheckpointViewInfoWords) {
|
|
1250
|
+
return fail(AbiStatus::ShortBuffer, "checkpoint view info buffer is short");
|
|
1251
|
+
}
|
|
1252
|
+
return status(AbiStatus::Ok);
|
|
1253
|
+
});
|
|
1254
|
+
if (loaded != 0) return loaded;
|
|
1255
|
+
pauseCheckpointViewForTest();
|
|
1256
|
+
std::uint32_t* words = outputView.data();
|
|
1257
|
+
splitU64(facts.frame, words);
|
|
1258
|
+
words[2] = facts.bodyCount;
|
|
1259
|
+
words[3] = facts.contactCount;
|
|
1260
|
+
words[4] = facts.reactionCount;
|
|
1261
|
+
words[5] = facts.breakCount;
|
|
1262
|
+
words[6] = facts.fluidCount;
|
|
1263
|
+
return status(AbiStatus::Ok);
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
std::int32_t publishCheckpointMotion(
|
|
1267
|
+
std::uint32_t handle,
|
|
1268
|
+
const SelectedCredential& credential,
|
|
1269
|
+
double* pose,
|
|
1270
|
+
std::uint32_t pose_values,
|
|
1271
|
+
double* velocity,
|
|
1272
|
+
std::uint32_t velocity_values,
|
|
1273
|
+
std::uint32_t* ids,
|
|
1274
|
+
std::uint32_t id_words,
|
|
1275
|
+
std::uint8_t* status_bytes,
|
|
1276
|
+
std::uint32_t status_count,
|
|
1277
|
+
std::uint32_t* output_header,
|
|
1278
|
+
std::uint32_t header_words) {
|
|
1279
|
+
if (output_header == nullptr || header_words != kMotionHeaderWords) {
|
|
1280
|
+
return fail(AbiStatus::InvalidArgument, "motion header must contain 6 words");
|
|
1281
|
+
}
|
|
1282
|
+
if (pose_values > kMotionPoseValueLimit || velocity_values > kMotionVelocityValueLimit
|
|
1283
|
+
|| id_words > kMotionIdWordLimit || status_count > kMotionStatusByteLimit) {
|
|
1284
|
+
return fail(AbiStatus::InvalidArgument, "motion capacity exceeds the native limit");
|
|
1285
|
+
}
|
|
1286
|
+
if (!addressBytesFit(pose_values, sizeof(double))
|
|
1287
|
+
|| !addressBytesFit(velocity_values, sizeof(double))
|
|
1288
|
+
|| !addressBytesFit(id_words, sizeof(std::uint32_t))
|
|
1289
|
+
|| !addressBytesFit(status_count, sizeof(std::uint8_t))
|
|
1290
|
+
|| !addressBytesFit(header_words, sizeof(std::uint32_t))) {
|
|
1291
|
+
return fail(AbiStatus::InvalidArgument, "motion capacity exceeds the address space");
|
|
1292
|
+
}
|
|
1293
|
+
if ((pose_values > 0 && pose == nullptr) || (velocity_values > 0 && velocity == nullptr)
|
|
1294
|
+
|| (id_words > 0 && ids == nullptr) || (status_count > 0 && status_bytes == nullptr)) {
|
|
1295
|
+
return fail(AbiStatus::InvalidArgument, "motion buffer pointer is null");
|
|
1296
|
+
}
|
|
1297
|
+
bool rangeOverflow = false;
|
|
1298
|
+
const CallerRange ranges[] = {
|
|
1299
|
+
countedCallerRange(pose, pose_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
1300
|
+
countedCallerRange(velocity, velocity_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
1301
|
+
countedCallerRange(ids, id_words, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
1302
|
+
{status_bytes, static_cast<std::size_t>(status_count), alignof(std::uint8_t), RangeRole::Output},
|
|
1303
|
+
countedCallerRange(output_header, header_words, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
1304
|
+
};
|
|
1305
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
1306
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1307
|
+
Pins3D pins;
|
|
1308
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1309
|
+
auto poseView = pins.view<double>(0);
|
|
1310
|
+
auto velocityView = pins.view<double>(1);
|
|
1311
|
+
auto idView = pins.view<std::uint32_t>(2);
|
|
1312
|
+
auto statusView = pins.view<std::uint8_t>(3);
|
|
1313
|
+
auto headerView = pins.view<std::uint32_t>(4);
|
|
1314
|
+
if (!headerView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1315
|
+
std::shared_ptr<const CheckpointData> pinned;
|
|
1316
|
+
ViewFacts facts;
|
|
1317
|
+
const std::int32_t loaded = loadSelectedCheckpoint(
|
|
1318
|
+
handle, credential, pinned, facts, [&](const ViewFacts& local) {
|
|
1319
|
+
const std::uint64_t poseNeed = static_cast<std::uint64_t>(local.bodyCount) * kMotionPoseStride;
|
|
1320
|
+
const std::uint64_t velocityNeed = static_cast<std::uint64_t>(local.bodyCount) * kMotionVelocityStride;
|
|
1321
|
+
const std::uint64_t idNeed = static_cast<std::uint64_t>(local.bodyCount) * 2u;
|
|
1322
|
+
if (poseNeed > pose_values || velocityNeed > velocity_values
|
|
1323
|
+
|| idNeed > id_words || local.bodyCount > status_count) {
|
|
1324
|
+
return fail(AbiStatus::ShortBuffer, "motion buffer is short");
|
|
1325
|
+
}
|
|
1326
|
+
if (local.bodyCount > 0 && (!poseView || !velocityView || !idView || !statusView)) {
|
|
1327
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1328
|
+
}
|
|
1329
|
+
return status(AbiStatus::Ok);
|
|
1330
|
+
});
|
|
1331
|
+
if (loaded != 0) return loaded;
|
|
1332
|
+
pauseCheckpointViewForTest();
|
|
1333
|
+
return projectCheckpointMotion(
|
|
1334
|
+
*pinned, facts, poseView.data(), velocityView.data(), idView.data(),
|
|
1335
|
+
statusView.data(), headerView.data());
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
std::int32_t publishCheckpointPacket(
|
|
1339
|
+
std::uint32_t handle,
|
|
1340
|
+
const SelectedCredential& credential,
|
|
1341
|
+
std::uint8_t* packet,
|
|
1342
|
+
std::uint32_t packet_bytes) {
|
|
1343
|
+
if (packet_bytes > 0 && packet == nullptr) {
|
|
1344
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint view buffer pointer is null");
|
|
1345
|
+
}
|
|
1346
|
+
if (!addressBytesFit(packet_bytes, sizeof(std::uint8_t))) {
|
|
1347
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint output packet length exceeds the address space");
|
|
1348
|
+
}
|
|
1349
|
+
const CallerRange ranges[] = {
|
|
1350
|
+
{packet, static_cast<std::size_t>(packet_bytes), alignof(double), RangeRole::Output},
|
|
1351
|
+
};
|
|
1352
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1353
|
+
Pins3D pins;
|
|
1354
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1355
|
+
auto packetView = pins.view<std::uint8_t>(0);
|
|
1356
|
+
if (!packetView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1357
|
+
std::shared_ptr<const CheckpointData> pinned;
|
|
1358
|
+
ViewFacts facts;
|
|
1359
|
+
const std::int32_t loaded = loadSelectedCheckpoint(
|
|
1360
|
+
handle, credential, pinned, facts, [&](const ViewFacts& local) {
|
|
1361
|
+
LatestOutputLayout layout;
|
|
1362
|
+
if (const auto err = layoutLatestOutput(local, layout)) return err;
|
|
1363
|
+
if (layout.bytes > std::numeric_limits<std::uint32_t>::max()
|
|
1364
|
+
|| layout.bytes > std::numeric_limits<std::size_t>::max()) {
|
|
1365
|
+
return fail(AbiStatus::InvalidArgument, "checkpoint output packet exceeds the output word");
|
|
1366
|
+
}
|
|
1367
|
+
if (layout.bytes > packet_bytes) {
|
|
1368
|
+
return fail(AbiStatus::ShortBuffer, "checkpoint output packet is short");
|
|
1369
|
+
}
|
|
1370
|
+
return status(AbiStatus::Ok);
|
|
1371
|
+
});
|
|
1372
|
+
if (loaded != 0) return loaded;
|
|
1373
|
+
pauseCheckpointViewForTest();
|
|
1374
|
+
return writeCheckpointPacket(*pinned, facts, packet_bytes == 0 ? nullptr : packetView.data());
|
|
1375
|
+
}
|
|
1376
|
+
|
|
509
1377
|
} // namespace
|
|
510
1378
|
|
|
511
1379
|
extern "C" std::uint32_t rundot_kinetix_world_abi_version() {
|
|
512
1380
|
return kWorldAbiVersion;
|
|
513
1381
|
}
|
|
514
1382
|
|
|
1383
|
+
extern "C" std::uint32_t rundot_kinetix_world_max_support_records() {
|
|
1384
|
+
return rundot::kinetix::physics::kWorldMaxSupportRecords;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
515
1387
|
extern "C" std::uint32_t rundot_kinetix_world_max_handles() {
|
|
516
1388
|
return kMaxHandles;
|
|
517
1389
|
}
|
|
@@ -520,6 +1392,14 @@ extern "C" std::uint32_t rundot_kinetix_world_topology_abi_version() {
|
|
|
520
1392
|
return rundot::kinetix::physics::kWorldTopologyAbiVersion;
|
|
521
1393
|
}
|
|
522
1394
|
|
|
1395
|
+
extern "C" std::uint32_t rundot_kinetix_world_topology_geometry_abi_version() {
|
|
1396
|
+
return rundot::kinetix::physics::kWorldTopologyGeometryAbiVersion;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
extern "C" std::uint32_t rundot_kinetix_world_topology_geometry_command_stride() {
|
|
1400
|
+
return rundot::kinetix::physics::kWorldTopologyGeometryCommandStride;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
523
1403
|
extern "C" std::uint32_t rundot_kinetix_world_topology_max_commands() {
|
|
524
1404
|
return rundot::kinetix::physics::kWorldMaxTopologyCommands;
|
|
525
1405
|
}
|
|
@@ -544,53 +1424,153 @@ extern "C" std::uint32_t rundot_kinetix_world_topology_joint_identity_stride() {
|
|
|
544
1424
|
return rundot::kinetix::physics::kWorldTopologyJointIdentityStride;
|
|
545
1425
|
}
|
|
546
1426
|
|
|
1427
|
+
extern "C" std::uint32_t rundot_kinetix_world_topology_fluid_id_stride() {
|
|
1428
|
+
return rundot::kinetix::physics::kWorldTopologyFluidIdStride;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
547
1431
|
extern "C" std::uint32_t rundot_kinetix_world_joint_warm_state_stride() {
|
|
548
1432
|
return rundot::kinetix::physics::kJointWarmStateStride;
|
|
549
1433
|
}
|
|
550
1434
|
|
|
551
1435
|
extern "C" std::uintptr_t rundot_kinetix_world_buffer_allocate(std::uint32_t byte_count) noexcept {
|
|
552
1436
|
if (byte_count == 0) return 0;
|
|
553
|
-
return reinterpret_cast<std::uintptr_t>(
|
|
1437
|
+
return reinterpret_cast<std::uintptr_t>(ScratchLeases3D::instance().acquire(byte_count));
|
|
554
1438
|
}
|
|
555
1439
|
|
|
556
|
-
extern "C"
|
|
557
|
-
|
|
1440
|
+
extern "C" std::int32_t rundot_kinetix_world_buffer_free(std::uintptr_t pointer) noexcept {
|
|
1441
|
+
const auto status = ScratchLeases3D::instance().release(reinterpret_cast<void*>(pointer));
|
|
1442
|
+
switch (status) {
|
|
1443
|
+
case rundot::kinetix::memory::LeaseStatus::Ok:
|
|
1444
|
+
return 0;
|
|
1445
|
+
case rundot::kinetix::memory::LeaseStatus::Busy:
|
|
1446
|
+
return fail(AbiStatus::BufferBusy, "buffer lease is pinned");
|
|
1447
|
+
case rundot::kinetix::memory::LeaseStatus::UnknownLease:
|
|
1448
|
+
default:
|
|
1449
|
+
return fail(AbiStatus::BufferRejected, "buffer lease is unknown or not a base pointer");
|
|
1450
|
+
}
|
|
558
1451
|
}
|
|
559
1452
|
|
|
560
|
-
extern "C" std::int32_t
|
|
1453
|
+
extern "C" std::int32_t rundot_kinetix_world_create_with_checkpoint_capacity(
|
|
561
1454
|
std::uint32_t abi_version,
|
|
562
1455
|
std::uint32_t numeric_profile,
|
|
563
1456
|
const std::uint8_t* profile_id,
|
|
564
1457
|
std::uint32_t profile_id_bytes,
|
|
565
1458
|
const std::uint8_t* geometry_digest,
|
|
566
1459
|
std::uint32_t geometry_digest_bytes,
|
|
1460
|
+
std::uint32_t body_capacity,
|
|
1461
|
+
std::uint32_t joint_capacity,
|
|
1462
|
+
std::uint32_t fluid_capacity,
|
|
1463
|
+
std::uint32_t fluid_interaction_capacity,
|
|
1464
|
+
std::uint32_t checkpoint_capacity,
|
|
567
1465
|
std::uint32_t* output_handle) noexcept {
|
|
568
1466
|
return guard([&]() {
|
|
569
|
-
std::lock_guard<std::mutex> lock(slotsMutex);
|
|
570
1467
|
clearError();
|
|
571
|
-
|
|
1468
|
+
const CallerRange ranges[] = {
|
|
1469
|
+
{profile_id, profile_id_bytes * sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input},
|
|
1470
|
+
{geometry_digest, geometry_digest_bytes * sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input},
|
|
1471
|
+
{output_handle, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
1472
|
+
};
|
|
1473
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1474
|
+
Pins3D pins;
|
|
1475
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1476
|
+
auto profileIdView = pins.view<const std::uint8_t>(0);
|
|
1477
|
+
auto geometryDigestView = pins.view<const std::uint8_t>(1);
|
|
1478
|
+
auto handleView = pins.view<std::uint32_t>(2);
|
|
1479
|
+
if (!profileIdView || !geometryDigestView || !handleView) {
|
|
1480
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
if (numeric_profile == 0
|
|
1484
|
+
|| profile_id_bytes == 0
|
|
572
1485
|
|| profile_id_bytes > rundot::kinetix::physics::kWorldMaxProfileIdBytes
|
|
573
|
-
||
|
|
574
|
-
|
|
1486
|
+
|| geometry_digest_bytes != 32
|
|
1487
|
+
|| body_capacity == 0
|
|
1488
|
+
|| body_capacity > rundot::kinetix::physics::kWorldMaxBodies
|
|
1489
|
+
|| joint_capacity > rundot::kinetix::physics::kWorldMaxJoints
|
|
1490
|
+
|| fluid_capacity > rundot::kinetix::physics::kWorldMaxFluids
|
|
1491
|
+
|| static_cast<std::uint64_t>(fluid_interaction_capacity)
|
|
1492
|
+
> static_cast<std::uint64_t>(body_capacity) * fluid_capacity
|
|
1493
|
+
|| checkpoint_capacity < 1
|
|
1494
|
+
|| checkpoint_capacity > kMaxCheckpointsPerWorld) {
|
|
1495
|
+
return fail(AbiStatus::InvalidArgument, "world profile arguments or checkpoint capacity are invalid");
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
std::uint32_t freeSlotIndex = kMaxHandles;
|
|
1499
|
+
{
|
|
1500
|
+
std::lock_guard<std::mutex> lock(slotsMutex);
|
|
1501
|
+
for (std::uint32_t index = 0; index < slots.size(); index += 1) {
|
|
1502
|
+
if (!slots[index].control && !slots[index].retired) {
|
|
1503
|
+
freeSlotIndex = index;
|
|
1504
|
+
break;
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
if (freeSlotIndex >= slots.size()) {
|
|
1509
|
+
return fail(AbiStatus::HandleCapacity, "world handle capacity is exhausted");
|
|
575
1510
|
}
|
|
1511
|
+
|
|
576
1512
|
WorldProfile profile;
|
|
577
1513
|
profile.abiVersion = abi_version;
|
|
578
1514
|
profile.numericProfile = numeric_profile;
|
|
579
|
-
profile.id.assign(reinterpret_cast<const char*>(
|
|
580
|
-
std::copy_n(
|
|
581
|
-
|
|
1515
|
+
profile.id.assign(reinterpret_cast<const char*>(profileIdView.data()), profile_id_bytes);
|
|
1516
|
+
std::copy_n(geometryDigestView.data(), profile.geometryDigest.size(), profile.geometryDigest.begin());
|
|
1517
|
+
WorldLimits limits;
|
|
1518
|
+
limits.maxBodies = body_capacity;
|
|
1519
|
+
limits.maxJoints = joint_capacity;
|
|
1520
|
+
limits.maxFluids = fluid_capacity;
|
|
1521
|
+
limits.maxFluidInteractions = fluid_interaction_capacity;
|
|
1522
|
+
limits.maxForceValues = static_cast<std::uint64_t>(body_capacity)
|
|
1523
|
+
* rundot::kinetix::physics::kForceStride;
|
|
1524
|
+
|
|
1525
|
+
auto candidate = std::allocate_shared<Slot::Control>(
|
|
1526
|
+
rundot::kinetix::physics::geometry_private::ControlAllocator<Slot::Control>{},
|
|
1527
|
+
std::move(profile), limits, checkpoint_capacity);
|
|
582
1528
|
const WorldError validation = candidate->world.validate();
|
|
583
1529
|
if (!validation.ok()) return fail(validation);
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
1530
|
+
|
|
1531
|
+
std::uint32_t assignedHandle = 0;
|
|
1532
|
+
{
|
|
1533
|
+
std::lock_guard<std::mutex> lock(slotsMutex);
|
|
1534
|
+
std::uint32_t targetIndex = freeSlotIndex;
|
|
1535
|
+
if (slots[targetIndex].control || slots[targetIndex].retired) {
|
|
1536
|
+
targetIndex = kMaxHandles;
|
|
1537
|
+
for (std::uint32_t index = 0; index < slots.size(); index += 1) {
|
|
1538
|
+
if (!slots[index].control && !slots[index].retired) {
|
|
1539
|
+
targetIndex = index;
|
|
1540
|
+
break;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
if (targetIndex >= slots.size()) {
|
|
1545
|
+
return fail(AbiStatus::HandleCapacity, "world handle capacity is exhausted");
|
|
1546
|
+
}
|
|
1547
|
+
slots[targetIndex].control = std::move(candidate);
|
|
1548
|
+
assignedHandle = makeHandle(targetIndex, slots[targetIndex].generation);
|
|
589
1549
|
}
|
|
590
|
-
|
|
1550
|
+
*handleView.data() = assignedHandle;
|
|
1551
|
+
return status(AbiStatus::Ok);
|
|
591
1552
|
});
|
|
592
1553
|
}
|
|
593
1554
|
|
|
1555
|
+
extern "C" std::int32_t rundot_kinetix_world_create(
|
|
1556
|
+
std::uint32_t abi_version,
|
|
1557
|
+
std::uint32_t numeric_profile,
|
|
1558
|
+
const std::uint8_t* profile_id,
|
|
1559
|
+
std::uint32_t profile_id_bytes,
|
|
1560
|
+
const std::uint8_t* geometry_digest,
|
|
1561
|
+
std::uint32_t geometry_digest_bytes,
|
|
1562
|
+
std::uint32_t body_capacity,
|
|
1563
|
+
std::uint32_t joint_capacity,
|
|
1564
|
+
std::uint32_t fluid_capacity,
|
|
1565
|
+
std::uint32_t fluid_interaction_capacity,
|
|
1566
|
+
std::uint32_t* output_handle) noexcept {
|
|
1567
|
+
return rundot_kinetix_world_create_with_checkpoint_capacity(
|
|
1568
|
+
abi_version, numeric_profile, profile_id, profile_id_bytes,
|
|
1569
|
+
geometry_digest, geometry_digest_bytes, body_capacity,
|
|
1570
|
+
joint_capacity, fluid_capacity, fluid_interaction_capacity,
|
|
1571
|
+
kDefaultCheckpointsPerWorld, output_handle);
|
|
1572
|
+
}
|
|
1573
|
+
|
|
594
1574
|
extern "C" std::int32_t rundot_kinetix_world_destroy(std::uint32_t handle) noexcept {
|
|
595
1575
|
return guard([&]() {
|
|
596
1576
|
clearError();
|
|
@@ -607,12 +1587,22 @@ extern "C" std::int32_t rundot_kinetix_world_destroy(std::uint32_t handle) noexc
|
|
|
607
1587
|
return fail(AbiStatus::StaleHandle, "world handle is stale");
|
|
608
1588
|
}
|
|
609
1589
|
if (!slot.control) return fail(AbiStatus::InvalidHandle, "world handle is not active");
|
|
610
|
-
control =
|
|
1590
|
+
control = slot.control;
|
|
1591
|
+
// Keep this order: withControl releases slotsMutex before it locks Control::mutex.
|
|
1592
|
+
std::lock_guard<std::mutex> worldLock(control->mutex);
|
|
1593
|
+
if (control->retired) return fail(AbiStatus::StaleHandle, "world handle is stale");
|
|
1594
|
+
const bool attached = control->world.isAttached();
|
|
1595
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
1596
|
+
recordDestroyAttachmentForTest(attached);
|
|
1597
|
+
#endif
|
|
1598
|
+
if (attached) {
|
|
1599
|
+
return fail(AbiStatus::WorldAttached, "cannot destroy attached world");
|
|
1600
|
+
}
|
|
1601
|
+
control->retired = true;
|
|
1602
|
+
slot.control.reset();
|
|
611
1603
|
if (slot.generation == kMaxGeneration) slot.retired = true;
|
|
612
1604
|
else slot.generation += 1;
|
|
613
1605
|
}
|
|
614
|
-
std::lock_guard<std::mutex> worldLock(control->mutex);
|
|
615
|
-
control->retired = true;
|
|
616
1606
|
return status(AbiStatus::Ok);
|
|
617
1607
|
});
|
|
618
1608
|
}
|
|
@@ -622,18 +1612,106 @@ extern "C" std::int32_t rundot_kinetix_world_digest(
|
|
|
622
1612
|
std::uint64_t* output) noexcept {
|
|
623
1613
|
return guard([&]() {
|
|
624
1614
|
clearError();
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
1615
|
+
const CallerRange ranges[] = {
|
|
1616
|
+
{output, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output},
|
|
1617
|
+
};
|
|
1618
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1619
|
+
Pins3D pins;
|
|
1620
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1621
|
+
auto outputView = pins.view<std::uint64_t>(0);
|
|
1622
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
628
1623
|
return withWorld(handle, [&](World& world) {
|
|
629
|
-
*
|
|
1624
|
+
*outputView.data() = world.digest();
|
|
630
1625
|
return status(AbiStatus::Ok);
|
|
631
1626
|
});
|
|
632
1627
|
});
|
|
633
1628
|
}
|
|
634
1629
|
|
|
635
|
-
extern "C" std::int32_t
|
|
636
|
-
std::uint32_t handle,
|
|
1630
|
+
extern "C" std::int32_t rundot_kinetix_world_frame(
|
|
1631
|
+
std::uint32_t handle, std::uint64_t* output) noexcept {
|
|
1632
|
+
return guard([&]() {
|
|
1633
|
+
clearError();
|
|
1634
|
+
const CallerRange ranges[] = {
|
|
1635
|
+
{output, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output},
|
|
1636
|
+
};
|
|
1637
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1638
|
+
Pins3D pins;
|
|
1639
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1640
|
+
auto outputView = pins.view<std::uint64_t>(0);
|
|
1641
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1642
|
+
return withWorld(handle, [&](World& world) {
|
|
1643
|
+
*outputView.data() = world.frame();
|
|
1644
|
+
return status(AbiStatus::Ok);
|
|
1645
|
+
});
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
extern "C" std::int32_t rundot_kinetix_world_body_geometry_info(
|
|
1650
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1651
|
+
std::uint32_t* output, std::uint32_t output_values) noexcept {
|
|
1652
|
+
return guard([&]() {
|
|
1653
|
+
clearError();
|
|
1654
|
+
bool rangeOverflow = false;
|
|
1655
|
+
const CallerRange ranges[] = {
|
|
1656
|
+
countedCallerRange(output, output_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
1657
|
+
};
|
|
1658
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
1659
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1660
|
+
Pins3D pins;
|
|
1661
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1662
|
+
auto outputView = pins.view<std::uint32_t>(0);
|
|
1663
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1664
|
+
|
|
1665
|
+
if (output_values < rundot::kinetix::physics::kWorldBodyGeometryInfoStride) {
|
|
1666
|
+
return fail(AbiStatus::ShortBuffer, "body geometry info buffer is too small");
|
|
1667
|
+
}
|
|
1668
|
+
return withWorld(handle, [&](World& world) {
|
|
1669
|
+
using namespace rundot::kinetix::physics;
|
|
1670
|
+
WorldGeometryView geometry;
|
|
1671
|
+
const auto result = world.readGeometry(BodyId{joinU64(body_low, body_high)}, geometry);
|
|
1672
|
+
if (!result.ok()) return fail(result);
|
|
1673
|
+
outputView.data()[0] = kWorldBodyGeometryInfoVersion;
|
|
1674
|
+
outputView.data()[1] = static_cast<std::uint32_t>(geometry.descriptor.kind);
|
|
1675
|
+
outputView.data()[2] = geometry.descriptor.count;
|
|
1676
|
+
outputView.data()[3] = geometry.descriptor.format;
|
|
1677
|
+
outputView.data()[4] = geometry.descriptor.featureOffset;
|
|
1678
|
+
outputView.data()[5] = static_cast<std::uint32_t>(geometry.values.size());
|
|
1679
|
+
return status(AbiStatus::Ok);
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
extern "C" std::int32_t rundot_kinetix_world_copy_body_geometry(
|
|
1685
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1686
|
+
double* output, std::uint32_t output_capacity_values) noexcept {
|
|
1687
|
+
return guard([&]() {
|
|
1688
|
+
clearError();
|
|
1689
|
+
bool rangeOverflow = false;
|
|
1690
|
+
const CallerRange ranges[] = {
|
|
1691
|
+
countedCallerRange(output, output_capacity_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
1692
|
+
};
|
|
1693
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
1694
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1695
|
+
Pins3D pins;
|
|
1696
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1697
|
+
auto outputView = pins.view<double>(0);
|
|
1698
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1699
|
+
|
|
1700
|
+
return withWorld(handle, [&](World& world) {
|
|
1701
|
+
rundot::kinetix::physics::WorldGeometryView geometry;
|
|
1702
|
+
const auto result = world.readGeometry(BodyId{joinU64(body_low, body_high)}, geometry);
|
|
1703
|
+
if (!result.ok()) return fail(result);
|
|
1704
|
+
if (output_capacity_values < geometry.values.size()) {
|
|
1705
|
+
return fail(AbiStatus::ShortBuffer, "body geometry value buffer is too small");
|
|
1706
|
+
}
|
|
1707
|
+
std::copy(geometry.values.begin(), geometry.values.end(), outputView.data());
|
|
1708
|
+
return status(AbiStatus::Ok);
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
extern "C" std::int32_t rundot_kinetix_world_replace_state(
|
|
1714
|
+
std::uint32_t handle,
|
|
637
1715
|
std::uint32_t frame_low,
|
|
638
1716
|
std::uint32_t frame_high,
|
|
639
1717
|
const double* bodies,
|
|
@@ -649,32 +1727,68 @@ extern "C" std::int32_t rundot_kinetix_world_replace_state(
|
|
|
649
1727
|
const std::uint8_t* joint_warm_state,
|
|
650
1728
|
std::uint32_t joint_warm_state_bytes,
|
|
651
1729
|
const std::uint32_t* topology_state,
|
|
652
|
-
std::uint32_t topology_state_values
|
|
1730
|
+
std::uint32_t topology_state_values,
|
|
1731
|
+
const double* surface_velocities,
|
|
1732
|
+
std::uint32_t surface_velocity_values,
|
|
1733
|
+
const double* fluids,
|
|
1734
|
+
std::uint32_t fluid_values) noexcept {
|
|
653
1735
|
return guard([&]() {
|
|
654
1736
|
clearError();
|
|
1737
|
+
bool rangeOverflow = false;
|
|
1738
|
+
const CallerRange ranges[] = {
|
|
1739
|
+
countedCallerRange(bodies, body_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1740
|
+
countedCallerRange(joints, joint_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1741
|
+
countedCallerRange(geometry, geometry_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1742
|
+
countedCallerRange(contact_cache, contact_cache_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1743
|
+
countedCallerRange(forces, force_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1744
|
+
countedCallerRange(joint_warm_state, joint_warm_state_bytes, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input, rangeOverflow),
|
|
1745
|
+
countedCallerRange(topology_state, topology_state_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Input, rangeOverflow),
|
|
1746
|
+
countedCallerRange(surface_velocities, surface_velocity_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1747
|
+
countedCallerRange(fluids, fluid_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
1748
|
+
};
|
|
1749
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
1750
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
1751
|
+
Pins3D pins;
|
|
1752
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
1753
|
+
auto bodiesView = pins.view<const double>(0);
|
|
1754
|
+
auto jointsView = pins.view<const double>(1);
|
|
1755
|
+
auto geometryView = pins.view<const double>(2);
|
|
1756
|
+
auto contactCacheView = pins.view<const double>(3);
|
|
1757
|
+
auto forcesView = pins.view<const double>(4);
|
|
1758
|
+
auto jointWarmStateView = pins.view<const std::uint8_t>(5);
|
|
1759
|
+
auto topologyStateView = pins.view<const std::uint32_t>(6);
|
|
1760
|
+
auto surfaceVelocitiesView = pins.view<const double>(7);
|
|
1761
|
+
auto fluidsView = pins.view<const double>(8);
|
|
1762
|
+
if (!bodiesView || !jointsView || !geometryView || !contactCacheView || !forcesView
|
|
1763
|
+
|| !jointWarmStateView || !topologyStateView || !surfaceVelocitiesView || !fluidsView) {
|
|
1764
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
1765
|
+
}
|
|
1766
|
+
|
|
655
1767
|
return withWorld(handle, [&](World& world) {
|
|
656
|
-
if (!validValues(bodies, body_values) || !validValues(joints, joint_values)
|
|
657
|
-
|| !validValues(geometry, geometry_values) || !validValues(contact_cache, contact_cache_values)
|
|
658
|
-
|| !validValues(forces, force_values)) {
|
|
659
|
-
return fail(AbiStatus::InvalidArgument, "world state pointer is missing");
|
|
660
|
-
}
|
|
661
1768
|
std::uint32_t jointCount = 0;
|
|
662
|
-
if (!countJoints(
|
|
1769
|
+
if (!countJoints(jointsView.data(), joint_values, jointCount)) {
|
|
663
1770
|
return fail(AbiStatus::InvalidArgument, "joint values do not match variable joint record strides");
|
|
664
1771
|
}
|
|
665
1772
|
if (!validStateCounts(
|
|
666
1773
|
body_values, joint_values, geometry_values, contact_cache_values, force_values)
|
|
667
|
-
|| jointCount > rundot::kinetix::physics::kWorldMaxJoints
|
|
1774
|
+
|| jointCount > rundot::kinetix::physics::kWorldMaxJoints
|
|
1775
|
+
|| fluid_values % rundot::kinetix::physics::kFluidStride != 0
|
|
1776
|
+
|| fluid_values / rundot::kinetix::physics::kFluidStride
|
|
1777
|
+
> rundot::kinetix::physics::kWorldMaxFluids
|
|
1778
|
+
|| surface_velocity_values > rundot::kinetix::physics::kWorldMaxBodies
|
|
1779
|
+
* rundot::kinetix::physics::kSurfaceVelocityStride) {
|
|
668
1780
|
return fail(AbiStatus::InvalidArgument, "world state counts exceed a stride or capacity");
|
|
669
1781
|
}
|
|
670
1782
|
WorldState replacement;
|
|
671
1783
|
replacement.frame = static_cast<std::uint64_t>(frame_low)
|
|
672
1784
|
| (static_cast<std::uint64_t>(frame_high) << 32);
|
|
673
|
-
assignValues(replacement.bodies,
|
|
674
|
-
assignValues(replacement.joints,
|
|
675
|
-
assignValues(replacement.geometry,
|
|
676
|
-
assignValues(replacement.contactCache,
|
|
677
|
-
assignValues(replacement.forces,
|
|
1785
|
+
assignValues(replacement.bodies, bodiesView.data(), body_values);
|
|
1786
|
+
assignValues(replacement.joints, jointsView.data(), joint_values);
|
|
1787
|
+
assignValues(std::get<std::vector<double>>(replacement.geometry), geometryView.data(), geometry_values);
|
|
1788
|
+
assignValues(replacement.contactCache, contactCacheView.data(), contact_cache_values);
|
|
1789
|
+
assignValues(replacement.forces, forcesView.data(), force_values);
|
|
1790
|
+
assignValues(replacement.surfaceVelocities, surfaceVelocitiesView.data(), surface_velocity_values);
|
|
1791
|
+
assignValues(replacement.fluids, fluidsView.data(), fluid_values);
|
|
678
1792
|
const std::uint32_t bodyStride = (body_values % rundot::kinetix::physics::kBodyStrideWide == 0 && (body_values % rundot::kinetix::physics::kBodyStride != 0 || body_values == 0))
|
|
679
1793
|
? rundot::kinetix::physics::kBodyStrideWide
|
|
680
1794
|
: ((body_values % rundot::kinetix::physics::kBodyStride == 0) ? rundot::kinetix::physics::kBodyStride : (body_values % rundot::kinetix::physics::kBodyStrideWide == 0 ? rundot::kinetix::physics::kBodyStrideWide : rundot::kinetix::physics::kBodyStride));
|
|
@@ -683,11 +1797,12 @@ extern "C" std::int32_t rundot_kinetix_world_replace_state(
|
|
|
683
1797
|
return fail(AbiStatus::InvalidArgument,
|
|
684
1798
|
"joint warm state needs explicit topology identity");
|
|
685
1799
|
}
|
|
686
|
-
if (!parseTopologyState(
|
|
687
|
-
bodyCount, jointCount,
|
|
1800
|
+
if (!parseTopologyState(topologyStateView.data(), topology_state_values,
|
|
1801
|
+
bodyCount, jointCount, fluid_values / rundot::kinetix::physics::kFluidStride,
|
|
1802
|
+
replacement.topology)) {
|
|
688
1803
|
return fail(AbiStatus::InvalidArgument, "world topology state is malformed");
|
|
689
1804
|
}
|
|
690
|
-
if (!parseWarmStates(
|
|
1805
|
+
if (!parseWarmStates(jointWarmStateView.data(), joint_warm_state_bytes,
|
|
691
1806
|
jointCount, replacement.jointWarmState)) {
|
|
692
1807
|
return fail(AbiStatus::InvalidArgument, "joint warm state byte count is invalid");
|
|
693
1808
|
}
|
|
@@ -752,6 +1867,418 @@ extern "C" std::int32_t rundot_kinetix_world_apply_impulse(
|
|
|
752
1867
|
});
|
|
753
1868
|
}
|
|
754
1869
|
|
|
1870
|
+
extern "C" std::int32_t rundot_kinetix_world_set_body_force(
|
|
1871
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1872
|
+
double force_x, double force_y, double force_z,
|
|
1873
|
+
double torque_x, double torque_y, double torque_z) noexcept {
|
|
1874
|
+
return guard([&]() {
|
|
1875
|
+
clearError();
|
|
1876
|
+
return withWorld(handle, [&](World& world) {
|
|
1877
|
+
const WorldError result = world.setBodyForce(BodyId{joinU64(body_low, body_high)},
|
|
1878
|
+
{force_x, force_y, force_z}, {torque_x, torque_y, torque_z});
|
|
1879
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1880
|
+
});
|
|
1881
|
+
});
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
extern "C" std::int32_t rundot_kinetix_world_apply_force(
|
|
1885
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1886
|
+
double force_x, double force_y, double force_z,
|
|
1887
|
+
double torque_x, double torque_y, double torque_z) noexcept {
|
|
1888
|
+
return guard([&]() {
|
|
1889
|
+
clearError();
|
|
1890
|
+
return withWorld(handle, [&](World& world) {
|
|
1891
|
+
const WorldError result = world.applyForce(
|
|
1892
|
+
BodyId{joinU64(body_low, body_high)},
|
|
1893
|
+
{force_x, force_y, force_z}, {torque_x, torque_y, torque_z});
|
|
1894
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1895
|
+
});
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
extern "C" std::int32_t rundot_kinetix_world_apply_force_at_point(
|
|
1900
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1901
|
+
double force_x, double force_y, double force_z,
|
|
1902
|
+
double point_x, double point_y, double point_z) noexcept {
|
|
1903
|
+
return guard([&]() {
|
|
1904
|
+
clearError();
|
|
1905
|
+
return withWorld(handle, [&](World& world) {
|
|
1906
|
+
const WorldError result = world.applyForceAtPoint(
|
|
1907
|
+
BodyId{joinU64(body_low, body_high)},
|
|
1908
|
+
{force_x, force_y, force_z}, {point_x, point_y, point_z});
|
|
1909
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1910
|
+
});
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
extern "C" std::int32_t rundot_kinetix_world_clear_body_force(
|
|
1915
|
+
std::uint32_t handle, std::uint32_t body_low,
|
|
1916
|
+
std::uint32_t body_high) noexcept {
|
|
1917
|
+
return guard([&]() {
|
|
1918
|
+
clearError();
|
|
1919
|
+
return withWorld(handle, [&](World& world) {
|
|
1920
|
+
const WorldError result = world.clearBodyForce(
|
|
1921
|
+
BodyId{joinU64(body_low, body_high)});
|
|
1922
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1923
|
+
});
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
extern "C" std::int32_t rundot_kinetix_world_set_body_surface_velocity(
|
|
1928
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1929
|
+
double velocity_x, double velocity_y, double velocity_z) noexcept {
|
|
1930
|
+
return guard([&]() {
|
|
1931
|
+
clearError();
|
|
1932
|
+
return withWorld(handle, [&](World& world) {
|
|
1933
|
+
const WorldError result = world.setBodySurfaceVelocity(
|
|
1934
|
+
BodyId{joinU64(body_low, body_high)},
|
|
1935
|
+
{velocity_x, velocity_y, velocity_z});
|
|
1936
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1937
|
+
});
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
extern "C" std::int32_t rundot_kinetix_world_set_body_linear_velocity(
|
|
1942
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1943
|
+
double velocity_x, double velocity_y, double velocity_z) noexcept {
|
|
1944
|
+
return guard([&]() {
|
|
1945
|
+
clearError();
|
|
1946
|
+
return withWorld(handle, [&](World& world) {
|
|
1947
|
+
const WorldError result = world.setBodyLinearVelocity(
|
|
1948
|
+
BodyId{joinU64(body_low, body_high)},
|
|
1949
|
+
{velocity_x, velocity_y, velocity_z});
|
|
1950
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1951
|
+
});
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
extern "C" std::int32_t rundot_kinetix_world_set_body_angular_velocity(
|
|
1956
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1957
|
+
double velocity_x, double velocity_y, double velocity_z) noexcept {
|
|
1958
|
+
return guard([&]() {
|
|
1959
|
+
clearError();
|
|
1960
|
+
return withWorld(handle, [&](World& world) {
|
|
1961
|
+
const WorldError result = world.setBodyAngularVelocity(
|
|
1962
|
+
BodyId{joinU64(body_low, body_high)},
|
|
1963
|
+
{velocity_x, velocity_y, velocity_z});
|
|
1964
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1965
|
+
});
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_pose_stride() noexcept {
|
|
1970
|
+
return rundot::kinetix::physics::kMotionPoseStride;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_velocity_stride() noexcept {
|
|
1974
|
+
return rundot::kinetix::physics::kMotionVelocityStride;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_status_version() noexcept {
|
|
1978
|
+
return rundot::kinetix::physics::kMotionStatusVersion;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_pose_value_limit() noexcept {
|
|
1982
|
+
return rundot::kinetix::physics::kMotionPoseValueLimit;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_velocity_value_limit() noexcept {
|
|
1986
|
+
return rundot::kinetix::physics::kMotionVelocityValueLimit;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_id_word_limit() noexcept {
|
|
1990
|
+
return rundot::kinetix::physics::kMotionIdWordLimit;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
extern "C" std::uint32_t rundot_kinetix_world_motion_status_byte_limit() noexcept {
|
|
1994
|
+
return rundot::kinetix::physics::kMotionStatusByteLimit;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
extern "C" std::int32_t rundot_kinetix_world_set_body_transform(
|
|
1998
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
1999
|
+
double x, double y, double z, double qx, double qy, double qz, double qw) noexcept {
|
|
2000
|
+
return guard([&]() {
|
|
2001
|
+
clearError();
|
|
2002
|
+
return withWorld(handle, [&](World& world) {
|
|
2003
|
+
const WorldError result = world.setBodyTransform(
|
|
2004
|
+
BodyId{joinU64(body_low, body_high)}, {x, y, z}, {qx, qy, qz, qw});
|
|
2005
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
2006
|
+
});
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
extern "C" std::int32_t rundot_kinetix_world_set_body_linear_damping(
|
|
2011
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
2012
|
+
double damping) noexcept {
|
|
2013
|
+
return guard([&]() {
|
|
2014
|
+
clearError();
|
|
2015
|
+
return withWorld(handle, [&](World& world) {
|
|
2016
|
+
const WorldError result = world.setBodyLinearDamping(
|
|
2017
|
+
BodyId{joinU64(body_low, body_high)}, damping);
|
|
2018
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
2019
|
+
});
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
extern "C" std::int32_t rundot_kinetix_world_wake_body(
|
|
2024
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high) noexcept {
|
|
2025
|
+
return guard([&]() {
|
|
2026
|
+
clearError();
|
|
2027
|
+
return withWorld(handle, [&](World& world) {
|
|
2028
|
+
const WorldError result = world.wakeBody(BodyId{joinU64(body_low, body_high)});
|
|
2029
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
2030
|
+
});
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
extern "C" std::int32_t rundot_kinetix_world_write_body_motion(
|
|
2035
|
+
std::uint32_t handle,
|
|
2036
|
+
double* pose, std::uint32_t pose_values,
|
|
2037
|
+
double* velocity, std::uint32_t velocity_values,
|
|
2038
|
+
std::uint32_t* ids, std::uint32_t id_words,
|
|
2039
|
+
std::uint8_t* status_bytes, std::uint32_t status_count,
|
|
2040
|
+
std::uint32_t* output_header, std::uint32_t header_words) noexcept {
|
|
2041
|
+
return guard([&]() {
|
|
2042
|
+
clearError();
|
|
2043
|
+
using rundot::kinetix::physics::kMotionHeaderWords;
|
|
2044
|
+
using rundot::kinetix::physics::kMotionIdWordLimit;
|
|
2045
|
+
using rundot::kinetix::physics::kMotionPoseStride;
|
|
2046
|
+
using rundot::kinetix::physics::kMotionPoseValueLimit;
|
|
2047
|
+
using rundot::kinetix::physics::kMotionStatusByteLimit;
|
|
2048
|
+
using rundot::kinetix::physics::kMotionStatusVersion;
|
|
2049
|
+
using rundot::kinetix::physics::kMotionVelocityStride;
|
|
2050
|
+
using rundot::kinetix::physics::kMotionVelocityValueLimit;
|
|
2051
|
+
using rundot::kinetix::physics::kWorldMaxBodies;
|
|
2052
|
+
if (output_header == nullptr || header_words != kMotionHeaderWords) {
|
|
2053
|
+
return fail(AbiStatus::InvalidArgument, "motion header must contain 6 words");
|
|
2054
|
+
}
|
|
2055
|
+
if (pose_values > kMotionPoseValueLimit || velocity_values > kMotionVelocityValueLimit
|
|
2056
|
+
|| id_words > kMotionIdWordLimit || status_count > kMotionStatusByteLimit) {
|
|
2057
|
+
return fail(AbiStatus::InvalidArgument, "motion capacity exceeds the native limit");
|
|
2058
|
+
}
|
|
2059
|
+
if ((pose_values > 0 && pose == nullptr) || (velocity_values > 0 && velocity == nullptr)
|
|
2060
|
+
|| (id_words > 0 && ids == nullptr) || (status_count > 0 && status_bytes == nullptr)) {
|
|
2061
|
+
return fail(AbiStatus::InvalidArgument, "motion buffer pointer is null");
|
|
2062
|
+
}
|
|
2063
|
+
bool rangeOverflow = false;
|
|
2064
|
+
const CallerRange ranges[] = {
|
|
2065
|
+
countedCallerRange(pose, pose_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2066
|
+
countedCallerRange(velocity, velocity_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2067
|
+
countedCallerRange(ids, id_words, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
2068
|
+
{status_bytes, static_cast<std::size_t>(status_count), alignof(std::uint8_t), RangeRole::Output},
|
|
2069
|
+
countedCallerRange(output_header, header_words, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
2070
|
+
};
|
|
2071
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
2072
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2073
|
+
Pins3D pins;
|
|
2074
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2075
|
+
auto poseView = pins.view<double>(0);
|
|
2076
|
+
auto velocityView = pins.view<double>(1);
|
|
2077
|
+
auto idView = pins.view<std::uint32_t>(2);
|
|
2078
|
+
auto statusView = pins.view<std::uint8_t>(3);
|
|
2079
|
+
auto headerView = pins.view<std::uint32_t>(4);
|
|
2080
|
+
if (!headerView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2081
|
+
return withWorld(handle, [&](World& world) {
|
|
2082
|
+
const auto count = static_cast<std::uint32_t>(world.topology().bodyIds.size());
|
|
2083
|
+
if (count > kWorldMaxBodies) {
|
|
2084
|
+
return fail(rundot::kinetix::physics::WorldError{
|
|
2085
|
+
rundot::kinetix::physics::WorldErrorCode::CapacityExceeded,
|
|
2086
|
+
"motion body count exceeds the native limit"});
|
|
2087
|
+
}
|
|
2088
|
+
if (static_cast<std::uint64_t>(count) * kMotionPoseStride > pose_values
|
|
2089
|
+
|| static_cast<std::uint64_t>(count) * kMotionVelocityStride > velocity_values
|
|
2090
|
+
|| static_cast<std::uint64_t>(count) * 2 > id_words
|
|
2091
|
+
|| count > status_count) {
|
|
2092
|
+
return fail(AbiStatus::ShortBuffer, "motion buffer is short");
|
|
2093
|
+
}
|
|
2094
|
+
if (count > 0 && (!poseView || !velocityView || !idView || !statusView)) {
|
|
2095
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2096
|
+
}
|
|
2097
|
+
std::span<double> poseSpan = count == 0
|
|
2098
|
+
? std::span<double>{} : std::span<double>(poseView.data(), pose_values);
|
|
2099
|
+
std::span<double> velocitySpan = count == 0
|
|
2100
|
+
? std::span<double>{} : std::span<double>(velocityView.data(), velocity_values);
|
|
2101
|
+
std::span<std::uint32_t> idSpan = count == 0
|
|
2102
|
+
? std::span<std::uint32_t>{} : std::span<std::uint32_t>(idView.data(), id_words);
|
|
2103
|
+
std::span<std::uint8_t> motionStatus = count == 0
|
|
2104
|
+
? std::span<std::uint8_t>{} : std::span<std::uint8_t>(statusView.data(), status_count);
|
|
2105
|
+
rundot::kinetix::physics::BodyMotionWrite written;
|
|
2106
|
+
const WorldError result = world.writeBodyMotionInto(
|
|
2107
|
+
poseSpan, velocitySpan, idSpan, motionStatus, written);
|
|
2108
|
+
if (!result.ok()) return fail(result);
|
|
2109
|
+
headerView.data()[0] = written.count;
|
|
2110
|
+
headerView.data()[1] = kMotionStatusVersion;
|
|
2111
|
+
splitU64(written.mutationRevision, headerView.data() + 2);
|
|
2112
|
+
splitU64(written.restoreEpoch, headerView.data() + 4);
|
|
2113
|
+
return status(AbiStatus::Ok);
|
|
2114
|
+
});
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
extern "C" std::int32_t rundot_kinetix_world_apply_support(
|
|
2119
|
+
std::uint32_t handle,
|
|
2120
|
+
const rundot_kinetix_world_support_spring* springs,
|
|
2121
|
+
std::uint32_t spring_count,
|
|
2122
|
+
const rundot_kinetix_world_support_force* forces,
|
|
2123
|
+
std::uint32_t force_count,
|
|
2124
|
+
std::uint32_t wake_low,
|
|
2125
|
+
std::uint32_t wake_high) noexcept {
|
|
2126
|
+
return guard([&]() {
|
|
2127
|
+
clearError();
|
|
2128
|
+
if ((spring_count > 0 && springs == nullptr) || (force_count > 0 && forces == nullptr)) {
|
|
2129
|
+
return fail(AbiStatus::InvalidArgument, "support record pointer is null");
|
|
2130
|
+
}
|
|
2131
|
+
if (static_cast<std::uint64_t>(spring_count) + force_count
|
|
2132
|
+
> rundot::kinetix::physics::kWorldMaxSupportRecords) {
|
|
2133
|
+
return fail(rundot::kinetix::physics::WorldError{
|
|
2134
|
+
rundot::kinetix::physics::WorldErrorCode::CapacityExceeded,
|
|
2135
|
+
"support record count exceeds the native limit"});
|
|
2136
|
+
}
|
|
2137
|
+
bool rangeOverflow = false;
|
|
2138
|
+
const CallerRange ranges[] = {
|
|
2139
|
+
countedCallerRange(springs, spring_count, sizeof(rundot_kinetix_world_support_spring), alignof(rundot_kinetix_world_support_spring), RangeRole::Input, rangeOverflow),
|
|
2140
|
+
countedCallerRange(forces, force_count, sizeof(rundot_kinetix_world_support_force), alignof(rundot_kinetix_world_support_force), RangeRole::Input, rangeOverflow),
|
|
2141
|
+
};
|
|
2142
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
2143
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2144
|
+
Pins3D pins;
|
|
2145
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2146
|
+
auto springView = pins.view<const rundot_kinetix_world_support_spring>(0);
|
|
2147
|
+
auto forceView = pins.view<const rundot_kinetix_world_support_force>(1);
|
|
2148
|
+
if ((spring_count > 0 && !springView) || (force_count > 0 && !forceView)) {
|
|
2149
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2150
|
+
}
|
|
2151
|
+
using namespace rundot::kinetix::physics;
|
|
2152
|
+
std::vector<WorldSupportSpringInput> springInputs(spring_count);
|
|
2153
|
+
for (std::uint32_t index = 0; index < spring_count; ++index) {
|
|
2154
|
+
const rundot_kinetix_world_support_spring& record = springView.data()[index];
|
|
2155
|
+
WorldSupportSpringInput& input = springInputs[index];
|
|
2156
|
+
input.body = BodyId{joinU64(record.body_low, record.body_high)};
|
|
2157
|
+
input.support = BodyId{joinU64(record.support_low, record.support_high)};
|
|
2158
|
+
input.point = {record.point[0], record.point[1], record.point[2]};
|
|
2159
|
+
input.normal = {record.normal[0], record.normal[1], record.normal[2]};
|
|
2160
|
+
input.compression = record.compression;
|
|
2161
|
+
input.travel = record.travel;
|
|
2162
|
+
input.stiffness = record.stiffness;
|
|
2163
|
+
input.damping = record.damping;
|
|
2164
|
+
}
|
|
2165
|
+
std::vector<WorldSupportForceInput> forceInputs(force_count);
|
|
2166
|
+
for (std::uint32_t index = 0; index < force_count; ++index) {
|
|
2167
|
+
const rundot_kinetix_world_support_force& record = forceView.data()[index];
|
|
2168
|
+
WorldSupportForceInput& input = forceInputs[index];
|
|
2169
|
+
input.body = BodyId{joinU64(record.body_low, record.body_high)};
|
|
2170
|
+
input.support = BodyId{joinU64(record.support_low, record.support_high)};
|
|
2171
|
+
input.force = {record.force[0], record.force[1], record.force[2]};
|
|
2172
|
+
input.point = {record.point[0], record.point[1], record.point[2]};
|
|
2173
|
+
}
|
|
2174
|
+
return withWorld(handle, [&](World& world) {
|
|
2175
|
+
const WorldError result = world.applySupport(
|
|
2176
|
+
springInputs, forceInputs, BodyId{joinU64(wake_low, wake_high)});
|
|
2177
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
2178
|
+
});
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
extern "C" std::int32_t rundot_kinetix_world_read_surface_velocity(
|
|
2183
|
+
std::uint32_t handle,
|
|
2184
|
+
std::uint32_t body_low,
|
|
2185
|
+
std::uint32_t body_high,
|
|
2186
|
+
double* velocity) noexcept {
|
|
2187
|
+
return guard([&]() {
|
|
2188
|
+
clearError();
|
|
2189
|
+
if (velocity == nullptr) return fail(AbiStatus::InvalidArgument, "surface velocity output is null");
|
|
2190
|
+
const CallerRange ranges[] = {
|
|
2191
|
+
{velocity, 3 * sizeof(double), alignof(double), RangeRole::Output},
|
|
2192
|
+
};
|
|
2193
|
+
Pins3D pins;
|
|
2194
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2195
|
+
auto velocityView = pins.view<double>(0);
|
|
2196
|
+
if (!velocityView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2197
|
+
return withWorld(handle, [&](World& world) {
|
|
2198
|
+
std::array<double, 3> value{};
|
|
2199
|
+
const WorldError result = world.readEffectiveSurfaceVelocity(
|
|
2200
|
+
BodyId{joinU64(body_low, body_high)}, value);
|
|
2201
|
+
if (!result.ok()) return fail(result);
|
|
2202
|
+
velocityView.data()[0] = value[0];
|
|
2203
|
+
velocityView.data()[1] = value[1];
|
|
2204
|
+
velocityView.data()[2] = value[2];
|
|
2205
|
+
return status(AbiStatus::Ok);
|
|
2206
|
+
});
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
extern "C" std::int32_t rundot_kinetix_world_read_body_mobility(
|
|
2211
|
+
std::uint32_t handle,
|
|
2212
|
+
std::uint32_t body_low,
|
|
2213
|
+
std::uint32_t body_high,
|
|
2214
|
+
double* inverse_linear,
|
|
2215
|
+
double* inverse_angular) noexcept {
|
|
2216
|
+
return guard([&]() {
|
|
2217
|
+
clearError();
|
|
2218
|
+
if (inverse_linear == nullptr || inverse_angular == nullptr) {
|
|
2219
|
+
return fail(AbiStatus::InvalidArgument, "mobility output is null");
|
|
2220
|
+
}
|
|
2221
|
+
const CallerRange ranges[] = {
|
|
2222
|
+
{inverse_linear, 3 * sizeof(double), alignof(double), RangeRole::Output},
|
|
2223
|
+
{inverse_angular, 6 * sizeof(double), alignof(double), RangeRole::Output},
|
|
2224
|
+
};
|
|
2225
|
+
Pins3D pins;
|
|
2226
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2227
|
+
auto linearView = pins.view<double>(0);
|
|
2228
|
+
auto angularView = pins.view<double>(1);
|
|
2229
|
+
if (!linearView || !angularView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2230
|
+
return withWorld(handle, [&](World& world) {
|
|
2231
|
+
WorldBodyMobility mobility;
|
|
2232
|
+
const WorldError result = world.readBodyMobility(
|
|
2233
|
+
BodyId{joinU64(body_low, body_high)}, mobility);
|
|
2234
|
+
if (!result.ok()) return fail(result);
|
|
2235
|
+
std::copy(mobility.inverseLinear.begin(), mobility.inverseLinear.end(), linearView.data());
|
|
2236
|
+
std::copy(mobility.inverseAngular.begin(), mobility.inverseAngular.end(), angularView.data());
|
|
2237
|
+
return status(AbiStatus::Ok);
|
|
2238
|
+
});
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
extern "C" std::int32_t rundot_kinetix_world_read_pending_support_impulse(
|
|
2243
|
+
std::uint32_t handle,
|
|
2244
|
+
std::uint32_t body_low,
|
|
2245
|
+
std::uint32_t body_high,
|
|
2246
|
+
double dt,
|
|
2247
|
+
std::uint32_t substeps,
|
|
2248
|
+
double* linear,
|
|
2249
|
+
double* angular,
|
|
2250
|
+
std::uint32_t* below_bound) noexcept {
|
|
2251
|
+
return guard([&]() {
|
|
2252
|
+
clearError();
|
|
2253
|
+
if (linear == nullptr || angular == nullptr) {
|
|
2254
|
+
return fail(AbiStatus::InvalidArgument, "pending support output is null");
|
|
2255
|
+
}
|
|
2256
|
+
const CallerRange ranges[] = {
|
|
2257
|
+
{linear, 3 * sizeof(double), alignof(double), RangeRole::Output},
|
|
2258
|
+
{angular, 3 * sizeof(double), alignof(double), RangeRole::Output},
|
|
2259
|
+
{below_bound, below_bound == nullptr ? 0 : sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
2260
|
+
};
|
|
2261
|
+
Pins3D pins;
|
|
2262
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2263
|
+
auto linearView = pins.view<double>(0);
|
|
2264
|
+
auto angularView = pins.view<double>(1);
|
|
2265
|
+
auto belowView = pins.view<std::uint32_t>(2);
|
|
2266
|
+
if (!linearView || !angularView || (below_bound != nullptr && !belowView)) {
|
|
2267
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2268
|
+
}
|
|
2269
|
+
return withWorld(handle, [&](World& world) {
|
|
2270
|
+
WorldSupportImpulse impulse;
|
|
2271
|
+
const WorldError result = world.readPendingSupportImpulse(
|
|
2272
|
+
BodyId{joinU64(body_low, body_high)}, dt, substeps, impulse);
|
|
2273
|
+
if (!result.ok()) return fail(result);
|
|
2274
|
+
std::copy(impulse.linear.begin(), impulse.linear.end(), linearView.data());
|
|
2275
|
+
std::copy(impulse.angular.begin(), impulse.angular.end(), angularView.data());
|
|
2276
|
+
if (below_bound != nullptr) belowView.data()[0] = impulse.belowBound;
|
|
2277
|
+
return status(AbiStatus::Ok);
|
|
2278
|
+
});
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
|
|
755
2282
|
extern "C" std::int32_t rundot_kinetix_world_query(
|
|
756
2283
|
std::uint32_t handle,
|
|
757
2284
|
std::uint32_t kind,
|
|
@@ -767,8 +2294,26 @@ extern "C" std::int32_t rundot_kinetix_world_query(
|
|
|
767
2294
|
return guard([&]() {
|
|
768
2295
|
clearError();
|
|
769
2296
|
using namespace rundot::kinetix::physics;
|
|
770
|
-
|
|
771
|
-
|
|
2297
|
+
bool rangeOverflow = false;
|
|
2298
|
+
const CallerRange ranges[] = {
|
|
2299
|
+
countedCallerRange(query, query_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
2300
|
+
countedCallerRange(hits, hit_capacity_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2301
|
+
countedCallerRange(body_ids, body_id_capacity_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
2302
|
+
{required_hit_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
2303
|
+
};
|
|
2304
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
2305
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2306
|
+
Pins3D pins;
|
|
2307
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2308
|
+
auto queryView = pins.view<const double>(0);
|
|
2309
|
+
auto hitsView = pins.view<double>(1);
|
|
2310
|
+
auto bodyIdsView = pins.view<std::uint32_t>(2);
|
|
2311
|
+
auto requiredHitCountView = pins.view<std::uint32_t>(3);
|
|
2312
|
+
if (!queryView || !hitsView || !bodyIdsView || !requiredHitCountView) {
|
|
2313
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
if (query_values != kWorldQueryInputStride
|
|
772
2317
|
|| kind < static_cast<std::uint32_t>(WorldQueryKind::Raycast)
|
|
773
2318
|
|| kind > static_cast<std::uint32_t>(WorldQueryKind::ClosestPoint)) {
|
|
774
2319
|
return fail(AbiStatus::InvalidArgument, "world query arguments are invalid");
|
|
@@ -777,44 +2322,92 @@ extern "C" std::int32_t rundot_kinetix_world_query(
|
|
|
777
2322
|
std::vector<WorldQueryHit> result;
|
|
778
2323
|
const WorldError queryError = world.query(
|
|
779
2324
|
static_cast<WorldQueryKind>(kind),
|
|
780
|
-
std::span<const double, kWorldQueryInputStride>{
|
|
2325
|
+
std::span<const double, kWorldQueryInputStride>{queryView.data(), query_values},
|
|
781
2326
|
BodyId{joinU64(excluded_body_low, excluded_body_high)},
|
|
782
2327
|
result);
|
|
783
2328
|
if (!queryError.ok()) return fail(queryError);
|
|
784
2329
|
if (result.size() > std::numeric_limits<std::uint32_t>::max()) {
|
|
785
2330
|
return fail(AbiStatus::InternalFailure, "world query result count is too large");
|
|
786
2331
|
}
|
|
787
|
-
*
|
|
2332
|
+
*requiredHitCountView.data() = static_cast<std::uint32_t>(result.size());
|
|
788
2333
|
const std::uint64_t requiredHitValues =
|
|
789
2334
|
static_cast<std::uint64_t>(result.size()) * kWorldQueryHitStride;
|
|
790
2335
|
const std::uint64_t requiredIdValues =
|
|
791
2336
|
static_cast<std::uint64_t>(result.size()) * kWorldQueryBodyIdStride;
|
|
792
2337
|
if (requiredHitValues > hit_capacity_values
|
|
793
|
-
|| requiredIdValues > body_id_capacity_values
|
|
794
|
-
|| (requiredHitValues != 0 && hits == nullptr)
|
|
795
|
-
|| (requiredIdValues != 0 && body_ids == nullptr)) {
|
|
2338
|
+
|| requiredIdValues > body_id_capacity_values) {
|
|
796
2339
|
return fail(AbiStatus::ShortBuffer, "world query output buffer is too small");
|
|
797
2340
|
}
|
|
798
|
-
OutputRange hitRange;
|
|
799
|
-
OutputRange idRange;
|
|
800
|
-
if (!outputRange(hits, requiredHitValues * sizeof(double), hitRange)
|
|
801
|
-
|| !outputRange(body_ids, requiredIdValues * sizeof(std::uint32_t), idRange)
|
|
802
|
-
|| !disjointOutputRanges(std::array{hitRange, idRange})) {
|
|
803
|
-
return fail(AbiStatus::InvalidArgument, "world query output buffers overlap");
|
|
804
|
-
}
|
|
805
2341
|
for (std::size_t index = 0; index < result.size(); index += 1) {
|
|
806
2342
|
const WorldQueryHit& hit = result[index];
|
|
807
2343
|
const std::size_t hitOffset = index * kWorldQueryHitStride;
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
splitU64(hit.body.value,
|
|
2344
|
+
hitsView.data()[hitOffset] = hit.distance;
|
|
2345
|
+
hitsView.data()[hitOffset + 1] = hit.point[0];
|
|
2346
|
+
hitsView.data()[hitOffset + 2] = hit.point[1];
|
|
2347
|
+
hitsView.data()[hitOffset + 3] = hit.point[2];
|
|
2348
|
+
hitsView.data()[hitOffset + 4] = hit.normal[0];
|
|
2349
|
+
hitsView.data()[hitOffset + 5] = hit.normal[1];
|
|
2350
|
+
hitsView.data()[hitOffset + 6] = hit.normal[2];
|
|
2351
|
+
hitsView.data()[hitOffset + 7] = static_cast<double>(hit.childIndex);
|
|
2352
|
+
splitU64(hit.body.value, bodyIdsView.data() + index * kWorldQueryBodyIdStride);
|
|
2353
|
+
}
|
|
2354
|
+
return status(AbiStatus::Ok);
|
|
2355
|
+
});
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
extern "C" std::int32_t rundot_kinetix_world_query_body_ray(
|
|
2360
|
+
std::uint32_t handle, std::uint32_t body_low, std::uint32_t body_high,
|
|
2361
|
+
const double* query, std::uint32_t query_values,
|
|
2362
|
+
std::uint32_t excluded_body_low, std::uint32_t excluded_body_high,
|
|
2363
|
+
double* hits, std::uint32_t hit_capacity_values,
|
|
2364
|
+
std::uint32_t* body_ids, std::uint32_t body_id_capacity_values,
|
|
2365
|
+
std::uint32_t* required_hit_count) noexcept {
|
|
2366
|
+
return guard([&]() {
|
|
2367
|
+
clearError();
|
|
2368
|
+
using namespace rundot::kinetix::physics;
|
|
2369
|
+
bool rangeOverflow = false;
|
|
2370
|
+
const CallerRange ranges[] = {
|
|
2371
|
+
countedCallerRange(query, query_values, sizeof(double), alignof(double), RangeRole::Input, rangeOverflow),
|
|
2372
|
+
countedCallerRange(hits, hit_capacity_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2373
|
+
countedCallerRange(body_ids, body_id_capacity_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
2374
|
+
{required_hit_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
2375
|
+
};
|
|
2376
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
2377
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2378
|
+
Pins3D pins;
|
|
2379
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2380
|
+
auto queryView = pins.view<const double>(0);
|
|
2381
|
+
auto hitsView = pins.view<double>(1);
|
|
2382
|
+
auto bodyIdsView = pins.view<std::uint32_t>(2);
|
|
2383
|
+
auto requiredHitCountView = pins.view<std::uint32_t>(3);
|
|
2384
|
+
if (!queryView || !hitsView || !bodyIdsView || !requiredHitCountView) {
|
|
2385
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
const BodyId body{joinU64(body_low, body_high)};
|
|
2389
|
+
if (body.value == 0 || query_values != kWorldQueryInputStride) {
|
|
2390
|
+
return fail(AbiStatus::InvalidArgument, "selected body ray arguments are invalid");
|
|
2391
|
+
}
|
|
2392
|
+
return withWorld(handle, [&](World& world) {
|
|
2393
|
+
std::vector<WorldQueryHit> result;
|
|
2394
|
+
const auto checked = world.raycastBody(body, std::span<const double, kWorldQueryInputStride>{queryView.data(), kWorldQueryInputStride},
|
|
2395
|
+
BodyId{joinU64(excluded_body_low, excluded_body_high)}, result);
|
|
2396
|
+
if (!checked.ok()) return fail(checked);
|
|
2397
|
+
if (!result.empty() && (hit_capacity_values < kWorldQueryHitStride
|
|
2398
|
+
|| body_id_capacity_values < kWorldQueryBodyIdStride)) {
|
|
2399
|
+
*requiredHitCountView.data() = 1;
|
|
2400
|
+
return fail(AbiStatus::ShortBuffer, "selected body ray output buffer is too small");
|
|
2401
|
+
}
|
|
2402
|
+
if (!result.empty()) {
|
|
2403
|
+
const auto& hit = result.front();
|
|
2404
|
+
hitsView.data()[0] = hit.distance;
|
|
2405
|
+
std::copy(hit.point.begin(), hit.point.end(), hitsView.data() + 1);
|
|
2406
|
+
std::copy(hit.normal.begin(), hit.normal.end(), hitsView.data() + 4);
|
|
2407
|
+
hitsView.data()[7] = hit.childIndex;
|
|
2408
|
+
splitU64(hit.body.value, bodyIdsView.data());
|
|
817
2409
|
}
|
|
2410
|
+
*requiredHitCountView.data() = static_cast<std::uint32_t>(result.size());
|
|
818
2411
|
return status(AbiStatus::Ok);
|
|
819
2412
|
});
|
|
820
2413
|
});
|
|
@@ -826,20 +2419,35 @@ extern "C" std::int32_t rundot_kinetix_world_state_info(
|
|
|
826
2419
|
std::uint32_t output_values) noexcept {
|
|
827
2420
|
return guard([&]() {
|
|
828
2421
|
clearError();
|
|
2422
|
+
bool rangeOverflow = false;
|
|
2423
|
+
const CallerRange ranges[] = {
|
|
2424
|
+
countedCallerRange(output, output_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
2425
|
+
};
|
|
2426
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
2427
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2428
|
+
Pins3D pins;
|
|
2429
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2430
|
+
auto outputView = pins.view<std::uint32_t>(0);
|
|
2431
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2432
|
+
|
|
2433
|
+
if (output_values < 10) {
|
|
2434
|
+
return fail(AbiStatus::ShortBuffer, "world state info needs ten uint32 values");
|
|
2435
|
+
}
|
|
829
2436
|
return withWorld(handle, [&](World& world) {
|
|
830
|
-
if (output == nullptr || output_values < 8) {
|
|
831
|
-
return fail(AbiStatus::ShortBuffer, "world state info needs eight uint32 values");
|
|
832
|
-
}
|
|
833
2437
|
const WorldState& state = world.state();
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
2438
|
+
const auto* legacyGeometry = std::get_if<std::vector<double>>(&state.geometry);
|
|
2439
|
+
if (legacyGeometry == nullptr) return fail(AbiStatus::InvalidArgument, "record geometry requires record-form state export");
|
|
2440
|
+
outputView.data()[0] = static_cast<std::uint32_t>(state.frame);
|
|
2441
|
+
outputView.data()[1] = static_cast<std::uint32_t>(state.frame >> 32);
|
|
2442
|
+
outputView.data()[2] = static_cast<std::uint32_t>(state.bodies.size());
|
|
2443
|
+
outputView.data()[3] = static_cast<std::uint32_t>(state.joints.size());
|
|
2444
|
+
outputView.data()[4] = static_cast<std::uint32_t>(legacyGeometry->size());
|
|
2445
|
+
outputView.data()[5] = static_cast<std::uint32_t>(state.contactCache.size());
|
|
2446
|
+
outputView.data()[6] = static_cast<std::uint32_t>(state.forces.size());
|
|
2447
|
+
outputView.data()[7] = static_cast<std::uint32_t>(
|
|
842
2448
|
state.jointWarmState.size() * rundot::kinetix::physics::kJointWarmStateStride);
|
|
2449
|
+
outputView.data()[8] = static_cast<std::uint32_t>(state.surfaceVelocities.size());
|
|
2450
|
+
outputView.data()[9] = static_cast<std::uint32_t>(state.fluids.size());
|
|
843
2451
|
return status(AbiStatus::Ok);
|
|
844
2452
|
});
|
|
845
2453
|
});
|
|
@@ -858,54 +2466,134 @@ extern "C" std::int32_t rundot_kinetix_world_copy_state(
|
|
|
858
2466
|
double* forces,
|
|
859
2467
|
std::uint32_t force_capacity,
|
|
860
2468
|
std::uint8_t* joint_warm_state,
|
|
861
|
-
std::uint32_t joint_warm_state_capacity_bytes
|
|
2469
|
+
std::uint32_t joint_warm_state_capacity_bytes,
|
|
2470
|
+
double* surface_velocities,
|
|
2471
|
+
std::uint32_t surface_velocity_capacity,
|
|
2472
|
+
double* fluids,
|
|
2473
|
+
std::uint32_t fluid_capacity) noexcept {
|
|
862
2474
|
return guard([&]() {
|
|
863
2475
|
clearError();
|
|
2476
|
+
bool rangeOverflow = false;
|
|
2477
|
+
const CallerRange ranges[] = {
|
|
2478
|
+
countedCallerRange(bodies, body_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2479
|
+
countedCallerRange(joints, joint_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2480
|
+
countedCallerRange(geometry, geometry_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2481
|
+
countedCallerRange(contact_cache, contact_cache_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2482
|
+
countedCallerRange(forces, force_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2483
|
+
countedCallerRange(joint_warm_state, joint_warm_state_capacity_bytes, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Output, rangeOverflow),
|
|
2484
|
+
countedCallerRange(surface_velocities, surface_velocity_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2485
|
+
countedCallerRange(fluids, fluid_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
2486
|
+
};
|
|
2487
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
2488
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2489
|
+
Pins3D pins;
|
|
2490
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2491
|
+
auto bodiesView = pins.view<double>(0);
|
|
2492
|
+
auto jointsView = pins.view<double>(1);
|
|
2493
|
+
auto geometryView = pins.view<double>(2);
|
|
2494
|
+
auto contactCacheView = pins.view<double>(3);
|
|
2495
|
+
auto forcesView = pins.view<double>(4);
|
|
2496
|
+
auto jointWarmStateView = pins.view<std::uint8_t>(5);
|
|
2497
|
+
auto surfaceVelocitiesView = pins.view<double>(6);
|
|
2498
|
+
auto fluidsView = pins.view<double>(7);
|
|
2499
|
+
if (!bodiesView || !jointsView || !geometryView || !contactCacheView
|
|
2500
|
+
|| !forcesView || !jointWarmStateView || !surfaceVelocitiesView || !fluidsView) {
|
|
2501
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2502
|
+
}
|
|
2503
|
+
|
|
864
2504
|
return withWorld(handle, [&](World& world) {
|
|
865
2505
|
const WorldState& state = world.state();
|
|
2506
|
+
const auto* legacyGeometry = std::get_if<std::vector<double>>(&state.geometry);
|
|
2507
|
+
if (legacyGeometry == nullptr) return fail(AbiStatus::InvalidArgument, "record geometry requires record-form state export");
|
|
866
2508
|
if (body_capacity < state.bodies.size() || joint_capacity < state.joints.size()
|
|
867
|
-
|| geometry_capacity <
|
|
2509
|
+
|| geometry_capacity < legacyGeometry->size() || contact_cache_capacity < state.contactCache.size()
|
|
868
2510
|
|| force_capacity < state.forces.size()
|
|
2511
|
+
|| fluid_capacity < state.fluids.size()
|
|
2512
|
+
|| surface_velocity_capacity < state.surfaceVelocities.size()
|
|
869
2513
|
|| joint_warm_state_capacity_bytes
|
|
870
2514
|
< state.jointWarmState.size() * rundot::kinetix::physics::kJointWarmStateStride) {
|
|
871
2515
|
return fail(AbiStatus::ShortBuffer, "world state output buffer is too small");
|
|
872
2516
|
}
|
|
873
|
-
if (
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|| (!state.forces.empty() && forces == nullptr)
|
|
877
|
-
|| (!state.jointWarmState.empty() && joint_warm_state == nullptr)) {
|
|
878
|
-
return fail(AbiStatus::InvalidArgument, "world state output pointer is missing");
|
|
879
|
-
}
|
|
880
|
-
std::array<OutputRange, 6> ranges{};
|
|
881
|
-
const std::array<const void*, 6> pointers{
|
|
882
|
-
bodies, joints, geometry, contact_cache, forces, joint_warm_state};
|
|
883
|
-
const std::array<std::uint64_t, 6> byteCounts{
|
|
884
|
-
state.bodies.size() * sizeof(double), state.joints.size() * sizeof(double),
|
|
885
|
-
state.geometry.size() * sizeof(double), state.contactCache.size() * sizeof(double),
|
|
886
|
-
state.forces.size() * sizeof(double),
|
|
887
|
-
state.jointWarmState.size() * rundot::kinetix::physics::kJointWarmStateStride};
|
|
888
|
-
for (std::size_t index = 0; index < ranges.size(); ++index) {
|
|
889
|
-
if (!outputRange(pointers[index], byteCounts[index], ranges[index])) {
|
|
890
|
-
return fail(AbiStatus::InvalidArgument, "world state output range is invalid");
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
if (!disjointOutputRanges(ranges)) {
|
|
894
|
-
return fail(AbiStatus::InvalidArgument, "world state output buffers overlap");
|
|
895
|
-
}
|
|
896
|
-
if (!state.bodies.empty()) std::copy(state.bodies.begin(), state.bodies.end(), bodies);
|
|
897
|
-
if (!state.joints.empty()) std::copy(state.joints.begin(), state.joints.end(), joints);
|
|
898
|
-
if (!state.geometry.empty()) std::copy(state.geometry.begin(), state.geometry.end(), geometry);
|
|
2517
|
+
if (!state.bodies.empty()) std::copy(state.bodies.begin(), state.bodies.end(), bodiesView.data());
|
|
2518
|
+
if (!state.joints.empty()) std::copy(state.joints.begin(), state.joints.end(), jointsView.data());
|
|
2519
|
+
if (!legacyGeometry->empty()) std::copy(legacyGeometry->begin(), legacyGeometry->end(), geometryView.data());
|
|
899
2520
|
if (!state.contactCache.empty()) {
|
|
900
|
-
std::copy(state.contactCache.begin(), state.contactCache.end(),
|
|
2521
|
+
std::copy(state.contactCache.begin(), state.contactCache.end(), contactCacheView.data());
|
|
901
2522
|
}
|
|
902
|
-
if (!state.forces.empty()) std::copy(state.forces.begin(), state.forces.end(),
|
|
903
|
-
if (!state.jointWarmState.empty()) writeWarmStates(
|
|
2523
|
+
if (!state.forces.empty()) std::copy(state.forces.begin(), state.forces.end(), forcesView.data());
|
|
2524
|
+
if (!state.jointWarmState.empty()) writeWarmStates(jointWarmStateView.data(), state.jointWarmState);
|
|
2525
|
+
if (!state.surfaceVelocities.empty()) {
|
|
2526
|
+
std::copy(state.surfaceVelocities.begin(), state.surfaceVelocities.end(), surfaceVelocitiesView.data());
|
|
2527
|
+
}
|
|
2528
|
+
if (!state.fluids.empty()) std::copy(state.fluids.begin(), state.fluids.end(), fluidsView.data());
|
|
904
2529
|
return status(AbiStatus::Ok);
|
|
905
2530
|
});
|
|
906
2531
|
});
|
|
907
2532
|
}
|
|
908
2533
|
|
|
2534
|
+
namespace {
|
|
2535
|
+
|
|
2536
|
+
bool fillCountedRange(
|
|
2537
|
+
rundot::kinetix::memory::CallerRange& range,
|
|
2538
|
+
const void* pointer,
|
|
2539
|
+
std::uint64_t count,
|
|
2540
|
+
std::uint64_t elementBytes,
|
|
2541
|
+
std::size_t alignment,
|
|
2542
|
+
rundot::kinetix::memory::RangeRole role) noexcept {
|
|
2543
|
+
std::size_t bytes = 0;
|
|
2544
|
+
if (!rundot::kinetix::physics::hostRangeBytes(count, elementBytes, bytes)) return false;
|
|
2545
|
+
range = {pointer, bytes, alignment, role, count, elementBytes};
|
|
2546
|
+
return true;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
class WorldByteClaim {
|
|
2550
|
+
public:
|
|
2551
|
+
explicit WorldByteClaim(std::uint64_t bytes) noexcept {
|
|
2552
|
+
if (bytes == 0) return;
|
|
2553
|
+
using Ledger = rundot::kinetix::memory::InstanceLedger<rundot::kinetix::memory::Physics3DModule>;
|
|
2554
|
+
if (!Ledger::instance().tryClaim(rundot::kinetix::memory::LedgerClass::World, bytes)) {
|
|
2555
|
+
failed_ = true;
|
|
2556
|
+
return;
|
|
2557
|
+
}
|
|
2558
|
+
bytes_ = bytes;
|
|
2559
|
+
}
|
|
2560
|
+
~WorldByteClaim() {
|
|
2561
|
+
if (bytes_ == 0) return;
|
|
2562
|
+
using Ledger = rundot::kinetix::memory::InstanceLedger<rundot::kinetix::memory::Physics3DModule>;
|
|
2563
|
+
Ledger::instance().release(rundot::kinetix::memory::LedgerClass::World, bytes_);
|
|
2564
|
+
}
|
|
2565
|
+
WorldByteClaim(const WorldByteClaim&) = delete;
|
|
2566
|
+
WorldByteClaim& operator=(const WorldByteClaim&) = delete;
|
|
2567
|
+
bool ok() const noexcept { return !failed_; }
|
|
2568
|
+
|
|
2569
|
+
private:
|
|
2570
|
+
std::uint64_t bytes_ = 0;
|
|
2571
|
+
bool failed_ = false;
|
|
2572
|
+
};
|
|
2573
|
+
|
|
2574
|
+
bool parsedCommandClaimBytes(std::uint32_t commandCount, std::uint64_t& bytes) noexcept {
|
|
2575
|
+
bytes = 0;
|
|
2576
|
+
if (commandCount == 0) return true;
|
|
2577
|
+
if (!rundot::kinetix::physics::checkedRangeBytes(
|
|
2578
|
+
commandCount,
|
|
2579
|
+
sizeof(rundot::kinetix::physics::TopologyCommand),
|
|
2580
|
+
std::numeric_limits<std::uint64_t>::max(),
|
|
2581
|
+
bytes)) {
|
|
2582
|
+
return false;
|
|
2583
|
+
}
|
|
2584
|
+
if (bytes > std::numeric_limits<std::uint64_t>::max() - 16) return false;
|
|
2585
|
+
bytes += 16;
|
|
2586
|
+
return true;
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
std::int32_t failCapacity() {
|
|
2590
|
+
return fail(rundot::kinetix::physics::WorldError{
|
|
2591
|
+
rundot::kinetix::physics::WorldErrorCode::CapacityExceeded,
|
|
2592
|
+
"plan retained capacity exceeded"});
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
} // namespace
|
|
2596
|
+
|
|
909
2597
|
extern "C" std::int32_t rundot_kinetix_world_apply_topology_batch(
|
|
910
2598
|
std::uint32_t handle,
|
|
911
2599
|
const std::uint32_t* commands,
|
|
@@ -919,18 +2607,52 @@ extern "C" std::int32_t rundot_kinetix_world_apply_topology_batch(
|
|
|
919
2607
|
std::uint32_t* required_output_values) noexcept {
|
|
920
2608
|
return guard([&]() {
|
|
921
2609
|
clearError();
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|| (
|
|
2610
|
+
CallerRange ranges[5];
|
|
2611
|
+
if (!fillCountedRange(ranges[0], commands, command_count,
|
|
2612
|
+
static_cast<std::uint64_t>(rundot::kinetix::physics::kWorldTopologyCommandStride) * sizeof(std::uint32_t),
|
|
2613
|
+
alignof(std::uint32_t), RangeRole::Input)
|
|
2614
|
+
|| !fillCountedRange(ranges[1], body_records, body_record_count,
|
|
2615
|
+
static_cast<std::uint64_t>(rundot::kinetix::physics::kBodyStride) * sizeof(double),
|
|
2616
|
+
alignof(double), RangeRole::Input)
|
|
2617
|
+
|| !fillCountedRange(ranges[2], joint_records, joint_record_count,
|
|
2618
|
+
static_cast<std::uint64_t>(rundot::kinetix::physics::kJointStride) * sizeof(double),
|
|
2619
|
+
alignof(double), RangeRole::Input)
|
|
2620
|
+
|| !fillCountedRange(ranges[3], output, output_capacity_values, sizeof(std::uint32_t),
|
|
2621
|
+
alignof(std::uint32_t), RangeRole::Output)) {
|
|
2622
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2623
|
+
}
|
|
2624
|
+
ranges[4] = {required_output_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output};
|
|
2625
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2626
|
+
Pins3D pins;
|
|
2627
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2628
|
+
auto commandsView = pins.view<const std::uint32_t>(0);
|
|
2629
|
+
auto bodyRecordsView = pins.view<const double>(1);
|
|
2630
|
+
auto jointRecordsView = pins.view<const double>(2);
|
|
2631
|
+
auto outputView = pins.view<std::uint32_t>(3);
|
|
2632
|
+
auto requiredOutputValuesView = pins.view<std::uint32_t>(4);
|
|
2633
|
+
if (!commandsView || !bodyRecordsView || !jointRecordsView || !outputView || !requiredOutputValuesView) {
|
|
2634
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
if (command_count > rundot::kinetix::physics::kWorldMaxTopologyCommands
|
|
2638
|
+
|| body_record_count > command_count || std::uint64_t(joint_record_count) > std::uint64_t(command_count) * 3) {
|
|
927
2639
|
return fail(AbiStatus::InvalidArgument, "topology batch pointers or counts are invalid");
|
|
928
2640
|
}
|
|
2641
|
+
std::uint64_t parseBytes = 0;
|
|
2642
|
+
if (!parsedCommandClaimBytes(command_count, parseBytes)) {
|
|
2643
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2644
|
+
}
|
|
2645
|
+
WorldByteClaim parseClaim(parseBytes);
|
|
2646
|
+
if (!parseClaim.ok()) return failCapacity();
|
|
929
2647
|
std::vector<TopologyCommand> parsed;
|
|
930
|
-
|
|
2648
|
+
try {
|
|
2649
|
+
parsed.reserve(command_count);
|
|
2650
|
+
} catch (const std::bad_alloc&) {
|
|
2651
|
+
return fail(AbiStatus::AllocationFailure, "topology allocation failed");
|
|
2652
|
+
}
|
|
931
2653
|
std::uint32_t maximumResults = 0;
|
|
932
2654
|
for (std::uint32_t index = 0; index < command_count; ++index) {
|
|
933
|
-
const std::uint32_t* fields =
|
|
2655
|
+
const std::uint32_t* fields = commandsView.data()
|
|
934
2656
|
+ static_cast<std::size_t>(index) * rundot::kinetix::physics::kWorldTopologyCommandStride;
|
|
935
2657
|
const auto tag = static_cast<rundot::kinetix::physics::WorldTopologyCommandTag>(fields[0]);
|
|
936
2658
|
if (tag == rundot::kinetix::physics::WorldTopologyCommandTag::CreateBody
|
|
@@ -939,35 +2661,137 @@ extern "C" std::int32_t rundot_kinetix_world_apply_topology_batch(
|
|
|
939
2661
|
}
|
|
940
2662
|
TopologyCommand command;
|
|
941
2663
|
if (!parseTopologyCommand(
|
|
942
|
-
fields,
|
|
2664
|
+
fields, bodyRecordsView.data(), body_record_count, jointRecordsView.data(), joint_record_count,
|
|
2665
|
+
nullptr, 0, command)) {
|
|
943
2666
|
const std::int32_t result = fail(AbiStatus::InvalidArgument, "topology command encoding is invalid");
|
|
944
2667
|
lastErrorCommandIndex = index;
|
|
945
2668
|
return result;
|
|
946
2669
|
}
|
|
947
2670
|
parsed.push_back(std::move(command));
|
|
948
2671
|
}
|
|
949
|
-
*
|
|
950
|
-
if (output_capacity_values < maximumResults
|
|
2672
|
+
*requiredOutputValuesView.data() = maximumResults;
|
|
2673
|
+
if (output_capacity_values < maximumResults) {
|
|
951
2674
|
return fail(AbiStatus::ShortBuffer, "topology result output buffer is too small");
|
|
952
2675
|
}
|
|
953
2676
|
return withWorld(handle, [&](World& world) {
|
|
954
2677
|
TopologyBatchResult batchResult;
|
|
955
2678
|
const WorldError result = world.applyTopologyBatch(parsed, batchResult);
|
|
956
2679
|
if (!result.ok()) return fail(result);
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
2680
|
+
*requiredOutputValuesView.data() = writeTopologyResult(batchResult, outputView.data());
|
|
2681
|
+
return status(AbiStatus::Ok);
|
|
2682
|
+
});
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
extern "C" std::int32_t rundot_kinetix_world_apply_topology_geometry_batch(
|
|
2687
|
+
std::uint32_t handle, std::uint32_t envelope_version,
|
|
2688
|
+
const std::uint32_t* commands, std::uint32_t command_count,
|
|
2689
|
+
const double* body_records, std::uint32_t body_record_count,
|
|
2690
|
+
const double* joint_records, std::uint32_t joint_record_count,
|
|
2691
|
+
const double* fluid_records, std::uint32_t fluid_record_count,
|
|
2692
|
+
const double* geometry_values, std::uint32_t geometry_value_count,
|
|
2693
|
+
std::uint32_t* output, std::uint32_t output_capacity_values,
|
|
2694
|
+
std::uint32_t* required_output_values) noexcept {
|
|
2695
|
+
return guard([&]() {
|
|
2696
|
+
clearError();
|
|
2697
|
+
using namespace rundot::kinetix::physics;
|
|
2698
|
+
CallerRange ranges[7];
|
|
2699
|
+
if (!fillCountedRange(ranges[0], commands, command_count,
|
|
2700
|
+
static_cast<std::uint64_t>(kWorldTopologyGeometryCommandStride) * sizeof(std::uint32_t),
|
|
2701
|
+
alignof(std::uint32_t), RangeRole::Input)
|
|
2702
|
+
|| !fillCountedRange(ranges[1], body_records, body_record_count,
|
|
2703
|
+
static_cast<std::uint64_t>(kBodyStride) * sizeof(double), alignof(double), RangeRole::Input)
|
|
2704
|
+
|| !fillCountedRange(ranges[2], joint_records, joint_record_count,
|
|
2705
|
+
static_cast<std::uint64_t>(kJointStride) * sizeof(double), alignof(double), RangeRole::Input)
|
|
2706
|
+
|| !fillCountedRange(ranges[3], fluid_records, fluid_record_count,
|
|
2707
|
+
static_cast<std::uint64_t>(kFluidStride) * sizeof(double), alignof(double), RangeRole::Input)
|
|
2708
|
+
|| !fillCountedRange(ranges[4], geometry_values, geometry_value_count, sizeof(double),
|
|
2709
|
+
alignof(double), RangeRole::Input)
|
|
2710
|
+
|| !fillCountedRange(ranges[5], output, output_capacity_values, sizeof(std::uint32_t),
|
|
2711
|
+
alignof(std::uint32_t), RangeRole::Output)) {
|
|
2712
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2713
|
+
}
|
|
2714
|
+
ranges[6] = {required_output_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output};
|
|
2715
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2716
|
+
Pins3D pins;
|
|
2717
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2718
|
+
auto commandsView = pins.view<const std::uint32_t>(0);
|
|
2719
|
+
auto bodyRecordsView = pins.view<const double>(1);
|
|
2720
|
+
auto jointRecordsView = pins.view<const double>(2);
|
|
2721
|
+
auto fluidRecordsView = pins.view<const double>(3);
|
|
2722
|
+
auto geometryValuesView = pins.view<const double>(4);
|
|
2723
|
+
auto outputView = pins.view<std::uint32_t>(5);
|
|
2724
|
+
auto requiredOutputValuesView = pins.view<std::uint32_t>(6);
|
|
2725
|
+
if (!commandsView || !bodyRecordsView || !jointRecordsView || !fluidRecordsView
|
|
2726
|
+
|| !geometryValuesView || !outputView || !requiredOutputValuesView) {
|
|
2727
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
if (envelope_version != kWorldTopologyGeometryAbiVersion
|
|
2731
|
+
|| command_count > kWorldMaxTopologyCommands || body_record_count > command_count
|
|
2732
|
+
|| std::uint64_t(joint_record_count) > std::uint64_t(command_count) * 3
|
|
2733
|
+
|| fluid_record_count > command_count || geometry_value_count > kGeometryMaxValues) {
|
|
2734
|
+
return fail(AbiStatus::InvalidArgument, "geometry topology envelope or counts are invalid");
|
|
2735
|
+
}
|
|
2736
|
+
std::uint64_t parseBytes = 0;
|
|
2737
|
+
if (!parsedCommandClaimBytes(command_count, parseBytes)) {
|
|
2738
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2739
|
+
}
|
|
2740
|
+
WorldByteClaim parseClaim(parseBytes);
|
|
2741
|
+
if (!parseClaim.ok()) return failCapacity();
|
|
2742
|
+
std::vector<TopologyCommand> parsed;
|
|
2743
|
+
try {
|
|
2744
|
+
parsed.reserve(command_count);
|
|
2745
|
+
} catch (const std::bad_alloc&) {
|
|
2746
|
+
return fail(AbiStatus::AllocationFailure, "topology allocation failed");
|
|
2747
|
+
}
|
|
2748
|
+
std::uint32_t maximumResults = 0, payloadEnd = 0;
|
|
2749
|
+
for (std::uint32_t index = 0; index < command_count; ++index) {
|
|
2750
|
+
const auto* fields = commandsView.data() + std::size_t(index) * kWorldTopologyGeometryCommandStride;
|
|
2751
|
+
TopologyCommand command;
|
|
2752
|
+
bool valid = parseTopologyCommand(fields, bodyRecordsView.data(), body_record_count,
|
|
2753
|
+
jointRecordsView.data(), joint_record_count, fluidRecordsView.data(), fluid_record_count,
|
|
2754
|
+
command);
|
|
2755
|
+
BodyGeometryAction* action = nullptr;
|
|
2756
|
+
if (auto* create = std::get_if<CreateBodyCommand>(&command)) action = &create->geometry;
|
|
2757
|
+
if (auto* edit = std::get_if<EditBodyCommand>(&command)) action = &edit->geometry;
|
|
2758
|
+
const auto tag = static_cast<WorldBodyGeometryActionTag>(fields[12]);
|
|
2759
|
+
valid = valid && fields[15] == 0;
|
|
2760
|
+
if (tag == WorldBodyGeometryActionTag::Install && action != nullptr) {
|
|
2761
|
+
valid = valid && fields[13] == payloadEnd && fields[14] != 0
|
|
2762
|
+
&& fields[14] <= geometry_value_count - payloadEnd;
|
|
2763
|
+
if (valid) {
|
|
2764
|
+
*action = InstallBodyGeometry{{geometryValuesView.data() + payloadEnd, fields[14]}};
|
|
2765
|
+
payloadEnd += fields[14];
|
|
2766
|
+
}
|
|
2767
|
+
} else {
|
|
2768
|
+
valid = valid && fields[13] == 0 && fields[14] == 0;
|
|
2769
|
+
if (tag == WorldBodyGeometryActionTag::Clear && action != nullptr) *action = ClearBodyGeometry{};
|
|
2770
|
+
else valid = valid && tag == WorldBodyGeometryActionTag::Keep;
|
|
2771
|
+
}
|
|
2772
|
+
if (!valid) {
|
|
2773
|
+
lastErrorCommandIndex = index;
|
|
2774
|
+
return fail(AbiStatus::InvalidArgument, "geometry topology command or payload range is invalid");
|
|
2775
|
+
}
|
|
2776
|
+
if (std::holds_alternative<CreateBodyCommand>(command)
|
|
2777
|
+
|| std::holds_alternative<CreateJointCommand>(command)
|
|
2778
|
+
|| std::holds_alternative<CreateFluidCommand>(command)) {
|
|
2779
|
+
maximumResults += kWorldTopologyResultStride;
|
|
2780
|
+
}
|
|
2781
|
+
parsed.push_back(std::move(command));
|
|
2782
|
+
}
|
|
2783
|
+
if (payloadEnd != geometry_value_count) {
|
|
2784
|
+
return fail(AbiStatus::InvalidArgument, "geometry topology payload or output ranges are invalid");
|
|
2785
|
+
}
|
|
2786
|
+
if (output_capacity_values < maximumResults) {
|
|
2787
|
+
*requiredOutputValuesView.data() = maximumResults;
|
|
2788
|
+
return fail(AbiStatus::ShortBuffer, "geometry topology result buffer is too small");
|
|
2789
|
+
}
|
|
2790
|
+
return withWorld(handle, [&](World& world) {
|
|
2791
|
+
TopologyBatchResult result;
|
|
2792
|
+
const auto applied = world.applyTopologyBatch(parsed, result);
|
|
2793
|
+
if (!applied.ok()) return fail(applied);
|
|
2794
|
+
*requiredOutputValuesView.data() = writeTopologyResult(result, outputView.data());
|
|
971
2795
|
return status(AbiStatus::Ok);
|
|
972
2796
|
});
|
|
973
2797
|
});
|
|
@@ -979,60 +2803,317 @@ extern "C" std::int32_t rundot_kinetix_world_topology_info(
|
|
|
979
2803
|
std::uint32_t output_values) noexcept {
|
|
980
2804
|
return guard([&]() {
|
|
981
2805
|
clearError();
|
|
982
|
-
|
|
983
|
-
|
|
2806
|
+
CallerRange ranges[1];
|
|
2807
|
+
if (!fillCountedRange(ranges[0], output, output_values, sizeof(std::uint32_t),
|
|
2808
|
+
alignof(std::uint32_t), RangeRole::Output)) {
|
|
2809
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2810
|
+
}
|
|
2811
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2812
|
+
Pins3D pins;
|
|
2813
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2814
|
+
auto outputView = pins.view<std::uint32_t>(0);
|
|
2815
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2816
|
+
|
|
2817
|
+
if (output_values < rundot::kinetix::physics::kWorldTopologyInfoStride) {
|
|
2818
|
+
return fail(AbiStatus::ShortBuffer, "topology info needs thirteen uint32 values");
|
|
2819
|
+
}
|
|
2820
|
+
return withWorld(handle, [&](World& world) {
|
|
2821
|
+
splitU64(world.restoreEpoch(), outputView.data());
|
|
2822
|
+
splitU64(world.topology().nextBodyId.value, outputView.data() + 2);
|
|
2823
|
+
splitU64(world.topology().nextJointId.value, outputView.data() + 4);
|
|
2824
|
+
splitU64(world.topology().nextFluidId.value, outputView.data() + 6);
|
|
2825
|
+
outputView.data()[8] = static_cast<std::uint32_t>(world.topology().bodyIds.size());
|
|
2826
|
+
outputView.data()[9] = static_cast<std::uint32_t>(world.topology().joints.size());
|
|
2827
|
+
outputView.data()[10] = static_cast<std::uint32_t>(world.topology().fluidIds.size());
|
|
2828
|
+
splitU64(world.mutationRevision(), outputView.data() + 11);
|
|
2829
|
+
return status(AbiStatus::Ok);
|
|
2830
|
+
});
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
extern "C" std::int32_t rundot_kinetix_world_prepare_topology_edit(
|
|
2835
|
+
std::uint32_t handle, std::uint32_t envelope_version,
|
|
2836
|
+
std::uint32_t expected_revision_lo, std::uint32_t expected_revision_hi,
|
|
2837
|
+
const std::uint32_t* commands, std::uint32_t command_count,
|
|
2838
|
+
const double* body_records, std::uint32_t body_record_count,
|
|
2839
|
+
const double* joint_records, std::uint32_t joint_record_count,
|
|
2840
|
+
const double* fluid_records, std::uint32_t fluid_record_count,
|
|
2841
|
+
const double* geometry_values, std::uint32_t geometry_value_count,
|
|
2842
|
+
std::uint32_t* created_output, std::uint32_t created_capacity_values,
|
|
2843
|
+
std::uint32_t* required_created_values,
|
|
2844
|
+
std::uint32_t* header_output, std::uint32_t header_capacity_values) noexcept {
|
|
2845
|
+
return guard([&]() {
|
|
2846
|
+
clearError();
|
|
2847
|
+
using namespace rundot::kinetix::physics;
|
|
2848
|
+
CallerRange ranges[8];
|
|
2849
|
+
if (!fillCountedRange(ranges[0], commands, command_count,
|
|
2850
|
+
static_cast<std::uint64_t>(kWorldTopologyGeometryCommandStride) * sizeof(std::uint32_t),
|
|
2851
|
+
alignof(std::uint32_t), RangeRole::Input)
|
|
2852
|
+
|| !fillCountedRange(ranges[1], body_records, body_record_count,
|
|
2853
|
+
static_cast<std::uint64_t>(kBodyStride) * sizeof(double), alignof(double), RangeRole::Input)
|
|
2854
|
+
|| !fillCountedRange(ranges[2], joint_records, joint_record_count,
|
|
2855
|
+
static_cast<std::uint64_t>(kJointStride) * sizeof(double), alignof(double), RangeRole::Input)
|
|
2856
|
+
|| !fillCountedRange(ranges[3], fluid_records, fluid_record_count,
|
|
2857
|
+
static_cast<std::uint64_t>(kFluidStride) * sizeof(double), alignof(double), RangeRole::Input)
|
|
2858
|
+
|| !fillCountedRange(ranges[4], geometry_values, geometry_value_count, sizeof(double),
|
|
2859
|
+
alignof(double), RangeRole::Input)
|
|
2860
|
+
|| !fillCountedRange(ranges[5], created_output, created_capacity_values, sizeof(std::uint32_t),
|
|
2861
|
+
alignof(std::uint32_t), RangeRole::Output)
|
|
2862
|
+
|| !fillCountedRange(ranges[7], header_output, header_capacity_values, sizeof(std::uint32_t),
|
|
2863
|
+
alignof(std::uint32_t), RangeRole::Output)) {
|
|
2864
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2865
|
+
}
|
|
2866
|
+
ranges[6] = {required_created_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output};
|
|
2867
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
2868
|
+
Pins3D pins;
|
|
2869
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
2870
|
+
auto commandsView = pins.view<const std::uint32_t>(0);
|
|
2871
|
+
auto bodyRecordsView = pins.view<const double>(1);
|
|
2872
|
+
auto jointRecordsView = pins.view<const double>(2);
|
|
2873
|
+
auto fluidRecordsView = pins.view<const double>(3);
|
|
2874
|
+
auto geometryValuesView = pins.view<const double>(4);
|
|
2875
|
+
auto createdView = pins.view<std::uint32_t>(5);
|
|
2876
|
+
auto requiredView = pins.view<std::uint32_t>(6);
|
|
2877
|
+
auto headerView = pins.view<std::uint32_t>(7);
|
|
2878
|
+
if (!commandsView || !bodyRecordsView || !jointRecordsView || !fluidRecordsView
|
|
2879
|
+
|| !geometryValuesView || !createdView || !requiredView || !headerView) {
|
|
2880
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
2881
|
+
}
|
|
2882
|
+
if (envelope_version != kWorldTopologyGeometryAbiVersion
|
|
2883
|
+
|| command_count > kWorldMaxTopologyCommands || body_record_count > command_count
|
|
2884
|
+
|| std::uint64_t(joint_record_count) > std::uint64_t(command_count) * 3
|
|
2885
|
+
|| fluid_record_count > command_count || geometry_value_count > kGeometryMaxValues) {
|
|
2886
|
+
return fail(AbiStatus::InvalidArgument, "geometry topology envelope or counts are invalid");
|
|
2887
|
+
}
|
|
2888
|
+
std::uint64_t parseBytes = 0;
|
|
2889
|
+
if (!parsedCommandClaimBytes(command_count, parseBytes)) {
|
|
2890
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
2891
|
+
}
|
|
2892
|
+
WorldByteClaim parseClaim(parseBytes);
|
|
2893
|
+
if (!parseClaim.ok()) return failCapacity();
|
|
2894
|
+
std::vector<TopologyCommand> parsed;
|
|
2895
|
+
try {
|
|
2896
|
+
parsed.reserve(command_count);
|
|
2897
|
+
} catch (const std::bad_alloc&) {
|
|
2898
|
+
return fail(AbiStatus::AllocationFailure, "topology allocation failed");
|
|
2899
|
+
}
|
|
2900
|
+
std::uint32_t maximumResults = 0;
|
|
2901
|
+
std::uint32_t payloadEnd = 0;
|
|
2902
|
+
for (std::uint32_t index = 0; index < command_count; ++index) {
|
|
2903
|
+
const auto* fields = commandsView.data() + std::size_t(index) * kWorldTopologyGeometryCommandStride;
|
|
2904
|
+
TopologyCommand command;
|
|
2905
|
+
bool valid = parseTopologyCommand(fields, bodyRecordsView.data(), body_record_count,
|
|
2906
|
+
jointRecordsView.data(), joint_record_count, fluidRecordsView.data(), fluid_record_count,
|
|
2907
|
+
command);
|
|
2908
|
+
BodyGeometryAction* action = nullptr;
|
|
2909
|
+
if (auto* create = std::get_if<CreateBodyCommand>(&command)) action = &create->geometry;
|
|
2910
|
+
if (auto* edit = std::get_if<EditBodyCommand>(&command)) action = &edit->geometry;
|
|
2911
|
+
const auto tag = static_cast<WorldBodyGeometryActionTag>(fields[12]);
|
|
2912
|
+
valid = valid && fields[15] == 0;
|
|
2913
|
+
if (tag == WorldBodyGeometryActionTag::Install && action != nullptr) {
|
|
2914
|
+
valid = valid && fields[13] == payloadEnd && fields[14] != 0
|
|
2915
|
+
&& fields[14] <= geometry_value_count - payloadEnd;
|
|
2916
|
+
if (valid) {
|
|
2917
|
+
*action = InstallBodyGeometry{{geometryValuesView.data() + payloadEnd, fields[14]}};
|
|
2918
|
+
payloadEnd += fields[14];
|
|
2919
|
+
}
|
|
2920
|
+
} else {
|
|
2921
|
+
valid = valid && fields[13] == 0 && fields[14] == 0;
|
|
2922
|
+
if (tag == WorldBodyGeometryActionTag::Clear && action != nullptr) *action = ClearBodyGeometry{};
|
|
2923
|
+
else valid = valid && tag == WorldBodyGeometryActionTag::Keep;
|
|
2924
|
+
}
|
|
2925
|
+
if (!valid) {
|
|
2926
|
+
lastErrorCommandIndex = index;
|
|
2927
|
+
return fail(AbiStatus::InvalidArgument, "geometry topology command or payload range is invalid");
|
|
2928
|
+
}
|
|
2929
|
+
if (std::holds_alternative<CreateBodyCommand>(command)
|
|
2930
|
+
|| std::holds_alternative<CreateJointCommand>(command)
|
|
2931
|
+
|| std::holds_alternative<CreateFluidCommand>(command)) {
|
|
2932
|
+
maximumResults += kWorldTopologyResultStride;
|
|
2933
|
+
}
|
|
2934
|
+
parsed.push_back(std::move(command));
|
|
2935
|
+
}
|
|
2936
|
+
if (payloadEnd != geometry_value_count) {
|
|
2937
|
+
return fail(AbiStatus::InvalidArgument, "geometry topology payload or output ranges are invalid");
|
|
2938
|
+
}
|
|
2939
|
+
return withWorld(handle, [&](World& world) {
|
|
2940
|
+
if (header_capacity_values < kTopologyEditHeaderWords) {
|
|
2941
|
+
return fail(AbiStatus::ShortBuffer, "topology edit header is short");
|
|
2942
|
+
}
|
|
2943
|
+
if (header_capacity_values > kTopologyEditHeaderWords) {
|
|
2944
|
+
return fail(AbiStatus::InvalidArgument, "topology edit header length is invalid");
|
|
2945
|
+
}
|
|
2946
|
+
if (created_capacity_values < maximumResults) {
|
|
2947
|
+
*requiredView.data() = maximumResults;
|
|
2948
|
+
return fail(AbiStatus::ShortBuffer, "topology edit output is short");
|
|
2949
|
+
}
|
|
2950
|
+
std::uint64_t serial = 0;
|
|
2951
|
+
const auto prepared = world.prepareTopologyEdit(
|
|
2952
|
+
parsed, joinU64(expected_revision_lo, expected_revision_hi), serial);
|
|
2953
|
+
if (!prepared.ok()) return fail(prepared);
|
|
2954
|
+
std::span<const BodyId> removedBodies;
|
|
2955
|
+
std::span<const JointId> removedJoints;
|
|
2956
|
+
std::span<const FluidId> removedFluids;
|
|
2957
|
+
std::span<const CreatedBodyIdentity> createdBodies;
|
|
2958
|
+
std::span<const CreatedJointIdentity> createdJoints;
|
|
2959
|
+
std::span<const CreatedFluidIdentity> createdFluids;
|
|
2960
|
+
const bool removedOk = world.readTopologyEditRemoved(serial, removedBodies, removedJoints, removedFluids);
|
|
2961
|
+
const bool createdOk = world.readTopologyEditCreated(serial, createdBodies, createdJoints, createdFluids);
|
|
2962
|
+
const bool countsFit = removedBodies.size() <= std::numeric_limits<std::uint32_t>::max()
|
|
2963
|
+
&& removedJoints.size() <= std::numeric_limits<std::uint32_t>::max()
|
|
2964
|
+
&& removedFluids.size() <= std::numeric_limits<std::uint32_t>::max();
|
|
2965
|
+
if (!removedOk || !createdOk || !countsFit) {
|
|
2966
|
+
world.abandonTopologyEdit(serial);
|
|
2967
|
+
return fail(AbiStatus::InvalidArgument, "plan removed records are invalid");
|
|
2968
|
+
}
|
|
2969
|
+
std::uint32_t written = 0;
|
|
2970
|
+
const auto writeCreated = [&](std::uint32_t kind, std::uint32_t temp, std::uint64_t id) {
|
|
2971
|
+
createdView.data()[written] = kind;
|
|
2972
|
+
createdView.data()[written + 1] = temp;
|
|
2973
|
+
splitU64(id, createdView.data() + written + 2);
|
|
2974
|
+
written += kWorldTopologyResultStride;
|
|
2975
|
+
};
|
|
2976
|
+
for (const auto& body : createdBodies) writeCreated(1, body.temp.value, body.id.value);
|
|
2977
|
+
for (const auto& joint : createdJoints) writeCreated(2, joint.temp.value, joint.id.value);
|
|
2978
|
+
for (const auto& fluid : createdFluids) writeCreated(3, fluid.temp.value, fluid.id.value);
|
|
2979
|
+
*requiredView.data() = written;
|
|
2980
|
+
auto* header = headerView.data();
|
|
2981
|
+
header[0] = kTopologyEditHeaderFormatVersion;
|
|
2982
|
+
splitU64(serial, header + 1);
|
|
2983
|
+
splitU64(world.mutationRevision(), header + 3);
|
|
2984
|
+
splitU64(world.restoreEpoch(), header + 5);
|
|
2985
|
+
header[7] = static_cast<std::uint32_t>(removedBodies.size());
|
|
2986
|
+
header[8] = static_cast<std::uint32_t>(removedJoints.size());
|
|
2987
|
+
header[9] = static_cast<std::uint32_t>(removedFluids.size());
|
|
2988
|
+
return status(AbiStatus::Ok);
|
|
2989
|
+
});
|
|
2990
|
+
});
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
extern "C" std::int32_t rundot_kinetix_world_copy_topology_edit_removed(
|
|
2994
|
+
std::uint32_t handle, std::uint32_t serial_lo, std::uint32_t serial_hi,
|
|
2995
|
+
std::uint32_t* out, std::uint32_t capacity_values) noexcept {
|
|
2996
|
+
return guard([&]() {
|
|
2997
|
+
clearError();
|
|
2998
|
+
using namespace rundot::kinetix::physics;
|
|
2999
|
+
CallerRange ranges[1];
|
|
3000
|
+
if (!fillCountedRange(ranges[0], out, capacity_values, sizeof(std::uint32_t),
|
|
3001
|
+
alignof(std::uint32_t), RangeRole::Output)) {
|
|
3002
|
+
return fail(AbiStatus::InvalidArgument, "topology range is outside the address space");
|
|
984
3003
|
}
|
|
3004
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3005
|
+
Pins3D pins;
|
|
3006
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3007
|
+
auto outputView = pins.view<std::uint32_t>(0);
|
|
3008
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3009
|
+
const auto serial = joinU64(serial_lo, serial_hi);
|
|
985
3010
|
return withWorld(handle, [&](World& world) {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
3011
|
+
std::span<const BodyId> bodies;
|
|
3012
|
+
std::span<const JointId> joints;
|
|
3013
|
+
std::span<const FluidId> fluids;
|
|
3014
|
+
if (!world.readTopologyEditRemoved(serial, bodies, joints, fluids)) {
|
|
3015
|
+
return fail(WorldError{WorldErrorCode::TopologyPlanNotFound, "no plan"});
|
|
3016
|
+
}
|
|
3017
|
+
const auto count = static_cast<std::uint64_t>(bodies.size()) + joints.size() + fluids.size();
|
|
3018
|
+
if (count > std::numeric_limits<std::uint32_t>::max() / kTopologyEditRemovedRecordWords) {
|
|
3019
|
+
return fail(AbiStatus::InvalidArgument, "removed record count is invalid");
|
|
3020
|
+
}
|
|
3021
|
+
const auto exact = static_cast<std::uint32_t>(count * kTopologyEditRemovedRecordWords);
|
|
3022
|
+
if (capacity_values < exact) return fail(AbiStatus::ShortBuffer, "removed output is short");
|
|
3023
|
+
if (capacity_values > exact) return fail(AbiStatus::InvalidArgument, "removed output length is invalid");
|
|
3024
|
+
if (exact == 0) return status(AbiStatus::Ok);
|
|
3025
|
+
auto* cursor = outputView.data();
|
|
3026
|
+
const auto write = [&](std::uint32_t kind, std::uint64_t id) {
|
|
3027
|
+
cursor[0] = kind;
|
|
3028
|
+
cursor[1] = 0;
|
|
3029
|
+
splitU64(id, cursor + 2);
|
|
3030
|
+
cursor += kTopologyEditRemovedRecordWords;
|
|
3031
|
+
};
|
|
3032
|
+
for (const auto id : bodies) write(kTopologyEditRemovedKindBody, id.value);
|
|
3033
|
+
for (const auto id : joints) write(kTopologyEditRemovedKindJoint, id.value);
|
|
3034
|
+
for (const auto id : fluids) write(kTopologyEditRemovedKindFluid, id.value);
|
|
991
3035
|
return status(AbiStatus::Ok);
|
|
992
3036
|
});
|
|
993
3037
|
});
|
|
994
3038
|
}
|
|
995
3039
|
|
|
3040
|
+
extern "C" std::int32_t rundot_kinetix_world_commit_topology_edit(
|
|
3041
|
+
std::uint32_t handle, std::uint32_t serial_lo, std::uint32_t serial_hi,
|
|
3042
|
+
std::uint32_t revision_lo, std::uint32_t revision_hi) noexcept {
|
|
3043
|
+
return guard([&]() {
|
|
3044
|
+
clearError();
|
|
3045
|
+
return withWorld(handle, [&](World& world) {
|
|
3046
|
+
const auto committed = world.commitTopologyEdit(
|
|
3047
|
+
joinU64(serial_lo, serial_hi), joinU64(revision_lo, revision_hi), nullptr);
|
|
3048
|
+
return committed.ok() ? status(AbiStatus::Ok) : fail(committed);
|
|
3049
|
+
});
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3052
|
+
|
|
3053
|
+
extern "C" std::int32_t rundot_kinetix_world_abandon_topology_edit(
|
|
3054
|
+
std::uint32_t handle, std::uint32_t serial_lo, std::uint32_t serial_hi) noexcept {
|
|
3055
|
+
return guard([&]() {
|
|
3056
|
+
clearError();
|
|
3057
|
+
return withWorld(handle, [&](World& world) {
|
|
3058
|
+
const auto abandoned = world.abandonTopologyEdit(joinU64(serial_lo, serial_hi));
|
|
3059
|
+
return abandoned.ok() ? status(AbiStatus::Ok) : fail(abandoned);
|
|
3060
|
+
});
|
|
3061
|
+
});
|
|
3062
|
+
}
|
|
3063
|
+
|
|
996
3064
|
extern "C" std::int32_t rundot_kinetix_world_copy_topology(
|
|
997
3065
|
std::uint32_t handle,
|
|
998
3066
|
std::uint32_t* body_ids,
|
|
999
3067
|
std::uint32_t body_id_capacity_values,
|
|
1000
3068
|
std::uint32_t* joint_identities,
|
|
1001
|
-
std::uint32_t joint_identity_capacity_values
|
|
3069
|
+
std::uint32_t joint_identity_capacity_values,
|
|
3070
|
+
std::uint32_t* fluid_ids,
|
|
3071
|
+
std::uint32_t fluid_id_capacity_values) noexcept {
|
|
1002
3072
|
return guard([&]() {
|
|
1003
3073
|
clearError();
|
|
3074
|
+
bool rangeOverflow = false;
|
|
3075
|
+
const CallerRange ranges[] = {
|
|
3076
|
+
countedCallerRange(body_ids, body_id_capacity_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3077
|
+
countedCallerRange(joint_identities, joint_identity_capacity_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3078
|
+
countedCallerRange(fluid_ids, fluid_id_capacity_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3079
|
+
};
|
|
3080
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3081
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3082
|
+
Pins3D pins;
|
|
3083
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3084
|
+
auto bodyIdsView = pins.view<std::uint32_t>(0);
|
|
3085
|
+
auto jointIdentitiesView = pins.view<std::uint32_t>(1);
|
|
3086
|
+
auto fluidIdsView = pins.view<std::uint32_t>(2);
|
|
3087
|
+
if (!bodyIdsView || !jointIdentitiesView || !fluidIdsView) {
|
|
3088
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3089
|
+
}
|
|
3090
|
+
|
|
1004
3091
|
return withWorld(handle, [&](World& world) {
|
|
1005
3092
|
const auto& topology = world.topology();
|
|
1006
3093
|
const std::size_t requiredBodyValues = topology.bodyIds.size()
|
|
1007
3094
|
* rundot::kinetix::physics::kWorldTopologyBodyIdStride;
|
|
1008
3095
|
const std::size_t requiredJointValues = topology.joints.size()
|
|
1009
3096
|
* rundot::kinetix::physics::kWorldTopologyJointIdentityStride;
|
|
3097
|
+
const std::size_t requiredFluidValues = topology.fluidIds.size()
|
|
3098
|
+
* rundot::kinetix::physics::kWorldTopologyFluidIdStride;
|
|
1010
3099
|
if (body_id_capacity_values < requiredBodyValues
|
|
1011
|
-
|| joint_identity_capacity_values < requiredJointValues
|
|
3100
|
+
|| joint_identity_capacity_values < requiredJointValues
|
|
3101
|
+
|| fluid_id_capacity_values < requiredFluidValues) {
|
|
1012
3102
|
return fail(AbiStatus::ShortBuffer, "topology identity output buffer is too small");
|
|
1013
3103
|
}
|
|
1014
|
-
if ((requiredBodyValues != 0 && body_ids == nullptr)
|
|
1015
|
-
|| (requiredJointValues != 0 && joint_identities == nullptr)) {
|
|
1016
|
-
return fail(AbiStatus::InvalidArgument, "topology identity output pointer is missing");
|
|
1017
|
-
}
|
|
1018
|
-
std::array<OutputRange, 2> ranges{};
|
|
1019
|
-
if (!outputRange(body_ids, requiredBodyValues * sizeof(std::uint32_t), ranges[0])
|
|
1020
|
-
|| !outputRange(joint_identities, requiredJointValues * sizeof(std::uint32_t), ranges[1])) {
|
|
1021
|
-
return fail(AbiStatus::InvalidArgument, "topology identity output range is invalid");
|
|
1022
|
-
}
|
|
1023
|
-
if (!disjointOutputRanges(ranges)) {
|
|
1024
|
-
return fail(AbiStatus::InvalidArgument, "topology identity output buffers overlap");
|
|
1025
|
-
}
|
|
1026
3104
|
for (std::size_t index = 0; index < topology.bodyIds.size(); ++index) {
|
|
1027
|
-
splitU64(topology.bodyIds[index].value,
|
|
3105
|
+
splitU64(topology.bodyIds[index].value, bodyIdsView.data() + index * 2);
|
|
1028
3106
|
}
|
|
1029
3107
|
for (std::size_t index = 0; index < topology.joints.size(); ++index) {
|
|
1030
3108
|
const auto& joint = topology.joints[index];
|
|
1031
|
-
std::uint32_t* output =
|
|
3109
|
+
std::uint32_t* output = jointIdentitiesView.data() + index * 6;
|
|
1032
3110
|
splitU64(joint.id.value, output);
|
|
1033
3111
|
splitU64(joint.bodyA.value, output + 2);
|
|
1034
3112
|
splitU64(joint.bodyB.value, output + 4);
|
|
1035
3113
|
}
|
|
3114
|
+
for (std::size_t index = 0; index < topology.fluidIds.size(); ++index) {
|
|
3115
|
+
splitU64(topology.fluidIds[index].value, fluidIdsView.data() + index * 2);
|
|
3116
|
+
}
|
|
1036
3117
|
return status(AbiStatus::Ok);
|
|
1037
3118
|
});
|
|
1038
3119
|
});
|
|
@@ -1066,6 +3147,21 @@ extern "C" std::int32_t rundot_kinetix_world_joint_exists(
|
|
|
1066
3147
|
});
|
|
1067
3148
|
}
|
|
1068
3149
|
|
|
3150
|
+
extern "C" std::int32_t rundot_kinetix_world_fluid_exists(
|
|
3151
|
+
std::uint32_t handle,
|
|
3152
|
+
std::uint32_t id_low,
|
|
3153
|
+
std::uint32_t id_high) noexcept {
|
|
3154
|
+
return guard([&]() {
|
|
3155
|
+
clearError();
|
|
3156
|
+
return withWorld(handle, [&](World& world) {
|
|
3157
|
+
rundot::kinetix::physics::FluidHandle ignored;
|
|
3158
|
+
const WorldError result = world.resolveFluid(
|
|
3159
|
+
FluidId{joinU64(id_low, id_high)}, ignored);
|
|
3160
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
3161
|
+
});
|
|
3162
|
+
});
|
|
3163
|
+
}
|
|
3164
|
+
|
|
1069
3165
|
extern "C" std::int32_t rundot_kinetix_world_read_body(
|
|
1070
3166
|
std::uint32_t handle,
|
|
1071
3167
|
std::uint32_t id_low,
|
|
@@ -1074,7 +3170,18 @@ extern "C" std::int32_t rundot_kinetix_world_read_body(
|
|
|
1074
3170
|
std::uint32_t output_values) noexcept {
|
|
1075
3171
|
return guard([&]() {
|
|
1076
3172
|
clearError();
|
|
1077
|
-
|
|
3173
|
+
bool rangeOverflow = false;
|
|
3174
|
+
const CallerRange ranges[] = {
|
|
3175
|
+
countedCallerRange(output, output_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
3176
|
+
};
|
|
3177
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3178
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3179
|
+
Pins3D pins;
|
|
3180
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3181
|
+
auto outputView = pins.view<double>(0);
|
|
3182
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3183
|
+
|
|
3184
|
+
if (output_values < rundot::kinetix::physics::kBodyStride) {
|
|
1078
3185
|
return fail(AbiStatus::ShortBuffer, "body read needs one body record");
|
|
1079
3186
|
}
|
|
1080
3187
|
return withWorld(handle, [&](World& world) {
|
|
@@ -1082,7 +3189,7 @@ extern "C" std::int32_t rundot_kinetix_world_read_body(
|
|
|
1082
3189
|
const WorldError result = world.readBody(
|
|
1083
3190
|
BodyId{joinU64(id_low, id_high)}, values);
|
|
1084
3191
|
if (!result.ok()) return fail(result);
|
|
1085
|
-
std::copy(values.begin(), values.end(),
|
|
3192
|
+
std::copy(values.begin(), values.end(), outputView.data());
|
|
1086
3193
|
return status(AbiStatus::Ok);
|
|
1087
3194
|
});
|
|
1088
3195
|
});
|
|
@@ -1099,28 +3206,69 @@ extern "C" std::int32_t rundot_kinetix_world_read_joint(
|
|
|
1099
3206
|
return guard([&]() {
|
|
1100
3207
|
clearError();
|
|
1101
3208
|
using namespace rundot::kinetix::physics;
|
|
1102
|
-
|
|
1103
|
-
|
|
3209
|
+
bool rangeOverflow = false;
|
|
3210
|
+
const CallerRange ranges[] = {
|
|
3211
|
+
countedCallerRange(output, output_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
3212
|
+
countedCallerRange(endpoint_ids, endpoint_id_values, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3213
|
+
};
|
|
3214
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3215
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3216
|
+
Pins3D pins;
|
|
3217
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3218
|
+
auto outputView = pins.view<double>(0);
|
|
3219
|
+
auto endpointIdsView = pins.view<std::uint32_t>(1);
|
|
3220
|
+
if (!outputView || !endpointIdsView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3221
|
+
|
|
3222
|
+
if (output_values < kJointStride || endpoint_id_values < 4) {
|
|
1104
3223
|
return fail(AbiStatus::ShortBuffer,
|
|
1105
3224
|
"joint read needs one joint record and four endpoint ID values");
|
|
1106
3225
|
}
|
|
1107
|
-
OutputRange recordRange;
|
|
1108
|
-
OutputRange endpointRange;
|
|
1109
|
-
if (!outputRange(output, kJointStride * sizeof(double), recordRange)
|
|
1110
|
-
|| !outputRange(endpoint_ids, 4 * sizeof(std::uint32_t), endpointRange)
|
|
1111
|
-
|| !disjointOutputRanges(std::array{recordRange, endpointRange})) {
|
|
1112
|
-
return fail(AbiStatus::InvalidArgument, "joint read output buffers overlap");
|
|
1113
|
-
}
|
|
1114
3226
|
return withWorld(handle, [&](World& world) {
|
|
1115
|
-
|
|
3227
|
+
JointRecord record;
|
|
1116
3228
|
BodyId bodyA;
|
|
1117
3229
|
BodyId bodyB;
|
|
1118
3230
|
const WorldError result = world.readJoint(
|
|
1119
|
-
JointId{joinU64(id_low, id_high)},
|
|
3231
|
+
JointId{joinU64(id_low, id_high)}, record, bodyA, bodyB);
|
|
3232
|
+
if (!result.ok()) return fail(result);
|
|
3233
|
+
const auto values = record.values();
|
|
3234
|
+
if (output_values < values.size()) return fail(AbiStatus::ShortBuffer, "joint read buffer cannot hold the full joint record");
|
|
3235
|
+
std::copy(values.begin(), values.end(), outputView.data());
|
|
3236
|
+
splitU64(bodyA.value, endpointIdsView.data());
|
|
3237
|
+
splitU64(bodyB.value, endpointIdsView.data() + 2);
|
|
3238
|
+
return status(AbiStatus::Ok);
|
|
3239
|
+
});
|
|
3240
|
+
});
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
extern "C" std::int32_t rundot_kinetix_world_read_fluid(
|
|
3244
|
+
std::uint32_t handle,
|
|
3245
|
+
std::uint32_t id_low,
|
|
3246
|
+
std::uint32_t id_high,
|
|
3247
|
+
double* output,
|
|
3248
|
+
std::uint32_t output_values) noexcept {
|
|
3249
|
+
return guard([&]() {
|
|
3250
|
+
clearError();
|
|
3251
|
+
bool rangeOverflow = false;
|
|
3252
|
+
const CallerRange ranges[] = {
|
|
3253
|
+
countedCallerRange(output, output_values, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
3254
|
+
};
|
|
3255
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3256
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3257
|
+
Pins3D pins;
|
|
3258
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3259
|
+
auto outputView = pins.view<double>(0);
|
|
3260
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3261
|
+
|
|
3262
|
+
if (output_values < rundot::kinetix::physics::kFluidStride) {
|
|
3263
|
+
return fail(AbiStatus::ShortBuffer,
|
|
3264
|
+
"fluid read needs one fluid record");
|
|
3265
|
+
}
|
|
3266
|
+
return withWorld(handle, [&](World& world) {
|
|
3267
|
+
std::array<double, rundot::kinetix::physics::kFluidStride> values{};
|
|
3268
|
+
const WorldError result = world.readFluid(
|
|
3269
|
+
FluidId{joinU64(id_low, id_high)}, values);
|
|
1120
3270
|
if (!result.ok()) return fail(result);
|
|
1121
|
-
std::copy(values.begin(), values.end(),
|
|
1122
|
-
splitU64(bodyA.value, endpoint_ids);
|
|
1123
|
-
splitU64(bodyB.value, endpoint_ids + 2);
|
|
3271
|
+
std::copy(values.begin(), values.end(), outputView.data());
|
|
1124
3272
|
return status(AbiStatus::Ok);
|
|
1125
3273
|
});
|
|
1126
3274
|
});
|
|
@@ -1131,12 +3279,17 @@ extern "C" std::int32_t rundot_kinetix_world_contact_output_info(
|
|
|
1131
3279
|
std::uint32_t* output_count) noexcept {
|
|
1132
3280
|
return guard([&]() {
|
|
1133
3281
|
clearError();
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
3282
|
+
const CallerRange ranges[] = {
|
|
3283
|
+
{output_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3284
|
+
};
|
|
3285
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3286
|
+
Pins3D pins;
|
|
3287
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3288
|
+
auto outputCountView = pins.view<std::uint32_t>(0);
|
|
3289
|
+
if (!outputCountView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3290
|
+
|
|
1138
3291
|
return withWorld(handle, [&](World& world) {
|
|
1139
|
-
*
|
|
3292
|
+
*outputCountView.data() = static_cast<std::uint32_t>(world.latestContacts().size());
|
|
1140
3293
|
return status(AbiStatus::Ok);
|
|
1141
3294
|
});
|
|
1142
3295
|
});
|
|
@@ -1151,6 +3304,19 @@ extern "C" std::int32_t rundot_kinetix_world_copy_contact_output(
|
|
|
1151
3304
|
return guard([&]() {
|
|
1152
3305
|
clearError();
|
|
1153
3306
|
using namespace rundot::kinetix::physics;
|
|
3307
|
+
bool rangeOverflow = false;
|
|
3308
|
+
const CallerRange ranges[] = {
|
|
3309
|
+
countedCallerRange(values, value_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
3310
|
+
countedCallerRange(metadata, metadata_capacity, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3311
|
+
};
|
|
3312
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3313
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3314
|
+
Pins3D pins;
|
|
3315
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3316
|
+
auto valuesView = pins.view<double>(0);
|
|
3317
|
+
auto metadataView = pins.view<std::uint32_t>(1);
|
|
3318
|
+
if (!valuesView || !metadataView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3319
|
+
|
|
1154
3320
|
return withWorld(handle, [&](World& world) {
|
|
1155
3321
|
const std::vector<WorldContactEvent>& events = world.latestContacts();
|
|
1156
3322
|
const std::uint64_t requiredValues = static_cast<std::uint64_t>(events.size())
|
|
@@ -1161,38 +3327,25 @@ extern "C" std::int32_t rundot_kinetix_world_copy_contact_output(
|
|
|
1161
3327
|
return fail(AbiStatus::ShortBuffer,
|
|
1162
3328
|
"contact output buffer is too small");
|
|
1163
3329
|
}
|
|
1164
|
-
if ((!events.empty() && values == nullptr)
|
|
1165
|
-
|| (!events.empty() && metadata == nullptr)) {
|
|
1166
|
-
return fail(AbiStatus::InvalidArgument,
|
|
1167
|
-
"contact output pointer is missing");
|
|
1168
|
-
}
|
|
1169
|
-
OutputRange valueRange;
|
|
1170
|
-
OutputRange metadataRange;
|
|
1171
|
-
if (!outputRange(values, requiredValues * sizeof(double), valueRange)
|
|
1172
|
-
|| !outputRange(metadata, requiredMetadata * sizeof(std::uint32_t),
|
|
1173
|
-
metadataRange)
|
|
1174
|
-
|| !disjointOutputRanges(std::array{valueRange, metadataRange})) {
|
|
1175
|
-
return fail(AbiStatus::InvalidArgument,
|
|
1176
|
-
"contact output buffers overlap");
|
|
1177
|
-
}
|
|
1178
3330
|
for (std::size_t index = 0; index < events.size(); ++index) {
|
|
1179
3331
|
const WorldContactEvent& event = events[index];
|
|
1180
3332
|
const std::size_t valueOffset = index * kWorldContactOutputValueStride;
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
3333
|
+
valuesView.data()[valueOffset] = event.normalImpulse;
|
|
3334
|
+
valuesView.data()[valueOffset + 1] = event.tangentImpulse1;
|
|
3335
|
+
valuesView.data()[valueOffset + 2] = event.tangentImpulse2;
|
|
3336
|
+
valuesView.data()[valueOffset + 3] = event.point[0];
|
|
3337
|
+
valuesView.data()[valueOffset + 4] = event.point[1];
|
|
3338
|
+
valuesView.data()[valueOffset + 5] = event.point[2];
|
|
3339
|
+
valuesView.data()[valueOffset + 6] = event.normal[0];
|
|
3340
|
+
valuesView.data()[valueOffset + 7] = event.normal[1];
|
|
3341
|
+
valuesView.data()[valueOffset + 8] = event.normal[2];
|
|
3342
|
+
valuesView.data()[valueOffset + 9] = event.penetration;
|
|
3343
|
+
valuesView.data()[valueOffset + 10] = event.closingSpeed;
|
|
1191
3344
|
const std::size_t metadataOffset = index * kWorldContactOutputMetadataStride;
|
|
1192
|
-
|
|
1193
|
-
splitU64(event.bodyA.value,
|
|
1194
|
-
splitU64(event.bodyB.value,
|
|
1195
|
-
|
|
3345
|
+
metadataView.data()[metadataOffset] = static_cast<std::uint32_t>(event.type);
|
|
3346
|
+
splitU64(event.bodyA.value, metadataView.data() + metadataOffset + 1);
|
|
3347
|
+
splitU64(event.bodyB.value, metadataView.data() + metadataOffset + 3);
|
|
3348
|
+
metadataView.data()[metadataOffset + 5] = (event.trigger ? 1u : 0u)
|
|
1196
3349
|
| (event.sensor ? 2u : 0u);
|
|
1197
3350
|
}
|
|
1198
3351
|
return status(AbiStatus::Ok);
|
|
@@ -1200,6 +3353,180 @@ extern "C" std::int32_t rundot_kinetix_world_copy_contact_output(
|
|
|
1200
3353
|
});
|
|
1201
3354
|
}
|
|
1202
3355
|
|
|
3356
|
+
extern "C" std::int32_t rundot_kinetix_world_joint_output_info(
|
|
3357
|
+
std::uint32_t handle,
|
|
3358
|
+
std::uint32_t* reaction_count,
|
|
3359
|
+
std::uint32_t* break_count) noexcept {
|
|
3360
|
+
return guard([&]() {
|
|
3361
|
+
clearError();
|
|
3362
|
+
const CallerRange ranges[] = {
|
|
3363
|
+
{reaction_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3364
|
+
{break_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3365
|
+
};
|
|
3366
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3367
|
+
Pins3D pins;
|
|
3368
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3369
|
+
auto reactionCountView = pins.view<std::uint32_t>(0);
|
|
3370
|
+
auto breakCountView = pins.view<std::uint32_t>(1);
|
|
3371
|
+
if (!reactionCountView || !breakCountView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3372
|
+
|
|
3373
|
+
return withWorld(handle, [&](World& world) {
|
|
3374
|
+
*reactionCountView.data() = static_cast<std::uint32_t>(
|
|
3375
|
+
world.latestJointReactions().size());
|
|
3376
|
+
*breakCountView.data() = static_cast<std::uint32_t>(
|
|
3377
|
+
world.latestJointBreaks().size());
|
|
3378
|
+
return status(AbiStatus::Ok);
|
|
3379
|
+
});
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
extern "C" std::int32_t rundot_kinetix_world_copy_joint_output(
|
|
3384
|
+
std::uint32_t handle,
|
|
3385
|
+
double* reaction_values,
|
|
3386
|
+
std::uint32_t reaction_value_capacity,
|
|
3387
|
+
std::uint32_t* reaction_metadata,
|
|
3388
|
+
std::uint32_t reaction_metadata_capacity,
|
|
3389
|
+
std::uint32_t* break_metadata,
|
|
3390
|
+
std::uint32_t break_metadata_capacity) noexcept {
|
|
3391
|
+
return guard([&]() {
|
|
3392
|
+
clearError();
|
|
3393
|
+
using namespace rundot::kinetix::physics;
|
|
3394
|
+
bool rangeOverflow = false;
|
|
3395
|
+
const CallerRange ranges[] = {
|
|
3396
|
+
countedCallerRange(reaction_values, reaction_value_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
3397
|
+
countedCallerRange(reaction_metadata, reaction_metadata_capacity, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3398
|
+
countedCallerRange(break_metadata, break_metadata_capacity, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3399
|
+
};
|
|
3400
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3401
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3402
|
+
Pins3D pins;
|
|
3403
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3404
|
+
auto reactionValuesView = pins.view<double>(0);
|
|
3405
|
+
auto reactionMetadataView = pins.view<std::uint32_t>(1);
|
|
3406
|
+
auto breakMetadataView = pins.view<std::uint32_t>(2);
|
|
3407
|
+
if (!reactionValuesView || !reactionMetadataView || !breakMetadataView) {
|
|
3408
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3409
|
+
}
|
|
3410
|
+
|
|
3411
|
+
return withWorld(handle, [&](World& world) {
|
|
3412
|
+
const std::vector<WorldJointReaction>& reactions =
|
|
3413
|
+
world.latestJointReactions();
|
|
3414
|
+
const std::vector<WorldJointBreakEvent>& breaks =
|
|
3415
|
+
world.latestJointBreaks();
|
|
3416
|
+
const std::uint64_t requiredValues = reactions.size()
|
|
3417
|
+
* kWorldJointReactionValueStride;
|
|
3418
|
+
const std::uint64_t requiredReactionMetadata = reactions.size()
|
|
3419
|
+
* kWorldJointReactionMetadataStride;
|
|
3420
|
+
const std::uint64_t requiredBreakMetadata = breaks.size()
|
|
3421
|
+
* kWorldJointBreakMetadataStride;
|
|
3422
|
+
if (reaction_value_capacity < requiredValues
|
|
3423
|
+
|| reaction_metadata_capacity < requiredReactionMetadata
|
|
3424
|
+
|| break_metadata_capacity < requiredBreakMetadata) {
|
|
3425
|
+
return fail(AbiStatus::ShortBuffer,
|
|
3426
|
+
"joint output buffer is too small");
|
|
3427
|
+
}
|
|
3428
|
+
for (std::size_t index = 0; index < reactions.size(); ++index) {
|
|
3429
|
+
const WorldJointReaction& reaction = reactions[index];
|
|
3430
|
+
const std::size_t valueOffset = index * kWorldJointReactionValueStride;
|
|
3431
|
+
for (std::uint32_t axis = 0; axis < 3; ++axis) {
|
|
3432
|
+
reactionValuesView.data()[valueOffset + axis] = reaction.force[axis];
|
|
3433
|
+
reactionValuesView.data()[valueOffset + 3 + axis] = reaction.torque[axis];
|
|
3434
|
+
}
|
|
3435
|
+
const std::size_t metadataOffset = index
|
|
3436
|
+
* kWorldJointReactionMetadataStride;
|
|
3437
|
+
splitU64(reaction.joint.value, reactionMetadataView.data() + metadataOffset);
|
|
3438
|
+
splitU64(reaction.bodyA.value, reactionMetadataView.data() + metadataOffset + 2);
|
|
3439
|
+
splitU64(reaction.bodyB.value, reactionMetadataView.data() + metadataOffset + 4);
|
|
3440
|
+
}
|
|
3441
|
+
for (std::size_t index = 0; index < breaks.size(); ++index) {
|
|
3442
|
+
const std::size_t metadataOffset = index * kWorldJointBreakMetadataStride;
|
|
3443
|
+
splitU64(breaks[index].joint.value, breakMetadataView.data() + metadataOffset);
|
|
3444
|
+
breakMetadataView.data()[metadataOffset + 2] = breaks[index].reasonBits;
|
|
3445
|
+
}
|
|
3446
|
+
return status(AbiStatus::Ok);
|
|
3447
|
+
});
|
|
3448
|
+
});
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
extern "C" std::int32_t rundot_kinetix_world_fluid_interaction_info(
|
|
3452
|
+
std::uint32_t handle,
|
|
3453
|
+
std::uint32_t* output_count) noexcept {
|
|
3454
|
+
return guard([&]() {
|
|
3455
|
+
clearError();
|
|
3456
|
+
const CallerRange ranges[] = {
|
|
3457
|
+
{output_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3458
|
+
};
|
|
3459
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3460
|
+
Pins3D pins;
|
|
3461
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3462
|
+
auto outputCountView = pins.view<std::uint32_t>(0);
|
|
3463
|
+
if (!outputCountView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3464
|
+
|
|
3465
|
+
return withWorld(handle, [&](World& world) {
|
|
3466
|
+
*outputCountView.data() = static_cast<std::uint32_t>(
|
|
3467
|
+
world.latestFluidInteractions().size());
|
|
3468
|
+
return status(AbiStatus::Ok);
|
|
3469
|
+
});
|
|
3470
|
+
});
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
extern "C" std::int32_t rundot_kinetix_world_copy_fluid_interactions(
|
|
3474
|
+
std::uint32_t handle,
|
|
3475
|
+
double* values,
|
|
3476
|
+
std::uint32_t value_capacity,
|
|
3477
|
+
std::uint32_t* metadata,
|
|
3478
|
+
std::uint32_t metadata_capacity) noexcept {
|
|
3479
|
+
return guard([&]() {
|
|
3480
|
+
clearError();
|
|
3481
|
+
using namespace rundot::kinetix::physics;
|
|
3482
|
+
bool rangeOverflow = false;
|
|
3483
|
+
const CallerRange ranges[] = {
|
|
3484
|
+
countedCallerRange(values, value_capacity, sizeof(double), alignof(double), RangeRole::Output, rangeOverflow),
|
|
3485
|
+
countedCallerRange(metadata, metadata_capacity, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output, rangeOverflow),
|
|
3486
|
+
};
|
|
3487
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3488
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3489
|
+
Pins3D pins;
|
|
3490
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3491
|
+
auto valuesView = pins.view<double>(0);
|
|
3492
|
+
auto metadataView = pins.view<std::uint32_t>(1);
|
|
3493
|
+
if (!valuesView || !metadataView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3494
|
+
|
|
3495
|
+
return withWorld(handle, [&](World& world) {
|
|
3496
|
+
const auto& interactions = world.latestFluidInteractions();
|
|
3497
|
+
const std::uint64_t requiredValues = interactions.size()
|
|
3498
|
+
* kWorldFluidInteractionValueStride;
|
|
3499
|
+
const std::uint64_t requiredMetadata = interactions.size()
|
|
3500
|
+
* kWorldFluidInteractionMetadataStride;
|
|
3501
|
+
if (value_capacity < requiredValues
|
|
3502
|
+
|| metadata_capacity < requiredMetadata) {
|
|
3503
|
+
return fail(AbiStatus::ShortBuffer,
|
|
3504
|
+
"fluid interaction buffer is too small");
|
|
3505
|
+
}
|
|
3506
|
+
for (std::size_t index = 0; index < interactions.size(); ++index) {
|
|
3507
|
+
const auto& interaction = interactions[index];
|
|
3508
|
+
const std::size_t valueOffset = index
|
|
3509
|
+
* kWorldFluidInteractionValueStride;
|
|
3510
|
+
valuesView.data()[valueOffset] = interaction.submergedVolume;
|
|
3511
|
+
std::copy(interaction.centerOfBuoyancy.begin(),
|
|
3512
|
+
interaction.centerOfBuoyancy.end(), valuesView.data() + valueOffset + 1);
|
|
3513
|
+
std::copy(interaction.totalForce.begin(),
|
|
3514
|
+
interaction.totalForce.end(), valuesView.data() + valueOffset + 4);
|
|
3515
|
+
std::copy(interaction.totalTorque.begin(),
|
|
3516
|
+
interaction.totalTorque.end(), valuesView.data() + valueOffset + 7);
|
|
3517
|
+
std::copy(interaction.relativeVelocity.begin(),
|
|
3518
|
+
interaction.relativeVelocity.end(), valuesView.data() + valueOffset + 10);
|
|
3519
|
+
const std::size_t metadataOffset = index
|
|
3520
|
+
* kWorldFluidInteractionMetadataStride;
|
|
3521
|
+
splitU64(interaction.body.value, metadataView.data() + metadataOffset);
|
|
3522
|
+
splitU64(interaction.fluid.value, metadataView.data() + metadataOffset + 2);
|
|
3523
|
+
metadataView.data()[metadataOffset + 4] = interaction.shouldWake ? 1u : 0u;
|
|
3524
|
+
}
|
|
3525
|
+
return status(AbiStatus::Ok);
|
|
3526
|
+
});
|
|
3527
|
+
});
|
|
3528
|
+
}
|
|
3529
|
+
|
|
1203
3530
|
extern "C" std::int32_t rundot_kinetix_world_capture_snapshot(
|
|
1204
3531
|
std::uint32_t handle,
|
|
1205
3532
|
std::uint8_t* output,
|
|
@@ -1207,18 +3534,25 @@ extern "C" std::int32_t rundot_kinetix_world_capture_snapshot(
|
|
|
1207
3534
|
std::uint32_t* required_bytes) noexcept {
|
|
1208
3535
|
return guard([&]() {
|
|
1209
3536
|
clearError();
|
|
3537
|
+
bool rangeOverflow = false;
|
|
3538
|
+
const CallerRange ranges[] = {
|
|
3539
|
+
countedCallerRange(output, output_capacity, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Output, rangeOverflow),
|
|
3540
|
+
{required_bytes, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3541
|
+
};
|
|
3542
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3543
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3544
|
+
Pins3D pins;
|
|
3545
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3546
|
+
auto outputView = pins.view<std::uint8_t>(0);
|
|
3547
|
+
auto requiredBytesView = pins.view<std::uint32_t>(1);
|
|
3548
|
+
if (!outputView || !requiredBytesView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3549
|
+
|
|
1210
3550
|
return withWorld(handle, [&](World& world) {
|
|
1211
|
-
if (required_bytes == nullptr) return fail(AbiStatus::InvalidArgument, "snapshot size output is missing");
|
|
1212
3551
|
const World::Snapshot snapshot = world.captureSnapshot();
|
|
1213
3552
|
if (snapshot.empty()) {
|
|
1214
3553
|
return fail({WorldErrorCode::InvalidProfile, "world profile cannot produce a snapshot"});
|
|
1215
3554
|
}
|
|
1216
|
-
|
|
1217
|
-
if (output_capacity < snapshot.size() || output == nullptr) {
|
|
1218
|
-
return fail(AbiStatus::ShortBuffer, "snapshot output buffer is too small");
|
|
1219
|
-
}
|
|
1220
|
-
std::copy(snapshot.begin(), snapshot.end(), output);
|
|
1221
|
-
return status(AbiStatus::Ok);
|
|
3555
|
+
return publishSnapshotBytes(snapshot, outputView.data(), output_capacity, requiredBytesView.data());
|
|
1222
3556
|
});
|
|
1223
3557
|
});
|
|
1224
3558
|
}
|
|
@@ -1229,11 +3563,26 @@ extern "C" std::int32_t rundot_kinetix_world_import_snapshot(
|
|
|
1229
3563
|
std::uint32_t byte_count) noexcept {
|
|
1230
3564
|
return guard([&]() {
|
|
1231
3565
|
clearError();
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
3566
|
+
bool rangeOverflow = false;
|
|
3567
|
+
const CallerRange ranges[] = {
|
|
3568
|
+
countedCallerRange(bytes, byte_count, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input, rangeOverflow),
|
|
3569
|
+
};
|
|
3570
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3571
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3572
|
+
Pins3D pins;
|
|
3573
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3574
|
+
auto bytesView = pins.view<const std::uint8_t>(0);
|
|
3575
|
+
if (!bytesView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3576
|
+
|
|
3577
|
+
if (byte_count == 0) {
|
|
3578
|
+
return fail(AbiStatus::InvalidArgument, "snapshot input is empty or out of range");
|
|
3579
|
+
}
|
|
3580
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3581
|
+
if (control.world.isAttached()) {
|
|
3582
|
+
return fail(AbiStatus::WorldAttached, "cannot import snapshot into attached world");
|
|
1235
3583
|
}
|
|
1236
|
-
const WorldError result = world.importSnapshot(
|
|
3584
|
+
const WorldError result = control.world.importSnapshot(
|
|
3585
|
+
std::span<const std::uint8_t>(bytesView.data(), byte_count), 0);
|
|
1237
3586
|
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1238
3587
|
});
|
|
1239
3588
|
});
|
|
@@ -1244,24 +3593,60 @@ extern "C" std::int32_t rundot_kinetix_world_checkpoint_capture(
|
|
|
1244
3593
|
std::uint32_t* checkpoint_handle) noexcept {
|
|
1245
3594
|
return guard([&]() {
|
|
1246
3595
|
clearError();
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
}
|
|
3596
|
+
const CallerRange ranges[] = {
|
|
3597
|
+
{checkpoint_handle, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3598
|
+
};
|
|
3599
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3600
|
+
Pins3D pins;
|
|
3601
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3602
|
+
auto checkpointHandleView = pins.view<std::uint32_t>(0);
|
|
3603
|
+
if (!checkpointHandleView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3604
|
+
|
|
1250
3605
|
return withControl(handle, [&](Slot::Control& control) {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
if (
|
|
3606
|
+
if (control.world.isAttached()) {
|
|
3607
|
+
return fail(AbiStatus::WorldAttached, "cannot capture legacy checkpoint while attached");
|
|
3608
|
+
}
|
|
3609
|
+
if (control.firstFree == Slot::Control::kFreeListEnd) {
|
|
3610
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
3611
|
+
}
|
|
3612
|
+
if (gNextLegacyGeneration.load(std::memory_order_relaxed) == 0) {
|
|
3613
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "legacy checkpoint token generation exhausted");
|
|
3614
|
+
}
|
|
3615
|
+
if (!rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().tryClaimSlot()) {
|
|
1255
3616
|
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
1256
3617
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
3618
|
+
SlotClaimGuard slotGuard;
|
|
3619
|
+
rundot::kinetix::physics::PreparedCheckpoint prepared;
|
|
3620
|
+
const WorldError captureErr = control.world.prepareCheckpoint(prepared, 0);
|
|
3621
|
+
if (!captureErr.ok()) {
|
|
3622
|
+
return fail(captureErr);
|
|
3623
|
+
}
|
|
3624
|
+
const auto reservation = reserveLegacyId(gNextLegacyGeneration, control.legacyIds);
|
|
3625
|
+
const auto* reserved = std::get_if<ReservedLegacyId>(&reservation);
|
|
3626
|
+
if (reserved == nullptr) {
|
|
3627
|
+
switch (std::get<LegacyIdReservationError>(reservation)) {
|
|
3628
|
+
case LegacyIdReservationError::Exhausted:
|
|
3629
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "legacy checkpoint token generation exhausted");
|
|
3630
|
+
case LegacyIdReservationError::TableInvariantViolation:
|
|
3631
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().noteImbalance();
|
|
3632
|
+
return fail(AbiStatus::InternalFailure, "legacy checkpoint table invariant failed");
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
const auto [gen, insertion] = *reserved;
|
|
3636
|
+
const std::uint32_t slotIndex = control.firstFree;
|
|
3637
|
+
CheckpointSlot& slot = control.checkpoints[slotIndex];
|
|
3638
|
+
const auto published = control.world.publishCheckpoint(std::move(prepared), slot.checkpoint);
|
|
3639
|
+
if (!published.ok()) {
|
|
3640
|
+
return fail(published);
|
|
1260
3641
|
}
|
|
1261
|
-
control.
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
3642
|
+
control.firstFree = slot.nextFree;
|
|
3643
|
+
slot.nextFree = Slot::Control::kFreeListEnd;
|
|
3644
|
+
slot.generation = gen;
|
|
3645
|
+
slot.kind = CheckpointCredentialKind::Legacy;
|
|
3646
|
+
++control.liveCheckpointCount;
|
|
3647
|
+
control.legacyIds[insertion] = {gen, slotIndex};
|
|
3648
|
+
*checkpointHandleView.data() = gen;
|
|
3649
|
+
slotGuard.dismiss();
|
|
1265
3650
|
return status(AbiStatus::Ok);
|
|
1266
3651
|
});
|
|
1267
3652
|
});
|
|
@@ -1273,12 +3658,15 @@ extern "C" std::int32_t rundot_kinetix_world_checkpoint_restore(
|
|
|
1273
3658
|
return guard([&]() {
|
|
1274
3659
|
clearError();
|
|
1275
3660
|
return withControl(handle, [&](Slot::Control& control) {
|
|
3661
|
+
if (control.world.isAttached()) {
|
|
3662
|
+
return fail(AbiStatus::WorldAttached, "cannot externally restore attached world");
|
|
3663
|
+
}
|
|
1276
3664
|
CheckpointSlot* checkpoint = findCheckpoint(control, checkpoint_handle);
|
|
1277
3665
|
if (checkpoint == nullptr) {
|
|
1278
3666
|
return fail(AbiStatus::InvalidCheckpoint,
|
|
1279
3667
|
"checkpoint handle is stale or belongs to another world");
|
|
1280
3668
|
}
|
|
1281
|
-
const WorldError result = control.world.restoreCheckpoint(checkpoint->checkpoint);
|
|
3669
|
+
const WorldError result = control.world.restoreCheckpoint(checkpoint->checkpoint, 0);
|
|
1282
3670
|
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
1283
3671
|
});
|
|
1284
3672
|
});
|
|
@@ -1290,12 +3678,28 @@ extern "C" std::int32_t rundot_kinetix_world_checkpoint_release(
|
|
|
1290
3678
|
return guard([&]() {
|
|
1291
3679
|
clearError();
|
|
1292
3680
|
return withControl(handle, [&](Slot::Control& control) {
|
|
3681
|
+
if (control.world.isAttached()) {
|
|
3682
|
+
return fail(AbiStatus::WorldAttached, "cannot release legacy checkpoint while attached");
|
|
3683
|
+
}
|
|
1293
3684
|
CheckpointSlot* checkpoint = findCheckpoint(control, checkpoint_handle);
|
|
1294
3685
|
if (checkpoint == nullptr) {
|
|
1295
3686
|
return fail(AbiStatus::InvalidCheckpoint,
|
|
1296
3687
|
"checkpoint handle is stale or belongs to another world");
|
|
1297
3688
|
}
|
|
1298
|
-
|
|
3689
|
+
const auto slotIndex = static_cast<std::uint32_t>(checkpoint - control.checkpoints.data());
|
|
3690
|
+
if (!eraseLegacyId(control.legacyIds, checkpoint_handle)) {
|
|
3691
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().noteImbalance();
|
|
3692
|
+
return fail(AbiStatus::InternalFailure, "legacy checkpoint table erase failed");
|
|
3693
|
+
}
|
|
3694
|
+
checkpoint->kind = CheckpointCredentialKind::Empty;
|
|
3695
|
+
checkpoint->checkpoint.clear();
|
|
3696
|
+
checkpoint->nextFree = control.firstFree;
|
|
3697
|
+
control.firstFree = slotIndex;
|
|
3698
|
+
--control.liveCheckpointCount;
|
|
3699
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().releaseSlot();
|
|
3700
|
+
if (control.liveCheckpointCount == 0) {
|
|
3701
|
+
control.world.dropCaptureCache();
|
|
3702
|
+
}
|
|
1299
3703
|
return status(AbiStatus::Ok);
|
|
1300
3704
|
});
|
|
1301
3705
|
});
|
|
@@ -1309,10 +3713,23 @@ extern "C" std::int32_t rundot_kinetix_world_checkpoint_capture_snapshot(
|
|
|
1309
3713
|
std::uint32_t* required_bytes) noexcept {
|
|
1310
3714
|
return guard([&]() {
|
|
1311
3715
|
clearError();
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
3716
|
+
bool rangeOverflow = false;
|
|
3717
|
+
const CallerRange ranges[] = {
|
|
3718
|
+
countedCallerRange(output, output_capacity, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Output, rangeOverflow),
|
|
3719
|
+
{required_bytes, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3720
|
+
};
|
|
3721
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3722
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3723
|
+
Pins3D pins;
|
|
3724
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3725
|
+
auto outputView = pins.view<std::uint8_t>(0);
|
|
3726
|
+
auto requiredBytesView = pins.view<std::uint32_t>(1);
|
|
3727
|
+
if (!outputView || !requiredBytesView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3728
|
+
|
|
1315
3729
|
return withControl(handle, [&](Slot::Control& control) {
|
|
3730
|
+
if (control.world.isAttached()) {
|
|
3731
|
+
return fail(AbiStatus::WorldAttached, "cannot capture checkpoint snapshot while attached");
|
|
3732
|
+
}
|
|
1316
3733
|
CheckpointSlot* checkpoint = findCheckpoint(control, checkpoint_handle);
|
|
1317
3734
|
if (checkpoint == nullptr) {
|
|
1318
3735
|
return fail(AbiStatus::InvalidCheckpoint,
|
|
@@ -1320,35 +3737,1152 @@ extern "C" std::int32_t rundot_kinetix_world_checkpoint_capture_snapshot(
|
|
|
1320
3737
|
}
|
|
1321
3738
|
World::Snapshot snapshot;
|
|
1322
3739
|
const WorldError result = control.world.captureCheckpointSnapshot(
|
|
1323
|
-
checkpoint->checkpoint, snapshot);
|
|
3740
|
+
checkpoint->checkpoint, snapshot, 0);
|
|
1324
3741
|
if (!result.ok()) return fail(result);
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
3742
|
+
return publishSnapshotBytes(snapshot, outputView.data(), output_capacity, requiredBytesView.data());
|
|
3743
|
+
});
|
|
3744
|
+
});
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
extern "C" std::int32_t rundot_kinetix_world_attach(
|
|
3748
|
+
std::uint32_t handle,
|
|
3749
|
+
std::uint32_t expected_digest_low,
|
|
3750
|
+
std::uint32_t expected_digest_high,
|
|
3751
|
+
std::uint32_t* output_token) noexcept {
|
|
3752
|
+
return guard([&]() {
|
|
3753
|
+
clearError();
|
|
3754
|
+
const CallerRange ranges[] = {
|
|
3755
|
+
{output_token, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3756
|
+
};
|
|
3757
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3758
|
+
Pins3D pins;
|
|
3759
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3760
|
+
auto outputTokenView = pins.view<std::uint32_t>(0);
|
|
3761
|
+
if (!outputTokenView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3762
|
+
|
|
3763
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3764
|
+
if (control.world.isAttached() || control.liveCheckpointCount != 0) {
|
|
3765
|
+
return fail(AbiStatus::WorldAttached, "world is already attached or has live checkpoints");
|
|
1328
3766
|
}
|
|
1329
|
-
|
|
3767
|
+
if (control.world.frame() != 0) {
|
|
3768
|
+
return fail(AbiStatus::InitialStateMismatch, "world frame must be 0 for attachment");
|
|
3769
|
+
}
|
|
3770
|
+
const std::uint64_t expectedDigest = joinU64(expected_digest_low, expected_digest_high);
|
|
3771
|
+
if (control.world.digest() != expectedDigest) {
|
|
3772
|
+
return fail(AbiStatus::InitialStateMismatch, "initial digest mismatch for attachment");
|
|
3773
|
+
}
|
|
3774
|
+
std::uint32_t token = 0;
|
|
3775
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
3776
|
+
pauseAttachForTest();
|
|
3777
|
+
#endif
|
|
3778
|
+
const WorldError attachErr = control.world.attach(expectedDigest, token);
|
|
3779
|
+
if (!attachErr.ok()) return fail(attachErr);
|
|
3780
|
+
*outputTokenView.data() = token;
|
|
1330
3781
|
return status(AbiStatus::Ok);
|
|
1331
3782
|
});
|
|
1332
3783
|
});
|
|
1333
3784
|
}
|
|
1334
3785
|
|
|
1335
|
-
extern "C" std::
|
|
1336
|
-
|
|
3786
|
+
extern "C" std::int32_t rundot_kinetix_world_detach(
|
|
3787
|
+
std::uint32_t handle,
|
|
3788
|
+
std::uint32_t token) noexcept {
|
|
3789
|
+
return guard([&]() {
|
|
3790
|
+
clearError();
|
|
3791
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3792
|
+
if (!control.world.isAttached()) {
|
|
3793
|
+
return fail(AbiStatus::InvalidArgument, "world is not attached");
|
|
3794
|
+
}
|
|
3795
|
+
if (token != control.world.attachmentToken()) {
|
|
3796
|
+
return fail(AbiStatus::InvalidArgument, "attachment token mismatch");
|
|
3797
|
+
}
|
|
3798
|
+
if (control.liveCheckpointCount != 0) {
|
|
3799
|
+
return fail(AbiStatus::WorldAttached, "cannot detach while runtime captured slots are live");
|
|
3800
|
+
}
|
|
3801
|
+
const WorldError detachErr = control.world.detach(token);
|
|
3802
|
+
if (!detachErr.ok()) return fail(detachErr);
|
|
3803
|
+
return status(AbiStatus::Ok);
|
|
3804
|
+
});
|
|
3805
|
+
});
|
|
1337
3806
|
}
|
|
1338
3807
|
|
|
1339
|
-
extern "C" std::
|
|
1340
|
-
|
|
3808
|
+
extern "C" std::int32_t rundot_kinetix_world_revision(
|
|
3809
|
+
std::uint32_t handle,
|
|
3810
|
+
std::uint64_t* output_revision) noexcept {
|
|
3811
|
+
return guard([&]() {
|
|
3812
|
+
clearError();
|
|
3813
|
+
const CallerRange ranges[] = {
|
|
3814
|
+
{output_revision, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output},
|
|
3815
|
+
};
|
|
3816
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3817
|
+
Pins3D pins;
|
|
3818
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3819
|
+
auto outputRevisionView = pins.view<std::uint64_t>(0);
|
|
3820
|
+
if (!outputRevisionView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3821
|
+
|
|
3822
|
+
return withWorld(handle, [&](World& world) {
|
|
3823
|
+
*outputRevisionView.data() = world.mutationRevision();
|
|
3824
|
+
return status(AbiStatus::Ok);
|
|
3825
|
+
});
|
|
3826
|
+
});
|
|
1341
3827
|
}
|
|
1342
3828
|
|
|
1343
|
-
extern "C" std::int32_t
|
|
1344
|
-
std::
|
|
1345
|
-
std::uint32_t
|
|
1346
|
-
std::uint32_t*
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
3829
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_capture_token(
|
|
3830
|
+
std::uint32_t handle,
|
|
3831
|
+
std::uint32_t attachment_token,
|
|
3832
|
+
std::uint32_t* output_slot_index,
|
|
3833
|
+
std::uint32_t* output_generation) noexcept {
|
|
3834
|
+
return guard([&]() {
|
|
3835
|
+
clearError();
|
|
3836
|
+
const CallerRange ranges[] = {
|
|
3837
|
+
{output_slot_index, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3838
|
+
{output_generation, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3839
|
+
};
|
|
3840
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3841
|
+
Pins3D pins;
|
|
3842
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3843
|
+
auto outputSlotIndexView = pins.view<std::uint32_t>(0);
|
|
3844
|
+
auto outputGenerationView = pins.view<std::uint32_t>(1);
|
|
3845
|
+
if (!outputSlotIndexView || !outputGenerationView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3846
|
+
|
|
3847
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3848
|
+
if (control.world.isAttached()) {
|
|
3849
|
+
if (attachment_token == 0 || attachment_token != control.world.attachmentToken()) {
|
|
3850
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3851
|
+
}
|
|
3852
|
+
} else {
|
|
3853
|
+
if (attachment_token != 0) {
|
|
3854
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
if (control.firstFree == Slot::Control::kFreeListEnd) {
|
|
3858
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
3859
|
+
}
|
|
3860
|
+
if (gNextCheckpointGeneration.load(std::memory_order_relaxed) == std::numeric_limits<std::uint32_t>::max()) {
|
|
3861
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "checkpoint token generation exhausted");
|
|
3862
|
+
}
|
|
3863
|
+
if (!rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().tryClaimSlot()) {
|
|
3864
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
3865
|
+
}
|
|
3866
|
+
SlotClaimGuard slotGuard;
|
|
3867
|
+
rundot::kinetix::physics::PreparedCheckpoint prepared;
|
|
3868
|
+
const WorldError captureErr = control.world.prepareCheckpoint(prepared, attachment_token);
|
|
3869
|
+
if (!captureErr.ok()) {
|
|
3870
|
+
return fail(captureErr);
|
|
3871
|
+
}
|
|
3872
|
+
std::uint32_t gen = 0;
|
|
3873
|
+
if (!reserveNextCheckpointGeneration(gen)) {
|
|
3874
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "checkpoint token generation exhausted");
|
|
3875
|
+
}
|
|
3876
|
+
const std::uint32_t slotIndex = control.firstFree;
|
|
3877
|
+
CheckpointSlot& slot = control.checkpoints[slotIndex];
|
|
3878
|
+
const auto published = control.world.publishCheckpoint(std::move(prepared), slot.checkpoint);
|
|
3879
|
+
if (!published.ok()) {
|
|
3880
|
+
return fail(published);
|
|
3881
|
+
}
|
|
3882
|
+
control.firstFree = slot.nextFree;
|
|
3883
|
+
slot.nextFree = Slot::Control::kFreeListEnd;
|
|
3884
|
+
slot.generation = gen;
|
|
3885
|
+
slot.kind = CheckpointCredentialKind::Token;
|
|
3886
|
+
++control.liveCheckpointCount;
|
|
3887
|
+
*outputSlotIndexView.data() = slotIndex;
|
|
3888
|
+
*outputGenerationView.data() = gen;
|
|
3889
|
+
slotGuard.dismiss();
|
|
3890
|
+
return status(AbiStatus::Ok);
|
|
3891
|
+
});
|
|
3892
|
+
});
|
|
3893
|
+
}
|
|
3894
|
+
|
|
3895
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_restore_token(
|
|
3896
|
+
std::uint32_t handle,
|
|
3897
|
+
std::uint32_t attachment_token,
|
|
3898
|
+
std::uint32_t slot_index,
|
|
3899
|
+
std::uint32_t generation) noexcept {
|
|
3900
|
+
return guard([&]() {
|
|
3901
|
+
clearError();
|
|
3902
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3903
|
+
if (control.world.isAttached()) {
|
|
3904
|
+
if (attachment_token == 0 || attachment_token != control.world.attachmentToken()) {
|
|
3905
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3906
|
+
}
|
|
3907
|
+
} else {
|
|
3908
|
+
if (attachment_token != 0) {
|
|
3909
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
if (slot_index >= control.checkpointCapacity) {
|
|
3913
|
+
return fail(AbiStatus::InvalidCheckpoint, "slot index out of range");
|
|
3914
|
+
}
|
|
3915
|
+
CheckpointSlot& slot = control.checkpoints[slot_index];
|
|
3916
|
+
if (slot.kind != CheckpointCredentialKind::Token || slot.generation != generation) {
|
|
3917
|
+
return fail(AbiStatus::InvalidCheckpoint,
|
|
3918
|
+
"checkpoint handle is stale or belongs to another world");
|
|
3919
|
+
}
|
|
3920
|
+
const WorldError result = control.world.restoreCheckpoint(
|
|
3921
|
+
slot.checkpoint, attachment_token);
|
|
3922
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
3923
|
+
});
|
|
3924
|
+
});
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_release_token(
|
|
3928
|
+
std::uint32_t handle,
|
|
3929
|
+
std::uint32_t attachment_token,
|
|
3930
|
+
std::uint32_t slot_index,
|
|
3931
|
+
std::uint32_t generation) noexcept {
|
|
3932
|
+
return guard([&]() {
|
|
3933
|
+
clearError();
|
|
3934
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3935
|
+
if (control.world.isAttached()) {
|
|
3936
|
+
if (attachment_token == 0 || attachment_token != control.world.attachmentToken()) {
|
|
3937
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3938
|
+
}
|
|
3939
|
+
} else {
|
|
3940
|
+
if (attachment_token != 0) {
|
|
3941
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3942
|
+
}
|
|
3943
|
+
}
|
|
3944
|
+
if (slot_index >= control.checkpointCapacity) {
|
|
3945
|
+
return fail(AbiStatus::InvalidCheckpoint, "slot index out of range");
|
|
3946
|
+
}
|
|
3947
|
+
CheckpointSlot& slot = control.checkpoints[slot_index];
|
|
3948
|
+
if (slot.kind != CheckpointCredentialKind::Token || slot.generation != generation) {
|
|
3949
|
+
return fail(AbiStatus::InvalidCheckpoint,
|
|
3950
|
+
"checkpoint handle is stale or belongs to another world");
|
|
3951
|
+
}
|
|
3952
|
+
slot.kind = CheckpointCredentialKind::Empty;
|
|
3953
|
+
slot.checkpoint.clear();
|
|
3954
|
+
slot.nextFree = control.firstFree;
|
|
3955
|
+
control.firstFree = slot_index;
|
|
3956
|
+
--control.liveCheckpointCount;
|
|
3957
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().releaseSlot();
|
|
3958
|
+
if (control.liveCheckpointCount == 0) {
|
|
3959
|
+
control.world.dropCaptureCache();
|
|
3960
|
+
}
|
|
3961
|
+
return status(AbiStatus::Ok);
|
|
3962
|
+
});
|
|
3963
|
+
});
|
|
3964
|
+
}
|
|
3965
|
+
|
|
3966
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_capture_snapshot_token(
|
|
3967
|
+
std::uint32_t handle,
|
|
3968
|
+
std::uint32_t attachment_token,
|
|
3969
|
+
std::uint32_t slot_index,
|
|
3970
|
+
std::uint32_t generation,
|
|
3971
|
+
std::uint8_t* output,
|
|
3972
|
+
std::uint32_t output_capacity,
|
|
3973
|
+
std::uint32_t* required_bytes) noexcept {
|
|
3974
|
+
return guard([&]() {
|
|
3975
|
+
clearError();
|
|
3976
|
+
bool rangeOverflow = false;
|
|
3977
|
+
const CallerRange ranges[] = {
|
|
3978
|
+
countedCallerRange(output, output_capacity, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Output, rangeOverflow),
|
|
3979
|
+
{required_bytes, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
3980
|
+
};
|
|
3981
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
3982
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
3983
|
+
Pins3D pins;
|
|
3984
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
3985
|
+
auto outputView = pins.view<std::uint8_t>(0);
|
|
3986
|
+
auto requiredBytesView = pins.view<std::uint32_t>(1);
|
|
3987
|
+
if (!outputView || !requiredBytesView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
3988
|
+
|
|
3989
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
3990
|
+
if (control.world.isAttached()) {
|
|
3991
|
+
if (attachment_token == 0 || attachment_token != control.world.attachmentToken()) {
|
|
3992
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3993
|
+
}
|
|
3994
|
+
} else {
|
|
3995
|
+
if (attachment_token != 0) {
|
|
3996
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
if (slot_index >= control.checkpointCapacity) {
|
|
4000
|
+
return fail(AbiStatus::InvalidCheckpoint, "slot index out of range");
|
|
4001
|
+
}
|
|
4002
|
+
CheckpointSlot& slot = control.checkpoints[slot_index];
|
|
4003
|
+
if (slot.kind != CheckpointCredentialKind::Token || slot.generation != generation) {
|
|
4004
|
+
return fail(AbiStatus::InvalidCheckpoint,
|
|
4005
|
+
"checkpoint handle is stale or belongs to another world");
|
|
4006
|
+
}
|
|
4007
|
+
World::Snapshot snapshot;
|
|
4008
|
+
const WorldError result = control.world.captureCheckpointSnapshot(
|
|
4009
|
+
slot.checkpoint, snapshot, attachment_token);
|
|
4010
|
+
if (!result.ok()) return fail(result);
|
|
4011
|
+
return publishSnapshotBytes(snapshot, outputView.data(), output_capacity, requiredBytesView.data());
|
|
4012
|
+
});
|
|
4013
|
+
});
|
|
4014
|
+
}
|
|
4015
|
+
|
|
4016
|
+
extern "C" std::int32_t rundot_kinetix_world_import_snapshot_attached(
|
|
4017
|
+
std::uint32_t handle,
|
|
4018
|
+
std::uint32_t attachment_token,
|
|
4019
|
+
const std::uint8_t* bytes,
|
|
4020
|
+
std::uint32_t byte_count) noexcept {
|
|
4021
|
+
return guard([&]() {
|
|
4022
|
+
clearError();
|
|
4023
|
+
bool rangeOverflow = false;
|
|
4024
|
+
const CallerRange ranges[] = {
|
|
4025
|
+
countedCallerRange(bytes, byte_count, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input, rangeOverflow),
|
|
4026
|
+
};
|
|
4027
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
4028
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4029
|
+
Pins3D pins;
|
|
4030
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4031
|
+
auto bytesView = pins.view<const std::uint8_t>(0);
|
|
4032
|
+
if (!bytesView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4033
|
+
|
|
4034
|
+
if (byte_count == 0) {
|
|
4035
|
+
return fail(AbiStatus::InvalidArgument, "snapshot input is empty or out of range");
|
|
4036
|
+
}
|
|
4037
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4038
|
+
if (!control.world.isAttached()) {
|
|
4039
|
+
return fail(AbiStatus::AttachmentMismatch, "world is not attached");
|
|
4040
|
+
}
|
|
4041
|
+
if (attachment_token == 0 || attachment_token != control.world.attachmentToken()) {
|
|
4042
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
4043
|
+
}
|
|
4044
|
+
const WorldError result = control.world.importSnapshot(
|
|
4045
|
+
std::span<const std::uint8_t>(bytesView.data(), byte_count), attachment_token);
|
|
4046
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
4047
|
+
});
|
|
4048
|
+
});
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
extern "C" std::uint32_t rundot_kinetix_world_digest_algorithm_revision() noexcept {
|
|
4052
|
+
return rundot::kinetix::physics::kWorldDigestAlgorithmRevision;
|
|
4053
|
+
}
|
|
4054
|
+
|
|
4055
|
+
extern "C" std::uint32_t rundot_kinetix_world_strong_digest_algorithm_revision() noexcept {
|
|
4056
|
+
return rundot::kinetix::physics::kWorldStrongDigestAlgorithmRevision;
|
|
4057
|
+
}
|
|
4058
|
+
|
|
4059
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_digest(
|
|
4060
|
+
std::uint32_t handle,
|
|
4061
|
+
std::uint32_t checkpoint_id,
|
|
4062
|
+
std::uint64_t* output) noexcept {
|
|
4063
|
+
return guard([&]() {
|
|
4064
|
+
clearError();
|
|
4065
|
+
const CallerRange ranges[] = {
|
|
4066
|
+
{output, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output},
|
|
4067
|
+
};
|
|
4068
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4069
|
+
Pins3D pins;
|
|
4070
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4071
|
+
auto outputView = pins.view<std::uint64_t>(0);
|
|
4072
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4073
|
+
|
|
4074
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4075
|
+
WorldCheckpoint* checkpoint = nullptr;
|
|
4076
|
+
const SelectedCredential credential{
|
|
4077
|
+
SelectedCredentialMode::Legacy, checkpoint_id, 0, 0, 0};
|
|
4078
|
+
if (const auto err = resolveSelectedCheckpoint(control, credential, checkpoint)) return err;
|
|
4079
|
+
const WorldError result = control.world.digestCheckpoint(
|
|
4080
|
+
*checkpoint, *outputView.data(), 0);
|
|
4081
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
4082
|
+
});
|
|
4083
|
+
});
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_digest_token(
|
|
4087
|
+
std::uint32_t handle,
|
|
4088
|
+
std::uint32_t attachment_token,
|
|
4089
|
+
std::uint32_t slot_index,
|
|
4090
|
+
std::uint32_t generation,
|
|
4091
|
+
std::uint64_t* output) noexcept {
|
|
4092
|
+
return guard([&]() {
|
|
4093
|
+
clearError();
|
|
4094
|
+
const CallerRange ranges[] = {
|
|
4095
|
+
{output, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output},
|
|
4096
|
+
};
|
|
4097
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4098
|
+
Pins3D pins;
|
|
4099
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4100
|
+
auto outputView = pins.view<std::uint64_t>(0);
|
|
4101
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4102
|
+
|
|
4103
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4104
|
+
WorldCheckpoint* checkpoint = nullptr;
|
|
4105
|
+
const SelectedCredential credential{
|
|
4106
|
+
SelectedCredentialMode::Token, 0, attachment_token, slot_index, generation};
|
|
4107
|
+
if (const auto err = resolveSelectedCheckpoint(control, credential, checkpoint)) return err;
|
|
4108
|
+
const WorldError result = control.world.digestCheckpoint(
|
|
4109
|
+
*checkpoint, *outputView.data(), attachment_token);
|
|
4110
|
+
return result.ok() ? status(AbiStatus::Ok) : fail(result);
|
|
4111
|
+
});
|
|
4112
|
+
});
|
|
4113
|
+
}
|
|
4114
|
+
|
|
4115
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_strong_digest(
|
|
4116
|
+
std::uint32_t handle,
|
|
4117
|
+
std::uint32_t checkpoint_id,
|
|
4118
|
+
std::uint8_t* output) noexcept {
|
|
4119
|
+
return guard([&]() {
|
|
4120
|
+
clearError();
|
|
4121
|
+
if (output == nullptr) return fail(AbiStatus::InvalidArgument, "strong digest output is null");
|
|
4122
|
+
const CallerRange ranges[] = {
|
|
4123
|
+
{output, 32, 1, RangeRole::Output},
|
|
4124
|
+
};
|
|
4125
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4126
|
+
Pins3D pins;
|
|
4127
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4128
|
+
auto outputView = pins.view<std::uint8_t>(0);
|
|
4129
|
+
if (!outputView || outputView.size() != 32) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4130
|
+
|
|
4131
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4132
|
+
WorldCheckpoint* checkpoint = nullptr;
|
|
4133
|
+
const SelectedCredential credential{
|
|
4134
|
+
SelectedCredentialMode::Legacy, checkpoint_id, 0, 0, 0};
|
|
4135
|
+
if (const auto err = resolveSelectedCheckpoint(control, credential, checkpoint)) return err;
|
|
4136
|
+
std::array<std::uint8_t, 32> local{};
|
|
4137
|
+
const WorldError result = control.world.strongDigestCheckpoint(*checkpoint, local, 0);
|
|
4138
|
+
if (!result.ok()) return fail(result);
|
|
4139
|
+
std::memcpy(outputView.data(), local.data(), 32);
|
|
4140
|
+
return status(AbiStatus::Ok);
|
|
4141
|
+
});
|
|
4142
|
+
});
|
|
4143
|
+
}
|
|
4144
|
+
|
|
4145
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_strong_digest_token(
|
|
4146
|
+
std::uint32_t handle,
|
|
4147
|
+
std::uint32_t attachment_token,
|
|
4148
|
+
std::uint32_t slot_index,
|
|
4149
|
+
std::uint32_t generation,
|
|
4150
|
+
std::uint8_t* output) noexcept {
|
|
4151
|
+
return guard([&]() {
|
|
4152
|
+
clearError();
|
|
4153
|
+
if (output == nullptr) return fail(AbiStatus::InvalidArgument, "strong digest output is null");
|
|
4154
|
+
const CallerRange ranges[] = {
|
|
4155
|
+
{output, 32, 1, RangeRole::Output},
|
|
4156
|
+
};
|
|
4157
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4158
|
+
Pins3D pins;
|
|
4159
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4160
|
+
auto outputView = pins.view<std::uint8_t>(0);
|
|
4161
|
+
if (!outputView || outputView.size() != 32) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4162
|
+
|
|
4163
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4164
|
+
WorldCheckpoint* checkpoint = nullptr;
|
|
4165
|
+
const SelectedCredential credential{
|
|
4166
|
+
SelectedCredentialMode::Token, 0, attachment_token, slot_index, generation};
|
|
4167
|
+
if (const auto err = resolveSelectedCheckpoint(control, credential, checkpoint)) return err;
|
|
4168
|
+
std::array<std::uint8_t, 32> local{};
|
|
4169
|
+
const WorldError result = control.world.strongDigestCheckpoint(
|
|
4170
|
+
*checkpoint, local, attachment_token);
|
|
4171
|
+
if (!result.ok()) return fail(result);
|
|
4172
|
+
std::memcpy(outputView.data(), local.data(), 32);
|
|
4173
|
+
return status(AbiStatus::Ok);
|
|
4174
|
+
});
|
|
4175
|
+
});
|
|
4176
|
+
}
|
|
4177
|
+
|
|
4178
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_view_info(
|
|
4179
|
+
std::uint32_t handle,
|
|
4180
|
+
std::uint32_t checkpoint_id,
|
|
4181
|
+
std::uint32_t* output,
|
|
4182
|
+
std::uint32_t output_words) noexcept {
|
|
4183
|
+
return guard([&]() {
|
|
4184
|
+
clearError();
|
|
4185
|
+
return publishCheckpointViewInfo(
|
|
4186
|
+
handle, SelectedCredential{SelectedCredentialMode::Legacy, checkpoint_id, 0, 0, 0},
|
|
4187
|
+
output, output_words);
|
|
4188
|
+
});
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4191
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_view_info_token(
|
|
4192
|
+
std::uint32_t handle,
|
|
4193
|
+
std::uint32_t attachment_token,
|
|
4194
|
+
std::uint32_t slot_index,
|
|
4195
|
+
std::uint32_t generation,
|
|
4196
|
+
std::uint32_t* output,
|
|
4197
|
+
std::uint32_t output_words) noexcept {
|
|
4198
|
+
return guard([&]() {
|
|
4199
|
+
clearError();
|
|
4200
|
+
return publishCheckpointViewInfo(
|
|
4201
|
+
handle,
|
|
4202
|
+
SelectedCredential{SelectedCredentialMode::Token, 0, attachment_token, slot_index, generation},
|
|
4203
|
+
output, output_words);
|
|
4204
|
+
});
|
|
4205
|
+
}
|
|
4206
|
+
|
|
4207
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_write_body_motion_into(
|
|
4208
|
+
std::uint32_t handle,
|
|
4209
|
+
std::uint32_t checkpoint_id,
|
|
4210
|
+
double* pose,
|
|
4211
|
+
std::uint32_t pose_values,
|
|
4212
|
+
double* velocity,
|
|
4213
|
+
std::uint32_t velocity_values,
|
|
4214
|
+
std::uint32_t* ids,
|
|
4215
|
+
std::uint32_t id_words,
|
|
4216
|
+
std::uint8_t* status_bytes,
|
|
4217
|
+
std::uint32_t status_count,
|
|
4218
|
+
std::uint32_t* output_header,
|
|
4219
|
+
std::uint32_t header_words) noexcept {
|
|
4220
|
+
return guard([&]() {
|
|
4221
|
+
clearError();
|
|
4222
|
+
return publishCheckpointMotion(
|
|
4223
|
+
handle, SelectedCredential{SelectedCredentialMode::Legacy, checkpoint_id, 0, 0, 0},
|
|
4224
|
+
pose, pose_values, velocity, velocity_values, ids, id_words,
|
|
4225
|
+
status_bytes, status_count, output_header, header_words);
|
|
4226
|
+
});
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_write_body_motion_into_token(
|
|
4230
|
+
std::uint32_t handle,
|
|
4231
|
+
std::uint32_t attachment_token,
|
|
4232
|
+
std::uint32_t slot_index,
|
|
4233
|
+
std::uint32_t generation,
|
|
4234
|
+
double* pose,
|
|
4235
|
+
std::uint32_t pose_values,
|
|
4236
|
+
double* velocity,
|
|
4237
|
+
std::uint32_t velocity_values,
|
|
4238
|
+
std::uint32_t* ids,
|
|
4239
|
+
std::uint32_t id_words,
|
|
4240
|
+
std::uint8_t* status_bytes,
|
|
4241
|
+
std::uint32_t status_count,
|
|
4242
|
+
std::uint32_t* output_header,
|
|
4243
|
+
std::uint32_t header_words) noexcept {
|
|
4244
|
+
return guard([&]() {
|
|
4245
|
+
clearError();
|
|
4246
|
+
return publishCheckpointMotion(
|
|
4247
|
+
handle,
|
|
4248
|
+
SelectedCredential{SelectedCredentialMode::Token, 0, attachment_token, slot_index, generation},
|
|
4249
|
+
pose, pose_values, velocity, velocity_values, ids, id_words,
|
|
4250
|
+
status_bytes, status_count, output_header, header_words);
|
|
4251
|
+
});
|
|
4252
|
+
}
|
|
4253
|
+
|
|
4254
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_copy_latest_output(
|
|
4255
|
+
std::uint32_t handle,
|
|
4256
|
+
std::uint32_t checkpoint_id,
|
|
4257
|
+
std::uint8_t* packet,
|
|
4258
|
+
std::uint32_t packet_bytes) noexcept {
|
|
4259
|
+
return guard([&]() {
|
|
4260
|
+
clearError();
|
|
4261
|
+
return publishCheckpointPacket(
|
|
4262
|
+
handle, SelectedCredential{SelectedCredentialMode::Legacy, checkpoint_id, 0, 0, 0},
|
|
4263
|
+
packet, packet_bytes);
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
|
|
4267
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_copy_latest_output_token(
|
|
4268
|
+
std::uint32_t handle,
|
|
4269
|
+
std::uint32_t attachment_token,
|
|
4270
|
+
std::uint32_t slot_index,
|
|
4271
|
+
std::uint32_t generation,
|
|
4272
|
+
std::uint8_t* packet,
|
|
4273
|
+
std::uint32_t packet_bytes) noexcept {
|
|
4274
|
+
return guard([&]() {
|
|
4275
|
+
clearError();
|
|
4276
|
+
return publishCheckpointPacket(
|
|
4277
|
+
handle,
|
|
4278
|
+
SelectedCredential{SelectedCredentialMode::Token, 0, attachment_token, slot_index, generation},
|
|
4279
|
+
packet, packet_bytes);
|
|
4280
|
+
});
|
|
4281
|
+
}
|
|
4282
|
+
|
|
4283
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_import(
|
|
4284
|
+
std::uint32_t handle,
|
|
4285
|
+
const std::uint8_t* bytes,
|
|
4286
|
+
std::uint32_t byte_count,
|
|
4287
|
+
std::uint32_t* checkpoint_handle) noexcept {
|
|
4288
|
+
return guard([&]() {
|
|
4289
|
+
clearError();
|
|
4290
|
+
bool rangeOverflow = false;
|
|
4291
|
+
const CallerRange ranges[] = {
|
|
4292
|
+
countedCallerRange(bytes, byte_count, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input, rangeOverflow),
|
|
4293
|
+
{checkpoint_handle, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4294
|
+
};
|
|
4295
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
4296
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4297
|
+
Pins3D pins;
|
|
4298
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4299
|
+
auto bytesView = pins.view<const std::uint8_t>(0);
|
|
4300
|
+
auto checkpointHandleView = pins.view<std::uint32_t>(1);
|
|
4301
|
+
if (!bytesView || !checkpointHandleView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4302
|
+
|
|
4303
|
+
if (byte_count == 0) {
|
|
4304
|
+
return fail(AbiStatus::InvalidArgument, "snapshot input is empty or out of range");
|
|
4305
|
+
}
|
|
4306
|
+
|
|
4307
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4308
|
+
if (control.world.isAttached()) {
|
|
4309
|
+
return fail(AbiStatus::WorldAttached, "cannot import legacy checkpoint while attached");
|
|
4310
|
+
}
|
|
4311
|
+
if (control.firstFree == Slot::Control::kFreeListEnd) {
|
|
4312
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
4313
|
+
}
|
|
4314
|
+
if (gNextLegacyGeneration.load(std::memory_order_relaxed) == 0) {
|
|
4315
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "legacy checkpoint token generation exhausted");
|
|
4316
|
+
}
|
|
4317
|
+
if (!rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().tryClaimSlot()) {
|
|
4318
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
4319
|
+
}
|
|
4320
|
+
SlotClaimGuard slotGuard;
|
|
4321
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
4322
|
+
if (consumeThrowAfterSlotClaim()) {
|
|
4323
|
+
throw std::runtime_error("checkpoint slot claim fault");
|
|
4324
|
+
}
|
|
4325
|
+
#endif
|
|
4326
|
+
rundot::kinetix::physics::WorldCheckpoint candidate;
|
|
4327
|
+
const WorldError importErr = control.world.importCheckpoint(
|
|
4328
|
+
std::span<const std::uint8_t>(bytesView.data(), byte_count), candidate, 0);
|
|
4329
|
+
if (!importErr.ok()) {
|
|
4330
|
+
return fail(importErr);
|
|
4331
|
+
}
|
|
4332
|
+
const auto reservation = reserveLegacyId(gNextLegacyGeneration, control.legacyIds);
|
|
4333
|
+
const auto* reserved = std::get_if<ReservedLegacyId>(&reservation);
|
|
4334
|
+
if (reserved == nullptr) {
|
|
4335
|
+
switch (std::get<LegacyIdReservationError>(reservation)) {
|
|
4336
|
+
case LegacyIdReservationError::Exhausted:
|
|
4337
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "legacy checkpoint token generation exhausted");
|
|
4338
|
+
case LegacyIdReservationError::TableInvariantViolation:
|
|
4339
|
+
rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().noteImbalance();
|
|
4340
|
+
return fail(AbiStatus::InternalFailure, "legacy checkpoint table invariant failed");
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
const auto [gen, insertion] = *reserved;
|
|
4344
|
+
const std::uint32_t slotIndex = control.firstFree;
|
|
4345
|
+
CheckpointSlot& slot = control.checkpoints[slotIndex];
|
|
4346
|
+
slot.checkpoint = std::move(candidate);
|
|
4347
|
+
control.firstFree = slot.nextFree;
|
|
4348
|
+
slot.nextFree = Slot::Control::kFreeListEnd;
|
|
4349
|
+
slot.generation = gen;
|
|
4350
|
+
slot.kind = CheckpointCredentialKind::Legacy;
|
|
4351
|
+
++control.liveCheckpointCount;
|
|
4352
|
+
control.legacyIds[insertion] = {gen, slotIndex};
|
|
4353
|
+
*checkpointHandleView.data() = gen;
|
|
4354
|
+
slotGuard.dismiss();
|
|
4355
|
+
return status(AbiStatus::Ok);
|
|
4356
|
+
});
|
|
4357
|
+
});
|
|
4358
|
+
}
|
|
4359
|
+
|
|
4360
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_import_token(
|
|
4361
|
+
std::uint32_t handle,
|
|
4362
|
+
std::uint32_t attachment_token,
|
|
4363
|
+
const std::uint8_t* bytes,
|
|
4364
|
+
std::uint32_t byte_count,
|
|
4365
|
+
std::uint32_t* output_slot_index,
|
|
4366
|
+
std::uint32_t* output_generation) noexcept {
|
|
4367
|
+
return guard([&]() {
|
|
4368
|
+
clearError();
|
|
4369
|
+
bool rangeOverflow = false;
|
|
4370
|
+
const CallerRange ranges[] = {
|
|
4371
|
+
countedCallerRange(bytes, byte_count, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Input, rangeOverflow),
|
|
4372
|
+
{output_slot_index, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4373
|
+
{output_generation, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4374
|
+
};
|
|
4375
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
4376
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4377
|
+
Pins3D pins;
|
|
4378
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4379
|
+
auto bytesView = pins.view<const std::uint8_t>(0);
|
|
4380
|
+
auto outputSlotIndexView = pins.view<std::uint32_t>(1);
|
|
4381
|
+
auto outputGenerationView = pins.view<std::uint32_t>(2);
|
|
4382
|
+
if (!bytesView || !outputSlotIndexView || !outputGenerationView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4383
|
+
|
|
4384
|
+
if (byte_count == 0) {
|
|
4385
|
+
return fail(AbiStatus::InvalidArgument, "snapshot input is empty or out of range");
|
|
4386
|
+
}
|
|
4387
|
+
|
|
4388
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4389
|
+
if (control.world.isAttached()) {
|
|
4390
|
+
if (attachment_token == 0 || attachment_token != control.world.attachmentToken()) {
|
|
4391
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
4392
|
+
}
|
|
4393
|
+
} else {
|
|
4394
|
+
if (attachment_token != 0) {
|
|
4395
|
+
return fail(AbiStatus::AttachmentMismatch, "attachment token mismatch");
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
if (control.firstFree == Slot::Control::kFreeListEnd) {
|
|
4399
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
4400
|
+
}
|
|
4401
|
+
if (gNextCheckpointGeneration.load(std::memory_order_relaxed) == std::numeric_limits<std::uint32_t>::max()) {
|
|
4402
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "checkpoint token generation exhausted");
|
|
4403
|
+
}
|
|
4404
|
+
if (!rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance().tryClaimSlot()) {
|
|
4405
|
+
return fail(AbiStatus::CheckpointCapacity, "checkpoint capacity is exhausted");
|
|
4406
|
+
}
|
|
4407
|
+
SlotClaimGuard slotGuard;
|
|
4408
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
4409
|
+
if (consumeThrowAfterSlotClaim()) {
|
|
4410
|
+
throw std::runtime_error("checkpoint slot claim fault");
|
|
4411
|
+
}
|
|
4412
|
+
#endif
|
|
4413
|
+
rundot::kinetix::physics::WorldCheckpoint candidate;
|
|
4414
|
+
const WorldError importErr = control.world.importCheckpoint(
|
|
4415
|
+
std::span<const std::uint8_t>(bytesView.data(), byte_count), candidate, attachment_token);
|
|
4416
|
+
if (!importErr.ok()) {
|
|
4417
|
+
return fail(importErr);
|
|
4418
|
+
}
|
|
4419
|
+
std::uint32_t gen = 0;
|
|
4420
|
+
if (!reserveNextCheckpointGeneration(gen)) {
|
|
4421
|
+
return fail(AbiStatus::CheckpointTokenExhausted, "checkpoint token generation exhausted");
|
|
4422
|
+
}
|
|
4423
|
+
const std::uint32_t slotIndex = control.firstFree;
|
|
4424
|
+
CheckpointSlot& slot = control.checkpoints[slotIndex];
|
|
4425
|
+
slot.checkpoint = std::move(candidate);
|
|
4426
|
+
control.firstFree = slot.nextFree;
|
|
4427
|
+
slot.nextFree = Slot::Control::kFreeListEnd;
|
|
4428
|
+
slot.generation = gen;
|
|
4429
|
+
slot.kind = CheckpointCredentialKind::Token;
|
|
4430
|
+
++control.liveCheckpointCount;
|
|
4431
|
+
*outputSlotIndexView.data() = slotIndex;
|
|
4432
|
+
*outputGenerationView.data() = gen;
|
|
4433
|
+
slotGuard.dismiss();
|
|
4434
|
+
return status(AbiStatus::Ok);
|
|
4435
|
+
});
|
|
4436
|
+
});
|
|
4437
|
+
}
|
|
4438
|
+
|
|
4439
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_capacity(
|
|
4440
|
+
std::uint32_t handle,
|
|
4441
|
+
std::uint32_t* output_capacity) noexcept {
|
|
4442
|
+
return guard([&]() {
|
|
4443
|
+
clearError();
|
|
4444
|
+
const CallerRange ranges[] = {
|
|
4445
|
+
{output_capacity, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4446
|
+
};
|
|
4447
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4448
|
+
Pins3D pins;
|
|
4449
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4450
|
+
auto outputCapacityView = pins.view<std::uint32_t>(0);
|
|
4451
|
+
if (!outputCapacityView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4452
|
+
|
|
4453
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4454
|
+
*outputCapacityView.data() = control.checkpointCapacity;
|
|
4455
|
+
return status(AbiStatus::Ok);
|
|
4456
|
+
});
|
|
4457
|
+
});
|
|
4458
|
+
}
|
|
4459
|
+
|
|
4460
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_live_count(
|
|
4461
|
+
std::uint32_t handle,
|
|
4462
|
+
std::uint32_t* output_live_count) noexcept {
|
|
4463
|
+
return guard([&]() {
|
|
4464
|
+
clearError();
|
|
4465
|
+
const CallerRange ranges[] = {
|
|
4466
|
+
{output_live_count, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4467
|
+
};
|
|
4468
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4469
|
+
Pins3D pins;
|
|
4470
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4471
|
+
auto outputLiveCountView = pins.view<std::uint32_t>(0);
|
|
4472
|
+
if (!outputLiveCountView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4473
|
+
|
|
4474
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4475
|
+
*outputLiveCountView.data() = control.liveCheckpointCount;
|
|
4476
|
+
return status(AbiStatus::Ok);
|
|
4477
|
+
});
|
|
4478
|
+
});
|
|
4479
|
+
}
|
|
4480
|
+
|
|
4481
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_preflight(
|
|
4482
|
+
std::uint32_t handle,
|
|
4483
|
+
std::uint32_t required_slots,
|
|
4484
|
+
std::uint32_t* can_allocate) noexcept {
|
|
4485
|
+
return guard([&]() {
|
|
4486
|
+
clearError();
|
|
4487
|
+
const CallerRange ranges[] = {
|
|
4488
|
+
{can_allocate, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4489
|
+
};
|
|
4490
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4491
|
+
Pins3D pins;
|
|
4492
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4493
|
+
auto canAllocateView = pins.view<std::uint32_t>(0);
|
|
4494
|
+
if (!canAllocateView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4495
|
+
|
|
4496
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4497
|
+
const std::uint32_t available = control.checkpointCapacity > control.liveCheckpointCount
|
|
4498
|
+
? control.checkpointCapacity - control.liveCheckpointCount
|
|
4499
|
+
: 0;
|
|
4500
|
+
const std::uint32_t currentGen = gNextCheckpointGeneration.load(std::memory_order_relaxed);
|
|
4501
|
+
const bool tokenAvailable = required_slots <= std::numeric_limits<std::uint32_t>::max() - currentGen;
|
|
4502
|
+
*canAllocateView.data() = (available >= required_slots && tokenAvailable) ? 1 : 0;
|
|
4503
|
+
return status(AbiStatus::Ok);
|
|
4504
|
+
});
|
|
4505
|
+
});
|
|
4506
|
+
}
|
|
4507
|
+
|
|
4508
|
+
extern "C" std::int32_t rundot_kinetix_instance_ledger_info(
|
|
4509
|
+
std::uint64_t* live_slots,
|
|
4510
|
+
std::uint64_t* high_water_slots,
|
|
4511
|
+
std::uint64_t* checkpoint_bytes,
|
|
4512
|
+
std::uint64_t* geometry_bytes,
|
|
4513
|
+
std::uint64_t* high_water_bytes,
|
|
4514
|
+
std::uint64_t* wasm_heap_bytes) noexcept {
|
|
4515
|
+
return guard([&]() {
|
|
4516
|
+
clearError();
|
|
4517
|
+
const CallerRange ranges[] = {
|
|
4518
|
+
{live_slots, live_slots ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4519
|
+
{high_water_slots, high_water_slots ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4520
|
+
{checkpoint_bytes, checkpoint_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4521
|
+
{geometry_bytes, geometry_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4522
|
+
{high_water_bytes, high_water_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4523
|
+
{wasm_heap_bytes, wasm_heap_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4524
|
+
};
|
|
4525
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4526
|
+
Pins3D pins;
|
|
4527
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4528
|
+
auto liveSlotsView = pins.view<std::uint64_t>(0);
|
|
4529
|
+
auto highWaterSlotsView = pins.view<std::uint64_t>(1);
|
|
4530
|
+
auto checkpointBytesView = pins.view<std::uint64_t>(2);
|
|
4531
|
+
auto geometryBytesView = pins.view<std::uint64_t>(3);
|
|
4532
|
+
auto highWaterBytesView = pins.view<std::uint64_t>(4);
|
|
4533
|
+
auto wasmHeapBytesView = pins.view<std::uint64_t>(5);
|
|
4534
|
+
if (!liveSlotsView || !highWaterSlotsView || !checkpointBytesView || !geometryBytesView
|
|
4535
|
+
|| !highWaterBytesView || !wasmHeapBytesView) {
|
|
4536
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4539
|
+
const auto& ledger = rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance();
|
|
4540
|
+
if (ledger.imbalance()) {
|
|
4541
|
+
return fail(AbiStatus::InternalFailure, "ledger imbalance detected");
|
|
4542
|
+
}
|
|
4543
|
+
if (live_slots != nullptr) *liveSlotsView.data() = ledger.liveSlots();
|
|
4544
|
+
if (high_water_slots != nullptr) *highWaterSlotsView.data() = ledger.highWaterSlots();
|
|
4545
|
+
if (checkpoint_bytes != nullptr) *checkpointBytesView.data() = ledger.checkpointBytes();
|
|
4546
|
+
if (geometry_bytes != nullptr) *geometryBytesView.data() = ledger.geometryBytes();
|
|
4547
|
+
if (high_water_bytes != nullptr) *highWaterBytesView.data() = ledger.highWaterBytes();
|
|
4548
|
+
if (wasm_heap_bytes != nullptr) *wasmHeapBytesView.data() = ledger.wasmMemoryBytes();
|
|
4549
|
+
return status(AbiStatus::Ok);
|
|
4550
|
+
});
|
|
4551
|
+
}
|
|
4552
|
+
|
|
4553
|
+
extern "C" std::int32_t rundot_kinetix_instance_ledger_reset_high_water() noexcept {
|
|
4554
|
+
auto& ledger = rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance();
|
|
4555
|
+
if (!ledger.resetHighWater()) {
|
|
4556
|
+
return fail(AbiStatus::LedgerLive, "cannot reset high-water while retained resources are live");
|
|
4557
|
+
}
|
|
4558
|
+
return status(AbiStatus::Ok);
|
|
4559
|
+
}
|
|
4560
|
+
|
|
4561
|
+
extern "C" std::int32_t rundot_kinetix_instance_ledger_metadata(
|
|
4562
|
+
std::uint64_t* metadata_bytes,
|
|
4563
|
+
std::uint64_t* payload_bytes,
|
|
4564
|
+
std::uint64_t* geometry_bytes,
|
|
4565
|
+
std::uint64_t* retained_bytes,
|
|
4566
|
+
std::uint64_t* live_worlds,
|
|
4567
|
+
std::uint64_t* imbalance) noexcept {
|
|
4568
|
+
return guard([&]() {
|
|
4569
|
+
clearError();
|
|
4570
|
+
const CallerRange ranges[] = {
|
|
4571
|
+
{metadata_bytes, metadata_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4572
|
+
{payload_bytes, payload_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4573
|
+
{geometry_bytes, geometry_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4574
|
+
{retained_bytes, retained_bytes ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4575
|
+
{live_worlds, live_worlds ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4576
|
+
{imbalance, imbalance ? sizeof(std::uint64_t) : 0, alignof(std::uint64_t), RangeRole::Output},
|
|
4577
|
+
};
|
|
4578
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4579
|
+
Pins3D pins;
|
|
4580
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4581
|
+
auto metadataBytesView = pins.view<std::uint64_t>(0);
|
|
4582
|
+
auto payloadBytesView = pins.view<std::uint64_t>(1);
|
|
4583
|
+
auto geometryBytesView = pins.view<std::uint64_t>(2);
|
|
4584
|
+
auto retainedBytesView = pins.view<std::uint64_t>(3);
|
|
4585
|
+
auto liveWorldsView = pins.view<std::uint64_t>(4);
|
|
4586
|
+
auto imbalanceView = pins.view<std::uint64_t>(5);
|
|
4587
|
+
if (!metadataBytesView || !payloadBytesView || !geometryBytesView || !retainedBytesView
|
|
4588
|
+
|| !liveWorldsView || !imbalanceView) {
|
|
4589
|
+
return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4590
|
+
}
|
|
4591
|
+
|
|
4592
|
+
const auto& ledger = rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance();
|
|
4593
|
+
if (metadata_bytes != nullptr) *metadataBytesView.data() = ledger.metadataBytes();
|
|
4594
|
+
if (payload_bytes != nullptr) *payloadBytesView.data() = ledger.checkpointBytes();
|
|
4595
|
+
if (geometry_bytes != nullptr) *geometryBytesView.data() = ledger.geometryBytes();
|
|
4596
|
+
if (retained_bytes != nullptr) *retainedBytesView.data() = ledger.retainedBytes();
|
|
4597
|
+
if (live_worlds != nullptr) *liveWorldsView.data() = ledger.liveWorlds();
|
|
4598
|
+
if (imbalance != nullptr) *imbalanceView.data() = ledger.imbalance() ? 1 : 0;
|
|
4599
|
+
return status(AbiStatus::Ok);
|
|
4600
|
+
});
|
|
4601
|
+
}
|
|
4602
|
+
|
|
4603
|
+
extern "C" std::int32_t rundot_kinetix_world_ownership_counts(
|
|
4604
|
+
std::uint32_t handle,
|
|
4605
|
+
std::uint32_t* unique_captures,
|
|
4606
|
+
std::uint32_t* abi_slots) noexcept {
|
|
4607
|
+
return guard([&]() {
|
|
4608
|
+
clearError();
|
|
4609
|
+
const CallerRange ranges[] = {
|
|
4610
|
+
{unique_captures, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4611
|
+
{abi_slots, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4612
|
+
};
|
|
4613
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4614
|
+
Pins3D pins;
|
|
4615
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4616
|
+
auto uniqueCapturesView = pins.view<std::uint32_t>(0);
|
|
4617
|
+
auto abiSlotsView = pins.view<std::uint32_t>(1);
|
|
4618
|
+
if (!uniqueCapturesView || !abiSlotsView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4619
|
+
|
|
4620
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4621
|
+
*uniqueCapturesView.data() = control.world.uniqueCaptureCount();
|
|
4622
|
+
*abiSlotsView.data() = control.liveCheckpointCount;
|
|
4623
|
+
return status(AbiStatus::Ok);
|
|
4624
|
+
});
|
|
4625
|
+
});
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4628
|
+
extern "C" std::int32_t rundot_kinetix_world_checkpoint_legacy_preflight(
|
|
4629
|
+
std::uint32_t handle,
|
|
4630
|
+
std::uint32_t required_slots,
|
|
4631
|
+
std::uint32_t* can_allocate) noexcept {
|
|
4632
|
+
return guard([&]() {
|
|
4633
|
+
clearError();
|
|
4634
|
+
const CallerRange ranges[] = {
|
|
4635
|
+
{can_allocate, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4636
|
+
};
|
|
4637
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4638
|
+
Pins3D pins;
|
|
4639
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4640
|
+
auto canAllocateView = pins.view<std::uint32_t>(0);
|
|
4641
|
+
if (!canAllocateView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4642
|
+
|
|
4643
|
+
return withControl(handle, [&](Slot::Control& control) {
|
|
4644
|
+
const std::uint32_t available = control.checkpointCapacity > control.liveCheckpointCount
|
|
4645
|
+
? control.checkpointCapacity - control.liveCheckpointCount
|
|
4646
|
+
: 0;
|
|
4647
|
+
const std::uint32_t currentGen = gNextLegacyGeneration.load(std::memory_order_relaxed);
|
|
4648
|
+
const std::uint64_t remaining = currentGen == 0 ? 0
|
|
4649
|
+
: std::uint64_t(std::numeric_limits<std::uint32_t>::max()) - currentGen + 1u;
|
|
4650
|
+
const bool legacyAvailable = required_slots <= remaining;
|
|
4651
|
+
*canAllocateView.data() = (available >= required_slots && legacyAvailable) ? 1 : 0;
|
|
4652
|
+
return status(AbiStatus::Ok);
|
|
4653
|
+
});
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
|
|
4657
|
+
extern "C" std::int32_t rundot_kinetix_world_capture_cache_bytes(
|
|
4658
|
+
std::uint32_t handle,
|
|
4659
|
+
std::uint64_t* output) noexcept {
|
|
4660
|
+
return guard([&]() {
|
|
4661
|
+
clearError();
|
|
4662
|
+
const CallerRange ranges[] = {
|
|
4663
|
+
{output, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output},
|
|
4664
|
+
};
|
|
4665
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4666
|
+
Pins3D pins;
|
|
4667
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4668
|
+
auto outputView = pins.view<std::uint64_t>(0);
|
|
4669
|
+
if (!outputView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4670
|
+
|
|
4671
|
+
return withWorld(handle, [&](World& world) {
|
|
4672
|
+
*outputView.data() = world.captureCacheBytes();
|
|
4673
|
+
return status(AbiStatus::Ok);
|
|
4674
|
+
});
|
|
4675
|
+
});
|
|
4676
|
+
}
|
|
4677
|
+
|
|
4678
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
4679
|
+
namespace {
|
|
4680
|
+
void advanceTestGeneration(std::atomic<std::uint32_t>& counter,
|
|
4681
|
+
std::uint32_t generation, std::uint32_t limit) noexcept {
|
|
4682
|
+
if (generation == 0 || generation > limit) return;
|
|
4683
|
+
auto current = counter.load(std::memory_order_relaxed);
|
|
4684
|
+
while (generation > current && !counter.compare_exchange_weak(current,
|
|
4685
|
+
generation, std::memory_order_relaxed, std::memory_order_relaxed)) {}
|
|
4686
|
+
}
|
|
4687
|
+
|
|
4688
|
+
bool restoreTestGeneration(std::atomic<std::uint32_t>& counter,
|
|
4689
|
+
std::uint32_t generation, std::uint32_t limit) noexcept {
|
|
4690
|
+
if (generation == 0 || generation > limit) return false;
|
|
4691
|
+
std::lock_guard<std::mutex> lock(slotsMutex);
|
|
4692
|
+
auto& ledger = rundot::kinetix::physics::geometry_private::InstanceMemoryLedger::instance();
|
|
4693
|
+
if (ledger.liveWorlds() != 0 || ledger.liveSlots() != 0) return false;
|
|
4694
|
+
counter.store(generation, std::memory_order_relaxed);
|
|
4695
|
+
return true;
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4699
|
+
extern "C" void rundot_kinetix_test_set_next_checkpoint_generation(
|
|
4700
|
+
std::uint32_t generation) noexcept {
|
|
4701
|
+
advanceTestGeneration(gNextCheckpointGeneration, generation,
|
|
4702
|
+
std::numeric_limits<std::uint32_t>::max());
|
|
4703
|
+
}
|
|
4704
|
+
|
|
4705
|
+
extern "C" void rundot_kinetix_test_set_next_legacy_generation(
|
|
4706
|
+
std::uint32_t generation) noexcept {
|
|
4707
|
+
if (generation == 0) return;
|
|
4708
|
+
auto current = gNextLegacyGeneration.load(std::memory_order_relaxed);
|
|
4709
|
+
while (current != 0 && generation > current
|
|
4710
|
+
&& !gNextLegacyGeneration.compare_exchange_weak(current, generation,
|
|
4711
|
+
std::memory_order_relaxed, std::memory_order_relaxed)) {}
|
|
4712
|
+
}
|
|
4713
|
+
|
|
4714
|
+
extern "C" bool rundot_kinetix_test_restore_checkpoint_generation(
|
|
4715
|
+
std::uint32_t generation) noexcept {
|
|
4716
|
+
return restoreTestGeneration(gNextCheckpointGeneration, generation,
|
|
4717
|
+
std::numeric_limits<std::uint32_t>::max());
|
|
4718
|
+
}
|
|
4719
|
+
|
|
4720
|
+
extern "C" bool rundot_kinetix_test_restore_legacy_generation(
|
|
4721
|
+
std::uint32_t generation) noexcept {
|
|
4722
|
+
return restoreTestGeneration(gNextLegacyGeneration, generation, std::numeric_limits<std::uint32_t>::max());
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4725
|
+
extern "C" void* rundot_kinetix_test_legacy_table(std::uint32_t handle) noexcept {
|
|
4726
|
+
void* output = nullptr;
|
|
4727
|
+
withControl(handle, [&](Slot::Control& control) {
|
|
4728
|
+
output = control.legacyIds.data();
|
|
4729
|
+
return status(AbiStatus::Ok);
|
|
4730
|
+
});
|
|
4731
|
+
return output;
|
|
4732
|
+
}
|
|
4733
|
+
|
|
4734
|
+
extern "C" void rundot_kinetix_test_pause_next_attach() noexcept {
|
|
4735
|
+
std::lock_guard<std::mutex> lock(destructionRaceTestState.mutex);
|
|
4736
|
+
destructionRaceTestState.pauseNextAttach = true;
|
|
4737
|
+
destructionRaceTestState.attachPaused = false;
|
|
4738
|
+
destructionRaceTestState.resumeAttach = false;
|
|
4739
|
+
destructionRaceTestState.destroyChecks = 0;
|
|
4740
|
+
destructionRaceTestState.destroyObservedAttached = false;
|
|
4741
|
+
}
|
|
4742
|
+
|
|
4743
|
+
extern "C" bool rundot_kinetix_test_wait_attach_paused(std::uint32_t timeoutMs) noexcept {
|
|
4744
|
+
std::unique_lock<std::mutex> lock(destructionRaceTestState.mutex);
|
|
4745
|
+
return destructionRaceTestState.changed.wait_for(lock,
|
|
4746
|
+
std::chrono::milliseconds(timeoutMs), [] {
|
|
4747
|
+
return destructionRaceTestState.attachPaused;
|
|
4748
|
+
});
|
|
4749
|
+
}
|
|
4750
|
+
|
|
4751
|
+
extern "C" void rundot_kinetix_test_resume_attach() noexcept {
|
|
4752
|
+
std::lock_guard<std::mutex> lock(destructionRaceTestState.mutex);
|
|
4753
|
+
destructionRaceTestState.resumeAttach = true;
|
|
4754
|
+
destructionRaceTestState.changed.notify_all();
|
|
4755
|
+
}
|
|
4756
|
+
|
|
4757
|
+
extern "C" bool rundot_kinetix_test_wait_destroy_attachment_check(
|
|
4758
|
+
std::uint32_t timeoutMs, bool* attached) noexcept {
|
|
4759
|
+
if (attached == nullptr) return false;
|
|
4760
|
+
std::unique_lock<std::mutex> lock(destructionRaceTestState.mutex);
|
|
4761
|
+
const bool observed = destructionRaceTestState.changed.wait_for(lock,
|
|
4762
|
+
std::chrono::milliseconds(timeoutMs), [] {
|
|
4763
|
+
return destructionRaceTestState.destroyChecks != 0;
|
|
4764
|
+
});
|
|
4765
|
+
if (observed) *attached = destructionRaceTestState.destroyObservedAttached;
|
|
4766
|
+
return observed;
|
|
4767
|
+
}
|
|
4768
|
+
|
|
4769
|
+
extern "C" void* rundot_kinetix_test_world(
|
|
4770
|
+
std::uint32_t handle) noexcept {
|
|
4771
|
+
const std::uint32_t encodedSlot = handle & kSlotMask;
|
|
4772
|
+
const std::uint32_t generation = handle >> 8;
|
|
4773
|
+
if (encodedSlot == 0 || encodedSlot > kMaxHandles || generation == 0) return nullptr;
|
|
4774
|
+
Slot& slot = slots[encodedSlot - 1];
|
|
4775
|
+
if (generation != slot.generation || !slot.control) return nullptr;
|
|
4776
|
+
return &slot.control->world;
|
|
4777
|
+
}
|
|
4778
|
+
|
|
4779
|
+
extern "C" std::uint32_t rundot_kinetix_test_checkpoint_generation() noexcept {
|
|
4780
|
+
return gNextCheckpointGeneration.load(std::memory_order_relaxed);
|
|
4781
|
+
}
|
|
4782
|
+
|
|
4783
|
+
extern "C" std::uint32_t rundot_kinetix_test_legacy_generation() noexcept {
|
|
4784
|
+
return gNextLegacyGeneration.load(std::memory_order_relaxed);
|
|
4785
|
+
}
|
|
4786
|
+
|
|
4787
|
+
extern "C" std::uint32_t rundot_kinetix_test_first_free(std::uint32_t handle) noexcept {
|
|
4788
|
+
std::uint32_t value = Slot::Control::kFreeListEnd;
|
|
4789
|
+
withControl(handle, [&](Slot::Control& control) {
|
|
4790
|
+
value = control.firstFree;
|
|
4791
|
+
return status(AbiStatus::Ok);
|
|
4792
|
+
});
|
|
4793
|
+
return value;
|
|
4794
|
+
}
|
|
4795
|
+
|
|
4796
|
+
extern "C" void rundot_kinetix_test_throw_after_slot_claim() noexcept {
|
|
4797
|
+
gThrowAfterSlotClaim = true;
|
|
4798
|
+
}
|
|
4799
|
+
|
|
4800
|
+
extern "C" void rundot_kinetix_test_arm_checkpoint_view_pin() noexcept {
|
|
4801
|
+
std::lock_guard<std::mutex> lock(viewPinTestState.mutex);
|
|
4802
|
+
viewPinTestState.arm = true;
|
|
4803
|
+
viewPinTestState.paused = false;
|
|
4804
|
+
viewPinTestState.resume = false;
|
|
4805
|
+
}
|
|
4806
|
+
|
|
4807
|
+
extern "C" bool rundot_kinetix_test_wait_checkpoint_view_pinned(
|
|
4808
|
+
std::uint32_t timeoutMs) noexcept {
|
|
4809
|
+
std::unique_lock<std::mutex> lock(viewPinTestState.mutex);
|
|
4810
|
+
return viewPinTestState.changed.wait_for(lock, std::chrono::milliseconds(timeoutMs), [] {
|
|
4811
|
+
return viewPinTestState.paused;
|
|
4812
|
+
});
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4815
|
+
extern "C" void rundot_kinetix_test_resume_checkpoint_view_pin() noexcept {
|
|
4816
|
+
std::lock_guard<std::mutex> lock(viewPinTestState.mutex);
|
|
4817
|
+
viewPinTestState.arm = false;
|
|
4818
|
+
viewPinTestState.resume = true;
|
|
4819
|
+
viewPinTestState.changed.notify_all();
|
|
4820
|
+
}
|
|
4821
|
+
#endif
|
|
4822
|
+
|
|
4823
|
+
extern "C" std::uint32_t rundot_kinetix_world_error_size() noexcept {
|
|
4824
|
+
return lastErrorSize;
|
|
4825
|
+
}
|
|
4826
|
+
|
|
4827
|
+
extern "C" std::uint32_t rundot_kinetix_world_error_command_index() noexcept {
|
|
4828
|
+
return lastErrorCommandIndex;
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4831
|
+
extern "C" std::int32_t rundot_kinetix_world_copy_error(
|
|
4832
|
+
std::uint8_t* output,
|
|
4833
|
+
std::uint32_t output_capacity,
|
|
4834
|
+
std::uint32_t* required_bytes) noexcept {
|
|
4835
|
+
return guard([&]() {
|
|
4836
|
+
bool rangeOverflow = false;
|
|
4837
|
+
const CallerRange ranges[] = {
|
|
4838
|
+
countedCallerRange(output, output_capacity, sizeof(std::uint8_t), alignof(std::uint8_t), RangeRole::Output, rangeOverflow),
|
|
4839
|
+
{required_bytes, sizeof(std::uint32_t), alignof(std::uint32_t), RangeRole::Output},
|
|
4840
|
+
};
|
|
4841
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
4842
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4843
|
+
Pins3D pins;
|
|
4844
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4845
|
+
auto outputView = pins.view<std::uint8_t>(0);
|
|
4846
|
+
auto requiredBytesView = pins.view<std::uint32_t>(1);
|
|
4847
|
+
if (!outputView || !requiredBytesView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4848
|
+
|
|
4849
|
+
*requiredBytesView.data() = lastErrorSize;
|
|
4850
|
+
if (output_capacity < lastErrorSize) {
|
|
4851
|
+
return status(AbiStatus::ShortBuffer);
|
|
4852
|
+
}
|
|
4853
|
+
if (lastErrorSize != 0) std::copy_n(lastError.data(), lastErrorSize, outputView.data());
|
|
4854
|
+
return status(AbiStatus::Ok);
|
|
4855
|
+
});
|
|
4856
|
+
}
|
|
4857
|
+
|
|
4858
|
+
extern "C" std::int32_t rundot_kinetix_instance_ledger_classes(
|
|
4859
|
+
std::uint64_t* bytes,
|
|
4860
|
+
std::uint64_t* high_water,
|
|
4861
|
+
std::uint32_t class_count) noexcept {
|
|
4862
|
+
return guard([&]() {
|
|
4863
|
+
clearError();
|
|
4864
|
+
bool rangeOverflow = false;
|
|
4865
|
+
const CallerRange ranges[] = {
|
|
4866
|
+
countedCallerRange(bytes, class_count, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output, rangeOverflow),
|
|
4867
|
+
countedCallerRange(high_water, class_count, sizeof(std::uint64_t), alignof(std::uint64_t), RangeRole::Output, rangeOverflow),
|
|
4868
|
+
};
|
|
4869
|
+
if (rangeOverflow) return fail(AbiStatus::InvalidArgument, "range is outside the address space");
|
|
4870
|
+
static_assert(std::size(ranges) <= rundot::kinetix::memory::kMaxCallerRanges);
|
|
4871
|
+
Pins3D pins;
|
|
4872
|
+
if (const auto err = admitCall(ranges, pins); err != AbiStatus::Ok) return status(err);
|
|
4873
|
+
auto bytesView = pins.view<std::uint64_t>(0);
|
|
4874
|
+
auto highWaterView = pins.view<std::uint64_t>(1);
|
|
4875
|
+
if (!bytesView || !highWaterView) return fail(AbiStatus::BufferRejected, "InvalidRange");
|
|
4876
|
+
|
|
4877
|
+
if (class_count != rundot::kinetix::memory::kLedgerClassCount) {
|
|
4878
|
+
return fail(AbiStatus::InvalidArgument, "ledger classes count must equal 9");
|
|
4879
|
+
}
|
|
4880
|
+
const auto snapshot = rundot::kinetix::memory::InstanceLedger<Module3D>::instance().read();
|
|
4881
|
+
if (snapshot.imbalanced) {
|
|
4882
|
+
return fail(AbiStatus::InternalFailure, "ledger imbalance detected");
|
|
4883
|
+
}
|
|
4884
|
+
std::copy_n(snapshot.bytes.data(), rundot::kinetix::memory::kLedgerClassCount, bytesView.data());
|
|
4885
|
+
std::copy_n(snapshot.highWaterBytes.data(), rundot::kinetix::memory::kLedgerClassCount, highWaterView.data());
|
|
4886
|
+
return status(AbiStatus::Ok);
|
|
4887
|
+
});
|
|
1354
4888
|
}
|