refactor: optimize ticking

This commit is contained in:
cha0s 2021-03-29 10:39:22 -05:00
parent 637163d201
commit 38a780759a
2 changed files with 11 additions and 2 deletions

View File

@ -41,7 +41,9 @@ export default (latus) => {
}
this.#entities[uuid] = entity;
this.#flatEntities.push(entity);
this.#entityTickers.push(entity.tick);
if (entity.hasTickers()) {
this.#entityTickers.push(entity.tick);
}
// eslint-disable-next-line no-param-reassign
entity.list = this;
entity.emit('addedToList');
@ -176,7 +178,10 @@ export default (latus) => {
entity.emit('removedFromList', this);
delete this.#entities[uuid];
this.#flatEntities.splice(this.#flatEntities.indexOf(entity), 1);
this.#entityTickers.splice(this.#entityTickers.indexOf(entity.tick), 1);
const index = this.#entityTickers.indexOf(entity.tick);
if (-1 !== index) {
this.#entityTickers.splice(index, 1);
}
this.emit('entityRemoved', entity);
}

View File

@ -211,6 +211,10 @@ export default (latus) => {
this.emit('destroyed');
}
hasTickers() {
return this.#traitTickers.length;
}
invokeHook(hook, ...args) {
const results = {};
if (!(hook in this.#hooks)) {