#include "debug.h"
#include <set>
-#include <iostream>
+#include <SDL/SDL.h>
+
+#include "locks/Mutex.h"
+#include "locks/Autolock.h"
#include "Entities/Entity.h"
#include "Entities/Particle.h"
#include "Entities/PhysicsEntity.h"
+#include "collisionManager.h"
+#include "effectManager.h"
+
/// ***** Private Method Headers *****
void updateParticles(float);
void updatePhysics(float);
+void clearUpParticles();
+void clearUpPhysics();
/// ***** Private Variables *****
setPhys active_Physics;
setPhys physics_To_Remove;
+Mutex particleSetLock;
+Mutex physicsEntitySetLock;
+
/// ***** Initializers/Cleaners *****
void manager::init()
{
+ particleSetLock.init();
+ physicsEntitySetLock.init();
+ collision::init();
}
void manager::clean()
{
+ collision::clean();
+ physicsEntitySetLock.clean();
+ particleSetLock.clean();
}
/// ***** Public Methods *****
}
}
- std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
- std::cerr << std::endl;
+ DPF(0, "ENTITY TYPE NOT SUPPORTED BY addEntity()!!");
}
void manager::remove(Entity* e)
{
{
+ Autolock lock( particleSetLock );
Particle* p = dynamic_cast<Particle*>(e);
if( p != 0 )
{
}
{
+ Autolock lock( physicsEntitySetLock );
PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
if( p != 0 )
{
}
}
- std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
- std::cerr << std::endl;
+ DPF(0, "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!");
}
void manager::handleInput()
{
- // TODO
+ effect::handleInput();
}
void manager::update(float time_step)
{
+ effect::update(time_step);
+
updateParticles(time_step);
updatePhysics(time_step);
}
void manager::draw()
{
+ clearUpParticles();
+ {
+ Autolock lock( particleSetLock );
+
+ // update active Particle*s
+ for( setPart::iterator it = active_Particles.begin();
+ it != active_Particles.end();
+ it++ )
+ {
+ (*it)->draw();
+ }
+ }
+
+ clearUpPhysics();
+ {
+ Autolock lock( physicsEntitySetLock );
+
+ // update active PhysicsEntity*s
+ for( setPhys::iterator it = active_Physics.begin();
+ it != active_Physics.end();
+ it++ )
+ {
+ (*it)->draw();
+ }
+ }
+}
+
+/// ***** Private Methods *****
+
+void updateParticles(float time_step)
+{
+ clearUpParticles();
+
// update active Particle*s
for( setPart::iterator it = active_Particles.begin();
it != active_Particles.end();
it++ )
{
- (*it)->draw();
+ (*it)->update(time_step);
}
+}
+void updatePhysics(float time_step)
+{
+ clearUpPhysics();
+
+ // apply collision math
+ collision::update(active_Physics);
// update active PhysicsEntity*s
for( setPhys::iterator it = active_Physics.begin();
it != active_Physics.end();
it++ )
{
- (*it)->draw();
+ (*it)->update(time_step);
}
}
-
-/// ***** Private Methods *****
-
-void updateParticles(float time_step)
+void clearUpParticles()
{
+ Autolock lock( particleSetLock );
+
// add new Particle*s to Active
for( setPart::iterator it = particles_To_Add.begin();
it != particles_To_Add.end();
active_Particles.erase(*it);
}
particles_To_Remove.clear();
-
- // update active Particle*s
- for( setPart::iterator it = active_Particles.begin();
- it != active_Particles.end();
- it++ )
- {
- (*it)->update(time_step);
- }
}
-void updatePhysics(float time_step)
+void clearUpPhysics()
{
+ Autolock lock( physicsEntitySetLock );
+
// add new PhysicsEntity*s to Active
for( setPhys::iterator it = physics_To_Add.begin();
it != physics_To_Add.end();
active_Physics.erase(*it);
}
physics_To_Remove.clear();
-
- // update active PhysicsEntity*s
- for( setPhys::iterator it = active_Physics.begin();
- it != active_Physics.end();
- it++ )
- {
- (*it)->update(time_step);
- }
}