@series-inc/rundot-syncplay 6.0.0-rc.24 → 6.0.0-rc.26

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 physicsProfileWasmMetadata = Object.freeze({
23
23
  "sourceHash": "13bc7e6c473b9a773bbb0f77d1c2126df59a074759ebb5efb90b8dde1ff4d10a",
24
24
  "wasmSha256": "d398c126e4da59324d6e28f14132173a9f980f9fc429f632baffacbae4744fef",
25
25
  "artifact": "profile",
26
- "packageVersion": "6.0.0-rc.24",
26
+ "packageVersion": "6.0.0-rc.26",
27
27
  "compilerFlags": [
28
28
  "-std=c++20",
29
29
  "-O3",
@@ -23,7 +23,7 @@ export const physicsWasmMetadata = Object.freeze({
23
23
  "sourceHash": "4bb02a55da437ff3075d5350d48f319bd8b89a6dd31d9a34d9b0cb3677ed4914",
24
24
  "wasmSha256": "76ea5a82d4e84d0e3bc3fd93dd54992b54c09614f7024e4f8b5bf91445db1955",
25
25
  "artifact": "production",
26
- "packageVersion": "6.0.0-rc.24",
26
+ "packageVersion": "6.0.0-rc.26",
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.24",
53
+ "packageVersion": "6.0.0-rc.26",
54
54
  "compilerFlags": [
55
55
  "-std=c++20",
56
56
  "-O3",
@@ -156,6 +156,15 @@ export interface DeterministicKccStepBaseResult3D {
156
156
  * physics step.
157
157
  */
158
158
  readonly physicsImpulses: readonly DeterministicKccPhysicsImpulse3D[];
159
+ readonly portalCrossed?: {
160
+ readonly portalId: number;
161
+ readonly turnedFacing: number;
162
+ readonly turnedVelocity: {
163
+ readonly x: number;
164
+ readonly y: number;
165
+ readonly z: number;
166
+ };
167
+ };
159
168
  }
160
169
  export interface DeterministicKccStepResultWithChecksum3D extends DeterministicKccStepBaseResult3D {
161
170
  readonly hasChecksum: true;
@@ -255,6 +264,44 @@ export interface DeterministicKccStepOptions3D {
255
264
  * reproduces the previous hardcoded behaviour bit-for-bit.
256
265
  */
257
266
  readonly jump?: DeterministicKccJumpTuning3D;
267
+ readonly portals?: readonly {
268
+ readonly id: number;
269
+ readonly portalA: {
270
+ readonly position: {
271
+ readonly x: number;
272
+ readonly y: number;
273
+ readonly z: number;
274
+ };
275
+ readonly rotation: {
276
+ readonly x: number;
277
+ readonly y: number;
278
+ readonly z: number;
279
+ readonly w: number;
280
+ };
281
+ readonly opening: {
282
+ readonly width: number;
283
+ readonly height: number;
284
+ };
285
+ };
286
+ readonly portalB: {
287
+ readonly position: {
288
+ readonly x: number;
289
+ readonly y: number;
290
+ readonly z: number;
291
+ };
292
+ readonly rotation: {
293
+ readonly x: number;
294
+ readonly y: number;
295
+ readonly z: number;
296
+ readonly w: number;
297
+ };
298
+ readonly opening: {
299
+ readonly width: number;
300
+ readonly height: number;
301
+ };
302
+ };
303
+ readonly open?: boolean;
304
+ }[];
258
305
  }
259
306
  export declare function stepDeterministicKcc3D(body: DeterministicKccBody3D, input: DeterministicKccInput3D, world: DeterministicKccWorld3D, options: DeterministicKccStepOptions3D & {
260
307
  readonly checksumMode: 'disabled';
@@ -1,6 +1,59 @@
1
1
  import { canonicalParse, canonicalStringify, decodeCanonicalBytes, defaultChecksum, encodeCanonicalBytes, } from './canonical.js';
2
2
  import { SyncplayError } from './errors.js';
3
3
  import { stepDeterministicKccRevision1_3D } from './movement3d-revision1.js';
4
+ function subVec3Pure(a, b) {
5
+ return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
6
+ }
7
+ function quatNormalizePure(q) {
8
+ const lenSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
9
+ if (lenSq <= 1e-15)
10
+ return { x: 0, y: 0, z: 0, w: 1 };
11
+ const inv = 1 / Math.sqrt(lenSq);
12
+ return { x: q.x * inv, y: q.y * inv, z: q.z * inv, w: q.w * inv };
13
+ }
14
+ function quatConjugatePure(q) {
15
+ return { x: -q.x, y: -q.y, z: -q.z, w: q.w };
16
+ }
17
+ function quatMultiplyPure(a, b) {
18
+ return {
19
+ x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
20
+ y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
21
+ z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
22
+ w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
23
+ };
24
+ }
25
+ function rotateVec3Pure(q, v) {
26
+ const qv = { x: q.x, y: q.y, z: q.z };
27
+ const uv = { x: qv.y * v.z - qv.z * v.y, y: qv.z * v.x - qv.x * v.z, z: qv.x * v.y - qv.y * v.x };
28
+ const uuv = { x: qv.y * uv.z - qv.z * uv.y, y: qv.z * uv.x - qv.x * uv.z, z: qv.x * uv.y - qv.y * uv.x };
29
+ return {
30
+ x: v.x + ((uv.x * q.w + uuv.x) * 2.0),
31
+ y: v.y + ((uv.y * q.w + uuv.y) * 2.0),
32
+ z: v.z + ((uv.z * q.w + uuv.z) * 2.0),
33
+ };
34
+ }
35
+ function invRotateVec3Pure(q, v) {
36
+ return rotateVec3Pure(quatConjugatePure(q), v);
37
+ }
38
+ const R_PORTAL_FLIP_KCC = { x: 0, y: 1, z: 0, w: 0 };
39
+ function computePortalRelativeTransformKcc(entryEnd, exitEnd) {
40
+ const entryRotNorm = quatNormalizePure(entryEnd.rotation);
41
+ const exitRotNorm = quatNormalizePure(exitEnd.rotation);
42
+ const rotRel = quatNormalizePure(quatMultiplyPure(exitRotNorm, quatMultiplyPure(R_PORTAL_FLIP_KCC, quatConjugatePure(entryRotNorm))));
43
+ return { rotation: rotRel };
44
+ }
45
+ function transformPointAcrossPortalKcc(entryEnd, exitEnd, point) {
46
+ const entryRotNorm = quatNormalizePure(entryEnd.rotation);
47
+ const exitRotNorm = quatNormalizePure(exitEnd.rotation);
48
+ const localPos = invRotateVec3Pure(entryRotNorm, subVec3Pure(point, entryEnd.position));
49
+ const flippedLocal = { x: -localPos.x, y: localPos.y, z: -localPos.z };
50
+ const rotated = rotateVec3Pure(exitRotNorm, flippedLocal);
51
+ return {
52
+ x: exitEnd.position.x + rotated.x,
53
+ y: exitEnd.position.y + rotated.y,
54
+ z: exitEnd.position.z + rotated.z,
55
+ };
56
+ }
4
57
  import { createPhysicsWorld3D, initPhysics3D, } from './physics/3d.js';
5
58
  import { meters, metersPerSecond, metersPerSecondSquared, } from './physics/units.js';
6
59
  import { quatToMat3, solverSqrt } from './physics3d-shared.js';
@@ -551,6 +604,55 @@ function stepDeterministicKccRevision2_3D(body, input, world, options, gravityPe
551
604
  if (physicsImpulses.length > 0)
552
605
  events.push('push-dynamic');
553
606
  }
607
+ let portalCrossed = undefined;
608
+ if (options.portals && options.portals.length > 0) {
609
+ for (const pair of options.portals) {
610
+ if (pair.open === false)
611
+ continue;
612
+ for (const [entryKey, exitKey] of [
613
+ ['portalA', 'portalB'],
614
+ ['portalB', 'portalA'],
615
+ ]) {
616
+ const entryEnd = pair[entryKey];
617
+ const exitEnd = pair[exitKey];
618
+ const entryRotNorm = quatNormalizePure(entryEnd.rotation);
619
+ const prevLocal = invRotateVec3Pure(entryRotNorm, subVec3Pure({ x: next.x, y: next.y, z: next.z }, entryEnd.position));
620
+ const newLocal = invRotateVec3Pure(entryRotNorm, subVec3Pure({ x, y, z }, entryEnd.position));
621
+ const halfW = entryEnd.opening.width * 0.5;
622
+ const halfH = entryEnd.opening.height * 0.5;
623
+ if (prevLocal.z > 0 && newLocal.z <= 0 && Math.abs(newLocal.x) <= halfW && Math.abs(newLocal.y) <= halfH) {
624
+ const exitPos = transformPointAcrossPortalKcc(entryEnd, exitEnd, { x, y, z });
625
+ const relTrans = computePortalRelativeTransformKcc(entryEnd, exitEnd);
626
+ const turnedVel = rotateVec3Pure(relTrans.rotation, { x: vx, y: vy, z: vz });
627
+ const charFacing = (Math.abs(vx) > 1e-6 || Math.abs(vz) > 1e-6) ? Math.atan2(vx, vz) : 0;
628
+ const charFwd = { x: Math.sin(charFacing), y: 0, z: Math.cos(charFacing) };
629
+ const turnedFwd = rotateVec3Pure(relTrans.rotation, charFwd);
630
+ const turnedFacing = Math.atan2(turnedFwd.x, turnedFwd.z);
631
+ x = exitPos.x;
632
+ y = exitPos.y;
633
+ z = exitPos.z;
634
+ vx = turnedVel.x;
635
+ vy = turnedVel.y;
636
+ vz = turnedVel.z;
637
+ events.push('portal-cross');
638
+ portalCrossed = {
639
+ portalId: pair.id,
640
+ turnedFacing,
641
+ turnedVelocity: { x: vx, y: vy, z: vz },
642
+ };
643
+ break;
644
+ }
645
+ }
646
+ if (portalCrossed)
647
+ break;
648
+ }
649
+ }
650
+ if (portalCrossed) {
651
+ grounded = false;
652
+ support = { kind: "none" };
653
+ supportClaimed = false;
654
+ coyoteFrames = 0;
655
+ }
554
656
  const boundsCorrection = clampBodyToBounds({ ...next, x, y, z, vx, vy, vz, grounded, coyoteFrames, jumpBufferFrames }, world);
555
657
  if (boundsCorrection.corrected) {
556
658
  correctionCount += boundsCorrection.corrections;
@@ -573,6 +675,7 @@ function stepDeterministicKccRevision2_3D(body, input, world, options, gravityPe
573
675
  collisionFilterCalls,
574
676
  collisionFilterRejectedHits,
575
677
  physicsImpulses,
678
+ portalCrossed,
576
679
  hasChecksum: false,
577
680
  checksumMode: 'disabled',
578
681
  };
@@ -585,6 +688,7 @@ function stepDeterministicKccRevision2_3D(body, input, world, options, gravityPe
585
688
  collisionFilterCalls,
586
689
  collisionFilterRejectedHits,
587
690
  physicsImpulses,
691
+ portalCrossed,
588
692
  hasChecksum: true,
589
693
  checksumMode: 'required',
590
694
  checksum: defaultChecksum({
@@ -25,7 +25,7 @@ export interface PhysicsVector3D<Quantity extends number = Dimensionless> {
25
25
  readonly y: Quantity;
26
26
  readonly z: Quantity;
27
27
  }
28
- interface PhysicsQuaternion3D extends PhysicsVector3D {
28
+ export interface PhysicsQuaternion3D extends PhysicsVector3D {
29
29
  readonly w: Dimensionless;
30
30
  }
31
31
  type PhysicsPrimitiveShape3D = Readonly<{
@@ -480,12 +480,22 @@ export interface PhysicsJointReaction3D {
480
480
  export interface PhysicsJointBreakEvent3D extends PhysicsJointReaction3D {
481
481
  readonly reason: 'impulse' | 'force' | 'torque' | 'force-and-torque';
482
482
  }
483
+ export interface PhysicsMotionBatchBodyEntry3D {
484
+ readonly id: PhysicsBodyId3D;
485
+ readonly poseJump: boolean;
486
+ }
487
+ export interface PhysicsMotionBatchSummary3D {
488
+ readonly count: number;
489
+ readonly bodies: readonly PhysicsMotionBatchBodyEntry3D[];
490
+ }
483
491
  export interface PhysicsLatestOutputs3D {
484
492
  readonly frame: bigint;
485
493
  readonly contacts: readonly PhysicsContactEvent3D[];
486
494
  readonly jointReactions: readonly PhysicsJointReaction3D[];
487
495
  readonly breakEvents: readonly PhysicsJointBreakEvent3D[];
488
496
  readonly fluidInteractions: readonly PhysicsFluidInteraction3D[];
497
+ readonly motionBatch?: PhysicsMotionBatchSummary3D;
498
+ readonly portalCrossings?: readonly PortalCrossingEvent[];
489
499
  }
490
500
  export interface PhysicsFluidInteraction3D {
491
501
  readonly bodyId: PhysicsBodyId3D;
@@ -542,6 +552,7 @@ export interface PhysicsRaycastQuery3D extends PhysicsQueryFilter3D {
542
552
  readonly dy: Dimensionless;
543
553
  readonly dz: Dimensionless;
544
554
  readonly maxDistance: Meters;
555
+ readonly maxPortalDepth?: number;
545
556
  }
546
557
  export interface PhysicsOverlapQuery3D extends PhysicsQueryFilter3D {
547
558
  readonly x: Meters;
@@ -568,6 +579,8 @@ export interface PhysicsCastHit3D {
568
579
  readonly point: PhysicsVector3D<Meters>;
569
580
  readonly normal: PhysicsVector3D;
570
581
  readonly childIndex: number;
582
+ readonly portalHops?: number;
583
+ readonly portalPath?: readonly number[];
571
584
  }
572
585
  export type PhysicsClosestPointResult3D = PhysicsCastHit3D;
573
586
  type PhysicsResolvedReferences3D<T> = T extends PhysicsPendingReference3D ? T['kind'] extends 'body' ? PhysicsBodyHandle3D : T['kind'] extends 'joint' ? PhysicsJointHandle3D : PhysicsFluidHandle3D : T extends readonly (infer Item)[] ? readonly PhysicsResolvedReferences3D<Item>[] : T extends Set<infer Item> ? Set<PhysicsResolvedReferences3D<Item>> : T extends Map<infer Key, infer Item> ? Map<Key, PhysicsResolvedReferences3D<Item>> : T extends (...args: readonly never[]) => unknown ? T : T extends number | string | bigint | boolean ? T : T extends object ? {
@@ -591,6 +604,18 @@ export interface PhysicsEditOps3D {
591
604
  createFluid(fluid: PhysicsFluidInput3D): PhysicsPendingReference3D<'fluid'>;
592
605
  replaceFluid(reference: PhysicsFluidReference3D, fluid: PhysicsFluidInput3D): PhysicsFluidReference3D;
593
606
  removeFluid(reference: PhysicsFluidReference3D): void;
607
+ atomicTeleport(reference: PhysicsBodyReference3D, pose: {
608
+ position: PhysicsVector3D<Meters | number>;
609
+ orientation: PhysicsQuaternion3D;
610
+ }, velocityRotation?: PhysicsQuaternion3D, dropContacts?: boolean): void;
611
+ setCollisionFilter(reference: PhysicsBodyReference3D, layer: number, mask: number): void;
612
+ createPortalPair(def: PortalPairDefinition): PortalPairHandle;
613
+ setPortalOpen(handle: PortalPairHandle, open: boolean): void;
614
+ movePortalEnd(handle: PortalPairHandle, end: 'A' | 'B', pose: {
615
+ position: PhysicsVector3D<Meters | number>;
616
+ rotation: PhysicsQuaternion3D;
617
+ }): void;
618
+ removePortalPair(handle: PortalPairHandle): void;
594
619
  }
595
620
  export interface PhysicsSupportSpring3D {
596
621
  readonly body: PhysicsBodyId3D | PhysicsBodyHandle3D;
@@ -716,6 +741,7 @@ export interface PhysicsWorld3D {
716
741
  digest(): bigint;
717
742
  info(): PhysicsWorldInfo3D;
718
743
  writeBodyTransformsInto(outTransforms: Float32Array, outStatusMask?: Uint8Array): number;
744
+ stepPortals?(): readonly PortalCrossingEvent[];
719
745
  validateBody?(reference: PhysicsBodyHandle3D | PhysicsBodyId3D): void;
720
746
  dispose(): void;
721
747
  }
@@ -774,6 +800,42 @@ export interface DeterministicVehicleStepOptions3D {
774
800
  * will experience exaggerated repulsion / flinging) and lacks native sleep/park integration.
775
801
  */
776
802
  export declare function stepDeterministicVehicle3D(vehicle: DeterministicVehicle3D, input: DeterministicVehicleInput3D, world: PhysicsWorld3D, options?: DeterministicVehicleStepOptions3D): DeterministicVehicleStepResult3D;
803
+ export interface PortalOpeningDefinition {
804
+ readonly width: number;
805
+ readonly height: number;
806
+ }
807
+ export interface PortalEndDefinition {
808
+ readonly position: PhysicsVector3D<number>;
809
+ readonly rotation: PhysicsQuaternion3D;
810
+ readonly opening: PortalOpeningDefinition;
811
+ readonly hostBodyId?: PhysicsBodyId3D | bigint;
812
+ }
813
+ export interface PortalPairDefinition {
814
+ readonly portalA: PortalEndDefinition;
815
+ readonly portalB: PortalEndDefinition;
816
+ readonly open?: boolean;
817
+ }
818
+ export interface PortalPairHandle {
819
+ readonly id: number;
820
+ }
821
+ export interface PortalCrossingEvent {
822
+ readonly bodyId: PhysicsBodyId3D | bigint;
823
+ readonly portalId: number;
824
+ readonly enteredEnd: 'A' | 'B';
825
+ readonly exitEnd: 'A' | 'B';
826
+ readonly turnedVelocity: PhysicsVector3D<number>;
827
+ }
828
+ export interface PortalRelativeTransform {
829
+ rotation: PhysicsQuaternion3D;
830
+ entryNormal: PhysicsVector3D<number>;
831
+ exitNormal: PhysicsVector3D<number>;
832
+ }
833
+ export interface PortalEndState {
834
+ position: PhysicsVector3D<number>;
835
+ rotation: PhysicsQuaternion3D;
836
+ opening: PortalOpeningDefinition;
837
+ hostBodyId?: PhysicsBodyId3D | bigint;
838
+ }
777
839
  export declare function initPhysics3D(options?: PhysicsInitOptions3D): Promise<void>;
778
840
  export declare function createPhysicsWorld3D(input: PhysicsWorldDefinition3D): PhysicsWorld3D;
779
841
  export type { Meters, Radians, MetersPerSecond, MetersPerSecondSquared, RadiansPerSecond, Newtons, NewtonMeters, NewtonSeconds, FrameVelocity, FrameGravity, UnitVector3, } from './units.js';