massive cleaning of file section headers
[physics.git] / src / entityManager.cpp
CommitLineData
054d658f 1#include "entityManager.h"
a483ed75
PG
2#include "debug.h"
3
33b8c69b
PG
4#include <set>
5#include <iostream>
6
054d658f
PG
7#include "Entities/Entity.h"
8#include "Entities/Particle.h"
9#include "Entities/PhysicsEntity.h"
10
ad9f1fb6 11/// ***** Private Method Headers *****
617dcc71 12
ad9f1fb6
PG
13void updateParticles(float);
14void updatePhysics(float);
15
16/// ***** Private Variables *****
617dcc71 17
f72f4a59 18typedef std::set<Particle*> setPart;
ad9f1fb6
PG
19setPart particles_To_Add;
20setPart active_Particles;
21setPart particles_To_Remove;
ad9f1fb6 22
f72f4a59 23typedef std::set<PhysicsEntity*> setPhys;
ad9f1fb6
PG
24setPhys physics_To_Add;
25setPhys active_Physics;
26setPhys physics_To_Remove;
ad9f1fb6 27
617dcc71 28/// ***** Initializers/Cleaners *****
ad9f1fb6 29
d388f0ec 30void manager::init()
ad9f1fb6 31{
2c18685d 32
ad9f1fb6 33}
d388f0ec 34void manager::clean()
ad9f1fb6 35{
2c18685d 36
ad9f1fb6
PG
37}
38
617dcc71
PG
39/// ***** Public Methods *****
40
d388f0ec 41void manager::add(Entity* e)
ad9f1fb6
PG
42{
43 {
d388f0ec
PG
44 Particle* p = dynamic_cast<Particle*>(e);
45 if( p != 0 )
46 {
47 particles_To_Add.insert(p);
48 return;
49 }
ad9f1fb6
PG
50 }
51
52 {
d388f0ec
PG
53 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
54 if( p != 0 )
55 {
56 physics_To_Add.insert(p);
57 return;
58 }
ad9f1fb6
PG
59 }
60
61 std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
62 std::cerr << std::endl;
63}
d388f0ec 64void manager::remove(Entity* e)
ad9f1fb6
PG
65{
66 {
d388f0ec
PG
67 Particle* p = dynamic_cast<Particle*>(e);
68 if( p != 0 )
69 {
70 particles_To_Remove.insert(p);
71 return;
72 }
ad9f1fb6
PG
73 }
74
75 {
d388f0ec
PG
76 PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
77 if( p != 0 )
78 {
79 physics_To_Remove.insert(p);
80 return;
81 }
ad9f1fb6
PG
82 }
83
84 std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
85 std::cerr << std::endl;
86}
87
d388f0ec 88void manager::handleInput()
ad9f1fb6
PG
89{
90 // TODO
91}
d388f0ec 92void manager::update(float time_step)
ad9f1fb6
PG
93{
94 updateParticles(time_step);
95 updatePhysics(time_step);
96}
d388f0ec 97void manager::draw()
ad9f1fb6
PG
98{
99 // update active Particle*s
100 for( setPart::iterator it = active_Particles.begin();
101 it != active_Particles.end();
102 it++ )
103 {
104 (*it)->draw();
105 }
106
107 // update active PhysicsEntity*s
108 for( setPhys::iterator it = active_Physics.begin();
109 it != active_Physics.end();
110 it++ )
111 {
112 (*it)->draw();
113 }
114}
115
116/// ***** Private Methods *****
617dcc71 117
ad9f1fb6
PG
118void updateParticles(float time_step)
119{
120 // add new Particle*s to Active
121 for( setPart::iterator it = particles_To_Add.begin();
122 it != particles_To_Add.end();
123 it++ )
124 {
125 active_Particles.insert(*it);
126 }
127 particles_To_Add.clear();
128
129 // remove dead Particle*s from Active
130 for( setPart::iterator it = particles_To_Remove.begin();
131 it != particles_To_Remove.end();
132 it++ )
133 {
134 active_Particles.erase(*it);
135 }
136 particles_To_Remove.clear();
137
138 // update active Particle*s
139 for( setPart::iterator it = active_Particles.begin();
140 it != active_Particles.end();
141 it++ )
142 {
143 (*it)->update(time_step);
144 }
145}
146void updatePhysics(float time_step)
147{
148 // add new PhysicsEntity*s to Active
149 for( setPhys::iterator it = physics_To_Add.begin();
150 it != physics_To_Add.end();
151 it++ )
152 {
153 active_Physics.insert(*it);
154 }
155 physics_To_Add.clear();
156
157 // remove dead PhysicsEntity*s from Active
158 for( setPhys::iterator it = physics_To_Remove.begin();
159 it != physics_To_Remove.end();
160 it++ )
161 {
162 active_Physics.erase(*it);
163 }
164 physics_To_Remove.clear();
165
166 // update active PhysicsEntity*s
167 for( setPhys::iterator it = active_Physics.begin();
168 it != active_Physics.end();
169 it++ )
170 {
171 (*it)->update(time_step);
172 }
173}