Adding state history for lag compensation

This commit is contained in:
Jeremiah Billmann
2013-07-06 12:20:54 -04:00
parent 67caaf00ec
commit dd03d7a8d7
3 changed files with 17 additions and 2 deletions
+15
View File
@@ -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);
}
}
};