reduce update packet size by ~70%

This commit is contained in:
Asraelite 2016-03-29 01:14:32 +01:00
parent 1af386d9f5
commit 0906441246
20 changed files with 219 additions and 143 deletions

View file

@ -11,7 +11,7 @@ class Player {
this.lastAction = Date.now();
this.connection = connection;
this.name = this.randomName();
this.delta = {};
this.delta = [];
this.chatCooldown = 0;
}
@ -20,6 +20,10 @@ class Player {
this.room.remove(this);
}
applyDelta(data) {
this.delta = this.delta.concat(data);
}
updateInputs(data) {
this.ship.updateInputs(data);
this.lastAction = Date.now();
@ -49,9 +53,9 @@ class Player {
}
sendUpdate() {
if (Object.keys(this.delta).length == 0) return;
if (this.delta.length == 0) return;
this.connection.send('update', this.delta);
this.delta = {};
this.delta = [];
}
tick() {