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/sky/clouds3d/SkySceneLoader.hpp>
67 #include <simgear/sky/clouds3d/SkyUtil.hpp>
68 #include <simgear/timing/sg_time.hxx>
69 #include <simgear/timing/lowleveltime.h>
71 #include <Aircraft/aircraft.hxx>
72 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
73 #include <Airports/runways.hxx>
74 #include <Airports/simple.hxx>
75 #include <ATC/ATCdisplay.hxx>
76 #include <ATC/ATCmgr.hxx>
77 #include <ATC/atislist.hxx>
78 #include <ATC/towerlist.hxx>
79 #include <ATC/approachlist.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/steam.hxx>
86 #include <Cockpit/panel.hxx>
87 #include <Cockpit/panel_io.hxx>
88 #include <FDM/ADA.hxx>
89 #include <FDM/Balloon.h>
90 #include <FDM/ExternalNet/ExternalNet.hxx>
91 #include <FDM/JSBSim/JSBSim.hxx>
92 #include <FDM/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 <Joystick/joystick.hxx>
102 #include <Objects/matlib.hxx>
103 #include <Model/acmodel.hxx>
104 #include <Navaids/fixlist.hxx>
105 #include <Navaids/ilslist.hxx>
106 #include <Navaids/mkrbeacons.hxx>
107 #include <Navaids/navlist.hxx>
108 #include <Scenery/scenery.hxx>
109 #include <Scenery/tilemgr.hxx>
110 #include <Sound/fg_fx.hxx>
111 #include <Sound/soundmgr.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 <WeatherCM/FGLocalWeatherDatabase.h>
122 # include <Environment/environment_mgr.hxx>
125 #include "fg_init.hxx"
127 #include "fg_commands.hxx"
128 #include "fg_props.hxx"
129 #include "options.hxx"
130 #include "globals.hxx"
131 #include "logger.hxx"
132 #include "viewmgr.hxx"
134 #if defined(FX) && defined(XMESA)
135 #include <GL/xmesa.h>
138 SG_USING_STD(string);
140 extern const char *default_root;
142 SkySceneLoader *sgCloud3d;
145 // Scan the command line options for the specified option and return
147 static string fgScanForOption( const string& option, int argc, char **argv ) {
150 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
152 int len = option.length();
155 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
157 string arg = argv[i];
158 if ( arg.find( option ) == 0 ) {
159 return arg.substr( len );
169 // Scan the user config files for the specified option and return
171 static string fgScanForOption( const string& option, const string& path ) {
172 sg_gzifstream in( path );
173 if ( !in.is_open() ) {
177 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
179 int len = option.length();
183 while ( ! in.eof() ) {
186 while ( in.get(c) && c != '\0' ) {
191 #if defined( macintosh )
192 getline( in, line, '\r' );
194 getline( in, line, '\n' );
197 // catch extraneous (DOS) line ending character
198 if ( line[line.length() - 1] < 32 ) {
199 line = line.substr( 0, line.length()-1 );
202 if ( line.find( option ) == 0 ) {
203 return line.substr( len );
213 // Read in configuration (files and command line options) but only set
215 bool fgInitFGRoot ( int argc, char **argv ) {
219 // First parse command line options looking for --fg-root=, this
220 // will override anything specified in a config file
221 root = fgScanForOption( "--fg-root=", argc, argv);
223 #if defined( unix ) || defined( __CYGWIN__ )
224 // Next check home directory for .fgfsrc.hostname file
225 if ( root.empty() ) {
226 envp = ::getenv( "HOME" );
227 if ( envp != NULL ) {
228 SGPath config( envp );
229 config.append( ".fgfsrc" );
231 gethostname( name, 256 );
232 config.concat( "." );
233 config.concat( name );
234 root = fgScanForOption( "--fg-root=", config.str() );
239 // Next check home directory for .fgfsrc file
240 if ( root.empty() ) {
241 envp = ::getenv( "HOME" );
242 if ( envp != NULL ) {
243 SGPath config( envp );
244 config.append( ".fgfsrc" );
245 root = fgScanForOption( "--fg-root=", config.str() );
249 // Next check if fg-root is set as an env variable
250 if ( root.empty() ) {
251 envp = ::getenv( "FG_ROOT" );
252 if ( envp != NULL ) {
257 // Otherwise, default to a random compiled-in location if we can't
258 // find fg-root any other way.
259 if ( root.empty() ) {
260 #if defined( __CYGWIN__ )
261 root = "/FlightGear";
262 #elif defined( WIN32 )
263 root = "\\FlightGear";
264 #elif defined( macintosh )
271 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
272 globals->set_fg_root(root);
278 // Read in configuration (files and command line options) but only set
280 bool fgInitFGAircraft ( int argc, char **argv ) {
284 // First parse command line options looking for --aircraft=, this
285 // will override anything specified in a config file
286 aircraft = fgScanForOption( "--aircraft=", argc, argv );
288 #if defined( unix ) || defined( __CYGWIN__ )
289 // Next check home directory for .fgfsrc.hostname file
290 if ( aircraft.empty() ) {
291 envp = ::getenv( "HOME" );
292 if ( envp != NULL ) {
293 SGPath config( envp );
294 config.append( ".fgfsrc" );
296 gethostname( name, 256 );
297 config.concat( "." );
298 config.concat( name );
299 aircraft = fgScanForOption( "--aircraft=", config.str() );
304 // Next check home directory for .fgfsrc file
305 if ( aircraft.empty() ) {
306 envp = ::getenv( "HOME" );
307 if ( envp != NULL ) {
308 SGPath config( envp );
309 config.append( ".fgfsrc" );
310 aircraft = fgScanForOption( "--aircraft=", config.str() );
314 // if an aircraft was specified, set the property name
315 if ( !aircraft.empty() ) {
316 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
317 fgSetString("/sim/aircraft", aircraft.c_str() );
319 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
326 // Return the current base package version
327 string fgBasePackageVersion() {
328 SGPath base_path( globals->get_fg_root() );
329 base_path.append("version");
331 sg_gzifstream in( base_path.str() );
332 if ( !in.is_open() ) {
333 SGPath old_path( globals->get_fg_root() );
334 old_path.append( "Thanks" );
335 sg_gzifstream old( old_path.str() );
336 if ( !old.is_open() ) {
339 return "[old version]";
350 // Initialize the localization
351 SGPropertyNode *fgInitLocale(const char *language) {
352 SGPropertyNode *c_node = NULL, *d_node = NULL;
353 SGPropertyNode *intl = fgGetNode("/sim/intl");
355 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
357 // localization not defined
362 // Select the proper language from the list
364 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
365 for (unsigned int i = 0; i < locale.size(); i++) {
367 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
368 for (unsigned int j = 0; j < lang.size(); j++) {
370 if (!strcmp(lang[j]->getStringValue(), language)) {
379 d_node = intl->getChild("locale");
383 // Check for localized font
384 SGPropertyNode *font_n = c_node->getNode("font", true);
385 if ( !strcmp(font_n->getStringValue(), "") )
386 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
390 // Load the default strings
392 SGPath d_path( globals->get_fg_root() );
394 const char *d_path_str = d_node->getStringValue("strings");
396 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
400 d_path.append(d_path_str);
401 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
404 SGPropertyNode *strings = c_node->getNode("strings");
406 readProperties(d_path.str(), strings);
407 } catch (const sg_exception &e) {
408 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
413 // Load the language specific strings
415 if (c_node != d_node) {
416 SGPath c_path( globals->get_fg_root() );
418 const char *c_path_str = c_node->getStringValue("strings");
420 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
424 c_path.append(c_path_str);
425 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
429 readProperties(c_path.str(), strings);
430 } catch (const sg_exception &e) {
431 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
441 // Initialize the localization routines
442 bool fgDetectLanguage() {
443 char *language = ::getenv("LANG");
445 if (language == NULL) {
446 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
450 SGPropertyNode *locale = fgInitLocale(language);
452 cerr << "No internationalization settings specified in preferences.xml"
458 globals->set_locale( locale );
463 // Attempt to locate and parse the various non-XML config files in order
464 // from least precidence to greatest precidence
466 do_options (int argc, char ** argv)
468 // Check for $fg_root/system.fgfsrc
469 SGPath config( globals->get_fg_root() );
470 config.append( "system.fgfsrc" );
471 fgParseOptions(config.str());
473 #if defined( unix ) || defined( __CYGWIN__ )
475 // Check for $fg_root/system.fgfsrc.hostname
476 gethostname( name, 256 );
477 config.concat( "." );
478 config.concat( name );
479 fgParseOptions(config.str());
482 // Check for ~/.fgfsrc
483 char* envp = ::getenv( "HOME" );
484 if ( envp != NULL ) {
486 config.append( ".fgfsrc" );
487 fgParseOptions(config.str());
490 #if defined( unix ) || defined( __CYGWIN__ )
491 // Check for ~/.fgfsrc.hostname
492 gethostname( name, 256 );
493 config.concat( "." );
494 config.concat( name );
495 fgParseOptions(config.str());
498 // Parse remaining command line options
499 // These will override anything specified in a config file
500 fgParseArgs(argc, argv);
504 // Read in configuration (file and command line)
505 bool fgInitConfig ( int argc, char **argv ) {
507 // First, set some sane default values
510 // Read global preferences from $FG_ROOT/preferences.xml
511 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
512 fgLoadProps("preferences.xml", globals->get_props());
513 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
515 // Detect the required language as early as possible
516 if ( !fgDetectLanguage() ) {
520 // Scan user config files and command line for a specified aircraft.
521 fgInitFGAircraft(argc, argv);
523 string aircraft = fgGetString("/sim/aircraft", "");
524 if ( aircraft.size() > 0 ) {
525 SGPath aircraft_path(globals->get_fg_root());
526 aircraft_path.append("Aircraft");
527 aircraft_path.append(aircraft);
528 aircraft_path.concat("-set.xml");
529 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
530 << " from " << aircraft_path.str());
532 readProperties(aircraft_path.str(), globals->get_props());
533 } catch (const sg_exception &e) {
534 string message = "Error reading default aircraft: ";
535 message += e.getFormattedMessage();
536 SG_LOG(SG_INPUT, SG_ALERT, message);
540 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
543 // parse options after loading aircraft to ensure any user
544 // overrides of defaults are honored.
545 do_options(argc, argv);
551 // find basic airport location info from airport database
552 bool fgFindAirportID( const string& id, FGAirport *a ) {
554 SGPath path( globals->get_fg_root() );
555 path.append( "Airports" );
556 path.append( "simple.mk4" );
557 FGAirports airports( path.c_str() );
559 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
561 if ( ! airports.search( id, a ) ) {
562 SG_LOG( SG_GENERAL, SG_ALERT,
563 "Failed to find " << id << " in " << path.str() );
570 SG_LOG( SG_GENERAL, SG_INFO,
571 "Position for " << id << " is ("
572 << a->longitude << ", "
573 << a->latitude << ")" );
579 // Preset lon/lat given an airport id
580 static bool fgSetPosFromAirportID( const string& id ) {
584 SG_LOG( SG_GENERAL, SG_INFO,
585 "Attempting to set starting position from airport code " << id );
587 if ( fgFindAirportID( id, &a ) ) {
589 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
590 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
592 // other code depends on the actual postition being set so set
594 fgSetDouble("/position/longitude-deg", a.longitude );
595 fgSetDouble("/position/latitude-deg", a.latitude );
597 SG_LOG( SG_GENERAL, SG_INFO,
598 "Position for " << id << " is (" << a.longitude
599 << ", " << a.latitude << ")" );
610 // Set current tower position lon/lat given an airport id
611 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
613 // tower height hard coded for now...
614 float towerheight=50.0f;
616 // make a little off the heading for 1 runway airports...
617 float fudge_lon = fabs(sin(hdg)) * .003f;
618 float fudge_lat = .003f - fudge_lon;
620 if ( fgFindAirportID( id, &a ) ) {
621 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
622 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
623 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
632 // Set current_options lon/lat given an airport id and heading (degrees)
633 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
636 double found_dir = 0.0;
639 // set initial position from runway and heading
641 SGPath path( globals->get_fg_root() );
642 path.append( "Airports" );
643 path.append( "runways.mk4" );
644 FGRunways runways( path.c_str() );
646 SG_LOG( SG_GENERAL, SG_INFO,
647 "Attempting to set starting position from runway code "
648 << id << " heading " << tgt_hdg );
650 if ( ! runways.search( id, &r ) ) {
651 SG_LOG( SG_GENERAL, SG_ALERT,
652 "Failed to find " << id << " in database." );
657 double min_diff = 360.0;
659 while ( r.id == id ) {
661 diff = tgt_hdg - r.heading;
662 while ( diff < -180.0 ) { diff += 360.0; }
663 while ( diff > 180.0 ) { diff -= 360.0; }
665 SG_LOG( SG_GENERAL, SG_INFO,
666 "Runway " << r.rwy_no << " heading = " << r.heading <<
667 " diff = " << diff );
668 if ( diff < min_diff ) {
675 diff = tgt_hdg - r.heading - 180.0;
676 while ( diff < -180.0 ) { diff += 360.0; }
677 while ( diff > 180.0 ) { diff -= 360.0; }
679 SG_LOG( SG_GENERAL, SG_INFO,
680 "Runway -" << r.rwy_no << " heading = " <<
682 " diff = " << diff );
683 if ( diff < min_diff ) {
692 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
693 << " + " << found_dir );
699 double heading = found_r.heading + found_dir;
700 while ( heading >= 360.0 ) { heading -= 360.0; }
702 double lat2, lon2, az2;
703 double azimuth = found_r.heading + found_dir + 180.0;
704 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
706 SG_LOG( SG_GENERAL, SG_INFO,
707 "runway = " << found_r.lon << ", " << found_r.lat
708 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
709 << " heading = " << azimuth );
711 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
712 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
713 &lat2, &lon2, &az2 );
715 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
717 double odist = fgGetDouble("/sim/presets/offset-distance");
718 odist *= SG_NM_TO_METER;
719 double oaz = azimuth;
720 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
721 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
723 while ( oaz >= 360.0 ) { oaz -= 360.0; }
724 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
730 fgSetDouble("/sim/presets/longitude-deg", lon2 );
731 fgSetDouble("/sim/presets/latitude-deg", lat2 );
732 fgSetDouble("/sim/presets/heading-deg", heading );
734 // other code depends on the actual values being set ...
735 fgSetDouble("/position/longitude-deg", lon2 );
736 fgSetDouble("/position/latitude-deg", lat2 );
737 fgSetDouble("/orientation/heading-deg", heading );
739 SG_LOG( SG_GENERAL, SG_INFO,
740 "Position for " << id << " is ("
742 << lat2 << ") new heading is "
749 // Set current_options lon/lat given an airport id and heading (degrees)
750 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
753 double heading = 0.0;
757 // standardize input number
758 string tmp = rwy.substr(1, 1);
759 if ( tmp == "L" || tmp == "R" || tmp == "C" ) {
767 // set initial position from runway and heading
769 SGPath path( globals->get_fg_root() );
770 path.append( "Airports" );
771 path.append( "runways.mk4" );
772 FGRunways runways( path.c_str() );
774 SG_LOG( SG_GENERAL, SG_INFO,
775 "Attempting to set starting position for "
776 << id << ":" << runway );
778 if ( ! runways.search( id, &r ) ) {
779 SG_LOG( SG_GENERAL, SG_ALERT,
780 "Failed to find " << id << " in database." );
784 while ( r.id == id ) {
786 if ( r.rwy_no == runway ) {
790 SG_LOG( SG_GENERAL, SG_INFO,
791 "Runway " << r.rwy_no << " heading = " << heading );
794 // calculate reciprocal runway number
795 string snum = r.rwy_no;
796 int len = snum.length();
798 string rev_letter = "";
800 for ( i = 0; i < len; ++i ) {
801 string tmp = snum.substr(i, 1);
805 } else if ( tmp == "R" ) {
808 } else if ( tmp == "C" ) {
813 for ( i = 0; i < len; ++i ) {
814 string tmp = snum.substr(i, 1);
815 if ( tmp == "L" || tmp == "R" || tmp == "C" || tmp == " " ) {
816 snum = snum.substr(0, i);
819 SG_LOG(SG_GENERAL, SG_DEBUG, "Runway num = '" << snum << "'");
820 int num = atoi( snum.c_str() ) + 18;
821 while ( num > 36 ) { num -= 36; }
822 while ( num <= 0 ) { num += 36; }
825 snprintf( recip_no, 10, "%02d%s", num, rev_letter.c_str() );
828 if ( (string)recip_no == runway ) {
830 heading = r.heading + 180;
831 while ( heading > 360.0 ) { heading -= 360; }
833 SG_LOG( SG_GENERAL, SG_INFO,
834 "Runway " << r.rwy_no << " heading = " << heading );
844 double lat2, lon2, az2;
845 double azimuth = heading + 180.0;
846 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
848 SG_LOG( SG_GENERAL, SG_INFO,
849 "runway = " << found_r.lon << ", " << found_r.lat
850 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
851 << " heading = " << azimuth );
853 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
855 found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
856 &lat2, &lon2, &az2 );
858 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
861 double odist = fgGetDouble("/sim/presets/offset-distance");
862 odist *= SG_NM_TO_METER;
863 double oaz = azimuth;
864 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
866 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
868 while ( oaz >= 360.0 ) { oaz -= 360.0; }
869 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
875 fgSetDouble("/sim/presets/longitude-deg", lon2 );
876 fgSetDouble("/sim/presets/latitude-deg", lat2 );
877 fgSetDouble("/sim/presets/heading-deg", heading );
879 // other code depends on the actual values being set ...
880 fgSetDouble("/position/longitude-deg", lon2 );
881 fgSetDouble("/position/latitude-deg", lat2 );
882 fgSetDouble("/orientation/heading-deg", heading );
884 SG_LOG( SG_GENERAL, SG_INFO,
885 "Position for " << id << " is ("
887 << lat2 << ") new heading is "
897 static void fgSetDistOrAltFromGlideSlope() {
898 double gs = fgGetDouble("/sim/presets/glideslope");
899 double od = fgGetDouble("/sim/presets/offset-distance");
900 double alt = fgGetDouble("/sim/presets/altitude-ft");
902 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
903 // set altitude from glideslope and offset-distance
904 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
905 alt = fabs(od*tan(gs));
906 fgSetDouble("/sim/presets/altitude-ft", alt);
907 fgSetBool("/sim/presets/onground", false);
908 SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt << " ft");
909 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
910 // set offset-distance from glideslope and altitude
912 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
913 fgSetDouble("/sim/presets/offset-distance", od);
914 SG_LOG(SG_GENERAL, SG_INFO, "Calculated offset distance as: "
916 } else if( fabs(gs) > 0.01 ) {
917 SG_LOG( SG_GENERAL, SG_ALERT,
918 "Glideslope given but not altitude or offset-distance." );
919 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
920 fgSetDouble("/sim/presets/glideslope", 0);
925 // Set the initial position based on presets (or defaults)
926 bool fgInitPosition() {
927 bool set_pos = false;
929 // If glideslope is specified, then calculate offset-distance or
930 // altitude relative to glide slope if either of those was not
932 fgSetDistOrAltFromGlideSlope();
934 // If we have an explicit, in-range lon/lat, don't change it, just use it.
935 // If not, check for an airport-id and use that.
936 // If not, default to the middle of the KSFO field.
937 // The default values for lon/lat are deliberately out of range
938 // so that the airport-id can take effect; valid lon/lat will
939 // override airport-id, however.
940 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
941 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
942 if ( lon_deg >= -180.0 && lon_deg <= 180.0
943 && lat_deg >= -90.0 && lat_deg <= 90.0 )
948 string apt = fgGetString("/sim/presets/airport-id");
949 string rwy_no = fgGetString("/sim/presets/runway");
950 double hdg = fgGetDouble("/sim/presets/heading-deg");
951 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
952 // An airport + runway is requested
953 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
954 // set tower position (a little off the heading for single
956 fgSetTowerPosFromAirportID( apt, hdg );
962 if ( !set_pos && !apt.empty() ) {
963 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
964 // set tower position (a little off the heading for single
966 fgSetTowerPosFromAirportID( apt, hdg );
973 // No lon/lat specified, no airport specified, default to
974 // middle of KSFO field.
975 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
976 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
979 fgSetDouble( "/position/longitude-deg",
980 fgGetDouble("/sim/presets/longitude-deg") );
981 fgSetDouble( "/position/latitude-deg",
982 fgGetDouble("/sim/presets/latitude-deg") );
983 fgSetDouble( "/orientation/heading-deg",
984 fgGetDouble("/sim/presets/heading-deg") );
990 // General house keeping initializations
991 bool fgInitGeneral() {
994 #if defined(FX) && defined(XMESA)
995 char *mesa_win_state;
998 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
999 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1001 root = globals->get_fg_root();
1002 if ( ! root.length() ) {
1003 // No root path set? Then bail ...
1004 SG_LOG( SG_GENERAL, SG_ALERT,
1005 "Cannot continue without a path to the base package "
1006 << "being defined." );
1009 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1011 #if defined(FX) && defined(XMESA)
1012 // initialize full screen flag
1013 globals->set_fullscreen(false);
1014 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1015 // Test for the MESA_GLX_FX env variable
1016 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1017 // test if we are fullscreen mesa/glide
1018 if ( (mesa_win_state[0] == 'f') ||
1019 (mesa_win_state[0] == 'F') ) {
1020 globals->set_fullscreen(true);
1030 // Initialize the flight model subsystem. This just creates the
1031 // object. The actual fdm initialization is delayed until we get a
1032 // proper scenery elevation hit. This is checked for in main.cxx
1036 if ( cur_fdm_state ) {
1037 delete cur_fdm_state;
1041 double dt = 1.0 / fgGetInt("/sim/model-hz");
1042 aircraft_dir = fgGetString("/sim/aircraft-dir");
1043 const string &model = fgGetString("/sim/flight-model");
1046 if ( model == "larcsim" ) {
1047 cur_fdm_state = new FGLaRCsim( dt );
1048 } else if ( model == "jsb" ) {
1049 cur_fdm_state = new FGJSBsim( dt );
1050 } else if ( model == "ada" ) {
1051 cur_fdm_state = new FGADA( dt );
1052 } else if ( model == "balloon" ) {
1053 cur_fdm_state = new FGBalloonSim( dt );
1054 } else if ( model == "magic" ) {
1055 cur_fdm_state = new FGMagicCarpet( dt );
1056 } else if ( model == "ufo" ) {
1057 cur_fdm_state = new FGUFO( dt );
1058 } else if ( model == "external" ) {
1059 // external is a synonym for "--fdm=null" and is
1060 // maintained here for backwards compatibility
1061 cur_fdm_state = new FGNullFDM( dt );
1062 } else if ( model.find("network") == 0 ) {
1063 string host = "localhost";
1067 string net_options = model.substr(8);
1068 string::size_type begin, end;
1071 end = net_options.find( ",", begin );
1072 if ( end != string::npos ) {
1073 host = net_options.substr(begin, end - begin);
1077 end = net_options.find( ",", begin );
1078 if ( end != string::npos ) {
1079 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1083 end = net_options.find( ",", begin );
1084 if ( end != string::npos ) {
1085 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1089 end = net_options.find( ",", begin );
1090 if ( end != string::npos ) {
1091 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1094 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1095 } else if ( model == "null" ) {
1096 cur_fdm_state = new FGNullFDM( dt );
1097 } else if ( model == "yasim" ) {
1098 cur_fdm_state = new YASim( dt );
1100 SG_LOG(SG_GENERAL, SG_ALERT,
1101 "Unrecognized flight model '" << model
1102 << "', cannot init flight dynamics model.");
1106 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1111 static void printMat(const sgVec4 *mat, char *name="")
1114 cout << name << endl;
1115 for(i=0; i<4; i++) {
1116 cout <<" "<<mat[i][0]<<" "<<mat[i][1]<<" "<<mat[i][2]<<" "<<mat[i][3]<<endl;
1121 // Initialize view parameters
1123 // force update of model so that viewer can get some data...
1124 globals->get_aircraft_model()->update(0);
1125 // run update for current view so that data is current...
1126 globals->get_viewmgr()->update(0);
1128 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1129 printMat(globals->get_current_view()->get_UP(),"UP");
1130 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1135 SGTime *fgInitTime() {
1137 static const SGPropertyNode *longitude
1138 = fgGetNode("/position/longitude-deg");
1139 static const SGPropertyNode *latitude
1140 = fgGetNode("/position/latitude-deg");
1141 static const SGPropertyNode *cur_time_override
1142 = fgGetNode("/sim/time/cur-time-override", true);
1144 SGPath zone( globals->get_fg_root() );
1145 zone.append( "Timezone" );
1146 SGTime *t = new SGTime( longitude->getDoubleValue()
1147 * SGD_DEGREES_TO_RADIANS,
1148 latitude->getDoubleValue()
1149 * SGD_DEGREES_TO_RADIANS,
1151 cur_time_override->getLongValue() );
1153 // Handle potential user specified time offsets
1154 time_t cur_time = t->get_cur_time();
1155 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1156 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1157 time_t aircraftLocalTime =
1158 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1160 // Okay, we now have six possible scenarios
1161 int offset = fgGetInt("/sim/startup/time-offset");
1162 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1163 if (offset_type == "system-offset") {
1164 globals->set_warp( offset );
1165 } else if (offset_type == "gmt-offset") {
1166 globals->set_warp( offset - (currGMT - systemLocalTime) );
1167 } else if (offset_type == "latitude-offset") {
1168 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1169 } else if (offset_type == "system") {
1170 globals->set_warp( offset - cur_time );
1171 } else if (offset_type == "gmt") {
1172 globals->set_warp( offset - currGMT );
1173 } else if (offset_type == "latitude") {
1174 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1177 SG_LOG( SG_GENERAL, SG_ALERT,
1178 "FG_TIME::Unsupported offset type " << offset_type );
1182 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1183 << globals->get_warp() );
1185 globals->set_warp_delta( 0 );
1187 t->update( 0.0, 0.0,
1188 cur_time_override->getLongValue(),
1189 globals->get_warp() );
1195 // This is the top level init routine which calls all the other
1196 // initialization routines. If you are adding a subsystem to flight
1197 // gear, its initialization call should located in this routine.
1198 // Returns non-zero if a problem encountered.
1199 bool fgInitSubsystems( void ) {
1200 static const SGPropertyNode *longitude
1201 = fgGetNode("/sim/presets/longitude-deg");
1202 static const SGPropertyNode *latitude
1203 = fgGetNode("/sim/presets/latitude-deg");
1204 static const SGPropertyNode *altitude
1205 = fgGetNode("/sim/presets/altitude-ft");
1207 fgLIGHT *l = &cur_light_params;
1209 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1210 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1213 ////////////////////////////////////////////////////////////////////
1214 // Initialize the material property subsystem.
1215 ////////////////////////////////////////////////////////////////////
1217 SGPath mpath( globals->get_fg_root() );
1218 mpath.append( "materials.xml" );
1219 if ( ! material_lib.load( mpath.str() ) ) {
1220 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1224 ////////////////////////////////////////////////////////////////////
1225 // Initialize the event manager subsystem.
1226 ////////////////////////////////////////////////////////////////////
1228 global_events.init();
1230 // Output event stats every 60 seconds
1231 global_events.Register( "FGEventMgr::print_stats()",
1232 &global_events, &FGEventMgr::print_stats,
1236 ////////////////////////////////////////////////////////////////////
1237 // Initialize the scenery management subsystem.
1238 ////////////////////////////////////////////////////////////////////
1240 if ( global_tile_mgr.init() ) {
1241 // Load the local scenery data
1242 double visibility_meters = fgGetDouble("/environment/visibility-m");
1244 global_tile_mgr.update( longitude->getDoubleValue(),
1245 latitude->getDoubleValue(),
1246 visibility_meters );
1248 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1252 // cause refresh of viewer scenery timestamps every 15 seconds...
1253 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1254 &global_tile_mgr, &FGTileMgr::refresh_view_timestamps,
1257 SG_LOG( SG_GENERAL, SG_DEBUG,
1258 "Current terrain elevation after tile mgr init " <<
1259 globals->get_scenery()->get_cur_elev() );
1262 ////////////////////////////////////////////////////////////////////
1263 // Initialize the flight model subsystem.
1264 ////////////////////////////////////////////////////////////////////
1268 // allocates structures so must happen before any of the flight
1269 // model or control parameters are set
1270 fgAircraftInit(); // In the future this might not be the case.
1273 ////////////////////////////////////////////////////////////////////
1274 // Initialize the view manager subsystem.
1275 ////////////////////////////////////////////////////////////////////
1280 ////////////////////////////////////////////////////////////////////
1281 // Initialize the lighting subsystem.
1282 ////////////////////////////////////////////////////////////////////
1284 // fgUpdateSunPos() needs a few position and view parameters set
1285 // so it can calculate local relative sun angle and a few other
1286 // things for correctly orienting the sky.
1289 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1291 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1294 // Initialize Lighting interpolation tables
1297 // force one lighting update to make it right to start with...
1299 // update the lighting parameters (based on sun angle)
1300 global_events.Register( "fgLight::Update()",
1301 &cur_light_params, &fgLIGHT::Update,
1305 ////////////////////////////////////////////////////////////////////
1306 // Create and register the logger.
1307 ////////////////////////////////////////////////////////////////////
1309 globals->get_subsystem_mgr()->add(FGSubsystemMgr::GENERAL,
1314 ////////////////////////////////////////////////////////////////////
1315 // Create and register the XML GUI.
1316 ////////////////////////////////////////////////////////////////////
1318 globals->get_subsystem_mgr()->add(FGSubsystemMgr::INIT,
1323 ////////////////////////////////////////////////////////////////////
1324 // Initialize the local time subsystem.
1325 ////////////////////////////////////////////////////////////////////
1327 // update the current timezone each 30 minutes
1328 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1332 ////////////////////////////////////////////////////////////////////
1333 // Initialize the weather subsystem.
1334 ////////////////////////////////////////////////////////////////////
1336 // Initialize the weather modeling subsystem
1338 // Initialize the WeatherDatabase
1339 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1341 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1342 current_aircraft.fdm_state->get_Longitude(),
1343 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1344 double init_vis = fgGetDouble("/environment/visibility-m");
1346 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1348 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1350 working_type = FGLocalWeatherDatabase::use_internet;
1352 working_type = FGLocalWeatherDatabase::default_mode;
1355 if ( init_vis > 0 ) {
1356 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1357 new FGLocalWeatherDatabase( position,
1358 globals->get_fg_root(),
1362 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1363 new FGLocalWeatherDatabase( position,
1364 globals->get_fg_root(),
1368 // cout << theFGLocalWeatherDatabase << endl;
1369 // cout << "visibility = "
1370 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1372 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1374 // register the periodic update of the weather
1375 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1378 globals->get_environment_mgr()->init();
1379 globals->get_environment_mgr()->bind();
1382 ////////////////////////////////////////////////////////////////////
1383 // Initialize the 3D cloud subsystem.
1384 ////////////////////////////////////////////////////////////////////
1385 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1386 SGPath cloud_path(globals->get_fg_root());
1387 cloud_path.append("large.sky");
1388 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1389 if ( !sgCloud3d->Load( cloud_path.str(),
1390 latitude->getDoubleValue(),
1391 longitude->getDoubleValue()) )
1393 fgSetBool("/sim/rendering/clouds3d", false);
1394 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1396 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1399 ////////////////////////////////////////////////////////////////////
1400 // Initialize vor/ndb/ils/fix list management and query systems
1401 ////////////////////////////////////////////////////////////////////
1403 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
1405 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
1406 current_navlist = new FGNavList;
1407 SGPath p_nav( globals->get_fg_root() );
1408 p_nav.append( "Navaids/default.nav" );
1409 current_navlist->init( p_nav );
1411 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
1412 current_beacons = new FGMarkerBeacons;
1413 current_beacons->init();
1414 current_ilslist = new FGILSList;
1415 SGPath p_ils( globals->get_fg_root() );
1416 p_ils.append( "Navaids/default.ils" );
1417 current_ilslist->init( p_ils );
1419 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1420 current_fixlist = new FGFixList;
1421 SGPath p_fix( globals->get_fg_root() );
1422 p_fix.append( "Navaids/default.fix" );
1423 current_fixlist->init( p_fix );
1425 ////////////////////////////////////////////////////////////////////
1426 // Initialize ATC list management and query systems
1427 ////////////////////////////////////////////////////////////////////
1429 SG_LOG(SG_GENERAL, SG_INFO, " ATIS");
1430 current_atislist = new FGATISList;
1431 SGPath p_atis( globals->get_fg_root() );
1432 p_atis.append( "ATC/default.atis" );
1433 current_atislist->init( p_atis );
1435 SG_LOG(SG_GENERAL, SG_INFO, " Tower");
1436 current_towerlist = new FGTowerList;
1437 SGPath p_tower( globals->get_fg_root() );
1438 p_tower.append( "ATC/default.tower" );
1439 current_towerlist->init( p_tower );
1441 SG_LOG(SG_GENERAL, SG_INFO, " Approach");
1442 current_approachlist = new FGApproachList;
1443 SGPath p_approach( globals->get_fg_root() );
1444 p_approach.append( "ATC/default.approach" );
1445 current_approachlist->init( p_approach );
1447 ////////////////////////////////////////////////////////////////////
1448 // Initialise ATC display system
1449 ////////////////////////////////////////////////////////////////////
1451 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1452 globals->set_ATC_display(new FGATCDisplay);
1453 globals->get_ATC_display()->init();
1455 ////////////////////////////////////////////////////////////////////
1456 // Initialise the ATC Manager
1457 ////////////////////////////////////////////////////////////////////
1459 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1460 globals->set_ATC_mgr(new FGATCMgr);
1461 globals->get_ATC_mgr()->init();
1463 ////////////////////////////////////////////////////////////////////
1464 // Initialise the AI Manager
1465 ////////////////////////////////////////////////////////////////////
1467 if (fgGetBool("/sim/ai-traffic/enabled")) {
1468 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1469 globals->set_AI_mgr(new FGAIMgr);
1470 globals->get_AI_mgr()->init();
1473 #ifdef ENABLE_AUDIO_SUPPORT
1474 ////////////////////////////////////////////////////////////////////
1475 // Initialize the sound subsystem.
1476 ////////////////////////////////////////////////////////////////////
1478 globals->set_soundmgr(new FGSoundMgr);
1479 globals->get_soundmgr()->init();
1480 globals->get_soundmgr()->bind();
1483 ////////////////////////////////////////////////////////////////////
1484 // Initialize the sound-effects subsystem.
1485 ////////////////////////////////////////////////////////////////////
1487 globals->get_subsystem_mgr()->add(FGSubsystemMgr::GENERAL,
1494 globals->get_subsystem_mgr()->add(FGSubsystemMgr::GENERAL,
1496 new FGInstrumentMgr);
1497 globals->get_subsystem_mgr()->add(FGSubsystemMgr::GENERAL,
1501 ////////////////////////////////////////////////////////////////////
1502 // Initialize the radio stack subsystem.
1503 ////////////////////////////////////////////////////////////////////
1505 // A textbook example of how FGSubsystem
1507 current_radiostack = new FGRadioStack;
1508 current_radiostack->init();
1509 current_radiostack->bind();
1512 ////////////////////////////////////////////////////////////////////
1513 // Initialize the cockpit subsystem
1514 ////////////////////////////////////////////////////////////////////
1516 if( fgCockpitInit( ¤t_aircraft )) {
1517 // Cockpit initialized ok.
1519 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1524 ////////////////////////////////////////////////////////////////////
1525 // Initialize the autopilot subsystem.
1526 ////////////////////////////////////////////////////////////////////
1528 globals->set_autopilot(new FGAutopilot);
1529 globals->get_autopilot()->init();
1530 globals->get_autopilot()->bind();
1532 // FIXME: these should go in the
1533 // GUI initialization code, not here.
1535 NewTgtAirportInit();
1539 ////////////////////////////////////////////////////////////////////
1540 // Initialize I/O subsystem.
1541 ////////////////////////////////////////////////////////////////////
1543 globals->get_io()->init();
1544 globals->get_io()->bind();
1546 // Initialize the 2D panel.
1547 string panel_path = fgGetString("/sim/panel/path",
1548 "Panels/Default/default.xml");
1549 current_panel = fgReadPanel(panel_path);
1550 if (current_panel == 0) {
1551 SG_LOG( SG_INPUT, SG_ALERT,
1552 "Error reading new panel from " << panel_path );
1554 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1555 current_panel->init();
1556 current_panel->bind();
1560 ////////////////////////////////////////////////////////////////////
1561 // Initialize the default (kludged) properties.
1562 ////////////////////////////////////////////////////////////////////
1567 ////////////////////////////////////////////////////////////////////
1568 // Initialize the controls subsystem.
1569 ////////////////////////////////////////////////////////////////////
1571 globals->get_controls()->init();
1572 globals->get_controls()->bind();
1575 ////////////////////////////////////////////////////////////////////
1576 // Initialize the steam subsystem.
1577 ////////////////////////////////////////////////////////////////////
1579 globals->get_steam()->init();
1580 globals->get_steam()->bind();
1583 ////////////////////////////////////////////////////////////////////
1584 // Initialize the input subsystem.
1585 ////////////////////////////////////////////////////////////////////
1587 globals->get_subsystem_mgr()->add(FGSubsystemMgr::GENERAL,
1592 ////////////////////////////////////////////////////////////////////
1593 // Bind and initialize subsystems.
1594 ////////////////////////////////////////////////////////////////////
1596 globals->get_subsystem_mgr()->bind();
1597 globals->get_subsystem_mgr()->init();
1600 ////////////////////////////////////////////////////////////////////////
1601 // End of subsystem initialization.
1602 ////////////////////////////////////////////////////////////////////
1604 SG_LOG( SG_GENERAL, SG_INFO, endl);
1606 // Save the initial state for future
1608 globals->saveInitialState();
1614 void fgReInitSubsystems( void )
1616 static const SGPropertyNode *longitude
1617 = fgGetNode("/sim/presets/longitude-deg");
1618 static const SGPropertyNode *latitude
1619 = fgGetNode("/sim/presets/latitude-deg");
1620 static const SGPropertyNode *altitude
1621 = fgGetNode("/sim/presets/altitude-ft");
1622 static const SGPropertyNode *master_freeze
1623 = fgGetNode("/sim/freeze/master");
1625 SG_LOG( SG_GENERAL, SG_INFO,
1626 "fgReInitSubsystems(): /position/altitude = "
1627 << altitude->getDoubleValue() );
1629 bool freeze = master_freeze->getBoolValue();
1631 fgSetBool("/sim/freeze/master", true);
1634 // Initialize the Scenery Management subsystem
1635 // FIXME, what really needs to get initialized here, at the time
1636 // this was commented out, scenery.init() was a noop
1641 // allocates structures so must happen before any of the flight
1642 // model or control parameters are set
1643 fgAircraftInit(); // In the future this might not be the case.
1645 // copy viewer settings into current-view path
1646 globals->get_viewmgr()->copyToCurrent();
1650 globals->get_controls()->reset_all();
1651 globals->get_autopilot()->reset();
1655 cur_light_params.Update();
1656 fgUpdateLocalTime();
1659 fgSetBool("/sim/freeze/master", false);