Makes world in Engine private

And some refactoring.
This commit is contained in:
logsol 2016-10-01 19:09:52 +02:00
parent 8641a2dc0b
commit c068592915
3 changed files with 12 additions and 14 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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;
};