perf: faster entity.room
This commit is contained in:
parent
ba34ef6e01
commit
8d67f220c9
|
@ -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) {
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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');
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user