Improved handling of resetting of the EventQueue::startTick().
This commit is contained in:
parent
747654fb6d
commit
0329ca5cea
@ -196,11 +196,13 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
|
|||||||
void frame(double time);
|
void frame(double time);
|
||||||
|
|
||||||
|
|
||||||
void setStartTick(osg::Timer_t tick) { _startTick = tick; }
|
void setStartTick(osg::Timer_t tick) { _startTick = tick; clear(); }
|
||||||
osg::Timer_t getStartTick() const { return _startTick; }
|
osg::Timer_t getStartTick() const { return _startTick; }
|
||||||
|
|
||||||
double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
|
double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
|
||||||
|
|
||||||
|
/** clear all events from queue. */
|
||||||
|
void clear();
|
||||||
|
|
||||||
/** convenience method for create an event ready to fill in. Clones the getCurrentEventState() to produce a up to date event state. */
|
/** convenience method for create an event ready to fill in. Clones the getCurrentEventState() to produce a up to date event state. */
|
||||||
GUIEventAdapter* createEvent();
|
GUIEventAdapter* createEvent();
|
||||||
|
@ -30,6 +30,13 @@ EventQueue::~EventQueue()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventQueue::clear()
|
||||||
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
||||||
|
_eventQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void EventQueue::setEvents(Events& events)
|
void EventQueue::setEvents(Events& events)
|
||||||
{
|
{
|
||||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
||||||
@ -67,22 +74,41 @@ bool EventQueue::takeEvents(Events& events, double cutOffTime)
|
|||||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
|
||||||
if (!_eventQueue.empty())
|
if (!_eventQueue.empty())
|
||||||
{
|
{
|
||||||
bool eventsTaken = false;
|
// find last event if queue that came in before the cuttof.
|
||||||
Events::iterator itr = _eventQueue.begin();
|
Events::reverse_iterator ritr = _eventQueue.rbegin();
|
||||||
for(;
|
for(; ritr != _eventQueue.rend() && ((*ritr)->getTime() > cutOffTime); ++ritr) {}
|
||||||
itr != _eventQueue.end() && ((*itr)->getTime() <= cutOffTime);
|
|
||||||
|
if (ritr==_eventQueue.rend()) return false;
|
||||||
|
|
||||||
|
for(Events::iterator itr = _eventQueue.begin();
|
||||||
|
itr != ritr.base();
|
||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
events.push_back(*itr);
|
events.push_back(*itr);
|
||||||
eventsTaken = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventsTaken)
|
// make sure that the events are in ascending time order, and any out of out events
|
||||||
|
// have their time reset to the next valid time after them in the events list.
|
||||||
|
double previousTime = cutOffTime;
|
||||||
|
for(Events::reverse_iterator itr = events.rbegin();
|
||||||
|
itr != events.rend();
|
||||||
|
++itr)
|
||||||
{
|
{
|
||||||
_eventQueue.erase(_eventQueue.begin(), itr);
|
if ((*itr)->getTime() > previousTime)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Reset event time from "<<(*itr)->getTime()<<" to "<<previousTime<<std::endl;
|
||||||
|
(*itr)->setTime(previousTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
previousTime = (*itr)->getTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventsTaken;
|
// remove the events we are taking from the original event queue.
|
||||||
|
_eventQueue.erase(_eventQueue.begin(), ritr.base());
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user