@draug/engine 1.0.18 → 1.0.20
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/index.cjs +167 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -99
- package/dist/index.d.ts +88 -99
- package/dist/index.js +165 -145
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -17,84 +17,53 @@ interface Logger {
|
|
|
17
17
|
error(message: LogMessage): void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
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;
|
|
21
33
|
add(id: number, initFn?: (obj: T) => T): T;
|
|
22
34
|
remove(id: number): void;
|
|
23
35
|
get(id: number): T | null;
|
|
24
36
|
tryGet(id: number): T;
|
|
37
|
+
writeComponentsToBuf(ids: ReadonlyArray<number>, out: T[]): number;
|
|
25
38
|
has(id: number): boolean;
|
|
26
39
|
size(): number;
|
|
27
40
|
forEach(cb: (id: number) => void): void;
|
|
28
|
-
bitmap(): Bitmap;
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
declare enum ComponentStorageType {
|
|
32
|
-
COMPONENT_STORAGE = 1,
|
|
33
|
-
SINGLETON_STORAGE = 2
|
|
34
|
-
}
|
|
35
|
-
type RegisterSingletoneComponentOptions<T extends object> = {
|
|
36
|
-
storageType: ComponentStorageType.SINGLETON_STORAGE;
|
|
37
|
-
factory: () => T;
|
|
38
|
-
};
|
|
39
43
|
type RegisterComponentStorageOptions<T extends object> = {
|
|
40
|
-
storageType: ComponentStorageType.COMPONENT_STORAGE;
|
|
41
44
|
factory?: () => T;
|
|
42
45
|
};
|
|
43
|
-
type RegisterComponentOptions<T extends object> =
|
|
46
|
+
type RegisterComponentOptions<T extends object> = RegisterComponentStorageOptions<T>;
|
|
44
47
|
declare class ComponentAlreadyRegisteredError extends Error {
|
|
45
48
|
constructor(component: ComponentType);
|
|
46
49
|
}
|
|
47
50
|
declare class ComponentsManager {
|
|
51
|
+
private readonly logger;
|
|
48
52
|
private maxEntityCount;
|
|
49
53
|
private readonly storages_;
|
|
50
54
|
private currId_;
|
|
51
55
|
private nextId;
|
|
52
|
-
constructor(maxEntityCount?: number);
|
|
53
|
-
register<T extends object>(component: ComponentType<T>, opts?: RegisterComponentOptions<T>):
|
|
56
|
+
constructor(logger: Logger, maxEntityCount?: number);
|
|
57
|
+
register<T extends object>(component: ComponentType<T>, opts?: RegisterComponentOptions<T>): ComponentStorage<T>;
|
|
54
58
|
private createComponentStore;
|
|
55
|
-
|
|
56
|
-
getStorage<T extends object>(component: ComponentType<T>): IStorage<T>;
|
|
59
|
+
getStorage<T extends object>(component: ComponentType<T>): ComponentStorage<T>;
|
|
57
60
|
getComponentId(ctor: ComponentType): number;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
private set_;
|
|
65
|
-
private pool_;
|
|
66
|
-
private id_;
|
|
67
|
-
private cls;
|
|
68
|
-
constructor(cap: number | undefined, factory: () => T, cls: ClassType<T>);
|
|
69
|
-
bitmap(): Bitmap;
|
|
70
|
-
get id(): number;
|
|
71
|
-
_internalSetId(id: number): number;
|
|
72
|
-
add(id: number, initFn?: (obj: T) => T): T;
|
|
73
|
-
remove(id: number): void;
|
|
74
|
-
get(id: number): T | null;
|
|
75
|
-
tryGet(id: number): T;
|
|
76
|
-
writeComponentsToBuf(ids: ReadonlyArray<number>, out: T[]): number;
|
|
77
|
-
has(id: number): boolean;
|
|
78
|
-
entityIds(): number[];
|
|
79
|
-
size(): number;
|
|
80
|
-
forEach(cb: (id: number) => void): void;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
declare class SingletonStorage<T extends object> implements IStorage<T> {
|
|
84
|
-
private factory;
|
|
85
|
-
private value;
|
|
86
|
-
private entityId;
|
|
87
|
-
constructor(factory: () => T);
|
|
88
|
-
bitmap(): Bitmap;
|
|
89
|
-
add(id: number, initFn?: ((obj: T) => T) | undefined): T;
|
|
90
|
-
remove(id: number): void;
|
|
91
|
-
get(id: number): T | null;
|
|
92
|
-
tryGet(id: number): T;
|
|
93
|
-
has(id: number): boolean;
|
|
94
|
-
size(): number;
|
|
95
|
-
forEach(cb: (id: number) => void): void;
|
|
96
|
-
private validateId;
|
|
97
|
-
}
|
|
63
|
+
type ComponentOptions = {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
66
|
+
declare function Component(options: ComponentOptions): ClassDecorator;
|
|
98
67
|
|
|
99
68
|
type EntityID = number;
|
|
100
69
|
declare class UnregisteredComponentStorageError extends Error {
|
|
@@ -156,6 +125,14 @@ declare class EventBus {
|
|
|
156
125
|
getBuffer<T>(key: EventKey<T>): EventBuffer<T>;
|
|
157
126
|
}
|
|
158
127
|
|
|
128
|
+
type ResourceMetadata = {
|
|
129
|
+
name: string;
|
|
130
|
+
};
|
|
131
|
+
type ResourceParams = {
|
|
132
|
+
name: string;
|
|
133
|
+
};
|
|
134
|
+
declare function Resource(params: ResourceParams): ClassDecorator;
|
|
135
|
+
declare function getResourceMetadata(resource: Function): ResourceMetadata;
|
|
159
136
|
declare class ResourcesManager {
|
|
160
137
|
private readonly logger;
|
|
161
138
|
private readonly items_;
|
|
@@ -203,12 +180,13 @@ declare class QueryManager {
|
|
|
203
180
|
}
|
|
204
181
|
|
|
205
182
|
type PluginID = string;
|
|
183
|
+
type PluginConstructor = ClassType<PluginBase>;
|
|
206
184
|
type PluginDependencies = {
|
|
207
185
|
components?: ComponentType[];
|
|
208
186
|
resources?: ClassType<any>[];
|
|
209
187
|
systems?: ClassType<SystemBase>[];
|
|
210
188
|
plugins?: Array<{
|
|
211
|
-
|
|
189
|
+
plugin: PluginConstructor;
|
|
212
190
|
version?: string;
|
|
213
191
|
}>;
|
|
214
192
|
};
|
|
@@ -219,7 +197,7 @@ interface PluginMetadata {
|
|
|
219
197
|
dependencies?: PluginDependencies;
|
|
220
198
|
}
|
|
221
199
|
declare function Plugin(metadata: PluginMetadata): ClassDecorator;
|
|
222
|
-
declare function getPluginMetadata(plugin:
|
|
200
|
+
declare function getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
223
201
|
declare function isPlugin(ctor: Function): boolean;
|
|
224
202
|
declare abstract class PluginBase {
|
|
225
203
|
onPluginLoad?: () => void;
|
|
@@ -227,36 +205,74 @@ declare abstract class PluginBase {
|
|
|
227
205
|
onAfterWorldInit?: (world: World) => void;
|
|
228
206
|
}
|
|
229
207
|
declare class PluginError extends Error {
|
|
230
|
-
constructor(pluginId:
|
|
208
|
+
constructor(pluginId: PluginConstructor);
|
|
231
209
|
}
|
|
232
210
|
declare class ErrNotAPlugin extends Error {
|
|
233
211
|
constructor(target: Function);
|
|
234
212
|
}
|
|
235
213
|
declare class ErrMissingPluginMetadata extends Error {
|
|
236
|
-
constructor(plugin:
|
|
214
|
+
constructor(plugin: PluginConstructor);
|
|
237
215
|
}
|
|
238
216
|
declare class ErrUnknownPlugin extends PluginError {
|
|
239
|
-
constructor(pluginId:
|
|
217
|
+
constructor(pluginId: PluginConstructor);
|
|
240
218
|
}
|
|
241
219
|
declare class ErrPluginNotInit extends PluginError {
|
|
242
|
-
constructor(pluginId:
|
|
220
|
+
constructor(pluginId: PluginConstructor);
|
|
243
221
|
}
|
|
244
222
|
declare class PluginsManager {
|
|
245
223
|
private readonly logger;
|
|
246
224
|
private plugins_;
|
|
247
225
|
private isInitiated_;
|
|
248
226
|
constructor(logger: Logger);
|
|
249
|
-
install<T extends
|
|
227
|
+
install<T extends PluginConstructor>(plugin: T, ...constructorProps: ConstructorParameters<T>): void;
|
|
250
228
|
build(): void;
|
|
251
229
|
/**
|
|
252
230
|
* @internal
|
|
253
231
|
*/
|
|
254
232
|
__internal__onAfterWorldInit(world: World): void;
|
|
255
|
-
getPluginMetadata(
|
|
256
|
-
getPluginInstance<T extends PluginBase>(
|
|
233
|
+
getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
234
|
+
getPluginInstance<T extends PluginBase>(plugin: ClassType<T>): T;
|
|
257
235
|
private resolveId;
|
|
258
236
|
}
|
|
259
237
|
|
|
238
|
+
interface TimeSource {
|
|
239
|
+
now(): number;
|
|
240
|
+
}
|
|
241
|
+
declare class Clock {
|
|
242
|
+
private readonly timeSource_;
|
|
243
|
+
private lastTimeMs_;
|
|
244
|
+
private ellapsedTime_;
|
|
245
|
+
private delta_;
|
|
246
|
+
private readonly time_;
|
|
247
|
+
constructor(timeSource_: TimeSource);
|
|
248
|
+
get deltaMs(): number;
|
|
249
|
+
get ellapsedTime(): number;
|
|
250
|
+
tick(): void;
|
|
251
|
+
getTime(): Readonly<Time>;
|
|
252
|
+
}
|
|
253
|
+
type Time = {
|
|
254
|
+
delta: number;
|
|
255
|
+
elapsed: number;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
type StepFunction = (dt: number, world: World) => void;
|
|
259
|
+
type PlatformLoop = (callback: () => void) => void;
|
|
260
|
+
declare class Loop {
|
|
261
|
+
private readonly clock;
|
|
262
|
+
private readonly stepFn;
|
|
263
|
+
private readonly platformLoop;
|
|
264
|
+
private running;
|
|
265
|
+
constructor(clock: Clock, stepFn: StepFunction, platformLoop: PlatformLoop);
|
|
266
|
+
start(world: World): void;
|
|
267
|
+
stop(): void;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
declare class Runtime {
|
|
271
|
+
private readonly loop;
|
|
272
|
+
constructor(loop: Loop);
|
|
273
|
+
run(world: World): void;
|
|
274
|
+
}
|
|
275
|
+
|
|
260
276
|
type WorldConstructor = {
|
|
261
277
|
maxEntityCount?: number;
|
|
262
278
|
logger: Logger;
|
|
@@ -272,6 +288,8 @@ declare class World {
|
|
|
272
288
|
readonly plugins: PluginsManager;
|
|
273
289
|
private readonly logger;
|
|
274
290
|
private entityRefs_;
|
|
291
|
+
private updatesCount_;
|
|
292
|
+
get updatesCount(): number;
|
|
275
293
|
constructor(params: WorldConstructor);
|
|
276
294
|
getEntityRef(id: number): EntityRef;
|
|
277
295
|
query(params: QueryParameters): number[];
|
|
@@ -279,7 +297,7 @@ declare class World {
|
|
|
279
297
|
removeComponent<T extends object>(entity: EntityID, component: ComponentType<T>): void;
|
|
280
298
|
addComponent<T extends object>(id: EntityID, component: ClassType<T>, initFn?: (obj: T) => void): T;
|
|
281
299
|
addComponent<T extends object>(id: EntityRef, component: ClassType<T>, initFn?: (obj: T) => void): T;
|
|
282
|
-
update(
|
|
300
|
+
update(clock: Clock): void;
|
|
283
301
|
build(): void;
|
|
284
302
|
}
|
|
285
303
|
|
|
@@ -324,12 +342,14 @@ type SystemMetadata = {
|
|
|
324
342
|
*/
|
|
325
343
|
computeAfter?: Set<SystemCtor>;
|
|
326
344
|
phase?: SystemPhase;
|
|
345
|
+
name: string;
|
|
327
346
|
};
|
|
328
347
|
type SystemDecoratorProps = {
|
|
329
348
|
query: SystemMetadata['query'];
|
|
330
349
|
requiredComponents?: ComponentType[];
|
|
331
350
|
computeAfter?: SystemCtor[];
|
|
332
351
|
phase?: SystemPhase;
|
|
352
|
+
name: SystemMetadata['name'];
|
|
333
353
|
};
|
|
334
354
|
declare function System(props: SystemDecoratorProps): ClassDecorator;
|
|
335
355
|
declare function getSystemMetadata(system: SystemCtor): SystemMetadata;
|
|
@@ -344,7 +364,7 @@ type SystemComputeContext = {
|
|
|
344
364
|
/** ECS world instance. */
|
|
345
365
|
readonly world: World;
|
|
346
366
|
/** Delta time (seconds or your engine's convention) since the previous update. */
|
|
347
|
-
readonly
|
|
367
|
+
readonly time: Time;
|
|
348
368
|
/** Logger instance for debugging and diagnostics. */
|
|
349
369
|
readonly logger: Logger;
|
|
350
370
|
};
|
|
@@ -379,42 +399,10 @@ declare class SystemsManager {
|
|
|
379
399
|
build(): void;
|
|
380
400
|
private rebuild;
|
|
381
401
|
get<T extends SystemBase>(ctor: SystemCtor<T>): T;
|
|
382
|
-
update(
|
|
402
|
+
update(time: Time): void;
|
|
383
403
|
private buildSystemsArray;
|
|
384
404
|
}
|
|
385
405
|
|
|
386
|
-
interface TimeSource {
|
|
387
|
-
now(): number;
|
|
388
|
-
}
|
|
389
|
-
declare class Clock {
|
|
390
|
-
private readonly timeSource_;
|
|
391
|
-
private lastTimeMs_;
|
|
392
|
-
private elapsedTime_;
|
|
393
|
-
private dt_;
|
|
394
|
-
constructor(timeSource_: TimeSource);
|
|
395
|
-
get dt(): number;
|
|
396
|
-
get ellapsedTime(): number;
|
|
397
|
-
tick(): void;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
type StepFunction = (dt: number, world: World) => void;
|
|
401
|
-
type PlatformLoop = (callback: () => void) => void;
|
|
402
|
-
declare class Loop {
|
|
403
|
-
private readonly clock;
|
|
404
|
-
private readonly stepFn;
|
|
405
|
-
private readonly platformLoop;
|
|
406
|
-
private running;
|
|
407
|
-
constructor(clock: Clock, stepFn: StepFunction, platformLoop: PlatformLoop);
|
|
408
|
-
start(world: World): void;
|
|
409
|
-
stop(): void;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
declare class Runtime {
|
|
413
|
-
private readonly loop;
|
|
414
|
-
constructor(loop: Loop);
|
|
415
|
-
run(world: World): void;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
406
|
declare enum VisitedState {
|
|
419
407
|
Unvisited = 0,
|
|
420
408
|
Visiting = 1,
|
|
@@ -493,6 +481,7 @@ declare class AssetsManager {
|
|
|
493
481
|
type EngineConstructor = {
|
|
494
482
|
loop: Loop;
|
|
495
483
|
logger?: Logger;
|
|
484
|
+
maxEntityCount?: number;
|
|
496
485
|
};
|
|
497
486
|
declare class Engine {
|
|
498
487
|
readonly runtime: Runtime;
|
|
@@ -504,4 +493,4 @@ declare class Engine {
|
|
|
504
493
|
start(): void;
|
|
505
494
|
}
|
|
506
495
|
|
|
507
|
-
export { Asset, type AssetDisposer, type AssetID, type AssetIDGenerator, type AssetLoader, AssetState, AssetStorage, AssetsManager, type ClassType, Clock, Commands, Component, ComponentAlreadyRegisteredError, type ComponentInitFn, ComponentStorage, type ComponentType, ComponentsManager, type CreateEntityComponentEntry, DAGNode, Engine, type EngineConstructor, EntitiesManager, type EntityID, EntityMaskNotFoundError, EntityRef, ErrDAGCycleDetected, ErrMissingPluginMetadata, ErrMissingSystemMetadata, ErrNotAPlugin, ErrNotASystem, ErrPluginNotInit, ErrUnknownPlugin, EventBuffer, EventBus,
|
|
496
|
+
export { Asset, type AssetDisposer, type AssetID, type AssetIDGenerator, type AssetLoader, AssetState, AssetStorage, AssetsManager, type ClassType, Clock, Commands, Component, ComponentAlreadyRegisteredError, type ComponentInitFn, ComponentStorage, type ComponentType, ComponentsManager, type CreateEntityComponentEntry, DAGNode, Engine, type EngineConstructor, EntitiesManager, type EntityID, EntityMaskNotFoundError, EntityRef, ErrDAGCycleDetected, ErrMissingPluginMetadata, ErrMissingSystemMetadata, ErrNotAPlugin, ErrNotASystem, ErrPluginNotInit, ErrUnknownPlugin, EventBuffer, EventBus, LogLevel, type LogMessage, type Logger, Loop, ObjectPool, type PlatformLoop, Plugin, PluginBase, type PluginDependencies, PluginError, type PluginID, type PluginMetadata, PluginsManager, Resource, type ResourceMetadata, ResourcesManager, Runtime, type StepFunction, System, SystemBase, type SystemComputeContext, SystemError, type SystemInitContext, SystemPhase, SystemsManager, type TimeSource, UnregisteredComponentStorageError, VisitedState, World, type WorldCommand, createEventKey, entry, getPluginMetadata, getResourceMetadata, getSystemMetadata, isPlugin, isSystem, topologicalSort };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,84 +17,53 @@ interface Logger {
|
|
|
17
17
|
error(message: LogMessage): void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
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;
|
|
21
33
|
add(id: number, initFn?: (obj: T) => T): T;
|
|
22
34
|
remove(id: number): void;
|
|
23
35
|
get(id: number): T | null;
|
|
24
36
|
tryGet(id: number): T;
|
|
37
|
+
writeComponentsToBuf(ids: ReadonlyArray<number>, out: T[]): number;
|
|
25
38
|
has(id: number): boolean;
|
|
26
39
|
size(): number;
|
|
27
40
|
forEach(cb: (id: number) => void): void;
|
|
28
|
-
bitmap(): Bitmap;
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
declare enum ComponentStorageType {
|
|
32
|
-
COMPONENT_STORAGE = 1,
|
|
33
|
-
SINGLETON_STORAGE = 2
|
|
34
|
-
}
|
|
35
|
-
type RegisterSingletoneComponentOptions<T extends object> = {
|
|
36
|
-
storageType: ComponentStorageType.SINGLETON_STORAGE;
|
|
37
|
-
factory: () => T;
|
|
38
|
-
};
|
|
39
43
|
type RegisterComponentStorageOptions<T extends object> = {
|
|
40
|
-
storageType: ComponentStorageType.COMPONENT_STORAGE;
|
|
41
44
|
factory?: () => T;
|
|
42
45
|
};
|
|
43
|
-
type RegisterComponentOptions<T extends object> =
|
|
46
|
+
type RegisterComponentOptions<T extends object> = RegisterComponentStorageOptions<T>;
|
|
44
47
|
declare class ComponentAlreadyRegisteredError extends Error {
|
|
45
48
|
constructor(component: ComponentType);
|
|
46
49
|
}
|
|
47
50
|
declare class ComponentsManager {
|
|
51
|
+
private readonly logger;
|
|
48
52
|
private maxEntityCount;
|
|
49
53
|
private readonly storages_;
|
|
50
54
|
private currId_;
|
|
51
55
|
private nextId;
|
|
52
|
-
constructor(maxEntityCount?: number);
|
|
53
|
-
register<T extends object>(component: ComponentType<T>, opts?: RegisterComponentOptions<T>):
|
|
56
|
+
constructor(logger: Logger, maxEntityCount?: number);
|
|
57
|
+
register<T extends object>(component: ComponentType<T>, opts?: RegisterComponentOptions<T>): ComponentStorage<T>;
|
|
54
58
|
private createComponentStore;
|
|
55
|
-
|
|
56
|
-
getStorage<T extends object>(component: ComponentType<T>): IStorage<T>;
|
|
59
|
+
getStorage<T extends object>(component: ComponentType<T>): ComponentStorage<T>;
|
|
57
60
|
getComponentId(ctor: ComponentType): number;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
private set_;
|
|
65
|
-
private pool_;
|
|
66
|
-
private id_;
|
|
67
|
-
private cls;
|
|
68
|
-
constructor(cap: number | undefined, factory: () => T, cls: ClassType<T>);
|
|
69
|
-
bitmap(): Bitmap;
|
|
70
|
-
get id(): number;
|
|
71
|
-
_internalSetId(id: number): number;
|
|
72
|
-
add(id: number, initFn?: (obj: T) => T): T;
|
|
73
|
-
remove(id: number): void;
|
|
74
|
-
get(id: number): T | null;
|
|
75
|
-
tryGet(id: number): T;
|
|
76
|
-
writeComponentsToBuf(ids: ReadonlyArray<number>, out: T[]): number;
|
|
77
|
-
has(id: number): boolean;
|
|
78
|
-
entityIds(): number[];
|
|
79
|
-
size(): number;
|
|
80
|
-
forEach(cb: (id: number) => void): void;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
declare class SingletonStorage<T extends object> implements IStorage<T> {
|
|
84
|
-
private factory;
|
|
85
|
-
private value;
|
|
86
|
-
private entityId;
|
|
87
|
-
constructor(factory: () => T);
|
|
88
|
-
bitmap(): Bitmap;
|
|
89
|
-
add(id: number, initFn?: ((obj: T) => T) | undefined): T;
|
|
90
|
-
remove(id: number): void;
|
|
91
|
-
get(id: number): T | null;
|
|
92
|
-
tryGet(id: number): T;
|
|
93
|
-
has(id: number): boolean;
|
|
94
|
-
size(): number;
|
|
95
|
-
forEach(cb: (id: number) => void): void;
|
|
96
|
-
private validateId;
|
|
97
|
-
}
|
|
63
|
+
type ComponentOptions = {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
66
|
+
declare function Component(options: ComponentOptions): ClassDecorator;
|
|
98
67
|
|
|
99
68
|
type EntityID = number;
|
|
100
69
|
declare class UnregisteredComponentStorageError extends Error {
|
|
@@ -156,6 +125,14 @@ declare class EventBus {
|
|
|
156
125
|
getBuffer<T>(key: EventKey<T>): EventBuffer<T>;
|
|
157
126
|
}
|
|
158
127
|
|
|
128
|
+
type ResourceMetadata = {
|
|
129
|
+
name: string;
|
|
130
|
+
};
|
|
131
|
+
type ResourceParams = {
|
|
132
|
+
name: string;
|
|
133
|
+
};
|
|
134
|
+
declare function Resource(params: ResourceParams): ClassDecorator;
|
|
135
|
+
declare function getResourceMetadata(resource: Function): ResourceMetadata;
|
|
159
136
|
declare class ResourcesManager {
|
|
160
137
|
private readonly logger;
|
|
161
138
|
private readonly items_;
|
|
@@ -203,12 +180,13 @@ declare class QueryManager {
|
|
|
203
180
|
}
|
|
204
181
|
|
|
205
182
|
type PluginID = string;
|
|
183
|
+
type PluginConstructor = ClassType<PluginBase>;
|
|
206
184
|
type PluginDependencies = {
|
|
207
185
|
components?: ComponentType[];
|
|
208
186
|
resources?: ClassType<any>[];
|
|
209
187
|
systems?: ClassType<SystemBase>[];
|
|
210
188
|
plugins?: Array<{
|
|
211
|
-
|
|
189
|
+
plugin: PluginConstructor;
|
|
212
190
|
version?: string;
|
|
213
191
|
}>;
|
|
214
192
|
};
|
|
@@ -219,7 +197,7 @@ interface PluginMetadata {
|
|
|
219
197
|
dependencies?: PluginDependencies;
|
|
220
198
|
}
|
|
221
199
|
declare function Plugin(metadata: PluginMetadata): ClassDecorator;
|
|
222
|
-
declare function getPluginMetadata(plugin:
|
|
200
|
+
declare function getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
223
201
|
declare function isPlugin(ctor: Function): boolean;
|
|
224
202
|
declare abstract class PluginBase {
|
|
225
203
|
onPluginLoad?: () => void;
|
|
@@ -227,36 +205,74 @@ declare abstract class PluginBase {
|
|
|
227
205
|
onAfterWorldInit?: (world: World) => void;
|
|
228
206
|
}
|
|
229
207
|
declare class PluginError extends Error {
|
|
230
|
-
constructor(pluginId:
|
|
208
|
+
constructor(pluginId: PluginConstructor);
|
|
231
209
|
}
|
|
232
210
|
declare class ErrNotAPlugin extends Error {
|
|
233
211
|
constructor(target: Function);
|
|
234
212
|
}
|
|
235
213
|
declare class ErrMissingPluginMetadata extends Error {
|
|
236
|
-
constructor(plugin:
|
|
214
|
+
constructor(plugin: PluginConstructor);
|
|
237
215
|
}
|
|
238
216
|
declare class ErrUnknownPlugin extends PluginError {
|
|
239
|
-
constructor(pluginId:
|
|
217
|
+
constructor(pluginId: PluginConstructor);
|
|
240
218
|
}
|
|
241
219
|
declare class ErrPluginNotInit extends PluginError {
|
|
242
|
-
constructor(pluginId:
|
|
220
|
+
constructor(pluginId: PluginConstructor);
|
|
243
221
|
}
|
|
244
222
|
declare class PluginsManager {
|
|
245
223
|
private readonly logger;
|
|
246
224
|
private plugins_;
|
|
247
225
|
private isInitiated_;
|
|
248
226
|
constructor(logger: Logger);
|
|
249
|
-
install<T extends
|
|
227
|
+
install<T extends PluginConstructor>(plugin: T, ...constructorProps: ConstructorParameters<T>): void;
|
|
250
228
|
build(): void;
|
|
251
229
|
/**
|
|
252
230
|
* @internal
|
|
253
231
|
*/
|
|
254
232
|
__internal__onAfterWorldInit(world: World): void;
|
|
255
|
-
getPluginMetadata(
|
|
256
|
-
getPluginInstance<T extends PluginBase>(
|
|
233
|
+
getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
234
|
+
getPluginInstance<T extends PluginBase>(plugin: ClassType<T>): T;
|
|
257
235
|
private resolveId;
|
|
258
236
|
}
|
|
259
237
|
|
|
238
|
+
interface TimeSource {
|
|
239
|
+
now(): number;
|
|
240
|
+
}
|
|
241
|
+
declare class Clock {
|
|
242
|
+
private readonly timeSource_;
|
|
243
|
+
private lastTimeMs_;
|
|
244
|
+
private ellapsedTime_;
|
|
245
|
+
private delta_;
|
|
246
|
+
private readonly time_;
|
|
247
|
+
constructor(timeSource_: TimeSource);
|
|
248
|
+
get deltaMs(): number;
|
|
249
|
+
get ellapsedTime(): number;
|
|
250
|
+
tick(): void;
|
|
251
|
+
getTime(): Readonly<Time>;
|
|
252
|
+
}
|
|
253
|
+
type Time = {
|
|
254
|
+
delta: number;
|
|
255
|
+
elapsed: number;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
type StepFunction = (dt: number, world: World) => void;
|
|
259
|
+
type PlatformLoop = (callback: () => void) => void;
|
|
260
|
+
declare class Loop {
|
|
261
|
+
private readonly clock;
|
|
262
|
+
private readonly stepFn;
|
|
263
|
+
private readonly platformLoop;
|
|
264
|
+
private running;
|
|
265
|
+
constructor(clock: Clock, stepFn: StepFunction, platformLoop: PlatformLoop);
|
|
266
|
+
start(world: World): void;
|
|
267
|
+
stop(): void;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
declare class Runtime {
|
|
271
|
+
private readonly loop;
|
|
272
|
+
constructor(loop: Loop);
|
|
273
|
+
run(world: World): void;
|
|
274
|
+
}
|
|
275
|
+
|
|
260
276
|
type WorldConstructor = {
|
|
261
277
|
maxEntityCount?: number;
|
|
262
278
|
logger: Logger;
|
|
@@ -272,6 +288,8 @@ declare class World {
|
|
|
272
288
|
readonly plugins: PluginsManager;
|
|
273
289
|
private readonly logger;
|
|
274
290
|
private entityRefs_;
|
|
291
|
+
private updatesCount_;
|
|
292
|
+
get updatesCount(): number;
|
|
275
293
|
constructor(params: WorldConstructor);
|
|
276
294
|
getEntityRef(id: number): EntityRef;
|
|
277
295
|
query(params: QueryParameters): number[];
|
|
@@ -279,7 +297,7 @@ declare class World {
|
|
|
279
297
|
removeComponent<T extends object>(entity: EntityID, component: ComponentType<T>): void;
|
|
280
298
|
addComponent<T extends object>(id: EntityID, component: ClassType<T>, initFn?: (obj: T) => void): T;
|
|
281
299
|
addComponent<T extends object>(id: EntityRef, component: ClassType<T>, initFn?: (obj: T) => void): T;
|
|
282
|
-
update(
|
|
300
|
+
update(clock: Clock): void;
|
|
283
301
|
build(): void;
|
|
284
302
|
}
|
|
285
303
|
|
|
@@ -324,12 +342,14 @@ type SystemMetadata = {
|
|
|
324
342
|
*/
|
|
325
343
|
computeAfter?: Set<SystemCtor>;
|
|
326
344
|
phase?: SystemPhase;
|
|
345
|
+
name: string;
|
|
327
346
|
};
|
|
328
347
|
type SystemDecoratorProps = {
|
|
329
348
|
query: SystemMetadata['query'];
|
|
330
349
|
requiredComponents?: ComponentType[];
|
|
331
350
|
computeAfter?: SystemCtor[];
|
|
332
351
|
phase?: SystemPhase;
|
|
352
|
+
name: SystemMetadata['name'];
|
|
333
353
|
};
|
|
334
354
|
declare function System(props: SystemDecoratorProps): ClassDecorator;
|
|
335
355
|
declare function getSystemMetadata(system: SystemCtor): SystemMetadata;
|
|
@@ -344,7 +364,7 @@ type SystemComputeContext = {
|
|
|
344
364
|
/** ECS world instance. */
|
|
345
365
|
readonly world: World;
|
|
346
366
|
/** Delta time (seconds or your engine's convention) since the previous update. */
|
|
347
|
-
readonly
|
|
367
|
+
readonly time: Time;
|
|
348
368
|
/** Logger instance for debugging and diagnostics. */
|
|
349
369
|
readonly logger: Logger;
|
|
350
370
|
};
|
|
@@ -379,42 +399,10 @@ declare class SystemsManager {
|
|
|
379
399
|
build(): void;
|
|
380
400
|
private rebuild;
|
|
381
401
|
get<T extends SystemBase>(ctor: SystemCtor<T>): T;
|
|
382
|
-
update(
|
|
402
|
+
update(time: Time): void;
|
|
383
403
|
private buildSystemsArray;
|
|
384
404
|
}
|
|
385
405
|
|
|
386
|
-
interface TimeSource {
|
|
387
|
-
now(): number;
|
|
388
|
-
}
|
|
389
|
-
declare class Clock {
|
|
390
|
-
private readonly timeSource_;
|
|
391
|
-
private lastTimeMs_;
|
|
392
|
-
private elapsedTime_;
|
|
393
|
-
private dt_;
|
|
394
|
-
constructor(timeSource_: TimeSource);
|
|
395
|
-
get dt(): number;
|
|
396
|
-
get ellapsedTime(): number;
|
|
397
|
-
tick(): void;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
type StepFunction = (dt: number, world: World) => void;
|
|
401
|
-
type PlatformLoop = (callback: () => void) => void;
|
|
402
|
-
declare class Loop {
|
|
403
|
-
private readonly clock;
|
|
404
|
-
private readonly stepFn;
|
|
405
|
-
private readonly platformLoop;
|
|
406
|
-
private running;
|
|
407
|
-
constructor(clock: Clock, stepFn: StepFunction, platformLoop: PlatformLoop);
|
|
408
|
-
start(world: World): void;
|
|
409
|
-
stop(): void;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
declare class Runtime {
|
|
413
|
-
private readonly loop;
|
|
414
|
-
constructor(loop: Loop);
|
|
415
|
-
run(world: World): void;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
406
|
declare enum VisitedState {
|
|
419
407
|
Unvisited = 0,
|
|
420
408
|
Visiting = 1,
|
|
@@ -493,6 +481,7 @@ declare class AssetsManager {
|
|
|
493
481
|
type EngineConstructor = {
|
|
494
482
|
loop: Loop;
|
|
495
483
|
logger?: Logger;
|
|
484
|
+
maxEntityCount?: number;
|
|
496
485
|
};
|
|
497
486
|
declare class Engine {
|
|
498
487
|
readonly runtime: Runtime;
|
|
@@ -504,4 +493,4 @@ declare class Engine {
|
|
|
504
493
|
start(): void;
|
|
505
494
|
}
|
|
506
495
|
|
|
507
|
-
export { Asset, type AssetDisposer, type AssetID, type AssetIDGenerator, type AssetLoader, AssetState, AssetStorage, AssetsManager, type ClassType, Clock, Commands, Component, ComponentAlreadyRegisteredError, type ComponentInitFn, ComponentStorage, type ComponentType, ComponentsManager, type CreateEntityComponentEntry, DAGNode, Engine, type EngineConstructor, EntitiesManager, type EntityID, EntityMaskNotFoundError, EntityRef, ErrDAGCycleDetected, ErrMissingPluginMetadata, ErrMissingSystemMetadata, ErrNotAPlugin, ErrNotASystem, ErrPluginNotInit, ErrUnknownPlugin, EventBuffer, EventBus,
|
|
496
|
+
export { Asset, type AssetDisposer, type AssetID, type AssetIDGenerator, type AssetLoader, AssetState, AssetStorage, AssetsManager, type ClassType, Clock, Commands, Component, ComponentAlreadyRegisteredError, type ComponentInitFn, ComponentStorage, type ComponentType, ComponentsManager, type CreateEntityComponentEntry, DAGNode, Engine, type EngineConstructor, EntitiesManager, type EntityID, EntityMaskNotFoundError, EntityRef, ErrDAGCycleDetected, ErrMissingPluginMetadata, ErrMissingSystemMetadata, ErrNotAPlugin, ErrNotASystem, ErrPluginNotInit, ErrUnknownPlugin, EventBuffer, EventBus, LogLevel, type LogMessage, type Logger, Loop, ObjectPool, type PlatformLoop, Plugin, PluginBase, type PluginDependencies, PluginError, type PluginID, type PluginMetadata, PluginsManager, Resource, type ResourceMetadata, ResourcesManager, Runtime, type StepFunction, System, SystemBase, type SystemComputeContext, SystemError, type SystemInitContext, SystemPhase, SystemsManager, type TimeSource, UnregisteredComponentStorageError, VisitedState, World, type WorldCommand, createEventKey, entry, getPluginMetadata, getResourceMetadata, getSystemMetadata, isPlugin, isSystem, topologicalSort };
|