From 0e043b2909d7b97caca4c769e9e32d29936d625f Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Wed, 22 May 2013 21:04:59 -0400 Subject: [PATCH] Progress: Server Loops --- lib/server/garageservergame.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index a372342..a0b393f 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -1,16 +1,26 @@ function GarageServerGame (options) { + var self = this; + this.players = []; - this.physicsIntervalId = setInterval(this.updatePhysics, options.physicsInterval ? options.physicsInterval : 15); - this.playersIntervalId = setInterval(this.updatePlayers, options.playersInterval ? options.playersInterval : 45); + this.physicsIntervalId = setInterval(function () { self.updatePhysics(options); }, options.physicsInterval ? options.physicsInterval : 15); + this.playersIntervalId = setInterval(function () { self.updatePlayers(options); }, options.playersInterval ? options.playersInterval : 45); } -GarageServerGame.prototype.updatePlayers = function () { - +GarageServerGame.prototype.updatePlayers = function (options) { + for(var i = 0; i < this.players.length; i ++) { + } }; -GarageServerGame.prototype.updatePhysics = function () { - +GarageServerGame.prototype.updatePhysics = function (options) { + for(var i = 0; i < this.players.length; i ++) { + if(this.players[i].inputs.length > 0) { + if(options.onUpdatePhysics) { + this.players[i].state = options.onUpdatePhysics(this.players[i].state, this.players[i].inputs); + } + this.players[i].inputs = []; + } + } }; GarageServerGame.prototype.addPlayer = function (client) { @@ -22,6 +32,7 @@ GarageServerGame.prototype.addPlayer = function (client) { var player = { client: client, + state: {}, inputs: [] };