doc that timers are sorted by endtime + don't call fgElapsedTime() if no timers to check, its a waste

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1613 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2013-04-07 08:03:48 +00:00
parent 02bb655c5c
commit 28539c8e95
2 changed files with 5 additions and 3 deletions

View File

@ -63,6 +63,7 @@ void FGAPIENTRY glutTimerFunc( unsigned int timeOut, FGCBTimer callback, int tim
timer->ID = timerID; timer->ID = timerID;
timer->TriggerTime = fgElapsedTime() + timeOut; timer->TriggerTime = fgElapsedTime() + timeOut;
/* Insert such that timers are sorted by end-time */
for( node = fgState.Timers.First; node; node = node->Node.Next ) for( node = fgState.Timers.First; node; node = node->Node.Next )
{ {
if( node->TriggerTime > timer->TriggerTime ) if( node->TriggerTime > timer->TriggerTime )

View File

@ -261,7 +261,7 @@ static void fghCheckTimers( void )
SFG_Timer *timer = fgState.Timers.First; SFG_Timer *timer = fgState.Timers.First;
if( timer->TriggerTime > checkTime ) if( timer->TriggerTime > checkTime )
/* XXX: are timers always sorted by triggerTime? If not, this and fghNextTimer are wrong */ /* Timers are sorted by triggerTime */
break; break;
fgListRemove( &fgState.Timers, &timer->Node ); fgListRemove( &fgState.Timers, &timer->Node );
@ -388,12 +388,13 @@ static int fghHavePendingRedisplays (void)
*/ */
static fg_time_t fghNextTimer( void ) static fg_time_t fghNextTimer( void )
{ {
fg_time_t currentTime = fgElapsedTime(); fg_time_t currentTime;
SFG_Timer *timer = fgState.Timers.First; SFG_Timer *timer = fgState.Timers.First; /* timers are sorted by trigger time, so only have to check the first */
if( !timer ) if( !timer )
return INT_MAX; return INT_MAX;
currentTime = fgElapsedTime();
if( timer->TriggerTime < currentTime ) if( timer->TriggerTime < currentTime )
return 0; return 0;
else else