qti-clockwork-ecs 0.1.0

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 ADDED
@@ -0,0 +1,173 @@
1
+ Clockwork Engine
2
+ Copyright (C) 2026 Quiet Terminal Interactive LTD
3
+
4
+ This project is licensed under the GNU Lesser General Public License v3.0.
5
+ See the license text below.
6
+
7
+ -----------------------------------------------------------------------
8
+
9
+ GNU LESSER GENERAL PUBLIC LICENSE
10
+ Version 3, 29 June 2007
11
+
12
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
13
+ Everyone is permitted to copy and distribute verbatim copies
14
+ of this license document, but changing it is not allowed.
15
+
16
+
17
+ This version of the GNU Lesser General Public License incorporates
18
+ the terms and conditions of version 3 of the GNU General Public
19
+ License, supplemented by the additional permissions listed below.
20
+
21
+ 0. Additional Definitions.
22
+
23
+ As used herein, "this License" refers to version 3 of the GNU Lesser
24
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
25
+ General Public License.
26
+
27
+ "The Library" refers to a covered work governed by this License,
28
+ other than an Application or a Combined Work as defined below.
29
+
30
+ An "Application" is any work that makes use of an interface provided
31
+ by the Library, but which is not otherwise based on the Library.
32
+ Defining a subclass of a class defined by the Library is deemed a mode
33
+ of using an interface provided by the Library.
34
+
35
+ A "Combined Work" is a work produced by combining or linking an
36
+ Application with the Library. The particular version of the Library
37
+ with which the Combined Work was made is also called the "Linked
38
+ Version".
39
+
40
+ The "Minimal Corresponding Source" for a Combined Work means the
41
+ Corresponding Source for the Combined Work, excluding any source code
42
+ for portions of the Combined Work that, considered in isolation, are
43
+ based on the Application, and not on the Linked Version.
44
+
45
+ The "Corresponding Application Code" for a Combined Work means the
46
+ object code and/or source code for the Application, including any data
47
+ and utility programs needed for reproducing the Combined Work from the
48
+ Application, but excluding the System Libraries of the Combined Work.
49
+
50
+ 1. Exception to Section 3 of the GNU GPL.
51
+
52
+ You may convey a covered work under sections 3 and 4 of this License
53
+ without being bound by section 3 of the GNU GPL.
54
+
55
+ 2. Conveying Modified Versions.
56
+
57
+ If you modify a copy of the Library, and, in your modifications, a
58
+ facility refers to a function or data to be supplied by an Application
59
+ that uses the facility (other than as an argument passed when the
60
+ facility is invoked), then you may convey a copy of the modified
61
+ version:
62
+
63
+ a) under this License, provided that you make a good faith effort to
64
+ ensure that, in the event an Application does not supply the
65
+ function or data, the facility still operates, and performs
66
+ whatever part of its purpose remains meaningful, or
67
+
68
+ b) under the GNU GPL, with none of the additional permissions of
69
+ this License applicable to that copy.
70
+
71
+ 3. Object Code Incorporating Material from Library Header Files.
72
+
73
+ The object code form of an Application may incorporate material from
74
+ a header file that is part of the Library. You may convey such object
75
+ code under terms of your choice, provided that, if the incorporated
76
+ material is not limited to numerical parameters, data structure
77
+ layouts and accessors, or small macros, inline functions and templates
78
+ (ten or fewer lines in length), you do both of the following:
79
+
80
+ a) Give prominent notice with each copy of the object code that the
81
+ Library is used in it and that the Library and its use are
82
+ covered by this License.
83
+
84
+ b) Accompany the object code with a copy of the GNU GPL and this license
85
+ document.
86
+
87
+ 4. Combined Works.
88
+
89
+ You may convey a Combined Work under terms of your choice that,
90
+ taken together, effectively do not restrict modification of the
91
+ portions of the Library contained in the Combined Work and reverse
92
+ engineering for debugging such modifications, if you also do each of
93
+ the following:
94
+
95
+ a) Give prominent notice with each copy of the Combined Work that
96
+ the Library is used in it and that the Library and its use are
97
+ covered by this License.
98
+
99
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
100
+ document.
101
+
102
+ c) For a Combined Work that displays copyright notices during
103
+ execution, include the copyright notice for the Library among
104
+ these notices, as well as a reference directing the user to the
105
+ copies of the GNU GPL and this license document.
106
+
107
+ d) Do one of the following:
108
+
109
+ 0) Convey the Minimal Corresponding Source under the terms of this
110
+ License, and the Corresponding Application Code in a form
111
+ suitable for, and under terms that permit, the user to
112
+ recombine or relink the Application with a modified version of
113
+ the Linked Version to produce a modified Combined Work, in the
114
+ manner specified by section 6 of the GNU GPL for conveying
115
+ Corresponding Source.
116
+
117
+ 1) Use a suitable shared library mechanism for linking with the
118
+ Library. A suitable mechanism is one that (a) uses at run time
119
+ a copy of the Library already present on the user's computer
120
+ system, and (b) will operate properly with a modified version
121
+ of the Library that is interface-compatible with the Linked
122
+ Version.
123
+
124
+ e) Provide Installation Information, but only if you would otherwise
125
+ be required to provide such information under section 6 of the
126
+ GNU GPL, and only to the extent that such information is
127
+ necessary to install and execute a modified version of the
128
+ Combined Work produced by recombining or relinking the
129
+ Application with a modified version of the Linked Version. (If
130
+ you use option 4d0, the Installation Information must accompany
131
+ the Minimal Corresponding Source and Corresponding Application
132
+ Code. If you use option 4d1, you must provide the Installation
133
+ Information in the manner specified by section 6 of the GNU GPL
134
+ for conveying Corresponding Source.)
135
+
136
+ 5. Combined Libraries.
137
+
138
+ You may place library facilities that are a work based on the
139
+ Library side by side in a single library together with other library
140
+ facilities that are not Applications and are not covered by this
141
+ License, and convey such a combined library under terms of your
142
+ choice, if you do both of the following:
143
+
144
+ a) Accompany the combined library with a copy of the same work based
145
+ on the Library, uncombined with any other library facilities,
146
+ conveyed under the terms of this License.
147
+
148
+ b) Give prominent notice with the combined library that part of it
149
+ is a work based on the Library, and explaining where to find the
150
+ accompanying uncombined form of the same work.
151
+
152
+ 6. Revised Versions of the GNU Lesser General Public License.
153
+
154
+ The Free Software Foundation may publish revised and/or new versions
155
+ of the GNU Lesser General Public License from time to time. Such new
156
+ versions will be similar in spirit to the present version, but may
157
+ differ in detail to address new problems or concerns.
158
+
159
+ Each version is given a distinguishing version number. If the
160
+ Library as you received it specifies that a certain numbered version
161
+ of the GNU Lesser General Public License "or any later version"
162
+ applies to it, you have the option of following the terms and
163
+ conditions either of that published version or of any later version
164
+ published by the Free Software Foundation. If the Library as you
165
+ received it does not specify a version number of the GNU Lesser
166
+ General Public License, you may choose any version of the GNU Lesser
167
+ General Public License ever published by the Free Software Foundation.
168
+
169
+ If the Library as you received it specifies that a proxy can decide
170
+ whether future versions of the GNU Lesser General Public License shall
171
+ apply, that proxy's public statement of acceptance of any version is
172
+ permanent authorization for you to choose that version for the
173
+ Library.
package/dist/index.cjs ADDED
@@ -0,0 +1,532 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BuiltinResourceTypes: () => BuiltinResourceTypes,
24
+ CommandBuffer: () => CommandBuffer,
25
+ ComponentStore: () => ComponentStore,
26
+ DeferredEntityBuilder: () => DeferredEntityBuilder,
27
+ EntityBuilder: () => EntityBuilder,
28
+ EntityManager: () => EntityManager,
29
+ ObjectPool: () => ObjectPool,
30
+ Query: () => Query,
31
+ ResourceMap: () => ResourceMap,
32
+ ResourceType: () => ResourceType,
33
+ World: () => World,
34
+ collectWorldStats: () => collectWorldStats,
35
+ packageId: () => packageId
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+ var packageId = "qti-clockwork-ecs";
39
+ var ResourceType = class _ResourceType {
40
+ static symbolIds = /* @__PURE__ */ new Map();
41
+ static ctorIds = /* @__PURE__ */ new WeakMap();
42
+ static nextId = 0;
43
+ id;
44
+ version;
45
+ dependencies;
46
+ constructor(id, options) {
47
+ this.id = id;
48
+ this.version = options?.version ?? 1;
49
+ this.dependencies = options?.dependencies ?? [];
50
+ }
51
+ static fromToken(token) {
52
+ if (typeof token === "string") {
53
+ return new _ResourceType(`string:${token}`);
54
+ }
55
+ if (typeof token === "symbol") {
56
+ let symbolId = this.symbolIds.get(token);
57
+ if (symbolId === void 0) {
58
+ symbolId = this.nextId++;
59
+ this.symbolIds.set(token, symbolId);
60
+ }
61
+ return new _ResourceType(`symbol:${symbolId}`);
62
+ }
63
+ let ctorId = this.ctorIds.get(token);
64
+ if (ctorId === void 0) {
65
+ ctorId = this.nextId++;
66
+ this.ctorIds.set(token, ctorId);
67
+ }
68
+ return new _ResourceType(`ctor:${ctorId}`);
69
+ }
70
+ };
71
+ var ResourceMap = class {
72
+ values = /* @__PURE__ */ new Map();
73
+ revision = 0;
74
+ insert(type, resource) {
75
+ for (const dependency of type.dependencies) {
76
+ const installed = this.values.get(dependency.id);
77
+ if (!installed) {
78
+ throw new Error(
79
+ `Resource "${type.id}" depends on missing "${dependency.id}"`
80
+ );
81
+ }
82
+ if (installed.type.version < dependency.version) {
83
+ throw new Error(
84
+ `Resource "${type.id}" requires "${dependency.id}" version ${dependency.version}+, found ${installed.type.version}`
85
+ );
86
+ }
87
+ }
88
+ this.revision += 1;
89
+ this.values.set(type.id, {
90
+ type,
91
+ value: resource,
92
+ revision: this.revision
93
+ });
94
+ }
95
+ get(type) {
96
+ const resource = this.tryGet(type);
97
+ if (resource === void 0) {
98
+ throw new Error(
99
+ `Resource "${type.id}" is not registered (required version ${type.version})`
100
+ );
101
+ }
102
+ return resource;
103
+ }
104
+ tryGet(type) {
105
+ const stored = this.values.get(type.id);
106
+ if (!stored) {
107
+ return void 0;
108
+ }
109
+ return stored.value;
110
+ }
111
+ remove(type) {
112
+ this.values.delete(type.id);
113
+ }
114
+ has(type) {
115
+ return this.values.has(type.id);
116
+ }
117
+ getInstalledVersion(type) {
118
+ return this.values.get(type.id)?.type.version;
119
+ }
120
+ getRevision(type) {
121
+ return this.values.get(type.id)?.revision;
122
+ }
123
+ };
124
+ var BuiltinResourceTypes = {
125
+ Time: new ResourceType("builtin:Time"),
126
+ Input: new ResourceType("builtin:Input"),
127
+ Assets: new ResourceType("builtin:Assets"),
128
+ Renderer: new ResourceType("builtin:Renderer"),
129
+ AudioContext: new ResourceType("builtin:AudioContext"),
130
+ Rng: new ResourceType("builtin:Rng"),
131
+ Config: new ResourceType("builtin:Config"),
132
+ Profiler: new ResourceType("builtin:Profiler")
133
+ };
134
+ var EntityManager = class {
135
+ generations = [];
136
+ alive = [];
137
+ freeIndices = [];
138
+ aliveCount = 0;
139
+ create() {
140
+ this.aliveCount += 1;
141
+ const index = this.freeIndices.pop();
142
+ if (index === void 0) {
143
+ const newIndex = this.generations.length;
144
+ this.generations.push(0);
145
+ this.alive.push(true);
146
+ return { index: newIndex, generation: 0 };
147
+ }
148
+ this.alive[index] = true;
149
+ return { index, generation: this.generations[index] };
150
+ }
151
+ destroy(entity) {
152
+ if (!this.isAlive(entity)) {
153
+ return;
154
+ }
155
+ this.aliveCount -= 1;
156
+ const { index } = entity;
157
+ this.alive[index] = false;
158
+ this.generations[index] = this.generations[index] + 1 >>> 0;
159
+ this.freeIndices.push(index);
160
+ }
161
+ isAlive(entity) {
162
+ const { index, generation } = entity;
163
+ if (index < 0 || index >= this.generations.length) {
164
+ return false;
165
+ }
166
+ return this.alive[index] === true && this.generations[index] === generation;
167
+ }
168
+ getGeneration(entity) {
169
+ if (entity.index < 0 || entity.index >= this.generations.length) {
170
+ return 0;
171
+ }
172
+ return this.generations[entity.index];
173
+ }
174
+ *iterAlive() {
175
+ for (let index = 0; index < this.alive.length; index += 1) {
176
+ if (!this.alive[index]) {
177
+ continue;
178
+ }
179
+ yield { index, generation: this.generations[index] };
180
+ }
181
+ }
182
+ };
183
+ var ComponentStore = class {
184
+ values = /* @__PURE__ */ new Map();
185
+ add(entity, component, changeTick = 0) {
186
+ this.values.set(entity.index, {
187
+ generation: entity.generation,
188
+ value: component,
189
+ changedAt: changeTick
190
+ });
191
+ }
192
+ remove(entity) {
193
+ const current = this.values.get(entity.index);
194
+ if (!current || current.generation !== entity.generation) {
195
+ return;
196
+ }
197
+ this.values.delete(entity.index);
198
+ }
199
+ removeByIndex(index) {
200
+ this.values.delete(index);
201
+ }
202
+ get(entity) {
203
+ const current = this.values.get(entity.index);
204
+ if (!current || current.generation !== entity.generation) {
205
+ return void 0;
206
+ }
207
+ return current.value;
208
+ }
209
+ has(entity) {
210
+ const current = this.values.get(entity.index);
211
+ return Boolean(current && current.generation === entity.generation);
212
+ }
213
+ getChangedAt(entity) {
214
+ const current = this.values.get(entity.index);
215
+ if (!current || current.generation !== entity.generation) {
216
+ return void 0;
217
+ }
218
+ return current.changedAt;
219
+ }
220
+ *iter() {
221
+ const keys = [...this.values.keys()].sort((a, b) => a - b);
222
+ for (const index of keys) {
223
+ const stored = this.values.get(index);
224
+ yield [{ index, generation: stored.generation }, stored.value];
225
+ }
226
+ }
227
+ sortedEntities() {
228
+ const keys = [...this.values.keys()].sort((a, b) => a - b);
229
+ const result = new Array(keys.length);
230
+ for (let i = 0; i < keys.length; i += 1) {
231
+ const index = keys[i];
232
+ const stored = this.values.get(index);
233
+ result[i] = { index, generation: stored.generation };
234
+ }
235
+ return result;
236
+ }
237
+ };
238
+ var Query = class {
239
+ constructor(world) {
240
+ this.world = world;
241
+ }
242
+ withTypes = /* @__PURE__ */ new Set();
243
+ withoutTypes = /* @__PURE__ */ new Set();
244
+ optionalTypes = /* @__PURE__ */ new Set();
245
+ changedTypes = /* @__PURE__ */ new Set();
246
+ lastIteratedTick = -1;
247
+ with(...components) {
248
+ for (const type of components) {
249
+ this.withTypes.add(type);
250
+ }
251
+ return this;
252
+ }
253
+ without(...components) {
254
+ for (const type of components) {
255
+ this.withoutTypes.add(type);
256
+ }
257
+ return this;
258
+ }
259
+ optional(component) {
260
+ this.optionalTypes.add(component);
261
+ return this;
262
+ }
263
+ changed(component) {
264
+ this.changedTypes.add(component);
265
+ return this;
266
+ }
267
+ *iter() {
268
+ const candidates = this.collectCandidates();
269
+ for (const entity of candidates) {
270
+ if (!this.matches(entity)) {
271
+ continue;
272
+ }
273
+ const components = /* @__PURE__ */ new Map();
274
+ for (const type of this.withTypes) {
275
+ components.set(type, this.world.getComponent(entity, type));
276
+ }
277
+ for (const type of this.optionalTypes) {
278
+ components.set(type, this.world.getComponent(entity, type));
279
+ }
280
+ yield { entity, components };
281
+ }
282
+ this.lastIteratedTick = this.world.currentTick;
283
+ }
284
+ collectCandidates() {
285
+ const withTypes = [...this.withTypes];
286
+ if (withTypes.length === 0) {
287
+ return [...this.world.entities.iterAlive()];
288
+ }
289
+ const seedStore = this.world.getStore(withTypes[0]);
290
+ if (!seedStore) {
291
+ return [];
292
+ }
293
+ return seedStore.sortedEntities();
294
+ }
295
+ matches(entity) {
296
+ if (!this.world.entities.isAlive(entity)) {
297
+ return false;
298
+ }
299
+ for (const type of this.withTypes) {
300
+ if (!this.world.hasComponent(entity, type)) {
301
+ return false;
302
+ }
303
+ }
304
+ for (const type of this.withoutTypes) {
305
+ if (this.world.hasComponent(entity, type)) {
306
+ return false;
307
+ }
308
+ }
309
+ for (const type of this.changedTypes) {
310
+ const changedAt = this.world.getComponentChangedAt(entity, type);
311
+ if (changedAt === void 0 || changedAt <= this.lastIteratedTick) {
312
+ return false;
313
+ }
314
+ }
315
+ return true;
316
+ }
317
+ };
318
+ var EntityBuilder = class {
319
+ constructor(world, entity) {
320
+ this.world = world;
321
+ this.entity = entity;
322
+ }
323
+ with(type, component) {
324
+ this.world.addComponent(this.entity, type, component);
325
+ return this;
326
+ }
327
+ build() {
328
+ return this.entity;
329
+ }
330
+ };
331
+ var DeferredEntityBuilder = class {
332
+ constructor(deferred) {
333
+ this.deferred = deferred;
334
+ }
335
+ with(type, component) {
336
+ this.deferred.initialComponents.push({ type, component });
337
+ return this;
338
+ }
339
+ };
340
+ var CommandBuffer = class {
341
+ constructor(world) {
342
+ this.world = world;
343
+ }
344
+ operations = [];
345
+ spawn() {
346
+ const deferred = { initialComponents: [] };
347
+ this.operations.push({ kind: "spawn", deferred });
348
+ return new DeferredEntityBuilder(deferred);
349
+ }
350
+ destroy(entity) {
351
+ this.operations.push({ kind: "destroy", entity });
352
+ }
353
+ addComponent(entity, type, component) {
354
+ this.operations.push({ kind: "add", entity, type, component });
355
+ }
356
+ removeComponent(entity, type) {
357
+ this.operations.push({ kind: "remove", entity, type });
358
+ }
359
+ flush() {
360
+ for (const operation of this.operations) {
361
+ switch (operation.kind) {
362
+ case "spawn": {
363
+ const entity = this.world.spawnEntity();
364
+ operation.deferred.resolved = entity;
365
+ for (const entry of operation.deferred.initialComponents) {
366
+ this.world.addComponent(entity, entry.type, entry.component);
367
+ }
368
+ break;
369
+ }
370
+ case "destroy": {
371
+ const entity = this.resolveEntity(operation.entity);
372
+ if (entity) {
373
+ this.world.destroy(entity);
374
+ }
375
+ break;
376
+ }
377
+ case "add": {
378
+ const entity = this.resolveEntity(operation.entity);
379
+ if (entity) {
380
+ this.world.addComponent(entity, operation.type, operation.component);
381
+ }
382
+ break;
383
+ }
384
+ case "remove": {
385
+ const entity = this.resolveEntity(operation.entity);
386
+ if (entity) {
387
+ this.world.removeComponent(entity, operation.type);
388
+ }
389
+ break;
390
+ }
391
+ }
392
+ }
393
+ this.operations.length = 0;
394
+ }
395
+ resolveEntity(entity) {
396
+ if ("initialComponents" in entity) {
397
+ return entity.resolved;
398
+ }
399
+ return entity;
400
+ }
401
+ };
402
+ var World = class {
403
+ entities = new EntityManager();
404
+ components = /* @__PURE__ */ new Map();
405
+ resources = new ResourceMap();
406
+ changeTick = 0;
407
+ get currentTick() {
408
+ return this.changeTick;
409
+ }
410
+ spawn() {
411
+ return new EntityBuilder(this, this.spawnEntity());
412
+ }
413
+ spawnEntity() {
414
+ this.changeTick += 1;
415
+ return this.entities.create();
416
+ }
417
+ destroy(entity) {
418
+ if (!this.entities.isAlive(entity)) {
419
+ return;
420
+ }
421
+ for (const store of this.components.values()) {
422
+ store.removeByIndex(entity.index);
423
+ }
424
+ this.entities.destroy(entity);
425
+ this.changeTick += 1;
426
+ }
427
+ commands() {
428
+ return new CommandBuffer(this);
429
+ }
430
+ query() {
431
+ return new Query(this);
432
+ }
433
+ getStore(type) {
434
+ return this.components.get(type);
435
+ }
436
+ addComponent(entity, type, component) {
437
+ if (!this.entities.isAlive(entity)) {
438
+ return;
439
+ }
440
+ const store = this.ensureStore(type);
441
+ this.changeTick += 1;
442
+ store.add(entity, component, this.changeTick);
443
+ }
444
+ removeComponent(entity, type) {
445
+ if (!this.entities.isAlive(entity)) {
446
+ return;
447
+ }
448
+ const store = this.components.get(type);
449
+ if (!store) {
450
+ return;
451
+ }
452
+ store.remove(entity);
453
+ this.changeTick += 1;
454
+ }
455
+ getComponent(entity, type) {
456
+ return this.getStore(type)?.get(entity);
457
+ }
458
+ hasComponent(entity, type) {
459
+ return this.components.get(type)?.has(entity) ?? false;
460
+ }
461
+ getComponentChangedAt(entity, type) {
462
+ return this.components.get(type)?.getChangedAt(entity);
463
+ }
464
+ insertResource(type, resource) {
465
+ this.resources.insert(ResourceType.fromToken(type), resource);
466
+ }
467
+ getResource(type) {
468
+ return this.resources.get(ResourceType.fromToken(type));
469
+ }
470
+ tryGetResource(type) {
471
+ return this.resources.tryGet(ResourceType.fromToken(type));
472
+ }
473
+ removeResource(type) {
474
+ this.resources.remove(ResourceType.fromToken(type));
475
+ }
476
+ hasResource(type) {
477
+ return this.resources.has(ResourceType.fromToken(type));
478
+ }
479
+ ensureStore(type) {
480
+ let store = this.components.get(type);
481
+ if (!store) {
482
+ store = new ComponentStore();
483
+ this.components.set(type, store);
484
+ }
485
+ return store;
486
+ }
487
+ };
488
+ var ObjectPool = class {
489
+ constructor(factory, reset) {
490
+ this.factory = factory;
491
+ this.reset = reset;
492
+ }
493
+ free = [];
494
+ acquire() {
495
+ return this.free.pop() ?? this.factory();
496
+ }
497
+ release(item) {
498
+ this.reset?.(item);
499
+ this.free.push(item);
500
+ }
501
+ size() {
502
+ return this.free.length;
503
+ }
504
+ };
505
+ function collectWorldStats(world) {
506
+ const entityCount = world.entities.aliveCount;
507
+ let componentInstanceCount = 0;
508
+ for (const store of world.components.values()) {
509
+ componentInstanceCount += [...store.iter()].length;
510
+ }
511
+ return {
512
+ entityCount,
513
+ componentStoreCount: world.components.size,
514
+ componentInstanceCount
515
+ };
516
+ }
517
+ // Annotate the CommonJS export names for ESM import in node:
518
+ 0 && (module.exports = {
519
+ BuiltinResourceTypes,
520
+ CommandBuffer,
521
+ ComponentStore,
522
+ DeferredEntityBuilder,
523
+ EntityBuilder,
524
+ EntityManager,
525
+ ObjectPool,
526
+ Query,
527
+ ResourceMap,
528
+ ResourceType,
529
+ World,
530
+ collectWorldStats,
531
+ packageId
532
+ });