From c0685929153c64887da1e459c883527e66e7ca8d Mon Sep 17 00:00:00 2001 From: logsol Date: Sat, 1 Oct 2016 19:09:52 +0200 Subject: [PATCH] Makes world in Engine private And some refactoring. --- app/Game/Core/GameObjects/GameObject.js | 2 +- app/Game/Core/Loader/Level.js | 1 + app/Game/Core/Physics/Engine.js | 23 ++++++++++------------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/Game/Core/GameObjects/GameObject.js b/app/Game/Core/GameObjects/GameObject.js index c0f63e3..22d770d 100755 --- a/app/Game/Core/GameObjects/GameObject.js +++ b/app/Game/Core/GameObjects/GameObject.js @@ -14,7 +14,7 @@ function (Box2D, Exception, Assert, Nc) { var def = this.getBodyDef(); def.userData = this; - this.body = physicsEngine.getWorld().CreateBody(def); + this.body = physicsEngine.createBody(def); this.ncTokens = (this.ncTokens || []).concat([ Nc.on(Nc.ns.client.game.events.destroy, this.destroy, this) diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index bd49a20..86fd92b 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -25,6 +25,7 @@ define([ Level.prototype.load = function (uid) { var self = this; + // FIXME: check if theres a security hazard here (user injected path) var path = Settings.MAPS_PATH + uid + ".json"; this.loadLevelDataFromPath(path, function (levelData) { self.setup(levelData); diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index c47efc3..245b8f6 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -15,7 +15,6 @@ function (Settings, Box2D, CollisionDetector, Nc) { Settings.BOX2D_ALLOW_SLEEP ); this.world.SetWarmStarting(true); - this.ground = null; this.lastStep = Date.now(); this.worldQueue = []; @@ -24,24 +23,22 @@ function (Settings, Box2D, CollisionDetector, Nc) { ]; } - Engine.prototype.getWorld = function () { - return this.world; - } - - Engine.prototype.getGround = function () { - return this.ground; - } - Engine.prototype.setCollisionDetector = function () { var detector = new CollisionDetector(); this.world.SetContactListener(detector.getListener()); } + Engine.prototype.getWorldForRubeLoader = function() { + return this.world; + }; + Engine.prototype.createBody = function (bodyDef) { - var body = this.world.CreateBody(bodyDef); - if(!this.ground) this.ground = body; - return body; + return this.world.CreateBody(bodyDef); + } + + Engine.prototype.destroyBody = function (body) { + return this.world.DestroyBody(body); } Engine.prototype.addToWorldQueue = function(callback) { @@ -65,8 +62,8 @@ function (Settings, Box2D, CollisionDetector, Nc) { } Engine.prototype.destroy = function() { - delete this.world; Nc.offAll(this.ncTokens); + delete this.world; };