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/AIMgr.hxx>
80 #include <Autopilot/auto_gui.hxx>
81 #include <Autopilot/newauto.hxx>
82 #include <Cockpit/cockpit.hxx>
83 #include <Cockpit/radiostack.hxx>
84 #include <Cockpit/panel.hxx>
85 #include <Cockpit/panel_io.hxx>
86 #include <FDM/ADA.hxx>
87 #include <FDM/Balloon.h>
88 #include <FDM/ExternalNet/ExternalNet.hxx>
89 #include <FDM/ExternalPipe/ExternalPipe.hxx>
90 #include <FDM/JSBSim/JSBSim.hxx>
91 #include <FDM/LaRCsim.hxx>
92 #include <FDM/MagicCarpet.hxx>
93 #include <FDM/UFO.hxx>
94 #include <FDM/NullFDM.hxx>
95 #include <FDM/YASim/YASim.hxx>
96 #include <GUI/new_gui.hxx>
97 #include <Include/general.hxx>
98 #include <Input/input.hxx>
99 #include <Instrumentation/instrument_mgr.hxx>
100 // #include <Joystick/joystick.hxx>
101 #include <Objects/matlib.hxx>
102 #include <Model/acmodel.hxx>
103 #include <Navaids/fixlist.hxx>
104 #include <Navaids/ilslist.hxx>
105 #include <Navaids/mkrbeacons.hxx>
106 #include <Navaids/navlist.hxx>
107 #include <Scenery/scenery.hxx>
108 #include <Scenery/tilemgr.hxx>
109 #if defined(HAVE_PLIB_PSL)
110 #include <Scripting/scriptmgr.hxx>
112 #include <Sound/fg_fx.hxx>
113 #include <Sound/soundmgr.hxx>
114 #include <Systems/system_mgr.hxx>
115 #include <Time/FGEventMgr.hxx>
116 #include <Time/light.hxx>
117 #include <Time/sunpos.hxx>
118 #include <Time/moonpos.hxx>
119 #include <Time/tmp.hxx>
122 #include <MultiPlayer/multiplaytxmgr.hxx>
123 #include <MultiPlayer/multiplayrxmgr.hxx>
127 # include <WeatherCM/FGLocalWeatherDatabase.h>
129 # include <Environment/environment_mgr.hxx>
132 #include "fg_init.hxx"
134 #include "fg_commands.hxx"
135 #include "fg_props.hxx"
136 #include "options.hxx"
137 #include "globals.hxx"
138 #include "logger.hxx"
139 #include "viewmgr.hxx"
141 #if defined(FX) && defined(XMESA)
142 #include <GL/xmesa.h>
145 SG_USING_STD(string);
147 extern const char *default_root;
149 #ifdef FG_USE_CLOUDS_3D
150 SkySceneLoader *sgCloud3d;
154 // Scan the command line options for the specified option and return
156 static string fgScanForOption( const string& option, int argc, char **argv ) {
159 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
161 int len = option.length();
164 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
166 string arg = argv[i];
167 if ( arg.find( option ) == 0 ) {
168 return arg.substr( len );
178 // Scan the user config files for the specified option and return
180 static string fgScanForOption( const string& option, const string& path ) {
181 sg_gzifstream in( path );
182 if ( !in.is_open() ) {
186 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
188 int len = option.length();
192 while ( ! in.eof() ) {
195 while ( in.get(c) && c != '\0' ) {
200 #if defined( macintosh )
201 getline( in, line, '\r' );
203 getline( in, line, '\n' );
206 // catch extraneous (DOS) line ending character
207 if ( line[line.length() - 1] < 32 ) {
208 line = line.substr( 0, line.length()-1 );
211 if ( line.find( option ) == 0 ) {
212 return line.substr( len );
222 // Read in configuration (files and command line options) but only set
224 bool fgInitFGRoot ( int argc, char **argv ) {
228 // First parse command line options looking for --fg-root=, this
229 // will override anything specified in a config file
230 root = fgScanForOption( "--fg-root=", argc, argv);
232 #if defined( unix ) || defined( __CYGWIN__ )
233 // Next check home directory for .fgfsrc.hostname file
234 if ( root.empty() ) {
235 envp = ::getenv( "HOME" );
236 if ( envp != NULL ) {
237 SGPath config( envp );
238 config.append( ".fgfsrc" );
240 gethostname( name, 256 );
241 config.concat( "." );
242 config.concat( name );
243 root = fgScanForOption( "--fg-root=", config.str() );
248 // Next check home directory for .fgfsrc file
249 if ( root.empty() ) {
250 envp = ::getenv( "HOME" );
251 if ( envp != NULL ) {
252 SGPath config( envp );
253 config.append( ".fgfsrc" );
254 root = fgScanForOption( "--fg-root=", config.str() );
258 // Next check if fg-root is set as an env variable
259 if ( root.empty() ) {
260 envp = ::getenv( "FG_ROOT" );
261 if ( envp != NULL ) {
266 // Otherwise, default to a random compiled-in location if we can't
267 // find fg-root any other way.
268 if ( root.empty() ) {
269 #if defined( __CYGWIN__ )
270 root = "/FlightGear";
271 #elif defined( WIN32 )
272 root = "\\FlightGear";
273 #elif defined( macintosh )
280 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
281 globals->set_fg_root(root);
287 // Read in configuration (files and command line options) but only set
289 bool fgInitFGAircraft ( int argc, char **argv ) {
293 // First parse command line options looking for --aircraft=, this
294 // will override anything specified in a config file
295 aircraft = fgScanForOption( "--aircraft=", argc, argv );
297 #if defined( unix ) || defined( __CYGWIN__ )
298 // Next check home directory for .fgfsrc.hostname file
299 if ( aircraft.empty() ) {
300 envp = ::getenv( "HOME" );
301 if ( envp != NULL ) {
302 SGPath config( envp );
303 config.append( ".fgfsrc" );
305 gethostname( name, 256 );
306 config.concat( "." );
307 config.concat( name );
308 aircraft = fgScanForOption( "--aircraft=", config.str() );
313 // Next check home directory for .fgfsrc file
314 if ( aircraft.empty() ) {
315 envp = ::getenv( "HOME" );
316 if ( envp != NULL ) {
317 SGPath config( envp );
318 config.append( ".fgfsrc" );
319 aircraft = fgScanForOption( "--aircraft=", config.str() );
323 // if an aircraft was specified, set the property name
324 if ( !aircraft.empty() ) {
325 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
326 fgSetString("/sim/aircraft", aircraft.c_str() );
328 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
335 // Return the current base package version
336 string fgBasePackageVersion() {
337 SGPath base_path( globals->get_fg_root() );
338 base_path.append("version");
340 sg_gzifstream in( base_path.str() );
341 if ( !in.is_open() ) {
342 SGPath old_path( globals->get_fg_root() );
343 old_path.append( "Thanks" );
344 sg_gzifstream old( old_path.str() );
345 if ( !old.is_open() ) {
348 return "[old version]";
359 // Initialize the localization
360 SGPropertyNode *fgInitLocale(const char *language) {
361 SGPropertyNode *c_node = NULL, *d_node = NULL;
362 SGPropertyNode *intl = fgGetNode("/sim/intl");
364 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
366 // localization not defined
371 // Select the proper language from the list
373 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
374 for (unsigned int i = 0; i < locale.size(); i++) {
376 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
377 for (unsigned int j = 0; j < lang.size(); j++) {
379 if (!strcmp(lang[j]->getStringValue(), language)) {
388 d_node = intl->getChild("locale");
392 // Check for localized font
393 SGPropertyNode *font_n = c_node->getNode("font", true);
394 if ( !strcmp(font_n->getStringValue(), "") )
395 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
399 // Load the default strings
401 SGPath d_path( globals->get_fg_root() );
403 const char *d_path_str = d_node->getStringValue("strings");
405 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
409 d_path.append(d_path_str);
410 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
413 SGPropertyNode *strings = c_node->getNode("strings");
415 readProperties(d_path.str(), strings);
416 } catch (const sg_exception &e) {
417 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
422 // Load the language specific strings
424 if (c_node != d_node) {
425 SGPath c_path( globals->get_fg_root() );
427 const char *c_path_str = c_node->getStringValue("strings");
429 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
433 c_path.append(c_path_str);
434 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
438 readProperties(c_path.str(), strings);
439 } catch (const sg_exception &e) {
440 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
450 // Initialize the localization routines
451 bool fgDetectLanguage() {
452 char *language = ::getenv("LANG");
454 if (language == NULL) {
455 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
459 SGPropertyNode *locale = fgInitLocale(language);
461 SG_LOG(SG_GENERAL, SG_ALERT,
462 "No internationalization settings specified in preferences.xml" );
467 globals->set_locale( locale );
472 // Attempt to locate and parse the various non-XML config files in order
473 // from least precidence to greatest precidence
475 do_options (int argc, char ** argv)
477 // Check for $fg_root/system.fgfsrc
478 SGPath config( globals->get_fg_root() );
479 config.append( "system.fgfsrc" );
480 fgParseOptions(config.str());
482 #if defined( unix ) || defined( __CYGWIN__ )
484 // Check for $fg_root/system.fgfsrc.hostname
485 gethostname( name, 256 );
486 config.concat( "." );
487 config.concat( name );
488 fgParseOptions(config.str());
491 // Check for ~/.fgfsrc
492 char* envp = ::getenv( "HOME" );
493 if ( envp != NULL ) {
495 config.append( ".fgfsrc" );
496 fgParseOptions(config.str());
499 #if defined( unix ) || defined( __CYGWIN__ )
500 // Check for ~/.fgfsrc.hostname
501 gethostname( name, 256 );
502 config.concat( "." );
503 config.concat( name );
504 fgParseOptions(config.str());
507 // Parse remaining command line options
508 // These will override anything specified in a config file
509 fgParseArgs(argc, argv);
513 // Read in configuration (file and command line)
514 bool fgInitConfig ( int argc, char **argv ) {
516 // First, set some sane default values
519 // Read global preferences from $FG_ROOT/preferences.xml
520 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
521 fgLoadProps("preferences.xml", globals->get_props());
522 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
524 // Detect the required language as early as possible
525 if ( !fgDetectLanguage() ) {
529 // Scan user config files and command line for a specified aircraft.
530 fgInitFGAircraft(argc, argv);
532 string aircraft = fgGetString("/sim/aircraft", "");
533 if ( aircraft.size() > 0 ) {
534 SGPath aircraft_path(globals->get_fg_root());
535 aircraft_path.append("Aircraft");
536 aircraft_path.append(aircraft);
537 aircraft_path.concat("-set.xml");
538 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
539 << " from " << aircraft_path.str());
541 readProperties(aircraft_path.str(), globals->get_props());
542 } catch (const sg_exception &e) {
543 string message = "Error reading default aircraft: ";
544 message += e.getFormattedMessage();
545 SG_LOG(SG_INPUT, SG_ALERT, message);
549 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
552 // parse options after loading aircraft to ensure any user
553 // overrides of defaults are honored.
554 do_options(argc, argv);
560 // find basic airport location info from airport database
561 bool fgFindAirportID( const string& id, FGAirport *a ) {
563 SGPath path( globals->get_fg_root() );
564 path.append( "Airports" );
565 path.append( "simple.mk4" );
566 FGAirports airports( path.c_str() );
568 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
570 if ( ! airports.search( id, a ) ) {
571 SG_LOG( SG_GENERAL, SG_ALERT,
572 "Failed to find " << id << " in " << path.str() );
579 SG_LOG( SG_GENERAL, SG_INFO,
580 "Position for " << id << " is ("
581 << a->longitude << ", "
582 << a->latitude << ")" );
588 // get airport elevation
589 static double fgGetAirportElev( const string& id ) {
593 SG_LOG( SG_GENERAL, SG_INFO,
594 "Finding elevation for airport: " << id );
596 if ( fgFindAirportID( id, &a ) ) {
604 // Preset lon/lat given an airport id
605 static bool fgSetPosFromAirportID( const string& id ) {
609 SG_LOG( SG_GENERAL, SG_INFO,
610 "Attempting to set starting position from airport code " << id );
612 if ( fgFindAirportID( id, &a ) ) {
614 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
615 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
617 // other code depends on the actual postition being set so set
619 fgSetDouble("/position/longitude-deg", a.longitude );
620 fgSetDouble("/position/latitude-deg", a.latitude );
622 SG_LOG( SG_GENERAL, SG_INFO,
623 "Position for " << id << " is (" << a.longitude
624 << ", " << a.latitude << ")" );
633 // Set current tower position lon/lat given an airport id
634 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
636 // tower height hard coded for now...
637 float towerheight=50.0f;
639 // make a little off the heading for 1 runway airports...
640 float fudge_lon = fabs(sin(hdg)) * .003f;
641 float fudge_lat = .003f - fudge_lon;
643 if ( fgFindAirportID( id, &a ) ) {
644 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
645 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
646 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
655 // Set current_options lon/lat given an airport id and heading (degrees)
656 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
660 // set initial position from runway and heading
662 SGPath path( globals->get_fg_root() );
663 path.append( "Airports" );
664 path.append( "runways.mk4" );
665 FGRunways runways( path.c_str() );
667 SG_LOG( SG_GENERAL, SG_INFO,
668 "Attempting to set starting position from airport code "
669 << id << " heading " << tgt_hdg );
671 if ( ! runways.search( id, (int)tgt_hdg, &r ) ) {
672 SG_LOG( SG_GENERAL, SG_ALERT,
673 "Failed to find a good runway for " << id << '\n' );
680 double lat2, lon2, az2;
681 double heading = r.heading;
682 double azimuth = heading + 180.0;
683 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
685 SG_LOG( SG_GENERAL, SG_INFO,
686 "runway = " << r.lon << ", " << r.lat
687 << " length = " << r.length * SG_FEET_TO_METER
688 << " heading = " << azimuth );
690 geo_direct_wgs_84 ( 0, r.lat, r.lon, azimuth,
691 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
692 &lat2, &lon2, &az2 );
694 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
696 double odist = fgGetDouble("/sim/presets/offset-distance");
697 odist *= SG_NM_TO_METER;
698 double oaz = azimuth;
699 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
700 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
702 while ( oaz >= 360.0 ) { oaz -= 360.0; }
703 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
709 fgSetDouble("/sim/presets/longitude-deg", lon2 );
710 fgSetDouble("/sim/presets/latitude-deg", lat2 );
711 fgSetDouble("/sim/presets/heading-deg", heading );
713 // other code depends on the actual values being set ...
714 fgSetDouble("/position/longitude-deg", lon2 );
715 fgSetDouble("/position/latitude-deg", lat2 );
716 fgSetDouble("/orientation/heading-deg", heading );
718 SG_LOG( SG_GENERAL, SG_INFO,
719 "Position for " << id << " is ("
721 << lat2 << ") new heading is "
728 // Set current_options lon/lat given an airport id and runway number
729 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
733 // set initial position from airport and runway number
735 SGPath path( globals->get_fg_root() );
736 path.append( "Airports" );
737 path.append( "runways.mk4" );
738 FGRunways runways( path.c_str() );
740 SG_LOG( SG_GENERAL, SG_INFO,
741 "Attempting to set starting position for "
742 << id << ":" << rwy );
744 if ( ! runways.search( id, rwy, &r ) ) {
745 SG_LOG( SG_GENERAL, SG_ALERT,
746 "Failed to find runway " << rwy <<
747 " at airport " << id );
754 double lat2, lon2, az2;
755 double heading = r.heading;
756 double azimuth = heading + 180.0;
757 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
759 SG_LOG( SG_GENERAL, SG_INFO,
760 "runway = " << r.lon << ", " << r.lat
761 << " length = " << r.length * SG_FEET_TO_METER
762 << " heading = " << azimuth );
764 geo_direct_wgs_84 ( 0, r.lat, r.lon,
766 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
767 &lat2, &lon2, &az2 );
769 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
772 double odist = fgGetDouble("/sim/presets/offset-distance");
773 odist *= SG_NM_TO_METER;
774 double oaz = azimuth;
775 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
777 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
779 while ( oaz >= 360.0 ) { oaz -= 360.0; }
780 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
786 fgSetDouble("/sim/presets/longitude-deg", lon2 );
787 fgSetDouble("/sim/presets/latitude-deg", lat2 );
788 fgSetDouble("/sim/presets/heading-deg", heading );
790 // other code depends on the actual values being set ...
791 fgSetDouble("/position/longitude-deg", lon2 );
792 fgSetDouble("/position/latitude-deg", lat2 );
793 fgSetDouble("/orientation/heading-deg", heading );
795 SG_LOG( SG_GENERAL, SG_INFO,
796 "Position for " << id << " is ("
798 << lat2 << ") new heading is "
805 static void fgSetDistOrAltFromGlideSlope() {
806 string apt_id = fgGetString("/sim/presets/airport-id");
807 double gs = fgGetDouble("/sim/presets/glideslope-deg")
808 * SG_DEGREES_TO_RADIANS ;
809 double od = fgGetDouble("/sim/presets/offset-distance");
810 double alt = fgGetDouble("/sim/presets/altitude-ft");
812 double apt_elev = 0.0;
813 if ( ! apt_id.empty() ) {
814 apt_elev = fgGetAirportElev( apt_id );
815 if ( apt_elev < -9990.0 ) {
822 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
823 // set altitude from glideslope and offset-distance
824 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
825 alt = fabs(od*tan(gs)) + apt_elev;
826 fgSetDouble("/sim/presets/altitude-ft", alt);
827 fgSetBool("/sim/presets/onground", false);
828 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
830 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
831 // set offset-distance from glideslope and altitude
832 od = (alt - apt_elev) / tan(gs);
833 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
834 fgSetDouble("/sim/presets/offset-distance", od);
835 fgSetBool("/sim/presets/onground", false);
836 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
838 } else if( fabs(gs) > 0.01 ) {
839 SG_LOG( SG_GENERAL, SG_ALERT,
840 "Glideslope given but not altitude or offset-distance." );
841 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
842 fgSetDouble("/sim/presets/glideslope-deg", 0);
843 fgSetBool("/sim/presets/onground", true);
848 // Set current_options lon/lat given an airport id and heading (degrees)
849 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
850 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
852 // set initial position from runway and heading
854 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
855 << id << ":" << freq );
857 double lon = nav->get_lon();
858 double lat = nav->get_lat();
860 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
862 double odist = fgGetDouble("/sim/presets/offset-distance")
864 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
866 while ( oaz >= 360.0 ) { oaz -= 360.0; }
867 double olat, olon, az2;
868 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
875 fgSetDouble("/sim/presets/longitude-deg", lon );
876 fgSetDouble("/sim/presets/latitude-deg", lat );
878 // other code depends on the actual values being set ...
879 fgSetDouble("/position/longitude-deg", lon );
880 fgSetDouble("/position/latitude-deg", lat );
881 fgSetDouble("/orientation/heading-deg",
882 fgGetDouble("/sim/presets/heading-deg") );
884 SG_LOG( SG_GENERAL, SG_INFO,
885 "Position for " << id << ":" << freq << " is ("
886 << lon << ", "<< lat << ")" );
890 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
891 << id << ":" << freq );
897 // Set current_options lon/lat given an airport id and heading (degrees)
898 static bool fgSetPosFromFix( const string& id ) {
901 // set initial position from runway and heading
902 if ( current_fixlist->query( id.c_str(), &fix ) ) {
903 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
906 double lon = fix.get_lon();
907 double lat = fix.get_lat();
909 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
911 double odist = fgGetDouble("/sim/presets/offset-distance")
913 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
915 while ( oaz >= 360.0 ) { oaz -= 360.0; }
916 double olat, olon, az2;
917 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
924 fgSetDouble("/sim/presets/longitude-deg", lon );
925 fgSetDouble("/sim/presets/latitude-deg", lat );
927 // other code depends on the actual values being set ...
928 fgSetDouble("/position/longitude-deg", lon );
929 fgSetDouble("/position/latitude-deg", lat );
930 fgSetDouble("/orientation/heading-deg",
931 fgGetDouble("/sim/presets/heading-deg") );
933 SG_LOG( SG_GENERAL, SG_INFO,
934 "Position for " << id << " is ("
935 << lon << ", "<< lat << ")" );
939 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
947 * Initialize vor/ndb/ils/fix list management and query systems
952 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
954 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
955 current_navlist = new FGNavList;
956 SGPath p_nav( globals->get_fg_root() );
957 p_nav.append( "Navaids/default.nav" );
958 current_navlist->init( p_nav );
960 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
961 current_beacons = new FGMarkerBeacons;
962 current_beacons->init();
963 current_ilslist = new FGILSList;
964 SGPath p_ils( globals->get_fg_root() );
965 p_ils.append( "Navaids/default.ils" );
966 current_ilslist->init( p_ils );
968 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
969 current_fixlist = new FGFixList;
970 SGPath p_fix( globals->get_fg_root() );
971 p_fix.append( "Navaids/default.fix" );
972 current_fixlist->init( p_fix );
978 // Set the initial position based on presets (or defaults)
979 bool fgInitPosition() {
980 bool set_pos = false;
982 // Default to starting on the ground unless one of the other
983 // conditions implies an in-air start.
984 fgSetBool("/sim/presets/onground", true);
986 // If glideslope is specified, then calculate offset-distance or
987 // altitude relative to glide slope if either of those was not
989 fgSetDistOrAltFromGlideSlope();
991 // If we have an explicit, in-range lon/lat, don't change it, just use it.
992 // If not, check for an airport-id and use that.
993 // If not, default to the middle of the KSFO field.
994 // The default values for lon/lat are deliberately out of range
995 // so that the airport-id can take effect; valid lon/lat will
996 // override airport-id, however.
997 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
998 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
999 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1000 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1005 string apt = fgGetString("/sim/presets/airport-id");
1006 string rwy_no = fgGetString("/sim/presets/runway");
1007 double hdg = fgGetDouble("/sim/presets/heading-deg");
1008 string vor = fgGetString("/sim/presets/vor-id");
1009 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1010 string ndb = fgGetString("/sim/presets/ndb-id");
1011 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1012 string fix = fgGetString("/sim/presets/fix");
1013 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1014 // An airport + runway is requested
1015 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1016 // set position (a little off the heading for single
1018 fgSetTowerPosFromAirportID( apt, hdg );
1023 if ( !set_pos && !apt.empty() ) {
1024 // An airport is requested (find runway closest to hdg)
1026 if (fgGetDouble("/sim/presets/altitude-ft") <= 0 &&
1027 fgGetDouble("/sim/presets/offset-distance") == 0)
1028 ok = fgSetPosFromAirportIDandHdg( apt, hdg );
1030 ok = fgSetPosFromAirportID( apt );
1033 // set position (a little off the heading for single
1035 fgSetTowerPosFromAirportID( apt, hdg );
1040 if ( !set_pos && !vor.empty() ) {
1041 // a VOR is requested
1042 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1043 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1044 fgSetBool("/sim/presets/onground", false);
1046 fgSetBool("/sim/presets/onground", true);
1051 if ( !set_pos && !ndb.empty() ) {
1052 // an NDB is requested
1053 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1054 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1055 fgSetBool("/sim/presets/onground", false);
1057 fgSetBool("/sim/presets/onground", true);
1062 if ( !set_pos && !fix.empty() ) {
1063 // a Fix is requested
1064 if ( fgSetPosFromFix( fix ) ) {
1065 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1066 fgSetBool("/sim/presets/onground", false);
1068 fgSetBool("/sim/presets/onground", true);
1075 // No lon/lat specified, no airport specified, default to
1076 // middle of KSFO field.
1077 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1078 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1081 fgSetDouble( "/position/longitude-deg",
1082 fgGetDouble("/sim/presets/longitude-deg") );
1083 fgSetDouble( "/position/latitude-deg",
1084 fgGetDouble("/sim/presets/latitude-deg") );
1085 fgSetDouble( "/orientation/heading-deg",
1086 fgGetDouble("/sim/presets/heading-deg") );
1092 // General house keeping initializations
1093 bool fgInitGeneral() {
1096 #if defined(FX) && defined(XMESA)
1097 char *mesa_win_state;
1100 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1101 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1103 root = globals->get_fg_root();
1104 if ( ! root.length() ) {
1105 // No root path set? Then bail ...
1106 SG_LOG( SG_GENERAL, SG_ALERT,
1107 "Cannot continue without a path to the base package "
1108 << "being defined." );
1111 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1113 #if defined(FX) && defined(XMESA)
1114 // initialize full screen flag
1115 globals->set_fullscreen(false);
1116 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1117 // Test for the MESA_GLX_FX env variable
1118 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1119 // test if we are fullscreen mesa/glide
1120 if ( (mesa_win_state[0] == 'f') ||
1121 (mesa_win_state[0] == 'F') ) {
1122 globals->set_fullscreen(true);
1132 // Initialize the flight model subsystem. This just creates the
1133 // object. The actual fdm initialization is delayed until we get a
1134 // proper scenery elevation hit. This is checked for in main.cxx
1138 if ( cur_fdm_state ) {
1139 delete cur_fdm_state;
1143 double dt = 1.0 / fgGetInt("/sim/model-hz");
1144 aircraft_dir = fgGetString("/sim/aircraft-dir");
1145 const string &model = fgGetString("/sim/flight-model");
1148 if ( model == "larcsim" ) {
1149 cur_fdm_state = new FGLaRCsim( dt );
1150 } else if ( model == "jsb" ) {
1151 cur_fdm_state = new FGJSBsim( dt );
1152 } else if ( model == "ada" ) {
1153 cur_fdm_state = new FGADA( dt );
1154 } else if ( model == "balloon" ) {
1155 cur_fdm_state = new FGBalloonSim( dt );
1156 } else if ( model == "magic" ) {
1157 cur_fdm_state = new FGMagicCarpet( dt );
1158 } else if ( model == "ufo" ) {
1159 cur_fdm_state = new FGUFO( dt );
1160 } else if ( model == "external" ) {
1161 // external is a synonym for "--fdm=null" and is
1162 // maintained here for backwards compatibility
1163 cur_fdm_state = new FGNullFDM( dt );
1164 } else if ( model.find("network") == 0 ) {
1165 string host = "localhost";
1169 string net_options = model.substr(8);
1170 string::size_type begin, end;
1173 end = net_options.find( ",", begin );
1174 if ( end != string::npos ) {
1175 host = net_options.substr(begin, end - begin);
1179 end = net_options.find( ",", begin );
1180 if ( end != string::npos ) {
1181 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1185 end = net_options.find( ",", begin );
1186 if ( end != string::npos ) {
1187 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1191 end = net_options.find( ",", begin );
1192 if ( end != string::npos ) {
1193 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1196 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1197 } else if ( model.find("pipe") == 0 ) {
1198 string pipe_path = model.substr(5);
1199 cur_fdm_state = new FGExternalPipe( dt, pipe_path );
1200 } else if ( model == "null" ) {
1201 cur_fdm_state = new FGNullFDM( dt );
1202 } else if ( model == "yasim" ) {
1203 cur_fdm_state = new YASim( dt );
1205 SG_LOG(SG_GENERAL, SG_ALERT,
1206 "Unrecognized flight model '" << model
1207 << "', cannot init flight dynamics model.");
1211 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1216 static void printMat(const sgVec4 *mat, char *name="")
1219 SG_LOG(SG_GENERAL, SG_BULK, name );
1220 for(i=0; i<4; i++) {
1221 SG_LOG(SG_GENERAL, SG_BULK, " " << mat[i][0] << " " << mat[i][1]
1222 << " " << mat[i][2] << " " << mat[i][3] );
1226 // Initialize view parameters
1228 // force update of model so that viewer can get some data...
1229 globals->get_aircraft_model()->update(0);
1230 // run update for current view so that data is current...
1231 globals->get_viewmgr()->update(0);
1233 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1234 printMat(globals->get_current_view()->get_UP(),"UP");
1235 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1240 SGTime *fgInitTime() {
1242 static const SGPropertyNode *longitude
1243 = fgGetNode("/position/longitude-deg");
1244 static const SGPropertyNode *latitude
1245 = fgGetNode("/position/latitude-deg");
1246 static const SGPropertyNode *cur_time_override
1247 = fgGetNode("/sim/time/cur-time-override", true);
1249 SGPath zone( globals->get_fg_root() );
1250 zone.append( "Timezone" );
1251 SGTime *t = new SGTime( longitude->getDoubleValue()
1252 * SGD_DEGREES_TO_RADIANS,
1253 latitude->getDoubleValue()
1254 * SGD_DEGREES_TO_RADIANS,
1256 cur_time_override->getLongValue() );
1258 // Handle potential user specified time offsets
1259 time_t cur_time = t->get_cur_time();
1260 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1261 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1262 time_t aircraftLocalTime =
1263 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1265 // Okay, we now have six possible scenarios
1266 int offset = fgGetInt("/sim/startup/time-offset");
1267 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1268 if (offset_type == "system-offset") {
1269 globals->set_warp( offset );
1270 } else if (offset_type == "gmt-offset") {
1271 globals->set_warp( offset - (currGMT - systemLocalTime) );
1272 } else if (offset_type == "latitude-offset") {
1273 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1274 } else if (offset_type == "system") {
1275 globals->set_warp( offset - cur_time );
1276 } else if (offset_type == "gmt") {
1277 globals->set_warp( offset - currGMT );
1278 } else if (offset_type == "latitude") {
1279 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1282 SG_LOG( SG_GENERAL, SG_ALERT,
1283 "FG_TIME::Unsupported offset type " << offset_type );
1287 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1288 << globals->get_warp() );
1290 globals->set_warp_delta( 0 );
1292 t->update( 0.0, 0.0,
1293 cur_time_override->getLongValue(),
1294 globals->get_warp() );
1300 // This is the top level init routine which calls all the other
1301 // initialization routines. If you are adding a subsystem to flight
1302 // gear, its initialization call should located in this routine.
1303 // Returns non-zero if a problem encountered.
1304 bool fgInitSubsystems() {
1305 // static const SGPropertyNode *longitude
1306 // = fgGetNode("/sim/presets/longitude-deg");
1307 // static const SGPropertyNode *latitude
1308 // = fgGetNode("/sim/presets/latitude-deg");
1309 // static const SGPropertyNode *altitude
1310 // = fgGetNode("/sim/presets/altitude-ft");
1312 fgLIGHT *l = &cur_light_params;
1314 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1315 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1318 ////////////////////////////////////////////////////////////////////
1319 // Initialize the material property subsystem.
1320 ////////////////////////////////////////////////////////////////////
1322 SGPath mpath( globals->get_fg_root() );
1323 mpath.append( "materials.xml" );
1324 if ( ! material_lib.load( mpath.str() ) ) {
1325 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1329 ////////////////////////////////////////////////////////////////////
1330 // Initialize the event manager subsystem.
1331 ////////////////////////////////////////////////////////////////////
1333 global_events.init();
1335 // Output event stats every 60 seconds
1336 global_events.Register( "FGEventMgr::print_stats()",
1337 &global_events, &FGEventMgr::print_stats,
1341 ////////////////////////////////////////////////////////////////////
1342 // Initialize the scenery management subsystem.
1343 ////////////////////////////////////////////////////////////////////
1345 if ( globals->get_tile_mgr()->init() ) {
1346 // Load the local scenery data
1347 double visibility_meters = fgGetDouble("/environment/visibility-m");
1349 globals->get_tile_mgr()->update( visibility_meters );
1351 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1355 // cause refresh of viewer scenery timestamps every 15 seconds...
1356 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1357 globals->get_tile_mgr(),
1358 &FGTileMgr::refresh_view_timestamps,
1361 SG_LOG( SG_GENERAL, SG_DEBUG,
1362 "Current terrain elevation after tile mgr init " <<
1363 globals->get_scenery()->get_cur_elev() );
1366 ////////////////////////////////////////////////////////////////////
1367 // Initialize the flight model subsystem.
1368 ////////////////////////////////////////////////////////////////////
1372 // allocates structures so must happen before any of the flight
1373 // model or control parameters are set
1374 fgAircraftInit(); // In the future this might not be the case.
1377 ////////////////////////////////////////////////////////////////////
1378 // Initialize the view manager subsystem.
1379 ////////////////////////////////////////////////////////////////////
1384 ////////////////////////////////////////////////////////////////////
1385 // Initialize the lighting subsystem.
1386 ////////////////////////////////////////////////////////////////////
1388 // fgUpdateSunPos() needs a few position and view parameters set
1389 // so it can calculate local relative sun angle and a few other
1390 // things for correctly orienting the sky.
1393 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1395 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1398 // Initialize Lighting interpolation tables
1401 // force one lighting update to make it right to start with...
1403 // update the lighting parameters (based on sun angle)
1404 global_events.Register( "fgLight::Update()",
1405 &cur_light_params, &fgLIGHT::Update,
1409 ////////////////////////////////////////////////////////////////////
1410 // Create and register the logger.
1411 ////////////////////////////////////////////////////////////////////
1413 globals->add_subsystem("logger", new FGLogger);
1416 #if defined(HAVE_PLIB_PSL)
1417 ////////////////////////////////////////////////////////////////////
1418 // Create and register the script manager.
1419 ////////////////////////////////////////////////////////////////////
1421 globals->add_subsystem("scripting", new FGScriptMgr);
1422 #endif // HAVE_PLIB_PSL
1425 ////////////////////////////////////////////////////////////////////
1426 // Create and register the XML GUI.
1427 ////////////////////////////////////////////////////////////////////
1429 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1432 ////////////////////////////////////////////////////////////////////
1433 // Initialize the local time subsystem.
1434 ////////////////////////////////////////////////////////////////////
1436 // update the current timezone each 30 minutes
1437 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1441 ////////////////////////////////////////////////////////////////////
1442 // Initialize the weather subsystem.
1443 ////////////////////////////////////////////////////////////////////
1445 // Initialize the weather modeling subsystem
1447 // Initialize the WeatherDatabase
1448 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1450 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1451 current_aircraft.fdm_state->get_Longitude(),
1452 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1453 double init_vis = fgGetDouble("/environment/visibility-m");
1455 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1457 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1459 working_type = FGLocalWeatherDatabase::use_internet;
1461 working_type = FGLocalWeatherDatabase::default_mode;
1464 if ( init_vis > 0 ) {
1465 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1466 new FGLocalWeatherDatabase( position,
1467 globals->get_fg_root(),
1471 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1472 new FGLocalWeatherDatabase( position,
1473 globals->get_fg_root(),
1477 // cout << theFGLocalWeatherDatabase << endl;
1478 // cout << "visibility = "
1479 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1481 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1483 // register the periodic update of the weather
1484 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1487 globals->get_environment_mgr()->init();
1488 globals->get_environment_mgr()->bind();
1491 #ifdef FG_USE_CLOUDS_3D
1492 ////////////////////////////////////////////////////////////////////
1493 // Initialize the 3D cloud subsystem.
1494 ////////////////////////////////////////////////////////////////////
1495 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1496 SGPath cloud_path(globals->get_fg_root());
1497 cloud_path.append("large.sky");
1498 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1499 if ( !sgCloud3d->Load( cloud_path.str(),
1500 latitude->getDoubleValue(),
1501 longitude->getDoubleValue()) )
1503 fgSetBool("/sim/rendering/clouds3d", false);
1504 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1506 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1510 ////////////////////////////////////////////////////////////////////
1511 // Initialise ATC display system
1512 ////////////////////////////////////////////////////////////////////
1514 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1515 globals->set_ATC_display(new FGATCDisplay);
1516 globals->get_ATC_display()->init();
1518 ////////////////////////////////////////////////////////////////////
1519 // Initialise the ATC Manager
1520 ////////////////////////////////////////////////////////////////////
1522 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1523 globals->set_ATC_mgr(new FGATCMgr);
1524 globals->get_ATC_mgr()->init();
1526 ////////////////////////////////////////////////////////////////////
1527 // Initialise the AI Manager
1528 ////////////////////////////////////////////////////////////////////
1530 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1531 globals->set_AI_mgr(new FGAIMgr);
1532 globals->get_AI_mgr()->init();
1535 #ifdef ENABLE_AUDIO_SUPPORT
1536 ////////////////////////////////////////////////////////////////////
1537 // Initialize the sound subsystem.
1538 ////////////////////////////////////////////////////////////////////
1540 globals->set_soundmgr(new FGSoundMgr);
1541 globals->get_soundmgr()->init();
1542 globals->get_soundmgr()->bind();
1545 ////////////////////////////////////////////////////////////////////
1546 // Initialize the sound-effects subsystem.
1547 ////////////////////////////////////////////////////////////////////
1549 globals->add_subsystem("fx", new FGFX);
1553 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1554 globals->add_subsystem("systems", new FGSystemMgr);
1556 ////////////////////////////////////////////////////////////////////
1557 // Initialize the radio stack subsystem.
1558 ////////////////////////////////////////////////////////////////////
1560 current_radiostack = new FGRadioStack;
1561 current_radiostack->init();
1562 current_radiostack->bind();
1565 ////////////////////////////////////////////////////////////////////
1566 // Initialize the cockpit subsystem
1567 ////////////////////////////////////////////////////////////////////
1569 if( fgCockpitInit( ¤t_aircraft )) {
1570 // Cockpit initialized ok.
1572 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1577 ////////////////////////////////////////////////////////////////////
1578 // Initialize the autopilot subsystem.
1579 ////////////////////////////////////////////////////////////////////
1581 globals->set_autopilot(new FGAutopilot);
1582 globals->get_autopilot()->init();
1583 globals->get_autopilot()->bind();
1585 // FIXME: these should go in the
1586 // GUI initialization code, not here.
1588 NewTgtAirportInit();
1592 ////////////////////////////////////////////////////////////////////
1593 // Initialize I/O subsystem.
1594 ////////////////////////////////////////////////////////////////////
1596 globals->get_io()->init();
1597 globals->get_io()->bind();
1600 ////////////////////////////////////////////////////////////////////
1601 // Add a new 2D panel.
1602 ////////////////////////////////////////////////////////////////////
1604 string panel_path = fgGetString("/sim/panel/path",
1605 "Panels/Default/default.xml");
1607 globals->set_current_panel( fgReadPanel(panel_path) );
1608 if (globals->get_current_panel() == 0) {
1609 SG_LOG( SG_INPUT, SG_ALERT,
1610 "Error reading new panel from " << panel_path );
1612 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1613 globals->get_current_panel()->init();
1614 globals->get_current_panel()->bind();
1618 ////////////////////////////////////////////////////////////////////
1619 // Initialize the default (kludged) properties.
1620 ////////////////////////////////////////////////////////////////////
1625 ////////////////////////////////////////////////////////////////////
1626 // Initialize the controls subsystem.
1627 ////////////////////////////////////////////////////////////////////
1629 globals->get_controls()->init();
1630 globals->get_controls()->bind();
1633 ////////////////////////////////////////////////////////////////////
1634 // Initialize the input subsystem.
1635 ////////////////////////////////////////////////////////////////////
1637 globals->add_subsystem("input", new FGInput);
1640 ////////////////////////////////////////////////////////////////////
1641 // Bind and initialize subsystems.
1642 ////////////////////////////////////////////////////////////////////
1644 globals->get_subsystem_mgr()->bind();
1645 globals->get_subsystem_mgr()->init();
1648 #ifdef FG_MPLAYER_AS
1649 ////////////////////////////////////////////////////////////////////
1650 // Initialize multiplayer subsystem
1651 ////////////////////////////////////////////////////////////////////
1653 globals->set_multiplayer_tx_mgr(new FGMultiplayTxMgr);
1654 globals->get_multiplayer_tx_mgr()->init();
1656 globals->set_multiplayer_rx_mgr(new FGMultiplayRxMgr);
1657 globals->get_multiplayer_rx_mgr()->init();
1660 ////////////////////////////////////////////////////////////////////////
1661 // End of subsystem initialization.
1662 ////////////////////////////////////////////////////////////////////
1664 SG_LOG( SG_GENERAL, SG_INFO, endl);
1666 // Save the initial state for future
1668 globals->saveInitialState();
1674 void fgReInitSubsystems()
1676 // static const SGPropertyNode *longitude
1677 // = fgGetNode("/sim/presets/longitude-deg");
1678 // static const SGPropertyNode *latitude
1679 // = fgGetNode("/sim/presets/latitude-deg");
1680 static const SGPropertyNode *altitude
1681 = fgGetNode("/sim/presets/altitude-ft");
1682 static const SGPropertyNode *master_freeze
1683 = fgGetNode("/sim/freeze/master");
1685 SG_LOG( SG_GENERAL, SG_INFO,
1686 "fgReInitSubsystems(): /position/altitude = "
1687 << altitude->getDoubleValue() );
1689 bool freeze = master_freeze->getBoolValue();
1691 fgSetBool("/sim/freeze/master", true);
1694 // Initialize the FDM
1697 // allocates structures so must happen before any of the flight
1698 // model or control parameters are set
1699 fgAircraftInit(); // In the future this might not be the case.
1701 // reload offsets from config defaults
1702 globals->get_viewmgr()->reinit();
1706 globals->get_controls()->reset_all();
1707 globals->get_autopilot()->reset();
1711 cur_light_params.Update();
1712 fgUpdateLocalTime();
1715 fgSetBool("/sim/freeze/master", false);