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 <Replay/replay.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 <Systems/system_mgr.hxx>
114 #include <Time/FGEventMgr.hxx>
115 #include <Time/light.hxx>
116 #include <Time/sunpos.hxx>
117 #include <Time/moonpos.hxx>
118 #include <Time/tmp.hxx>
121 #include <MultiPlayer/multiplaytxmgr.hxx>
122 #include <MultiPlayer/multiplayrxmgr.hxx>
126 # include <WeatherCM/FGLocalWeatherDatabase.h>
128 # include <Environment/environment_mgr.hxx>
131 #include "fg_init.hxx"
133 #include "fg_commands.hxx"
134 #include "fg_props.hxx"
135 #include "options.hxx"
136 #include "globals.hxx"
137 #include "logger.hxx"
138 #include "viewmgr.hxx"
140 #if defined(FX) && defined(XMESA)
141 #include <GL/xmesa.h>
144 SG_USING_STD(string);
149 extern const char *default_root;
151 #ifdef FG_USE_CLOUDS_3D
152 SkySceneLoader *sgCloud3d;
156 // Scan the command line options for the specified option and return
158 static string fgScanForOption( const string& option, int argc, char **argv ) {
161 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
163 int len = option.length();
166 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
168 string arg = argv[i];
169 if ( arg.find( option ) == 0 ) {
170 return arg.substr( len );
180 // Scan the user config files for the specified option and return
182 static string fgScanForOption( const string& option, const string& path ) {
183 sg_gzifstream in( path );
184 if ( !in.is_open() ) {
188 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
190 int len = option.length();
194 while ( ! in.eof() ) {
197 while ( in.get(c) && c != '\0' ) {
202 #if defined( macintosh )
203 getline( in, line, '\r' );
205 getline( in, line, '\n' );
208 // catch extraneous (DOS) line ending character
209 if ( line[line.length() - 1] < 32 ) {
210 line = line.substr( 0, line.length()-1 );
213 if ( line.find( option ) == 0 ) {
214 return line.substr( len );
224 // Read in configuration (files and command line options) but only set
226 bool fgInitFGRoot ( int argc, char **argv ) {
230 // First parse command line options looking for --fg-root=, this
231 // will override anything specified in a config file
232 root = fgScanForOption( "--fg-root=", argc, argv);
234 #if defined( unix ) || defined( __CYGWIN__ )
235 // Next check home directory for .fgfsrc.hostname file
236 if ( root.empty() ) {
237 envp = ::getenv( "HOME" );
238 if ( envp != NULL ) {
239 SGPath config( envp );
240 config.append( ".fgfsrc" );
242 gethostname( name, 256 );
243 config.concat( "." );
244 config.concat( name );
245 root = fgScanForOption( "--fg-root=", config.str() );
250 // Next check home directory for .fgfsrc file
251 if ( root.empty() ) {
252 envp = ::getenv( "HOME" );
253 if ( envp != NULL ) {
254 SGPath config( envp );
255 config.append( ".fgfsrc" );
256 root = fgScanForOption( "--fg-root=", config.str() );
260 // Next check if fg-root is set as an env variable
261 if ( root.empty() ) {
262 envp = ::getenv( "FG_ROOT" );
263 if ( envp != NULL ) {
268 // Otherwise, default to a random compiled-in location if we can't
269 // find fg-root any other way.
270 if ( root.empty() ) {
271 #if defined( __CYGWIN__ )
272 root = "/FlightGear";
273 #elif defined( WIN32 )
274 root = "\\FlightGear";
275 #elif defined( macintosh )
282 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
283 globals->set_fg_root(root);
289 // Read in configuration (files and command line options) but only set
291 bool fgInitFGAircraft ( int argc, char **argv ) {
295 // First parse command line options looking for --aircraft=, this
296 // will override anything specified in a config file
297 aircraft = fgScanForOption( "--aircraft=", argc, argv );
299 #if defined( unix ) || defined( __CYGWIN__ )
300 // Next check home directory for .fgfsrc.hostname file
301 if ( aircraft.empty() ) {
302 envp = ::getenv( "HOME" );
303 if ( envp != NULL ) {
304 SGPath config( envp );
305 config.append( ".fgfsrc" );
307 gethostname( name, 256 );
308 config.concat( "." );
309 config.concat( name );
310 aircraft = fgScanForOption( "--aircraft=", config.str() );
315 // Next check home directory for .fgfsrc file
316 if ( aircraft.empty() ) {
317 envp = ::getenv( "HOME" );
318 if ( envp != NULL ) {
319 SGPath config( envp );
320 config.append( ".fgfsrc" );
321 aircraft = fgScanForOption( "--aircraft=", config.str() );
325 // if an aircraft was specified, set the property name
326 if ( !aircraft.empty() ) {
327 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
328 fgSetString("/sim/aircraft", aircraft.c_str() );
330 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
337 // Return the current base package version
338 string fgBasePackageVersion() {
339 SGPath base_path( globals->get_fg_root() );
340 base_path.append("version");
342 sg_gzifstream in( base_path.str() );
343 if ( !in.is_open() ) {
344 SGPath old_path( globals->get_fg_root() );
345 old_path.append( "Thanks" );
346 sg_gzifstream old( old_path.str() );
347 if ( !old.is_open() ) {
350 return "[old version]";
361 // Initialize the localization
362 SGPropertyNode *fgInitLocale(const char *language) {
363 SGPropertyNode *c_node = NULL, *d_node = NULL;
364 SGPropertyNode *intl = fgGetNode("/sim/intl");
366 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
368 // localization not defined
373 // Select the proper language from the list
375 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
376 for (unsigned int i = 0; i < locale.size(); i++) {
378 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
379 for (unsigned int j = 0; j < lang.size(); j++) {
381 if (!strcmp(lang[j]->getStringValue(), language)) {
390 d_node = intl->getChild("locale");
394 // Check for localized font
395 SGPropertyNode *font_n = c_node->getNode("font", true);
396 if ( !strcmp(font_n->getStringValue(), "") )
397 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
401 // Load the default strings
403 SGPath d_path( globals->get_fg_root() );
405 const char *d_path_str = d_node->getStringValue("strings");
407 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
411 d_path.append(d_path_str);
412 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
415 SGPropertyNode *strings = c_node->getNode("strings");
417 readProperties(d_path.str(), strings);
418 } catch (const sg_exception &e) {
419 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
424 // Load the language specific strings
426 if (c_node != d_node) {
427 SGPath c_path( globals->get_fg_root() );
429 const char *c_path_str = c_node->getStringValue("strings");
431 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
435 c_path.append(c_path_str);
436 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
440 readProperties(c_path.str(), strings);
441 } catch (const sg_exception &e) {
442 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
452 // Initialize the localization routines
453 bool fgDetectLanguage() {
454 char *language = ::getenv("LANG");
456 if (language == NULL) {
457 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
461 SGPropertyNode *locale = fgInitLocale(language);
463 SG_LOG(SG_GENERAL, SG_ALERT,
464 "No internationalization settings specified in preferences.xml" );
469 globals->set_locale( locale );
474 // Attempt to locate and parse the various non-XML config files in order
475 // from least precidence to greatest precidence
477 do_options (int argc, char ** argv)
479 // Check for $fg_root/system.fgfsrc
480 SGPath config( globals->get_fg_root() );
481 config.append( "system.fgfsrc" );
482 fgParseOptions(config.str());
484 #if defined( unix ) || defined( __CYGWIN__ )
486 // Check for $fg_root/system.fgfsrc.hostname
487 gethostname( name, 256 );
488 config.concat( "." );
489 config.concat( name );
490 fgParseOptions(config.str());
493 // Check for ~/.fgfsrc
494 char* envp = ::getenv( "HOME" );
495 if ( envp != NULL ) {
497 config.append( ".fgfsrc" );
498 fgParseOptions(config.str());
501 #if defined( unix ) || defined( __CYGWIN__ )
502 // Check for ~/.fgfsrc.hostname
503 gethostname( name, 256 );
504 config.concat( "." );
505 config.concat( name );
506 fgParseOptions(config.str());
509 // Parse remaining command line options
510 // These will override anything specified in a config file
511 fgParseArgs(argc, argv);
515 // Read in configuration (file and command line)
516 bool fgInitConfig ( int argc, char **argv ) {
518 // First, set some sane default values
521 // Read global preferences from $FG_ROOT/preferences.xml
522 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
523 fgLoadProps("preferences.xml", globals->get_props());
524 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
526 // Detect the required language as early as possible
527 if ( !fgDetectLanguage() ) {
531 // Scan user config files and command line for a specified aircraft.
532 fgInitFGAircraft(argc, argv);
534 string aircraft = fgGetString("/sim/aircraft", "");
535 if ( aircraft.size() > 0 ) {
536 SGPath aircraft_path(globals->get_fg_root());
537 aircraft_path.append("Aircraft");
538 aircraft_path.append(aircraft);
539 aircraft_path.concat("-set.xml");
540 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
541 << " from " << aircraft_path.str());
543 readProperties(aircraft_path.str(), globals->get_props());
544 } catch (const sg_exception &e) {
545 string message = "Error reading default aircraft: ";
546 message += e.getFormattedMessage();
547 SG_LOG(SG_INPUT, SG_ALERT, message);
551 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
554 // parse options after loading aircraft to ensure any user
555 // overrides of defaults are honored.
556 do_options(argc, argv);
562 // find basic airport location info from airport database
563 bool fgFindAirportID( const string& id, FGAirport *a ) {
565 SGPath path( globals->get_fg_root() );
566 path.append( "Airports" );
567 path.append( "simple.mk4" );
568 FGAirports airports( path.c_str() );
570 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
572 if ( ! airports.search( id, a ) ) {
573 SG_LOG( SG_GENERAL, SG_ALERT,
574 "Failed to find " << id << " in " << path.str() );
581 SG_LOG( SG_GENERAL, SG_INFO,
582 "Position for " << id << " is ("
583 << a->longitude << ", "
584 << a->latitude << ")" );
590 // get airport elevation
591 static double fgGetAirportElev( const string& id ) {
595 SG_LOG( SG_GENERAL, SG_INFO,
596 "Finding elevation for airport: " << id );
598 if ( fgFindAirportID( id, &a ) ) {
606 // Preset lon/lat given an airport id
607 static bool fgSetPosFromAirportID( const string& id ) {
611 SG_LOG( SG_GENERAL, SG_INFO,
612 "Attempting to set starting position from airport code " << id );
614 if ( fgFindAirportID( id, &a ) ) {
616 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
617 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
619 // other code depends on the actual postition being set so set
621 fgSetDouble("/position/longitude-deg", a.longitude );
622 fgSetDouble("/position/latitude-deg", a.latitude );
624 SG_LOG( SG_GENERAL, SG_INFO,
625 "Position for " << id << " is (" << a.longitude
626 << ", " << a.latitude << ")" );
635 // Set current tower position lon/lat given an airport id
636 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
638 // tower height hard coded for now...
639 float towerheight=50.0f;
641 // make a little off the heading for 1 runway airports...
642 float fudge_lon = fabs(sin(hdg)) * .003f;
643 float fudge_lat = .003f - fudge_lon;
645 if ( fgFindAirportID( id, &a ) ) {
646 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
647 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
648 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
657 // Set current_options lon/lat given an airport id and heading (degrees)
658 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
662 // set initial position from runway and heading
664 SGPath path( globals->get_fg_root() );
665 path.append( "Airports" );
666 path.append( "runways.mk4" );
667 FGRunways runways( path.c_str() );
669 SG_LOG( SG_GENERAL, SG_INFO,
670 "Attempting to set starting position from airport code "
671 << id << " heading " << tgt_hdg );
673 if ( ! runways.search( id, (int)tgt_hdg, &r ) ) {
674 SG_LOG( SG_GENERAL, SG_ALERT,
675 "Failed to find a good runway for " << id << '\n' );
682 double lat2, lon2, az2;
683 double heading = r.heading;
684 double azimuth = heading + 180.0;
685 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
687 SG_LOG( SG_GENERAL, SG_INFO,
688 "runway = " << r.lon << ", " << r.lat
689 << " length = " << r.length * SG_FEET_TO_METER
690 << " heading = " << azimuth );
692 geo_direct_wgs_84 ( 0, r.lat, r.lon, azimuth,
693 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
694 &lat2, &lon2, &az2 );
696 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
698 double odist = fgGetDouble("/sim/presets/offset-distance");
699 odist *= SG_NM_TO_METER;
700 double oaz = azimuth;
701 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
702 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
705 while ( oaz >= 360.0 ) { oaz -= 360.0; }
706 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
712 fgSetDouble("/sim/presets/longitude-deg", lon2 );
713 fgSetDouble("/sim/presets/latitude-deg", lat2 );
714 fgSetDouble("/sim/presets/heading-deg", heading );
716 // other code depends on the actual values being set ...
717 fgSetDouble("/position/longitude-deg", lon2 );
718 fgSetDouble("/position/latitude-deg", lat2 );
719 fgSetDouble("/orientation/heading-deg", heading );
721 SG_LOG( SG_GENERAL, SG_INFO,
722 "Position for " << id << " is ("
724 << lat2 << ") new heading is "
731 // Set current_options lon/lat given an airport id and runway number
732 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
736 // set initial position from airport and runway number
738 SGPath path( globals->get_fg_root() );
739 path.append( "Airports" );
740 path.append( "runways.mk4" );
741 FGRunways runways( path.c_str() );
743 SG_LOG( SG_GENERAL, SG_INFO,
744 "Attempting to set starting position for "
745 << id << ":" << rwy );
747 if ( ! runways.search( id, rwy, &r ) ) {
748 SG_LOG( SG_GENERAL, SG_ALERT,
749 "Failed to find runway " << rwy <<
750 " at airport " << id );
757 double lat2, lon2, az2;
758 double heading = r.heading;
759 double azimuth = heading + 180.0;
760 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
762 SG_LOG( SG_GENERAL, SG_INFO,
763 "runway = " << r.lon << ", " << r.lat
764 << " length = " << r.length * SG_FEET_TO_METER
765 << " heading = " << azimuth );
767 geo_direct_wgs_84 ( 0, r.lat, r.lon,
769 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
770 &lat2, &lon2, &az2 );
772 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
775 double odist = fgGetDouble("/sim/presets/offset-distance");
776 odist *= SG_NM_TO_METER;
777 double oaz = azimuth;
778 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
780 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
781 heading = fgGetDouble("/sim/presets/heading-deg");
783 while ( oaz >= 360.0 ) { oaz -= 360.0; }
784 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
790 fgSetDouble("/sim/presets/longitude-deg", lon2 );
791 fgSetDouble("/sim/presets/latitude-deg", lat2 );
792 fgSetDouble("/sim/presets/heading-deg", heading );
794 // other code depends on the actual values being set ...
795 fgSetDouble("/position/longitude-deg", lon2 );
796 fgSetDouble("/position/latitude-deg", lat2 );
797 fgSetDouble("/orientation/heading-deg", heading );
799 SG_LOG( SG_GENERAL, SG_INFO,
800 "Position for " << id << " is ("
802 << lat2 << ") new heading is "
809 static void fgSetDistOrAltFromGlideSlope() {
810 string apt_id = fgGetString("/sim/presets/airport-id");
811 double gs = fgGetDouble("/sim/presets/glideslope-deg")
812 * SG_DEGREES_TO_RADIANS ;
813 double od = fgGetDouble("/sim/presets/offset-distance");
814 double alt = fgGetDouble("/sim/presets/altitude-ft");
816 double apt_elev = 0.0;
817 if ( ! apt_id.empty() ) {
818 apt_elev = fgGetAirportElev( apt_id );
819 if ( apt_elev < -9990.0 ) {
826 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
827 // set altitude from glideslope and offset-distance
828 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
829 alt = fabs(od*tan(gs)) + apt_elev;
830 fgSetDouble("/sim/presets/altitude-ft", alt);
831 fgSetBool("/sim/presets/onground", false);
832 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
834 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
835 // set offset-distance from glideslope and altitude
836 od = (alt - apt_elev) / tan(gs);
837 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
838 fgSetDouble("/sim/presets/offset-distance", od);
839 fgSetBool("/sim/presets/onground", false);
840 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
842 } else if( fabs(gs) > 0.01 ) {
843 SG_LOG( SG_GENERAL, SG_ALERT,
844 "Glideslope given but not altitude or offset-distance." );
845 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
846 fgSetDouble("/sim/presets/glideslope-deg", 0);
847 fgSetBool("/sim/presets/onground", true);
852 // Set current_options lon/lat given an airport id and heading (degrees)
853 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
854 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
856 // set initial position from runway and heading
858 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
859 << id << ":" << freq );
861 double lon = nav->get_lon();
862 double lat = nav->get_lat();
864 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
866 double odist = fgGetDouble("/sim/presets/offset-distance")
868 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
870 while ( oaz >= 360.0 ) { oaz -= 360.0; }
871 double olat, olon, az2;
872 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
879 fgSetDouble("/sim/presets/longitude-deg", lon );
880 fgSetDouble("/sim/presets/latitude-deg", lat );
882 // other code depends on the actual values being set ...
883 fgSetDouble("/position/longitude-deg", lon );
884 fgSetDouble("/position/latitude-deg", lat );
885 fgSetDouble("/orientation/heading-deg",
886 fgGetDouble("/sim/presets/heading-deg") );
888 SG_LOG( SG_GENERAL, SG_INFO,
889 "Position for " << id << ":" << freq << " is ("
890 << lon << ", "<< lat << ")" );
894 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
895 << id << ":" << freq );
901 // Set current_options lon/lat given an airport id and heading (degrees)
902 static bool fgSetPosFromFix( const string& id ) {
905 // set initial position from runway and heading
906 if ( current_fixlist->query( id.c_str(), &fix ) ) {
907 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
910 double lon = fix.get_lon();
911 double lat = fix.get_lat();
913 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
915 double odist = fgGetDouble("/sim/presets/offset-distance")
917 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
919 while ( oaz >= 360.0 ) { oaz -= 360.0; }
920 double olat, olon, az2;
921 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
928 fgSetDouble("/sim/presets/longitude-deg", lon );
929 fgSetDouble("/sim/presets/latitude-deg", lat );
931 // other code depends on the actual values being set ...
932 fgSetDouble("/position/longitude-deg", lon );
933 fgSetDouble("/position/latitude-deg", lat );
934 fgSetDouble("/orientation/heading-deg",
935 fgGetDouble("/sim/presets/heading-deg") );
937 SG_LOG( SG_GENERAL, SG_INFO,
938 "Position for " << id << " is ("
939 << lon << ", "<< lat << ")" );
943 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
951 * Initialize vor/ndb/ils/fix list management and query systems
956 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
958 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
959 current_navlist = new FGNavList;
960 SGPath p_nav( globals->get_fg_root() );
961 p_nav.append( "Navaids/default.nav" );
962 current_navlist->init( p_nav );
964 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
965 current_beacons = new FGMarkerBeacons;
966 current_beacons->init();
967 current_ilslist = new FGILSList;
968 SGPath p_ils( globals->get_fg_root() );
969 p_ils.append( "Navaids/default.ils" );
970 current_ilslist->init( p_ils );
972 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
973 current_fixlist = new FGFixList;
974 SGPath p_fix( globals->get_fg_root() );
975 p_fix.append( "Navaids/default.fix" );
976 current_fixlist->init( p_fix );
982 // Set the initial position based on presets (or defaults)
983 bool fgInitPosition() {
984 bool set_pos = false;
986 // If glideslope is specified, then calculate offset-distance or
987 // altitude relative to glide slope if either of those was not
989 if ( fgGetDouble("/sim/presets/glideslope-deg") > 0.1 ) {
990 fgSetDistOrAltFromGlideSlope();
993 // Select ground or air start depending on if an altitude is
994 // specified (this choice can be refined later based on other
996 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
997 fgSetBool("/sim/presets/onground", false);
999 fgSetBool("/sim/presets/onground", true);
1002 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1003 // If not, check for an airport-id and use that.
1004 // If not, default to the middle of the KSFO field.
1005 // The default values for lon/lat are deliberately out of range
1006 // so that the airport-id can take effect; valid lon/lat will
1007 // override airport-id, however.
1008 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1009 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1010 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1011 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1016 string apt = fgGetString("/sim/presets/airport-id");
1017 string rwy_no = fgGetString("/sim/presets/runway");
1018 double hdg = fgGetDouble("/sim/presets/heading-deg");
1019 string vor = fgGetString("/sim/presets/vor-id");
1020 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1021 string ndb = fgGetString("/sim/presets/ndb-id");
1022 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1023 string fix = fgGetString("/sim/presets/fix");
1025 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1026 // An airport + runway is requested
1027 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1028 // set tower position (a little off the heading for single
1030 fgSetTowerPosFromAirportID( apt, hdg );
1035 if ( !set_pos && !apt.empty() ) {
1036 // An airport is requested (find runway closest to hdg)
1037 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1038 // set tower position (a little off the heading for single
1040 fgSetTowerPosFromAirportID( apt, hdg );
1045 if ( !set_pos && !vor.empty() ) {
1046 // a VOR is requested
1047 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1052 if ( !set_pos && !ndb.empty() ) {
1053 // an NDB is requested
1054 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1059 if ( !set_pos && !fix.empty() ) {
1060 // a Fix is requested
1061 if ( fgSetPosFromFix( fix ) ) {
1067 // No lon/lat specified, no airport specified, default to
1068 // middle of KSFO field.
1069 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1070 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1073 fgSetDouble( "/position/longitude-deg",
1074 fgGetDouble("/sim/presets/longitude-deg") );
1075 fgSetDouble( "/position/latitude-deg",
1076 fgGetDouble("/sim/presets/latitude-deg") );
1077 fgSetDouble( "/orientation/heading-deg",
1078 fgGetDouble("/sim/presets/heading-deg") );
1084 // General house keeping initializations
1085 bool fgInitGeneral() {
1088 #if defined(FX) && defined(XMESA)
1089 char *mesa_win_state;
1092 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1093 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1095 root = globals->get_fg_root();
1096 if ( ! root.length() ) {
1097 // No root path set? Then bail ...
1098 SG_LOG( SG_GENERAL, SG_ALERT,
1099 "Cannot continue without a path to the base package "
1100 << "being defined." );
1103 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1105 #if defined(FX) && defined(XMESA)
1106 // initialize full screen flag
1107 globals->set_fullscreen(false);
1108 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1109 // Test for the MESA_GLX_FX env variable
1110 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1111 // test if we are fullscreen mesa/glide
1112 if ( (mesa_win_state[0] == 'f') ||
1113 (mesa_win_state[0] == 'F') ) {
1114 globals->set_fullscreen(true);
1124 // Initialize the flight model subsystem. This just creates the
1125 // object. The actual fdm initialization is delayed until we get a
1126 // proper scenery elevation hit. This is checked for in main.cxx
1130 if ( cur_fdm_state ) {
1131 delete cur_fdm_state;
1135 double dt = 1.0 / fgGetInt("/sim/model-hz");
1136 aircraft_dir = fgGetString("/sim/aircraft-dir");
1137 const string &model = fgGetString("/sim/flight-model");
1140 if ( model == "larcsim" ) {
1141 cur_fdm_state = new FGLaRCsim( dt );
1142 } else if ( model == "jsb" ) {
1143 cur_fdm_state = new FGJSBsim( dt );
1144 } else if ( model == "ada" ) {
1145 cur_fdm_state = new FGADA( dt );
1146 } else if ( model == "balloon" ) {
1147 cur_fdm_state = new FGBalloonSim( dt );
1148 } else if ( model == "magic" ) {
1149 cur_fdm_state = new FGMagicCarpet( dt );
1150 } else if ( model == "ufo" ) {
1151 cur_fdm_state = new FGUFO( dt );
1152 } else if ( model == "external" ) {
1153 // external is a synonym for "--fdm=null" and is
1154 // maintained here for backwards compatibility
1155 cur_fdm_state = new FGNullFDM( dt );
1156 } else if ( model.find("network") == 0 ) {
1157 string host = "localhost";
1161 string net_options = model.substr(8);
1162 string::size_type begin, end;
1165 end = net_options.find( ",", begin );
1166 if ( end != string::npos ) {
1167 host = net_options.substr(begin, end - begin);
1171 end = net_options.find( ",", begin );
1172 if ( end != string::npos ) {
1173 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1177 end = net_options.find( ",", begin );
1178 if ( end != string::npos ) {
1179 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1183 end = net_options.find( ",", begin );
1184 if ( end != string::npos ) {
1185 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1188 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1189 } else if ( model.find("pipe") == 0 ) {
1190 string pipe_path = model.substr(5);
1191 cur_fdm_state = new FGExternalPipe( dt, pipe_path );
1192 } else if ( model == "null" ) {
1193 cur_fdm_state = new FGNullFDM( dt );
1194 } else if ( model == "yasim" ) {
1195 cur_fdm_state = new YASim( dt );
1197 SG_LOG(SG_GENERAL, SG_ALERT,
1198 "Unrecognized flight model '" << model
1199 << "', cannot init flight dynamics model.");
1203 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1208 static void printMat(const sgVec4 *mat, char *name="")
1211 SG_LOG(SG_GENERAL, SG_BULK, name );
1212 for(i=0; i<4; i++) {
1213 SG_LOG(SG_GENERAL, SG_BULK, " " << mat[i][0] << " " << mat[i][1]
1214 << " " << mat[i][2] << " " << mat[i][3] );
1218 // Initialize view parameters
1220 // force update of model so that viewer can get some data...
1221 globals->get_aircraft_model()->update(0);
1222 // run update for current view so that data is current...
1223 globals->get_viewmgr()->update(0);
1225 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1226 printMat(globals->get_current_view()->get_UP(),"UP");
1227 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1232 SGTime *fgInitTime() {
1234 static const SGPropertyNode *longitude
1235 = fgGetNode("/position/longitude-deg");
1236 static const SGPropertyNode *latitude
1237 = fgGetNode("/position/latitude-deg");
1238 static const SGPropertyNode *cur_time_override
1239 = fgGetNode("/sim/time/cur-time-override", true);
1241 SGPath zone( globals->get_fg_root() );
1242 zone.append( "Timezone" );
1243 SGTime *t = new SGTime( longitude->getDoubleValue()
1244 * SGD_DEGREES_TO_RADIANS,
1245 latitude->getDoubleValue()
1246 * SGD_DEGREES_TO_RADIANS,
1248 cur_time_override->getLongValue() );
1250 // Handle potential user specified time offsets
1251 time_t cur_time = t->get_cur_time();
1252 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1253 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1254 time_t aircraftLocalTime =
1255 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1257 // Okay, we now have six possible scenarios
1258 int offset = fgGetInt("/sim/startup/time-offset");
1259 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1260 if (offset_type == "system-offset") {
1261 globals->set_warp( offset );
1262 } else if (offset_type == "gmt-offset") {
1263 globals->set_warp( offset - (currGMT - systemLocalTime) );
1264 } else if (offset_type == "latitude-offset") {
1265 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1266 } else if (offset_type == "system") {
1267 globals->set_warp( offset - cur_time );
1268 } else if (offset_type == "gmt") {
1269 globals->set_warp( offset - currGMT );
1270 } else if (offset_type == "latitude") {
1271 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1274 SG_LOG( SG_GENERAL, SG_ALERT,
1275 "FG_TIME::Unsupported offset type " << offset_type );
1279 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1280 << globals->get_warp() );
1282 globals->set_warp_delta( 0 );
1284 t->update( 0.0, 0.0,
1285 cur_time_override->getLongValue(),
1286 globals->get_warp() );
1292 // This is the top level init routine which calls all the other
1293 // initialization routines. If you are adding a subsystem to flight
1294 // gear, its initialization call should located in this routine.
1295 // Returns non-zero if a problem encountered.
1296 bool fgInitSubsystems() {
1297 // static const SGPropertyNode *longitude
1298 // = fgGetNode("/sim/presets/longitude-deg");
1299 // static const SGPropertyNode *latitude
1300 // = fgGetNode("/sim/presets/latitude-deg");
1301 // static const SGPropertyNode *altitude
1302 // = fgGetNode("/sim/presets/altitude-ft");
1304 fgLIGHT *l = &cur_light_params;
1306 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1307 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1310 ////////////////////////////////////////////////////////////////////
1311 // Initialize the material property subsystem.
1312 ////////////////////////////////////////////////////////////////////
1314 SGPath mpath( globals->get_fg_root() );
1315 mpath.append( "materials.xml" );
1316 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str()) ) {
1317 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1321 ////////////////////////////////////////////////////////////////////
1322 // Initialize the event manager subsystem.
1323 ////////////////////////////////////////////////////////////////////
1325 global_events.init();
1327 // Output event stats every 60 seconds
1328 global_events.Register( "FGEventMgr::print_stats()",
1329 &global_events, &FGEventMgr::print_stats,
1333 ////////////////////////////////////////////////////////////////////
1334 // Initialize the scenery management subsystem.
1335 ////////////////////////////////////////////////////////////////////
1337 if ( globals->get_tile_mgr()->init() ) {
1338 // Load the local scenery data
1339 double visibility_meters = fgGetDouble("/environment/visibility-m");
1341 globals->get_tile_mgr()->update( visibility_meters );
1343 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1347 // cause refresh of viewer scenery timestamps every 15 seconds...
1348 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1349 globals->get_tile_mgr(),
1350 &FGTileMgr::refresh_view_timestamps,
1353 SG_LOG( SG_GENERAL, SG_DEBUG,
1354 "Current terrain elevation after tile mgr init " <<
1355 globals->get_scenery()->get_cur_elev() );
1358 ////////////////////////////////////////////////////////////////////
1359 // Initialize the flight model subsystem.
1360 ////////////////////////////////////////////////////////////////////
1364 // allocates structures so must happen before any of the flight
1365 // model or control parameters are set
1366 fgAircraftInit(); // In the future this might not be the case.
1369 ////////////////////////////////////////////////////////////////////
1370 // Initialize the view manager subsystem.
1371 ////////////////////////////////////////////////////////////////////
1376 ////////////////////////////////////////////////////////////////////
1377 // Initialize the lighting subsystem.
1378 ////////////////////////////////////////////////////////////////////
1380 // fgUpdateSunPos() needs a few position and view parameters set
1381 // so it can calculate local relative sun angle and a few other
1382 // things for correctly orienting the sky.
1385 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1387 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1390 // Initialize Lighting interpolation tables
1393 // force one lighting update to make it right to start with...
1395 // update the lighting parameters (based on sun angle)
1396 global_events.Register( "fgLight::Update()",
1397 &cur_light_params, &fgLIGHT::Update,
1401 ////////////////////////////////////////////////////////////////////
1402 // Create and register the logger.
1403 ////////////////////////////////////////////////////////////////////
1405 globals->add_subsystem("logger", new FGLogger);
1408 #if defined(HAVE_PLIB_PSL)
1409 ////////////////////////////////////////////////////////////////////
1410 // Create and register the script manager.
1411 ////////////////////////////////////////////////////////////////////
1413 globals->add_subsystem("scripting", new FGScriptMgr);
1414 #endif // HAVE_PLIB_PSL
1417 ////////////////////////////////////////////////////////////////////
1418 // Create and register the XML GUI.
1419 ////////////////////////////////////////////////////////////////////
1421 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1424 ////////////////////////////////////////////////////////////////////
1425 // Initialize the local time subsystem.
1426 ////////////////////////////////////////////////////////////////////
1428 // update the current timezone each 30 minutes
1429 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1433 ////////////////////////////////////////////////////////////////////
1434 // Initialize the weather subsystem.
1435 ////////////////////////////////////////////////////////////////////
1437 // Initialize the weather modeling subsystem
1439 // Initialize the WeatherDatabase
1440 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1442 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1443 current_aircraft.fdm_state->get_Longitude(),
1444 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1445 double init_vis = fgGetDouble("/environment/visibility-m");
1447 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1449 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1451 working_type = FGLocalWeatherDatabase::use_internet;
1453 working_type = FGLocalWeatherDatabase::default_mode;
1456 if ( init_vis > 0 ) {
1457 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1458 new FGLocalWeatherDatabase( position,
1459 globals->get_fg_root(),
1463 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1464 new FGLocalWeatherDatabase( position,
1465 globals->get_fg_root(),
1469 // cout << theFGLocalWeatherDatabase << endl;
1470 // cout << "visibility = "
1471 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1473 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1475 // register the periodic update of the weather
1476 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1479 globals->add_subsystem("environment", new FGEnvironmentMgr);
1482 #ifdef FG_USE_CLOUDS_3D
1483 ////////////////////////////////////////////////////////////////////
1484 // Initialize the 3D cloud subsystem.
1485 ////////////////////////////////////////////////////////////////////
1486 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1487 static const SGPropertyNode *longitude
1488 = fgGetNode("/sim/presets/longitude-deg");
1489 static const SGPropertyNode *latitude
1490 = fgGetNode("/sim/presets/latitude-deg");
1491 static const SGPropertyNode *altitude
1492 = fgGetNode("/sim/presets/altitude-ft");
1494 SGPath cloud_path(globals->get_fg_root());
1495 cloud_path.append("large.sky");
1496 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1497 if ( !sgCloud3d->Load( cloud_path.str(),
1498 latitude->getDoubleValue(),
1499 longitude->getDoubleValue()) )
1501 fgSetBool("/sim/rendering/clouds3d", false);
1502 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1504 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1508 ////////////////////////////////////////////////////////////////////
1509 // Initialise ATC display system
1510 ////////////////////////////////////////////////////////////////////
1512 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1513 globals->set_ATC_display(new FGATCDisplay);
1514 globals->get_ATC_display()->init();
1516 ////////////////////////////////////////////////////////////////////
1517 // Initialise the ATC Manager
1518 ////////////////////////////////////////////////////////////////////
1520 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1521 globals->set_ATC_mgr(new FGATCMgr);
1522 globals->get_ATC_mgr()->init();
1524 ////////////////////////////////////////////////////////////////////
1525 // Initialise the AI Manager
1526 ////////////////////////////////////////////////////////////////////
1528 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1529 globals->set_AI_mgr(new FGAIMgr);
1530 globals->get_AI_mgr()->init();
1533 #ifdef ENABLE_AUDIO_SUPPORT
1534 ////////////////////////////////////////////////////////////////////
1535 // Initialize the sound subsystem.
1536 ////////////////////////////////////////////////////////////////////
1538 globals->set_soundmgr(new SGSoundMgr);
1539 globals->get_soundmgr()->init();
1540 globals->get_soundmgr()->bind();
1543 ////////////////////////////////////////////////////////////////////
1544 // Initialize the sound-effects subsystem.
1545 ////////////////////////////////////////////////////////////////////
1547 globals->add_subsystem("fx", new FGFX);
1551 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1552 globals->add_subsystem("systems", new FGSystemMgr);
1554 ////////////////////////////////////////////////////////////////////
1555 // Initialize the radio stack subsystem.
1556 ////////////////////////////////////////////////////////////////////
1558 current_radiostack = new FGRadioStack;
1559 current_radiostack->init();
1560 current_radiostack->bind();
1563 ////////////////////////////////////////////////////////////////////
1564 // Initialize the cockpit subsystem
1565 ////////////////////////////////////////////////////////////////////
1567 if( fgCockpitInit( ¤t_aircraft )) {
1568 // Cockpit initialized ok.
1570 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1575 ////////////////////////////////////////////////////////////////////
1576 // Initialize the autopilot subsystem.
1577 ////////////////////////////////////////////////////////////////////
1579 globals->set_autopilot(new FGAutopilot);
1580 globals->get_autopilot()->init();
1581 globals->get_autopilot()->bind();
1583 // FIXME: these should go in the
1584 // GUI initialization code, not here.
1586 NewTgtAirportInit();
1590 ////////////////////////////////////////////////////////////////////
1591 // Initialize I/O subsystem.
1592 ////////////////////////////////////////////////////////////////////
1594 globals->get_io()->init();
1595 globals->get_io()->bind();
1598 ////////////////////////////////////////////////////////////////////
1599 // Add a new 2D panel.
1600 ////////////////////////////////////////////////////////////////////
1602 string panel_path = fgGetString("/sim/panel/path",
1603 "Panels/Default/default.xml");
1605 globals->set_current_panel( fgReadPanel(panel_path) );
1606 if (globals->get_current_panel() == 0) {
1607 SG_LOG( SG_INPUT, SG_ALERT,
1608 "Error reading new panel from " << panel_path );
1610 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1611 globals->get_current_panel()->init();
1612 globals->get_current_panel()->bind();
1616 ////////////////////////////////////////////////////////////////////
1617 // Initialize the default (kludged) properties.
1618 ////////////////////////////////////////////////////////////////////
1623 ////////////////////////////////////////////////////////////////////
1624 // Initialize the controls subsystem.
1625 ////////////////////////////////////////////////////////////////////
1627 globals->get_controls()->init();
1628 globals->get_controls()->bind();
1631 ////////////////////////////////////////////////////////////////////
1632 // Initialize the input subsystem.
1633 ////////////////////////////////////////////////////////////////////
1635 globals->add_subsystem("input", new FGInput);
1638 ////////////////////////////////////////////////////////////////////
1639 // Initialize the replay subsystem
1640 ////////////////////////////////////////////////////////////////////
1641 globals->add_subsystem("replay", new FGReplay);
1643 ////////////////////////////////////////////////////////////////////
1644 // Bind and initialize subsystems.
1645 ////////////////////////////////////////////////////////////////////
1647 globals->get_subsystem_mgr()->bind();
1648 globals->get_subsystem_mgr()->init();
1651 #ifdef FG_MPLAYER_AS
1652 ////////////////////////////////////////////////////////////////////
1653 // Initialize multiplayer subsystem
1654 ////////////////////////////////////////////////////////////////////
1656 globals->set_multiplayer_tx_mgr(new FGMultiplayTxMgr);
1657 globals->get_multiplayer_tx_mgr()->init();
1659 globals->set_multiplayer_rx_mgr(new FGMultiplayRxMgr);
1660 globals->get_multiplayer_rx_mgr()->init();
1663 ////////////////////////////////////////////////////////////////////////
1664 // End of subsystem initialization.
1665 ////////////////////////////////////////////////////////////////////
1667 SG_LOG( SG_GENERAL, SG_INFO, endl);
1669 // Save the initial state for future
1671 globals->saveInitialState();
1677 void fgReInitSubsystems()
1679 // static const SGPropertyNode *longitude
1680 // = fgGetNode("/sim/presets/longitude-deg");
1681 // static const SGPropertyNode *latitude
1682 // = fgGetNode("/sim/presets/latitude-deg");
1683 static const SGPropertyNode *altitude
1684 = fgGetNode("/sim/presets/altitude-ft");
1685 static const SGPropertyNode *master_freeze
1686 = fgGetNode("/sim/freeze/master");
1688 SG_LOG( SG_GENERAL, SG_INFO,
1689 "fgReInitSubsystems(): /position/altitude = "
1690 << altitude->getDoubleValue() );
1692 bool freeze = master_freeze->getBoolValue();
1694 fgSetBool("/sim/freeze/master", true);
1697 // Initialize the FDM
1700 // allocates structures so must happen before any of the flight
1701 // model or control parameters are set
1702 fgAircraftInit(); // In the future this might not be the case.
1704 // reload offsets from config defaults
1705 globals->get_viewmgr()->reinit();
1709 globals->get_controls()->reset_all();
1710 globals->get_autopilot()->reset();
1714 cur_light_params.Update();
1715 fgUpdateLocalTime();
1718 fgSetBool("/sim/freeze/master", false);