perf: only send a numeric ID over the wire

This commit is contained in:
cha0s 2019-05-16 17:44:45 -05:00
parent 769338a946
commit 2fc0b35eee
3 changed files with 6 additions and 5 deletions

View File

@ -81,6 +81,8 @@ const decorate = compose(
Synchronized, Synchronized,
); );
let numericUid = 1;
export class Entity extends decorate(Resource) { export class Entity extends decorate(Resource) {
constructor(json) { constructor(json) {
@ -97,6 +99,7 @@ export class Entity extends decorate(Resource) {
// Bind to prevent lookup overhead. // Bind to prevent lookup overhead.
this.tick = this.tick.bind(this); this.tick = this.tick.bind(this);
// Fast props. // Fast props.
this.numericUid = numericUid++;
this.position = [0, 0]; this.position = [0, 0];
this.visibleAabb = [0, 0, 0, 0]; this.visibleAabb = [0, 0, 0, 0];
// Fast path for instance. // Fast path for instance.

View File

@ -6,11 +6,9 @@ export class EntityCreatePacket extends EntityPacket {
constructor(data, entity) { constructor(data, entity) {
if ('undefined' !== typeof entity) { if ('undefined' !== typeof entity) {
data.uuid = entity.instanceUuid;
data.layer = entity.layer.index; data.layer = entity.layer.index;
} }
super(data); super(data, entity);
this.entity = entity;
} }
static pack(packet) { static pack(packet) {

View File

@ -4,7 +4,7 @@ export class EntityPacket extends Packet {
constructor(data, entity) { constructor(data, entity) {
if ('undefined' !== typeof entity) { if ('undefined' !== typeof entity) {
data.uuid = entity.instanceUuid; data.uuid = entity.numericUid;
} }
super(data); super(data);
this.entity = entity; this.entity = entity;
@ -14,7 +14,7 @@ export class EntityPacket extends Packet {
return { return {
...super.schema, ...super.schema,
data: { data: {
uuid: 'string', uuid: 'uint32',
}, },
}; };
} }