projects
/
physics.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
423931a
)
refactored entityManager
author
Patrik Gornicz
<Gornicz.P@gmail.com>
Thu, 22 Jan 2009 01:05:08 +0000
(20:05 -0500)
committer
Patrik Gornicz
<Gornicz.P@gmail.com>
Thu, 22 Jan 2009 01:05:08 +0000
(20:05 -0500)
src/entityManager.cpp
patch
|
blob
|
blame
|
history
diff --git
a/src/entityManager.cpp
b/src/entityManager.cpp
index
7d75d3c
..
64d7480
100644
(file)
--- a/
src/entityManager.cpp
+++ b/
src/entityManager.cpp
@@
-33,32
+33,32
@@
/// ***** Private Method Headers *****
/// ***** Private Method Headers *****
-void updateParticles(float);
-void updatePhysics(float);
-
void clearUp
Particles();
-
void clearUp
Physics();
+
static
void updateParticles(float);
+
static
void updatePhysics(float);
+
static void addOrRemove
Particles();
+
static void addOrRemove
Physics();
/// ***** Private Variables *****
typedef std::set<Particle*> setPart;
/// ***** Private Variables *****
typedef std::set<Particle*> setPart;
-setPart particles_To_Add;
-setPart active_Particles;
-setPart particles_To_Remove;
+s
tatic s
etPart particles_To_Add;
+s
tatic s
etPart active_Particles;
+s
tatic s
etPart particles_To_Remove;
typedef std::set<PhysicsEntity*> setPhys;
typedef std::set<PhysicsEntity*> setPhys;
-setPhys physics_To_Add;
-setPhys active_Physics;
-setPhys physics_To_Remove;
+s
tatic s
etPhys physics_To_Add;
+s
tatic s
etPhys active_Physics;
+s
tatic s
etPhys physics_To_Remove;
-
Mutex particleSetLock
;
-
Mutex physicsEntitySetLock
;
+
static Mutex muSetPart
;
+
static Mutex muSetPhys
;
/// ***** Initializers/Cleaners *****
void manager::init()
{
/// ***** Initializers/Cleaners *****
void manager::init()
{
-
particleSetLock
.init();
-
physicsEntitySetLock
.init();
+
muSetPart
.init();
+
muSetPhys
.init();
collision::init();
}
collision::init();
}
@@
-66,40
+66,44
@@
void manager::clean()
{
collision::clean();
{
collision::clean();
-
physicsEntitySetLock
.clean();
-
particleSetLock
.clean();
+
muSetPhys
.clean();
+
muSetPart
.clean();
}
/// ***** Public Methods *****
}
/// ***** Public Methods *****
-void manager::add(Entity* e)
+void manager::add(Entity*
p
e)
{
{
+ DASSERT(pe != NULL);
+
{
{
- Particle* p
= dynamic_cast<Particle*>(
e);
- if( p
!= 0
)
+ Particle* p
p = dynamic_cast<Particle*>(p
e);
+ if( p
p != NULL
)
{
{
- particles_To_Add.insert(p);
+ particles_To_Add.insert(p
p
);
return;
}
}
{
return;
}
}
{
- PhysicsEntity* p
= dynamic_cast<PhysicsEntity*>(
e);
- if( p
!= 0
)
+ PhysicsEntity* p
pe = dynamic_cast<PhysicsEntity*>(p
e);
+ if( p
pe != NULL
)
{
{
- physics_To_Add.insert(p);
+ physics_To_Add.insert(p
pe
);
return;
}
}
DPF(0, "ENTITY TYPE NOT SUPPORTED BY addEntity()!!");
}
return;
}
}
DPF(0, "ENTITY TYPE NOT SUPPORTED BY addEntity()!!");
}
-void manager::remove(Entity* e)
+void manager::remove(Entity*
p
e)
{
{
+ DASSERT(pe != NULL);
+
{
{
- Autolock lock(
particleSetLock
);
- Particle* p = dynamic_cast<Particle*>(e);
- if( p !=
0
)
+ Autolock lock(
muSetPart
);
+ Particle* p = dynamic_cast<Particle*>(
p
e);
+ if( p !=
NULL
)
{
particles_To_Remove.insert(p);
return;
{
particles_To_Remove.insert(p);
return;
@@
-107,11
+111,11
@@
void manager::remove(Entity* e)
}
{
}
{
- Autolock lock(
physicsEntitySetLock
);
- PhysicsEntity* p
= dynamic_cast<PhysicsEntity*>(
e);
- if( p
!= 0
)
+ Autolock lock(
muSetPhys
);
+ PhysicsEntity* p
pe = dynamic_cast<PhysicsEntity*>(p
e);
+ if( p
pe != NULL
)
{
{
- physics_To_Remove.insert(p);
+ physics_To_Remove.insert(p
pe
);
return;
}
}
return;
}
}
@@
-132,11
+136,12
@@
void manager::update(float time_step)
}
void manager::draw()
{
}
void manager::draw()
{
- clearUpParticles();
{
{
- Autolock lock(
particleSetLock
);
+ Autolock lock(
muSetPart
);
- // update active Particle*s
+ addOrRemoveParticles();
+
+ // draw active Particle*s
for( setPart::iterator it = active_Particles.begin();
it != active_Particles.end();
it++ )
for( setPart::iterator it = active_Particles.begin();
it != active_Particles.end();
it++ )
@@
-145,11
+150,12
@@
void manager::draw()
}
}
}
}
- clearUpPhysics();
{
{
- Autolock lock( physicsEntitySetLock );
+ Autolock lock( muSetPhys );
+
+ addOrRemovePhysics();
- //
update
active PhysicsEntity*s
+ //
draw
active PhysicsEntity*s
for( setPhys::iterator it = active_Physics.begin();
it != active_Physics.end();
it++ )
for( setPhys::iterator it = active_Physics.begin();
it != active_Physics.end();
it++ )
@@
-163,7
+169,7
@@
void manager::draw()
void updateParticles(float time_step)
{
void updateParticles(float time_step)
{
-
clearUp
Particles();
+
addOrRemove
Particles();
// update active Particle*s
for( setPart::iterator it = active_Particles.begin();
// update active Particle*s
for( setPart::iterator it = active_Particles.begin();
@@
-175,7
+181,7
@@
void updateParticles(float time_step)
}
void updatePhysics(float time_step)
{
}
void updatePhysics(float time_step)
{
-
clearUp
Physics();
+
addOrRemove
Physics();
// apply collision math
collision::update(active_Physics);
// apply collision math
collision::update(active_Physics);
@@
-188,9
+194,9
@@
void updatePhysics(float time_step)
(*it)->update(time_step);
}
}
(*it)->update(time_step);
}
}
-void
clearUp
Particles()
+void
addOrRemove
Particles()
{
{
- Autolock lock(
particleSetLock
);
+ Autolock lock(
muSetPart
);
// add new Particle*s to Active
for( setPart::iterator it = particles_To_Add.begin();
// add new Particle*s to Active
for( setPart::iterator it = particles_To_Add.begin();
@@
-210,9
+216,9
@@
void clearUpParticles()
}
particles_To_Remove.clear();
}
}
particles_To_Remove.clear();
}
-void
clearUp
Physics()
+void
addOrRemove
Physics()
{
{
- Autolock lock(
physicsEntitySetLock
);
+ Autolock lock(
muSetPhys
);
// add new PhysicsEntity*s to Active
for( setPhys::iterator it = physics_To_Add.begin();
// add new PhysicsEntity*s to Active
for( setPhys::iterator it = physics_To_Add.begin();