From 28539c8e95d080bdb213c8a82f29d0fbb43712bc Mon Sep 17 00:00:00 2001 From: dcnieho 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: https://svn.code.sf.net/p/freeglut/code/trunk@1613 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/fg_callbacks.c | 1 + freeglut/freeglut/src/fg_main.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/freeglut/freeglut/src/fg_callbacks.c b/freeglut/freeglut/src/fg_callbacks.c index 7c82c81..768358b 100644 --- a/freeglut/freeglut/src/fg_callbacks.c +++ b/freeglut/freeglut/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/freeglut/freeglut/src/fg_main.c b/freeglut/freeglut/src/fg_main.c index d2108e7..39fecd4 100644 --- a/freeglut/freeglut/src/fg_main.c +++ b/freeglut/freeglut/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