Converted Time counter to a uniform unsigned long it value.

The initialized flag was redundant with the main Initialized flag,
and conversion of timeval to milliseconds in POSIX makes the code
cleaner. Timeval has a longer range, but the time value is already
limited by the GLUT API.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@706 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
joekrahn 2006-09-24 21:28:38 +00:00
parent d38b3eeff0
commit 007f03763e
3 changed files with 28 additions and 56 deletions

View File

@ -65,11 +65,7 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
0, /* FPSInterval */ 0, /* FPSInterval */
0, /* SwapCount */ 0, /* SwapCount */
0, /* SwapTime */ 0, /* SwapTime */
#if TARGET_HOST_MS_WINDOWS 0, /* Time */
{ 0, GL_FALSE }, /* Time */
#else
{ { 0, 0 }, GL_FALSE },
#endif
{ NULL, NULL }, /* Timers */ { NULL, NULL }, /* Timers */
{ NULL, NULL }, /* FreeTimers */ { NULL, NULL }, /* FreeTimers */
NULL, /* IdleCallback */ NULL, /* IdleCallback */
@ -285,8 +281,6 @@ void fgDeinitialize( void )
fgState.GameModeDepth = 16; fgState.GameModeDepth = 16;
fgState.GameModeRefresh = 72; fgState.GameModeRefresh = 72;
fgState.Time.Set = GL_FALSE;
fgListInit( &fgState.Timers ); fgListInit( &fgState.Timers );
fgListInit( &fgState.FreeTimers ); fgListInit( &fgState.FreeTimers );
@ -524,7 +518,8 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
fgCreateStructure( ); fgCreateStructure( );
fgElapsedTime( ); /* Get start time */
fgState.Time = fgSystemTime();
/* check if GLUT_FPS env var is set */ /* check if GLUT_FPS env var is set */
#ifndef _WIN32_WCE #ifndef _WIN32_WCE

View File

@ -246,18 +246,6 @@ struct tagSFG_XYUse
GLboolean Use; /* ...and a single boolean. */ GLboolean Use; /* ...and a single boolean. */
}; };
/* A helper structure holding a timeval and a boolean */
typedef struct tagSFG_Time SFG_Time;
struct tagSFG_Time
{
#if TARGET_HOST_MS_WINDOWS
DWORD Value;
#else
struct timeval Value;
#endif
GLboolean Set;
};
/* /*
* An enumeration containing the state of the GLUT execution: * An enumeration containing the state of the GLUT execution:
* initializing, running, or stopping * initializing, running, or stopping
@ -294,7 +282,7 @@ struct tagSFG_State
GLuint SwapCount; /* Count of glutSwapBuffer calls */ GLuint SwapCount; /* Count of glutSwapBuffer calls */
GLuint SwapTime; /* Time of last SwapBuffers */ GLuint SwapTime; /* Time of last SwapBuffers */
SFG_Time Time; /* Time that glutInit was called */ unsigned long Time; /* Time that glutInit was called */
SFG_List Timers; /* The freeglut timer hooks */ SFG_List Timers; /* The freeglut timer hooks */
SFG_List FreeTimers; /* The unused timer hooks */ SFG_List FreeTimers; /* The unused timer hooks */
@ -899,6 +887,9 @@ void fgDisplayMenu( void );
/* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */ /* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */
long fgElapsedTime( void ); long fgElapsedTime( void );
/* System time in milliseconds */
long unsigned fgSystemTime(void);
/* List functions */ /* List functions */
void fgListInit(SFG_List *list); void fgListInit(SFG_List *list);
void fgListAppend(SFG_List *list, SFG_Node *node); void fgListAppend(SFG_List *list, SFG_Node *node);

View File

@ -301,46 +301,32 @@ static void fghCheckTimers( void )
} }
} }
/* Platform-dependent time in milliseconds, as an unsigned 32-bit integer.
* This value wraps every 49.7 days, but integer overflows cancel
* when subtracting an initial start time, unless the total time exceeds
* 32-bit, where the GLUT API return value is also overflowed.
*/
unsigned long fgSystemTime(void) {
#if TARGET_HOST_POSIX_X11
struct timeval now;
gettimeofday( &now, NULL );
return now.tv_usec/1000 + now.tv_sec*1000;
#elif TARGET_HOST_MS_WINDOWS
# if defined(_WIN32_WCE)
return GetTickCount();
# else
return timeGetTime();
# endif
#endif
}
/* /*
* Elapsed Time * Elapsed Time
*/ */
long fgElapsedTime( void ) long fgElapsedTime( void )
{ {
if ( fgState.Time.Set ) return (long) (fgSystemTime() - fgState.Time);
{
#if TARGET_HOST_POSIX_X11
struct timeval now;
long elapsed;
gettimeofday( &now, NULL );
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
return elapsed;
#elif TARGET_HOST_MS_WINDOWS
# if defined(_WIN32_WCE)
return GetTickCount() - fgState.Time.Value;
# else
return timeGetTime() - fgState.Time.Value;
# endif
#endif
}
else
{
#if TARGET_HOST_POSIX_X11
gettimeofday( &fgState.Time.Value, NULL );
#elif TARGET_HOST_MS_WINDOWS
# if defined(_WIN32_WCE)
fgState.Time.Value = GetTickCount();
# else
fgState.Time.Value = timeGetTime ();
# endif
#endif
fgState.Time.Set = GL_TRUE ;
return 0 ;
}
} }
/* /*