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/sky/clouds3d/SkySceneLoader.hpp>
69 # include <simgear/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;
703 while ( oaz >= 360.0 ) { oaz -= 360.0; }
704 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
710 fgSetDouble("/sim/presets/longitude-deg", lon2 );
711 fgSetDouble("/sim/presets/latitude-deg", lat2 );
712 fgSetDouble("/sim/presets/heading-deg", heading );
714 // other code depends on the actual values being set ...
715 fgSetDouble("/position/longitude-deg", lon2 );
716 fgSetDouble("/position/latitude-deg", lat2 );
717 fgSetDouble("/orientation/heading-deg", heading );
719 SG_LOG( SG_GENERAL, SG_INFO,
720 "Position for " << id << " is ("
722 << lat2 << ") new heading is "
729 // Set current_options lon/lat given an airport id and runway number
730 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
734 // set initial position from airport and runway number
736 SGPath path( globals->get_fg_root() );
737 path.append( "Airports" );
738 path.append( "runways.mk4" );
739 FGRunways runways( path.c_str() );
741 SG_LOG( SG_GENERAL, SG_INFO,
742 "Attempting to set starting position for "
743 << id << ":" << rwy );
745 if ( ! runways.search( id, rwy, &r ) ) {
746 SG_LOG( SG_GENERAL, SG_ALERT,
747 "Failed to find runway " << rwy <<
748 " at airport " << id );
755 double lat2, lon2, az2;
756 double heading = r.heading;
757 double azimuth = heading + 180.0;
758 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
760 SG_LOG( SG_GENERAL, SG_INFO,
761 "runway = " << r.lon << ", " << r.lat
762 << " length = " << r.length * SG_FEET_TO_METER
763 << " heading = " << azimuth );
765 geo_direct_wgs_84 ( 0, r.lat, r.lon,
767 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
768 &lat2, &lon2, &az2 );
770 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
773 double odist = fgGetDouble("/sim/presets/offset-distance");
774 odist *= SG_NM_TO_METER;
775 double oaz = azimuth;
776 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
778 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
780 while ( oaz >= 360.0 ) { oaz -= 360.0; }
781 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
787 fgSetDouble("/sim/presets/longitude-deg", lon2 );
788 fgSetDouble("/sim/presets/latitude-deg", lat2 );
789 fgSetDouble("/sim/presets/heading-deg", heading );
791 // other code depends on the actual values being set ...
792 fgSetDouble("/position/longitude-deg", lon2 );
793 fgSetDouble("/position/latitude-deg", lat2 );
794 fgSetDouble("/orientation/heading-deg", heading );
796 SG_LOG( SG_GENERAL, SG_INFO,
797 "Position for " << id << " is ("
799 << lat2 << ") new heading is "
806 static void fgSetDistOrAltFromGlideSlope() {
807 string apt_id = fgGetString("/sim/presets/airport-id");
808 double gs = fgGetDouble("/sim/presets/glideslope-deg")
809 * SG_DEGREES_TO_RADIANS ;
810 double od = fgGetDouble("/sim/presets/offset-distance");
811 double alt = fgGetDouble("/sim/presets/altitude-ft");
813 double apt_elev = 0.0;
814 if ( ! apt_id.empty() ) {
815 apt_elev = fgGetAirportElev( apt_id );
816 if ( apt_elev < -9990.0 ) {
823 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
824 // set altitude from glideslope and offset-distance
825 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
826 alt = fabs(od*tan(gs)) + apt_elev;
827 fgSetDouble("/sim/presets/altitude-ft", alt);
828 fgSetBool("/sim/presets/onground", false);
829 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
831 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
832 // set offset-distance from glideslope and altitude
833 od = (alt - apt_elev) / tan(gs);
834 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
835 fgSetDouble("/sim/presets/offset-distance", od);
836 fgSetBool("/sim/presets/onground", false);
837 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
839 } else if( fabs(gs) > 0.01 ) {
840 SG_LOG( SG_GENERAL, SG_ALERT,
841 "Glideslope given but not altitude or offset-distance." );
842 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
843 fgSetDouble("/sim/presets/glideslope-deg", 0);
844 fgSetBool("/sim/presets/onground", true);
849 // Set current_options lon/lat given an airport id and heading (degrees)
850 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
851 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
853 // set initial position from runway and heading
855 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
856 << id << ":" << freq );
858 double lon = nav->get_lon();
859 double lat = nav->get_lat();
861 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
863 double odist = fgGetDouble("/sim/presets/offset-distance")
865 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
867 while ( oaz >= 360.0 ) { oaz -= 360.0; }
868 double olat, olon, az2;
869 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
876 fgSetDouble("/sim/presets/longitude-deg", lon );
877 fgSetDouble("/sim/presets/latitude-deg", lat );
879 // other code depends on the actual values being set ...
880 fgSetDouble("/position/longitude-deg", lon );
881 fgSetDouble("/position/latitude-deg", lat );
882 fgSetDouble("/orientation/heading-deg",
883 fgGetDouble("/sim/presets/heading-deg") );
885 SG_LOG( SG_GENERAL, SG_INFO,
886 "Position for " << id << ":" << freq << " is ("
887 << lon << ", "<< lat << ")" );
891 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
892 << id << ":" << freq );
898 // Set current_options lon/lat given an airport id and heading (degrees)
899 static bool fgSetPosFromFix( const string& id ) {
902 // set initial position from runway and heading
903 if ( current_fixlist->query( id.c_str(), &fix ) ) {
904 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
907 double lon = fix.get_lon();
908 double lat = fix.get_lat();
910 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
912 double odist = fgGetDouble("/sim/presets/offset-distance")
914 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
916 while ( oaz >= 360.0 ) { oaz -= 360.0; }
917 double olat, olon, az2;
918 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
925 fgSetDouble("/sim/presets/longitude-deg", lon );
926 fgSetDouble("/sim/presets/latitude-deg", lat );
928 // other code depends on the actual values being set ...
929 fgSetDouble("/position/longitude-deg", lon );
930 fgSetDouble("/position/latitude-deg", lat );
931 fgSetDouble("/orientation/heading-deg",
932 fgGetDouble("/sim/presets/heading-deg") );
934 SG_LOG( SG_GENERAL, SG_INFO,
935 "Position for " << id << " is ("
936 << lon << ", "<< lat << ")" );
940 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
948 * Initialize vor/ndb/ils/fix list management and query systems
953 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
955 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
956 current_navlist = new FGNavList;
957 SGPath p_nav( globals->get_fg_root() );
958 p_nav.append( "Navaids/default.nav" );
959 current_navlist->init( p_nav );
961 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
962 current_beacons = new FGMarkerBeacons;
963 current_beacons->init();
964 current_ilslist = new FGILSList;
965 SGPath p_ils( globals->get_fg_root() );
966 p_ils.append( "Navaids/default.ils" );
967 current_ilslist->init( p_ils );
969 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
970 current_fixlist = new FGFixList;
971 SGPath p_fix( globals->get_fg_root() );
972 p_fix.append( "Navaids/default.fix" );
973 current_fixlist->init( p_fix );
979 // Set the initial position based on presets (or defaults)
980 bool fgInitPosition() {
981 bool set_pos = false;
983 // If glideslope is specified, then calculate offset-distance or
984 // altitude relative to glide slope if either of those was not
986 if ( fgGetDouble("/sim/presets/glideslope-deg") > 0.1 ) {
987 fgSetDistOrAltFromGlideSlope();
990 // Select ground or air start depending on if an altitude is
991 // specified (this choice can be refined later based on other
993 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
994 fgSetBool("/sim/presets/onground", false);
996 fgSetBool("/sim/presets/onground", true);
999 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1000 // If not, check for an airport-id and use that.
1001 // If not, default to the middle of the KSFO field.
1002 // The default values for lon/lat are deliberately out of range
1003 // so that the airport-id can take effect; valid lon/lat will
1004 // override airport-id, however.
1005 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1006 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1007 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1008 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1013 string apt = fgGetString("/sim/presets/airport-id");
1014 string rwy_no = fgGetString("/sim/presets/runway");
1015 double hdg = fgGetDouble("/sim/presets/heading-deg");
1016 string vor = fgGetString("/sim/presets/vor-id");
1017 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1018 string ndb = fgGetString("/sim/presets/ndb-id");
1019 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1020 string fix = fgGetString("/sim/presets/fix");
1021 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1022 // An airport + runway is requested
1023 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1024 // set position (a little off the heading for single
1026 fgSetTowerPosFromAirportID( apt, hdg );
1031 if ( !set_pos && !apt.empty() ) {
1032 // An airport is requested (find runway closest to hdg)
1034 if (fgGetDouble("/sim/presets/altitude-ft") <= 0 &&
1035 fgGetDouble("/sim/presets/offset-distance") == 0)
1036 ok = fgSetPosFromAirportIDandHdg( apt, hdg );
1038 ok = fgSetPosFromAirportID( apt );
1041 // set position (a little off the heading for single
1043 fgSetTowerPosFromAirportID( apt, hdg );
1048 if ( !set_pos && !vor.empty() ) {
1049 // a VOR is requested
1050 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1054 if ( !set_pos && !ndb.empty() ) {
1055 // an NDB is requested
1056 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1060 if ( !set_pos && !fix.empty() ) {
1061 // a Fix is requested
1062 if ( fgSetPosFromFix( fix ) ) {
1068 // No lon/lat specified, no airport specified, default to
1069 // middle of KSFO field.
1070 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1071 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1074 fgSetDouble( "/position/longitude-deg",
1075 fgGetDouble("/sim/presets/longitude-deg") );
1076 fgSetDouble( "/position/latitude-deg",
1077 fgGetDouble("/sim/presets/latitude-deg") );
1078 fgSetDouble( "/orientation/heading-deg",
1079 fgGetDouble("/sim/presets/heading-deg") );
1085 // General house keeping initializations
1086 bool fgInitGeneral() {
1089 #if defined(FX) && defined(XMESA)
1090 char *mesa_win_state;
1093 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1094 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1096 root = globals->get_fg_root();
1097 if ( ! root.length() ) {
1098 // No root path set? Then bail ...
1099 SG_LOG( SG_GENERAL, SG_ALERT,
1100 "Cannot continue without a path to the base package "
1101 << "being defined." );
1104 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1106 #if defined(FX) && defined(XMESA)
1107 // initialize full screen flag
1108 globals->set_fullscreen(false);
1109 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1110 // Test for the MESA_GLX_FX env variable
1111 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1112 // test if we are fullscreen mesa/glide
1113 if ( (mesa_win_state[0] == 'f') ||
1114 (mesa_win_state[0] == 'F') ) {
1115 globals->set_fullscreen(true);
1125 // Initialize the flight model subsystem. This just creates the
1126 // object. The actual fdm initialization is delayed until we get a
1127 // proper scenery elevation hit. This is checked for in main.cxx
1131 if ( cur_fdm_state ) {
1132 delete cur_fdm_state;
1136 double dt = 1.0 / fgGetInt("/sim/model-hz");
1137 aircraft_dir = fgGetString("/sim/aircraft-dir");
1138 const string &model = fgGetString("/sim/flight-model");
1141 if ( model == "larcsim" ) {
1142 cur_fdm_state = new FGLaRCsim( dt );
1143 } else if ( model == "jsb" ) {
1144 cur_fdm_state = new FGJSBsim( dt );
1145 } else if ( model == "ada" ) {
1146 cur_fdm_state = new FGADA( dt );
1147 } else if ( model == "balloon" ) {
1148 cur_fdm_state = new FGBalloonSim( dt );
1149 } else if ( model == "magic" ) {
1150 cur_fdm_state = new FGMagicCarpet( dt );
1151 } else if ( model == "ufo" ) {
1152 cur_fdm_state = new FGUFO( dt );
1153 } else if ( model == "external" ) {
1154 // external is a synonym for "--fdm=null" and is
1155 // maintained here for backwards compatibility
1156 cur_fdm_state = new FGNullFDM( dt );
1157 } else if ( model.find("network") == 0 ) {
1158 string host = "localhost";
1162 string net_options = model.substr(8);
1163 string::size_type begin, end;
1166 end = net_options.find( ",", begin );
1167 if ( end != string::npos ) {
1168 host = net_options.substr(begin, end - begin);
1172 end = net_options.find( ",", begin );
1173 if ( end != string::npos ) {
1174 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1178 end = net_options.find( ",", begin );
1179 if ( end != string::npos ) {
1180 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1184 end = net_options.find( ",", begin );
1185 if ( end != string::npos ) {
1186 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1189 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1190 } else if ( model.find("pipe") == 0 ) {
1191 string pipe_path = model.substr(5);
1192 cur_fdm_state = new FGExternalPipe( dt, pipe_path );
1193 } else if ( model == "null" ) {
1194 cur_fdm_state = new FGNullFDM( dt );
1195 } else if ( model == "yasim" ) {
1196 cur_fdm_state = new YASim( dt );
1198 SG_LOG(SG_GENERAL, SG_ALERT,
1199 "Unrecognized flight model '" << model
1200 << "', cannot init flight dynamics model.");
1204 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1209 static void printMat(const sgVec4 *mat, char *name="")
1212 SG_LOG(SG_GENERAL, SG_BULK, name );
1213 for(i=0; i<4; i++) {
1214 SG_LOG(SG_GENERAL, SG_BULK, " " << mat[i][0] << " " << mat[i][1]
1215 << " " << mat[i][2] << " " << mat[i][3] );
1219 // Initialize view parameters
1221 // force update of model so that viewer can get some data...
1222 globals->get_aircraft_model()->update(0);
1223 // run update for current view so that data is current...
1224 globals->get_viewmgr()->update(0);
1226 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1227 printMat(globals->get_current_view()->get_UP(),"UP");
1228 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1233 SGTime *fgInitTime() {
1235 static const SGPropertyNode *longitude
1236 = fgGetNode("/position/longitude-deg");
1237 static const SGPropertyNode *latitude
1238 = fgGetNode("/position/latitude-deg");
1239 static const SGPropertyNode *cur_time_override
1240 = fgGetNode("/sim/time/cur-time-override", true);
1242 SGPath zone( globals->get_fg_root() );
1243 zone.append( "Timezone" );
1244 SGTime *t = new SGTime( longitude->getDoubleValue()
1245 * SGD_DEGREES_TO_RADIANS,
1246 latitude->getDoubleValue()
1247 * SGD_DEGREES_TO_RADIANS,
1249 cur_time_override->getLongValue() );
1251 // Handle potential user specified time offsets
1252 time_t cur_time = t->get_cur_time();
1253 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1254 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1255 time_t aircraftLocalTime =
1256 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1258 // Okay, we now have six possible scenarios
1259 int offset = fgGetInt("/sim/startup/time-offset");
1260 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1261 if (offset_type == "system-offset") {
1262 globals->set_warp( offset );
1263 } else if (offset_type == "gmt-offset") {
1264 globals->set_warp( offset - (currGMT - systemLocalTime) );
1265 } else if (offset_type == "latitude-offset") {
1266 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1267 } else if (offset_type == "system") {
1268 globals->set_warp( offset - cur_time );
1269 } else if (offset_type == "gmt") {
1270 globals->set_warp( offset - currGMT );
1271 } else if (offset_type == "latitude") {
1272 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1275 SG_LOG( SG_GENERAL, SG_ALERT,
1276 "FG_TIME::Unsupported offset type " << offset_type );
1280 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1281 << globals->get_warp() );
1283 globals->set_warp_delta( 0 );
1285 t->update( 0.0, 0.0,
1286 cur_time_override->getLongValue(),
1287 globals->get_warp() );
1293 // This is the top level init routine which calls all the other
1294 // initialization routines. If you are adding a subsystem to flight
1295 // gear, its initialization call should located in this routine.
1296 // Returns non-zero if a problem encountered.
1297 bool fgInitSubsystems() {
1298 // static const SGPropertyNode *longitude
1299 // = fgGetNode("/sim/presets/longitude-deg");
1300 // static const SGPropertyNode *latitude
1301 // = fgGetNode("/sim/presets/latitude-deg");
1302 // static const SGPropertyNode *altitude
1303 // = fgGetNode("/sim/presets/altitude-ft");
1305 fgLIGHT *l = &cur_light_params;
1307 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1308 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1311 ////////////////////////////////////////////////////////////////////
1312 // Initialize the material property subsystem.
1313 ////////////////////////////////////////////////////////////////////
1315 SGPath mpath( globals->get_fg_root() );
1316 mpath.append( "materials.xml" );
1317 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str()) ) {
1318 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1322 ////////////////////////////////////////////////////////////////////
1323 // Initialize the event manager subsystem.
1324 ////////////////////////////////////////////////////////////////////
1326 global_events.init();
1328 // Output event stats every 60 seconds
1329 global_events.Register( "FGEventMgr::print_stats()",
1330 &global_events, &FGEventMgr::print_stats,
1334 ////////////////////////////////////////////////////////////////////
1335 // Initialize the scenery management subsystem.
1336 ////////////////////////////////////////////////////////////////////
1338 if ( globals->get_tile_mgr()->init() ) {
1339 // Load the local scenery data
1340 double visibility_meters = fgGetDouble("/environment/visibility-m");
1342 globals->get_tile_mgr()->update( visibility_meters );
1344 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1348 // cause refresh of viewer scenery timestamps every 15 seconds...
1349 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1350 globals->get_tile_mgr(),
1351 &FGTileMgr::refresh_view_timestamps,
1354 SG_LOG( SG_GENERAL, SG_DEBUG,
1355 "Current terrain elevation after tile mgr init " <<
1356 globals->get_scenery()->get_cur_elev() );
1359 ////////////////////////////////////////////////////////////////////
1360 // Initialize the flight model subsystem.
1361 ////////////////////////////////////////////////////////////////////
1365 // allocates structures so must happen before any of the flight
1366 // model or control parameters are set
1367 fgAircraftInit(); // In the future this might not be the case.
1370 ////////////////////////////////////////////////////////////////////
1371 // Initialize the view manager subsystem.
1372 ////////////////////////////////////////////////////////////////////
1377 ////////////////////////////////////////////////////////////////////
1378 // Initialize the lighting subsystem.
1379 ////////////////////////////////////////////////////////////////////
1381 // fgUpdateSunPos() needs a few position and view parameters set
1382 // so it can calculate local relative sun angle and a few other
1383 // things for correctly orienting the sky.
1386 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1388 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1391 // Initialize Lighting interpolation tables
1394 // force one lighting update to make it right to start with...
1396 // update the lighting parameters (based on sun angle)
1397 global_events.Register( "fgLight::Update()",
1398 &cur_light_params, &fgLIGHT::Update,
1402 ////////////////////////////////////////////////////////////////////
1403 // Create and register the logger.
1404 ////////////////////////////////////////////////////////////////////
1406 globals->add_subsystem("logger", new FGLogger);
1409 #if defined(HAVE_PLIB_PSL)
1410 ////////////////////////////////////////////////////////////////////
1411 // Create and register the script manager.
1412 ////////////////////////////////////////////////////////////////////
1414 globals->add_subsystem("scripting", new FGScriptMgr);
1415 #endif // HAVE_PLIB_PSL
1418 ////////////////////////////////////////////////////////////////////
1419 // Create and register the XML GUI.
1420 ////////////////////////////////////////////////////////////////////
1422 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1425 ////////////////////////////////////////////////////////////////////
1426 // Initialize the local time subsystem.
1427 ////////////////////////////////////////////////////////////////////
1429 // update the current timezone each 30 minutes
1430 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1434 ////////////////////////////////////////////////////////////////////
1435 // Initialize the weather subsystem.
1436 ////////////////////////////////////////////////////////////////////
1438 // Initialize the weather modeling subsystem
1440 // Initialize the WeatherDatabase
1441 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1443 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1444 current_aircraft.fdm_state->get_Longitude(),
1445 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1446 double init_vis = fgGetDouble("/environment/visibility-m");
1448 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1450 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1452 working_type = FGLocalWeatherDatabase::use_internet;
1454 working_type = FGLocalWeatherDatabase::default_mode;
1457 if ( init_vis > 0 ) {
1458 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1459 new FGLocalWeatherDatabase( position,
1460 globals->get_fg_root(),
1464 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1465 new FGLocalWeatherDatabase( position,
1466 globals->get_fg_root(),
1470 // cout << theFGLocalWeatherDatabase << endl;
1471 // cout << "visibility = "
1472 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1474 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1476 // register the periodic update of the weather
1477 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1480 globals->add_subsystem("environment", new FGEnvironmentMgr);
1483 #ifdef FG_USE_CLOUDS_3D
1484 ////////////////////////////////////////////////////////////////////
1485 // Initialize the 3D cloud subsystem.
1486 ////////////////////////////////////////////////////////////////////
1487 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1488 SGPath cloud_path(globals->get_fg_root());
1489 cloud_path.append("large.sky");
1490 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1491 if ( !sgCloud3d->Load( cloud_path.str(),
1492 latitude->getDoubleValue(),
1493 longitude->getDoubleValue()) )
1495 fgSetBool("/sim/rendering/clouds3d", false);
1496 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1498 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1502 ////////////////////////////////////////////////////////////////////
1503 // Initialise ATC display system
1504 ////////////////////////////////////////////////////////////////////
1506 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1507 globals->set_ATC_display(new FGATCDisplay);
1508 globals->get_ATC_display()->init();
1510 ////////////////////////////////////////////////////////////////////
1511 // Initialise the ATC Manager
1512 ////////////////////////////////////////////////////////////////////
1514 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1515 globals->set_ATC_mgr(new FGATCMgr);
1516 globals->get_ATC_mgr()->init();
1518 ////////////////////////////////////////////////////////////////////
1519 // Initialise the AI Manager
1520 ////////////////////////////////////////////////////////////////////
1522 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1523 globals->set_AI_mgr(new FGAIMgr);
1524 globals->get_AI_mgr()->init();
1527 #ifdef ENABLE_AUDIO_SUPPORT
1528 ////////////////////////////////////////////////////////////////////
1529 // Initialize the sound subsystem.
1530 ////////////////////////////////////////////////////////////////////
1532 globals->set_soundmgr(new SGSoundMgr);
1533 globals->get_soundmgr()->init();
1534 globals->get_soundmgr()->bind();
1537 ////////////////////////////////////////////////////////////////////
1538 // Initialize the sound-effects subsystem.
1539 ////////////////////////////////////////////////////////////////////
1541 globals->add_subsystem("fx", new FGFX);
1545 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1546 globals->add_subsystem("systems", new FGSystemMgr);
1548 ////////////////////////////////////////////////////////////////////
1549 // Initialize the radio stack subsystem.
1550 ////////////////////////////////////////////////////////////////////
1552 current_radiostack = new FGRadioStack;
1553 current_radiostack->init();
1554 current_radiostack->bind();
1557 ////////////////////////////////////////////////////////////////////
1558 // Initialize the cockpit subsystem
1559 ////////////////////////////////////////////////////////////////////
1561 if( fgCockpitInit( ¤t_aircraft )) {
1562 // Cockpit initialized ok.
1564 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1569 ////////////////////////////////////////////////////////////////////
1570 // Initialize the autopilot subsystem.
1571 ////////////////////////////////////////////////////////////////////
1573 globals->set_autopilot(new FGAutopilot);
1574 globals->get_autopilot()->init();
1575 globals->get_autopilot()->bind();
1577 // FIXME: these should go in the
1578 // GUI initialization code, not here.
1580 NewTgtAirportInit();
1584 ////////////////////////////////////////////////////////////////////
1585 // Initialize I/O subsystem.
1586 ////////////////////////////////////////////////////////////////////
1588 globals->get_io()->init();
1589 globals->get_io()->bind();
1592 ////////////////////////////////////////////////////////////////////
1593 // Add a new 2D panel.
1594 ////////////////////////////////////////////////////////////////////
1596 string panel_path = fgGetString("/sim/panel/path",
1597 "Panels/Default/default.xml");
1599 globals->set_current_panel( fgReadPanel(panel_path) );
1600 if (globals->get_current_panel() == 0) {
1601 SG_LOG( SG_INPUT, SG_ALERT,
1602 "Error reading new panel from " << panel_path );
1604 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1605 globals->get_current_panel()->init();
1606 globals->get_current_panel()->bind();
1610 ////////////////////////////////////////////////////////////////////
1611 // Initialize the default (kludged) properties.
1612 ////////////////////////////////////////////////////////////////////
1617 ////////////////////////////////////////////////////////////////////
1618 // Initialize the controls subsystem.
1619 ////////////////////////////////////////////////////////////////////
1621 globals->get_controls()->init();
1622 globals->get_controls()->bind();
1625 ////////////////////////////////////////////////////////////////////
1626 // Initialize the input subsystem.
1627 ////////////////////////////////////////////////////////////////////
1629 globals->add_subsystem("input", new FGInput);
1632 ////////////////////////////////////////////////////////////////////
1633 // Bind and initialize subsystems.
1634 ////////////////////////////////////////////////////////////////////
1636 globals->get_subsystem_mgr()->bind();
1637 globals->get_subsystem_mgr()->init();
1640 #ifdef FG_MPLAYER_AS
1641 ////////////////////////////////////////////////////////////////////
1642 // Initialize multiplayer subsystem
1643 ////////////////////////////////////////////////////////////////////
1645 globals->set_multiplayer_tx_mgr(new FGMultiplayTxMgr);
1646 globals->get_multiplayer_tx_mgr()->init();
1648 globals->set_multiplayer_rx_mgr(new FGMultiplayRxMgr);
1649 globals->get_multiplayer_rx_mgr()->init();
1652 ////////////////////////////////////////////////////////////////////////
1653 // End of subsystem initialization.
1654 ////////////////////////////////////////////////////////////////////
1656 SG_LOG( SG_GENERAL, SG_INFO, endl);
1658 // Save the initial state for future
1660 globals->saveInitialState();
1666 void fgReInitSubsystems()
1668 // static const SGPropertyNode *longitude
1669 // = fgGetNode("/sim/presets/longitude-deg");
1670 // static const SGPropertyNode *latitude
1671 // = fgGetNode("/sim/presets/latitude-deg");
1672 static const SGPropertyNode *altitude
1673 = fgGetNode("/sim/presets/altitude-ft");
1674 static const SGPropertyNode *master_freeze
1675 = fgGetNode("/sim/freeze/master");
1677 SG_LOG( SG_GENERAL, SG_INFO,
1678 "fgReInitSubsystems(): /position/altitude = "
1679 << altitude->getDoubleValue() );
1681 bool freeze = master_freeze->getBoolValue();
1683 fgSetBool("/sim/freeze/master", true);
1686 // Initialize the FDM
1689 // allocates structures so must happen before any of the flight
1690 // model or control parameters are set
1691 fgAircraftInit(); // In the future this might not be the case.
1693 // reload offsets from config defaults
1694 globals->get_viewmgr()->reinit();
1698 globals->get_controls()->reset_all();
1699 globals->get_autopilot()->reset();
1703 cur_light_params.Update();
1704 fgUpdateLocalTime();
1707 fgSetBool("/sim/freeze/master", false);