From 26f3d22db73d556e63fdac6433a85f77dc360374 Mon Sep 17 00:00:00 2001 From: logsol Date: Sat, 28 Jul 2012 13:26:05 +0200 Subject: [PATCH] replaced all tabs with 4 spaces --- app/Bootstrap/Channel.js | 44 ++-- app/Bootstrap/Client.js | 16 +- app/Bootstrap/HttpServer.js | 104 ++++---- app/Bootstrap/Server.js | 18 +- app/Bootstrap/Socket.js | 40 +-- app/Game/Client/Collision/Detector.js | 28 +- app/Game/Client/Control/KeyboardInput.js | 2 +- app/Game/Client/GameController.js | 104 ++++---- app/Game/Client/Networker.js | 200 ++++++++------- app/Game/Client/View/CameraController.js | 72 +++--- app/Game/Client/View/DomController.js | 82 +++--- app/Game/Client/View/ViewController.js | 140 +++++----- app/Game/Config/Settings.js | 76 +++--- app/Game/Core/Control/InputController.js | 2 +- app/Game/Core/Physics/Engine.js | 50 ++-- app/Game/Core/Player.js | 312 +++++++++++------------ app/Game/Core/Protocol/Helper.js | 38 +-- app/Game/Core/Protocol/Parser.js | 16 +- app/Game/Core/User.js | 8 +- app/Game/Server/Channel.js | 178 ++++++------- app/Game/Server/CoordinatorLink.js | 20 +- app/Game/Server/GameController.js | 126 ++++----- app/Game/Server/User.js | 56 ++-- app/Lib/Utilities/RequestAnimFrame.js | 4 +- app/Lobby/Coordinator.js | 106 ++++---- app/Lobby/User.js | 92 +++---- channel.js | 8 +- client.js | 26 +- server.js | 24 +- static/html/index.html | 36 +-- 30 files changed, 1017 insertions(+), 1011 deletions(-) mode change 100644 => 100755 app/Game/Core/Control/InputController.js mode change 100644 => 100755 app/Game/Core/Player.js mode change 100644 => 100755 app/Game/Core/Protocol/Helper.js mode change 100644 => 100755 app/Game/Core/Protocol/Parser.js diff --git a/app/Bootstrap/Channel.js b/app/Bootstrap/Channel.js index 6403951..23f7018 100755 --- a/app/Bootstrap/Channel.js +++ b/app/Bootstrap/Channel.js @@ -1,34 +1,34 @@ define([ - "Game/Server/Channel", - "Game/Server/CoordinatorLink" + "Game/Server/Channel", + "Game/Server/CoordinatorLink" ], function(Channel, CoordinatorLink) { - function ChannelBootstrap(process) { + function ChannelBootstrap(process) { - var coordinatorLink = new CoordinatorLink(process); - var channel = null; + var coordinatorLink = new CoordinatorLink(process); + var channel = null; - process.on('message', function(message) { + process.on('message', function(message) { - switch(message){ - case 'CREATE': - channel = new Channel(coordinatorLink); - break; + switch(message){ + case 'CREATE': + channel = new Channel(coordinatorLink); + break; - case 'KILL': - channel.destroy(); - process.exit(0); - break; + case 'KILL': + channel.destroy(); + process.exit(0); + break; - default: - coordinatorLink.receive(message); - break; - } - }); - } + default: + coordinatorLink.receive(message); + break; + } + }); + } - return ChannelBootstrap; - + return ChannelBootstrap; + }); \ No newline at end of file diff --git a/app/Bootstrap/Client.js b/app/Bootstrap/Client.js index 8da6d65..ca5aeeb 100755 --- a/app/Bootstrap/Client.js +++ b/app/Bootstrap/Client.js @@ -1,15 +1,15 @@ define([ - "Game/Client/Networker", - "Lib/Vendor/SocketIO" + "Game/Client/Networker", + "Lib/Vendor/SocketIO" ], function(Networker, SocketIO) { - function Client(location, options) { - this.socket = SocketIO.connect(location, options); - this.networker = new Networker(this.socket); - } + function Client(location, options) { + this.socket = SocketIO.connect(location, options); + this.networker = new Networker(this.socket); + } - return Client; - + return Client; + }); \ No newline at end of file diff --git a/app/Bootstrap/HttpServer.js b/app/Bootstrap/HttpServer.js index cc2b473..974b289 100755 --- a/app/Bootstrap/HttpServer.js +++ b/app/Bootstrap/HttpServer.js @@ -1,71 +1,71 @@ define([ - 'http', - 'node-static' + 'http', + 'node-static' ], function(http, nodeStatic) { - function HttpServer(options) { - options.port = options.port || 1234; - options.caching = typeof options.caching != 'undefined' ? options.caching : true; - options.rootDirectory = options.rootDirectory || './'; + function HttpServer(options) { + options.port = options.port || 1234; + options.caching = typeof options.caching != 'undefined' ? options.caching : true; + options.rootDirectory = options.rootDirectory || './'; - this.server = null; + this.server = null; - this.init(options); - } + this.init(options); + } - HttpServer.prototype.init = function(options) { - var self = this; + HttpServer.prototype.init = function(options) { + var self = this; - var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching }); + var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching }); - this.server = http.createServer( - function(req, res){ - req.addListener('end', function () { - switch(true) { - case req.url == '/': - fileServer.serveFile('./static/html/index.html', 200, {}, req, res); - break; + this.server = http.createServer( + function(req, res){ + req.addListener('end', function () { + switch(true) { + case req.url == '/': + fileServer.serveFile('./static/html/index.html', 200, {}, req, res); + break; - case req.url == '/client.js': - fileServer.serveFile('./client.js', 200, {}, req, res); - break; + case req.url == '/client.js': + fileServer.serveFile('./client.js', 200, {}, req, res); + break; - case req.url == '/require.js': - fileServer.serveFile('./node_modules/requirejs/require.js', 200, {}, req, res); - break; + case req.url == '/require.js': + fileServer.serveFile('./node_modules/requirejs/require.js', 200, {}, req, res); + break; - case new RegExp(/^\/app/).test(req.url): - fileServer.serve(req, res, function(){ - self.handleFileError(res) - }); - break; + case new RegExp(/^\/app/).test(req.url): + fileServer.serve(req, res, function(){ + self.handleFileError(res) + }); + break; - case new RegExp(/^\/static/).test(req.url): - fileServer.serve(req, res, function(){ - self.handleFileError(res) - }); - break; + case new RegExp(/^\/static/).test(req.url): + fileServer.serve(req, res, function(){ + self.handleFileError(res) + }); + break; - default: - self.handleFileError(res); - break; - } - }); - } - ); - this.server.listen(options.port); - } + default: + self.handleFileError(res); + break; + } + }); + } + ); + this.server.listen(options.port); + } - HttpServer.prototype.getServer = function(){ - return this.server; - } + HttpServer.prototype.getServer = function(){ + return this.server; + } - HttpServer.prototype.handleFileError = function (res){ - res.writeHead(404, {'Content-Type': 'text/html'}); - res.end('

404 not ... found

'); - } + HttpServer.prototype.handleFileError = function (res){ + res.writeHead(404, {'Content-Type': 'text/html'}); + res.end('

404 not ... found

'); + } - return HttpServer; + return HttpServer; }); \ No newline at end of file diff --git a/app/Bootstrap/Server.js b/app/Bootstrap/Server.js index dabe14a..981834a 100755 --- a/app/Bootstrap/Server.js +++ b/app/Bootstrap/Server.js @@ -1,16 +1,16 @@ define([ - "Bootstrap/HttpServer", - "Bootstrap/Socket", - "Lobby/Coordinator" + "Bootstrap/HttpServer", + "Bootstrap/Socket", + "Lobby/Coordinator" ], function(HttpServer, Socket, Coordinator) { - function Server(options) { - coordinator = new Coordinator(); - httpServer = new HttpServer(options); - this.socket = new Socket(httpServer.getServer(), options, coordinator); - } + function Server(options) { + coordinator = new Coordinator(); + httpServer = new HttpServer(options); + this.socket = new Socket(httpServer.getServer(), options, coordinator); + } - return Server; + return Server; }); \ No newline at end of file diff --git a/app/Bootstrap/Socket.js b/app/Bootstrap/Socket.js index e4f7c3e..b82f9d3 100755 --- a/app/Bootstrap/Socket.js +++ b/app/Bootstrap/Socket.js @@ -1,36 +1,36 @@ define([ - 'socket.io' + 'socket.io' ], function(io) { - function Socket(server, options, coordinator) { + function Socket(server, options, coordinator) { options.logLevel = typeof options.logLevel != 'undefined' ? options.logLevel : 0; - this.coordinator = coordinator; - this.socket = io.listen(server); + this.coordinator = coordinator; + this.socket = io.listen(server); - this.init(options); - } + this.init(options); + } - Socket.prototype.init = function(options){ + Socket.prototype.init = function(options){ - var self = this; - this.socket.configure('development', function(){ - this.set('log level', options.logLevel); - }); + var self = this; + this.socket.configure('development', function(){ + this.set('log level', options.logLevel); + }); - this.socket.on('connection', function(user){ - self.onConnection(user); - }); - } + this.socket.on('connection', function(user){ + self.onConnection(user); + }); + } - Socket.prototype.onConnection = function(socketLink){ - this.coordinator.createUser(socketLink); - } + Socket.prototype.onConnection = function(socketLink){ + this.coordinator.createUser(socketLink); + } - return Socket; - + return Socket; + }); diff --git a/app/Game/Client/Collision/Detector.js b/app/Game/Client/Collision/Detector.js index 4c0a0cc..9c50c7f 100755 --- a/app/Game/Client/Collision/Detector.js +++ b/app/Game/Client/Collision/Detector.js @@ -1,24 +1,24 @@ define([ - "Lib/Vendor/Box2D", - "Game/Core/Collision/Detector" + "Lib/Vendor/Box2D", + "Game/Core/Collision/Detector" ], function(Box2D, Parent) { - function Detector(me) { - Parent.call(this); - this.me = me; - } + function Detector(me) { + Parent.call(this); + this.me = me; + } - Detector.prototype = Object.create(Parent.prototype); + Detector.prototype = Object.create(Parent.prototype); - Detector.prototype.handleStand = function(point, isColliding) { - if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR - || point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) { + Detector.prototype.handleStand = function(point, isColliding) { + if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR + || point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) { - this.me.onFootSensorDetection(isColliding); - } - } + this.me.onFootSensorDetection(isColliding); + } + } - return Detector; + return Detector; }); \ No newline at end of file diff --git a/app/Game/Client/Control/KeyboardInput.js b/app/Game/Client/Control/KeyboardInput.js index c2f5f1e..442cdc8 100755 --- a/app/Game/Client/Control/KeyboardInput.js +++ b/app/Game/Client/Control/KeyboardInput.js @@ -8,7 +8,7 @@ define(["Game/Client/Control/Key"], function(Key){ this.init(); } - KeyboardInput.prototype.init = function() { + KeyboardInput.prototype.init = function() { // Using window is ok here because it only runs in the browser window.onkeydown = this._onKeyDown.bind(this); window.onkeyup = this._onKeyUp.bind(this); diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index ca48ea1..403acec 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -1,76 +1,76 @@ define([ - "Game/Core/GameController", - "Game/Client/Physics/Engine", - "Game/Client/View/ViewController", - "Game/Client/Control/KeyboardController", - "Game/Core/NotificationCenter", - "Lib/Utilities/RequestAnimFrame" + "Game/Core/GameController", + "Game/Client/Physics/Engine", + "Game/Client/View/ViewController", + "Game/Client/Control/KeyboardController", + "Game/Core/NotificationCenter", + "Lib/Utilities/RequestAnimFrame" ], function(Parent, PhysicsEngine, ViewController, KeyboardController, NotificationCenter, requestAnimFrame) { - function GameController () { - this.viewController = new ViewController(); + function GameController () { + this.viewController = new ViewController(); - Parent.call(this, new PhysicsEngine()); + Parent.call(this, new PhysicsEngine()); - this.me = null; - this.keyboardController = null; + this.me = null; + this.keyboardController = null; - //NotificationCenter.on('me/joined', this.meJoined, this) + //NotificationCenter.on('me/joined', this.meJoined, this) - //this.update(); - } + //this.update(); + } - GameController.prototype = Object.create(Parent.prototype); + GameController.prototype = Object.create(Parent.prototype); /* - GameController.prototype.getMe = function() { - return this.me; - } + GameController.prototype.getMe = function() { + return this.me; + } - GameController.prototype.update = function() { + GameController.prototype.update = function() { - requestAnimFrame(this.update.bind(this)); + requestAnimFrame(this.update.bind(this)); - this.physicsEngine.update(); - this.viewController.update(); + this.physicsEngine.update(); + this.viewController.update(); - if(this.me) { - this.keyboardController.update(); - this.me.update(); - } - } + if(this.me) { + this.keyboardController.update(); + this.me.update(); + } + } - GameController.prototype.meJoined = function(user) { - this.me = this.userJoined(user); + GameController.prototype.meJoined = function(user) { + this.me = this.userJoined(user); - this.keyboardController = new KeyboardController(this.me, this); - } + this.keyboardController = new KeyboardController(this.me, this); + } - GameController.prototype.processGameCommand = function(command, options) { - - if (command == "worldUpdate") { + GameController.prototype.processGameCommand = function(command, options) { + + if (command == "worldUpdate") { - var body = this.physicsEngine.world.GetBodyList(); - do { - var userData = body.GetUserData(); - if(userData && options[userData]) { - var update = options[userData]; - - //console.log('position difference:', (body.GetPosition().y - update.p.y) * 30, body.GetLinearVelocity().y); - - body.SetAwake(true); - body.SetPosition(update.p); - body.SetAngle(update.a); - body.SetLinearVelocity(update.lv); - body.SetAngularVelocity(update.av); - } - } while (body = body.GetNext()); + var body = this.physicsEngine.world.GetBodyList(); + do { + var userData = body.GetUserData(); + if(userData && options[userData]) { + var update = options[userData]; + + //console.log('position difference:', (body.GetPosition().y - update.p.y) * 30, body.GetLinearVelocity().y); + + body.SetAwake(true); + body.SetPosition(update.p); + body.SetAngle(update.a); + body.SetLinearVelocity(update.lv); + body.SetAngularVelocity(update.av); + } + } while (body = body.GetNext()); - } + } - } + } */ - return GameController; + return GameController; }); diff --git a/app/Game/Client/Networker.js b/app/Game/Client/Networker.js index 93cfe5b..1fe988d 100755 --- a/app/Game/Client/Networker.js +++ b/app/Game/Client/Networker.js @@ -1,112 +1,118 @@ define([ - "Game/Core/Protocol/Helper", - "Game/Client/GameController" + "Game/Core/Protocol/Helper", + "Game/Client/GameController" ], function(ProtocolHelper, GameController) { - function Networker(socketLink) { - this.socketLink = socketLink; - this.gameController = null; + function Networker(socketLink) { + this.socketLink = socketLink; + this.gameController = null; - this.init(); - } + this.init(); + } - Networker.prototype.init = function() { - - var self = this; + Networker.prototype.init = function() { + + var self = this; - this.socketLink.on('connect', function() { - self.onConnect(); - }); + this.socketLink.on('connect', function() { + self.onConnect(); + }); /* - this.socketLink.on('message', function(message) { - self.onMessage(message); - }); + this.socketLink.on('message', function(message) { + self.onMessage(message); + }); */ - this.socketLink.on('disconnect', function() { - self.onDisconnect(); - }); + this.socketLink.on('disconnect', function() { + self.onDisconnect(); + }); - } + } + + Networker.prototype.onConnect = function() { + console.log('connected.') + this.join('dungeon'); + } + + Networker.prototype.onDisconnect = function() { + if(this.gameController) this.gameController.destruct(); + this.gameController = null; + console.log('disconnected. game destroyed. no auto-reconnect'); + } + + Networker.prototype.join = function(channelName){ + this.sendCommand('join', channelName); + } + + + Networker.prototype.onJoinSuccess = function(options) { + this.gameController = new GameController(options.id); + this.gameController.loadLevel("default.json"); + /* + console.log("Joined " + options.channelName); + + if (options.userIds && options.userIds.length > 0) { + for(var i = 0; i < options.userIds.length; i++) { + this.gameController.userJoined(options.userIds[i]) + } + } + */ + } + + Networker.prototype.sendCommand = function(command, options) { + var message = ProtocolHelper.encodeCommand(command, options); + this.socketLink.send(message); + } - Networker.prototype.onConnect = function() { - console.log('connected.') - this.join('dungeon'); - } /* - Networker.prototype.onMessage = function(message) { - var self = this; - ProtocolHelper.runCommands(message, function(command, options) { - self.processControlCommand(command, options); - }); - } + Networker.prototype.onMessage = function(message) { + var self = this; + + ProtocolHelper.runCommands(message, function(command, options) { + self.processControlCommand(command, options); + }); + + } + + Networker.prototype.onUserJoined = function(userId) { + this.gameController.userJoined(userId); + console.log("User " + userId + " joined"); + } + + Networker.prototype.sendGameCommand = function(command, options) { + this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options)); + } + + Networker.prototype.onUserLeft = function(userId) { + this.gameController.userLeft(userId); + } + + Networker.prototype.processControlCommand = function(command, options) { + switch(command) { + case 'joinSuccess': + this.onJoinSuccess(options); + break; + + case 'gameCommand': + for(var gameCommand in options) { + this.gameController.processGameCommand(gameCommand, options[gameCommand]); + } + break; + + case 'userJoined': + this.onUserJoined(options); + break; + + case 'userLeft': + this.onUserLeft(options); + break; + + default: + break; + } + } */ - Networker.prototype.onDisconnect = function() { - if(this.gameController) this.gameController.destruct(); - this.gameController = null; - console.log('disconnected. game destroyed. no auto-reconnect'); - } - - Networker.prototype.join = function(channelName){ - this.sendCommand('join', channelName); - } - - Networker.prototype.sendCommand = function(command, options) { - var message = ProtocolHelper.encodeCommand(command, options); - this.socketLink.send(message); - } -/* - Networker.prototype.onJoinSuccess = function(options) { - this.gameController = new GameController(options.id); - this.gameController.loadLevel("default.json") - console.log("Joined " + options.channelName); - - if (options.userIds && options.userIds.length > 0) { - for(var i = 0; i < options.userIds.length; i++) { - this.gameController.userJoined(options.userIds[i]) - } - } - } - - Networker.prototype.onUserJoined = function(userId) { - this.gameController.userJoined(userId); - console.log("User " + userId + " joined"); - } - - Networker.prototype.sendGameCommand = function(command, options) { - this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options)); - } - - Networker.prototype.onUserLeft = function(userId) { - this.gameController.userLeft(userId); - } - - Networker.prototype.processControlCommand = function(command, options) { - switch(command) { - case 'joinSuccess': - this.onJoinSuccess(options); - break; - - case 'gameCommand': - for(var gameCommand in options) { - this.gameController.processGameCommand(gameCommand, options[gameCommand]); - } - break; - - case 'userJoined': - this.onUserJoined(options); - break; - - case 'userLeft': - this.onUserLeft(options); - break; - - default: - break; - } - } -*/ - return Networker; - + return Networker; + }); \ No newline at end of file diff --git a/app/Game/Client/View/CameraController.js b/app/Game/Client/View/CameraController.js index b5873bc..6aadee1 100755 --- a/app/Game/Client/View/CameraController.js +++ b/app/Game/Client/View/CameraController.js @@ -1,50 +1,50 @@ define(['Lib/Vendor/Three', 'Game/Config/Settings'], function(Three, Settings) { - function CameraController(isOrthographic) { + function CameraController(isOrthographic) { - isOrthographic = typeof isOrthographic == 'undefined' - ? true - : isOrthographic; + isOrthographic = typeof isOrthographic == 'undefined' + ? true + : isOrthographic; - if(isOrthographic) { - - this.camera = new Three.OrthographicCamera( - -Settings.STAGE_WIDTH/2, - Settings.STAGE_WIDTH/2, - Settings.STAGE_HEIGHT/2, - -Settings.STAGE_HEIGHT/2, - -2000, - 1000 - ); + if(isOrthographic) { + + this.camera = new Three.OrthographicCamera( + -Settings.STAGE_WIDTH/2, + Settings.STAGE_WIDTH/2, + Settings.STAGE_HEIGHT/2, + -Settings.STAGE_HEIGHT/2, + -2000, + 1000 + ); - } else { + } else { - this.camera = new Three.PerspectiveCamera( - 45, - Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT, - -2000, - 1000 - ); - } + this.camera = new Three.PerspectiveCamera( + 45, + Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT, + -2000, + 1000 + ); + } - this.camera.position.z = 481; - } + this.camera.position.z = 481; + } - CameraController.prototype.getCamera = function(){ - return this.camera; - } + CameraController.prototype.getCamera = function(){ + return this.camera; + } - CameraController.prototype.setPosition = function(x, y){ - this.camera.position.x = x; - this.camera.position.y = y; - } + CameraController.prototype.setPosition = function(x, y){ + this.camera.position.x = x; + this.camera.position.y = y; + } - CameraController.prototype.setZoom = function(z){ - this.camera.position.z = z; - } + CameraController.prototype.setZoom = function(z){ + this.camera.position.z = z; + } - return CameraController; - + return CameraController; + }); \ No newline at end of file diff --git a/app/Game/Client/View/DomController.js b/app/Game/Client/View/DomController.js index 204f342..ce6e31b 100755 --- a/app/Game/Client/View/DomController.js +++ b/app/Game/Client/View/DomController.js @@ -1,53 +1,53 @@ define(['Game/Config/Settings'], function(Settings) { - var DomController = { - canvas: null, - debugCanvas: null - }; + var DomController = { + canvas: null, + debugCanvas: null + }; - DomController.getCanvasContainer = function(){ - var container = document.getElementById(Settings.CANVAS_DOM_ID); + DomController.getCanvasContainer = function(){ + var container = document.getElementById(Settings.CANVAS_DOM_ID); - if(container) { - return container; - } else { - throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID; - } - } + if(container) { + return container; + } else { + throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID; + } + } - DomController.getCanvas = function(){ - return DomController.canvas; - } + DomController.getCanvas = function(){ + return DomController.canvas; + } - DomController.setCanvas = function(canvas){ - - var container = DomController.getCanvasContainer(); - if(DomController.canvas){ - container.removeChild(DomController.canvas); - } + DomController.setCanvas = function(canvas){ + + var container = DomController.getCanvasContainer(); + if(DomController.canvas){ + container.removeChild(DomController.canvas); + } - DomController.canvas = canvas; - container.appendChild(canvas); - } + DomController.canvas = canvas; + container.appendChild(canvas); + } - DomController.getDebugCanvas = function(){ - return DomController.debugCanvas; - } + DomController.getDebugCanvas = function(){ + return DomController.debugCanvas; + } - DomController.createDebugCanvas = function(){ - - var container = DomController.getCanvasContainer(); - if(DomController.debugCanvas){ - container.removeChild(DomController.debugCanvas); - } + DomController.createDebugCanvas = function(){ + + var container = DomController.getCanvasContainer(); + if(DomController.debugCanvas){ + container.removeChild(DomController.debugCanvas); + } - var canvas = document.createElement('canvas'); - canvas.width = Settings.STAGE_WIDTH; - canvas.height = Settings.STAGE_HEIGHT; - DomController.debugCanvas = canvas; - container.appendChild(canvas); - } + var canvas = document.createElement('canvas'); + canvas.width = Settings.STAGE_WIDTH; + canvas.height = Settings.STAGE_HEIGHT; + DomController.debugCanvas = canvas; + container.appendChild(canvas); + } - return DomController; - + return DomController; + }); \ No newline at end of file diff --git a/app/Game/Client/View/ViewController.js b/app/Game/Client/View/ViewController.js index 2f8c080..5db0e61 100755 --- a/app/Game/Client/View/ViewController.js +++ b/app/Game/Client/View/ViewController.js @@ -1,59 +1,59 @@ var requires = [ - "Game/Client/View/DomController", - "Lib/Vendor/Three", - "Game/Config/Settings", - "Game/Client/View/CameraController" + "Game/Client/View/DomController", + "Lib/Vendor/Three", + "Game/Config/Settings", + "Game/Client/View/CameraController" ]; define(requires, function(DomController, Three, Settings, CameraController){ - - function ViewController(){ + + function ViewController(){ - this.mesh = null; - this.scene = null; - this.renderer = null; - this.cameraController = new CameraController(); + this.mesh = null; + this.scene = null; + this.renderer = null; + this.cameraController = new CameraController(); - this.init(); - } + this.init(); + } - function isWebGlEnabled () { - try { - return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); - } catch(e) { - return false; - } - } + function isWebGlEnabled () { + try { + return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); + } catch(e) { + return false; + } + } - ViewController.prototype.init = function(){ + ViewController.prototype.init = function(){ - var self = this; + var self = this; - var rendererOptions = { - antialias: true, - preserveDrawingBuffer: true - }; + var rendererOptions = { + antialias: true, + preserveDrawingBuffer: true + }; - if(isWebGlEnabled()) { - this.renderer = new Three.WebGLRenderer(rendererOptions); - } else { - this.renderer = new Three.CanvasRenderer(rendererOptions); - } - - this.renderer.setClearColorHex(0x333333, 1); - this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT); + if(isWebGlEnabled()) { + this.renderer = new Three.WebGLRenderer(rendererOptions); + } else { + this.renderer = new Three.CanvasRenderer(rendererOptions); + } + + this.renderer.setClearColorHex(0x333333, 1); + this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT); - DomController.setCanvas(this.renderer.domElement); + DomController.setCanvas(this.renderer.domElement); - if(Settings.DEBUG_MODE){ - DomController.createDebugCanvas(); - } + if(Settings.DEBUG_MODE){ + DomController.createDebugCanvas(); + } - this.scene = new Three.Scene(); - this.scene.add(this.cameraController.getCamera()); + this.scene = new Three.Scene(); + this.scene.add(this.cameraController.getCamera()); - var ambientLight = new Three.AmbientLight(0xffffff); + var ambientLight = new Three.AmbientLight(0xffffff); this.scene.add(ambientLight); var directionalLight = new Three.DirectionalLight(0xffffff); @@ -62,52 +62,52 @@ define(requires, function(DomController, Three, Settings, CameraController){ this.createMesh(100, 100, 100, 100, 'static/img/100.png', function(mesh){ - self.mesh = mesh; - self.scene.add(mesh); + self.mesh = mesh; + self.scene.add(mesh); }); /* - this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){ - self.scene.add(mesh); + this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){ + self.scene.add(mesh); }); */ //this.animate(this); - } + } - ViewController.prototype.update = function() { + ViewController.prototype.update = function() { - if(this.mesh) { - this.mesh.rotation.z += .01; - this.mesh.position.z += 1; - this.mesh.position.x += .4; - this.mesh.position.y += .4; + if(this.mesh) { + this.mesh.rotation.z += .01; + this.mesh.position.z += 1; + this.mesh.position.x += .4; + this.mesh.position.y += .4; } - this.render(); - } + this.render(); + } - ViewController.prototype.render = function() { + ViewController.prototype.render = function() { - this.renderer.render(this.scene, this.cameraController.getCamera()); - } + this.renderer.render(this.scene, this.cameraController.getCamera()); + } - ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) { - var textureImg = new Image(); + ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) { + var textureImg = new Image(); textureImg.onload = function(){ - var material = new Three.MeshLambertMaterial({ - map: Three.ImageUtils.loadTexture(imgPath) - }); + var material = new Three.MeshLambertMaterial({ + map: Three.ImageUtils.loadTexture(imgPath) + }); - var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material); - mesh.overdraw = true;/* - mesh.position.z = 0; - mesh.position.x = x; - mesh.position.y = y; - */ - callback(mesh); + var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material); + mesh.overdraw = true;/* + mesh.position.z = 0; + mesh.position.x = x; + mesh.position.y = y; + */ + callback(mesh); }; textureImg.src = imgPath; - } + } - return ViewController; + return ViewController; }); \ No newline at end of file diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index b438367..a3eeae8 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -1,50 +1,50 @@ define({ - STAGE_WIDTH: 600, - STAGE_HEIGHT: 400, + STAGE_WIDTH: 600, + STAGE_HEIGHT: 400, - // BOX2D INITIALATORS - RATIO: 35, - BOX2D_WORLD_AABB_SIZE: 3000, - BOX2D_ALLOW_SLEEP: true, - BOX2D_GRAVITY: 16, - BOX2D_VELOCITY_ITERATIONS: 5, - BOX2D_POSITION_ITERATIONS: 5, - BOX2D_TIME_STEP: 1 / 60, + // BOX2D INITIALATORS + RATIO: 35, + BOX2D_WORLD_AABB_SIZE: 3000, + BOX2D_ALLOW_SLEEP: true, + BOX2D_GRAVITY: 16, + BOX2D_VELOCITY_ITERATIONS: 5, + BOX2D_POSITION_ITERATIONS: 5, + BOX2D_TIME_STEP: 1 / 60, - // GRAPHIC PATHS - GRAPHICS_PATH: 'static/img/', - GRAPHICS_SUBPATH_ITEMS: 'items/', - GRAPHICS_SUBPATH_CHARACTERS: 'characters/', + // GRAPHIC PATHS + GRAPHICS_PATH: 'static/img/', + GRAPHICS_SUBPATH_ITEMS: 'items/', + GRAPHICS_SUBPATH_CHARACTERS: 'characters/', - TILE_SIZE: 15, + TILE_SIZE: 15, - // GAME PLAY - WALK_SPEED: 2.5, - RUN_SPEED: 4.0, - FLY_SPEED: 3.2, - JUMP_SPEED: 3.0, - JUMP_UPLIFT: 0.05, + // GAME PLAY + WALK_SPEED: 2.5, + RUN_SPEED: 4.0, + FLY_SPEED: 3.2, + JUMP_SPEED: 3.0, + JUMP_UPLIFT: 0.05, - // restitution: bouncyness, friction: rubbing, density: mass - TILE_FRICTION: 0.99, - TILE_RESTITUTION: 0.1, + // restitution: bouncyness, friction: rubbing, density: mass + TILE_FRICTION: 0.99, + TILE_RESTITUTION: 0.1, - PLAYER_DENSITY: 0.96, - PLAYER_FRICTION: 5, - PLAYER_MOTION_FRICTION: 0.1, - PLAYER_RESTITUTION: 0.0, - PLAYER_LINEAR_DAMPING: .5, + PLAYER_DENSITY: 0.96, + PLAYER_FRICTION: 5, + PLAYER_MOTION_FRICTION: 0.1, + PLAYER_RESTITUTION: 0.0, + PLAYER_LINEAR_DAMPING: .5, - ITEM_DENSITY: 0.9, - ITEM_FRICTION: 0.99, - ITEM_RESTITUTION: 0.02, + ITEM_DENSITY: 0.9, + ITEM_FRICTION: 0.99, + ITEM_RESTITUTION: 0.02, - // BROWSER - CANVAS_DOM_ID: 'canvasContainer', - IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined', + // BROWSER + CANVAS_DOM_ID: 'canvasContainer', + IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined', - DEBUG_MODE: true, + DEBUG_MODE: true, - // NETWORKING - WORLD_UPDATE_BROADCAST_INTERVAL: 15 + // NETWORKING + WORLD_UPDATE_BROADCAST_INTERVAL: 15 }) \ No newline at end of file diff --git a/app/Game/Core/Control/InputController.js b/app/Game/Core/Control/InputController.js old mode 100644 new mode 100755 index db85b7b..2aa7aab --- a/app/Game/Core/Control/InputController.js +++ b/app/Game/Core/Control/InputController.js @@ -31,7 +31,7 @@ define(function(){ InputController.prototype.jumping = function() { if (this._isJumping) { - this.player.jumping(); + this.player.jumping(); } } diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index 85121c3..f39b62d 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -1,36 +1,36 @@ define([ - "Game/Config/Settings", - "Lib/Vendor/Box2D", - "Game/Core/Collision/Detector" + "Game/Config/Settings", + "Lib/Vendor/Box2D", + "Game/Core/Collision/Detector" ], function(Settings, Box2D, CollisionDetector) { - function Engine () { - this.world = new Box2D.Dynamics.b2World( - new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), - Settings.BOX2D_ALLOW_SLEEP - ); - } + function Engine () { + this.world = new Box2D.Dynamics.b2World( + new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), + Settings.BOX2D_ALLOW_SLEEP + ); + } - Engine.prototype.getWorld = function() { - return this.world; - } + Engine.prototype.getWorld = function() { + return this.world; + } - Engine.prototype.setCollisionDetector = function(me) { - - var detector = new CollisionDetector(me); // FIXME: check if core collision detector works - this.world.SetContactListener(detector.getListener()); - } + Engine.prototype.setCollisionDetector = function(me) { + + var detector = new CollisionDetector(me); // FIXME: check if core collision detector works + this.world.SetContactListener(detector.getListener()); + } - Engine.prototype.createBody = function(bodyDef) { - return this.world.CreateBody(bodyDef); - } + Engine.prototype.createBody = function(bodyDef) { + return this.world.CreateBody(bodyDef); + } - Engine.prototype.update = function() { - this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS); - this.world.ClearForces(); - } + Engine.prototype.update = function() { + this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS); + this.world.ClearForces(); + } - return Engine; + return Engine; }); \ No newline at end of file diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js old mode 100644 new mode 100755 index abfd590..914248a --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -1,193 +1,193 @@ define([ - "Game/Core/Physics/Doll", - "Game/Config/Settings" + "Game/Core/Physics/Doll", + "Game/Config/Settings" ], function(Doll, Settings) { - function Player (id, physicsEngine, repository) { - this.physicsEngine = physicsEngine; - this.id = id; - this.repository = repository; - this.standing = false; - this.doll; - this.mc; - this.currentAnimationState = 'stand'; - this.lookDirection = 1; - this.moveDirection = 0; - - this.init(id); - } + function Player (id, physicsEngine, repository) { + this.physicsEngine = physicsEngine; + this.id = id; + this.repository = repository; + this.standing = false; + this.doll; + this.mc; + this.currentAnimationState = 'stand'; + this.lookDirection = 1; + this.moveDirection = 0; + + this.init(id); + } - Player.prototype.init = function(id) { - this.doll = new Doll(this.physicsEngine, id); - //this.mc = EmbedHandler.load(EmbedHandler.CHUCK); - //this.mc.stop(); - //var mclp = new MovieClipLabelParser(); - //mclp.parse(this.mc); - } + Player.prototype.init = function(id) { + this.doll = new Doll(this.physicsEngine, id); + //this.mc = EmbedHandler.load(EmbedHandler.CHUCK); + //this.mc.stop(); + //var mclp = new MovieClipLabelParser(); + //mclp.parse(this.mc); + } - Player.prototype.spawn = function(x, y) { - //this.repository.createModel(this.mc, this.doll.getBody()); - this.doll.spawn(x, y); - } + Player.prototype.spawn = function(x, y) { + //this.repository.createModel(this.mc, this.doll.getBody()); + this.doll.spawn(x, y); + } - Player.prototype.getDoll = function() { - return this.doll; - } + Player.prototype.getDoll = function() { + return this.doll; + } - Player.prototype.getBody = function() { - return this.doll.getBody(); - } + Player.prototype.getBody = function() { + return this.doll.getBody(); + } - Player.prototype.setStanding = function(isStanding) { - var resetStates = ['jump', 'jumploop']; - if (resetStates.indexOf(this.currentAnimationState)>=0 && !this.standing && isStanding) { - this.animate('stand'); - } - this.standing = isStanding; - } + Player.prototype.setStanding = function(isStanding) { + var resetStates = ['jump', 'jumploop']; + if (resetStates.indexOf(this.currentAnimationState)>=0 && !this.standing && isStanding) { + this.animate('stand'); + } + this.standing = isStanding; + } - Player.prototype.isStanding = function() { - return this.standing; - } + Player.prototype.isStanding = function() { + return this.standing; + } - Player.prototype.move = function(direction) { - this.moveDirection = direction; - - switch(true) { - case direction == this.lookDirection && this.isStanding(): - this.doll.move(direction, Settings.RUN_SPEED); - break; + Player.prototype.move = function(direction) { + this.moveDirection = direction; + + switch(true) { + case direction == this.lookDirection && this.isStanding(): + this.doll.move(direction, Settings.RUN_SPEED); + break; - case !this.isStanding(): - this.doll.move(direction, Settings.FLY_SPEED); - break; + case !this.isStanding(): + this.doll.move(direction, Settings.FLY_SPEED); + break; - default: - this.doll.move(direction, Settings.WALK_SPEED); - break; - } + default: + this.doll.move(direction, Settings.WALK_SPEED); + break; + } - if (this.isStanding()) { - this.animate(this.calculateWalkAnimation()); - } - } + if (this.isStanding()) { + this.animate(this.calculateWalkAnimation()); + } + } - Player.prototype.stop = function() { - this.moveDirection = 0; - this.doll.stop(); - if (this.isWalking() || this.standing) { - this.animate('stand'); - } - } + Player.prototype.stop = function() { + this.moveDirection = 0; + this.doll.stop(); + if (this.isWalking() || this.standing) { + this.animate('stand'); + } + } - Player.prototype.jump = function() { - if (this.isStanding()) { - this.doll.jump(); - this.animate('jump'); - this.setStanding(false); - } - } + Player.prototype.jump = function() { + if (this.isStanding()) { + this.doll.jump(); + this.animate('jump'); + this.setStanding(false); + } + } - Player.prototype.jumping = function() { - if (!this.isStanding()) { - this.doll.jumping(); - } - } + Player.prototype.jumping = function() { + if (!this.isStanding()) { + this.doll.jumping(); + } + } - Player.prototype.duck = function() { - if (this.standing && !this.isWalking()) { - this.animate('duck'); - } - } + Player.prototype.duck = function() { + if (this.standing && !this.isWalking()) { + this.animate('duck'); + } + } - Player.prototype.standUp = function() { - if (this.standing) { - this.animate('standup'); - } - } + Player.prototype.standUp = function() { + if (this.standing) { + this.animate('standup'); + } + } - Player.prototype.animate = function(type) { - if (type == this.currentAnimationState) { - return; - } + Player.prototype.animate = function(type) { + if (type == this.currentAnimationState) { + return; + } - //this.mc.gotoAndPlay(type); + //this.mc.gotoAndPlay(type); - this.currentAnimationState = type; - } + this.currentAnimationState = type; + } - Player.prototype.calculateWalkAnimation = function() { - if (this.moveDirection == this.lookDirection) { - return 'run'; - } - return 'walkback'; - } + Player.prototype.calculateWalkAnimation = function() { + if (this.moveDirection == this.lookDirection) { + return 'run'; + } + return 'walkback'; + } - Player.prototype.look = function(x, y) { - /* - var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180); - var lastLookDirection = this.lookDirection; + Player.prototype.look = function(x, y) { + /* + var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180); + var lastLookDirection = this.lookDirection; - if (x < Settings.STAGE_WIDTH / 2) { - this.mc.scaleX = -1; - this.lookDirection = -1; - degree = (-45 + degree / 2); - this.mc.head.rotation = degree; - } else if (x >= Settings.STAGE_WIDTH / 2) { - this.mc.scaleX = 1; - this.lookDirection = 1; - degree = (45 + -degree / 2) - 90; - this.mc.head.rotation = degree; - } + if (x < Settings.STAGE_WIDTH / 2) { + this.mc.scaleX = -1; + this.lookDirection = -1; + degree = (-45 + degree / 2); + this.mc.head.rotation = degree; + } else if (x >= Settings.STAGE_WIDTH / 2) { + this.mc.scaleX = 1; + this.lookDirection = 1; + degree = (45 + -degree / 2) - 90; + this.mc.head.rotation = degree; + } - if (this.lookDirection != lastLookDirection && this.isWalking()) { - this.animate(this.calculateWalkAnimation()); - }*/ - } + if (this.lookDirection != lastLookDirection && this.isWalking()) { + this.animate(this.calculateWalkAnimation()); + }*/ + } - Player.prototype.isWalking = function() { - var states = ['walk', 'walkback', 'run']; + Player.prototype.isWalking = function() { + var states = ['walk', 'walkback', 'run']; - if (states.indexOf(this.currentAnimationState) >= 0) { - return true; - } - return false; - } + if (states.indexOf(this.currentAnimationState) >= 0) { + return true; + } + return false; + } - // called by CollisionDetection - Player.prototype.onFootSensorDetection = function(isColliding) { - if(isColliding) { - if(this.doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) { - return; - } - this.setStanding(true); - } else { - // TODO This needs some more thought to it. - // maybe take a look at collision groups for collision detection, - // to group all tiles together + // called by CollisionDetection + Player.prototype.onFootSensorDetection = function(isColliding) { + if(isColliding) { + if(this.doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) { + return; + } + this.setStanding(true); + } else { + // TODO This needs some more thought to it. + // maybe take a look at collision groups for collision detection, + // to group all tiles together - //this.setStanding(false); - //this.animate('jumploop'); - } - } + //this.setStanding(false); + //this.animate('jumploop'); + } + } - Player.prototype.update = function() { - //this.mc.head.y = this.mc.head_posmask.y; + Player.prototype.update = function() { + //this.mc.head.y = this.mc.head_posmask.y; - if (this.doll.getBody().GetLinearVelocity().x == 0 && this.isWalking()) { - this.stop(); - } + if (this.doll.getBody().GetLinearVelocity().x == 0 && this.isWalking()) { + this.stop(); + } - if (!this.doll.getBody().IsAwake()) { - this.setStanding(true); - } - } + if (!this.doll.getBody().IsAwake()) { + this.setStanding(true); + } + } - Player.prototype.destroy = function() { - this.doll.destroy(); - } + Player.prototype.destroy = function() { + this.doll.destroy(); + } - return Player; + return Player; }); diff --git a/app/Game/Core/Protocol/Helper.js b/app/Game/Core/Protocol/Helper.js old mode 100644 new mode 100755 index b65bc66..e8023e1 --- a/app/Game/Core/Protocol/Helper.js +++ b/app/Game/Core/Protocol/Helper.js @@ -1,29 +1,29 @@ define([ - "Game/Core/Protocol/Parser" + "Game/Core/Protocol/Parser" ], function(Parser) { - var Helper = {} + var Helper = {} - Helper.encodeCommand = function(command, options){ - return Parser.encode(Helper.assemble(command, options)); - } + Helper.encodeCommand = function(command, options){ + return Parser.encode(Helper.assemble(command, options)); + } - Helper.assemble = function(command, options){ - var commands = {}; - commands[command] = options || null; - return commands; - } + Helper.assemble = function(command, options){ + var commands = {}; + commands[command] = options || null; + return commands; + } - Helper.runCommands = function(message, callback){ - var commands = Parser.decode(message); - - for(var command in commands) { - callback(command, commands[command]); - } - } + Helper.runCommands = function(message, callback){ + var commands = Parser.decode(message); + + for(var command in commands) { + callback(command, commands[command]); + } + } - return Helper; - + return Helper; + }); \ No newline at end of file diff --git a/app/Game/Core/Protocol/Parser.js b/app/Game/Core/Protocol/Parser.js old mode 100644 new mode 100755 index f498898..1f6faa7 --- a/app/Game/Core/Protocol/Parser.js +++ b/app/Game/Core/Protocol/Parser.js @@ -3,15 +3,15 @@ define([ function() { - var Parser = {}; + var Parser = {}; - Parser.encode = function(message){ - return JSON.stringify(message); - } + Parser.encode = function(message){ + return JSON.stringify(message); + } - Parser.decode = function(message){ - return JSON.parse(message); - } + Parser.decode = function(message){ + return JSON.parse(message); + } - return Parser; + return Parser; }); \ No newline at end of file diff --git a/app/Game/Core/User.js b/app/Game/Core/User.js index f661e18..3c0e051 100755 --- a/app/Game/Core/User.js +++ b/app/Game/Core/User.js @@ -1,8 +1,8 @@ define(function() { - function User(id) { - this.id = id; - } + function User(id) { + this.id = id; + } - return User; + return User; }); \ No newline at end of file diff --git a/app/Game/Server/Channel.js b/app/Game/Server/Channel.js index f934ab4..e6fc666 100755 --- a/app/Game/Server/Channel.js +++ b/app/Game/Server/Channel.js @@ -1,108 +1,108 @@ -define([ - "Game/Server/GameController", - "Game/Core/NotificationCenter" -], + define([ + "Game/Server/GameController", + "Game/Core/NotificationCenter" + ], -function(GameController, NotificationCenter) { + function(GameController, NotificationCenter) { - function Channel(coordinatorLink) { - var self = this; + function Channel(coordinatorLink) { + var self = this; - this.coordinatorLink = coordinatorLink; - this.coordinatorLink.receive = function(message) { self.onMessage(message) }; - - this.users = {}; + this.coordinatorLink = coordinatorLink; + this.coordinatorLink.receive = function(message) { self.onMessage(message) }; + + 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); - }); -*/ - } + 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.validateName = function(name){ + return true; + } - // Messages look like: - // {channel: {setName: 'foo'}} - // {user: {jupm: null}, id: 12} - Channel.prototype.onMessage = function(message) { + // Messages look like: + // {channel: {setName: 'foo'}} + // {user: {jupm: null}, id: 12} + Channel.prototype.onMessage = function(message) { - for(var recipient in message) { + for(var recipient in message) { - switch(recipient) { + switch(recipient) { - case 'user': - this.forward(this.users[message.id], message.user); - break; - case 'id': // Do nothing, it is needed by the user - break; - case 'channel': - this.forward(this, message.channel); - break; - default: - throw 'unknown recipient'; - break; - } - } - }; + case 'user': + this.forward(this.users[message.id], message.user); + break; + case 'id': // Do nothing, it is needed by the user + break; + case 'channel': + this.forward(this, message.channel); + break; + default: + throw 'unknown recipient'; + break; + } + } + }; - Channel.prototype.forward = function(target, message) { - for(var command in message) { - if(typeof target[command] == 'function'){ - target[command].call(target, message[command]); - } else { - throw 'trying to call undefined function ' + target[command]; - } - } - }; + Channel.prototype.forward = function(target, message) { + for(var command in message) { + if(typeof target[command] == 'function'){ + target[command].call(target, message[command]); + } else { + throw 'trying to call undefined function ' + target[command]; + } + } + }; - Channel.prototype.setName = function(name) { - this.name = name; - console.log(' created channel ' + name); - } - -/* - Channel.prototype.addUser = function(user){ - var userIds = Object.keys(this.users); + Channel.prototype.setName = function(name) { + this.name = name; + console.log(' created channel ' + name); + } + + /* + Channel.prototype.addUser = function(user){ + var userIds = Object.keys(this.users); - this.users[user.id] = user; + this.users[user.id] = user; - user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds}); - this.sendCommandToAllUsersExcept('userJoined', user.id, user); + user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds}); + this.sendCommandToAllUsersExcept('userJoined', user.id, user); - NotificationCenter.trigger('user/joined', user); - } + NotificationCenter.trigger('user/joined', user); + } - Channel.prototype.releaseUser = function(user) { - this.gameController.userIdLeft(user.id); + Channel.prototype.releaseUser = function(user) { + this.gameController.userIdLeft(user.id); - this.sendCommandToAllUsersExcept("userLeft", user.id, user); - delete this.users[user.id]; - } + this.sendCommandToAllUsersExcept("userLeft", user.id, user); + delete this.users[user.id]; + } - Channel.prototype.sendCommandToAllUsers = function(command, options) { - for(var id in this.users) { - this.users[id].sendCommand(command, options); - } - } + Channel.prototype.sendCommandToAllUsers = function(command, options) { + for(var id in this.users) { + this.users[id].sendCommand(command, options); + } + } - Channel.prototype.sendCommandToAllUsersExcept = function(command, options, except_user) { - for(var id in this.users) { - if (id != except_user.id) { - this.users[id].sendCommand(command, options); - } - } - } + Channel.prototype.sendCommandToAllUsersExcept = function(command, options, except_user) { + for(var id in this.users) { + if (id != except_user.id) { + this.users[id].sendCommand(command, options); + } + } + } - Channel.prototype.processGameCommandFromUser = function(command, options, user) { - this.gameController.progressGameCommandFromUser(command, options, user); - } -*/ - return Channel; - -}); \ No newline at end of file + Channel.prototype.processGameCommandFromUser = function(command, options, user) { + this.gameController.progressGameCommandFromUser(command, options, user); + } + */ + return Channel; + + }); \ No newline at end of file diff --git a/app/Game/Server/CoordinatorLink.js b/app/Game/Server/CoordinatorLink.js index f0691e4..d80426d 100755 --- a/app/Game/Server/CoordinatorLink.js +++ b/app/Game/Server/CoordinatorLink.js @@ -3,18 +3,18 @@ define([ function() { - function CoordinatorLink(process) { - this.process = process; - } + function CoordinatorLink(process) { + this.process = process; + } - CoordinatorLink.prototype.send = function(message) { - this.process.send(message); - }; + 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'; - }; + CoordinatorLink.prototype.receive = function(message) { + throw 'This method is abstract and must be overwritten by Channel'; + }; - return CoordinatorLink; + return CoordinatorLink; }); \ No newline at end of file diff --git a/app/Game/Server/GameController.js b/app/Game/Server/GameController.js index 5c35dd9..b175851 100755 --- a/app/Game/Server/GameController.js +++ b/app/Game/Server/GameController.js @@ -1,84 +1,84 @@ define([ - "Game/Core/GameController", - "Game/Core/Physics/Engine", - "Game/Config/Settings", - "Game/Core/Control/InputController", - "Lib/Utilities/RequestAnimFrame", - "Game/Core/NotificationCenter" + "Game/Core/GameController", + "Game/Core/Physics/Engine", + "Game/Config/Settings", + "Game/Core/Control/InputController", + "Lib/Utilities/RequestAnimFrame", + "Game/Core/NotificationCenter" ], function(Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, NotificationCenter) { - function GameController () { - Parent.call(this, new PhysicsEngine()); + function GameController () { + Parent.call(this, new PhysicsEngine()); - this.inputControllers = {}; + 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 = Object.create(Parent.prototype); /* - GameController.prototype.update = function() { + GameController.prototype.update = function() { - requestAnimFrame(this.update.bind(this)); + requestAnimFrame(this.update.bind(this)); - this.physicsEngine.update(); - for(var id in this.players) { - this.players[id].update(); - } - } + this.physicsEngine.update(); + for(var id in this.players) { + this.players[id].update(); + } + } - GameController.prototype.userJoined = function(user) { - Parent.prototype.userJoined.call(this, user); - - var id = user.id; - var player = this.players[id]; - this.inputControllers[id] = new InputController(player); - } + GameController.prototype.userJoined = function(user) { + Parent.prototype.userJoined.call(this, user); + + var id = user.id; + var player = this.players[id]; + this.inputControllers[id] = new InputController(player); + } - GameController.prototype.userLeft = function(user) { - Parent.prototype.userLeft.call(this, user); - delete this.inputControllers[user.id]; - } + GameController.prototype.userLeft = function(user) { + Parent.prototype.userLeft.call(this, user); + delete this.inputControllers[user.id]; + } - GameController.prototype.progressGameCommandFromUser = function(command, options, user) { - var inputController = this.inputControllers[user.id]; - if (typeof inputController[command] == 'function') { - inputController[command](options); - } - } + GameController.prototype.progressGameCommandFromUser = function(command, options, user) { + var inputController = this.inputControllers[user.id]; + if (typeof inputController[command] == 'function') { + inputController[command](options); + } + } - GameController.prototype.updateWorld = function() { - - var update = {}; - var isUpdateNeeded = false; + GameController.prototype.updateWorld = function() { + + var update = {}; + var isUpdateNeeded = false; - var body = this.physicsEngine.world.GetBodyList(); - do { - var userData = body.GetUserData(); + var body = this.physicsEngine.world.GetBodyList(); + do { + var userData = body.GetUserData(); - if(userData && body.IsAwake()){ - update[userData] = { - p: body.GetPosition(), - a: body.GetAngle(), - lv: body.GetLinearVelocity(), - av: body.GetAngularVelocity() - }; - isUpdateNeeded = true; - } - } while (body = body.GetNext()); - - if(isUpdateNeeded) { - //NotificationCenter.trigger("sendCommandToAllUsers", ['gameCommand', {worldUpdate:update}]); - } + if(userData && body.IsAwake()){ + update[userData] = { + p: body.GetPosition(), + a: body.GetAngle(), + lv: body.GetLinearVelocity(), + av: body.GetAngularVelocity() + }; + isUpdateNeeded = true; + } + } while (body = body.GetNext()); + + if(isUpdateNeeded) { + //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); + } */ - return GameController; + return GameController; }); diff --git a/app/Game/Server/User.js b/app/Game/Server/User.js index b920088..d944d9c 100755 --- a/app/Game/Server/User.js +++ b/app/Game/Server/User.js @@ -1,45 +1,45 @@ define([ - "Game/Core/User", - "Game/Core/Protocol/Helper", - "Game/Core/NotificationCenter" + "Game/Core/User", + "Game/Core/Protocol/Helper", + "Game/Core/NotificationCenter" ], function(Parent, ProtocolHelper, NotificationCenter) { - function User(id, coordinator) { - Parent.call(this, id); - this.id = socketLink.id; - this.socketLink = socketLink; - this.coordinator = coordinator; - this.channel = null; - - this.init(socketLink); - } + function User(id, coordinator) { + Parent.call(this, id); + this.id = socketLink.id; + this.socketLink = socketLink; + this.coordinator = coordinator; + this.channel = null; + + this.init(socketLink); + } - User.prototype = Object.create(Parent.prototype); + User.prototype = Object.create(Parent.prototype); - User.prototype.init = function(socketLink){ + User.prototype.init = function(socketLink){ - var self = this; + var self = this; - } + } /* - User.prototype.setChannel = function(channel) { - this.channel = channel; - } + User.prototype.setChannel = function(channel) { + this.channel = channel; + } - User.prototype.sendCommand = function(command, options) { + User.prototype.sendCommand = function(command, options) { - var message = ProtocolHelper.encodeCommand(command, options); - this.socketLink.send(message); - } + var message = ProtocolHelper.encodeCommand(command, options); + this.socketLink.send(message); + } - User.prototype.toString = function() { - return "[User " + this.id + "]"; - }; + User.prototype.toString = function() { + return "[User " + this.id + "]"; + }; */ - return User; - + return User; + }); \ No newline at end of file diff --git a/app/Lib/Utilities/RequestAnimFrame.js b/app/Lib/Utilities/RequestAnimFrame.js index 1b7ce56..e1ce83a 100755 --- a/app/Lib/Utilities/RequestAnimFrame.js +++ b/app/Lib/Utilities/RequestAnimFrame.js @@ -4,7 +4,7 @@ define([ function(Settings) { - var requestAnimFrame = (function(){ + var requestAnimFrame = (function(){ var _setTimeout = function( callback ){ setTimeout(callback, Settings.BOX2D_TIME_STEP * 1000); @@ -25,5 +25,5 @@ function(Settings) { })(); - return requestAnimFrame; + return requestAnimFrame; }); \ No newline at end of file diff --git a/app/Lobby/Coordinator.js b/app/Lobby/Coordinator.js index b2434d4..7549525 100755 --- a/app/Lobby/Coordinator.js +++ b/app/Lobby/Coordinator.js @@ -1,74 +1,74 @@ define([ - "Lobby/User", - "Game/Server/Channel", - "child_process" + "Lobby/User", + "Game/Server/Channel", + "child_process" ], function(User, Channel, childProcess) { - var fork = childProcess.fork; + var fork = childProcess.fork; - function Coordinator() { - this.channels = {}; - this.lobbyUsers = {}; - } + function Coordinator() { + this.channels = {}; + this.lobbyUsers = {}; + } - Coordinator.prototype.createUser = function(socketLink){ - var user = new User(socketLink, this); - this.assignUserToLobby(user); - } + Coordinator.prototype.createUser = function(socketLink){ + var user = new User(socketLink, this); + this.assignUserToLobby(user); + } - Coordinator.prototype.assignUserToLobby = function(user){ - if(user.channelProcess) { - //user.channel.releaseUser(user); -> generate message - } - this.lobbyUsers[user.id] = user; - } + Coordinator.prototype.assignUserToLobby = function(user){ + if(user.channelProcess) { + //user.channel.releaseUser(user); -> generate message + } + this.lobbyUsers[user.id] = user; + } - Coordinator.prototype.assignUserToChannel = function(user, channelName){ + Coordinator.prototype.assignUserToChannel = function(user, channelName){ - if(user.channelProcess) { - //user.channel.releaseUser(user); -> generate message - } + if(user.channelProcess) { + //user.channel.releaseUser(user); -> generate message + } - if(!Channel.validateName(channelName)){ - //TODO send validation error - return false; - } + if(!Channel.validateName(channelName)){ + //TODO send validation error + return false; + } - var channel = this.channels[channelName]; - if(!channel) { + var channel = this.channels[channelName]; + if(!channel) { - try { - channel = fork('channel.js'); - channel.send('CREATE'); + try { + channel = fork('channel.js'); + channel.send('CREATE'); - channel.send({ - channel: { - setName: channelName - } - }); - - } catch (err) { - throw 'Failed to fork channel ' + channelName + '! (' + err + ')'; - } + channel.send({ + channel: { + setName: channelName + } + }); + + } catch (err) { + throw 'Failed to fork channel ' + channelName + '! (' + err + ')'; + } - this.channels[channelName] = channel; - } + this.channels[channelName] = channel; + } - //channel.addUser(user); - //user.setChannel(channel); + //channel.addUser(user); + //user.setChannel(channel); - delete this.lobbyUsers[user.id]; - } + delete this.lobbyUsers[user.id]; + } - Coordinator.prototype.removeUser = function(user){ - delete this.lobbyUsers[user.id]; - if(user.channelProcess) { - //user.channel.releaseUser(user); -> generate message - } - } + Coordinator.prototype.removeUser = function(user){ + delete this.lobbyUsers[user.id]; + if(user.channelProcess) { + //user.channel.releaseUser(user); -> generate message + } + } - return Coordinator; + return Coordinator; }); \ No newline at end of file diff --git a/app/Lobby/User.js b/app/Lobby/User.js index 325842e..d3e5eba 100755 --- a/app/Lobby/User.js +++ b/app/Lobby/User.js @@ -1,66 +1,66 @@ define([ - "Game/Core/User", - "Game/Core/Protocol/Helper" + "Game/Core/User", + "Game/Core/Protocol/Helper" ], function(Parent, ProtocolHelper) { - function User(socketLink, coordinator) { - Parent.call(this, socketLink.id); + function User(socketLink, coordinator) { + Parent.call(this, socketLink.id); - this.coordinator = coordinator; - this.channelProcess = null; + this.coordinator = coordinator; + this.channelProcess = null; - var self = this; + var self = this; - socketLink.on('message', function(message){ - self.onMessage(message); - }); - socketLink.on('disconnect', function(){ - self.onDisconnect(); - }); - } + socketLink.on('message', function(message){ + self.onMessage(message); + }); + socketLink.on('disconnect', function(){ + self.onDisconnect(); + }); + } - User.prototype = Object.create(Parent.prototype); + User.prototype = Object.create(Parent.prototype); - User.prototype.setChannelProcess = function(channelProcess) { - this.channelProcess = channelProcess; - } + User.prototype.setChannelProcess = function(channelProcess) { + this.channelProcess = channelProcess; + } - User.prototype.onMessage = function(message){ - var self = this; - ProtocolHelper.runCommands(message, function(command, options){ - self.processControlCommand(command, options); - }); - } + 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.onDisconnect = function(){ + this.coordinator.removeUser(this); + } - User.prototype.processControlCommand = function(command, options){ - switch(command) { + User.prototype.processControlCommand = function(command, options){ + switch(command) { - case 'join': - this.coordinator.assignUserToChannel(this, options); - break; + case 'join': + this.coordinator.assignUserToChannel(this, options); + break; - case 'leave': - this.coordinator.assignUserToLobby(this); - 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; + case 'gameCommand': + for(var gameCommand in options) { + //NotificationCenter.trigger("processGameCommandFromUser", [gameCommand, options[gameCommand], this]); + //this.channel.processGameCommandFromUser(gameCommand, options[gameCommand], this); + } + break; - default: - break; - } - } + default: + break; + } + } - return User; + return User; }); \ No newline at end of file diff --git a/channel.js b/channel.js index 0c6ac7d..6857222 100755 --- a/channel.js +++ b/channel.js @@ -1,13 +1,13 @@ var requirejs = require('requirejs'); requirejs.config({ - baseUrl: 'app' + baseUrl: 'app' }); var inspector = {}; requirejs(["Bootstrap/Channel"], function(ChannelBootstrap) { - - var channelBootstrap = new ChannelBootstrap(process); - inspector.channelBootstrap = channelBootstrap; + + var channelBootstrap = new ChannelBootstrap(process); + inspector.channelBootstrap = channelBootstrap; }); \ No newline at end of file diff --git a/client.js b/client.js index 1fc4c81..deadab0 100755 --- a/client.js +++ b/client.js @@ -1,22 +1,22 @@ requirejs.config({ - baseUrl: 'app' + baseUrl: 'app' }); var inspector = {}; requirejs(["Bootstrap/Client"], function(Client) { - - var options = { - "reconnect": false, - "reconnection delay": 500, - "max reconnection attempts": 10, + + var options = { + "reconnect": false, + "reconnection delay": 500, + "max reconnection attempts": 10, - "transports": [ - "websocket", - "flashsocket" - ], - }; + "transports": [ + "websocket", + "flashsocket" + ], + }; - var client = new Client(location.href, options); - inspector.client = client; + var client = new Client(location.href, options); + inspector.client = client; }); \ No newline at end of file diff --git a/server.js b/server.js index ca6ac73..5d8a4f9 100755 --- a/server.js +++ b/server.js @@ -3,24 +3,24 @@ var requirejs = require('requirejs'); var inspector = {}; requirejs.config({ - nodeRequire: require, - baseUrl: 'app' + nodeRequire: require, + baseUrl: 'app' }); -var port = process.argv[2] - || process.env.PORT - || process.env.npm_package_config_port; +var port = process.argv[2] + || process.env.PORT + || process.env.npm_package_config_port; var options = { - port: port, - rootDirectory: './', - caching: false, - logLevel: process.argv[3] || 0 + port: port, + rootDirectory: './', + caching: false, + logLevel: process.argv[3] || 0 }; -requirejs(["Bootstrap/Server"], function(Server) { - var server = new Server(options); - inspector.server = server; +requirejs(["Bootstrap/Server"], function (Server) { + var server = new Server(options); + inspector.server = server; }); exports = module.exports = inspector; \ No newline at end of file diff --git a/static/html/index.html b/static/html/index.html index 2da2e5d..bfb5a67 100755 --- a/static/html/index.html +++ b/static/html/index.html @@ -3,24 +3,24 @@ Chuck