From 415dceb52422a126a9f687c2aea4f3df20c09da4 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Mon, 1 Jul 2013 21:45:21 -0400 Subject: [PATCH] Progress: Delta time & fixed timestep --- client/garageserver.io.js | 7 ------- example/public/javascripts/game.js | 2 +- lib/server/garageserver.io.js | 3 +-- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/client/garageserver.io.js b/client/garageserver.io.js index cb6a34f..03e9988 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -23,8 +23,6 @@ window.GarageServerIO = (function (window, socketio) { this.state = {}; this.clientTime; this.renderTime; - this.deltaTime = 0; - this.tickerTime = new Date().getTime(), this.physicsDelta; this.playerId; this.pingDelay = 100; @@ -231,7 +229,6 @@ window.GarageServerIO = (function (window, socketio) { addPlayerInput = function (clientInput) { _inputController.addInput(clientInput); - if (_options.clientSidePrediction && _options.onUpdatePlayerPhysics) { _stateController.state = _options.onUpdatePlayerPhysics(_stateController.state, [{ input: clientInput }], _stateController.physicsDelta); } @@ -288,10 +285,6 @@ window.GarageServerIO = (function (window, socketio) { }, getPlayerStates = function (stateCallback) { - var newTickTime = new Date().getTime(); - _stateController.deltaTime = newTickTime - _stateController.tickerTime; - _stateController.tickerTime = newTickTime; - if(_options.interpolation && _options.onInterpolation) { getPlayerStatesInterpolated(stateCallback); } diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index c7e8328..38359e0 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -40,7 +40,7 @@ $(function () { ctxGameCanvas.clearRect(0, 0, gameCanvas.width, gameCanvas.height); GarageServerIO.getPlayerStates(function (state) { - ctxGameCanvas.fillRect(state.x, state.y, 10, 10); + ctxGameCanvas.fillRect(state.x, state.y, 15, 15); }); }, diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index bc14934..8aded4a 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -16,7 +16,6 @@ options = { function GarageServer (socketio, options) { this.io = socketio; - this.physicsDelta = (options.physicsInterval ? options.physicsInterval : 15) / 1000; this.game = new garageServerGame.createGame(options); this.registerSocketEvents(options); } @@ -28,7 +27,7 @@ GarageServer.prototype.registerSocketEvents = function (options) { if (options.logging) { console.log('garageserver.io:: socket ' + socket.id + ' connection'); } - socket.emit('state', { physicsDelta: self.physicsDelta }); + socket.emit('state', { physicsDelta: (options.physicsInterval ? options.physicsInterval : 15) / 1000 }); self.onPlayerConnect(socket, options); socket.on('disconnect', function () {