Furthered GarageServer.IO API calls to support client side prediction for entities - #20 - still have to change how client side prediction is invoked/processed.

This commit is contained in:
Jeremiah Billmann
2015-05-20 04:04:31 +00:00
parent fbdcfe3da5
commit f28dee8927
5 changed files with 89 additions and 34 deletions
+8 -1
View File
@@ -36,6 +36,7 @@ function GarageServer(socketio, options) {
this.socketPath = namespace;
this.io = socketio;
this.clientSidePrediction = options.clientSidePrediction;
this.registerSocketEvents(options);
this.game = new garageServerGame(options, function (state, region) {
if (!region) {
@@ -155,7 +156,13 @@ GarageServer.prototype.addEntity = function (id, referrerId) {
};
GarageServer.prototype.removeEntity = function (id) {
this.io.of(this.socketPath).emit('re', id);
if (this.clientSidePrediction) {
var entity = this.game.getEntity(id);
this.io.of(this.socketPath).emit('re', { id: entity.referrerId, seq: entity.referrerSeq });
}
else {
this.io.of(this.socketPath).emit('re', { id: id });
}
this.game.removeEntity(id);
};
+27 -4
View File
@@ -43,18 +43,32 @@ GarageServerGame.prototype.broadcastState = function () {
};
GarageServerGame.prototype.getState = function (controller) {
var states = [];
var states = [],
clientSidePrediction = this.options.clientSidePrediction;
controller.entities.forEach(function (entity) {
states.push([ entity.id, entity.state, entity.sequence ]);
if (clientSidePrediction && entity.referrerId != null) {
states.push([ entity.id, entity.state, entity.sequence, entity.referrerId, entity.referrerSeq ]);
}
else {
states.push([ entity.id, entity.state, entity.sequence ]);
}
});
return states;
};
GarageServerGame.prototype.getStateByRegion = function (controller, region) {
var states = [];
var states = [],
clientSidePrediction = this.options.clientSidePrediction;
controller.entities.forEach(function (entity) {
if (entity.region === region) {
states.push([ entity.id, entity.state, entity.sequence ]);
if (clientSidePrediction && entity.referrerId != null) {
states.push([ entity.id, entity.state, entity.sequence, entity.referrerId, entity.referrerSeq ]);
}
else {
states.push([ entity.id, entity.state, entity.sequence ]);
}
}
});
return states;
@@ -107,6 +121,15 @@ GarageServerGame.prototype.addEntity = function (id, referrerId) {
this.entityController.add(id, referrerId);
};
GarageServerGame.prototype.getEntity = function (id) {
for (var idx = 0; idx < this.entityController.entities.length; idx ++) {
if (this.entityController.entities[idx].id === id) {
return this.entityController.entities[idx];
}
}
};
GarageServerGame.prototype.removeEntity = function (id) {
this.entityController.remove(id);
};