1 // fg_init.cxx -- Flight Gear top level initialization routines
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 // For BC 5.01 this must be included before OpenGL includes.
30 #ifdef SG_MATH_EXCEPTION_CLASH
42 #include <string.h> // strcmp()
45 #if defined( unix ) || defined( __CYGWIN__ )
46 # include <unistd.h> // for gethostname()
49 // work around a stdc++ lib bug in some versions of linux, but doesn't
50 // seem to hurt to have this here for all versions of Linux.
52 # define _G_NO_EXTERN_TEMPLATES
55 #include <simgear/compiler.h>
56 #include <simgear/misc/exception.hxx>
60 #include <simgear/constants.h>
61 #include <simgear/debug/logstream.hxx>
62 #include <simgear/math/point3d.hxx>
63 #include <simgear/math/polar3d.hxx>
64 #include <simgear/math/sg_geodesy.hxx>
65 #include <simgear/misc/sg_path.hxx>
66 #ifdef FG_USE_CLOUDS_3D
67 # include <simgear/sky/clouds3d/SkySceneLoader.hpp>
68 # include <simgear/sky/clouds3d/SkyUtil.hpp>
70 #include <simgear/timing/sg_time.hxx>
71 #include <simgear/timing/lowleveltime.h>
73 #include <Aircraft/aircraft.hxx>
74 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
75 #include <Airports/runways.hxx>
76 #include <Airports/simple.hxx>
77 #include <ATC/ATCdisplay.hxx>
78 #include <ATC/ATCmgr.hxx>
79 #include <ATC/AIMgr.hxx>
80 #include <Autopilot/auto_gui.hxx>
81 #include <Autopilot/newauto.hxx>
82 #include <Cockpit/cockpit.hxx>
83 #include <Cockpit/radiostack.hxx>
84 #include <Cockpit/panel.hxx>
85 #include <Cockpit/panel_io.hxx>
86 #include <FDM/ADA.hxx>
87 #include <FDM/Balloon.h>
88 #include <FDM/ExternalNet/ExternalNet.hxx>
89 #include <FDM/ExternalPipe/ExternalPipe.hxx>
90 #include <FDM/JSBSim/JSBSim.hxx>
91 #include <FDM/LaRCsim.hxx>
92 #include <FDM/MagicCarpet.hxx>
93 #include <FDM/UFO.hxx>
94 #include <FDM/NullFDM.hxx>
95 #include <FDM/YASim/YASim.hxx>
96 #include <GUI/new_gui.hxx>
97 #include <Include/general.hxx>
98 #include <Input/input.hxx>
99 #include <Instrumentation/instrument_mgr.hxx>
100 // #include <Joystick/joystick.hxx>
101 #include <Objects/matlib.hxx>
102 #include <Model/acmodel.hxx>
103 #include <Navaids/fixlist.hxx>
104 #include <Navaids/ilslist.hxx>
105 #include <Navaids/mkrbeacons.hxx>
106 #include <Navaids/navlist.hxx>
107 #include <Scenery/scenery.hxx>
108 #include <Scenery/tilemgr.hxx>
109 #if defined(HAVE_PLIB_PSL)
110 #include <Scripting/scriptmgr.hxx>
112 #include <Sound/fg_fx.hxx>
113 #include <Sound/soundmgr.hxx>
114 #include <Systems/system_mgr.hxx>
115 #include <Time/FGEventMgr.hxx>
116 #include <Time/light.hxx>
117 #include <Time/sunpos.hxx>
118 #include <Time/moonpos.hxx>
119 #include <Time/tmp.hxx>
122 # include <WeatherCM/FGLocalWeatherDatabase.h>
124 # include <Environment/environment_mgr.hxx>
127 #include "fg_init.hxx"
129 #include "fg_commands.hxx"
130 #include "fg_props.hxx"
131 #include "options.hxx"
132 #include "globals.hxx"
133 #include "logger.hxx"
134 #include "viewmgr.hxx"
136 #if defined(FX) && defined(XMESA)
137 #include <GL/xmesa.h>
140 SG_USING_STD(string);
142 extern const char *default_root;
144 #ifdef FG_USE_CLOUDS_3D
145 SkySceneLoader *sgCloud3d;
149 // Scan the command line options for the specified option and return
151 static string fgScanForOption( const string& option, int argc, char **argv ) {
154 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
156 int len = option.length();
159 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
161 string arg = argv[i];
162 if ( arg.find( option ) == 0 ) {
163 return arg.substr( len );
173 // Scan the user config files for the specified option and return
175 static string fgScanForOption( const string& option, const string& path ) {
176 sg_gzifstream in( path );
177 if ( !in.is_open() ) {
181 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
183 int len = option.length();
187 while ( ! in.eof() ) {
190 while ( in.get(c) && c != '\0' ) {
195 #if defined( macintosh )
196 getline( in, line, '\r' );
198 getline( in, line, '\n' );
201 // catch extraneous (DOS) line ending character
202 if ( line[line.length() - 1] < 32 ) {
203 line = line.substr( 0, line.length()-1 );
206 if ( line.find( option ) == 0 ) {
207 return line.substr( len );
217 // Read in configuration (files and command line options) but only set
219 bool fgInitFGRoot ( int argc, char **argv ) {
223 // First parse command line options looking for --fg-root=, this
224 // will override anything specified in a config file
225 root = fgScanForOption( "--fg-root=", argc, argv);
227 #if defined( unix ) || defined( __CYGWIN__ )
228 // Next check home directory for .fgfsrc.hostname file
229 if ( root.empty() ) {
230 envp = ::getenv( "HOME" );
231 if ( envp != NULL ) {
232 SGPath config( envp );
233 config.append( ".fgfsrc" );
235 gethostname( name, 256 );
236 config.concat( "." );
237 config.concat( name );
238 root = fgScanForOption( "--fg-root=", config.str() );
243 // Next check home directory for .fgfsrc file
244 if ( root.empty() ) {
245 envp = ::getenv( "HOME" );
246 if ( envp != NULL ) {
247 SGPath config( envp );
248 config.append( ".fgfsrc" );
249 root = fgScanForOption( "--fg-root=", config.str() );
253 // Next check if fg-root is set as an env variable
254 if ( root.empty() ) {
255 envp = ::getenv( "FG_ROOT" );
256 if ( envp != NULL ) {
261 // Otherwise, default to a random compiled-in location if we can't
262 // find fg-root any other way.
263 if ( root.empty() ) {
264 #if defined( __CYGWIN__ )
265 root = "/FlightGear";
266 #elif defined( WIN32 )
267 root = "\\FlightGear";
268 #elif defined( macintosh )
275 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
276 globals->set_fg_root(root);
282 // Read in configuration (files and command line options) but only set
284 bool fgInitFGAircraft ( int argc, char **argv ) {
288 // First parse command line options looking for --aircraft=, this
289 // will override anything specified in a config file
290 aircraft = fgScanForOption( "--aircraft=", argc, argv );
292 #if defined( unix ) || defined( __CYGWIN__ )
293 // Next check home directory for .fgfsrc.hostname file
294 if ( aircraft.empty() ) {
295 envp = ::getenv( "HOME" );
296 if ( envp != NULL ) {
297 SGPath config( envp );
298 config.append( ".fgfsrc" );
300 gethostname( name, 256 );
301 config.concat( "." );
302 config.concat( name );
303 aircraft = fgScanForOption( "--aircraft=", config.str() );
308 // Next check home directory for .fgfsrc file
309 if ( aircraft.empty() ) {
310 envp = ::getenv( "HOME" );
311 if ( envp != NULL ) {
312 SGPath config( envp );
313 config.append( ".fgfsrc" );
314 aircraft = fgScanForOption( "--aircraft=", config.str() );
318 // if an aircraft was specified, set the property name
319 if ( !aircraft.empty() ) {
320 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
321 fgSetString("/sim/aircraft", aircraft.c_str() );
323 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
330 // Return the current base package version
331 string fgBasePackageVersion() {
332 SGPath base_path( globals->get_fg_root() );
333 base_path.append("version");
335 sg_gzifstream in( base_path.str() );
336 if ( !in.is_open() ) {
337 SGPath old_path( globals->get_fg_root() );
338 old_path.append( "Thanks" );
339 sg_gzifstream old( old_path.str() );
340 if ( !old.is_open() ) {
343 return "[old version]";
354 // Initialize the localization
355 SGPropertyNode *fgInitLocale(const char *language) {
356 SGPropertyNode *c_node = NULL, *d_node = NULL;
357 SGPropertyNode *intl = fgGetNode("/sim/intl");
359 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
361 // localization not defined
366 // Select the proper language from the list
368 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
369 for (unsigned int i = 0; i < locale.size(); i++) {
371 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
372 for (unsigned int j = 0; j < lang.size(); j++) {
374 if (!strcmp(lang[j]->getStringValue(), language)) {
383 d_node = intl->getChild("locale");
387 // Check for localized font
388 SGPropertyNode *font_n = c_node->getNode("font", true);
389 if ( !strcmp(font_n->getStringValue(), "") )
390 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
394 // Load the default strings
396 SGPath d_path( globals->get_fg_root() );
398 const char *d_path_str = d_node->getStringValue("strings");
400 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
404 d_path.append(d_path_str);
405 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
408 SGPropertyNode *strings = c_node->getNode("strings");
410 readProperties(d_path.str(), strings);
411 } catch (const sg_exception &e) {
412 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
417 // Load the language specific strings
419 if (c_node != d_node) {
420 SGPath c_path( globals->get_fg_root() );
422 const char *c_path_str = c_node->getStringValue("strings");
424 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
428 c_path.append(c_path_str);
429 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
433 readProperties(c_path.str(), strings);
434 } catch (const sg_exception &e) {
435 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
445 // Initialize the localization routines
446 bool fgDetectLanguage() {
447 char *language = ::getenv("LANG");
449 if (language == NULL) {
450 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
454 SGPropertyNode *locale = fgInitLocale(language);
456 cerr << "No internationalization settings specified in preferences.xml"
462 globals->set_locale( locale );
467 // Attempt to locate and parse the various non-XML config files in order
468 // from least precidence to greatest precidence
470 do_options (int argc, char ** argv)
472 // Check for $fg_root/system.fgfsrc
473 SGPath config( globals->get_fg_root() );
474 config.append( "system.fgfsrc" );
475 fgParseOptions(config.str());
477 #if defined( unix ) || defined( __CYGWIN__ )
479 // Check for $fg_root/system.fgfsrc.hostname
480 gethostname( name, 256 );
481 config.concat( "." );
482 config.concat( name );
483 fgParseOptions(config.str());
486 // Check for ~/.fgfsrc
487 char* envp = ::getenv( "HOME" );
488 if ( envp != NULL ) {
490 config.append( ".fgfsrc" );
491 fgParseOptions(config.str());
494 #if defined( unix ) || defined( __CYGWIN__ )
495 // Check for ~/.fgfsrc.hostname
496 gethostname( name, 256 );
497 config.concat( "." );
498 config.concat( name );
499 fgParseOptions(config.str());
502 // Parse remaining command line options
503 // These will override anything specified in a config file
504 fgParseArgs(argc, argv);
508 // Read in configuration (file and command line)
509 bool fgInitConfig ( int argc, char **argv ) {
511 // First, set some sane default values
514 // Read global preferences from $FG_ROOT/preferences.xml
515 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
516 fgLoadProps("preferences.xml", globals->get_props());
517 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
519 // Detect the required language as early as possible
520 if ( !fgDetectLanguage() ) {
524 // Scan user config files and command line for a specified aircraft.
525 fgInitFGAircraft(argc, argv);
527 string aircraft = fgGetString("/sim/aircraft", "");
528 if ( aircraft.size() > 0 ) {
529 SGPath aircraft_path(globals->get_fg_root());
530 aircraft_path.append("Aircraft");
531 aircraft_path.append(aircraft);
532 aircraft_path.concat("-set.xml");
533 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
534 << " from " << aircraft_path.str());
536 readProperties(aircraft_path.str(), globals->get_props());
537 } catch (const sg_exception &e) {
538 string message = "Error reading default aircraft: ";
539 message += e.getFormattedMessage();
540 SG_LOG(SG_INPUT, SG_ALERT, message);
544 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
547 // parse options after loading aircraft to ensure any user
548 // overrides of defaults are honored.
549 do_options(argc, argv);
555 // find basic airport location info from airport database
556 bool fgFindAirportID( const string& id, FGAirport *a ) {
558 SGPath path( globals->get_fg_root() );
559 path.append( "Airports" );
560 path.append( "simple.mk4" );
561 FGAirports airports( path.c_str() );
563 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
565 if ( ! airports.search( id, a ) ) {
566 SG_LOG( SG_GENERAL, SG_ALERT,
567 "Failed to find " << id << " in " << path.str() );
574 SG_LOG( SG_GENERAL, SG_INFO,
575 "Position for " << id << " is ("
576 << a->longitude << ", "
577 << a->latitude << ")" );
583 // get airport elevation
584 static double fgGetAirportElev( const string& id ) {
588 SG_LOG( SG_GENERAL, SG_INFO,
589 "Finding elevation for airport: " << id );
591 if ( fgFindAirportID( id, &a ) ) {
599 // Preset lon/lat given an airport id
600 static bool fgSetPosFromAirportID( const string& id ) {
604 SG_LOG( SG_GENERAL, SG_INFO,
605 "Attempting to set starting position from airport code " << id );
607 if ( fgFindAirportID( id, &a ) ) {
609 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
610 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
612 // other code depends on the actual postition being set so set
614 fgSetDouble("/position/longitude-deg", a.longitude );
615 fgSetDouble("/position/latitude-deg", a.latitude );
617 SG_LOG( SG_GENERAL, SG_INFO,
618 "Position for " << id << " is (" << a.longitude
619 << ", " << a.latitude << ")" );
628 // Set current tower position lon/lat given an airport id
629 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
631 // tower height hard coded for now...
632 float towerheight=50.0f;
634 // make a little off the heading for 1 runway airports...
635 float fudge_lon = fabs(sin(hdg)) * .003f;
636 float fudge_lat = .003f - fudge_lon;
638 if ( fgFindAirportID( id, &a ) ) {
639 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
640 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
641 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
650 // Set current_options lon/lat given an airport id and heading (degrees)
651 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
654 double found_dir = 0.0;
657 // set initial position from runway and heading
659 SGPath path( globals->get_fg_root() );
660 path.append( "Airports" );
661 path.append( "runways.mk4" );
662 FGRunways runways( path.c_str() );
664 SG_LOG( SG_GENERAL, SG_INFO,
665 "Attempting to set starting position from runway code "
666 << id << " heading " << tgt_hdg );
668 if ( ! runways.search( id, &r ) ) {
669 SG_LOG( SG_GENERAL, SG_ALERT,
670 "Failed to find " << id << " in database." );
675 double min_diff = 360.0;
677 while ( r.id == id ) {
679 diff = tgt_hdg - r.heading;
680 while ( diff < -180.0 ) { diff += 360.0; }
681 while ( diff > 180.0 ) { diff -= 360.0; }
683 SG_LOG( SG_GENERAL, SG_INFO,
684 "Runway " << r.rwy_no << " heading = " << r.heading <<
685 " diff = " << diff );
686 if ( diff < min_diff ) {
693 diff = tgt_hdg - r.heading - 180.0;
694 while ( diff < -180.0 ) { diff += 360.0; }
695 while ( diff > 180.0 ) { diff -= 360.0; }
697 SG_LOG( SG_GENERAL, SG_INFO,
698 "Runway -" << r.rwy_no << " heading = " <<
700 " diff = " << diff );
701 if ( diff < min_diff ) {
710 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
711 << " + " << found_dir );
717 double heading = found_r.heading + found_dir;
718 while ( heading >= 360.0 ) { heading -= 360.0; }
720 double lat2, lon2, az2;
721 double azimuth = found_r.heading + found_dir + 180.0;
722 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
724 SG_LOG( SG_GENERAL, SG_INFO,
725 "runway = " << found_r.lon << ", " << found_r.lat
726 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
727 << " heading = " << azimuth );
729 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
730 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
731 &lat2, &lon2, &az2 );
733 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
735 double odist = fgGetDouble("/sim/presets/offset-distance");
736 odist *= SG_NM_TO_METER;
737 double oaz = azimuth;
738 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
739 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
741 while ( oaz >= 360.0 ) { oaz -= 360.0; }
742 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
748 fgSetDouble("/sim/presets/longitude-deg", lon2 );
749 fgSetDouble("/sim/presets/latitude-deg", lat2 );
750 fgSetDouble("/sim/presets/heading-deg", heading );
752 // other code depends on the actual values being set ...
753 fgSetDouble("/position/longitude-deg", lon2 );
754 fgSetDouble("/position/latitude-deg", lat2 );
755 fgSetDouble("/orientation/heading-deg", heading );
757 SG_LOG( SG_GENERAL, SG_INFO,
758 "Position for " << id << " is ("
760 << lat2 << ") new heading is "
767 // Set current_options lon/lat given an airport id and heading (degrees)
768 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
771 double heading = 0.0;
775 // standardize input number
776 string tmp = rwy.substr(1, 1);
777 if ( tmp == "L" || tmp == "R" || tmp == "C" ) {
785 // set initial position from runway and heading
787 SGPath path( globals->get_fg_root() );
788 path.append( "Airports" );
789 path.append( "runways.mk4" );
790 FGRunways runways( path.c_str() );
792 SG_LOG( SG_GENERAL, SG_INFO,
793 "Attempting to set starting position for "
794 << id << ":" << runway );
796 if ( ! runways.search( id, &r ) ) {
797 SG_LOG( SG_GENERAL, SG_ALERT,
798 "Failed to find " << id << " in database." );
802 while ( r.id == id ) {
804 if ( r.rwy_no == runway ) {
808 SG_LOG( SG_GENERAL, SG_INFO,
809 "Runway " << r.rwy_no << " heading = " << heading );
812 // calculate reciprocal runway number
813 string snum = r.rwy_no;
814 int len = snum.length();
816 string rev_letter = "";
818 for ( i = 0; i < len; ++i ) {
819 string tmp = snum.substr(i, 1);
823 } else if ( tmp == "R" ) {
826 } else if ( tmp == "C" ) {
831 for ( i = 0; i < len; ++i ) {
832 string tmp = snum.substr(i, 1);
833 if ( tmp == "L" || tmp == "R" || tmp == "C" || tmp == " " ) {
834 snum = snum.substr(0, i);
837 SG_LOG(SG_GENERAL, SG_DEBUG, "Runway num = '" << snum << "'");
838 int num = atoi( snum.c_str() ) + 18;
839 while ( num > 36 ) { num -= 36; }
840 while ( num <= 0 ) { num += 36; }
843 snprintf( recip_no, 10, "%02d%s", num, rev_letter.c_str() );
846 if ( (string)recip_no == runway ) {
848 heading = r.heading + 180;
849 while ( heading > 360.0 ) { heading -= 360; }
851 SG_LOG( SG_GENERAL, SG_INFO,
852 "Runway " << r.rwy_no << " heading = " << heading );
862 double lat2, lon2, az2;
863 double azimuth = heading + 180.0;
864 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
866 SG_LOG( SG_GENERAL, SG_INFO,
867 "runway = " << found_r.lon << ", " << found_r.lat
868 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
869 << " heading = " << azimuth );
871 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
873 found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
874 &lat2, &lon2, &az2 );
876 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
879 double odist = fgGetDouble("/sim/presets/offset-distance");
880 odist *= SG_NM_TO_METER;
881 double oaz = azimuth;
882 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
884 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
886 while ( oaz >= 360.0 ) { oaz -= 360.0; }
887 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
893 fgSetDouble("/sim/presets/longitude-deg", lon2 );
894 fgSetDouble("/sim/presets/latitude-deg", lat2 );
895 fgSetDouble("/sim/presets/heading-deg", heading );
897 // other code depends on the actual values being set ...
898 fgSetDouble("/position/longitude-deg", lon2 );
899 fgSetDouble("/position/latitude-deg", lat2 );
900 fgSetDouble("/orientation/heading-deg", heading );
902 SG_LOG( SG_GENERAL, SG_INFO,
903 "Position for " << id << " is ("
905 << lat2 << ") new heading is "
915 static void fgSetDistOrAltFromGlideSlope() {
916 string apt_id = fgGetString("/sim/presets/airport-id");
917 double gs = fgGetDouble("/sim/presets/glideslope-deg")
918 * SG_DEGREES_TO_RADIANS ;
919 double od = fgGetDouble("/sim/presets/offset-distance");
920 double alt = fgGetDouble("/sim/presets/altitude-ft");
922 double apt_elev = 0.0;
923 if ( ! apt_id.empty() ) {
924 apt_elev = fgGetAirportElev( apt_id );
925 if ( apt_elev < -9990.0 ) {
932 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
933 // set altitude from glideslope and offset-distance
934 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
935 alt = fabs(od*tan(gs)) + apt_elev;
936 fgSetDouble("/sim/presets/altitude-ft", alt);
937 fgSetBool("/sim/presets/onground", false);
938 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
940 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
941 // set offset-distance from glideslope and altitude
942 od = (alt - apt_elev) / tan(gs);
943 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
944 fgSetDouble("/sim/presets/offset-distance", od);
945 fgSetBool("/sim/presets/onground", false);
946 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
948 } else if( fabs(gs) > 0.01 ) {
949 SG_LOG( SG_GENERAL, SG_ALERT,
950 "Glideslope given but not altitude or offset-distance." );
951 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
952 fgSetDouble("/sim/presets/glideslope-deg", 0);
953 fgSetBool("/sim/presets/onground", true);
958 // Set current_options lon/lat given an airport id and heading (degrees)
959 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
960 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
962 // set initial position from runway and heading
964 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
965 << id << ":" << freq );
967 double lon = nav->get_lon();
968 double lat = nav->get_lat();
970 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
972 double odist = fgGetDouble("/sim/presets/offset-distance")
974 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
976 while ( oaz >= 360.0 ) { oaz -= 360.0; }
977 double olat, olon, az2;
978 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
985 fgSetDouble("/sim/presets/longitude-deg", lon );
986 fgSetDouble("/sim/presets/latitude-deg", lat );
988 // other code depends on the actual values being set ...
989 fgSetDouble("/position/longitude-deg", lon );
990 fgSetDouble("/position/latitude-deg", lat );
991 fgSetDouble("/orientation/heading-deg",
992 fgGetDouble("/sim/presets/heading-deg") );
994 SG_LOG( SG_GENERAL, SG_INFO,
995 "Position for " << id << ":" << freq << " is ("
996 << lon << ", "<< lat << ")" );
1000 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
1001 << id << ":" << freq );
1007 // Set current_options lon/lat given an airport id and heading (degrees)
1008 static bool fgSetPosFromFix( const string& id ) {
1011 // set initial position from runway and heading
1012 if ( current_fixlist->query( id.c_str(), &fix ) ) {
1013 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
1016 double lon = fix.get_lon();
1017 double lat = fix.get_lat();
1019 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
1021 double odist = fgGetDouble("/sim/presets/offset-distance")
1023 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
1025 while ( oaz >= 360.0 ) { oaz -= 360.0; }
1026 double olat, olon, az2;
1027 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
1034 fgSetDouble("/sim/presets/longitude-deg", lon );
1035 fgSetDouble("/sim/presets/latitude-deg", lat );
1037 // other code depends on the actual values being set ...
1038 fgSetDouble("/position/longitude-deg", lon );
1039 fgSetDouble("/position/latitude-deg", lat );
1040 fgSetDouble("/orientation/heading-deg",
1041 fgGetDouble("/sim/presets/heading-deg") );
1043 SG_LOG( SG_GENERAL, SG_INFO,
1044 "Position for " << id << " is ("
1045 << lon << ", "<< lat << ")" );
1049 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
1057 * Initialize vor/ndb/ils/fix list management and query systems
1062 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
1064 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
1065 current_navlist = new FGNavList;
1066 SGPath p_nav( globals->get_fg_root() );
1067 p_nav.append( "Navaids/default.nav" );
1068 current_navlist->init( p_nav );
1070 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
1071 current_beacons = new FGMarkerBeacons;
1072 current_beacons->init();
1073 current_ilslist = new FGILSList;
1074 SGPath p_ils( globals->get_fg_root() );
1075 p_ils.append( "Navaids/default.ils" );
1076 current_ilslist->init( p_ils );
1078 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1079 current_fixlist = new FGFixList;
1080 SGPath p_fix( globals->get_fg_root() );
1081 p_fix.append( "Navaids/default.fix" );
1082 current_fixlist->init( p_fix );
1088 // Set the initial position based on presets (or defaults)
1089 bool fgInitPosition() {
1090 bool set_pos = false;
1092 // If glideslope is specified, then calculate offset-distance or
1093 // altitude relative to glide slope if either of those was not
1095 fgSetDistOrAltFromGlideSlope();
1097 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1098 // If not, check for an airport-id and use that.
1099 // If not, default to the middle of the KSFO field.
1100 // The default values for lon/lat are deliberately out of range
1101 // so that the airport-id can take effect; valid lon/lat will
1102 // override airport-id, however.
1103 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1104 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1105 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1106 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1111 string apt = fgGetString("/sim/presets/airport-id");
1112 string rwy_no = fgGetString("/sim/presets/runway");
1113 double hdg = fgGetDouble("/sim/presets/heading-deg");
1114 string vor = fgGetString("/sim/presets/vor-id");
1115 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1116 string ndb = fgGetString("/sim/presets/ndb-id");
1117 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1118 string fix = fgGetString("/sim/presets/fix");
1119 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1120 // An airport + runway is requested
1121 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1122 // set position (a little off the heading for single
1124 fgSetTowerPosFromAirportID( apt, hdg );
1129 if ( !set_pos && !apt.empty() ) {
1130 // An airport is requested (find runway closest to hdg)
1132 if (fgGetDouble("/sim/presets/altitude-ft") <= 0 &&
1133 fgGetDouble("/sim/presets/offset-distance") == 0)
1134 ok = fgSetPosFromAirportIDandHdg( apt, hdg );
1136 ok = fgSetPosFromAirportID( apt );
1139 // set position (a little off the heading for single
1141 fgSetTowerPosFromAirportID( apt, hdg );
1146 if ( !set_pos && !vor.empty() ) {
1147 // a VOR is requested
1148 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1149 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1150 fgSetBool("/sim/presets/onground", false);
1152 fgSetBool("/sim/presets/onground", true);
1157 if ( !set_pos && !ndb.empty() ) {
1158 // an NDB is requested
1159 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1160 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1161 fgSetBool("/sim/presets/onground", false);
1163 fgSetBool("/sim/presets/onground", true);
1168 if ( !set_pos && !fix.empty() ) {
1169 // a Fix is requested
1170 if ( fgSetPosFromFix( fix ) ) {
1171 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1172 fgSetBool("/sim/presets/onground", false);
1174 fgSetBool("/sim/presets/onground", true);
1181 // No lon/lat specified, no airport specified, default to
1182 // middle of KSFO field.
1183 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1184 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1187 fgSetDouble( "/position/longitude-deg",
1188 fgGetDouble("/sim/presets/longitude-deg") );
1189 fgSetDouble( "/position/latitude-deg",
1190 fgGetDouble("/sim/presets/latitude-deg") );
1191 fgSetDouble( "/orientation/heading-deg",
1192 fgGetDouble("/sim/presets/heading-deg") );
1198 // General house keeping initializations
1199 bool fgInitGeneral() {
1202 #if defined(FX) && defined(XMESA)
1203 char *mesa_win_state;
1206 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1207 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1209 root = globals->get_fg_root();
1210 if ( ! root.length() ) {
1211 // No root path set? Then bail ...
1212 SG_LOG( SG_GENERAL, SG_ALERT,
1213 "Cannot continue without a path to the base package "
1214 << "being defined." );
1217 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1219 #if defined(FX) && defined(XMESA)
1220 // initialize full screen flag
1221 globals->set_fullscreen(false);
1222 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1223 // Test for the MESA_GLX_FX env variable
1224 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1225 // test if we are fullscreen mesa/glide
1226 if ( (mesa_win_state[0] == 'f') ||
1227 (mesa_win_state[0] == 'F') ) {
1228 globals->set_fullscreen(true);
1238 // Initialize the flight model subsystem. This just creates the
1239 // object. The actual fdm initialization is delayed until we get a
1240 // proper scenery elevation hit. This is checked for in main.cxx
1244 if ( cur_fdm_state ) {
1245 delete cur_fdm_state;
1249 double dt = 1.0 / fgGetInt("/sim/model-hz");
1250 aircraft_dir = fgGetString("/sim/aircraft-dir");
1251 const string &model = fgGetString("/sim/flight-model");
1254 if ( model == "larcsim" ) {
1255 cur_fdm_state = new FGLaRCsim( dt );
1256 } else if ( model == "jsb" ) {
1257 cur_fdm_state = new FGJSBsim( dt );
1258 } else if ( model == "ada" ) {
1259 cur_fdm_state = new FGADA( dt );
1260 } else if ( model == "balloon" ) {
1261 cur_fdm_state = new FGBalloonSim( dt );
1262 } else if ( model == "magic" ) {
1263 cur_fdm_state = new FGMagicCarpet( dt );
1264 } else if ( model == "ufo" ) {
1265 cur_fdm_state = new FGUFO( dt );
1266 } else if ( model == "external" ) {
1267 // external is a synonym for "--fdm=null" and is
1268 // maintained here for backwards compatibility
1269 cur_fdm_state = new FGNullFDM( dt );
1270 } else if ( model.find("network") == 0 ) {
1271 string host = "localhost";
1275 string net_options = model.substr(8);
1276 string::size_type begin, end;
1279 end = net_options.find( ",", begin );
1280 if ( end != string::npos ) {
1281 host = net_options.substr(begin, end - begin);
1285 end = net_options.find( ",", begin );
1286 if ( end != string::npos ) {
1287 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1291 end = net_options.find( ",", begin );
1292 if ( end != string::npos ) {
1293 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1297 end = net_options.find( ",", begin );
1298 if ( end != string::npos ) {
1299 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1302 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1303 } else if ( model.find("pipe") == 0 ) {
1304 string pipe_path = model.substr(5);
1305 cur_fdm_state = new FGExternalPipe( dt, pipe_path );
1306 } else if ( model == "null" ) {
1307 cur_fdm_state = new FGNullFDM( dt );
1308 } else if ( model == "yasim" ) {
1309 cur_fdm_state = new YASim( dt );
1311 SG_LOG(SG_GENERAL, SG_ALERT,
1312 "Unrecognized flight model '" << model
1313 << "', cannot init flight dynamics model.");
1317 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1322 static void printMat(const sgVec4 *mat, char *name="")
1325 cout << name << endl;
1326 for(i=0; i<4; i++) {
1327 cout <<" "<<mat[i][0]<<" "<<mat[i][1]<<" "<<mat[i][2]<<" "<<mat[i][3]<<endl;
1332 // Initialize view parameters
1334 // force update of model so that viewer can get some data...
1335 globals->get_aircraft_model()->update(0);
1336 // run update for current view so that data is current...
1337 globals->get_viewmgr()->update(0);
1339 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1340 printMat(globals->get_current_view()->get_UP(),"UP");
1341 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1346 SGTime *fgInitTime() {
1348 static const SGPropertyNode *longitude
1349 = fgGetNode("/position/longitude-deg");
1350 static const SGPropertyNode *latitude
1351 = fgGetNode("/position/latitude-deg");
1352 static const SGPropertyNode *cur_time_override
1353 = fgGetNode("/sim/time/cur-time-override", true);
1355 SGPath zone( globals->get_fg_root() );
1356 zone.append( "Timezone" );
1357 SGTime *t = new SGTime( longitude->getDoubleValue()
1358 * SGD_DEGREES_TO_RADIANS,
1359 latitude->getDoubleValue()
1360 * SGD_DEGREES_TO_RADIANS,
1362 cur_time_override->getLongValue() );
1364 // Handle potential user specified time offsets
1365 time_t cur_time = t->get_cur_time();
1366 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1367 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1368 time_t aircraftLocalTime =
1369 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1371 // Okay, we now have six possible scenarios
1372 int offset = fgGetInt("/sim/startup/time-offset");
1373 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1374 if (offset_type == "system-offset") {
1375 globals->set_warp( offset );
1376 } else if (offset_type == "gmt-offset") {
1377 globals->set_warp( offset - (currGMT - systemLocalTime) );
1378 } else if (offset_type == "latitude-offset") {
1379 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1380 } else if (offset_type == "system") {
1381 globals->set_warp( offset - cur_time );
1382 } else if (offset_type == "gmt") {
1383 globals->set_warp( offset - currGMT );
1384 } else if (offset_type == "latitude") {
1385 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1388 SG_LOG( SG_GENERAL, SG_ALERT,
1389 "FG_TIME::Unsupported offset type " << offset_type );
1393 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1394 << globals->get_warp() );
1396 globals->set_warp_delta( 0 );
1398 t->update( 0.0, 0.0,
1399 cur_time_override->getLongValue(),
1400 globals->get_warp() );
1406 // This is the top level init routine which calls all the other
1407 // initialization routines. If you are adding a subsystem to flight
1408 // gear, its initialization call should located in this routine.
1409 // Returns non-zero if a problem encountered.
1410 bool fgInitSubsystems() {
1411 static const SGPropertyNode *longitude
1412 = fgGetNode("/sim/presets/longitude-deg");
1413 static const SGPropertyNode *latitude
1414 = fgGetNode("/sim/presets/latitude-deg");
1415 static const SGPropertyNode *altitude
1416 = fgGetNode("/sim/presets/altitude-ft");
1418 fgLIGHT *l = &cur_light_params;
1420 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1421 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1424 ////////////////////////////////////////////////////////////////////
1425 // Initialize the material property subsystem.
1426 ////////////////////////////////////////////////////////////////////
1428 SGPath mpath( globals->get_fg_root() );
1429 mpath.append( "materials.xml" );
1430 if ( ! material_lib.load( mpath.str() ) ) {
1431 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1435 ////////////////////////////////////////////////////////////////////
1436 // Initialize the event manager subsystem.
1437 ////////////////////////////////////////////////////////////////////
1439 global_events.init();
1441 // Output event stats every 60 seconds
1442 global_events.Register( "FGEventMgr::print_stats()",
1443 &global_events, &FGEventMgr::print_stats,
1447 ////////////////////////////////////////////////////////////////////
1448 // Initialize the scenery management subsystem.
1449 ////////////////////////////////////////////////////////////////////
1451 if ( globals->get_tile_mgr()->init() ) {
1452 // Load the local scenery data
1453 double visibility_meters = fgGetDouble("/environment/visibility-m");
1455 globals->get_tile_mgr()->update( visibility_meters );
1457 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1461 // cause refresh of viewer scenery timestamps every 15 seconds...
1462 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1463 globals->get_tile_mgr(),
1464 &FGTileMgr::refresh_view_timestamps,
1467 SG_LOG( SG_GENERAL, SG_DEBUG,
1468 "Current terrain elevation after tile mgr init " <<
1469 globals->get_scenery()->get_cur_elev() );
1472 ////////////////////////////////////////////////////////////////////
1473 // Initialize the flight model subsystem.
1474 ////////////////////////////////////////////////////////////////////
1478 // allocates structures so must happen before any of the flight
1479 // model or control parameters are set
1480 fgAircraftInit(); // In the future this might not be the case.
1483 ////////////////////////////////////////////////////////////////////
1484 // Initialize the view manager subsystem.
1485 ////////////////////////////////////////////////////////////////////
1490 ////////////////////////////////////////////////////////////////////
1491 // Initialize the lighting subsystem.
1492 ////////////////////////////////////////////////////////////////////
1494 // fgUpdateSunPos() needs a few position and view parameters set
1495 // so it can calculate local relative sun angle and a few other
1496 // things for correctly orienting the sky.
1499 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1501 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1504 // Initialize Lighting interpolation tables
1507 // force one lighting update to make it right to start with...
1509 // update the lighting parameters (based on sun angle)
1510 global_events.Register( "fgLight::Update()",
1511 &cur_light_params, &fgLIGHT::Update,
1515 ////////////////////////////////////////////////////////////////////
1516 // Create and register the logger.
1517 ////////////////////////////////////////////////////////////////////
1519 globals->add_subsystem("logger", new FGLogger);
1522 #if defined(HAVE_PLIB_PSL)
1523 ////////////////////////////////////////////////////////////////////
1524 // Create and register the script manager.
1525 ////////////////////////////////////////////////////////////////////
1527 globals->add_subsystem("scripting", new FGScriptMgr);
1528 #endif // HAVE_PLIB_PSL
1531 ////////////////////////////////////////////////////////////////////
1532 // Create and register the XML GUI.
1533 ////////////////////////////////////////////////////////////////////
1535 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1538 ////////////////////////////////////////////////////////////////////
1539 // Initialize the local time subsystem.
1540 ////////////////////////////////////////////////////////////////////
1542 // update the current timezone each 30 minutes
1543 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1547 ////////////////////////////////////////////////////////////////////
1548 // Initialize the weather subsystem.
1549 ////////////////////////////////////////////////////////////////////
1551 // Initialize the weather modeling subsystem
1553 // Initialize the WeatherDatabase
1554 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1556 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1557 current_aircraft.fdm_state->get_Longitude(),
1558 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1559 double init_vis = fgGetDouble("/environment/visibility-m");
1561 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1563 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1565 working_type = FGLocalWeatherDatabase::use_internet;
1567 working_type = FGLocalWeatherDatabase::default_mode;
1570 if ( init_vis > 0 ) {
1571 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1572 new FGLocalWeatherDatabase( position,
1573 globals->get_fg_root(),
1577 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1578 new FGLocalWeatherDatabase( position,
1579 globals->get_fg_root(),
1583 // cout << theFGLocalWeatherDatabase << endl;
1584 // cout << "visibility = "
1585 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1587 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1589 // register the periodic update of the weather
1590 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1593 globals->get_environment_mgr()->init();
1594 globals->get_environment_mgr()->bind();
1597 #ifdef FG_USE_CLOUDS_3D
1598 ////////////////////////////////////////////////////////////////////
1599 // Initialize the 3D cloud subsystem.
1600 ////////////////////////////////////////////////////////////////////
1601 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1602 SGPath cloud_path(globals->get_fg_root());
1603 cloud_path.append("large.sky");
1604 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1605 if ( !sgCloud3d->Load( cloud_path.str(),
1606 latitude->getDoubleValue(),
1607 longitude->getDoubleValue()) )
1609 fgSetBool("/sim/rendering/clouds3d", false);
1610 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1612 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1616 ////////////////////////////////////////////////////////////////////
1617 // Initialise ATC display system
1618 ////////////////////////////////////////////////////////////////////
1620 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1621 globals->set_ATC_display(new FGATCDisplay);
1622 globals->get_ATC_display()->init();
1624 ////////////////////////////////////////////////////////////////////
1625 // Initialise the ATC Manager
1626 ////////////////////////////////////////////////////////////////////
1628 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1629 globals->set_ATC_mgr(new FGATCMgr);
1630 globals->get_ATC_mgr()->init();
1632 ////////////////////////////////////////////////////////////////////
1633 // Initialise the AI Manager
1634 ////////////////////////////////////////////////////////////////////
1636 if (fgGetBool("/sim/ai-traffic/enabled")) {
1637 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1638 globals->set_AI_mgr(new FGAIMgr);
1639 globals->get_AI_mgr()->init();
1642 #ifdef ENABLE_AUDIO_SUPPORT
1643 ////////////////////////////////////////////////////////////////////
1644 // Initialize the sound subsystem.
1645 ////////////////////////////////////////////////////////////////////
1647 globals->set_soundmgr(new FGSoundMgr);
1648 globals->get_soundmgr()->init();
1649 globals->get_soundmgr()->bind();
1652 ////////////////////////////////////////////////////////////////////
1653 // Initialize the sound-effects subsystem.
1654 ////////////////////////////////////////////////////////////////////
1656 globals->add_subsystem("fx", new FGFX);
1660 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1661 globals->add_subsystem("systems", new FGSystemMgr);
1663 ////////////////////////////////////////////////////////////////////
1664 // Initialize the radio stack subsystem.
1665 ////////////////////////////////////////////////////////////////////
1667 current_radiostack = new FGRadioStack;
1668 current_radiostack->init();
1669 current_radiostack->bind();
1672 ////////////////////////////////////////////////////////////////////
1673 // Initialize the cockpit subsystem
1674 ////////////////////////////////////////////////////////////////////
1676 if( fgCockpitInit( ¤t_aircraft )) {
1677 // Cockpit initialized ok.
1679 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1684 ////////////////////////////////////////////////////////////////////
1685 // Initialize the autopilot subsystem.
1686 ////////////////////////////////////////////////////////////////////
1688 globals->set_autopilot(new FGAutopilot);
1689 globals->get_autopilot()->init();
1690 globals->get_autopilot()->bind();
1692 // FIXME: these should go in the
1693 // GUI initialization code, not here.
1695 NewTgtAirportInit();
1699 ////////////////////////////////////////////////////////////////////
1700 // Initialize I/O subsystem.
1701 ////////////////////////////////////////////////////////////////////
1703 globals->get_io()->init();
1704 globals->get_io()->bind();
1706 // Initialize the 2D panel.
1707 string panel_path = fgGetString("/sim/panel/path",
1708 "Panels/Default/default.xml");
1709 current_panel = fgReadPanel(panel_path);
1710 if (current_panel == 0) {
1711 SG_LOG( SG_INPUT, SG_ALERT,
1712 "Error reading new panel from " << panel_path );
1714 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1715 current_panel->init();
1716 current_panel->bind();
1720 ////////////////////////////////////////////////////////////////////
1721 // Initialize the default (kludged) properties.
1722 ////////////////////////////////////////////////////////////////////
1727 ////////////////////////////////////////////////////////////////////
1728 // Initialize the controls subsystem.
1729 ////////////////////////////////////////////////////////////////////
1731 globals->get_controls()->init();
1732 globals->get_controls()->bind();
1735 ////////////////////////////////////////////////////////////////////
1736 // Initialize the input subsystem.
1737 ////////////////////////////////////////////////////////////////////
1739 globals->add_subsystem("input", new FGInput);
1742 ////////////////////////////////////////////////////////////////////
1743 // Bind and initialize subsystems.
1744 ////////////////////////////////////////////////////////////////////
1746 globals->get_subsystem_mgr()->bind();
1747 globals->get_subsystem_mgr()->init();
1750 ////////////////////////////////////////////////////////////////////////
1751 // End of subsystem initialization.
1752 ////////////////////////////////////////////////////////////////////
1754 SG_LOG( SG_GENERAL, SG_INFO, endl);
1756 // Save the initial state for future
1758 globals->saveInitialState();
1764 void fgReInitSubsystems()
1766 static const SGPropertyNode *longitude
1767 = fgGetNode("/sim/presets/longitude-deg");
1768 static const SGPropertyNode *latitude
1769 = fgGetNode("/sim/presets/latitude-deg");
1770 static const SGPropertyNode *altitude
1771 = fgGetNode("/sim/presets/altitude-ft");
1772 static const SGPropertyNode *master_freeze
1773 = fgGetNode("/sim/freeze/master");
1775 SG_LOG( SG_GENERAL, SG_INFO,
1776 "fgReInitSubsystems(): /position/altitude = "
1777 << altitude->getDoubleValue() );
1779 bool freeze = master_freeze->getBoolValue();
1781 fgSetBool("/sim/freeze/master", true);
1784 // Initialize the FDM
1787 // allocates structures so must happen before any of the flight
1788 // model or control parameters are set
1789 fgAircraftInit(); // In the future this might not be the case.
1791 // reload offsets from config defaults
1792 globals->get_viewmgr()->reinit();
1796 globals->get_controls()->reset_all();
1797 globals->get_autopilot()->reset();
1801 cur_light_params.Update();
1802 fgUpdateLocalTime();
1805 fgSetBool("/sim/freeze/master", false);