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: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@706
7f0cb862-5218-0410-a997-
914c9d46530a
0, /* FPSInterval */
0, /* SwapCount */
0, /* SwapTime */
-#if TARGET_HOST_MS_WINDOWS
- { 0, GL_FALSE }, /* Time */
-#else
- { { 0, 0 }, GL_FALSE },
-#endif
+ 0, /* Time */
{ NULL, NULL }, /* Timers */
{ NULL, NULL }, /* FreeTimers */
NULL, /* IdleCallback */
fgState.GameModeDepth = 16;
fgState.GameModeRefresh = 72;
- fgState.Time.Set = GL_FALSE;
-
fgListInit( &fgState.Timers );
fgListInit( &fgState.FreeTimers );
fgCreateStructure( );
- fgElapsedTime( );
+ /* Get start time */
+ fgState.Time = fgSystemTime();
/* check if GLUT_FPS env var is set */
#ifndef _WIN32_WCE
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:
* initializing, running, or stopping
GLuint SwapCount; /* Count of glutSwapBuffer calls */
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 FreeTimers; /* The unused timer hooks */
/* Elapsed time as per glutGet(GLUT_ELAPSED_TIME). */
long fgElapsedTime( void );
+/* System time in milliseconds */
+long unsigned fgSystemTime(void);
+
/* List functions */
void fgListInit(SFG_List *list);
void fgListAppend(SFG_List *list, SFG_Node *node);
}
}
-/*
- * Elapsed Time
- */
-long fgElapsedTime( void )
-{
- if ( fgState.Time.Set )
- {
-#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
- {
+
+/* 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
- gettimeofday( &fgState.Time.Value, NULL );
+ struct timeval now;
+ gettimeofday( &now, NULL );
+ return now.tv_usec/1000 + now.tv_sec*1000;
#elif TARGET_HOST_MS_WINDOWS
# if defined(_WIN32_WCE)
- fgState.Time.Value = GetTickCount();
+ return GetTickCount();
# else
- fgState.Time.Value = timeGetTime ();
+ return timeGetTime();
# endif
#endif
- fgState.Time.Set = GL_TRUE ;
-
- return 0 ;
- }
+}
+
+/*
+ * Elapsed Time
+ */
+long fgElapsedTime( void )
+{
+ return (long) (fgSystemTime() - fgState.Time);
}
/*