mirror of
https://github.com/wassname/GarageServer.IO.git
synced 2026-07-14 01:00:07 +08:00
Fixed broadcast issue
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user