Reduced output traffic based on inputs

This commit is contained in:
Jeremiah Billmann
2013-06-12 21:25:54 -04:00
parent dc4aa76ca5
commit e987d73711
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
$(function () {
GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', { logging: false });
GarageServerIO.connectToGarageServer('http://garageserver_io.jbillmann.c9.io', { logging: true });
var gameCanvas = document.getElementById('gameCanvas'),
+4 -3
View File
@@ -11,9 +11,10 @@ function GarageServerGame(options) {
GarageServerGame.prototype.updatePlayers = function (options) {
var currentTime = new Date().getTime();
for (var i = 0; i < this.players.length; i ++) {
//TODO: Retink efficiency
this.players[i].client.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
this.players[i].client.broadcast.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
if(this.players[i].inputs.length > 0) {
this.players[i].client.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
this.players[i].client.broadcast.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
}
}
};