Updated GarageServer.IO API calls to support client side prediction for entities - #20

This commit is contained in:
Jeremiah Billmann
2015-05-20 02:10:07 +00:00
parent 21d8fb2884
commit fbdcfe3da5
12 changed files with 48 additions and 25 deletions
+3 -2
View File
@@ -8,7 +8,7 @@ function EntityController (maxHistorySecondBuffer) {
}
EntityController.prototype = {
add: function (id) {
add: function (id, referrerId) {
var newEntity, entityFound = false;
this.entities.some(function (entity) {
@@ -20,7 +20,8 @@ EntityController.prototype = {
});
if (!entityFound) {
newEntity = new entity(id, this.maxHistorySecondBuffer);
var referrerSeq = this.entities.filter(function (value) { return value.referrerId === referrerId; }).length;
newEntity = new entity(id, referrerId, referrerSeq, this.maxHistorySecondBuffer);
this.entities.push(newEntity);
}
return newEntity;
+3 -1
View File
@@ -2,10 +2,12 @@ var history = require('./history');
exports = module.exports = Entity;
function Entity (id, maxHistorySecondBuffer) {
function Entity (id, referrerId, referrerSeq, maxHistorySecondBuffer) {
this.state = {};
this.sequence = 1;
this.id = id;
this.referrerId = referrerId;
this.referrerSeq = referrerSeq;
this.maxHistorySecondBuffer = maxHistorySecondBuffer;
this.stateHistory = [];
this.region = '';
+1 -1
View File
@@ -3,7 +3,7 @@ var entity = require('./entity');
exports = module.exports = Player;
function Player (socket, maxHistorySecondBuffer) {
entity.call(this, socket.id, maxHistorySecondBuffer);
entity.call(this, socket.id, null, null, maxHistorySecondBuffer);
this.socket = socket;
this.inputs = [];
}
+2 -2
View File
@@ -150,8 +150,8 @@ GarageServer.prototype.updateEntityState = function (id, state) {
this.game.updateEntityState(id, state);
};
GarageServer.prototype.addEntity = function (id) {
this.game.addEntity(id);
GarageServer.prototype.addEntity = function (id, referrerId) {
this.game.addEntity(id, referrerId);
};
GarageServer.prototype.removeEntity = function (id) {
+2 -2
View File
@@ -103,8 +103,8 @@ GarageServerGame.prototype.removePlayer = function (id) {
this.playerController.remove(id);
};
GarageServerGame.prototype.addEntity = function (id) {
this.entityController.add(id);
GarageServerGame.prototype.addEntity = function (id, referrerId) {
this.entityController.add(id, referrerId);
};
GarageServerGame.prototype.removeEntity = function (id) {