diff --git a/include/osgGA/EventQueue b/include/osgGA/EventQueue index 1b518aa2b..3306acf87 100644 --- a/include/osgGA/EventQueue +++ b/include/osgGA/EventQueue @@ -41,6 +41,9 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced /** Take the entire event queue leaving the EventQueue' event queue empty.*/ 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.*/ bool copyEvents(Events& events) const; diff --git a/src/osgGA/EventQueue.cpp b/src/osgGA/EventQueue.cpp index 7e61f4907..741d49a70 100644 --- a/src/osgGA/EventQueue.cpp +++ b/src/osgGA/EventQueue.cpp @@ -62,6 +62,34 @@ bool EventQueue::takeEvents(Events& events) } } +bool EventQueue::takeEvents(Events& events, double cutOffTime) +{ + OpenThreads::ScopedLock 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 { OpenThreads::ScopedLock lock(_eventQueueMutex); diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index 1cfb4eeb4..f86a28b36 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -635,6 +635,15 @@ void CompositeViewer::advance(double 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")) { // update previous frame stats @@ -676,6 +685,8 @@ void CompositeViewer::eventTraversal() if (_views.empty()) return; + double cutOffTime = _frameStamp->getReferenceTime(); + double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); // OSG_NOTICE<<"CompositeViewer::frameEventTraversal()."<checkEvents(); osgGA::EventQueue::Events gw_events; - gw->getEventQueue()->takeEvents(gw_events); + gw->getEventQueue()->takeEvents(gw_events, cutOffTime); osgGA::EventQueue::Events::iterator itr; for(itr = gw_events.begin(); @@ -895,8 +906,7 @@ void CompositeViewer::eventTraversal() ++vitr) { View* view = vitr->get(); - view->getEventQueue()->frame( getFrameStamp()->getReferenceTime() ); - view->getEventQueue()->takeEvents(viewEventsMap[view]); + view->getEventQueue()->takeEvents(viewEventsMap[view], cutOffTime); } diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index ed02a5476..16e83ac7f 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -584,6 +584,11 @@ void Viewer::advance(double simulationTime) _frameStamp->setSimulationTime(simulationTime); } + if (_eventQueue.valid()) + { + _eventQueue->frame( getFrameStamp()->getReferenceTime() ); + } + if (getViewerStats() && getViewerStats()->collectStats("frame_rate")) { // update previous frame stats @@ -595,6 +600,7 @@ void Viewer::advance(double simulationTime) getViewerStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime()); } + if (osg::Referenced::getDeleteHandler()) { osg::Referenced::getDeleteHandler()->flush(); @@ -607,6 +613,7 @@ void Viewer::eventTraversal() { if (_done) return; + double cutOffTime = _frameStamp->getReferenceTime(); double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); // OSG_NOTICE<<"Viewer::frameEventTraversal()."<checkEvents(); osgGA::EventQueue::Events gw_events; - gw->getEventQueue()->takeEvents(gw_events); + gw->getEventQueue()->takeEvents(gw_events, cutOffTime); osgGA::EventQueue::Events::iterator itr; for(itr = gw_events.begin(); @@ -791,9 +798,7 @@ void Viewer::eventTraversal() // OSG_NOTICE<<"mouseEventState Xmin = "<getXmin()<<" Ymin="<getYmin()<<" xMax="<getXmax()<<" Ymax="<getYmax()<frame( getFrameStamp()->getReferenceTime() ); - _eventQueue->takeEvents(events); + _eventQueue->takeEvents(events, cutOffTime); #if 0