1 #include "entityManager.h"
2 #include "Entities/Entity.h"
3 #include "Entities/Particle.h"
4 #include "Entities/PhysicsEntity.h"
11 /// ***** Private Method Headers *****
12 void updateParticles(float);
13 void updatePhysics(float);
15 /// ***** Private Variables *****
16 typedef set<Particle*> setPart;
17 setPart particles_To_Add;
18 setPart active_Particles;
19 setPart particles_To_Remove;
22 typedef set<PhysicsEntity*> setPhys;
23 setPhys physics_To_Add;
24 setPhys active_Physics;
25 setPhys physics_To_Remove;
28 /// ***** Public Methods *****
30 void entityManager::init()
33 void entityManager::clean()
37 void entityManager::add(Entity* e)
40 Particle* p = dynamic_cast<Particle*>(e);
43 particles_To_Add.insert(p);
49 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
52 physics_To_Add.insert(p);
57 std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
58 std::cerr << std::endl;
60 void entityManager::remove(Entity* e)
63 Particle* p = dynamic_cast<Particle*>(e);
66 particles_To_Remove.insert(p);
72 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
75 physics_To_Remove.insert(p);
80 std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
81 std::cerr << std::endl;
84 void entityManager::clear()
86 clearParticles = true;
90 void entityManager::handleInput()
94 void entityManager::update(float time_step)
96 updateParticles(time_step);
97 updatePhysics(time_step);
99 void entityManager::draw()
101 // update active Particle*s
102 for( setPart::iterator it = active_Particles.begin();
103 it != active_Particles.end();
109 // update active PhysicsEntity*s
110 for( setPhys::iterator it = active_Physics.begin();
111 it != active_Physics.end();
118 /// ***** Private Methods *****
119 void updateParticles(float time_step)
121 // add new Particle*s to Active
122 for( setPart::iterator it = particles_To_Add.begin();
123 it != particles_To_Add.end();
126 active_Particles.insert(*it);
128 particles_To_Add.clear();
130 // remove dead Particle*s from Active
131 for( setPart::iterator it = particles_To_Remove.begin();
132 it != particles_To_Remove.end();
135 active_Particles.erase(*it);
137 particles_To_Remove.clear();
139 // update active Particle*s
140 for( setPart::iterator it = active_Particles.begin();
141 it != active_Particles.end();
144 (*it)->update(time_step);
147 void updatePhysics(float time_step)
149 // add new PhysicsEntity*s to Active
150 for( setPhys::iterator it = physics_To_Add.begin();
151 it != physics_To_Add.end();
154 active_Physics.insert(*it);
156 physics_To_Add.clear();
158 // remove dead PhysicsEntity*s from Active
159 for( setPhys::iterator it = physics_To_Remove.begin();
160 it != physics_To_Remove.end();
163 active_Physics.erase(*it);
165 physics_To_Remove.clear();
167 // update active PhysicsEntity*s
168 for( setPhys::iterator it = active_Physics.begin();
169 it != active_Physics.end();
172 (*it)->update(time_step);