From 806a6e1d47e4a2ff48f8d77303bd7674a5ddec2f Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Sat, 21 Jul 2012 23:03:37 +0200 Subject: [PATCH 1/3] moved client stuff from Engine to Client/Physics/Engine --- app/Game/Core/Physics/Doll.js | 12 ++++---- app/Game/Core/Physics/Engine.js | 51 ++++++++------------------------- 2 files changed, 18 insertions(+), 45 deletions(-) diff --git a/app/Game/Core/Physics/Doll.js b/app/Game/Core/Physics/Doll.js index 06a4b97..56f1ef0 100644 --- a/app/Game/Core/Physics/Doll.js +++ b/app/Game/Core/Physics/Doll.js @@ -1,4 +1,4 @@ -define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function(Box2D, Settings, Detector) { +define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function(Box2D, Settings, CollisionDetector) { function Doll (physicsEngine, id){ this.id = id; @@ -18,7 +18,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto bodyDef.fixedRotation = true; bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; - bodyDef.userData = Detector.IDENTIFIER.PLAYER + '-' + this.id; + bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.id; this.body = world.CreateBody(bodyDef); @@ -32,14 +32,14 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO)); fixtureDef.shape = headShape; fixtureDef.isSensor = false; - fixtureDef.userData = Detector.IDENTIFIER.PLAYER_HEAD; + fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_HEAD; this.body.CreateFixture(fixtureDef); var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape(); bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -21 / Settings.RATIO)); fixtureDef.shape = bodyShape; fixtureDef.isSensor = false; - fixtureDef.userData = Detector.IDENTIFIER.PLAYER_CHEST; + fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_CHEST; this.body.CreateFixture(fixtureDef); var legsShape = new Box2D.Collision.Shapes.b2CircleShape(); @@ -48,7 +48,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto fixtureDef.shape = legsShape; fixtureDef.friction = Settings.PLAYER_FRICTION; fixtureDef.isSensor = false; - fixtureDef.userData = Detector.IDENTIFIER.PLAYER_LEGS; + fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_LEGS; this.legs = this.body.CreateFixture(fixtureDef); @@ -57,7 +57,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO)); fixtureDef.shape = feetShape; fixtureDef.isSensor = true; - fixtureDef.userData = Detector.IDENTIFIER.FOOTSENSOR; + fixtureDef.userData = CollisionDetector.IDENTIFIER.FOOTSENSOR; this.body.CreateFixture(fixtureDef); this.body.SetActive(false); diff --git a/app/Game/Core/Physics/Engine.js b/app/Game/Core/Physics/Engine.js index 47605d1..f5323eb 100755 --- a/app/Game/Core/Physics/Engine.js +++ b/app/Game/Core/Physics/Engine.js @@ -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; From b4c59ae7c6ca94c4e27776461f43a32e12a832e7 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Sat, 21 Jul 2012 23:11:01 +0200 Subject: [PATCH 2/3] changed paths --- app/Game/Core/Protocol/Helper.js | 6 +++++- app/Game/Core/Protocol/Parser.js | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Game/Core/Protocol/Helper.js b/app/Game/Core/Protocol/Helper.js index f25aa91..b65bc66 100644 --- a/app/Game/Core/Protocol/Helper.js +++ b/app/Game/Core/Protocol/Helper.js @@ -1,4 +1,8 @@ -define(["Protocol/Parser"], function(Parser) { +define([ + "Game/Core/Protocol/Parser" +], + +function(Parser) { var Helper = {} diff --git a/app/Game/Core/Protocol/Parser.js b/app/Game/Core/Protocol/Parser.js index fbc0426..f498898 100644 --- a/app/Game/Core/Protocol/Parser.js +++ b/app/Game/Core/Protocol/Parser.js @@ -1,4 +1,7 @@ -define(function() { +define([ +], + +function() { var Parser = {}; From 22ae392aced12941ac2f75612045ae7ec3a0bbf9 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Sat, 21 Jul 2012 23:53:33 +0200 Subject: [PATCH 3/3] moved detector to core --- app/Game/Client/Collision/Detector.js | 24 ------------------ app/Game/Core/Collision/Detector.js | 35 +++++++++++++++++++++++++-- app/Game/Core/Player.js | 7 +++++- app/Game/Server/Collision/Detector.js | 19 +++++++++++++++ 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/app/Game/Client/Collision/Detector.js b/app/Game/Client/Collision/Detector.js index a2a2b0c..dbf3528 100755 --- a/app/Game/Client/Collision/Detector.js +++ b/app/Game/Client/Collision/Detector.js @@ -8,20 +8,10 @@ function(Box2D, Parent) { function Detector(me) { Parent.call(this); this.me = me; - - this.listener = new Box2D.Dynamics.b2ContactListener(); - this.listener.chuckDetector = this; - this.listener.BeginContact = this.BeginContact; - this.listener.PostSolve = this.PostSolve; - this.listener.EndContact = this.EndContact; } Detector.prototype = Object.create(Parent); - Detector.prototype.getListener = function() { - return this.listener; - } - Detector.prototype.handleStand = function(point, isColliding) { if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR || point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR) { @@ -30,19 +20,5 @@ function(Box2D, Parent) { } } - /** Extension **/ - - Detector.prototype.BeginContact = function(point) { - this.chuckDetector.handleStand(point, true); - } - - Detector.prototype.PostSolve = function(point, impulse) { - this.chuckDetector.handleStand(point, true); - } - - Detector.prototype.EndContact = function(point) { - this.chuckDetector.handleStand(point, false); - } - return Detector; }); \ No newline at end of file diff --git a/app/Game/Core/Collision/Detector.js b/app/Game/Core/Collision/Detector.js index b4e7edc..71cd746 100644 --- a/app/Game/Core/Collision/Detector.js +++ b/app/Game/Core/Collision/Detector.js @@ -1,6 +1,16 @@ -define(function() { +define([ + "Lib/Vendor/Box2D", + "Game/Core/Collision/Detector" +], + +function(Box2D, Parent) { function Detector() { + this.listener = new Box2D.Dynamics.b2ContactListener(); + this.listener.chuckDetector = this; + this.listener.BeginContact = this.BeginContact; + this.listener.PostSolve = this.PostSolve; + this.listener.EndContact = this.EndContact; } Detector.IDENTIFIER = { @@ -12,6 +22,27 @@ define(function() { PLAYER_FOOT_SENSOR: 'footsensor' } - return Detector; + Detector.prototype.getListener = function() { + return this.listener; + } + Detector.prototype.handleStand = function(point, isColliding) { + throw "Overwrite this function"; + } + + /** Extension **/ + + Detector.prototype.BeginContact = function(point) { + this.chuckDetector.handleStand(point, true); + } + + Detector.prototype.PostSolve = function(point, impulse) { + this.chuckDetector.handleStand(point, true); + } + + Detector.prototype.EndContact = function(point) { + this.chuckDetector.handleStand(point, false); + } + + return Detector; }); \ No newline at end of file diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index 4d54cf3..5491d4c 100644 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -1,4 +1,9 @@ -define(["Chuck/Physics/Doll", "Chuck/Settings"], function(Doll, Settings){ +define([ + "Game/Core/Physics/Doll", + "Game/Config/Settings" +], + +function(Doll, Settings) { function Player (physicsEngine, id, repository) { this.physicsEngine = physicsEngine; diff --git a/app/Game/Server/Collision/Detector.js b/app/Game/Server/Collision/Detector.js index e69de29..46b63ba 100644 --- a/app/Game/Server/Collision/Detector.js +++ b/app/Game/Server/Collision/Detector.js @@ -0,0 +1,19 @@ +define([ + "Lib/Vendor/Box2D", + "Game/Core/Collision/Detector" +], + +function(Box2D, Parent) { + + function Detector() { + Parent.call(this); + } + + Detector.prototype = Object.create(Parent); + + Detector.prototype.handleStand = function(point, isColliding) { + throw "Implement this function"; + } + + return Detector; +}); \ No newline at end of file