2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
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.
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.
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/>.
18 #include "entityManager.h"
23 #include "Entities/Entity.h"
24 #include "Entities/Particle.h"
25 #include "Entities/PhysicsEntity.h"
27 #include "collisionHandler.h"
28 #include "effectManager.h"
30 /// ***** Private Method Headers *****
32 void updateParticles(float);
33 void updatePhysics(float);
35 /// ***** Private Variables *****
37 typedef std::set<Particle*> setPart;
38 setPart particles_To_Add;
39 setPart active_Particles;
40 setPart particles_To_Remove;
42 typedef std::set<PhysicsEntity*> setPhys;
43 setPhys physics_To_Add;
44 setPhys active_Physics;
45 setPhys physics_To_Remove;
47 /// ***** Initializers/Cleaners *****
58 /// ***** Public Methods *****
60 void manager::add(Entity* e)
63 Particle* p = dynamic_cast<Particle*>(e);
66 particles_To_Add.insert(p);
72 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
75 physics_To_Add.insert(p);
81 cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!" << endl;
84 void manager::remove(Entity* e)
87 Particle* p = dynamic_cast<Particle*>(e);
90 particles_To_Remove.insert(p);
96 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
99 physics_To_Remove.insert(p);
105 cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!" << endl;
109 void manager::handleInput()
111 effect::handleInput();
113 void manager::update(float time_step)
115 effect::update(time_step);
117 updateParticles(time_step);
118 updatePhysics(time_step);
122 // update active Particle*s
123 for( setPart::iterator it = active_Particles.begin();
124 it != active_Particles.end();
130 // update active PhysicsEntity*s
131 for( setPhys::iterator it = active_Physics.begin();
132 it != active_Physics.end();
139 /// ***** Private Methods *****
141 void updateParticles(float time_step)
143 // add new Particle*s to Active
144 for( setPart::iterator it = particles_To_Add.begin();
145 it != particles_To_Add.end();
148 active_Particles.insert(*it);
150 particles_To_Add.clear();
152 // remove dead Particle*s from Active
153 for( setPart::iterator it = particles_To_Remove.begin();
154 it != particles_To_Remove.end();
157 active_Particles.erase(*it);
159 particles_To_Remove.clear();
161 // update active Particle*s
162 for( setPart::iterator it = active_Particles.begin();
163 it != active_Particles.end();
166 (*it)->update(time_step);
169 void updatePhysics(float time_step)
171 // add new PhysicsEntity*s to Active
172 for( setPhys::iterator it = physics_To_Add.begin();
173 it != physics_To_Add.end();
176 active_Physics.insert(*it);
178 physics_To_Add.clear();
180 // remove dead PhysicsEntity*s from Active
181 for( setPhys::iterator it = physics_To_Remove.begin();
182 it != physics_To_Remove.end();
185 active_Physics.erase(*it);
187 physics_To_Remove.clear();
189 // apply collision math
190 collision::update(active_Physics, time_step);
192 // update active PhysicsEntity*s
193 for( setPhys::iterator it = active_Physics.begin();
194 it != active_Physics.end();
197 (*it)->update(time_step);