From: Patrik Gornicz Date: Sat, 2 Aug 2008 00:05:38 +0000 (-0400) Subject: gravity working through manager X-Git-Tag: physics-premerge~177 X-Git-Url: http://gitweb.pgornicz.com/?a=commitdiff_plain;h=33b8c69b7b2e8d3f31124130a503ec2179c4969c;p=libbear.git gravity working through manager --- diff --git a/src/effectManager.cpp b/src/effectManager.cpp index ab13b25..b661f51 100644 --- a/src/effectManager.cpp +++ b/src/effectManager.cpp @@ -1,18 +1,61 @@ #include "effectManager.h" +#include "Effects/Effect.h" #include "Effects/Gravity.h" -Gravity* g = new Gravity(); +/// ***** Private Variables ***** +Effect** effects; +int numEffects; + +/// ***** Public Methods ***** + +void effect::init() +{ + numEffects = 1; + effects = new Effect*[numEffects](); + + effects[0] = new Gravity(); +} +void effect::clean() +{ + for(int i=0; i < numEffects; i++) + { + delete effects[i]; + } + + delete effects; +} Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step) { - return g->positionDelta(e, time_step); + Vector2 acc(0,0); + + for(int i=0; i < numEffects; i++) + { + acc += effects[i]->positionDelta(e, time_step); + } + + return acc; } Vector2 effect::velocityDelta(const PhysicsEntity* e, float time_step) { - return g->velocityDelta(e, time_step); + Vector2 acc(0,0); + + for(int i=0; i < numEffects; i++) + { + acc += effects[i]->velocityDelta(e, time_step); + } + + return acc; } Vector2 effect::forceDelta(const PhysicsEntity* e, float time_step) { - return g->forceDelta(e, time_step); + Vector2 acc(0,0); + + for(int i=0; i < numEffects; i++) + { + acc += effects[i]->forceDelta(e, time_step); + } + + return acc; } diff --git a/src/effectManager.h b/src/effectManager.h index e8ba499..0157e24 100644 --- a/src/effectManager.h +++ b/src/effectManager.h @@ -7,6 +7,9 @@ /// ***** Header Methods ***** namespace effect { + void init(); + void clean(); + Vector2 positionDelta(const PhysicsEntity*, float); Vector2 velocityDelta(const PhysicsEntity*, float); Vector2 forceDelta(const PhysicsEntity*, float); diff --git a/src/entityManager.cpp b/src/entityManager.cpp index f707061..850f70f 100644 --- a/src/entityManager.cpp +++ b/src/entityManager.cpp @@ -1,10 +1,9 @@ -#include - -#include - #include "entityManager.h" #include "debug.h" +#include +#include + #include "Entities/Entity.h" #include "Entities/Particle.h" #include "Entities/PhysicsEntity.h" diff --git a/src/game.cpp b/src/game.cpp index ebf2ba7..1aabda2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5,6 +5,7 @@ using std::vector; #include "entityCreator.h" +#include "effectManager.h" #include "GameStates/GameState.h" #include "GameStates/Running.h" @@ -35,6 +36,8 @@ void gameInit() active_States.push_back(running); + effect::init(); + #ifdef DEBUGGING cout << "World Created" << endl; #endif @@ -42,6 +45,8 @@ void gameInit() void gameClean() { + effect::clean(); + creator::clean(); delete creating_Polygon; diff --git a/src/ticks.cpp b/src/ticks.cpp index f3938d4..6bc200c 100644 --- a/src/ticks.cpp +++ b/src/ticks.cpp @@ -1,6 +1,7 @@ -#include #include "ticks.h" +#include + /* this file is specific to a UNIX system */ /// ***** Public Methods *****