From f103ba70ea4095f42852cbfca9e5525737db8efb Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 11:56:24 -0400 Subject: [PATCH] effects are now stored in a set, improved grav well control --- src/config/config.cpp | 10 +++++++++- src/config/config.h | 2 ++ src/effectManager.cpp | 55 +++++++++++++++++++++++++++------------------------ 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 895c1d9..35efe4f 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -48,9 +48,17 @@ bool cfg::endGame() return input::wasReleased(SDLK_ESCAPE); } +bool cfg::mouseWellFollow() +{ + return input::isPressed(SDLK_f); +} bool cfg::mouseWellOn() { - return input::isPressed(SDLK_SPACE); + return input::wasPressed(SDLK_SPACE); +} +bool cfg::mouseWellOff() +{ + return input::wasReleased(SDLK_SPACE); } /// ***** Private Methods ***** diff --git a/src/config/config.h b/src/config/config.h index b13a075..c794f65 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -31,7 +31,9 @@ namespace cfg bool pause(); bool unPause(); + bool mouseWellFollow(); bool mouseWellOn(); + bool mouseWellOff(); } #endif // CONFIG_H diff --git a/src/effectManager.cpp b/src/effectManager.cpp index b77fc1d..c59decc 100644 --- a/src/effectManager.cpp +++ b/src/effectManager.cpp @@ -17,6 +17,8 @@ #include "effectManager.h" +#include + #include "Effects/Effect.h" #include "Effects/Gravity.h" #include "Effects/GravityWell.h" @@ -28,8 +30,8 @@ /// ***** Private Variables ***** -Effect** effects; -int numEffects; +typedef std::set setEffect; +setEffect active_Effects; GravityWell* mouseWell; @@ -37,23 +39,20 @@ GravityWell* mouseWell; void effect::init() { - numEffects = 3; - effects = new Effect*[numEffects](); - mouseWell = new GravityWell(input::mousePosition()); - effects[0] = new Screen(); - effects[1] = new Gravity(); - effects[2] = mouseWell; + active_Effects.insert(new Screen()); + active_Effects.insert(new Gravity()); + active_Effects.insert(mouseWell); } void effect::clean() { - for(int i=0; i < numEffects; i++) + for( setEffect::iterator it = active_Effects.begin(); + it != active_Effects.end(); + it++ ) { - delete effects[i]; + // TODO !!!!!!!!! } - - delete[] effects; } /// ***** Public Methods ***** @@ -64,24 +63,24 @@ void effect::update(float) } void effect::handleInput() { - if(cfg::mouseWellOn()) - { - numEffects = 3; + if(cfg::mouseWellFollow()) mouseWell->setPosition(input::mousePosition()); - } - else - { - numEffects = 2; - } + + if(cfg::mouseWellOn()) + active_Effects.insert(mouseWell); + if(cfg::mouseWellOff()) + active_Effects.erase(mouseWell); } Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step) { Vector2 acc(0,0); - for(int i=0; i < numEffects; i++) + for( setEffect::iterator it = active_Effects.begin(); + it != active_Effects.end(); + it++ ) { - acc += effects[i]->positionDelta(e, time_step); + acc += (*it)->positionDelta(e, time_step); } return acc; @@ -90,9 +89,11 @@ Vector2 effect::velocityDelta(const PhysicsEntity* e, float time_step) { Vector2 acc(0,0); - for(int i=0; i < numEffects; i++) + for( setEffect::iterator it = active_Effects.begin(); + it != active_Effects.end(); + it++ ) { - acc += effects[i]->velocityDelta(e, time_step); + acc += (*it)->velocityDelta(e, time_step); } return acc; @@ -101,9 +102,11 @@ Vector2 effect::forceDelta(const PhysicsEntity* e, float time_step) { Vector2 acc(0,0); - for(int i=0; i < numEffects; i++) + for( setEffect::iterator it = active_Effects.begin(); + it != active_Effects.end(); + it++ ) { - acc += effects[i]->forceDelta(e, time_step); + acc += (*it)->forceDelta(e, time_step); } return acc; -- 2.10.2