From e321124aa0dd43068088fd2ce8b986dfb11b7736 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Fri, 5 Jul 2013 23:36:56 -0400 Subject: [PATCH] Progress: #3 --- lib/server/garageservergame.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index 310e95d..4f0242f 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -13,25 +13,35 @@ function GarageServerGame(options) { } GarageServerGame.prototype.updateState = function (options) { - var currentTime = new Date().getTime() - this.startTime; - this.updatePlayers(currentTime, options); - this.updateEntities(currentTime, options); -}; + var currentTime = new Date().getTime() - this.startTime, + state = { time: currentTime, playerStates: [], entityStates: [] }; -GarageServerGame.prototype.updatePlayers = function (currentTime, options) { - var state = { time: currentTime, playerStates: [], entityStates: [] }; - - this.players.forEach(function (player) { - state.playerStates.push([ player.client.id, player.state, player.sequence ]); - }); + state.playerStates = this.updatePlayers(); + state.entityStates = this.updateEntities(); this.players.forEach(function (player) { player.client.emit('update', state); }); }; -GarageServerGame.prototype.updateEntities = function (currentTime, options) { - +GarageServerGame.prototype.updatePlayers = function () { + var states = []; + + this.players.forEach(function (player) { + states.push([ player.client.id, player.state, player.sequence ]); + }); + + return states; +}; + +GarageServerGame.prototype.updateEntities = function () { + var states = []; + + this.entities.forEach(function (entity) { + states.push([ entity.id, entity.state, entity.sequence ]); + }); + + return states; }; GarageServerGame.prototype.updatePhysics = function (options) {