Added playerId to callbacks

This commit is contained in:
Jeremiah Billmann
2013-07-03 17:27:54 -04:00
parent b1e4e7a52e
commit 0204d254e6
5 changed files with 10 additions and 10 deletions
+6 -6
View File
@@ -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 {
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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)
}
*/
+1 -1
View File
@@ -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 = [];