Added mutexes to ParticleProcessor and ParticleSystemUpdater to improve the thread safety of osgParticle
This commit is contained in:
parent
bd6b7d581e
commit
401f3bcd43
@ -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
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
@ -23,14 +23,18 @@ 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())
|
||||
{
|
||||
//added 1/17/06- bgandere@nps.edu
|
||||
//ensures ParticleSystem will only be updated once per frame
|
||||
//regardless of the number of cameras viewing it
|
||||
if( _frameNumber < nv.getFrameStamp()->getFrameNumber())
|
||||
{
|
||||
|
||||
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
|
||||
if( _frameNumber < nv.getFrameStamp()->getFrameNumber())
|
||||
{
|
||||
double t = nv.getFrameStamp()->getReferenceTime();
|
||||
if (_t0 != -1)
|
||||
{
|
||||
@ -44,10 +48,11 @@ 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();
|
||||
}
|
||||
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//set frame number to the current frame number
|
||||
_frameNumber = nv.getFrameStamp()->getFrameNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user