mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-06-28 16:20:43 +08:00
Progress: Server Loops
This commit is contained in:
@@ -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: []
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user