From 2fc0b35eee6fd2a1d6066216207e406b116c58d8 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 16 May 2019 17:44:45 -0500 Subject: [PATCH] perf: only send a numeric ID over the wire --- packages/entity/index.js | 3 +++ packages/entity/packets/entity-create.packet.js | 4 +--- packages/entity/packets/entity.packet.js | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/entity/index.js b/packages/entity/index.js index 7babcba..dcafc33 100644 --- a/packages/entity/index.js +++ b/packages/entity/index.js @@ -81,6 +81,8 @@ const decorate = compose( Synchronized, ); +let numericUid = 1; + export class Entity extends decorate(Resource) { constructor(json) { @@ -97,6 +99,7 @@ export class Entity extends decorate(Resource) { // Bind to prevent lookup overhead. this.tick = this.tick.bind(this); // Fast props. + this.numericUid = numericUid++; this.position = [0, 0]; this.visibleAabb = [0, 0, 0, 0]; // Fast path for instance. diff --git a/packages/entity/packets/entity-create.packet.js b/packages/entity/packets/entity-create.packet.js index c69b1e1..1344eaf 100644 --- a/packages/entity/packets/entity-create.packet.js +++ b/packages/entity/packets/entity-create.packet.js @@ -6,11 +6,9 @@ export class EntityCreatePacket extends EntityPacket { constructor(data, entity) { if ('undefined' !== typeof entity) { - data.uuid = entity.instanceUuid; data.layer = entity.layer.index; } - super(data); - this.entity = entity; + super(data, entity); } static pack(packet) { diff --git a/packages/entity/packets/entity.packet.js b/packages/entity/packets/entity.packet.js index de4d0c5..3fc930c 100644 --- a/packages/entity/packets/entity.packet.js +++ b/packages/entity/packets/entity.packet.js @@ -4,7 +4,7 @@ export class EntityPacket extends Packet { constructor(data, entity) { if ('undefined' !== typeof entity) { - data.uuid = entity.instanceUuid; + data.uuid = entity.numericUid; } super(data); this.entity = entity; @@ -14,7 +14,7 @@ export class EntityPacket extends Packet { return { ...super.schema, data: { - uuid: 'string', + uuid: 'uint32', }, }; }