]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Various floating point / initial value bug fixes from Christian Mayer.
[flightgear.git] / src / Main / fg_init.cxx
index 1550b111b97138d8cdc32fff45baf3af416bfac1..5419fcd040a421a6c6c44a009cee0d98375fe68e 100644 (file)
@@ -52,6 +52,7 @@
 #endif
 
 #include <simgear/compiler.h>
+#include <simgear/misc/exception.hxx>
 
 #include STL_STRING
 
 #include "fg_props.hxx"
 #include "options.hxx"
 #include "globals.hxx"
+#include "viewmgr.hxx"
 
 #if defined(FX) && defined(XMESA)
 #include <GL/xmesa.h>
@@ -181,6 +183,30 @@ bool fgInitFGRoot ( int argc, char **argv ) {
 }
 
 
+// Return the current base package version
+string fgBasePackageVersion() {
+    SGPath base_path( globals->get_fg_root() );
+    base_path.append("version");
+
+    sg_gzifstream in( base_path.str() );
+    if ( !in.is_open() ) {
+       SGPath old_path( globals->get_fg_root() );
+       old_path.append( "Thanks" );
+       sg_gzifstream old( old_path.str() );
+       if ( !old.is_open() ) {
+           return "[none]";
+       } else {
+           return "[old version]";
+       }
+    }
+
+    string version;
+    in >> version;
+
+    return version;
+}
+
+
 // Read in configuration (file and command line)
 bool fgInitConfig ( int argc, char **argv ) {
 
@@ -191,12 +217,15 @@ bool fgInitConfig ( int argc, char **argv ) {
     SGPath props_path(globals->get_fg_root());
     props_path.append("preferences.xml");
     SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
-    if (!readProperties(props_path.str(), globals->get_props())) {
-      SG_LOG(SG_INPUT, SG_ALERT, "Failed to read global preferences from "
-            << props_path.str());
-    } else {
-      SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
+    try {
+      readProperties(props_path.str(), globals->get_props());
+    } catch (const sg_exception &e) {
+      string message = "Error reading global preferences: ";
+      message += e.getFormattedMessage();
+      SG_LOG(SG_INPUT, SG_ALERT, message);
+      exit(2);
     }
+    SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
 
     // Attempt to locate and parse the various config files in order
     // from least precidence to greatest precidence
@@ -509,24 +538,30 @@ bool fgInitSubsystems( void ) {
 
     aircraft_dir = fgGetString("/sim/aircraft-dir");
     const string &model = fgGetString("/sim/flight-model");
-    if (model == "larcsim") {
-       cur_fdm_state = new FGLaRCsim( dt );
-    } else if (model == "jsb") {
-       cur_fdm_state = new FGJSBsim( dt );
-    } else if (model == "ada") {
-       cur_fdm_state = new FGADA( dt );
-    } else if (model == "balloon") {
-       cur_fdm_state = new FGBalloonSim( dt );
-    } else if (model == "magic") {
-       cur_fdm_state = new FGMagicCarpet( dt );
-    } else if (model == "external") {
-       cur_fdm_state = new FGExternal( dt );
-    } else {
-       SG_LOG(SG_GENERAL, SG_ALERT,
-              "Unrecognized flight model '" << model
-              << ", can't init aircraft");
+    try {
+       if (model == "larcsim") {
+           cur_fdm_state = new FGLaRCsim( dt );
+       } else if (model == "jsb") {
+           cur_fdm_state = new FGJSBsim( dt );
+       } else if (model == "ada") {
+           cur_fdm_state = new FGADA( dt );
+       } else if (model == "balloon") {
+           cur_fdm_state = new FGBalloonSim( dt );
+       } else if (model == "magic") {
+           cur_fdm_state = new FGMagicCarpet( dt );
+       } else if (model == "external") {
+           cur_fdm_state = new FGExternal( dt );
+       } else {
+           SG_LOG(SG_GENERAL, SG_ALERT,
+                  "Unrecognized flight model '" << model
+                  << ", can't init aircraft");
+           exit(-1);
+       }
+    } catch ( ... ) {
+       SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
        exit(-1);
     }
+
     cur_fdm_state->init();
     cur_fdm_state->bind();
     
@@ -625,19 +660,35 @@ bool fgInitSubsystems( void ) {
     sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
               current_aircraft.fdm_state->get_Longitude(),
               current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
-    FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 
+    double init_vis = fgGetDouble("/environment/visibility-m");
+
+    FGLocalWeatherDatabase::DatabaseWorkingType working_type;
+
+    if (fgGetString("/environment/weather/working-type") == "internet")
+    {
+      working_type = FGLocalWeatherDatabase::use_internet;
+    } else {
+      working_type = FGLocalWeatherDatabase::default_mode;
+    }
+    
+    if ( init_vis > 0 ) {
+      FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 
+       new FGLocalWeatherDatabase( position,
+                                   globals->get_fg_root(),
+                                    working_type,
+                                    init_vis );
+    } else {
+      FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 
        new FGLocalWeatherDatabase( position,
-                                   globals->get_fg_root() );
+                                   globals->get_fg_root(),
+                                    working_type );
+    }
+
     // cout << theFGLocalWeatherDatabase << endl;
     // cout << "visibility = " 
     //      << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
 
     WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
-    
-    double init_vis = fgGetDouble("/environment/visibility-m");
-    if ( init_vis > 0 ) {
-       WeatherDatabase->setWeatherVisibility( init_vis );
-    }
 
     // register the periodic update of the weather
     global_events.Register( "weather update", fgUpdateWeatherDatabase,
@@ -758,8 +809,8 @@ bool fgInitSubsystems( void ) {
     // Initialize the controls subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    controls.init();
-    controls.bind();
+    globals->get_controls()->init();
+    globals->get_controls()->bind();
 
 
     ////////////////////////////////////////////////////////////////////
@@ -833,7 +884,7 @@ void fgReInitSubsystems( void )
 
     cur_fdm_state->init();
 
-    controls.reset_all();
+    globals->get_controls()->reset_all();
     current_autopilot->reset();
 
     fgUpdateSunPos();