X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_main.c;h=8aed70194b8efe04ca61f1b717b69c6d079399c2;hb=34316b553a4d3d0702630712f73e024919865ee2;hp=e73be9ca9d60356de1888ef5de64237eab7b2caa;hpb=2b306903f06d3ff70c2e6b7bcd7386d2e56ffbdf;p=freeglut diff --git a/src/freeglut_main.c b/src/freeglut_main.c index e73be9c..8aed701 100644 --- a/src/freeglut_main.c +++ b/src/freeglut_main.c @@ -301,46 +301,32 @@ static void fghCheckTimers( void ) } } -/* - * 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); } /* @@ -1304,7 +1290,10 @@ void FGAPIENTRY glutMainLoopEvent( void ) /* Cease processing this event if it is auto repeated */ if (window->State.KeyRepeating) + { + if (event.type == KeyPress) window->State.KeyRepeating = GL_FALSE; break; + } if( event.type == KeyPress ) { @@ -1559,7 +1548,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, { SFG_Window* window; PAINTSTRUCT ps; - LONG lRet = 1; + LRESULT lRet = 1; FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ; @@ -1623,8 +1612,15 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, } window->State.NeedToResize = GL_TRUE; - window->State.Width = fgState.Size.X; - window->State.Height = fgState.Size.Y; + if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) ) + { + SFG_Window *current_window = fgStructure.CurrentWindow; + + fgSetWindow( window ); + window->State.Width = glutGet( GLUT_WINDOW_WIDTH ); + window->State.Height = glutGet( GLUT_WINDOW_HEIGHT ); + fgSetWindow( current_window ); + } ReleaseDC( window->Window.Handle, window->Window.Device ); @@ -2092,7 +2088,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, GetKeyboardState( state ); - if( ToAscii( wParam, 0, state, code, 0 ) == 1 ) + if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 ) wParam=code[ 0 ]; INVOKE_WCB( *window, KeyboardUp,