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
42 #include <string.h> // strcmp()
45 #if defined( unix ) || defined( __CYGWIN__ )
46 # include <unistd.h> // for gethostname()
49 // work around a stdc++ lib bug in some versions of linux, but doesn't
50 // seem to hurt to have this here for all versions of Linux.
52 # define _G_NO_EXTERN_TEMPLATES
55 #include <simgear/compiler.h>
56 #include <simgear/misc/exception.hxx>
60 #include <simgear/constants.h>
61 #include <simgear/debug/logstream.hxx>
62 #include <simgear/math/point3d.hxx>
63 #include <simgear/math/polar3d.hxx>
64 #include <simgear/math/sg_geodesy.hxx>
65 #include <simgear/misc/sg_path.hxx>
66 #ifdef FG_USE_CLOUDS_3D
67 # include <simgear/sky/clouds3d/SkySceneLoader.hpp>
68 # include <simgear/sky/clouds3d/SkyUtil.hpp>
70 #include <simgear/timing/sg_time.hxx>
71 #include <simgear/timing/lowleveltime.h>
73 #include <Aircraft/aircraft.hxx>
74 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
75 #include <Airports/runways.hxx>
76 #include <Airports/simple.hxx>
77 #include <ATC/ATCdisplay.hxx>
78 #include <ATC/ATCmgr.hxx>
79 #include <ATC/atislist.hxx>
80 #include <ATC/towerlist.hxx>
81 #include <ATC/approachlist.hxx>
82 #include <ATC/AIMgr.hxx>
83 #include <Autopilot/auto_gui.hxx>
84 #include <Autopilot/newauto.hxx>
85 #include <Cockpit/cockpit.hxx>
86 #include <Cockpit/radiostack.hxx>
87 #include <Cockpit/panel.hxx>
88 #include <Cockpit/panel_io.hxx>
89 #include <FDM/ADA.hxx>
90 #include <FDM/Balloon.h>
91 #include <FDM/ExternalNet/ExternalNet.hxx>
92 #include <FDM/JSBSim/JSBSim.hxx>
93 #include <FDM/LaRCsim.hxx>
94 #include <FDM/MagicCarpet.hxx>
95 #include <FDM/UFO.hxx>
96 #include <FDM/NullFDM.hxx>
97 #include <FDM/YASim/YASim.hxx>
98 #include <GUI/new_gui.hxx>
99 #include <Include/general.hxx>
100 #include <Input/input.hxx>
101 #include <Instrumentation/instrument_mgr.hxx>
102 // #include <Joystick/joystick.hxx>
103 #include <Objects/matlib.hxx>
104 #include <Model/acmodel.hxx>
105 #include <Navaids/fixlist.hxx>
106 #include <Navaids/ilslist.hxx>
107 #include <Navaids/mkrbeacons.hxx>
108 #include <Navaids/navlist.hxx>
109 #include <Scenery/scenery.hxx>
110 #include <Scenery/tilemgr.hxx>
111 #if defined(HAVE_PLIB_PSL)
112 #include <Scripting/scriptmgr.hxx>
114 #include <Sound/fg_fx.hxx>
115 #include <Sound/soundmgr.hxx>
116 #include <Systems/system_mgr.hxx>
117 #include <Time/FGEventMgr.hxx>
118 #include <Time/light.hxx>
119 #include <Time/sunpos.hxx>
120 #include <Time/moonpos.hxx>
121 #include <Time/tmp.hxx>
124 # include <WeatherCM/FGLocalWeatherDatabase.h>
126 # include <Environment/environment_mgr.hxx>
129 #include "fg_init.hxx"
131 #include "fg_commands.hxx"
132 #include "fg_props.hxx"
133 #include "options.hxx"
134 #include "globals.hxx"
135 #include "logger.hxx"
136 #include "viewmgr.hxx"
138 #if defined(FX) && defined(XMESA)
139 #include <GL/xmesa.h>
142 SG_USING_STD(string);
144 extern const char *default_root;
146 #ifdef FG_USE_CLOUDS_3D
147 SkySceneLoader *sgCloud3d;
151 // Scan the command line options for the specified option and return
153 static string fgScanForOption( const string& option, int argc, char **argv ) {
156 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
158 int len = option.length();
161 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
163 string arg = argv[i];
164 if ( arg.find( option ) == 0 ) {
165 return arg.substr( len );
175 // Scan the user config files for the specified option and return
177 static string fgScanForOption( const string& option, const string& path ) {
178 sg_gzifstream in( path );
179 if ( !in.is_open() ) {
183 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
185 int len = option.length();
189 while ( ! in.eof() ) {
192 while ( in.get(c) && c != '\0' ) {
197 #if defined( macintosh )
198 getline( in, line, '\r' );
200 getline( in, line, '\n' );
203 // catch extraneous (DOS) line ending character
204 if ( line[line.length() - 1] < 32 ) {
205 line = line.substr( 0, line.length()-1 );
208 if ( line.find( option ) == 0 ) {
209 return line.substr( len );
219 // Read in configuration (files and command line options) but only set
221 bool fgInitFGRoot ( int argc, char **argv ) {
225 // First parse command line options looking for --fg-root=, this
226 // will override anything specified in a config file
227 root = fgScanForOption( "--fg-root=", argc, argv);
229 #if defined( unix ) || defined( __CYGWIN__ )
230 // Next check home directory for .fgfsrc.hostname file
231 if ( root.empty() ) {
232 envp = ::getenv( "HOME" );
233 if ( envp != NULL ) {
234 SGPath config( envp );
235 config.append( ".fgfsrc" );
237 gethostname( name, 256 );
238 config.concat( "." );
239 config.concat( name );
240 root = fgScanForOption( "--fg-root=", config.str() );
245 // Next check home directory for .fgfsrc file
246 if ( root.empty() ) {
247 envp = ::getenv( "HOME" );
248 if ( envp != NULL ) {
249 SGPath config( envp );
250 config.append( ".fgfsrc" );
251 root = fgScanForOption( "--fg-root=", config.str() );
255 // Next check if fg-root is set as an env variable
256 if ( root.empty() ) {
257 envp = ::getenv( "FG_ROOT" );
258 if ( envp != NULL ) {
263 // Otherwise, default to a random compiled-in location if we can't
264 // find fg-root any other way.
265 if ( root.empty() ) {
266 #if defined( __CYGWIN__ )
267 root = "/FlightGear";
268 #elif defined( WIN32 )
269 root = "\\FlightGear";
270 #elif defined( macintosh )
277 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
278 globals->set_fg_root(root);
284 // Read in configuration (files and command line options) but only set
286 bool fgInitFGAircraft ( int argc, char **argv ) {
290 // First parse command line options looking for --aircraft=, this
291 // will override anything specified in a config file
292 aircraft = fgScanForOption( "--aircraft=", argc, argv );
294 #if defined( unix ) || defined( __CYGWIN__ )
295 // Next check home directory for .fgfsrc.hostname file
296 if ( aircraft.empty() ) {
297 envp = ::getenv( "HOME" );
298 if ( envp != NULL ) {
299 SGPath config( envp );
300 config.append( ".fgfsrc" );
302 gethostname( name, 256 );
303 config.concat( "." );
304 config.concat( name );
305 aircraft = fgScanForOption( "--aircraft=", config.str() );
310 // Next check home directory for .fgfsrc file
311 if ( aircraft.empty() ) {
312 envp = ::getenv( "HOME" );
313 if ( envp != NULL ) {
314 SGPath config( envp );
315 config.append( ".fgfsrc" );
316 aircraft = fgScanForOption( "--aircraft=", config.str() );
320 // if an aircraft was specified, set the property name
321 if ( !aircraft.empty() ) {
322 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
323 fgSetString("/sim/aircraft", aircraft.c_str() );
325 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
332 // Return the current base package version
333 string fgBasePackageVersion() {
334 SGPath base_path( globals->get_fg_root() );
335 base_path.append("version");
337 sg_gzifstream in( base_path.str() );
338 if ( !in.is_open() ) {
339 SGPath old_path( globals->get_fg_root() );
340 old_path.append( "Thanks" );
341 sg_gzifstream old( old_path.str() );
342 if ( !old.is_open() ) {
345 return "[old version]";
356 // Initialize the localization
357 SGPropertyNode *fgInitLocale(const char *language) {
358 SGPropertyNode *c_node = NULL, *d_node = NULL;
359 SGPropertyNode *intl = fgGetNode("/sim/intl");
361 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
363 // localization not defined
368 // Select the proper language from the list
370 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
371 for (unsigned int i = 0; i < locale.size(); i++) {
373 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
374 for (unsigned int j = 0; j < lang.size(); j++) {
376 if (!strcmp(lang[j]->getStringValue(), language)) {
385 d_node = intl->getChild("locale");
389 // Check for localized font
390 SGPropertyNode *font_n = c_node->getNode("font", true);
391 if ( !strcmp(font_n->getStringValue(), "") )
392 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
396 // Load the default strings
398 SGPath d_path( globals->get_fg_root() );
400 const char *d_path_str = d_node->getStringValue("strings");
402 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
406 d_path.append(d_path_str);
407 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
410 SGPropertyNode *strings = c_node->getNode("strings");
412 readProperties(d_path.str(), strings);
413 } catch (const sg_exception &e) {
414 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
419 // Load the language specific strings
421 if (c_node != d_node) {
422 SGPath c_path( globals->get_fg_root() );
424 const char *c_path_str = c_node->getStringValue("strings");
426 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
430 c_path.append(c_path_str);
431 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
435 readProperties(c_path.str(), strings);
436 } catch (const sg_exception &e) {
437 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
447 // Initialize the localization routines
448 bool fgDetectLanguage() {
449 char *language = ::getenv("LANG");
451 if (language == NULL) {
452 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
456 SGPropertyNode *locale = fgInitLocale(language);
458 cerr << "No internationalization settings specified in preferences.xml"
464 globals->set_locale( locale );
469 // Attempt to locate and parse the various non-XML config files in order
470 // from least precidence to greatest precidence
472 do_options (int argc, char ** argv)
474 // Check for $fg_root/system.fgfsrc
475 SGPath config( globals->get_fg_root() );
476 config.append( "system.fgfsrc" );
477 fgParseOptions(config.str());
479 #if defined( unix ) || defined( __CYGWIN__ )
481 // Check for $fg_root/system.fgfsrc.hostname
482 gethostname( name, 256 );
483 config.concat( "." );
484 config.concat( name );
485 fgParseOptions(config.str());
488 // Check for ~/.fgfsrc
489 char* envp = ::getenv( "HOME" );
490 if ( envp != NULL ) {
492 config.append( ".fgfsrc" );
493 fgParseOptions(config.str());
496 #if defined( unix ) || defined( __CYGWIN__ )
497 // Check for ~/.fgfsrc.hostname
498 gethostname( name, 256 );
499 config.concat( "." );
500 config.concat( name );
501 fgParseOptions(config.str());
504 // Parse remaining command line options
505 // These will override anything specified in a config file
506 fgParseArgs(argc, argv);
510 // Read in configuration (file and command line)
511 bool fgInitConfig ( int argc, char **argv ) {
513 // First, set some sane default values
516 // Read global preferences from $FG_ROOT/preferences.xml
517 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
518 fgLoadProps("preferences.xml", globals->get_props());
519 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
521 // Detect the required language as early as possible
522 if ( !fgDetectLanguage() ) {
526 // Scan user config files and command line for a specified aircraft.
527 fgInitFGAircraft(argc, argv);
529 string aircraft = fgGetString("/sim/aircraft", "");
530 if ( aircraft.size() > 0 ) {
531 SGPath aircraft_path(globals->get_fg_root());
532 aircraft_path.append("Aircraft");
533 aircraft_path.append(aircraft);
534 aircraft_path.concat("-set.xml");
535 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
536 << " from " << aircraft_path.str());
538 readProperties(aircraft_path.str(), globals->get_props());
539 } catch (const sg_exception &e) {
540 string message = "Error reading default aircraft: ";
541 message += e.getFormattedMessage();
542 SG_LOG(SG_INPUT, SG_ALERT, message);
546 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
549 // parse options after loading aircraft to ensure any user
550 // overrides of defaults are honored.
551 do_options(argc, argv);
557 // find basic airport location info from airport database
558 bool fgFindAirportID( const string& id, FGAirport *a ) {
560 SGPath path( globals->get_fg_root() );
561 path.append( "Airports" );
562 path.append( "simple.mk4" );
563 FGAirports airports( path.c_str() );
565 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
567 if ( ! airports.search( id, a ) ) {
568 SG_LOG( SG_GENERAL, SG_ALERT,
569 "Failed to find " << id << " in " << path.str() );
576 SG_LOG( SG_GENERAL, SG_INFO,
577 "Position for " << id << " is ("
578 << a->longitude << ", "
579 << a->latitude << ")" );
585 // get airport elevation
586 static double fgGetAirportElev( const string& id ) {
590 SG_LOG( SG_GENERAL, SG_INFO,
591 "Finding elevation for airport: " << id );
593 if ( fgFindAirportID( id, &a ) ) {
601 // Preset lon/lat given an airport id
602 static bool fgSetPosFromAirportID( const string& id ) {
606 SG_LOG( SG_GENERAL, SG_INFO,
607 "Attempting to set starting position from airport code " << id );
609 if ( fgFindAirportID( id, &a ) ) {
611 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
612 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
614 // other code depends on the actual postition being set so set
616 fgSetDouble("/position/longitude-deg", a.longitude );
617 fgSetDouble("/position/latitude-deg", a.latitude );
619 SG_LOG( SG_GENERAL, SG_INFO,
620 "Position for " << id << " is (" << a.longitude
621 << ", " << a.latitude << ")" );
630 // Set current tower position lon/lat given an airport id
631 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
633 // tower height hard coded for now...
634 float towerheight=50.0f;
636 // make a little off the heading for 1 runway airports...
637 float fudge_lon = fabs(sin(hdg)) * .003f;
638 float fudge_lat = .003f - fudge_lon;
640 if ( fgFindAirportID( id, &a ) ) {
641 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
642 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
643 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
652 // Set current_options lon/lat given an airport id and heading (degrees)
653 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
656 double found_dir = 0.0;
659 // set initial position from runway and heading
661 SGPath path( globals->get_fg_root() );
662 path.append( "Airports" );
663 path.append( "runways.mk4" );
664 FGRunways runways( path.c_str() );
666 SG_LOG( SG_GENERAL, SG_INFO,
667 "Attempting to set starting position from runway code "
668 << id << " heading " << tgt_hdg );
670 if ( ! runways.search( id, &r ) ) {
671 SG_LOG( SG_GENERAL, SG_ALERT,
672 "Failed to find " << id << " in database." );
677 double min_diff = 360.0;
679 while ( r.id == id ) {
681 diff = tgt_hdg - r.heading;
682 while ( diff < -180.0 ) { diff += 360.0; }
683 while ( diff > 180.0 ) { diff -= 360.0; }
685 SG_LOG( SG_GENERAL, SG_INFO,
686 "Runway " << r.rwy_no << " heading = " << r.heading <<
687 " diff = " << diff );
688 if ( diff < min_diff ) {
695 diff = tgt_hdg - r.heading - 180.0;
696 while ( diff < -180.0 ) { diff += 360.0; }
697 while ( diff > 180.0 ) { diff -= 360.0; }
699 SG_LOG( SG_GENERAL, SG_INFO,
700 "Runway -" << r.rwy_no << " heading = " <<
702 " diff = " << diff );
703 if ( diff < min_diff ) {
712 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
713 << " + " << found_dir );
719 double heading = found_r.heading + found_dir;
720 while ( heading >= 360.0 ) { heading -= 360.0; }
722 double lat2, lon2, az2;
723 double azimuth = found_r.heading + found_dir + 180.0;
724 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
726 SG_LOG( SG_GENERAL, SG_INFO,
727 "runway = " << found_r.lon << ", " << found_r.lat
728 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
729 << " heading = " << azimuth );
731 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
732 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
733 &lat2, &lon2, &az2 );
735 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
737 double odist = fgGetDouble("/sim/presets/offset-distance");
738 odist *= SG_NM_TO_METER;
739 double oaz = azimuth;
740 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
741 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
743 while ( oaz >= 360.0 ) { oaz -= 360.0; }
744 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
750 fgSetDouble("/sim/presets/longitude-deg", lon2 );
751 fgSetDouble("/sim/presets/latitude-deg", lat2 );
752 fgSetDouble("/sim/presets/heading-deg", heading );
754 // other code depends on the actual values being set ...
755 fgSetDouble("/position/longitude-deg", lon2 );
756 fgSetDouble("/position/latitude-deg", lat2 );
757 fgSetDouble("/orientation/heading-deg", heading );
759 SG_LOG( SG_GENERAL, SG_INFO,
760 "Position for " << id << " is ("
762 << lat2 << ") new heading is "
769 // Set current_options lon/lat given an airport id and heading (degrees)
770 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
773 double heading = 0.0;
777 // standardize input number
778 string tmp = rwy.substr(1, 1);
779 if ( tmp == "L" || tmp == "R" || tmp == "C" ) {
787 // set initial position from runway and heading
789 SGPath path( globals->get_fg_root() );
790 path.append( "Airports" );
791 path.append( "runways.mk4" );
792 FGRunways runways( path.c_str() );
794 SG_LOG( SG_GENERAL, SG_INFO,
795 "Attempting to set starting position for "
796 << id << ":" << runway );
798 if ( ! runways.search( id, &r ) ) {
799 SG_LOG( SG_GENERAL, SG_ALERT,
800 "Failed to find " << id << " in database." );
804 while ( r.id == id ) {
806 if ( r.rwy_no == runway ) {
810 SG_LOG( SG_GENERAL, SG_INFO,
811 "Runway " << r.rwy_no << " heading = " << heading );
814 // calculate reciprocal runway number
815 string snum = r.rwy_no;
816 int len = snum.length();
818 string rev_letter = "";
820 for ( i = 0; i < len; ++i ) {
821 string tmp = snum.substr(i, 1);
825 } else if ( tmp == "R" ) {
828 } else if ( tmp == "C" ) {
833 for ( i = 0; i < len; ++i ) {
834 string tmp = snum.substr(i, 1);
835 if ( tmp == "L" || tmp == "R" || tmp == "C" || tmp == " " ) {
836 snum = snum.substr(0, i);
839 SG_LOG(SG_GENERAL, SG_DEBUG, "Runway num = '" << snum << "'");
840 int num = atoi( snum.c_str() ) + 18;
841 while ( num > 36 ) { num -= 36; }
842 while ( num <= 0 ) { num += 36; }
845 snprintf( recip_no, 10, "%02d%s", num, rev_letter.c_str() );
848 if ( (string)recip_no == runway ) {
850 heading = r.heading + 180;
851 while ( heading > 360.0 ) { heading -= 360; }
853 SG_LOG( SG_GENERAL, SG_INFO,
854 "Runway " << r.rwy_no << " heading = " << heading );
864 double lat2, lon2, az2;
865 double azimuth = heading + 180.0;
866 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
868 SG_LOG( SG_GENERAL, SG_INFO,
869 "runway = " << found_r.lon << ", " << found_r.lat
870 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
871 << " heading = " << azimuth );
873 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
875 found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
876 &lat2, &lon2, &az2 );
878 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
881 double odist = fgGetDouble("/sim/presets/offset-distance");
882 odist *= SG_NM_TO_METER;
883 double oaz = azimuth;
884 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
886 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
888 while ( oaz >= 360.0 ) { oaz -= 360.0; }
889 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
895 fgSetDouble("/sim/presets/longitude-deg", lon2 );
896 fgSetDouble("/sim/presets/latitude-deg", lat2 );
897 fgSetDouble("/sim/presets/heading-deg", heading );
899 // other code depends on the actual values being set ...
900 fgSetDouble("/position/longitude-deg", lon2 );
901 fgSetDouble("/position/latitude-deg", lat2 );
902 fgSetDouble("/orientation/heading-deg", heading );
904 SG_LOG( SG_GENERAL, SG_INFO,
905 "Position for " << id << " is ("
907 << lat2 << ") new heading is "
917 static void fgSetDistOrAltFromGlideSlope() {
918 string apt_id = fgGetString("/sim/presets/airport-id");
919 double gs = fgGetDouble("/sim/presets/glideslope-deg")
920 * SG_DEGREES_TO_RADIANS ;
921 double od = fgGetDouble("/sim/presets/offset-distance");
922 double alt = fgGetDouble("/sim/presets/altitude-ft");
924 double apt_elev = 0.0;
925 if ( ! apt_id.empty() ) {
926 apt_elev = fgGetAirportElev( apt_id );
927 if ( apt_elev < -9990.0 ) {
934 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
935 // set altitude from glideslope and offset-distance
936 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
937 alt = fabs(od*tan(gs)) + apt_elev;
938 fgSetDouble("/sim/presets/altitude-ft", alt);
939 fgSetBool("/sim/presets/onground", false);
940 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
942 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
943 // set offset-distance from glideslope and altitude
944 od = (alt - apt_elev) / tan(gs);
945 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
946 fgSetDouble("/sim/presets/offset-distance", od);
947 fgSetBool("/sim/presets/onground", false);
948 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
950 } else if( fabs(gs) > 0.01 ) {
951 SG_LOG( SG_GENERAL, SG_ALERT,
952 "Glideslope given but not altitude or offset-distance." );
953 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
954 fgSetDouble("/sim/presets/glideslope-deg", 0);
955 fgSetBool("/sim/presets/onground", true);
960 // Set current_options lon/lat given an airport id and heading (degrees)
961 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
962 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
964 // set initial position from runway and heading
966 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
967 << id << ":" << freq );
969 double lon = nav->get_lon();
970 double lat = nav->get_lat();
972 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
974 double odist = fgGetDouble("/sim/presets/offset-distance")
976 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
978 while ( oaz >= 360.0 ) { oaz -= 360.0; }
979 double olat, olon, az2;
980 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
987 fgSetDouble("/sim/presets/longitude-deg", lon );
988 fgSetDouble("/sim/presets/latitude-deg", lat );
990 // other code depends on the actual values being set ...
991 fgSetDouble("/position/longitude-deg", lon );
992 fgSetDouble("/position/latitude-deg", lat );
993 fgSetDouble("/orientation/heading-deg",
994 fgGetDouble("/sim/presets/heading-deg") );
996 SG_LOG( SG_GENERAL, SG_INFO,
997 "Position for " << id << ":" << freq << " is ("
998 << lon << ", "<< lat << ")" );
1002 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
1003 << id << ":" << freq );
1009 // Set current_options lon/lat given an airport id and heading (degrees)
1010 static bool fgSetPosFromFix( const string& id ) {
1013 // set initial position from runway and heading
1014 if ( current_fixlist->query( id.c_str(), &fix ) ) {
1015 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
1018 double lon = fix.get_lon();
1019 double lat = fix.get_lat();
1021 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
1023 double odist = fgGetDouble("/sim/presets/offset-distance")
1025 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
1027 while ( oaz >= 360.0 ) { oaz -= 360.0; }
1028 double olat, olon, az2;
1029 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
1036 fgSetDouble("/sim/presets/longitude-deg", lon );
1037 fgSetDouble("/sim/presets/latitude-deg", lat );
1039 // other code depends on the actual values being set ...
1040 fgSetDouble("/position/longitude-deg", lon );
1041 fgSetDouble("/position/latitude-deg", lat );
1042 fgSetDouble("/orientation/heading-deg",
1043 fgGetDouble("/sim/presets/heading-deg") );
1045 SG_LOG( SG_GENERAL, SG_INFO,
1046 "Position for " << id << " is ("
1047 << lon << ", "<< lat << ")" );
1051 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
1058 // Set the initial position based on presets (or defaults)
1059 bool fgInitPosition() {
1060 bool set_pos = false;
1062 // If glideslope is specified, then calculate offset-distance or
1063 // altitude relative to glide slope if either of those was not
1065 fgSetDistOrAltFromGlideSlope();
1067 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1068 // If not, check for an airport-id and use that.
1069 // If not, default to the middle of the KSFO field.
1070 // The default values for lon/lat are deliberately out of range
1071 // so that the airport-id can take effect; valid lon/lat will
1072 // override airport-id, however.
1073 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1074 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1075 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1076 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1081 string apt = fgGetString("/sim/presets/airport-id");
1082 string rwy_no = fgGetString("/sim/presets/runway");
1083 double hdg = fgGetDouble("/sim/presets/heading-deg");
1084 string vor = fgGetString("/sim/presets/vor-id");
1085 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1086 string ndb = fgGetString("/sim/presets/ndb-id");
1087 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1088 string fix = fgGetString("/sim/presets/fix");
1089 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1090 // An airport + runway is requested
1091 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1092 // set position (a little off the heading for single
1094 fgSetTowerPosFromAirportID( apt, hdg );
1099 if ( !set_pos && !apt.empty() ) {
1100 // An airport is requested (find runway closest to hdg)
1101 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1102 // set position (a little off the heading for single
1104 fgSetTowerPosFromAirportID( apt, hdg );
1109 if ( !set_pos && !vor.empty() ) {
1110 // a VOR is requested
1111 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1112 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1113 fgSetBool("/sim/presets/onground", false);
1115 fgSetBool("/sim/presets/onground", true);
1120 if ( !set_pos && !ndb.empty() ) {
1121 // an NDB is requested
1122 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1123 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1124 fgSetBool("/sim/presets/onground", false);
1126 fgSetBool("/sim/presets/onground", true);
1131 if ( !set_pos && !fix.empty() ) {
1132 // a Fix is requested
1133 if ( fgSetPosFromFix( fix ) ) {
1134 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1135 fgSetBool("/sim/presets/onground", false);
1137 fgSetBool("/sim/presets/onground", true);
1144 // No lon/lat specified, no airport specified, default to
1145 // middle of KSFO field.
1146 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1147 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1150 fgSetDouble( "/position/longitude-deg",
1151 fgGetDouble("/sim/presets/longitude-deg") );
1152 fgSetDouble( "/position/latitude-deg",
1153 fgGetDouble("/sim/presets/latitude-deg") );
1154 fgSetDouble( "/orientation/heading-deg",
1155 fgGetDouble("/sim/presets/heading-deg") );
1161 // General house keeping initializations
1162 bool fgInitGeneral() {
1165 #if defined(FX) && defined(XMESA)
1166 char *mesa_win_state;
1169 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1170 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1172 root = globals->get_fg_root();
1173 if ( ! root.length() ) {
1174 // No root path set? Then bail ...
1175 SG_LOG( SG_GENERAL, SG_ALERT,
1176 "Cannot continue without a path to the base package "
1177 << "being defined." );
1180 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1182 #if defined(FX) && defined(XMESA)
1183 // initialize full screen flag
1184 globals->set_fullscreen(false);
1185 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1186 // Test for the MESA_GLX_FX env variable
1187 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1188 // test if we are fullscreen mesa/glide
1189 if ( (mesa_win_state[0] == 'f') ||
1190 (mesa_win_state[0] == 'F') ) {
1191 globals->set_fullscreen(true);
1201 // Initialize the flight model subsystem. This just creates the
1202 // object. The actual fdm initialization is delayed until we get a
1203 // proper scenery elevation hit. This is checked for in main.cxx
1207 if ( cur_fdm_state ) {
1208 delete cur_fdm_state;
1212 double dt = 1.0 / fgGetInt("/sim/model-hz");
1213 aircraft_dir = fgGetString("/sim/aircraft-dir");
1214 const string &model = fgGetString("/sim/flight-model");
1217 if ( model == "larcsim" ) {
1218 cur_fdm_state = new FGLaRCsim( dt );
1219 } else if ( model == "jsb" ) {
1220 cur_fdm_state = new FGJSBsim( dt );
1221 } else if ( model == "ada" ) {
1222 cur_fdm_state = new FGADA( dt );
1223 } else if ( model == "balloon" ) {
1224 cur_fdm_state = new FGBalloonSim( dt );
1225 } else if ( model == "magic" ) {
1226 cur_fdm_state = new FGMagicCarpet( dt );
1227 } else if ( model == "ufo" ) {
1228 cur_fdm_state = new FGUFO( dt );
1229 } else if ( model == "external" ) {
1230 // external is a synonym for "--fdm=null" and is
1231 // maintained here for backwards compatibility
1232 cur_fdm_state = new FGNullFDM( dt );
1233 } else if ( model.find("network") == 0 ) {
1234 string host = "localhost";
1238 string net_options = model.substr(8);
1239 string::size_type begin, end;
1242 end = net_options.find( ",", begin );
1243 if ( end != string::npos ) {
1244 host = net_options.substr(begin, end - begin);
1248 end = net_options.find( ",", begin );
1249 if ( end != string::npos ) {
1250 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1254 end = net_options.find( ",", begin );
1255 if ( end != string::npos ) {
1256 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1260 end = net_options.find( ",", begin );
1261 if ( end != string::npos ) {
1262 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1265 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1266 } else if ( model == "null" ) {
1267 cur_fdm_state = new FGNullFDM( dt );
1268 } else if ( model == "yasim" ) {
1269 cur_fdm_state = new YASim( dt );
1271 SG_LOG(SG_GENERAL, SG_ALERT,
1272 "Unrecognized flight model '" << model
1273 << "', cannot init flight dynamics model.");
1277 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1282 static void printMat(const sgVec4 *mat, char *name="")
1285 cout << name << endl;
1286 for(i=0; i<4; i++) {
1287 cout <<" "<<mat[i][0]<<" "<<mat[i][1]<<" "<<mat[i][2]<<" "<<mat[i][3]<<endl;
1292 // Initialize view parameters
1294 // force update of model so that viewer can get some data...
1295 globals->get_aircraft_model()->update(0);
1296 // run update for current view so that data is current...
1297 globals->get_viewmgr()->update(0);
1299 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1300 printMat(globals->get_current_view()->get_UP(),"UP");
1301 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1306 SGTime *fgInitTime() {
1308 static const SGPropertyNode *longitude
1309 = fgGetNode("/position/longitude-deg");
1310 static const SGPropertyNode *latitude
1311 = fgGetNode("/position/latitude-deg");
1312 static const SGPropertyNode *cur_time_override
1313 = fgGetNode("/sim/time/cur-time-override", true);
1315 SGPath zone( globals->get_fg_root() );
1316 zone.append( "Timezone" );
1317 SGTime *t = new SGTime( longitude->getDoubleValue()
1318 * SGD_DEGREES_TO_RADIANS,
1319 latitude->getDoubleValue()
1320 * SGD_DEGREES_TO_RADIANS,
1322 cur_time_override->getLongValue() );
1324 // Handle potential user specified time offsets
1325 time_t cur_time = t->get_cur_time();
1326 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1327 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1328 time_t aircraftLocalTime =
1329 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1331 // Okay, we now have six possible scenarios
1332 int offset = fgGetInt("/sim/startup/time-offset");
1333 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1334 if (offset_type == "system-offset") {
1335 globals->set_warp( offset );
1336 } else if (offset_type == "gmt-offset") {
1337 globals->set_warp( offset - (currGMT - systemLocalTime) );
1338 } else if (offset_type == "latitude-offset") {
1339 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1340 } else if (offset_type == "system") {
1341 globals->set_warp( offset - cur_time );
1342 } else if (offset_type == "gmt") {
1343 globals->set_warp( offset - currGMT );
1344 } else if (offset_type == "latitude") {
1345 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1348 SG_LOG( SG_GENERAL, SG_ALERT,
1349 "FG_TIME::Unsupported offset type " << offset_type );
1353 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1354 << globals->get_warp() );
1356 globals->set_warp_delta( 0 );
1358 t->update( 0.0, 0.0,
1359 cur_time_override->getLongValue(),
1360 globals->get_warp() );
1366 // This is the top level init routine which calls all the other
1367 // initialization routines. If you are adding a subsystem to flight
1368 // gear, its initialization call should located in this routine.
1369 // Returns non-zero if a problem encountered.
1370 bool fgInitSubsystems() {
1371 static const SGPropertyNode *longitude
1372 = fgGetNode("/sim/presets/longitude-deg");
1373 static const SGPropertyNode *latitude
1374 = fgGetNode("/sim/presets/latitude-deg");
1375 static const SGPropertyNode *altitude
1376 = fgGetNode("/sim/presets/altitude-ft");
1378 fgLIGHT *l = &cur_light_params;
1380 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1381 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1384 ////////////////////////////////////////////////////////////////////
1385 // Initialize the material property subsystem.
1386 ////////////////////////////////////////////////////////////////////
1388 SGPath mpath( globals->get_fg_root() );
1389 mpath.append( "materials.xml" );
1390 if ( ! material_lib.load( mpath.str() ) ) {
1391 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1395 ////////////////////////////////////////////////////////////////////
1396 // Initialize the event manager subsystem.
1397 ////////////////////////////////////////////////////////////////////
1399 global_events.init();
1401 // Output event stats every 60 seconds
1402 global_events.Register( "FGEventMgr::print_stats()",
1403 &global_events, &FGEventMgr::print_stats,
1407 ////////////////////////////////////////////////////////////////////
1408 // Initialize the scenery management subsystem.
1409 ////////////////////////////////////////////////////////////////////
1411 if ( globals->get_tile_mgr()->init() ) {
1412 // Load the local scenery data
1413 double visibility_meters = fgGetDouble("/environment/visibility-m");
1415 globals->get_tile_mgr()->update( visibility_meters );
1417 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1421 // cause refresh of viewer scenery timestamps every 15 seconds...
1422 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1423 globals->get_tile_mgr(),
1424 &FGTileMgr::refresh_view_timestamps,
1427 SG_LOG( SG_GENERAL, SG_DEBUG,
1428 "Current terrain elevation after tile mgr init " <<
1429 globals->get_scenery()->get_cur_elev() );
1432 ////////////////////////////////////////////////////////////////////
1433 // Initialize the flight model subsystem.
1434 ////////////////////////////////////////////////////////////////////
1438 // allocates structures so must happen before any of the flight
1439 // model or control parameters are set
1440 fgAircraftInit(); // In the future this might not be the case.
1443 ////////////////////////////////////////////////////////////////////
1444 // Initialize the view manager subsystem.
1445 ////////////////////////////////////////////////////////////////////
1450 ////////////////////////////////////////////////////////////////////
1451 // Initialize the lighting subsystem.
1452 ////////////////////////////////////////////////////////////////////
1454 // fgUpdateSunPos() needs a few position and view parameters set
1455 // so it can calculate local relative sun angle and a few other
1456 // things for correctly orienting the sky.
1459 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1461 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1464 // Initialize Lighting interpolation tables
1467 // force one lighting update to make it right to start with...
1469 // update the lighting parameters (based on sun angle)
1470 global_events.Register( "fgLight::Update()",
1471 &cur_light_params, &fgLIGHT::Update,
1475 ////////////////////////////////////////////////////////////////////
1476 // Create and register the logger.
1477 ////////////////////////////////////////////////////////////////////
1479 globals->add_subsystem("logger", new FGLogger);
1482 #if defined(HAVE_PLIB_PSL)
1483 ////////////////////////////////////////////////////////////////////
1484 // Create and register the script manager.
1485 ////////////////////////////////////////////////////////////////////
1487 globals->add_subsystem("scripting", new FGScriptMgr);
1488 #endif // HAVE_PLIB_PSL
1491 ////////////////////////////////////////////////////////////////////
1492 // Create and register the XML GUI.
1493 ////////////////////////////////////////////////////////////////////
1495 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1498 ////////////////////////////////////////////////////////////////////
1499 // Initialize the local time subsystem.
1500 ////////////////////////////////////////////////////////////////////
1502 // update the current timezone each 30 minutes
1503 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1507 ////////////////////////////////////////////////////////////////////
1508 // Initialize the weather subsystem.
1509 ////////////////////////////////////////////////////////////////////
1511 // Initialize the weather modeling subsystem
1513 // Initialize the WeatherDatabase
1514 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1516 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1517 current_aircraft.fdm_state->get_Longitude(),
1518 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1519 double init_vis = fgGetDouble("/environment/visibility-m");
1521 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1523 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1525 working_type = FGLocalWeatherDatabase::use_internet;
1527 working_type = FGLocalWeatherDatabase::default_mode;
1530 if ( init_vis > 0 ) {
1531 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1532 new FGLocalWeatherDatabase( position,
1533 globals->get_fg_root(),
1537 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1538 new FGLocalWeatherDatabase( position,
1539 globals->get_fg_root(),
1543 // cout << theFGLocalWeatherDatabase << endl;
1544 // cout << "visibility = "
1545 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1547 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1549 // register the periodic update of the weather
1550 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1553 globals->get_environment_mgr()->init();
1554 globals->get_environment_mgr()->bind();
1557 #ifdef FG_USE_CLOUDS_3D
1558 ////////////////////////////////////////////////////////////////////
1559 // Initialize the 3D cloud subsystem.
1560 ////////////////////////////////////////////////////////////////////
1561 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1562 SGPath cloud_path(globals->get_fg_root());
1563 cloud_path.append("large.sky");
1564 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1565 if ( !sgCloud3d->Load( cloud_path.str(),
1566 latitude->getDoubleValue(),
1567 longitude->getDoubleValue()) )
1569 fgSetBool("/sim/rendering/clouds3d", false);
1570 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1572 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1576 ////////////////////////////////////////////////////////////////////
1577 // Initialize vor/ndb/ils/fix list management and query systems
1578 ////////////////////////////////////////////////////////////////////
1580 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
1582 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
1583 current_navlist = new FGNavList;
1584 SGPath p_nav( globals->get_fg_root() );
1585 p_nav.append( "Navaids/default.nav" );
1586 current_navlist->init( p_nav );
1588 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
1589 current_beacons = new FGMarkerBeacons;
1590 current_beacons->init();
1591 current_ilslist = new FGILSList;
1592 SGPath p_ils( globals->get_fg_root() );
1593 p_ils.append( "Navaids/default.ils" );
1594 current_ilslist->init( p_ils );
1596 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1597 current_fixlist = new FGFixList;
1598 SGPath p_fix( globals->get_fg_root() );
1599 p_fix.append( "Navaids/default.fix" );
1600 current_fixlist->init( p_fix );
1602 ////////////////////////////////////////////////////////////////////
1603 // Initialize ATC list management and query systems
1604 ////////////////////////////////////////////////////////////////////
1606 SG_LOG(SG_GENERAL, SG_INFO, " ATIS");
1607 current_atislist = new FGATISList;
1608 SGPath p_atis( globals->get_fg_root() );
1609 p_atis.append( "ATC/default.atis" );
1610 current_atislist->init( p_atis );
1612 SG_LOG(SG_GENERAL, SG_INFO, " Tower");
1613 current_towerlist = new FGTowerList;
1614 SGPath p_tower( globals->get_fg_root() );
1615 p_tower.append( "ATC/default.tower" );
1616 current_towerlist->init( p_tower );
1618 SG_LOG(SG_GENERAL, SG_INFO, " Approach");
1619 current_approachlist = new FGApproachList;
1620 SGPath p_approach( globals->get_fg_root() );
1621 p_approach.append( "ATC/default.approach" );
1622 current_approachlist->init( p_approach );
1624 ////////////////////////////////////////////////////////////////////
1625 // Initialise ATC display system
1626 ////////////////////////////////////////////////////////////////////
1628 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1629 globals->set_ATC_display(new FGATCDisplay);
1630 globals->get_ATC_display()->init();
1632 ////////////////////////////////////////////////////////////////////
1633 // Initialise the ATC Manager
1634 ////////////////////////////////////////////////////////////////////
1636 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1637 globals->set_ATC_mgr(new FGATCMgr);
1638 globals->get_ATC_mgr()->init();
1640 ////////////////////////////////////////////////////////////////////
1641 // Initialise the AI Manager
1642 ////////////////////////////////////////////////////////////////////
1644 if (fgGetBool("/sim/ai-traffic/enabled")) {
1645 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1646 globals->set_AI_mgr(new FGAIMgr);
1647 globals->get_AI_mgr()->init();
1650 #ifdef ENABLE_AUDIO_SUPPORT
1651 ////////////////////////////////////////////////////////////////////
1652 // Initialize the sound subsystem.
1653 ////////////////////////////////////////////////////////////////////
1655 globals->set_soundmgr(new FGSoundMgr);
1656 globals->get_soundmgr()->init();
1657 globals->get_soundmgr()->bind();
1660 ////////////////////////////////////////////////////////////////////
1661 // Initialize the sound-effects subsystem.
1662 ////////////////////////////////////////////////////////////////////
1664 globals->add_subsystem("fx", new FGFX);
1668 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1669 globals->add_subsystem("systems", new FGSystemMgr);
1671 ////////////////////////////////////////////////////////////////////
1672 // Initialize the radio stack subsystem.
1673 ////////////////////////////////////////////////////////////////////
1675 current_radiostack = new FGRadioStack;
1676 current_radiostack->init();
1677 current_radiostack->bind();
1680 ////////////////////////////////////////////////////////////////////
1681 // Initialize the cockpit subsystem
1682 ////////////////////////////////////////////////////////////////////
1684 if( fgCockpitInit( ¤t_aircraft )) {
1685 // Cockpit initialized ok.
1687 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1692 ////////////////////////////////////////////////////////////////////
1693 // Initialize the autopilot subsystem.
1694 ////////////////////////////////////////////////////////////////////
1696 globals->set_autopilot(new FGAutopilot);
1697 globals->get_autopilot()->init();
1698 globals->get_autopilot()->bind();
1700 // FIXME: these should go in the
1701 // GUI initialization code, not here.
1703 NewTgtAirportInit();
1707 ////////////////////////////////////////////////////////////////////
1708 // Initialize I/O subsystem.
1709 ////////////////////////////////////////////////////////////////////
1711 globals->get_io()->init();
1712 globals->get_io()->bind();
1714 // Initialize the 2D panel.
1715 string panel_path = fgGetString("/sim/panel/path",
1716 "Panels/Default/default.xml");
1717 current_panel = fgReadPanel(panel_path);
1718 if (current_panel == 0) {
1719 SG_LOG( SG_INPUT, SG_ALERT,
1720 "Error reading new panel from " << panel_path );
1722 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1723 current_panel->init();
1724 current_panel->bind();
1728 ////////////////////////////////////////////////////////////////////
1729 // Initialize the default (kludged) properties.
1730 ////////////////////////////////////////////////////////////////////
1735 ////////////////////////////////////////////////////////////////////
1736 // Initialize the controls subsystem.
1737 ////////////////////////////////////////////////////////////////////
1739 globals->get_controls()->init();
1740 globals->get_controls()->bind();
1743 ////////////////////////////////////////////////////////////////////
1744 // Initialize the input subsystem.
1745 ////////////////////////////////////////////////////////////////////
1747 globals->add_subsystem("input", new FGInput);
1750 ////////////////////////////////////////////////////////////////////
1751 // Bind and initialize subsystems.
1752 ////////////////////////////////////////////////////////////////////
1754 globals->get_subsystem_mgr()->bind();
1755 globals->get_subsystem_mgr()->init();
1758 ////////////////////////////////////////////////////////////////////////
1759 // End of subsystem initialization.
1760 ////////////////////////////////////////////////////////////////////
1762 SG_LOG( SG_GENERAL, SG_INFO, endl);
1764 // Save the initial state for future
1766 globals->saveInitialState();
1772 void fgReInitSubsystems()
1774 static const SGPropertyNode *longitude
1775 = fgGetNode("/sim/presets/longitude-deg");
1776 static const SGPropertyNode *latitude
1777 = fgGetNode("/sim/presets/latitude-deg");
1778 static const SGPropertyNode *altitude
1779 = fgGetNode("/sim/presets/altitude-ft");
1780 static const SGPropertyNode *master_freeze
1781 = fgGetNode("/sim/freeze/master");
1783 SG_LOG( SG_GENERAL, SG_INFO,
1784 "fgReInitSubsystems(): /position/altitude = "
1785 << altitude->getDoubleValue() );
1787 bool freeze = master_freeze->getBoolValue();
1789 fgSetBool("/sim/freeze/master", true);
1792 // Initialize the FDM
1795 // allocates structures so must happen before any of the flight
1796 // model or control parameters are set
1797 fgAircraftInit(); // In the future this might not be the case.
1799 // copy viewer settings into current-view path
1800 globals->get_viewmgr()->copyToCurrent();
1804 globals->get_controls()->reset_all();
1805 globals->get_autopilot()->reset();
1809 cur_light_params.Update();
1810 fgUpdateLocalTime();
1813 fgSetBool("/sim/freeze/master", false);