]> git.mxchange.org Git - flightgear.git/commitdiff
Beginning work on compensating for sim time vs. real world time "jitter".
authorcurt <curt>
Fri, 8 Jan 1999 03:23:51 +0000 (03:23 +0000)
committercurt <curt>
Fri, 8 Jan 1999 03:23:51 +0000 (03:23 +0000)
FDM/flight.cxx
FDM/flight.hxx
Main/GLUTmain.cxx
Main/fg_init.cxx

index cadf164c7d2748b1ef3e99e4060f2892ba73b0ba..3225b32270a7f5ca0e08b1b5ff97374e4fbcc9fa 100644 (file)
 #include <Math/fg_geodesy.hxx>
 
 
+// base_fdm_state is the internal state that is updated in integer
+// multiples of "dt".  This leads to "jitter" with respect to the real
+// world time, so we introduce cur_fdm_state which is extrapolated by
+// the difference between sim time and real world time
+
 FGState cur_fdm_state;
+FGState base_fdm_state;
 
 
 // Initialize the flight model parameters
 int fgFlightModelInit(int model, FGState& f, double dt) {
     double save_alt = 0.0;
-    int result;
 
     FG_LOG( FG_FLIGHT ,FG_INFO, "Initializing flight model" );
 
+    base_fdm_state = f;
+
     if ( model == FGState::FG_SLEW ) {
        // fgSlewInit(dt);
     } else if ( model == FGState::FG_LARCSIM ) {
+
        // lets try to avoid really screwing up the LaRCsim model
-       if ( f.get_Altitude() < -9000.0 ) {
-           save_alt = f.get_Altitude();
-           f.set_Altitude( 0.0 );
+       if ( base_fdm_state.get_Altitude() < -9000.0 ) {
+           save_alt = base_fdm_state.get_Altitude();
+           base_fdm_state.set_Altitude( 0.0 );
        }
 
-       FGState_2_LaRCsim(f);  // translate FG to LaRCsim structure
+       // translate FG to LaRCsim structure
+       FGState_2_LaRCsim(base_fdm_state);
+
+       // initialize LaRCsim
        fgLaRCsimInit(dt);
-       FG_LOG( FG_FLIGHT, FG_INFO, "FG pos = " << f.get_Latitude() );
-       fgLaRCsim_2_FGState(f);  // translate LaRCsim back to FG structure
+
+       FG_LOG( FG_FLIGHT, FG_INFO, "FG pos = " << 
+               base_fdm_state.get_Latitude() );
+
+       // translate LaRCsim back to FG structure
+       fgLaRCsim_2_FGState(base_fdm_state);
 
        // but lets restore our original bogus altitude when we are done
        if ( save_alt < -9000.0 ) {
-           f.set_Altitude( save_alt );
+           base_fdm_state.set_Altitude( save_alt );
        }
     } else if ( model == FGState::FG_EXTERNAL ) {
-       fgExternalInit(f, dt);
+       fgExternalInit(base_fdm_state, dt);
     } else {
        FG_LOG( FG_FLIGHT, FG_WARN,
                  "Unimplemented flight model == " << model );
     }
 
-    result = 1;
+    f = base_fdm_state;
 
-    return(result);
+    return 1;
 }
 
 
 // Run multiloop iterations of the flight model
-int fgFlightModelUpdate(int model, FGState& f, int multiloop) {
+int fgFlightModelUpdate(int model, FGState& f, int multiloop, int jitter) {
     double time_step, start_elev, end_elev;
-    int result;
+
     // printf("Altitude = %.2f\n", FG_Altitude * 0.3048);
 
+    // base_fdm_state = f;
+
     time_step = (1.0 / DEFAULT_MODEL_HZ) * multiloop;
-    start_elev = f.get_Altitude();
+    start_elev = base_fdm_state.get_Altitude();
 
     if ( model == FGState::FG_SLEW ) {
        // fgSlewUpdate(f, multiloop);
     } else if ( model == FGState::FG_LARCSIM ) {
-       fgLaRCsimUpdate(f, multiloop);
+       fgLaRCsimUpdate(base_fdm_state, multiloop);
     } else if ( model == FGState::FG_EXTERNAL ) {
        // fgExternalUpdate(f, multiloop);
     } else {
@@ -95,40 +112,44 @@ int fgFlightModelUpdate(int model, FGState& f, int multiloop) {
                "Unimplemented flight model == " <<  model );
     }
 
-    end_elev = f.get_Altitude();
+    end_elev = base_fdm_state.get_Altitude();
 
     if ( time_step > 0.0 ) {
        // feet per second
-       f.set_Climb_Rate( (end_elev - start_elev) / time_step );
+       base_fdm_state.set_Climb_Rate( (end_elev - start_elev) / time_step );
     }
 
-    result = 1;
+    f = base_fdm_state;
 
-    return(result);
+    return 1;
 }
 
 
 // Set the altitude (force)
-void fgFlightModelSetAltitude(int model, FGState& f, double alt_meters) {
+void fgFlightModelSetAltitude(int model, double alt_meters) {
     double sea_level_radius_meters;
     double lat_geoc;
+
     // Set the FG variables first
-    fgGeodToGeoc( f.get_Latitude(), alt_meters, 
+    fgGeodToGeoc( base_fdm_state.get_Latitude(), alt_meters, 
                  &sea_level_radius_meters, &lat_geoc);
 
-    f.set_Altitude( alt_meters * METER_TO_FEET );
-    f.set_Radius_to_vehicle( f.get_Altitude() + 
-                             (sea_level_radius_meters * METER_TO_FEET) );
+    base_fdm_state.set_Altitude( alt_meters * METER_TO_FEET );
+    base_fdm_state.set_Radius_to_vehicle( base_fdm_state.get_Altitude() + 
+                                         (sea_level_radius_meters * 
+                                          METER_TO_FEET) );
 
     // additional work needed for some flight models
     if ( model == FGState::FG_LARCSIM ) {
-       ls_ForceAltitude( f.get_Altitude() );
+       ls_ForceAltitude( base_fdm_state.get_Altitude() );
     }
-
 }
 
 
 // $Log$
+// Revision 1.8  1999/01/08 03:23:51  curt
+// Beginning work on compensating for sim time vs. real world time "jitter".
+//
 // Revision 1.7  1998/12/18 23:37:07  curt
 // Collapsed out the FGState variables not currently needed.  They are just
 // commented out and can be readded easily at any time.  The point of this
index fdd514bd18a96c254a7cc28d4c3a81ce5500a801..17d3c47332b45fab30f7433d429ca2b6866f8400 100644 (file)
@@ -781,16 +781,19 @@ extern FGState cur_fdm_state;
 int fgFlightModelInit(int model, FGState& f, double dt);
 
 // Run multiloop iterations of the flight model
-int fgFlightModelUpdate(int model, FGState& f, int multiloop);
+int fgFlightModelUpdate(int model, FGState& f, int multiloop, int jitter);
 
 // Set the altitude (force)
-void fgFlightModelSetAltitude(int model, FGState& f, double alt_meters);
+void fgFlightModelSetAltitude(int model, double alt_meters);
 
 
 #endif // _FLIGHT_HXX
 
 
 // $Log$
+// Revision 1.8  1999/01/08 03:23:52  curt
+// Beginning work on compensating for sim time vs. real world time "jitter".
+//
 // Revision 1.7  1998/12/18 23:37:09  curt
 // Collapsed out the FGState variables not currently needed.  They are just
 // commented out and can be readded easily at any time.  The point of this
index 261df03cb09faeca348ccf2e7f506d3d641c9fd9..1b25327f8534e350ca3532ac90d78ef3b2731a72 100644 (file)
@@ -367,7 +367,7 @@ static void fgRenderFrame( void ) {
 
 
 // Update internal time dependent calculations (i.e. flight model)
-void fgUpdateTimeDepCalcs(int multi_loop) {
+void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
     FGState *f = current_aircraft.fdm_state;
     fgLIGHT *l = &cur_light_params;
     fgTIME *t = &cur_time_params;
@@ -385,10 +385,10 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
 
        // printf("updating flight model x %d\n", multi_loop);
        fgFlightModelUpdate( current_options.get_flight_model(), 
-                            cur_fdm_state, multi_loop );
+                            cur_fdm_state, multi_loop, remainder );
     } else {
        fgFlightModelUpdate( current_options.get_flight_model(), 
-                            cur_fdm_state, 0 );
+                            cur_fdm_state, 0, remainder );
     }
 
     // update the view angle
@@ -437,10 +437,9 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
 void fgInitTimeDepCalcs( void ) {
     // initialize timer
 
-#ifdef HAVE_SETITIMER
-    fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
-#endif HAVE_SETITIMER
-
+    // #ifdef HAVE_SETITIMER
+    //   fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
+    // #endif HAVE_SETITIMER
 }
 
 static const double alt_adjust_ft = 3.758099;
@@ -492,7 +491,6 @@ static void fgMainLoop( void ) {
                   scenery.cur_elev + alt_adjust_m - 3.0,
                   scenery.cur_elev + alt_adjust_m );
            fgFlightModelSetAltitude( current_options.get_flight_model(), 
-                                     cur_fdm_state, 
                                      scenery.cur_elev + alt_adjust_m );
 
            FG_LOG( FG_ALL, FG_DEBUG, 
@@ -555,7 +553,7 @@ static void fgMainLoop( void ) {
        
        // flight model
        if ( multi_loop > 0 ) {
-           fgUpdateTimeDepCalcs(multi_loop);
+           fgUpdateTimeDepCalcs(multi_loop, remainder);
        } else {
            FG_LOG( FG_ALL, FG_INFO, "Elapsed time is zero ... we're zinging" );
        }
@@ -1002,6 +1000,9 @@ int main( int argc, char **argv ) {
 
 
 // $Log$
+// Revision 1.79  1999/01/08 03:23:56  curt
+// Beginning work on compensating for sim time vs. real world time "jitter".
+//
 // Revision 1.78  1999/01/07 20:25:08  curt
 // Updated struct fgGENERAL to class FGGeneral.
 //
index d6cf46f130d04b460a5c6e42cf1b3f79284511f9..58ebc1a57ab7effc74115697171926435ddb57f7 100644 (file)
@@ -122,7 +122,7 @@ int fgInitPosition( void ) {
 // General house keeping initializations
 int fgInitGeneral( void ) {
     string root;
-    int i;
+    // int i;
 
     FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
     FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
@@ -379,6 +379,9 @@ int fgInitSubsystems( void )
 
 
 // $Log$
+// Revision 1.61  1999/01/08 03:23:57  curt
+// Beginning work on compensating for sim time vs. real world time "jitter".
+//
 // Revision 1.60  1999/01/07 20:25:09  curt
 // Updated struct fgGENERAL to class FGGeneral.
 //