mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-12 00:40:09 +08:00
Storing state history for lag compensation.
This commit is contained in:
@@ -11,10 +11,10 @@ Entity.prototype = {
|
||||
addState: function (state, executionTime) {
|
||||
var minTime, spliceTo = 0;
|
||||
this.stateHistory.push({ state: state, executionTime: executionTime });
|
||||
minTime = this.stateHistory[this.stateHistory - 1].executionTime - 1000;
|
||||
minTime = this.stateHistory[this.stateHistory.length - 1].executionTime - 1000;
|
||||
|
||||
for (var i = 0; i < this.stateHistory.length; i ++) {
|
||||
if (this.stateHistory[i].executionTime >= minTime) {
|
||||
if (this.stateHistory[i].executionTime > minTime) {
|
||||
spliceTo = i - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ GarageServerGame.prototype.updatePhysics = function (options) {
|
||||
this.playerController.entities.forEach(function (player) {
|
||||
if (player.inputs.length > 0) {
|
||||
if (options.onUpdatePlayerPhysics) {
|
||||
player.state = options.onUpdatePlayerPhysics(player.client.id, player.state, player.inputs, self.physicsDelta);
|
||||
player.addState(options.onUpdatePlayerPhysics(player.client.id, player.state, player.inputs, self.physicsDelta), player.inputs[player.inputs.length - 1].time);
|
||||
player.sequence += player.inputs.length;
|
||||
player.inputs = [];
|
||||
}
|
||||
player.sequence += player.inputs.length;
|
||||
player.inputs = [];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user