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"
24 #include "Entities/Entity.h"
25 #include "Entities/Particle.h"
26 #include "Entities/PhysicsEntity.h"
28 /// ***** Private Method Headers *****
30 void updateParticles(float);
31 void updatePhysics(float);
33 /// ***** Private Variables *****
35 typedef std::set<Particle*> setPart;
36 setPart particles_To_Add;
37 setPart active_Particles;
38 setPart particles_To_Remove;
40 typedef std::set<PhysicsEntity*> setPhys;
41 setPhys physics_To_Add;
42 setPhys active_Physics;
43 setPhys physics_To_Remove;
45 /// ***** Initializers/Cleaners *****
56 /// ***** Public Methods *****
58 void manager::add(Entity* e)
61 Particle* p = dynamic_cast<Particle*>(e);
64 particles_To_Add.insert(p);
70 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
73 physics_To_Add.insert(p);
78 std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
79 std::cerr << std::endl;
81 void manager::remove(Entity* e)
84 Particle* p = dynamic_cast<Particle*>(e);
87 particles_To_Remove.insert(p);
93 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
96 physics_To_Remove.insert(p);
101 std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
102 std::cerr << std::endl;
105 void manager::handleInput()
109 void manager::update(float time_step)
111 updateParticles(time_step);
112 updatePhysics(time_step);
116 // update active Particle*s
117 for( setPart::iterator it = active_Particles.begin();
118 it != active_Particles.end();
124 // update active PhysicsEntity*s
125 for( setPhys::iterator it = active_Physics.begin();
126 it != active_Physics.end();
133 /// ***** Private Methods *****
135 void updateParticles(float time_step)
137 // add new Particle*s to Active
138 for( setPart::iterator it = particles_To_Add.begin();
139 it != particles_To_Add.end();
142 active_Particles.insert(*it);
144 particles_To_Add.clear();
146 // remove dead Particle*s from Active
147 for( setPart::iterator it = particles_To_Remove.begin();
148 it != particles_To_Remove.end();
151 active_Particles.erase(*it);
153 particles_To_Remove.clear();
155 // update active Particle*s
156 for( setPart::iterator it = active_Particles.begin();
157 it != active_Particles.end();
160 (*it)->update(time_step);
163 void updatePhysics(float time_step)
165 // add new PhysicsEntity*s to Active
166 for( setPhys::iterator it = physics_To_Add.begin();
167 it != physics_To_Add.end();
170 active_Physics.insert(*it);
172 physics_To_Add.clear();
174 // remove dead PhysicsEntity*s from Active
175 for( setPhys::iterator it = physics_To_Remove.begin();
176 it != physics_To_Remove.end();
179 active_Physics.erase(*it);
181 physics_To_Remove.clear();
183 // update active PhysicsEntity*s
184 for( setPhys::iterator it = active_Physics.begin();
185 it != active_Physics.end();
188 (*it)->update(time_step);