]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Sync with latest JSBSim CVS
[flightgear.git] / src / Main / fg_init.cxx
index 5419fcd040a421a6c6c44a009cee0d98375fe68e..4632eb3133ec3372f5a3686b7022c776bebc3b2a 100644 (file)
@@ -68,6 +68,7 @@
 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
 #include <Airports/runways.hxx>
 #include <Airports/simple.hxx>
+#include <ATC/ATCdisplay.hxx>
 #include <Autopilot/auto_gui.hxx>
 #include <Autopilot/newauto.hxx>
 #include <Cockpit/cockpit.hxx>
@@ -80,6 +81,7 @@
 #include <FDM/JSBSim.hxx>
 #include <FDM/LaRCsim.hxx>
 #include <FDM/MagicCarpet.hxx>
+#include <FDM/NullFDM.hxx>
 #include <Include/general.hxx>
 #include <Input/input.hxx>
 // #include <Joystick/joystick.hxx>
@@ -90,6 +92,8 @@
 #include <Navaids/navlist.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
+#include <Sound/fg_fx.hxx>
+#include <Sound/soundmgr.hxx>
 #include <Time/event.hxx>
 #include <Time/light.hxx>
 #include <Time/sunpos.hxx>
@@ -455,7 +459,7 @@ bool fgInitGeneral( void ) {
     if ( ! root.length() ) {
        // No root path set? Then bail ...
        SG_LOG( SG_GENERAL, SG_ALERT,
-               "Cannot continue without environment variable FG_ROOT"
+               "Cannot continue without a path to the base package "
                << "being defined." );
        exit(-1);
     }
@@ -485,6 +489,13 @@ bool fgInitGeneral( void ) {
 // gear, its initialization call should located in this routine.
 // Returns non-zero if a problem encountered.
 bool fgInitSubsystems( void ) {
+    static const SGPropertyNode *longitude
+       = fgGetNode("/position/longitude-deg");
+    static const SGPropertyNode *latitude
+       = fgGetNode("/position/latitude-deg");
+    static const SGPropertyNode *altitude
+       = fgGetNode("/position/altitude-ft");
+
     fgLIGHT *l = &cur_light_params;
 
     SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
@@ -508,12 +519,8 @@ bool fgInitSubsystems( void ) {
     // Initialize the scenery management subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    if ( fgSceneryInit() ) {
-       // Material lib initialized ok.
-    } else {
-       SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
-       exit(-1);
-    }
+    scenery.init();
+    scenery.bind();
 
     if ( global_tile_mgr.init() ) {
        // Load the local scenery data
@@ -526,7 +533,7 @@ bool fgInitSubsystems( void ) {
 
     SG_LOG( SG_GENERAL, SG_DEBUG,
            "Current terrain elevation after tile mgr init " <<
-           scenery.cur_elev );
+           scenery.get_cur_elev() );
 
 
     ////////////////////////////////////////////////////////////////////
@@ -551,6 +558,8 @@ bool fgInitSubsystems( void ) {
            cur_fdm_state = new FGMagicCarpet( dt );
        } else if (model == "external") {
            cur_fdm_state = new FGExternal( dt );
+       } else if (model == "null") {
+           cur_fdm_state = new FGNullFDM( dt );
        } else {
            SG_LOG(SG_GENERAL, SG_ALERT,
                   "Unrecognized flight model '" << model
@@ -562,8 +571,10 @@ bool fgInitSubsystems( void ) {
        exit(-1);
     }
 
-    cur_fdm_state->init();
-    cur_fdm_state->bind();
+    // Actual fdm initialization is delayed until we get a proper
+    // scenery elevation hit.  This is checked for in main.cxx
+    // cur_fdm_state->init();
+    // cur_fdm_state->bind();
     
     // allocates structures so must happen before any of the flight
     // model or control parameters are set
@@ -587,23 +598,25 @@ bool fgInitSubsystems( void ) {
     // Initialize the view manager subsystem.
     ////////////////////////////////////////////////////////////////////
 
+#if 0  /* As this wrongly does an integer division and gets x and y the wrong way around, I guess it's not needed.  JAF */
     // Initialize win_ratio parameters
     for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
        globals->get_viewmgr()->get_view(i)->
            set_win_ratio( fgGetInt("/sim/startup/xsize") /
                           fgGetInt("/sim/startup/ysize") );
     }
+#endif
 
     // Initialize pilot view
     FGViewerRPH *pilot_view =
        (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
 
-    pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), 
-                                  cur_fdm_state->get_Lat_geocentric()
-                                  cur_fdm_state->get_Altitude() *
-                                  SG_FEET_TO_METER );
-    pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
-                                     SG_FEET_TO_METER ); 
+    pilot_view->set_geod_view_pos( longitude->getDoubleValue()
+                                    * SGD_DEGREES_TO_RADIANS
+                                  latitude->getDoubleValue()
+                                    * SGD_DEGREES_TO_RADIANS,
+                                  altitude->getDoubleValue()
+                                    * SG_FEET_TO_METER );
     pilot_view->set_rph( cur_fdm_state->get_Phi(),
                         cur_fdm_state->get_Theta(),
                         cur_fdm_state->get_Psi() );
@@ -723,6 +736,25 @@ bool fgInitSubsystems( void ) {
     p_fix.append( "Navaids/default.fix" );
     current_fixlist->init( p_fix );
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize ATC list management and query systems
+    ////////////////////////////////////////////////////////////////////
+
+    //DCL
+    SG_LOG(SG_GENERAL, SG_INFO, "  ATIS");
+    current_atislist = new FGATISList;
+    SGPath p_atis( globals->get_fg_root() );
+    p_atis.append( "ATC/default.atis" );
+    current_atislist->init( p_atis );
+
+    ////////////////////////////////////////////////////////////////////
+    // Initialise ATC display system
+    ////////////////////////////////////////////////////////////////////
+
+    //DCL
+    SG_LOG(SG_GENERAL, SG_INFO, "  ATC Display");
+    current_atcdisplay = new FGATCDisplay;
+    current_atcdisplay->init();   
 
     ////////////////////////////////////////////////////////////////////
     // Initialize the built-in commands.
@@ -730,6 +762,23 @@ bool fgInitSubsystems( void ) {
     fgInitCommands();
 
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the sound subsystem.
+    ////////////////////////////////////////////////////////////////////
+
+    globals->set_soundmgr(new FGSoundMgr);
+    globals->get_soundmgr()->init();
+    globals->get_soundmgr()->bind();
+
+
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the sound-effects subsystem.
+    ////////////////////////////////////////////////////////////////////
+    globals->set_fx(new FGFX);
+    globals->get_fx()->init();
+    globals->get_fx()->bind();
+
+
     ////////////////////////////////////////////////////////////////////
     // Initialize the radio stack subsystem.
     ////////////////////////////////////////////////////////////////////
@@ -837,26 +886,63 @@ bool fgInitSubsystems( void ) {
 
 void fgReInitSubsystems( void )
 {
+    static const SGPropertyNode *longitude
+       = fgGetNode("/position/longitude-deg");
+    static const SGPropertyNode *latitude
+       = fgGetNode("/position/latitude-deg");
+    static const SGPropertyNode *altitude
+       = fgGetNode("/position/altitude-ft");
+
     SG_LOG( SG_GENERAL, SG_INFO,
-           "/position/altitude = " << fgGetDouble("/position/altitude-ft") );
+           "/position/altitude = " << altitude->getDoubleValue() );
 
     bool freeze = globals->get_freeze();
-    if( !freeze )
+    if( !freeze ) {
         globals->set_freeze( true );
+    }
     
     // Initialize the Scenery Management subsystem
-    if ( ! fgSceneryInit() ) {
-       SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
-       exit(-1);
-    }
+    scenery.init();
 
-    if( global_tile_mgr.init() ) {
+    // if( global_tile_mgr.init() ) {
        // Load the local scenery data
-       global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
-                               fgGetDouble("/position/latitude-deg") );
-    } else {
-       SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
-               exit(-1);
+       global_tile_mgr.update( longitude->getDoubleValue(),
+                               latitude->getDoubleValue() );
+    // } else {
+       // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
+               // exit(-1);
+    // }
+
+    // Delete then Initialize the flight model subsystem.
+    delete cur_fdm_state;
+
+    double dt = 1.0 / fgGetInt("/sim/model-hz");
+    aircraft_dir = fgGetString("/sim/aircraft-dir");
+    const string &model = fgGetString("/sim/flight-model");
+    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 if (model == "null") {
+           cur_fdm_state = new FGNullFDM( 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);
     }
 
     // Initialize view parameters
@@ -866,12 +952,12 @@ void fgReInitSubsystems( void )
     pilot_view->set_view_offset( 0.0 );
     pilot_view->set_goal_view_offset( 0.0 );
 
-    pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), 
-                                  cur_fdm_state->get_Lat_geocentric()
-                                  cur_fdm_state->get_Altitude() *
-                                  SG_FEET_TO_METER );
-    pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
-                                     SG_FEET_TO_METER ); 
+    pilot_view->set_geod_view_pos( longitude->getDoubleValue()
+                                    * SGD_DEGREES_TO_RADIANS
+                                  latitude->getDoubleValue()
+                                    * SGD_DEGREES_TO_RADIANS, 
+                                  cur_fdm_state->get_Altitude()
+                                    * SG_FEET_TO_METER );
     pilot_view->set_rph( cur_fdm_state->get_Phi(),
                         cur_fdm_state->get_Theta(),
                         cur_fdm_state->get_Psi() );
@@ -882,8 +968,6 @@ void fgReInitSubsystems( void )
     SG_LOG( SG_GENERAL, SG_DEBUG, "  abs_view_pos = "
            << globals->get_current_view()->get_abs_view_pos());
 
-    cur_fdm_state->init();
-
     globals->get_controls()->reset_all();
     current_autopilot->reset();