]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Various mods to allow querying for nearest airport (with optional ability to
[flightgear.git] / src / Main / fg_init.cxx
index 7062ca8c62330801f4c81963ad6a4910be687320..8691347359c55581c42e880878f72e44f48217ef 100644 (file)
@@ -58,6 +58,7 @@
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/interpolator.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #ifdef FG_USE_CLOUDS_3D
 #  include <simgear/scene/sky/clouds3d/SkySceneLoader.hpp>
@@ -75,7 +76,8 @@
 #include <ATC/ATCmgr.hxx>
 #include <ATC/AIMgr.hxx>
 #include <Autopilot/auto_gui.hxx>
-#include <Autopilot/newauto.hxx>
+#include <Autopilot/route_mgr.hxx>
+#include <Autopilot/xmlauto.hxx>
 #include <Cockpit/cockpit.hxx>
 #include <Cockpit/radiostack.hxx>
 #include <Cockpit/panel.hxx>
@@ -95,6 +97,7 @@
 #include <Input/input.hxx>
 #include <Instrumentation/instrument_mgr.hxx>
 #include <Model/acmodel.hxx>
+#include <AIModel/AIManager.hxx>
 #include <Navaids/fixlist.hxx>
 #include <Navaids/ilslist.hxx>
 #include <Navaids/mkrbeacons.hxx>
 #include <Replay/replay.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
-#if defined(HAVE_PLIB_PSL)
-#include <Scripting/scriptmgr.hxx>
-#endif
+#include <Scripting/NasalSys.hxx>
 #include <Sound/fg_fx.hxx>
 #include <Systems/system_mgr.hxx>
 #include <Time/light.hxx>
@@ -604,6 +605,7 @@ bool fgInitConfig ( int argc, char **argv ) {
         } else {
             SG_LOG( SG_INPUT, SG_ALERT, "Cannot find specified aircraft: "
                     << aircraft );
+            return false;
         }
 
     } else {
@@ -1447,14 +1449,19 @@ bool fgInitSubsystems() {
     // Initialize the event manager subsystem.
     ////////////////////////////////////////////////////////////////////
 
-     globals->get_event_mgr()->bind();
      globals->get_event_mgr()->init();
+     globals->get_event_mgr()->setFreezeProperty(fgGetNode("/sim/freeze/clock"));
+
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the property interpolator subsystem
+    ////////////////////////////////////////////////////////////////////
+    globals->add_subsystem("interpolator", new SGInterpolator);
 
-     // Output event stats every 60 seconds
-     globals->get_event_mgr()->add( "SGEventMgr::print_stats()",
-                                    globals->get_event_mgr(),
-                                    &SGEventMgr::print_stats,
-                                    60000 );
+
+    ////////////////////////////////////////////////////////////////////
+    // Add the FlightGear property utilities.
+    ////////////////////////////////////////////////////////////////////
+    globals->add_subsystem("properties", new FGProperties);
 
     ////////////////////////////////////////////////////////////////////
     // Initialize the material property subsystem.
@@ -1483,10 +1490,10 @@ bool fgInitSubsystems() {
     }
 
     // cause refresh of viewer scenery timestamps every 15 seconds...
-    globals->get_event_mgr()->add( "FGTileMgr::refresh_view_timestamps()",
-                                   globals->get_tile_mgr(),
-                                   &FGTileMgr::refresh_view_timestamps,
-                                   15000 );
+    globals->get_event_mgr()->addTask( "FGTileMgr::refresh_view_timestamps()",
+                                       globals->get_tile_mgr(),
+                                       &FGTileMgr::refresh_view_timestamps,
+                                       15 );
 
     SG_LOG( SG_GENERAL, SG_DEBUG,
             "Current terrain elevation after tile mgr init " <<
@@ -1504,29 +1511,25 @@ bool fgInitSubsystems() {
     fgAircraftInit();   // In the future this might not be the case.
 
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the XML Autopilot subsystem.
+    ////////////////////////////////////////////////////////////////////
+
+    globals->add_subsystem( "xml-autopilot", new FGXMLAutopilot );
+    globals->add_subsystem( "route-manager", new FGRouteMgr );
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the view manager subsystem.
     ////////////////////////////////////////////////////////////////////
 
     fgInitView();
 
-
     ////////////////////////////////////////////////////////////////////
     // Create and register the logger.
     ////////////////////////////////////////////////////////////////////
     
     globals->add_subsystem("logger", new FGLogger);
 
-
-#if defined(HAVE_PLIB_PSL)
-    ////////////////////////////////////////////////////////////////////
-    // Create and register the script manager.
-    ////////////////////////////////////////////////////////////////////
-
-    globals->add_subsystem("scripting", new FGScriptMgr);
-#endif // HAVE_PLIB_PSL
-
-
     ////////////////////////////////////////////////////////////////////
     // Create and register the XML GUI.
     ////////////////////////////////////////////////////////////////////
@@ -1539,8 +1542,8 @@ bool fgInitSubsystems() {
     ////////////////////////////////////////////////////////////////////
 
     // update the current timezone each 30 minutes
-    globals->get_event_mgr()->add( "fgUpdateLocalTime()",
-                                   &fgUpdateLocalTime, 30*60*1000 );
+    globals->get_event_mgr()->addTask( "fgUpdateLocalTime()",
+                                       &fgUpdateLocalTime, 30*60 );
 
 
     ////////////////////////////////////////////////////////////////////
@@ -1659,6 +1662,14 @@ bool fgInitSubsystems() {
     globals->get_AI_mgr()->init();
 
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialise the AI Model Manager
+    ////////////////////////////////////////////////////////////////////
+
+    SG_LOG(SG_GENERAL, SG_INFO, "  AI Model Manager");
+    globals->add_subsystem("ai_model", new FGAIManager);
+
+
 #ifdef ENABLE_AUDIO_SUPPORT
     ////////////////////////////////////////////////////////////////////
     // Initialize the sound subsystem.
@@ -1705,13 +1716,9 @@ bool fgInitSubsystems() {
     // Initialize the autopilot subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    globals->set_autopilot(new FGAutopilot);
-    globals->get_autopilot()->init();
-    globals->get_autopilot()->bind();
-
                                 // FIXME: these should go in the
                                 // GUI initialization code, not here.
-    fgAPAdjustInit();
+    // fgAPAdjustInit();
     NewTgtAirportInit();
     NewHeadingInit();
     NewAltitudeInit();
@@ -1742,13 +1749,6 @@ bool fgInitSubsystems() {
     }
 
     
-    ////////////////////////////////////////////////////////////////////
-    // Initialize the default (kludged) properties.
-    ////////////////////////////////////////////////////////////////////
-
-    fgInitProps();
-
-
     ////////////////////////////////////////////////////////////////////
     // Initialize the controls subsystem.
     ////////////////////////////////////////////////////////////////////
@@ -1788,6 +1788,14 @@ bool fgInitSubsystems() {
     globals->get_multiplayer_rx_mgr()->init();
 #endif
 
+    ////////////////////////////////////////////////////////////////////////
+    // Initialize the Nasal interpreter.
+    // Do this last, so that the loaded scripts see initialized state
+    ////////////////////////////////////////////////////////////////////////
+    FGNasalSys* nasal = new FGNasalSys();
+    globals->add_subsystem("nasal", nasal);
+    nasal->init();
+
     ////////////////////////////////////////////////////////////////////////
     // End of subsystem initialization.
     ////////////////////////////////////////////////////////////////////
@@ -1821,6 +1829,7 @@ void fgReInitSubsystems()
     if ( !freeze ) {
         fgSetBool("/sim/freeze/master", true);
     }
+    fgSetBool("/sim/crashed", false);
 
     // Initialize the FDM
     fgInitFDM();
@@ -1835,7 +1844,6 @@ void fgReInitSubsystems()
     fgInitView();
 
     globals->get_controls()->reset_all();
-    globals->get_autopilot()->reset();
 
     fgUpdateLocalTime();