@zaisma/physics 2.6.0 → 2.7.0

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/index.d.ts CHANGED
@@ -250,6 +250,10 @@ export interface AddedBody {
250
250
  * one; "ball" at a point, turning any way; "hinge" turning about axis (a door; minimumNumber and maximumNumber limit
251
251
  * it, in radians); "slider" sliding along axis (limits in metres); "spring" pulling toward restLengthM apart
252
252
  * (stiffnessNumber, dampingNumber); "rope" never further than restLengthM apart.
253
+ *
254
+ * A hinge's angle and a slider's distance are measured as the other end (or the world) seen from the body: a body
255
+ * on a slider to the world with limits 0 to 2 moves 2 m against the axis. Point the axis the other way to turn the
256
+ * measure round. A motor's target is measured the same way.
253
257
  */
254
258
  export interface JointDeclaration {
255
259
  id: string;
@@ -266,6 +270,49 @@ export interface JointDeclaration {
266
270
  restLengthM?: number;
267
271
  stiffnessNumber?: number;
268
272
  dampingNumber?: number;
273
+ /** What turns a hinge or slides a slider by itself: a door that closes, a winch, a lift, a crane's arm. Its target changes while playing with setJoint's motorTargetNumber. */
274
+ motor?: JointMotorDeclaration;
275
+ /** How hard it pulls or pushes its ends, in newtons, before it breaks: it lets go, every game is told (the jointBroke hook), and setJoint's isEnabled true mends it. A 10 kg weight hangs with 98 N. Left out, it never breaks. */
276
+ breakForceNewtons?: number;
277
+ }
278
+
279
+ /** A joint's motor. "speed" holds a speed (radians a second about a hinge, metres a second along a slider); "position" goes to a place (radians, metres) and holds it like a spring. */
280
+ export interface JointMotorDeclaration {
281
+ motorKind: "speed" | "position";
282
+ /** The speed it holds or the place it goes to, -10000 to 10000; default 0. */
283
+ targetNumber?: number;
284
+ /** The most it pushes: newtons along a slider, newton metres about a hinge. Left out, as hard as it takes. */
285
+ maximumForceNumber?: number;
286
+ /** How hard a "position" motor pulls toward its place, for each unit it's off, whatever the body weighs; default 2000. */
287
+ stiffnessNumber?: number;
288
+ /** How hard it resists moving off its target's speed; default 10000 for "speed" (it holds its speed firmly), 200 for "position". */
289
+ dampingNumber?: number;
290
+ }
291
+
292
+ /**
293
+ * A zone: a place in the world, with no walls, that knows who's in it and may pull, push and slow them. A capture
294
+ * point, a checkpoint, a kill plane, water, wind, a lift shaft with no gravity. Bodies that never move aren't
295
+ * counted. Who's in it is worked out before each step from where everything is; the zoneEntered and zoneLeft hooks
296
+ * tell every game, zoneOccupants(zoneId) answers now, and a character kind's step asks stepContext.zoneIdsOf(character).
297
+ */
298
+ export interface ZoneDeclaration {
299
+ id: string;
300
+ /** What it's made of, 1 to 8 shapes, each placed in the zone's own space. */
301
+ shapes: { shapeKind: "box" | "ball" | "capsule" | "cylinder"; sizeM?: Point; radiusM?: number; heightM?: number; positionM?: Point; rotationDeg?: TurnDeg }[];
302
+ positionM?: Point;
303
+ rotationDeg?: TurnDeg;
304
+ /** A body it rides: positionM and rotationDeg are then in that body's own space (the deck of a ferry, the bed of a truck, a lift's floor). */
305
+ bodyId?: string;
306
+ /** Whose layers it counts; left out, everything that moves. */
307
+ collisionLayerNames?: string[];
308
+ /** How much of the world's gravity pulls inside it, -1000 to 1000; default 100. 0 floats, 20 is the moon, -20 lifts a balloon. */
309
+ gravityPct?: number;
310
+ /** A push on everything inside, in metres a second each second, whatever it weighs: wind, a current, a fan. */
311
+ pushMPerSecPerSec?: Point;
312
+ /** How much it slows what moves inside it, 0 to 100; default 0. Water is about 2, thick mud 8: a body's speed falls by this share each second, and the piece's walkers wade at 1 / (1 + dampingNumber / 4) of their speed (two thirds in water, a third in mud). */
313
+ dampingNumber?: number;
314
+ /** Whether it's on from the start; default true. setZone switches it while playing: off, nobody is in it and it does nothing. */
315
+ isEnabled?: boolean;
269
316
  }
270
317
 
271
318
  export interface WorldDeclaration {
@@ -280,6 +327,8 @@ export interface WorldDeclaration {
280
327
  bodyKinds?: Record<string, BodyKindDeclaration>;
281
328
  /** Joints there from the start, up to 1000 with those added while playing. */
282
329
  joints?: JointDeclaration[];
330
+ /** Zones, up to 250: places that know who's in them and may pull, push and slow them. */
331
+ zones?: ZoneDeclaration[];
283
332
  /**
284
333
  * Layers by name, up to 15, with the layers each touches (both ways: a layer touches another when either says so).
285
334
  * "world" (fixed bodies'), "body" (moving bodies') and "character" (characters') are where things are unless they
@@ -318,6 +367,7 @@ export interface PhysicsWorld {
318
367
  readonly bodies: readonly CheckedBody[];
319
368
  readonly bodyKinds: readonly { name: string; declared: BodyKindDeclaration }[];
320
369
  readonly joints: readonly JointDeclaration[];
370
+ readonly zones: readonly { id: string; bodyId: string | null; isEnabled: boolean; gravityPct: number; pushMPerSecPerSec: Point; dampingNumber: number }[];
321
371
  readonly collisionLayers: readonly { name: string; touchedNames: string[] }[];
322
372
  readonly character: { heightM: number; radiusM: number; stepHeightM: number; maximumSlopeDeg: number };
323
373
  readonly characterSizes: readonly { name: string; heightM: number; radiusM: number; stepHeightM: number; maximumSlopeDeg: number }[];
@@ -437,6 +487,70 @@ export interface BallOverlapQuery {
437
487
  collisionLayerNames?: string[];
438
488
  excludedId?: string;
439
489
  }
490
+ export interface BoxCastQuery extends RayQuery {
491
+ /** Its width, height and depth. */
492
+ sizeM: Point;
493
+ rotation?: Rotation;
494
+ isStoppedAtPenetration?: boolean;
495
+ }
496
+ export interface BoxOverlapQuery {
497
+ centerM: Point;
498
+ sizeM: Point;
499
+ rotation?: Rotation;
500
+ collisionLayerNames?: string[];
501
+ excludedId?: string;
502
+ }
503
+ /** Many rays at once: rays holds six numbers a ray, where it starts (x, y, z) and its direction (x, y, z, of any length). Up to 65,536 rays a call. */
504
+ export interface RaysQuery {
505
+ rays: Float32Array;
506
+ /** How many of rays to cast; left out, all it holds. */
507
+ rayCount?: number;
508
+ maximumDistanceM: number;
509
+ collisionLayerNames?: string[];
510
+ excludedId?: string;
511
+ }
512
+ /** castRays' answer: how far each ray went (-1 for one that met nothing), the normal where it stopped (three numbers a ray), and any one ray's hit whole. */
513
+ export interface RaysAnswer {
514
+ rayCount: number;
515
+ hitCount: number;
516
+ distancesM: Float32Array;
517
+ normals: Float32Array;
518
+ /** One ray's hit as castRay answers it, or null for a ray that met nothing. With into, written there. */
519
+ hitAt(rayIndex: number, into?: QueryHit): QueryHit | null;
520
+ }
521
+ /** A place asked which zones it's in: a point (centerM alone), a ball (with radiusM) or a capsule (with radiusM and heightM, standing up or turned by rotation). */
522
+ export interface ZonesAtQuery {
523
+ centerM: Point;
524
+ radiusM?: number;
525
+ heightM?: number;
526
+ rotation?: Rotation;
527
+ }
528
+
529
+ /** What asks the world as it stands now: the same in a game, on a game server, in a kind's step and over a level. */
530
+ export interface PhysicsQueries {
531
+ /** The first thing a ray meets, or null. With into (an object the game keeps), written there instead of a new one: for a game casting thousands a second. */
532
+ castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
533
+ /** Everything a ray passes through, nearest first, one hit a shape, up to maximumHitCount (default 16, at most 256): a bullet that goes through thin walls. With into (a list the game keeps), written there. */
534
+ castRayAll(query: RayQuery & { maximumHitCount?: number }, into?: QueryHit[]): QueryHit[];
535
+ /** Many rays in one call, several times cheaper a ray than castRay: a shotgun's pellets, a lidar, a crowd's feet. With into (an answer the game keeps), written there. */
536
+ castRays(query: RaysQuery, into?: RaysAnswer): RaysAnswer;
537
+ castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
538
+ /** The first thing a capsule (standing up, or turned) meets moving along a direction, or null. */
539
+ castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
540
+ /** The first thing a box (turned by rotation) meets moving along a direction, or null: a crate's width, a vehicle's body, a melee swing. */
541
+ castBox(query: BoxCastQuery, into?: QueryHit): QueryHit | null;
542
+ overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
543
+ /** Everything a box overlaps: a room, a blast, a trigger of the game's own. */
544
+ overlapBox(query: BoxOverlapQuery): { bodyId: string | null; characterId: string | null }[];
545
+ /**
546
+ * Where a capsule touches the world, with each contact's normal and depth: what a game's own movement pushes out
547
+ * of walls by. With into (a list of the caller's own, kept and given again), written there: nothing is left for
548
+ * the garbage collector.
549
+ */
550
+ overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
551
+ /** The ids of the zones that are on and that a place touches now. */
552
+ zonesAt(query: ZonesAtQuery): string[];
553
+ }
440
554
 
441
555
  /** The world's numbers a step moves by: the piece's settings, turned by a character kind's own. */
442
556
  export interface PhysicsTuning {
@@ -452,7 +566,7 @@ export interface PhysicsTuning {
452
566
  }
453
567
 
454
568
  /** What a character kind's step reaches: the world's queries, the move, and whose step it is. */
455
- export interface CharacterStepContext {
569
+ export interface CharacterStepContext extends PhysicsQueries {
456
570
  tickIndex: number;
457
571
  tickDurationSec: number;
458
572
  isReplay: boolean;
@@ -467,18 +581,33 @@ export interface CharacterStepContext {
467
581
  * whether it stands.
468
582
  */
469
583
  moveAndSlide(character: SteppedCharacter, movedM: Point, into?: { movedM: Point; isGrounded: boolean }): { movedM: Point; isGrounded: boolean };
470
- castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
471
- castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
472
- castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
473
- overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
474
- /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
475
- overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
584
+ /** The ids of the zones a character is in now. */
585
+ zoneIdsOf(character: SteppedCharacter): string[];
586
+ /**
587
+ * What the zones a character stands in do there, together, or null where nothing pulls, pushes or slows it: the
588
+ * piece's walk moves by it, and a game's own kinematic kind does the same in its step (the engine moves bodies and
589
+ * dynamic characters by it itself). The object is the piece's own, filled again by the next call.
590
+ */
591
+ zoneEffectsOf(character: SteppedCharacter): { gravityPct: number; pushMPerSecPerSec: Point; dampingNumber: number } | null;
592
+ /** Who was in a zone at this step's start: [{ bodyId, characterId }], one of the two null. */
593
+ zoneOccupants(zoneId: string): { bodyId: string | null; characterId: string | null }[];
594
+ /** A body's place, rotation, speed and spin now, in an object of the body's own that the next call fills again (copy what you keep). Give the body a body kind's step was given, or a body's id. Null for a body that isn't here. */
595
+ bodyMotion(body: SteppedBody | string): { positionM: Point; rotation: Rotation; velocityMPerSec: Point; spinRadPerSec: Point } | null;
596
+ /**
597
+ * Pushes a moving body with a force in newtons for this one step: at its centre of mass, or at a place in the
598
+ * world (atM), which turns it too. From a body kind's step (and a character kind that steps before the world) the
599
+ * engine works with it through the whole step, so a lift equal to the body's weight holds it still. Answers false
600
+ * for a body physics doesn't move.
601
+ */
602
+ addForce(body: SteppedBody | string, forceNewtons: Point, atM?: Point | null): boolean;
603
+ /** Turns a moving body with a torque in newton metres about the world's axes, for this one step. */
604
+ addTorque(body: SteppedBody | string, torqueNewtonMetres: Point): boolean;
476
605
  /** A body as the world has it now, read only (pulling a cart: how fast it lets him go), or null. */
477
606
  bodyState(bodyId: string): (Omit<BodyState, "riderCharacterIds"> & { massKg: number | null }) | null;
478
607
  /** Another character as the world has it now, read only, or null. */
479
608
  characterState(characterId: string): { positionM: Point; velocityMPerSec: Point; facingYawRad: number; isGrounded: boolean; rideBodyId: string | null; collisionLayerName: string; characterSizeName: string | null; own: Record<string, any> } | null;
480
- /** Ties or lets go a joint from the step (a press that takes a cart's handles), so a replay runs it exactly. Answers false for a joint that isn't here. */
481
- setJoint(jointId: string, changes: { isEnabled: boolean }): boolean;
609
+ /** Ties or lets go a joint from the step (a press that takes a cart's handles), or gives its motor another target, so a replay runs it exactly. Answers false for a joint that isn't here. */
610
+ setJoint(jointId: string, changes: { isEnabled?: boolean; motorTargetNumber?: number }): boolean;
482
611
  /** Puts the character on one of the world's collision layers from its step (through his own cart while he holds it). */
483
612
  setLayer(character: SteppedCharacter, collisionLayerName: string): void;
484
613
  /**
@@ -605,6 +734,42 @@ export interface PhysicsHookHandlers {
605
734
  beforePutBack: (positionM: Point, fallen: { id: string; isCharacter: boolean; roomState: any }) => Point | void;
606
735
  /** In every game: a moving body hit something hard enough to hear. */
607
736
  bodyHit: (hit: { bodyId: string | null; otherBodyId: string | null; otherCharacterId: string | null; speedMPerSec: number }) => void;
737
+ /** In every game: a body or a character came into a zone (one of the two ids, the other null). */
738
+ zoneEntered: (change: { zoneId: string; bodyId: string | null; characterId: string | null }) => void;
739
+ /** In every game: a body or a character left a zone, or left the world while in it. */
740
+ zoneLeft: (change: { zoneId: string; bodyId: string | null; characterId: string | null }) => void;
741
+ /** In every game: a joint with a breakForceNewtons was pulled or pushed harder than that, and let go. */
742
+ jointBroke: (broken: { jointId: string; bodyId: string; otherBodyId: string | null }) => void;
743
+ }
744
+
745
+ /** A body as its kind's step gets it. */
746
+ export interface SteppedBody {
747
+ readonly id: string;
748
+ /** Which of the world's bodyKinds it's made as. */
749
+ readonly bodyKindName: string;
750
+ /** The kind's own fields for this body: change them in place. */
751
+ own: Record<string, any>;
752
+ /** Who sits in its first seat this step, or null. */
753
+ readonly driverCharacterId: string | null;
754
+ readonly rigidBody: Engine.RigidBody;
755
+ }
756
+
757
+ /**
758
+ * Rules of a game's own for one of the world's body kinds: fields every body of the kind keeps, and a step run once
759
+ * a fixed step for each, the same in every player's game and on the game server. A boat that floats and is steered,
760
+ * an aircraft, a hover bike, a turret that tracks, a mine that counts down.
761
+ */
762
+ export interface BodyBehaviorDeclaration {
763
+ /** What the kind keeps of each body beyond the piece's own (its throttle, its fuel, its fuse): plain fields, shared on the wire. Up to 8 of a world's body kinds may have fields of their own. */
764
+ stateFields?: FieldDeclaration[];
765
+ /**
766
+ * One fixed step of one body, before the engine moves the world. driverInput is the input of whoever sits in its
767
+ * first seat (the character kind's inputFields), or null with nobody there. It pushes with stepContext.addForce
768
+ * and addTorque, reads with stepContext.bodyMotion(body) and the queries, and keeps what it must remember in body.own.
769
+ */
770
+ step(body: SteppedBody, driverInput: Record<string, any> | null, stepContext: CharacterStepContext): void;
771
+ /** true to step a body of this kind while it lies at rest with nobody in its first seat (a mine's fuse, a turret that watches). By default such a body isn't stepped, and costs nothing. */
772
+ isSteppedAtRest?: boolean;
608
773
  }
609
774
 
610
775
  // ---- What a game calls ----
@@ -620,6 +785,10 @@ export interface BodyState {
620
785
  /** How heavy it is now; null for a fixed body. */
621
786
  massKg: number | null;
622
787
  isResting: boolean;
788
+ /** Which of the world's bodyKinds it's made as, or null for a body declared with shapes of its own. */
789
+ bodyKindName: string | null;
790
+ /** Its kind's own fields (physicsKind's bodies), or null for a kind with no rules of its own. */
791
+ own: Record<string, any> | null;
623
792
  riderCharacterIds: string[];
624
793
  /** A character kind's own (with @zaisma/physics-party: holderCharacterIds on a body; heldBodyId, handPositionM, loadPct on a character). */
625
794
  [kindOwn: string]: any;
@@ -645,7 +814,7 @@ export interface CharacterView {
645
814
  }
646
815
 
647
816
  /** What changes the world, the same alone, in a player's game that runs it, and on a game server. */
648
- export interface PhysicsChanges {
817
+ export interface PhysicsChanges extends PhysicsQueries {
649
818
  bodyIds(): string[];
650
819
  hasBody(bodyId: string): boolean;
651
820
  bodyState(bodyId: string): BodyState | null;
@@ -653,7 +822,7 @@ export interface PhysicsChanges {
653
822
  addBody(body: AddedBody): boolean;
654
823
  removeBody(bodyId: string): boolean;
655
824
  /** Sets a body at once: its place and turn (a teleport), its speed or spin, how it moves (a parked cart made fixed), its layer. */
656
- setBody(bodyId: string, changes: { positionM?: Point; rotationDeg?: TurnDeg; velocityMPerSec?: Point; spinRadPerSec?: Point; motionKind?: "moving" | "kinematic" | "fixed"; collisionLayerName?: string; /** How heavy it is now, 0.01 to 100000 kg, to the hundredth: what rides in a cart's bed weighs on it. */ massKg?: number }): boolean;
825
+ setBody(bodyId: string, changes: { positionM?: Point; rotationDeg?: TurnDeg; velocityMPerSec?: Point; spinRadPerSec?: Point; motionKind?: "moving" | "kinematic" | "fixed"; collisionLayerName?: string; /** How heavy it is now, 0.01 to 100000 kg, to the hundredth: what rides in a cart's bed weighs on it. */ massKg?: number; /** Some of its kind's own fields. */ own?: Record<string, any> }): boolean;
657
826
  /** A sudden change of a body's speed, as a hit gives. */
658
827
  pushBody(bodyId: string, pushMPerSec: Point): boolean;
659
828
  characterIds(): string[];
@@ -669,18 +838,17 @@ export interface PhysicsChanges {
669
838
  /** Adds a joint while playing. */
670
839
  addJoint(joint: JointDeclaration): boolean;
671
840
  removeJoint(jointId: string): boolean;
672
- /** Lets a joint go (isEnabled false), or holds again. */
673
- setJoint(jointId: string, changes: { isEnabled: boolean }): boolean;
841
+ /** Lets a joint go (isEnabled false) or holds again (true: a broken one is mended), or gives its motor another target (a door told to close, a winch to turn). */
842
+ setJoint(jointId: string, changes: { isEnabled?: boolean; motorTargetNumber?: number }): boolean;
674
843
  isJointEnabled(jointId: string): boolean;
675
- /** The first thing a ray meets, or null. With into (an object the game keeps), written there instead of a new one: for a game casting thousands a second. */
676
- castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
677
- castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
678
- /** The first thing a capsule (standing up, or turned) meets moving along a direction, or null. */
679
- castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
680
- overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
681
- /** Where a capsule touches the world, with each contact's normal and depth: what a game's own movement pushes out of walls by. */
682
- /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
683
- overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
844
+ /** A joint as the world has it now: whether it holds, whether it broke, and its motor's target (0 without one). Null for a joint that isn't here. */
845
+ jointState(jointId: string): { isEnabled: boolean; isBroken: boolean; motorTargetNumber: number } | null;
846
+ zoneIds(): string[];
847
+ /** Who's in a zone, as of the last step: [{ bodyId, characterId }], one of the two null. */
848
+ zoneOccupants(zoneId: string): { bodyId: string | null; characterId: string | null }[];
849
+ /** Switches a zone on or off for everyone (a fan that starts, a capture point that opens). */
850
+ setZone(zoneId: string, changes: { isEnabled: boolean }): boolean;
851
+ isZoneEnabled(zoneId: string): boolean;
684
852
  /** Switches one of the world's triangle groups on or off for everyone (a door that opens, a bridge that falls), 1 to 63. */
685
853
  setTriangleGroup(groupNumber: number, isEnabled: boolean): boolean;
686
854
  isTriangleGroupEnabled(groupNumber: number): boolean;
@@ -705,7 +873,7 @@ export interface Physics extends PhysicsChanges {
705
873
  * its spring reaches (where the wheel hangs below its place), how far round it's turned, its steering, and whether it
706
874
  * touches anything. A body without wheels has none.
707
875
  */
708
- drawnBody(bodyId: string): { positionM: Point; rotation: Rotation; steerNumber: number; wheels: { suspensionM: number; spinRad: number; steerRad: number; isOnGround: boolean }[] } | null;
876
+ drawnBody(bodyId: string): { positionM: Point; rotation: Rotation; steerNumber: number; wheels: { suspensionM: number; spinRad: number; steerRad: number; isOnGround: boolean }[]; /** Its kind's own fields as drawn this frame, or null for a kind with none. */ own: Record<string, any> | null } | null;
709
877
  /** Puts a three.js object where a body is drawn this frame. */
710
878
  applyTo(object3d: { position: { set(x: number, y: number, z: number): void }; quaternion: { set(...parts: number[]): unknown } }, bodyId: string): boolean;
711
879
  /** This player's input from now on, or with { characterId } a bot's this game moves: the character kind's input fields. */
@@ -744,6 +912,8 @@ export interface PhysicsKindOptions {
744
912
  hooks?: Partial<PhysicsHookHandlers>;
745
913
  /** How the world's characters move: the piece's walk (the default), a game's own, or a piece's (@zaisma/physics-party). */
746
914
  characters?: CharacterKind | CharacterKindDeclaration;
915
+ /** Rules of the game's own for the world's body kinds, by a bodyKinds name: fields each body keeps and a step that moves it. The same in the game and on its game server. */
916
+ bodies?: Record<string, BodyBehaviorDeclaration>;
747
917
  }
748
918
 
749
919
  export interface PhysicsKind extends Kind<Physics, ServerPhysics> {
@@ -783,7 +953,7 @@ export interface LevelCharactersOptions {
783
953
  }
784
954
 
785
955
  /** What a game calls on characters over a level: @zaisma/net's characters, and the level's queries and drawing. */
786
- export interface LevelCharacters extends import("../net/index.js").Characters {
956
+ export interface LevelCharacters extends import("../net/index.js").Characters, PhysicsQueries {
787
957
  readonly world: PhysicsWorld;
788
958
  readonly settings: Settings<PhysicsSettingValues>;
789
959
  /** Where and how to draw a character this frame: its feet, facing, speed, footing and its kind's own fields. */
@@ -795,26 +965,14 @@ export interface LevelCharacters extends import("../net/index.js").Characters {
795
965
  applyTo(object3d: { position: { set(x: number, y: number, z: number): void }; quaternion: { set(...parts: number[]): unknown } }, bodyId: string): boolean;
796
966
  /** One of the level's bodies as this game has it now, or null. */
797
967
  bodyState(bodyId: string): { positionM: Point; rotation: Rotation } | null;
798
- castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
799
- castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
800
- castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
801
- overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
802
- /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
803
- overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
804
968
  }
805
969
 
806
970
  /** The same on a game server: kind.onServer(state, room). */
807
- export interface ServerLevelCharacters extends import("../net/index.js").ServerCharacters {
971
+ export interface ServerLevelCharacters extends import("../net/index.js").ServerCharacters, PhysicsQueries {
808
972
  readonly world: PhysicsWorld;
809
973
  characterState(characterId: string): CharacterView | null;
810
974
  /** One of the level's bodies as this room has it now, or null. */
811
975
  bodyState(bodyId: string): { positionM: Point; rotation: Rotation } | null;
812
- castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
813
- castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
814
- castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
815
- overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
816
- /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
817
- overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
818
976
  /** Switches one of the level's triangle groups in this room (a door, a bridge), 1 to 63: every player's game from the next step. */
819
977
  setTriangleGroup(groupNumber: number, isEnabled: boolean): boolean;
820
978
  }
package/index.js CHANGED
@@ -19,9 +19,9 @@ export { PieceError } from "../piece/index.js";
19
19
  * every frame. Throws PieceError "engine_not_loaded" before loadPhysics() has finished.
20
20
  */
21
21
  export function createPhysics(givenWorld, given = {}) {
22
- if (given === null || typeof given !== "object" || Object.keys(given).some((key) => !["settings", "hooks", "ticksPerSec", "playerId", "characters"].includes(key))) refuse("unknown_argument", "createPhysics takes a world, then { settings, hooks, ticksPerSec, playerId, characters }.", "given", "Give the world first, then an object with any of those.");
22
+ if (given === null || typeof given !== "object" || Object.keys(given).some((key) => !["settings", "hooks", "ticksPerSec", "playerId", "characters", "bodies"].includes(key))) refuse("unknown_argument", "createPhysics takes a world, then { settings, hooks, ticksPerSec, playerId, characters, bodies }.", "given", "Give the world first, then an object with any of those.");
23
23
  const { ticksPerSec = 30, playerId = "player" } = given;
24
24
  if (!(Number.isInteger(ticksPerSec) && ticksPerSec >= 1 && ticksPerSec <= 60)) refuse("bad_argument", `ticksPerSec is ${JSON.stringify(ticksPerSec)}.`, "ticksPerSec", "Give a whole number from 1 to 60: 30 suits most games.");
25
25
  checkId(playerId, "bad_character_id", "playerId");
26
- return alonePhysics(givenWorld, { settings: given.settings, hooks: given.hooks, ticksPerSec, playerId, characters: given.characters, defineShape });
26
+ return alonePhysics(givenWorld, { settings: given.settings, hooks: given.hooks, ticksPerSec, playerId, characters: given.characters, bodies: given.bodies, defineShape });
27
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/physics",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Physics that works as it's added, alone and online, for every kind of game: one world of bodies (moving, kinematic or fixed), ground for big outdoor maps, joints, wheeled vehicles, seats, collision layers and queries, with characters that move by the game's own rules. Rapier is the engine, shipped inside.",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "homepage": "https://zaisma.com",
@@ -34,6 +34,7 @@
34
34
  "LICENSE.txt",
35
35
  "README.md",
36
36
  "characters.js",
37
+ "bodies.js",
37
38
  "data.js",
38
39
  "declare.js",
39
40
  "engine.js",
package/piece.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "statement_version_number": 1,
3
3
  "name": "@zaisma/physics",
4
- "piece_version": "2.6.0",
4
+ "piece_version": "2.7.0",
5
5
  "kind": "foundation",
6
6
  "standard": "@zaisma/standard",
7
7
  "summary": "Physics that works as it's added, alone and online, for every kind of game: one world of bodies (moving, kinematic or fixed), ground for big outdoor maps, joints, wheeled vehicles, seats, collision layers and queries, with characters that move by the game's own rules. Rapier is the engine, shipped inside.",
@@ -16,6 +16,7 @@
16
16
  "declare.js",
17
17
  "engine.js",
18
18
  "characters.js",
19
+ "bodies.js",
19
20
  "data.js",
20
21
  "rapier/rapier.d.ts",
21
22
  "batch.js",
@@ -40,6 +41,7 @@
40
41
  "declare.js",
41
42
  "engine.js",
42
43
  "characters.js",
44
+ "bodies.js",
43
45
  "data.js",
44
46
  "batch.js",
45
47
  "simulation.js",
@@ -135,6 +137,21 @@
135
137
  "name": "body_hit",
136
138
  "hook_kind": "event",
137
139
  "summary": "Told when a moving body hits something hard enough to hear, with { bodyId, otherBodyId, otherCharacterId, speedMPerSec }: for a thud, dust or a rumble."
140
+ },
141
+ {
142
+ "name": "zone_entered",
143
+ "hook_kind": "event",
144
+ "summary": "Told when a body or a character comes into one of the world's zones, with { zoneId, bodyId, characterId }: a capture point taken, a checkpoint crossed, a splash."
145
+ },
146
+ {
147
+ "name": "zone_left",
148
+ "hook_kind": "event",
149
+ "summary": "Told when a body or a character leaves one of the world's zones (or leaves the world while in it), with { zoneId, bodyId, characterId }."
150
+ },
151
+ {
152
+ "name": "joint_broke",
153
+ "hook_kind": "event",
154
+ "summary": "Told when a joint with a breakForceNewtons lets go because it was pulled or pushed harder than that, with { jointId, bodyId, otherBodyId }: a rope that snaps, a bridge that gives way."
138
155
  }
139
156
  ]
140
157
  }
package/piece.json.js CHANGED
@@ -2,7 +2,7 @@
2
2
  export default {
3
3
  "statement_version_number": 1,
4
4
  "name": "@zaisma/physics",
5
- "piece_version": "2.6.0",
5
+ "piece_version": "2.7.0",
6
6
  "kind": "foundation",
7
7
  "standard": "@zaisma/standard",
8
8
  "summary": "Physics that works as it's added, alone and online, for every kind of game: one world of bodies (moving, kinematic or fixed), ground for big outdoor maps, joints, wheeled vehicles, seats, collision layers and queries, with characters that move by the game's own rules. Rapier is the engine, shipped inside.",
@@ -17,6 +17,7 @@ export default {
17
17
  "declare.js",
18
18
  "engine.js",
19
19
  "characters.js",
20
+ "bodies.js",
20
21
  "data.js",
21
22
  "rapier/rapier.d.ts",
22
23
  "batch.js",
@@ -41,6 +42,7 @@ export default {
41
42
  "declare.js",
42
43
  "engine.js",
43
44
  "characters.js",
45
+ "bodies.js",
44
46
  "data.js",
45
47
  "batch.js",
46
48
  "simulation.js",
@@ -136,6 +138,21 @@ export default {
136
138
  "name": "body_hit",
137
139
  "hook_kind": "event",
138
140
  "summary": "Told when a moving body hits something hard enough to hear, with { bodyId, otherBodyId, otherCharacterId, speedMPerSec }: for a thud, dust or a rumble."
141
+ },
142
+ {
143
+ "name": "zone_entered",
144
+ "hook_kind": "event",
145
+ "summary": "Told when a body or a character comes into one of the world's zones, with { zoneId, bodyId, characterId }: a capture point taken, a checkpoint crossed, a splash."
146
+ },
147
+ {
148
+ "name": "zone_left",
149
+ "hook_kind": "event",
150
+ "summary": "Told when a body or a character leaves one of the world's zones (or leaves the world while in it), with { zoneId, bodyId, characterId }."
151
+ },
152
+ {
153
+ "name": "joint_broke",
154
+ "hook_kind": "event",
155
+ "summary": "Told when a joint with a breakForceNewtons lets go because it was pulled or pushed harder than that, with { jointId, bodyId, otherBodyId }: a rope that snaps, a bridge that gives way."
139
156
  }
140
157
  ]
141
158
  };
package/rapier/CHANGES.md CHANGED
@@ -12,6 +12,8 @@ Nothing of Rapier's own is removed: its whole JavaScript API is there as in the
12
12
  - **Three fields made visible inside the crate** (`pub(crate)`), so the module can reach them: the character controller's `controller`, `result` and `events` (`src/control/character_controller.rs`), and the vehicle controller's `controller` (`src/control/ray_cast_vehicle_controller.rs`).
13
13
  - **Level colliders, never paired with each other** (build 2). `RawBatch.markLevelCollider(colliders, collider)` sets the lowest bit of a collider's `user_data`; the broad phase of the `rapier3d` crate (`src/geometry/broad_phase_bvh.rs`, patched in the published 0.30.1 source, whose checksum the build checks) then never keeps a pair of two marked colliders. The stock one keeps every pair of touching fixed colliders and walks them all each step, which made a level of thousands of pieces slow and heavy; two fixed colliders never collide, so nothing else changes. A game that sets `user_data` on its own colliders keeps that bit clear.
14
14
  - **A broad phase that rests** (build 2). A step in which no collider moved, came or went leaves the broad phase as it is, where the stock one rewrites its whole tree every step: a world at rest costs the same however big its level.
15
+ - **Build 3: a world's own rules.** `RawBatch` gains zones (who is inside each, found once a step; their pull, push and slowing given as real forces through the step's substeps), every hit along a ray, many rays in one call, box casts and box overlaps, forces and torques on a body for one step, the force a joint holds (read from what the solver gave it, ropes and springs included) and a motor's most force. A swept ball's or capsule's touch point is now where it is in the world (it was off for anything away from the world's middle, since 2.5.0).
16
+ - **A character's move that slides along every surface it touches** (build 3; `src/control/character_controller.rs`, patched in the crate). The stock move takes one surface at a time: touching a wall and two ground triangles together, it passes what's left from one to the next until it runs out of tries and answers no move at all. Here what's left is held off every surface touched since the move last went anywhere: along one, along the crease of two, or nowhere in a corner of three. And on ground it may stand on, the move keeps its walk and loses only the slip gravity would give it: the stock one dropped the part it took for "down the slope", which on ground a hair from level points anywhere, so whether a step moved turned on a tenth of a millimetre.
15
17
  - **The loader**: one module that starts the engine from WebAssembly the piece is given (`startEngine`, `startEngineLater`) instead of fetching its own, and that also exports `RawBatch`, `ENGINE_VERSION` and `engineMemory()`.
16
18
  - **The crate versions** are locked by Zaisma's own `Cargo.lock`: the tag's lock file was a version behind its `Cargo.toml`.
17
19