]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / Main / fg_init.cxx
index 15fcf922e44d6c3c2405ccff4a792c57543b744c..9949478d420f7f723d797a650bff8be2cd616cb7 100644 (file)
@@ -63,6 +63,7 @@
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/scene/material/matlib.hxx>
 #ifdef FG_USE_CLOUDS_3D
 #  include <simgear/sky/clouds3d/SkySceneLoader.hpp>
 #  include <simgear/sky/clouds3d/SkyUtil.hpp>
@@ -97,8 +98,6 @@
 #include <Include/general.hxx>
 #include <Input/input.hxx>
 #include <Instrumentation/instrument_mgr.hxx>
-// #include <Joystick/joystick.hxx>
-#include <Objects/matlib.hxx>
 #include <Model/acmodel.hxx>
 #include <Navaids/fixlist.hxx>
 #include <Navaids/ilslist.hxx>
 #include <Scripting/scriptmgr.hxx>
 #endif
 #include <Sound/fg_fx.hxx>
-#include <Sound/soundmgr.hxx>
 #include <Systems/system_mgr.hxx>
 #include <Time/FGEventMgr.hxx>
 #include <Time/light.hxx>
 
 SG_USING_STD(string);
 
+
+class Sound;
+
 extern const char *default_root;
 
 #ifdef FG_USE_CLOUDS_3D
@@ -458,8 +459,8 @@ bool fgDetectLanguage() {
 
     SGPropertyNode *locale = fgInitLocale(language);
     if (!locale) {
-       cerr << "No internationalization settings specified in preferences.xml"
-            << endl;
+       SG_LOG(SG_GENERAL, SG_ALERT,
+              "No internationalization settings specified in preferences.xml" );
 
        return false;
     }
@@ -739,7 +740,7 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
 
         SG_LOG( SG_GENERAL, SG_INFO,
                 "Attempting to set starting position for "
-                << id << ":" << runway );
+                << id << ":" << rwy );
 
         if ( ! runways.search( id, rwy, &r ) ) {
             SG_LOG( SG_GENERAL, SG_ALERT,
@@ -982,7 +983,18 @@ bool fgInitPosition() {
     // If glideslope is specified, then calculate offset-distance or
     // altitude relative to glide slope if either of those was not
     // specified.
-    fgSetDistOrAltFromGlideSlope();
+    if ( fgGetDouble("/sim/presets/glideslope-deg") > 0.1 ) {
+        fgSetDistOrAltFromGlideSlope();
+    }
+
+    // Select ground or air start depending on if an altitude is
+    // specified (this choice can be refined later based on other
+    // input.)
+    if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
+        fgSetBool("/sim/presets/onground", false);
+    } else {
+        fgSetBool("/sim/presets/onground", true);
+    }
 
     // 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.
@@ -1036,33 +1048,18 @@ bool fgInitPosition() {
     if ( !set_pos && !vor.empty() ) {
         // a VOR is requested
         if ( fgSetPosFromNAV( vor, vor_freq ) ) {
-            if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
-                fgSetBool("/sim/presets/onground", false);
-            } else {
-                fgSetBool("/sim/presets/onground", true);
-            }
             set_pos = true;
         }
     }
     if ( !set_pos && !ndb.empty() ) {
         // an NDB is requested
         if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
-            if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
-                fgSetBool("/sim/presets/onground", false);
-            } else {
-                fgSetBool("/sim/presets/onground", true);
-            }
             set_pos = true;
         }
     }
     if ( !set_pos && !fix.empty() ) {
         // a Fix is requested
         if ( fgSetPosFromFix( fix ) ) {
-            if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
-                fgSetBool("/sim/presets/onground", false);
-            } else {
-                fgSetBool("/sim/presets/onground", true);
-            }
             set_pos = true;
         }
     }
@@ -1212,11 +1209,11 @@ void fgInitFDM() {
 static void printMat(const sgVec4 *mat, char *name="")
 {
     int i;
-    cout << name << endl;
+    SG_LOG(SG_GENERAL, SG_BULK, name );
     for(i=0; i<4; i++) {
-        cout <<"  "<<mat[i][0]<<" "<<mat[i][1]<<" "<<mat[i][2]<<" "<<mat[i][3]<<endl;
+        SG_LOG(SG_GENERAL, SG_BULK, "  " << mat[i][0] << " " << mat[i][1]
+                                    << " " << mat[i][2] << " " << mat[i][3] );
     }
-    cout << endl;
 }
 
 // Initialize view parameters
@@ -1298,12 +1295,12 @@ SGTime *fgInitTime() {
 // 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");
+    // 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");
 
     fgLIGHT *l = &cur_light_params;
 
@@ -1317,7 +1314,7 @@ bool fgInitSubsystems() {
 
     SGPath mpath( globals->get_fg_root() );
     mpath.append( "materials.xml" );
-    if ( ! material_lib.load( mpath.str() ) ) {
+    if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str()) ) {
         SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
         exit(-1);
     }
@@ -1523,18 +1520,17 @@ bool fgInitSubsystems() {
     // Initialise the AI Manager 
     ////////////////////////////////////////////////////////////////////
 
-    if (fgGetBool("/sim/ai-traffic/enabled")) {
-        SG_LOG(SG_GENERAL, SG_INFO, "  AI Manager");
-        globals->set_AI_mgr(new FGAIMgr);
-        globals->get_AI_mgr()->init();
-    }
+    SG_LOG(SG_GENERAL, SG_INFO, "  AI Manager");
+    globals->set_AI_mgr(new FGAIMgr);
+    globals->get_AI_mgr()->init();
+
 
 #ifdef ENABLE_AUDIO_SUPPORT
     ////////////////////////////////////////////////////////////////////
     // Initialize the sound subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    globals->set_soundmgr(new FGSoundMgr);
+    globals->set_soundmgr(new SGSoundMgr);
     globals->get_soundmgr()->init();
     globals->get_soundmgr()->bind();
 
@@ -1593,17 +1589,22 @@ bool fgInitSubsystems() {
     globals->get_io()->init();
     globals->get_io()->bind();
 
-    // Initialize the 2D panel.
+
+    ////////////////////////////////////////////////////////////////////
+    // Add a new 2D panel.
+    ////////////////////////////////////////////////////////////////////
+
     string panel_path = fgGetString("/sim/panel/path",
                                     "Panels/Default/default.xml");
-    current_panel = fgReadPanel(panel_path);
-    if (current_panel == 0) {
+
+    globals->set_current_panel( fgReadPanel(panel_path) );
+    if (globals->get_current_panel() == 0) {
         SG_LOG( SG_INPUT, SG_ALERT, 
                 "Error reading new panel from " << panel_path );
     } else {
         SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
-        current_panel->init();
-        current_panel->bind();
+        globals->get_current_panel()->init();
+        globals->get_current_panel()->bind();
     }
 
     
@@ -1665,10 +1666,10 @@ bool fgInitSubsystems() {
 
 void fgReInitSubsystems()
 {
-    static const SGPropertyNode *longitude
-        = fgGetNode("/sim/presets/longitude-deg");
-    static const SGPropertyNode *latitude
-        = fgGetNode("/sim/presets/latitude-deg");
+    // 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");
     static const SGPropertyNode *master_freeze