From 0204d254e60bbe391f2cd31cbb07737673ee8df0 Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Wed, 3 Jul 2013 17:27:54 -0400 Subject: [PATCH] Added playerId to callbacks --- client/garageserver.io.js | 12 ++++++------ example/public/javascripts/game.js | 2 +- example/shared/core.js | 2 +- lib/server/garageserver.io.js | 2 +- lib/server/garageservergame.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/garageserver.io.js b/client/garageserver.io.js index b686e0a..535f2d6 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -7,9 +7,9 @@ options = { onPlayerRemove: function (id), onGameState: function (state), onPing: function (pingDelay), - onUpdatePlayerPhysics: function (state, inputs, deltaTime), + onUpdatePlayerPhysics: function (id, state, inputs, deltaTime), onUpdate: function (), - onInterpolation: function(previousState, targetState, amount) + onInterpolation: function(id, previousState, targetState, amount) logging: true, clientSidePrediction: true, interpolation: true, @@ -261,7 +261,7 @@ 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); + _stateController.state = _options.onUpdatePlayerPhysics(_stateController.playerId, _stateController.state, [{ input: clientInput }], _stateController.physicsDelta); } _socket.emit('input', [ clientInput, _inputController.sequenceNumber, _stateController.renderTime ]); }, @@ -292,7 +292,7 @@ window.GarageServerIO = (function (window, socketio) { _inputController.removeUpToSequence(playerState[2]); if (_options.clientSidePrediction && _inputController.any()) { - _stateController.state = _options.onUpdatePlayerPhysics(_stateController.state, _inputController.inputs, _stateController.physicsDelta); + _stateController.state = _options.onUpdatePlayerPhysics(_stateController.playerId, _stateController.state, _inputController.inputs, _stateController.physicsDelta); } }, @@ -340,8 +340,8 @@ window.GarageServerIO = (function (window, socketio) { positions = player.getSurroundingPositions(_stateController.renderTime); if (positions.previous && positions.target) { amount = getInterpolatedAmount(positions.previous.time, positions.target.time); - newState = _options.onInterpolation(positions.previous.state, positions.target.state, amount); - player.currentState = newState = _options.onInterpolation(player.currentState, newState, _stateController.physicsDelta * 20); + newState = _options.onInterpolation(player.id, positions.previous.state, positions.target.state, amount); + player.currentState = newState = _options.onInterpolation(player.id, player.currentState, newState, _stateController.physicsDelta * 20); stateCallback(player.currentState); } else { diff --git a/example/public/javascripts/game.js b/example/public/javascripts/game.js index 46c6846..20a478c 100644 --- a/example/public/javascripts/game.js +++ b/example/public/javascripts/game.js @@ -9,7 +9,7 @@ $(function () { clientSidePrediction: true, interpolation: true, onUpdatePlayerPhysics: onUpdatePlayerPhysics, - onInterpolation: function (previousState, targetState, amount) { + onInterpolation: function (id, previousState, targetState, amount) { var interpolationState = {}; interpolationState.x = (previousState.x + amount * (targetState.x - previousState.x)); interpolationState.y = (previousState.y + amount * (targetState.y - previousState.y)); diff --git a/example/shared/core.js b/example/shared/core.js index 704ba7a..717535c 100644 --- a/example/shared/core.js +++ b/example/shared/core.js @@ -1,6 +1,6 @@ (function(exports){ - exports.onUpdatePlayerPhysics = function (state, inputs, deltaTime) { + exports.onUpdatePlayerPhysics = function (id, state, inputs, deltaTime) { var i = 0; if (!state.x && !state.y) { diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index 8c39a6c..5e03bf2 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -10,7 +10,7 @@ options = { onPlayerDisconnect: function (socket), onPing: function (socket, data), onPlayerState: function (socket, data), - onUpdatePlayerPhysics: function (state, inputs), + onUpdatePlayerPhysics: function (id, state, inputs, deltaTime) } */ diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index a8b2f87..d0d4ee2 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -39,7 +39,7 @@ GarageServerGame.prototype.updatePhysics = function (options) { this.players.forEach(function (player) { if (player.inputs.length > 0) { if (options.onUpdatePlayerPhysics) { - player.state = options.onUpdatePlayerPhysics(player.state, player.inputs, self.physicsDelta); + player.state = options.onUpdatePlayerPhysics(player.client.id, player.state, player.inputs, self.physicsDelta); } player.sequence += player.inputs.length; player.inputs = [];