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. // Fast props.
this.numericUid = numericUid++; this.numericUid = numericUid++;
this.position = [0, 0]; this.position = [0, 0];
this.room = null;
this.visibleAabb = [0, 0, 0, 0]; this.visibleAabb = [0, 0, 0, 0];
// Fast path for instance. // Fast path for instance.
if ('undefined' !== typeof json) { if ('undefined' !== typeof json) {

View File

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

View File

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