perf: faster entity.room

This commit is contained in:
cha0s 2019-05-17 05:47:40 -05:00
parent ba34ef6e01
commit 8d67f220c9
3 changed files with 12 additions and 14 deletions

View File

@ -133,6 +133,7 @@ export class Entity extends decorate(Resource) {
// Fast props.
this.numericUid = numericUid++;
this.position = [0, 0];
this.room = null;
this.visibleAabb = [0, 0, 0, 0];
// Fast path for instance.
if ('undefined' !== typeof json) {

View File

@ -112,7 +112,7 @@ export class Room extends decorate(class {}) {
}
onEntityAddedToRoom(entity) {
entity.room = this;
entity.setRoom(this);
if (AVOCADO_CLIENT) {
const queuedPackets = this.queuedEntityPackets[entity.instanceUuid];
for (let i = 0; i < queuedPackets.length; i++) {

View File

@ -6,24 +6,21 @@ export class Roomed extends Trait {
return 'roomed';
}
constructor(entity, params, state) {
super(entity, params, state);
this._room = undefined;
}
destroy() {
const room = this._room;
delete this._room;
const room = this.entity.room;
this.entity.room = null;
this.entity.emit('removedFromRoom', room);
}
get room() {
return this._room;
}
methods() {
return {
set room(room) {
this._room = room;
this.entity.emit('addedToRoom');
setRoom: (room) => {
this.entity.room = room;
this.entity.emit('addedToRoom');
},
};
}
}