mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-14 12:00:08 +08:00
@@ -9,7 +9,7 @@ options = {
|
||||
onPlayerInput: function (socket, input),
|
||||
onPlayerDisconnect: function (socket),
|
||||
onPing: function (socket, data),
|
||||
onState: function (socket, data),
|
||||
onPlayerState: function (socket, data),
|
||||
onUpdatePlayerPhysics: function (state, inputs),
|
||||
}
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ GarageServer.prototype.registerSocketEvents = function (options) {
|
||||
|
||||
socket.on('input', function (data) {
|
||||
if (options.logging) {
|
||||
console.log('garageserver.io:: socket input ' + socket.id + ' ' + data.input + ' ' + data.seq);
|
||||
console.log('garageserver.io:: socket input ' + socket.id + ' ' + data[0] + ' ' + data[1]);
|
||||
}
|
||||
self.onPlayerInput(socket, data, options);
|
||||
});
|
||||
@@ -55,7 +55,7 @@ GarageServer.prototype.registerSocketEvents = function (options) {
|
||||
if (options.logging) {
|
||||
console.log('garageserver.io:: socket playerState ' + data);
|
||||
}
|
||||
self.onState(socket, data, options);
|
||||
self.onPlayerState(socket, data, options);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -89,10 +89,10 @@ GarageServer.prototype.onPing = function (socket, data, options) {
|
||||
}
|
||||
};
|
||||
|
||||
GarageServer.prototype.onState = function (socket, data, options) {
|
||||
GarageServer.prototype.onPlayerState = function (socket, data, options) {
|
||||
this.game.setPlayerState(socket, data);
|
||||
if (options.onState) {
|
||||
options.onState(socket, data);
|
||||
if (options.onPlayerState) {
|
||||
options.onPlayerState(socket, data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ GarageServerGame.prototype.updatePlayers = function (options) {
|
||||
state = { time: currentTime, playerStates: [] };
|
||||
|
||||
this.players.forEach(function (player) {
|
||||
state.playerStates.push({ id: player.client.id, state: player.state, seq: player.sequence });
|
||||
state.playerStates.push([ player.client.id, player.state, player.sequence ]);
|
||||
});
|
||||
|
||||
this.players.forEach(function (player) {
|
||||
@@ -54,10 +54,9 @@ GarageServerGame.prototype.addPlayer = function (client) {
|
||||
}
|
||||
});
|
||||
|
||||
// Set player state callback
|
||||
var player = {
|
||||
client: client,
|
||||
state: {x: 0, y: 0},
|
||||
state: {},
|
||||
inputs: [],
|
||||
sequence: 1
|
||||
};
|
||||
@@ -78,7 +77,6 @@ GarageServerGame.prototype.setPlayerState = function (client, state) {
|
||||
this.players.some(function (player) {
|
||||
if (player.client.id === client.id) {
|
||||
player.state = state;
|
||||
player.sequence += 1;
|
||||
player.inputs = [];
|
||||
return true;
|
||||
}
|
||||
@@ -88,7 +86,7 @@ GarageServerGame.prototype.setPlayerState = function (client, state) {
|
||||
GarageServerGame.prototype.addPlayerInput = function (client, input) {
|
||||
this.players.some(function (player) {
|
||||
if (player.client.id === client.id) {
|
||||
player.inputs.push(input);
|
||||
player.inputs.push({ input: input[0], seq: input[1], time: input[2] });
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user