]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
start "voice" subsystem
[flightgear.git] / src / Main / fg_init.cxx
index 8f5c0069c35c17b5edeb400e4f321895c9d279be..be2598893cda909a7ec9207edf9a1cfd4e416591 100644 (file)
@@ -35,7 +35,6 @@
 #include <stdlib.h>
 #include <string.h>             // strcmp()
 
-
 #if defined( unix ) || defined( __CYGWIN__ )
 #  include <unistd.h>           // for gethostname()
 #endif
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Scripting/NasalSys.hxx>
+#include <Scripting/NasalDisplay.hxx>
 #include <Sound/fg_fx.hxx>
 #include <Sound/beacon.hxx>
 #include <Sound/morse.hxx>
+#include <Sound/voice.hxx>
 #include <Systems/system_mgr.hxx>
 #include <Time/light.hxx>
 #include <Time/sunsolver.hxx>
@@ -145,6 +146,14 @@ float init_volume;
 static string fgScanForOption( const string& option, int argc, char **argv ) {
     int i = 1;
 
+    if (hostname == NULL)
+    {
+        char _hostname[256];
+        gethostname(_hostname, 256);
+        hostname = strdup(_hostname);
+        free_hostname = true;
+    }
+
     SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
 
     int len = option.length();
@@ -207,45 +216,56 @@ static string fgScanForOption( const string& option, const string& path ) {
     return "";
 }
 
-
-// Read in configuration (files and command line options) but only set
-// fg_root
-bool fgInitFGRoot ( int argc, char **argv ) {
-    string root;
-
-    // First parse command line options looking for --fg-root=, this
-    // will override anything specified in a config file
-    root = fgScanForOption( "--fg-root=", argc, argv);
-
-    if (hostname == NULL)
-    {
-        char _hostname[256];
-        gethostname(_hostname, 256);
-        hostname = strdup(_hostname);
-        free_hostname = true;
-    }
+// Scan the user config files for the specified option and return
+// the value.
+static string fgScanForOption( const string& option ) {
+    string arg("");
 
 #if defined( unix ) || defined( __CYGWIN__ )
     // Next check home directory for .fgfsrc.hostname file
-    if ( root.empty() ) {
+    if ( arg.empty() ) {
         if ( homedir != NULL ) {
             SGPath config( homedir );
             config.append( ".fgfsrc" );
             config.concat( "." );
             config.concat( hostname );
-            root = fgScanForOption( "--fg-root=", config.str() );
+            arg = fgScanForOption( option, config.str() );
         }
     }
 #endif
 
     // Next check home directory for .fgfsrc file
-    if ( root.empty() ) {
+    if ( arg.empty() ) {
         if ( homedir != NULL ) {
             SGPath config( homedir );
             config.append( ".fgfsrc" );
-            root = fgScanForOption( "--fg-root=", config.str() );
+            arg = fgScanForOption( option, config.str() );
         }
     }
+
+    if ( arg.empty() ) {
+        // Check for $fg_root/system.fgfsrc
+        SGPath config( globals->get_fg_root() );
+        config.append( "system.fgfsrc" );
+        arg = fgScanForOption( option, config.str() );
+    }
+
+    return arg;
+}
+
+
+// Read in configuration (files and command line options) but only set
+// fg_root
+bool fgInitFGRoot ( int argc, char **argv ) {
+    string root;
+
+    // First parse command line options looking for --fg-root=, this
+    // will override anything specified in a config file
+    root = fgScanForOption( "--fg-root=", argc, argv);
+
+    // Check in one of the user configuration files.
+    if (root.empty() )
+        root = fgScanForOption( "--fg-root=" );
     
     // Next check if fg-root is set as an env variable
     if ( root.empty() ) {
@@ -299,40 +319,15 @@ bool fgInitFGRoot ( int argc, char **argv ) {
 // aircraft
 bool fgInitFGAircraft ( int argc, char **argv ) {
     string aircraft;
-    char* homedir = NULL;
 
     // First parse command line options looking for --aircraft=, this
     // will override anything specified in a config file
     aircraft = fgScanForOption( "--aircraft=", argc, argv );
 
-#if defined( unix ) || defined( __CYGWIN__ )
-    // Next check home directory for .fgfsrc.hostname file
-    if ( aircraft.empty() ) {
-        if ( homedir != NULL ) {
-            SGPath config( homedir );
-            config.append( ".fgfsrc" );
-            config.concat( "." );
-            config.concat( hostname );
-            aircraft = fgScanForOption( "--aircraft=", config.str() );
-        }
-    }
-#endif
-
-    // Next check home directory for .fgfsrc file
-    if ( aircraft.empty() ) {
-        if ( homedir != NULL ) {
-            SGPath config( homedir );
-            config.append( ".fgfsrc" );
-            aircraft = fgScanForOption( "--aircraft=", config.str() );
-        }
-    }
+    // Check in one of the user configuration files.
+    if ( aircraft.empty() )
+        aircraft = fgScanForOption( "--aircraft=" );
 
-    if ( aircraft.empty() ) {
-        // Check for $fg_root/system.fgfsrc
-        SGPath sysconf( globals->get_fg_root() );
-        sysconf.append( "system.fgfsrc" );
-        aircraft = fgScanForOption( "--aircraft=", sysconf.str() );
-    }
     // if an aircraft was specified, set the property name
     if ( !aircraft.empty() ) {
         SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
@@ -529,7 +524,7 @@ static string fgFindAircraftPath( const SGPath &path, const string &aircraft ) {
     while ((dire = ulReadDir(dirp)) != NULL) {
         if (dire->d_isdir) {
             if ( strcmp("CVS", dire->d_name) && strcmp(".", dire->d_name)
-                 && strcmp("..", dire->d_name) )
+                 && strcmp("..", dire->d_name) && strcmp("AI", dire->d_name))
             {
                 SGPath next = path;
                 next.append(dire->d_name);
@@ -612,15 +607,15 @@ bool fgInitConfig ( int argc, char **argv ) {
         SGPath config( homedir );
         config.append( ".fgfs" );
 #endif
-        config.append( "preferences.xml" );
-        SG_LOG(SG_INPUT, SG_INFO, "Reading user preferences");
+        config.append( "autosave.xml" );
+        SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from autosave.xml");
         try {
             fgLoadProps(config.str().c_str(), globals->get_props(), false,
                         SGPropertyNode::USERARCHIVE);
         } catch (...) {
-            SG_LOG(SG_INPUT, SG_BULK, "First time reading user preferences.");
+            SG_LOG(SG_INPUT, SG_BULK, "First time reading user settings");
         }
-        SG_LOG(SG_INPUT, SG_BULK, "Finished Reading user preferences");
+        SG_LOG(SG_INPUT, SG_BULK, "Finished Reading user settings");
     }
 
     // parse options after loading aircraft to ensure any user
@@ -631,48 +626,7 @@ bool fgInitConfig ( int argc, char **argv ) {
 }
 
 
-// find basic airport location info from airport database
-bool fgFindAirportID( const string& id, FGAirport *a ) {
-    const FGAirport* result;
-    if ( id.length() ) {
-        SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
-
-        result = globals->get_airports()->search( id );
-
-        if ( result == NULL ) {
-            SG_LOG( SG_GENERAL, SG_ALERT,
-                    "Failed to find " << id << " in apt.dat.gz" );
-            return false;
-        }
-    } else {
-        return false;
-    }
-
-    *a = *result;
-
-    SG_LOG( SG_GENERAL, SG_INFO,
-            "Position for " << id << " is ("
-            << a->getLongitude() << ", "
-            << a->getLatitude() << ")" );
-
-    return true;
-}
-
-
-// get airport elevation
-static double fgGetAirportElev( const string& id ) {
-    FGAirport a;
-    // double lon, lat;
 
-    SG_LOG( SG_GENERAL, SG_INFO,
-            "Finding elevation for airport: " << id );
-
-    if ( fgFindAirportID( id, &a ) ) {
-        return a.getElevation();
-    } else {
-        return -9999.0;
-    }
-}
 
 
 #if 0 
@@ -682,7 +636,7 @@ static double fgGetAirportElev( const string& id ) {
 
 // Preset lon/lat given an airport id
 static bool fgSetPosFromAirportID( const string& id ) {
-    FGAirport a;
+    FGAirport *a;
     // double lon, lat;
 
     SG_LOG( SG_GENERAL, SG_INFO,
@@ -690,17 +644,17 @@ static bool fgSetPosFromAirportID( const string& id ) {
 
     if ( fgFindAirportID( id, &a ) ) {
         // presets
-        fgSetDouble("/sim/presets/longitude-deg", a.longitude );
-        fgSetDouble("/sim/presets/latitude-deg", a.latitude );
+        fgSetDouble("/sim/presets/longitude-deg", a->longitude );
+        fgSetDouble("/sim/presets/latitude-deg", a->latitude );
 
         // other code depends on the actual postition being set so set
         // that as well
-        fgSetDouble("/position/longitude-deg", a.longitude );
-        fgSetDouble("/position/latitude-deg", a.latitude );
+        fgSetDouble("/position/longitude-deg", a->longitude );
+        fgSetDouble("/position/latitude-deg", a->latitude );
 
         SG_LOG( SG_GENERAL, SG_INFO,
-                "Position for " << id << " is (" << a.longitude
-                << ", " << a.latitude << ")" );
+                "Position for " << id << " is (" << a->longitude
+                << ", " << a->latitude << ")" );
 
         return true;
     } else {
@@ -712,7 +666,7 @@ static bool fgSetPosFromAirportID( const string& id ) {
 
 // Set current tower position lon/lat given an airport id
 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
-    FGAirport a;
+    
     // tower height hard coded for now...
     float towerheight=50.0f;
 
@@ -720,10 +674,11 @@ static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
     float fudge_lon = fabs(sin(hdg)) * .003f;
     float fudge_lat = .003f - fudge_lon;
 
-    if ( fgFindAirportID( id, &a ) ) {
-        fgSetDouble("/sim/tower/longitude-deg",  a.getLongitude() + fudge_lon);
-        fgSetDouble("/sim/tower/latitude-deg",  a.getLatitude() + fudge_lat);
-        fgSetDouble("/sim/tower/altitude-ft", a.getElevation() + towerheight);
+    const FGAirport *a = fgFindAirportID( id);
+    if ( a) {
+        fgSetDouble("/sim/tower/longitude-deg",  a->getLongitude() + fudge_lon);
+        fgSetDouble("/sim/tower/latitude-deg",  a->getLatitude() + fudge_lat);
+        fgSetDouble("/sim/tower/altitude-ft", a->getElevation() + towerheight);
         return true;
     } else {
         return false;
@@ -1584,7 +1539,6 @@ bool fgInitSubsystems() {
     //     = 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, "========== ==========");
 
@@ -1724,7 +1678,7 @@ bool fgInitSubsystems() {
     ////////////////////////////////////////////////////////////////////
 
     globals->add_subsystem("fx", new FGFX);
-    
+    globals->add_subsystem("voice", new FGVoiceMgr);
 #endif
 
     ////////////////////////////////////////////////////////////////////
@@ -1806,6 +1760,14 @@ bool fgInitSubsystems() {
     globals->get_io()->bind();
 
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialise Nasal display system
+    ////////////////////////////////////////////////////////////////////
+
+    SG_LOG(SG_GENERAL, SG_INFO, "  Nasal Display");
+    globals->set_Nasal_display(new FGNasalDisplay);
+    globals->get_Nasal_display()->init(); 
+
     ////////////////////////////////////////////////////////////////////
     // Add a new 2D panel.
     ////////////////////////////////////////////////////////////////////
@@ -1885,7 +1847,7 @@ bool fgInitSubsystems() {
                                 // Save the initial state for future
                                 // reference.
     globals->saveInitialState();
-
+    
     return true;
 }