working towards usable new structure

This commit is contained in:
logsol 2012-07-22 17:54:27 +02:00
parent 3afc2fa66e
commit 815c63009f
15 changed files with 223 additions and 84 deletions

View file

@ -3,24 +3,28 @@ define([
"Game/Client/Physics/Engine",
"Game/Client/View/ViewController",
"Game/Client/Control/KeyboardController",
"Game/Core/NotificationCenter",
"Lib/Utilities/RequestAnimFrame"
],
function(Parent, PhysicsEngine, ViewController, KeyboardController, requestAnimFrame) {
function(Parent, PhysicsEngine, ViewController, KeyboardController, NotificationCenter, requestAnimFrame) {
function GameController () {
this.viewController = new ViewController();
Parent.call(this, new PhysicsEngine());
this.me = null;
this.keyboardController = null;
this.viewController = new ViewController();
this.update();
//NotificationCenter.on('me/joined', this.meJoined, this)
//this.update();
}
GameController.prototype = Object.create(Parent.prototype);
/*
GameController.prototype.getMe = function() {
return this.me;
}
@ -40,6 +44,7 @@ function(Parent, PhysicsEngine, ViewController, KeyboardController, requestAnimF
GameController.prototype.meJoined = function(user) {
this.me = this.userJoined(user);
this.keyboardController = new KeyboardController(this.me, this);
}
@ -66,6 +71,6 @@ function(Parent, PhysicsEngine, ViewController, KeyboardController, requestAnimF
}
}
*/
return GameController;
});

View file

@ -19,7 +19,7 @@ function(ProtocolHelper, GameController) {
this.socketLink.on('connect', function() {
self.onConnect();
});
/*
this.socketLink.on('message', function(message) {
self.onMessage(message);
});
@ -27,12 +27,13 @@ function(ProtocolHelper, GameController) {
this.socketLink.on('disconnect', function() {
self.onDisconnect();
});
*/
}
Networker.prototype.onConnect = function() {
this.join('dungeon');
}
/*
Networker.prototype.onMessage = function(message) {
var self = this;
ProtocolHelper.runCommands(message, function(command, options) {
@ -44,7 +45,7 @@ function(ProtocolHelper, GameController) {
if(this.gameController) this.gameController.destruct();
this.gameController = null;
}
*/
Networker.prototype.join = function(channelName){
this.sendCommand('join', channelName);
}
@ -53,9 +54,9 @@ function(ProtocolHelper, GameController) {
var message = ProtocolHelper.encodeCommand(command, options);
this.socketLink.send(message);
}
/*
Networker.prototype.onJoinSuccess = function(options) {
this.gameController = new GameController(this, options.id);
this.gameController = new GameController(options.id);
this.gameController.loadLevel("default.json")
console.log("Joined " + options.channelName);
@ -103,7 +104,7 @@ function(ProtocolHelper, GameController) {
break;
}
}
*/
return Networker;
});

2
app/Game/Client/Physics/Engine.js Normal file → Executable file
View file

@ -17,7 +17,7 @@ function(Parent, Settings, DomController, Box2D) {
Engine.prototype.setupDebugDraw = function() {
//var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
var debugSprite = Dom.getDebugCanvas().getContext("2d");
var debugSprite = DomController.getDebugCanvas().getContext("2d");
// set debug draw
var debugDraw = new Box2D.Dynamics.b2DebugDraw();

View file

@ -7,7 +7,6 @@ define([
function(Engine, Level, Player) {
function GameController(physicsEngine) {
console.log('constructor called');
this.players = {};
if (! physicsEngine instanceof Engine) {
@ -30,12 +29,16 @@ function(Engine, Level, Player) {
this.level.loadLevelInToEngine();
}
/*
GameController.prototype.destroy = function() {
for(var player in this.players) {
this.players[player].destroy();
}
}
GameController.prototype.userJoined = function(user) {
var player = new Player(user.id, this.physicsEngine);
this.players[user.id] = player;
@ -48,5 +51,7 @@ function(Engine, Level, Player) {
delete this.players[user.id];
}
*/
return GameController;
});

8
app/Game/Core/User.js Executable file
View file

@ -0,0 +1,8 @@
define(function() {
function User(id) {
this.id = id;
}
return User;
});

View file

@ -1,26 +1,32 @@
define([
"Game/Server/GameController",
"Game/Server/NotificationCenter"
"Game/Core/NotificationCenter"
],
function(GameController, NotificationCenter) {
function Channel(name) {
this.name = name;
function Channel(coordinatorLink) {
this.coordinatorLink = coordinatorLink;
console.log('A CHANNEL WAS CREATED');
/*
this.users = {};
this.gameController = new GameController();
this.gameController.loadLevel("default.json");
*/
/*
var self = this;
NotificationCenter.on("processGameCommandFromUser", function(topic, args) {
self.processGameCommandFromUser.apply(self, args);
});
*/
}
Channel.validateName = function(name){
return true;
}
/*
Channel.prototype.addUser = function(user){
var userIds = Object.keys(this.users);
@ -56,7 +62,7 @@ function(GameController, NotificationCenter) {
Channel.prototype.processGameCommandFromUser = function(command, options, user) {
this.gameController.progressGameCommandFromUser(command, options, user);
}
*/
return Channel;
});

View file

@ -0,0 +1,20 @@
define([
],
function() {
function CoordinatorLink(process) {
this.process = process;
}
CoordinatorLink.prototype.send = function(message) {
this.process.send(message);
};
CoordinatorLink.prototype.receive = function(message) {
throw 'This method is abstract and must be overwritten by Channel';
};
return CoordinatorLink;
});

View file

@ -4,7 +4,7 @@ define([
"Game/Config/Settings",
"Game/Core/Control/InputController",
"Lib/Utilities/RequestAnimFrame",
"Game/Server/NotificationCenter"
"Game/Core/NotificationCenter"
],
function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, NotificationCenter) {
@ -14,15 +14,15 @@ function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, Not
this.inputControllers = {};
this.update();
this.updateWorld();
//this.update();
//this.updateWorld();
NotificationCenter.on('user/joined', this.userJoined, this);
NotificationCenter.on('user/left', this.userLeft, this);
//NotificationCenter.on('user/joined', this.userJoined, this);
//NotificationCenter.on('user/left', this.userLeft, this);
}
GameController.prototype = Object.create(Parent.prototype);
/*
GameController.prototype.update = function() {
requestAnimFrame(this.update.bind(this));
@ -79,6 +79,6 @@ function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, Not
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
}
*/
return GameController;
});

View file

@ -1,12 +1,13 @@
define([
"Game/Core/User",
"Game/Core/Protocol/Helper",
"Game/Server/NotificationCenter"
"Game/Core/NotificationCenter"
],
function(ProtocolHelper, NotificationCenter) {
function User(socketLink, coordinator) {
function(Parent, ProtocolHelper, NotificationCenter) {
function User(id, coordinator) {
Parent.call(this, id);
this.id = socketLink.id;
this.socketLink = socketLink;
this.coordinator = coordinator;
@ -15,19 +16,14 @@ function(ProtocolHelper, NotificationCenter) {
this.init(socketLink);
}
User.prototype = Object.create(Parent.prototype);
User.prototype.init = function(socketLink){
var self = this;
socketLink.on('message', function(message){
self.onMessage(message);
});
socketLink.on('disconnect', function(){
self.onDisconnect();
});
}
/*
User.prototype.setChannel = function(channel) {
this.channel = channel;
}
@ -38,44 +34,12 @@ function(ProtocolHelper, NotificationCenter) {
this.socketLink.send(message);
}
User.prototype.onMessage = function(message){
var self = this;
ProtocolHelper.runCommands(message, function(command, options){
self.processControlCommand(command, options);
});
}
User.prototype.onDisconnect = function(){
this.coordinator.removeUser(this);
}
User.prototype.processControlCommand = function(command, options){
switch(command) {
case 'join':
this.coordinator.assignUserToChannel(this, options);
break;
case 'leave':
this.coordinator.assignUserToLobby(this);
break;
case 'gameCommand':
for(var gameCommand in options) {
//NotificationCenter.trigger("processGameCommandFromUser", [gameCommand, options[gameCommand], this]);
//this.channel.processGameCommandFromUser(gameCommand, options[gameCommand], this);
}
break;
default:
break;
}
}
User.prototype.toString = function() {
return "[User " + this.id + "]";
};
*/
return User;
});