altered define paths

This commit is contained in:
logsol 2012-07-21 23:41:41 +02:00
parent 231d957498
commit 704c78367b

View file

@ -1,4 +1,4 @@
var requires = [ define([
"Chuck/Physics/Engine", "Chuck/Physics/Engine",
"Chuck/Settings", "Chuck/Settings",
"Chuck/Player", "Chuck/Player",
@ -6,24 +6,24 @@ var requires = [
"Chuck/Loader/Level", "Chuck/Loader/Level",
"Chuck/Control/InputController", "Chuck/Control/InputController",
"RequestAnimationFrame" "RequestAnimationFrame"
]; ],
define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputController, requestAnimFrame){ function(PhysicsEngine, Settings, Player, Box2D, Level, InputController, requestAnimFrame){
function ServerProcessor (serverGame) { function GameController (channel) {
this.serverGame = serverGame; this.channel = channel;
this.players = {}; this.players = {};
this.init(); this.init();
} }
ServerProcessor.prototype.init = function() { GameController.prototype.init = function() {
this.physicsEngine = this.factory.new(PhysicsEngine); this.physicsEngine = this.factory.new(PhysicsEngine);
this.update(); this.update();
this.updateWorld(); this.updateWorld();
} }
ServerProcessor.prototype.loadLevel = function(path) { GameController.prototype.loadLevel = function(path) {
if (this.level) { if (this.level) {
this.level.unload(); this.level.unload();
} }
@ -32,11 +32,11 @@ define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputCo
this.level.loadLevelInToEngine(); this.level.loadLevelInToEngine();
} }
ServerProcessor.prototype.getPhysicsEngine = function() { GameController.prototype.getPhysicsEngine = function() {
return this.physicsEngine; return this.physicsEngine;
} }
ServerProcessor.prototype.update = function() { GameController.prototype.update = function() {
requestAnimFrame(this.update.bind(this)); requestAnimFrame(this.update.bind(this));
@ -46,11 +46,13 @@ define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputCo
} }
} }
ServerProcessor.prototype.destruct = function() { GameController.prototype.destruct = function() {
} }
ServerProcessor.prototype.createPlayerWithId = function(id) { GameController.prototype.createPlayerForUser = function(user) {
var id = user.id;
var player = new Player(this.physicsEngine, id, null); var player = new Player(this.physicsEngine, id, null);
this.players[id] = { this.players[id] = {
player: player, player: player,
@ -61,20 +63,24 @@ define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputCo
this.physicsEngine.setCollisionDetector(player); this.physicsEngine.setCollisionDetector(player);
} }
ServerProcessor.prototype.progressGameCommandFromId = function(command, options, id) { GameController.prototype.progressGameCommandFromId = function(command, options, id) {
var inputController = this.players[id].inputController; var inputController = this.players[id].inputController;
if (typeof inputController[command] == 'function') { if (typeof inputController[command] == 'function') {
inputController[command](options); inputController[command](options);
} }
} }
ServerProcessor.prototype.userIdLeft = function(id) { GameController.prototype.userIdLeft = function(id) {
var player = this.players[id].player; var player = this.players[id].player;
player.destroy(); player.destroy();
delete this.players[id]; delete this.players[id];
} }
ServerProcessor.prototype.updateWorld = function() { GameController.prototype.updateClientsWorld = function(update_world) {
this.channel.sendCommandToAllUsers('gameCommand', {worldUpdate: update_world});
}
GameController.prototype.updateWorld = function() {
var update = {}; var update = {};
var isUpdateNeeded = false; var isUpdateNeeded = false;
@ -102,5 +108,5 @@ define(requires, function(PhysicsEngine, Settings, Player, Box2D, Level, InputCo
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL); setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
} }
return ServerProcessor; return GameController;
}); });