mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-25 13:00:24 +08:00
Updated GarageServer.IO API calls to support client side prediction for entities - #20
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 = '';
|
||||
|
||||
@@ -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 = [];
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user