perf: bind entity tickers AOT
This commit is contained in:
parent
537cc167f8
commit
e22394e875
|
@ -72,6 +72,8 @@ export class Entity extends decorate(Resource) {
|
|||
if ('undefined' !== typeof json) {
|
||||
this.fromJSON(json);
|
||||
}
|
||||
// Bind to prevent lookup overhead.
|
||||
this.tick = this.tick.bind(this);
|
||||
}
|
||||
|
||||
acceptPacket(packet) {
|
||||
|
|
|
@ -19,6 +19,7 @@ export class EntityList extends decorate(class {}) {
|
|||
this._afterDestructionTickers = [];
|
||||
this._dirtyEntities = [];
|
||||
this._entities = {};
|
||||
this._entityTickers = []
|
||||
this._flatEntities = [];
|
||||
this._quadTree = new QuadTree();
|
||||
this.initializeSynchronizedChildren();
|
||||
|
@ -35,6 +36,7 @@ export class EntityList extends decorate(class {}) {
|
|||
const uuid = entity.instanceUuid;
|
||||
this._entities[uuid] = entity;
|
||||
this._flatEntities.push(entity);
|
||||
this._entityTickers.push(entity.tick);
|
||||
this.state = this.state.set(uuid, entity.state);
|
||||
entity.addTrait('listed');
|
||||
entity.setIntoList(this);
|
||||
|
@ -102,9 +104,12 @@ export class EntityList extends decorate(class {}) {
|
|||
|
||||
removeEntity(entity) {
|
||||
const uuid = entity.instanceUuid;
|
||||
if (!(uuid in this._entities[uuid])) {
|
||||
return;
|
||||
}
|
||||
delete this._entities[uuid];
|
||||
const index = this._flatEntities.indexOf(entity);
|
||||
this._flatEntities.splice(index, 1);
|
||||
this._flatEntities.splice(index, this._flatEntities.indexOf(entity));
|
||||
this._entityTickers.splice(this._entityTickers.indexOf(entity.tick), 1);
|
||||
this.state = this.state.delete(uuid);
|
||||
this.emit('entityRemoved', entity);
|
||||
if (entity.is('listed')) {
|
||||
|
@ -141,9 +146,8 @@ export class EntityList extends decorate(class {}) {
|
|||
}
|
||||
|
||||
tickEntities(elapsed) {
|
||||
for (let i = 0; i < this._flatEntities.length; i++) {
|
||||
const entity = this._flatEntities[i];
|
||||
entity.tick(elapsed);
|
||||
for (let i = 0; i < this._entityTickers.length; i++) {
|
||||
this._entityTickers[i](elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user