flow(ecs): entities and tick/finalization

This commit is contained in:
cha0s 2022-12-03 13:35:41 -06:00
parent 689ce1e52b
commit e31beefec8
3 changed files with 22 additions and 6 deletions

View File

@ -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();
}

View File

@ -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() {}
}

View File

@ -1,4 +1,3 @@
/* eslint-disable react/prefer-stateless-function */
import {expect} from 'chai';
import Bundle from '../src/bundle';