Fixed issue with events having a negative delta of time between them.

This commit is contained in:
Robert Osfield 2011-06-14 12:44:44 +00:00
parent 6a6c5bccda
commit 5b3eed5dce
4 changed files with 53 additions and 7 deletions

View File

@ -41,6 +41,9 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
/** Take the entire event queue leaving the EventQueue' event queue empty.*/ /** Take the entire event queue leaving the EventQueue' event queue empty.*/
bool takeEvents(Events& events); bool takeEvents(Events& events);
/** Take the events that were recorded before with specified time queue.*/
bool takeEvents(Events& events, double cutOffTime);
/** Take a copy the entire event queue leaving the EventQueue' event queue intact.*/ /** Take a copy the entire event queue leaving the EventQueue' event queue intact.*/
bool copyEvents(Events& events) const; bool copyEvents(Events& events) const;

View File

@ -62,6 +62,34 @@ bool EventQueue::takeEvents(Events& events)
} }
} }
bool EventQueue::takeEvents(Events& events, double cutOffTime)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
if (!_eventQueue.empty())
{
bool eventsTaken = false;
Events::iterator itr = _eventQueue.begin();
for(;
itr != _eventQueue.end() && ((*itr)->getTime() <= cutOffTime);
++itr)
{
events.push_back(*itr);
eventsTaken = true;
}
if (eventsTaken)
{
_eventQueue.erase(_eventQueue.begin(), itr);
}
return eventsTaken;
}
else
{
return false;
}
}
bool EventQueue::copyEvents(Events& events) const bool EventQueue::copyEvents(Events& events) const
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);

View File

@ -635,6 +635,15 @@ void CompositeViewer::advance(double simulationTime)
_frameStamp->setSimulationTime(simulationTime); _frameStamp->setSimulationTime(simulationTime);
} }
for(RefViews::iterator vitr = _views.begin();
vitr != _views.end();
++vitr)
{
View* view = vitr->get();
view->getEventQueue()->frame( getFrameStamp()->getReferenceTime() );
}
if (getViewerStats() && getViewerStats()->collectStats("frame_rate")) if (getViewerStats() && getViewerStats()->collectStats("frame_rate"))
{ {
// update previous frame stats // update previous frame stats
@ -676,6 +685,8 @@ void CompositeViewer::eventTraversal()
if (_views.empty()) return; if (_views.empty()) return;
double cutOffTime = _frameStamp->getReferenceTime();
double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
// OSG_NOTICE<<"CompositeViewer::frameEventTraversal()."<<std::endl; // OSG_NOTICE<<"CompositeViewer::frameEventTraversal()."<<std::endl;
@ -716,7 +727,7 @@ void CompositeViewer::eventTraversal()
gw->checkEvents(); gw->checkEvents();
osgGA::EventQueue::Events gw_events; osgGA::EventQueue::Events gw_events;
gw->getEventQueue()->takeEvents(gw_events); gw->getEventQueue()->takeEvents(gw_events, cutOffTime);
osgGA::EventQueue::Events::iterator itr; osgGA::EventQueue::Events::iterator itr;
for(itr = gw_events.begin(); for(itr = gw_events.begin();
@ -895,8 +906,7 @@ void CompositeViewer::eventTraversal()
++vitr) ++vitr)
{ {
View* view = vitr->get(); View* view = vitr->get();
view->getEventQueue()->frame( getFrameStamp()->getReferenceTime() ); view->getEventQueue()->takeEvents(viewEventsMap[view], cutOffTime);
view->getEventQueue()->takeEvents(viewEventsMap[view]);
} }

View File

@ -584,6 +584,11 @@ void Viewer::advance(double simulationTime)
_frameStamp->setSimulationTime(simulationTime); _frameStamp->setSimulationTime(simulationTime);
} }
if (_eventQueue.valid())
{
_eventQueue->frame( getFrameStamp()->getReferenceTime() );
}
if (getViewerStats() && getViewerStats()->collectStats("frame_rate")) if (getViewerStats() && getViewerStats()->collectStats("frame_rate"))
{ {
// update previous frame stats // update previous frame stats
@ -595,6 +600,7 @@ void Viewer::advance(double simulationTime)
getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime()); getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime());
} }
if (osg::Referenced::getDeleteHandler()) if (osg::Referenced::getDeleteHandler())
{ {
osg::Referenced::getDeleteHandler()->flush(); osg::Referenced::getDeleteHandler()->flush();
@ -607,6 +613,7 @@ void Viewer::eventTraversal()
{ {
if (_done) return; if (_done) return;
double cutOffTime = _frameStamp->getReferenceTime();
double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
// OSG_NOTICE<<"Viewer::frameEventTraversal()."<<std::endl; // OSG_NOTICE<<"Viewer::frameEventTraversal()."<<std::endl;
@ -645,7 +652,7 @@ void Viewer::eventTraversal()
gw->checkEvents(); gw->checkEvents();
osgGA::EventQueue::Events gw_events; osgGA::EventQueue::Events gw_events;
gw->getEventQueue()->takeEvents(gw_events); gw->getEventQueue()->takeEvents(gw_events, cutOffTime);
osgGA::EventQueue::Events::iterator itr; osgGA::EventQueue::Events::iterator itr;
for(itr = gw_events.begin(); for(itr = gw_events.begin();
@ -791,9 +798,7 @@ void Viewer::eventTraversal()
// OSG_NOTICE<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl; // OSG_NOTICE<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl;
_eventQueue->takeEvents(events, cutOffTime);
_eventQueue->frame( getFrameStamp()->getReferenceTime() );
_eventQueue->takeEvents(events);
#if 0 #if 0