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>
66 #include <simgear/timing/lowleveltime.h>
68 #include <Aircraft/aircraft.hxx>
69 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
70 #include <Airports/runways.hxx>
71 #include <Airports/simple.hxx>
72 #include <ATC/ATCdisplay.hxx>
73 #include <Autopilot/auto_gui.hxx>
74 #include <Autopilot/newauto.hxx>
75 #include <Cockpit/cockpit.hxx>
76 #include <Cockpit/radiostack.hxx>
77 #include <Cockpit/panel.hxx>
78 #include <Cockpit/panel_io.hxx>
79 #include <FDM/ADA.hxx>
80 #include <FDM/Balloon.h>
81 #include <FDM/External.hxx>
82 #include <FDM/JSBSim.hxx>
83 #include <FDM/LaRCsim.hxx>
84 #include <FDM/MagicCarpet.hxx>
85 #include <FDM/NullFDM.hxx>
86 #include <FDM/YASim/YASim.hxx>
87 #include <Include/general.hxx>
88 #include <Input/input.hxx>
89 // #include <Joystick/joystick.hxx>
90 #include <Objects/matlib.hxx>
91 #include <Navaids/fixlist.hxx>
92 #include <Navaids/ilslist.hxx>
93 #include <Navaids/mkrbeacons.hxx>
94 #include <Navaids/navlist.hxx>
95 #include <Scenery/scenery.hxx>
96 #include <Scenery/tilemgr.hxx>
97 #include <Sound/fg_fx.hxx>
98 #include <Sound/soundmgr.hxx>
99 #include <Time/event.hxx>
100 #include <Time/light.hxx>
101 #include <Time/sunpos.hxx>
102 #include <Time/moonpos.hxx>
103 #include <Time/tmp.hxx>
105 #ifndef FG_NEW_ENVIRONMENT
106 # include <WeatherCM/FGLocalWeatherDatabase.h>
108 # include <Environment/environment.hxx>
111 #include "fg_init.hxx"
113 #include "fg_commands.hxx"
114 #include "fg_props.hxx"
115 #include "options.hxx"
116 #include "globals.hxx"
117 #include "viewmgr.hxx"
119 #if defined(FX) && defined(XMESA)
120 #include <GL/xmesa.h>
123 SG_USING_STD(string);
125 extern const char *default_root;
128 // Read in configuration (file and command line) and just set fg_root
129 bool fgInitFGRoot ( int argc, char **argv ) {
133 // First parse command line options looking for fg-root, this will
134 // override anything specified in a config file
135 root = fgScanForRoot(argc, argv);
137 #if defined( unix ) || defined( __CYGWIN__ )
138 // Next check home directory for .fgfsrc.hostname file
140 envp = ::getenv( "HOME" );
141 if ( envp != NULL ) {
142 SGPath config( envp );
143 config.append( ".fgfsrc" );
145 gethostname( name, 256 );
146 config.concat( "." );
147 config.concat( name );
148 root = fgScanForRoot(config.str());
153 // Next check home directory for .fgfsrc file
155 envp = ::getenv( "HOME" );
156 if ( envp != NULL ) {
157 SGPath config( envp );
158 config.append( ".fgfsrc" );
159 root = fgScanForRoot(config.str());
163 // Next check if fg-root is set as an env variable
165 envp = ::getenv( "FG_ROOT" );
166 if ( envp != NULL ) {
171 // Otherwise, default to a random compiled-in location if we can't
172 // find fg-root any other way.
174 #if defined( __CYGWIN__ )
175 root = "/FlightGear";
176 #elif defined( WIN32 )
177 root = "\\FlightGear";
178 #elif defined( macintosh )
185 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
186 globals->set_fg_root(root);
192 // Return the current base package version
193 string fgBasePackageVersion() {
194 SGPath base_path( globals->get_fg_root() );
195 base_path.append("version");
197 sg_gzifstream in( base_path.str() );
198 if ( !in.is_open() ) {
199 SGPath old_path( globals->get_fg_root() );
200 old_path.append( "Thanks" );
201 sg_gzifstream old( old_path.str() );
202 if ( !old.is_open() ) {
205 return "[old version]";
216 // Read in configuration (file and command line)
217 bool fgInitConfig ( int argc, char **argv ) {
219 // First, set some sane default values
222 // Read global preferences from $FG_ROOT/preferences.xml
223 SGPath props_path(globals->get_fg_root());
224 props_path.append("preferences.xml");
225 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
227 readProperties(props_path.str(), globals->get_props());
228 } catch (const sg_exception &e) {
229 string message = "Error reading global preferences: ";
230 message += e.getFormattedMessage();
231 SG_LOG(SG_INPUT, SG_ALERT, message);
234 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
236 // Read the default aircraft config file.
237 string aircraft = fgGetString("/sim/aircraft", "");
238 if (aircraft.size() > 0) {
239 SGPath aircraft_path(globals->get_fg_root());
240 aircraft_path.append("Aircraft");
241 aircraft_path.append(aircraft);
242 aircraft_path.concat("-set.xml");
243 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
244 << " from " << props_path.str());
246 readProperties(aircraft_path.str(), globals->get_props());
247 } catch (const sg_exception &e) {
248 string message = "Error reading default aircraft: ";
249 message += e.getFormattedMessage();
250 SG_LOG(SG_INPUT, SG_ALERT, message);
254 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
257 // Attempt to locate and parse the various config files in order
258 // from least precidence to greatest precidence
260 // Check for $fg_root/system.fgfsrc
261 SGPath config( globals->get_fg_root() );
262 config.append( "system.fgfsrc" );
263 fgParseOptions(config.str());
266 #if defined( unix ) || defined( __CYGWIN__ )
267 // Check for $fg_root/system.fgfsrc.hostname
268 gethostname( name, 256 );
269 config.concat( "." );
270 config.concat( name );
271 fgParseOptions(config.str());
274 // Check for ~/.fgfsrc
275 char* envp = ::getenv( "HOME" );
276 if ( envp != NULL ) {
278 config.append( ".fgfsrc" );
279 fgParseOptions(config.str());
282 #if defined( unix ) || defined( __CYGWIN__ )
283 // Check for ~/.fgfsrc.hostname
284 gethostname( name, 256 );
285 config.concat( "." );
286 config.concat( name );
287 fgParseOptions(config.str());
290 // Parse remaining command line options
291 // These will override anything specified in a config file
292 fgParseArgs(argc, argv);
298 // find basic airport location info from airport database
299 bool fgFindAirportID( const string& id, FGAirport *a ) {
301 SGPath path( globals->get_fg_root() );
302 path.append( "Airports" );
303 path.append( "simple.mk4" );
304 FGAirports airports( path.c_str() );
306 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
308 if ( ! airports.search( id, a ) ) {
309 SG_LOG( SG_GENERAL, SG_ALERT,
310 "Failed to find " << id << " in " << path.str() );
317 SG_LOG( SG_GENERAL, SG_INFO,
318 "Position for " << id << " is ("
319 << a->longitude << ", "
320 << a->latitude << ")" );
326 // Set current_options lon/lat given an airport id
327 bool fgSetPosFromAirportID( const string& id ) {
331 SG_LOG( SG_GENERAL, SG_INFO,
332 "Attempting to set starting position from airport code " << id );
334 if ( fgFindAirportID( id, &a ) ) {
335 fgSetDouble("/position/longitude-deg", a.longitude );
336 fgSetDouble("/position/latitude-deg", a.latitude );
337 SG_LOG( SG_GENERAL, SG_INFO,
338 "Position for " << id << " is ("
339 << a.longitude << ", "
340 << a.latitude << ")" );
350 // Set current_options lon/lat given an airport id and heading (degrees)
351 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
354 double found_dir = 0.0;
357 // set initial position from runway and heading
359 SGPath path( globals->get_fg_root() );
360 path.append( "Airports" );
361 path.append( "runways.mk4" );
362 FGRunways runways( path.c_str() );
364 SG_LOG( SG_GENERAL, SG_INFO,
365 "Attempting to set starting position from runway code "
366 << id << " heading " << tgt_hdg );
368 // SGPath inpath( globals->get_fg_root() );
369 // inpath.append( "Airports" );
370 // inpath.append( "apt_simple" );
371 // airports.load( inpath.c_str() );
373 // SGPath outpath( globals->get_fg_root() );
374 // outpath.append( "Airports" );
375 // outpath.append( "simple.gdbm" );
376 // airports.dump_gdbm( outpath.c_str() );
378 if ( ! runways.search( id, &r ) ) {
379 SG_LOG( SG_GENERAL, SG_ALERT,
380 "Failed to find " << id << " in database." );
385 double min_diff = 360.0;
387 while ( r.id == id ) {
389 diff = tgt_hdg - r.heading;
390 while ( diff < -180.0 ) { diff += 360.0; }
391 while ( diff > 180.0 ) { diff -= 360.0; }
393 SG_LOG( SG_GENERAL, SG_INFO,
394 "Runway " << r.rwy_no << " heading = " << r.heading <<
395 " diff = " << diff );
396 if ( diff < min_diff ) {
403 diff = tgt_hdg - r.heading - 180.0;
404 while ( diff < -180.0 ) { diff += 360.0; }
405 while ( diff > 180.0 ) { diff -= 360.0; }
407 SG_LOG( SG_GENERAL, SG_INFO,
408 "Runway -" << r.rwy_no << " heading = " <<
410 " diff = " << diff );
411 if ( diff < min_diff ) {
420 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
421 << " + " << found_dir );
427 double heading = found_r.heading + found_dir;
428 while ( heading >= 360.0 ) { heading -= 360.0; }
430 double lat2, lon2, az2;
431 double azimuth = found_r.heading + found_dir + 180.0;
432 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
434 SG_LOG( SG_GENERAL, SG_INFO,
435 "runway = " << found_r.lon << ", " << found_r.lat
436 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
437 << " heading = " << azimuth );
439 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
440 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
441 &lat2, &lon2, &az2 );
443 if ( fabs( fgGetDouble("/sim/startup/offset-distance") ) > SG_EPSILON ) {
445 double odist = fgGetDouble("/sim/startup/offset-distance");
446 odist *= SG_NM_TO_METER;
447 double oaz = azimuth;
448 if ( fabs(fgGetDouble("/sim/startup/offset-azimuth")) > SG_EPSILON ) {
449 oaz = fgGetDouble("/sim/startup/offset-azimuth") + 180;
451 while ( oaz >= 360.0 ) { oaz -= 360.0; }
452 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
457 fgSetDouble("/position/longitude-deg", lon2 );
458 fgSetDouble("/position/latitude-deg", lat2 );
459 fgSetDouble("/orientation/heading-deg", heading );
461 SG_LOG( SG_GENERAL, SG_INFO,
462 "Position for " << id << " is ("
464 << lat2 << ") new heading is "
471 // General house keeping initializations
472 bool fgInitGeneral( void ) {
475 #if defined(FX) && defined(XMESA)
476 char *mesa_win_state;
479 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
480 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
482 root = globals->get_fg_root();
483 if ( ! root.length() ) {
484 // No root path set? Then bail ...
485 SG_LOG( SG_GENERAL, SG_ALERT,
486 "Cannot continue without a path to the base package "
487 << "being defined." );
490 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
492 #if defined(FX) && defined(XMESA)
493 // initialize full screen flag
494 globals->set_fullscreen(false);
495 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
496 // Test for the MESA_GLX_FX env variable
497 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
498 // test if we are fullscreen mesa/glide
499 if ( (mesa_win_state[0] == 'f') ||
500 (mesa_win_state[0] == 'F') ) {
501 globals->set_fullscreen(true);
511 // Initialize the flight model subsystem. This just creates the
512 // object. The actual fdm initialization is delayed until we get a
513 // proper scenery elevation hit. This is checked for in main.cxx
517 if ( cur_fdm_state ) {
518 delete cur_fdm_state;
522 double dt = 1.0 / fgGetInt("/sim/model-hz");
523 aircraft_dir = fgGetString("/sim/aircraft-dir");
524 const string &model = fgGetString("/sim/flight-model");
527 if (model == "larcsim") {
528 cur_fdm_state = new FGLaRCsim( dt );
529 } else if (model == "jsb") {
530 cur_fdm_state = new FGJSBsim( dt );
531 } else if (model == "ada") {
532 cur_fdm_state = new FGADA( dt );
533 } else if (model == "balloon") {
534 cur_fdm_state = new FGBalloonSim( dt );
535 } else if (model == "magic") {
536 cur_fdm_state = new FGMagicCarpet( dt );
537 } else if (model == "external") {
538 cur_fdm_state = new FGExternal( dt );
539 } else if (model == "null") {
540 cur_fdm_state = new FGNullFDM( dt );
541 } else if (model == "yasim") {
542 cur_fdm_state = new YASim( dt );
544 SG_LOG(SG_GENERAL, SG_ALERT,
545 "Unrecognized flight model '" << model
546 << "', cannot init flight dynamics model.");
550 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
556 // Initialize view parameters
558 // Initialize pilot view
559 static const SGPropertyNode *longitude
560 = fgGetNode("/position/longitude-deg");
561 static const SGPropertyNode *latitude
562 = fgGetNode("/position/latitude-deg");
563 static const SGPropertyNode *altitude
564 = fgGetNode("/position/altitude-ft");
566 FGViewerRPH *pilot_view
567 = (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
569 pilot_view->set_geod_view_pos( longitude->getDoubleValue()
570 * SGD_DEGREES_TO_RADIANS,
571 latitude->getDoubleValue()
572 * SGD_DEGREES_TO_RADIANS,
573 altitude->getDoubleValue()
574 * SG_FEET_TO_METER );
575 pilot_view->set_rph( cur_fdm_state->get_Phi(),
576 cur_fdm_state->get_Theta(),
577 cur_fdm_state->get_Psi() );
579 // set current view to 0 (first) which is our main pilot view
580 globals->set_current_view( pilot_view );
582 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
583 << globals->get_current_view()->get_abs_view_pos());
587 SGTime *fgInitTime() {
589 static const SGPropertyNode *longitude
590 = fgGetNode("/position/longitude-deg");
591 static const SGPropertyNode *latitude
592 = fgGetNode("/position/latitude-deg");
593 static const SGPropertyNode *cur_time_override
594 = fgGetNode("/sim/time/cur-time-override", true);
596 SGPath zone( globals->get_fg_root() );
597 zone.append( "Timezone" );
598 SGTime *t = new SGTime( longitude->getDoubleValue()
599 * SGD_DEGREES_TO_RADIANS,
600 latitude->getDoubleValue()
601 * SGD_DEGREES_TO_RADIANS,
603 cur_time_override->getLongValue() );
605 // Handle potential user specified time offsets
606 time_t cur_time = t->get_cur_time();
607 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
608 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
609 time_t aircraftLocalTime =
610 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
612 // Okay, we now have six possible scenarios
613 int offset = fgGetInt("/sim/startup/time-offset");
614 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
615 if (offset_type == "system-offset") {
616 globals->set_warp( offset );
617 } else if (offset_type == "gmt-offset") {
618 globals->set_warp( offset - (currGMT - systemLocalTime) );
619 } else if (offset_type == "latitude-offset") {
620 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
621 } else if (offset_type == "system") {
622 globals->set_warp( offset - cur_time );
623 } else if (offset_type == "gmt") {
624 globals->set_warp( offset - currGMT );
625 } else if (offset_type == "latitude") {
626 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
629 SG_LOG( SG_GENERAL, SG_ALERT,
630 "FG_TIME::Unsupported offset type " << offset_type );
634 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
635 << globals->get_warp() );
637 globals->set_warp_delta( 0 );
640 cur_time_override->getLongValue(),
641 globals->get_warp() );
647 // This is the top level init routine which calls all the other
648 // initialization routines. If you are adding a subsystem to flight
649 // gear, its initialization call should located in this routine.
650 // Returns non-zero if a problem encountered.
651 bool fgInitSubsystems( void ) {
652 static const SGPropertyNode *longitude
653 = fgGetNode("/position/longitude-deg");
654 static const SGPropertyNode *latitude
655 = fgGetNode("/position/latitude-deg");
656 static const SGPropertyNode *altitude
657 = fgGetNode("/position/altitude-ft");
659 fgLIGHT *l = &cur_light_params;
661 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
662 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
665 ////////////////////////////////////////////////////////////////////
666 // Initialize the material property subsystem.
667 ////////////////////////////////////////////////////////////////////
669 SGPath mpath( globals->get_fg_root() );
670 mpath.append( "materials.xml" );
671 if ( ! material_lib.load( mpath.str() ) ) {
672 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
677 ////////////////////////////////////////////////////////////////////
678 // Initialize the scenery management subsystem.
679 ////////////////////////////////////////////////////////////////////
684 if ( global_tile_mgr.init() ) {
685 // Load the local scenery data
686 global_tile_mgr.update( longitude->getDoubleValue(),
687 latitude->getDoubleValue() );
689 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
693 SG_LOG( SG_GENERAL, SG_DEBUG,
694 "Current terrain elevation after tile mgr init " <<
695 scenery.get_cur_elev() );
698 ////////////////////////////////////////////////////////////////////
699 // Initialize the flight model subsystem.
700 ////////////////////////////////////////////////////////////////////
704 // allocates structures so must happen before any of the flight
705 // model or control parameters are set
706 fgAircraftInit(); // In the future this might not be the case.
709 ////////////////////////////////////////////////////////////////////
710 // Initialize the event manager subsystem.
711 ////////////////////////////////////////////////////////////////////
713 global_events.Init();
715 // Output event stats every 60 seconds
716 global_events.Register( "fgEVENT_MGR::PrintStats()",
717 fgMethodCallback<fgEVENT_MGR>( &global_events,
718 &fgEVENT_MGR::PrintStats),
719 fgEVENT::FG_EVENT_READY, 60000 );
722 ////////////////////////////////////////////////////////////////////
723 // Initialize the view manager subsystem.
724 ////////////////////////////////////////////////////////////////////
729 ////////////////////////////////////////////////////////////////////
730 // Initialize the lighting subsystem.
731 ////////////////////////////////////////////////////////////////////
733 // fgUpdateSunPos() needs a few position and view parameters set
734 // so it can calculate local relative sun angle and a few other
735 // things for correctly orienting the sky.
738 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
739 fgEVENT::FG_EVENT_READY, 60000);
740 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
741 fgEVENT::FG_EVENT_READY, 60000);
743 // Initialize Lighting interpolation tables
746 // update the lighting parameters (based on sun angle)
747 global_events.Register( "fgLight::Update()",
748 fgMethodCallback<fgLIGHT>( &cur_light_params,
750 fgEVENT::FG_EVENT_READY, 30000 );
753 ////////////////////////////////////////////////////////////////////
754 // Initialize the local time subsystem.
755 ////////////////////////////////////////////////////////////////////
757 // update the current timezone each 30 minutes
758 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
759 fgEVENT::FG_EVENT_READY, 1800000);
762 ////////////////////////////////////////////////////////////////////
763 // Initialize the weather subsystem.
764 ////////////////////////////////////////////////////////////////////
766 // Initialize the weather modeling subsystem
767 #ifndef FG_NEW_ENVIRONMENT
768 // Initialize the WeatherDatabase
769 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
771 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
772 current_aircraft.fdm_state->get_Longitude(),
773 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
774 double init_vis = fgGetDouble("/environment/visibility-m");
776 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
778 if (fgGetString("/environment/weather/working-type") == "internet")
780 working_type = FGLocalWeatherDatabase::use_internet;
782 working_type = FGLocalWeatherDatabase::default_mode;
785 if ( init_vis > 0 ) {
786 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
787 new FGLocalWeatherDatabase( position,
788 globals->get_fg_root(),
792 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
793 new FGLocalWeatherDatabase( position,
794 globals->get_fg_root(),
798 // cout << theFGLocalWeatherDatabase << endl;
799 // cout << "visibility = "
800 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
802 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
804 // register the periodic update of the weather
805 global_events.Register( "weather update", fgUpdateWeatherDatabase,
806 fgEVENT::FG_EVENT_READY, 30000);
808 current_environment.init();
809 current_environment.bind();
812 ////////////////////////////////////////////////////////////////////
813 // Initialize vor/ndb/ils/fix list management and query systems
814 ////////////////////////////////////////////////////////////////////
816 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
818 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
819 current_navlist = new FGNavList;
820 SGPath p_nav( globals->get_fg_root() );
821 p_nav.append( "Navaids/default.nav" );
822 current_navlist->init( p_nav );
824 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
825 current_beacons = new FGMarkerBeacons;
826 current_beacons->init();
827 current_ilslist = new FGILSList;
828 SGPath p_ils( globals->get_fg_root() );
829 p_ils.append( "Navaids/default.ils" );
830 current_ilslist->init( p_ils );
832 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
833 current_fixlist = new FGFixList;
834 SGPath p_fix( globals->get_fg_root() );
835 p_fix.append( "Navaids/default.fix" );
836 current_fixlist->init( p_fix );
838 ////////////////////////////////////////////////////////////////////
839 // Initialize ATC list management and query systems
840 ////////////////////////////////////////////////////////////////////
843 SG_LOG(SG_GENERAL, SG_INFO, " ATIS");
844 current_atislist = new FGATISList;
845 SGPath p_atis( globals->get_fg_root() );
846 p_atis.append( "ATC/default.atis" );
847 current_atislist->init( p_atis );
849 ////////////////////////////////////////////////////////////////////
850 // Initialise ATC display system
851 ////////////////////////////////////////////////////////////////////
854 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
855 current_atcdisplay = new FGATCDisplay;
856 current_atcdisplay->init();
858 ////////////////////////////////////////////////////////////////////
859 // Initialize the built-in commands.
860 ////////////////////////////////////////////////////////////////////
864 #ifdef ENABLE_AUDIO_SUPPORT
865 ////////////////////////////////////////////////////////////////////
866 // Initialize the sound subsystem.
867 ////////////////////////////////////////////////////////////////////
869 globals->set_soundmgr(new FGSoundMgr);
870 globals->get_soundmgr()->init();
871 globals->get_soundmgr()->bind();
874 ////////////////////////////////////////////////////////////////////
875 // Initialize the sound-effects subsystem.
876 ////////////////////////////////////////////////////////////////////
877 globals->set_fx(new FGFX);
878 globals->get_fx()->init();
879 globals->get_fx()->bind();
883 ////////////////////////////////////////////////////////////////////
884 // Initialize the radio stack subsystem.
885 ////////////////////////////////////////////////////////////////////
887 // A textbook example of how FGSubsystem
889 current_radiostack = new FGRadioStack;
890 current_radiostack->init();
891 current_radiostack->bind();
894 ////////////////////////////////////////////////////////////////////
895 // Initialize the cockpit subsystem
896 ////////////////////////////////////////////////////////////////////
898 if( fgCockpitInit( ¤t_aircraft )) {
899 // Cockpit initialized ok.
901 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
906 ////////////////////////////////////////////////////////////////////
907 // Initialize the joystick subsystem.
908 ////////////////////////////////////////////////////////////////////
910 // if ( ! fgJoystickInit() ) {
911 // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
915 ////////////////////////////////////////////////////////////////////
916 // Initialize the autopilot subsystem.
917 ////////////////////////////////////////////////////////////////////
919 current_autopilot = new FGAutopilot;
920 current_autopilot->init();
922 // initialize the gui parts of the autopilot
928 ////////////////////////////////////////////////////////////////////
929 // Initialize I/O subsystem.
930 ////////////////////////////////////////////////////////////////////
932 #if ! defined( macintosh )
936 // Initialize the 2D panel.
937 string panel_path = fgGetString("/sim/panel/path",
938 "Panels/Default/default.xml");
939 current_panel = fgReadPanel(panel_path);
940 if (current_panel == 0) {
941 SG_LOG( SG_INPUT, SG_ALERT,
942 "Error reading new panel from " << panel_path );
944 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
945 current_panel->init();
946 current_panel->bind();
950 ////////////////////////////////////////////////////////////////////
951 // Initialize the default (kludged) properties.
952 ////////////////////////////////////////////////////////////////////
957 ////////////////////////////////////////////////////////////////////
958 // Initialize the controls subsystem.
959 ////////////////////////////////////////////////////////////////////
961 globals->get_controls()->init();
962 globals->get_controls()->bind();
965 ////////////////////////////////////////////////////////////////////
966 // Initialize the input subsystem.
967 ////////////////////////////////////////////////////////////////////
969 current_input.init();
970 current_input.bind();
973 ////////////////////////////////////////////////////////////////////////
974 // End of subsystem initialization.
975 ////////////////////////////////////////////////////////////////////
977 SG_LOG( SG_GENERAL, SG_INFO, endl);
979 // Save the initial state for future
981 globals->saveInitialState();
987 void fgReInitSubsystems( void )
989 static const SGPropertyNode *longitude
990 = fgGetNode("/position/longitude-deg");
991 static const SGPropertyNode *latitude
992 = fgGetNode("/position/latitude-deg");
993 static const SGPropertyNode *altitude
994 = fgGetNode("/position/altitude-ft");
995 static const SGPropertyNode *master_freeze
996 = fgGetNode("/sim/freeze/master");
998 SG_LOG( SG_GENERAL, SG_INFO,
999 "/position/altitude = " << altitude->getDoubleValue() );
1001 bool freeze = master_freeze->getBoolValue();
1003 fgSetBool("/sim/freeze/master", true);
1006 // Initialize the Scenery Management subsystem
1010 if( global_tile_mgr.init() ) {
1011 Load the local scenery data
1012 global_tile_mgr.update( longitude->getDoubleValue(),
1013 latitude->getDoubleValue() );
1015 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1022 // allocates structures so must happen before any of the flight
1023 // model or control parameters are set
1024 fgAircraftInit(); // In the future this might not be the case.
1028 globals->get_controls()->reset_all();
1029 current_autopilot->reset();
1033 cur_light_params.Update();
1034 fgUpdateLocalTime();
1037 fgSetBool("/sim/freeze/master", false);