| 1 | /* |
| 2 | * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include "effectManager.h" |
| 19 | |
| 20 | #include <set> |
| 21 | |
| 22 | #include "Effects/Effect.h" |
| 23 | #include "Effects/Gravity.h" |
| 24 | #include "Effects/GravityWell.h" |
| 25 | #include "Effects/Screen.h" |
| 26 | |
| 27 | #include "Vector2.h" |
| 28 | #include "input/inputManager.h" |
| 29 | #include "config/config.h" |
| 30 | |
| 31 | /// ***** Private Variables ***** |
| 32 | |
| 33 | typedef std::set<Effect*> setEffect; |
| 34 | setEffect active_Effects; |
| 35 | |
| 36 | GravityWell* mouseWell; |
| 37 | |
| 38 | /// ***** Initializers/Cleaners ***** |
| 39 | |
| 40 | void effect::init() |
| 41 | { |
| 42 | mouseWell = new GravityWell(Vector2(0,0)); |
| 43 | |
| 44 | active_Effects.insert(new Screen()); |
| 45 | active_Effects.insert(new Gravity()); |
| 46 | } |
| 47 | void effect::clean() |
| 48 | { |
| 49 | for( setEffect::iterator it = active_Effects.begin(); |
| 50 | it != active_Effects.end(); |
| 51 | it++ ) |
| 52 | { |
| 53 | // TODO !!!!!!!!! |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /// ***** Public Methods ***** |
| 58 | |
| 59 | void effect::update(float) |
| 60 | { |
| 61 | |
| 62 | } |
| 63 | void effect::handleInput() |
| 64 | { |
| 65 | if(cfg::mouseWellFollow()) |
| 66 | mouseWell->setPosition(input::mousePosition()); |
| 67 | |
| 68 | if(cfg::mouseWellOn()) |
| 69 | active_Effects.insert(mouseWell); |
| 70 | if(cfg::mouseWellOff()) |
| 71 | active_Effects.erase(mouseWell); |
| 72 | } |
| 73 | |
| 74 | Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step) |
| 75 | { |
| 76 | Vector2 acc(0,0); |
| 77 | |
| 78 | for( setEffect::iterator it = active_Effects.begin(); |
| 79 | it != active_Effects.end(); |
| 80 | it++ ) |
| 81 | { |
| 82 | acc += (*it)->positionDelta(e, time_step); |
| 83 | } |
| 84 | |
| 85 | return acc; |
| 86 | } |
| 87 | Vector2 effect::velocityDelta(const PhysicsEntity* e, float time_step) |
| 88 | { |
| 89 | Vector2 acc(0,0); |
| 90 | |
| 91 | for( setEffect::iterator it = active_Effects.begin(); |
| 92 | it != active_Effects.end(); |
| 93 | it++ ) |
| 94 | { |
| 95 | acc += (*it)->velocityDelta(e, time_step); |
| 96 | } |
| 97 | |
| 98 | return acc; |
| 99 | } |
| 100 | Vector2 effect::forceDelta(const PhysicsEntity* e, float time_step) |
| 101 | { |
| 102 | Vector2 acc(0,0); |
| 103 | |
| 104 | for( setEffect::iterator it = active_Effects.begin(); |
| 105 | it != active_Effects.end(); |
| 106 | it++ ) |
| 107 | { |
| 108 | acc += (*it)->forceDelta(e, time_step); |
| 109 | } |
| 110 | |
| 111 | return acc; |
| 112 | } |