@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
|
@@ -2,19 +2,23 @@ const raycastQueryBytes = 48;
|
|
|
2
2
|
const overlapQueryBytes = 192;
|
|
3
3
|
const shapeCastQueryBytes = 216;
|
|
4
4
|
const closestPointsQueryBytes = 24;
|
|
5
|
-
const queryFilterBytes =
|
|
5
|
+
const queryFilterBytes = 16;
|
|
6
6
|
const castHitBytes = 64;
|
|
7
7
|
const closestPointHitBytes = 40;
|
|
8
8
|
const overlapHitBytes = 8;
|
|
9
|
+
const overlapContactHitBytes = 80;
|
|
9
10
|
const maxBodies = 4096;
|
|
10
11
|
const maxPolygonVertices = 8;
|
|
11
12
|
const maxQueryContextAlignment = 8;
|
|
12
13
|
const noFeature = 0xffffffff;
|
|
13
14
|
const queryKinds = Object.freeze({ static: 0, kinematic: 1, dynamic: 2 });
|
|
15
|
+
const filterFields = new Set(['bodyKinds', 'excludeBodyIds', 'layerMask',
|
|
16
|
+
'hitSolids', 'includeSensors', 'includeTriggers']);
|
|
14
17
|
|
|
15
18
|
const requestFields = Object.freeze({
|
|
16
19
|
raycast: new Set(['x', 'y', 'dx', 'dy', 'maxDistance', 'filter', 'maxResults']),
|
|
17
20
|
overlap: new Set(['shape', 'x', 'y', 'angle', 'filter', 'maxResults']),
|
|
21
|
+
overlapContacts: new Set(['shape', 'x', 'y', 'angle', 'filter', 'maxResults']),
|
|
18
22
|
shapeCast: new Set(['shape', 'x', 'y', 'angle', 'dx', 'dy', 'maxDistance', 'filter', 'maxResults']),
|
|
19
23
|
closestPoints: new Set(['x', 'y', 'filter', 'maxResults']),
|
|
20
24
|
});
|
|
@@ -66,13 +70,23 @@ function normalizeMaxResults(value) {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
function normalizeFilter(input, encodeBodyId) {
|
|
69
|
-
if (input === undefined) {
|
|
70
|
-
return { bodyKindMask: 7, excludedIds: [] };
|
|
71
|
-
}
|
|
73
|
+
if (input === undefined) input = {};
|
|
72
74
|
if (!input || typeof input !== 'object' || Array.isArray(input)) queryFail('INVALID_FILTER: filter must be an object');
|
|
73
75
|
const filter = input;
|
|
74
76
|
for (const key of Object.keys(filter)) {
|
|
75
|
-
if (key
|
|
77
|
+
if (!filterFields.has(key)) queryFail(`INVALID_FILTER: unknown field filter.${key}`);
|
|
78
|
+
}
|
|
79
|
+
const layerMask = filter.layerMask === undefined ? 0xffffffff : filter.layerMask;
|
|
80
|
+
if (!Number.isInteger(layerMask) || layerMask < 0 || layerMask > 0xffffffff) {
|
|
81
|
+
queryFail('INVALID_FILTER: layerMask must be an unsigned 32-bit integer');
|
|
82
|
+
}
|
|
83
|
+
let flags = 0;
|
|
84
|
+
for (const [field, bit, defaultValue] of [
|
|
85
|
+
['hitSolids', 1, true], ['includeSensors', 2, false], ['includeTriggers', 4, false],
|
|
86
|
+
]) {
|
|
87
|
+
const value = filter[field] === undefined ? defaultValue : filter[field];
|
|
88
|
+
if (typeof value !== 'boolean') queryFail(`INVALID_FILTER: ${field} must be Boolean`);
|
|
89
|
+
if (value) flags |= bit;
|
|
76
90
|
}
|
|
77
91
|
let bodyKindMask = 7;
|
|
78
92
|
if (filter.bodyKinds !== undefined) {
|
|
@@ -85,14 +99,14 @@ function normalizeFilter(input, encodeBodyId) {
|
|
|
85
99
|
bodyKindMask |= 1 << queryKinds[kind];
|
|
86
100
|
}
|
|
87
101
|
}
|
|
88
|
-
if (filter.excludeBodyIds === undefined) return { bodyKindMask, excludedIds: [] };
|
|
102
|
+
if (filter.excludeBodyIds === undefined) return { bodyKindMask, layerMask, flags, excludedIds: [] };
|
|
89
103
|
if (!Array.isArray(filter.excludeBodyIds)) queryFail('INVALID_FILTER: excludeBodyIds must be an array');
|
|
90
104
|
const excluded = new Set();
|
|
91
105
|
for (const id of filter.excludeBodyIds) {
|
|
92
106
|
const ordinal = encodeBodyId(id);
|
|
93
107
|
if (ordinal !== undefined) excluded.add(ordinal);
|
|
94
108
|
}
|
|
95
|
-
return { bodyKindMask, excludedIds: [...excluded].sort((a, b) => a - b) };
|
|
109
|
+
return { bodyKindMask, layerMask, flags, excludedIds: [...excluded].sort((a, b) => a - b) };
|
|
96
110
|
}
|
|
97
111
|
|
|
98
112
|
export function normalizeRequest(input, kind, encodeBodyId, normalizeShape) {
|
|
@@ -115,7 +129,7 @@ export function normalizeRequest(input, kind, encodeBodyId, normalizeShape) {
|
|
|
115
129
|
filter,
|
|
116
130
|
maxResults,
|
|
117
131
|
};
|
|
118
|
-
if (kind === 'overlap') {
|
|
132
|
+
if (kind === 'overlap' || kind === 'overlapContacts') {
|
|
119
133
|
normalized.shape = normalizeShape(request.shape, false).normalizedShape;
|
|
120
134
|
return normalized;
|
|
121
135
|
}
|
|
@@ -145,6 +159,8 @@ function writeShape(view, offset, shape, shapeCodes) {
|
|
|
145
159
|
export function writeFilter(view, offset, filter) {
|
|
146
160
|
view.setUint32(offset, filter.bodyKindMask, true);
|
|
147
161
|
view.setUint32(offset + 4, filter.excludedIds.length, true);
|
|
162
|
+
view.setUint32(offset + 8, filter.layerMask, true);
|
|
163
|
+
view.setUint32(offset + 12, filter.flags, true);
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
export function statusError(status) {
|
|
@@ -194,8 +210,8 @@ export function readCastHits(view, outputPointer, count, decodeBodyId, maxDistan
|
|
|
194
210
|
}
|
|
195
211
|
results.push(Object.freeze({ kind: 'initialOverlap', bodyId: decodeBodyId(bodyId), distance: 0, fraction: 0 }));
|
|
196
212
|
} else {
|
|
197
|
-
const
|
|
198
|
-
if (featureId === noFeature ||
|
|
213
|
+
const normalLengthSq = normalX * normalX + normalY * normalY;
|
|
214
|
+
if (featureId === noFeature || normalLengthSq === 0 || Math.abs(normalLengthSq - 1) > 4e-12) {
|
|
199
215
|
queryFail('NATIVE_OUTPUT_INVALID');
|
|
200
216
|
}
|
|
201
217
|
results.push(Object.freeze({
|
|
@@ -244,6 +260,38 @@ export function readClosestPoints(view, outputPointer, count, decodeBodyId) {
|
|
|
244
260
|
return Object.freeze(results);
|
|
245
261
|
}
|
|
246
262
|
|
|
263
|
+
export function readOverlapContacts(view, outputPointer, count, decodeBodyId) {
|
|
264
|
+
const contacts = [];
|
|
265
|
+
let previous = -1;
|
|
266
|
+
for (let index = 0; index < count; index += 1) {
|
|
267
|
+
const offset = outputPointer + index * overlapContactHitBytes;
|
|
268
|
+
const bodyId = view.getUint32(offset, true);
|
|
269
|
+
if (bodyId <= previous) queryFail('NATIVE_OUTPUT_INVALID');
|
|
270
|
+
previous = bodyId;
|
|
271
|
+
const pointCount = view.getUint32(offset + 4, true);
|
|
272
|
+
if (pointCount === 0 || pointCount > 2) queryFail('NATIVE_OUTPUT_INVALID');
|
|
273
|
+
const normalX = view.getFloat64(offset + 8, true);
|
|
274
|
+
const normalY = view.getFloat64(offset + 16, true);
|
|
275
|
+
const depth = view.getFloat64(offset + 24, true);
|
|
276
|
+
const points = [];
|
|
277
|
+
for (let p = 0; p < pointCount; p += 1) {
|
|
278
|
+
const pOffset = offset + 32 + p * 24;
|
|
279
|
+
points.push(Object.freeze({
|
|
280
|
+
x: view.getFloat64(pOffset, true),
|
|
281
|
+
y: view.getFloat64(pOffset + 8, true),
|
|
282
|
+
featureId: view.getUint32(pOffset + 16, true),
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
contacts.push(Object.freeze({
|
|
286
|
+
bodyId: decodeBodyId(bodyId),
|
|
287
|
+
normal: Object.freeze({ x: normalX, y: normalY }),
|
|
288
|
+
depth,
|
|
289
|
+
points: Object.freeze(points),
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
return Object.freeze(contacts);
|
|
293
|
+
}
|
|
294
|
+
|
|
247
295
|
export function readOverlap(view, outputPointer, count, decodeBodyId) {
|
|
248
296
|
const ids = [];
|
|
249
297
|
let previous = -1;
|
|
@@ -277,7 +325,7 @@ export function writeQueryRequest(view, requestPointer, request, kind, shapeCode
|
|
|
277
325
|
view.setFloat64(requestPointer + 32, request.maxDistance, true);
|
|
278
326
|
view.setUint32(requestPointer + 40, request.maxResults, true);
|
|
279
327
|
}
|
|
280
|
-
} else if (kind === 'overlap') {
|
|
328
|
+
} else if (kind === 'overlap' || kind === 'overlapContacts') {
|
|
281
329
|
writeShape(view, requestPointer, request.shape, shapeCodes);
|
|
282
330
|
view.setFloat64(requestPointer + 160, request.x, true);
|
|
283
331
|
view.setFloat64(requestPointer + 168, request.y, true);
|
|
@@ -292,11 +340,11 @@ export function writeQueryRequest(view, requestPointer, request, kind, shapeCode
|
|
|
292
340
|
|
|
293
341
|
export const queryAbi = Object.freeze({
|
|
294
342
|
requestBytes: Object.freeze({
|
|
295
|
-
raycast: raycastQueryBytes, overlap: overlapQueryBytes,
|
|
343
|
+
raycast: raycastQueryBytes, overlap: overlapQueryBytes, overlapContacts: overlapQueryBytes,
|
|
296
344
|
shapeCast: shapeCastQueryBytes, closestPoints: closestPointsQueryBytes,
|
|
297
345
|
}),
|
|
298
346
|
resultBytes: Object.freeze({
|
|
299
|
-
raycast: castHitBytes, overlap: overlapHitBytes,
|
|
347
|
+
raycast: castHitBytes, overlap: overlapHitBytes, overlapContacts: overlapContactHitBytes,
|
|
300
348
|
shapeCast: castHitBytes, closestPoints: closestPointHitBytes,
|
|
301
349
|
}),
|
|
302
350
|
filterBytes: queryFilterBytes,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Dimensionless, CubicMeters, Meters, Radians, SquareMeters } from '../../units.js';
|
|
3
|
+
import type { PhysicsVertex2D } from '../../physics2d-owned.js';
|
|
4
|
+
|
|
5
|
+
export type PhysicsSubmergedShape2D =
|
|
6
|
+
| { readonly type: 'circle'; readonly radius: Meters }
|
|
7
|
+
| { readonly type: 'box'; readonly halfX: Meters; readonly halfY: Meters }
|
|
8
|
+
| { readonly type: 'capsule'; readonly halfLength: Meters; readonly radius: Meters }
|
|
9
|
+
| { readonly type: 'polygon'; readonly vertices: readonly PhysicsVertex2D<Meters>[] };
|
|
10
|
+
|
|
11
|
+
export interface PhysicsSubmergedBody2D {
|
|
12
|
+
readonly shape: PhysicsSubmergedShape2D;
|
|
13
|
+
readonly x?: Meters;
|
|
14
|
+
readonly y?: Meters;
|
|
15
|
+
readonly angle?: Radians;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PhysicsSubmergedFluid2D {
|
|
19
|
+
readonly bounds: {
|
|
20
|
+
readonly minX: Meters;
|
|
21
|
+
readonly maxX: Meters;
|
|
22
|
+
readonly minY: Meters;
|
|
23
|
+
readonly maxY: Meters;
|
|
24
|
+
};
|
|
25
|
+
readonly plane?: {
|
|
26
|
+
readonly normal: PhysicsVertex2D<Dimensionless>;
|
|
27
|
+
readonly offset: Meters;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PhysicsSubmergedGeometry2D {
|
|
32
|
+
readonly area: SquareMeters;
|
|
33
|
+
readonly centroid: PhysicsVertex2D<Meters>;
|
|
34
|
+
readonly firstMoment: { readonly x: CubicMeters; readonly y: CubicMeters };
|
|
35
|
+
readonly fullArea: SquareMeters;
|
|
36
|
+
readonly fraction: Dimensionless;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PhysicsSubmergedQuery2D {
|
|
40
|
+
readonly body: PhysicsSubmergedBody2D;
|
|
41
|
+
readonly fluid: PhysicsSubmergedFluid2D;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function calculatePhysics2DSubmergedGeometry(
|
|
45
|
+
body: PhysicsSubmergedBody2D,
|
|
46
|
+
fluid: PhysicsSubmergedFluid2D,
|
|
47
|
+
): PhysicsSubmergedGeometry2D;
|
|
48
|
+
|
|
49
|
+
export function calculatePhysics2DSubmergedGeometryBatch(
|
|
50
|
+
queries: readonly PhysicsSubmergedQuery2D[],
|
|
51
|
+
): readonly PhysicsSubmergedGeometry2D[];
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { bodyAbi, shapeCodes } from './body-state.mjs';
|
|
2
|
+
import { ready } from './wasm-instance.mjs';
|
|
3
|
+
|
|
4
|
+
const inputBytes = 248;
|
|
5
|
+
const outputBytes = 56;
|
|
6
|
+
const maxQueries = 4096;
|
|
7
|
+
const offsets = Object.freeze({
|
|
8
|
+
shape: 0,
|
|
9
|
+
vertexCount: 4,
|
|
10
|
+
planeEnabled: 8,
|
|
11
|
+
x: 16,
|
|
12
|
+
y: 24,
|
|
13
|
+
angle: 32,
|
|
14
|
+
halfX: 40,
|
|
15
|
+
halfY: 48,
|
|
16
|
+
radius: 56,
|
|
17
|
+
minX: 64,
|
|
18
|
+
maxX: 72,
|
|
19
|
+
minY: 80,
|
|
20
|
+
maxY: 88,
|
|
21
|
+
planeNormalX: 96,
|
|
22
|
+
planeNormalY: 104,
|
|
23
|
+
planeOffset: 112,
|
|
24
|
+
vertices: 120,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function fail(category, detail) {
|
|
28
|
+
throw new Error(`KINETIX_PHYSICS2D_SUBMERGED_GEOMETRY_${category}: ${detail}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function number(value, name) {
|
|
32
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) fail('INVALID_INPUT', `${name} must be finite`);
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function optionalNumber(value, fallback, name) {
|
|
37
|
+
return number(value === undefined ? fallback : value, name);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function normalizeBody(input) {
|
|
41
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) fail('INVALID_INPUT', 'body must be an object');
|
|
42
|
+
const shape = input.shape;
|
|
43
|
+
if (!shape || typeof shape !== 'object' || Array.isArray(shape)
|
|
44
|
+
|| typeof shape.type !== 'string' || !Object.hasOwn(shapeCodes, shape.type)
|
|
45
|
+
|| !['circle', 'box', 'capsule', 'polygon'].includes(shape.type)) {
|
|
46
|
+
fail('INVALID_INPUT', 'body.shape must use circle, box, capsule, or polygon');
|
|
47
|
+
}
|
|
48
|
+
const normalizedShape = { type: shape.type };
|
|
49
|
+
if (shape.type === 'circle') {
|
|
50
|
+
normalizedShape.radius = number(shape.radius, 'body.shape.radius');
|
|
51
|
+
} else if (shape.type === 'box') {
|
|
52
|
+
normalizedShape.halfX = number(shape.halfX, 'body.shape.halfX');
|
|
53
|
+
normalizedShape.halfY = number(shape.halfY, 'body.shape.halfY');
|
|
54
|
+
} else if (shape.type === 'capsule') {
|
|
55
|
+
normalizedShape.halfLength = number(shape.halfLength, 'body.shape.halfLength');
|
|
56
|
+
normalizedShape.radius = number(shape.radius, 'body.shape.radius');
|
|
57
|
+
} else {
|
|
58
|
+
if (!Array.isArray(shape.vertices) || shape.vertices.length < 3
|
|
59
|
+
|| shape.vertices.length > bodyAbi.maxPolygonVertices) {
|
|
60
|
+
fail('INVALID_INPUT', `body.shape.vertices must contain 3-${bodyAbi.maxPolygonVertices} vertices`);
|
|
61
|
+
}
|
|
62
|
+
normalizedShape.vertices = shape.vertices.map((vertex, index) => Object.freeze({
|
|
63
|
+
x: number(vertex?.x, `body.shape.vertices[${index}].x`),
|
|
64
|
+
y: number(vertex?.y, `body.shape.vertices[${index}].y`),
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
shape: Object.freeze(normalizedShape),
|
|
69
|
+
x: optionalNumber(input.x, 0, 'body.x'),
|
|
70
|
+
y: optionalNumber(input.y, 0, 'body.y'),
|
|
71
|
+
angle: optionalNumber(input.angle, 0, 'body.angle'),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function normalizeFluid(input) {
|
|
76
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) fail('INVALID_INPUT', 'fluid must be an object');
|
|
77
|
+
const bounds = input.bounds;
|
|
78
|
+
if (!bounds || typeof bounds !== 'object' || Array.isArray(bounds)) fail('INVALID_INPUT', 'fluid.bounds must be an object');
|
|
79
|
+
let plane;
|
|
80
|
+
if (input.plane !== undefined) {
|
|
81
|
+
if (!input.plane || typeof input.plane !== 'object' || Array.isArray(input.plane)
|
|
82
|
+
|| !input.plane.normal || typeof input.plane.normal !== 'object' || Array.isArray(input.plane.normal)) {
|
|
83
|
+
fail('INVALID_INPUT', 'fluid.plane.normal must be an object');
|
|
84
|
+
}
|
|
85
|
+
plane = Object.freeze({
|
|
86
|
+
normalX: number(input.plane.normal.x, 'fluid.plane.normal.x'),
|
|
87
|
+
normalY: number(input.plane.normal.y, 'fluid.plane.normal.y'),
|
|
88
|
+
offset: number(input.plane.offset, 'fluid.plane.offset'),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return Object.freeze({
|
|
92
|
+
bounds: Object.freeze({
|
|
93
|
+
minX: number(bounds.minX, 'fluid.bounds.minX'),
|
|
94
|
+
maxX: number(bounds.maxX, 'fluid.bounds.maxX'),
|
|
95
|
+
minY: number(bounds.minY, 'fluid.bounds.minY'),
|
|
96
|
+
maxY: number(bounds.maxY, 'fluid.bounds.maxY'),
|
|
97
|
+
}),
|
|
98
|
+
plane,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function writeInput(view, offset, query) {
|
|
103
|
+
const { body, fluid } = query;
|
|
104
|
+
const { shape } = body;
|
|
105
|
+
view.setUint32(offset + offsets.shape, shapeCodes[shape.type], true);
|
|
106
|
+
view.setUint32(offset + offsets.vertexCount, shape.type === 'polygon' ? shape.vertices.length : 0, true);
|
|
107
|
+
view.setUint32(offset + offsets.planeEnabled, fluid.plane ? 1 : 0, true);
|
|
108
|
+
view.setUint32(offset + 12, 0, true);
|
|
109
|
+
view.setFloat64(offset + offsets.x, body.x, true);
|
|
110
|
+
view.setFloat64(offset + offsets.y, body.y, true);
|
|
111
|
+
view.setFloat64(offset + offsets.angle, body.angle, true);
|
|
112
|
+
view.setFloat64(offset + offsets.halfX, shape.type === 'box' ? shape.halfX
|
|
113
|
+
: shape.type === 'capsule' ? shape.halfLength : 0, true);
|
|
114
|
+
view.setFloat64(offset + offsets.halfY, shape.type === 'box' ? shape.halfY : 0, true);
|
|
115
|
+
view.setFloat64(offset + offsets.radius,
|
|
116
|
+
shape.type === 'circle' || shape.type === 'capsule' ? shape.radius : 0, true);
|
|
117
|
+
view.setFloat64(offset + offsets.minX, fluid.bounds.minX, true);
|
|
118
|
+
view.setFloat64(offset + offsets.maxX, fluid.bounds.maxX, true);
|
|
119
|
+
view.setFloat64(offset + offsets.minY, fluid.bounds.minY, true);
|
|
120
|
+
view.setFloat64(offset + offsets.maxY, fluid.bounds.maxY, true);
|
|
121
|
+
view.setFloat64(offset + offsets.planeNormalX, fluid.plane?.normalX ?? 0, true);
|
|
122
|
+
view.setFloat64(offset + offsets.planeNormalY, fluid.plane?.normalY ?? 0, true);
|
|
123
|
+
view.setFloat64(offset + offsets.planeOffset, fluid.plane?.offset ?? 0, true);
|
|
124
|
+
for (let index = 0; index < bodyAbi.maxPolygonVertices; index += 1) {
|
|
125
|
+
const vertex = shape.type === 'polygon' ? shape.vertices[index] : undefined;
|
|
126
|
+
view.setFloat64(offset + offsets.vertices + index * 16, vertex?.x ?? 0, true);
|
|
127
|
+
view.setFloat64(offset + offsets.vertices + index * 16 + 8, vertex?.y ?? 0, true);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function readOutput(view, offset) {
|
|
132
|
+
const result = Object.freeze({
|
|
133
|
+
area: view.getFloat64(offset, true),
|
|
134
|
+
centroid: Object.freeze({ x: view.getFloat64(offset + 8, true), y: view.getFloat64(offset + 16, true) }),
|
|
135
|
+
firstMoment: Object.freeze({ x: view.getFloat64(offset + 24, true), y: view.getFloat64(offset + 32, true) }),
|
|
136
|
+
fullArea: view.getFloat64(offset + 40, true),
|
|
137
|
+
fraction: view.getFloat64(offset + 48, true),
|
|
138
|
+
});
|
|
139
|
+
const values = [result.area, result.centroid.x, result.centroid.y,
|
|
140
|
+
result.firstMoment.x, result.firstMoment.y, result.fullArea, result.fraction];
|
|
141
|
+
if (values.some((value) => !Number.isFinite(value))) fail('NON_FINITE_OUTPUT', 'native output is not finite');
|
|
142
|
+
if (result.area < 0 || result.fullArea <= 0 || result.fraction < 0 || result.fraction > 1) {
|
|
143
|
+
fail('INVALID_OUTPUT', 'native output violates area bounds');
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function checkStatus(status) {
|
|
149
|
+
if (status === 0) return;
|
|
150
|
+
if (status === -1) fail('INVALID_ARGUMENTS', 'native argument validation failed');
|
|
151
|
+
if (status === -2) fail('INVALID_INPUT', 'native shape or fluid validation failed');
|
|
152
|
+
if (status === -3) fail('CAPACITY_EXCEEDED', `at most ${maxQueries} queries are supported`);
|
|
153
|
+
if (status === -4) fail('NON_FINITE_OUTPUT', 'native output is not finite');
|
|
154
|
+
if (status === -5) fail('NUMERICAL_RESOLUTION', 'intersection is below the supported numeric resolution');
|
|
155
|
+
fail('STATUS_INVALID', `native status ${status}`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function calculatePhysics2DSubmergedGeometryBatch(queries) {
|
|
159
|
+
const exports = ready();
|
|
160
|
+
if (!Array.isArray(queries)) fail('INVALID_INPUT', 'queries must be an array');
|
|
161
|
+
if (queries.length > maxQueries) fail('CAPACITY_EXCEEDED', `at most ${maxQueries} queries are supported`);
|
|
162
|
+
if (queries.length === 0) return Object.freeze([]);
|
|
163
|
+
const normalized = queries.map((query, index) => {
|
|
164
|
+
if (!query || typeof query !== 'object' || Array.isArray(query)) {
|
|
165
|
+
fail('INVALID_INPUT', `queries[${index}] must be an object`);
|
|
166
|
+
}
|
|
167
|
+
return Object.freeze({ body: normalizeBody(query.body), fluid: normalizeFluid(query.fluid) });
|
|
168
|
+
});
|
|
169
|
+
const inputSize = normalized.length * inputBytes;
|
|
170
|
+
const pointer = exports.malloc(inputSize + normalized.length * outputBytes);
|
|
171
|
+
if (!pointer) throw new Error('KINETIX_PHYSICS2D_ALLOCATION_FAILED');
|
|
172
|
+
try {
|
|
173
|
+
const view = new DataView(exports.memory.buffer);
|
|
174
|
+
normalized.forEach((query, index) => writeInput(view, pointer + index * inputBytes, query));
|
|
175
|
+
checkStatus(exports.rundot_physics2d_submerged_geometry(
|
|
176
|
+
pointer, normalized.length, pointer + inputSize, normalized.length));
|
|
177
|
+
return Object.freeze(normalized.map((_, index) => readOutput(
|
|
178
|
+
new DataView(exports.memory.buffer), pointer + inputSize + index * outputBytes)));
|
|
179
|
+
} finally {
|
|
180
|
+
exports.free(pointer);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function calculatePhysics2DSubmergedGeometry(body, fluid) {
|
|
185
|
+
return calculatePhysics2DSubmergedGeometryBatch([{ body, fluid }])[0];
|
|
186
|
+
}
|
package/core/src/runtime.mjs
CHANGED
|
@@ -21,3 +21,26 @@ export {
|
|
|
21
21
|
encodeKinetixSessionConfig,
|
|
22
22
|
kinetixSessionConfigDigest,
|
|
23
23
|
} from './kinetix-session-config.mjs';
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
DETERMINISTIC_MATH_SOURCE,
|
|
27
|
+
DETERMINISTIC_MATH_PROFILE,
|
|
28
|
+
DETERMINISTIC_MATH_VERSION,
|
|
29
|
+
DETERMINISTIC_MATH_FUNCTIONS,
|
|
30
|
+
DETERMINISTIC_MATH_KNOWN_ANSWERS,
|
|
31
|
+
DeterministicMathConflictError,
|
|
32
|
+
verifyDeterministicMathKnownAnswers,
|
|
33
|
+
isDeterministicMathInstalled,
|
|
34
|
+
installDeterministicMath,
|
|
35
|
+
ensureDeterministicMathInstalled,
|
|
36
|
+
createInitialStateWithDeterministicMath,
|
|
37
|
+
} from './kinetix-deterministic-math.mjs';
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
copyUint8Array,
|
|
41
|
+
uint8ArrayByteLength,
|
|
42
|
+
} from "./shared/bytes.mjs";
|
|
43
|
+
export {
|
|
44
|
+
prepareSha256Hex,
|
|
45
|
+
sha256Hex,
|
|
46
|
+
} from "./shared/sha256.mjs";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const ByteArray = Uint8Array;
|
|
2
|
+
const typedArrayPrototype = Object.getPrototypeOf(ByteArray.prototype);
|
|
3
|
+
const kind = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
|
|
4
|
+
const length = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'byteLength').get;
|
|
5
|
+
const buffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'buffer').get;
|
|
6
|
+
const offset = Object.getOwnPropertyDescriptor(typedArrayPrototype, 'byteOffset').get;
|
|
7
|
+
const bufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get;
|
|
8
|
+
const resizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable')?.get;
|
|
9
|
+
const set = ByteArray.prototype.set;
|
|
10
|
+
|
|
11
|
+
/** Require fixed, local Uint8Array storage. Caller properties do not define its type. */
|
|
12
|
+
export function uint8ArrayByteLength(value) {
|
|
13
|
+
try {
|
|
14
|
+
if (kind.call(value) !== 'Uint8Array') return undefined;
|
|
15
|
+
const storage = buffer.call(value);
|
|
16
|
+
bufferLength.call(storage);
|
|
17
|
+
if (resizable?.call(storage)) return undefined;
|
|
18
|
+
const count = length.call(value);
|
|
19
|
+
// This also rejects a detached buffer when the view has zero length.
|
|
20
|
+
new ByteArray(storage, offset.call(value), 0);
|
|
21
|
+
return count;
|
|
22
|
+
} catch { return undefined; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Copy a range without caller getters, iterators, or species constructors. */
|
|
26
|
+
export function copyUint8Array(value, start = 0, end = uint8ArrayByteLength(value)) {
|
|
27
|
+
const count = uint8ArrayByteLength(value);
|
|
28
|
+
if (count === undefined || !Number.isSafeInteger(start) || !Number.isSafeInteger(end)
|
|
29
|
+
|| start < 0 || end < start || end > count) throw new TypeError('Invalid byte array range.');
|
|
30
|
+
const output = new ByteArray(end - start);
|
|
31
|
+
set.call(output, new ByteArray(buffer.call(value), offset.call(value) + start, end - start));
|
|
32
|
+
return output;
|
|
33
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const SHA256_K = new
|
|
1
|
+
const SHA256_K = new Int32Array([
|
|
2
2
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
3
3
|
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
4
4
|
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
@@ -10,29 +10,59 @@ const SHA256_K = new Uint32Array([
|
|
|
10
10
|
]);
|
|
11
11
|
|
|
12
12
|
function rotr(x, n) {
|
|
13
|
-
return (
|
|
13
|
+
return (x >>> n) | (x << (32 - n));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let nodeCreateHash = null;
|
|
17
|
+
try {
|
|
18
|
+
if (typeof process !== 'undefined' && typeof process.getBuiltinModule === 'function') {
|
|
19
|
+
nodeCreateHash = process.getBuiltinModule('node:crypto')?.createHash ?? null;
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
nodeCreateHash = null;
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
export function sha256Hex(bytes) {
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
if (nodeCreateHash !== null) {
|
|
27
|
+
return nodeCreateHash("sha256").update(bytes).digest("hex");
|
|
28
|
+
}
|
|
29
|
+
return sha256HexPureJs(bytes);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function sha256HexPureJs(bytes) {
|
|
33
|
+
if (!ArrayBuffer.isView(bytes)) {
|
|
34
|
+
throw new TypeError('Expected Uint8Array or ArrayBufferView');
|
|
35
|
+
}
|
|
36
|
+
const input = bytes instanceof Uint8Array
|
|
37
|
+
? bytes
|
|
38
|
+
: new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
39
|
+
return hashPrepared(input, preparePureJs(input.byteLength));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function preparePureJs(len) {
|
|
43
|
+
const paddedLen = Math.ceil((len + 9) / 64) * 64;
|
|
19
44
|
const padded = new Uint8Array(paddedLen);
|
|
20
|
-
padded.set(bytes);
|
|
21
45
|
padded[len] = 0x80;
|
|
22
46
|
const dv = new DataView(padded.buffer);
|
|
23
47
|
dv.setUint32(paddedLen - 8, Math.floor(len / 0x20000000), false);
|
|
24
48
|
dv.setUint32(paddedLen - 4, (len << 3) >>> 0, false);
|
|
25
49
|
|
|
26
|
-
const h = new
|
|
50
|
+
const h = new Int32Array([
|
|
27
51
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
28
52
|
]);
|
|
29
|
-
const w = new
|
|
53
|
+
const w = new Int32Array(64);
|
|
54
|
+
return { len, paddedLen, padded, dv, h, w };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function hashPrepared(input, scratch) {
|
|
58
|
+
const { paddedLen, padded, dv, h, w } = scratch;
|
|
59
|
+
padded.set(input);
|
|
30
60
|
for (let offset = 0; offset < paddedLen; offset += 64) {
|
|
31
|
-
for (let i = 0; i < 16; i += 1) w[i] = dv.
|
|
61
|
+
for (let i = 0; i < 16; i += 1) w[i] = dv.getInt32(offset + i * 4, false);
|
|
32
62
|
for (let i = 16; i < 64; i += 1) {
|
|
33
63
|
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
|
34
64
|
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
35
|
-
w[i] = (w[i - 16] + s0 + w[i - 7] + s1)
|
|
65
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
|
|
36
66
|
}
|
|
37
67
|
let a = h[0];
|
|
38
68
|
let b = h[1];
|
|
@@ -45,29 +75,49 @@ export function sha256Hex(bytes) {
|
|
|
45
75
|
for (let i = 0; i < 64; i += 1) {
|
|
46
76
|
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
47
77
|
const ch = (e & f) ^ (~e & g);
|
|
48
|
-
const t1 = (hh + S1 + ch + SHA256_K[i] + w[i])
|
|
78
|
+
const t1 = (hh + S1 + ch + SHA256_K[i] + w[i]) | 0;
|
|
49
79
|
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
50
80
|
const maj = (a & b) ^ (a & cc) ^ (b & cc);
|
|
51
|
-
const t2 = (S0 + maj)
|
|
81
|
+
const t2 = (S0 + maj) | 0;
|
|
52
82
|
hh = g;
|
|
53
83
|
g = f;
|
|
54
84
|
f = e;
|
|
55
|
-
e = (d + t1)
|
|
85
|
+
e = (d + t1) | 0;
|
|
56
86
|
d = cc;
|
|
57
87
|
cc = b;
|
|
58
88
|
b = a;
|
|
59
|
-
a = (t1 + t2)
|
|
89
|
+
a = (t1 + t2) | 0;
|
|
60
90
|
}
|
|
61
|
-
h[0] = (h[0] + a)
|
|
62
|
-
h[1] = (h[1] + b)
|
|
63
|
-
h[2] = (h[2] + cc)
|
|
64
|
-
h[3] = (h[3] + d)
|
|
65
|
-
h[4] = (h[4] + e)
|
|
66
|
-
h[5] = (h[5] + f)
|
|
67
|
-
h[6] = (h[6] + g)
|
|
68
|
-
h[7] = (h[7] + hh)
|
|
91
|
+
h[0] = (h[0] + a) | 0;
|
|
92
|
+
h[1] = (h[1] + b) | 0;
|
|
93
|
+
h[2] = (h[2] + cc) | 0;
|
|
94
|
+
h[3] = (h[3] + d) | 0;
|
|
95
|
+
h[4] = (h[4] + e) | 0;
|
|
96
|
+
h[5] = (h[5] + f) | 0;
|
|
97
|
+
h[6] = (h[6] + g) | 0;
|
|
98
|
+
h[7] = (h[7] + hh) | 0;
|
|
69
99
|
}
|
|
70
100
|
let hex = '';
|
|
71
|
-
for (let i = 0; i < 8; i += 1) hex += h[i].toString(16).padStart(8, '0');
|
|
101
|
+
for (let i = 0; i < 8; i += 1) hex += (h[i] >>> 0).toString(16).padStart(8, '0');
|
|
72
102
|
return hex;
|
|
73
103
|
}
|
|
104
|
+
export function prepareSha256Hex(byteLength) {
|
|
105
|
+
if (!Number.isSafeInteger(byteLength) || byteLength < 0 || byteLength > 0x7ffffff0) {
|
|
106
|
+
throw new RangeError('Invalid SHA-256 input length.');
|
|
107
|
+
}
|
|
108
|
+
const nodeHash = nodeCreateHash === null ? null : nodeCreateHash('sha256');
|
|
109
|
+
const scratch = nodeHash === null ? preparePureJs(byteLength) : null;
|
|
110
|
+
let finished = false;
|
|
111
|
+
return (bytes) => {
|
|
112
|
+
if (finished) throw new Error('SHA-256 writer is already finished.');
|
|
113
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
114
|
+
throw new TypeError('SHA-256 writer requires a Uint8Array.');
|
|
115
|
+
}
|
|
116
|
+
if (bytes.byteLength !== byteLength) {
|
|
117
|
+
throw new TypeError('SHA-256 writer input length does not match.');
|
|
118
|
+
}
|
|
119
|
+
finished = true;
|
|
120
|
+
if (nodeHash !== null) return nodeHash.update(bytes).digest('hex');
|
|
121
|
+
return hashPrepared(bytes, scratch);
|
|
122
|
+
};
|
|
123
|
+
}
|
package/core/units.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
declare const UnitBrand: unique symbol;
|
|
2
|
+
|
|
3
|
+
export type Quantity<Unit extends string> = number & { readonly [UnitBrand]: Unit };
|
|
4
|
+
export type Dimensionless = number & { readonly [UnitBrand]?: never };
|
|
5
|
+
|
|
6
|
+
export type Meters = Quantity<'m'>;
|
|
7
|
+
export type Radians = Quantity<'rad'>;
|
|
8
|
+
export type MetersPerSecond = Quantity<'m/s'>;
|
|
9
|
+
export type MetersPerSecondSquared = Quantity<'m/s^2'>;
|
|
10
|
+
export type RadiansPerSecond = Quantity<'rad/s'>;
|
|
11
|
+
export type Newtons = Quantity<'N'>;
|
|
12
|
+
export type NewtonMeters = Quantity<'N*m'>;
|
|
13
|
+
export type NewtonSeconds = Quantity<'N*s'>;
|
|
14
|
+
export type FrameVelocity = Quantity<'m/frame'>;
|
|
15
|
+
export type FrameGravity = Quantity<'m/frame^2'>;
|
|
16
|
+
export type Seconds = Quantity<'s'>;
|
|
17
|
+
export type Hertz = Quantity<'Hz'>;
|
|
18
|
+
export type Kilograms = Quantity<'kg'>;
|
|
19
|
+
export type InverseKilograms = Quantity<'kg^-1'>;
|
|
20
|
+
export type InverseKilogramMetersSquared = Quantity<'kg^-1*m^-2'>;
|
|
21
|
+
export type SquareMeters = Quantity<'m^2'>;
|
|
22
|
+
export type CubicMeters = Quantity<'m^3'>;
|
|
23
|
+
export type KilogramMetersSquared = Quantity<'kg*m^2'>;
|
|
24
|
+
export type KilogramsPerCubicMeter = Quantity<'kg/m^3'>;
|
|
25
|
+
export type KilogramsPerSquareMeter = Quantity<'kg/m^2'>;
|
|
26
|
+
export type NewtonsPerMeter = Quantity<'N/m'>;
|
|
27
|
+
export type NewtonSecondsPerMeter = Quantity<'N*s/m'>;
|
|
28
|
+
export type Turns = Quantity<'turn'>;
|
|
29
|
+
export type TurnsPerSecond = Quantity<'turn/s'>;
|
|
30
|
+
export type TurnsPerMinute = Quantity<'turn/min'>;
|
|
31
|
+
|
|
32
|
+
export type PerSecond = Quantity<'s^-1'>;
|
|
33
|
+
export type PerSecondSquared = Quantity<'s^-2'>;
|
|
34
|
+
export type SquareMetersPerSecondSquared = Quantity<'m^2/s^2'>;
|
|
35
|
+
export type NewtonMeterSeconds = Quantity<'N*m*s'>;
|
|
36
|
+
export type MetersPerRadian = Quantity<'m/rad'>;
|
|
37
|
+
export type RadiansPerMeter = Quantity<'rad/m'>;
|
|
38
|
+
|
|
39
|
+
export type NewtonMeterSecondsPerRadian = Quantity<'N*m*s/rad'>;
|
|
40
|
+
|
|
41
|
+
export interface UnitVector2<Quantity extends number> {
|
|
42
|
+
readonly x: Quantity;
|
|
43
|
+
readonly y: Quantity;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface UnitVector3<Quantity extends number> {
|
|
47
|
+
readonly x: Quantity;
|
|
48
|
+
readonly y: Quantity;
|
|
49
|
+
readonly z: Quantity;
|
|
50
|
+
}
|