moved client stuff from Engine to Client/Physics/Engine

This commit is contained in:
Jeena Paradies 2012-07-21 23:03:37 +02:00
parent fc22ac5643
commit 806a6e1d47
2 changed files with 18 additions and 45 deletions

View file

@ -1,16 +1,16 @@
define(["Chuck/Settings", "Client/Dom", "Vendor/Box2D", "Chuck/Collision/Detector"], function(Settings, Dom, Box2D, CollisionDetector){
define([
"Game/Config/Settings",
"Lib/Vendor/Box2D",
"Game/Core/Collision/Detector"
],
function(Settings, Box2D, CollisionDetector) {
function Engine () {
this.world;
this.init();
}
Engine.prototype.init = function() {
this.world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), Settings.BOX2D_ALLOW_SLEEP);
if(Settings.IS_BROWSER_ENVIRONMENT && Settings.DEBUG_MODE) {
this.setupDebugDraw();
}
this.world = new Box2D.Dynamics.b2World(
new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY),
Settings.BOX2D_ALLOW_SLEEP
);
}
Engine.prototype.getWorld = function() {
@ -19,36 +19,10 @@ define(["Chuck/Settings", "Client/Dom", "Vendor/Box2D", "Chuck/Collision/Detecto
Engine.prototype.setCollisionDetector = function(me) {
var detector = new CollisionDetector(me);
var detector = new CollisionDetector(me); // FIXME: check if core collision detector works
this.world.SetContactListener(detector.getListener());
}
Engine.prototype.setupDebugDraw = function() {
//var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
var debugSprite = Dom.getDebugCanvas().getContext("2d");
// set debug draw
var debugDraw = new Box2D.Dynamics.b2DebugDraw();
debugDraw.SetSprite(debugSprite);
debugDraw.SetDrawScale(Settings.RATIO);
debugDraw.SetFillAlpha(0.5);
debugDraw.SetLineThickness(1.0);
debugDraw.SetFlags(null
| Box2D.Dynamics.b2DebugDraw.e_shapeBit
| Box2D.Dynamics.b2DebugDraw.e_jointBit
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
);
this.world.SetDebugDraw(debugDraw);
this.world.SetWarmStarting(true);
}
Engine.prototype.createBody = function(bodyDef) {
return this.world.CreateBody(bodyDef);
}
@ -56,7 +30,6 @@ define(["Chuck/Settings", "Client/Dom", "Vendor/Box2D", "Chuck/Collision/Detecto
Engine.prototype.update = function() {
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
this.world.ClearForces();
this.world.DrawDebugData();
}
return Engine;