From e4d747e7ac9da4da8617459050735d96ad4518d5 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 18 Dec 1998 23:40:55 +0000 Subject: [PATCH] New frame rate counting mechanism. --- Main/GLUTmain.cxx | 76 ++++++++++++++++++++++++++--------------------- Main/fg_init.cxx | 9 ++++-- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index 38879b54e..572e69215 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -454,8 +454,10 @@ static void fgMainLoop( void ) { fgTIME *t; static int remainder = 0; int elapsed, multi_loop; - int i; - double accum; + // int i; + // double accum; + static time_t last_time = 0; + static int frames = 0; f = current_aircraft.fdm_state; g = &general; @@ -464,6 +466,15 @@ static void fgMainLoop( void ) { FG_LOG( FG_ALL, FG_DEBUG, "Running Main Loop"); FG_LOG( FG_ALL, FG_DEBUG, "======= ==== ===="); +#if defined( ENABLE_LINUX_JOYSTICK ) + // Read joystick and update control settings + fgJoystickRead(); +#elif defined( ENABLE_GLUT_JOYSTICK ) + // Glut joystick support works by feeding a joystick handler + // function to glut. This is taken care of once in the joystick + // init routine and we don't have to worry about it again. +#endif + current_weather.Update(); // Fix elevation. I'm just sticking this here for now, it should @@ -501,15 +512,6 @@ static void fgMainLoop( void ) { // update "time" fgTimeUpdate(f, t); -#if defined( ENABLE_LINUX_JOYSTICK ) - // Read joystick and update control settings - fgJoystickRead(); -#elif defined( ENABLE_GLUT_JOYSTICK ) - // Glut joystick support works by feeding a joystick handler - // function to glut. This is taken care of once in the joystick - // init routine and we don't have to worry about it again. -#endif - // Get elapsed time for this past frame elapsed = fgGetTimeInterval(); FG_LOG( FG_ALL, FG_BULK, @@ -517,7 +519,15 @@ static void fgMainLoop( void ) { << ", previous remainder is = " << remainder ); // Calculate frame rate average - if ( elapsed > 0.0 ) { + if ( (t->cur_time != last_time) && (last_time > 0) ) { + g->frame_rate = frames; + frames = 0; + } + last_time = t->cur_time; + ++frames; + + /* old fps calculation + if ( elapsed > 0 ) { accum = 0.0; for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) { accum += g->frames[i]; @@ -530,34 +540,29 @@ static void fgMainLoop( void ) { g->frame_rate = accum / (float)FG_FRAME_RATE_HISTORY; // printf("ave = %.2f\n", g->frame_rate); } - - // Calculate model iterations needed for next frame - FG_LOG( FG_ALL, FG_DEBUG, - "--> Frame rate is = " << g->frame_rate ); - elapsed += remainder; - - multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ); - remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ); - FG_LOG( FG_ALL, FG_BULK, - "Model iterations needed = " << multi_loop - << ", new remainder = " << remainder ); - - /* printf("right before fm - ground = %.2f runway = %.2f alt = %.2f\n", - scenery.cur_elev, - FG_Runway_altitude * FEET_TO_METER, - FG_Altitude * FEET_TO_METER); */ + */ // Run flight model if ( ! use_signals ) { + // Calculate model iterations needed for next frame + FG_LOG( FG_ALL, FG_DEBUG, + "--> Frame rate is = " << g->frame_rate ); + elapsed += remainder; + + multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ); + remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ); + FG_LOG( FG_ALL, FG_BULK, + "Model iterations needed = " << multi_loop + << ", new remainder = " << remainder ); + // flight model - fgUpdateTimeDepCalcs(multi_loop); + if ( multi_loop > 0 ) { + fgUpdateTimeDepCalcs(multi_loop); + } else { + FG_LOG( FG_ALL, FG_INFO, "Elapsed time is zero ... we're zinging" ); + } } - /* printf("After fm - ground = %.2f runway = %.2f alt = %.2f\n", - scenery.cur_elev, - FG_Runway_altitude * FEET_TO_METER, - FG_Altitude * FEET_TO_METER); */ - // Do any serial port work that might need to be done fgSerialProcess(); @@ -1002,6 +1007,9 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.77 1998/12/18 23:40:55 curt +// New frame rate counting mechanism. +// // Revision 1.76 1998/12/11 20:26:26 curt // Fixed view frustum culling accuracy bug so we can look out the sides and // back without tri-stripes dropping out. diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index e443fe3ac..b95f8b35b 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -140,9 +140,9 @@ int fgInitGeneral( void ) { FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << root << endl ); // prime the frame rate counter pump - for ( i = 0; i < FG_FRAME_RATE_HISTORY; i++ ) { - general.frames[i] = 0.0; - } + // for ( i = 0; i < FG_FRAME_RATE_HISTORY; i++ ) { + // general.frames[i] = 0.0; + // } return ( 1 ); } @@ -381,6 +381,9 @@ int fgInitSubsystems( void ) // $Log$ +// Revision 1.59 1998/12/18 23:40:57 curt +// New frame rate counting mechanism. +// // Revision 1.58 1998/12/09 18:50:25 curt // Converted "class fgVIEW" to "class FGView" and updated to make data // members private and make required accessor functions. -- 2.39.5