@series-inc/rundot-syncplay 6.0.0-rc.20 → 6.0.0-rc.22

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.
@@ -23,7 +23,7 @@ export const physicsWasmMetadata = Object.freeze({
23
23
  "sourceHash": "30d67b9dfdb77f788603b2a93728e54bec583b44178914b495ed5722b10e15e7",
24
24
  "wasmSha256": "c5270d88e727d25069dd211f1994e04e9a1d6dfcb481b38244d7c0165888ad42",
25
25
  "artifact": "production",
26
- "packageVersion": "6.0.0-rc.20",
26
+ "packageVersion": "6.0.0-rc.22",
27
27
  "compilerFlags": [
28
28
  "-std=c++20",
29
29
  "-O3",
@@ -50,7 +50,7 @@ export const physics2dWasmMetadata = Object.freeze({
50
50
  "sourceHash": "faa090a03a6fddaf79c704fb1d76f810955ff35597449c8cec9541a75905a37e",
51
51
  "wasmSha256": "49cb90541deed40f5fff1015bb578e13ec9a793d51931c1227e3e5a11bbfa3f7",
52
52
  "artifact": "production",
53
- "packageVersion": "6.0.0-rc.20",
53
+ "packageVersion": "6.0.0-rc.22",
54
54
  "compilerFlags": [
55
55
  "-std=c++20",
56
56
  "-O3",
package/dist/browser.d.ts CHANGED
@@ -2,7 +2,7 @@ export { cookDeterministicAnimation, createDeterministicAnimationRuntimeState, r
2
2
  export { assertAssetManifestMatches, cookDeterministicAssets, materializeDeterministicMapEntities, materializePrototypeEntities, stableAssetCookJson, validatePrototypeEntitiesAgainstFrameRuntime } from './asset-cooking.js';
3
3
  export { compileDeterministicBotDocument, summarizeDeterministicBotDocumentTraceCounterDelta, summarizeDeterministicBotDocumentTraceCoverage, traceDeterministicBotDocument } from './bot-documents.js';
4
4
  export { cookDeterministicBotAsset, createDeterministicBotBlackboard, getBlackboardValue, runDeterministicBotSimulation, selectDeterministicUtility, tickDeterministicBehaviorTree, tickDeterministicBehaviorTreeWithMemory, tickDeterministicHfsm } from './bot-primitives.js';
5
- export { canonicalize, canonicalStringify, cloneCanonical, decodeCanonicalBytes, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeCanonicalBytes, encodeUtf8 } from './canonical.js';
5
+ export { canonicalize, canonicalParse, canonicalStringify, cloneCanonical, decodeCanonicalBytes, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeCanonicalBytes, encodeUtf8 } from './canonical.js';
6
6
  export { createStableIndexedMap, deterministicShuffle, stableEntries, stableSortedKeys } from './collections.js';
7
7
  export { aabbContainsPoint, aabbIntersects, circleIntersects, circleIntersectsAabb, closestPointOnSegment, fixedAabb, fixedCircle, fixedVec2, orientation, pointOnSegment, segmentPointDistance, segmentSegmentDistance, segmentsIntersect, sortAabbsByStableId, translateAabb } from './collision.js';
8
8
  export { assertDeterministicPayloadFields, createDeterministicCommandTimeline, createDeterministicCommandTimelineSnapshot, deterministicPayloadMatchesFields, evaluateDeterministicCommandTimelineMigrationResult } from './commands.js';
package/dist/browser.js CHANGED
@@ -3,7 +3,7 @@ export { cookDeterministicAnimation, createDeterministicAnimationRuntimeState, r
3
3
  export { assertAssetManifestMatches, cookDeterministicAssets, materializeDeterministicMapEntities, materializePrototypeEntities, stableAssetCookJson, validatePrototypeEntitiesAgainstFrameRuntime } from './asset-cooking.js';
4
4
  export { compileDeterministicBotDocument, summarizeDeterministicBotDocumentTraceCounterDelta, summarizeDeterministicBotDocumentTraceCoverage, traceDeterministicBotDocument } from './bot-documents.js';
5
5
  export { cookDeterministicBotAsset, createDeterministicBotBlackboard, getBlackboardValue, runDeterministicBotSimulation, selectDeterministicUtility, tickDeterministicBehaviorTree, tickDeterministicBehaviorTreeWithMemory, tickDeterministicHfsm } from './bot-primitives.js';
6
- export { canonicalize, canonicalStringify, cloneCanonical, decodeCanonicalBytes, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeCanonicalBytes, encodeUtf8 } from './canonical.js';
6
+ export { canonicalize, canonicalParse, canonicalStringify, cloneCanonical, decodeCanonicalBytes, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeCanonicalBytes, encodeUtf8 } from './canonical.js';
7
7
  export { createStableIndexedMap, deterministicShuffle, stableEntries, stableSortedKeys } from './collections.js';
8
8
  export { aabbContainsPoint, aabbIntersects, circleIntersects, circleIntersectsAabb, closestPointOnSegment, fixedAabb, fixedCircle, fixedVec2, orientation, pointOnSegment, segmentPointDistance, segmentSegmentDistance, segmentsIntersect, sortAabbsByStableId, translateAabb } from './collision.js';
9
9
  export { assertDeterministicPayloadFields, createDeterministicCommandTimeline, createDeterministicCommandTimelineSnapshot, deterministicPayloadMatchesFields, evaluateDeterministicCommandTimelineMigrationResult } from './commands.js';
@@ -3,6 +3,7 @@ export type CanonicalValue = null | boolean | string | number | readonly Canonic
3
3
  };
4
4
  export declare function canonicalize(value: unknown): CanonicalValue;
5
5
  export declare function canonicalStringify(value: unknown): string;
6
+ export declare function canonicalParse<T = unknown>(text: string): T;
6
7
  export declare function cloneCanonical<T>(value: T): T;
7
8
  export declare function decodeCanonicalValue<T>(value: CanonicalValue): T;
8
9
  export declare function defaultChecksum(value: unknown): string;
package/dist/canonical.js CHANGED
@@ -6,6 +6,9 @@ export function canonicalize(value) {
6
6
  export function canonicalStringify(value) {
7
7
  return JSON.stringify(canonicalize(value));
8
8
  }
9
+ export function canonicalParse(text) {
10
+ return decodeCanonical(JSON.parse(text));
11
+ }
9
12
  export function cloneCanonical(value) {
10
13
  return decodeCanonical(JSON.parse(canonicalStringify(value)));
11
14
  }
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { createDeterministicAuthorityRoom } from './authority-room.js';
4
4
  export { compileDeterministicBotDocument, summarizeDeterministicBotDocumentTraceCounterDelta, summarizeDeterministicBotDocumentTraceCoverage, traceDeterministicBotDocument } from './bot-documents.js';
5
5
  export { cookDeterministicBotAsset, createDeterministicBotBlackboard, getBlackboardValue, runDeterministicBotSimulation, selectDeterministicUtility, tickDeterministicBehaviorTree, tickDeterministicBehaviorTreeWithMemory, tickDeterministicHfsm } from './bot-primitives.js';
6
6
  export { isCadenceTick } from './cadence.js';
7
- export { canonicalize, canonicalStringify, cloneCanonical, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeUtf8 } from './canonical.js';
7
+ export { canonicalize, canonicalParse, canonicalStringify, cloneCanonical, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeUtf8 } from './canonical.js';
8
8
  export { createStableIndexedMap, deterministicShuffle, stableEntries, stableSortedKeys } from './collections.js';
9
9
  export { aabbContainsPoint, aabbIntersects, circleIntersects, circleIntersectsAabb, closestPointOnSegment, fixedAabb, fixedCircle, fixedVec2, orientation, pointOnSegment, segmentPointDistance, segmentSegmentDistance, segmentsIntersect, sortAabbsByStableId, translateAabb } from './collision.js';
10
10
  export { assertDeterministicPayloadFields, createDeterministicCommandTimeline, createDeterministicCommandTimelineSnapshot, deterministicPayloadMatchesFields, evaluateDeterministicCommandTimelineMigrationResult } from './commands.js';
@@ -22,7 +22,9 @@ export { buildDeterministicLagCompensatedHitboxProxies3D, createDeterministicLag
22
22
  export { createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDeterministicLocalAuthoritySnapshotCompleteEnvelope, createDeterministicLocalAuthoritySnapshotOfferEnvelope, createDeterministicLocalAuthoritySnapshotRequestEnvelope, decodeDeterministicLocalAuthorityWireEnvelope, deterministicLocalAuthorityWireProtocol, encodeDeterministicLocalAuthorityWireEnvelope } from './local-authority-wire.js';
23
23
  export { createDeterministicMath, isDeterministicMathInstalled } from './math.js';
24
24
  export { rewindDeterministicTargets, runDeterministicMovementCrowdSimulation, runDeterministicMovementSimulation, stepDeterministicFpsAim, stepDeterministicKcc2D, stepDeterministicTopDownMover, validateDeterministicLagCompensatedHit } from './movement.js';
25
- export { stepDeterministicCarry3D, stepDeterministicKcc3D } from './movement3d.js';
25
+ export { stepDeterministicCarry3D, stepDeterministicKcc3D, type DeterministicKccSupport3D, encodeDeterministicKccSupport3D, decodeDeterministicKccSupport3D, encodeDeterministicKccSupport3DBytes, decodeDeterministicKccSupport3DBytes, } from './movement3d.js';
26
+ export { encodeDeterministicVehicleState3D, decodeDeterministicVehicleState3D, encodeDeterministicVehicleState3DBytes, decodeDeterministicVehicleState3DBytes, } from './physics/vehicle-state3d.js';
27
+ export { vec3, meters3, radians3, metersPerSecond3, metersPerSecondSquared3, newtons3, vec2, meters2, radians2, metersPerSecond2, } from './physics/units.js';
26
28
  export { applyDeterministicReciprocalAvoidance, cookDeterministicNavigationGraph, cookTilemapNavigationGraph, createDeterministicFlowField, findDeterministicPath, smoothDeterministicPath, stepDeterministicNavigationAgents } from './navigation.js';
27
29
  export { cookDeterministicNavmesh, cookImportedDeterministicNavmesh, findDeterministicNavmeshPath, findDeterministicNavmeshPointPath, locateDeterministicNavmeshPolygon, runDeterministicNavmeshStress, smoothDeterministicNavmeshPath, stepDeterministicNavmeshAgents, stepDeterministicNavmeshOffMeshTraversal } from './navmesh.js';
28
30
  export { createNetworkedSyncplayClient, prepareNetworkedSyncplayTransport } from './networked-client.js';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ export { createDeterministicAuthorityRoom } from './authority-room.js';
5
5
  export { compileDeterministicBotDocument, summarizeDeterministicBotDocumentTraceCounterDelta, summarizeDeterministicBotDocumentTraceCoverage, traceDeterministicBotDocument } from './bot-documents.js';
6
6
  export { cookDeterministicBotAsset, createDeterministicBotBlackboard, getBlackboardValue, runDeterministicBotSimulation, selectDeterministicUtility, tickDeterministicBehaviorTree, tickDeterministicBehaviorTreeWithMemory, tickDeterministicHfsm } from './bot-primitives.js';
7
7
  export { isCadenceTick } from './cadence.js';
8
- export { canonicalize, canonicalStringify, cloneCanonical, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeUtf8 } from './canonical.js';
8
+ export { canonicalize, canonicalParse, canonicalStringify, cloneCanonical, decodeCanonicalValue, decodeUtf8, defaultChecksum, encodeUtf8 } from './canonical.js';
9
9
  export { createStableIndexedMap, deterministicShuffle, stableEntries, stableSortedKeys } from './collections.js';
10
10
  export { aabbContainsPoint, aabbIntersects, circleIntersects, circleIntersectsAabb, closestPointOnSegment, fixedAabb, fixedCircle, fixedVec2, orientation, pointOnSegment, segmentPointDistance, segmentSegmentDistance, segmentsIntersect, sortAabbsByStableId, translateAabb } from './collision.js';
11
11
  export { assertDeterministicPayloadFields, createDeterministicCommandTimeline, createDeterministicCommandTimelineSnapshot, deterministicPayloadMatchesFields, evaluateDeterministicCommandTimelineMigrationResult } from './commands.js';
@@ -22,7 +22,9 @@ export { buildDeterministicLagCompensatedHitboxProxies3D, createDeterministicLag
22
22
  export { createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDeterministicLocalAuthoritySnapshotCompleteEnvelope, createDeterministicLocalAuthoritySnapshotOfferEnvelope, createDeterministicLocalAuthoritySnapshotRequestEnvelope, decodeDeterministicLocalAuthorityWireEnvelope, deterministicLocalAuthorityWireProtocol, encodeDeterministicLocalAuthorityWireEnvelope } from './local-authority-wire.js';
23
23
  export { createDeterministicMath, isDeterministicMathInstalled } from './math.js';
24
24
  export { rewindDeterministicTargets, runDeterministicMovementCrowdSimulation, runDeterministicMovementSimulation, stepDeterministicFpsAim, stepDeterministicKcc2D, stepDeterministicTopDownMover, validateDeterministicLagCompensatedHit } from './movement.js';
25
- export { stepDeterministicCarry3D, stepDeterministicKcc3D } from './movement3d.js';
25
+ export { stepDeterministicCarry3D, stepDeterministicKcc3D, encodeDeterministicKccSupport3D, decodeDeterministicKccSupport3D, encodeDeterministicKccSupport3DBytes, decodeDeterministicKccSupport3DBytes, } from './movement3d.js';
26
+ export { encodeDeterministicVehicleState3D, decodeDeterministicVehicleState3D, encodeDeterministicVehicleState3DBytes, decodeDeterministicVehicleState3DBytes, } from './physics/vehicle-state3d.js';
27
+ export { vec3, meters3, radians3, metersPerSecond3, metersPerSecondSquared3, newtons3, vec2, meters2, radians2, metersPerSecond2, } from './physics/units.js';
26
28
  export { applyDeterministicReciprocalAvoidance, cookDeterministicNavigationGraph, cookTilemapNavigationGraph, createDeterministicFlowField, findDeterministicPath, smoothDeterministicPath, stepDeterministicNavigationAgents } from './navigation.js';
27
29
  export { cookDeterministicNavmesh, cookImportedDeterministicNavmesh, findDeterministicNavmeshPath, findDeterministicNavmeshPointPath, locateDeterministicNavmeshPolygon, runDeterministicNavmeshStress, smoothDeterministicNavmeshPath, stepDeterministicNavmeshAgents, stepDeterministicNavmeshOffMeshTraversal } from './navmesh.js';
28
30
  export { createNetworkedSyncplayClient, prepareNetworkedSyncplayTransport } from './networked-client.js';
@@ -347,3 +347,7 @@ export declare function runDeterministicKcc3DCrowdFixture(players: number, frame
347
347
  }>;
348
348
  export declare function runDeterministicKcc3DAdversarialFixture(): Promise<DeterministicKcc3DAdversarialFixtureResult>;
349
349
  export declare function runDeterministicKcc3DGeometryFixture(): Promise<DeterministicKcc3DGeometryFixtureResult>;
350
+ export declare function encodeDeterministicKccSupport3D(support: DeterministicKccSupport3D): string;
351
+ export declare function decodeDeterministicKccSupport3D(json: string): DeterministicKccSupport3D;
352
+ export declare function encodeDeterministicKccSupport3DBytes(support: DeterministicKccSupport3D): Uint8Array;
353
+ export declare function decodeDeterministicKccSupport3DBytes(bytes: Uint8Array): DeterministicKccSupport3D;
@@ -1,4 +1,5 @@
1
- import { defaultChecksum } from './canonical.js';
1
+ import { canonicalParse, canonicalStringify, decodeCanonicalBytes, defaultChecksum, encodeCanonicalBytes, } from './canonical.js';
2
+ import { SyncplayError } from './errors.js';
2
3
  import { stepDeterministicKccRevision1_3D } from './movement3d-revision1.js';
3
4
  import { createPhysicsWorld3D, initPhysics3D, } from './physics/3d.js';
4
5
  import { meters, metersPerSecond, metersPerSecondSquared, } from './physics/units.js';
@@ -2474,3 +2475,127 @@ function stableKeys(record) {
2474
2475
  function compareStrings(left, right) {
2475
2476
  return left < right ? -1 : left > right ? 1 : 0;
2476
2477
  }
2478
+ export function encodeDeterministicKccSupport3D(support) {
2479
+ if (!support || typeof support !== "object" || !("kind" in support)) {
2480
+ throw new SyncplayError("Deterministic KCC support is invalid", {
2481
+ code: "kinetix.kcc.support-invalid",
2482
+ });
2483
+ }
2484
+ if (support.kind === "physics" && (typeof support.bodyId !== "bigint" || support.bodyId <= 0n)) {
2485
+ throw new SyncplayError("Deterministic KCC physics support requires a positive bigint bodyId", {
2486
+ code: "kinetix.kcc.support-invalid",
2487
+ });
2488
+ }
2489
+ if (support.kind === "analytic" && (typeof support.id !== "string" || support.id.length === 0)) {
2490
+ throw new SyncplayError("Deterministic KCC analytic support requires a non-empty id", {
2491
+ code: "kinetix.kcc.support-invalid",
2492
+ });
2493
+ }
2494
+ if (support.kind !== "none" && support.kind !== "analytic" && support.kind !== "physics") {
2495
+ throw new SyncplayError("Deterministic KCC support kind is invalid", {
2496
+ code: "kinetix.kcc.support-invalid",
2497
+ });
2498
+ }
2499
+ return canonicalStringify(support);
2500
+ }
2501
+ export function decodeDeterministicKccSupport3D(json) {
2502
+ if (typeof json !== "string") {
2503
+ throw new SyncplayError("KCC support payload must be a string", {
2504
+ code: "kinetix.kcc.payload-invalid",
2505
+ });
2506
+ }
2507
+ let decoded;
2508
+ try {
2509
+ decoded = canonicalParse(json);
2510
+ }
2511
+ catch (cause) {
2512
+ throw new SyncplayError("Failed to parse KCC support JSON", {
2513
+ code: "kinetix.kcc.payload-invalid",
2514
+ cause,
2515
+ });
2516
+ }
2517
+ if (!decoded || typeof decoded !== "object" || !("kind" in decoded)) {
2518
+ throw new SyncplayError("Deterministic KCC support payload is invalid", {
2519
+ code: "kinetix.kcc.payload-invalid",
2520
+ });
2521
+ }
2522
+ const s = decoded;
2523
+ if (s.kind !== "none" && s.kind !== "analytic" && s.kind !== "physics") {
2524
+ throw new SyncplayError("Deterministic KCC support payload kind is invalid", {
2525
+ code: "kinetix.kcc.payload-invalid",
2526
+ });
2527
+ }
2528
+ if (s.kind === "physics" && (typeof s.bodyId !== "bigint" || s.bodyId <= 0n)) {
2529
+ throw new SyncplayError("Deterministic KCC physics support payload requires a positive bigint bodyId", {
2530
+ code: "kinetix.kcc.payload-invalid",
2531
+ });
2532
+ }
2533
+ if (s.kind === "analytic" && (typeof s.id !== "string" || s.id.length === 0)) {
2534
+ throw new SyncplayError("Deterministic KCC analytic support payload requires a non-empty id", {
2535
+ code: "kinetix.kcc.payload-invalid",
2536
+ });
2537
+ }
2538
+ return s;
2539
+ }
2540
+ export function encodeDeterministicKccSupport3DBytes(support) {
2541
+ if (!support || typeof support !== "object" || !("kind" in support)) {
2542
+ throw new SyncplayError("Deterministic KCC support is invalid", {
2543
+ code: "kinetix.kcc.support-invalid",
2544
+ });
2545
+ }
2546
+ if (support.kind === "physics" && (typeof support.bodyId !== "bigint" || support.bodyId <= 0n)) {
2547
+ throw new SyncplayError("Deterministic KCC physics support requires a positive bigint bodyId", {
2548
+ code: "kinetix.kcc.support-invalid",
2549
+ });
2550
+ }
2551
+ if (support.kind === "analytic" && (typeof support.id !== "string" || support.id.length === 0)) {
2552
+ throw new SyncplayError("Deterministic KCC analytic support requires a non-empty id", {
2553
+ code: "kinetix.kcc.support-invalid",
2554
+ });
2555
+ }
2556
+ if (support.kind !== "none" && support.kind !== "analytic" && support.kind !== "physics") {
2557
+ throw new SyncplayError("Deterministic KCC support kind is invalid", {
2558
+ code: "kinetix.kcc.support-invalid",
2559
+ });
2560
+ }
2561
+ return encodeCanonicalBytes(support);
2562
+ }
2563
+ export function decodeDeterministicKccSupport3DBytes(bytes) {
2564
+ if (!(bytes instanceof Uint8Array)) {
2565
+ throw new SyncplayError("KCC support byte payload must be a Uint8Array", {
2566
+ code: "kinetix.kcc.payload-invalid",
2567
+ });
2568
+ }
2569
+ let decoded;
2570
+ try {
2571
+ decoded = decodeCanonicalBytes(bytes);
2572
+ }
2573
+ catch (cause) {
2574
+ throw new SyncplayError("Failed to parse KCC support byte payload", {
2575
+ code: "kinetix.kcc.payload-invalid",
2576
+ cause,
2577
+ });
2578
+ }
2579
+ if (!decoded || typeof decoded !== "object" || !("kind" in decoded)) {
2580
+ throw new SyncplayError("Deterministic KCC support byte payload is invalid", {
2581
+ code: "kinetix.kcc.payload-invalid",
2582
+ });
2583
+ }
2584
+ const s = decoded;
2585
+ if (s.kind !== "none" && s.kind !== "analytic" && s.kind !== "physics") {
2586
+ throw new SyncplayError("Deterministic KCC support byte payload kind is invalid", {
2587
+ code: "kinetix.kcc.payload-invalid",
2588
+ });
2589
+ }
2590
+ if (s.kind === "physics" && (typeof s.bodyId !== "bigint" || s.bodyId <= 0n)) {
2591
+ throw new SyncplayError("Deterministic KCC physics support byte payload requires a positive bigint bodyId", {
2592
+ code: "kinetix.kcc.payload-invalid",
2593
+ });
2594
+ }
2595
+ if (s.kind === "analytic" && (typeof s.id !== "string" || s.id.length === 0)) {
2596
+ throw new SyncplayError("Deterministic KCC analytic support byte payload requires a non-empty id", {
2597
+ code: "kinetix.kcc.payload-invalid",
2598
+ });
2599
+ }
2600
+ return s;
2601
+ }
@@ -669,7 +669,20 @@ export interface PhysicsWorld3D {
669
669
  setBodyDamping?(reference: PhysicsBodyHandle3D | PhysicsBodyId3D, damping: Dimensionless): void;
670
670
  setBodyLinearDamping(reference: PhysicsBodyHandle3D | PhysicsBodyId3D, damping: Dimensionless): void;
671
671
  wakeBody(reference: PhysicsBodyHandle3D | PhysicsBodyId3D): void;
672
- /** Pose: x,y,z,qx,qy,qz,qw. Velocity: vx,vy,vz,wx,wy,wz. IDs ascend. */
672
+ /**
673
+ * Batch reads motion state for all active bodies in ascending logical ID order.
674
+ *
675
+ * Buffer layouts:
676
+ * - poses: 7 Float64 values per body (x, y, z, qx, qy, qz, qw).
677
+ * - velocities: 6 Float64 values per body (vx, vy, vz, wx, wy, wz).
678
+ * - ids: 1 BigUint64 logical body ID per body.
679
+ * - status: 1 Uint8 byte per body with bitmask flags:
680
+ * - Bits 0-1 (& 0x03): Body kind (0 = static, 1 = dynamic, 2 = kinematic).
681
+ * - Bit 2 (0x04): Trigger flag (1 if trigger, 0 otherwise).
682
+ * - Bit 3 (0x08): Sensor flag (1 if sensor, 0 otherwise).
683
+ * - Bit 4 (0x10): Sleeping flag (1 if sleeping, 0 if awake).
684
+ * - Bit 5 (0x20): Angular motion tracking enabled (1 if tracked, 0 otherwise).
685
+ */
673
686
  writeBodyMotionInto(poses: Float64Array, velocities: Float64Array, ids: BigUint64Array, status: Uint8Array): Readonly<PhysicsMotionBatch3D>;
674
687
  applySupport(records: PhysicsSupportRecords3D, options?: {
675
688
  readonly wake?: PhysicsBodyId3D | PhysicsBodyHandle3D;
@@ -753,6 +766,13 @@ export interface DeterministicVehicleStepResult3D {
753
766
  export interface DeterministicVehicleStepOptions3D {
754
767
  readonly applyImpulses?: boolean;
755
768
  }
769
+ /**
770
+ * Steps a deterministic vehicle using the legacy revision 1 algorithm.
771
+ *
772
+ * @deprecated Use stepDeterministicVehicleState3D (revision 2) instead.
773
+ * Revision 1 does not support light dynamic supports (supports below stable mass ratios
774
+ * will experience exaggerated repulsion / flinging) and lacks native sleep/park integration.
775
+ */
756
776
  export declare function stepDeterministicVehicle3D(vehicle: DeterministicVehicle3D, input: DeterministicVehicleInput3D, world: PhysicsWorld3D, options?: DeterministicVehicleStepOptions3D): DeterministicVehicleStepResult3D;
757
777
  export declare function initPhysics3D(options?: PhysicsInitOptions3D): Promise<void>;
758
778
  export declare function createPhysicsWorld3D(input: PhysicsWorldDefinition3D): PhysicsWorld3D;
@@ -477,6 +477,13 @@ function vehicleWheelContact(world, chassis, chassisHandle, wheel) {
477
477
  groundVelocity,
478
478
  };
479
479
  }
480
+ /**
481
+ * Steps a deterministic vehicle using the legacy revision 1 algorithm.
482
+ *
483
+ * @deprecated Use stepDeterministicVehicleState3D (revision 2) instead.
484
+ * Revision 1 does not support light dynamic supports (supports below stable mass ratios
485
+ * will experience exaggerated repulsion / flinging) and lacks native sleep/park integration.
486
+ */
480
487
  export function stepDeterministicVehicle3D(vehicle, input, world, options = {}) {
481
488
  return invoke('vehicle', () => {
482
489
  const chassis = validateVehicle(world, vehicle, input);
@@ -1,4 +1,4 @@
1
- import type { Meters, Radians, MetersPerSecond, MetersPerSecondSquared, RadiansPerSecond, Newtons, NewtonMeters, NewtonSeconds, FrameVelocity, FrameGravity, Seconds, Hertz, Kilograms, InverseKilograms, InverseKilogramMetersSquared, SquareMeters, CubicMeters, KilogramMetersSquared, KilogramsPerCubicMeter, KilogramsPerSquareMeter, NewtonsPerMeter, NewtonSecondsPerMeter, Turns, TurnsPerSecond, TurnsPerMinute, PerSecond, PerSecondSquared, SquareMetersPerSecondSquared, NewtonMeterSeconds, MetersPerRadian, RadiansPerMeter, NewtonMeterSecondsPerRadian } from '../../core/units.js';
1
+ import type { Meters, Radians, MetersPerSecond, MetersPerSecondSquared, RadiansPerSecond, Newtons, NewtonMeters, NewtonSeconds, FrameVelocity, FrameGravity, Seconds, Hertz, Kilograms, InverseKilograms, InverseKilogramMetersSquared, SquareMeters, CubicMeters, KilogramMetersSquared, KilogramsPerCubicMeter, KilogramsPerSquareMeter, NewtonsPerMeter, NewtonSecondsPerMeter, Turns, TurnsPerSecond, TurnsPerMinute, PerSecond, PerSecondSquared, SquareMetersPerSecondSquared, NewtonMeterSeconds, MetersPerRadian, RadiansPerMeter, NewtonMeterSecondsPerRadian, UnitVector2, UnitVector3 } from '../../core/units.js';
2
2
  export type { Quantity, Meters, Radians, MetersPerSecond, MetersPerSecondSquared, RadiansPerSecond, Newtons, NewtonMeters, NewtonSeconds, FrameVelocity, FrameGravity, Dimensionless, Seconds, Hertz, Kilograms, InverseKilograms, InverseKilogramMetersSquared, SquareMeters, CubicMeters, KilogramMetersSquared, KilogramsPerCubicMeter, KilogramsPerSquareMeter, NewtonsPerMeter, NewtonSecondsPerMeter, Turns, TurnsPerSecond, TurnsPerMinute, PerSecond, PerSecondSquared, SquareMetersPerSecondSquared, NewtonMeterSeconds, MetersPerRadian, RadiansPerMeter, NewtonMeterSecondsPerRadian, UnitVector2, UnitVector3, } from '../../core/units.js';
3
3
  export declare const meters: (value: number) => Meters;
4
4
  export declare const radians: (value: number) => Radians;
@@ -36,3 +36,59 @@ export declare function velocityToFrame(value: MetersPerSecond, tickRate: number
36
36
  export declare function velocityToSeconds(value: FrameVelocity, tickRate: number): MetersPerSecond;
37
37
  export declare function gravityToFrame(value: MetersPerSecondSquared, tickRate: number): FrameGravity;
38
38
  export declare function gravityToSeconds(value: FrameGravity, tickRate: number): MetersPerSecondSquared;
39
+ export declare function vec3<Quantity extends number>(brand: (value: number) => Quantity, x: number, y: number, z: number): UnitVector3<Quantity>;
40
+ export declare function vec3<Quantity extends number>(brand: (value: number) => Quantity, v: {
41
+ readonly x: number;
42
+ readonly y: number;
43
+ readonly z: number;
44
+ }): UnitVector3<Quantity>;
45
+ export declare function vec2<Quantity extends number>(brand: (value: number) => Quantity, x: number, y: number): UnitVector2<Quantity>;
46
+ export declare function vec2<Quantity extends number>(brand: (value: number) => Quantity, v: {
47
+ readonly x: number;
48
+ readonly y: number;
49
+ }): UnitVector2<Quantity>;
50
+ export declare function meters3(x: number, y: number, z: number): UnitVector3<Meters>;
51
+ export declare function meters3(v: {
52
+ readonly x: number;
53
+ readonly y: number;
54
+ readonly z: number;
55
+ }): UnitVector3<Meters>;
56
+ export declare function radians3(x: number, y: number, z: number): UnitVector3<Radians>;
57
+ export declare function radians3(v: {
58
+ readonly x: number;
59
+ readonly y: number;
60
+ readonly z: number;
61
+ }): UnitVector3<Radians>;
62
+ export declare function metersPerSecond3(x: number, y: number, z: number): UnitVector3<MetersPerSecond>;
63
+ export declare function metersPerSecond3(v: {
64
+ readonly x: number;
65
+ readonly y: number;
66
+ readonly z: number;
67
+ }): UnitVector3<MetersPerSecond>;
68
+ export declare function metersPerSecondSquared3(x: number, y: number, z: number): UnitVector3<MetersPerSecondSquared>;
69
+ export declare function metersPerSecondSquared3(v: {
70
+ readonly x: number;
71
+ readonly y: number;
72
+ readonly z: number;
73
+ }): UnitVector3<MetersPerSecondSquared>;
74
+ export declare function newtons3(x: number, y: number, z: number): UnitVector3<Newtons>;
75
+ export declare function newtons3(v: {
76
+ readonly x: number;
77
+ readonly y: number;
78
+ readonly z: number;
79
+ }): UnitVector3<Newtons>;
80
+ export declare function meters2(x: number, y: number): UnitVector2<Meters>;
81
+ export declare function meters2(v: {
82
+ readonly x: number;
83
+ readonly y: number;
84
+ }): UnitVector2<Meters>;
85
+ export declare function radians2(x: number, y: number): UnitVector2<Radians>;
86
+ export declare function radians2(v: {
87
+ readonly x: number;
88
+ readonly y: number;
89
+ }): UnitVector2<Radians>;
90
+ export declare function metersPerSecond2(x: number, y: number): UnitVector2<MetersPerSecond>;
91
+ export declare function metersPerSecond2(v: {
92
+ readonly x: number;
93
+ readonly y: number;
94
+ }): UnitVector2<MetersPerSecond>;
@@ -54,3 +54,39 @@ export function gravityToSeconds(value, tickRate) {
54
54
  const rate = validTickRate(tickRate);
55
55
  return metersPerSecondSquared(value * rate * rate);
56
56
  }
57
+ export function vec3(brand, xOrVec, y, z) {
58
+ if (typeof xOrVec === 'object' && xOrVec !== null) {
59
+ return Object.freeze({ x: brand(xOrVec.x), y: brand(xOrVec.y), z: brand(xOrVec.z) });
60
+ }
61
+ return Object.freeze({ x: brand(xOrVec), y: brand(y), z: brand(z) });
62
+ }
63
+ export function vec2(brand, xOrVec, y) {
64
+ if (typeof xOrVec === 'object' && xOrVec !== null) {
65
+ return Object.freeze({ x: brand(xOrVec.x), y: brand(xOrVec.y) });
66
+ }
67
+ return Object.freeze({ x: brand(xOrVec), y: brand(y) });
68
+ }
69
+ export function meters3(xOrVec, y, z) {
70
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec3(meters, xOrVec) : vec3(meters, xOrVec, y, z);
71
+ }
72
+ export function radians3(xOrVec, y, z) {
73
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec3(radians, xOrVec) : vec3(radians, xOrVec, y, z);
74
+ }
75
+ export function metersPerSecond3(xOrVec, y, z) {
76
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec3(metersPerSecond, xOrVec) : vec3(metersPerSecond, xOrVec, y, z);
77
+ }
78
+ export function metersPerSecondSquared3(xOrVec, y, z) {
79
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec3(metersPerSecondSquared, xOrVec) : vec3(metersPerSecondSquared, xOrVec, y, z);
80
+ }
81
+ export function newtons3(xOrVec, y, z) {
82
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec3(newtons, xOrVec) : vec3(newtons, xOrVec, y, z);
83
+ }
84
+ export function meters2(xOrVec, y) {
85
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec2(meters, xOrVec) : vec2(meters, xOrVec, y);
86
+ }
87
+ export function radians2(xOrVec, y) {
88
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec2(radians, xOrVec) : vec2(radians, xOrVec, y);
89
+ }
90
+ export function metersPerSecond2(xOrVec, y) {
91
+ return typeof xOrVec === 'object' && xOrVec !== null ? vec2(metersPerSecond, xOrVec) : vec2(metersPerSecond, xOrVec, y);
92
+ }
@@ -90,4 +90,8 @@ export declare function stepDeterministicVehicleState3D(definition: Deterministi
90
90
  readonly checksumMode?: 'required';
91
91
  }): DeterministicVehicleStateStepWithChecksum3D;
92
92
  export declare function stepDeterministicVehicleState3D(definition: DeterministicVehicleDefinition3D, state: DeterministicVehicleState3D, input: DeterministicVehicleInput3D, world: PhysicsWorld3D, options?: DeterministicVehicleStateStepOptions3D): DeterministicVehicleStateStepResult3D;
93
+ export declare function encodeDeterministicVehicleState3D(state: DeterministicVehicleState3D): string;
94
+ export declare function decodeDeterministicVehicleState3D(json: string): DeterministicVehicleState3D;
95
+ export declare function encodeDeterministicVehicleState3DBytes(state: DeterministicVehicleState3D): Uint8Array;
96
+ export declare function decodeDeterministicVehicleState3DBytes(bytes: Uint8Array): DeterministicVehicleState3D;
93
97
  export {};
@@ -1,4 +1,4 @@
1
- import { defaultChecksum } from '../canonical.js';
1
+ import { canonicalParse, canonicalStringify, decodeCanonicalBytes, defaultChecksum, encodeCanonicalBytes, } from '../canonical.js';
2
2
  import { SyncplayError } from '../errors.js';
3
3
  import { meters, newtons, newtonSecondsPerMeter, newtonsPerMeter, turns, } from './units.js';
4
4
  const fixedScale = 1000;
@@ -132,15 +132,22 @@ function directionalMobility(mobility, arm, direction) {
132
132
  + direction.z * direction.z * mobility.inverseLinear.z
133
133
  + dot(angularArm, response);
134
134
  }
135
- function integrate(body, impulse, arm) {
135
+ function integrateDirect(body, ix, iy, iz, arm) {
136
136
  if (!body.dynamic)
137
137
  return;
138
- body.velocity.linear = {
139
- x: body.velocity.linear.x + body.mobility.inverseLinear.x * impulse.x,
140
- y: body.velocity.linear.y + body.mobility.inverseLinear.y * impulse.y,
141
- z: body.velocity.linear.z + body.mobility.inverseLinear.z * impulse.z,
142
- };
143
- body.velocity.angular = add(body.velocity.angular, applyAngular(body.mobility.inverseAngular, cross(arm, impulse)));
138
+ body.velocity.linear.x += body.mobility.inverseLinear.x * ix;
139
+ body.velocity.linear.y += body.mobility.inverseLinear.y * iy;
140
+ body.velocity.linear.z += body.mobility.inverseLinear.z * iz;
141
+ const tx = arm.y * iz - arm.z * iy;
142
+ const ty = arm.z * ix - arm.x * iz;
143
+ const tz = arm.x * iy - arm.y * ix;
144
+ const ia = body.mobility.inverseAngular;
145
+ body.velocity.angular.x += ia[0] * tx + ia[1] * ty + ia[2] * tz;
146
+ body.velocity.angular.y += ia[1] * tx + ia[3] * ty + ia[4] * tz;
147
+ body.velocity.angular.z += ia[2] * tx + ia[4] * ty + ia[5] * tz;
148
+ }
149
+ function integrate(body, impulse, arm) {
150
+ integrateDirect(body, impulse.x, impulse.y, impulse.z, arm);
144
151
  }
145
152
  function pointVelocity(body, point) {
146
153
  const arm = sub(point, body.com);
@@ -172,31 +179,41 @@ function exactZero(value) {
172
179
  function sameBits(left, right) {
173
180
  return Object.is(left, right);
174
181
  }
182
+ const clippedDiskResult = { forward: 0, side: 0 };
175
183
  function clipDisk(oldForward, oldSide, nextForward, nextSide, radius) {
176
184
  if (nextForward * nextForward + nextSide * nextSide <= radius * radius) {
177
- return { forward: nextForward, side: nextSide };
185
+ clippedDiskResult.forward = nextForward;
186
+ clippedDiskResult.side = nextSide;
187
+ return clippedDiskResult;
178
188
  }
179
189
  const deltaForward = nextForward - oldForward;
180
190
  const deltaSide = nextSide - oldSide;
181
191
  const a = deltaForward * deltaForward + deltaSide * deltaSide;
182
192
  const b = 2 * (oldForward * deltaForward + oldSide * deltaSide);
183
193
  const c = oldForward * oldForward + oldSide * oldSide - radius * radius;
184
- if (!(a > 0))
185
- return { forward: oldForward, side: oldSide };
194
+ if (!(a > 0)) {
195
+ clippedDiskResult.forward = oldForward;
196
+ clippedDiskResult.side = oldSide;
197
+ return clippedDiskResult;
198
+ }
186
199
  const discriminant = b * b - 4 * a * c;
187
- if (!(discriminant >= 0))
188
- return { forward: oldForward, side: oldSide };
200
+ if (!(discriminant >= 0)) {
201
+ clippedDiskResult.forward = oldForward;
202
+ clippedDiskResult.side = oldSide;
203
+ return clippedDiskResult;
204
+ }
189
205
  const root = Math.sqrt(discriminant);
190
206
  const first = (-b - root) / (2 * a);
191
207
  const second = (-b + root) / (2 * a);
192
- const inside = (value) => value >= 0 && value <= 1;
193
- const parameter = inside(first) ? first : (inside(second) ? second : Number.NaN);
194
- if (!Number.isFinite(parameter))
195
- return { forward: oldForward, side: oldSide };
196
- return {
197
- forward: oldForward + parameter * deltaForward,
198
- side: oldSide + parameter * deltaSide,
199
- };
208
+ const parameter = first >= 0 && first <= 1 ? first : (second >= 0 && second <= 1 ? second : Number.NaN);
209
+ if (!Number.isFinite(parameter)) {
210
+ clippedDiskResult.forward = oldForward;
211
+ clippedDiskResult.side = oldSide;
212
+ return clippedDiskResult;
213
+ }
214
+ clippedDiskResult.forward = oldForward + parameter * deltaForward;
215
+ clippedDiskResult.side = oldSide + parameter * deltaSide;
216
+ return clippedDiskResult;
200
217
  }
201
218
  function finiteNumber(value, label) {
202
219
  if (typeof value !== 'number' || !Number.isFinite(value)) {
@@ -361,7 +378,7 @@ function parseState(value, definition) {
361
378
  }
362
379
  function parseOptions(value) {
363
380
  if (value === undefined)
364
- return { checksumMode: 'required', apply: false };
381
+ return { checksumMode: 'required', apply: true };
365
382
  if (!isRecord(value))
366
383
  fail('physics.vehicle-invalid', 'options must be an object.');
367
384
  const mode = value.checksumMode === undefined ? 'required' : value.checksumMode;
@@ -371,7 +388,7 @@ function parseOptions(value) {
371
388
  if (value.apply !== undefined && typeof value.apply !== 'boolean') {
372
389
  fail('physics.vehicle-invalid', 'apply must be a boolean.');
373
390
  }
374
- return { checksumMode: mode, apply: value.apply === true };
391
+ return { checksumMode: mode, apply: value.apply ?? true };
375
392
  }
376
393
  function parseMotion(value) {
377
394
  if (!isRecord(value))
@@ -479,7 +496,7 @@ function readMotion(world, handle) {
479
496
  function worldPoint(motion, local) {
480
497
  return add(motion.position, rotate(motion.orientation, local));
481
498
  }
482
- function castWheel(world, chassis, motion, wheel) {
499
+ function castWheel(world, chassis, motion, wheel, onlyBody) {
483
500
  const anchor = worldPoint(motion, wheel.localAnchor);
484
501
  const direction = normalize(rotate(motion.orientation, wheel.suspensionDirection));
485
502
  if (direction.x === 0 && direction.y === 0 && direction.z === 0) {
@@ -500,6 +517,7 @@ function castWheel(world, chassis, motion, wheel) {
500
517
  hitTriggers: false,
501
518
  hitSensors: false,
502
519
  excludeBody: chassis,
520
+ ...(onlyBody !== undefined ? { onlyBody } : {}),
503
521
  };
504
522
  const hits = world.raycast(query);
505
523
  if (!Array.isArray(hits))
@@ -572,11 +590,23 @@ function idsOf(wheels) {
572
590
  return wheels.flatMap((wheel) => (wheel.support.kind === 'grounded' && wheel.support.bodyId !== undefined ? [wheel.support.bodyId] : []));
573
591
  }
574
592
  function validateParked(world, chassis, motion, definition, state, entry, dt) {
575
- const casts = definition.wheels.map((wheel) => castWheel(world, chassis, motion, wheel));
576
593
  for (const id of uniqueIds(idsOf(state.wheels))) {
577
594
  if (resolveOptional(world, id) === undefined)
578
595
  return { ok: false, reason: 'support-removed' };
596
+ const reason = supportReason(world, id);
597
+ if (reason !== undefined)
598
+ return { ok: false, reason };
579
599
  }
600
+ const casts = definition.wheels.map((wheel, index) => {
601
+ let onlyBody;
602
+ if (!entry) {
603
+ const support = state.wheels[index]?.support;
604
+ if (support?.kind === 'grounded' && support.bodyId !== undefined) {
605
+ onlyBody = resolveOptional(world, support.bodyId);
606
+ }
607
+ }
608
+ return castWheel(world, chassis, motion, wheel, onlyBody);
609
+ });
580
610
  for (let index = 0; index < state.wheels.length; index += 1) {
581
611
  const support = state.wheels[index].support;
582
612
  const hit = casts[index].hit;
@@ -594,11 +624,6 @@ function validateParked(world, chassis, motion, definition, state, entry, dt) {
594
624
  if (reason !== undefined)
595
625
  return { ok: false, reason };
596
626
  }
597
- for (const id of uniqueIds(idsOf(state.wheels))) {
598
- const reason = supportReason(world, id);
599
- if (reason !== undefined)
600
- return { ok: false, reason };
601
- }
602
627
  return { ok: true, casts };
603
628
  }
604
629
  function steerTurns(wheel, steer) {
@@ -790,9 +815,13 @@ function solveActive(world, chassisId, chassisHandle, chassisMotion, definition,
790
815
  }
791
816
  return { wheels, tires, chassis };
792
817
  }
818
+ function applyTireDirect(chassis, tire, ix, iy, iz) {
819
+ integrateDirect(chassis, ix, iy, iz, tire.chassisArm);
820
+ integrateDirect(tire.support, -ix, -iy, -iz, tire.supportArm);
821
+ }
793
822
  function applyTire(chassis, tire, impulse) {
794
- integrate(chassis, impulse, tire.chassisArm);
795
- integrate(tire.support, scale(impulse, -1), tire.supportArm);
823
+ integrateDirect(chassis, impulse.x, impulse.y, impulse.z, tire.chassisArm);
824
+ integrateDirect(tire.support, -impulse.x, -impulse.y, -impulse.z, tire.supportArm);
796
825
  }
797
826
  function solveTires(chassis, tires) {
798
827
  for (let iteration = 0; iteration < tireIterations; iteration += 1) {
@@ -801,30 +830,56 @@ function solveTires(chassis, tires) {
801
830
  fail('physics.vehicle-invalid', 'tire mobility is not finite.');
802
831
  }
803
832
  if (iteration === 0 && tire.drive !== 0) {
804
- const driven = clipDisk(tire.lambdaForward, tire.lambdaSide, tire.lambdaForward + tire.drive, tire.lambdaSide, tire.disk);
805
- const driveImpulse = add(scale(tire.forward, driven.forward - tire.lambdaForward), scale(tire.side, driven.side - tire.lambdaSide));
806
- applyTire(chassis, tire, driveImpulse);
807
- tire.lambdaForward = driven.forward;
808
- tire.lambdaSide = driven.side;
809
- tire.driveAdded = driven.forward;
833
+ clipDisk(tire.lambdaForward, tire.lambdaSide, tire.lambdaForward + tire.drive, tire.lambdaSide, tire.disk);
834
+ const df = clippedDiskResult.forward - tire.lambdaForward;
835
+ const ds = clippedDiskResult.side - tire.lambdaSide;
836
+ const ix = tire.forward.x * df + tire.side.x * ds;
837
+ const iy = tire.forward.y * df + tire.side.y * ds;
838
+ const iz = tire.forward.z * df + tire.side.z * ds;
839
+ applyTireDirect(chassis, tire, ix, iy, iz);
840
+ tire.lambdaForward = clippedDiskResult.forward;
841
+ tire.lambdaSide = clippedDiskResult.side;
842
+ tire.driveAdded = clippedDiskResult.forward;
810
843
  }
811
844
  const oldForward = tire.lambdaForward;
812
845
  const oldSide = tire.lambdaSide;
813
- const relative = sub(pointVelocity(chassis, tire.point), pointVelocity(tire.support, tire.point));
846
+ const armCx = tire.point.x - chassis.com.x;
847
+ const armCy = tire.point.y - chassis.com.y;
848
+ const armCz = tire.point.z - chassis.com.z;
849
+ const vCx = chassis.velocity.linear.x + (chassis.velocity.angular.y * armCz - chassis.velocity.angular.z * armCy) + chassis.surface.x;
850
+ const vCy = chassis.velocity.linear.y + (chassis.velocity.angular.z * armCx - chassis.velocity.angular.x * armCz) + chassis.surface.y;
851
+ const vCz = chassis.velocity.linear.z + (chassis.velocity.angular.x * armCy - chassis.velocity.angular.y * armCx) + chassis.surface.z;
852
+ const support = tire.support;
853
+ const armSx = tire.point.x - support.com.x;
854
+ const armSy = tire.point.y - support.com.y;
855
+ const armSz = tire.point.z - support.com.z;
856
+ const vSx = support.velocity.linear.x + (support.velocity.angular.y * armSz - support.velocity.angular.z * armSy) + support.surface.x;
857
+ const vSy = support.velocity.linear.y + (support.velocity.angular.z * armSx - support.velocity.angular.x * armSz) + support.surface.y;
858
+ const vSz = support.velocity.linear.z + (support.velocity.angular.x * armSy - support.velocity.angular.y * armSx) + support.surface.z;
859
+ const relX = vCx - vSx;
860
+ const relY = vCy - vSy;
861
+ const relZ = vCz - vSz;
862
+ const dotForward = relX * tire.forward.x + relY * tire.forward.y + relZ * tire.forward.z;
863
+ const dotSide = relX * tire.side.x + relY * tire.side.y + relZ * tire.side.z;
814
864
  let passive = tire.lambdaForward - tire.driveAdded;
815
865
  if (tire.kForward > 0)
816
- passive += -dot(relative, tire.forward) / tire.kForward;
866
+ passive += -dotForward / tire.kForward;
817
867
  if (passive > tire.box)
818
868
  passive = tire.box;
819
869
  if (passive < -tire.box)
820
870
  passive = -tire.box;
821
871
  let nextSide = tire.lambdaSide;
822
872
  if (tire.kSide > 0)
823
- nextSide += -dot(relative, tire.side) / tire.kSide;
824
- const clipped = clipDisk(oldForward, oldSide, tire.driveAdded + passive, nextSide, tire.disk);
825
- applyTire(chassis, tire, add(scale(tire.forward, clipped.forward - oldForward), scale(tire.side, clipped.side - oldSide)));
826
- tire.lambdaForward = clipped.forward;
827
- tire.lambdaSide = clipped.side;
873
+ nextSide += -dotSide / tire.kSide;
874
+ clipDisk(oldForward, oldSide, tire.driveAdded + passive, nextSide, tire.disk);
875
+ const df = clippedDiskResult.forward - oldForward;
876
+ const ds = clippedDiskResult.side - oldSide;
877
+ const ix = tire.forward.x * df + tire.side.x * ds;
878
+ const iy = tire.forward.y * df + tire.side.y * ds;
879
+ const iz = tire.forward.z * df + tire.side.z * ds;
880
+ applyTireDirect(chassis, tire, ix, iy, iz);
881
+ tire.lambdaForward = clippedDiskResult.forward;
882
+ tire.lambdaSide = clippedDiskResult.side;
828
883
  }
829
884
  }
830
885
  }
@@ -1075,8 +1130,24 @@ export function stepDeterministicVehicleState3D(definition, state, input, world,
1075
1130
  }
1076
1131
  }
1077
1132
  for (const tire of active.tires) {
1078
- const relative = sub(pointVelocity(active.chassis, tire.point), pointVelocity(tire.support, tire.point));
1079
- const delta = roundHalfUp(1_000_000 * info.dt * dot(relative, tire.forward) / (2 * Math.PI * active.wheels[tire.index].spec.radius));
1133
+ const armCx = tire.point.x - active.chassis.com.x;
1134
+ const armCy = tire.point.y - active.chassis.com.y;
1135
+ const armCz = tire.point.z - active.chassis.com.z;
1136
+ const vCx = active.chassis.velocity.linear.x + (active.chassis.velocity.angular.y * armCz - active.chassis.velocity.angular.z * armCy) + active.chassis.surface.x;
1137
+ const vCy = active.chassis.velocity.linear.y + (active.chassis.velocity.angular.z * armCx - active.chassis.velocity.angular.x * armCz) + active.chassis.surface.y;
1138
+ const vCz = active.chassis.velocity.linear.z + (active.chassis.velocity.angular.x * armCy - active.chassis.velocity.angular.y * armCx) + active.chassis.surface.z;
1139
+ const support = tire.support;
1140
+ const armSx = tire.point.x - support.com.x;
1141
+ const armSy = tire.point.y - support.com.y;
1142
+ const armSz = tire.point.z - support.com.z;
1143
+ const vSx = support.velocity.linear.x + (support.velocity.angular.y * armSz - support.velocity.angular.z * armSy) + support.surface.x;
1144
+ const vSy = support.velocity.linear.y + (support.velocity.angular.z * armSx - support.velocity.angular.x * armSz) + support.surface.y;
1145
+ const vSz = support.velocity.linear.z + (support.velocity.angular.x * armSy - support.velocity.angular.y * armSx) + support.surface.z;
1146
+ const relX = vCx - vSx;
1147
+ const relY = vCy - vSy;
1148
+ const relZ = vCz - vSz;
1149
+ const dotForward = relX * tire.forward.x + relY * tire.forward.y + relZ * tire.forward.z;
1150
+ const delta = roundHalfUp(1_000_000 * info.dt * dotForward / (2 * Math.PI * active.wheels[tire.index].spec.radius));
1080
1151
  spinDelta[tire.index] = delta;
1081
1152
  micros[tire.index] = addMicro(micros[tire.index], delta);
1082
1153
  }
@@ -1181,3 +1252,65 @@ function restoreVelocities(chassis, tires, saved) {
1181
1252
  tire.support.velocity = cloneVelocity(velocity);
1182
1253
  }
1183
1254
  }
1255
+ export function encodeDeterministicVehicleState3D(state) {
1256
+ if (!state || typeof state !== "object" || state.behaviorRevision !== 2 || typeof state.chassisId !== "bigint" || !Array.isArray(state.wheels)) {
1257
+ throw new SyncplayError("Deterministic vehicle state is invalid", {
1258
+ code: "kinetix.vehicle.state-invalid",
1259
+ });
1260
+ }
1261
+ return canonicalStringify(state);
1262
+ }
1263
+ export function decodeDeterministicVehicleState3D(json) {
1264
+ if (typeof json !== "string") {
1265
+ throw new SyncplayError("Vehicle state payload must be a string", {
1266
+ code: "kinetix.vehicle.payload-invalid",
1267
+ });
1268
+ }
1269
+ let decoded;
1270
+ try {
1271
+ decoded = canonicalParse(json);
1272
+ }
1273
+ catch (cause) {
1274
+ throw new SyncplayError("Failed to parse vehicle state JSON", {
1275
+ code: "kinetix.vehicle.payload-invalid",
1276
+ cause,
1277
+ });
1278
+ }
1279
+ if (!decoded || typeof decoded !== "object" || decoded.behaviorRevision !== 2 || typeof decoded.chassisId !== "bigint" || !Array.isArray(decoded.wheels)) {
1280
+ throw new SyncplayError("Deterministic vehicle state payload does not conform to revision 2", {
1281
+ code: "kinetix.vehicle.payload-invalid",
1282
+ });
1283
+ }
1284
+ return decoded;
1285
+ }
1286
+ export function encodeDeterministicVehicleState3DBytes(state) {
1287
+ if (!state || typeof state !== "object" || state.behaviorRevision !== 2 || typeof state.chassisId !== "bigint" || !Array.isArray(state.wheels)) {
1288
+ throw new SyncplayError("Deterministic vehicle state is invalid", {
1289
+ code: "kinetix.vehicle.state-invalid",
1290
+ });
1291
+ }
1292
+ return encodeCanonicalBytes(state);
1293
+ }
1294
+ export function decodeDeterministicVehicleState3DBytes(bytes) {
1295
+ if (!(bytes instanceof Uint8Array)) {
1296
+ throw new SyncplayError("Vehicle state byte payload must be a Uint8Array", {
1297
+ code: "kinetix.vehicle.payload-invalid",
1298
+ });
1299
+ }
1300
+ let decoded;
1301
+ try {
1302
+ decoded = decodeCanonicalBytes(bytes);
1303
+ }
1304
+ catch (cause) {
1305
+ throw new SyncplayError("Failed to parse vehicle state byte payload", {
1306
+ code: "kinetix.vehicle.payload-invalid",
1307
+ cause,
1308
+ });
1309
+ }
1310
+ if (!decoded || typeof decoded !== "object" || decoded.behaviorRevision !== 2 || typeof decoded.chassisId !== "bigint" || !Array.isArray(decoded.wheels)) {
1311
+ throw new SyncplayError("Deterministic vehicle state byte payload does not conform to revision 2", {
1312
+ code: "kinetix.vehicle.payload-invalid",
1313
+ });
1314
+ }
1315
+ return decoded;
1316
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@series-inc/rundot-syncplay",
3
- "version": "6.0.0-rc.20",
3
+ "version": "6.0.0-rc.22",
4
4
  "description": "Kinetix orchestration, rollback, replay, late-join, and deterministic networking for RUN.game",
5
5
  "repository": {
6
6
  "type": "git",
@@ -215,7 +215,7 @@
215
215
  "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
216
216
  "test": "npm run test:core && npm run test:capability-restoration && npm run test:unit-control && npm run test:entity-registry",
217
217
  "test:module-promotion": "node --expose-gc --import tsx --test tests/module-promotion.test.ts tests/module-docs.test.ts tests/module-bundle-budget.test.ts scripts/prove-module-promotion.test.mjs",
218
- "test:core": "node --expose-gc --import tsx --test --test-concurrency=1 tests/canonical.test.ts tests/canonical-portability.test.ts tests/runtime-session.test.ts tests/kinetix-runtime-session.test.ts tests/runtime-support.test.ts tests/runtime-guards.test.ts tests/r3f-render-adapter.test.ts tests/snapshot-cost.test.ts tests/sdkSession.test.ts tests/input-authority.test.ts tests/session-wire.test.ts tests/runtime-room-metadata.test.ts tests/session-snapshot.test.ts tests/authority-room.test.ts tests/networked-client-snapshot.test.ts tests/runner.test.ts tests/testing.test.ts tests/browser-session.test.ts tests/secret-config.test.ts tests/secret-protocol.test.ts tests/secret-authority.test.ts tests/secret-client.test.ts tests/late-join-checksum.test.ts tests/late-join-input-backfill.test.ts tests/replay-scoring.test.ts tests/bot-backfill.test.ts tests/latency-simulation.test.ts tests/production-input-budget.test.ts tests/time-sync.test.ts tests/match-log.test.ts tests/spectator.test.ts tests/synctest.test.ts tests/instant-replay.test.ts tests/session-promotion.test.ts tests/entrypoints.test.ts tests/export-surface.test.ts tests/module-seam.test.ts tests/module-contract-portability.test.ts tests/module-identity.test.ts tests/module-corpus.test.ts tests/component-model.test.ts tests/component-model-rollback.test.ts tests/component-model-integration.test.ts tests/actors-ai.test.ts tests/character-3d.test.ts tests/character-3d-certification.test.ts tests/combat-modules.test.ts tests/combat-modules-integration.test.ts tests/firearm.test.ts tests/gameplay-effects.test.ts tests/spatial-interaction.test.ts tests/stats-abilities.test.ts tests/inventory-equipment.test.ts tests/inventory-equipment-certification.test.ts tests/platformer-2d.test.ts tests/platformer-2d-certification.test.ts tests/module-promotion.test.ts tests/module-docs.test.ts tests/module-bundle-budget.test.ts tests/published-side-effects.test.ts tests/host-timing.test.ts tests/test-manifest.test.ts tests/coarse-region.test.ts tests/input-codec.test.ts tests/command-ingress.test.ts tests/session-reconfigure.test.ts tests/prediction-mode.test.ts tests/ephemeral-channel.test.ts tests/runner-surface.test.ts tests/runner-harness.test.ts tests/effects-adapter-bounds.test.ts tests/simulated-match-secrets.test.ts tests/run-glue-surface.test.mjs core/tests/core-boundary.test.mjs tests/math-core-parity.test.ts tests/math-profile.test.ts tests/movement3d-kcc-unit-contract.test.ts tests/movement3d-static-ground.test.ts tests/state-digest.test.ts tests/large-blob-state.test.ts tests/math-installation-order.test.ts tests/networked-blob-state.test.ts tests/networked-checksum-burst.test.ts tests/networked-runtime-commit.test.ts tests/physics-helper-motion-reads.test.ts tests/physics-unit-conversions.test.ts tests/physics-checkpoint-capacity.test.ts tests/runner-cleanup.test.ts tests/runtime-release-outcome.test.ts tests/session-checkpoint-budget.test.ts tests/session-owned-cleanup.test.ts tests/tool-owned-adapter.test.ts tests/tool-runtime-lifetime.test.ts tests/movement3d-revision1-baseline.test.ts tests/movement3d-revision1-corpus.test.ts tests/legacy-query-revision1-corpus.test.ts tests/physics-support-boundary.test.ts tests/kcc-corpus-encoding.test.ts tests/voxel-swept-quad-paint.test.ts tests/physics-support-artifact.test.ts tests/movement3d-revision1-binding.test.ts tests/physics-si-pulley-runtime.test.ts tests/vehicle-state3d.test.ts tests/vehicle-state3d-artifact.test.ts tests/physics-si-rope-gear-powertrain-runtime.test.ts tests/voxel-body-state.test.ts",
218
+ "test:core": "node --expose-gc --import tsx --test --test-concurrency=1 tests/canonical.test.ts tests/canonical-portability.test.ts tests/runtime-session.test.ts tests/kinetix-runtime-session.test.ts tests/runtime-support.test.ts tests/runtime-guards.test.ts tests/r3f-render-adapter.test.ts tests/snapshot-cost.test.ts tests/sdkSession.test.ts tests/input-authority.test.ts tests/session-wire.test.ts tests/runtime-room-metadata.test.ts tests/session-snapshot.test.ts tests/authority-room.test.ts tests/networked-client-snapshot.test.ts tests/runner.test.ts tests/testing.test.ts tests/browser-session.test.ts tests/secret-config.test.ts tests/secret-protocol.test.ts tests/secret-authority.test.ts tests/secret-client.test.ts tests/late-join-checksum.test.ts tests/late-join-input-backfill.test.ts tests/replay-scoring.test.ts tests/bot-backfill.test.ts tests/latency-simulation.test.ts tests/production-input-budget.test.ts tests/time-sync.test.ts tests/match-log.test.ts tests/spectator.test.ts tests/synctest.test.ts tests/instant-replay.test.ts tests/session-promotion.test.ts tests/entrypoints.test.ts tests/export-surface.test.ts tests/module-seam.test.ts tests/module-contract-portability.test.ts tests/module-identity.test.ts tests/module-corpus.test.ts tests/component-model.test.ts tests/component-model-rollback.test.ts tests/component-model-integration.test.ts tests/actors-ai.test.ts tests/character-3d.test.ts tests/character-3d-certification.test.ts tests/combat-modules.test.ts tests/combat-modules-integration.test.ts tests/firearm.test.ts tests/gameplay-effects.test.ts tests/spatial-interaction.test.ts tests/stats-abilities.test.ts tests/inventory-equipment.test.ts tests/inventory-equipment-certification.test.ts tests/platformer-2d.test.ts tests/platformer-2d-certification.test.ts tests/module-promotion.test.ts tests/module-docs.test.ts tests/module-bundle-budget.test.ts tests/published-side-effects.test.ts tests/host-timing.test.ts tests/test-manifest.test.ts tests/coarse-region.test.ts tests/input-codec.test.ts tests/command-ingress.test.ts tests/session-reconfigure.test.ts tests/prediction-mode.test.ts tests/ephemeral-channel.test.ts tests/runner-surface.test.ts tests/runner-harness.test.ts tests/effects-adapter-bounds.test.ts tests/simulated-match-secrets.test.ts tests/run-glue-surface.test.mjs core/tests/core-boundary.test.mjs tests/math-core-parity.test.ts tests/math-profile.test.ts tests/movement3d-kcc-unit-contract.test.ts tests/movement3d-static-ground.test.ts tests/state-digest.test.ts tests/large-blob-state.test.ts tests/math-installation-order.test.ts tests/networked-blob-state.test.ts tests/networked-checksum-burst.test.ts tests/networked-runtime-commit.test.ts tests/physics-helper-motion-reads.test.ts tests/physics-unit-conversions.test.ts tests/physics-checkpoint-capacity.test.ts tests/runner-cleanup.test.ts tests/runtime-release-outcome.test.ts tests/session-checkpoint-budget.test.ts tests/session-owned-cleanup.test.ts tests/tool-owned-adapter.test.ts tests/tool-runtime-lifetime.test.ts tests/movement3d-revision1-baseline.test.ts tests/movement3d-revision1-corpus.test.ts tests/legacy-query-revision1-corpus.test.ts tests/physics-support-boundary.test.ts tests/kcc-corpus-encoding.test.ts tests/voxel-swept-quad-paint.test.ts tests/physics-support-artifact.test.ts tests/movement3d-revision1-binding.test.ts tests/physics-si-pulley-runtime.test.ts tests/vehicle-state3d.test.ts tests/vehicle-state3d-artifact.test.ts tests/partner-rc22-codecs-units.test.ts tests/vehicle-acceptance-matrix.test.ts tests/partner-tarball-closure.test.ts tests/physics-si-rope-gear-powertrain-runtime.test.ts tests/voxel-body-state.test.ts",
219
219
  "test:sdk-contract": "node --import tsx --test tests/sdk-runtime-contract.test.ts",
220
220
  "test:soak": "tsx --test tests/runtime-soak.test.ts",
221
221
  "test:extended": "node --expose-gc --import tsx --test tests/performance-primitives.test.ts && tsx --test tests/animation.test.ts tests/asset-cooking.test.ts tests/backend-proof-checksum-vectors.test.ts tests/bot-documents.test.ts tests/bot-primitives.test.ts tests/collision.test.ts tests/command-timeline.test.ts tests/config-bundle.test.ts tests/deterministic-primitives.test.ts tests/ecs-lite.test.ts tests/effects-adapter.test.ts tests/engine-runtime.test.ts tests/errors.test.ts tests/events.test.ts tests/input-button.test.ts tests/load-128-players.test.ts tests/math.test.ts tests/movement.test.ts tests/movement3d.test.ts tests/multiclient-authority.test.ts tests/navigation.test.ts tests/noise.test.ts tests/physics3d-geometry-limits.test.ts tests/physics3d-shared.test.ts tests/physics3d-static-memoization.test.ts tests/random.test.ts tests/rollback-history.test.ts tests/schema-artifacts.test.ts tests/schema-codegen.test.ts tests/schema-dsl-binary.test.ts tests/schema.test.ts tests/signals.test.ts tests/sparse-set.test.ts tests/static-checker.test.ts tests/system-lifecycle.test.ts tests/wire-canonical-sentinels.test.ts tests/ws-frame.test.ts tests/wreck-yard-defects.test.ts tests/wreck-yard-performance-harness.test.ts tests/wreck-yard-partner-verification-rc15.test.ts",