mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-09-09 11:14:19 +08:00
Renamed folder
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
exports = module.exports = Entity;
|
||||
|
||||
function Entity (id) {
|
||||
this.state = {};
|
||||
this.sequence = 1;
|
||||
this.id = id;
|
||||
this.stateHistory = [];
|
||||
}
|
||||
|
||||
Entity.prototype = {
|
||||
addState: function (state, executionTime) {
|
||||
this.addHistory(state, executionTime);
|
||||
this.sequence += 1;
|
||||
},
|
||||
addHistory: function (state, executionTime) {
|
||||
var minTime, spliceTo = 0;
|
||||
this.state = state;
|
||||
this.stateHistory.push({ state: state, executionTime: executionTime });
|
||||
minTime = this.stateHistory[this.stateHistory.length - 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
var entity = require('./entity');
|
||||
|
||||
exports = module.exports = Player;
|
||||
|
||||
function Player (client) {
|
||||
entity.call(this, client.id);
|
||||
this.client = client;
|
||||
this.inputs = [];
|
||||
}
|
||||
|
||||
Player.prototype = Object.create(entity.prototype);
|
||||
|
||||
Player.prototype.addState = function (state, executionTime) {
|
||||
this.addHistory(state, executionTime);
|
||||
this.sequence += this.inputs.length;
|
||||
this.inputs = [];
|
||||
};
|
||||
Reference in New Issue
Block a user