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.
|
// 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) {
|
||||||
|
|
|
@ -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++) {
|
||||||
|
|
|
@ -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');
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user