From edfc70126a7ad6f62ec86ad7f11b734a10133911 Mon Sep 17 00:00:00 2001 From: Diederick Niehorster Date: Sun, 7 Apr 2013 08:03:48 +0000 Subject: [PATCH] doc that timers are sorted by endtime + don't call fgElapsedTime() if no timers to check, its a waste git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1613 7f0cb862-5218-0410-a997-914c9d46530a --- src/fg_callbacks.c | 1 + src/fg_main.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/fg_callbacks.c b/src/fg_callbacks.c index 7c82c81..768358b 100644 --- a/src/fg_callbacks.c +++ b/src/fg_callbacks.c @@ -63,6 +63,7 @@ void FGAPIENTRY glutTimerFunc( unsigned int timeOut, FGCBTimer callback, int tim timer->ID = timerID; timer->TriggerTime = fgElapsedTime() + timeOut; + /* Insert such that timers are sorted by end-time */ for( node = fgState.Timers.First; node; node = node->Node.Next ) { if( node->TriggerTime > timer->TriggerTime ) diff --git a/src/fg_main.c b/src/fg_main.c index d2108e7..39fecd4 100644 --- a/src/fg_main.c +++ b/src/fg_main.c @@ -261,7 +261,7 @@ static void fghCheckTimers( void ) SFG_Timer *timer = fgState.Timers.First; if( timer->TriggerTime > checkTime ) - /* XXX: are timers always sorted by triggerTime? If not, this and fghNextTimer are wrong */ + /* Timers are sorted by triggerTime */ break; fgListRemove( &fgState.Timers, &timer->Node ); @@ -388,12 +388,13 @@ static int fghHavePendingRedisplays (void) */ static fg_time_t fghNextTimer( void ) { - fg_time_t currentTime = fgElapsedTime(); - SFG_Timer *timer = fgState.Timers.First; + fg_time_t currentTime; + SFG_Timer *timer = fgState.Timers.First; /* timers are sorted by trigger time, so only have to check the first */ if( !timer ) return INT_MAX; + currentTime = fgElapsedTime(); if( timer->TriggerTime < currentTime ) return 0; else -- 1.7.10.4