refactor: efficient entity toNetwork

This commit is contained in:
cha0s 2019-09-30 20:52:52 -05:00
parent d90a345afe
commit 204907c27f
2 changed files with 10 additions and 7 deletions

View File

@ -386,6 +386,10 @@ export class Entity extends decorate(Resource) {
}
}
toNetwork() {
return this.mergeDiff();
}
toJSON() {
const json = {};
for (const type in this._traits) {

View File

@ -35,18 +35,17 @@ export class EntityList extends decorate(class {}) {
if (packet instanceof EntityListUpdateEntityPacket) {
for (let i = 0; i < packet.data.length; i++) {
const {uuid, packets} = packet.data[i];
// WHY ?
if (!this._entities[uuid]) {
continue;
}
for (let j = 0; j < packets.length; j++) {
this._entities[uuid].acceptPacket(packets[j]);
if (this._entities[uuid]) {
this._entities[uuid].acceptPacket(packets[j]);
}
}
}
}
if (packet instanceof SynchronizedCreatePacket) {
const entity = new Entity(packet.data.spec);
this.addEntity(entity);
Entity.loadOrInstance(packet.data.spec).then((entity) => {
this.addEntity(entity);
});
}
if (packet instanceof SynchronizedDestroyPacket) {
const uuid = packet.data.synchronized.id;