1 #include "entityManager.h"
7 #include "Entities/Entity.h"
8 #include "Entities/Particle.h"
9 #include "Entities/PhysicsEntity.h"
11 /// ***** Private Method Headers *****
13 void updateParticles(float);
14 void updatePhysics(float);
16 /// ***** Private Variables *****
18 typedef std::set<Particle*> setPart;
19 setPart particles_To_Add;
20 setPart active_Particles;
21 setPart particles_To_Remove;
23 typedef std::set<PhysicsEntity*> setPhys;
24 setPhys physics_To_Add;
25 setPhys active_Physics;
26 setPhys physics_To_Remove;
28 /// ***** Initializers/Cleaners *****
39 /// ***** Public Methods *****
41 void manager::add(Entity* e)
44 Particle* p = dynamic_cast<Particle*>(e);
47 particles_To_Add.insert(p);
53 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
56 physics_To_Add.insert(p);
61 std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
62 std::cerr << std::endl;
64 void manager::remove(Entity* e)
67 Particle* p = dynamic_cast<Particle*>(e);
70 particles_To_Remove.insert(p);
76 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
79 physics_To_Remove.insert(p);
84 std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
85 std::cerr << std::endl;
88 void manager::handleInput()
92 void manager::update(float time_step)
94 updateParticles(time_step);
95 updatePhysics(time_step);
99 // update active Particle*s
100 for( setPart::iterator it = active_Particles.begin();
101 it != active_Particles.end();
107 // update active PhysicsEntity*s
108 for( setPhys::iterator it = active_Physics.begin();
109 it != active_Physics.end();
116 /// ***** Private Methods *****
118 void updateParticles(float time_step)
120 // add new Particle*s to Active
121 for( setPart::iterator it = particles_To_Add.begin();
122 it != particles_To_Add.end();
125 active_Particles.insert(*it);
127 particles_To_Add.clear();
129 // remove dead Particle*s from Active
130 for( setPart::iterator it = particles_To_Remove.begin();
131 it != particles_To_Remove.end();
134 active_Particles.erase(*it);
136 particles_To_Remove.clear();
138 // update active Particle*s
139 for( setPart::iterator it = active_Particles.begin();
140 it != active_Particles.end();
143 (*it)->update(time_step);
146 void updatePhysics(float time_step)
148 // add new PhysicsEntity*s to Active
149 for( setPhys::iterator it = physics_To_Add.begin();
150 it != physics_To_Add.end();
153 active_Physics.insert(*it);
155 physics_To_Add.clear();
157 // remove dead PhysicsEntity*s from Active
158 for( setPhys::iterator it = physics_To_Remove.begin();
159 it != physics_To_Remove.end();
162 active_Physics.erase(*it);
164 physics_To_Remove.clear();
166 // update active PhysicsEntity*s
167 for( setPhys::iterator it = active_Physics.begin();
168 it != active_Physics.end();
171 (*it)->update(time_step);