mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-08-06 12:50:11 +08:00
@@ -107,6 +107,10 @@ GarageServer.prototype.onPlayerState = function (socket, data, options) {
|
||||
}
|
||||
};
|
||||
|
||||
GarageServer.prototype.start = function () {
|
||||
|
||||
};
|
||||
|
||||
exports.createGarageServer = function (io, options) {
|
||||
return new GarageServer(io, options);
|
||||
};
|
||||
@@ -4,19 +4,21 @@ var PlayerController = require('./controllers/playercontroller'),
|
||||
exports = module.exports = GarageServerGame;
|
||||
|
||||
function GarageServerGame(options) {
|
||||
var self = this;
|
||||
|
||||
this.playerController = new PlayerController();
|
||||
this.entityController = new EntityController();
|
||||
this.options = options;
|
||||
this.startTime = new Date().getTime();
|
||||
this.physicsInterval = options.physicsInterval ? options.physicsInterval : 15;
|
||||
this.startTime;
|
||||
this.stateInterval = options.stateInterval ? options.stateInterval : 45;
|
||||
this.physicsDelta = this.physicsInterval / 1000;
|
||||
this.physicsIntervalId = setInterval(function () { self.updatePhysics(options); }, this.physicsInterval);
|
||||
this.stateIntervalId = setInterval(function () { self.updateState(options); }, this.stateInterval);
|
||||
this.stateIntervalId = 0;
|
||||
}
|
||||
|
||||
GarageServerGame.prototype.start = function () {
|
||||
var self = this;
|
||||
|
||||
this.startTime = new Date().getTime();
|
||||
this.stateIntervalId = setInterval(function () { self.updateState(self.options); }, this.stateInterval);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.updateState = function (options) {
|
||||
var currentTime = new Date().getTime() - this.startTime,
|
||||
state = { time: currentTime, playerStates: [], entityStates: [] };
|
||||
@@ -58,6 +60,32 @@ GarageServerGame.prototype.updatePhysics = function (options) {
|
||||
});
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.getPlayerInputs = function (id) {
|
||||
var inputs;
|
||||
|
||||
this.playerController.entities.forSome(function (player) {
|
||||
if (player.id === id) {
|
||||
inputs = player.inputs;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return inputs;
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.updatePlayerState = function (id, state) {
|
||||
var currentTime = new Date().getTime() - this.startTime;
|
||||
|
||||
this.playerController.entities.forSome(function (player) {
|
||||
if (player.id === id) {
|
||||
player.addState(state, currentTime);
|
||||
player.sequence += player.inputs.length;
|
||||
player.inputs = [];
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.addPlayer = function (client) {
|
||||
this.playerController.add(client);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user