@draug/engine 1.0.19 → 1.0.21
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 +96 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -68
- package/dist/index.d.ts +47 -68
- package/dist/index.js +94 -112
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,86 +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 data_;
|
|
65
|
-
private entityIds_;
|
|
66
|
-
private indexMap_;
|
|
67
|
-
private pool_;
|
|
68
|
-
private id_;
|
|
69
|
-
private size_;
|
|
70
|
-
private cls;
|
|
71
|
-
constructor(cap: number | undefined, factory: () => T, cls: ClassType<T>);
|
|
72
|
-
bitmap(): Bitmap;
|
|
73
|
-
get id(): number;
|
|
74
|
-
_internalSetId(id: number): number;
|
|
75
|
-
add(id: number, initFn?: (obj: T) => T): T;
|
|
76
|
-
remove(id: number): void;
|
|
77
|
-
get(id: number): T | null;
|
|
78
|
-
tryGet(id: number): T;
|
|
79
|
-
writeComponentsToBuf(ids: ReadonlyArray<number>, out: T[]): number;
|
|
80
|
-
has(id: number): boolean;
|
|
81
|
-
size(): number;
|
|
82
|
-
forEach(cb: (id: number) => void): void;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
declare class SingletonStorage<T extends object> implements IStorage<T> {
|
|
86
|
-
private factory;
|
|
87
|
-
private value;
|
|
88
|
-
private entityId;
|
|
89
|
-
constructor(factory: () => T);
|
|
90
|
-
bitmap(): Bitmap;
|
|
91
|
-
add(id: number, initFn?: ((obj: T) => T) | undefined): T;
|
|
92
|
-
remove(id: number): void;
|
|
93
|
-
get(id: number): T | null;
|
|
94
|
-
tryGet(id: number): T;
|
|
95
|
-
has(id: number): boolean;
|
|
96
|
-
size(): number;
|
|
97
|
-
forEach(cb: (id: number) => void): void;
|
|
98
|
-
private validateId;
|
|
99
|
-
}
|
|
63
|
+
type ComponentOptions = {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
66
|
+
declare function Component(options: ComponentOptions): ClassDecorator;
|
|
100
67
|
|
|
101
68
|
type EntityID = number;
|
|
102
69
|
declare class UnregisteredComponentStorageError extends Error {
|
|
@@ -158,6 +125,14 @@ declare class EventBus {
|
|
|
158
125
|
getBuffer<T>(key: EventKey<T>): EventBuffer<T>;
|
|
159
126
|
}
|
|
160
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;
|
|
161
136
|
declare class ResourcesManager {
|
|
162
137
|
private readonly logger;
|
|
163
138
|
private readonly items_;
|
|
@@ -205,23 +180,24 @@ declare class QueryManager {
|
|
|
205
180
|
}
|
|
206
181
|
|
|
207
182
|
type PluginID = string;
|
|
183
|
+
type PluginConstructor = ClassType<PluginBase>;
|
|
208
184
|
type PluginDependencies = {
|
|
209
185
|
components?: ComponentType[];
|
|
210
186
|
resources?: ClassType<any>[];
|
|
211
187
|
systems?: ClassType<SystemBase>[];
|
|
212
188
|
plugins?: Array<{
|
|
213
|
-
|
|
189
|
+
plugin: PluginConstructor;
|
|
214
190
|
version?: string;
|
|
215
191
|
}>;
|
|
216
192
|
};
|
|
217
193
|
interface PluginMetadata {
|
|
218
|
-
id
|
|
194
|
+
id?: PluginID;
|
|
219
195
|
version: string;
|
|
220
196
|
name: string;
|
|
221
197
|
dependencies?: PluginDependencies;
|
|
222
198
|
}
|
|
223
199
|
declare function Plugin(metadata: PluginMetadata): ClassDecorator;
|
|
224
|
-
declare function getPluginMetadata(plugin:
|
|
200
|
+
declare function getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
225
201
|
declare function isPlugin(ctor: Function): boolean;
|
|
226
202
|
declare abstract class PluginBase {
|
|
227
203
|
onPluginLoad?: () => void;
|
|
@@ -229,34 +205,33 @@ declare abstract class PluginBase {
|
|
|
229
205
|
onAfterWorldInit?: (world: World) => void;
|
|
230
206
|
}
|
|
231
207
|
declare class PluginError extends Error {
|
|
232
|
-
constructor(pluginId:
|
|
208
|
+
constructor(pluginId: PluginConstructor);
|
|
233
209
|
}
|
|
234
210
|
declare class ErrNotAPlugin extends Error {
|
|
235
211
|
constructor(target: Function);
|
|
236
212
|
}
|
|
237
213
|
declare class ErrMissingPluginMetadata extends Error {
|
|
238
|
-
constructor(plugin:
|
|
214
|
+
constructor(plugin: PluginConstructor);
|
|
239
215
|
}
|
|
240
216
|
declare class ErrUnknownPlugin extends PluginError {
|
|
241
|
-
constructor(pluginId:
|
|
217
|
+
constructor(pluginId: PluginConstructor);
|
|
242
218
|
}
|
|
243
219
|
declare class ErrPluginNotInit extends PluginError {
|
|
244
|
-
constructor(pluginId:
|
|
220
|
+
constructor(pluginId: PluginConstructor);
|
|
245
221
|
}
|
|
246
222
|
declare class PluginsManager {
|
|
247
223
|
private readonly logger;
|
|
248
224
|
private plugins_;
|
|
249
225
|
private isInitiated_;
|
|
250
226
|
constructor(logger: Logger);
|
|
251
|
-
install<T extends
|
|
227
|
+
install<T extends PluginConstructor>(plugin: T, ...constructorProps: ConstructorParameters<T>): void;
|
|
252
228
|
build(): void;
|
|
253
229
|
/**
|
|
254
230
|
* @internal
|
|
255
231
|
*/
|
|
256
232
|
__internal__onAfterWorldInit(world: World): void;
|
|
257
|
-
getPluginMetadata(
|
|
258
|
-
getPluginInstance<T extends PluginBase>(
|
|
259
|
-
private resolveId;
|
|
233
|
+
getPluginMetadata(plugin: PluginConstructor): PluginMetadata;
|
|
234
|
+
getPluginInstance<T extends PluginBase>(plugin: ClassType<T>): T;
|
|
260
235
|
}
|
|
261
236
|
|
|
262
237
|
interface TimeSource {
|
|
@@ -312,6 +287,8 @@ declare class World {
|
|
|
312
287
|
readonly plugins: PluginsManager;
|
|
313
288
|
private readonly logger;
|
|
314
289
|
private entityRefs_;
|
|
290
|
+
private updatesCount_;
|
|
291
|
+
get updatesCount(): number;
|
|
315
292
|
constructor(params: WorldConstructor);
|
|
316
293
|
getEntityRef(id: number): EntityRef;
|
|
317
294
|
query(params: QueryParameters): number[];
|
|
@@ -364,12 +341,14 @@ type SystemMetadata = {
|
|
|
364
341
|
*/
|
|
365
342
|
computeAfter?: Set<SystemCtor>;
|
|
366
343
|
phase?: SystemPhase;
|
|
344
|
+
name: string;
|
|
367
345
|
};
|
|
368
346
|
type SystemDecoratorProps = {
|
|
369
347
|
query: SystemMetadata['query'];
|
|
370
348
|
requiredComponents?: ComponentType[];
|
|
371
349
|
computeAfter?: SystemCtor[];
|
|
372
350
|
phase?: SystemPhase;
|
|
351
|
+
name: SystemMetadata['name'];
|
|
373
352
|
};
|
|
374
353
|
declare function System(props: SystemDecoratorProps): ClassDecorator;
|
|
375
354
|
declare function getSystemMetadata(system: SystemCtor): SystemMetadata;
|
|
@@ -513,4 +492,4 @@ declare class Engine {
|
|
|
513
492
|
start(): void;
|
|
514
493
|
}
|
|
515
494
|
|
|
516
|
-
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,
|
|
495
|
+
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.js
CHANGED
|
@@ -75,7 +75,8 @@ function System(props) {
|
|
|
75
75
|
const requiredComponents = new Set(props.requiredComponents);
|
|
76
76
|
const computeAfter = new Set(props.computeAfter);
|
|
77
77
|
const phase = props.phase ?? 1 /* MAIN */;
|
|
78
|
-
const
|
|
78
|
+
const name = props.name ?? target.name;
|
|
79
|
+
const metadata = { query, requiredComponents, computeAfter, phase, name };
|
|
79
80
|
systemTarget[SystemMetadataSymbol] = metadata;
|
|
80
81
|
};
|
|
81
82
|
}
|
|
@@ -121,7 +122,8 @@ var SystemsManager = class {
|
|
|
121
122
|
this.requiredComponents_.add(c);
|
|
122
123
|
for (const c of requiredComponents)
|
|
123
124
|
this.requiredComponents_.add(c);
|
|
124
|
-
|
|
125
|
+
const meta = getSystemMetadata(ctor);
|
|
126
|
+
this.logger.debug(() => `[Systems]: system "${meta.name}" was registered`);
|
|
125
127
|
}
|
|
126
128
|
build() {
|
|
127
129
|
this.buildSystemsArray();
|
|
@@ -413,55 +415,41 @@ var ComponentStorage = class {
|
|
|
413
415
|
}
|
|
414
416
|
};
|
|
415
417
|
|
|
416
|
-
// src/ecs/components/
|
|
417
|
-
var
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
remove(id2) {
|
|
436
|
-
if (!this.validateId(id2))
|
|
437
|
-
return;
|
|
438
|
-
this.value = null;
|
|
439
|
-
this.entityId = null;
|
|
440
|
-
}
|
|
441
|
-
get(id2) {
|
|
442
|
-
if (!this.validateId(id2))
|
|
443
|
-
return null;
|
|
444
|
-
return this.value;
|
|
445
|
-
}
|
|
446
|
-
tryGet(id2) {
|
|
447
|
-
if (!this.validateId(id2))
|
|
448
|
-
throw new Error("[SingletoneStorage]: ID missmatch.");
|
|
449
|
-
return this.value;
|
|
450
|
-
}
|
|
451
|
-
has(id2) {
|
|
452
|
-
return this.validateId(id2);
|
|
453
|
-
}
|
|
454
|
-
size() {
|
|
455
|
-
return this.value !== null ? 1 : 0;
|
|
456
|
-
}
|
|
457
|
-
forEach(cb) {
|
|
458
|
-
if (this.entityId !== null)
|
|
459
|
-
cb(this.entityId);
|
|
418
|
+
// src/ecs/components/utils.ts
|
|
419
|
+
var registry = /* @__PURE__ */ new Map();
|
|
420
|
+
var id = 0;
|
|
421
|
+
var ComponentMetadataSymbol = /* @__PURE__ */ Symbol("component");
|
|
422
|
+
function Component(options) {
|
|
423
|
+
return (target) => {
|
|
424
|
+
const metadata = {
|
|
425
|
+
name: options.name,
|
|
426
|
+
id: ++id
|
|
427
|
+
};
|
|
428
|
+
registry.set(target, metadata.id);
|
|
429
|
+
target[ComponentMetadataSymbol] = metadata;
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function getComponentId(ctor) {
|
|
433
|
+
const id2 = registry.get(ctor);
|
|
434
|
+
if (id2 === void 0) {
|
|
435
|
+
throw new Error(`Component not registered: ${ctor.name}`);
|
|
460
436
|
}
|
|
461
|
-
|
|
462
|
-
|
|
437
|
+
return id2;
|
|
438
|
+
}
|
|
439
|
+
var ErrNotComponent = class extends Error {
|
|
440
|
+
constructor(ctor) {
|
|
441
|
+
super(`Class ${ctor.name} is not a Component. Use @Component decorator to define components.`);
|
|
463
442
|
}
|
|
464
443
|
};
|
|
444
|
+
function getComponentMetadata(component) {
|
|
445
|
+
if (isComponent(component)) {
|
|
446
|
+
return component[ComponentMetadataSymbol];
|
|
447
|
+
}
|
|
448
|
+
throw new ErrNotComponent(component);
|
|
449
|
+
}
|
|
450
|
+
function isComponent(ctor) {
|
|
451
|
+
return ComponentMetadataSymbol in ctor;
|
|
452
|
+
}
|
|
465
453
|
|
|
466
454
|
// src/ecs/components/manager.ts
|
|
467
455
|
var ComponentAlreadyRegisteredError = class extends Error {
|
|
@@ -470,9 +458,11 @@ var ComponentAlreadyRegisteredError = class extends Error {
|
|
|
470
458
|
}
|
|
471
459
|
};
|
|
472
460
|
var ComponentsManager = class {
|
|
473
|
-
constructor(maxEntityCount = ECS_DEFAULTS.MAX_ENTITY_COUNT) {
|
|
461
|
+
constructor(logger, maxEntityCount = ECS_DEFAULTS.MAX_ENTITY_COUNT) {
|
|
462
|
+
this.logger = logger;
|
|
474
463
|
this.maxEntityCount = maxEntityCount;
|
|
475
464
|
}
|
|
465
|
+
logger;
|
|
476
466
|
maxEntityCount;
|
|
477
467
|
storages_ = /* @__PURE__ */ new Map();
|
|
478
468
|
currId_ = 0;
|
|
@@ -482,19 +472,10 @@ var ComponentsManager = class {
|
|
|
482
472
|
register(component, opts) {
|
|
483
473
|
if (this.storages_.has(component))
|
|
484
474
|
return this.storages_.get(component);
|
|
485
|
-
|
|
486
|
-
switch (opts?.storageType) {
|
|
487
|
-
case 2 /* SINGLETON_STORAGE */:
|
|
488
|
-
store = this.createSingletonStore(opts);
|
|
489
|
-
break;
|
|
490
|
-
case 1 /* COMPONENT_STORAGE */:
|
|
491
|
-
store = this.createComponentStore(component, opts);
|
|
492
|
-
break;
|
|
493
|
-
default:
|
|
494
|
-
store = this.createComponentStore(component, opts);
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
475
|
+
const store = this.createComponentStore(component, opts);
|
|
497
476
|
this.storages_.set(component, store);
|
|
477
|
+
const meta = getComponentMetadata(component);
|
|
478
|
+
this.logger.debug(() => `[Components]: Registered component "${meta.name}"`);
|
|
498
479
|
return store;
|
|
499
480
|
}
|
|
500
481
|
createComponentStore(component, opts) {
|
|
@@ -503,12 +484,6 @@ var ComponentsManager = class {
|
|
|
503
484
|
store._internalSetId(this.nextId());
|
|
504
485
|
return store;
|
|
505
486
|
}
|
|
506
|
-
createSingletonStore(opts) {
|
|
507
|
-
if (!opts?.factory) {
|
|
508
|
-
throw new Error("For singletone storage provide factory is required!");
|
|
509
|
-
}
|
|
510
|
-
return new SingletonStorage(opts.factory);
|
|
511
|
-
}
|
|
512
487
|
getStorage(component) {
|
|
513
488
|
const store = this.storages_.get(component);
|
|
514
489
|
if (store === void 0)
|
|
@@ -520,24 +495,30 @@ var ComponentsManager = class {
|
|
|
520
495
|
}
|
|
521
496
|
};
|
|
522
497
|
|
|
523
|
-
// src/ecs/
|
|
524
|
-
var
|
|
525
|
-
|
|
526
|
-
function Component() {
|
|
498
|
+
// src/ecs/resources/resources.ts
|
|
499
|
+
var ResourceMetadataSymbol = /* @__PURE__ */ Symbol("resource");
|
|
500
|
+
function Resource(params) {
|
|
527
501
|
return (target) => {
|
|
528
|
-
|
|
529
|
-
|
|
502
|
+
const metadata = {
|
|
503
|
+
name: params.name
|
|
504
|
+
};
|
|
505
|
+
target[ResourceMetadataSymbol] = metadata;
|
|
530
506
|
};
|
|
531
507
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
throw new Error(`Component not registered: ${ctor.name}`);
|
|
508
|
+
var ErrNotResource = class extends Error {
|
|
509
|
+
constructor(ctor) {
|
|
510
|
+
super(`Class ${ctor.name} is not a Resource. Use @Resource decorator to define resources.`);
|
|
536
511
|
}
|
|
537
|
-
|
|
512
|
+
};
|
|
513
|
+
function getResourceMetadata(resource) {
|
|
514
|
+
if (isResource(resource)) {
|
|
515
|
+
return resource[ResourceMetadataSymbol];
|
|
516
|
+
}
|
|
517
|
+
throw new ErrNotResource(resource);
|
|
518
|
+
}
|
|
519
|
+
function isResource(ctor) {
|
|
520
|
+
return ResourceMetadataSymbol in ctor;
|
|
538
521
|
}
|
|
539
|
-
|
|
540
|
-
// src/ecs/resources/resources.ts
|
|
541
522
|
var ResourcesManager = class {
|
|
542
523
|
constructor(logger) {
|
|
543
524
|
this.logger = logger;
|
|
@@ -546,13 +527,15 @@ var ResourcesManager = class {
|
|
|
546
527
|
items_ = /* @__PURE__ */ new Map();
|
|
547
528
|
insert(type, value) {
|
|
548
529
|
this.items_.set(type, value);
|
|
549
|
-
|
|
530
|
+
const metadata = getResourceMetadata(type);
|
|
531
|
+
this.logger.debug(() => `[Resources]: Inserted new Resource "${metadata.name}"`);
|
|
550
532
|
return value;
|
|
551
533
|
}
|
|
552
534
|
get(type) {
|
|
553
535
|
const value = this.items_.get(type);
|
|
536
|
+
const meta = getResourceMetadata(type);
|
|
554
537
|
if (!value)
|
|
555
|
-
throw new Error(`Resource of class ${
|
|
538
|
+
throw new Error(`Resource of class ${meta.name} does not exist!`);
|
|
556
539
|
return value;
|
|
557
540
|
}
|
|
558
541
|
getOrInsert(type, factory) {
|
|
@@ -564,7 +547,8 @@ var ResourcesManager = class {
|
|
|
564
547
|
return value;
|
|
565
548
|
}
|
|
566
549
|
remove(type) {
|
|
567
|
-
|
|
550
|
+
const meta = getResourceMetadata(type);
|
|
551
|
+
this.logger.debug(() => `[Resources]: Removed resource "${meta.name}"`);
|
|
568
552
|
this.items_.delete(type);
|
|
569
553
|
}
|
|
570
554
|
};
|
|
@@ -598,7 +582,10 @@ var Commands = class {
|
|
|
598
582
|
}
|
|
599
583
|
};
|
|
600
584
|
this.add(cmd);
|
|
601
|
-
this.logger.debug(() =>
|
|
585
|
+
this.logger.debug(() => {
|
|
586
|
+
const components = entries.map((x) => getComponentMetadata(x[0]).name).join(", ");
|
|
587
|
+
return `[Commands.createEntity]: Created new entity with ID ${id2}. Linked components: [${components}]`;
|
|
588
|
+
});
|
|
602
589
|
return id2;
|
|
603
590
|
}
|
|
604
591
|
};
|
|
@@ -798,14 +785,14 @@ var PluginsManager = class {
|
|
|
798
785
|
if (!isPlugin(plugin))
|
|
799
786
|
throw new ErrMissingPluginMetadata(plugin);
|
|
800
787
|
const metadata = getPluginMetadata(plugin);
|
|
801
|
-
if (this.plugins_.has(
|
|
788
|
+
if (this.plugins_.has(plugin))
|
|
802
789
|
return;
|
|
803
790
|
const entry2 = {
|
|
804
791
|
ctor: plugin,
|
|
805
792
|
ctorParams: constructorProps,
|
|
806
793
|
metadata
|
|
807
794
|
};
|
|
808
|
-
this.plugins_.set(
|
|
795
|
+
this.plugins_.set(plugin, entry2);
|
|
809
796
|
this.logger.debug(() => `[Plugins]: Installed plugin ${metadata.name} (${metadata.version})`);
|
|
810
797
|
}
|
|
811
798
|
build() {
|
|
@@ -816,15 +803,15 @@ var PluginsManager = class {
|
|
|
816
803
|
for (const id2 of this.plugins_.keys()) {
|
|
817
804
|
nodes.set(id2, new DAGNode(id2));
|
|
818
805
|
}
|
|
819
|
-
for (const [
|
|
820
|
-
const node = nodes.get(
|
|
806
|
+
for (const [plugin, entry2] of this.plugins_) {
|
|
807
|
+
const node = nodes.get(plugin);
|
|
821
808
|
const depPlugins = entry2.metadata.dependencies?.plugins ?? [];
|
|
822
809
|
for (const dep of depPlugins) {
|
|
823
|
-
const depNode = nodes.get(dep.
|
|
810
|
+
const depNode = nodes.get(dep.plugin);
|
|
824
811
|
if (!depNode) {
|
|
825
|
-
throw new ErrMissingPluginDependency(
|
|
812
|
+
throw new ErrMissingPluginDependency(plugin, dep.plugin);
|
|
826
813
|
}
|
|
827
|
-
|
|
814
|
+
depNode.vertices.push(node);
|
|
828
815
|
}
|
|
829
816
|
}
|
|
830
817
|
let sortedNodes;
|
|
@@ -854,31 +841,20 @@ var PluginsManager = class {
|
|
|
854
841
|
p.instance?.onAfterWorldInit?.(world);
|
|
855
842
|
}
|
|
856
843
|
}
|
|
857
|
-
getPluginMetadata(
|
|
858
|
-
const
|
|
859
|
-
|
|
860
|
-
if (!entry2) throw new ErrUnknownPlugin(id2);
|
|
844
|
+
getPluginMetadata(plugin) {
|
|
845
|
+
const entry2 = this.plugins_.get(plugin);
|
|
846
|
+
if (!entry2) throw new ErrUnknownPlugin(plugin);
|
|
861
847
|
return entry2.metadata;
|
|
862
848
|
}
|
|
863
|
-
getPluginInstance(
|
|
849
|
+
getPluginInstance(plugin) {
|
|
850
|
+
const entry2 = this.plugins_.get(plugin);
|
|
851
|
+
if (!entry2) throw new ErrUnknownPlugin(plugin);
|
|
852
|
+
if (!entry2.instance) throw new ErrPluginNotInit(plugin);
|
|
864
853
|
if (!this.isInitiated_) {
|
|
865
|
-
throw new
|
|
854
|
+
throw new ErrPluginNotInit(plugin);
|
|
866
855
|
}
|
|
867
|
-
const id2 = this.resolveId(pluginOrId);
|
|
868
|
-
const entry2 = this.plugins_.get(id2);
|
|
869
|
-
if (!entry2) throw new ErrUnknownPlugin(id2);
|
|
870
|
-
if (!entry2.instance) throw new ErrPluginNotInit(id2);
|
|
871
856
|
return entry2.instance;
|
|
872
857
|
}
|
|
873
|
-
resolveId(pluginOrId) {
|
|
874
|
-
if (typeof pluginOrId === "string") {
|
|
875
|
-
return pluginOrId;
|
|
876
|
-
}
|
|
877
|
-
if (!isPlugin(pluginOrId)) {
|
|
878
|
-
throw new ErrMissingPluginMetadata(pluginOrId);
|
|
879
|
-
}
|
|
880
|
-
return getPluginMetadata(pluginOrId).id;
|
|
881
|
-
}
|
|
882
858
|
};
|
|
883
859
|
|
|
884
860
|
// src/ecs/world.ts
|
|
@@ -893,9 +869,13 @@ var World3 = class {
|
|
|
893
869
|
plugins;
|
|
894
870
|
logger;
|
|
895
871
|
entityRefs_ = /* @__PURE__ */ new Map();
|
|
872
|
+
updatesCount_ = 0;
|
|
873
|
+
get updatesCount() {
|
|
874
|
+
return this.updatesCount_;
|
|
875
|
+
}
|
|
896
876
|
constructor(params) {
|
|
897
877
|
this.entities = new EntitiesManager(params.logger);
|
|
898
|
-
this.components = new ComponentsManager(params.maxEntityCount ?? ECS_DEFAULTS.MAX_ENTITY_COUNT);
|
|
878
|
+
this.components = new ComponentsManager(params.logger, params.maxEntityCount ?? ECS_DEFAULTS.MAX_ENTITY_COUNT);
|
|
899
879
|
this.systems = new SystemsManager(this, params.logger);
|
|
900
880
|
this.events = new EventBus();
|
|
901
881
|
this.resources = new ResourcesManager(params.logger);
|
|
@@ -941,6 +921,7 @@ var World3 = class {
|
|
|
941
921
|
update(clock) {
|
|
942
922
|
this.systems.update(clock.getTime());
|
|
943
923
|
this.commands.flush(this);
|
|
924
|
+
this.updatesCount_++;
|
|
944
925
|
}
|
|
945
926
|
build() {
|
|
946
927
|
this.plugins.build();
|
|
@@ -1235,9 +1216,9 @@ export {
|
|
|
1235
1216
|
PluginBase,
|
|
1236
1217
|
PluginError,
|
|
1237
1218
|
PluginsManager,
|
|
1219
|
+
Resource,
|
|
1238
1220
|
ResourcesManager,
|
|
1239
1221
|
Runtime,
|
|
1240
|
-
SingletonStorage,
|
|
1241
1222
|
System,
|
|
1242
1223
|
SystemBase,
|
|
1243
1224
|
SystemError,
|
|
@@ -1249,6 +1230,7 @@ export {
|
|
|
1249
1230
|
createEventKey,
|
|
1250
1231
|
entry,
|
|
1251
1232
|
getPluginMetadata,
|
|
1233
|
+
getResourceMetadata,
|
|
1252
1234
|
getSystemMetadata,
|
|
1253
1235
|
isPlugin,
|
|
1254
1236
|
isSystem,
|