Splitted Client and Server Processors

This commit is contained in:
logsol 2012-07-13 17:13:01 +02:00
parent ae53d40c60
commit 8f38c6dcc6
4 changed files with 74 additions and 35 deletions

View file

@ -1,11 +1,23 @@
define(["Chuck/Processor"], function(Processor){
define(["Chuck/Settings", "Chuck/Processors/ServerProcessor", "Chuck/Processors/ClientProcessor"], function(Settings, ServerProcessor, ClientProcessor){
function Game(networker){
this.networker = networker;
this.processor = new Processor();
this.processor = this.createProcessor();
this.processor.loadLevel("default.json");
}
Game.prototype.createProcessor = function(){
var processor;
if(Settings.IS_BROWSER_ENVIRONMENT){
processor = new ClientProcessor();
} else {
processor = new ServerProcessor();
}
return processor;
}
Game.prototype.processGameCommand = function(command, options){
console.log('(not implemented) processGameCommand:', command, options);
}

View file

@ -11,15 +11,11 @@ var requires = [
define(requires, function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){
function Processor () {
if(Settings.IS_BROWSER_ENVIRONMENT) {
this.initClient();
} else {
this.initServer();
}
function ClientGame () {
this.init();
};
Processor.prototype.initClient = function() {
ClientGame.prototype.init = function() {
this.viewController = new ViewController();
this.physicsEngine = new PhysicsEngine();
this.me = new Player(this.physicsEngine, null);
@ -30,14 +26,7 @@ define(requires, function(ViewController, PhysicsEngine, Player, InputControlUni
this.update();
}
Processor.prototype.initServer = function() {
this.physicsEngine = new PhysicsEngine();
//this.physicsEngine.setCollisionDetector(players);
this.update();
}
Processor.prototype.loadLevel = function(path) {
ClientGame.prototype.loadLevel = function(path) {
if (this.level) {
this.level.unload();
}
@ -46,35 +35,27 @@ define(requires, function(ViewController, PhysicsEngine, Player, InputControlUni
this.level.loadLevelInToEngine();
}
Processor.prototype.getPhysicsEngine = function() {
ClientGame.prototype.getPhysicsEngine = function() {
return this.physicsEngine;
}
Processor.prototype.getMe = function() {
ClientGame.prototype.getMe = function() {
return this.me;
}
Processor.prototype.update = function() {
ClientGame.prototype.update = function() {
requestAnimFrame(this.update.bind(this));
//console.log(self.physicsEngine.getWorld().GetBodyList().GetPosition());
this.physicsEngine.update();
if(Settings.IS_BROWSER_ENVIRONMENT) {
this.viewController.update();
this.inputControlUnit.update();
this.me.update();
//self.camera.update();
//self.repository.update();
}
this.viewController.update();
this.inputControlUnit.update();
this.me.update();
}
Processor.prototype.destruct = function() {
ClientGame.prototype.destruct = function() {
}
return Processor;
return ClientGame;
});

View file

@ -0,0 +1,46 @@
var requires = [
"Chuck/Physics/Engine",
"Chuck/Player",
"Vendor/Box2D",
"Chuck/Loader/Level",
"RequestAnimationFrame"
];
define(requires, function(PhysicsEngine, Player, Box2D, Level, requestAnimFrame){
function ServerGame () {
this.init();
};
ServerGame.prototype.init = function() {
this.physicsEngine = new PhysicsEngine();
this.update();
}
ServerGame.prototype.loadLevel = function(path) {
if (this.level) {
this.level.unload();
}
this.level = new Level(path, this.physicsEngine);
this.level.loadLevelInToEngine();
console.log(this.level);
}
ServerGame.prototype.getPhysicsEngine = function() {
return this.physicsEngine;
}
ServerGame.prototype.update = function() {
requestAnimFrame(this.update.bind(this));
this.physicsEngine.update();
}
ServerGame.prototype.destruct = function() {
}
return ServerGame;
});

View file

@ -1,9 +1,9 @@
define(function() {
define(["Chuck/Game"], function(Game) {
function Channel(name) {
this.name = name;
this.users = {};
this.game = new Game();
// create game here
}