]> git.mxchange.org Git - flightgear.git/commitdiff
New frame rate counting mechanism.
authorcurt <curt>
Fri, 18 Dec 1998 23:40:55 +0000 (23:40 +0000)
committercurt <curt>
Fri, 18 Dec 1998 23:40:55 +0000 (23:40 +0000)
Main/GLUTmain.cxx
Main/fg_init.cxx

index 38879b54e8317ba1b825662f57bdd9aec8df9097..572e69215fafa0bcfbe693fa72dbca3ee3bf3539 100644 (file)
@@ -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.
index e443fe3ac6f984bd5db087fb9004a0db4bc0f435..b95f8b35b34a8837eadce8c3fab87428abd5f6fd 100644 (file)
@@ -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.