@zylem/game-lib 0.6.2 → 0.6.4
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/LICENSE +21 -0
- package/README.md +9 -16
- package/dist/actions.d.ts +30 -21
- package/dist/actions.js +793 -146
- package/dist/actions.js.map +1 -1
- package/dist/behavior/jumper-2d.d.ts +114 -0
- package/dist/behavior/jumper-2d.js +711 -0
- package/dist/behavior/jumper-2d.js.map +1 -0
- package/dist/behavior/platformer-3d.d.ts +296 -0
- package/dist/behavior/platformer-3d.js +761 -0
- package/dist/behavior/platformer-3d.js.map +1 -0
- package/dist/behavior/ricochet-2d.d.ts +275 -0
- package/dist/behavior/ricochet-2d.js +425 -0
- package/dist/behavior/ricochet-2d.js.map +1 -0
- package/dist/behavior/ricochet-3d.d.ts +117 -0
- package/dist/behavior/ricochet-3d.js +443 -0
- package/dist/behavior/ricochet-3d.js.map +1 -0
- package/dist/behavior/screen-visibility.d.ts +79 -0
- package/dist/behavior/screen-visibility.js +358 -0
- package/dist/behavior/screen-visibility.js.map +1 -0
- package/dist/behavior/screen-wrap.d.ts +87 -0
- package/dist/behavior/screen-wrap.js +246 -0
- package/dist/behavior/screen-wrap.js.map +1 -0
- package/dist/behavior/shooter-2d.d.ts +79 -0
- package/dist/behavior/shooter-2d.js +180 -0
- package/dist/behavior/shooter-2d.js.map +1 -0
- package/dist/behavior/thruster.d.ts +11 -0
- package/dist/behavior/thruster.js +292 -0
- package/dist/behavior/thruster.js.map +1 -0
- package/dist/behavior/top-down-movement.d.ts +56 -0
- package/dist/behavior/top-down-movement.js +125 -0
- package/dist/behavior/top-down-movement.js.map +1 -0
- package/dist/behavior/world-boundary-2d.d.ts +142 -0
- package/dist/behavior/world-boundary-2d.js +235 -0
- package/dist/behavior/world-boundary-2d.js.map +1 -0
- package/dist/behavior/world-boundary-3d.d.ts +76 -0
- package/dist/behavior/world-boundary-3d.js +274 -0
- package/dist/behavior/world-boundary-3d.js.map +1 -0
- package/dist/behavior-descriptor-BXnVR8Ki.d.ts +159 -0
- package/dist/{blueprints-Cq3Ko6_G.d.ts → blueprints-DmbK2dki.d.ts} +2 -2
- package/dist/camera-4XO5gbQH.d.ts +905 -0
- package/dist/camera.d.ts +3 -2
- package/dist/camera.js +1653 -377
- package/dist/camera.js.map +1 -1
- package/dist/composition-BASvMKrW.d.ts +218 -0
- package/dist/{core-bO8TzV7u.d.ts → core-CARRaS55.d.ts} +110 -69
- package/dist/core.d.ts +11 -6
- package/dist/core.js +10766 -5626
- package/dist/core.js.map +1 -1
- package/dist/{entities-DvByhMGU.d.ts → entities-ChFirVL9.d.ts} +133 -29
- package/dist/entities.d.ts +5 -3
- package/dist/entities.js +4679 -3202
- package/dist/entities.js.map +1 -1
- package/dist/entity-vj-HTjzU.d.ts +1169 -0
- package/dist/global-change-2JvMaz44.d.ts +25 -0
- package/dist/main.d.ts +1118 -16
- package/dist/main.js +17538 -8499
- package/dist/main.js.map +1 -1
- package/dist/physics-pose-DCc4oE44.d.ts +25 -0
- package/dist/physics-protocol-BDD3P5W2.d.ts +200 -0
- package/dist/physics-worker.d.ts +21 -0
- package/dist/physics-worker.js +306 -0
- package/dist/physics-worker.js.map +1 -0
- package/dist/physics.d.ts +205 -0
- package/dist/physics.js +577 -0
- package/dist/physics.js.map +1 -0
- package/dist/stage-types-C19IhuzA.d.ts +731 -0
- package/dist/stage.d.ts +11 -7
- package/dist/stage.js +8024 -3852
- package/dist/stage.js.map +1 -1
- package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
- package/dist/thruster-23lzoPZd.d.ts +180 -0
- package/dist/world-DfgxoNMt.d.ts +105 -0
- package/package.json +53 -13
- package/dist/behaviors.d.ts +0 -854
- package/dist/behaviors.js +0 -1209
- package/dist/behaviors.js.map +0 -1
- package/dist/camera-CeJPAgGg.d.ts +0 -116
- package/dist/moveable-B_vyA6cw.d.ts +0 -67
- package/dist/stage-types-Bd-KtcYT.d.ts +0 -375
- package/dist/transformable-CUhvyuYO.d.ts +0 -67
- package/dist/world-C8tQ7Plj.d.ts +0 -774
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { B as BodyCommand, a as SerializableBodyDesc, S as SerializableColliderDesc, b as SerializableCharacterController, P as PhysicsStepResultEvent, C as CollisionPair } from './physics-protocol-BDD3P5W2.js';
|
|
2
|
+
export { h as ColliderShapeKind, F as FLOATS_PER_BODY, c as PhysicsCommand, f as PhysicsErrorEvent, d as PhysicsEvent, e as PhysicsReadyEvent, g as SerializableBodyType, T as TransformOffset } from './physics-protocol-BDD3P5W2.js';
|
|
3
|
+
import { P as PhysicsPoseHistory, a as PhysicsPose } from './physics-pose-DCc4oE44.js';
|
|
4
|
+
import { RigidBodyDesc, ColliderDesc } from '@dimforge/rapier3d-compat';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Main-thread handle for a physics body that lives in a Web Worker.
|
|
8
|
+
*
|
|
9
|
+
* Provides the same read interface as a Rapier RigidBody (translation,
|
|
10
|
+
* rotation, linvel, angvel) by returning cached values that are synced
|
|
11
|
+
* from the worker each frame.
|
|
12
|
+
*
|
|
13
|
+
* Write operations (setLinvel, setTranslation, etc.) are queued as
|
|
14
|
+
* {@link BodyCommand}s and sent to the worker on the next step.
|
|
15
|
+
*/
|
|
16
|
+
declare class PhysicsBodyHandle {
|
|
17
|
+
readonly uuid: string;
|
|
18
|
+
/** Last-known physics state, updated from worker each frame. */
|
|
19
|
+
private _snapshot;
|
|
20
|
+
/** Queued commands to be sent to the worker on next step. */
|
|
21
|
+
private _pendingCommands;
|
|
22
|
+
/** Optional reference to the proxy's shared command queue. */
|
|
23
|
+
private _sharedQueue;
|
|
24
|
+
constructor(uuid: string, sharedQueue?: BodyCommand[]);
|
|
25
|
+
/** Cached position from last physics step. */
|
|
26
|
+
translation(): {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
z: number;
|
|
30
|
+
};
|
|
31
|
+
/** Cached rotation quaternion from last physics step. */
|
|
32
|
+
rotation(): {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
z: number;
|
|
36
|
+
w: number;
|
|
37
|
+
};
|
|
38
|
+
/** Cached linear velocity from last physics step. */
|
|
39
|
+
linvel(): {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
z: number;
|
|
43
|
+
};
|
|
44
|
+
/** Cached angular velocity from last physics step. */
|
|
45
|
+
angvel(): {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
z: number;
|
|
49
|
+
};
|
|
50
|
+
getPoseHistory(): PhysicsPoseHistory;
|
|
51
|
+
getRenderPose(alpha: number): PhysicsPose;
|
|
52
|
+
setLinvel(v: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
z: number;
|
|
56
|
+
}, _wakeUp?: boolean): void;
|
|
57
|
+
setAngvel(v: {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
z: number;
|
|
61
|
+
}, _wakeUp?: boolean): void;
|
|
62
|
+
setTranslation(v: {
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
z: number;
|
|
66
|
+
}, _wakeUp?: boolean): void;
|
|
67
|
+
setRotation(q: {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
z: number;
|
|
71
|
+
w: number;
|
|
72
|
+
}, _wakeUp?: boolean): void;
|
|
73
|
+
applyImpulse(v: {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
z: number;
|
|
77
|
+
}, _wakeUp?: boolean): void;
|
|
78
|
+
applyTorqueImpulse(v: {
|
|
79
|
+
x: number;
|
|
80
|
+
y: number;
|
|
81
|
+
z: number;
|
|
82
|
+
}, _wakeUp?: boolean): void;
|
|
83
|
+
lockTranslations(locked: boolean, _wakeUp?: boolean): void;
|
|
84
|
+
lockRotations(locked: boolean, _wakeUp?: boolean): void;
|
|
85
|
+
setLinearDamping(damping: number): void;
|
|
86
|
+
setGravityScale(scale: number, _wakeUp?: boolean): void;
|
|
87
|
+
/** Returns 'Dynamic' for compatibility; actual type is not synced. */
|
|
88
|
+
bodyType(): number;
|
|
89
|
+
mass(): number;
|
|
90
|
+
isEnabled(): boolean;
|
|
91
|
+
isSleeping(): boolean;
|
|
92
|
+
/** Collider access is not available through the handle. Returns null. */
|
|
93
|
+
collider(_index: number): null;
|
|
94
|
+
/**
|
|
95
|
+
* Update the cached snapshot from worker data.
|
|
96
|
+
* Called by the PhysicsProxy after receiving a stepResult.
|
|
97
|
+
*/
|
|
98
|
+
_seedSnapshot(px: number, py: number, pz: number, rx: number, ry: number, rz: number, rw: number, lvx: number, lvy: number, lvz: number, avx: number, avy: number, avz: number): void;
|
|
99
|
+
_updateSnapshot(px: number, py: number, pz: number, rx: number, ry: number, rz: number, rw: number, lvx: number, lvy: number, lvz: number, avx: number, avy: number, avz: number): void;
|
|
100
|
+
/** Drain pending commands. */
|
|
101
|
+
_drainCommands(): BodyCommand[];
|
|
102
|
+
private enqueue;
|
|
103
|
+
private copyPose;
|
|
104
|
+
private writePose;
|
|
105
|
+
private setCollapsedTranslation;
|
|
106
|
+
private setCollapsedRotation;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Callback signature for collision events dispatched by the proxy.
|
|
111
|
+
*/
|
|
112
|
+
type CollisionCallback = (pair: CollisionPair) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Main-thread proxy that communicates with the physics Web Worker.
|
|
115
|
+
*
|
|
116
|
+
* Usage:
|
|
117
|
+
* ```ts
|
|
118
|
+
* const proxy = new PhysicsProxy();
|
|
119
|
+
* await proxy.init([0, -9.81, 0], 60);
|
|
120
|
+
* const handle = proxy.addBody(uuid, bodyDesc, colliderDescs);
|
|
121
|
+
* // each frame:
|
|
122
|
+
* await proxy.step(delta);
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* The proxy owns the worker lifecycle and manages body handles.
|
|
126
|
+
* After each step, all handles are updated with fresh transform data
|
|
127
|
+
* and collision callbacks are fired.
|
|
128
|
+
*/
|
|
129
|
+
declare class PhysicsProxy {
|
|
130
|
+
private worker;
|
|
131
|
+
private handles;
|
|
132
|
+
private commandQueue;
|
|
133
|
+
private collisionListeners;
|
|
134
|
+
private pendingStep;
|
|
135
|
+
/** Latest interpolation alpha from the worker (0..1). */
|
|
136
|
+
interpolationAlpha: number;
|
|
137
|
+
/**
|
|
138
|
+
* Spawn the worker and initialize the Rapier world inside it.
|
|
139
|
+
* Resolves when the worker reports `ready`.
|
|
140
|
+
*
|
|
141
|
+
* @param gravity World gravity as [x, y, z].
|
|
142
|
+
* @param physicsRate Physics tick rate in Hz (default 60).
|
|
143
|
+
* @param workerUrl URL to the physics worker script. The consuming
|
|
144
|
+
* application must provide this because bundlers (Vite, Webpack)
|
|
145
|
+
* can only resolve worker URLs from application source code.
|
|
146
|
+
* Example for Vite:
|
|
147
|
+
* ```ts
|
|
148
|
+
* new URL('@zylem/game-lib/dist/physics-worker.js', import.meta.url)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
init(gravity: [number, number, number], physicsRate?: number, workerUrl?: URL): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Register a body in the worker and return a main-thread handle.
|
|
154
|
+
*
|
|
155
|
+
* @returns A {@link PhysicsBodyHandle} for reading cached transforms
|
|
156
|
+
* and queuing write commands.
|
|
157
|
+
*/
|
|
158
|
+
addBody(uuid: string, body: SerializableBodyDesc, colliders: SerializableColliderDesc[], characterController?: SerializableCharacterController): PhysicsBodyHandle;
|
|
159
|
+
/** Remove a body from the worker and discard its handle. */
|
|
160
|
+
removeBody(uuid: string): void;
|
|
161
|
+
/** Get a body handle by entity UUID. */
|
|
162
|
+
getHandle(uuid: string): PhysicsBodyHandle | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* Send a step command to the worker with the current frame delta
|
|
165
|
+
* and all queued body commands.
|
|
166
|
+
*
|
|
167
|
+
* Returns a promise that resolves after the worker replies with
|
|
168
|
+
* the step result. Handles are updated and collision callbacks
|
|
169
|
+
* are fired before the promise resolves.
|
|
170
|
+
*/
|
|
171
|
+
step(delta: number): Promise<PhysicsStepResultEvent>;
|
|
172
|
+
/**
|
|
173
|
+
* Subscribe to collision events.
|
|
174
|
+
* @returns Unsubscribe function.
|
|
175
|
+
*/
|
|
176
|
+
onCollision(callback: CollisionCallback): () => void;
|
|
177
|
+
/** Terminate the worker and release all handles. */
|
|
178
|
+
dispose(): void;
|
|
179
|
+
private send;
|
|
180
|
+
private onWorkerMessage;
|
|
181
|
+
private applyStepResult;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Convert a Rapier RigidBodyDesc to a plain serializable object.
|
|
186
|
+
*
|
|
187
|
+
* Rapier descriptors are WASM-backed class instances that cannot cross
|
|
188
|
+
* the postMessage boundary. This extracts the relevant data into a
|
|
189
|
+
* JSON-safe format that the worker can reconstruct.
|
|
190
|
+
*/
|
|
191
|
+
declare function serializeBodyDesc(desc: RigidBodyDesc): SerializableBodyDesc;
|
|
192
|
+
/**
|
|
193
|
+
* Convert a Rapier ColliderDesc to a plain serializable object.
|
|
194
|
+
*
|
|
195
|
+
* Because Rapier's ColliderDesc uses opaque shape enums and internal
|
|
196
|
+
* buffers, we infer the shape from the descriptor's internal type tag
|
|
197
|
+
* and extract the numeric dimensions.
|
|
198
|
+
*/
|
|
199
|
+
declare function serializeColliderDesc(desc: ColliderDesc): SerializableColliderDesc;
|
|
200
|
+
/**
|
|
201
|
+
* Create a serializable character controller descriptor.
|
|
202
|
+
*/
|
|
203
|
+
declare function serializeCharacterController(): SerializableCharacterController;
|
|
204
|
+
|
|
205
|
+
export { BodyCommand, CollisionPair, PhysicsBodyHandle, PhysicsProxy, PhysicsStepResultEvent, SerializableBodyDesc, SerializableCharacterController, SerializableColliderDesc, serializeBodyDesc, serializeCharacterController, serializeColliderDesc };
|