mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-05 17:30:44 +08:00
Adding state history for lag compensation
This commit is contained in:
@@ -45,7 +45,7 @@ PlayerController.prototype.addInput = function (id, input, sequence, time) {
|
||||
});
|
||||
};
|
||||
|
||||
PlayerController.prototype.updateState = function (id, state) {
|
||||
PlayerController.prototype.setState = function (id, state) {
|
||||
this.entities.some(function (player) {
|
||||
if (player.client.id === id) {
|
||||
player.state = state;
|
||||
|
||||
@@ -4,8 +4,23 @@ function Entity () {
|
||||
this.state;
|
||||
this.sequence = 1;
|
||||
this.id;
|
||||
this.stateHistory = [];
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (var i = 0; i < this.stateHistory.length; i ++) {
|
||||
if (this.stateHistory[i].executionTime >= minTime) {
|
||||
spliceTo = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (spliceTo > 0) {
|
||||
this.stateHistory.splice(0, spliceTo);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -59,7 +59,7 @@ GarageServerGame.prototype.removePlayer = function (id) {
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.setPlayerState = function (id, state) {
|
||||
this.playerController.updateState(id, state);
|
||||
this.playerController.setState(id, state);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.addPlayerInput = function (id, input, sequence, time) {
|
||||
|
||||
Reference in New Issue
Block a user