From Brad Anderegg, add _frameNumber and associated code to ensure that particles
only get updated once per frame.
This commit is contained in:
parent
83add79c07
commit
3baf9f51d2
@ -167,6 +167,10 @@ namespace osgParticle
|
||||
double _startTime;
|
||||
double _currentTime;
|
||||
double _resetTime;
|
||||
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//a var to keep from doing multiple updates
|
||||
int _frameNumber;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
|
@ -87,6 +87,10 @@ namespace osgParticle
|
||||
|
||||
ParticleSystem_Vector _psv;
|
||||
double _t0;
|
||||
|
||||
//added 1/17/06- bgandere@nps.edu
|
||||
//a var to keep from doing multiple updates per frame
|
||||
int _frameNumber;
|
||||
};
|
||||
|
||||
// INLINE FUNCTIONS
|
||||
|
@ -26,7 +26,8 @@ osgParticle::ParticleProcessor::ParticleProcessor()
|
||||
_lifeTime(0.0),
|
||||
_startTime(0.0),
|
||||
_currentTime(0.0),
|
||||
_resetTime(0.0)
|
||||
_resetTime(0.0),
|
||||
_frameNumber(0)
|
||||
{
|
||||
setCullingActive(false);
|
||||
}
|
||||
@ -64,51 +65,59 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
if (nv.getFrameStamp())
|
||||
{
|
||||
|
||||
// retrieve the current time
|
||||
double t = nv.getFrameStamp()->getReferenceTime();
|
||||
|
||||
// reset this processor if we've reached the reset point
|
||||
if ((_currentTime >= _resetTime) && (_resetTime > 0))
|
||||
{
|
||||
_currentTime = 0;
|
||||
_t0 = -1;
|
||||
}
|
||||
|
||||
// skip if we haven't initialized _t0 yet
|
||||
if (_t0 != -1)
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//a check to make sure we havent updated yet this frame
|
||||
if(_frameNumber < nv.getFrameStamp()->getFrameNumber())
|
||||
{
|
||||
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (_currentTime >= _startTime)
|
||||
// retrieve the current time
|
||||
double t = nv.getFrameStamp()->getReferenceTime();
|
||||
|
||||
// reset this processor if we've reached the reset point
|
||||
if ((_currentTime >= _resetTime) && (_resetTime > 0))
|
||||
{
|
||||
if (_endless || (_currentTime < (_startTime + _lifeTime)))
|
||||
alive = true;
|
||||
_currentTime = 0;
|
||||
_t0 = -1;
|
||||
}
|
||||
|
||||
// update current time
|
||||
_currentTime += t - _t0;
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
_enabled &&
|
||||
!_ps->isFrozen() &&
|
||||
(_ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !_ps->getFreezeOnCull()))
|
||||
// skip if we haven't initialized _t0 yet
|
||||
if (_t0 != -1)
|
||||
{
|
||||
// initialize matrix flags
|
||||
_need_ltw_matrix = true;
|
||||
_need_wtl_matrix = true;
|
||||
_current_nodevisitor = &nv;
|
||||
|
||||
// do some process (unimplemented in this base class)
|
||||
process(t - _t0);
|
||||
// check whether the processor is alive
|
||||
bool alive = false;
|
||||
if (_currentTime >= _startTime)
|
||||
{
|
||||
if (_endless || (_currentTime < (_startTime + _lifeTime)))
|
||||
alive = true;
|
||||
}
|
||||
|
||||
// update current time
|
||||
_currentTime += t - _t0;
|
||||
|
||||
// process only if the particle system is not frozen/culled
|
||||
if (alive &&
|
||||
_enabled &&
|
||||
!_ps->isFrozen() &&
|
||||
(_ps->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !_ps->getFreezeOnCull()))
|
||||
{
|
||||
// initialize matrix flags
|
||||
_need_ltw_matrix = true;
|
||||
_need_wtl_matrix = true;
|
||||
_current_nodevisitor = &nv;
|
||||
|
||||
// do some process (unimplemented in this base class)
|
||||
process(t - _t0);
|
||||
}
|
||||
}
|
||||
|
||||
// update _t0
|
||||
_t0 = t;
|
||||
}
|
||||
|
||||
// update _t0
|
||||
_t0 = t;
|
||||
|
||||
//added- 1/17/06- bgandere@nps.edu
|
||||
//updates the _frameNumber, keeping it current
|
||||
_frameNumber = nv.getFrameStamp()->getFrameNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
using namespace osg;
|
||||
|
||||
osgParticle::ParticleSystemUpdater::ParticleSystemUpdater()
|
||||
: osg::Node(), _t0(-1)
|
||||
: osg::Node(), _t0(-1), _frameNumber(0)
|
||||
{
|
||||
setCullingActive(false);
|
||||
}
|
||||
@ -26,19 +26,28 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
|
||||
if (cv) {
|
||||
if (nv.getFrameStamp())
|
||||
{
|
||||
double t = nv.getFrameStamp()->getReferenceTime();
|
||||
if (_t0 != -1)
|
||||
{
|
||||
ParticleSystem_Vector::iterator i;
|
||||
for (i=_psv.begin(); i!=_psv.end(); ++i)
|
||||
//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)
|
||||
{
|
||||
if (!i->get()->isFrozen() && (i->get()->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !i->get()->getFreezeOnCull()))
|
||||
ParticleSystem_Vector::iterator i;
|
||||
for (i=_psv.begin(); i!=_psv.end(); ++i)
|
||||
{
|
||||
i->get()->update(t - _t0);
|
||||
if (!i->get()->isFrozen() && (i->get()->getLastFrameNumber() >= (nv.getFrameStamp()->getFrameNumber() - 1) || !i->get()->getFreezeOnCull()))
|
||||
{
|
||||
i->get()->update(t - _t0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_t0 = t;
|
||||
_t0 = t;
|
||||
}
|
||||
//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