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

@ -13,6 +13,14 @@ class Room {
this.teamB = new Set();
this.world = new World(this);
this.name = (Math.random() * 100000 | 0).toString(36);
this.tps = 60;
this.idGenerator = (function*() {
let i = 0;
while (true)
yield i++;
})();
this.gameServer = gameServer;
this.io = this.gameServer.net.io;
@ -46,6 +54,10 @@ class Room {
this.message('roomLeave', player.name, 'team' + player.team);
}
generateId() {
return this.idGenerator.next().value;
}
setTeam(player, team) {
this.teamA.delete(player);
this.teamB.delete(player);
@ -58,9 +70,9 @@ class Room {
player.connection.drop();
}
update(self) {
//if (this.world.tickCount % 100 == 0)
self.players.forEach(player => {
update() {
this.world.tick();
this.players.forEach(player => {
player.sendUpdate();
if (Date.now() - player.lastAction > 10000) {
//this.kick(player);
@ -75,7 +87,7 @@ class Room {
chat(player, message) {
wingbase.log(`${this.name}/${player.name}: ${message}`);
this.chatCooldown++;
this.io.to(this.name).emit('chat', {
type: 'player',
@ -104,6 +116,7 @@ class Room {
let data = {
playerShipId: player.ship.id,
bounds: this.world.bounds,
tps: this.tps,
bodies: Array.from(this.world.bodies).map(b => b.packFull())
};
@ -113,7 +126,8 @@ class Room {
start() {
this.world.populate();
this.world.start();
this.interval = setInterval(_ => this.update(this), 1 / 60);
let wait = 1 / this.tps * 1000;
this.interval = setInterval(this.update.bind(this), wait);
}
stop() {