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 "collisionManager.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);
80 DPF(0, "ENTITY TYPE NOT SUPPORTED BY addEntity()!!");
82 void manager::remove(Entity* e)
85 Particle* p = dynamic_cast<Particle*>(e);
88 particles_To_Remove.insert(p);
94 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
97 physics_To_Remove.insert(p);
102 DPF(0, "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!");
105 void manager::handleInput()
107 effect::handleInput();
109 void manager::update(float time_step)
111 effect::update(time_step);
113 updateParticles(time_step);
114 updatePhysics(time_step);
118 // update active Particle*s
119 for( setPart::iterator it = active_Particles.begin();
120 it != active_Particles.end();
126 // update active PhysicsEntity*s
127 for( setPhys::iterator it = active_Physics.begin();
128 it != active_Physics.end();
135 /// ***** Private Methods *****
137 void updateParticles(float time_step)
139 // add new Particle*s to Active
140 for( setPart::iterator it = particles_To_Add.begin();
141 it != particles_To_Add.end();
144 active_Particles.insert(*it);
146 particles_To_Add.clear();
148 // remove dead Particle*s from Active
149 for( setPart::iterator it = particles_To_Remove.begin();
150 it != particles_To_Remove.end();
153 active_Particles.erase(*it);
155 particles_To_Remove.clear();
157 // update active Particle*s
158 for( setPart::iterator it = active_Particles.begin();
159 it != active_Particles.end();
162 (*it)->update(time_step);
165 void updatePhysics(float time_step)
167 // add new PhysicsEntity*s to Active
168 for( setPhys::iterator it = physics_To_Add.begin();
169 it != physics_To_Add.end();
172 active_Physics.insert(*it);
174 physics_To_Add.clear();
176 // remove dead PhysicsEntity*s from Active
177 for( setPhys::iterator it = physics_To_Remove.begin();
178 it != physics_To_Remove.end();
181 active_Physics.erase(*it);
183 physics_To_Remove.clear();
185 // apply collision math
186 collision::update(active_Physics);
188 // update active PhysicsEntity*s
189 for( setPhys::iterator it = active_Physics.begin();
190 it != active_Physics.end();
193 (*it)->update(time_step);