@draug/engine 1.0.21 → 1.0.23
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/chunk-BYP45ZLQ.js +37 -0
- package/dist/chunk-BYP45ZLQ.js.map +1 -0
- package/dist/chunk-CNBFO5GJ.cjs +37 -0
- package/dist/chunk-CNBFO5GJ.cjs.map +1 -0
- package/dist/chunk-GUD2YACA.cjs +1256 -0
- package/dist/chunk-GUD2YACA.cjs.map +1 -0
- package/dist/chunk-SWTBVK53.js +1256 -0
- package/dist/chunk-SWTBVK53.js.map +1 -0
- package/dist/index.cjs +169 -1115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -382
- package/dist/index.d.ts +9 -382
- package/dist/index.js +80 -950
- package/dist/index.js.map +1 -1
- package/dist/std/components/index.cjs +9 -0
- package/dist/std/components/index.cjs.map +1 -0
- package/dist/std/components/index.d.cts +71 -0
- package/dist/std/components/index.d.ts +71 -0
- package/dist/std/components/index.js +9 -0
- package/dist/std/components/index.js.map +1 -0
- package/dist/std/systems/index.cjs +8 -0
- package/dist/std/systems/index.cjs.map +1 -0
- package/dist/std/systems/index.d.cts +11 -0
- package/dist/std/systems/index.d.ts +11 -0
- package/dist/std/systems/index.js +8 -0
- package/dist/std/systems/index.js.map +1 -0
- package/dist/system-jRDSVzc9.d.cts +382 -0
- package/dist/system-jRDSVzc9.d.ts +382 -0
- package/package.json +13 -1
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { Bitmap } from 'bitmap-index';
|
|
2
|
+
|
|
3
|
+
type ClassType<T> = new (...args: any[]) => T;
|
|
4
|
+
type ComponentType<T extends object = object> = ClassType<T>;
|
|
5
|
+
|
|
6
|
+
declare enum LogLevel {
|
|
7
|
+
Debug = 0,
|
|
8
|
+
Info = 1,
|
|
9
|
+
Warn = 2,
|
|
10
|
+
Error = 3
|
|
11
|
+
}
|
|
12
|
+
type LogMessage = () => string;
|
|
13
|
+
interface Logger {
|
|
14
|
+
debug(message: LogMessage): void;
|
|
15
|
+
info(message: LogMessage): void;
|
|
16
|
+
warn(message: LogMessage): void;
|
|
17
|
+
error(message: LogMessage): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class ComponentStorage<T extends object> {
|
|
21
|
+
private bits_;
|
|
22
|
+
private data_;
|
|
23
|
+
private entityIds_;
|
|
24
|
+
private indexMap_;
|
|
25
|
+
private pool_;
|
|
26
|
+
private id_;
|
|
27
|
+
private size_;
|
|
28
|
+
private cls;
|
|
29
|
+
constructor(cap: number | undefined, factory: () => T, cls: ClassType<T>);
|
|
30
|
+
bitmap(): Bitmap;
|
|
31
|
+
get id(): number;
|
|
32
|
+
_internalSetId(id: number): number;
|
|
33
|
+
add(id: number, initFn?: (obj: T) => T): T;
|
|
34
|
+
remove(id: number): void;
|
|
35
|
+
get(id: number): T | null;
|
|
36
|
+
tryGet(id: number): T;
|
|
37
|
+
writeComponentsToBuf(ids: ReadonlyArray<number>, out: T[]): number;
|
|
38
|
+
has(id: number): boolean;
|
|
39
|
+
size(): number;
|
|
40
|
+
forEach(cb: (id: number) => void): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type RegisterComponentStorageOptions<T extends object> = {
|
|
44
|
+
factory?: () => T;
|
|
45
|
+
};
|
|
46
|
+
type RegisterComponentOptions<T extends object> = RegisterComponentStorageOptions<T>;
|
|
47
|
+
declare class ComponentAlreadyRegisteredError extends Error {
|
|
48
|
+
constructor(component: ComponentType);
|
|
49
|
+
}
|
|
50
|
+
declare class ComponentsManager {
|
|
51
|
+
private readonly logger;
|
|
52
|
+
private maxEntityCount;
|
|
53
|
+
private readonly storages_;
|
|
54
|
+
private currId_;
|
|
55
|
+
private nextId;
|
|
56
|
+
constructor(logger: Logger, maxEntityCount?: number);
|
|
57
|
+
register<T extends object>(component: ComponentType<T>, opts?: RegisterComponentOptions<T>): ComponentStorage<T>;
|
|
58
|
+
private createComponentStore;
|
|
59
|
+
getStorage<T extends object>(component: ComponentType<T>): ComponentStorage<T>;
|
|
60
|
+
getComponentId(ctor: ComponentType): number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type EntityID = number;
|
|
64
|
+
declare class UnregisteredComponentStorageError extends Error {
|
|
65
|
+
constructor(component: ComponentType);
|
|
66
|
+
}
|
|
67
|
+
declare class EntityMaskNotFoundError extends Error {
|
|
68
|
+
constructor(id: EntityID);
|
|
69
|
+
}
|
|
70
|
+
declare class EntitiesManager {
|
|
71
|
+
private readonly logger;
|
|
72
|
+
private id_;
|
|
73
|
+
constructor(logger: Logger);
|
|
74
|
+
private nextId;
|
|
75
|
+
create(): EntityID;
|
|
76
|
+
}
|
|
77
|
+
declare class EntityRef {
|
|
78
|
+
private world;
|
|
79
|
+
id: EntityID;
|
|
80
|
+
constructor(world: World, id: EntityID);
|
|
81
|
+
with<T extends ComponentType[], Result extends {
|
|
82
|
+
[K in keyof T]: InstanceType<T[K]>;
|
|
83
|
+
}>(...components: T): Result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare class EventBuffer<T extends unknown> {
|
|
87
|
+
private readBuf;
|
|
88
|
+
private writeBuf;
|
|
89
|
+
write(event: T): void;
|
|
90
|
+
/**
|
|
91
|
+
* Advances the buffer to the next frame.
|
|
92
|
+
*
|
|
93
|
+
* Performs a double-buffer flip:
|
|
94
|
+
* - Promotes all events written during the previous frame (`writeBuf`)
|
|
95
|
+
* to be readable in the current frame (`readBuf`).
|
|
96
|
+
* - Reuses the previous `readBuf` as the new `writeBuf` and clears it
|
|
97
|
+
* to collect events for the next frame.
|
|
98
|
+
*
|
|
99
|
+
* After calling this method:
|
|
100
|
+
* - `get()` will return a stable snapshot of events produced in the previous frame.
|
|
101
|
+
* - `add()` will write into an empty buffer for the current frame.
|
|
102
|
+
*
|
|
103
|
+
* Guarantees:
|
|
104
|
+
* - No events written during the current frame are visible until the next `swap()`.
|
|
105
|
+
* - Readers observe a consistent, immutable snapshot within a frame.
|
|
106
|
+
*
|
|
107
|
+
* Expected to be called exactly once per frame, before system execution.
|
|
108
|
+
*/
|
|
109
|
+
swap(): void;
|
|
110
|
+
read(): ReadonlyArray<T>;
|
|
111
|
+
size(): number;
|
|
112
|
+
}
|
|
113
|
+
type EventKey<T> = symbol & {
|
|
114
|
+
__type?: T;
|
|
115
|
+
};
|
|
116
|
+
declare function createEventKey<T>(description?: string): EventKey<T>;
|
|
117
|
+
declare class EventBus {
|
|
118
|
+
private storage;
|
|
119
|
+
swapAll(): void;
|
|
120
|
+
getBuffer<T>(key: EventKey<T>): EventBuffer<T>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type ResourceMetadata = {
|
|
124
|
+
name: string;
|
|
125
|
+
};
|
|
126
|
+
type ResourceParams = {
|
|
127
|
+
name: string;
|
|
128
|
+
};
|
|
129
|
+
declare function Resource(params: ResourceParams): ClassDecorator;
|
|
130
|
+
declare function getResourceMetadata(resource: Function): ResourceMetadata;
|
|
131
|
+
declare class ResourcesManager {
|
|
132
|
+
private readonly logger;
|
|
133
|
+
private readonly items_;
|
|
134
|
+
constructor(logger: Logger);
|
|
135
|
+
insert<T extends object>(type: ClassType<T>, value: T): T;
|
|
136
|
+
get<T extends object>(type: ClassType<T>): T;
|
|
137
|
+
getOrInsert<T extends object>(type: ClassType<T>, factory: () => T): T;
|
|
138
|
+
remove<T>(type: ClassType<T>): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
type WorldCommand = (world: World) => void;
|
|
142
|
+
type ComponentInitFn<C extends ComponentType> = (component: InstanceType<C>) => void;
|
|
143
|
+
type CreateEntityComponentEntry<T extends ComponentType = ComponentType> = T extends unknown ? [T, ComponentInitFn<T>] : never;
|
|
144
|
+
declare function entry<T extends ComponentType>(component: T, init?: ComponentInitFn<T>): CreateEntityComponentEntry;
|
|
145
|
+
declare class Commands {
|
|
146
|
+
private readonly world;
|
|
147
|
+
private readonly logger;
|
|
148
|
+
private readonly commandsQueue_;
|
|
149
|
+
constructor(world: World, logger: Logger);
|
|
150
|
+
add(cmd: WorldCommand): void;
|
|
151
|
+
flush(world: World): void;
|
|
152
|
+
createEntity(...entries: CreateEntityComponentEntry[]): number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type QueryParameters = {
|
|
156
|
+
include?: ComponentType[];
|
|
157
|
+
exclude?: ComponentType[];
|
|
158
|
+
anyOf?: ComponentType[];
|
|
159
|
+
excludeEntitiesIds?: number[];
|
|
160
|
+
filter?: (id: number) => boolean;
|
|
161
|
+
};
|
|
162
|
+
declare class QueryManager {
|
|
163
|
+
private readonly world;
|
|
164
|
+
private cache;
|
|
165
|
+
constructor(world: World);
|
|
166
|
+
get(params: QueryParameters): EntityID[];
|
|
167
|
+
invalidate(component: ComponentType): void;
|
|
168
|
+
private getKey;
|
|
169
|
+
private ids;
|
|
170
|
+
private collectDeps;
|
|
171
|
+
private compute;
|
|
172
|
+
private combineBitmaps;
|
|
173
|
+
private applyExclusions;
|
|
174
|
+
private extractIds;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
type PluginID = string;
|
|
178
|
+
type PluginConstructor = ClassType<PluginBase>;
|
|
179
|
+
type PluginDependencies = {
|
|
180
|
+
components?: ComponentType[];
|
|
181
|
+
resources?: ClassType<any>[];
|
|
182
|
+
systems?: ClassType<SystemBase>[];
|
|
183
|
+
plugins?: Array<{
|
|
184
|
+
plugin: PluginConstructor;
|
|
185
|
+
version?: string;
|
|
186
|
+
}>;
|
|
187
|
+
};
|
|
188
|
+
interface PluginMetadata {
|
|
189
|
+
id?: PluginID;
|
|
190
|
+
version: string;
|
|
191
|
+
name: string;
|
|
192
|
+
dependencies?: PluginDependencies;
|
|
193
|
+
}
|
|
194
|
+
declare function Plugin(metadata: PluginMetadata): ClassDecorator;
|
|
195
|
+
declare function getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
196
|
+
declare function isPlugin(ctor: Function): boolean;
|
|
197
|
+
declare abstract class PluginBase {
|
|
198
|
+
onPluginLoad?: () => void;
|
|
199
|
+
onPluginUnload?: (world: World) => void;
|
|
200
|
+
onAfterWorldInit?: (world: World) => void;
|
|
201
|
+
}
|
|
202
|
+
declare class PluginError extends Error {
|
|
203
|
+
constructor(pluginId: PluginConstructor);
|
|
204
|
+
}
|
|
205
|
+
declare class ErrNotAPlugin extends Error {
|
|
206
|
+
constructor(target: Function);
|
|
207
|
+
}
|
|
208
|
+
declare class ErrMissingPluginMetadata extends Error {
|
|
209
|
+
constructor(plugin: PluginConstructor);
|
|
210
|
+
}
|
|
211
|
+
declare class ErrUnknownPlugin extends PluginError {
|
|
212
|
+
constructor(pluginId: PluginConstructor);
|
|
213
|
+
}
|
|
214
|
+
declare class ErrPluginNotInit extends PluginError {
|
|
215
|
+
constructor(pluginId: PluginConstructor);
|
|
216
|
+
}
|
|
217
|
+
declare class PluginsManager {
|
|
218
|
+
private readonly logger;
|
|
219
|
+
private plugins_;
|
|
220
|
+
private isInitiated_;
|
|
221
|
+
constructor(logger: Logger);
|
|
222
|
+
install<T extends PluginConstructor>(plugin: T, ...constructorProps: ConstructorParameters<T>): void;
|
|
223
|
+
build(): void;
|
|
224
|
+
/**
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
__internal__onAfterWorldInit(world: World): void;
|
|
228
|
+
getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
229
|
+
getPluginInstance<T extends PluginBase>(plugin: ClassType<T>): T;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
interface TimeSource {
|
|
233
|
+
now(): number;
|
|
234
|
+
}
|
|
235
|
+
declare class Clock {
|
|
236
|
+
private readonly timeSource_;
|
|
237
|
+
private lastTimeMs_;
|
|
238
|
+
private ellapsedTime_;
|
|
239
|
+
private delta_;
|
|
240
|
+
private readonly time_;
|
|
241
|
+
constructor(timeSource_: TimeSource);
|
|
242
|
+
get deltaMs(): number;
|
|
243
|
+
get ellapsedTime(): number;
|
|
244
|
+
tick(): void;
|
|
245
|
+
getTime(): Readonly<Time>;
|
|
246
|
+
}
|
|
247
|
+
type Time = {
|
|
248
|
+
delta: number;
|
|
249
|
+
elapsed: number;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
type WorldConstructor = {
|
|
253
|
+
maxEntityCount?: number;
|
|
254
|
+
logger: Logger;
|
|
255
|
+
};
|
|
256
|
+
declare class World {
|
|
257
|
+
readonly entities: EntitiesManager;
|
|
258
|
+
readonly components: ComponentsManager;
|
|
259
|
+
readonly systems: SystemsManager;
|
|
260
|
+
readonly events: EventBus;
|
|
261
|
+
readonly resources: ResourcesManager;
|
|
262
|
+
readonly commands: Commands;
|
|
263
|
+
readonly queries: QueryManager;
|
|
264
|
+
readonly plugins: PluginsManager;
|
|
265
|
+
private readonly logger;
|
|
266
|
+
private entityRefs_;
|
|
267
|
+
private updatesCount_;
|
|
268
|
+
get updatesCount(): number;
|
|
269
|
+
constructor(params: WorldConstructor);
|
|
270
|
+
getEntityRef(id: number): EntityRef;
|
|
271
|
+
query(params: QueryParameters): number[];
|
|
272
|
+
removeComponent<T extends object>(ref: EntityRef, component: ComponentType<T>): void;
|
|
273
|
+
removeComponent<T extends object>(entity: EntityID, component: ComponentType<T>): void;
|
|
274
|
+
addComponent<T extends object>(id: EntityID, component: ClassType<T>, initFn?: (obj: T) => void): T;
|
|
275
|
+
addComponent<T extends object>(id: EntityRef, component: ClassType<T>, initFn?: (obj: T) => void): T;
|
|
276
|
+
update(clock: Clock): void;
|
|
277
|
+
build(): void;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
declare class SystemError extends Error {
|
|
281
|
+
constructor(target: Function);
|
|
282
|
+
}
|
|
283
|
+
declare class ErrNotASystem extends Error {
|
|
284
|
+
constructor(target: Function);
|
|
285
|
+
}
|
|
286
|
+
declare class ErrMissingSystemMetadata extends SystemError {
|
|
287
|
+
constructor(target: SystemCtor);
|
|
288
|
+
}
|
|
289
|
+
declare enum SystemPhase {
|
|
290
|
+
PRE = 0,
|
|
291
|
+
MAIN = 1,
|
|
292
|
+
POST = 2
|
|
293
|
+
}
|
|
294
|
+
type SystemMetadata = {
|
|
295
|
+
/**
|
|
296
|
+
* ECS query definition used to select entities for this system execution.
|
|
297
|
+
*
|
|
298
|
+
* Determines the iteration set passed to {@link SystemBase.compute}.
|
|
299
|
+
* The ECS runtime resolves entities based on this query each update.
|
|
300
|
+
*/
|
|
301
|
+
query: Readonly<QueryParameters>;
|
|
302
|
+
/**
|
|
303
|
+
* Explicit list of component types required by the system but not necessarily
|
|
304
|
+
* part of the iteration query.
|
|
305
|
+
*
|
|
306
|
+
* Used for:
|
|
307
|
+
* - ensuring component storages are initialized in the world
|
|
308
|
+
* - safe access via `world.components.getStorage`
|
|
309
|
+
* - dependencies that should not affect entity selection
|
|
310
|
+
*
|
|
311
|
+
* This does NOT influence entity iteration; only runtime validation/setup.
|
|
312
|
+
*/
|
|
313
|
+
requiredComponents: Set<ComponentType>;
|
|
314
|
+
/**
|
|
315
|
+
* Systems that must run before this one. Pass constructor arguments
|
|
316
|
+
* `super(OtherSystemCtor, ...)` to add edges; each listed system is scheduled earlier than
|
|
317
|
+
* this instance. Used when {@link SystemsManager.build} computes a topological execution order.
|
|
318
|
+
*/
|
|
319
|
+
computeAfter?: Set<SystemCtor>;
|
|
320
|
+
phase?: SystemPhase;
|
|
321
|
+
name: string;
|
|
322
|
+
};
|
|
323
|
+
type SystemDecoratorProps = {
|
|
324
|
+
query: SystemMetadata['query'];
|
|
325
|
+
requiredComponents?: ComponentType[];
|
|
326
|
+
computeAfter?: SystemCtor[];
|
|
327
|
+
phase?: SystemPhase;
|
|
328
|
+
name: SystemMetadata['name'];
|
|
329
|
+
};
|
|
330
|
+
declare function System(props: SystemDecoratorProps): ClassDecorator;
|
|
331
|
+
declare function getSystemMetadata(system: SystemCtor): SystemMetadata;
|
|
332
|
+
declare function isSystem(ctor: Function): boolean;
|
|
333
|
+
type SystemCtor<T extends SystemBase = SystemBase> = ClassType<T>;
|
|
334
|
+
/**
|
|
335
|
+
* Arguments passed to {@link SystemBase.compute} on each {@link SystemsManager.update} call.
|
|
336
|
+
*/
|
|
337
|
+
type SystemComputeContext = {
|
|
338
|
+
/** Entity IDs from the query for this {@link SystemBase.compute} invocation. */
|
|
339
|
+
readonly entities: number[];
|
|
340
|
+
/** ECS world instance. */
|
|
341
|
+
readonly world: World;
|
|
342
|
+
/** Delta time (seconds or your engine's convention) since the previous update. */
|
|
343
|
+
readonly time: Time;
|
|
344
|
+
/** Logger instance for debugging and diagnostics. */
|
|
345
|
+
readonly logger: Logger;
|
|
346
|
+
};
|
|
347
|
+
type SystemInitContext = {
|
|
348
|
+
world: World;
|
|
349
|
+
logger: Logger;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Base class for ECS systems executed by {@link SystemsManager}.
|
|
353
|
+
*
|
|
354
|
+
* Subclasses declare which components they iterate over (`queryComponents`), which component
|
|
355
|
+
* types must exist in the world for registration (`requiredComponents`), and optional ordering
|
|
356
|
+
* relative to other systems (`computeAfter` / `super(OtherSystem)`).
|
|
357
|
+
*/
|
|
358
|
+
declare abstract class SystemBase {
|
|
359
|
+
/**
|
|
360
|
+
* Logic for one systems pass: run for all entities in {@link SystemComputeContext.entities}.
|
|
361
|
+
*/
|
|
362
|
+
abstract compute(ctx: SystemComputeContext): void;
|
|
363
|
+
onInit?(ctx: SystemInitContext): void;
|
|
364
|
+
}
|
|
365
|
+
declare class SystemsManager {
|
|
366
|
+
private readonly world;
|
|
367
|
+
private readonly logger;
|
|
368
|
+
private systems_;
|
|
369
|
+
private executionOrder_;
|
|
370
|
+
private requiredComponents_;
|
|
371
|
+
private dirty_;
|
|
372
|
+
constructor(world: World, logger: Logger);
|
|
373
|
+
getRequiredComponents(): Set<ComponentType>;
|
|
374
|
+
register<T extends SystemBase>(sys: T): void;
|
|
375
|
+
build(): void;
|
|
376
|
+
private rebuild;
|
|
377
|
+
get<T extends SystemBase>(ctor: SystemCtor<T>): T;
|
|
378
|
+
update(time: Time): void;
|
|
379
|
+
private buildSystemsArray;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export { PluginsManager as A, type ResourceMetadata as B, Clock as C, ResourcesManager as D, EntitiesManager as E, SystemBase as F, type SystemComputeContext as G, SystemError as H, type SystemInitContext as I, SystemPhase as J, SystemsManager as K, type Logger as L, type WorldCommand as M, createEventKey as N, entry as O, Plugin as P, getPluginMetadata as Q, Resource as R, System as S, type TimeSource as T, UnregisteredComponentStorageError as U, getResourceMetadata as V, World as W, getSystemMetadata as X, isPlugin as Y, isSystem as Z, type ClassType as a, Commands as b, ComponentAlreadyRegisteredError as c, type ComponentInitFn as d, ComponentStorage as e, type ComponentType as f, ComponentsManager as g, type CreateEntityComponentEntry as h, type EntityID as i, EntityMaskNotFoundError as j, EntityRef as k, ErrMissingPluginMetadata as l, ErrMissingSystemMetadata as m, ErrNotAPlugin as n, ErrNotASystem as o, ErrPluginNotInit as p, ErrUnknownPlugin as q, EventBuffer as r, EventBus as s, LogLevel as t, type LogMessage as u, PluginBase as v, type PluginDependencies as w, PluginError as x, type PluginID as y, type PluginMetadata as z };
|