@woosh/meep-engine 2.128.0 → 2.128.2
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/README.md +23 -1
- package/package.json +1 -1
- package/src/core/assert.d.ts +2 -2
- package/src/core/assert.js +2 -2
- package/src/engine/ecs/Entity.d.ts.map +1 -1
- package/src/engine/ecs/Entity.js +14 -5
- package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
- package/src/engine/ecs/EntityComponentDataset.js +48 -2
- package/src/engine/ecs/EntityManager.d.ts +25 -3
- package/src/engine/ecs/EntityManager.d.ts.map +1 -1
- package/src/engine/ecs/EntityManager.js +33 -7
- package/src/engine/ecs/EntityReference.d.ts.map +1 -1
- package/src/engine/ecs/EntityReference.js +2 -0
- package/src/engine/ecs/System.d.ts.map +1 -1
- package/src/engine/ecs/System.js +3 -28
- package/src/engine/ecs/{validateSystem.d.ts → system_validate_class.d.ts} +2 -2
- package/src/engine/ecs/system_validate_class.d.ts.map +1 -0
- package/src/engine/ecs/{validateSystem.js → system_validate_class.js} +1 -1
- package/src/engine/scene/SceneManager.js +3 -3
- package/src/engine/ecs/validateSystem.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -13,11 +13,33 @@ To help get you started, various samples are provided under `/samples` folder. F
|
|
|
13
13
|
|
|
14
14
|
## Quality
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
### Testing
|
|
17
|
+
Meep is covered by 2,801 handwritten unit tests, reaching 90%+ coverage in `core` and 40%+ coverage total.
|
|
17
18
|
|
|
18
19
|
The aim is to [ensure quality](https://about.codecov.io/blog/the-case-against-100-code-coverage/). As a result, the tests are written to cover complex code first and to exhaustively validate critical algorithms.
|
|
19
20
|
Most of the test code is significantly larger than the code that is being tested.
|
|
20
21
|
|
|
22
|
+
### Assertions
|
|
23
|
+
Meep is covered by 3,162 asserts. [Assertions](https://en.wikipedia.org/wiki/Assertion_(software_development)) provide very extensive pre- and post-condition checks throughout the engine.
|
|
24
|
+
Asserts are intended primarily for development builds.
|
|
25
|
+
To remove asserts in Vite builds, you can use `@rollup/plugin-strip` package like so:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import strip from '@rollup/plugin-strip';
|
|
29
|
+
import { defineConfig } from 'vite';
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
plugins: [{
|
|
33
|
+
// this will remove all assert statements from the production build
|
|
34
|
+
...strip(),
|
|
35
|
+
apply: 'build'
|
|
36
|
+
}],
|
|
37
|
+
// ... the rest of the config ...
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Assertion package can be found under `/src/core/assert.js`.
|
|
42
|
+
|
|
21
43
|
## Package Size
|
|
22
44
|
|
|
23
45
|
Meep is infinitely tree-shakable, you only package what you use.
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"description": "Pure JavaScript game engine. Fully featured and production ready.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.128.
|
|
8
|
+
"version": "2.128.2",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
package/src/core/assert.d.ts
CHANGED
|
@@ -120,8 +120,8 @@ export namespace assert {
|
|
|
120
120
|
*/
|
|
121
121
|
export function notNaN(value: number, name?: string): void;
|
|
122
122
|
/**
|
|
123
|
-
* Is given number finite?
|
|
124
|
-
* Will trigger if number is infinite, i.e. fails the `Number.isFinite` test
|
|
123
|
+
* Is the given number finite?
|
|
124
|
+
* Will trigger if the number is infinite, i.e. fails the `Number.isFinite` test
|
|
125
125
|
* @param {number} value
|
|
126
126
|
* @param {string} [name] optional name for the value being checked
|
|
127
127
|
*/
|
package/src/core/assert.js
CHANGED
|
@@ -447,8 +447,8 @@ assert.notNaN = function (value, name = "value") {
|
|
|
447
447
|
};
|
|
448
448
|
|
|
449
449
|
/**
|
|
450
|
-
* Is given number finite?
|
|
451
|
-
* Will trigger if number is infinite, i.e. fails the `Number.isFinite` test
|
|
450
|
+
* Is the given number finite?
|
|
451
|
+
* Will trigger if the number is infinite, i.e. fails the `Number.isFinite` test
|
|
452
452
|
* @param {number} value
|
|
453
453
|
* @param {string} [name] optional name for the value being checked
|
|
454
454
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/Entity.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/Entity.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;IAkcI;;;;;;;;;;;;OAYG;IACH,+BAJW,MAAM,oCAEJ,MAAM,CAmBlB;IA9dD;;;;;OAKG;IACH,oBAFU,eAAe,CAES;IAGlC;;;OAGG;IACH,iBAEC;IAED;;;OAGG;IACH,yBAEC;IAED;;;;OAIG;IACH,2BAAgB;IAShB;;;;;;OAMG;IACH,gCAAe;IAEf;;;OAGG;IACH,OAFU,WAAW,GAAC,MAAM,CAEN;IAEtB;;;;OAIG;IACH,yBAAgB;IAEhB;;OAEG;IACH;QACI;;WAEG;;MAEL;IAUF;;;OAGG;IACH,eAFW,MAAM,GAAC,WAAW,QAI5B;IAED;;;;OAIG;IACH,cAHW,MAAM,GAAC,WAAW,GAChB,OAAO,CAMnB;IAED;;;OAGG;IACH,gBAFW,MAAM,GAAC,WAAW,QAI5B;IAED;;;;;;;OAOG;IACH,gCAEC;IAED;;OAEG;IACH,4BAUC;IAED;;;OAGG;IACH,oBAEC;IAED;;;;;;OAMG;IACH,+BAFa,MAAM,CAsBlB;IAED;;;;;OAKG;IACH,+BAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,0CAYC;IAED;;;;;OAKG;IACH,8CAQC;IAED;;;;OAIG;IACH,kCAFa,MAAE,IAAI,CA0BlB;IAED;;;;OAIG;IACH,qBAHW,MAAM,qBAWhB;IAED;;;OAGG;IACH,wBAFW,MAAM,gBAmBhB;IAED;;;;;;OAMG;IACH,4BALW,MAAM,sCAGJ,MAAM,CAgBlB;IAED;;;;;;OAMG;IACH,+BALW,MAAM,sCAGJ,MAAM,CA4BlB;IAED;;;;;;OAMG;IACH,WAJa,OAAO,CA0BnB;IAED;;;;;;;;;;;;;;;OAeG;IACH,wCANa,MAAM,CA+DlB;IAmCL;;;;OAIG;IACH,mBAFU,OAAO,CAEQ;;CAPxB;;gCA1gB+B,sBAAsB;4BAD1B,kBAAkB;mBAD3B,oCAAoC"}
|
package/src/engine/ecs/Entity.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assert } from "../../core/assert.js";
|
|
2
2
|
import Signal from "../../core/events/signal/Signal.js";
|
|
3
|
-
import { isDefined } from "../../core/process/matcher/isDefined.js";
|
|
4
3
|
import { EntityFlags } from "./EntityFlags.js";
|
|
5
4
|
import { EntityReference } from "./EntityReference.js";
|
|
6
5
|
import { EventType } from "./EventType.js";
|
|
@@ -172,7 +171,9 @@ export class Entity {
|
|
|
172
171
|
for (let i = n - 1; i >= 0; i--) {
|
|
173
172
|
const component = elements[i];
|
|
174
173
|
|
|
175
|
-
|
|
174
|
+
const ComponentClass = Object.getPrototypeOf(component).constructor;
|
|
175
|
+
|
|
176
|
+
this.removeComponent(ComponentClass);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
|
|
@@ -295,6 +296,8 @@ export class Entity {
|
|
|
295
296
|
* @param {*} [event]
|
|
296
297
|
*/
|
|
297
298
|
sendEvent(eventName, event) {
|
|
299
|
+
assert.isString(eventName, "eventName");
|
|
300
|
+
|
|
298
301
|
if (this.getFlag(EntityFlags.Built)) {
|
|
299
302
|
this.dataset.sendEvent(this.reference.id, eventName, event);
|
|
300
303
|
} else {
|
|
@@ -307,6 +310,8 @@ export class Entity {
|
|
|
307
310
|
* @param {string} eventName
|
|
308
311
|
*/
|
|
309
312
|
promiseEvent(eventName) {
|
|
313
|
+
assert.isString(eventName, "eventName");
|
|
314
|
+
|
|
310
315
|
return new Promise((resolve, reject) => {
|
|
311
316
|
|
|
312
317
|
const handle_event = () => {
|
|
@@ -331,6 +336,9 @@ export class Entity {
|
|
|
331
336
|
* @returns {Entity}
|
|
332
337
|
*/
|
|
333
338
|
addEventListener(eventName, listener, context) {
|
|
339
|
+
assert.isString(eventName, "eventName");
|
|
340
|
+
assert.isFunction(listener, "listener");
|
|
341
|
+
|
|
334
342
|
if (this.getFlag(EntityFlags.Built)) {
|
|
335
343
|
this.dataset.addEntityEventListener(this.reference.id, eventName, listener, context);
|
|
336
344
|
} else {
|
|
@@ -351,6 +359,9 @@ export class Entity {
|
|
|
351
359
|
* @returns {Entity}
|
|
352
360
|
*/
|
|
353
361
|
removeEventListener(eventName, listener, context) {
|
|
362
|
+
assert.isString(eventName, "eventName");
|
|
363
|
+
assert.isFunction(listener, "listener");
|
|
364
|
+
|
|
354
365
|
if (this.getFlag(EntityFlags.Built)) {
|
|
355
366
|
this.dataset.removeEntityEventListener(this.reference.id, eventName, listener, context);
|
|
356
367
|
} else {
|
|
@@ -502,9 +513,7 @@ export class Entity {
|
|
|
502
513
|
|
|
503
514
|
const r = new Entity();
|
|
504
515
|
|
|
505
|
-
dataset.
|
|
506
|
-
.filter(isDefined)
|
|
507
|
-
.forEach(r.add, r);
|
|
516
|
+
dataset.readEntityComponents(r.components, 0, entity);
|
|
508
517
|
|
|
509
518
|
r.setFlag(EntityFlags.Built);
|
|
510
519
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AAyHA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wDAfyB,MAAM;IAiB3B;;;;OAIG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC;;;;;;;;;OASG;IACH,2BAAkC;IAElC;;;;;OAKG;IACH,yBAAsB;IAEtB;;;;OAIG;IACH,4BAAgC;IAEhC;;;;OAIG;IACH,2BAAuB;IAEvB;;;;OAIG;IACH,mBAAgB;IAEhB;;;;OAIG;IACH,oBAAgB;IAEhB;;;;;;;OAOG;IACH,mBAAe;IAEf;;;OAGG;IACH,0BAFU,OAAO,MAAM,CAAC,CAEO;IAE/B;;;OAGG;IACH,0BAFU,OAAO,MAAM,CAAC,CAEO;IAG/B;;;;OAIG;IACH,+BAA4B;IAE5B;;;;OAIG;IACH,kCAA+B;IAE/B;;;OAGG;IACH,kBAAe;IAGf;;;;;;OAMG;IACH,mEAkCC;IAED;;;;;OAKG;IACH,kDAHW,OAAO,GACL,OAAO,CAqDnB;IAED;;;;;OAKG;IACH,qDAHW,OAAO,GACL,OAAO,CA6DnB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,yBAFa,MAAM,CAIlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,qBACN,EAAE,SAmCZ;IAED
|
|
1
|
+
{"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AAyHA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wDAfyB,MAAM;IAiB3B;;;;OAIG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC;;;;;;;;;OASG;IACH,2BAAkC;IAElC;;;;;OAKG;IACH,yBAAsB;IAEtB;;;;OAIG;IACH,4BAAgC;IAEhC;;;;OAIG;IACH,2BAAuB;IAEvB;;;;OAIG;IACH,mBAAgB;IAEhB;;;;OAIG;IACH,oBAAgB;IAEhB;;;;;;;OAOG;IACH,mBAAe;IAEf;;;OAGG;IACH,0BAFU,OAAO,MAAM,CAAC,CAEO;IAE/B;;;OAGG;IACH,0BAFU,OAAO,MAAM,CAAC,CAEO;IAG/B;;;;OAIG;IACH,+BAA4B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AM,cACN,MAAM,sCAGJ,OAAO,CA2CnB;IAED;;;;;;;OAOG;IACH,kBANW,MAAM,QACN,MAAM,gBAEJ,IAAI,CAmBhB;IAED;;;;OAIG;IACH,+BAHW,MAAM,GACJ,OAAO,CAenB;IAED;;;;OAIG;IACH,SAHa,IAAI,CAShB;IAED;;;;;OAKG;IACH,YAHa,IAAI,CAehB;IAED;;;;OAIG;IACH,yCAHW,MAAM,GACJ,IAAI,wBAAkB,CAiBlC;IAED;;;;;OAKG;IACH,mBAHW,sBAAsB,6BACpB,IAAI,CA6DhB;IAED;;;;;OAKG;IACH,2EAFa,IAAI,CAgDhB;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,oDAFa,IAAI,CAgBhB;IAGL;;;;;OAKG;IACH,mCAFU,OAAO,CAEwC;IAIzD;;OAEG;IACH,4BAhnBgB,UAAU,MAAM,CAAC,CAgnBoB;IAErD;;OAEG;IACH,iCAlZe,MAAM,wCAGJ,OAAO,CA+Y+B;IAvnBnD;;;OAGG;IACH,qBAFY,UAAU,MAAM,CAAC,CAY5B;CAqlBJ;mBA/gEkB,oCAAoC"}
|
|
@@ -476,11 +476,56 @@ export class EntityComponentDataset {
|
|
|
476
476
|
return result;
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
+
/**
|
|
480
|
+
*
|
|
481
|
+
* @param {[]} output
|
|
482
|
+
* @param {number} output_offset
|
|
483
|
+
* @param {number} entity_id
|
|
484
|
+
* @returns {number} how many components were written to the output
|
|
485
|
+
* @see getAllComponents
|
|
486
|
+
*/
|
|
487
|
+
readEntityComponents(
|
|
488
|
+
output,
|
|
489
|
+
output_offset,
|
|
490
|
+
entity_id
|
|
491
|
+
) {
|
|
492
|
+
|
|
493
|
+
assert.isNonNegativeInteger(entity_id, 'entity_id');
|
|
494
|
+
assert.ok(this.entityExists(entity_id), `Entity ${entity_id} doesn't exist`);
|
|
495
|
+
assert.isArray(output, "output");
|
|
496
|
+
assert.isNonNegativeInteger(output_offset, 'output_offset');
|
|
497
|
+
|
|
498
|
+
const componentTypeCount = this.componentTypeCount;
|
|
499
|
+
const occupancy_start = componentTypeCount * entity_id;
|
|
500
|
+
const occupancy_end = occupancy_start + componentTypeCount;
|
|
501
|
+
|
|
502
|
+
const occupancy = this.componentOccupancy;
|
|
503
|
+
|
|
504
|
+
let offset = output_offset;
|
|
505
|
+
|
|
506
|
+
for (
|
|
507
|
+
let i = occupancy.nextSetBit(occupancy_start);
|
|
508
|
+
i < occupancy_end && i !== -1;
|
|
509
|
+
i = occupancy.nextSetBit(i + 1)
|
|
510
|
+
) {
|
|
511
|
+
const componentIndex = i % componentTypeCount;
|
|
512
|
+
|
|
513
|
+
const component = this.components[componentIndex][entity_id];
|
|
514
|
+
|
|
515
|
+
output[offset++] = component;
|
|
516
|
+
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return offset - output_offset;
|
|
520
|
+
}
|
|
521
|
+
|
|
479
522
|
/**
|
|
480
523
|
* Get all components associated with a given entity.
|
|
481
524
|
* Note that this method allocates. If performance is important - prefer alternatives.
|
|
525
|
+
* Prefer to use {@link readEntityComponents} for performance reasons.
|
|
482
526
|
* @param {number} entity_id
|
|
483
527
|
* @returns {[]} all components attached to the entity, array is not compacted
|
|
528
|
+
* @see readEntityComponents
|
|
484
529
|
*/
|
|
485
530
|
getAllComponents(entity_id) {
|
|
486
531
|
assert.isNonNegativeInteger(entity_id, 'entity_id');
|
|
@@ -1775,8 +1820,8 @@ export class EntityComponentDataset {
|
|
|
1775
1820
|
|
|
1776
1821
|
/**
|
|
1777
1822
|
* Notifies every component of specified entity with given event
|
|
1778
|
-
* @param {
|
|
1779
|
-
* @param {
|
|
1823
|
+
* @param {number} entity
|
|
1824
|
+
* @param {string} name event name
|
|
1780
1825
|
* @param {Object} [event=undefined]
|
|
1781
1826
|
* @returns {void}
|
|
1782
1827
|
* @see addEntityEventListener
|
|
@@ -1785,6 +1830,7 @@ export class EntityComponentDataset {
|
|
|
1785
1830
|
// console.log("sendEvent", entity, name, event);
|
|
1786
1831
|
|
|
1787
1832
|
assert.isString(name, "name");
|
|
1833
|
+
assert.isNonNegativeInteger(entity, "entity");
|
|
1788
1834
|
|
|
1789
1835
|
dispatchEntityEventListeners(this.__entityEventListeners, entity, name, event);
|
|
1790
1836
|
|
|
@@ -9,7 +9,29 @@ export namespace EntityManagerState {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Brings together {@link System}s and an {@link EntityComponentDataset}
|
|
12
|
-
* Main entry point into the simulation process
|
|
12
|
+
* Main entry point into the simulation process.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const em = new EntityManager()
|
|
16
|
+
*
|
|
17
|
+
* em.addSystem(new MySystem())
|
|
18
|
+
* em.addSystem(new MyOtherSystem())
|
|
19
|
+
*
|
|
20
|
+
* em.attachDataset(new EntityComponentDataset())
|
|
21
|
+
*
|
|
22
|
+
* em.startup();
|
|
23
|
+
*
|
|
24
|
+
* // ..
|
|
25
|
+
*
|
|
26
|
+
* em.simulate(0.016); // advance simulation forward by 16ms
|
|
27
|
+
*
|
|
28
|
+
* // ..
|
|
29
|
+
*
|
|
30
|
+
* em.shutdown();
|
|
31
|
+
*
|
|
32
|
+
* // ..
|
|
33
|
+
*
|
|
34
|
+
* em.detachDataset();
|
|
13
35
|
*
|
|
14
36
|
* @author Alex Goldring
|
|
15
37
|
* @copyright Company Named Limited (c) 2025
|
|
@@ -179,11 +201,11 @@ export class EntityManager {
|
|
|
179
201
|
*/
|
|
180
202
|
promiseSystem(systemClass: Class): Promise<System<any, any, any, any, any>>;
|
|
181
203
|
/**
|
|
182
|
-
* @param {Class}
|
|
204
|
+
* @param {Class} SystemClass
|
|
183
205
|
* @param {SystemState} state
|
|
184
206
|
* @returns {Promise.<System>}
|
|
185
207
|
*/
|
|
186
|
-
promiseSystemInState(
|
|
208
|
+
promiseSystemInState(SystemClass: Class, state: SystemState): Promise<System<any, any, any, any, any>>;
|
|
187
209
|
/**
|
|
188
210
|
* This method is asynchronous by nature, it will not be done until each system has finished its shutdown
|
|
189
211
|
* Make sure to use callback to be notified when the shutdown has completed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAgBU,MAAM;;;;;;;;;AAiBhB
|
|
1
|
+
{"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAgBU,MAAM;;;;;;;;;AAiBhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;IAEI;;;;OAIG;IACH,kBAFU,iCAAQ,CAEL;IAEb;;;;;;OAMG;IACH,uCAA2B;IAE3B;;;;;OAKG;IACH,iCAA4B;IAE5B;;OAEG;IACH;;;QAGI;;WAEG;qBADO,uCAAc;;MAI1B;IAEF;;;OAGG;IACH,OAFU,kBAAkB,CAEO;IAEnC;;;;;;OAMG;IACH,gDAA2C;IAE3C;;;;;;;;;OASG;IACH,qBAFU,MAAM,CAEqB;IAErC;;;;;OAKG;IACH,wCAFU,MAAM,CAE4B;IAE5C;;;;OAIG;IACH,SAFU,sBAAsB,CAEjB;IAEf;;;;;OAKG;IACH,uCAAsC;IAEtC;;;OAGG;IACH,6BAmFC;IAED;;;OAGG;IACH,uBAFa,OAAO,CAuBnB;IAED;;;;;OAKG;IACH,uBAJW,sBAAsB,QA4ChC;IAGD;;;OAGG;IACH,sBA2BC;IAED;;;;OAIG;IACH,qCAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,6CAgBC;IAED;;;;;OAKG;IACH,wCAHW,MAAM,GACJ,IAAI,aAAS,CAiBzB;IAGD;;;OAGG;IACH,oBAFW,MAAM,QAoEhB;IAED;;;;;OAKG;IACH,iEA6DC;IAED;;;;OAIG;IACH,uDAFa,QAAQ,OAAO,CAAC,CA2C5B;IAED;;;;;OAKG;IACH,mBAmCC;IAED;;;;;OAKG;IACH,oBAqFC;IAED;;;;;OAKG;IACH,kEAyEC;IAED;;;;OAIG;IACH,mCAFa,wCAAgB,CA0B5B;IAED;;;;OAIG;IACH,8DAFa,wCAAgB,CA0B5B;IAED;;;;;OAKG;IACH,mEAoFC;IAGL;;OAEG;IACH,yBA5rBe,sBAAsB,UA4rBA;IACrC;;OAEG;IACH,0BAAqC;CATpC;uBA17BmC,aAAa;mBAR9B,oCAAoC;uCAMhB,6BAA6B"}
|
|
@@ -10,7 +10,7 @@ import { EntityComponentDataset } from "./EntityComponentDataset.js";
|
|
|
10
10
|
import { EntityObserver } from "./EntityObserver.js";
|
|
11
11
|
import { System, SystemState } from "./System.js";
|
|
12
12
|
import { computeSystemComponentDependencyGraph } from "./system/computeSystemComponentDependencyGraph.js";
|
|
13
|
-
import {
|
|
13
|
+
import { system_validate_class } from "./system_validate_class.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @readonly
|
|
@@ -33,7 +33,29 @@ const DEFAULT_SYSTEM_STARTUP_TIMEOUT_CHECK = 5;
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Brings together {@link System}s and an {@link EntityComponentDataset}
|
|
36
|
-
* Main entry point into the simulation process
|
|
36
|
+
* Main entry point into the simulation process.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const em = new EntityManager()
|
|
40
|
+
*
|
|
41
|
+
* em.addSystem(new MySystem())
|
|
42
|
+
* em.addSystem(new MyOtherSystem())
|
|
43
|
+
*
|
|
44
|
+
* em.attachDataset(new EntityComponentDataset())
|
|
45
|
+
*
|
|
46
|
+
* em.startup();
|
|
47
|
+
*
|
|
48
|
+
* // ..
|
|
49
|
+
*
|
|
50
|
+
* em.simulate(0.016); // advance simulation forward by 16ms
|
|
51
|
+
*
|
|
52
|
+
* // ..
|
|
53
|
+
*
|
|
54
|
+
* em.shutdown();
|
|
55
|
+
*
|
|
56
|
+
* // ..
|
|
57
|
+
*
|
|
58
|
+
* em.detachDataset();
|
|
37
59
|
*
|
|
38
60
|
* @author Alex Goldring
|
|
39
61
|
* @copyright Company Named Limited (c) 2025
|
|
@@ -476,7 +498,7 @@ export class EntityManager {
|
|
|
476
498
|
|
|
477
499
|
|
|
478
500
|
try {
|
|
479
|
-
|
|
501
|
+
system_validate_class(system);
|
|
480
502
|
} catch (e) {
|
|
481
503
|
console.error(`Validation of '${computeSystemName(system)}' failed : `, e, system);
|
|
482
504
|
}
|
|
@@ -674,7 +696,7 @@ export class EntityManager {
|
|
|
674
696
|
};
|
|
675
697
|
|
|
676
698
|
// Link EntityManager
|
|
677
|
-
if (system.entityManager === null) {
|
|
699
|
+
if (system.entityManager === null || system.entityManager === undefined) {
|
|
678
700
|
system.entityManager = this;
|
|
679
701
|
} else if (system.entityManager !== this) {
|
|
680
702
|
throw new Error(`System is bound to another EntityManager`);
|
|
@@ -819,16 +841,20 @@ export class EntityManager {
|
|
|
819
841
|
}
|
|
820
842
|
|
|
821
843
|
/**
|
|
822
|
-
* @param {Class}
|
|
844
|
+
* @param {Class} SystemClass
|
|
823
845
|
* @param {SystemState} state
|
|
824
846
|
* @returns {Promise.<System>}
|
|
825
847
|
*/
|
|
826
|
-
promiseSystemInState(
|
|
848
|
+
promiseSystemInState(SystemClass, state) {
|
|
849
|
+
|
|
850
|
+
assert.defined(SystemClass, 'SystemClass');
|
|
851
|
+
assert.enum(state, SystemState, 'state');
|
|
852
|
+
|
|
827
853
|
const em = this;
|
|
828
854
|
|
|
829
855
|
return new Promise(function (resolve, reject) {
|
|
830
856
|
|
|
831
|
-
const pSystem = em.promiseSystem(
|
|
857
|
+
const pSystem = em.promiseSystem(SystemClass);
|
|
832
858
|
|
|
833
859
|
pSystem.then(function (system) {
|
|
834
860
|
function tryProcessSystem() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityReference.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityReference.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH;
|
|
1
|
+
{"version":3,"file":"EntityReference.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityReference.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IAwHI;;;;;OAKG;IACH,gBAJW,MAAM,cACN,MAAM,GACL,eAAe,CAQ1B;IAED;;;;;OAKG;IACH,6CAHW,MAAM,GACJ,eAAe,CAQ3B;IAhJD;;;;OAIG;IACH,IAFU,MAAM,CAET;IAEP;;;;;OAKG;IACH,YAFU,MAAM,CAED;IAEf;;;OAGG;IACH,YAFW,eAAe,QAOzB;IAED;;;OAGG;IACH,SAFa,eAAe,CAQ3B;IAED;;;OAGG;IACH,QAFY,MAAM,CAIjB;IAED;;;;OAIG;IACH,cAHW,eAAe,GACd,OAAO,CAMlB;IAED;;;;OAIG;IACH,qCAFa,OAAO,CAYnB;IAED;;;;;OAKG;IACH,sCAFa,OAAO,CASnB;IAED;;;;OAIG;IACH,0CAFW,MAAM,QAShB;IAED;;;;OAIG;IACH,SAHW,MAAM,cACN,MAAM,QAUhB;IA+BL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAN1C;;cAWS,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"System.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/System.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH;IAEI;;;;;OAKG;IACH,uCAAqB;IAErB;;;;OAIG;IACH,oBAA+C;IAE/C;;;;;;;OAOG;IACH,6BAAkB;IAElB;;;;;;;;;;OAUG;IACH,0BAFU,6BAA6B,CAElB;IAGrB;;OAEG;IACH,mCAcC;IAED;;;;;OAKG;IACH,oCAFY,MAAM,CA8BjB;IAED;;;;;;OAMG;IACH,uCAHa,QAAQ,IAAI,CAAC,CAKzB;IAED;;;;;;;OAOG;IACH,wCAHa,QAAQ,IAAI,CAAC,CAKzB;IAGD;;;;OAIG;IACH,wCAEC;IAED;;;;OAIG;IACH,0CAEC;IAED;;;;;;;;;;OAUG;IACH,6DAEC;IAED;;;;;;;;;;OAUG;IACH,6DAEC;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;IAEzB;;;;OAIG;IACH,yBAA4B;IAG5B;;;;;;OAMG;IACH,oBAAuB;CAvBtB
|
|
1
|
+
{"version":3,"file":"System.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/System.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH;IAEI;;;;;OAKG;IACH,uCAAqB;IAErB;;;;OAIG;IACH,oBAA+C;IAE/C;;;;;;;OAOG;IACH,6BAAkB;IAElB;;;;;;;;;;OAUG;IACH,0BAFU,6BAA6B,CAElB;IAGrB;;OAEG;IACH,mCAcC;IAED;;;;;OAKG;IACH,oCAFY,MAAM,CA8BjB;IAED;;;;;;OAMG;IACH,uCAHa,QAAQ,IAAI,CAAC,CAKzB;IAED;;;;;;;OAOG;IACH,wCAHa,QAAQ,IAAI,CAAC,CAKzB;IAGD;;;;OAIG;IACH,wCAEC;IAED;;;;OAIG;IACH,0CAEC;IAED;;;;;;;;;;OAUG;IACH,6DAEC;IAED;;;;;;;;;;OAUG;IACH,6DAEC;IAIL;;;OAGG;IACH,mBAFU,OAAO,CAEQ;IAEzB;;;;OAIG;IACH,yBAA4B;IAG5B;;;;;;OAMG;IACH,oBAAuB;CAvBtB;0BA2BS,MAAM;;;;;;;;qBArOK,6BAA6B"}
|
package/src/engine/ecs/System.js
CHANGED
|
@@ -174,7 +174,7 @@ export class System {
|
|
|
174
174
|
|
|
175
175
|
/**
|
|
176
176
|
* Invoked when a dataset is attached to the system, this happens before any entities are linked.
|
|
177
|
-
* Happens as a result of {@link EntityManager.
|
|
177
|
+
* Happens as a result of {@link EntityManager.attachDataset}.
|
|
178
178
|
* It is generally advised *NOT* to modify the dataset here.
|
|
179
179
|
* Managed by {@link EntityManager}'s lifecycle. Do not call this manually.
|
|
180
180
|
*
|
|
@@ -189,7 +189,7 @@ export class System {
|
|
|
189
189
|
|
|
190
190
|
/**
|
|
191
191
|
* Invoked when dataset is about to be detached from the system, this happens after all entities have been unlinked.
|
|
192
|
-
* Happens as a result of {@link EntityManager.
|
|
192
|
+
* Happens as a result of {@link EntityManager.detachDataset}.
|
|
193
193
|
* It is generally advised *NOT* to modify the dataset here.
|
|
194
194
|
* Managed by {@link EntityManager}'s lifecycle. Do not call this manually.
|
|
195
195
|
*
|
|
@@ -223,29 +223,10 @@ System.prototype.fixedUpdate = noop; // by assigning NO-OP we enable a simple ch
|
|
|
223
223
|
* Note that this time step can vary depending on system conditions and hardware we are running on.
|
|
224
224
|
* It is generally safe to assume that this update will happen once per frame, but it is not guaranteed.
|
|
225
225
|
* Also, note that when the application window/tab is suspended, the next update step can have a very large value.
|
|
226
|
-
* @param {number} timeDelta
|
|
226
|
+
* @param {number} timeDelta in seconds
|
|
227
227
|
*/
|
|
228
228
|
System.prototype.update = noop; // by assigning NO-OP we enable a simple check, whether running the update would be useful
|
|
229
229
|
|
|
230
|
-
Object.defineProperties(System.prototype, {
|
|
231
|
-
/**
|
|
232
|
-
* @deprecated
|
|
233
|
-
*/
|
|
234
|
-
componentClass: {
|
|
235
|
-
configurable: true,
|
|
236
|
-
/**
|
|
237
|
-
* @deprecated
|
|
238
|
-
* @returns {Class<C>}
|
|
239
|
-
*/
|
|
240
|
-
get() {
|
|
241
|
-
console.warn(`componentClass property is deprecated and should not be used`);
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
});
|
|
248
|
-
|
|
249
230
|
/**
|
|
250
231
|
* @readonly
|
|
251
232
|
* @enum {number}
|
|
@@ -273,9 +254,3 @@ export const SystemState = {
|
|
|
273
254
|
STOPPED: 4
|
|
274
255
|
}
|
|
275
256
|
|
|
276
|
-
/**
|
|
277
|
-
* @readonly
|
|
278
|
-
* @deprecated use {@link SystemState} directly instead
|
|
279
|
-
*/
|
|
280
|
-
System.State = SystemState;
|
|
281
|
-
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* @param {System} system
|
|
4
4
|
* @throws {Error} if the system fails validation
|
|
5
5
|
*/
|
|
6
|
-
export function
|
|
6
|
+
export function system_validate_class(system: System<any, any, any, any, any>): void;
|
|
7
7
|
import { System } from "./System.js";
|
|
8
|
-
//# sourceMappingURL=
|
|
8
|
+
//# sourceMappingURL=system_validate_class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system_validate_class.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/system_validate_class.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qFA0FC;uBAjGsB,aAAa"}
|
|
@@ -5,7 +5,7 @@ import { System } from "./System.js";
|
|
|
5
5
|
* @param {System} system
|
|
6
6
|
* @throws {Error} if the system fails validation
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
8
|
+
export function system_validate_class(system) {
|
|
9
9
|
if (system === undefined) {
|
|
10
10
|
throw new Error("System is undefined");
|
|
11
11
|
}
|
|
@@ -154,7 +154,7 @@ class SceneManager {
|
|
|
154
154
|
|
|
155
155
|
if (this.#current_scene !== null) {
|
|
156
156
|
this.#current_scene.active.set(false);
|
|
157
|
-
this.#entity_manager.
|
|
157
|
+
this.#entity_manager.detachDataset();
|
|
158
158
|
|
|
159
159
|
this.#current_scene = null;
|
|
160
160
|
}
|
|
@@ -191,7 +191,7 @@ class SceneManager {
|
|
|
191
191
|
scene.active.set(false);
|
|
192
192
|
|
|
193
193
|
if (this.#entity_manager.dataset === scene.dataset) {
|
|
194
|
-
this.#entity_manager.
|
|
194
|
+
this.#entity_manager.detachDataset();
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
//remove speed modifiers
|
|
@@ -222,7 +222,7 @@ class SceneManager {
|
|
|
222
222
|
|
|
223
223
|
const em = this.#entity_manager;
|
|
224
224
|
|
|
225
|
-
em.
|
|
225
|
+
em.attachDataset(scene.dataset);
|
|
226
226
|
|
|
227
227
|
scene.active.set(true);
|
|
228
228
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateSystem.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/validateSystem.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,8EA0FC;uBAjGsB,aAAa"}
|