@zylem/game-lib 0.7.0 → 0.8.2

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 (98) hide show
  1. package/README.md +15 -1
  2. package/dist/actions.d.ts +71 -8
  3. package/dist/actions.js +1 -1
  4. package/dist/api/game-lib.api.json +55350 -0
  5. package/dist/api/game-lib.api.md +4608 -0
  6. package/dist/api/game-lib.d.ts +8447 -0
  7. package/dist/api/game-lib.typedoc.json +352456 -0
  8. package/dist/audio.js +1 -1
  9. package/dist/{base-node-life-cycle-CnJ-7zX-.d.ts → base-node-life-cycle-BK9xebT9.d.ts} +18 -4
  10. package/dist/behavior.d.ts +2 -3
  11. package/dist/behavior.js +1 -1
  12. package/dist/blueprints-TbGY-h53.d.ts +162 -0
  13. package/dist/chunk-3PRBSSTS.js +24 -0
  14. package/dist/chunk-47DG7I7M.js +1 -0
  15. package/dist/chunk-7GYFZKK7.js +1 -0
  16. package/dist/chunk-7QF6YTEZ.js +1 -0
  17. package/dist/chunk-7WRQ2UAN.js +1 -0
  18. package/dist/chunk-BH53MBAZ.js +1 -0
  19. package/dist/chunk-BIGH6D34.js +0 -0
  20. package/dist/chunk-CD7ZOZ35.js +1 -0
  21. package/dist/chunk-CFVRRRZZ.js +1 -0
  22. package/dist/chunk-CM5YRNBJ.js +19 -0
  23. package/dist/chunk-COM6HJ2L.js +1 -0
  24. package/dist/chunk-D2PATZCC.js +1 -0
  25. package/dist/chunk-DFLI7ICU.js +0 -0
  26. package/dist/chunk-EVYHPR3J.js +1 -0
  27. package/dist/chunk-IPWUDOV5.js +1 -0
  28. package/dist/chunk-JNFFTNMH.js +1 -0
  29. package/dist/chunk-JQKS42G4.js +1 -0
  30. package/dist/chunk-KVSJE4XD.js +1 -0
  31. package/dist/chunk-MZZCDXFB.js +1 -0
  32. package/dist/chunk-ORIDWL3T.js +0 -0
  33. package/dist/{chunk-RXDTAWI2.js → chunk-PCFF4LLO.js} +1 -1
  34. package/dist/chunk-QB3NL7VQ.js +1 -0
  35. package/dist/chunk-TAUWDQZF.js +9 -0
  36. package/dist/chunk-UG22Z42P.js +1 -0
  37. package/dist/chunk-VS2D4B3W.js +1 -0
  38. package/dist/chunk-WQ3WMMZD.js +1 -0
  39. package/dist/chunk-XK63E4SX.js +1 -0
  40. package/dist/chunk-YAOXFYOD.js +1 -0
  41. package/dist/chunk-ZRT3ZQVH.js +1 -0
  42. package/dist/collision-builder-B_tm8OVy.d.ts +49 -0
  43. package/dist/core.d.ts +45 -30
  44. package/dist/core.js +1 -24
  45. package/dist/debug-state-DRoeasG2.d.ts +17 -0
  46. package/dist/debug.d.ts +71 -19
  47. package/dist/debug.js +1 -1
  48. package/dist/{default-controls-BGc61yYl.d.ts → default-controls-CAKJ5zlo.d.ts} +3 -3
  49. package/dist/entity-B9yZeBm4.d.ts +34 -0
  50. package/dist/{entity-DNkYKfdp.d.ts → entity-BGEq1yfC.d.ts} +91 -444
  51. package/dist/{entity-type-map-C94h2TDW.d.ts → entity-type-map-CW6RHQkx.d.ts} +153 -6
  52. package/dist/entity.d.ts +15 -10
  53. package/dist/entity.js +1 -1
  54. package/dist/events.d.ts +10 -1
  55. package/dist/events.js +1 -1
  56. package/dist/{game-Cuj5gy7U.d.ts → game-DbqBQiFC.d.ts} +460 -135
  57. package/dist/game-default-6AZZCNST.js +1 -0
  58. package/dist/{game-interfaces-tfpM5NBk.d.ts → game-interfaces-vF5sRi1n.d.ts} +8 -2
  59. package/dist/globals.d.ts +12 -1
  60. package/dist/globals.js +1 -1
  61. package/dist/graphics.d.ts +16 -46
  62. package/dist/graphics.js +1 -1
  63. package/dist/input-ui.d.ts +5 -4
  64. package/dist/input-ui.js +1 -1
  65. package/dist/input.d.ts +48 -4
  66. package/dist/input.js +1 -1
  67. package/dist/{material-Wz83vTTp.d.ts → material-DbSuZBbP.d.ts} +25 -50
  68. package/dist/public.d.ts +38 -0
  69. package/dist/public.js +1 -0
  70. package/dist/runtime.d.ts +7 -381
  71. package/dist/runtime.js +1 -1
  72. package/dist/schema/entity.schema.json +244 -0
  73. package/dist/schema/game-config.schema.json +643 -0
  74. package/dist/schema/input-config.schema.json +517 -0
  75. package/dist/schema/stage-config.schema.json +93 -0
  76. package/dist/schema/stage.schema.json +271 -0
  77. package/dist/schema.d.ts +550 -0
  78. package/dist/schema.js +1 -0
  79. package/dist/stage-transition-CmGpV4tc.d.ts +46 -0
  80. package/dist/vector-DN6zlPoE.d.ts +161 -0
  81. package/dist/web-components.d.ts +15 -12
  82. package/dist/web-components.js +1 -9
  83. package/dist/{zylem-stage-runtime-Cs-UDEVU.d.ts → zylem-camera-Du2UPW9O.d.ts} +74 -264
  84. package/package.json +28 -20
  85. package/dist/chunk-73VZQZUL.js +0 -1
  86. package/dist/chunk-A34ZG3L4.js +0 -1
  87. package/dist/chunk-CDPY4VOQ.js +0 -1
  88. package/dist/chunk-DR6XXZE7.js +0 -19
  89. package/dist/chunk-FM5TBEPO.js +0 -1
  90. package/dist/chunk-G2IIMSUH.js +0 -1
  91. package/dist/chunk-MSC2BEO5.js +0 -1
  92. package/dist/chunk-NIH5CONO.js +0 -1
  93. package/dist/chunk-ONWXGBWB.js +0 -1
  94. package/dist/chunk-QEDQDR27.js +0 -1
  95. package/dist/chunk-WKHW2QO2.js +0 -1
  96. package/dist/chunk-YHKXQ2ZN.js +0 -1
  97. package/dist/game-default-PZLLHYL7.js +0 -1
  98. package/dist/world-C9zdyl5d.d.ts +0 -103
package/dist/runtime.d.ts CHANGED
@@ -1,382 +1,9 @@
1
- import { R as RuntimeDebugBinding } from './zylem-stage-runtime-Cs-UDEVU.js';
2
- export { S as StageRuntimeAdapter, a as StageRuntimeContext, b as StageRuntimeStepContext, c as createZylemRuntimeStageAdapter } from './zylem-stage-runtime-Cs-UDEVU.js';
3
- import { S as StageBodyKind, a as StageBodyConfig, b as StageColliderConfig } from './entity-DNkYKfdp.js';
4
- export { l as STAGE_EVENT_STRIDE, m as STAGE_INVALID_SLOT, n as STAGE_POSE_LEN, o as STAGE_RENDER_STRIDE, g as StageBoundaryDim, c as StageColliderShape, d as StageEvent, h as StageEventType, e as StagePose, i as StageRicochetDim, j as StageRicochetReflection, k as StageTopDownPlane, f as StageWasmExports, p as WasmStageRuntime, W as WasmStageRuntimeOptions, q as createWasmStageRuntime } from './entity-DNkYKfdp.js';
5
- import { a as Vec3Input } from './material-Wz83vTTp.js';
6
- import './base-node-life-cycle-CnJ-7zX-.js';
1
+ import { StageBodyKindValue, StageBodyConfig, StageColliderConfig } from '@zylem/behaviors/core';
2
+ export { BehaviorRuntime, EntityDefinition, EntityHandle, Simulation, SimulationBodyDefinition, SimulationColliderDefinition, SimulationEvent, SimulationFrame, SimulationOptions, StageBodyConfig, StageBodyInfo, StageBodyKind, StageBodyKindValue, StageBoundaryDim, StageColliderConfig, StageColliderShape, StageDebugRender, StageEvent, StageEventType, StagePose, StageRaycastHit, StageRenderSlot, StageRicochetDim, StageRicochetReflection, StageTopDownPlane, createSimulation } from '@zylem/behaviors/core';
3
+ import { e as Vec3Input } from './vector-DN6zlPoE.js';
4
+ export { l as SimulationBody, S as SimulationStepClock } from './vector-DN6zlPoE.js';
5
+ export { p as packCollisionGroups } from './collision-builder-B_tm8OVy.js';
7
6
  import 'three';
8
- import './world-C9zdyl5d.js';
9
- import '@dimforge/rapier3d-compat';
10
- import 'three/webgpu';
11
- import './events.js';
12
- import 'mitt';
13
- import '@zylem/behaviors/core';
14
-
15
- /**
16
- * Helpers for the `@zylem/runtime` wasm module: batched Float32 input/render/summary buffers.
17
- * Consumers bundle the `.wasm` file (e.g. Vite `?url`) and pass bytes or a fetch URL to {@link loadZylemRuntimeWasm}.
18
- */
19
- /** Matches `INPUT_STRIDE` in `zylem-runtime` Rust. */
20
- declare const ZYLEM_RUNTIME_INPUT_STRIDE = 9;
21
- /** Matches `RENDER_STRIDE` in `zylem-runtime` Rust. */
22
- declare const ZYLEM_RUNTIME_RENDER_STRIDE = 12;
23
- /** Matches `SUMMARY_LEN` in `zylem-runtime` Rust. */
24
- declare const ZYLEM_RUNTIME_SUMMARY_LEN = 6;
25
- interface ZylemRuntimeExports {
26
- readonly memory: WebAssembly.Memory;
27
- zylem_runtime_init(capacity: number, initialActive: number): number;
28
- zylem_runtime_clear_static_box_colliders(): void;
29
- zylem_runtime_add_static_box_collider(centerX: number, centerY: number, centerZ: number, halfExtentX: number, halfExtentY: number, halfExtentZ: number, friction: number, restitution: number): void;
30
- zylem_runtime_bootstrap_instancing(halfExtentX: number, halfExtentY: number, halfExtentZ: number): number;
31
- zylem_runtime_gameplay2d_clear_config(): void;
32
- zylem_runtime_gameplay2d_set_world_bounds(left: number, right: number, bottom: number, top: number): void;
33
- zylem_runtime_configure_dynamic_circle_body2d(slot: number, radius: number, initialVelocityX: number, initialVelocityY: number, minSpeed: number, maxSpeed: number, speedMultiplier: number, maxAngleDeg: number, reflectionMode: number, usesBoundary2d: number, usesRicochet2d: number): number;
34
- zylem_runtime_configure_kinematic_aabb_body2d(slot: number, playerIndex: number, speed: number, halfWidth: number, halfHeight: number): number;
35
- zylem_runtime_gameplay2d_add_trigger_aabb(triggerId: number, centerX: number, centerY: number, centerZ: number, halfWidth: number, halfHeight: number): void;
36
- zylem_runtime_bootstrap_gameplay2d(): number;
37
- zylem_runtime_gameplay2d_set_input_axis(playerIndex: number, vertical: number): void;
38
- zylem_runtime_gameplay2d_set_slot_position(slot: number, x: number, y: number, z: number): void;
39
- zylem_runtime_gameplay2d_set_slot_velocity(slot: number, x: number, y: number): void;
40
- zylem_runtime_step(dt: number): number;
41
- zylem_runtime_active_count(): number;
42
- zylem_runtime_tick_count(): number;
43
- zylem_runtime_activate_next(): number;
44
- zylem_runtime_input_stride(): number;
45
- zylem_runtime_render_stride(): number;
46
- zylem_runtime_summary_len(): number;
47
- zylem_runtime_input_ptr(): number;
48
- zylem_runtime_input_len(): number;
49
- zylem_runtime_render_ptr(): number;
50
- zylem_runtime_render_len(): number;
51
- zylem_runtime_summary_ptr(): number;
52
- zylem_runtime_summary_buffer_len(): number;
53
- zylem_runtime_event_stride(): number;
54
- zylem_runtime_event_ptr(): number;
55
- zylem_runtime_event_len(): number;
56
- zylem_runtime_event_count(): number;
57
- zylem_runtime_gameplay3d_clear_config(): void;
58
- zylem_runtime_configure_platformer_capsule_body3d(slot: number, halfHeight: number, radius: number): number;
59
- zylem_runtime_configure_platformer_3d(slot: number, walkSpeed: number, runSpeed: number, jumpForce: number, maxJumps: number, gravity: number, coyoteTime: number, jumpBufferTime: number, jumpCutMultiplier: number, multiJumpWindow: number, maxSlopeDeg: number, autostepHeight: number, snapToGround: number): number;
60
- zylem_runtime_bootstrap_gameplay3d(): number;
61
- zylem_runtime_gameplay3d_set_input_axes(slot: number, moveX: number, moveZ: number): void;
62
- zylem_runtime_gameplay3d_set_input_buttons(slot: number, jump: number, run: number): void;
63
- zylem_runtime_gameplay3d_set_slot_position(slot: number, x: number, y: number, z: number): void;
64
- zylem_runtime_gameplay3d_grounded(slot: number): number;
65
- zylem_runtime_gameplay3d_jump_count(slot: number): number;
66
- zylem_runtime_gameplay3d_state(slot: number): number;
67
- zylem_runtime_gameplay3d_event_ptr(): number;
68
- zylem_runtime_gameplay3d_event_len(): number;
69
- zylem_runtime_gameplay3d_event_count(): number;
70
- zylem_runtime_heightfield_scratch_ptr(): number;
71
- zylem_runtime_heightfield_scratch_capacity(): number;
72
- zylem_runtime_clear_static_heightfield_colliders(): void;
73
- zylem_runtime_add_static_heightfield_collider(rows: number, cols: number, heightsLen: number, scaleX: number, scaleY: number, scaleZ: number, translationX: number, translationY: number, translationZ: number, friction: number, restitution: number): number;
74
- zylem_runtime_gameplay3d_debug_render(): number;
75
- zylem_runtime_gameplay3d_debug_vertices_ptr(): number;
76
- zylem_runtime_gameplay3d_debug_colors_ptr(): number;
77
- }
78
- interface ZylemRuntimeBufferViews {
79
- readonly exports: ZylemRuntimeExports;
80
- /** Input slot buffer (host → Rust), length `inputLen` floats. */
81
- inputView: Float32Array;
82
- /** Render slot buffer (Rust → host), length `renderLen` floats. */
83
- renderView: Float32Array;
84
- /** Aggregates (Rust → host), length `summaryLen` floats. */
85
- summaryView: Float32Array;
86
- inputStride: number;
87
- renderStride: number;
88
- summaryLen: number;
89
- inputLen: number;
90
- renderLen: number;
91
- eventStride: number;
92
- eventView: Float32Array;
93
- eventLen: number;
94
- /**
95
- * Gameplay3D event buffer view. Backed by `zylem_runtime_gameplay3d_event_*`
96
- * exports. Populated only after the runtime switches into Gameplay3D mode.
97
- */
98
- gameplay3dEventView: Float32Array;
99
- gameplay3dEventLen: number;
100
- /**
101
- * Recreate typed views after init or if `memory.buffer` was resized.
102
- * Call after {@link ZylemRuntimeExports.zylem_runtime_init} and whenever the wasm memory grows.
103
- */
104
- refreshViews(): void;
105
- }
106
- interface ZylemRuntimeStaticBoxCollider {
107
- center: readonly [number, number, number];
108
- halfExtents: readonly [number, number, number];
109
- friction?: number;
110
- restitution?: number;
111
- }
112
- interface ZylemRuntimeGameplay2DWorldBounds {
113
- left: number;
114
- right: number;
115
- bottom: number;
116
- top: number;
117
- }
118
- interface ZylemRuntimeDynamicCircleBody2DConfig {
119
- slot: number;
120
- position: readonly [number, number, number];
121
- radius: number;
122
- initialVelocity: readonly [number, number];
123
- minSpeed: number;
124
- maxSpeed: number;
125
- speedMultiplier: number;
126
- maxAngleDeg: number;
127
- reflectionMode: 'simple' | 'angled';
128
- /** Enables top/bottom boundary reflection in gameplay2d. */
129
- usesBoundary2d: boolean;
130
- /** Enables circle-vs-kinematic-AABB ricochet. */
131
- usesRicochet2d: boolean;
132
- }
133
- interface ZylemRuntimeKinematicAabbBody2DConfig {
134
- slot: number;
135
- position: readonly [number, number, number];
136
- playerIndex: number;
137
- speed: number;
138
- halfExtents: readonly [number, number];
139
- }
140
- /** World-space trigger strip in XY (gameplay2d); does not consume a body slot. */
141
- interface ZylemRuntimeGameplay2DTriggerAabb {
142
- /** Stable id returned on {@link ZylemRuntimeEventType.RegionEntered} as `secondarySlot` (keep small integers for f32 event buffers). */
143
- triggerId: number;
144
- position: readonly [number, number, number];
145
- halfExtents: readonly [number, number];
146
- }
147
- interface ZylemRuntimeGameplay2DConfig {
148
- bounds: ZylemRuntimeGameplay2DWorldBounds;
149
- dynamicCircles: ReadonlyArray<ZylemRuntimeDynamicCircleBody2DConfig>;
150
- kinematicAabbs: ReadonlyArray<ZylemRuntimeKinematicAabbBody2DConfig>;
151
- /** Optional sensor regions: wasm emits {@link ZylemRuntimeEventType.RegionEntered} when the dynamic circle enters (edge-triggered). Game rules stay in TS. */
152
- triggerAabbs?: ReadonlyArray<ZylemRuntimeGameplay2DTriggerAabb>;
153
- }
154
- declare const ZYLEM_RUNTIME_EVENT_STRIDE = 4;
155
- declare const enum ZylemRuntimeEventType {
156
- BoundaryBounce = 1,
157
- ColliderBounce = 2,
158
- RegionEntered = 3,
159
- /** Platformer3D applied a jump impulse. `secondarySlot` is `jumpCount`. */
160
- JumpStarted = 4,
161
- /** Platformer3D landed (was airborne, now grounded). */
162
- Landed = 5
163
- }
164
- interface ZylemRuntimeEvent {
165
- type: ZylemRuntimeEventType;
166
- primarySlot: number;
167
- secondarySlot: number;
168
- aux: number;
169
- }
170
- interface ZylemRuntimeInstancedBatchConfig {
171
- positions: ReadonlyArray<readonly [number, number, number]>;
172
- halfExtents: readonly [number, number, number];
173
- staticColliders?: ReadonlyArray<ZylemRuntimeStaticBoxCollider>;
174
- }
175
- /** Capsule shape config for a Gameplay3D platformer body. */
176
- interface ZylemRuntimePlatformerCapsuleConfig {
177
- slot: number;
178
- position: readonly [number, number, number];
179
- halfHeight: number;
180
- radius: number;
181
- }
182
- /**
183
- * Tunable platformer movement parameters. Maps 1:1 to Rust's
184
- * `Platformer3DConfig`. All time values are in seconds.
185
- */
186
- interface ZylemRuntimePlatformer3DConfig {
187
- slot: number;
188
- walkSpeed: number;
189
- runSpeed: number;
190
- jumpForce: number;
191
- maxJumps: number;
192
- gravity: number;
193
- coyoteTime: number;
194
- jumpBufferTime: number;
195
- jumpCutMultiplier: number;
196
- multiJumpWindow: number;
197
- maxSlopeDeg: number;
198
- autostepHeight: number;
199
- snapToGround: number;
200
- }
201
- interface ZylemRuntimeGameplay3DConfig {
202
- capsules: ReadonlyArray<ZylemRuntimePlatformerCapsuleConfig>;
203
- platformers: ReadonlyArray<ZylemRuntimePlatformer3DConfig>;
204
- staticColliders?: ReadonlyArray<ZylemRuntimeStaticBoxCollider>;
205
- }
206
- /**
207
- * Instantiates the zylem-runtime wasm module.
208
- */
209
- declare function loadZylemRuntimeWasm(source: RequestInfo | URL | ArrayBuffer, imports?: WebAssembly.Imports): Promise<{
210
- instance: WebAssembly.Instance;
211
- exports: ZylemRuntimeExports;
212
- }>;
213
- /**
214
- * Wraps buffer pointer/length exports as {@link Float32Array} views. Strides are read from the module after init.
215
- */
216
- declare function attachZylemRuntimeBufferViews(exports: ZylemRuntimeExports): ZylemRuntimeBufferViews;
217
- /**
218
- * Writes one input slot: position (3), rotation (4), contacts (1), speed (1).
219
- * `values` must have length 9 (or use {@link writeInputSlotFromParts}).
220
- */
221
- declare function writeInputSlot(view: Float32Array, stride: number, slotIndex: number, values: readonly number[]): void;
222
- declare function writeInputSlotFromParts(view: Float32Array, stride: number, slotIndex: number, parts: {
223
- position: readonly [number, number, number];
224
- rotation: readonly [number, number, number, number];
225
- contacts: number;
226
- speed: number;
227
- }): void;
228
- interface ZylemRenderSlot {
229
- position: [number, number, number];
230
- rotation: [number, number, number, number];
231
- scaleMultiplier: number;
232
- contactCount: number;
233
- heat: number;
234
- speed: number;
235
- }
236
- /**
237
- * Reads one render slot from the post-step render buffer.
238
- */
239
- declare function readRenderSlot(view: Float32Array, stride: number, slotIndex: number): ZylemRenderSlot;
240
- interface ZylemSummarySnapshot {
241
- entityCount: number;
242
- collidingEntities: number;
243
- totalContacts: number;
244
- averageHeat: number;
245
- maxHeat: number;
246
- maxContacts: number;
247
- }
248
- /**
249
- * Reads the summary buffer (6 floats).
250
- */
251
- declare function readSummary(view: Float32Array): ZylemSummarySnapshot;
252
- /**
253
- * Initializes wasm, runs `zylem_runtime_init`, and returns typed exports plus buffer views.
254
- */
255
- declare function createZylemRuntimeSession(source: RequestInfo | URL | ArrayBuffer, capacity: number, initialActive: number, imports?: WebAssembly.Imports): Promise<ZylemRuntimeBufferViews>;
256
- declare function bootstrapZylemRuntimeGameplay2D(buffers: ZylemRuntimeBufferViews, config: ZylemRuntimeGameplay2DConfig): ZylemRuntimeBufferViews;
257
- declare function createZylemRuntimeGameplay2DSession(source: RequestInfo | URL | ArrayBuffer, capacity: number, config: ZylemRuntimeGameplay2DConfig, imports?: WebAssembly.Imports): Promise<ZylemRuntimeBufferViews>;
258
- declare function setZylemRuntimeGameplay2DInputAxis(buffers: ZylemRuntimeBufferViews, playerIndex: number, vertical: number): void;
259
- declare function setZylemRuntimeGameplay2DSlotPosition(buffers: ZylemRuntimeBufferViews, slot: number, x: number, y: number, z: number): void;
260
- declare function setZylemRuntimeGameplay2DSlotVelocity(buffers: ZylemRuntimeBufferViews, slot: number, x: number, y: number): void;
261
- declare function readZylemRuntimeEvents(buffers: ZylemRuntimeBufferViews): ZylemRuntimeEvent[];
262
- /**
263
- * Writes initial positions to the input buffer and boots the runtime into instancing mode.
264
- */
265
- declare function bootstrapZylemRuntimeInstancing(buffers: ZylemRuntimeBufferViews, config: ZylemRuntimeInstancedBatchConfig): ZylemRuntimeBufferViews;
266
- /**
267
- * Creates a runtime session configured from a set of explicit instanced entity positions.
268
- */
269
- declare function createZylemRuntimeInstancedBatchSession(source: RequestInfo | URL | ArrayBuffer, config: ZylemRuntimeInstancedBatchConfig, imports?: WebAssembly.Imports): Promise<ZylemRuntimeBufferViews>;
270
- /**
271
- * Pushes capsule + platformer config to wasm. Does NOT switch the simulation
272
- * mode — call {@link bootstrapZylemRuntimeGameplay3D} after writing initial
273
- * positions to the input buffer.
274
- */
275
- declare function configureZylemRuntimePlatformer3D(buffers: ZylemRuntimeBufferViews, config: ZylemRuntimeGameplay3DConfig): void;
276
- /**
277
- * Writes initial capsule positions to the input buffer, registers static box
278
- * colliders, configures platformer/capsule bodies, and switches the runtime
279
- * into Gameplay3D mode. Returns the same buffers with views refreshed.
280
- */
281
- declare function bootstrapZylemRuntimeGameplay3D(buffers: ZylemRuntimeBufferViews, config: ZylemRuntimeGameplay3DConfig): ZylemRuntimeBufferViews;
282
- /**
283
- * Convenience wrapper that loads wasm, sizes the runtime to fit the provided
284
- * capsules, and bootstraps Gameplay3D in one call.
285
- */
286
- declare function createZylemRuntimeGameplay3DSession(source: RequestInfo | URL | ArrayBuffer, config: ZylemRuntimeGameplay3DConfig, imports?: WebAssembly.Imports): Promise<ZylemRuntimeBufferViews>;
287
- declare function setZylemRuntimeGameplay3DInputAxes(buffers: ZylemRuntimeBufferViews, slot: number, moveX: number, moveZ: number): void;
288
- declare function setZylemRuntimeGameplay3DInputButtons(buffers: ZylemRuntimeBufferViews, slot: number, jump: boolean, run: boolean): void;
289
- declare function setZylemRuntimeGameplay3DSlotPosition(buffers: ZylemRuntimeBufferViews, slot: number, x: number, y: number, z: number): void;
290
- declare function getZylemRuntimeGameplay3DGrounded(buffers: ZylemRuntimeBufferViews, slot: number): boolean;
291
- declare function getZylemRuntimeGameplay3DJumpCount(buffers: ZylemRuntimeBufferViews, slot: number): number;
292
- /**
293
- * Animation-facing platformer states surfaced from the wasm runtime FSM.
294
- * Discriminants are stable and match `Platformer3DFsmState` in
295
- * `packages/zylem-runtime/src/runtime/behaviors/platformer_3d/fsm.rs` —
296
- * never reorder.
297
- */
298
- declare enum ZylemRuntimePlatformer3DFsmState {
299
- Idle = 0,
300
- Walking = 1,
301
- Running = 2,
302
- Jumping = 3,
303
- Falling = 4,
304
- Landing = 5
305
- }
306
- /**
307
- * Reads the current animation FSM state for a Gameplay3D platformer slot.
308
- * Returns {@link ZylemRuntimePlatformer3DFsmState.Idle} when the simulation
309
- * is not in Gameplay3D mode or the slot is out of range.
310
- */
311
- declare function getZylemRuntimeGameplay3DState(buffers: ZylemRuntimeBufferViews, slot: number): ZylemRuntimePlatformer3DFsmState;
312
- /**
313
- * Configuration for a static heightfield collider passed to the wasm
314
- * runtime. Mirrors the TS Rapier plane layout used by `playgroundPlane`
315
- * (see `PlaneMeshBuilder.postBuild`):
316
- *
317
- * - `rows` is the number of X subdivisions (so the X vertex count is
318
- * `rows + 1`).
319
- * - `cols` is the number of Z subdivisions.
320
- * - `heights` must have exactly `(rows + 1) * (cols + 1)` entries laid
321
- * out outer-x, inner-z, i.e. `heights[xIdx * (cols + 1) + zIdx]`.
322
- * - `scale` is `[tileX, heightScale, tileZ]`.
323
- * - `translation` shifts the heightfield in world space (heightfield
324
- * vertex y=0 maps to `translation[1]`).
325
- */
326
- interface ZylemRuntimeStaticHeightfieldCollider {
327
- rows: number;
328
- cols: number;
329
- heights: Float32Array;
330
- scale: readonly [number, number, number];
331
- translation: readonly [number, number, number];
332
- friction?: number;
333
- restitution?: number;
334
- }
335
- /**
336
- * Stages `cfg.heights` into the wasm heightfield scratch buffer and
337
- * registers a pending heightfield collider. Must be called after wasm
338
- * `init` and before `zylem_runtime_bootstrap_gameplay3d`. Throws if the
339
- * heights array exceeds the scratch capacity or its length doesn't match
340
- * `(rows + 1) * (cols + 1)`.
341
- */
342
- declare function addZylemRuntimeStaticHeightfieldCollider(exports: ZylemRuntimeExports, memory: WebAssembly.Memory, cfg: ZylemRuntimeStaticHeightfieldCollider): void;
343
- /**
344
- * Result of a Gameplay3D debug-render snapshot. Both views are fresh
345
- * `Float32Array`s over the wasm memory, sliced to the populated prefix.
346
- *
347
- * - `vertices` is `vertexCount * 3` floats laid out as
348
- * `[x, y, z, x, y, z, ...]` with consecutive *pairs* forming line
349
- * segments (matching the layout of TS Rapier's `world.debugRender()`).
350
- * - `colors` is `vertexCount * 4` floats laid out as
351
- * `[r, g, b, a, r, g, b, a, ...]` already converted from rapier's HSLA
352
- * palette so it can be fed directly into a `LineBasicMaterial` with
353
- * `vertexColors: true`.
354
- */
355
- interface ZylemRuntimeGameplay3DDebugRender {
356
- vertices: Float32Array;
357
- colors: Float32Array;
358
- vertexCount: number;
359
- }
360
- /**
361
- * Refreshes the wasm Gameplay3D debug-render buffers from the current
362
- * Rapier world, then returns fresh `Float32Array` views over them.
363
- * Returns `null` when the simulation is not in Gameplay3D mode or there
364
- * are no lines to draw. Views are always reconstructed from the current
365
- * `memory.buffer` so they stay valid across wasm memory growth.
366
- */
367
- declare function getZylemRuntimeGameplay3DDebugRender(exports: ZylemRuntimeExports, memory: WebAssembly.Memory): ZylemRuntimeGameplay3DDebugRender | null;
368
- /**
369
- * Reads the Gameplay3D event buffer (JumpStarted / Landed) for the most
370
- * recent step. Mirrors {@link readZylemRuntimeEvents} but pulls from the
371
- * dedicated 3D buffer; refreshes views first in case wasm memory grew.
372
- */
373
- declare function readZylemRuntimeGameplay3DEvents(buffers: ZylemRuntimeBufferViews): ZylemRuntimeEvent[];
374
-
375
- /**
376
- * Binds wasm runtime diagnostics to global {@link debugState.enabled} (from `createGame({ debug })`).
377
- * Pass via stage `runtimeDebugBinding` or rely on {@link ZylemGame} default after load.
378
- */
379
- declare function createRuntimeDebugBindingFromDebugState(): RuntimeDebugBinding;
380
7
 
381
8
  /**
382
9
  * Runtime-side collision builder. Emits plain `BodyConfig` + `ColliderConfig`
@@ -393,7 +20,7 @@ declare function createRuntimeDebugBindingFromDebugState(): RuntimeDebugBinding;
393
20
 
394
21
  /** Body-level options the host can override per entity. */
395
22
  interface RuntimeBodyOptions {
396
- kind?: StageBodyKind;
23
+ kind?: StageBodyKindValue;
397
24
  position?: Vec3Input;
398
25
  rotation?: readonly [number, number, number, number];
399
26
  linearDamping?: number;
@@ -414,7 +41,6 @@ interface RuntimeColliderOptions {
414
41
  collisionFilter?: string[];
415
42
  }
416
43
  declare function buildRuntimeBody(options?: RuntimeBodyOptions): StageBodyConfig;
417
- declare function packCollisionGroups(collisionType?: string, collisionFilter?: string[]): number;
418
44
  /** Cuboid collider sized as `size.xyz` (full extents — half-extents are computed). */
419
45
  declare function buildBoxCollider(size: Vec3Input, options?: RuntimeColliderOptions): StageColliderConfig;
420
46
  declare function buildSphereCollider(radius: number, options?: RuntimeColliderOptions): StageColliderConfig;
@@ -430,4 +56,4 @@ interface RuntimeCollisionBundle {
430
56
  }
431
57
  declare function bundleRuntimeCollision(body: StageBodyConfig, colliders: StageColliderConfig[]): RuntimeCollisionBundle;
432
58
 
433
- export { type RuntimeBodyOptions, type RuntimeColliderOptions, type RuntimeCollisionBundle, RuntimeDebugBinding, StageBodyConfig, StageBodyKind, StageColliderConfig, ZYLEM_RUNTIME_EVENT_STRIDE, ZYLEM_RUNTIME_INPUT_STRIDE, ZYLEM_RUNTIME_RENDER_STRIDE, ZYLEM_RUNTIME_SUMMARY_LEN, type ZylemRenderSlot, type ZylemRuntimeBufferViews, type ZylemRuntimeDynamicCircleBody2DConfig, type ZylemRuntimeEvent, ZylemRuntimeEventType, type ZylemRuntimeExports, type ZylemRuntimeGameplay2DConfig, type ZylemRuntimeGameplay2DTriggerAabb, type ZylemRuntimeGameplay2DWorldBounds, type ZylemRuntimeGameplay3DConfig, type ZylemRuntimeGameplay3DDebugRender, type ZylemRuntimeInstancedBatchConfig, type ZylemRuntimeKinematicAabbBody2DConfig, type ZylemRuntimePlatformer3DConfig, ZylemRuntimePlatformer3DFsmState, type ZylemRuntimePlatformerCapsuleConfig, type ZylemRuntimeStaticBoxCollider, type ZylemRuntimeStaticHeightfieldCollider, type ZylemSummarySnapshot, addZylemRuntimeStaticHeightfieldCollider, attachZylemRuntimeBufferViews, bootstrapZylemRuntimeGameplay2D, bootstrapZylemRuntimeGameplay3D, bootstrapZylemRuntimeInstancing, buildBoxCollider, buildCapsuleCollider, buildConvexHullCollider, buildCylinderCollider, buildHeightfieldCollider, buildRuntimeBody, buildSphereCollider, buildTrimeshCollider, bundleRuntimeCollision, configureZylemRuntimePlatformer3D, createRuntimeDebugBindingFromDebugState, createZylemRuntimeGameplay2DSession, createZylemRuntimeGameplay3DSession, createZylemRuntimeInstancedBatchSession, createZylemRuntimeSession, getZylemRuntimeGameplay3DDebugRender, getZylemRuntimeGameplay3DGrounded, getZylemRuntimeGameplay3DJumpCount, getZylemRuntimeGameplay3DState, loadZylemRuntimeWasm, packCollisionGroups, readRenderSlot, readSummary, readZylemRuntimeEvents, readZylemRuntimeGameplay3DEvents, setZylemRuntimeGameplay2DInputAxis, setZylemRuntimeGameplay2DSlotPosition, setZylemRuntimeGameplay2DSlotVelocity, setZylemRuntimeGameplay3DInputAxes, setZylemRuntimeGameplay3DInputButtons, setZylemRuntimeGameplay3DSlotPosition, writeInputSlot, writeInputSlotFromParts };
59
+ export { type RuntimeBodyOptions, type RuntimeColliderOptions, type RuntimeCollisionBundle, buildBoxCollider, buildCapsuleCollider, buildConvexHullCollider, buildCylinderCollider, buildHeightfieldCollider, buildRuntimeBody, buildSphereCollider, buildTrimeshCollider, bundleRuntimeCollision };
package/dist/runtime.js CHANGED
@@ -1 +1 @@
1
- import{a as te,b as ge,c as he,d as Re,e as xe,f as Se,g as Ee,h as Ce,i as Ze,j as we,k as Be,l as ve,m as De,n as Me}from"./chunk-A34ZG3L4.js";import"./chunk-CDPY4VOQ.js";import{a as Q,b as ee}from"./chunk-73VZQZUL.js";import"./chunk-YHKXQ2ZN.js";import{b as X,c as M,d as I,g as $,h}from"./chunk-G2IIMSUH.js";var Ie=9,ze=12,Ae=6,Ve=4,L=(o=>(o[o.BoundaryBounce=1]="BoundaryBounce",o[o.ColliderBounce=2]="ColliderBounce",o[o.RegionEntered=3]="RegionEntered",o[o.JumpStarted=4]="JumpStarted",o[o.Landed=5]="Landed",o))(L||{});async function ne(e,n={}){let t;e instanceof ArrayBuffer?t=e:t=await(await fetch(e)).arrayBuffer();let{instance:i}=await WebAssembly.instantiate(t,n),r=i.exports;return{instance:i,exports:r}}function ie(e){let n=e.zylem_runtime_input_stride(),t=e.zylem_runtime_render_stride(),i=e.zylem_runtime_summary_len(),r,o,a,p=0,s=0,u=new Float32Array(0),m=0,c=new Float32Array(0),b=0,l=e.zylem_runtime_event_stride();function R(){let _=e.memory.buffer,y=e.zylem_runtime_input_ptr(),f=e.zylem_runtime_input_len(),Z=e.zylem_runtime_render_ptr(),C=e.zylem_runtime_render_len(),w=e.zylem_runtime_summary_ptr(),B=e.zylem_runtime_summary_buffer_len(),v=e.zylem_runtime_event_ptr(),x=e.zylem_runtime_event_len(),D=e.zylem_runtime_gameplay3d_event_ptr(),S=e.zylem_runtime_gameplay3d_event_len();p=f,s=C,m=x,b=S,r=new Float32Array(_,y,f),o=new Float32Array(_,Z,C),a=new Float32Array(_,w,B),u=x>0?new Float32Array(_,v,x):new Float32Array(0),c=S>0?new Float32Array(_,D,S):new Float32Array(0)}return R(),{exports:e,get inputView(){return r},get renderView(){return o},get summaryView(){return a},inputStride:n,renderStride:t,summaryLen:i,get inputLen(){return p},get renderLen(){return s},eventStride:l,get eventView(){return u},get eventLen(){return m},get gameplay3dEventView(){return c},get gameplay3dEventLen(){return b},refreshViews:R}}function Ge(e,n,t,i){let r=t*n;if(i.length<n)throw new Error(`writeInputSlot: expected at least ${n} values, got ${i.length}`);for(let o=0;o<n;o++)e[r+o]=i[o]}function Te(e,n,t,i){let r=t*n;e[r]=i.position[0],e[r+1]=i.position[1],e[r+2]=i.position[2],e[r+3]=i.rotation[0],e[r+4]=i.rotation[1],e[r+5]=i.rotation[2],e[r+6]=i.rotation[3],e[r+7]=i.contacts,e[r+8]=i.speed}function H(e,n,t){let i=t*n;return{position:[e[i],e[i+1],e[i+2]],rotation:[e[i+3],e[i+4],e[i+5],e[i+6]],scaleMultiplier:e[i+7],contactCount:e[i+8],heat:e[i+9],speed:e[i+10]}}function ke(e){return{entityCount:e[0],collidingEntities:e[1],totalContacts:e[2],averageHeat:e[3],maxHeat:e[4],maxContacts:e[5]}}async function V(e,n,t,i){let{exports:r}=await ne(e,i);if(n===0)throw new Error("createZylemRuntimeSession: capacity must be > 0");r.zylem_runtime_init(n,t);let o=ie(r);if(o.refreshViews(),o.inputLen===0)throw new Error("zylem_runtime_init did not allocate buffers");return o}function Oe(e,n){e.exports.zylem_runtime_gameplay2d_clear_config(),e.exports.zylem_runtime_gameplay2d_set_world_bounds(n.bounds.left,n.bounds.right,n.bounds.bottom,n.bounds.top);for(let t of n.dynamicCircles)e.exports.zylem_runtime_configure_dynamic_circle_body2d(t.slot,t.radius,t.initialVelocity[0],t.initialVelocity[1],t.minSpeed,t.maxSpeed,t.speedMultiplier,t.maxAngleDeg,t.reflectionMode==="angled"?1:0,t.usesBoundary2d?1:0,t.usesRicochet2d?1:0);for(let t of n.kinematicAabbs)e.exports.zylem_runtime_configure_kinematic_aabb_body2d(t.slot,t.playerIndex,t.speed,t.halfExtents[0],t.halfExtents[1]);for(let t of n.triggerAabbs??[])e.exports.zylem_runtime_gameplay2d_add_trigger_aabb(t.triggerId>>>0,t.position[0],t.position[1],t.position[2],t.halfExtents[0],t.halfExtents[1])}function re(e,n){e.inputView.fill(0);for(let t of n.dynamicCircles){let i=t.slot*e.inputStride;e.inputView[i]=t.position[0],e.inputView[i+1]=t.position[1],e.inputView[i+2]=t.position[2],e.inputView[i+6]=1,e.inputView[i+7]=t.radius,e.inputView[i+8]=t.radius}for(let t of n.kinematicAabbs){let i=t.slot*e.inputStride;e.inputView[i]=t.position[0],e.inputView[i+1]=t.position[1],e.inputView[i+2]=t.position[2],e.inputView[i+6]=1,e.inputView[i+7]=t.halfExtents[0],e.inputView[i+8]=t.halfExtents[1]}return Oe(e,n),e.exports.zylem_runtime_bootstrap_gameplay2d(),e.exports.zylem_runtime_step(0),e.refreshViews(),e}async function N(e,n,t,i){let r=await V(e,n,n,i);return re(r,t)}function G(e,n,t){e.exports.zylem_runtime_gameplay2d_set_input_axis(n,t)}function U(e,n,t,i,r){e.exports.zylem_runtime_gameplay2d_set_slot_position(n,t,i,r)}function P(e,n,t,i){e.exports.zylem_runtime_gameplay2d_set_slot_velocity(n,t,i)}function F(e){let n=e.exports.zylem_runtime_event_count(),t=[];for(let i=0;i<n;i++){let r=i*e.eventStride;t.push({type:e.eventView[r],primarySlot:e.eventView[r+1],secondarySlot:e.eventView[r+2],aux:e.eventView[r+3]})}return t}function oe(e,n){if(n.positions.length===0)throw new Error("bootstrapZylemRuntimeInstancing: positions must not be empty");if(e.inputStride<9)throw new Error("bootstrapZylemRuntimeInstancing: input stride is smaller than expected");if(e.inputLen<n.positions.length*e.inputStride)throw new Error("bootstrapZylemRuntimeInstancing: input buffer is too small for positions");e.inputView.fill(0);for(let t=0;t<n.positions.length;t++){let i=t*e.inputStride,r=n.positions[t];e.inputView[i]=r[0],e.inputView[i+1]=r[1],e.inputView[i+2]=r[2],e.inputView[i+6]=1}e.exports.zylem_runtime_clear_static_box_colliders();for(let t of n.staticColliders??[])e.exports.zylem_runtime_add_static_box_collider(t.center[0],t.center[1],t.center[2],t.halfExtents[0],t.halfExtents[1],t.halfExtents[2],t.friction??.95,t.restitution??.05);return e.exports.zylem_runtime_bootstrap_instancing(n.halfExtents[0],n.halfExtents[1],n.halfExtents[2]),e.exports.zylem_runtime_step(0),e.refreshViews(),e}async function Y(e,n,t){let i=await V(e,n.positions.length,n.positions.length,t);return oe(i,n)}function ae(e,n){e.exports.zylem_runtime_gameplay3d_clear_config();for(let t of n.capsules)e.exports.zylem_runtime_configure_platformer_capsule_body3d(t.slot,Math.max(t.halfHeight,.01),Math.max(t.radius,.01));for(let t of n.platformers)e.exports.zylem_runtime_configure_platformer_3d(t.slot,t.walkSpeed,t.runSpeed,t.jumpForce,t.maxJumps>>>0,t.gravity,t.coyoteTime,t.jumpBufferTime,t.jumpCutMultiplier,t.multiJumpWindow,t.maxSlopeDeg,t.autostepHeight,t.snapToGround)}function me(e,n){if(n.capsules.length===0)throw new Error("bootstrapZylemRuntimeGameplay3D: at least one capsule must be provided");if(e.inputStride<9)throw new Error("bootstrapZylemRuntimeGameplay3D: input stride is smaller than expected");e.inputView.fill(0);for(let t of n.capsules){let i=t.slot*e.inputStride;e.inputView[i]=t.position[0],e.inputView[i+1]=t.position[1],e.inputView[i+2]=t.position[2],e.inputView[i+6]=1}e.exports.zylem_runtime_clear_static_box_colliders();for(let t of n.staticColliders??[])e.exports.zylem_runtime_add_static_box_collider(t.center[0],t.center[1],t.center[2],t.halfExtents[0],t.halfExtents[1],t.halfExtents[2],t.friction??.95,t.restitution??0);return ae(e,n),e.exports.zylem_runtime_bootstrap_gameplay3d(),e.exports.zylem_runtime_step(0),e.refreshViews(),e}async function Le(e,n,t){let i=Math.max(...n.capsules.map(o=>o.slot))+1,r=await V(e,i,i,t);return me(r,n)}function He(e,n,t,i){e.exports.zylem_runtime_gameplay3d_set_input_axes(n,t,i)}function Ne(e,n,t,i){e.exports.zylem_runtime_gameplay3d_set_input_buttons(n,t?1:0,i?1:0)}function Ue(e,n,t,i,r){e.exports.zylem_runtime_gameplay3d_set_slot_position(n,t,i,r)}function Pe(e,n){return e.exports.zylem_runtime_gameplay3d_grounded(n)!==0}function Fe(e,n){return e.exports.zylem_runtime_gameplay3d_jump_count(n)>>>0}var le=(a=>(a[a.Idle=0]="Idle",a[a.Walking=1]="Walking",a[a.Running=2]="Running",a[a.Jumping=3]="Jumping",a[a.Falling=4]="Falling",a[a.Landing=5]="Landing",a))(le||{});function Ye(e,n){let t=e.exports.zylem_runtime_gameplay3d_state(n)>>>0;switch(t){case 1:case 2:case 3:case 4:case 5:return t;default:return 0}}function We(e,n,t){let i=(t.rows+1)*(t.cols+1);if(t.heights.length!==i)throw new Error(`addZylemRuntimeStaticHeightfieldCollider: heights length ${t.heights.length} != expected ${i} for rows=${t.rows} cols=${t.cols}`);let r=e.zylem_runtime_heightfield_scratch_capacity();if(t.heights.length>r)throw new Error(`addZylemRuntimeStaticHeightfieldCollider: heights length ${t.heights.length} exceeds wasm scratch capacity ${r}`);let o=e.zylem_runtime_heightfield_scratch_ptr();if(new Float32Array(n.buffer,o,r).set(t.heights),e.zylem_runtime_add_static_heightfield_collider(t.rows>>>0,t.cols>>>0,t.heights.length>>>0,t.scale[0],t.scale[1],t.scale[2],t.translation[0],t.translation[1],t.translation[2],t.friction??1,t.restitution??0)===0)throw new Error("addZylemRuntimeStaticHeightfieldCollider: wasm rejected the heightfield (rows/cols/length mismatch)")}function je(e,n){let t=e.zylem_runtime_gameplay3d_debug_render()>>>0;if(t===0)return null;let i=e.zylem_runtime_gameplay3d_debug_vertices_ptr(),r=e.zylem_runtime_gameplay3d_debug_colors_ptr();if(i===0||r===0)return null;let o=new Float32Array(n.buffer,i,t*3),a=new Float32Array(n.buffer,r,t*4);return{vertices:o,colors:a,vertexCount:t}}function qe(e){let n=e.exports.zylem_runtime_gameplay3d_event_count();if(n===0)return[];e.refreshViews();let t=e.gameplay3dEventView,i=[];for(let r=0;r<n;r++){let o=r*e.eventStride;i.push({type:t[o],primarySlot:t[o+1],secondarySlot:t[o+2],aux:t[o+3]})}return i}import{Color as ot}from"three";import{bindRuntimeDynamicCircleBody2DHandle as at,emitRuntimeRicochet as ye,emitRuntimeTriggerRegionEnter as mt,RUNTIME_BOUNDARY_2D_BEHAVIOR_KEY as fe,RUNTIME_DYNAMIC_CIRCLE_BODY_2D_BEHAVIOR_KEY as lt,RUNTIME_PLAYER_INPUT_2D_BEHAVIOR_KEY as st,RUNTIME_RICOCHET_2D_BEHAVIOR_KEY as ut,RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY as pe}from"@zylem/behaviors/runtime-2d";import{Color as z,InstancedBufferAttribute as $e,InstancedMesh as Qe,Matrix4 as et,MeshStandardMaterial as tt,Object3D as nt,Quaternion as it}from"three";import{MeshStandardNodeMaterial as q}from"three/webgpu";import{LinearSRGBColorSpace as se}from"three";import{attribute as Ke,clamp as Je,mix as Xe,vec3 as ue}from"three/tsl";var T="instanceHeat",W=16739133;function ce(e,n){let t={r:0,g:0,b:0};n.getRGB(t,se);let i={r:0,g:0,b:0};e.color.getRGB(i,se);let r=Je(Ke(T,"float"),0,1),o=ue(i.r,i.g,i.b),a=ue(t.r,t.g,t.b);e.colorNode=Xe(o,a,r),e.needsUpdate=!0}var k=class{batches=new Map;scene=null;setScene(n){this.scene=n}registerBatch(n){let t=this.batches.get(n.key);if(t)return t.instancedMesh;let i=n.geometry.clone(),r=j(n.material)?n.material.color:void 0,o=n.baseColor?.clone()??r?.clone()??new z(16777215),a=n.colorMode??"base",p=j(n.material),s=rt(n.material.clone(),o,a),u=a==="heatTint"&&p&&s instanceof q;u&&i.setAttribute(T,new $e(new Float32Array(n.count),1));let m=new Qe(i,s,n.count);m.count=n.count,m.frustumCulled=!1,m.castShadow=!0,m.receiveShadow=!0;let c=new et().makeScale(0,0,0);for(let l=0;l<n.count;l++)m.setMatrixAt(l,c);m.instanceMatrix.needsUpdate=!0;let b={key:n.key,instancedMesh:m,geometry:i,material:s,baseColor:o,colorMode:a,heatTintUsesInstanceHeatAttribute:u,dummy:new nt,rotation:new it,colorScratch:new z,hotColor:new z(W),prevTransforms:null,prevCount:0};return this.batches.set(n.key,b),this.scene?.add(m),m}updateBatch(n,t){let i=this.batches.get(n);if(!i)return;let r=i.dummy,o=i.rotation,a=i.colorScratch,p=i.heatTintUsesInstanceHeatAttribute?i.geometry.getAttribute(T):void 0,s=t.renderView,u=t.renderStride,m=t.exports.zylem_runtime_active_count();i.instancedMesh.count=m;let c=i.colorMode==="heatTint",b=i.prevCount!==m,l=i.prevTransforms;(!l||l.length<m*8)&&(l=new Float32Array(m*8),i.prevTransforms=l);let R=!1,_=!1;for(let y=0;y<m;y++){let f=y*u,Z=s[f],C=s[f+1],w=s[f+2],B=s[f+3],v=s[f+4],x=s[f+5],D=s[f+6],S=c?s[f+7]:1,d=y*8;if((b||l[d]!==Z||l[d+1]!==C||l[d+2]!==w||l[d+3]!==B||l[d+4]!==v||l[d+5]!==x||l[d+6]!==D||l[d+7]!==S)&&(r.position.set(Z,C,w),o.set(B,v,x,D).normalize(),r.quaternion.copy(o),r.scale.setScalar(S),r.updateMatrix(),i.instancedMesh.setMatrixAt(y,r.matrix),l[d]=Z,l[d+1]=C,l[d+2]=w,l[d+3]=B,l[d+4]=v,l[d+5]=x,l[d+6]=D,l[d+7]=S,R=!0),c){let _e=s[f+9],O=Math.max(0,Math.min(1,_e));p?p.array[y]!==O&&(p.array[y]=O,_=!0):(a.copy(i.baseColor).lerp(i.hotColor,O),i.instancedMesh.setColorAt(y,a),_=!0)}}i.prevCount=m,R&&(i.instancedMesh.instanceMatrix.needsUpdate=!0),p?_&&(p.needsUpdate=!0):c&&_&&i.instancedMesh.instanceColor&&(i.instancedMesh.instanceColor.needsUpdate=!0)}removeBatch(n){let t=this.batches.get(n);t&&(this.scene?.remove(t.instancedMesh),t.geometry.dispose(),t.material.dispose(),t.instancedMesh.dispose(),this.batches.delete(n))}clear(){for(let n of[...this.batches.keys()])this.removeBatch(n)}dispose(){this.clear(),this.scene=null}};function j(e){return e instanceof tt||e instanceof q}function rt(e,n,t){if(j(e))return e.vertexColors=!1,e.color.copy(n),t==="heatTint"&&e instanceof q&&ce(e,new z(W)),e.needsUpdate=!0,e;if("vertexColors"in e&&(e.vertexColors=t==="heatTint"),"color"in e){let i=e;t==="base"?i.color.copy(n):i.color.copy(new z(16777215))}return"needsUpdate"in e&&(e.needsUpdate=!0),e}var K=class{constructor(n){this.wasmSource=n}runtimeEntities=[];runtimeInstanceManager=new k;batches=new Map;gameplay=null;context=null;rebuildPromise=null;dirty=!0;lastRuntimeDiagnostics=!1;ownsEntity(n){let t=n.options?.runtime;return t?.simulation==="runtime"||t?.body==="static"}rendersEntity(n){let t=n.options?.runtime;return t?.simulation==="runtime"&&t.render==="instanced"}registerEntity(n){this.ownsEntity(n)&&(this.runtimeEntities.includes(n)||this.runtimeEntities.push(n),n.physicsAttached=!1,this.rendersEntity(n)&&(n.isInstanced=!0),this.rendersEntity(n)&&n.mesh&&(n.mesh.visible=!1),this.dirty=!0)}unregisterEntity(n){let t=this.runtimeEntities.indexOf(n);t>=0&&this.runtimeEntities.splice(t,1),n.runtimeSlot=-1,this.dirty=!0}async init(n){this.context=n,this.runtimeInstanceManager.setScene(n.scene.scene),await this.rebuildBatches()}step(n){this.context=n;let t=this.peekRuntimeDiagnostics(n);if(this.lastRuntimeDiagnostics!==t&&(this.lastRuntimeDiagnostics=t,this.dirty=!0),!this.rebuildPromise){if(this.dirty){this.rebuildPromise=this.rebuildBatches().finally(()=>{this.rebuildPromise=null});return}for(let i of this.batches.values())i.runtime.exports.zylem_runtime_step(n.delta),i.runtime.refreshViews(),this.runtimeInstanceManager.updateBatch(i.key,i.runtime);this.stepGameplay(n)}}destroy(n){this.runtimeInstanceManager.dispose(),this.runtimeEntities.length=0,this.batches.clear(),this.gameplay=null,this.context=null,this.lastRuntimeDiagnostics=!1,this.dirty=!0}async rebuildBatches(){if(this.runtimeInstanceManager.clear(),this.batches.clear(),this.gameplay=null,!this.context||this.runtimeEntities.length===0){this.lastRuntimeDiagnostics=this.peekRuntimeDiagnostics(),this.dirty=!1;return}let n=new Map,t=[],i=[];for(let r of this.runtimeEntities){if(this.rendersEntity(r)){if(!r.mesh?.geometry||!r.materials?.length)continue;let o=te.generateEntityBatchKey(r),a=n.get(o)??[];a.push(r),n.set(o,a)}else i.push(r);pt(r)&&t.push({center:A(r),halfExtents:J(r),friction:.95,restitution:.05})}for(let[r,o]of n){let a=o[0],p=a.mesh.geometry,s=a.materials[0],u=a.options.runtime,m=J(a),b={positions:o.map(y=>A(y)),halfExtents:m,staticColliders:t},l=await Y(this.wasmSource,b),R=this.peekRuntimeDiagnostics(),_=yt(u?.colorMode,R);this.runtimeInstanceManager.registerBatch({key:r,geometry:p,material:s,count:o.length,baseColor:a.options.material?.color??a.options.color??new ot(16777215),colorMode:_}),this.runtimeInstanceManager.updateBatch(r,l),o.forEach((y,f)=>{y.batchKey=r,y.instanceId=f,y.runtimeSlot=f,y.isInstanced=!0,y.mesh&&(y.mesh.visible=!1)}),this.batches.set(r,{key:r,entities:o,runtime:l})}i.length>0&&(this.gameplay=await this.createGameplayState(i),this.syncGameplayEntities(this.gameplay)),this.dirty=!1,this.lastRuntimeDiagnostics=this.peekRuntimeDiagnostics()}peekRuntimeDiagnostics(n){return(n??this.context)?.debug?.runtimeDiagnostics()??!1}async createGameplayState(n){let t=bt(n),i=[],r=[],o=[],a=[];for(let[s,u]of n.entries()){let m=_t(u);a[s]={ball:m.ballRef,ricochet:m.ricochetRef},m.ballRef&&i.push({slot:s,position:A(u),radius:ft(u),initialVelocity:m.ballRef.options.initialVelocity,minSpeed:m.ricochetRef?.options.minSpeed??2,maxSpeed:m.ricochetRef?.options.maxSpeed??20,speedMultiplier:m.ricochetRef?.options.speedMultiplier??1.05,maxAngleDeg:m.ricochetRef?.options.maxAngleDeg??60,reflectionMode:m.ricochetRef?.options.reflectionMode??"angled",usesBoundary2d:gt(u,fe),usesRicochet2d:!!m.ricochetRef}),m.paddleRef&&r.push({slot:s,position:A(u),playerIndex:m.paddleRef.options.player==="p1"?0:1,speed:m.paddleRef.options.speed,halfExtents:dt(u)});let c=u.getBehaviorRefs().find(b=>b.descriptor.key===pe);c&&o.push({triggerId:c.options.triggerId,position:A(u),halfExtents:c.options.halfExtents})}let p=await N(this.wasmSource,n.length,{bounds:t,dynamicCircles:i,kinematicAabbs:r,...o.length>0?{triggerAabbs:o}:{}});for(let[s,u]of n.entries()){u.runtimeSlot=s;let m=a[s]?.ball;m&&at(m,{setPosition:(c,b,l)=>U(p,s,c,b,l),setVelocity:(c,b)=>P(p,s,c,b),getPosition:()=>{let c=u.group??u.mesh;return c?{x:c.position.x,y:c.position.y,z:c.position.z}:null}})}return{runtime:p,entities:n,slotToEntity:[...n],slotRefs:a}}syncGameplayEntities(n){for(let[t,i]of n.slotToEntity.entries()){let r=H(n.runtime.renderView,n.runtime.renderStride,t),o=i.group??i.mesh;o&&(o.position.set(r.position[0],r.position[1],r.position[2]),o.quaternion.set(r.rotation[0],r.rotation[1],r.rotation[2],r.rotation[3]))}}stepGameplay(n){if(this.gameplay){G(this.gameplay.runtime,0,de(n.inputs,"p1")),G(this.gameplay.runtime,1,de(n.inputs,"p2")),this.gameplay.runtime.exports.zylem_runtime_step(n.delta),this.gameplay.runtime.refreshViews(),this.syncGameplayEntities(this.gameplay);for(let t of F(this.gameplay.runtime))switch(t.type){case 1:{let i=this.gameplay.slotRefs[t.primarySlot];i?.ricochet&&ye(i.ricochet,{kind:"wall"});break}case 2:{let i=this.gameplay.slotRefs[t.primarySlot];i?.ricochet&&ye(i.ricochet,{kind:"paddle"});break}case 3:{let i=t.secondarySlot;for(let r of this.gameplay.entities){let o=r.getBehaviorRefs().find(a=>a.descriptor.key===pe);o&&o.options.triggerId===i&&mt(o,{triggerId:i})}break}}}}};function ct(e){return new K(e.source)}function yt(e,n){return e==="heatTint"||n?"heatTint":e??"base"}function J(e){let n=e.options?.tile;if(n){let i=$(n,X),r=Math.max(e.options?.size?.z??1,.01);return[Math.max(i.x/2,.01),Math.max(r/2,.01),Math.max(i.y/2,.01)]}let t=h(e.options?.size,I);return[Math.max(t.x/2,.01),Math.max(t.y/2,.01),Math.max(t.z/2,.01)]}function A(e){let n=h(e.options?.position,M);if(e.options?.tile){let i=J(e);return[n.x,n.y-i[1],n.z]}return[n.x,n.y,n.z]}function pt(e){return e.options?.runtime?.body==="static"}function dt(e){let n=h(e.options?.size,I);return[Math.max(n.x/2,.01),Math.max(n.y/2,.01)]}function ft(e){return Math.max(e.options.radius??.5,.01)}function de(e,n){let t=e[n]?.directions,i=e[n]?.axes?.Vertical;return(t?.Up?.held?1:0)-(t?.Down?.held?1:0)||-(i?.value??0)}function bt(e){for(let n of e){let t=n.getBehaviorRefs().find(i=>i.descriptor.key===fe);if(t)return t.options.boundaries}return{left:-15,right:15,bottom:-5,top:5}}function _t(e){let n=e.getBehaviorRefs();return{ballRef:n.find(t=>t.descriptor.key===lt),paddleRef:n.find(t=>t.descriptor.key===st),ricochetRef:n.find(t=>t.descriptor.key===ut)}}function gt(e,n){return e.getBehaviorRefs().some(t=>t.descriptor.key===n)}var g={kind:0,position:[0,0,0],rotation:[0,0,0,1],linearDamping:0,angularDamping:0,gravityScale:1,canSleep:!1,ccdEnabled:!0,lockRotation:[!1,!1,!1],lockTranslation:[!1,!1,!1]};function ht(e={}){let n=h(e.position,M);return{kind:e.kind??g.kind,position:[n.x,n.y,n.z],rotation:e.rotation??g.rotation,linearDamping:e.linearDamping??g.linearDamping,angularDamping:e.angularDamping??g.angularDamping,gravityScale:e.gravityScale??g.gravityScale,canSleep:e.canSleep??g.canSleep,ccdEnabled:e.ccdEnabled??g.ccdEnabled,lockRotation:e.lockRotation??g.lockRotation,lockTranslation:e.lockTranslation??g.lockTranslation}}function be(e,n){if(!e)return 4294967295;let t=Q(e),i=n?ee(n):65535;return(1<<t&65535)<<16|i&65535}function E(e,n){let t=h(n.offset,M);return{shape:e,offset:[t.x,t.y,t.z],friction:n.friction??.5,restitution:n.restitution??0,sensor:n.sensor??!1,collisionGroups:be(n.collisionType,n.collisionFilter)}}function Rt(e,n={}){let t=h(e,I);return E({type:"box",halfExtents:[t.x/2,t.y/2,t.z/2]},n)}function xt(e,n={}){return E({type:"sphere",radius:e},n)}function St(e,n,t={}){return E({type:"capsule",halfHeight:e,radius:n},t)}function Et(e,n,t={}){return E({type:"cylinder",halfHeight:e,radius:n},t)}function Ct(e,n={}){return E({type:"convexHull",vertices:e},n)}function Zt(e,n,t={}){return E({type:"trimesh",vertices:e,indices:n},t)}function wt(e,n,t,i,r={}){return E({type:"heightfield",rows:e,cols:n,heights:t,scale:i},r)}function Bt(e,n){return{body:e,colliders:n}}export{Re as STAGE_EVENT_STRIDE,ge as STAGE_INVALID_SLOT,xe as STAGE_POSE_LEN,he as STAGE_RENDER_STRIDE,Se as StageBodyKind,Ee as StageBoundaryDim,Be as StageEventType,Ce as StageRicochetDim,Ze as StageRicochetReflection,we as StageTopDownPlane,ve as WasmStageRuntime,Ve as ZYLEM_RUNTIME_EVENT_STRIDE,Ie as ZYLEM_RUNTIME_INPUT_STRIDE,ze as ZYLEM_RUNTIME_RENDER_STRIDE,Ae as ZYLEM_RUNTIME_SUMMARY_LEN,L as ZylemRuntimeEventType,le as ZylemRuntimePlatformer3DFsmState,We as addZylemRuntimeStaticHeightfieldCollider,ie as attachZylemRuntimeBufferViews,re as bootstrapZylemRuntimeGameplay2D,me as bootstrapZylemRuntimeGameplay3D,oe as bootstrapZylemRuntimeInstancing,Rt as buildBoxCollider,St as buildCapsuleCollider,Ct as buildConvexHullCollider,Et as buildCylinderCollider,wt as buildHeightfieldCollider,ht as buildRuntimeBody,xt as buildSphereCollider,Zt as buildTrimeshCollider,Bt as bundleRuntimeCollision,ae as configureZylemRuntimePlatformer3D,Me as createRuntimeDebugBindingFromDebugState,De as createWasmStageRuntime,N as createZylemRuntimeGameplay2DSession,Le as createZylemRuntimeGameplay3DSession,Y as createZylemRuntimeInstancedBatchSession,V as createZylemRuntimeSession,ct as createZylemRuntimeStageAdapter,je as getZylemRuntimeGameplay3DDebugRender,Pe as getZylemRuntimeGameplay3DGrounded,Fe as getZylemRuntimeGameplay3DJumpCount,Ye as getZylemRuntimeGameplay3DState,ne as loadZylemRuntimeWasm,be as packCollisionGroups,H as readRenderSlot,ke as readSummary,F as readZylemRuntimeEvents,qe as readZylemRuntimeGameplay3DEvents,G as setZylemRuntimeGameplay2DInputAxis,U as setZylemRuntimeGameplay2DSlotPosition,P as setZylemRuntimeGameplay2DSlotVelocity,He as setZylemRuntimeGameplay3DInputAxes,Ne as setZylemRuntimeGameplay3DInputButtons,Ue as setZylemRuntimeGameplay3DSlotPosition,Ge as writeInputSlot,Te as writeInputSlotFromParts};
1
+ import{a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j,i as k,j as l,k as m,l as n,m as o,n as p,o as q,p as r}from"./chunk-47DG7I7M.js";import{b}from"./chunk-YAOXFYOD.js";import{b as a}from"./chunk-EVYHPR3J.js";import"./chunk-7WRQ2UAN.js";export{b as SimulationBody,l as StageBodyKind,m as StageBoundaryDim,n as StageEventType,o as StageRicochetDim,p as StageRicochetReflection,q as StageTopDownPlane,d as buildBoxCollider,f as buildCapsuleCollider,h as buildConvexHullCollider,g as buildCylinderCollider,j as buildHeightfieldCollider,c as buildRuntimeBody,e as buildSphereCollider,i as buildTrimeshCollider,k as bundleRuntimeCollision,r as createSimulation,a as packCollisionGroups};