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 #include <simgear/scene/material/matlib.hxx>
67 #ifdef FG_USE_CLOUDS_3D
68 # include <simgear/scene/sky/clouds3d/SkySceneLoader.hpp>
69 # include <simgear/scene/sky/clouds3d/SkyUtil.hpp>
71 #include <simgear/timing/sg_time.hxx>
72 #include <simgear/timing/lowleveltime.h>
74 #include <Aircraft/aircraft.hxx>
75 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
76 #include <Airports/runways.hxx>
77 #include <Airports/simple.hxx>
78 #include <ATC/ATCdisplay.hxx>
79 #include <ATC/ATCmgr.hxx>
80 #include <ATC/AIMgr.hxx>
81 #include <Autopilot/auto_gui.hxx>
82 #include <Autopilot/newauto.hxx>
83 #include <Cockpit/cockpit.hxx>
84 #include <Cockpit/radiostack.hxx>
85 #include <Cockpit/panel.hxx>
86 #include <Cockpit/panel_io.hxx>
87 #include <FDM/ADA.hxx>
88 #include <FDM/Balloon.h>
89 #include <FDM/ExternalNet/ExternalNet.hxx>
90 #include <FDM/ExternalPipe/ExternalPipe.hxx>
91 #include <FDM/JSBSim/JSBSim.hxx>
92 #include <FDM/LaRCsim/LaRCsim.hxx>
93 #include <FDM/MagicCarpet.hxx>
94 #include <FDM/UFO.hxx>
95 #include <FDM/NullFDM.hxx>
96 #include <FDM/YASim/YASim.hxx>
97 #include <GUI/new_gui.hxx>
98 #include <Include/general.hxx>
99 #include <Input/input.hxx>
100 #include <Instrumentation/instrument_mgr.hxx>
101 #include <Model/acmodel.hxx>
102 #include <Navaids/fixlist.hxx>
103 #include <Navaids/ilslist.hxx>
104 #include <Navaids/mkrbeacons.hxx>
105 #include <Navaids/navlist.hxx>
106 #include <Scenery/scenery.hxx>
107 #include <Scenery/tilemgr.hxx>
108 #if defined(HAVE_PLIB_PSL)
109 #include <Scripting/scriptmgr.hxx>
111 #include <Sound/fg_fx.hxx>
112 #include <Systems/system_mgr.hxx>
113 #include <Time/FGEventMgr.hxx>
114 #include <Time/light.hxx>
115 #include <Time/sunpos.hxx>
116 #include <Time/moonpos.hxx>
117 #include <Time/tmp.hxx>
120 #include <MultiPlayer/multiplaytxmgr.hxx>
121 #include <MultiPlayer/multiplayrxmgr.hxx>
125 # include <WeatherCM/FGLocalWeatherDatabase.h>
127 # include <Environment/environment_mgr.hxx>
130 #include "fg_init.hxx"
132 #include "fg_commands.hxx"
133 #include "fg_props.hxx"
134 #include "options.hxx"
135 #include "globals.hxx"
136 #include "logger.hxx"
137 #include "viewmgr.hxx"
139 #if defined(FX) && defined(XMESA)
140 #include <GL/xmesa.h>
143 SG_USING_STD(string);
148 extern const char *default_root;
150 #ifdef FG_USE_CLOUDS_3D
151 SkySceneLoader *sgCloud3d;
155 // Scan the command line options for the specified option and return
157 static string fgScanForOption( const string& option, int argc, char **argv ) {
160 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
162 int len = option.length();
165 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
167 string arg = argv[i];
168 if ( arg.find( option ) == 0 ) {
169 return arg.substr( len );
179 // Scan the user config files for the specified option and return
181 static string fgScanForOption( const string& option, const string& path ) {
182 sg_gzifstream in( path );
183 if ( !in.is_open() ) {
187 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
189 int len = option.length();
193 while ( ! in.eof() ) {
196 while ( in.get(c) && c != '\0' ) {
201 #if defined( macintosh )
202 getline( in, line, '\r' );
204 getline( in, line, '\n' );
207 // catch extraneous (DOS) line ending character
208 if ( line[line.length() - 1] < 32 ) {
209 line = line.substr( 0, line.length()-1 );
212 if ( line.find( option ) == 0 ) {
213 return line.substr( len );
223 // Read in configuration (files and command line options) but only set
225 bool fgInitFGRoot ( int argc, char **argv ) {
229 // First parse command line options looking for --fg-root=, this
230 // will override anything specified in a config file
231 root = fgScanForOption( "--fg-root=", argc, argv);
233 #if defined( unix ) || defined( __CYGWIN__ )
234 // Next check home directory for .fgfsrc.hostname file
235 if ( root.empty() ) {
236 envp = ::getenv( "HOME" );
237 if ( envp != NULL ) {
238 SGPath config( envp );
239 config.append( ".fgfsrc" );
241 gethostname( name, 256 );
242 config.concat( "." );
243 config.concat( name );
244 root = fgScanForOption( "--fg-root=", config.str() );
249 // Next check home directory for .fgfsrc file
250 if ( root.empty() ) {
251 envp = ::getenv( "HOME" );
252 if ( envp != NULL ) {
253 SGPath config( envp );
254 config.append( ".fgfsrc" );
255 root = fgScanForOption( "--fg-root=", config.str() );
259 // Next check if fg-root is set as an env variable
260 if ( root.empty() ) {
261 envp = ::getenv( "FG_ROOT" );
262 if ( envp != NULL ) {
267 // Otherwise, default to a random compiled-in location if we can't
268 // find fg-root any other way.
269 if ( root.empty() ) {
270 #if defined( __CYGWIN__ )
271 root = "/FlightGear";
272 #elif defined( WIN32 )
273 root = "\\FlightGear";
274 #elif defined( macintosh )
281 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
282 globals->set_fg_root(root);
288 // Read in configuration (files and command line options) but only set
290 bool fgInitFGAircraft ( int argc, char **argv ) {
294 // First parse command line options looking for --aircraft=, this
295 // will override anything specified in a config file
296 aircraft = fgScanForOption( "--aircraft=", argc, argv );
298 #if defined( unix ) || defined( __CYGWIN__ )
299 // Next check home directory for .fgfsrc.hostname file
300 if ( aircraft.empty() ) {
301 envp = ::getenv( "HOME" );
302 if ( envp != NULL ) {
303 SGPath config( envp );
304 config.append( ".fgfsrc" );
306 gethostname( name, 256 );
307 config.concat( "." );
308 config.concat( name );
309 aircraft = fgScanForOption( "--aircraft=", config.str() );
314 // Next check home directory for .fgfsrc file
315 if ( aircraft.empty() ) {
316 envp = ::getenv( "HOME" );
317 if ( envp != NULL ) {
318 SGPath config( envp );
319 config.append( ".fgfsrc" );
320 aircraft = fgScanForOption( "--aircraft=", config.str() );
324 // if an aircraft was specified, set the property name
325 if ( !aircraft.empty() ) {
326 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
327 fgSetString("/sim/aircraft", aircraft.c_str() );
329 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
336 // Return the current base package version
337 string fgBasePackageVersion() {
338 SGPath base_path( globals->get_fg_root() );
339 base_path.append("version");
341 sg_gzifstream in( base_path.str() );
342 if ( !in.is_open() ) {
343 SGPath old_path( globals->get_fg_root() );
344 old_path.append( "Thanks" );
345 sg_gzifstream old( old_path.str() );
346 if ( !old.is_open() ) {
349 return "[old version]";
360 // Initialize the localization
361 SGPropertyNode *fgInitLocale(const char *language) {
362 SGPropertyNode *c_node = NULL, *d_node = NULL;
363 SGPropertyNode *intl = fgGetNode("/sim/intl");
365 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
367 // localization not defined
372 // Select the proper language from the list
374 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
375 for (unsigned int i = 0; i < locale.size(); i++) {
377 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
378 for (unsigned int j = 0; j < lang.size(); j++) {
380 if (!strcmp(lang[j]->getStringValue(), language)) {
389 d_node = intl->getChild("locale");
393 // Check for localized font
394 SGPropertyNode *font_n = c_node->getNode("font", true);
395 if ( !strcmp(font_n->getStringValue(), "") )
396 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
400 // Load the default strings
402 SGPath d_path( globals->get_fg_root() );
404 const char *d_path_str = d_node->getStringValue("strings");
406 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
410 d_path.append(d_path_str);
411 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
414 SGPropertyNode *strings = c_node->getNode("strings");
416 readProperties(d_path.str(), strings);
417 } catch (const sg_exception &e) {
418 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
423 // Load the language specific strings
425 if (c_node != d_node) {
426 SGPath c_path( globals->get_fg_root() );
428 const char *c_path_str = c_node->getStringValue("strings");
430 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
434 c_path.append(c_path_str);
435 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
439 readProperties(c_path.str(), strings);
440 } catch (const sg_exception &e) {
441 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
451 // Initialize the localization routines
452 bool fgDetectLanguage() {
453 char *language = ::getenv("LANG");
455 if (language == NULL) {
456 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
460 SGPropertyNode *locale = fgInitLocale(language);
462 SG_LOG(SG_GENERAL, SG_ALERT,
463 "No internationalization settings specified in preferences.xml" );
468 globals->set_locale( locale );
473 // Attempt to locate and parse the various non-XML config files in order
474 // from least precidence to greatest precidence
476 do_options (int argc, char ** argv)
478 // Check for $fg_root/system.fgfsrc
479 SGPath config( globals->get_fg_root() );
480 config.append( "system.fgfsrc" );
481 fgParseOptions(config.str());
483 #if defined( unix ) || defined( __CYGWIN__ )
485 // Check for $fg_root/system.fgfsrc.hostname
486 gethostname( name, 256 );
487 config.concat( "." );
488 config.concat( name );
489 fgParseOptions(config.str());
492 // Check for ~/.fgfsrc
493 char* envp = ::getenv( "HOME" );
494 if ( envp != NULL ) {
496 config.append( ".fgfsrc" );
497 fgParseOptions(config.str());
500 #if defined( unix ) || defined( __CYGWIN__ )
501 // Check for ~/.fgfsrc.hostname
502 gethostname( name, 256 );
503 config.concat( "." );
504 config.concat( name );
505 fgParseOptions(config.str());
508 // Parse remaining command line options
509 // These will override anything specified in a config file
510 fgParseArgs(argc, argv);
514 // Read in configuration (file and command line)
515 bool fgInitConfig ( int argc, char **argv ) {
517 // First, set some sane default values
520 // Read global preferences from $FG_ROOT/preferences.xml
521 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
522 fgLoadProps("preferences.xml", globals->get_props());
523 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
525 // Detect the required language as early as possible
526 if ( !fgDetectLanguage() ) {
530 // Scan user config files and command line for a specified aircraft.
531 fgInitFGAircraft(argc, argv);
533 string aircraft = fgGetString("/sim/aircraft", "");
534 if ( aircraft.size() > 0 ) {
535 SGPath aircraft_path(globals->get_fg_root());
536 aircraft_path.append("Aircraft");
537 aircraft_path.append(aircraft);
538 aircraft_path.concat("-set.xml");
539 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
540 << " from " << aircraft_path.str());
542 readProperties(aircraft_path.str(), globals->get_props());
543 } catch (const sg_exception &e) {
544 string message = "Error reading default aircraft: ";
545 message += e.getFormattedMessage();
546 SG_LOG(SG_INPUT, SG_ALERT, message);
550 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
553 // parse options after loading aircraft to ensure any user
554 // overrides of defaults are honored.
555 do_options(argc, argv);
561 // find basic airport location info from airport database
562 bool fgFindAirportID( const string& id, FGAirport *a ) {
564 SGPath path( globals->get_fg_root() );
565 path.append( "Airports" );
566 path.append( "simple.mk4" );
567 FGAirports airports( path.c_str() );
569 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
571 if ( ! airports.search( id, a ) ) {
572 SG_LOG( SG_GENERAL, SG_ALERT,
573 "Failed to find " << id << " in " << path.str() );
580 SG_LOG( SG_GENERAL, SG_INFO,
581 "Position for " << id << " is ("
582 << a->longitude << ", "
583 << a->latitude << ")" );
589 // get airport elevation
590 static double fgGetAirportElev( const string& id ) {
594 SG_LOG( SG_GENERAL, SG_INFO,
595 "Finding elevation for airport: " << id );
597 if ( fgFindAirportID( id, &a ) ) {
605 // Preset lon/lat given an airport id
606 static bool fgSetPosFromAirportID( const string& id ) {
610 SG_LOG( SG_GENERAL, SG_INFO,
611 "Attempting to set starting position from airport code " << id );
613 if ( fgFindAirportID( id, &a ) ) {
615 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
616 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
618 // other code depends on the actual postition being set so set
620 fgSetDouble("/position/longitude-deg", a.longitude );
621 fgSetDouble("/position/latitude-deg", a.latitude );
623 SG_LOG( SG_GENERAL, SG_INFO,
624 "Position for " << id << " is (" << a.longitude
625 << ", " << a.latitude << ")" );
634 // Set current tower position lon/lat given an airport id
635 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
637 // tower height hard coded for now...
638 float towerheight=50.0f;
640 // make a little off the heading for 1 runway airports...
641 float fudge_lon = fabs(sin(hdg)) * .003f;
642 float fudge_lat = .003f - fudge_lon;
644 if ( fgFindAirportID( id, &a ) ) {
645 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
646 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
647 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
656 // Set current_options lon/lat given an airport id and heading (degrees)
657 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
661 // set initial position from runway and heading
663 SGPath path( globals->get_fg_root() );
664 path.append( "Airports" );
665 path.append( "runways.mk4" );
666 FGRunways runways( path.c_str() );
668 SG_LOG( SG_GENERAL, SG_INFO,
669 "Attempting to set starting position from airport code "
670 << id << " heading " << tgt_hdg );
672 if ( ! runways.search( id, (int)tgt_hdg, &r ) ) {
673 SG_LOG( SG_GENERAL, SG_ALERT,
674 "Failed to find a good runway for " << id << '\n' );
681 double lat2, lon2, az2;
682 double heading = r.heading;
683 double azimuth = heading + 180.0;
684 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
686 SG_LOG( SG_GENERAL, SG_INFO,
687 "runway = " << r.lon << ", " << r.lat
688 << " length = " << r.length * SG_FEET_TO_METER
689 << " heading = " << azimuth );
691 geo_direct_wgs_84 ( 0, r.lat, r.lon, azimuth,
692 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
693 &lat2, &lon2, &az2 );
695 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
697 double odist = fgGetDouble("/sim/presets/offset-distance");
698 odist *= SG_NM_TO_METER;
699 double oaz = azimuth;
700 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
701 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
704 while ( oaz >= 360.0 ) { oaz -= 360.0; }
705 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
711 fgSetDouble("/sim/presets/longitude-deg", lon2 );
712 fgSetDouble("/sim/presets/latitude-deg", lat2 );
713 fgSetDouble("/sim/presets/heading-deg", heading );
715 // other code depends on the actual values being set ...
716 fgSetDouble("/position/longitude-deg", lon2 );
717 fgSetDouble("/position/latitude-deg", lat2 );
718 fgSetDouble("/orientation/heading-deg", heading );
720 SG_LOG( SG_GENERAL, SG_INFO,
721 "Position for " << id << " is ("
723 << lat2 << ") new heading is "
730 // Set current_options lon/lat given an airport id and runway number
731 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
735 // set initial position from airport and runway number
737 SGPath path( globals->get_fg_root() );
738 path.append( "Airports" );
739 path.append( "runways.mk4" );
740 FGRunways runways( path.c_str() );
742 SG_LOG( SG_GENERAL, SG_INFO,
743 "Attempting to set starting position for "
744 << id << ":" << rwy );
746 if ( ! runways.search( id, rwy, &r ) ) {
747 SG_LOG( SG_GENERAL, SG_ALERT,
748 "Failed to find runway " << rwy <<
749 " at airport " << id );
756 double lat2, lon2, az2;
757 double heading = r.heading;
758 double azimuth = heading + 180.0;
759 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
761 SG_LOG( SG_GENERAL, SG_INFO,
762 "runway = " << r.lon << ", " << r.lat
763 << " length = " << r.length * SG_FEET_TO_METER
764 << " heading = " << azimuth );
766 geo_direct_wgs_84 ( 0, r.lat, r.lon,
768 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
769 &lat2, &lon2, &az2 );
771 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
774 double odist = fgGetDouble("/sim/presets/offset-distance");
775 odist *= SG_NM_TO_METER;
776 double oaz = azimuth;
777 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
779 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
780 heading = fgGetDouble("/sim/presets/heading-deg");
782 while ( oaz >= 360.0 ) { oaz -= 360.0; }
783 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
789 fgSetDouble("/sim/presets/longitude-deg", lon2 );
790 fgSetDouble("/sim/presets/latitude-deg", lat2 );
791 fgSetDouble("/sim/presets/heading-deg", heading );
793 // other code depends on the actual values being set ...
794 fgSetDouble("/position/longitude-deg", lon2 );
795 fgSetDouble("/position/latitude-deg", lat2 );
796 fgSetDouble("/orientation/heading-deg", heading );
798 SG_LOG( SG_GENERAL, SG_INFO,
799 "Position for " << id << " is ("
801 << lat2 << ") new heading is "
808 static void fgSetDistOrAltFromGlideSlope() {
809 string apt_id = fgGetString("/sim/presets/airport-id");
810 double gs = fgGetDouble("/sim/presets/glideslope-deg")
811 * SG_DEGREES_TO_RADIANS ;
812 double od = fgGetDouble("/sim/presets/offset-distance");
813 double alt = fgGetDouble("/sim/presets/altitude-ft");
815 double apt_elev = 0.0;
816 if ( ! apt_id.empty() ) {
817 apt_elev = fgGetAirportElev( apt_id );
818 if ( apt_elev < -9990.0 ) {
825 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
826 // set altitude from glideslope and offset-distance
827 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
828 alt = fabs(od*tan(gs)) + apt_elev;
829 fgSetDouble("/sim/presets/altitude-ft", alt);
830 fgSetBool("/sim/presets/onground", false);
831 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
833 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
834 // set offset-distance from glideslope and altitude
835 od = (alt - apt_elev) / tan(gs);
836 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
837 fgSetDouble("/sim/presets/offset-distance", od);
838 fgSetBool("/sim/presets/onground", false);
839 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
841 } else if( fabs(gs) > 0.01 ) {
842 SG_LOG( SG_GENERAL, SG_ALERT,
843 "Glideslope given but not altitude or offset-distance." );
844 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
845 fgSetDouble("/sim/presets/glideslope-deg", 0);
846 fgSetBool("/sim/presets/onground", true);
851 // Set current_options lon/lat given an airport id and heading (degrees)
852 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
853 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
855 // set initial position from runway and heading
857 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
858 << id << ":" << freq );
860 double lon = nav->get_lon();
861 double lat = nav->get_lat();
863 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
865 double odist = fgGetDouble("/sim/presets/offset-distance")
867 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
869 while ( oaz >= 360.0 ) { oaz -= 360.0; }
870 double olat, olon, az2;
871 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
878 fgSetDouble("/sim/presets/longitude-deg", lon );
879 fgSetDouble("/sim/presets/latitude-deg", lat );
881 // other code depends on the actual values being set ...
882 fgSetDouble("/position/longitude-deg", lon );
883 fgSetDouble("/position/latitude-deg", lat );
884 fgSetDouble("/orientation/heading-deg",
885 fgGetDouble("/sim/presets/heading-deg") );
887 SG_LOG( SG_GENERAL, SG_INFO,
888 "Position for " << id << ":" << freq << " is ("
889 << lon << ", "<< lat << ")" );
893 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
894 << id << ":" << freq );
900 // Set current_options lon/lat given an airport id and heading (degrees)
901 static bool fgSetPosFromFix( const string& id ) {
904 // set initial position from runway and heading
905 if ( current_fixlist->query( id.c_str(), &fix ) ) {
906 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
909 double lon = fix.get_lon();
910 double lat = fix.get_lat();
912 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
914 double odist = fgGetDouble("/sim/presets/offset-distance")
916 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
918 while ( oaz >= 360.0 ) { oaz -= 360.0; }
919 double olat, olon, az2;
920 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
927 fgSetDouble("/sim/presets/longitude-deg", lon );
928 fgSetDouble("/sim/presets/latitude-deg", lat );
930 // other code depends on the actual values being set ...
931 fgSetDouble("/position/longitude-deg", lon );
932 fgSetDouble("/position/latitude-deg", lat );
933 fgSetDouble("/orientation/heading-deg",
934 fgGetDouble("/sim/presets/heading-deg") );
936 SG_LOG( SG_GENERAL, SG_INFO,
937 "Position for " << id << " is ("
938 << lon << ", "<< lat << ")" );
942 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
950 * Initialize vor/ndb/ils/fix list management and query systems
955 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
957 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
958 current_navlist = new FGNavList;
959 SGPath p_nav( globals->get_fg_root() );
960 p_nav.append( "Navaids/default.nav" );
961 current_navlist->init( p_nav );
963 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
964 current_beacons = new FGMarkerBeacons;
965 current_beacons->init();
966 current_ilslist = new FGILSList;
967 SGPath p_ils( globals->get_fg_root() );
968 p_ils.append( "Navaids/default.ils" );
969 current_ilslist->init( p_ils );
971 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
972 current_fixlist = new FGFixList;
973 SGPath p_fix( globals->get_fg_root() );
974 p_fix.append( "Navaids/default.fix" );
975 current_fixlist->init( p_fix );
981 // Set the initial position based on presets (or defaults)
982 bool fgInitPosition() {
983 bool set_pos = false;
985 // If glideslope is specified, then calculate offset-distance or
986 // altitude relative to glide slope if either of those was not
988 if ( fgGetDouble("/sim/presets/glideslope-deg") > 0.1 ) {
989 fgSetDistOrAltFromGlideSlope();
992 // Select ground or air start depending on if an altitude is
993 // specified (this choice can be refined later based on other
995 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
996 fgSetBool("/sim/presets/onground", false);
998 fgSetBool("/sim/presets/onground", true);
1001 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1002 // If not, check for an airport-id and use that.
1003 // If not, default to the middle of the KSFO field.
1004 // The default values for lon/lat are deliberately out of range
1005 // so that the airport-id can take effect; valid lon/lat will
1006 // override airport-id, however.
1007 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1008 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1009 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1010 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1015 string apt = fgGetString("/sim/presets/airport-id");
1016 string rwy_no = fgGetString("/sim/presets/runway");
1017 double hdg = fgGetDouble("/sim/presets/heading-deg");
1018 string vor = fgGetString("/sim/presets/vor-id");
1019 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1020 string ndb = fgGetString("/sim/presets/ndb-id");
1021 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1022 string fix = fgGetString("/sim/presets/fix");
1024 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1025 // An airport + runway is requested
1026 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1027 // set tower position (a little off the heading for single
1029 fgSetTowerPosFromAirportID( apt, hdg );
1034 if ( !set_pos && !apt.empty() ) {
1035 // An airport is requested (find runway closest to hdg)
1036 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1037 // set tower position (a little off the heading for single
1039 fgSetTowerPosFromAirportID( apt, hdg );
1044 if ( !set_pos && !vor.empty() ) {
1045 // a VOR is requested
1046 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1051 if ( !set_pos && !ndb.empty() ) {
1052 // an NDB is requested
1053 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1058 if ( !set_pos && !fix.empty() ) {
1059 // a Fix is requested
1060 if ( fgSetPosFromFix( fix ) ) {
1066 // No lon/lat specified, no airport specified, default to
1067 // middle of KSFO field.
1068 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1069 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1072 fgSetDouble( "/position/longitude-deg",
1073 fgGetDouble("/sim/presets/longitude-deg") );
1074 fgSetDouble( "/position/latitude-deg",
1075 fgGetDouble("/sim/presets/latitude-deg") );
1076 fgSetDouble( "/orientation/heading-deg",
1077 fgGetDouble("/sim/presets/heading-deg") );
1083 // General house keeping initializations
1084 bool fgInitGeneral() {
1087 #if defined(FX) && defined(XMESA)
1088 char *mesa_win_state;
1091 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1092 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1094 root = globals->get_fg_root();
1095 if ( ! root.length() ) {
1096 // No root path set? Then bail ...
1097 SG_LOG( SG_GENERAL, SG_ALERT,
1098 "Cannot continue without a path to the base package "
1099 << "being defined." );
1102 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1104 #if defined(FX) && defined(XMESA)
1105 // initialize full screen flag
1106 globals->set_fullscreen(false);
1107 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1108 // Test for the MESA_GLX_FX env variable
1109 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1110 // test if we are fullscreen mesa/glide
1111 if ( (mesa_win_state[0] == 'f') ||
1112 (mesa_win_state[0] == 'F') ) {
1113 globals->set_fullscreen(true);
1123 // Initialize the flight model subsystem. This just creates the
1124 // object. The actual fdm initialization is delayed until we get a
1125 // proper scenery elevation hit. This is checked for in main.cxx
1129 if ( cur_fdm_state ) {
1130 delete cur_fdm_state;
1134 double dt = 1.0 / fgGetInt("/sim/model-hz");
1135 aircraft_dir = fgGetString("/sim/aircraft-dir");
1136 const string &model = fgGetString("/sim/flight-model");
1139 if ( model == "larcsim" ) {
1140 cur_fdm_state = new FGLaRCsim( dt );
1141 } else if ( model == "jsb" ) {
1142 cur_fdm_state = new FGJSBsim( dt );
1143 } else if ( model == "ada" ) {
1144 cur_fdm_state = new FGADA( dt );
1145 } else if ( model == "balloon" ) {
1146 cur_fdm_state = new FGBalloonSim( dt );
1147 } else if ( model == "magic" ) {
1148 cur_fdm_state = new FGMagicCarpet( dt );
1149 } else if ( model == "ufo" ) {
1150 cur_fdm_state = new FGUFO( dt );
1151 } else if ( model == "external" ) {
1152 // external is a synonym for "--fdm=null" and is
1153 // maintained here for backwards compatibility
1154 cur_fdm_state = new FGNullFDM( dt );
1155 } else if ( model.find("network") == 0 ) {
1156 string host = "localhost";
1160 string net_options = model.substr(8);
1161 string::size_type begin, end;
1164 end = net_options.find( ",", begin );
1165 if ( end != string::npos ) {
1166 host = net_options.substr(begin, end - begin);
1170 end = net_options.find( ",", begin );
1171 if ( end != string::npos ) {
1172 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1176 end = net_options.find( ",", begin );
1177 if ( end != string::npos ) {
1178 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1182 end = net_options.find( ",", begin );
1183 if ( end != string::npos ) {
1184 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1187 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1188 } else if ( model.find("pipe") == 0 ) {
1189 string pipe_path = model.substr(5);
1190 cur_fdm_state = new FGExternalPipe( dt, pipe_path );
1191 } else if ( model == "null" ) {
1192 cur_fdm_state = new FGNullFDM( dt );
1193 } else if ( model == "yasim" ) {
1194 cur_fdm_state = new YASim( dt );
1196 SG_LOG(SG_GENERAL, SG_ALERT,
1197 "Unrecognized flight model '" << model
1198 << "', cannot init flight dynamics model.");
1202 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1207 static void printMat(const sgVec4 *mat, char *name="")
1210 SG_LOG(SG_GENERAL, SG_BULK, name );
1211 for(i=0; i<4; i++) {
1212 SG_LOG(SG_GENERAL, SG_BULK, " " << mat[i][0] << " " << mat[i][1]
1213 << " " << mat[i][2] << " " << mat[i][3] );
1217 // Initialize view parameters
1219 // force update of model so that viewer can get some data...
1220 globals->get_aircraft_model()->update(0);
1221 // run update for current view so that data is current...
1222 globals->get_viewmgr()->update(0);
1224 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1225 printMat(globals->get_current_view()->get_UP(),"UP");
1226 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1231 SGTime *fgInitTime() {
1233 static const SGPropertyNode *longitude
1234 = fgGetNode("/position/longitude-deg");
1235 static const SGPropertyNode *latitude
1236 = fgGetNode("/position/latitude-deg");
1237 static const SGPropertyNode *cur_time_override
1238 = fgGetNode("/sim/time/cur-time-override", true);
1240 SGPath zone( globals->get_fg_root() );
1241 zone.append( "Timezone" );
1242 SGTime *t = new SGTime( longitude->getDoubleValue()
1243 * SGD_DEGREES_TO_RADIANS,
1244 latitude->getDoubleValue()
1245 * SGD_DEGREES_TO_RADIANS,
1247 cur_time_override->getLongValue() );
1249 // Handle potential user specified time offsets
1250 time_t cur_time = t->get_cur_time();
1251 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1252 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1253 time_t aircraftLocalTime =
1254 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1256 // Okay, we now have six possible scenarios
1257 int offset = fgGetInt("/sim/startup/time-offset");
1258 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1259 if (offset_type == "system-offset") {
1260 globals->set_warp( offset );
1261 } else if (offset_type == "gmt-offset") {
1262 globals->set_warp( offset - (currGMT - systemLocalTime) );
1263 } else if (offset_type == "latitude-offset") {
1264 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1265 } else if (offset_type == "system") {
1266 globals->set_warp( offset - cur_time );
1267 } else if (offset_type == "gmt") {
1268 globals->set_warp( offset - currGMT );
1269 } else if (offset_type == "latitude") {
1270 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1273 SG_LOG( SG_GENERAL, SG_ALERT,
1274 "FG_TIME::Unsupported offset type " << offset_type );
1278 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1279 << globals->get_warp() );
1281 globals->set_warp_delta( 0 );
1283 t->update( 0.0, 0.0,
1284 cur_time_override->getLongValue(),
1285 globals->get_warp() );
1291 // This is the top level init routine which calls all the other
1292 // initialization routines. If you are adding a subsystem to flight
1293 // gear, its initialization call should located in this routine.
1294 // Returns non-zero if a problem encountered.
1295 bool fgInitSubsystems() {
1296 // static const SGPropertyNode *longitude
1297 // = fgGetNode("/sim/presets/longitude-deg");
1298 // static const SGPropertyNode *latitude
1299 // = fgGetNode("/sim/presets/latitude-deg");
1300 // static const SGPropertyNode *altitude
1301 // = fgGetNode("/sim/presets/altitude-ft");
1303 fgLIGHT *l = &cur_light_params;
1305 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1306 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1309 ////////////////////////////////////////////////////////////////////
1310 // Initialize the material property subsystem.
1311 ////////////////////////////////////////////////////////////////////
1313 SGPath mpath( globals->get_fg_root() );
1314 mpath.append( "materials.xml" );
1315 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str()) ) {
1316 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1320 ////////////////////////////////////////////////////////////////////
1321 // Initialize the event manager subsystem.
1322 ////////////////////////////////////////////////////////////////////
1324 global_events.init();
1326 // Output event stats every 60 seconds
1327 global_events.Register( "FGEventMgr::print_stats()",
1328 &global_events, &FGEventMgr::print_stats,
1332 ////////////////////////////////////////////////////////////////////
1333 // Initialize the scenery management subsystem.
1334 ////////////////////////////////////////////////////////////////////
1336 if ( globals->get_tile_mgr()->init() ) {
1337 // Load the local scenery data
1338 double visibility_meters = fgGetDouble("/environment/visibility-m");
1340 globals->get_tile_mgr()->update( visibility_meters );
1342 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1346 // cause refresh of viewer scenery timestamps every 15 seconds...
1347 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1348 globals->get_tile_mgr(),
1349 &FGTileMgr::refresh_view_timestamps,
1352 SG_LOG( SG_GENERAL, SG_DEBUG,
1353 "Current terrain elevation after tile mgr init " <<
1354 globals->get_scenery()->get_cur_elev() );
1357 ////////////////////////////////////////////////////////////////////
1358 // Initialize the flight model subsystem.
1359 ////////////////////////////////////////////////////////////////////
1363 // allocates structures so must happen before any of the flight
1364 // model or control parameters are set
1365 fgAircraftInit(); // In the future this might not be the case.
1368 ////////////////////////////////////////////////////////////////////
1369 // Initialize the view manager subsystem.
1370 ////////////////////////////////////////////////////////////////////
1375 ////////////////////////////////////////////////////////////////////
1376 // Initialize the lighting subsystem.
1377 ////////////////////////////////////////////////////////////////////
1379 // fgUpdateSunPos() needs a few position and view parameters set
1380 // so it can calculate local relative sun angle and a few other
1381 // things for correctly orienting the sky.
1384 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1386 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1389 // Initialize Lighting interpolation tables
1392 // force one lighting update to make it right to start with...
1394 // update the lighting parameters (based on sun angle)
1395 global_events.Register( "fgLight::Update()",
1396 &cur_light_params, &fgLIGHT::Update,
1400 ////////////////////////////////////////////////////////////////////
1401 // Create and register the logger.
1402 ////////////////////////////////////////////////////////////////////
1404 globals->add_subsystem("logger", new FGLogger);
1407 #if defined(HAVE_PLIB_PSL)
1408 ////////////////////////////////////////////////////////////////////
1409 // Create and register the script manager.
1410 ////////////////////////////////////////////////////////////////////
1412 globals->add_subsystem("scripting", new FGScriptMgr);
1413 #endif // HAVE_PLIB_PSL
1416 ////////////////////////////////////////////////////////////////////
1417 // Create and register the XML GUI.
1418 ////////////////////////////////////////////////////////////////////
1420 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1423 ////////////////////////////////////////////////////////////////////
1424 // Initialize the local time subsystem.
1425 ////////////////////////////////////////////////////////////////////
1427 // update the current timezone each 30 minutes
1428 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1432 ////////////////////////////////////////////////////////////////////
1433 // Initialize the weather subsystem.
1434 ////////////////////////////////////////////////////////////////////
1436 // Initialize the weather modeling subsystem
1438 // Initialize the WeatherDatabase
1439 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1441 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1442 current_aircraft.fdm_state->get_Longitude(),
1443 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1444 double init_vis = fgGetDouble("/environment/visibility-m");
1446 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1448 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1450 working_type = FGLocalWeatherDatabase::use_internet;
1452 working_type = FGLocalWeatherDatabase::default_mode;
1455 if ( init_vis > 0 ) {
1456 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1457 new FGLocalWeatherDatabase( position,
1458 globals->get_fg_root(),
1462 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1463 new FGLocalWeatherDatabase( position,
1464 globals->get_fg_root(),
1468 // cout << theFGLocalWeatherDatabase << endl;
1469 // cout << "visibility = "
1470 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1472 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1474 // register the periodic update of the weather
1475 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1478 globals->add_subsystem("environment", new FGEnvironmentMgr);
1481 #ifdef FG_USE_CLOUDS_3D
1482 ////////////////////////////////////////////////////////////////////
1483 // Initialize the 3D cloud subsystem.
1484 ////////////////////////////////////////////////////////////////////
1485 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1486 static const SGPropertyNode *longitude
1487 = fgGetNode("/sim/presets/longitude-deg");
1488 static const SGPropertyNode *latitude
1489 = fgGetNode("/sim/presets/latitude-deg");
1490 static const SGPropertyNode *altitude
1491 = fgGetNode("/sim/presets/altitude-ft");
1493 SGPath cloud_path(globals->get_fg_root());
1494 cloud_path.append("large.sky");
1495 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1496 if ( !sgCloud3d->Load( cloud_path.str(),
1497 latitude->getDoubleValue(),
1498 longitude->getDoubleValue()) )
1500 fgSetBool("/sim/rendering/clouds3d", false);
1501 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1503 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1507 ////////////////////////////////////////////////////////////////////
1508 // Initialise ATC display system
1509 ////////////////////////////////////////////////////////////////////
1511 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1512 globals->set_ATC_display(new FGATCDisplay);
1513 globals->get_ATC_display()->init();
1515 ////////////////////////////////////////////////////////////////////
1516 // Initialise the ATC Manager
1517 ////////////////////////////////////////////////////////////////////
1519 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1520 globals->set_ATC_mgr(new FGATCMgr);
1521 globals->get_ATC_mgr()->init();
1523 ////////////////////////////////////////////////////////////////////
1524 // Initialise the AI Manager
1525 ////////////////////////////////////////////////////////////////////
1527 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1528 globals->set_AI_mgr(new FGAIMgr);
1529 globals->get_AI_mgr()->init();
1532 #ifdef ENABLE_AUDIO_SUPPORT
1533 ////////////////////////////////////////////////////////////////////
1534 // Initialize the sound subsystem.
1535 ////////////////////////////////////////////////////////////////////
1537 globals->set_soundmgr(new SGSoundMgr);
1538 globals->get_soundmgr()->init();
1539 globals->get_soundmgr()->bind();
1542 ////////////////////////////////////////////////////////////////////
1543 // Initialize the sound-effects subsystem.
1544 ////////////////////////////////////////////////////////////////////
1546 globals->add_subsystem("fx", new FGFX);
1550 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1551 globals->add_subsystem("systems", new FGSystemMgr);
1553 ////////////////////////////////////////////////////////////////////
1554 // Initialize the radio stack subsystem.
1555 ////////////////////////////////////////////////////////////////////
1557 current_radiostack = new FGRadioStack;
1558 current_radiostack->init();
1559 current_radiostack->bind();
1562 ////////////////////////////////////////////////////////////////////
1563 // Initialize the cockpit subsystem
1564 ////////////////////////////////////////////////////////////////////
1566 if( fgCockpitInit( ¤t_aircraft )) {
1567 // Cockpit initialized ok.
1569 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1574 ////////////////////////////////////////////////////////////////////
1575 // Initialize the autopilot subsystem.
1576 ////////////////////////////////////////////////////////////////////
1578 globals->set_autopilot(new FGAutopilot);
1579 globals->get_autopilot()->init();
1580 globals->get_autopilot()->bind();
1582 // FIXME: these should go in the
1583 // GUI initialization code, not here.
1585 NewTgtAirportInit();
1589 ////////////////////////////////////////////////////////////////////
1590 // Initialize I/O subsystem.
1591 ////////////////////////////////////////////////////////////////////
1593 globals->get_io()->init();
1594 globals->get_io()->bind();
1597 ////////////////////////////////////////////////////////////////////
1598 // Add a new 2D panel.
1599 ////////////////////////////////////////////////////////////////////
1601 string panel_path = fgGetString("/sim/panel/path",
1602 "Panels/Default/default.xml");
1604 globals->set_current_panel( fgReadPanel(panel_path) );
1605 if (globals->get_current_panel() == 0) {
1606 SG_LOG( SG_INPUT, SG_ALERT,
1607 "Error reading new panel from " << panel_path );
1609 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1610 globals->get_current_panel()->init();
1611 globals->get_current_panel()->bind();
1615 ////////////////////////////////////////////////////////////////////
1616 // Initialize the default (kludged) properties.
1617 ////////////////////////////////////////////////////////////////////
1622 ////////////////////////////////////////////////////////////////////
1623 // Initialize the controls subsystem.
1624 ////////////////////////////////////////////////////////////////////
1626 globals->get_controls()->init();
1627 globals->get_controls()->bind();
1630 ////////////////////////////////////////////////////////////////////
1631 // Initialize the input subsystem.
1632 ////////////////////////////////////////////////////////////////////
1634 globals->add_subsystem("input", new FGInput);
1637 ////////////////////////////////////////////////////////////////////
1638 // Bind and initialize subsystems.
1639 ////////////////////////////////////////////////////////////////////
1641 globals->get_subsystem_mgr()->bind();
1642 globals->get_subsystem_mgr()->init();
1645 #ifdef FG_MPLAYER_AS
1646 ////////////////////////////////////////////////////////////////////
1647 // Initialize multiplayer subsystem
1648 ////////////////////////////////////////////////////////////////////
1650 globals->set_multiplayer_tx_mgr(new FGMultiplayTxMgr);
1651 globals->get_multiplayer_tx_mgr()->init();
1653 globals->set_multiplayer_rx_mgr(new FGMultiplayRxMgr);
1654 globals->get_multiplayer_rx_mgr()->init();
1657 ////////////////////////////////////////////////////////////////////////
1658 // End of subsystem initialization.
1659 ////////////////////////////////////////////////////////////////////
1661 SG_LOG( SG_GENERAL, SG_INFO, endl);
1663 // Save the initial state for future
1665 globals->saveInitialState();
1671 void fgReInitSubsystems()
1673 // static const SGPropertyNode *longitude
1674 // = fgGetNode("/sim/presets/longitude-deg");
1675 // static const SGPropertyNode *latitude
1676 // = fgGetNode("/sim/presets/latitude-deg");
1677 static const SGPropertyNode *altitude
1678 = fgGetNode("/sim/presets/altitude-ft");
1679 static const SGPropertyNode *master_freeze
1680 = fgGetNode("/sim/freeze/master");
1682 SG_LOG( SG_GENERAL, SG_INFO,
1683 "fgReInitSubsystems(): /position/altitude = "
1684 << altitude->getDoubleValue() );
1686 bool freeze = master_freeze->getBoolValue();
1688 fgSetBool("/sim/freeze/master", true);
1691 // Initialize the FDM
1694 // allocates structures so must happen before any of the flight
1695 // model or control parameters are set
1696 fgAircraftInit(); // In the future this might not be the case.
1698 // reload offsets from config defaults
1699 globals->get_viewmgr()->reinit();
1703 globals->get_controls()->reset_all();
1704 globals->get_autopilot()->reset();
1708 cur_light_params.Update();
1709 fgUpdateLocalTime();
1712 fgSetBool("/sim/freeze/master", false);