Progress: Adding delta time and fixed timestep

This commit is contained in:
Jeremiah Billmann
2013-07-01 21:03:05 -04:00
parent 7e66be0ac0
commit 9b7b0a9531
4 changed files with 14 additions and 12 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ options = {
function GarageServer (socketio, options) {
this.io = socketio;
this.physicsInterval = options.physicsInterval ? options.physicsInterval : 15;
this.physicsDelta = (options.physicsInterval ? options.physicsInterval : 15) / 1000;
this.game = new garageServerGame.createGame(options);
this.registerSocketEvents(options);
}
@@ -28,7 +28,7 @@ GarageServer.prototype.registerSocketEvents = function (options) {
if (options.logging) {
console.log('garageserver.io:: socket ' + socket.id + ' connection');
}
socket.emit('state', { physicsDelta: self.physicsInterval });
socket.emit('state', { physicsDelta: self.physicsDelta });
self.onPlayerConnect(socket, options);
socket.on('disconnect', function () {
+3 -2
View File
@@ -7,7 +7,7 @@ function GarageServerGame(options) {
this.startTime = new Date().getTime();
this.physicsInterval = options.physicsInterval ? options.physicsInterval : 15;
this.stateInterval = options.stateInterval ? options.stateInterval : 45;
this.physicsDelta = this.physicsInterval / 1000;
this.physicsIntervalId = setInterval(function () { self.updatePhysics(options); }, this.physicsInterval);
this.stateIntervalId = setInterval(function () { self.updateState(options); }, this.stateInterval);
}
@@ -35,10 +35,11 @@ GarageServerGame.prototype.updateEntities = function (options) {
};
GarageServerGame.prototype.updatePhysics = function (options) {
var self = this;
this.players.forEach(function (player) {
if (player.inputs.length > 0) {
if (options.onUpdatePlayerPhysics) {
player.state = options.onUpdatePlayerPhysics(player.state, player.inputs);
player.state = options.onUpdatePlayerPhysics(player.state, player.inputs, self.physicsDelta);
}
player.sequence += player.inputs.length;
player.inputs = [];