This commit is contained in:
Jeremiah Billmann
2013-07-14 11:16:43 -04:00
parent 2e714b80ce
commit 710f33a753
4 changed files with 27 additions and 7 deletions
+12 -4
View File
@@ -16,14 +16,14 @@ GarageServerGame.prototype.start = function () {
var self = this;
this.startTime = new Date().getTime();
this.stateIntervalId = setInterval(function () { self.updateState(); }, this.stateInterval);
this.stateIntervalId = setInterval(function () { self.broadcastState(); }, this.stateInterval);
};
GarageServerGame.prototype.stop = function () {
clearInterval(this.stateIntervalId);
};
GarageServerGame.prototype.updateState = function () {
GarageServerGame.prototype.broadcastState = function () {
var currentTime = new Date().getTime() - this.startTime,
state = { time: currentTime, playerStates: [], entityStates: [] };
@@ -64,9 +64,17 @@ GarageServerGame.prototype.getPlayer = function (id) {
};
GarageServerGame.prototype.updatePlayerState = function (id, state) {
var currentTime = new Date().getTime() - this.startTime;
this.updateState(this.playerController, id, state);
};
this.playerController.entities.some(function (player) {
GarageServerGame.prototype.updateEntityState = function (id, state) {
this.updateState(this.entityController, id, state);
};
GarageServerGame.prototype.updateState = function (controller, id, state) {
var currentTime = new Date().getTime() - this.startTime;
controller.entities.some(function (player) {
if (player.id === id) {
player.addState(state, currentTime);
player.sequence += player.inputs.length;