flow(ecs): entities and tick/finalization
This commit is contained in:
parent
689ce1e52b
commit
e31beefec8
|
@ -77,7 +77,7 @@ export default class Ecs {
|
|||
|
||||
}
|
||||
const wrappedSystem = new WrappedSystem(this.Components);
|
||||
wrappedSystem.reindex(Object.keys(this.$$entities));
|
||||
wrappedSystem.reindex(this.entities);
|
||||
this.$$systems.push(wrappedSystem);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ export default class Ecs {
|
|||
}
|
||||
|
||||
createExact(entity, components) {
|
||||
this.createManyExact([entity, components]);
|
||||
this.createManyExact([[entity, components]]);
|
||||
}
|
||||
|
||||
createMany(componentsList) {
|
||||
|
@ -139,7 +139,7 @@ export default class Ecs {
|
|||
let components = {};
|
||||
let entity;
|
||||
if (Array.isArray(entities[i])) {
|
||||
[entity, components] = entities[i];
|
||||
[entity, components = {}] = entities[i];
|
||||
}
|
||||
else {
|
||||
entity = entities[i];
|
||||
|
@ -213,7 +213,7 @@ export default class Ecs {
|
|||
}
|
||||
|
||||
destroyAll() {
|
||||
this.destroyMany(Object.keys(this.$$entities).map((entity) => BigInt(entity)));
|
||||
this.destroyMany(this.entities);
|
||||
}
|
||||
|
||||
destroyMany(entities) {
|
||||
|
@ -291,6 +291,14 @@ export default class Ecs {
|
|||
view.setUint32(0, entitiesWritten, true);
|
||||
}
|
||||
|
||||
get entities() {
|
||||
const entities = [];
|
||||
for (const i in this.$$entities) {
|
||||
entities.push(BigInt(i));
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
get(entity) {
|
||||
if (!this.$$entities[entity]) {
|
||||
return undefined;
|
||||
|
@ -420,7 +428,10 @@ export default class Ecs {
|
|||
}
|
||||
}
|
||||
|
||||
tickFinalize() {
|
||||
tickFinalize(elapsed) {
|
||||
for (let i = 0; i < this.$$systems.length; i++) {
|
||||
this.$$systems[i].finalize(elapsed);
|
||||
}
|
||||
this.tickDestruction();
|
||||
this.setClean();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ export default class System {
|
|||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
finalize() {}
|
||||
|
||||
static normalize(SystemLike) {
|
||||
if (SystemLike.prototype instanceof System) {
|
||||
return SystemLike;
|
||||
|
@ -62,4 +65,7 @@ export default class System {
|
|||
this.destroying = [];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
tick() {}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable react/prefer-stateless-function */
|
||||
import {expect} from 'chai';
|
||||
|
||||
import Bundle from '../src/bundle';
|
||||
|
|
Loading…
Reference in New Issue
Block a user