mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
fiusing notificationCenter for sendCommandToAllUsers for testing, seems to work
This commit is contained in:
parent
4ac86c69b4
commit
8cf8f057bb
4 changed files with 20 additions and 8 deletions
|
|
@ -14,10 +14,10 @@ define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputCo
|
||||||
this.serverGame = serverGame;
|
this.serverGame = serverGame;
|
||||||
this.players = {};
|
this.players = {};
|
||||||
this.init();
|
this.init();
|
||||||
};
|
}
|
||||||
|
|
||||||
ServerProcessor.prototype.init = function() {
|
ServerProcessor.prototype.init = function() {
|
||||||
this.physicsEngine = new PhysicsEngine();
|
this.physicsEngine = this.factory.new(PhysicsEngine);
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
this.updateWorld();
|
this.updateWorld();
|
||||||
|
|
@ -95,7 +95,8 @@ define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputCo
|
||||||
} while (body = body.GetNext());
|
} while (body = body.GetNext());
|
||||||
|
|
||||||
if(isUpdateNeeded) {
|
if(isUpdateNeeded) {
|
||||||
this.serverGame.updateClientsWorld(update);
|
//this.serverGame.updateClientsWorld(update);
|
||||||
|
this.notificationCenter.trigger("sendCommandToAllUsers", ['gameCommand', {worldUpdate:update}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
|
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ define(["Chuck/Processors/ServerProcessor"], function(ServerProcessor) {
|
||||||
|
|
||||||
function ServerGame(channel) {
|
function ServerGame(channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.serverProcessor = new ServerProcessor(this);
|
this.serverProcessor = this.factory.new(ServerProcessor, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerGame.prototype.loadLevel = function(path) {
|
ServerGame.prototype.loadLevel = function(path) {
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,6 @@ define(["Server/User", "Server/Channel", "Server/Factory"], function(User, Chann
|
||||||
this.channels[channelName] = channel;
|
this.channels[channelName] = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.notificationCenter = channel.notificationCenter;
|
|
||||||
user.factory = channel.factory;
|
|
||||||
|
|
||||||
channel.addUser(user);
|
channel.addUser(user);
|
||||||
user.setChannel(channel);
|
user.setChannel(channel);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,25 @@ define(["Protocol/Helper"], function(ProtocolHelper) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype.setChannel = function(channel){
|
User.prototype.setChannel = function(channel) {
|
||||||
|
if (this.notificationCenter) {
|
||||||
|
this.notificationCenter.off("updateClientsWorld");
|
||||||
|
}
|
||||||
|
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
|
// Use the right factory and nc
|
||||||
|
this.notificationCenter = this.channel.notificationCenter;
|
||||||
|
this.factory = this.channel.factory;
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this.notificationCenter.on("sendCommandToAllUsers", function(topic, args) {
|
||||||
|
self.sendCommand.apply(self, args);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype.sendCommand = function(command, options) {
|
User.prototype.sendCommand = function(command, options) {
|
||||||
|
|
||||||
var message = ProtocolHelper.encodeCommand(command, options);
|
var message = ProtocolHelper.encodeCommand(command, options);
|
||||||
this.socketLink.send(message);
|
this.socketLink.send(message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue