]> git.mxchange.org Git - flightgear.git/commitdiff
Clean ups to the code that determines initial position based on command
authorcurt <curt>
Sat, 16 Nov 2002 21:34:51 +0000 (21:34 +0000)
committercurt <curt>
Sat, 16 Nov 2002 21:34:51 +0000 (21:34 +0000)
line options or defaults.

src/GUI/apt_dlg.cxx
src/GUI/gui_local.cxx
src/Main/fg_init.cxx
src/Main/fg_init.hxx
src/Main/main.cxx

index c45505545178e4368a04978365334ca8e3ffee42..d751977c73869e472012722a1fc26c0161cfe8e7 100644 (file)
@@ -92,21 +92,18 @@ void AptDialog_OK (puObject *)
             cur_fdm_state->unbind();
         
             AptId = a.id.c_str();  /// NHV fix wrong case crash
-            fgSetString("/sim/presets/airport-id",  AptId.c_str() );
-            // fgSetDouble("/position/altitude-ft", -9999.0 );
-            // fgSetPosFromAirportID( AptId );
-            fgSetPosFromAirportIDandHdg( AptId, 
-                                         cur_fdm_state->get_Psi() *
-                                         SGD_RADIANS_TO_DEGREES);
-            fgSetTowerPosFromAirportID( AptId, 
-                                        cur_fdm_state->get_Psi() *
-                                        SGD_RADIANS_TO_DEGREES);
+            fgSetString("/sim/presets/airport-id", AptId.c_str() );
+            fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
+            fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
+            fgInitPosition();
+
             // BusyCursor(0);
             fgReInitSubsystems();
            double visibility_meters =
-             fgGetDouble("/environment/visibility-m");
+                fgGetDouble("/environment/visibility-m");
             global_tile_mgr.update( longitude->getDoubleValue(),
-                                    latitude->getDoubleValue(),visibility_meters );
+                                    latitude->getDoubleValue(),
+                                    visibility_meters );
             // BusyCursor(1);
         } else {
             AptId  += " not in database.";
index 329c823410f67eb049690de45a82ed2aa149e361..1342ce2f83516409c6534f5d2168b904e07508a2 100644 (file)
@@ -73,13 +73,6 @@ void reInit(puObject *cb)
 
     globals->restoreInitialState();
 
-    // Unsuccessful KLUDGE to fix the 'every other time'
-    // problem when doing a 'reset' after a 'goto airport'
-       
-    // string AptId( fgGetString("/sim/presets/airport-id") );
-    // if( AptId.c_str() != "\0" )
-    //      fgSetPosFromAirportID( AptId );
-       
     SGTime *t = globals->get_time_params();
     delete t;
     t = fgInitTime();
@@ -87,10 +80,9 @@ void reInit(puObject *cb)
 
     fgReInitSubsystems();
 
-    // reduntant(fgReInitSubsystems) ?
-    double visibility_meters = fgGetDouble("/environment/visibility-m");
     global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
-                            fgGetDouble("/position/latitude-deg"),visibility_meters );
+                            fgGetDouble("/position/latitude-deg"),
+                            fgGetDouble("/environment/visibility-m") );
     
     cur_light_params.Update();
 
index 4f2f996da2ad3a25a471c27476ddf3a99510c874..e876fd6a346b3f33d834cc20367f2dc3bd12460a 100644 (file)
@@ -577,7 +577,7 @@ bool fgFindAirportID( const string& id, FGAirport *a ) {
 
 
 // Preset lon/lat given an airport id
-bool fgSetPosFromAirportID( const string& id ) {
+static bool fgSetPosFromAirportID( const string& id ) {
     FGAirport a;
     // double lon, lat;
 
@@ -608,7 +608,7 @@ bool fgSetPosFromAirportID( const string& id ) {
 
 
 // Set current tower position lon/lat given an airport id
-bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
+static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
     FGAirport a;
     // tower height hard coded for now...
     float towerheight=50.0f;
@@ -630,7 +630,7 @@ bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
 
 
 // Set current_options lon/lat given an airport id and heading (degrees)
-bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
+static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
     FGRunway r;
     FGRunway found_r;
     double found_dir = 0.0;
@@ -756,36 +756,83 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
 }
 
 
-void fgSetPosFromGlideSlope() {
+static void fgSetDistOrAltFromGlideSlope() {
     double gs = fgGetDouble("/sim/presets/glideslope");
     double od = fgGetDouble("/sim/presets/offset-distance");
     double alt = fgGetDouble("/sim/presets/altitude-ft");
     
-    // if glideslope and offset-distance are set and altitude is not,
-    // calculate the initial altitude
     if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
+        // set altitude from glideslope and offset-distance
         od *= SG_NM_TO_METER * SG_METER_TO_FEET;
         alt = fabs(od*tan(gs));
-        fgSetDouble("/sim/presets/altitude-ft",alt);
+        fgSetDouble("/sim/presets/altitude-ft", alt);
         fgSetBool("/sim/presets/onground", false);
         SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt  << " ft");
     } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
+        // set offset-distance from glideslope and altitude
         od  = alt/tan(gs);
         od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
-        fgSetDouble("/sim/presets/offset-distance",od);
+        fgSetDouble("/sim/presets/offset-distance", od);
         SG_LOG(SG_GENERAL, SG_INFO, "Calculated offset distance as: " 
                                        << od  << " nm");
     } else if( fabs(gs) > 0.01 ) {
         SG_LOG( SG_GENERAL, SG_ALERT,
                 "Glideslope given but not altitude or offset-distance." );
         SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
-        fgSetDouble("/sim/presets/glideslope",0);
+        fgSetDouble("/sim/presets/glideslope", 0);
     }                              
 }                       
 
 
+// Set the initial position based on presets (or defaults)
+bool fgInitPosition() {
+    // Calculate offset-distance or altitude relative to glide slope
+    // if either was not specified.
+    fgSetDistOrAltFromGlideSlope();
+
+    // If we have an explicit, in-range lon/lat, don't change it, just use it.
+    // If not, check for an airport-id and use that.
+    // If not, default to the middle of the KSFO field.
+    // The default values for lon/lat are deliberately out of range
+    // so that the airport-id can take effect; valid lon/lat will
+    // override airport-id, however.
+    double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
+    double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
+    if ( lon_deg >= -180.0 && lon_deg <= 180.0
+         && lat_deg >= -90.0 && lat_deg <= 90.0 )
+    {
+        // valid lon/lat specified, use it.
+    } else {
+        string apt = fgGetString("/sim/presets/airport-id");
+        double hdg = fgGetDouble("/sim/presets/heading-deg");
+        if ( !apt.empty() ) {
+            // An airport id is requested, set position from that.
+            fgSetPosFromAirportIDandHdg( apt, hdg );
+
+            // set tower position (a little off the heading for single
+            // runway airports)
+            fgSetTowerPosFromAirportID( apt, hdg );
+        } else {
+            // No lon/lat specified, no airport specified, default to
+            // middle of KSFO field.
+            fgSetDouble("/sim/presets/longitude-deg", -122.374843);
+            fgSetDouble("/sim/presets/latitude-deg", 37.619002);
+        }
+    }
+
+    fgSetDouble( "/position/longitude-deg",
+                 fgGetDouble("/sim/presets/longitude-deg") );
+    fgSetDouble( "/position/latitude-deg",
+                 fgGetDouble("/sim/presets/latitude-deg") );
+    fgSetDouble( "/orientation/heading-deg",
+                 fgGetDouble("/sim/presets/heading-deg") );
+
+    return true;
+}
+
+
 // General house keeping initializations
-bool fgInitGeneral( void ) {
+bool fgInitGeneral() {
     string root;
 
 #if defined(FX) && defined(XMESA)
index d967c44c5a8a838a8822dab6e2743518eed5d1ea..cd529cc6f24a361a531c7ba68fccbd09c3c3aabf 100644 (file)
@@ -79,18 +79,8 @@ void fgReInitSubsystems( void );
 // find basic airport location info from airport database
 bool fgFindAirportID( const string& id, FGAirport *a );
 
-// Set pos given an airport id
-bool fgSetPosFromAirportID( const string& id );
-
-// Set tower position given an airport id
-bool fgSetTowerPosFromAirportID( const string& id, double hdg );
-
-// Set position and heading given an airport id and heading (degrees)
-bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg );
-
-//find altitude given glideslope and offset distance or offset distance
-//given glideslope and altitude
-void fgSetPosFromGlideSlope(void);
+// Set the initial position based on presets (or defaults)
+bool fgInitPosition();
 
 // Initialize various time dependent systems (lighting, sun position, etc.)
 // returns a new instance of the SGTime class
index b29307dac77b6446f571446b64bd5d5a94d92d28..a3b1f325f4fd3ef5893c84d93a7504c7d7a019c4 100644 (file)
@@ -1609,31 +1609,9 @@ static bool fgMainInit( int argc, char **argv ) {
 #  endif
 #endif
 
-    // Set position relative to glide slope if requested
-    fgSetPosFromGlideSlope();
-
-    // If we have an explicit, in-range lon/lat, use it.
-    // If not, check for an airport-id and use that.
-    // If not, default to the middle of the KSFO field.
-    // The default values for lon/lat are deliberately out of range
-    // so that the airport-id can take effect; valid lon/lat will
-    // override airport-id, however.
-    double lon_deg = fgGetDouble("/position/longitude-deg");
-    double lat_deg = fgGetDouble("/position/latitude-deg");
-    if (lon_deg < -180 || lon_deg > 180 || lat_deg < -90 || lat_deg > 90) {
-      if ( fgGetString("/sim/presets/airport-id")[0] != '\0' ) {
-       fgSetPosFromAirportIDandHdg( fgGetString("/sim/presets/airport-id"),
-                                    fgGetDouble("/sim/presets/heading-deg") );
-        // set tower position (a little off the heading for single 
-       // runway airports)
-        fgSetTowerPosFromAirportID( fgGetString("/sim/presets/airport-id"),
-                                   fgGetDouble("/sim/presets/heading-deg") );
-      } else {
-                               // Default to middle of KSFO field
-       fgSetDouble("/sim/presets/longitude-deg", -122.374843);
-       fgSetDouble("/sim/presets/latitude-deg", 37.619002);
-      }
-    }
+    // based on the requested presets, calculate the true starting
+    // lon, lat
+    fgInitPosition();
 
     SGTime *t = fgInitTime();
     globals->set_time_params( t );