diff --git a/client/garageserver.io.js b/client/garageserver.io.js index e9c9e1b..edcacce 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -31,6 +31,7 @@ window.GarageServerIO = (function (window, socketio) { this.interpolation = false; this.pingInterval = 2000; this.clientSidePrediction = false; + this.smoothingFactor = 1; } StateController.prototype = { setTime: function (serverTime) { @@ -191,6 +192,7 @@ window.GarageServerIO = (function (window, socketio) { _stateController.interpolationDelay = data.interpolationDelay; _stateController.pingInterval = data.pingInterval; _stateController.clientSidePrediction = data.clientSidePrediction; + _stateController.smoothingFactor = data.smoothingFactor; setInterval(function (){ _socket.emit('ping', new Date().getTime()); }, _stateController.pingInterval); @@ -358,7 +360,7 @@ window.GarageServerIO = (function (window, socketio) { if (positions.previous && positions.target) { amount = getInterpolatedAmount(positions.previous.time, positions.target.time); newState = _options.onInterpolation(entity.id, positions.previous.state, positions.target.state, amount); - entity.currentState = newState = _options.onInterpolation(entity.id, entity.currentState, newState, _stateController.physicsDelta * 20); + entity.currentState = newState = _options.onInterpolation(entity.id, entity.currentState, newState, _stateController.smoothingFactor); } } }); diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index 8e14eee..be7daa2 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -2,20 +2,18 @@ var GarageServerGame = require('./garageservergame'); /* options = { - physicsInterval: 15, stateInterval: 45, logging: true, clientSidePrediction: true, interpolation: true, interpolationDelay: 100, + smoothingFactor: 0.3, pingInterval: 2000, onPlayerConnect: function (socket), onPlayerInput: function (socket, input), onPlayerDisconnect: function (socket), onPing: function (socket, data), onPlayerState: function (socket, data), - onUpdatePlayerPhysics: function (id, state, inputs, deltaTime), - onUpdateEntityPhysics: function (id, state, deltaTime) } */ @@ -34,6 +32,7 @@ GarageServer.prototype.registerSocketEvents = function (options) { } socket.emit('state', { physicsDelta: (options.physicsInterval ? options.physicsInterval : 15) / 1000, + smoothingFactor: options.smoothingFactor ? options.smoothingFactor : 1, interpolation: options.interpolation ? options.interpolation : false, interpolationDelay: options.interpolationDelay ? options.interpolationDelay : 100, pingInterval: options.pingInterval ? options.pingInterval : 2000,