1 // fg_init.cxx -- Flight Gear top level initialization routines
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 // For BC 5.01 this must be included before OpenGL includes.
30 #ifdef SG_MATH_EXCEPTION_CLASH
44 #if defined( unix ) || defined( __CYGWIN__ )
45 # include <unistd.h> // for gethostname()
48 // work around a stdc++ lib bug in some versions of linux, but doesn't
49 // seem to hurt to have this here for all versions of Linux.
51 # define _G_NO_EXTERN_TEMPLATES
54 #include <simgear/compiler.h>
55 #include <simgear/misc/exception.hxx>
59 #include <simgear/constants.h>
60 #include <simgear/debug/logstream.hxx>
61 #include <simgear/math/point3d.hxx>
62 #include <simgear/math/polar3d.hxx>
63 #include <simgear/math/sg_geodesy.hxx>
64 #include <simgear/misc/sg_path.hxx>
65 #include <simgear/timing/sg_time.hxx>
67 #include <Aircraft/aircraft.hxx>
68 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
69 #include <Airports/runways.hxx>
70 #include <Airports/simple.hxx>
71 #include <ATC/ATCdisplay.hxx>
72 #include <Autopilot/auto_gui.hxx>
73 #include <Autopilot/newauto.hxx>
74 #include <Cockpit/cockpit.hxx>
75 #include <Cockpit/radiostack.hxx>
76 #include <Cockpit/panel.hxx>
77 #include <Cockpit/panel_io.hxx>
78 #include <FDM/ADA.hxx>
79 #include <FDM/Balloon.h>
80 #include <FDM/External.hxx>
81 #include <FDM/JSBSim.hxx>
82 #include <FDM/LaRCsim.hxx>
83 #include <FDM/MagicCarpet.hxx>
84 #include <FDM/NullFDM.hxx>
85 #include <FDM/YASim/YASim.hxx>
86 #include <Include/general.hxx>
87 #include <Input/input.hxx>
88 // #include <Joystick/joystick.hxx>
89 #include <Objects/matlib.hxx>
90 #include <Navaids/fixlist.hxx>
91 #include <Navaids/ilslist.hxx>
92 #include <Navaids/mkrbeacons.hxx>
93 #include <Navaids/navlist.hxx>
94 #include <Scenery/scenery.hxx>
95 #include <Scenery/tilemgr.hxx>
96 #include <Sound/fg_fx.hxx>
97 #include <Sound/soundmgr.hxx>
98 #include <Time/event.hxx>
99 #include <Time/light.hxx>
100 #include <Time/sunpos.hxx>
101 #include <Time/moonpos.hxx>
102 #include <Time/tmp.hxx>
104 #ifndef FG_OLD_WEATHER
105 # include <WeatherCM/FGLocalWeatherDatabase.h>
107 # include <Weather/weather.hxx>
110 #include "fg_init.hxx"
112 #include "fg_commands.hxx"
113 #include "fg_props.hxx"
114 #include "options.hxx"
115 #include "globals.hxx"
116 #include "viewmgr.hxx"
118 #if defined(FX) && defined(XMESA)
119 #include <GL/xmesa.h>
122 SG_USING_STD(string);
124 extern const char *default_root;
127 // Read in configuration (file and command line) and just set fg_root
128 bool fgInitFGRoot ( int argc, char **argv ) {
132 // First parse command line options looking for fg-root, this will
133 // override anything specified in a config file
134 root = fgScanForRoot(argc, argv);
136 #if defined( unix ) || defined( __CYGWIN__ )
137 // Next check home directory for .fgfsrc.hostname file
139 envp = ::getenv( "HOME" );
140 if ( envp != NULL ) {
141 SGPath config( envp );
142 config.append( ".fgfsrc" );
144 gethostname( name, 256 );
145 config.concat( "." );
146 config.concat( name );
147 root = fgScanForRoot(config.str());
152 // Next check home directory for .fgfsrc file
154 envp = ::getenv( "HOME" );
155 if ( envp != NULL ) {
156 SGPath config( envp );
157 config.append( ".fgfsrc" );
158 root = fgScanForRoot(config.str());
162 // Next check if fg-root is set as an env variable
164 envp = ::getenv( "FG_ROOT" );
165 if ( envp != NULL ) {
170 // Otherwise, default to a random compiled-in location if we can't
171 // find fg-root any other way.
173 #if defined( __CYGWIN__ )
174 root = "/FlightGear";
175 #elif defined( WIN32 )
176 root = "\\FlightGear";
177 #elif defined( macintosh )
184 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
185 globals->set_fg_root(root);
191 // Return the current base package version
192 string fgBasePackageVersion() {
193 SGPath base_path( globals->get_fg_root() );
194 base_path.append("version");
196 sg_gzifstream in( base_path.str() );
197 if ( !in.is_open() ) {
198 SGPath old_path( globals->get_fg_root() );
199 old_path.append( "Thanks" );
200 sg_gzifstream old( old_path.str() );
201 if ( !old.is_open() ) {
204 return "[old version]";
215 // Read in configuration (file and command line)
216 bool fgInitConfig ( int argc, char **argv ) {
218 // First, set some sane default values
221 // Read global preferences from $FG_ROOT/preferences.xml
222 SGPath props_path(globals->get_fg_root());
223 props_path.append("preferences.xml");
224 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
226 readProperties(props_path.str(), globals->get_props());
227 } catch (const sg_exception &e) {
228 string message = "Error reading global preferences: ";
229 message += e.getFormattedMessage();
230 SG_LOG(SG_INPUT, SG_ALERT, message);
233 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
235 // Read the default aircraft config file.
236 string aircraft = fgGetString("/sim/aircraft", "");
237 if (aircraft.size() > 0) {
238 SGPath aircraft_path(globals->get_fg_root());
239 aircraft_path.append("Aircraft");
240 aircraft_path.append(aircraft);
241 aircraft_path.concat("-set.xml");
242 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
243 << " from " << props_path.str());
245 readProperties(aircraft_path.str(), globals->get_props());
246 } catch (const sg_exception &e) {
247 string message = "Error reading default aircraft: ";
248 message += e.getFormattedMessage();
249 SG_LOG(SG_INPUT, SG_ALERT, message);
253 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
256 // Attempt to locate and parse the various config files in order
257 // from least precidence to greatest precidence
259 // Check for $fg_root/system.fgfsrc
260 SGPath config( globals->get_fg_root() );
261 config.append( "system.fgfsrc" );
262 fgParseOptions(config.str());
265 #if defined( unix ) || defined( __CYGWIN__ )
266 // Check for $fg_root/system.fgfsrc.hostname
267 gethostname( name, 256 );
268 config.concat( "." );
269 config.concat( name );
270 fgParseOptions(config.str());
273 // Check for ~/.fgfsrc
274 char* envp = ::getenv( "HOME" );
275 if ( envp != NULL ) {
277 config.append( ".fgfsrc" );
278 fgParseOptions(config.str());
281 #if defined( unix ) || defined( __CYGWIN__ )
282 // Check for ~/.fgfsrc.hostname
283 gethostname( name, 256 );
284 config.concat( "." );
285 config.concat( name );
286 fgParseOptions(config.str());
289 // Parse remaining command line options
290 // These will override anything specified in a config file
291 fgParseArgs(argc, argv);
297 // find basic airport location info from airport database
298 bool fgFindAirportID( const string& id, FGAirport *a ) {
300 SGPath path( globals->get_fg_root() );
301 path.append( "Airports" );
302 path.append( "simple.mk4" );
303 FGAirports airports( path.c_str() );
305 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
307 if ( ! airports.search( id, a ) ) {
308 SG_LOG( SG_GENERAL, SG_ALERT,
309 "Failed to find " << id << " in " << path.str() );
316 SG_LOG( SG_GENERAL, SG_INFO,
317 "Position for " << id << " is ("
318 << a->longitude << ", "
319 << a->latitude << ")" );
325 // Set current_options lon/lat given an airport id
326 bool fgSetPosFromAirportID( const string& id ) {
330 SG_LOG( SG_GENERAL, SG_INFO,
331 "Attempting to set starting position from airport code " << id );
333 if ( fgFindAirportID( id, &a ) ) {
334 fgSetDouble("/position/longitude-deg", a.longitude );
335 fgSetDouble("/position/latitude-deg", a.latitude );
336 SG_LOG( SG_GENERAL, SG_INFO,
337 "Position for " << id << " is ("
338 << a.longitude << ", "
339 << a.latitude << ")" );
349 // Set current_options lon/lat given an airport id and heading (degrees)
350 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
353 double found_dir = 0.0;
356 // set initial position from runway and heading
358 SGPath path( globals->get_fg_root() );
359 path.append( "Airports" );
360 path.append( "runways.mk4" );
361 FGRunways runways( path.c_str() );
363 SG_LOG( SG_GENERAL, SG_INFO,
364 "Attempting to set starting position from runway code "
365 << id << " heading " << tgt_hdg );
367 // SGPath inpath( globals->get_fg_root() );
368 // inpath.append( "Airports" );
369 // inpath.append( "apt_simple" );
370 // airports.load( inpath.c_str() );
372 // SGPath outpath( globals->get_fg_root() );
373 // outpath.append( "Airports" );
374 // outpath.append( "simple.gdbm" );
375 // airports.dump_gdbm( outpath.c_str() );
377 if ( ! runways.search( id, &r ) ) {
378 SG_LOG( SG_GENERAL, SG_ALERT,
379 "Failed to find " << id << " in database." );
384 double min_diff = 360.0;
386 while ( r.id == id ) {
388 diff = tgt_hdg - r.heading;
389 while ( diff < -180.0 ) { diff += 360.0; }
390 while ( diff > 180.0 ) { diff -= 360.0; }
392 SG_LOG( SG_GENERAL, SG_INFO,
393 "Runway " << r.rwy_no << " heading = " << r.heading <<
394 " diff = " << diff );
395 if ( diff < min_diff ) {
402 diff = tgt_hdg - r.heading - 180.0;
403 while ( diff < -180.0 ) { diff += 360.0; }
404 while ( diff > 180.0 ) { diff -= 360.0; }
406 SG_LOG( SG_GENERAL, SG_INFO,
407 "Runway -" << r.rwy_no << " heading = " <<
409 " diff = " << diff );
410 if ( diff < min_diff ) {
419 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
420 << " + " << found_dir );
426 double heading = found_r.heading + found_dir;
427 while ( heading >= 360.0 ) { heading -= 360.0; }
429 double lat2, lon2, az2;
430 double azimuth = found_r.heading + found_dir + 180.0;
431 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
433 SG_LOG( SG_GENERAL, SG_INFO,
434 "runway = " << found_r.lon << ", " << found_r.lat
435 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
436 << " heading = " << azimuth );
438 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
439 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
440 &lat2, &lon2, &az2 );
442 if ( fabs( fgGetDouble("/sim/startup/offset-distance") ) > SG_EPSILON ) {
444 double odist = fgGetDouble("/sim/startup/offset-distance");
445 odist *= SG_NM_TO_METER;
446 double oaz = azimuth;
447 if ( fabs(fgGetDouble("/sim/startup/offset-azimuth")) > SG_EPSILON ) {
448 oaz = fgGetDouble("/sim/startup/offset-azimuth") + 180;
450 while ( oaz >= 360.0 ) { oaz -= 360.0; }
451 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
456 fgSetDouble("/position/longitude-deg", lon2 );
457 fgSetDouble("/position/latitude-deg", lat2 );
458 fgSetDouble("/orientation/heading-deg", heading );
460 SG_LOG( SG_GENERAL, SG_INFO,
461 "Position for " << id << " is ("
463 << lat2 << ") new heading is "
470 // General house keeping initializations
471 bool fgInitGeneral( void ) {
474 #if defined(FX) && defined(XMESA)
475 char *mesa_win_state;
478 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
479 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
481 root = globals->get_fg_root();
482 if ( ! root.length() ) {
483 // No root path set? Then bail ...
484 SG_LOG( SG_GENERAL, SG_ALERT,
485 "Cannot continue without a path to the base package "
486 << "being defined." );
489 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
491 #if defined(FX) && defined(XMESA)
492 // initialize full screen flag
493 globals->set_fullscreen(false);
494 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
495 // Test for the MESA_GLX_FX env variable
496 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
497 // test if we are fullscreen mesa/glide
498 if ( (mesa_win_state[0] == 'f') ||
499 (mesa_win_state[0] == 'F') ) {
500 globals->set_fullscreen(true);
510 // Initialize the flight model subsystem. This just creates the
511 // object. The actual fdm initialization is delayed until we get a
512 // proper scenery elevation hit. This is checked for in main.cxx
516 if ( cur_fdm_state ) {
517 delete cur_fdm_state;
521 double dt = 1.0 / fgGetInt("/sim/model-hz");
522 aircraft_dir = fgGetString("/sim/aircraft-dir");
523 const string &model = fgGetString("/sim/flight-model");
526 if (model == "larcsim") {
527 cur_fdm_state = new FGLaRCsim( dt );
528 } else if (model == "jsb") {
529 cur_fdm_state = new FGJSBsim( dt );
530 } else if (model == "ada") {
531 cur_fdm_state = new FGADA( dt );
532 } else if (model == "balloon") {
533 cur_fdm_state = new FGBalloonSim( dt );
534 } else if (model == "magic") {
535 cur_fdm_state = new FGMagicCarpet( dt );
536 } else if (model == "external") {
537 cur_fdm_state = new FGExternal( dt );
538 } else if (model == "null") {
539 cur_fdm_state = new FGNullFDM( dt );
540 } else if (model == "yasim") {
541 cur_fdm_state = new YASim( dt );
543 SG_LOG(SG_GENERAL, SG_ALERT,
544 "Unrecognized flight model '" << model
545 << "', cannot init flight dynamics model.");
549 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
555 // Initialize view parameters
557 // Initialize pilot view
558 static const SGPropertyNode *longitude
559 = fgGetNode("/position/longitude-deg");
560 static const SGPropertyNode *latitude
561 = fgGetNode("/position/latitude-deg");
562 static const SGPropertyNode *altitude
563 = fgGetNode("/position/altitude-ft");
565 FGViewerRPH *pilot_view
566 = (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
568 pilot_view->set_geod_view_pos( longitude->getDoubleValue()
569 * SGD_DEGREES_TO_RADIANS,
570 latitude->getDoubleValue()
571 * SGD_DEGREES_TO_RADIANS,
572 altitude->getDoubleValue()
573 * SG_FEET_TO_METER );
574 pilot_view->set_rph( cur_fdm_state->get_Phi(),
575 cur_fdm_state->get_Theta(),
576 cur_fdm_state->get_Psi() );
578 // set current view to 0 (first) which is our main pilot view
579 globals->set_current_view( pilot_view );
581 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
582 << globals->get_current_view()->get_abs_view_pos());
586 // This is the top level init routine which calls all the other
587 // initialization routines. If you are adding a subsystem to flight
588 // gear, its initialization call should located in this routine.
589 // Returns non-zero if a problem encountered.
590 bool fgInitSubsystems( void ) {
591 static const SGPropertyNode *longitude
592 = fgGetNode("/position/longitude-deg");
593 static const SGPropertyNode *latitude
594 = fgGetNode("/position/latitude-deg");
595 static const SGPropertyNode *altitude
596 = fgGetNode("/position/altitude-ft");
598 fgLIGHT *l = &cur_light_params;
600 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
601 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
604 ////////////////////////////////////////////////////////////////////
605 // Initialize the material property subsystem.
606 ////////////////////////////////////////////////////////////////////
608 SGPath mpath( globals->get_fg_root() );
609 mpath.append( "materials.xml" );
610 if ( ! material_lib.load( mpath.str() ) ) {
611 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
616 ////////////////////////////////////////////////////////////////////
617 // Initialize the scenery management subsystem.
618 ////////////////////////////////////////////////////////////////////
623 if ( global_tile_mgr.init() ) {
624 // Load the local scenery data
625 global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
626 fgGetDouble("/position/latitude-deg") );
628 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
632 SG_LOG( SG_GENERAL, SG_DEBUG,
633 "Current terrain elevation after tile mgr init " <<
634 scenery.get_cur_elev() );
637 ////////////////////////////////////////////////////////////////////
638 // Initialize the flight model subsystem.
639 ////////////////////////////////////////////////////////////////////
643 // allocates structures so must happen before any of the flight
644 // model or control parameters are set
645 fgAircraftInit(); // In the future this might not be the case.
648 ////////////////////////////////////////////////////////////////////
649 // Initialize the event manager subsystem.
650 ////////////////////////////////////////////////////////////////////
652 global_events.Init();
654 // Output event stats every 60 seconds
655 global_events.Register( "fgEVENT_MGR::PrintStats()",
656 fgMethodCallback<fgEVENT_MGR>( &global_events,
657 &fgEVENT_MGR::PrintStats),
658 fgEVENT::FG_EVENT_READY, 60000 );
661 ////////////////////////////////////////////////////////////////////
662 // Initialize the view manager subsystem.
663 ////////////////////////////////////////////////////////////////////
668 ////////////////////////////////////////////////////////////////////
669 // Initialize the lighting subsystem.
670 ////////////////////////////////////////////////////////////////////
672 // fgUpdateSunPos() needs a few position and view parameters set
673 // so it can calculate local relative sun angle and a few other
674 // things for correctly orienting the sky.
677 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
678 fgEVENT::FG_EVENT_READY, 60000);
679 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
680 fgEVENT::FG_EVENT_READY, 60000);
682 // Initialize Lighting interpolation tables
685 // update the lighting parameters (based on sun angle)
686 global_events.Register( "fgLight::Update()",
687 fgMethodCallback<fgLIGHT>( &cur_light_params,
689 fgEVENT::FG_EVENT_READY, 30000 );
692 ////////////////////////////////////////////////////////////////////
693 // Initialize the local time subsystem.
694 ////////////////////////////////////////////////////////////////////
696 // update the current timezone each 30 minutes
697 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
698 fgEVENT::FG_EVENT_READY, 1800000);
701 ////////////////////////////////////////////////////////////////////
702 // Initialize the weather subsystem.
703 ////////////////////////////////////////////////////////////////////
705 // Initialize the weather modeling subsystem
706 #ifndef FG_OLD_WEATHER
707 // Initialize the WeatherDatabase
708 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
710 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
711 current_aircraft.fdm_state->get_Longitude(),
712 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
713 double init_vis = fgGetDouble("/environment/visibility-m");
715 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
717 if (fgGetString("/environment/weather/working-type") == "internet")
719 working_type = FGLocalWeatherDatabase::use_internet;
721 working_type = FGLocalWeatherDatabase::default_mode;
724 if ( init_vis > 0 ) {
725 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
726 new FGLocalWeatherDatabase( position,
727 globals->get_fg_root(),
731 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
732 new FGLocalWeatherDatabase( position,
733 globals->get_fg_root(),
737 // cout << theFGLocalWeatherDatabase << endl;
738 // cout << "visibility = "
739 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
741 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
743 // register the periodic update of the weather
744 global_events.Register( "weather update", fgUpdateWeatherDatabase,
745 fgEVENT::FG_EVENT_READY, 30000);
747 current_weather.Init();
750 ////////////////////////////////////////////////////////////////////
751 // Initialize vor/ndb/ils/fix list management and query systems
752 ////////////////////////////////////////////////////////////////////
754 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
756 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
757 current_navlist = new FGNavList;
758 SGPath p_nav( globals->get_fg_root() );
759 p_nav.append( "Navaids/default.nav" );
760 current_navlist->init( p_nav );
762 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
763 current_beacons = new FGMarkerBeacons;
764 current_beacons->init();
765 current_ilslist = new FGILSList;
766 SGPath p_ils( globals->get_fg_root() );
767 p_ils.append( "Navaids/default.ils" );
768 current_ilslist->init( p_ils );
770 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
771 current_fixlist = new FGFixList;
772 SGPath p_fix( globals->get_fg_root() );
773 p_fix.append( "Navaids/default.fix" );
774 current_fixlist->init( p_fix );
776 ////////////////////////////////////////////////////////////////////
777 // Initialize ATC list management and query systems
778 ////////////////////////////////////////////////////////////////////
781 SG_LOG(SG_GENERAL, SG_INFO, " ATIS");
782 current_atislist = new FGATISList;
783 SGPath p_atis( globals->get_fg_root() );
784 p_atis.append( "ATC/default.atis" );
785 current_atislist->init( p_atis );
787 ////////////////////////////////////////////////////////////////////
788 // Initialise ATC display system
789 ////////////////////////////////////////////////////////////////////
792 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
793 current_atcdisplay = new FGATCDisplay;
794 current_atcdisplay->init();
796 ////////////////////////////////////////////////////////////////////
797 // Initialize the built-in commands.
798 ////////////////////////////////////////////////////////////////////
802 #ifdef ENABLE_AUDIO_SUPPORT
803 ////////////////////////////////////////////////////////////////////
804 // Initialize the sound subsystem.
805 ////////////////////////////////////////////////////////////////////
807 globals->set_soundmgr(new FGSoundMgr);
808 globals->get_soundmgr()->init();
809 globals->get_soundmgr()->bind();
812 ////////////////////////////////////////////////////////////////////
813 // Initialize the sound-effects subsystem.
814 ////////////////////////////////////////////////////////////////////
815 globals->set_fx(new FGFX);
816 globals->get_fx()->init();
817 globals->get_fx()->bind();
821 ////////////////////////////////////////////////////////////////////
822 // Initialize the radio stack subsystem.
823 ////////////////////////////////////////////////////////////////////
825 // A textbook example of how FGSubsystem
827 current_radiostack = new FGRadioStack;
828 current_radiostack->init();
829 current_radiostack->bind();
832 ////////////////////////////////////////////////////////////////////
833 // Initialize the cockpit subsystem
834 ////////////////////////////////////////////////////////////////////
836 if( fgCockpitInit( ¤t_aircraft )) {
837 // Cockpit initialized ok.
839 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
844 ////////////////////////////////////////////////////////////////////
845 // Initialize the joystick subsystem.
846 ////////////////////////////////////////////////////////////////////
848 // if ( ! fgJoystickInit() ) {
849 // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
853 ////////////////////////////////////////////////////////////////////
854 // Initialize the autopilot subsystem.
855 ////////////////////////////////////////////////////////////////////
857 current_autopilot = new FGAutopilot;
858 current_autopilot->init();
860 // initialize the gui parts of the autopilot
866 ////////////////////////////////////////////////////////////////////
867 // Initialize I/O subsystem.
868 ////////////////////////////////////////////////////////////////////
870 #if ! defined( macintosh )
874 // Initialize the 2D panel.
875 string panel_path = fgGetString("/sim/panel/path",
876 "Panels/Default/default.xml");
877 current_panel = fgReadPanel(panel_path);
878 if (current_panel == 0) {
879 SG_LOG( SG_INPUT, SG_ALERT,
880 "Error reading new panel from " << panel_path );
882 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
883 current_panel->init();
884 current_panel->bind();
888 ////////////////////////////////////////////////////////////////////
889 // Initialize the default (kludged) properties.
890 ////////////////////////////////////////////////////////////////////
895 ////////////////////////////////////////////////////////////////////
896 // Initialize the controls subsystem.
897 ////////////////////////////////////////////////////////////////////
899 globals->get_controls()->init();
900 globals->get_controls()->bind();
903 ////////////////////////////////////////////////////////////////////
904 // Initialize the input subsystem.
905 ////////////////////////////////////////////////////////////////////
907 current_input.init();
908 current_input.bind();
911 ////////////////////////////////////////////////////////////////////////
912 // End of subsystem initialization.
913 ////////////////////////////////////////////////////////////////////
915 SG_LOG( SG_GENERAL, SG_INFO, endl);
917 // Save the initial state for future
919 globals->saveInitialState();
925 void fgReInitSubsystems( void )
927 static const SGPropertyNode *longitude
928 = fgGetNode("/position/longitude-deg");
929 static const SGPropertyNode *latitude
930 = fgGetNode("/position/latitude-deg");
931 static const SGPropertyNode *altitude
932 = fgGetNode("/position/altitude-ft");
933 static const SGPropertyNode *master_freeze
934 = fgGetNode("/sim/freeze/master");
936 SG_LOG( SG_GENERAL, SG_INFO,
937 "/position/altitude = " << altitude->getDoubleValue() );
939 bool freeze = master_freeze->getBoolValue();
941 fgSetBool("/sim/freeze/master", true);
944 // Initialize the Scenery Management subsystem
948 if( global_tile_mgr.init() ) {
949 Load the local scenery data
950 global_tile_mgr.update( longitude->getDoubleValue(),
951 latitude->getDoubleValue() );
953 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
962 globals->get_controls()->reset_all();
963 current_autopilot->reset();
967 cur_light_params.Update();
971 fgSetBool("/sim/freeze/master", false);