Fixed broadcast issue

This commit is contained in:
Jeremiah Billmann
2013-06-08 16:19:29 -04:00
parent a46831d6ae
commit 815bf73cde
2 changed files with 7 additions and 9 deletions
+2 -4
View File
@@ -15,16 +15,14 @@ options = {
function GarageServer (socketio, options) {
this.io = socketio;
this.game = null;
this.game = new garageServerGame.createGame(options);
this.registerSocketEvents(options);
}
GarageServer.prototype.registerSocketEvents = function (options) {
var self = this;
self.io.of('/garageserver.io').on('connection', function (socket) {
self.game = new garageServerGame.createGame(socket, options);
if (options.logging) {
console.log('garageserver.io:: socket ' + socket.id + ' connection');
}
+5 -5
View File
@@ -1,8 +1,7 @@
function GarageServerGame (socket, options) {
function GarageServerGame (options) {
var self = this;
this.players = [];
this.socket = socket;
this.options = options;
this.physicsIntervalId = setInterval(function () { self.updatePhysics(options); }, options.physicsInterval ? options.physicsInterval : 15);
@@ -13,7 +12,8 @@ GarageServerGame.prototype.updatePlayers = function () {
var currentTime = new Date().getTime();
for (var i = 0; i < this.players.length; i ++) {
//TODO: Retink efficiency
this.socket.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
this.players[i].client.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
this.players[i].client.broadcast.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime });
}
};
@@ -64,6 +64,6 @@ GarageServerGame.prototype.addPlayerInput = function (client, input) {
}
};
exports.createGame = function (socketio, options){
return new GarageServerGame(socketio, options);
exports.createGame = function (options){
return new GarageServerGame(options);
};