Progress: Server Loops

This commit is contained in:
Jeremiah Billmann
2013-05-22 21:04:59 -04:00
parent a5b072955f
commit 0e043b2909
+17 -6
View File
@@ -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: []
};