]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Expose a radio function (receiveBeacon) to the Nasal subsystem
[flightgear.git] / src / Main / fg_init.cxx
index 3a3bad44f380c4da9411890ff413776315f814bd..807606916fe2dfd61e2b8ef942d0398ce8a5c909 100644 (file)
@@ -56,6 +56,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
 #include <simgear/structure/event_mgr.hxx>
+#include <simgear/structure/SGPerfMon.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/sg_dir.hxx>
 #include <simgear/misc/sgstream.hxx>
 #include <Traffic/TrafficMgr.hxx>
 #include <MultiPlayer/multiplaymgr.hxx>
 #include <FDM/fdm_shell.hxx>
-
+#include <Environment/ephemeris.hxx>
 #include <Environment/environment_mgr.hxx>
 
 #include "fg_init.hxx"
@@ -338,6 +339,29 @@ public:
     }
     
     _searchAircraft = aircraft + "-set.xml";
+    std::string aircraftDir = fgGetString("/sim/aircraft-dir", "");
+    if (!aircraftDir.empty()) {
+      // aircraft-dir was set, skip any searching at all, if it's valid
+      simgear::Dir acPath(aircraftDir);
+      SGPath setFile = acPath.file(_searchAircraft);
+      if (setFile.exists()) {
+        SG_LOG(SG_GENERAL, SG_INFO, "found aircraft in dir: " << aircraftDir );
+        
+        try {
+          readProperties(setFile.str(), globals->get_props());
+        } catch ( const sg_exception &e ) {
+          SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
+          return false;
+        }
+        
+        return true;
+      } else {
+        SG_LOG(SG_GENERAL, SG_ALERT, "aircraft '" << _searchAircraft << 
+               "' not found in specified dir:" << aircraftDir);
+        return false;
+      }
+    }
+    
     if (!checkCache()) {
       // prepare cache for re-scan
       SGPropertyNode *n = _cache->getNode("fg-root", true);
@@ -491,32 +515,19 @@ static SGPath platformDefaultDataPath()
 #endif
 
 // Read in configuration (file and command line)
-bool fgInitConfig ( int argc, char **argv ) {
-
-    flightgear::Options::sharedInstance()->init(argc, argv);
-  
-    // Read global preferences from $FG_ROOT/preferences.xml
-    SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
-    fgLoadProps("preferences.xml", globals->get_props());
-    SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
-
-    // Detect the required language as early as possible
-    if ( !fgDetectLanguage() ) {
-        return false;
-    }
-
-    SGPropertyNode autosave;
+bool fgInitConfig ( int argc, char **argv )
+{
     SGPath dataPath = platformDefaultDataPath();
-  
+    
     const char *fg_home = getenv("FG_HOME");
     if (fg_home)
-        dataPath = fg_home;
-  
+      dataPath = fg_home;
+    
     simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
     if (!exportDir.exists()) {
       exportDir.create(0777);
     }
-
+    
     // Set /sim/fg-home and don't allow malign code to override it until
     // Nasal security is set up.  Use FG_HOME if necessary.
     SGPropertyNode *home = fgGetNode("/sim", true);
@@ -524,6 +535,21 @@ bool fgInitConfig ( int argc, char **argv ) {
     home = home->getChild("fg-home", 0, true);
     home->setStringValue(dataPath.c_str());
     home->setAttribute(SGPropertyNode::WRITE, false);
+  
+    flightgear::Options::sharedInstance()->init(argc, argv, dataPath);
+  
+    // Read global preferences from $FG_ROOT/preferences.xml
+    SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
+    fgLoadProps("preferences.xml", globals->get_props());
+    SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
+
+    // Detect the required language as early as possible
+    if ( !fgDetectLanguage() ) {
+        return false;
+    }
+
+    SGPropertyNode autosave;
+
 
     SGPath autosaveFile = simgear::Dir(dataPath).file("autosave.xml");
     if (autosaveFile.exists()) {
@@ -535,7 +561,7 @@ bool fgInitConfig ( int argc, char **argv ) {
             << "(from " << e.getOrigin() << ")");
       }
     }
-    
+  
   // Scan user config files and command line for a specified aircraft.
     flightgear::Options::sharedInstance()->initAircraft();
       
@@ -1151,16 +1177,19 @@ bool fgInitGeneral() {
 // gear, its initialization call should located in this routine.
 // Returns non-zero if a problem encountered.
 bool fgInitSubsystems() {
-    // static const SGPropertyNode *longitude
-    //     = fgGetNode("/sim/presets/longitude-deg");
-    // static const SGPropertyNode *latitude
-    //     = fgGetNode("/sim/presets/latitude-deg");
-    // static const SGPropertyNode *altitude
-    //     = fgGetNode("/sim/presets/altitude-ft");
 
     SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
     SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the sound subsystem.
+    ////////////////////////////////////////////////////////////////////
+    // Sound manager uses an own subsystem group "SOUND" which is the last
+    // to be updated in every loop.
+    // Sound manager is updated last so it can use the CPU while the GPU
+    // is processing the scenery (doubled the frame-rate for me) -EMH-
+    globals->add_subsystem("sound", new SGSoundMgr, SGSubsystemMgr::SOUND);
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the event manager subsystem.
     ////////////////////////////////////////////////////////////////////
@@ -1180,6 +1209,14 @@ bool fgInitSubsystems() {
     ////////////////////////////////////////////////////////////////////
     globals->add_subsystem("properties", new FGProperties);
 
+
+    ////////////////////////////////////////////////////////////////////
+    // Add the performance monitoring system.
+    ////////////////////////////////////////////////////////////////////
+    globals->add_subsystem("performance-mon",
+            new SGPerformanceMonitor(globals->get_subsystem_mgr(),
+                                     fgGetNode("/sim/performance-monitor", true)));
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the material property subsystem.
     ////////////////////////////////////////////////////////////////////
@@ -1214,7 +1251,8 @@ bool fgInitSubsystems() {
 
     // Initialize the weather modeling subsystem
     globals->add_subsystem("environment", new FGEnvironmentMgr);
-
+    globals->add_subsystem("ephemeris", new Ephemeris);
+    
     ////////////////////////////////////////////////////////////////////
     // Initialize the aircraft systems and instrumentation (before the
     // autopilot.)
@@ -1262,9 +1300,7 @@ bool fgInitSubsystems() {
     // sub system infrastructure.
     ////////////////////////////////////////////////////////////////////
 
-    SG_LOG(SG_GENERAL, SG_INFO, "  ATC Manager");
-    globals->set_ATC_mgr(new FGATCMgr);
-    globals->get_ATC_mgr()->init(); 
+    globals->add_subsystem("ATC-old", new FGATCMgr, SGSubsystemMgr::INIT);
 
     ////////////////////////////////////////////////////////////////////
    // Initialize the ATC subsystem
@@ -1286,14 +1322,14 @@ bool fgInitSubsystems() {
     // Initialise the AI Model Manager
     ////////////////////////////////////////////////////////////////////
     SG_LOG(SG_GENERAL, SG_INFO, "  AI Model Manager");
-    globals->add_subsystem("ai_model", new FGAIManager, SGSubsystemMgr::POST_FDM);
-    globals->add_subsystem("submodel_mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);
+    globals->add_subsystem("ai-model", new FGAIManager, SGSubsystemMgr::POST_FDM);
+    globals->add_subsystem("submodel-mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);
 
 
     // It's probably a good idea to initialize the top level traffic manager
     // After the AI and ATC systems have been initialized properly.
     // AI Traffic manager
-    globals->add_subsystem("Traffic Manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
+    globals->add_subsystem("traffic-manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
 
     ////////////////////////////////////////////////////////////////////
     // Add a new 2D panel.
@@ -1428,7 +1464,7 @@ void fgReInitSubsystems()
     
     // Force reupdating the positions of the ai 3d models. They are used for
     // initializing ground level for the FDM.
-    globals->get_subsystem("ai_model")->reinit();
+    globals->get_subsystem("ai-model")->reinit();
 
     // Initialize the FDM
     globals->get_subsystem("flight")->reinit();