Added mutexes to ParticleProcessor and ParticleSystemUpdater to improve the thread safety of osgParticle

This commit is contained in:
Robert Osfield 2006-12-22 21:52:53 +00:00
parent bd6b7d581e
commit 401f3bcd43
4 changed files with 21 additions and 11 deletions

View File

@ -171,6 +171,8 @@ namespace osgParticle
//added- 1/17/06- bgandere@nps.edu
//a var to keep from doing multiple updates
int _frameNumber;
OpenThreads::Mutex _cullUpdatelMutex;
};
// INLINE FUNCTIONS

View File

@ -91,6 +91,8 @@ namespace osgParticle
//added 1/17/06- bgandere@nps.edu
//a var to keep from doing multiple updates per frame
int _frameNumber;
OpenThreads::Mutex _cullUpdatelMutex;
};
// INLINE FUNCTIONS

View File

@ -62,9 +62,10 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
// continue only if the particle system is valid
if (_ps.valid())
{
if (nv.getFrameStamp())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_cullUpdatelMutex);
//added- 1/17/06- bgandere@nps.edu
//a check to make sure we havent updated yet this frame
if(_frameNumber < nv.getFrameStamp()->getFrameNumber())

View File

@ -23,9 +23,13 @@ osgParticle::ParticleSystemUpdater::ParticleSystemUpdater(const ParticleSystemUp
void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
{
osgUtil::CullVisitor *cv = dynamic_cast<osgUtil::CullVisitor *>(&nv);
if (cv) {
if (cv)
{
if (nv.getFrameStamp())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_cullUpdatelMutex);
//added 1/17/06- bgandere@nps.edu
//ensures ParticleSystem will only be updated once per frame
//regardless of the number of cameras viewing it
@ -45,6 +49,7 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
}
_t0 = t;
}
//added- 1/17/06- bgandere@nps.edu
//set frame number to the current frame number
_frameNumber = nv.getFrameStamp()->getFrameNumber();