@zylem/behaviors 0.8.9 → 0.8.11
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/dist/acrobatics-2d.d.ts +25 -0
- package/dist/acrobatics-2d.js +37 -0
- package/dist/action-rpg.d.ts +21 -0
- package/dist/action-rpg.js +39 -0
- package/dist/adventure-tools.d.ts +22 -0
- package/dist/adventure-tools.js +39 -0
- package/dist/behavior-descriptor-NS_qnzzp.d.ts +4527 -0
- package/dist/behavior-metadata-Drm1zxI2.d.ts +13 -0
- package/dist/catalog.d.ts +2143 -0
- package/dist/catalog.js +9 -0
- package/dist/chunk-2BE5BW7D.js +130 -0
- package/dist/{chunk-CTSYM56P.js → chunk-2QCCLHJC.js} +10 -6
- package/dist/chunk-2UGT4MIF.js +94 -0
- package/dist/chunk-3J3ISPFQ.js +99 -0
- package/dist/chunk-3LBGEWT6.js +124 -0
- package/dist/{chunk-UUMH3DC3.js → chunk-3QBNWT7B.js} +5 -1
- package/dist/chunk-3T44EDXU.js +114 -0
- package/dist/chunk-5AJJ44QK.js +129 -0
- package/dist/{chunk-YDLO5M7S.js → chunk-5SMXQ6AU.js} +1 -0
- package/dist/chunk-5VJIP535.js +71 -0
- package/dist/chunk-6DTIJB7B.js +166 -0
- package/dist/chunk-73MHJY6R.js +78 -0
- package/dist/chunk-73YASAYS.js +137 -0
- package/dist/{chunk-LLDLVVG4.js → chunk-7HGDADLB.js} +25 -9
- package/dist/chunk-7IOQEXYR.js +92 -0
- package/dist/{chunk-OU2SW4U5.js → chunk-APAM55J3.js} +10 -6
- package/dist/chunk-BLTBZJPG.js +126 -0
- package/dist/chunk-BN6QZDR5.js +90 -0
- package/dist/chunk-BR33KT4Z.js +3186 -0
- package/dist/chunk-C5AYL42A.js +138 -0
- package/dist/{chunk-OBF6BIA2.js → chunk-CBQSC6W3.js} +2 -2
- package/dist/chunk-DDLZLJ7W.js +8 -0
- package/dist/chunk-DRIXFB4C.js +132 -0
- package/dist/{chunk-7CE6OHLW.js → chunk-DTLUKSX2.js} +6 -2
- package/dist/{chunk-TK3AXXXI.js → chunk-EMEA45JQ.js} +10 -6
- package/dist/chunk-EQFLPRF7.js +130 -0
- package/dist/{chunk-M25QJBDN.js → chunk-GNRMH7D3.js} +18 -6
- package/dist/chunk-GYEKT5AY.js +102 -0
- package/dist/{chunk-SHZZ2QRV.js → chunk-HCWLIPXP.js} +5 -1
- package/dist/{chunk-WHKPWIQO.js → chunk-HMVEQB2T.js} +1 -0
- package/dist/chunk-HQ2UFI3S.js +116 -0
- package/dist/chunk-I52PC5IU.js +128 -0
- package/dist/{chunk-CB3C7CRD.js → chunk-IAIJG2PB.js} +10 -6
- package/dist/{chunk-NDJO56BB.js → chunk-IJILTFEL.js} +5 -1
- package/dist/{chunk-7GGR26YA.js → chunk-IRNU4JGV.js} +10 -6
- package/dist/chunk-IRPBFVAK.js +141 -0
- package/dist/chunk-JFBR4FNX.js +140 -0
- package/dist/{chunk-ERS6SNA5.js → chunk-K34N2CBL.js} +5 -1
- package/dist/chunk-LMMF7KXF.js +178 -0
- package/dist/chunk-LWGJ3QQZ.js +107 -0
- package/dist/chunk-MPNGQLHZ.js +132 -0
- package/dist/chunk-OH5LJAEJ.js +135 -0
- package/dist/{chunk-57GLKGEX.js → chunk-P6TMZSWF.js} +32 -7
- package/dist/chunk-PDHHOVVQ.js +126 -0
- package/dist/{chunk-7TIIRJKF.js → chunk-RUBKGAPS.js} +5 -1
- package/dist/chunk-S44ZHYE6.js +1912 -0
- package/dist/chunk-SFMJNAW3.js +128 -0
- package/dist/{chunk-E2MOFIDH.js → chunk-SKKVOH6D.js} +13 -7
- package/dist/{chunk-RR3XNDKG.js → chunk-T2LAQQDS.js} +1 -1
- package/dist/chunk-TSYXRRS4.js +125 -0
- package/dist/chunk-TZHO6P22.js +150 -0
- package/dist/chunk-V26L6MY6.js +127 -0
- package/dist/chunk-V4M46BF6.js +105 -0
- package/dist/chunk-VSFWETXS.js +127 -0
- package/dist/chunk-VU4LTE2X.js +147 -0
- package/dist/chunk-WF6HC5U3.js +8 -0
- package/dist/chunk-WG5NCDS4.js +99 -0
- package/dist/{chunk-7LHXAEOZ.js → chunk-WUYHS6JZ.js} +6 -2
- package/dist/chunk-XNRY6NOC.js +120 -0
- package/dist/{chunk-55CFXXZH.js → chunk-XT47QZQ6.js} +32 -7
- package/dist/chunk-Y5CCNMJI.js +58 -0
- package/dist/chunk-YVVB6YMG.js +133 -0
- package/dist/chunk-ZZXTGVGN.js +131 -0
- package/dist/combat-ai.d.ts +21 -0
- package/dist/combat-ai.js +41 -0
- package/dist/{components--RTwuT4S.d.ts → components-ClmBORMP.d.ts} +1 -1
- package/dist/cooldown.d.ts +2 -8
- package/dist/cooldown.js +3 -2
- package/dist/coordinators/boundary-ricochet-3d.d.ts +3 -2
- package/dist/coordinators/boundary-ricochet-3d.js +2 -2
- package/dist/coordinators/boundary-ricochet.d.ts +3 -2
- package/dist/coordinators/boundary-ricochet.js +2 -2
- package/dist/coordinators/multidirectional-space-shooter.d.ts +3 -2
- package/dist/coordinators/multidirectional-space-shooter.js +2 -2
- package/dist/coordinators/top-down-shooter.d.ts +3 -2
- package/dist/coordinators/top-down-shooter.js +2 -2
- package/dist/core.d.ts +387 -26
- package/dist/core.js +1583 -6
- package/dist/destructible-3d.d.ts +3 -2
- package/dist/destructible-3d.js +3 -2
- package/dist/destructible-prebake.d.ts +1 -1
- package/dist/environmental-locomotion.d.ts +23 -0
- package/dist/environmental-locomotion.js +35 -0
- package/dist/first-person.d.ts +3 -2
- package/dist/first-person.js +25 -4
- package/dist/golf-racket.d.ts +21 -0
- package/dist/golf-racket.js +37 -0
- package/dist/index.d.ts +28 -6
- package/dist/index.js +766 -82
- package/dist/jumper-2d.d.ts +2 -1
- package/dist/jumper-2d.js +25 -4
- package/dist/jumper-3d.d.ts +2 -1
- package/dist/jumper-3d.js +25 -4
- package/dist/lane-defense.d.ts +21 -0
- package/dist/lane-defense.js +39 -0
- package/dist/life-simulation.d.ts +21 -0
- package/dist/life-simulation.js +39 -0
- package/dist/matching-pinball.d.ts +21 -0
- package/dist/matching-pinball.js +39 -0
- package/dist/melee-combat.d.ts +22 -0
- package/dist/melee-combat.js +45 -0
- package/dist/{moveable-CFOHmblC.d.ts → moveable-CXK2wEZL.d.ts} +2 -2
- package/dist/particle-emitter/presets.d.ts +1 -1
- package/dist/particle-emitter.d.ts +5 -4
- package/dist/particle-emitter.js +3 -2
- package/dist/{payload-BQzu-oY_.d.ts → payload-WEzfgjSL.d.ts} +1 -1
- package/dist/platformer-2d.d.ts +2 -1
- package/dist/platformer-2d.js +25 -4
- package/dist/platformer-3d.d.ts +2 -1
- package/dist/platformer-3d.js +25 -4
- package/dist/racing-vehicles.d.ts +21 -0
- package/dist/racing-vehicles.js +37 -0
- package/dist/rhythm-performance.d.ts +21 -0
- package/dist/rhythm-performance.js +39 -0
- package/dist/ricochet-2d.d.ts +2 -1
- package/dist/ricochet-2d.js +25 -4
- package/dist/ricochet-3d.d.ts +2 -1
- package/dist/ricochet-3d.js +25 -4
- package/dist/runtime-2d.d.ts +2 -1
- package/dist/runtime-2d.js +10 -1
- package/dist/screen-visibility.d.ts +2 -1
- package/dist/screen-visibility.js +3 -2
- package/dist/screen-wrap.d.ts +2 -7
- package/dist/screen-wrap.js +4 -3
- package/dist/shooter-2d.d.ts +3 -2
- package/dist/shooter-2d.js +3 -2
- package/dist/skate-snowboard.d.ts +21 -0
- package/dist/skate-snowboard.js +37 -0
- package/dist/{spark-C4Tp-52_.d.ts → spark-VoQoemz_.d.ts} +1 -1
- package/dist/spatial-puzzles.d.ts +21 -0
- package/dist/spatial-puzzles.js +35 -0
- package/dist/squad-rts.d.ts +21 -0
- package/dist/squad-rts.js +39 -0
- package/dist/stealth-city.d.ts +21 -0
- package/dist/stealth-city.js +41 -0
- package/dist/survival-resources.d.ts +21 -0
- package/dist/survival-resources.js +37 -0
- package/dist/tactical-grid.d.ts +21 -0
- package/dist/tactical-grid.js +39 -0
- package/dist/thruster.d.ts +2 -1
- package/dist/thruster.js +4 -3
- package/dist/top-down-movement.d.ts +2 -1
- package/dist/top-down-movement.js +24 -3
- package/dist/turn-based-rpg.d.ts +21 -0
- package/dist/turn-based-rpg.js +39 -0
- package/dist/{vector-DjhLUrak.d.ts → vector-s7GbCrVn.d.ts} +1 -1
- package/dist/weapon-systems.d.ts +22 -0
- package/dist/weapon-systems.js +45 -0
- package/dist/world-boundary-2d.d.ts +2 -1
- package/dist/world-boundary-2d.js +25 -4
- package/dist/world-boundary-3d.d.ts +2 -1
- package/dist/world-boundary-3d.js +26 -5
- package/package.json +90 -5
- package/dist/behavior-system-DkFAwLb_.d.ts +0 -914
- package/dist/chunk-GZ3DQIIZ.js +0 -888
- package/dist/{chunk-OSPQFWQF.js → chunk-4K37UL53.js} +3 -3
- package/dist/{chunk-DD4U42FG.js → chunk-AQB246W5.js} +3 -3
- package/dist/{chunk-UKGBQTHL.js → chunk-CXDNR4R4.js} +3 -3
|
@@ -1,914 +0,0 @@
|
|
|
1
|
-
import { StageWasmExports } from '@zylem/runtime';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* BehaviorDescriptor
|
|
5
|
-
*
|
|
6
|
-
* Type-safe behavior descriptors that provide options inference.
|
|
7
|
-
* Used with entity.use() to declaratively attach behaviors to entities.
|
|
8
|
-
*
|
|
9
|
-
* Each behavior can define its own handle type via `createHandle`,
|
|
10
|
-
* providing behavior-specific methods with full type safety.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Base handle returned by entity.use() for lazy access to behavior runtime.
|
|
15
|
-
* FSM is null until entity is spawned and components are initialized.
|
|
16
|
-
*/
|
|
17
|
-
interface BaseBehaviorHandle<O extends Record<string, any> = Record<string, any>> {
|
|
18
|
-
/** Get the FSM instance (null until entity is spawned) */
|
|
19
|
-
getFSM(): any | null;
|
|
20
|
-
/** Get the current options */
|
|
21
|
-
getOptions(): O;
|
|
22
|
-
/** Access the underlying behavior ref */
|
|
23
|
-
readonly ref: BehaviorRef<O>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Reference to a behavior stored on an entity
|
|
27
|
-
*/
|
|
28
|
-
interface BehaviorRef<O extends Record<string, any> = Record<string, any>> {
|
|
29
|
-
/** The behavior descriptor */
|
|
30
|
-
descriptor: BehaviorDescriptor<O, any>;
|
|
31
|
-
/** Merged options (defaults + overrides) */
|
|
32
|
-
options: O;
|
|
33
|
-
/** Optional FSM instance - set lazily when entity is spawned */
|
|
34
|
-
fsm?: any;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A typed behavior descriptor that associates a symbol key with:
|
|
38
|
-
* - Default options (providing type inference)
|
|
39
|
-
* - A system factory to create the behavior system
|
|
40
|
-
* - An optional handle factory for behavior-specific methods
|
|
41
|
-
*/
|
|
42
|
-
interface BehaviorDescriptor<O extends Record<string, any> = Record<string, any>, H extends Record<string, any> = Record<string, never>, I = unknown> {
|
|
43
|
-
/** Unique symbol identifying this behavior */
|
|
44
|
-
readonly key: symbol;
|
|
45
|
-
/** Default options (used for type inference) */
|
|
46
|
-
readonly defaultOptions: O;
|
|
47
|
-
/** Factory to create the behavior system */
|
|
48
|
-
readonly systemFactory: any;
|
|
49
|
-
/**
|
|
50
|
-
* Optional factory to create behavior-specific handle methods.
|
|
51
|
-
* These methods are merged into the handle returned by entity.use().
|
|
52
|
-
*/
|
|
53
|
-
readonly createHandle?: (ref: any) => H;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* The full handle type returned by entity.use().
|
|
57
|
-
* Combines base handle with behavior-specific methods.
|
|
58
|
-
*/
|
|
59
|
-
type BehaviorHandle<O extends Record<string, any> = Record<string, any>, H extends Record<string, any> = Record<string, never>> = BaseBehaviorHandle<O> & H;
|
|
60
|
-
/**
|
|
61
|
-
* Configuration for defining a new behavior
|
|
62
|
-
*/
|
|
63
|
-
interface DefineBehaviorConfig<O extends Record<string, any>, H extends Record<string, any> = Record<string, never>, I = unknown> {
|
|
64
|
-
/** Human-readable name for debugging */
|
|
65
|
-
name: string;
|
|
66
|
-
/** Default options - these define the type */
|
|
67
|
-
defaultOptions: O;
|
|
68
|
-
/** Factory function to create the system */
|
|
69
|
-
systemFactory: BehaviorSystemFactory;
|
|
70
|
-
/**
|
|
71
|
-
* Optional factory to create behavior-specific handle methods.
|
|
72
|
-
* The returned object is merged into the handle returned by entity.use().
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* createHandle: (ref) => ({
|
|
77
|
-
* getLastHits: () => ref.fsm?.getLastHits() ?? null,
|
|
78
|
-
* getMovement: (moveX, moveY) => ref.fsm?.getMovement(moveX, moveY) ?? { moveX, moveY },
|
|
79
|
-
* }),
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
createHandle?: (ref: BehaviorRef<O>) => H;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Define a typed behavior descriptor.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* export const WorldBoundary2DBehavior = defineBehavior({
|
|
90
|
-
* name: 'world-boundary-2d',
|
|
91
|
-
* defaultOptions: { boundaries: { top: 0, bottom: 0, left: 0, right: 0 } },
|
|
92
|
-
* systemFactory: (ctx) => new WorldBoundary2DSystem(ctx.world),
|
|
93
|
-
* createHandle: (ref) => ({
|
|
94
|
-
* getLastHits: () => ref.fsm?.getLastHits() ?? null,
|
|
95
|
-
* getMovement: (moveX: number, moveY: number) =>
|
|
96
|
-
* ref.fsm?.getMovement(moveX, moveY) ?? { moveX, moveY },
|
|
97
|
-
* }),
|
|
98
|
-
* });
|
|
99
|
-
*
|
|
100
|
-
* // Usage - handle has getLastHits and getMovement with full types
|
|
101
|
-
* const boundary = ship.use(WorldBoundary2DBehavior, { ... });
|
|
102
|
-
* const hits = boundary.getLastHits(); // Fully typed!
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
declare function defineBehavior<O extends Record<string, any>, H extends Record<string, any> = Record<string, never>, I = unknown>(config: DefineBehaviorConfig<O, H, I>): BehaviorDescriptor<O, H, I>;
|
|
106
|
-
|
|
107
|
-
type VelocityIntentMode = 'replace' | 'add';
|
|
108
|
-
interface VelocityIntent {
|
|
109
|
-
x?: number;
|
|
110
|
-
y?: number;
|
|
111
|
-
z?: number;
|
|
112
|
-
mode: VelocityIntentMode;
|
|
113
|
-
priority?: number;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Transform state managed by Valtio for per-frame physics intent accumulation.
|
|
117
|
-
*
|
|
118
|
-
* This store accumulates transformation intents during the frame,
|
|
119
|
-
* then applies them all at once after onUpdate() callbacks complete.
|
|
120
|
-
*
|
|
121
|
-
* Design decisions:
|
|
122
|
-
* - Position: Accumulated deltas (additive)
|
|
123
|
-
* - Rotation: Last value wins (replacement)
|
|
124
|
-
* - Velocity: Accumulated deltas (additive)
|
|
125
|
-
* - Angular velocity: Accumulated deltas (additive)
|
|
126
|
-
*/
|
|
127
|
-
interface TransformState {
|
|
128
|
-
/** Position deltas to be applied (accumulated) */
|
|
129
|
-
position: {
|
|
130
|
-
x: number;
|
|
131
|
-
y: number;
|
|
132
|
-
z: number;
|
|
133
|
-
};
|
|
134
|
-
/** Rotation quaternion (last value wins) */
|
|
135
|
-
rotation: {
|
|
136
|
-
x: number;
|
|
137
|
-
y: number;
|
|
138
|
-
z: number;
|
|
139
|
-
w: number;
|
|
140
|
-
};
|
|
141
|
-
/** Linear velocity (accumulated) */
|
|
142
|
-
velocity: {
|
|
143
|
-
x: number;
|
|
144
|
-
y: number;
|
|
145
|
-
z: number;
|
|
146
|
-
};
|
|
147
|
-
/** Angular velocity (accumulated) */
|
|
148
|
-
angularVelocity: {
|
|
149
|
-
x: number;
|
|
150
|
-
y: number;
|
|
151
|
-
z: number;
|
|
152
|
-
};
|
|
153
|
-
/** Per-source velocity intents composed once per frame */
|
|
154
|
-
velocityChannels: Record<string, VelocityIntent>;
|
|
155
|
-
/** Dirty flags to track what needs to be applied */
|
|
156
|
-
dirty: {
|
|
157
|
-
position: boolean;
|
|
158
|
-
rotation: boolean;
|
|
159
|
-
velocityX: boolean;
|
|
160
|
-
velocityY: boolean;
|
|
161
|
-
velocityZ: boolean;
|
|
162
|
-
velocityChannels: boolean;
|
|
163
|
-
angularVelocity: boolean;
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Create a new transform store with optional initial values.
|
|
168
|
-
* The store is a Valtio proxy, making it reactive for debugging/visualization.
|
|
169
|
-
*
|
|
170
|
-
* @param initial Optional initial state values
|
|
171
|
-
* @returns Reactive transform state
|
|
172
|
-
*/
|
|
173
|
-
declare function createTransformStore(initial?: Partial<TransformState>): TransformState;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Minimal, runtime-agnostic entity options contract.
|
|
177
|
-
*
|
|
178
|
-
* The full engine entity (in `@zylem/game-lib`) provides a richer options type,
|
|
179
|
-
* but behaviors only rely on this loose shape.
|
|
180
|
-
*/
|
|
181
|
-
interface GameEntityOptions {
|
|
182
|
-
[key: string]: any;
|
|
183
|
-
name?: string;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Structural stand-in for the engine `GameEntity`.
|
|
187
|
-
*
|
|
188
|
-
* Behaviors annotate against this loose contract so that `@zylem/behaviors`
|
|
189
|
-
* (and its `@zylem/behaviors/core` surface) never has to depend on the concrete
|
|
190
|
-
* `@zylem/game-lib` entity implementation. The real engine entity is
|
|
191
|
-
* structurally assignable to this type.
|
|
192
|
-
*/
|
|
193
|
-
declare class GameEntity<TOptions = unknown> {
|
|
194
|
-
[key: string]: any;
|
|
195
|
-
uuid: string;
|
|
196
|
-
name: string;
|
|
197
|
-
type: string;
|
|
198
|
-
options?: TOptions & Record<string, unknown>;
|
|
199
|
-
group: any;
|
|
200
|
-
mesh?: any;
|
|
201
|
-
materials?: any[];
|
|
202
|
-
/** Opaque host-owned physics references (never inspected by behaviors). */
|
|
203
|
-
body: unknown | null;
|
|
204
|
-
collider: unknown | null;
|
|
205
|
-
colliderDesc?: any;
|
|
206
|
-
colliderDescs: any[];
|
|
207
|
-
bodyDesc?: any;
|
|
208
|
-
physicsAttached: boolean;
|
|
209
|
-
runtimeHandle?: number;
|
|
210
|
-
transformStore?: TransformState;
|
|
211
|
-
nodeDestroy?: any;
|
|
212
|
-
isInstanced?: boolean;
|
|
213
|
-
private __behaviorRefs;
|
|
214
|
-
create(): this;
|
|
215
|
-
onCleanup(callback: () => void): this;
|
|
216
|
-
setPosition(_x: number, _y: number, _z: number): void;
|
|
217
|
-
setRotation(_x: number, _y: number, _z: number): void;
|
|
218
|
-
setRotationZ(_z: number): void;
|
|
219
|
-
setScale(_x: number, _y: number, _z: number): void;
|
|
220
|
-
/**
|
|
221
|
-
* Attach a behavior to this entity. The real engine entity does substantially
|
|
222
|
-
* more, but this functional stub stores the merged ref and builds the handle
|
|
223
|
-
* so descriptor/handle logic (and tests that drive behaviors directly) work
|
|
224
|
-
* without the full engine.
|
|
225
|
-
*/
|
|
226
|
-
use<O extends Record<string, any>, H extends Record<string, any> = Record<string, never>>(descriptor: BehaviorDescriptor<O, H>, options?: Partial<O>): BehaviorHandle<O, H>;
|
|
227
|
-
/** Live behavior refs attached via {@link use}. */
|
|
228
|
-
getBehaviorRefs(): BehaviorRef<any>[];
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Factory contract injected into behavior systems via
|
|
232
|
-
* {@link BehaviorSystemContext.createEntity}. The host engine supplies the real
|
|
233
|
-
* entity factory at stage-construction time.
|
|
234
|
-
*/
|
|
235
|
-
type CreateEntityFn = (options?: Partial<GameEntityOptions>) => GameEntity<GameEntityOptions>;
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* `WasmStageRuntime` — owns one wasm `WebAssembly.Instance` of
|
|
239
|
-
* `@zylem/runtime` and exposes the unified-Stage FFI as typed TypeScript
|
|
240
|
-
* methods. This is the single simulation adapter for the whole framework:
|
|
241
|
-
* behavior systems talk to it through the {@link BehaviorRuntime} contract,
|
|
242
|
-
* and hosts (e.g. `@zylem/game-lib`) drive it through
|
|
243
|
-
* {@link createSimulation} in `./simulation`.
|
|
244
|
-
*/
|
|
245
|
-
|
|
246
|
-
/** Sentinel handle for "no entity / failed allocation". Mirrors `INVALID_SLOT` in Rust. */
|
|
247
|
-
declare const STAGE_INVALID_SLOT = 4294967295;
|
|
248
|
-
declare const StageBodyKind: {
|
|
249
|
-
readonly Dynamic: 0;
|
|
250
|
-
readonly Static: 1;
|
|
251
|
-
readonly KinematicPosition: 2;
|
|
252
|
-
readonly KinematicVelocity: 3;
|
|
253
|
-
};
|
|
254
|
-
type StageBodyKindValue = (typeof StageBodyKind)[keyof typeof StageBodyKind];
|
|
255
|
-
declare const StageBoundaryDim: {
|
|
256
|
-
readonly Two: 2;
|
|
257
|
-
readonly Three: 3;
|
|
258
|
-
};
|
|
259
|
-
declare const StageRicochetDim: {
|
|
260
|
-
readonly Two: 2;
|
|
261
|
-
readonly Three: 3;
|
|
262
|
-
};
|
|
263
|
-
declare const StageRicochetReflection: {
|
|
264
|
-
readonly Mirror: 0;
|
|
265
|
-
readonly Angled: 1;
|
|
266
|
-
};
|
|
267
|
-
declare const StageTopDownPlane: {
|
|
268
|
-
readonly Xy: 0;
|
|
269
|
-
readonly Xz: 1;
|
|
270
|
-
};
|
|
271
|
-
declare const StageEventType: {
|
|
272
|
-
readonly CollisionStarted: 1;
|
|
273
|
-
readonly CollisionStopped: 2;
|
|
274
|
-
readonly BoundaryHit: 3;
|
|
275
|
-
readonly Ricochet: 4;
|
|
276
|
-
readonly RegionEntered: 5;
|
|
277
|
-
readonly JumpStarted: 6;
|
|
278
|
-
readonly Landed: 7;
|
|
279
|
-
readonly Wrapped: 8;
|
|
280
|
-
readonly CooldownFired: 9;
|
|
281
|
-
};
|
|
282
|
-
type StageBoundaryDimValue = (typeof StageBoundaryDim)[keyof typeof StageBoundaryDim];
|
|
283
|
-
type StageRicochetDimValue = (typeof StageRicochetDim)[keyof typeof StageRicochetDim];
|
|
284
|
-
type StageRicochetReflectionValue = (typeof StageRicochetReflection)[keyof typeof StageRicochetReflection];
|
|
285
|
-
type StageTopDownPlaneValue = (typeof StageTopDownPlane)[keyof typeof StageTopDownPlane];
|
|
286
|
-
/** Position + rotation snapshot for one runtime slot. */
|
|
287
|
-
interface StagePose {
|
|
288
|
-
position: [number, number, number];
|
|
289
|
-
rotation: [number, number, number, number];
|
|
290
|
-
}
|
|
291
|
-
interface StageWorldBoundaryOptions {
|
|
292
|
-
top: number;
|
|
293
|
-
bottom: number;
|
|
294
|
-
left: number;
|
|
295
|
-
right: number;
|
|
296
|
-
front?: number;
|
|
297
|
-
back?: number;
|
|
298
|
-
padding?: number;
|
|
299
|
-
}
|
|
300
|
-
interface StageScreenWrapOptions {
|
|
301
|
-
width: number;
|
|
302
|
-
height: number;
|
|
303
|
-
centerX?: number;
|
|
304
|
-
centerY?: number;
|
|
305
|
-
edgeThreshold?: number;
|
|
306
|
-
}
|
|
307
|
-
interface StageRicochetOptions {
|
|
308
|
-
minSpeed: number;
|
|
309
|
-
maxSpeed: number;
|
|
310
|
-
speedMultiplier: number;
|
|
311
|
-
maxAngleDeg: number;
|
|
312
|
-
reflectionMode: StageRicochetReflectionValue;
|
|
313
|
-
}
|
|
314
|
-
interface StageThrusterOptions {
|
|
315
|
-
maxSpeed: number;
|
|
316
|
-
acceleration: number;
|
|
317
|
-
turnRateRadPerSec: number;
|
|
318
|
-
linearDamping: number;
|
|
319
|
-
}
|
|
320
|
-
interface StageTopDownOptions {
|
|
321
|
-
plane: StageTopDownPlaneValue;
|
|
322
|
-
speed: number;
|
|
323
|
-
faceMovement?: boolean;
|
|
324
|
-
}
|
|
325
|
-
interface StageShooter2DOptions {
|
|
326
|
-
fireRateHz: number;
|
|
327
|
-
muzzleOffsetX: number;
|
|
328
|
-
muzzleOffsetY: number;
|
|
329
|
-
muzzleSpeed: number;
|
|
330
|
-
}
|
|
331
|
-
interface StageJumper2DOptions {
|
|
332
|
-
jumpForce: number;
|
|
333
|
-
maxJumps: number;
|
|
334
|
-
jumpBufferTime: number;
|
|
335
|
-
coyoteTime: number;
|
|
336
|
-
gravity: number;
|
|
337
|
-
}
|
|
338
|
-
interface StageJumper3DOptions {
|
|
339
|
-
jumpForce: number;
|
|
340
|
-
maxJumps: number;
|
|
341
|
-
gravity: number;
|
|
342
|
-
/** Coyote time in seconds (default 0.1). */
|
|
343
|
-
coyoteTime?: number;
|
|
344
|
-
/** Jump buffer window in seconds (default 0.08). */
|
|
345
|
-
jumpBufferTime?: number;
|
|
346
|
-
}
|
|
347
|
-
interface StagePlatformer3DOptions {
|
|
348
|
-
halfHeight: number;
|
|
349
|
-
radius: number;
|
|
350
|
-
walkSpeed: number;
|
|
351
|
-
runSpeed: number;
|
|
352
|
-
jumpForce: number;
|
|
353
|
-
maxJumps: number;
|
|
354
|
-
gravity: number;
|
|
355
|
-
/** Coyote time in seconds (default 0.1). */
|
|
356
|
-
coyoteTime?: number;
|
|
357
|
-
/** Jump buffer window in seconds (default 0.1). */
|
|
358
|
-
jumpBufferTime?: number;
|
|
359
|
-
/** Velocity multiplier applied on early jump release (default 0.5). */
|
|
360
|
-
jumpCutMultiplier?: number;
|
|
361
|
-
/** Seconds before a multi-jump becomes available (default 0.15). */
|
|
362
|
-
multiJumpWindow?: number;
|
|
363
|
-
/** Max slope angle in degrees the KCC can climb (default 50). */
|
|
364
|
-
slopeClimbAngle?: number;
|
|
365
|
-
/** Slope angle in degrees past which the character slides (default 40). */
|
|
366
|
-
slopeSlideAngle?: number;
|
|
367
|
-
/** Autostep max height in world units; 0 disables (default 0.3). */
|
|
368
|
-
autostepHeight?: number;
|
|
369
|
-
/** Minimum unobstructed width for an autostep (default 0.1). */
|
|
370
|
-
autostepMinWidth?: number;
|
|
371
|
-
/** Snap-to-ground distance in world units; 0 disables (default 0.3). */
|
|
372
|
-
snapToGroundDistance?: number;
|
|
373
|
-
/** KCC collision offset between collider and environment (default 0.05). */
|
|
374
|
-
characterOffset?: number;
|
|
375
|
-
/** Collider local offset X (fallback / override). */
|
|
376
|
-
offsetX?: number;
|
|
377
|
-
/** Collider local offset Y (fallback / override). */
|
|
378
|
-
offsetY?: number;
|
|
379
|
-
/** Collider local offset Z (fallback / override). */
|
|
380
|
-
offsetZ?: number;
|
|
381
|
-
/** 0 = auto-read attached collider; 1 = use stored shape fields. */
|
|
382
|
-
shapeSource?: number;
|
|
383
|
-
}
|
|
384
|
-
declare const StagePlatformerShapeSource: {
|
|
385
|
-
readonly Auto: 0;
|
|
386
|
-
readonly Override: 1;
|
|
387
|
-
};
|
|
388
|
-
interface StagePlatformer2DOptions {
|
|
389
|
-
halfHeight: number;
|
|
390
|
-
radius: number;
|
|
391
|
-
walkSpeed: number;
|
|
392
|
-
runSpeed: number;
|
|
393
|
-
jumpForce: number;
|
|
394
|
-
maxJumps: number;
|
|
395
|
-
gravity: number;
|
|
396
|
-
/** Coyote time in seconds (default 0.1). */
|
|
397
|
-
coyoteTime?: number;
|
|
398
|
-
/** Jump buffer window in seconds (default 0.1). */
|
|
399
|
-
jumpBufferTime?: number;
|
|
400
|
-
/** Velocity multiplier applied on early jump release (default 0.5). */
|
|
401
|
-
jumpCutMultiplier?: number;
|
|
402
|
-
/** Seconds before a multi-jump becomes available (default 0.15). */
|
|
403
|
-
multiJumpWindow?: number;
|
|
404
|
-
/** Max slope angle in degrees the KCC can climb (default 50). */
|
|
405
|
-
slopeClimbAngle?: number;
|
|
406
|
-
/** Slope angle in degrees past which the character slides (default 40). */
|
|
407
|
-
slopeSlideAngle?: number;
|
|
408
|
-
/** Autostep max height in world units; 0 disables (default 0.25). */
|
|
409
|
-
autostepHeight?: number;
|
|
410
|
-
/** Minimum unobstructed width for an autostep (default 0.05). */
|
|
411
|
-
autostepMinWidth?: number;
|
|
412
|
-
/** Snap-to-ground distance in world units; 0 disables (default 0.2). */
|
|
413
|
-
snapToGroundDistance?: number;
|
|
414
|
-
/** KCC collision offset between collider and environment (default 0.05). */
|
|
415
|
-
characterOffset?: number;
|
|
416
|
-
/** Collider local offset X (fallback / override). */
|
|
417
|
-
offsetX?: number;
|
|
418
|
-
/** Collider local offset Y (fallback / override). */
|
|
419
|
-
offsetY?: number;
|
|
420
|
-
/** Collider local offset Z (fallback / override). */
|
|
421
|
-
offsetZ?: number;
|
|
422
|
-
/** 0 = auto-read attached collider; 1 = use stored shape fields. */
|
|
423
|
-
shapeSource?: number;
|
|
424
|
-
}
|
|
425
|
-
interface StageFirstPersonOptions {
|
|
426
|
-
walkSpeed: number;
|
|
427
|
-
runSpeed: number;
|
|
428
|
-
eyeHeight: number;
|
|
429
|
-
lookSensitivity: number;
|
|
430
|
-
}
|
|
431
|
-
interface StageFirstPersonInput {
|
|
432
|
-
moveX: number;
|
|
433
|
-
moveZ: number;
|
|
434
|
-
lookYawDelta: number;
|
|
435
|
-
lookPitchDelta: number;
|
|
436
|
-
run: boolean;
|
|
437
|
-
}
|
|
438
|
-
/** Button bits for the slot-indexed input buffer's bitmask field. */
|
|
439
|
-
declare const STAGE_INPUT_BUTTON_JUMP = 1;
|
|
440
|
-
declare const STAGE_INPUT_BUTTON_RUN = 2;
|
|
441
|
-
/**
|
|
442
|
-
* Decoded per-slot behavior snapshot written by the runtime after every
|
|
443
|
-
* step: movement fields come from whichever character behavior the entity
|
|
444
|
-
* has (platformer 3D/2D, jumper 3D/2D); first-person fills yaw/pitch.
|
|
445
|
-
* Values reflect the end of the previous `step()` (one-frame read lag).
|
|
446
|
-
*/
|
|
447
|
-
interface StageBehaviorSnapshot {
|
|
448
|
-
grounded: boolean;
|
|
449
|
-
fsmState: number;
|
|
450
|
-
jumpCount: number;
|
|
451
|
-
verticalVelocity: number;
|
|
452
|
-
speed: number;
|
|
453
|
-
yaw: number;
|
|
454
|
-
pitch: number;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Wasm fast-path backrefs a behavior system stores on its `BehaviorRef` every
|
|
458
|
-
* frame so descriptor handles can read the runtime snapshot buffer instead of
|
|
459
|
-
* a duplicate TS FSM (or hardcoded defaults).
|
|
460
|
-
*/
|
|
461
|
-
interface WasmSnapshotBackref {
|
|
462
|
-
__wasmStage?: BehaviorRuntime | null;
|
|
463
|
-
__entity?: {
|
|
464
|
-
runtimeHandle?: number;
|
|
465
|
-
} | null;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Read the behavior snapshot for the entity a `BehaviorRef` is linked to.
|
|
469
|
-
* Returns `null` off the wasm fast path (no stage runtime / no
|
|
470
|
-
* `runtimeHandle` / no snapshot yet), in which case handles should fall back
|
|
471
|
-
* to their TS FSM.
|
|
472
|
-
*/
|
|
473
|
-
declare function readBehaviorSnapshot(ref: object): StageBehaviorSnapshot | null;
|
|
474
|
-
/**
|
|
475
|
-
* Runtime surface behavior systems rely on. `WasmStageRuntime` is the real
|
|
476
|
-
* wasm-backed implementation; `MockBehaviorRuntime` (see
|
|
477
|
-
* `./mock-behavior-runtime`) implements the same contract for unit tests, so
|
|
478
|
-
* descriptors stay runtime-agnostic.
|
|
479
|
-
*/
|
|
480
|
-
interface BehaviorRuntime {
|
|
481
|
-
getPose(handle: number, out?: StagePose): StagePose | null;
|
|
482
|
-
setPosition(handle: number, x: number, y: number, z: number): boolean;
|
|
483
|
-
setRotation(handle: number, x: number, y: number, z: number, w: number): boolean;
|
|
484
|
-
writeInputAxes(handle: number, axisA: number, axisB: number): boolean;
|
|
485
|
-
writeInputLook(handle: number, yawDelta: number, pitchDelta: number): boolean;
|
|
486
|
-
/** Write reserved input slots (thruster world-space vector X/Y). */
|
|
487
|
-
writeInputReserved(handle: number, reservedA: number, reservedB: number): boolean;
|
|
488
|
-
writeInputButton(handle: number, buttonMask: number, pressed: boolean): boolean;
|
|
489
|
-
/** Read the per-slot behavior snapshot written at the end of the previous step. */
|
|
490
|
-
readSnapshot(handle: number, out?: StageBehaviorSnapshot): StageBehaviorSnapshot | null;
|
|
491
|
-
attachThruster(handle: number, opts: StageThrusterOptions): boolean;
|
|
492
|
-
setThrusterInput(handle: number, thrust: number, rotate: number, vectorX?: number, vectorY?: number): void;
|
|
493
|
-
attachTopDown(handle: number, opts: StageTopDownOptions): boolean;
|
|
494
|
-
setTopDownInput(handle: number, moveX: number, moveY: number): void;
|
|
495
|
-
attachShooter2D(handle: number, opts: StageShooter2DOptions): boolean;
|
|
496
|
-
attachScreenWrap(handle: number, opts: StageScreenWrapOptions): boolean;
|
|
497
|
-
queryScreenWrap(handle: number): {
|
|
498
|
-
fsm: number;
|
|
499
|
-
lastWrappedAxes: number;
|
|
500
|
-
} | null;
|
|
501
|
-
attachWorldBoundary(handle: number, dim: StageBoundaryDimValue, opts: StageWorldBoundaryOptions): boolean;
|
|
502
|
-
queryWorldBoundary(handle: number): {
|
|
503
|
-
hits: number;
|
|
504
|
-
clamped: [number, number, number];
|
|
505
|
-
} | null;
|
|
506
|
-
attachRicochet(handle: number, dim: StageRicochetDimValue, opts: StageRicochetOptions): boolean;
|
|
507
|
-
attachPlatformer3D(handle: number, opts: StagePlatformer3DOptions): boolean;
|
|
508
|
-
setPlatformer3DInputAxes(handle: number, moveX: number, moveZ: number): void;
|
|
509
|
-
setPlatformer3DInputButtons(handle: number, jump: boolean, run: boolean): void;
|
|
510
|
-
attachPlatformer2D(handle: number, opts: StagePlatformer2DOptions): boolean;
|
|
511
|
-
setPlatformer2DInputAxes(handle: number, moveX: number): void;
|
|
512
|
-
setPlatformer2DInputButtons(handle: number, jump: boolean, run: boolean): void;
|
|
513
|
-
attachFirstPerson(handle: number, opts: StageFirstPersonOptions): boolean;
|
|
514
|
-
setFirstPersonInput(handle: number, input: StageFirstPersonInput): void;
|
|
515
|
-
attachJumper2D(handle: number, opts: StageJumper2DOptions): boolean;
|
|
516
|
-
setJumper2DInput(handle: number, jumpPressed: boolean): void;
|
|
517
|
-
attachJumper3D(handle: number, opts: StageJumper3DOptions): boolean;
|
|
518
|
-
setJumper3DInput(handle: number, jumpPressed: boolean): void;
|
|
519
|
-
}
|
|
520
|
-
/** Default options used when constructing a wasm-backed Stage runtime. */
|
|
521
|
-
interface WasmStageRuntimeOptions {
|
|
522
|
-
initialCapacity?: number;
|
|
523
|
-
gravity?: readonly [number, number, number];
|
|
524
|
-
imports?: WebAssembly.Imports;
|
|
525
|
-
/**
|
|
526
|
-
* Custom wasm source. Defaults to the `zylem_runtime.wasm` bundled with
|
|
527
|
-
* `@zylem/runtime`.
|
|
528
|
-
*/
|
|
529
|
-
source?: RequestInfo | URL | ArrayBuffer | Uint8Array;
|
|
530
|
-
}
|
|
531
|
-
type StageEventTypeValue = (typeof StageEventType)[keyof typeof StageEventType];
|
|
532
|
-
/** One decoded event drained from the runtime's per-step event buffer. */
|
|
533
|
-
interface StageEvent {
|
|
534
|
-
type: StageEventTypeValue;
|
|
535
|
-
primarySlot: number | null;
|
|
536
|
-
secondarySlot: number | null;
|
|
537
|
-
payload: [number, number, number];
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Decoded view of one entity's slot in the unified render buffer.
|
|
541
|
-
*
|
|
542
|
-
* Mirrors the `STAGE_RENDER_STRIDE` (12-float) packing documented in
|
|
543
|
-
* `runtime/stage/render.rs`:
|
|
544
|
-
* `[0..3]` position, `[3..7]` rotation xyzw, `[7]` uniform scale,
|
|
545
|
-
* `[8..11]` custom0..custom2 (shading hints), `[11]` custom3 sleeping flag
|
|
546
|
-
* (1.0 = sleeping).
|
|
547
|
-
*/
|
|
548
|
-
interface StageRenderSlot {
|
|
549
|
-
position: [number, number, number];
|
|
550
|
-
rotation: [number, number, number, number];
|
|
551
|
-
scale: number;
|
|
552
|
-
custom: [number, number, number, number];
|
|
553
|
-
/** True when custom[3] indicates the body is sleeping. */
|
|
554
|
-
isSleeping: boolean;
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Read a single entity slot out of a unified-Stage render buffer view.
|
|
558
|
-
*
|
|
559
|
-
* @param view The `Float32Array` over wasm memory (e.g. `WasmStageRuntime.render`).
|
|
560
|
-
* @param slot The entity's wasm slot id (its `runtimeHandle`).
|
|
561
|
-
* @param out Optional target object to write into (avoids per-call allocation).
|
|
562
|
-
* @returns The decoded slot, or `null` when the slot is out of range.
|
|
563
|
-
*/
|
|
564
|
-
declare function readStageRenderSlot(view: Float32Array, slot: number, out?: StageRenderSlot): StageRenderSlot | null;
|
|
565
|
-
interface StageBodyConfig {
|
|
566
|
-
kind: StageBodyKindValue;
|
|
567
|
-
position: readonly [number, number, number];
|
|
568
|
-
rotation: readonly [number, number, number, number];
|
|
569
|
-
linearDamping: number;
|
|
570
|
-
angularDamping: number;
|
|
571
|
-
gravityScale: number;
|
|
572
|
-
canSleep: boolean;
|
|
573
|
-
ccdEnabled: boolean;
|
|
574
|
-
lockRotation: readonly [boolean, boolean, boolean];
|
|
575
|
-
lockTranslation: readonly [boolean, boolean, boolean];
|
|
576
|
-
}
|
|
577
|
-
type StageColliderShape = {
|
|
578
|
-
type: 'box';
|
|
579
|
-
halfExtents: readonly [number, number, number];
|
|
580
|
-
} | {
|
|
581
|
-
type: 'sphere';
|
|
582
|
-
radius: number;
|
|
583
|
-
} | {
|
|
584
|
-
type: 'capsule';
|
|
585
|
-
halfHeight: number;
|
|
586
|
-
radius: number;
|
|
587
|
-
} | {
|
|
588
|
-
type: 'cylinder';
|
|
589
|
-
halfHeight: number;
|
|
590
|
-
radius: number;
|
|
591
|
-
} | {
|
|
592
|
-
type: 'cone';
|
|
593
|
-
halfHeight: number;
|
|
594
|
-
radius: number;
|
|
595
|
-
} | {
|
|
596
|
-
type: 'convexHull';
|
|
597
|
-
vertices: Float32Array;
|
|
598
|
-
} | {
|
|
599
|
-
type: 'trimesh';
|
|
600
|
-
vertices: Float32Array;
|
|
601
|
-
indices: Uint32Array;
|
|
602
|
-
} | {
|
|
603
|
-
type: 'heightfield';
|
|
604
|
-
rows: number;
|
|
605
|
-
cols: number;
|
|
606
|
-
scale: readonly [number, number, number];
|
|
607
|
-
heights: Float32Array;
|
|
608
|
-
};
|
|
609
|
-
interface StageColliderConfig {
|
|
610
|
-
shape: StageColliderShape;
|
|
611
|
-
offset: readonly [number, number, number];
|
|
612
|
-
friction: number;
|
|
613
|
-
restitution: number;
|
|
614
|
-
sensor: boolean;
|
|
615
|
-
/** Packed interaction-groups: high 16 bits = membership, low 16 bits = filter. */
|
|
616
|
-
collisionGroups: number;
|
|
617
|
-
}
|
|
618
|
-
/** Result of a physics raycast against the stage. */
|
|
619
|
-
interface StageRaycastHit {
|
|
620
|
-
slot: number;
|
|
621
|
-
distance: number;
|
|
622
|
-
normal: [number, number, number];
|
|
623
|
-
}
|
|
624
|
-
/** Body introspection payload for debug tooling. */
|
|
625
|
-
interface StageBodyInfo {
|
|
626
|
-
bodyType: number;
|
|
627
|
-
mass: number;
|
|
628
|
-
isSleeping: boolean;
|
|
629
|
-
isEnabled: boolean;
|
|
630
|
-
linearVelocity: [number, number, number];
|
|
631
|
-
}
|
|
632
|
-
/** Line-list wireframe for physics debug rendering. */
|
|
633
|
-
interface StageDebugRender {
|
|
634
|
-
/** `[x, y, z]` per vertex, two vertices per line. */
|
|
635
|
-
vertices: Float32Array;
|
|
636
|
-
/** RGBA per vertex. */
|
|
637
|
-
colors: Float32Array;
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Owns the wasm instance plus the live float-views over its render / event /
|
|
641
|
-
* pose / scratch buffers. One instance per logical stage; each stage gets
|
|
642
|
-
* its own `WebAssembly.Instance` so the singleton inside `stage_ffi.rs`
|
|
643
|
-
* stays single-stage scoped (today's `thread_local!` contract).
|
|
644
|
-
*/
|
|
645
|
-
declare class WasmStageRuntime implements BehaviorRuntime {
|
|
646
|
-
readonly exports: StageWasmExports;
|
|
647
|
-
private readonly memory;
|
|
648
|
-
private renderView;
|
|
649
|
-
private inputView;
|
|
650
|
-
private snapshotView;
|
|
651
|
-
private eventView;
|
|
652
|
-
private poseView;
|
|
653
|
-
private vec3View;
|
|
654
|
-
private queryView;
|
|
655
|
-
private scratchView;
|
|
656
|
-
constructor(exports: StageWasmExports, options?: WasmStageRuntimeOptions);
|
|
657
|
-
/** Recreate typed views over wasm memory. Call after step() or whenever memory may have grown. */
|
|
658
|
-
refreshViews(): void;
|
|
659
|
-
/** Step the simulation by `dt` seconds. Refreshes views afterwards. */
|
|
660
|
-
step(dt: number): number;
|
|
661
|
-
dispose(): void;
|
|
662
|
-
get tickCount(): number;
|
|
663
|
-
get activeCount(): number;
|
|
664
|
-
setGravity(x: number, y: number, z: number): void;
|
|
665
|
-
/**
|
|
666
|
-
* Toggle per-step collision-event collection in the wasm stage. Hosts
|
|
667
|
-
* with no collision listeners should disable it — with thousands of
|
|
668
|
-
* touching bodies the per-step contact-pair hashing is a significant
|
|
669
|
-
* fraction of `step()`.
|
|
670
|
-
*/
|
|
671
|
-
setEventsEnabled(enabled: boolean): void;
|
|
672
|
-
/** Cap Rapier contact solver iterations (default 4). */
|
|
673
|
-
setSolverIterations(iterations: number): void;
|
|
674
|
-
/**
|
|
675
|
-
* Override sleep activation thresholds for sleep-capable dynamic bodies.
|
|
676
|
-
* Higher velocity thresholds / lower `timeUntilSleep` put piles to sleep
|
|
677
|
-
* sooner.
|
|
678
|
-
*/
|
|
679
|
-
setSleepThresholds(normalizedLinearThreshold: number, angularThreshold: number, timeUntilSleep: number): void;
|
|
680
|
-
/** Number of awake (non-sleeping) dynamic rigid bodies. */
|
|
681
|
-
awakeDynamicCount(): number;
|
|
682
|
-
createEntity(): number;
|
|
683
|
-
destroyEntity(slot: number): boolean;
|
|
684
|
-
attachBody(slot: number, config: StageBodyConfig): boolean;
|
|
685
|
-
addCollider(slot: number, config: StageColliderConfig): boolean;
|
|
686
|
-
private stageScratch;
|
|
687
|
-
private stageScratchIndices;
|
|
688
|
-
getPose(slot: number, out?: StagePose): StagePose | null;
|
|
689
|
-
setPosition(slot: number, x: number, y: number, z: number): boolean;
|
|
690
|
-
setRotation(slot: number, x: number, y: number, z: number, w: number): boolean;
|
|
691
|
-
setLinearVelocity(slot: number, x: number, y: number, z: number): boolean;
|
|
692
|
-
getLinearVelocity(slot: number, out?: [number, number, number]): [number, number, number] | null;
|
|
693
|
-
setAngularVelocity(slot: number, x: number, y: number, z: number): boolean;
|
|
694
|
-
getAngularVelocity(slot: number, out?: [number, number, number]): [number, number, number] | null;
|
|
695
|
-
applyImpulse(slot: number, x: number, y: number, z: number): boolean;
|
|
696
|
-
/** Cast a ray against the physics world. Returns the closest hit or `null`. */
|
|
697
|
-
castRay(origin: readonly [number, number, number], dir: readonly [number, number, number], maxDistance: number, solidOnly?: boolean): StageRaycastHit | null;
|
|
698
|
-
/** Body introspection for debug tooling. */
|
|
699
|
-
getBodyInfo(slot: number): StageBodyInfo | null;
|
|
700
|
-
/** Wireframe debug render of every collider (all shapes). */
|
|
701
|
-
getDebugRender(): StageDebugRender | null;
|
|
702
|
-
/** Read-only view over the render buffer; one slot occupies {@link STAGE_RENDER_STRIDE} floats. */
|
|
703
|
-
get render(): Float32Array;
|
|
704
|
-
get renderStride(): number;
|
|
705
|
-
/**
|
|
706
|
-
* Decode a single entity slot from the live render buffer. Convenience
|
|
707
|
-
* wrapper over {@link readStageRenderSlot} bound to this runtime's view.
|
|
708
|
-
*/
|
|
709
|
-
readRenderSlot(slot: number, out?: StageRenderSlot): StageRenderSlot | null;
|
|
710
|
-
/** Drain the wasm event buffer into a fresh array of typed events. */
|
|
711
|
-
drainEvents(): StageEvent[];
|
|
712
|
-
/** Writable view over the slot-indexed input buffer ({@link STAGE_INPUT_STRIDE} floats/slot). */
|
|
713
|
-
get input(): Float32Array;
|
|
714
|
-
get inputStride(): number;
|
|
715
|
-
/** Read-only view over the per-slot behavior snapshot buffer ({@link STAGE_SNAPSHOT_STRIDE} floats/slot). */
|
|
716
|
-
get snapshot(): Float32Array;
|
|
717
|
-
get snapshotStride(): number;
|
|
718
|
-
/**
|
|
719
|
-
* Write the primary movement axes for a slot into the slot-indexed input
|
|
720
|
-
* buffer and mark the slot dirty. Field-scoped (doesn't touch look
|
|
721
|
-
* deltas or buttons) so multiple behaviors composed on one entity can
|
|
722
|
-
* each write their part.
|
|
723
|
-
*/
|
|
724
|
-
writeInputAxes(slot: number, axisA: number, axisB: number): boolean;
|
|
725
|
-
/** Write the look deltas (first-person yaw/pitch) for a slot. */
|
|
726
|
-
writeInputLook(slot: number, yawDelta: number, pitchDelta: number): boolean;
|
|
727
|
-
/** Write reserved input slots (thruster world-space vector X/Y). */
|
|
728
|
-
writeInputReserved(slot: number, reservedA: number, reservedB: number): boolean;
|
|
729
|
-
/**
|
|
730
|
-
* Set or clear one button bit ({@link STAGE_INPUT_BUTTON_JUMP} /
|
|
731
|
-
* {@link STAGE_INPUT_BUTTON_RUN}) in a slot's input bitmask.
|
|
732
|
-
*/
|
|
733
|
-
writeInputButton(slot: number, buttonMask: number, pressed: boolean): boolean;
|
|
734
|
-
/**
|
|
735
|
-
* Decode a slot's behavior snapshot from the buffer written at the end of
|
|
736
|
-
* the previous step. Returns `null` when the slot has no behavior data.
|
|
737
|
-
*/
|
|
738
|
-
readSnapshot(slot: number, out?: StageBehaviorSnapshot): StageBehaviorSnapshot | null;
|
|
739
|
-
get queryScratch(): Float32Array;
|
|
740
|
-
attachCooldown(slot: number): boolean;
|
|
741
|
-
registerCooldown(slot: number, id: number, durationSeconds: number, immediate?: boolean): boolean;
|
|
742
|
-
fireCooldown(slot: number, id: number): boolean;
|
|
743
|
-
resetCooldown(slot: number, id: number): boolean;
|
|
744
|
-
cooldownRemaining(slot: number, id: number): number;
|
|
745
|
-
attachWorldBoundary(slot: number, dim: StageBoundaryDimValue, bounds: StageWorldBoundaryOptions): boolean;
|
|
746
|
-
queryWorldBoundary(slot: number): {
|
|
747
|
-
hits: number;
|
|
748
|
-
clamped: [number, number, number];
|
|
749
|
-
} | null;
|
|
750
|
-
attachScreenWrap(slot: number, opts: StageScreenWrapOptions): boolean;
|
|
751
|
-
queryScreenWrap(slot: number): {
|
|
752
|
-
fsm: number;
|
|
753
|
-
lastWrappedAxes: number;
|
|
754
|
-
} | null;
|
|
755
|
-
attachRicochet(slot: number, dim: StageRicochetDimValue, opts: StageRicochetOptions): boolean;
|
|
756
|
-
queryRicochet(slot: number): {
|
|
757
|
-
bounces: number;
|
|
758
|
-
lastKind: number;
|
|
759
|
-
} | null;
|
|
760
|
-
attachThruster(slot: number, opts: StageThrusterOptions): boolean;
|
|
761
|
-
setThrusterInput(slot: number, thrust: number, turn: number, vectorX?: number, vectorY?: number): void;
|
|
762
|
-
queryThruster(slot: number): {
|
|
763
|
-
headingRad: number;
|
|
764
|
-
speed: number;
|
|
765
|
-
} | null;
|
|
766
|
-
attachTopDown(slot: number, opts: StageTopDownOptions): boolean;
|
|
767
|
-
setTopDownInput(slot: number, axisA: number, axisB: number): void;
|
|
768
|
-
attachJumper2D(slot: number, opts: StageJumper2DOptions): boolean;
|
|
769
|
-
setJumper2DInput(slot: number, jumpPressed: boolean): void;
|
|
770
|
-
queryJumper2D(slot: number): {
|
|
771
|
-
grounded: boolean;
|
|
772
|
-
jumpCount: number;
|
|
773
|
-
coyote: number;
|
|
774
|
-
jumpBuffer: number;
|
|
775
|
-
} | null;
|
|
776
|
-
attachJumper3D(slot: number, opts: StageJumper3DOptions): boolean;
|
|
777
|
-
setJumper3DInput(slot: number, jump: boolean): void;
|
|
778
|
-
queryJumper3D(slot: number): {
|
|
779
|
-
grounded: boolean;
|
|
780
|
-
jumpCount: number;
|
|
781
|
-
verticalVelocity: number;
|
|
782
|
-
} | null;
|
|
783
|
-
attachShooter2D(slot: number, opts: StageShooter2DOptions): boolean;
|
|
784
|
-
fireShooter2D(slot: number, x: number, y: number, z: number, yaw: number): boolean;
|
|
785
|
-
queryShooter2D(slot: number): {
|
|
786
|
-
cooldown: number;
|
|
787
|
-
firedCount: number;
|
|
788
|
-
} | null;
|
|
789
|
-
attachPlatformer3D(slot: number, opts: StagePlatformer3DOptions): boolean;
|
|
790
|
-
setPlatformer3DInputAxes(slot: number, moveX: number, moveZ: number): void;
|
|
791
|
-
setPlatformer3DInputButtons(slot: number, jump: boolean, run: boolean): void;
|
|
792
|
-
queryPlatformer3D(slot: number): {
|
|
793
|
-
grounded: boolean;
|
|
794
|
-
jumpCount: number;
|
|
795
|
-
fsmState: number;
|
|
796
|
-
speed: number;
|
|
797
|
-
} | null;
|
|
798
|
-
attachPlatformer2D(slot: number, opts: StagePlatformer2DOptions): boolean;
|
|
799
|
-
setPlatformer2DInputAxes(slot: number, moveX: number): void;
|
|
800
|
-
setPlatformer2DInputButtons(slot: number, jump: boolean, run: boolean): void;
|
|
801
|
-
queryPlatformer2D(slot: number): {
|
|
802
|
-
grounded: boolean;
|
|
803
|
-
jumpCount: number;
|
|
804
|
-
fsmState: number;
|
|
805
|
-
verticalVelocity: number;
|
|
806
|
-
} | null;
|
|
807
|
-
attachFirstPerson(slot: number, opts: StageFirstPersonOptions): boolean;
|
|
808
|
-
setFirstPersonInput(slot: number, input: StageFirstPersonInput): void;
|
|
809
|
-
queryFirstPerson(slot: number): {
|
|
810
|
-
yaw: number;
|
|
811
|
-
pitch: number;
|
|
812
|
-
speed: number;
|
|
813
|
-
eyeHeight: number;
|
|
814
|
-
} | null;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Load the bundled `@zylem/runtime` wasm (or a custom `source`), instantiate
|
|
818
|
-
* it, and construct a `WasmStageRuntime` around the exports.
|
|
819
|
-
*/
|
|
820
|
-
declare function createWasmStageRuntime(options?: WasmStageRuntimeOptions): Promise<WasmStageRuntime>;
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* Structural stand-in for the engine world wrapper. The engine's world
|
|
824
|
-
* delegate exposes an entity lookup map; behaviors only rely on this slice.
|
|
825
|
-
*
|
|
826
|
-
* The map value is intentionally `unknown` (not the `GameEntity` stub class):
|
|
827
|
-
* the engine's concrete entity class is a different nominal type, and systems
|
|
828
|
-
* that iterate the map narrow entities themselves.
|
|
829
|
-
*/
|
|
830
|
-
interface ZylemWorld {
|
|
831
|
-
collisionMap?: Map<string, unknown>;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
/**
|
|
835
|
-
* BehaviorSystem Interface
|
|
836
|
-
*
|
|
837
|
-
* Legacy behavior systems reserved the first `update` argument for an ECS world
|
|
838
|
-
* handle; it is always `undefined` now.
|
|
839
|
-
*/
|
|
840
|
-
/**
|
|
841
|
-
* A behavior system that processes entities with specific components.
|
|
842
|
-
*
|
|
843
|
-
* @example
|
|
844
|
-
* ```typescript
|
|
845
|
-
* class ThrusterSystem implements BehaviorSystem {
|
|
846
|
-
* update(_ecs: unknown, delta: number): void {
|
|
847
|
-
* // Iterate behavior links, push intent into wasm runtime, etc.
|
|
848
|
-
* }
|
|
849
|
-
* }
|
|
850
|
-
* ```
|
|
851
|
-
*/
|
|
852
|
-
interface BehaviorSystem {
|
|
853
|
-
/** Optional eager initialization when a behavior link is registered on a live entity */
|
|
854
|
-
attach?(link: BehaviorEntityLink): void;
|
|
855
|
-
/** Called once per frame. The first argument is always `undefined` (reserved legacy slot). */
|
|
856
|
-
update(ecs: unknown, delta: number): void;
|
|
857
|
-
/**
|
|
858
|
-
* Called once per frame after the simulation has stepped and before the
|
|
859
|
-
* host syncs render poses. Systems that need this frame's post-step state
|
|
860
|
-
* (e.g. wasm-side teleports) run here instead of in `update`.
|
|
861
|
-
*/
|
|
862
|
-
postUpdate?(ecs: unknown, delta: number): void;
|
|
863
|
-
/** Optional cleanup when a behavior link is detached from a live entity */
|
|
864
|
-
detach?(link: BehaviorEntityLink): void;
|
|
865
|
-
/** Optional cleanup when stage is destroyed */
|
|
866
|
-
destroy?(ecs?: unknown): void;
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Runtime link between a spawned entity and one of its behavior refs.
|
|
870
|
-
* Systems can iterate these links to avoid scanning all world entities.
|
|
871
|
-
*/
|
|
872
|
-
interface BehaviorEntityLink {
|
|
873
|
-
entity: any;
|
|
874
|
-
ref: any;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Context provided to behavior-system factories.
|
|
878
|
-
*
|
|
879
|
-
* After the runtime-only stage migration, `wasmStage` is the source of
|
|
880
|
-
* truth — descriptors should call `wasmStage.attach<X>(handle, opts)` /
|
|
881
|
-
* `wasmStage.query<X>(handle)` from inside the system instead of touching
|
|
882
|
-
* `entity.body` directly. The legacy `world` / `scene` fields remain for
|
|
883
|
-
* unmigrated descriptors.
|
|
884
|
-
*/
|
|
885
|
-
interface BehaviorSystemContext {
|
|
886
|
-
world: ZylemWorld | null;
|
|
887
|
-
/** Host scene wrapper (engine-specific); behaviors only call `add`/`remove`-style methods on it. */
|
|
888
|
-
scene: any;
|
|
889
|
-
/** Wasm-driven Stage runtime; omitted when the stage has no wasm module. */
|
|
890
|
-
wasmStage?: BehaviorRuntime | null;
|
|
891
|
-
/**
|
|
892
|
-
* Returns live behavior links for a descriptor key.
|
|
893
|
-
* O(1) lookup into a pre-built stage index.
|
|
894
|
-
*/
|
|
895
|
-
getBehaviorLinks?: (key: symbol) => Iterable<BehaviorEntityLink>;
|
|
896
|
-
/**
|
|
897
|
-
* Host-injected entity factory. Behaviors that spawn entities at runtime
|
|
898
|
-
* (e.g. destructible-3d fragments) use this instead of importing the engine
|
|
899
|
-
* entity factory directly, keeping the behavior layer decoupled.
|
|
900
|
-
*/
|
|
901
|
-
createEntity?: CreateEntityFn;
|
|
902
|
-
/**
|
|
903
|
-
* Host-injected accessor for the global game-state bag, passed to entity
|
|
904
|
-
* lifecycle hooks (e.g. `nodeDestroy`).
|
|
905
|
-
*/
|
|
906
|
-
getGlobals?: () => any;
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* Factory function that creates a BehaviorSystem.
|
|
910
|
-
* Receives the stage for access to world, scene, etc.
|
|
911
|
-
*/
|
|
912
|
-
type BehaviorSystemFactory<T extends BehaviorSystem = BehaviorSystem> = (stage: BehaviorSystemContext) => T;
|
|
913
|
-
|
|
914
|
-
export { type VelocityIntentMode as $, type StageJumper2DOptions as A, type BaseBehaviorHandle as B, type CreateEntityFn as C, type DefineBehaviorConfig as D, type StageJumper3DOptions as E, type StagePlatformer2DOptions as F, GameEntity as G, type StagePlatformer3DOptions as H, StagePlatformerShapeSource as I, type StagePose as J, type StageRaycastHit as K, type StageRenderSlot as L, StageRicochetDim as M, type StageRicochetDimValue as N, type StageRicochetOptions as O, StageRicochetReflection as P, type StageRicochetReflectionValue as Q, type StageScreenWrapOptions as R, STAGE_INPUT_BUTTON_JUMP as S, type StageShooter2DOptions as T, type StageThrusterOptions as U, type StageTopDownOptions as V, StageTopDownPlane as W, type StageTopDownPlaneValue as X, type StageWorldBoundaryOptions as Y, type TransformState as Z, type VelocityIntent as _, type BehaviorDescriptor as a, type WasmSnapshotBackref as a0, WasmStageRuntime as a1, type WasmStageRuntimeOptions as a2, createTransformStore as a3, createWasmStageRuntime as a4, defineBehavior as a5, readBehaviorSnapshot as a6, readStageRenderSlot as a7, type BehaviorEntityLink as b, type BehaviorHandle as c, type BehaviorRef as d, type BehaviorRuntime as e, type BehaviorSystem as f, type BehaviorSystemContext as g, type BehaviorSystemFactory as h, type GameEntityOptions as i, STAGE_INPUT_BUTTON_RUN as j, STAGE_INVALID_SLOT as k, type StageBehaviorSnapshot as l, type StageBodyConfig as m, type StageBodyInfo as n, StageBodyKind as o, type StageBodyKindValue as p, StageBoundaryDim as q, type StageBoundaryDimValue as r, type StageColliderConfig as s, type StageColliderShape as t, type StageDebugRender as u, type StageEvent as v, StageEventType as w, type StageEventTypeValue as x, type StageFirstPersonInput as y, type StageFirstPersonOptions as z };
|