HTML and CSS Reference
In-Depth Information
for (var i = 0; i < this.keysToDelete.length; i++) {
delete this.keys[this.keysToDelete[i]];
}
this.keysToDelete.length = 0;
return commands;
}
Sending command to the server (network.js):
lastProcessMs: -1,
sendCommands: function(tick, commands) {
var processMs = (tick * g.MS_PER_TICK) + g.LATENCY_MS;
if (this.lastProcessMs >= processMs) {
// This command is scheduled to run before/during the previous
// command. Move it just ahead of the previous command.
// Note that, because of this, some commands may get dropped
// because they are sandwiched between two other commands in
// time. As long as all clients drop the same commands, this
// isn't a problem.
processMs = this.lastProcessMs + 1;
}
this.lastProcessMs = processMs;
this.socket.emit('clientinput', {
ms: processMs,
commands: commands
});
}
Receiving the command on the server (app.js):
var applyCommand = function(gameId, playerId, ms, commandlist) {
var handler = gameManager.getGameHandler(gameId);
var game = handler.game;
var playerServerData = handler.playerServerData[playerId];
if (game.tick * g.MS_PER_TICK >= ms) {
// This command came in too late, we have to adjust the time
// and apply the command later than expected.
// Note that this makes life difficult. Now the command
// will execute at a different time than was expected by the
// client when the client sent the command.
ms = (game.tick * g.MS_PER_TICK) + 1 + g.intdiv(g.LATENCY_MS, 2);
}
Search WWH ::




Custom Search