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/JSBSim/JSBSim.hxx>
90 #include <FDM/LaRCsim.hxx>
91 #include <FDM/MagicCarpet.hxx>
92 #include <FDM/UFO.hxx>
93 #include <FDM/NullFDM.hxx>
94 #include <FDM/YASim/YASim.hxx>
95 #include <GUI/new_gui.hxx>
96 #include <Include/general.hxx>
97 #include <Input/input.hxx>
98 #include <Instrumentation/instrument_mgr.hxx>
99 // #include <Joystick/joystick.hxx>
100 #include <Objects/matlib.hxx>
101 #include <Model/acmodel.hxx>
102 #include <Navaids/fixlist.hxx>
103 #include <Navaids/ilslist.hxx>
104 #include <Navaids/mkrbeacons.hxx>
105 #include <Navaids/navlist.hxx>
106 #include <Scenery/scenery.hxx>
107 #include <Scenery/tilemgr.hxx>
108 #if defined(HAVE_PLIB_PSL)
109 #include <Scripting/scriptmgr.hxx>
111 #include <Sound/fg_fx.hxx>
112 #include <Sound/soundmgr.hxx>
113 #include <Systems/system_mgr.hxx>
114 #include <Time/FGEventMgr.hxx>
115 #include <Time/light.hxx>
116 #include <Time/sunpos.hxx>
117 #include <Time/moonpos.hxx>
118 #include <Time/tmp.hxx>
121 # include <WeatherCM/FGLocalWeatherDatabase.h>
123 # include <Environment/environment_mgr.hxx>
126 #include "fg_init.hxx"
128 #include "fg_commands.hxx"
129 #include "fg_props.hxx"
130 #include "options.hxx"
131 #include "globals.hxx"
132 #include "logger.hxx"
133 #include "viewmgr.hxx"
135 #if defined(FX) && defined(XMESA)
136 #include <GL/xmesa.h>
139 SG_USING_STD(string);
141 extern const char *default_root;
143 #ifdef FG_USE_CLOUDS_3D
144 SkySceneLoader *sgCloud3d;
148 // Scan the command line options for the specified option and return
150 static string fgScanForOption( const string& option, int argc, char **argv ) {
153 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
155 int len = option.length();
158 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
160 string arg = argv[i];
161 if ( arg.find( option ) == 0 ) {
162 return arg.substr( len );
172 // Scan the user config files for the specified option and return
174 static string fgScanForOption( const string& option, const string& path ) {
175 sg_gzifstream in( path );
176 if ( !in.is_open() ) {
180 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
182 int len = option.length();
186 while ( ! in.eof() ) {
189 while ( in.get(c) && c != '\0' ) {
194 #if defined( macintosh )
195 getline( in, line, '\r' );
197 getline( in, line, '\n' );
200 // catch extraneous (DOS) line ending character
201 if ( line[line.length() - 1] < 32 ) {
202 line = line.substr( 0, line.length()-1 );
205 if ( line.find( option ) == 0 ) {
206 return line.substr( len );
216 // Read in configuration (files and command line options) but only set
218 bool fgInitFGRoot ( int argc, char **argv ) {
222 // First parse command line options looking for --fg-root=, this
223 // will override anything specified in a config file
224 root = fgScanForOption( "--fg-root=", argc, argv);
226 #if defined( unix ) || defined( __CYGWIN__ )
227 // Next check home directory for .fgfsrc.hostname file
228 if ( root.empty() ) {
229 envp = ::getenv( "HOME" );
230 if ( envp != NULL ) {
231 SGPath config( envp );
232 config.append( ".fgfsrc" );
234 gethostname( name, 256 );
235 config.concat( "." );
236 config.concat( name );
237 root = fgScanForOption( "--fg-root=", config.str() );
242 // Next check home directory for .fgfsrc file
243 if ( root.empty() ) {
244 envp = ::getenv( "HOME" );
245 if ( envp != NULL ) {
246 SGPath config( envp );
247 config.append( ".fgfsrc" );
248 root = fgScanForOption( "--fg-root=", config.str() );
252 // Next check if fg-root is set as an env variable
253 if ( root.empty() ) {
254 envp = ::getenv( "FG_ROOT" );
255 if ( envp != NULL ) {
260 // Otherwise, default to a random compiled-in location if we can't
261 // find fg-root any other way.
262 if ( root.empty() ) {
263 #if defined( __CYGWIN__ )
264 root = "/FlightGear";
265 #elif defined( WIN32 )
266 root = "\\FlightGear";
267 #elif defined( macintosh )
274 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
275 globals->set_fg_root(root);
281 // Read in configuration (files and command line options) but only set
283 bool fgInitFGAircraft ( int argc, char **argv ) {
287 // First parse command line options looking for --aircraft=, this
288 // will override anything specified in a config file
289 aircraft = fgScanForOption( "--aircraft=", argc, argv );
291 #if defined( unix ) || defined( __CYGWIN__ )
292 // Next check home directory for .fgfsrc.hostname file
293 if ( aircraft.empty() ) {
294 envp = ::getenv( "HOME" );
295 if ( envp != NULL ) {
296 SGPath config( envp );
297 config.append( ".fgfsrc" );
299 gethostname( name, 256 );
300 config.concat( "." );
301 config.concat( name );
302 aircraft = fgScanForOption( "--aircraft=", config.str() );
307 // Next check home directory for .fgfsrc file
308 if ( aircraft.empty() ) {
309 envp = ::getenv( "HOME" );
310 if ( envp != NULL ) {
311 SGPath config( envp );
312 config.append( ".fgfsrc" );
313 aircraft = fgScanForOption( "--aircraft=", config.str() );
317 // if an aircraft was specified, set the property name
318 if ( !aircraft.empty() ) {
319 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
320 fgSetString("/sim/aircraft", aircraft.c_str() );
322 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
329 // Return the current base package version
330 string fgBasePackageVersion() {
331 SGPath base_path( globals->get_fg_root() );
332 base_path.append("version");
334 sg_gzifstream in( base_path.str() );
335 if ( !in.is_open() ) {
336 SGPath old_path( globals->get_fg_root() );
337 old_path.append( "Thanks" );
338 sg_gzifstream old( old_path.str() );
339 if ( !old.is_open() ) {
342 return "[old version]";
353 // Initialize the localization
354 SGPropertyNode *fgInitLocale(const char *language) {
355 SGPropertyNode *c_node = NULL, *d_node = NULL;
356 SGPropertyNode *intl = fgGetNode("/sim/intl");
358 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
360 // localization not defined
365 // Select the proper language from the list
367 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
368 for (unsigned int i = 0; i < locale.size(); i++) {
370 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
371 for (unsigned int j = 0; j < lang.size(); j++) {
373 if (!strcmp(lang[j]->getStringValue(), language)) {
382 d_node = intl->getChild("locale");
386 // Check for localized font
387 SGPropertyNode *font_n = c_node->getNode("font", true);
388 if ( !strcmp(font_n->getStringValue(), "") )
389 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
393 // Load the default strings
395 SGPath d_path( globals->get_fg_root() );
397 const char *d_path_str = d_node->getStringValue("strings");
399 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
403 d_path.append(d_path_str);
404 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
407 SGPropertyNode *strings = c_node->getNode("strings");
409 readProperties(d_path.str(), strings);
410 } catch (const sg_exception &e) {
411 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
416 // Load the language specific strings
418 if (c_node != d_node) {
419 SGPath c_path( globals->get_fg_root() );
421 const char *c_path_str = c_node->getStringValue("strings");
423 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
427 c_path.append(c_path_str);
428 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
432 readProperties(c_path.str(), strings);
433 } catch (const sg_exception &e) {
434 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
444 // Initialize the localization routines
445 bool fgDetectLanguage() {
446 char *language = ::getenv("LANG");
448 if (language == NULL) {
449 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
453 SGPropertyNode *locale = fgInitLocale(language);
455 cerr << "No internationalization settings specified in preferences.xml"
461 globals->set_locale( locale );
466 // Attempt to locate and parse the various non-XML config files in order
467 // from least precidence to greatest precidence
469 do_options (int argc, char ** argv)
471 // Check for $fg_root/system.fgfsrc
472 SGPath config( globals->get_fg_root() );
473 config.append( "system.fgfsrc" );
474 fgParseOptions(config.str());
476 #if defined( unix ) || defined( __CYGWIN__ )
478 // Check for $fg_root/system.fgfsrc.hostname
479 gethostname( name, 256 );
480 config.concat( "." );
481 config.concat( name );
482 fgParseOptions(config.str());
485 // Check for ~/.fgfsrc
486 char* envp = ::getenv( "HOME" );
487 if ( envp != NULL ) {
489 config.append( ".fgfsrc" );
490 fgParseOptions(config.str());
493 #if defined( unix ) || defined( __CYGWIN__ )
494 // Check for ~/.fgfsrc.hostname
495 gethostname( name, 256 );
496 config.concat( "." );
497 config.concat( name );
498 fgParseOptions(config.str());
501 // Parse remaining command line options
502 // These will override anything specified in a config file
503 fgParseArgs(argc, argv);
507 // Read in configuration (file and command line)
508 bool fgInitConfig ( int argc, char **argv ) {
510 // First, set some sane default values
513 // Read global preferences from $FG_ROOT/preferences.xml
514 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
515 fgLoadProps("preferences.xml", globals->get_props());
516 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
518 // Detect the required language as early as possible
519 if ( !fgDetectLanguage() ) {
523 // Scan user config files and command line for a specified aircraft.
524 fgInitFGAircraft(argc, argv);
526 string aircraft = fgGetString("/sim/aircraft", "");
527 if ( aircraft.size() > 0 ) {
528 SGPath aircraft_path(globals->get_fg_root());
529 aircraft_path.append("Aircraft");
530 aircraft_path.append(aircraft);
531 aircraft_path.concat("-set.xml");
532 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
533 << " from " << aircraft_path.str());
535 readProperties(aircraft_path.str(), globals->get_props());
536 } catch (const sg_exception &e) {
537 string message = "Error reading default aircraft: ";
538 message += e.getFormattedMessage();
539 SG_LOG(SG_INPUT, SG_ALERT, message);
543 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
546 // parse options after loading aircraft to ensure any user
547 // overrides of defaults are honored.
548 do_options(argc, argv);
554 // find basic airport location info from airport database
555 bool fgFindAirportID( const string& id, FGAirport *a ) {
557 SGPath path( globals->get_fg_root() );
558 path.append( "Airports" );
559 path.append( "simple.mk4" );
560 FGAirports airports( path.c_str() );
562 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
564 if ( ! airports.search( id, a ) ) {
565 SG_LOG( SG_GENERAL, SG_ALERT,
566 "Failed to find " << id << " in " << path.str() );
573 SG_LOG( SG_GENERAL, SG_INFO,
574 "Position for " << id << " is ("
575 << a->longitude << ", "
576 << a->latitude << ")" );
582 // get airport elevation
583 static double fgGetAirportElev( const string& id ) {
587 SG_LOG( SG_GENERAL, SG_INFO,
588 "Finding elevation for airport: " << id );
590 if ( fgFindAirportID( id, &a ) ) {
598 // Preset lon/lat given an airport id
599 static bool fgSetPosFromAirportID( const string& id ) {
603 SG_LOG( SG_GENERAL, SG_INFO,
604 "Attempting to set starting position from airport code " << id );
606 if ( fgFindAirportID( id, &a ) ) {
608 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
609 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
611 // other code depends on the actual postition being set so set
613 fgSetDouble("/position/longitude-deg", a.longitude );
614 fgSetDouble("/position/latitude-deg", a.latitude );
616 SG_LOG( SG_GENERAL, SG_INFO,
617 "Position for " << id << " is (" << a.longitude
618 << ", " << a.latitude << ")" );
627 // Set current tower position lon/lat given an airport id
628 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
630 // tower height hard coded for now...
631 float towerheight=50.0f;
633 // make a little off the heading for 1 runway airports...
634 float fudge_lon = fabs(sin(hdg)) * .003f;
635 float fudge_lat = .003f - fudge_lon;
637 if ( fgFindAirportID( id, &a ) ) {
638 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
639 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
640 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
649 // Set current_options lon/lat given an airport id and heading (degrees)
650 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
653 double found_dir = 0.0;
656 // set initial position from runway and heading
658 SGPath path( globals->get_fg_root() );
659 path.append( "Airports" );
660 path.append( "runways.mk4" );
661 FGRunways runways( path.c_str() );
663 SG_LOG( SG_GENERAL, SG_INFO,
664 "Attempting to set starting position from runway code "
665 << id << " heading " << tgt_hdg );
667 if ( ! runways.search( id, &r ) ) {
668 SG_LOG( SG_GENERAL, SG_ALERT,
669 "Failed to find " << id << " in database." );
674 double min_diff = 360.0;
676 while ( r.id == id ) {
678 diff = tgt_hdg - r.heading;
679 while ( diff < -180.0 ) { diff += 360.0; }
680 while ( diff > 180.0 ) { diff -= 360.0; }
682 SG_LOG( SG_GENERAL, SG_INFO,
683 "Runway " << r.rwy_no << " heading = " << r.heading <<
684 " diff = " << diff );
685 if ( diff < min_diff ) {
692 diff = tgt_hdg - r.heading - 180.0;
693 while ( diff < -180.0 ) { diff += 360.0; }
694 while ( diff > 180.0 ) { diff -= 360.0; }
696 SG_LOG( SG_GENERAL, SG_INFO,
697 "Runway -" << r.rwy_no << " heading = " <<
699 " diff = " << diff );
700 if ( diff < min_diff ) {
709 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
710 << " + " << found_dir );
716 double heading = found_r.heading + found_dir;
717 while ( heading >= 360.0 ) { heading -= 360.0; }
719 double lat2, lon2, az2;
720 double azimuth = found_r.heading + found_dir + 180.0;
721 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
723 SG_LOG( SG_GENERAL, SG_INFO,
724 "runway = " << found_r.lon << ", " << found_r.lat
725 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
726 << " heading = " << azimuth );
728 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
729 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
730 &lat2, &lon2, &az2 );
732 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
734 double odist = fgGetDouble("/sim/presets/offset-distance");
735 odist *= SG_NM_TO_METER;
736 double oaz = azimuth;
737 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
738 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
740 while ( oaz >= 360.0 ) { oaz -= 360.0; }
741 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
747 fgSetDouble("/sim/presets/longitude-deg", lon2 );
748 fgSetDouble("/sim/presets/latitude-deg", lat2 );
749 fgSetDouble("/sim/presets/heading-deg", heading );
751 // other code depends on the actual values being set ...
752 fgSetDouble("/position/longitude-deg", lon2 );
753 fgSetDouble("/position/latitude-deg", lat2 );
754 fgSetDouble("/orientation/heading-deg", heading );
756 SG_LOG( SG_GENERAL, SG_INFO,
757 "Position for " << id << " is ("
759 << lat2 << ") new heading is "
766 // Set current_options lon/lat given an airport id and heading (degrees)
767 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
770 double heading = 0.0;
774 // standardize input number
775 string tmp = rwy.substr(1, 1);
776 if ( tmp == "L" || tmp == "R" || tmp == "C" ) {
784 // set initial position from runway and heading
786 SGPath path( globals->get_fg_root() );
787 path.append( "Airports" );
788 path.append( "runways.mk4" );
789 FGRunways runways( path.c_str() );
791 SG_LOG( SG_GENERAL, SG_INFO,
792 "Attempting to set starting position for "
793 << id << ":" << runway );
795 if ( ! runways.search( id, &r ) ) {
796 SG_LOG( SG_GENERAL, SG_ALERT,
797 "Failed to find " << id << " in database." );
801 while ( r.id == id ) {
803 if ( r.rwy_no == runway ) {
807 SG_LOG( SG_GENERAL, SG_INFO,
808 "Runway " << r.rwy_no << " heading = " << heading );
811 // calculate reciprocal runway number
812 string snum = r.rwy_no;
813 int len = snum.length();
815 string rev_letter = "";
817 for ( i = 0; i < len; ++i ) {
818 string tmp = snum.substr(i, 1);
822 } else if ( tmp == "R" ) {
825 } else if ( tmp == "C" ) {
830 for ( i = 0; i < len; ++i ) {
831 string tmp = snum.substr(i, 1);
832 if ( tmp == "L" || tmp == "R" || tmp == "C" || tmp == " " ) {
833 snum = snum.substr(0, i);
836 SG_LOG(SG_GENERAL, SG_DEBUG, "Runway num = '" << snum << "'");
837 int num = atoi( snum.c_str() ) + 18;
838 while ( num > 36 ) { num -= 36; }
839 while ( num <= 0 ) { num += 36; }
842 snprintf( recip_no, 10, "%02d%s", num, rev_letter.c_str() );
845 if ( (string)recip_no == runway ) {
847 heading = r.heading + 180;
848 while ( heading > 360.0 ) { heading -= 360; }
850 SG_LOG( SG_GENERAL, SG_INFO,
851 "Runway " << r.rwy_no << " heading = " << heading );
861 double lat2, lon2, az2;
862 double azimuth = heading + 180.0;
863 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
865 SG_LOG( SG_GENERAL, SG_INFO,
866 "runway = " << found_r.lon << ", " << found_r.lat
867 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
868 << " heading = " << azimuth );
870 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
872 found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
873 &lat2, &lon2, &az2 );
875 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
878 double odist = fgGetDouble("/sim/presets/offset-distance");
879 odist *= SG_NM_TO_METER;
880 double oaz = azimuth;
881 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
883 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
885 while ( oaz >= 360.0 ) { oaz -= 360.0; }
886 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
892 fgSetDouble("/sim/presets/longitude-deg", lon2 );
893 fgSetDouble("/sim/presets/latitude-deg", lat2 );
894 fgSetDouble("/sim/presets/heading-deg", heading );
896 // other code depends on the actual values being set ...
897 fgSetDouble("/position/longitude-deg", lon2 );
898 fgSetDouble("/position/latitude-deg", lat2 );
899 fgSetDouble("/orientation/heading-deg", heading );
901 SG_LOG( SG_GENERAL, SG_INFO,
902 "Position for " << id << " is ("
904 << lat2 << ") new heading is "
914 static void fgSetDistOrAltFromGlideSlope() {
915 string apt_id = fgGetString("/sim/presets/airport-id");
916 double gs = fgGetDouble("/sim/presets/glideslope-deg")
917 * SG_DEGREES_TO_RADIANS ;
918 double od = fgGetDouble("/sim/presets/offset-distance");
919 double alt = fgGetDouble("/sim/presets/altitude-ft");
921 double apt_elev = 0.0;
922 if ( ! apt_id.empty() ) {
923 apt_elev = fgGetAirportElev( apt_id );
924 if ( apt_elev < -9990.0 ) {
931 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
932 // set altitude from glideslope and offset-distance
933 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
934 alt = fabs(od*tan(gs)) + apt_elev;
935 fgSetDouble("/sim/presets/altitude-ft", alt);
936 fgSetBool("/sim/presets/onground", false);
937 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
939 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
940 // set offset-distance from glideslope and altitude
941 od = (alt - apt_elev) / tan(gs);
942 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
943 fgSetDouble("/sim/presets/offset-distance", od);
944 fgSetBool("/sim/presets/onground", false);
945 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
947 } else if( fabs(gs) > 0.01 ) {
948 SG_LOG( SG_GENERAL, SG_ALERT,
949 "Glideslope given but not altitude or offset-distance." );
950 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
951 fgSetDouble("/sim/presets/glideslope-deg", 0);
952 fgSetBool("/sim/presets/onground", true);
957 // Set current_options lon/lat given an airport id and heading (degrees)
958 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
959 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
961 // set initial position from runway and heading
963 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
964 << id << ":" << freq );
966 double lon = nav->get_lon();
967 double lat = nav->get_lat();
969 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
971 double odist = fgGetDouble("/sim/presets/offset-distance")
973 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
975 while ( oaz >= 360.0 ) { oaz -= 360.0; }
976 double olat, olon, az2;
977 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
984 fgSetDouble("/sim/presets/longitude-deg", lon );
985 fgSetDouble("/sim/presets/latitude-deg", lat );
987 // other code depends on the actual values being set ...
988 fgSetDouble("/position/longitude-deg", lon );
989 fgSetDouble("/position/latitude-deg", lat );
990 fgSetDouble("/orientation/heading-deg",
991 fgGetDouble("/sim/presets/heading-deg") );
993 SG_LOG( SG_GENERAL, SG_INFO,
994 "Position for " << id << ":" << freq << " is ("
995 << lon << ", "<< lat << ")" );
999 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
1000 << id << ":" << freq );
1006 // Set current_options lon/lat given an airport id and heading (degrees)
1007 static bool fgSetPosFromFix( const string& id ) {
1010 // set initial position from runway and heading
1011 if ( current_fixlist->query( id.c_str(), &fix ) ) {
1012 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
1015 double lon = fix.get_lon();
1016 double lat = fix.get_lat();
1018 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
1020 double odist = fgGetDouble("/sim/presets/offset-distance")
1022 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
1024 while ( oaz >= 360.0 ) { oaz -= 360.0; }
1025 double olat, olon, az2;
1026 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
1033 fgSetDouble("/sim/presets/longitude-deg", lon );
1034 fgSetDouble("/sim/presets/latitude-deg", lat );
1036 // other code depends on the actual values being set ...
1037 fgSetDouble("/position/longitude-deg", lon );
1038 fgSetDouble("/position/latitude-deg", lat );
1039 fgSetDouble("/orientation/heading-deg",
1040 fgGetDouble("/sim/presets/heading-deg") );
1042 SG_LOG( SG_GENERAL, SG_INFO,
1043 "Position for " << id << " is ("
1044 << lon << ", "<< lat << ")" );
1048 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
1055 // Set the initial position based on presets (or defaults)
1056 bool fgInitPosition() {
1057 bool set_pos = false;
1059 // If glideslope is specified, then calculate offset-distance or
1060 // altitude relative to glide slope if either of those was not
1062 fgSetDistOrAltFromGlideSlope();
1064 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1065 // If not, check for an airport-id and use that.
1066 // If not, default to the middle of the KSFO field.
1067 // The default values for lon/lat are deliberately out of range
1068 // so that the airport-id can take effect; valid lon/lat will
1069 // override airport-id, however.
1070 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1071 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1072 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1073 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1078 string apt = fgGetString("/sim/presets/airport-id");
1079 string rwy_no = fgGetString("/sim/presets/runway");
1080 double hdg = fgGetDouble("/sim/presets/heading-deg");
1081 string vor = fgGetString("/sim/presets/vor-id");
1082 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1083 string ndb = fgGetString("/sim/presets/ndb-id");
1084 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1085 string fix = fgGetString("/sim/presets/fix");
1086 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1087 // An airport + runway is requested
1088 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1089 // set position (a little off the heading for single
1091 fgSetTowerPosFromAirportID( apt, hdg );
1096 if ( !set_pos && !apt.empty() ) {
1097 // An airport is requested (find runway closest to hdg)
1098 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1099 // set position (a little off the heading for single
1101 fgSetTowerPosFromAirportID( apt, hdg );
1106 if ( !set_pos && !vor.empty() ) {
1107 // a VOR is requested
1108 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1109 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1110 fgSetBool("/sim/presets/onground", false);
1112 fgSetBool("/sim/presets/onground", true);
1117 if ( !set_pos && !ndb.empty() ) {
1118 // an NDB is requested
1119 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1120 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1121 fgSetBool("/sim/presets/onground", false);
1123 fgSetBool("/sim/presets/onground", true);
1128 if ( !set_pos && !fix.empty() ) {
1129 // a Fix is requested
1130 if ( fgSetPosFromFix( fix ) ) {
1131 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
1132 fgSetBool("/sim/presets/onground", false);
1134 fgSetBool("/sim/presets/onground", true);
1141 // No lon/lat specified, no airport specified, default to
1142 // middle of KSFO field.
1143 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1144 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1147 fgSetDouble( "/position/longitude-deg",
1148 fgGetDouble("/sim/presets/longitude-deg") );
1149 fgSetDouble( "/position/latitude-deg",
1150 fgGetDouble("/sim/presets/latitude-deg") );
1151 fgSetDouble( "/orientation/heading-deg",
1152 fgGetDouble("/sim/presets/heading-deg") );
1158 // General house keeping initializations
1159 bool fgInitGeneral() {
1162 #if defined(FX) && defined(XMESA)
1163 char *mesa_win_state;
1166 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1167 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1169 root = globals->get_fg_root();
1170 if ( ! root.length() ) {
1171 // No root path set? Then bail ...
1172 SG_LOG( SG_GENERAL, SG_ALERT,
1173 "Cannot continue without a path to the base package "
1174 << "being defined." );
1177 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1179 #if defined(FX) && defined(XMESA)
1180 // initialize full screen flag
1181 globals->set_fullscreen(false);
1182 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1183 // Test for the MESA_GLX_FX env variable
1184 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1185 // test if we are fullscreen mesa/glide
1186 if ( (mesa_win_state[0] == 'f') ||
1187 (mesa_win_state[0] == 'F') ) {
1188 globals->set_fullscreen(true);
1198 // Initialize the flight model subsystem. This just creates the
1199 // object. The actual fdm initialization is delayed until we get a
1200 // proper scenery elevation hit. This is checked for in main.cxx
1204 if ( cur_fdm_state ) {
1205 delete cur_fdm_state;
1209 double dt = 1.0 / fgGetInt("/sim/model-hz");
1210 aircraft_dir = fgGetString("/sim/aircraft-dir");
1211 const string &model = fgGetString("/sim/flight-model");
1214 if ( model == "larcsim" ) {
1215 cur_fdm_state = new FGLaRCsim( dt );
1216 } else if ( model == "jsb" ) {
1217 cur_fdm_state = new FGJSBsim( dt );
1218 } else if ( model == "ada" ) {
1219 cur_fdm_state = new FGADA( dt );
1220 } else if ( model == "balloon" ) {
1221 cur_fdm_state = new FGBalloonSim( dt );
1222 } else if ( model == "magic" ) {
1223 cur_fdm_state = new FGMagicCarpet( dt );
1224 } else if ( model == "ufo" ) {
1225 cur_fdm_state = new FGUFO( dt );
1226 } else if ( model == "external" ) {
1227 // external is a synonym for "--fdm=null" and is
1228 // maintained here for backwards compatibility
1229 cur_fdm_state = new FGNullFDM( dt );
1230 } else if ( model.find("network") == 0 ) {
1231 string host = "localhost";
1235 string net_options = model.substr(8);
1236 string::size_type begin, end;
1239 end = net_options.find( ",", begin );
1240 if ( end != string::npos ) {
1241 host = net_options.substr(begin, end - begin);
1245 end = net_options.find( ",", begin );
1246 if ( end != string::npos ) {
1247 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1251 end = net_options.find( ",", begin );
1252 if ( end != string::npos ) {
1253 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1257 end = net_options.find( ",", begin );
1258 if ( end != string::npos ) {
1259 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1262 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1263 } else if ( model == "null" ) {
1264 cur_fdm_state = new FGNullFDM( dt );
1265 } else if ( model == "yasim" ) {
1266 cur_fdm_state = new YASim( dt );
1268 SG_LOG(SG_GENERAL, SG_ALERT,
1269 "Unrecognized flight model '" << model
1270 << "', cannot init flight dynamics model.");
1274 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1279 static void printMat(const sgVec4 *mat, char *name="")
1282 cout << name << endl;
1283 for(i=0; i<4; i++) {
1284 cout <<" "<<mat[i][0]<<" "<<mat[i][1]<<" "<<mat[i][2]<<" "<<mat[i][3]<<endl;
1289 // Initialize view parameters
1291 // force update of model so that viewer can get some data...
1292 globals->get_aircraft_model()->update(0);
1293 // run update for current view so that data is current...
1294 globals->get_viewmgr()->update(0);
1296 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1297 printMat(globals->get_current_view()->get_UP(),"UP");
1298 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1303 SGTime *fgInitTime() {
1305 static const SGPropertyNode *longitude
1306 = fgGetNode("/position/longitude-deg");
1307 static const SGPropertyNode *latitude
1308 = fgGetNode("/position/latitude-deg");
1309 static const SGPropertyNode *cur_time_override
1310 = fgGetNode("/sim/time/cur-time-override", true);
1312 SGPath zone( globals->get_fg_root() );
1313 zone.append( "Timezone" );
1314 SGTime *t = new SGTime( longitude->getDoubleValue()
1315 * SGD_DEGREES_TO_RADIANS,
1316 latitude->getDoubleValue()
1317 * SGD_DEGREES_TO_RADIANS,
1319 cur_time_override->getLongValue() );
1321 // Handle potential user specified time offsets
1322 time_t cur_time = t->get_cur_time();
1323 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1324 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1325 time_t aircraftLocalTime =
1326 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1328 // Okay, we now have six possible scenarios
1329 int offset = fgGetInt("/sim/startup/time-offset");
1330 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1331 if (offset_type == "system-offset") {
1332 globals->set_warp( offset );
1333 } else if (offset_type == "gmt-offset") {
1334 globals->set_warp( offset - (currGMT - systemLocalTime) );
1335 } else if (offset_type == "latitude-offset") {
1336 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1337 } else if (offset_type == "system") {
1338 globals->set_warp( offset - cur_time );
1339 } else if (offset_type == "gmt") {
1340 globals->set_warp( offset - currGMT );
1341 } else if (offset_type == "latitude") {
1342 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1345 SG_LOG( SG_GENERAL, SG_ALERT,
1346 "FG_TIME::Unsupported offset type " << offset_type );
1350 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1351 << globals->get_warp() );
1353 globals->set_warp_delta( 0 );
1355 t->update( 0.0, 0.0,
1356 cur_time_override->getLongValue(),
1357 globals->get_warp() );
1363 // This is the top level init routine which calls all the other
1364 // initialization routines. If you are adding a subsystem to flight
1365 // gear, its initialization call should located in this routine.
1366 // Returns non-zero if a problem encountered.
1367 bool fgInitSubsystems() {
1368 static const SGPropertyNode *longitude
1369 = fgGetNode("/sim/presets/longitude-deg");
1370 static const SGPropertyNode *latitude
1371 = fgGetNode("/sim/presets/latitude-deg");
1372 static const SGPropertyNode *altitude
1373 = fgGetNode("/sim/presets/altitude-ft");
1375 fgLIGHT *l = &cur_light_params;
1377 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1378 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1381 ////////////////////////////////////////////////////////////////////
1382 // Initialize the material property subsystem.
1383 ////////////////////////////////////////////////////////////////////
1385 SGPath mpath( globals->get_fg_root() );
1386 mpath.append( "materials.xml" );
1387 if ( ! material_lib.load( mpath.str() ) ) {
1388 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1392 ////////////////////////////////////////////////////////////////////
1393 // Initialize the event manager subsystem.
1394 ////////////////////////////////////////////////////////////////////
1396 global_events.init();
1398 // Output event stats every 60 seconds
1399 global_events.Register( "FGEventMgr::print_stats()",
1400 &global_events, &FGEventMgr::print_stats,
1404 ////////////////////////////////////////////////////////////////////
1405 // Initialize the scenery management subsystem.
1406 ////////////////////////////////////////////////////////////////////
1408 if ( globals->get_tile_mgr()->init() ) {
1409 // Load the local scenery data
1410 double visibility_meters = fgGetDouble("/environment/visibility-m");
1412 globals->get_tile_mgr()->update( visibility_meters );
1414 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1418 // cause refresh of viewer scenery timestamps every 15 seconds...
1419 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1420 globals->get_tile_mgr(),
1421 &FGTileMgr::refresh_view_timestamps,
1424 SG_LOG( SG_GENERAL, SG_DEBUG,
1425 "Current terrain elevation after tile mgr init " <<
1426 globals->get_scenery()->get_cur_elev() );
1429 ////////////////////////////////////////////////////////////////////
1430 // Initialize the flight model subsystem.
1431 ////////////////////////////////////////////////////////////////////
1435 // allocates structures so must happen before any of the flight
1436 // model or control parameters are set
1437 fgAircraftInit(); // In the future this might not be the case.
1440 ////////////////////////////////////////////////////////////////////
1441 // Initialize the view manager subsystem.
1442 ////////////////////////////////////////////////////////////////////
1447 ////////////////////////////////////////////////////////////////////
1448 // Initialize the lighting subsystem.
1449 ////////////////////////////////////////////////////////////////////
1451 // fgUpdateSunPos() needs a few position and view parameters set
1452 // so it can calculate local relative sun angle and a few other
1453 // things for correctly orienting the sky.
1456 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1458 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1461 // Initialize Lighting interpolation tables
1464 // force one lighting update to make it right to start with...
1466 // update the lighting parameters (based on sun angle)
1467 global_events.Register( "fgLight::Update()",
1468 &cur_light_params, &fgLIGHT::Update,
1472 ////////////////////////////////////////////////////////////////////
1473 // Create and register the logger.
1474 ////////////////////////////////////////////////////////////////////
1476 globals->add_subsystem("logger", new FGLogger);
1479 #if defined(HAVE_PLIB_PSL)
1480 ////////////////////////////////////////////////////////////////////
1481 // Create and register the script manager.
1482 ////////////////////////////////////////////////////////////////////
1484 globals->add_subsystem("scripting", new FGScriptMgr);
1485 #endif // HAVE_PLIB_PSL
1488 ////////////////////////////////////////////////////////////////////
1489 // Create and register the XML GUI.
1490 ////////////////////////////////////////////////////////////////////
1492 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1495 ////////////////////////////////////////////////////////////////////
1496 // Initialize the local time subsystem.
1497 ////////////////////////////////////////////////////////////////////
1499 // update the current timezone each 30 minutes
1500 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1504 ////////////////////////////////////////////////////////////////////
1505 // Initialize the weather subsystem.
1506 ////////////////////////////////////////////////////////////////////
1508 // Initialize the weather modeling subsystem
1510 // Initialize the WeatherDatabase
1511 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1513 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1514 current_aircraft.fdm_state->get_Longitude(),
1515 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1516 double init_vis = fgGetDouble("/environment/visibility-m");
1518 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1520 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1522 working_type = FGLocalWeatherDatabase::use_internet;
1524 working_type = FGLocalWeatherDatabase::default_mode;
1527 if ( init_vis > 0 ) {
1528 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1529 new FGLocalWeatherDatabase( position,
1530 globals->get_fg_root(),
1534 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1535 new FGLocalWeatherDatabase( position,
1536 globals->get_fg_root(),
1540 // cout << theFGLocalWeatherDatabase << endl;
1541 // cout << "visibility = "
1542 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1544 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1546 // register the periodic update of the weather
1547 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1550 globals->get_environment_mgr()->init();
1551 globals->get_environment_mgr()->bind();
1554 #ifdef FG_USE_CLOUDS_3D
1555 ////////////////////////////////////////////////////////////////////
1556 // Initialize the 3D cloud subsystem.
1557 ////////////////////////////////////////////////////////////////////
1558 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1559 SGPath cloud_path(globals->get_fg_root());
1560 cloud_path.append("large.sky");
1561 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1562 if ( !sgCloud3d->Load( cloud_path.str(),
1563 latitude->getDoubleValue(),
1564 longitude->getDoubleValue()) )
1566 fgSetBool("/sim/rendering/clouds3d", false);
1567 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1569 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1573 ////////////////////////////////////////////////////////////////////
1574 // Initialize vor/ndb/ils/fix list management and query systems
1575 ////////////////////////////////////////////////////////////////////
1577 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
1579 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
1580 current_navlist = new FGNavList;
1581 SGPath p_nav( globals->get_fg_root() );
1582 p_nav.append( "Navaids/default.nav" );
1583 current_navlist->init( p_nav );
1585 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
1586 current_beacons = new FGMarkerBeacons;
1587 current_beacons->init();
1588 current_ilslist = new FGILSList;
1589 SGPath p_ils( globals->get_fg_root() );
1590 p_ils.append( "Navaids/default.ils" );
1591 current_ilslist->init( p_ils );
1593 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1594 current_fixlist = new FGFixList;
1595 SGPath p_fix( globals->get_fg_root() );
1596 p_fix.append( "Navaids/default.fix" );
1597 current_fixlist->init( p_fix );
1599 ////////////////////////////////////////////////////////////////////
1600 // Initialise ATC display system
1601 ////////////////////////////////////////////////////////////////////
1603 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1604 globals->set_ATC_display(new FGATCDisplay);
1605 globals->get_ATC_display()->init();
1607 ////////////////////////////////////////////////////////////////////
1608 // Initialise the ATC Manager
1609 ////////////////////////////////////////////////////////////////////
1611 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1612 globals->set_ATC_mgr(new FGATCMgr);
1613 globals->get_ATC_mgr()->init();
1615 ////////////////////////////////////////////////////////////////////
1616 // Initialise the AI Manager
1617 ////////////////////////////////////////////////////////////////////
1619 if (fgGetBool("/sim/ai-traffic/enabled")) {
1620 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1621 globals->set_AI_mgr(new FGAIMgr);
1622 globals->get_AI_mgr()->init();
1625 #ifdef ENABLE_AUDIO_SUPPORT
1626 ////////////////////////////////////////////////////////////////////
1627 // Initialize the sound subsystem.
1628 ////////////////////////////////////////////////////////////////////
1630 globals->set_soundmgr(new FGSoundMgr);
1631 globals->get_soundmgr()->init();
1632 globals->get_soundmgr()->bind();
1635 ////////////////////////////////////////////////////////////////////
1636 // Initialize the sound-effects subsystem.
1637 ////////////////////////////////////////////////////////////////////
1639 globals->add_subsystem("fx", new FGFX);
1643 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1644 globals->add_subsystem("systems", new FGSystemMgr);
1646 ////////////////////////////////////////////////////////////////////
1647 // Initialize the radio stack subsystem.
1648 ////////////////////////////////////////////////////////////////////
1650 current_radiostack = new FGRadioStack;
1651 current_radiostack->init();
1652 current_radiostack->bind();
1655 ////////////////////////////////////////////////////////////////////
1656 // Initialize the cockpit subsystem
1657 ////////////////////////////////////////////////////////////////////
1659 if( fgCockpitInit( ¤t_aircraft )) {
1660 // Cockpit initialized ok.
1662 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1667 ////////////////////////////////////////////////////////////////////
1668 // Initialize the autopilot subsystem.
1669 ////////////////////////////////////////////////////////////////////
1671 globals->set_autopilot(new FGAutopilot);
1672 globals->get_autopilot()->init();
1673 globals->get_autopilot()->bind();
1675 // FIXME: these should go in the
1676 // GUI initialization code, not here.
1678 NewTgtAirportInit();
1682 ////////////////////////////////////////////////////////////////////
1683 // Initialize I/O subsystem.
1684 ////////////////////////////////////////////////////////////////////
1686 globals->get_io()->init();
1687 globals->get_io()->bind();
1689 // Initialize the 2D panel.
1690 string panel_path = fgGetString("/sim/panel/path",
1691 "Panels/Default/default.xml");
1692 current_panel = fgReadPanel(panel_path);
1693 if (current_panel == 0) {
1694 SG_LOG( SG_INPUT, SG_ALERT,
1695 "Error reading new panel from " << panel_path );
1697 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1698 current_panel->init();
1699 current_panel->bind();
1703 ////////////////////////////////////////////////////////////////////
1704 // Initialize the default (kludged) properties.
1705 ////////////////////////////////////////////////////////////////////
1710 ////////////////////////////////////////////////////////////////////
1711 // Initialize the controls subsystem.
1712 ////////////////////////////////////////////////////////////////////
1714 globals->get_controls()->init();
1715 globals->get_controls()->bind();
1718 ////////////////////////////////////////////////////////////////////
1719 // Initialize the input subsystem.
1720 ////////////////////////////////////////////////////////////////////
1722 globals->add_subsystem("input", new FGInput);
1725 ////////////////////////////////////////////////////////////////////
1726 // Bind and initialize subsystems.
1727 ////////////////////////////////////////////////////////////////////
1729 globals->get_subsystem_mgr()->bind();
1730 globals->get_subsystem_mgr()->init();
1733 ////////////////////////////////////////////////////////////////////////
1734 // End of subsystem initialization.
1735 ////////////////////////////////////////////////////////////////////
1737 SG_LOG( SG_GENERAL, SG_INFO, endl);
1739 // Save the initial state for future
1741 globals->saveInitialState();
1747 void fgReInitSubsystems()
1749 static const SGPropertyNode *longitude
1750 = fgGetNode("/sim/presets/longitude-deg");
1751 static const SGPropertyNode *latitude
1752 = fgGetNode("/sim/presets/latitude-deg");
1753 static const SGPropertyNode *altitude
1754 = fgGetNode("/sim/presets/altitude-ft");
1755 static const SGPropertyNode *master_freeze
1756 = fgGetNode("/sim/freeze/master");
1758 SG_LOG( SG_GENERAL, SG_INFO,
1759 "fgReInitSubsystems(): /position/altitude = "
1760 << altitude->getDoubleValue() );
1762 bool freeze = master_freeze->getBoolValue();
1764 fgSetBool("/sim/freeze/master", true);
1767 // Initialize the FDM
1770 // allocates structures so must happen before any of the flight
1771 // model or control parameters are set
1772 fgAircraftInit(); // In the future this might not be the case.
1774 // reload offsets from config defaults
1775 globals->get_viewmgr()->reinit();
1779 globals->get_controls()->reset_all();
1780 globals->get_autopilot()->reset();
1784 cur_light_params.Update();
1785 fgUpdateLocalTime();
1788 fgSetBool("/sim/freeze/master", false);