1 #include "entityManager.h"
7 #include "Entities/Entity.h"
8 #include "Entities/Particle.h"
9 #include "Entities/PhysicsEntity.h"
11 /// ***** Private Method Headers *****
12 void updateParticles(float);
13 void updatePhysics(float);
15 /// ***** Private Variables *****
16 typedef std::set<Particle*> setPart;
17 setPart particles_To_Add;
18 setPart active_Particles;
19 setPart particles_To_Remove;
22 typedef std::set<PhysicsEntity*> setPhys;
23 setPhys physics_To_Add;
24 setPhys active_Physics;
25 setPhys physics_To_Remove;
28 /// ***** Public Methods *****
39 void manager::add(Entity* e)
42 Particle* p = dynamic_cast<Particle*>(e);
45 particles_To_Add.insert(p);
51 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
54 physics_To_Add.insert(p);
59 std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
60 std::cerr << std::endl;
62 void manager::remove(Entity* e)
65 Particle* p = dynamic_cast<Particle*>(e);
68 particles_To_Remove.insert(p);
74 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
77 physics_To_Remove.insert(p);
82 std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
83 std::cerr << std::endl;
88 clearParticles = true;
92 void manager::handleInput()
96 void manager::update(float time_step)
98 updateParticles(time_step);
99 updatePhysics(time_step);
103 // update active Particle*s
104 for( setPart::iterator it = active_Particles.begin();
105 it != active_Particles.end();
111 // update active PhysicsEntity*s
112 for( setPhys::iterator it = active_Physics.begin();
113 it != active_Physics.end();
121 /// ***** Private Methods *****
122 void updateParticles(float time_step)
124 // add new Particle*s to Active
125 for( setPart::iterator it = particles_To_Add.begin();
126 it != particles_To_Add.end();
129 active_Particles.insert(*it);
131 particles_To_Add.clear();
133 // remove dead Particle*s from Active
134 for( setPart::iterator it = particles_To_Remove.begin();
135 it != particles_To_Remove.end();
138 active_Particles.erase(*it);
140 particles_To_Remove.clear();
142 // update active Particle*s
143 for( setPart::iterator it = active_Particles.begin();
144 it != active_Particles.end();
147 (*it)->update(time_step);
150 void updatePhysics(float time_step)
152 // add new PhysicsEntity*s to Active
153 for( setPhys::iterator it = physics_To_Add.begin();
154 it != physics_To_Add.end();
157 active_Physics.insert(*it);
159 physics_To_Add.clear();
161 // remove dead PhysicsEntity*s from Active
162 for( setPhys::iterator it = physics_To_Remove.begin();
163 it != physics_To_Remove.end();
166 active_Physics.erase(*it);
168 physics_To_Remove.clear();
170 // update active PhysicsEntity*s
171 for( setPhys::iterator it = active_Physics.begin();
172 it != active_Physics.end();
175 (*it)->update(time_step);