@zylem/behaviors 0.4.1 → 0.5.1

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.
Files changed (145) hide show
  1. package/README.md +13 -1
  2. package/dist/{behavior-system-y8SGrGWy.d.ts → behavior-system-CeJXzNvr.d.ts} +305 -17
  3. package/dist/{chunk-GFARAJV2.js → chunk-2PAHQZZD.js} +44 -73
  4. package/dist/chunk-2PAHQZZD.js.map +1 -0
  5. package/dist/chunk-52FJIDGL.js +30 -0
  6. package/dist/chunk-52FJIDGL.js.map +1 -0
  7. package/dist/{chunk-UYFOLI2X.js → chunk-5A5AYP2C.js} +1 -1
  8. package/dist/{chunk-UYFOLI2X.js.map → chunk-5A5AYP2C.js.map} +1 -1
  9. package/dist/{chunk-A4CA35DQ.js → chunk-5EBIIYZD.js} +25 -45
  10. package/dist/chunk-5EBIIYZD.js.map +1 -0
  11. package/dist/{chunk-4L36OPY2.js → chunk-5NJGASUJ.js} +81 -135
  12. package/dist/chunk-5NJGASUJ.js.map +1 -0
  13. package/dist/{chunk-27UPCP5B.js → chunk-5UMCWV5A.js} +22 -13
  14. package/dist/chunk-5UMCWV5A.js.map +1 -0
  15. package/dist/chunk-5WRI5ZAA.js +31 -0
  16. package/dist/chunk-5WRI5ZAA.js.map +1 -0
  17. package/dist/{chunk-5SM5SH5O.js → chunk-7JLWZXPA.js} +2 -2
  18. package/dist/{chunk-Z72F2ENM.js → chunk-AEBDZWCP.js} +17 -26
  19. package/dist/chunk-AEBDZWCP.js.map +1 -0
  20. package/dist/chunk-AS3HR7AS.js +188 -0
  21. package/dist/chunk-AS3HR7AS.js.map +1 -0
  22. package/dist/chunk-E4X4YJZB.js +841 -0
  23. package/dist/chunk-E4X4YJZB.js.map +1 -0
  24. package/dist/{chunk-VMQHNJJI.js → chunk-F6ESSHQK.js} +17 -23
  25. package/dist/chunk-F6ESSHQK.js.map +1 -0
  26. package/dist/chunk-GQAPBNGT.js +210 -0
  27. package/dist/chunk-GQAPBNGT.js.map +1 -0
  28. package/dist/chunk-JGXRQUTC.js +191 -0
  29. package/dist/chunk-JGXRQUTC.js.map +1 -0
  30. package/dist/{chunk-BXP4K7RF.js → chunk-JVADRLWX.js} +57 -186
  31. package/dist/chunk-JVADRLWX.js.map +1 -0
  32. package/dist/{chunk-ZA43LPRM.js → chunk-KIYUUSPK.js} +2 -2
  33. package/dist/{chunk-QDCJLJUV.js → chunk-KOWGILCN.js} +22 -13
  34. package/dist/chunk-KOWGILCN.js.map +1 -0
  35. package/dist/{chunk-WWVD5DR5.js → chunk-M3QDKKDF.js} +2 -8
  36. package/dist/chunk-M3QDKKDF.js.map +1 -0
  37. package/dist/{chunk-FTDZAKZW.js → chunk-NQPYMUDF.js} +7 -5
  38. package/dist/{chunk-FTDZAKZW.js.map → chunk-NQPYMUDF.js.map} +1 -1
  39. package/dist/{chunk-XP3ASVGJ.js → chunk-NW4SE5XW.js} +2 -2
  40. package/dist/{chunk-KDY5N6J4.js → chunk-OPZ2LVS2.js} +1 -22
  41. package/dist/{chunk-KDY5N6J4.js.map → chunk-OPZ2LVS2.js.map} +1 -1
  42. package/dist/{chunk-5XZWTFGF.js → chunk-PLIXVF7B.js} +3 -3
  43. package/dist/chunk-PLIXVF7B.js.map +1 -0
  44. package/dist/{chunk-Y7YIAWPW.js → chunk-SGHIGTVZ.js} +1 -11
  45. package/dist/{chunk-Y7YIAWPW.js.map → chunk-SGHIGTVZ.js.map} +1 -1
  46. package/dist/{chunk-UL6Q5HDP.js → chunk-TBUKJKY6.js} +3 -25
  47. package/dist/chunk-TBUKJKY6.js.map +1 -0
  48. package/dist/chunk-VFDUKGRZ.js +155 -0
  49. package/dist/chunk-VFDUKGRZ.js.map +1 -0
  50. package/dist/chunk-VT3H43QA.js +288 -0
  51. package/dist/chunk-VT3H43QA.js.map +1 -0
  52. package/dist/chunk-W26PHBME.js +309 -0
  53. package/dist/chunk-W26PHBME.js.map +1 -0
  54. package/dist/components-BANNjAZP.d.ts +30 -0
  55. package/dist/cooldown.d.ts +2 -2
  56. package/dist/cooldown.js +1 -0
  57. package/dist/coordinators/boundary-ricochet-3d.d.ts +4 -4
  58. package/dist/coordinators/boundary-ricochet-3d.js +1 -0
  59. package/dist/coordinators/boundary-ricochet.d.ts +4 -4
  60. package/dist/coordinators/boundary-ricochet.js +3 -2
  61. package/dist/coordinators/first-person-shooter.js +1 -0
  62. package/dist/coordinators/multidirectional-space-shooter.d.ts +3 -3
  63. package/dist/coordinators/multidirectional-space-shooter.js +5 -3
  64. package/dist/coordinators/top-down-shooter.d.ts +3 -3
  65. package/dist/coordinators/top-down-shooter.js +5 -3
  66. package/dist/core.d.ts +288 -8
  67. package/dist/core.js +480 -13
  68. package/dist/core.js.map +1 -1
  69. package/dist/destructible-3d.d.ts +32 -4
  70. package/dist/destructible-3d.js +2 -1
  71. package/dist/destructible-prebake.js +1 -0
  72. package/dist/{entity-types-CmtQ-IBp.d.ts → entity-types-DhfsZbSK.d.ts} +5 -3
  73. package/dist/first-person.d.ts +27 -38
  74. package/dist/first-person.js +8 -8
  75. package/dist/index.d.ts +14 -15
  76. package/dist/index.js +37 -52
  77. package/dist/jumper-2d.d.ts +3 -17
  78. package/dist/jumper-2d.js +4 -9
  79. package/dist/jumper-3d.d.ts +5 -39
  80. package/dist/jumper-3d.js +5 -10
  81. package/dist/{moveable-Cl9h-_w7.d.ts → moveable-XhzWPAw5.d.ts} +21 -4
  82. package/dist/particle-emitter/presets.js +1 -0
  83. package/dist/particle-emitter.d.ts +3 -3
  84. package/dist/particle-emitter.js +3 -2
  85. package/dist/platformer-2d.d.ts +13 -82
  86. package/dist/platformer-2d.js +4 -5
  87. package/dist/platformer-3d.d.ts +13 -78
  88. package/dist/platformer-3d.js +4 -5
  89. package/dist/ricochet-2d.d.ts +3 -3
  90. package/dist/ricochet-2d.js +4 -3
  91. package/dist/ricochet-3d.d.ts +3 -3
  92. package/dist/ricochet-3d.js +4 -3
  93. package/dist/runtime-2d.d.ts +2 -2
  94. package/dist/runtime-2d.js +1 -0
  95. package/dist/runtime-2d.js.map +1 -1
  96. package/dist/screen-visibility.d.ts +2 -2
  97. package/dist/screen-visibility.js +1 -0
  98. package/dist/screen-wrap.d.ts +2 -2
  99. package/dist/screen-wrap.js +4 -3
  100. package/dist/shooter-2d.d.ts +3 -3
  101. package/dist/shooter-2d.js +4 -3
  102. package/dist/thruster.d.ts +5 -34
  103. package/dist/thruster.js +4 -6
  104. package/dist/top-down-movement.d.ts +9 -27
  105. package/dist/top-down-movement.js +6 -6
  106. package/dist/{vector-Bm65-FOG.d.ts → vector-DjhLUrak.d.ts} +2 -4
  107. package/dist/world-boundary-2d.d.ts +2 -2
  108. package/dist/world-boundary-2d.js +5 -4
  109. package/dist/world-boundary-3d.d.ts +2 -2
  110. package/dist/world-boundary-3d.js +4 -3
  111. package/package.json +2 -3
  112. package/dist/chunk-27UPCP5B.js.map +0 -1
  113. package/dist/chunk-4L36OPY2.js.map +0 -1
  114. package/dist/chunk-4URF65BR.js +0 -44
  115. package/dist/chunk-4URF65BR.js.map +0 -1
  116. package/dist/chunk-5XZWTFGF.js.map +0 -1
  117. package/dist/chunk-67XLJ26X.js +0 -536
  118. package/dist/chunk-67XLJ26X.js.map +0 -1
  119. package/dist/chunk-75FJIUIG.js +0 -240
  120. package/dist/chunk-75FJIUIG.js.map +0 -1
  121. package/dist/chunk-A4CA35DQ.js.map +0 -1
  122. package/dist/chunk-BXP4K7RF.js.map +0 -1
  123. package/dist/chunk-F72WX4MH.js +0 -422
  124. package/dist/chunk-F72WX4MH.js.map +0 -1
  125. package/dist/chunk-GFARAJV2.js.map +0 -1
  126. package/dist/chunk-JXMF4NUI.js +0 -309
  127. package/dist/chunk-JXMF4NUI.js.map +0 -1
  128. package/dist/chunk-OTLSUYQQ.js +0 -29
  129. package/dist/chunk-OTLSUYQQ.js.map +0 -1
  130. package/dist/chunk-Q75LKHDF.js +0 -56
  131. package/dist/chunk-Q75LKHDF.js.map +0 -1
  132. package/dist/chunk-QDCJLJUV.js.map +0 -1
  133. package/dist/chunk-RDHSHEZM.js +0 -479
  134. package/dist/chunk-RDHSHEZM.js.map +0 -1
  135. package/dist/chunk-UIG7MWS2.js +0 -518
  136. package/dist/chunk-UIG7MWS2.js.map +0 -1
  137. package/dist/chunk-UL6Q5HDP.js.map +0 -1
  138. package/dist/chunk-VMQHNJJI.js.map +0 -1
  139. package/dist/chunk-WWVD5DR5.js.map +0 -1
  140. package/dist/chunk-Z72F2ENM.js.map +0 -1
  141. package/dist/components-BWG1GkZA.d.ts +0 -20
  142. package/dist/use-behavior-B85d5u7-.d.ts +0 -13
  143. /package/dist/{chunk-5SM5SH5O.js.map → chunk-7JLWZXPA.js.map} +0 -0
  144. /package/dist/{chunk-ZA43LPRM.js.map → chunk-KIYUUSPK.js.map} +0 -0
  145. /package/dist/{chunk-XP3ASVGJ.js.map → chunk-NW4SE5XW.js.map} +0 -0
package/dist/core.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { L as VelocityIntentMode, T as TransformState } from './behavior-system-y8SGrGWy.js';
2
- export { B as BaseBehaviorHandle, a as BehaviorDescriptor, b as BehaviorEntityLink, c as BehaviorHandle, d as BehaviorRef, e as BehaviorSystem, f as BehaviorSystemContext, g as BehaviorSystemFactory, C as CreateEntityFn, D as DefineBehaviorConfig, G as GameEntity, h as GameEntityOptions, S as STAGE_INPUT_BUTTON_JUMP, i as STAGE_INPUT_BUTTON_RUN, j as StageBehaviorSnapshot, k as StageBodyKind, l as StageBoundaryDim, m as StageBoundaryDimValue, n as StageEventType, o as StageFirstPersonInput, p as StageFirstPersonOptions, q as StageJumper2DOptions, r as StageJumper3DOptions, s as StagePlatformer2DOptions, t as StagePlatformer3DOptions, u as StagePose, v as StageRicochetDim, w as StageRicochetDimValue, x as StageRicochetOptions, y as StageRicochetReflection, z as StageRicochetReflectionValue, A as StageScreenWrapOptions, E as StageShooter2DOptions, F as StageThrusterOptions, H as StageTopDownOptions, I as StageTopDownPlane, J as StageTopDownPlaneValue, K as StageWorldBoundaryOptions, V as VelocityIntent, W as WasmSnapshotBackref, M as WasmStageRuntime, N as WasmStageRuntimeOptions, O as createTransformStore, P as defineBehavior, Q as readBehaviorSnapshot } from './behavior-system-y8SGrGWy.js';
3
- export { u as useBehavior } from './use-behavior-B85d5u7-.js';
4
- export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent } from './components-BWG1GkZA.js';
5
- export { E as EntityWithBody, M as MoveableEntity, g as getPosition, a as getVelocity, m as makeMoveable, b as move, c as moveForwardXY, d as moveX, e as moveXY, f as moveXZ, h as moveY, i as moveZ, r as resetVelocity, s as setPosition, j as setPositionX, k as setPositionY, l as setPositionZ, w as wrapAround3D, n as wrapAroundXY } from './moveable-Cl9h-_w7.js';
6
- export { V as VEC2_ONE, a as VEC2_ZERO, b as VEC3_ONE, c as VEC3_ZERO, d as Vec2, e as Vec2Components, f as Vec2Input, g as Vec3, h as Vec3Components, i as Vec3Input, j as isVec2Input, k as isVec3Input, n as normalizeVec2, l as normalizeVec3, t as toRapierVector3, m as toThreeVector2, o as toThreeVector3 } from './vector-Bm65-FOG.js';
1
+ import { _ as VelocityIntentMode, Y as TransformState, e as BehaviorRuntime, I as StagePose, l as StageBehaviorSnapshot, T as StageThrusterOptions, U as StageTopDownOptions, R as StageShooter2DOptions, Q as StageScreenWrapOptions, r as StageBoundaryDimValue, X as StageWorldBoundaryOptions, M as StageRicochetDimValue, N as StageRicochetOptions, H as StagePlatformer3DOptions, F as StagePlatformer2DOptions, z as StageFirstPersonOptions, y as StageFirstPersonInput, A as StageJumper2DOptions, E as StageJumper3DOptions, a0 as WasmStageRuntime, a1 as WasmStageRuntimeOptions, p as StageBodyKindValue, t as StageColliderShape, K as StageRenderSlot, J as StageRaycastHit, n as StageBodyInfo, u as StageDebugRender } from './behavior-system-CeJXzNvr.js';
2
+ export { B as BaseBehaviorHandle, a as BehaviorDescriptor, b as BehaviorEntityLink, c as BehaviorHandle, d as BehaviorRef, f as BehaviorSystem, g as BehaviorSystemContext, h as BehaviorSystemFactory, C as CreateEntityFn, D as DefineBehaviorConfig, G as GameEntity, i as GameEntityOptions, S as STAGE_INPUT_BUTTON_JUMP, j as STAGE_INPUT_BUTTON_RUN, k as STAGE_INVALID_SLOT, m as StageBodyConfig, o as StageBodyKind, q as StageBoundaryDim, s as StageColliderConfig, v as StageEvent, w as StageEventType, x as StageEventTypeValue, L as StageRicochetDim, O as StageRicochetReflection, P as StageRicochetReflectionValue, V as StageTopDownPlane, W as StageTopDownPlaneValue, Z as VelocityIntent, $ as WasmSnapshotBackref, a2 as createTransformStore, a3 as createWasmStageRuntime, a4 as defineBehavior, a5 as readBehaviorSnapshot, a6 as readStageRenderSlot } from './behavior-system-CeJXzNvr.js';
3
+ export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent, u as useBehavior } from './components-BANNjAZP.js';
4
+ export { E as EntityWithBody, M as MoveableBodyLike, a as MoveableEntity, V as Vector, g as getPosition, b as getVelocity, m as makeMoveable, c as move, d as moveForwardXY, e as moveX, f as moveXY, h as moveXZ, i as moveY, j as moveZ, r as resetVelocity, s as setPosition, k as setPositionX, l as setPositionY, n as setPositionZ, w as wrapAround3D, o as wrapAroundXY } from './moveable-XhzWPAw5.js';
5
+ export { V as VEC2_ONE, a as VEC2_ZERO, b as VEC3_ONE, c as VEC3_ZERO, d as Vec2, e as Vec2Components, f as Vec2Input, g as Vec3, h as Vec3Components, i as Vec3Input, j as isVec2Input, k as isVec3Input, n as normalizeVec2, l as normalizeVec3, t as toThreeVector2, m as toThreeVector3 } from './vector-DjhLUrak.js';
7
6
  export { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
8
7
  export { F as FirstPersonPerspective } from './first-person-perspective-C9Mptl0-.js';
9
8
  export { ILogger, ITransition, SyncCallback, t } from 'typescript-fsm';
10
- import '@dimforge/rapier3d-compat';
9
+ export { STAGE_EVENT_STRIDE, STAGE_INPUT_STRIDE, STAGE_RENDER_STRIDE, STAGE_SNAPSHOT_STRIDE, StageWasmExports } from '@zylem/runtime';
11
10
  import 'three';
12
11
 
13
12
  interface VelocityIntentOptions {
@@ -22,4 +21,285 @@ interface VelocityIntentVector {
22
21
  declare function setVelocityIntent(store: TransformState, sourceId: string, vector: VelocityIntentVector, options?: VelocityIntentOptions): void;
23
22
  declare function clearVelocityIntent(store: TransformState, sourceId: string): void;
24
23
 
25
- export { TransformState, VelocityIntentMode, type VelocityIntentOptions, type VelocityIntentVector, clearVelocityIntent, setVelocityIntent };
24
+ /**
25
+ * In-memory implementation of the {@link BehaviorRuntime} contract for unit
26
+ * tests. Records every attach / input call per handle and lets tests seed
27
+ * poses and behavior snapshots without instantiating the wasm runtime.
28
+ */
29
+
30
+ interface MockSlotState {
31
+ pose: StagePose;
32
+ snapshot: StageBehaviorSnapshot | null;
33
+ input: {
34
+ axisA: number;
35
+ axisB: number;
36
+ yawDelta: number;
37
+ pitchDelta: number;
38
+ reservedA: number;
39
+ reservedB: number;
40
+ buttons: number;
41
+ };
42
+ attachments: Map<string, unknown>;
43
+ inputs: Array<{
44
+ kind: string;
45
+ args: unknown[];
46
+ }>;
47
+ screenWrapQuery: {
48
+ fsm: number;
49
+ lastWrappedAxes: number;
50
+ } | null;
51
+ worldBoundaryQuery: {
52
+ hits: number;
53
+ clamped: [number, number, number];
54
+ } | null;
55
+ }
56
+ declare class MockBehaviorRuntime implements BehaviorRuntime {
57
+ private slots;
58
+ private slot;
59
+ /** Seed the pose returned by {@link getPose} for a handle. */
60
+ setPose(handle: number, pose: StagePose): void;
61
+ /** Seed the snapshot returned by {@link readSnapshot} for a handle. */
62
+ setSnapshot(handle: number, snapshot: StageBehaviorSnapshot | null): void;
63
+ /** Seed {@link queryScreenWrap} results. */
64
+ setScreenWrapQuery(handle: number, value: {
65
+ fsm: number;
66
+ lastWrappedAxes: number;
67
+ } | null): void;
68
+ /** Seed {@link queryWorldBoundary} results. */
69
+ setWorldBoundaryQuery(handle: number, value: {
70
+ hits: number;
71
+ clamped: [number, number, number];
72
+ } | null): void;
73
+ /** Attachment options recorded for a handle, keyed by behavior name. */
74
+ getAttachment<T>(handle: number, kind: string): T | undefined;
75
+ hasAttachment(handle: number, kind: string): boolean;
76
+ /** Every per-entity input call recorded for a handle, oldest first. */
77
+ getInputCalls(handle: number): Array<{
78
+ kind: string;
79
+ args: unknown[];
80
+ }>;
81
+ /** Last written batched-input state for a handle. */
82
+ getBatchedInput(handle: number): MockSlotState['input'];
83
+ reset(): void;
84
+ setPosition(handle: number, x: number, y: number, z: number): boolean;
85
+ setRotation(handle: number, x: number, y: number, z: number, w: number): boolean;
86
+ getPose(handle: number, out?: StagePose): StagePose | null;
87
+ writeInputAxes(handle: number, axisA: number, axisB: number): boolean;
88
+ writeInputLook(handle: number, yawDelta: number, pitchDelta: number): boolean;
89
+ writeInputReserved(handle: number, reservedA: number, reservedB: number): boolean;
90
+ writeInputButton(handle: number, buttonMask: number, pressed: boolean): boolean;
91
+ readSnapshot(handle: number, out?: StageBehaviorSnapshot): StageBehaviorSnapshot | null;
92
+ attachThruster(handle: number, opts: StageThrusterOptions): boolean;
93
+ setThrusterInput(handle: number, thrust: number, rotate: number, vectorX?: number, vectorY?: number): void;
94
+ attachTopDown(handle: number, opts: StageTopDownOptions): boolean;
95
+ setTopDownInput(handle: number, moveX: number, moveY: number): void;
96
+ attachShooter2D(handle: number, opts: StageShooter2DOptions): boolean;
97
+ attachScreenWrap(handle: number, opts: StageScreenWrapOptions): boolean;
98
+ queryScreenWrap(handle: number): {
99
+ fsm: number;
100
+ lastWrappedAxes: number;
101
+ } | null;
102
+ attachWorldBoundary(handle: number, dim: StageBoundaryDimValue, opts: StageWorldBoundaryOptions): boolean;
103
+ queryWorldBoundary(handle: number): {
104
+ hits: number;
105
+ clamped: [number, number, number];
106
+ } | null;
107
+ attachRicochet(handle: number, dim: StageRicochetDimValue, opts: StageRicochetOptions): boolean;
108
+ attachPlatformer3D(handle: number, opts: StagePlatformer3DOptions): boolean;
109
+ setPlatformer3DInputAxes(handle: number, moveX: number, moveZ: number): void;
110
+ setPlatformer3DInputButtons(handle: number, jump: boolean, run: boolean): void;
111
+ attachPlatformer2D(handle: number, opts: StagePlatformer2DOptions): boolean;
112
+ setPlatformer2DInputAxes(handle: number, moveX: number): void;
113
+ setPlatformer2DInputButtons(handle: number, jump: boolean, run: boolean): void;
114
+ attachFirstPerson(handle: number, opts: StageFirstPersonOptions): boolean;
115
+ setFirstPersonInput(handle: number, input: StageFirstPersonInput): void;
116
+ attachJumper2D(handle: number, opts: StageJumper2DOptions): boolean;
117
+ setJumper2DInput(handle: number, jumpPressed: boolean): void;
118
+ attachJumper3D(handle: number, opts: StageJumper3DOptions): boolean;
119
+ setJumper3DInput(handle: number, jumpPressed: boolean): void;
120
+ }
121
+
122
+ /**
123
+ * `Simulation` (a.k.a. `BehaviorWorld`) — the primary public abstraction of
124
+ * `@zylem/behaviors`. It owns the wasm runtime lifecycle (one
125
+ * `WebAssembly.Instance` of `@zylem/runtime` per simulation), the fixed
126
+ * timestep accumulator, an entity registry mapping opaque
127
+ * {@link EntityHandle}s to runtime slots, and per-step event translation
128
+ * from raw stage events into typed {@link SimulationEvent}s.
129
+ *
130
+ * Hosts (e.g. `@zylem/game-lib`) call {@link createSimulation} once per
131
+ * stage, `spawn()`/`despawn()` entities, call `update(delta)` once per
132
+ * render frame, and read poses for rendering from the returned
133
+ * {@link SimulationFrame}.
134
+ */
135
+
136
+ /**
137
+ * Opaque, stable identifier for a simulation entity. `slot` is the raw
138
+ * runtime slot index — treat it as an implementation detail owned by the
139
+ * Simulation (it is only exposed so hosts can wire behavior systems, which
140
+ * address the batched buffers by slot).
141
+ */
142
+ interface EntityHandle {
143
+ /** Monotonic public id, never reused within a Simulation. */
144
+ readonly id: number;
145
+ /** Raw runtime slot index. Internal — may be reused after despawn. */
146
+ readonly slot: number;
147
+ }
148
+ /** Partial body description; unspecified fields use sensible defaults. */
149
+ interface SimulationBodyDefinition {
150
+ kind?: StageBodyKindValue;
151
+ position?: readonly [number, number, number];
152
+ rotation?: readonly [number, number, number, number];
153
+ linearDamping?: number;
154
+ angularDamping?: number;
155
+ gravityScale?: number;
156
+ canSleep?: boolean;
157
+ ccdEnabled?: boolean;
158
+ lockRotation?: readonly [boolean, boolean, boolean];
159
+ lockTranslation?: readonly [boolean, boolean, boolean];
160
+ }
161
+ /** Partial collider description; unspecified fields use sensible defaults. */
162
+ interface SimulationColliderDefinition {
163
+ shape: StageColliderShape;
164
+ offset?: readonly [number, number, number];
165
+ friction?: number;
166
+ restitution?: number;
167
+ sensor?: boolean;
168
+ collisionGroups?: number;
169
+ }
170
+ /** Everything needed to materialize one entity inside the runtime. */
171
+ interface EntityDefinition {
172
+ body?: SimulationBodyDefinition;
173
+ colliders?: SimulationColliderDefinition[];
174
+ }
175
+ /** Typed, handle-resolved simulation event. */
176
+ type SimulationEvent = {
177
+ type: 'collisionStarted' | 'collisionStopped';
178
+ a: EntityHandle | null;
179
+ b: EntityHandle | null;
180
+ /** True when either collider in the pair is a sensor (zone overlap). */
181
+ sensor: boolean;
182
+ /** Best-effort contact normal (x, y); zero for sensor pairs / stops. */
183
+ normal: [number, number];
184
+ } | {
185
+ type: 'boundaryHit';
186
+ entity: EntityHandle | null;
187
+ axes: number;
188
+ signs: number;
189
+ } | {
190
+ type: 'ricochet';
191
+ entity: EntityHandle | null;
192
+ kind: number;
193
+ } | {
194
+ type: 'regionEntered';
195
+ entity: EntityHandle | null;
196
+ triggerId: number;
197
+ } | {
198
+ type: 'jumpStarted';
199
+ entity: EntityHandle | null;
200
+ jumpCount: number;
201
+ } | {
202
+ type: 'landed';
203
+ entity: EntityHandle | null;
204
+ } | {
205
+ type: 'wrapped';
206
+ entity: EntityHandle | null;
207
+ axes: number;
208
+ } | {
209
+ type: 'cooldownFired';
210
+ entity: EntityHandle | null;
211
+ cooldownId: number;
212
+ };
213
+ /**
214
+ * Snapshot of one `update()` call: how many fixed steps ran, the live render
215
+ * buffer view, the previous-step render copy + interpolation alpha for
216
+ * smooth rendering, and the translated events from every step taken.
217
+ */
218
+ interface SimulationFrame {
219
+ /** Wall-clock delta handed to `update()`. */
220
+ deltaTime: number;
221
+ /** Number of fixed steps executed (0 when accumulating). */
222
+ stepsTaken: number;
223
+ /** Interpolation alpha in [0, 1): fraction of a fixed step accumulated. */
224
+ alpha: number;
225
+ /** Live render buffer (post-step poses), {@link STAGE_RENDER_STRIDE} floats per slot. */
226
+ render: Float32Array;
227
+ /** Copy of the render buffer as of the step before the last one. */
228
+ previousRender: Float32Array;
229
+ renderStride: number;
230
+ /** Typed events from all steps taken this update, oldest first. */
231
+ events: SimulationEvent[];
232
+ }
233
+ interface SimulationOptions extends WasmStageRuntimeOptions {
234
+ /** Fixed physics timestep in seconds (default 1/60). */
235
+ fixedTimestep?: number;
236
+ /** Max fixed steps per `update()` to avoid death spirals (default 4). */
237
+ maxSubSteps?: number;
238
+ }
239
+ /**
240
+ * The behavior world. Construct via {@link createSimulation}.
241
+ */
242
+ declare class Simulation {
243
+ /**
244
+ * The low-level wasm adapter. Behavior systems receive this as their
245
+ * `wasmStage` context so descriptors can attach/query behaviors by slot;
246
+ * hosts should prefer the handle-based methods on the Simulation itself.
247
+ */
248
+ readonly adapter: WasmStageRuntime;
249
+ readonly fixedTimestep: number;
250
+ private readonly maxSubSteps;
251
+ private accumulator;
252
+ private nextEntityId;
253
+ private slotToHandle;
254
+ private idToHandle;
255
+ private previousRender;
256
+ private disposed;
257
+ constructor(adapter: WasmStageRuntime, options?: SimulationOptions);
258
+ /**
259
+ * Create a runtime entity from a plain definition. Returns `null` when
260
+ * the runtime rejects the allocation.
261
+ */
262
+ spawn(definition?: EntityDefinition): EntityHandle | null;
263
+ despawn(handle: EntityHandle): boolean;
264
+ /** Resolve a raw runtime slot back to its public handle, if alive. */
265
+ handleForSlot(slot: number): EntityHandle | null;
266
+ get entityCount(): number;
267
+ /**
268
+ * Advance the simulation by `deltaTime` seconds using a fixed-timestep
269
+ * accumulator. Runs zero or more fixed steps and returns a
270
+ * {@link SimulationFrame} with translated events and interpolation data.
271
+ */
272
+ update(deltaTime: number): SimulationFrame;
273
+ private capturePreviousRender;
274
+ private translateEvents;
275
+ getPose(handle: EntityHandle, out?: StagePose): StagePose | null;
276
+ setPosition(handle: EntityHandle, x: number, y: number, z: number): boolean;
277
+ setRotation(handle: EntityHandle, x: number, y: number, z: number, w: number): boolean;
278
+ setLinearVelocity(handle: EntityHandle, x: number, y: number, z: number): boolean;
279
+ getLinearVelocity(handle: EntityHandle): [number, number, number] | null;
280
+ setAngularVelocity(handle: EntityHandle, x: number, y: number, z: number): boolean;
281
+ applyImpulse(handle: EntityHandle, x: number, y: number, z: number): boolean;
282
+ readRenderSlot(handle: EntityHandle, out?: StageRenderSlot): StageRenderSlot | null;
283
+ /** Decode a handle's pose from the previous-step render copy. */
284
+ readPreviousRenderSlot(handle: EntityHandle, out?: StageRenderSlot): StageRenderSlot | null;
285
+ readSnapshot(handle: EntityHandle, out?: StageBehaviorSnapshot): StageBehaviorSnapshot | null;
286
+ setGravity(x: number, y: number, z: number): void;
287
+ /** Physics raycast; the hit's slot is resolved to an entity handle. */
288
+ castRay(origin: readonly [number, number, number], dir: readonly [number, number, number], maxDistance: number, solidOnly?: boolean): (Omit<StageRaycastHit, 'slot'> & {
289
+ entity: EntityHandle | null;
290
+ }) | null;
291
+ getBodyInfo(handle: EntityHandle): StageBodyInfo | null;
292
+ getDebugRender(): StageDebugRender | null;
293
+ get isDisposed(): boolean;
294
+ /** Destroy the wasm stage. The Simulation must not be used afterwards. */
295
+ dispose(): void;
296
+ }
297
+ /** Alias matching the architecture doc's naming. */
298
+ type BehaviorWorld = Simulation;
299
+ /**
300
+ * Load and instantiate the `@zylem/runtime` wasm module and wrap it in a
301
+ * {@link Simulation}. One call per logical stage/world.
302
+ */
303
+ declare function createSimulation(options?: SimulationOptions): Promise<Simulation>;
304
+
305
+ export { BehaviorRuntime, type BehaviorWorld, type EntityDefinition, type EntityHandle, MockBehaviorRuntime, Simulation, type SimulationBodyDefinition, type SimulationColliderDefinition, type SimulationEvent, type SimulationFrame, type SimulationOptions, StageBehaviorSnapshot, StageBodyInfo, StageBodyKindValue, StageBoundaryDimValue, StageColliderShape, StageDebugRender, StageFirstPersonInput, StageFirstPersonOptions, StageJumper2DOptions, StageJumper3DOptions, StagePlatformer2DOptions, StagePlatformer3DOptions, StagePose, StageRaycastHit, StageRenderSlot, StageRicochetDimValue, StageRicochetOptions, StageScreenWrapOptions, StageShooter2DOptions, StageThrusterOptions, StageTopDownOptions, StageWorldBoundaryOptions, TransformState, VelocityIntentMode, type VelocityIntentOptions, type VelocityIntentVector, WasmStageRuntime, WasmStageRuntimeOptions, clearVelocityIntent, createSimulation, setVelocityIntent };