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
36 #include <string.h> // strcmp()
39 #if defined( unix ) || defined( __CYGWIN__ )
40 # include <unistd.h> // for gethostname()
43 // work around a stdc++ lib bug in some versions of linux, but doesn't
44 // seem to hurt to have this here for all versions of Linux.
46 # define _G_NO_EXTERN_TEMPLATES
49 #include <simgear/compiler.h>
50 #include <simgear/misc/exception.hxx>
54 #include <simgear/constants.h>
55 #include <simgear/debug/logstream.hxx>
56 #include <simgear/math/point3d.hxx>
57 #include <simgear/math/polar3d.hxx>
58 #include <simgear/math/sg_geodesy.hxx>
59 #include <simgear/misc/sg_path.hxx>
60 #include <simgear/scene/material/matlib.hxx>
61 #ifdef FG_USE_CLOUDS_3D
62 # include <simgear/scene/sky/clouds3d/SkySceneLoader.hpp>
63 # include <simgear/scene/sky/clouds3d/SkyUtil.hpp>
64 # include <simgear/screen/texture.hxx>
66 #include <simgear/timing/sg_time.hxx>
67 #include <simgear/timing/lowleveltime.h>
69 #include <Aircraft/aircraft.hxx>
70 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
71 #include <Airports/runways.hxx>
72 #include <Airports/simple.hxx>
73 #include <ATC/ATCdisplay.hxx>
74 #include <ATC/ATCmgr.hxx>
75 #include <ATC/AIMgr.hxx>
76 #include <Autopilot/auto_gui.hxx>
77 #include <Autopilot/newauto.hxx>
78 #include <Cockpit/cockpit.hxx>
79 #include <Cockpit/radiostack.hxx>
80 #include <Cockpit/panel.hxx>
81 #include <Cockpit/panel_io.hxx>
82 #include <FDM/ADA.hxx>
83 #include <FDM/Balloon.h>
84 #include <FDM/ExternalNet/ExternalNet.hxx>
85 #include <FDM/ExternalPipe/ExternalPipe.hxx>
86 #include <FDM/JSBSim/JSBSim.hxx>
87 #include <FDM/LaRCsim/LaRCsim.hxx>
88 #include <FDM/MagicCarpet.hxx>
89 #include <FDM/UFO.hxx>
90 #include <FDM/NullFDM.hxx>
91 #include <FDM/YASim/YASim.hxx>
92 #include <GUI/new_gui.hxx>
93 #include <Include/general.hxx>
94 #include <Input/input.hxx>
95 #include <Instrumentation/instrument_mgr.hxx>
96 #include <Model/acmodel.hxx>
97 #include <Navaids/fixlist.hxx>
98 #include <Navaids/ilslist.hxx>
99 #include <Navaids/mkrbeacons.hxx>
100 #include <Navaids/navlist.hxx>
101 #include <Replay/replay.hxx>
102 #include <Scenery/scenery.hxx>
103 #include <Scenery/tilemgr.hxx>
104 #if defined(HAVE_PLIB_PSL)
105 #include <Scripting/scriptmgr.hxx>
107 #include <Sound/fg_fx.hxx>
108 #include <Systems/system_mgr.hxx>
109 #include <Time/FGEventMgr.hxx>
110 #include <Time/light.hxx>
111 #include <Time/sunpos.hxx>
112 #include <Time/moonpos.hxx>
113 #include <Time/tmp.hxx>
116 #include <MultiPlayer/multiplaytxmgr.hxx>
117 #include <MultiPlayer/multiplayrxmgr.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);
144 extern const char *default_root;
146 #ifdef FG_USE_CLOUDS_3D
147 SkySceneLoader *sgCloud3d;
151 // Scan the command line options for the specified option and return
153 static string fgScanForOption( const string& option, int argc, char **argv ) {
156 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
158 int len = option.length();
161 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
163 string arg = argv[i];
164 if ( arg.find( option ) == 0 ) {
165 return arg.substr( len );
175 // Scan the user config files for the specified option and return
177 static string fgScanForOption( const string& option, const string& path ) {
178 sg_gzifstream in( path );
179 if ( !in.is_open() ) {
183 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
185 int len = option.length();
189 while ( ! in.eof() ) {
192 while ( in.get(c) && c != '\0' ) {
197 #if defined( macintosh )
198 getline( in, line, '\r' );
200 getline( in, line, '\n' );
203 // catch extraneous (DOS) line ending character
204 if ( line[line.length() - 1] < 32 ) {
205 line = line.substr( 0, line.length()-1 );
208 if ( line.find( option ) == 0 ) {
209 return line.substr( len );
219 // Read in configuration (files and command line options) but only set
221 bool fgInitFGRoot ( int argc, char **argv ) {
225 // First parse command line options looking for --fg-root=, this
226 // will override anything specified in a config file
227 root = fgScanForOption( "--fg-root=", argc, argv);
229 #if defined( unix ) || defined( __CYGWIN__ )
230 // Next check home directory for .fgfsrc.hostname file
231 if ( root.empty() ) {
232 envp = ::getenv( "HOME" );
233 if ( envp != NULL ) {
234 SGPath config( envp );
235 config.append( ".fgfsrc" );
237 gethostname( name, 256 );
238 config.concat( "." );
239 config.concat( name );
240 root = fgScanForOption( "--fg-root=", config.str() );
245 // Next check home directory for .fgfsrc file
246 if ( root.empty() ) {
247 envp = ::getenv( "HOME" );
248 if ( envp != NULL ) {
249 SGPath config( envp );
250 config.append( ".fgfsrc" );
251 root = fgScanForOption( "--fg-root=", config.str() );
255 // Next check if fg-root is set as an env variable
256 if ( root.empty() ) {
257 envp = ::getenv( "FG_ROOT" );
258 if ( envp != NULL ) {
263 // Otherwise, default to a random compiled-in location if we can't
264 // find fg-root any other way.
265 if ( root.empty() ) {
266 #if defined( __CYGWIN__ )
267 root = "/FlightGear";
268 #elif defined( WIN32 )
269 root = "\\FlightGear";
270 #elif defined( macintosh )
277 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
278 globals->set_fg_root(root);
284 // Read in configuration (files and command line options) but only set
286 bool fgInitFGAircraft ( int argc, char **argv ) {
290 // First parse command line options looking for --aircraft=, this
291 // will override anything specified in a config file
292 aircraft = fgScanForOption( "--aircraft=", argc, argv );
294 #if defined( unix ) || defined( __CYGWIN__ )
295 // Next check home directory for .fgfsrc.hostname file
296 if ( aircraft.empty() ) {
297 envp = ::getenv( "HOME" );
298 if ( envp != NULL ) {
299 SGPath config( envp );
300 config.append( ".fgfsrc" );
302 gethostname( name, 256 );
303 config.concat( "." );
304 config.concat( name );
305 aircraft = fgScanForOption( "--aircraft=", config.str() );
310 // Next check home directory for .fgfsrc file
311 if ( aircraft.empty() ) {
312 envp = ::getenv( "HOME" );
313 if ( envp != NULL ) {
314 SGPath config( envp );
315 config.append( ".fgfsrc" );
316 aircraft = fgScanForOption( "--aircraft=", config.str() );
320 // if an aircraft was specified, set the property name
321 if ( !aircraft.empty() ) {
322 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
323 fgSetString("/sim/aircraft", aircraft.c_str() );
325 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
332 // Return the current base package version
333 string fgBasePackageVersion() {
334 SGPath base_path( globals->get_fg_root() );
335 base_path.append("version");
337 sg_gzifstream in( base_path.str() );
338 if ( !in.is_open() ) {
339 SGPath old_path( globals->get_fg_root() );
340 old_path.append( "Thanks" );
341 sg_gzifstream old( old_path.str() );
342 if ( !old.is_open() ) {
345 return "[old version]";
356 // Initialize the localization
357 SGPropertyNode *fgInitLocale(const char *language) {
358 SGPropertyNode *c_node = NULL, *d_node = NULL;
359 SGPropertyNode *intl = fgGetNode("/sim/intl");
361 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
363 // localization not defined
368 // Select the proper language from the list
370 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
371 for (unsigned int i = 0; i < locale.size(); i++) {
373 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
374 for (unsigned int j = 0; j < lang.size(); j++) {
376 if (!strcmp(lang[j]->getStringValue(), language)) {
385 d_node = intl->getChild("locale");
389 // Check for localized font
390 SGPropertyNode *font_n = c_node->getNode("font", true);
391 if ( !strcmp(font_n->getStringValue(), "") )
392 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
396 // Load the default strings
398 SGPath d_path( globals->get_fg_root() );
400 const char *d_path_str = d_node->getStringValue("strings");
402 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
406 d_path.append(d_path_str);
407 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
410 SGPropertyNode *strings = c_node->getNode("strings");
412 readProperties(d_path.str(), strings);
413 } catch (const sg_exception &e) {
414 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
419 // Load the language specific strings
421 if (c_node != d_node) {
422 SGPath c_path( globals->get_fg_root() );
424 const char *c_path_str = c_node->getStringValue("strings");
426 SG_LOG(SG_GENERAL, SG_ALERT, "Incorrect path in configuration file.");
430 c_path.append(c_path_str);
431 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from "
435 readProperties(c_path.str(), strings);
436 } catch (const sg_exception &e) {
437 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
447 // Initialize the localization routines
448 bool fgDetectLanguage() {
449 char *language = ::getenv("LANG");
451 if (language == NULL) {
452 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
456 SGPropertyNode *locale = fgInitLocale(language);
458 SG_LOG(SG_GENERAL, SG_ALERT,
459 "No internationalization settings specified in preferences.xml" );
464 globals->set_locale( locale );
469 // Attempt to locate and parse the various non-XML config files in order
470 // from least precidence to greatest precidence
472 do_options (int argc, char ** argv)
474 // Check for $fg_root/system.fgfsrc
475 SGPath config( globals->get_fg_root() );
476 config.append( "system.fgfsrc" );
477 fgParseOptions(config.str());
479 #if defined( unix ) || defined( __CYGWIN__ )
481 // Check for $fg_root/system.fgfsrc.hostname
482 gethostname( name, 256 );
483 config.concat( "." );
484 config.concat( name );
485 fgParseOptions(config.str());
488 // Check for ~/.fgfsrc
489 char* envp = ::getenv( "HOME" );
490 if ( envp != NULL ) {
492 config.append( ".fgfsrc" );
493 fgParseOptions(config.str());
496 #if defined( unix ) || defined( __CYGWIN__ )
497 // Check for ~/.fgfsrc.hostname
498 gethostname( name, 256 );
499 config.concat( "." );
500 config.concat( name );
501 fgParseOptions(config.str());
504 // Parse remaining command line options
505 // These will override anything specified in a config file
506 fgParseArgs(argc, argv);
510 // Read in configuration (file and command line)
511 bool fgInitConfig ( int argc, char **argv ) {
513 // First, set some sane default values
516 // Read global preferences from $FG_ROOT/preferences.xml
517 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
518 fgLoadProps("preferences.xml", globals->get_props());
519 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
521 // Detect the required language as early as possible
522 if ( !fgDetectLanguage() ) {
526 // Scan user config files and command line for a specified aircraft.
527 fgInitFGAircraft(argc, argv);
529 string aircraft = fgGetString("/sim/aircraft", "");
530 if ( aircraft.size() > 0 ) {
531 SGPath aircraft_path(globals->get_fg_root());
532 aircraft_path.append("Aircraft");
533 aircraft_path.append(aircraft);
534 aircraft_path.concat("-set.xml");
535 SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
536 << " from " << aircraft_path.str());
538 readProperties(aircraft_path.str(), globals->get_props());
539 } catch (const sg_exception &e) {
540 string message = "Error reading default aircraft: ";
541 message += e.getFormattedMessage();
542 SG_LOG(SG_INPUT, SG_ALERT, message);
546 SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
549 // parse options after loading aircraft to ensure any user
550 // overrides of defaults are honored.
551 do_options(argc, argv);
557 // find basic airport location info from airport database
558 bool fgFindAirportID( const string& id, FGAirport *a ) {
561 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
563 result = globals->get_airports()->search( id );
565 if ( result.id.empty() ) {
566 SG_LOG( SG_GENERAL, SG_ALERT,
567 "Failed to find " << id << " in simple.apt.gz" );
576 SG_LOG( SG_GENERAL, SG_INFO,
577 "Position for " << id << " is ("
578 << a->longitude << ", "
579 << a->latitude << ")" );
585 // get airport elevation
586 static double fgGetAirportElev( const string& id ) {
590 SG_LOG( SG_GENERAL, SG_INFO,
591 "Finding elevation for airport: " << id );
593 if ( fgFindAirportID( id, &a ) ) {
601 // Preset lon/lat given an airport id
602 static bool fgSetPosFromAirportID( const string& id ) {
606 SG_LOG( SG_GENERAL, SG_INFO,
607 "Attempting to set starting position from airport code " << id );
609 if ( fgFindAirportID( id, &a ) ) {
611 fgSetDouble("/sim/presets/longitude-deg", a.longitude );
612 fgSetDouble("/sim/presets/latitude-deg", a.latitude );
614 // other code depends on the actual postition being set so set
616 fgSetDouble("/position/longitude-deg", a.longitude );
617 fgSetDouble("/position/latitude-deg", a.latitude );
619 SG_LOG( SG_GENERAL, SG_INFO,
620 "Position for " << id << " is (" << a.longitude
621 << ", " << a.latitude << ")" );
630 // Set current tower position lon/lat given an airport id
631 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
633 // tower height hard coded for now...
634 float towerheight=50.0f;
636 // make a little off the heading for 1 runway airports...
637 float fudge_lon = fabs(sin(hdg)) * .003f;
638 float fudge_lat = .003f - fudge_lon;
640 if ( fgFindAirportID( id, &a ) ) {
641 fgSetDouble("/sim/tower/longitude-deg", a.longitude + fudge_lon);
642 fgSetDouble("/sim/tower/latitude-deg", a.latitude + fudge_lat);
643 fgSetDouble("/sim/tower/altitude-ft", a.elevation + towerheight);
652 // Set current_options lon/lat given an airport id and heading (degrees)
653 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
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 airport code "
666 << id << " heading " << tgt_hdg );
668 if ( ! runways.search( id, (int)tgt_hdg, &r ) ) {
669 SG_LOG( SG_GENERAL, SG_ALERT,
670 "Failed to find a good runway for " << id << '\n' );
677 double lat2, lon2, az2;
678 double heading = r.heading;
679 double azimuth = heading + 180.0;
680 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
682 SG_LOG( SG_GENERAL, SG_INFO,
683 "runway = " << r.lon << ", " << r.lat
684 << " length = " << r.length * SG_FEET_TO_METER
685 << " heading = " << azimuth );
687 geo_direct_wgs_84 ( 0, r.lat, r.lon, azimuth,
688 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
689 &lat2, &lon2, &az2 );
691 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON ) {
693 double odist = fgGetDouble("/sim/presets/offset-distance");
694 odist *= SG_NM_TO_METER;
695 double oaz = azimuth;
696 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON ) {
697 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
700 while ( oaz >= 360.0 ) { oaz -= 360.0; }
701 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
707 fgSetDouble("/sim/presets/longitude-deg", lon2 );
708 fgSetDouble("/sim/presets/latitude-deg", lat2 );
709 fgSetDouble("/sim/presets/heading-deg", heading );
711 // other code depends on the actual values being set ...
712 fgSetDouble("/position/longitude-deg", lon2 );
713 fgSetDouble("/position/latitude-deg", lat2 );
714 fgSetDouble("/orientation/heading-deg", heading );
716 SG_LOG( SG_GENERAL, SG_INFO,
717 "Position for " << id << " is ("
719 << lat2 << ") new heading is "
726 // Set current_options lon/lat given an airport id and runway number
727 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
731 // set initial position from airport and runway number
733 SGPath path( globals->get_fg_root() );
734 path.append( "Airports" );
735 path.append( "runways.mk4" );
736 FGRunways runways( path.c_str() );
738 SG_LOG( SG_GENERAL, SG_INFO,
739 "Attempting to set starting position for "
740 << id << ":" << rwy );
742 if ( ! runways.search( id, rwy, &r ) ) {
743 SG_LOG( SG_GENERAL, SG_ALERT,
744 "Failed to find runway " << rwy <<
745 " at airport " << id );
752 double lat2, lon2, az2;
753 double heading = r.heading;
754 double azimuth = heading + 180.0;
755 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
757 SG_LOG( SG_GENERAL, SG_INFO,
758 "runway = " << r.lon << ", " << r.lat
759 << " length = " << r.length * SG_FEET_TO_METER
760 << " heading = " << azimuth );
762 geo_direct_wgs_84 ( 0, r.lat, r.lon,
764 r.length * SG_FEET_TO_METER * 0.5 - 5.0,
765 &lat2, &lon2, &az2 );
767 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
770 double odist = fgGetDouble("/sim/presets/offset-distance");
771 odist *= SG_NM_TO_METER;
772 double oaz = azimuth;
773 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth")) > SG_EPSILON )
775 oaz = fgGetDouble("/sim/presets/offset-azimuth") + 180;
776 heading = fgGetDouble("/sim/presets/heading-deg");
778 while ( oaz >= 360.0 ) { oaz -= 360.0; }
779 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
785 fgSetDouble("/sim/presets/longitude-deg", lon2 );
786 fgSetDouble("/sim/presets/latitude-deg", lat2 );
787 fgSetDouble("/sim/presets/heading-deg", heading );
789 // other code depends on the actual values being set ...
790 fgSetDouble("/position/longitude-deg", lon2 );
791 fgSetDouble("/position/latitude-deg", lat2 );
792 fgSetDouble("/orientation/heading-deg", heading );
794 SG_LOG( SG_GENERAL, SG_INFO,
795 "Position for " << id << " is ("
797 << lat2 << ") new heading is "
804 static void fgSetDistOrAltFromGlideSlope() {
805 string apt_id = fgGetString("/sim/presets/airport-id");
806 double gs = fgGetDouble("/sim/presets/glideslope-deg")
807 * SG_DEGREES_TO_RADIANS ;
808 double od = fgGetDouble("/sim/presets/offset-distance");
809 double alt = fgGetDouble("/sim/presets/altitude-ft");
811 double apt_elev = 0.0;
812 if ( ! apt_id.empty() ) {
813 apt_elev = fgGetAirportElev( apt_id );
814 if ( apt_elev < -9990.0 ) {
821 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
822 // set altitude from glideslope and offset-distance
823 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
824 alt = fabs(od*tan(gs)) + apt_elev;
825 fgSetDouble("/sim/presets/altitude-ft", alt);
826 fgSetBool("/sim/presets/onground", false);
827 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
829 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
830 // set offset-distance from glideslope and altitude
831 od = (alt - apt_elev) / tan(gs);
832 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
833 fgSetDouble("/sim/presets/offset-distance", od);
834 fgSetBool("/sim/presets/onground", false);
835 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
837 } else if( fabs(gs) > 0.01 ) {
838 SG_LOG( SG_GENERAL, SG_ALERT,
839 "Glideslope given but not altitude or offset-distance." );
840 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
841 fgSetDouble("/sim/presets/glideslope-deg", 0);
842 fgSetBool("/sim/presets/onground", true);
847 // Set current_options lon/lat given an airport id and heading (degrees)
848 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
849 FGNav *nav = current_navlist->findByIdentAndFreq( id.c_str(), freq );
851 // set initial position from runway and heading
853 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
854 << id << ":" << freq );
856 double lon = nav->get_lon();
857 double lat = nav->get_lat();
859 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
861 double odist = fgGetDouble("/sim/presets/offset-distance")
863 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
865 while ( oaz >= 360.0 ) { oaz -= 360.0; }
866 double olat, olon, az2;
867 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
874 fgSetDouble("/sim/presets/longitude-deg", lon );
875 fgSetDouble("/sim/presets/latitude-deg", lat );
877 // other code depends on the actual values being set ...
878 fgSetDouble("/position/longitude-deg", lon );
879 fgSetDouble("/position/latitude-deg", lat );
880 fgSetDouble("/orientation/heading-deg",
881 fgGetDouble("/sim/presets/heading-deg") );
883 SG_LOG( SG_GENERAL, SG_INFO,
884 "Position for " << id << ":" << freq << " is ("
885 << lon << ", "<< lat << ")" );
889 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
890 << id << ":" << freq );
896 // Set current_options lon/lat given an airport id and heading (degrees)
897 static bool fgSetPosFromFix( const string& id ) {
900 // set initial position from runway and heading
901 if ( current_fixlist->query( id.c_str(), &fix ) ) {
902 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
905 double lon = fix.get_lon();
906 double lat = fix.get_lat();
908 if ( fabs( fgGetDouble("/sim/presets/offset-distance") ) > SG_EPSILON )
910 double odist = fgGetDouble("/sim/presets/offset-distance")
912 double oaz = fabs(fgGetDouble("/sim/presets/offset-azimuth"))
914 while ( oaz >= 360.0 ) { oaz -= 360.0; }
915 double olat, olon, az2;
916 geo_direct_wgs_84 ( 0, lat, lon, oaz, odist, &olat, &olon, &az2 );
923 fgSetDouble("/sim/presets/longitude-deg", lon );
924 fgSetDouble("/sim/presets/latitude-deg", lat );
926 // other code depends on the actual values being set ...
927 fgSetDouble("/position/longitude-deg", lon );
928 fgSetDouble("/position/latitude-deg", lat );
929 fgSetDouble("/orientation/heading-deg",
930 fgGetDouble("/sim/presets/heading-deg") );
932 SG_LOG( SG_GENERAL, SG_INFO,
933 "Position for " << id << " is ("
934 << lon << ", "<< lat << ")" );
938 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
946 * Initialize vor/ndb/ils/fix list management and query systems (as
947 * well as simple airport db list)
952 SG_LOG(SG_GENERAL, SG_INFO, "Loading Simple Airport List");
953 SGPath p_simple( globals->get_fg_root() );
954 p_simple.append( "Airports/simple.apt" );
955 FGAirportList *airports = new FGAirportList( p_simple.str() );
956 globals->set_airports( airports );
958 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
960 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
961 current_navlist = new FGNavList;
962 SGPath p_nav( globals->get_fg_root() );
963 p_nav.append( "Navaids/default.nav" );
964 current_navlist->init( p_nav );
966 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
967 current_beacons = new FGMarkerBeacons;
968 current_beacons->init();
969 current_ilslist = new FGILSList;
970 SGPath p_ils( globals->get_fg_root() );
971 p_ils.append( "Navaids/default.ils" );
972 current_ilslist->init( p_ils );
974 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
975 current_fixlist = new FGFixList;
976 SGPath p_fix( globals->get_fg_root() );
977 p_fix.append( "Navaids/default.fix" );
978 current_fixlist->init( p_fix );
984 // Set the initial position based on presets (or defaults)
985 bool fgInitPosition() {
986 bool set_pos = false;
988 // If glideslope is specified, then calculate offset-distance or
989 // altitude relative to glide slope if either of those was not
991 if ( fgGetDouble("/sim/presets/glideslope-deg") > 0.1 ) {
992 fgSetDistOrAltFromGlideSlope();
995 // Select ground or air start depending on if an altitude is
996 // specified (this choice can be refined later based on other
998 if ( fgGetDouble("/sim/presets/altitude-ft") > -9990.0 ) {
999 fgSetBool("/sim/presets/onground", false);
1001 fgSetBool("/sim/presets/onground", true);
1004 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1005 // If not, check for an airport-id and use that.
1006 // If not, default to the middle of the KSFO field.
1007 // The default values for lon/lat are deliberately out of range
1008 // so that the airport-id can take effect; valid lon/lat will
1009 // override airport-id, however.
1010 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1011 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1012 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1013 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1018 string apt = fgGetString("/sim/presets/airport-id");
1019 string rwy_no = fgGetString("/sim/presets/runway");
1020 double hdg = fgGetDouble("/sim/presets/heading-deg");
1021 string vor = fgGetString("/sim/presets/vor-id");
1022 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1023 string ndb = fgGetString("/sim/presets/ndb-id");
1024 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1025 string fix = fgGetString("/sim/presets/fix");
1027 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1028 // An airport + runway is requested
1029 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no ) ) {
1030 // set tower position (a little off the heading for single
1032 fgSetTowerPosFromAirportID( apt, hdg );
1037 if ( !set_pos && !apt.empty() ) {
1038 // An airport is requested (find runway closest to hdg)
1039 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1040 // set tower position (a little off the heading for single
1042 fgSetTowerPosFromAirportID( apt, hdg );
1047 if ( !set_pos && !vor.empty() ) {
1048 // a VOR is requested
1049 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1054 if ( !set_pos && !ndb.empty() ) {
1055 // an NDB is requested
1056 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1061 if ( !set_pos && !fix.empty() ) {
1062 // a Fix is requested
1063 if ( fgSetPosFromFix( fix ) ) {
1069 // No lon/lat specified, no airport specified, default to
1070 // middle of KSFO field.
1071 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1072 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1075 fgSetDouble( "/position/longitude-deg",
1076 fgGetDouble("/sim/presets/longitude-deg") );
1077 fgSetDouble( "/position/latitude-deg",
1078 fgGetDouble("/sim/presets/latitude-deg") );
1079 fgSetDouble( "/orientation/heading-deg",
1080 fgGetDouble("/sim/presets/heading-deg") );
1086 // General house keeping initializations
1087 bool fgInitGeneral() {
1090 #if defined(FX) && defined(XMESA)
1091 char *mesa_win_state;
1094 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1095 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1097 root = globals->get_fg_root();
1098 if ( ! root.length() ) {
1099 // No root path set? Then bail ...
1100 SG_LOG( SG_GENERAL, SG_ALERT,
1101 "Cannot continue without a path to the base package "
1102 << "being defined." );
1105 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1107 #if defined(FX) && defined(XMESA)
1108 // initialize full screen flag
1109 globals->set_fullscreen(false);
1110 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1111 // Test for the MESA_GLX_FX env variable
1112 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1113 // test if we are fullscreen mesa/glide
1114 if ( (mesa_win_state[0] == 'f') ||
1115 (mesa_win_state[0] == 'F') ) {
1116 globals->set_fullscreen(true);
1126 // Initialize the flight model subsystem. This just creates the
1127 // object. The actual fdm initialization is delayed until we get a
1128 // proper scenery elevation hit. This is checked for in main.cxx
1132 if ( cur_fdm_state ) {
1133 delete cur_fdm_state;
1137 double dt = 1.0 / fgGetInt("/sim/model-hz");
1138 aircraft_dir = fgGetString("/sim/aircraft-dir");
1139 const string &model = fgGetString("/sim/flight-model");
1142 if ( model == "larcsim" ) {
1143 cur_fdm_state = new FGLaRCsim( dt );
1144 } else if ( model == "jsb" ) {
1145 cur_fdm_state = new FGJSBsim( dt );
1146 } else if ( model == "ada" ) {
1147 cur_fdm_state = new FGADA( dt );
1148 } else if ( model == "balloon" ) {
1149 cur_fdm_state = new FGBalloonSim( dt );
1150 } else if ( model == "magic" ) {
1151 cur_fdm_state = new FGMagicCarpet( dt );
1152 } else if ( model == "ufo" ) {
1153 cur_fdm_state = new FGUFO( dt );
1154 } else if ( model == "external" ) {
1155 // external is a synonym for "--fdm=null" and is
1156 // maintained here for backwards compatibility
1157 cur_fdm_state = new FGNullFDM( dt );
1158 } else if ( model.find("network") == 0 ) {
1159 string host = "localhost";
1163 string net_options = model.substr(8);
1164 string::size_type begin, end;
1167 end = net_options.find( ",", begin );
1168 if ( end != string::npos ) {
1169 host = net_options.substr(begin, end - begin);
1173 end = net_options.find( ",", begin );
1174 if ( end != string::npos ) {
1175 port1 = atoi( net_options.substr(begin, end - begin).c_str() );
1179 end = net_options.find( ",", begin );
1180 if ( end != string::npos ) {
1181 port2 = atoi( net_options.substr(begin, end - begin).c_str() );
1185 end = net_options.find( ",", begin );
1186 if ( end != string::npos ) {
1187 port3 = atoi( net_options.substr(begin, end - begin).c_str() );
1190 cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
1191 } else if ( model.find("pipe") == 0 ) {
1192 string pipe_path = model.substr(5);
1193 cur_fdm_state = new FGExternalPipe( dt, pipe_path );
1194 } else if ( model == "null" ) {
1195 cur_fdm_state = new FGNullFDM( dt );
1196 } else if ( model == "yasim" ) {
1197 cur_fdm_state = new YASim( dt );
1199 SG_LOG(SG_GENERAL, SG_ALERT,
1200 "Unrecognized flight model '" << model
1201 << "', cannot init flight dynamics model.");
1205 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
1210 static void printMat(const sgVec4 *mat, char *name="")
1213 SG_LOG(SG_GENERAL, SG_BULK, name );
1214 for(i=0; i<4; i++) {
1215 SG_LOG(SG_GENERAL, SG_BULK, " " << mat[i][0] << " " << mat[i][1]
1216 << " " << mat[i][2] << " " << mat[i][3] );
1220 // Initialize view parameters
1222 // force update of model so that viewer can get some data...
1223 globals->get_aircraft_model()->update(0);
1224 // run update for current view so that data is current...
1225 globals->get_viewmgr()->update(0);
1227 printMat(globals->get_current_view()->get_VIEW(),"VIEW");
1228 printMat(globals->get_current_view()->get_UP(),"UP");
1229 // printMat(globals->get_current_view()->get_LOCAL(),"LOCAL");
1234 SGTime *fgInitTime() {
1236 static const SGPropertyNode *longitude
1237 = fgGetNode("/position/longitude-deg");
1238 static const SGPropertyNode *latitude
1239 = fgGetNode("/position/latitude-deg");
1240 static const SGPropertyNode *cur_time_override
1241 = fgGetNode("/sim/time/cur-time-override", true);
1243 SGPath zone( globals->get_fg_root() );
1244 zone.append( "Timezone" );
1245 SGTime *t = new SGTime( longitude->getDoubleValue()
1246 * SGD_DEGREES_TO_RADIANS,
1247 latitude->getDoubleValue()
1248 * SGD_DEGREES_TO_RADIANS,
1250 cur_time_override->getLongValue() );
1252 // Handle potential user specified time offsets
1253 time_t cur_time = t->get_cur_time();
1254 time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1255 time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1256 time_t aircraftLocalTime =
1257 sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1259 // Okay, we now have six possible scenarios
1260 int offset = fgGetInt("/sim/startup/time-offset");
1261 const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1262 if (offset_type == "system-offset") {
1263 globals->set_warp( offset );
1264 } else if (offset_type == "gmt-offset") {
1265 globals->set_warp( offset - (currGMT - systemLocalTime) );
1266 } else if (offset_type == "latitude-offset") {
1267 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1268 } else if (offset_type == "system") {
1269 globals->set_warp( offset - cur_time );
1270 } else if (offset_type == "gmt") {
1271 globals->set_warp( offset - currGMT );
1272 } else if (offset_type == "latitude") {
1273 globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
1276 SG_LOG( SG_GENERAL, SG_ALERT,
1277 "FG_TIME::Unsupported offset type " << offset_type );
1281 SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
1282 << globals->get_warp() );
1284 globals->set_warp_delta( 0 );
1286 t->update( 0.0, 0.0,
1287 cur_time_override->getLongValue(),
1288 globals->get_warp() );
1294 // This is the top level init routine which calls all the other
1295 // initialization routines. If you are adding a subsystem to flight
1296 // gear, its initialization call should located in this routine.
1297 // Returns non-zero if a problem encountered.
1298 bool fgInitSubsystems() {
1299 // static const SGPropertyNode *longitude
1300 // = fgGetNode("/sim/presets/longitude-deg");
1301 // static const SGPropertyNode *latitude
1302 // = fgGetNode("/sim/presets/latitude-deg");
1303 // static const SGPropertyNode *altitude
1304 // = fgGetNode("/sim/presets/altitude-ft");
1306 fgLIGHT *l = &cur_light_params;
1308 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1309 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1312 ////////////////////////////////////////////////////////////////////
1313 // Initialize the material property subsystem.
1314 ////////////////////////////////////////////////////////////////////
1316 SGPath mpath( globals->get_fg_root() );
1317 mpath.append( "materials.xml" );
1318 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str()) ) {
1319 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1323 ////////////////////////////////////////////////////////////////////
1324 // Initialize the event manager subsystem.
1325 ////////////////////////////////////////////////////////////////////
1327 global_events.init();
1329 // Output event stats every 60 seconds
1330 global_events.Register( "FGEventMgr::print_stats()",
1331 &global_events, &FGEventMgr::print_stats,
1335 ////////////////////////////////////////////////////////////////////
1336 // Initialize the scenery management subsystem.
1337 ////////////////////////////////////////////////////////////////////
1339 if ( globals->get_tile_mgr()->init() ) {
1340 // Load the local scenery data
1341 double visibility_meters = fgGetDouble("/environment/visibility-m");
1343 globals->get_tile_mgr()->update( visibility_meters );
1345 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1349 // cause refresh of viewer scenery timestamps every 15 seconds...
1350 global_events.Register( "FGTileMgr::refresh_view_timestamps()",
1351 globals->get_tile_mgr(),
1352 &FGTileMgr::refresh_view_timestamps,
1355 SG_LOG( SG_GENERAL, SG_DEBUG,
1356 "Current terrain elevation after tile mgr init " <<
1357 globals->get_scenery()->get_cur_elev() );
1360 ////////////////////////////////////////////////////////////////////
1361 // Initialize the flight model subsystem.
1362 ////////////////////////////////////////////////////////////////////
1366 // allocates structures so must happen before any of the flight
1367 // model or control parameters are set
1368 fgAircraftInit(); // In the future this might not be the case.
1371 ////////////////////////////////////////////////////////////////////
1372 // Initialize the view manager subsystem.
1373 ////////////////////////////////////////////////////////////////////
1378 ////////////////////////////////////////////////////////////////////
1379 // Initialize the lighting subsystem.
1380 ////////////////////////////////////////////////////////////////////
1382 // fgUpdateSunPos() needs a few position and view parameters set
1383 // so it can calculate local relative sun angle and a few other
1384 // things for correctly orienting the sky.
1387 global_events.Register( "fgUpdateSunPos()", &fgUpdateSunPos,
1389 global_events.Register( "fgUpdateMoonPos()", &fgUpdateMoonPos,
1392 // Initialize Lighting interpolation tables
1395 // force one lighting update to make it right to start with...
1397 // update the lighting parameters (based on sun angle)
1398 global_events.Register( "fgLight::Update()",
1399 &cur_light_params, &fgLIGHT::Update,
1403 ////////////////////////////////////////////////////////////////////
1404 // Create and register the logger.
1405 ////////////////////////////////////////////////////////////////////
1407 globals->add_subsystem("logger", new FGLogger);
1410 #if defined(HAVE_PLIB_PSL)
1411 ////////////////////////////////////////////////////////////////////
1412 // Create and register the script manager.
1413 ////////////////////////////////////////////////////////////////////
1415 globals->add_subsystem("scripting", new FGScriptMgr);
1416 #endif // HAVE_PLIB_PSL
1419 ////////////////////////////////////////////////////////////////////
1420 // Create and register the XML GUI.
1421 ////////////////////////////////////////////////////////////////////
1423 globals->add_subsystem("gui", new NewGUI, FGSubsystemMgr::INIT);
1426 ////////////////////////////////////////////////////////////////////
1427 // Initialize the local time subsystem.
1428 ////////////////////////////////////////////////////////////////////
1430 // update the current timezone each 30 minutes
1431 global_events.Register( "fgUpdateLocalTime()", &fgUpdateLocalTime,
1435 ////////////////////////////////////////////////////////////////////
1436 // Initialize the weather subsystem.
1437 ////////////////////////////////////////////////////////////////////
1439 // Initialize the weather modeling subsystem
1441 // Initialize the WeatherDatabase
1442 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
1444 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
1445 current_aircraft.fdm_state->get_Longitude(),
1446 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
1447 double init_vis = fgGetDouble("/environment/visibility-m");
1449 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
1451 if (!strcmp(fgGetString("/environment/weather/working-type"), "internet"))
1453 working_type = FGLocalWeatherDatabase::use_internet;
1455 working_type = FGLocalWeatherDatabase::default_mode;
1458 if ( init_vis > 0 ) {
1459 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1460 new FGLocalWeatherDatabase( position,
1461 globals->get_fg_root(),
1465 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
1466 new FGLocalWeatherDatabase( position,
1467 globals->get_fg_root(),
1471 // cout << theFGLocalWeatherDatabase << endl;
1472 // cout << "visibility = "
1473 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
1475 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
1477 // register the periodic update of the weather
1478 global_events.Register( "weather update", &fgUpdateWeatherDatabase,
1481 globals->add_subsystem("environment", new FGEnvironmentMgr);
1484 #ifdef FG_USE_CLOUDS_3D
1485 ////////////////////////////////////////////////////////////////////
1486 // Initialize the 3D cloud subsystem.
1487 ////////////////////////////////////////////////////////////////////
1488 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1489 static const SGPropertyNode *longitude
1490 = fgGetNode("/sim/presets/longitude-deg");
1491 static const SGPropertyNode *latitude
1492 = fgGetNode("/sim/presets/latitude-deg");
1493 static const SGPropertyNode *altitude
1494 = fgGetNode("/sim/presets/altitude-ft");
1496 SGPath cloud_path(globals->get_fg_root());
1498 cloud_path.append("Textures/Sky/scattered.rgba");
1499 SG_LOG(SG_GENERAL, SG_INFO, "Loading CLOUDS3d from: " << cloud_path.c_str());
1502 tx.read_rgba_texture(cloud_path.c_str());
1503 if ( !sgCloud3d->Load( tx.texture(), tx.width(),
1505 cloud_path.append("large.sky");
1506 if ( !sgCloud3d->Load( cloud_path.str(),
1508 latitude->getDoubleValue(),
1509 longitude->getDoubleValue()) )
1511 fgSetBool("/sim/rendering/clouds3d", false);
1512 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d FAILED: ");
1514 SG_LOG(SG_GENERAL, SG_INFO, "CLOUDS3d Loaded: ");
1518 ////////////////////////////////////////////////////////////////////
1519 // Initialise ATC display system
1520 ////////////////////////////////////////////////////////////////////
1522 SG_LOG(SG_GENERAL, SG_INFO, " ATC Display");
1523 globals->set_ATC_display(new FGATCDisplay);
1524 globals->get_ATC_display()->init();
1526 ////////////////////////////////////////////////////////////////////
1527 // Initialise the ATC Manager
1528 ////////////////////////////////////////////////////////////////////
1530 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1531 globals->set_ATC_mgr(new FGATCMgr);
1532 globals->get_ATC_mgr()->init();
1534 ////////////////////////////////////////////////////////////////////
1535 // Initialise the AI Manager
1536 ////////////////////////////////////////////////////////////////////
1538 SG_LOG(SG_GENERAL, SG_INFO, " AI Manager");
1539 globals->set_AI_mgr(new FGAIMgr);
1540 globals->get_AI_mgr()->init();
1543 #ifdef ENABLE_AUDIO_SUPPORT
1544 ////////////////////////////////////////////////////////////////////
1545 // Initialize the sound subsystem.
1546 ////////////////////////////////////////////////////////////////////
1548 globals->set_soundmgr(new SGSoundMgr);
1549 globals->get_soundmgr()->init();
1550 globals->get_soundmgr()->bind();
1553 ////////////////////////////////////////////////////////////////////
1554 // Initialize the sound-effects subsystem.
1555 ////////////////////////////////////////////////////////////////////
1557 globals->add_subsystem("fx", new FGFX);
1561 globals->add_subsystem("instrumentation", new FGInstrumentMgr);
1562 globals->add_subsystem("systems", new FGSystemMgr);
1564 ////////////////////////////////////////////////////////////////////
1565 // Initialize the radio stack subsystem.
1566 ////////////////////////////////////////////////////////////////////
1568 current_radiostack = new FGRadioStack;
1569 current_radiostack->init();
1570 current_radiostack->bind();
1573 ////////////////////////////////////////////////////////////////////
1574 // Initialize the cockpit subsystem
1575 ////////////////////////////////////////////////////////////////////
1577 if( fgCockpitInit( ¤t_aircraft )) {
1578 // Cockpit initialized ok.
1580 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1585 ////////////////////////////////////////////////////////////////////
1586 // Initialize the autopilot subsystem.
1587 ////////////////////////////////////////////////////////////////////
1589 globals->set_autopilot(new FGAutopilot);
1590 globals->get_autopilot()->init();
1591 globals->get_autopilot()->bind();
1593 // FIXME: these should go in the
1594 // GUI initialization code, not here.
1596 NewTgtAirportInit();
1600 ////////////////////////////////////////////////////////////////////
1601 // Initialize I/O subsystem.
1602 ////////////////////////////////////////////////////////////////////
1604 globals->get_io()->init();
1605 globals->get_io()->bind();
1608 ////////////////////////////////////////////////////////////////////
1609 // Add a new 2D panel.
1610 ////////////////////////////////////////////////////////////////////
1612 string panel_path = fgGetString("/sim/panel/path",
1613 "Panels/Default/default.xml");
1615 globals->set_current_panel( fgReadPanel(panel_path) );
1616 if (globals->get_current_panel() == 0) {
1617 SG_LOG( SG_INPUT, SG_ALERT,
1618 "Error reading new panel from " << panel_path );
1620 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1621 globals->get_current_panel()->init();
1622 globals->get_current_panel()->bind();
1626 ////////////////////////////////////////////////////////////////////
1627 // Initialize the default (kludged) properties.
1628 ////////////////////////////////////////////////////////////////////
1633 ////////////////////////////////////////////////////////////////////
1634 // Initialize the controls subsystem.
1635 ////////////////////////////////////////////////////////////////////
1637 globals->get_controls()->init();
1638 globals->get_controls()->bind();
1641 ////////////////////////////////////////////////////////////////////
1642 // Initialize the input subsystem.
1643 ////////////////////////////////////////////////////////////////////
1645 globals->add_subsystem("input", new FGInput);
1648 ////////////////////////////////////////////////////////////////////
1649 // Initialize the replay subsystem
1650 ////////////////////////////////////////////////////////////////////
1651 globals->add_subsystem("replay", new FGReplay);
1653 ////////////////////////////////////////////////////////////////////
1654 // Bind and initialize subsystems.
1655 ////////////////////////////////////////////////////////////////////
1657 globals->get_subsystem_mgr()->bind();
1658 globals->get_subsystem_mgr()->init();
1661 #ifdef FG_MPLAYER_AS
1662 ////////////////////////////////////////////////////////////////////
1663 // Initialize multiplayer subsystem
1664 ////////////////////////////////////////////////////////////////////
1666 globals->set_multiplayer_tx_mgr(new FGMultiplayTxMgr);
1667 globals->get_multiplayer_tx_mgr()->init();
1669 globals->set_multiplayer_rx_mgr(new FGMultiplayRxMgr);
1670 globals->get_multiplayer_rx_mgr()->init();
1673 ////////////////////////////////////////////////////////////////////////
1674 // End of subsystem initialization.
1675 ////////////////////////////////////////////////////////////////////
1677 SG_LOG( SG_GENERAL, SG_INFO, endl);
1679 // Save the initial state for future
1681 globals->saveInitialState();
1687 void fgReInitSubsystems()
1689 // static const SGPropertyNode *longitude
1690 // = fgGetNode("/sim/presets/longitude-deg");
1691 // static const SGPropertyNode *latitude
1692 // = fgGetNode("/sim/presets/latitude-deg");
1693 static const SGPropertyNode *altitude
1694 = fgGetNode("/sim/presets/altitude-ft");
1695 static const SGPropertyNode *master_freeze
1696 = fgGetNode("/sim/freeze/master");
1698 SG_LOG( SG_GENERAL, SG_INFO,
1699 "fgReInitSubsystems(): /position/altitude = "
1700 << altitude->getDoubleValue() );
1702 bool freeze = master_freeze->getBoolValue();
1704 fgSetBool("/sim/freeze/master", true);
1707 // Initialize the FDM
1710 // allocates structures so must happen before any of the flight
1711 // model or control parameters are set
1712 fgAircraftInit(); // In the future this might not be the case.
1714 // reload offsets from config defaults
1715 globals->get_viewmgr()->reinit();
1719 globals->get_controls()->reset_all();
1720 globals->get_autopilot()->reset();
1724 cur_light_params.Update();
1725 fgUpdateLocalTime();
1728 fgSetBool("/sim/freeze/master", false);