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,
);
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.

View File

@ -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) {

View File

@ -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',
},
};
}