refactor: efficient entity toNetwork
This commit is contained in:
parent
d90a345afe
commit
204907c27f
|
@ -386,6 +386,10 @@ export class Entity extends decorate(Resource) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toNetwork() {
|
||||||
|
return this.mergeDiff();
|
||||||
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
const json = {};
|
const json = {};
|
||||||
for (const type in this._traits) {
|
for (const type in this._traits) {
|
||||||
|
|
|
@ -35,18 +35,17 @@ export class EntityList extends decorate(class {}) {
|
||||||
if (packet instanceof EntityListUpdateEntityPacket) {
|
if (packet instanceof EntityListUpdateEntityPacket) {
|
||||||
for (let i = 0; i < packet.data.length; i++) {
|
for (let i = 0; i < packet.data.length; i++) {
|
||||||
const {uuid, packets} = packet.data[i];
|
const {uuid, packets} = packet.data[i];
|
||||||
// WHY ?
|
|
||||||
if (!this._entities[uuid]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (let j = 0; j < packets.length; j++) {
|
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) {
|
if (packet instanceof SynchronizedCreatePacket) {
|
||||||
const entity = new Entity(packet.data.spec);
|
Entity.loadOrInstance(packet.data.spec).then((entity) => {
|
||||||
this.addEntity(entity);
|
this.addEntity(entity);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (packet instanceof SynchronizedDestroyPacket) {
|
if (packet instanceof SynchronizedDestroyPacket) {
|
||||||
const uuid = packet.data.synchronized.id;
|
const uuid = packet.data.synchronized.id;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user