mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-08 00:10:05 +08:00
Refactor out socket call from garageservergame on server
This commit is contained in:
@@ -29,10 +29,14 @@ api methods
|
||||
sendPlayersEvent(data)
|
||||
*/
|
||||
function GarageServer(socketio, options) {
|
||||
this.socketPath = '/garageserver.io';
|
||||
var namespace = '/garageserver.io';
|
||||
|
||||
this.socketPath = namespace;
|
||||
this.io = socketio;
|
||||
this.game = new garageServerGame(options);
|
||||
this.registerSocketEvents(options);
|
||||
this.game = new garageServerGame(options, function (state) {
|
||||
socketio.of(namespace).emit('update' ,state);
|
||||
});
|
||||
}
|
||||
|
||||
GarageServer.prototype.registerSocketEvents = function (options) {
|
||||
|
||||
@@ -3,13 +3,14 @@ var playerController = require('./controllers/playercontroller'),
|
||||
|
||||
exports = module.exports = GarageServerGame;
|
||||
|
||||
function GarageServerGame(options) {
|
||||
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.broadcastCallback = broadcastCallback;
|
||||
}
|
||||
|
||||
GarageServerGame.prototype.start = function () {
|
||||
@@ -29,10 +30,8 @@ GarageServerGame.prototype.broadcastState = function () {
|
||||
|
||||
state.playerStates = this.getState(this.playerController);
|
||||
state.entityStates = this.getState(this.entityController);
|
||||
|
||||
this.playerController.entities.forEach(function (player) {
|
||||
player.client.emit('update', state);
|
||||
});
|
||||
|
||||
this.broadcastCallback(state);
|
||||
};
|
||||
|
||||
GarageServerGame.prototype.getState = function (controller) {
|
||||
|
||||
Reference in New Issue
Block a user