mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-01 16:50:06 +08:00
Resolved #19
This commit is contained in:
@@ -2,8 +2,9 @@ var entity = require('../entities/entity');
|
||||
|
||||
exports = module.exports = EntityController;
|
||||
|
||||
function EntityController () {
|
||||
function EntityController (maxHistorySecondBuffer) {
|
||||
this.entities = [];
|
||||
this.maxHistorySecondBuffer = maxHistorySecondBuffer;
|
||||
}
|
||||
|
||||
EntityController.prototype = {
|
||||
@@ -19,7 +20,7 @@ EntityController.prototype = {
|
||||
});
|
||||
|
||||
if (!entityFound) {
|
||||
newEntity = new entity(id);
|
||||
newEntity = new entity(id, this.maxHistorySecondBuffer);
|
||||
this.entities.push(newEntity);
|
||||
}
|
||||
return newEntity;
|
||||
|
||||
@@ -3,8 +3,8 @@ var entityController = require('./entitycontroller'),
|
||||
|
||||
exports = module.exports = PlayerController;
|
||||
|
||||
function PlayerController () {
|
||||
entityController.call(this);
|
||||
function PlayerController (maxHistorySecondBuffer) {
|
||||
entityController.call(this, maxHistorySecondBuffer);
|
||||
}
|
||||
|
||||
PlayerController.prototype = Object.create(entityController.prototype);
|
||||
@@ -21,7 +21,7 @@ PlayerController.prototype.add = function (client) {
|
||||
});
|
||||
|
||||
if (!playerFound) {
|
||||
newPlayer = new player(client);
|
||||
newPlayer = new player(client, this.maxHistorySecondBuffer);
|
||||
this.entities.push(newPlayer);
|
||||
}
|
||||
return newPlayer;
|
||||
|
||||
@@ -2,10 +2,11 @@ var history = require('./history');
|
||||
|
||||
exports = module.exports = Entity;
|
||||
|
||||
function Entity (id) {
|
||||
function Entity (id, maxHistorySecondBuffer) {
|
||||
this.state = {};
|
||||
this.sequence = 1;
|
||||
this.id = id;
|
||||
this.maxHistorySecondBuffer = maxHistorySecondBuffer;
|
||||
this.stateHistory = [];
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ Entity.prototype = {
|
||||
var minTime, spliceTo = 0, newHistory = new history(state, executionTime);
|
||||
|
||||
this.stateHistory.push(newHistory);
|
||||
minTime = this.stateHistory[this.stateHistory.length - 1].executionTime - 1000;
|
||||
minTime = this.stateHistory[this.stateHistory.length - 1].executionTime - this.maxHistorySecondBuffer;
|
||||
|
||||
for (var i = 0; i < this.stateHistory.length; i ++) {
|
||||
if (this.stateHistory[i].executionTime > minTime) {
|
||||
|
||||
@@ -2,8 +2,8 @@ var entity = require('./entity');
|
||||
|
||||
exports = module.exports = Player;
|
||||
|
||||
function Player (client) {
|
||||
entity.call(this, client.id);
|
||||
function Player (client, maxHistorySecondBuffer) {
|
||||
entity.call(this, client.id, maxHistorySecondBuffer);
|
||||
this.client = client;
|
||||
this.inputs = [];
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ options = {
|
||||
interpolationDelay: 100,
|
||||
smoothingFactor: 0.3,
|
||||
pingInterval: 2000,
|
||||
maxUpdateBuffer: 120,
|
||||
maxHistorySecondBuffer: 1000,
|
||||
worldState: {},
|
||||
onPlayerConnect: function (socket),
|
||||
onPlayerInput: function (socket, input),
|
||||
@@ -53,6 +55,7 @@ GarageServer.prototype.registerSocketEvents = function (options) {
|
||||
interpolationDelay: options.interpolationDelay ? options.interpolationDelay : 100,
|
||||
pingInterval: options.pingInterval ? options.pingInterval : 2000,
|
||||
clientSidePrediction: options.clientSidePrediction ? options.clientSidePrediction : false,
|
||||
maxUpdateBuffer: options.maxUpdateBuffer ? options.maxUpdateBuffer : 120,
|
||||
worldState: options.worldState ? options.worldState : {}
|
||||
});
|
||||
self.onPlayerConnect(socket, options);
|
||||
|
||||
@@ -4,12 +4,12 @@ var playerController = require('./controllers/playercontroller'),
|
||||
exports = module.exports = GarageServerGame;
|
||||
|
||||
function GarageServerGame(options, broadcastCallback) {
|
||||
this.playerController = new playerController();
|
||||
this.entityController = new entityController();
|
||||
this.options = options;
|
||||
this.startTime = 0;
|
||||
this.stateInterval = options.stateInterval ? options.stateInterval : 45;
|
||||
this.stateIntervalId = 0;
|
||||
this.playerController = new playerController(this.options.maxHistorySecondBuffer ? this.options.maxHistorySecondBuffer : 1000);
|
||||
this.entityController = new entityController(this.options.maxHistorySecondBuffer ? this.options.maxHistorySecondBuffer : 1000);
|
||||
this.broadcastCallback = broadcastCallback;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user