Added a new state variable "Initalized".

Replaced referenced to Time.Set with this new variable where appropriate.
fgElapsedTime() now set the start time if Time.Set is false.
Moved glutGet(GLUT_ELAPSED_TIME) handling to before the assert.


git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@348 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
cjp 2003-11-15 16:24:33 +00:00
parent 6895440554
commit 2b78c976ea
6 changed files with 44 additions and 26 deletions

View File

@ -58,6 +58,7 @@ SFG_Display fgDisplay;
SFG_State fgState = { { -1, -1, FALSE }, /* Position */
{ 300, 300, TRUE }, /* Size */
GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */
FALSE, /* Initalized */
FALSE, /* ForceDirectContext */
TRUE, /* TryDirectContext */
FALSE, /* ForceIconic */
@ -197,6 +198,8 @@ void fgInitialize( const char* displayName )
#endif
fgJoystickInit( 0 );
fgState.Initalized = GL_TRUE;
}
/*
@ -206,13 +209,15 @@ void fgDeinitialize( void )
{
SFG_Timer *timer;
if( !fgState.Time.Set )
if( !fgState.Initalized )
{
fgWarning( "fgDeinitialize(): fgState.Timer is null => "
"no valid initialization has been performed" );
fgWarning( "fgDeinitialize(): "
"no valid initialization has been performed" );
return;
}
fgState.Initalized = GL_FALSE;
/*
* If there was a menu created, destroy the rendering context
*/
@ -312,17 +317,12 @@ void FGAPIENTRY glutInit( int* pargc, char** argv )
if( !fgState.ProgramName )
fgError ("Could not allocate space for the program's name.");
if( fgState.Time.Set )
if( fgState.Initalized )
fgError( "illegal glutInit() reinitialization attemp" );
fgCreateStructure( );
#if TARGET_HOST_UNIX_X11
gettimeofday( &fgState.Time.Value, NULL );
#elif TARGET_HOST_WIN32
fgState.Time.Value = timeGetTime( );
#endif
fgState.Time.Set = TRUE;
fgElapsedTime( );
/* check if GLUT_FPS env var is set */
{

View File

@ -218,6 +218,8 @@ struct tagSFG_State
SFG_XYUse Size; /* The default windows' size */
unsigned int DisplayMode; /* Display mode for new windows */
GLboolean Initalized; /* Freeglut has been initalized */
GLboolean ForceDirectContext; /* Force direct rendering? */
GLboolean TryDirectContext; /* What about giving a try to? */
@ -643,7 +645,7 @@ extern SFG_State fgState;
* A call to this function makes us sure that the Display and Structure
* subsystems have been properly initialized and are ready to be used
*/
#define freeglut_assert_ready assert( fgState.Time.Set );
#define freeglut_assert_ready assert( fgState.Initalized );
/*
* Following definitions are somewhat similiar to GLib's,

View File

@ -296,19 +296,31 @@ static void fghCheckTimers( void )
*/
long fgElapsedTime( void )
{
if (fgState.Time.Set)
{
#if TARGET_HOST_UNIX_X11
struct timeval now;
long elapsed;
struct timeval now;
long elapsed;
gettimeofday( &now, NULL );
gettimeofday( &now, NULL );
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
return elapsed;
return elapsed;
#elif TARGET_HOST_WIN32
return timeGetTime() - fgState.Time.Value;
return timeGetTime() - fgState.Time.Value;
#endif
}
else
{
#if TARGET_HOST_UNIX_X11
gettimeofday( &fgState.Time.Value, NULL );
#elif TARGET_HOST_WIN32
fgState.Time.Value = timeGetTime( );
#endif
fgState.Time.Set = TRUE;
}
}
/*

View File

@ -127,8 +127,14 @@ int FGAPIENTRY glutGet( GLenum eWhat )
int returnValue ;
GLboolean boolValue ;
if ( eWhat == GLUT_INIT_STATE )
return ( fgState.Time.Set ) ;
switch (eWhat)
{
case GLUT_INIT_STATE:
return ( fgState.Initalized ) ;
case GLUT_ELAPSED_TIME:
return( fgElapsedTime() );
}
freeglut_assert_ready;
@ -137,9 +143,6 @@ int FGAPIENTRY glutGet( GLenum eWhat )
*/
switch( eWhat )
{
case GLUT_ELAPSED_TIME:
return( fgElapsedTime() );
/*
* Following values are stored in fgState and fgDisplay global structures
*/

View File

@ -83,7 +83,7 @@ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title,
* If the freeglut internals haven't been initialized yet,
* do it now. Hack's idea courtesy of Chris Purnell...
*/
if( !fgState.Time.Set )
if( !fgState.Initalized )
glutInit( &fakeArgc, NULL );
/*
@ -136,7 +136,7 @@ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback )
* If the freeglut internals haven't been initialized yet,
* do it now. Hack's idea courtesy of Chris Purnell...
*/
if( !fgState.Time.Set )
if( !fgState.Initalized )
glutInit( &fakeArgc, NULL );
menu->ParentWindow = fgStructure.Window;

View File

@ -960,7 +960,8 @@ void FGAPIENTRY glutFullScreen( void )
fgDisplay.ScreenWidth,
fgDisplay.ScreenHeight
);
XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
XFlush( fgDisplay.Display ); /* This is needed */
XTranslateCoordinates(
fgDisplay.Display,