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 - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include <string.h> // strcmp()
32 #if defined( unix ) || defined( __CYGWIN__ )
33 # include <unistd.h> // for gethostname()
36 # include <direct.h> // for getcwd()
37 # define getcwd _getcwd
38 # include <io.h> // isatty()
39 # define isatty _isatty
40 # include "winsock2.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>
52 #include <boost/algorithm/string/compare.hpp>
53 #include <boost/algorithm/string/predicate.hpp>
55 #include <simgear/constants.h>
56 #include <simgear/debug/logstream.hxx>
57 #include <simgear/structure/exception.hxx>
58 #include <simgear/structure/event_mgr.hxx>
59 #include <simgear/misc/sg_path.hxx>
60 #include <simgear/misc/sg_dir.hxx>
61 #include <simgear/misc/sgstream.hxx>
63 #include <simgear/misc/interpolator.hxx>
64 #include <simgear/scene/material/matlib.hxx>
65 #include <simgear/scene/model/particles.hxx>
66 #include <simgear/sound/soundmgr_openal.hxx>
68 #include <Aircraft/controls.hxx>
69 #include <Aircraft/replay.hxx>
70 #include <Airports/apt_loader.hxx>
71 #include <Airports/runways.hxx>
72 #include <Airports/simple.hxx>
73 #include <Airports/dynamics.hxx>
75 #include <AIModel/AIManager.hxx>
78 # include <ATCDCL/ATCmgr.hxx>
79 # include "ATCDCL/commlist.hxx"
81 # include "ATC/atis.hxx"
82 # include "ATC/atcutils.hxx"
85 #include <Autopilot/route_mgr.hxx>
86 #include <Autopilot/autopilotgroup.hxx>
88 #include <Cockpit/cockpit.hxx>
89 #include <Cockpit/panel.hxx>
90 #include <Cockpit/panel_io.hxx>
92 #include <GUI/new_gui.hxx>
93 #include <Input/input.hxx>
94 #include <Instrumentation/instrument_mgr.hxx>
95 #include <Model/acmodel.hxx>
96 #include <AIModel/submodel.hxx>
97 #include <AIModel/AIManager.hxx>
98 #include <Navaids/navdb.hxx>
99 #include <Navaids/navlist.hxx>
100 #include <Navaids/fix.hxx>
101 #include <Navaids/fixlist.hxx>
102 #include <Navaids/airways.hxx>
103 #include <Scenery/scenery.hxx>
104 #include <Scenery/tilemgr.hxx>
105 #include <Scripting/NasalSys.hxx>
106 #include <Sound/voice.hxx>
107 #include <Systems/system_mgr.hxx>
108 #include <Time/light.hxx>
109 #include <Traffic/TrafficMgr.hxx>
110 #include <MultiPlayer/multiplaymgr.hxx>
111 #include <FDM/fdm_shell.hxx>
113 #include <Environment/environment_mgr.hxx>
115 #include "fg_init.hxx"
117 #include "fg_commands.hxx"
118 #include "fg_props.hxx"
119 #include "options.hxx"
120 #include "globals.hxx"
121 #include "logger.hxx"
122 #include "renderer.hxx"
123 #include "viewmgr.hxx"
128 # include <CoreFoundation/CoreFoundation.h>
132 using namespace boost::algorithm;
134 extern const char *default_root;
137 // Scan the command line options for the specified option and return
139 static string fgScanForOption( const string& option, int argc, char **argv ) {
142 if (hostname == NULL)
145 if( gethostname(_hostname, 256) >= 0 ) {
146 hostname = strdup(_hostname);
147 free_hostname = true;
151 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
153 int len = option.length();
156 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
158 string arg = argv[i];
159 if ( arg.find( option ) == 0 ) {
160 return arg.substr( len );
170 // Scan the user config files for the specified option and return
172 static string fgScanForOption( const string& option, const string& path ) {
173 sg_gzifstream in( path );
174 if ( !in.is_open() ) {
178 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
180 int len = option.length();
183 while ( ! in.eof() ) {
185 getline( in, line, '\n' );
187 // catch extraneous (DOS) line ending character
188 if ( line[line.length() - 1] < 32 ) {
189 line = line.substr( 0, line.length()-1 );
192 if ( line.find( option ) == 0 ) {
193 return line.substr( len );
202 // Scan the user config files for the specified option and return
204 static string fgScanForOption( const string& option ) {
207 #if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
208 // Next check home directory for .fgfsrc.hostname file
210 if ( homedir != NULL && hostname != NULL && strlen(hostname) > 0) {
211 SGPath config( homedir );
212 config.append( ".fgfsrc" );
213 config.concat( "." );
214 config.concat( hostname );
215 arg = fgScanForOption( option, config.str() );
220 // Next check home directory for .fgfsrc file
222 if ( homedir != NULL ) {
223 SGPath config( homedir );
224 config.append( ".fgfsrc" );
225 arg = fgScanForOption( option, config.str() );
230 // Check for $fg_root/system.fgfsrc
231 SGPath config( globals->get_fg_root() );
232 config.append( "system.fgfsrc" );
233 arg = fgScanForOption( option, config.str() );
240 // Read in configuration (files and command line options) but only set
241 // fg_root and aircraft_paths, which are needed *before* do_options() is called
244 bool fgInitFGRoot ( int argc, char **argv ) {
247 // First parse command line options looking for --fg-root=, this
248 // will override anything specified in a config file
249 root = fgScanForOption( "--fg-root=", argc, argv);
251 // Check in one of the user configuration files.
253 root = fgScanForOption( "--fg-root=" );
255 // Next check if fg-root is set as an env variable
256 if ( root.empty() ) {
257 char *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__ )
268 #elif defined( _WIN32 )
270 #elif defined(__APPLE__)
272 The following code looks for the base package inside the application
273 bundle, in the standard Contents/Resources location.
275 CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
277 // look for a 'data' subdir
278 CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true);
280 // now convert down to a path, and the a c-string
281 CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
282 root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
284 CFRelease(resourcesUrl);
292 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
293 globals->set_fg_root(root);
299 // Read in configuration (files and command line options) but only set
301 bool fgInitFGAircraft ( int argc, char **argv ) {
303 string aircraftDir = fgScanForOption("--fg-aircraft=", argc, argv);
304 if (aircraftDir.empty()) {
305 aircraftDir = fgScanForOption("--fg-aircraft=");
308 const char* envp = ::getenv("FG_AIRCRAFT");
309 if (aircraftDir.empty() && envp) {
310 globals->append_aircraft_paths(envp);
313 if (!aircraftDir.empty()) {
314 globals->append_aircraft_paths(aircraftDir);
319 // First parse command line options looking for --aircraft=, this
320 // will override anything specified in a config file
321 aircraft = fgScanForOption( "--aircraft=", argc, argv );
322 if ( aircraft.empty() ) {
323 // check synonym option
324 aircraft = fgScanForOption( "--vehicle=", argc, argv );
327 // Check in one of the user configuration files.
328 if ( aircraft.empty() ) {
329 aircraft = fgScanForOption( "--aircraft=" );
331 if ( aircraft.empty() ) {
332 aircraft = fgScanForOption( "--vehicle=" );
335 // if an aircraft was specified, set the property name
336 if ( !aircraft.empty() ) {
337 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
338 fgSetString("/sim/aircraft", aircraft.c_str() );
340 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
347 // Return the current base package version
348 string fgBasePackageVersion() {
349 SGPath base_path( globals->get_fg_root() );
350 base_path.append("version");
352 sg_gzifstream in( base_path.str() );
353 if ( !in.is_open() ) {
354 SGPath old_path( globals->get_fg_root() );
355 old_path.append( "Thanks" );
356 sg_gzifstream old( old_path.str() );
357 if ( !old.is_open() ) {
360 return "[old version]";
371 // Initialize the localization
372 SGPropertyNode *fgInitLocale(const char *language) {
373 SGPropertyNode *c_node = NULL, *d_node = NULL;
374 SGPropertyNode *intl = fgGetNode("/sim/intl");
376 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
378 // localization not defined
383 // Select the proper language from the list
385 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
386 for (unsigned int i = 0; i < locale.size(); i++) {
388 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
389 for (unsigned int j = 0; j < lang.size(); j++) {
391 if (!strcmp(lang[j]->getStringValue(), language)) {
400 d_node = intl->getChild("locale");
404 // Check for localized font
405 SGPropertyNode *font_n = c_node->getNode("font", true);
406 if ( !strcmp(font_n->getStringValue(), "") )
407 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
411 // Load the default strings
413 SGPath d_path( globals->get_fg_root() );
415 const char *d_path_str = d_node->getStringValue("strings");
417 SG_LOG(SG_GENERAL, SG_ALERT, "No path in " << d_node->getPath() << "/strings.");
421 d_path.append(d_path_str);
422 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from " << d_path.str());
424 SGPropertyNode *strings = c_node->getNode("strings");
426 readProperties(d_path.str(), strings);
427 } catch (const sg_exception &) {
428 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
433 // Load the language specific strings
435 if (c_node != d_node) {
436 SGPath c_path( globals->get_fg_root() );
438 const char *c_path_str = c_node->getStringValue("strings");
440 SG_LOG(SG_GENERAL, SG_ALERT, "No path in " << c_node->getPath() << "/strings");
444 c_path.append(c_path_str);
445 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from " << c_path.str());
448 readProperties(c_path.str(), strings);
449 } catch (const sg_exception &) {
450 SG_LOG(SG_GENERAL, SG_ALERT,
451 "Unable to read the localized strings from " << c_path.str());
461 // Initialize the localization routines
462 bool fgDetectLanguage() {
463 const char *language = ::getenv("LANG");
465 if (language == NULL) {
466 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
470 SGPropertyNode *locale = fgInitLocale(language);
472 SG_LOG(SG_GENERAL, SG_ALERT,
473 "No internationalization settings specified in preferences.xml" );
478 globals->set_locale( locale );
483 // Attempt to locate and parse the various non-XML config files in order
484 // from least precidence to greatest precidence
486 do_options (int argc, char ** argv)
488 // Check for $fg_root/system.fgfsrc
489 SGPath config( globals->get_fg_root() );
490 config.append( "system.fgfsrc" );
491 fgParseOptions(config.str());
493 #if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
494 if( hostname != NULL && strlen(hostname) > 0 ) {
495 config.concat( "." );
496 config.concat( hostname );
497 fgParseOptions(config.str());
501 // Check for ~/.fgfsrc
502 if ( homedir != NULL ) {
503 config.set( homedir );
504 config.append( ".fgfsrc" );
505 fgParseOptions(config.str());
508 #if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
509 if( hostname != NULL && strlen(hostname) > 0 ) {
510 // Check for ~/.fgfsrc.hostname
511 config.concat( "." );
512 config.concat( hostname );
513 fgParseOptions(config.str());
517 // Parse remaining command line options
518 // These will override anything specified in a config file
519 fgParseArgs(argc, argv);
523 bool fgFindAircraftInDir(const SGPath& dirPath, T* obj, bool (T::*pred)(const SGPath& p))
525 if (!dirPath.exists()) {
526 SG_LOG(SG_GENERAL, SG_WARN, "fgFindAircraftInDir: no such path:" << dirPath.str());
531 simgear::Dir dir(dirPath);
532 simgear::PathList setFiles(dir.children(simgear::Dir::TYPE_FILE, "-set.xml"));
533 simgear::PathList::iterator p;
534 for (p = setFiles.begin(); p != setFiles.end(); ++p) {
535 // check file name ends with -set.xml
537 // if we found a -set.xml at this level, don't recurse any deeper
540 bool done = (obj->*pred)(*p);
544 } // of -set.xml iteration
550 simgear::PathList subdirs(dir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT));
551 for (p = subdirs.begin(); p != subdirs.end(); ++p) {
552 if (p->file() == "CVS") {
556 if (fgFindAircraftInDir(*p, obj, pred)) {
559 } // of subdirs iteration
565 void fgFindAircraft(T* obj, bool (T::*pred)(const SGPath& p))
567 const string_list& paths(globals->get_aircraft_paths());
568 string_list::const_iterator it = paths.begin();
569 for (; it != paths.end(); ++it) {
570 bool done = fgFindAircraftInDir(SGPath(*it), obj, pred);
574 } // of aircraft paths iteration
576 // if we reach this point, search the default location (always last)
577 SGPath rootAircraft(globals->get_fg_root());
578 rootAircraft.append("Aircraft");
579 fgFindAircraftInDir(rootAircraft, obj, pred);
582 class FindAndCacheAircraft
585 FindAndCacheAircraft(SGPropertyNode* autoSave)
587 _cache = autoSave->getNode("sim/startup/path-cache", true);
592 std::string aircraft = fgGetString( "/sim/aircraft", "");
593 if (aircraft.empty()) {
594 SG_LOG(SG_GENERAL, SG_ALERT, "no aircraft specified");
598 _searchAircraft = aircraft + "-set.xml";
600 // prepare cache for re-scan
601 SGPropertyNode *n = _cache->getNode("fg-root", true);
602 n->setStringValue(globals->get_fg_root().c_str());
603 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
604 _cache->removeChildren("aircraft");
606 fgFindAircraft(this, &FindAndCacheAircraft::checkAircraft);
609 if (_foundPath.str().empty()) {
610 SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find specified aircraft: " << aircraft );
614 SG_LOG(SG_GENERAL, SG_INFO, "Loading aircraft -set file from:" << _foundPath.str());
615 fgSetString( "/sim/aircraft-dir", _foundPath.dir().c_str());
616 if (!_foundPath.exists()) {
617 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to find -set file:" << _foundPath.str());
622 readProperties(_foundPath.str(), globals->get_props());
623 } catch ( const sg_exception &e ) {
624 SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
634 if (globals->get_fg_root() != _cache->getStringValue("fg-root", "")) {
635 return false; // cache mismatch
638 vector<SGPropertyNode_ptr> cache = _cache->getChildren("aircraft");
639 for (unsigned int i = 0; i < cache.size(); i++) {
640 const char *name = cache[i]->getStringValue("file", "");
641 if (!boost::equals(_searchAircraft, name, is_iequal())) {
645 SGPath xml(cache[i]->getStringValue("path", ""));
653 } // of aircraft in cache iteration
658 bool checkAircraft(const SGPath& p)
663 if (!_cache->getChild("aircraft", i++, false))
667 SGPropertyNode *n, *entry = _cache->getChild("aircraft", --i, true);
669 std::string fileName(p.file());
670 n = entry->getNode("file", true);
671 n->setStringValue(fileName);
672 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
674 n = entry->getNode("path", true);
675 n->setStringValue(p.dir());
676 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
678 if ( boost::equals(fileName, _searchAircraft.c_str(), is_iequal()) ) {
686 std::string _searchAircraft;
688 SGPropertyNode* _cache;
691 // Read in configuration (file and command line)
692 bool fgInitConfig ( int argc, char **argv ) {
694 // First, set some sane default values
697 // Read global preferences from $FG_ROOT/preferences.xml
698 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
699 fgLoadProps("preferences.xml", globals->get_props());
700 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
702 // Detect the required language as early as possible
703 if ( !fgDetectLanguage() ) {
707 SGPropertyNode autosave;
709 char *envp = ::getenv( "APPDATA" );
711 SGPath config( envp );
712 config.append( "flightgear.org" );
714 if ( homedir != NULL ) {
715 SGPath config( homedir );
716 config.append( ".fgfs" );
718 const char *fg_home = getenv("FG_HOME");
722 SGPath home_export(config.str());
723 home_export.append("Export/dummy");
724 home_export.create_dir(0777);
726 // Set /sim/fg-home and don't allow malign code to override it until
727 // Nasal security is set up. Use FG_HOME if necessary.
728 SGPropertyNode *home = fgGetNode("/sim", true);
729 home->removeChild("fg-home", 0, false);
730 home = home->getChild("fg-home", 0, true);
731 home->setStringValue(config.c_str());
732 home->setAttribute(SGPropertyNode::WRITE, false);
734 config.append( "autosave.xml" );
735 if (config.exists()) {
736 SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
738 readProperties(config.str(), &autosave, SGPropertyNode::USERARCHIVE);
739 } catch (sg_exception& e) {
740 SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
741 << "(from " << e.getOrigin() << ")");
746 // Scan user config files and command line for a specified aircraft.
747 fgInitFGAircraft(argc, argv);
748 FindAndCacheAircraft f(&autosave);
749 if (!f.loadAircraft()) {
753 copyProperties(&autosave, globals->get_props());
755 // parse options after loading aircraft to ensure any user
756 // overrides of defaults are honored.
757 do_options(argc, argv);
762 // Set current tower position lon/lat given an airport id
763 static bool fgSetTowerPosFromAirportID( const string& id) {
764 const FGAirport *a = fgFindAirportID( id);
766 SGGeod tower = a->getTowerLocation();
767 fgSetDouble("/sim/tower/longitude-deg", tower.getLongitudeDeg());
768 fgSetDouble("/sim/tower/latitude-deg", tower.getLatitudeDeg());
769 fgSetDouble("/sim/tower/altitude-ft", tower.getElevationFt());
777 struct FGTowerLocationListener : SGPropertyChangeListener {
778 void valueChanged(SGPropertyNode* node) {
779 const string id(node->getStringValue());
780 fgSetTowerPosFromAirportID(id);
784 void fgInitTowerLocationListener() {
785 fgGetNode("/sim/tower/airport-id", true)
786 ->addChangeListener( new FGTowerLocationListener(), true );
789 static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double aTargetHeading = HUGE_VAL)
791 SGGeod startPos(aStartPos);
792 if (aTargetHeading == HUGE_VAL) {
793 aTargetHeading = aHeading;
796 if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON ) {
797 double offsetDistance = fgGetDouble("/sim/presets/offset-distance-nm");
798 offsetDistance *= SG_NM_TO_METER;
799 double offsetAzimuth = aHeading;
800 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth-deg")) > SG_EPSILON ) {
801 offsetAzimuth = fgGetDouble("/sim/presets/offset-azimuth-deg");
802 aHeading = aTargetHeading;
807 SGGeodesy::direct(startPos, offsetAzimuth + 180, offsetDistance, offset, az2);
812 fgSetDouble("/sim/presets/longitude-deg", startPos.getLongitudeDeg() );
813 fgSetDouble("/sim/presets/latitude-deg", startPos.getLatitudeDeg() );
814 fgSetDouble("/sim/presets/heading-deg", aHeading );
816 // other code depends on the actual values being set ...
817 fgSetDouble("/position/longitude-deg", startPos.getLongitudeDeg() );
818 fgSetDouble("/position/latitude-deg", startPos.getLatitudeDeg() );
819 fgSetDouble("/orientation/heading-deg", aHeading );
822 // Set current_options lon/lat given an airport id and heading (degrees)
823 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
827 // set initial position from runway and heading
828 SG_LOG( SG_GENERAL, SG_INFO,
829 "Attempting to set starting position from airport code "
830 << id << " heading " << tgt_hdg );
832 const FGAirport* apt = fgFindAirportID(id);
833 if (!apt) return false;
834 FGRunway* r = apt->findBestRunwayForHeading(tgt_hdg);
835 fgSetString("/sim/atc/runway", r->ident().c_str());
837 SGGeod startPos = r->pointOnCenterline(fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
838 fgApplyStartOffset(startPos, r->headingDeg(), tgt_hdg);
842 // Set current_options lon/lat given an airport id and parkig position name
843 static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) {
847 // can't see an easy way around this const_cast at the moment
848 FGAirport* apt = const_cast<FGAirport*>(fgFindAirportID(id));
850 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport " << id );
853 FGAirportDynamics* dcs = apt->getDynamics();
855 SG_LOG( SG_GENERAL, SG_ALERT,
856 "Failed to find parking position " << parkpos <<
857 " at airport " << id );
861 int park_index = dcs->getNrOfParkings() - 1;
862 while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) park_index--;
863 if (park_index < 0) {
864 SG_LOG( SG_GENERAL, SG_ALERT,
865 "Failed to find parking position " << parkpos <<
866 " at airport " << id );
869 FGParking* parking = dcs->getParking(park_index);
870 parking->setAvailable(false);
872 SGGeod::fromDeg(parking->getLongitude(), parking->getLatitude()),
873 parking->getHeading());
878 // Set current_options lon/lat given an airport id and runway number
879 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, bool rwy_req ) {
883 // set initial position from airport and runway number
884 SG_LOG( SG_GENERAL, SG_INFO,
885 "Attempting to set starting position for "
886 << id << ":" << rwy );
888 const FGAirport* apt = fgFindAirportID(id);
890 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport:" << id);
894 if (!apt->hasRunwayWithIdent(rwy)) {
895 SG_LOG( SG_GENERAL, rwy_req ? SG_ALERT : SG_INFO,
896 "Failed to find runway " << rwy <<
897 " at airport " << id << ". Using default runway." );
901 FGRunway* r(apt->getRunwayByIdent(rwy));
902 fgSetString("/sim/atc/runway", r->ident().c_str());
903 SGGeod startPos = r->pointOnCenterline( fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
904 fgApplyStartOffset(startPos, r->headingDeg());
909 static void fgSetDistOrAltFromGlideSlope() {
910 // cout << "fgSetDistOrAltFromGlideSlope()" << endl;
911 string apt_id = fgGetString("/sim/presets/airport-id");
912 double gs = fgGetDouble("/sim/presets/glideslope-deg")
913 * SG_DEGREES_TO_RADIANS ;
914 double od = fgGetDouble("/sim/presets/offset-distance-nm");
915 double alt = fgGetDouble("/sim/presets/altitude-ft");
917 double apt_elev = 0.0;
918 if ( ! apt_id.empty() ) {
919 apt_elev = fgGetAirportElev( apt_id );
920 if ( apt_elev < -9990.0 ) {
927 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
928 // set altitude from glideslope and offset-distance
929 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
930 alt = fabs(od*tan(gs)) + apt_elev;
931 fgSetDouble("/sim/presets/altitude-ft", alt);
932 fgSetBool("/sim/presets/onground", false);
933 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
935 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
936 // set offset-distance from glideslope and altitude
937 od = (alt - apt_elev) / tan(gs);
938 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
939 fgSetDouble("/sim/presets/offset-distance-nm", od);
940 fgSetBool("/sim/presets/onground", false);
941 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
943 } else if( fabs(gs) > 0.01 ) {
944 SG_LOG( SG_GENERAL, SG_ALERT,
945 "Glideslope given but not altitude or offset-distance." );
946 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
947 fgSetDouble("/sim/presets/glideslope-deg", 0);
948 fgSetBool("/sim/presets/onground", true);
953 // Set current_options lon/lat given an airport id and heading (degrees)
954 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
956 = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq );
959 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
960 << id << ":" << freq );
964 fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
968 // Set current_options lon/lat given an aircraft carrier id
969 static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
971 // set initial position from runway and heading
975 if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) {
976 double lon = geodPos.getLongitudeDeg();
977 double lat = geodPos.getLatitudeDeg();
978 double alt = geodPos.getElevationFt();
980 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
981 << carrier << " at lat = " << lat << ", lon = " << lon
982 << ", alt = " << alt << ", heading = " << heading);
984 fgSetDouble("/sim/presets/longitude-deg", lon);
985 fgSetDouble("/sim/presets/latitude-deg", lat);
986 fgSetDouble("/sim/presets/altitude-ft", alt);
987 fgSetDouble("/sim/presets/heading-deg", heading);
988 fgSetDouble("/position/longitude-deg", lon);
989 fgSetDouble("/position/latitude-deg", lat);
990 fgSetDouble("/position/altitude-ft", alt);
991 fgSetDouble("/orientation/heading-deg", heading);
993 fgSetString("/sim/presets/speed-set", "UVW");
994 fgSetDouble("/velocities/uBody-fps", uvw(0));
995 fgSetDouble("/velocities/vBody-fps", uvw(1));
996 fgSetDouble("/velocities/wBody-fps", uvw(2));
997 fgSetDouble("/sim/presets/uBody-fps", uvw(0));
998 fgSetDouble("/sim/presets/vBody-fps", uvw(1));
999 fgSetDouble("/sim/presets/wBody-fps", uvw(2));
1001 fgSetBool("/sim/presets/onground", true);
1005 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = "
1011 // Set current_options lon/lat given an airport id and heading (degrees)
1012 static bool fgSetPosFromFix( const string& id )
1014 FGPositioned::TypeFilter fixFilter(FGPositioned::FIX);
1015 FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter);
1017 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id );
1021 fgApplyStartOffset(fix->geod(), fgGetDouble("/sim/presets/heading-deg"));
1026 * Initialize vor/ndb/ils/fix list management and query systems (as
1027 * well as simple airport db list)
1032 SG_LOG(SG_GENERAL, SG_INFO, "Loading Airport Database ...");
1034 SGPath aptdb( globals->get_fg_root() );
1035 aptdb.append( "Airports/apt.dat" );
1037 SGPath p_metar( globals->get_fg_root() );
1038 p_metar.append( "Airports/metar.dat" );
1040 // Initialise the frequency search map BEFORE reading
1041 // the airport database:
1045 current_commlist = new FGCommList;
1046 current_commlist->init( globals->get_fg_root() );
1047 fgAirportDBLoad( aptdb.str(), current_commlist, p_metar.str() );
1049 FGNavList *navlist = new FGNavList;
1050 FGNavList *loclist = new FGNavList;
1051 FGNavList *gslist = new FGNavList;
1052 FGNavList *dmelist = new FGNavList;
1053 FGNavList *tacanlist = new FGNavList;
1054 FGNavList *carrierlist = new FGNavList;
1055 FGTACANList *channellist = new FGTACANList;
1057 globals->set_navlist( navlist );
1058 globals->set_loclist( loclist );
1059 globals->set_gslist( gslist );
1060 globals->set_dmelist( dmelist );
1061 globals->set_tacanlist( tacanlist );
1062 globals->set_carrierlist( carrierlist );
1063 globals->set_channellist( channellist );
1065 if ( !fgNavDBInit(navlist, loclist, gslist, dmelist, tacanlist, carrierlist, channellist) ) {
1066 SG_LOG( SG_GENERAL, SG_ALERT,
1067 "Problems loading one or more navigational database" );
1070 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1071 SGPath p_fix( globals->get_fg_root() );
1072 p_fix.append( "Navaids/fix.dat" );
1074 fixlist.init( p_fix ); // adds fixes to the DB in positioned.cxx
1076 SG_LOG(SG_GENERAL, SG_INFO, " Airways");
1077 flightgear::Airway::load();
1083 // Set the initial position based on presets (or defaults)
1084 bool fgInitPosition() {
1085 // cout << "fgInitPosition()" << endl;
1086 double gs = fgGetDouble("/sim/presets/glideslope-deg")
1087 * SG_DEGREES_TO_RADIANS ;
1088 double od = fgGetDouble("/sim/presets/offset-distance-nm");
1089 double alt = fgGetDouble("/sim/presets/altitude-ft");
1091 bool set_pos = false;
1093 // If glideslope is specified, then calculate offset-distance or
1094 // altitude relative to glide slope if either of those was not
1096 if ( fabs( gs ) > 0.01 ) {
1097 fgSetDistOrAltFromGlideSlope();
1101 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1102 // If not, check for an airport-id and use that.
1103 // If not, default to the middle of the KSFO field.
1104 // The default values for lon/lat are deliberately out of range
1105 // so that the airport-id can take effect; valid lon/lat will
1106 // override airport-id, however.
1107 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1108 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1109 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1110 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1115 string apt = fgGetString("/sim/presets/airport-id");
1116 string rwy_no = fgGetString("/sim/presets/runway");
1117 bool rwy_req = fgGetBool("/sim/presets/runway-requested");
1118 string vor = fgGetString("/sim/presets/vor-id");
1119 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1120 string ndb = fgGetString("/sim/presets/ndb-id");
1121 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1122 string carrier = fgGetString("/sim/presets/carrier");
1123 string parkpos = fgGetString("/sim/presets/parkpos");
1124 string fix = fgGetString("/sim/presets/fix");
1125 SGPropertyNode *hdg_preset = fgGetNode("/sim/presets/heading-deg", true);
1126 double hdg = hdg_preset->getDoubleValue();
1128 // save some start parameters, so that we can later say what the
1129 // user really requested. TODO generalize that and move it to options.cxx
1130 static bool start_options_saved = false;
1131 if (!start_options_saved) {
1132 start_options_saved = true;
1133 SGPropertyNode *opt = fgGetNode("/sim/startup/options", true);
1135 opt->setDoubleValue("latitude-deg", lat_deg);
1136 opt->setDoubleValue("longitude-deg", lon_deg);
1137 opt->setDoubleValue("heading-deg", hdg);
1138 opt->setStringValue("airport", apt.c_str());
1139 opt->setStringValue("runway", rwy_no.c_str());
1143 hdg = fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270);
1145 if ( !set_pos && !apt.empty() && !parkpos.empty() ) {
1146 // An airport + parking position is requested
1147 if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
1148 // set tower position
1149 fgSetString("/sim/tower/airport-id", apt.c_str());
1154 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1155 // An airport + runway is requested
1156 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
1157 // set tower position (a little off the heading for single
1159 fgSetString("/sim/tower/airport-id", apt.c_str());
1164 if ( !set_pos && !apt.empty() ) {
1165 // An airport is requested (find runway closest to hdg)
1166 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1167 // set tower position (a little off the heading for single
1169 fgSetString("/sim/tower/airport-id", apt.c_str());
1174 if (hdg_preset->getDoubleValue() > 9990.0)
1175 hdg_preset->setDoubleValue(hdg);
1177 if ( !set_pos && !vor.empty() ) {
1178 // a VOR is requested
1179 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1184 if ( !set_pos && !ndb.empty() ) {
1185 // an NDB is requested
1186 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1191 if ( !set_pos && !carrier.empty() ) {
1192 // an aircraft carrier is requested
1193 if ( fgSetPosFromCarrier( carrier, parkpos ) ) {
1198 if ( !set_pos && !fix.empty() ) {
1199 // a Fix is requested
1200 if ( fgSetPosFromFix( fix ) ) {
1206 // No lon/lat specified, no airport specified, default to
1207 // middle of KSFO field.
1208 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1209 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1212 fgSetDouble( "/position/longitude-deg",
1213 fgGetDouble("/sim/presets/longitude-deg") );
1214 fgSetDouble( "/position/latitude-deg",
1215 fgGetDouble("/sim/presets/latitude-deg") );
1216 fgSetDouble( "/orientation/heading-deg", hdg_preset->getDoubleValue());
1218 // determine if this should be an on-ground or in-air start
1219 if ((fabs(gs) > 0.01 || fabs(od) > 0.1 || alt > 0.1) && carrier.empty()) {
1220 fgSetBool("/sim/presets/onground", false);
1222 fgSetBool("/sim/presets/onground", true);
1229 // General house keeping initializations
1230 bool fgInitGeneral() {
1233 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1234 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1236 root = globals->get_fg_root();
1237 if ( ! root.length() ) {
1238 // No root path set? Then bail ...
1239 SG_LOG( SG_GENERAL, SG_ALERT,
1240 "Cannot continue without a path to the base package "
1241 << "being defined." );
1244 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1246 globals->set_browser(fgGetString("/sim/startup/browser-app", "firefox %u"));
1248 char buf[512], *cwd = getcwd(buf, 511);
1250 SGPropertyNode *curr = fgGetNode("/sim", true);
1251 curr->removeChild("fg-current", 0, false);
1252 curr = curr->getChild("fg-current", 0, true);
1253 curr->setStringValue(cwd ? cwd : "");
1254 curr->setAttribute(SGPropertyNode::WRITE, false);
1256 fgSetBool("/sim/startup/stdout-to-terminal", isatty(1) != 0 );
1257 fgSetBool("/sim/startup/stderr-to-terminal", isatty(2) != 0 );
1261 // This is the top level init routine which calls all the other
1262 // initialization routines. If you are adding a subsystem to flight
1263 // gear, its initialization call should located in this routine.
1264 // Returns non-zero if a problem encountered.
1265 bool fgInitSubsystems() {
1266 // static const SGPropertyNode *longitude
1267 // = fgGetNode("/sim/presets/longitude-deg");
1268 // static const SGPropertyNode *latitude
1269 // = fgGetNode("/sim/presets/latitude-deg");
1270 // static const SGPropertyNode *altitude
1271 // = fgGetNode("/sim/presets/altitude-ft");
1273 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1274 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1276 ////////////////////////////////////////////////////////////////////
1277 // Initialize the event manager subsystem.
1278 ////////////////////////////////////////////////////////////////////
1280 globals->get_event_mgr()->init();
1281 globals->get_event_mgr()->setRealtimeProperty(fgGetNode("/sim/time/delta-realtime-sec", true));
1283 ////////////////////////////////////////////////////////////////////
1284 // Initialize the property interpolator subsystem. Put into the INIT
1285 // group because the "nasal" subsystem may need it at GENERAL take-down.
1286 ////////////////////////////////////////////////////////////////////
1287 globals->add_subsystem("interpolator", new SGInterpolator, SGSubsystemMgr::INIT);
1290 ////////////////////////////////////////////////////////////////////
1291 // Add the FlightGear property utilities.
1292 ////////////////////////////////////////////////////////////////////
1293 globals->add_subsystem("properties", new FGProperties);
1295 ////////////////////////////////////////////////////////////////////
1296 // Initialize the material property subsystem.
1297 ////////////////////////////////////////////////////////////////////
1299 SGPath mpath( globals->get_fg_root() );
1300 mpath.append( "materials.xml" );
1301 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
1302 globals->get_props()) ) {
1303 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1308 ////////////////////////////////////////////////////////////////////
1309 // Initialize the scenery management subsystem.
1310 ////////////////////////////////////////////////////////////////////
1312 globals->add_subsystem("tile-manager", globals->get_tile_mgr(),
1313 SGSubsystemMgr::DISPLAY);
1315 globals->get_scenery()->get_scene_graph()
1316 ->addChild(simgear::Particles::getCommonRoot());
1317 simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
1319 ////////////////////////////////////////////////////////////////////
1320 // Initialize the flight model subsystem.
1321 ////////////////////////////////////////////////////////////////////
1323 globals->add_subsystem("flight", new FDMShell, SGSubsystemMgr::FDM);
1325 ////////////////////////////////////////////////////////////////////
1326 // Initialize the weather subsystem.
1327 ////////////////////////////////////////////////////////////////////
1329 // Initialize the weather modeling subsystem
1330 globals->add_subsystem("environment", new FGEnvironmentMgr);
1332 ////////////////////////////////////////////////////////////////////
1333 // Initialize the aircraft systems and instrumentation (before the
1335 ////////////////////////////////////////////////////////////////////
1337 globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM);
1338 globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM);
1340 ////////////////////////////////////////////////////////////////////
1341 // Initialize the XML Autopilot subsystem.
1342 ////////////////////////////////////////////////////////////////////
1344 globals->add_subsystem( "xml-autopilot", FGXMLAutopilotGroup::createInstance(), SGSubsystemMgr::FDM );
1345 globals->add_subsystem( "route-manager", new FGRouteMgr );
1347 ////////////////////////////////////////////////////////////////////
1348 // Initialize the Input-Output subsystem
1349 ////////////////////////////////////////////////////////////////////
1350 globals->add_subsystem( "io", new FGIO );
1352 ////////////////////////////////////////////////////////////////////
1353 // Create and register the logger.
1354 ////////////////////////////////////////////////////////////////////
1356 globals->add_subsystem("logger", new FGLogger);
1358 ////////////////////////////////////////////////////////////////////
1359 // Create and register the XML GUI.
1360 ////////////////////////////////////////////////////////////////////
1362 globals->add_subsystem("gui", new NewGUI, SGSubsystemMgr::INIT);
1364 ////////////////////////////////////////////////////////////////////
1365 // Initialize the lighting subsystem.
1366 ////////////////////////////////////////////////////////////////////
1368 globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
1370 //////////////////////////////////////////////////////////////////////
1371 // Initialize the 2D cloud subsystem.
1372 ////////////////////////////////////////////////////////////////////
1373 fgGetBool("/sim/rendering/bump-mapping", false);
1375 #ifdef ENABLE_AUDIO_SUPPORT
1376 ////////////////////////////////////////////////////////////////////
1377 // Initialize the sound-effects subsystem.
1378 ////////////////////////////////////////////////////////////////////
1379 globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);
1382 ////////////////////////////////////////////////////////////////////
1383 // Initialise the ATC Manager
1384 ////////////////////////////////////////////////////////////////////
1387 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1388 globals->set_ATC_mgr(new FGATCMgr);
1389 globals->get_ATC_mgr()->init();
1391 ////////////////////////////////////////////////////////////////////
1392 // Initialise the ATIS Manager
1393 ////////////////////////////////////////////////////////////////////
1394 globals->add_subsystem("atis", new FGAtisManager, SGSubsystemMgr::POST_FDM);
1398 ////////////////////////////////////////////////////////////////////
1399 // Initialize multiplayer subsystem
1400 ////////////////////////////////////////////////////////////////////
1402 globals->add_subsystem("mp", new FGMultiplayMgr, SGSubsystemMgr::POST_FDM);
1404 ////////////////////////////////////////////////////////////////////
1405 // Initialise the AI Model Manager
1406 ////////////////////////////////////////////////////////////////////
1407 SG_LOG(SG_GENERAL, SG_INFO, " AI Model Manager");
1408 globals->add_subsystem("ai_model", new FGAIManager, SGSubsystemMgr::POST_FDM);
1409 globals->add_subsystem("submodel_mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);
1412 // It's probably a good idea to initialize the top level traffic manager
1413 // After the AI and ATC systems have been initialized properly.
1414 // AI Traffic manager
1415 globals->add_subsystem("Traffic Manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
1418 if( fgCockpitInit()) {
1419 // Cockpit initialized ok.
1421 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1426 ////////////////////////////////////////////////////////////////////
1427 // Add a new 2D panel.
1428 ////////////////////////////////////////////////////////////////////
1430 string panel_path = fgGetString("/sim/panel/path",
1431 "Panels/Default/default.xml");
1433 globals->set_current_panel( fgReadPanel(panel_path) );
1434 if (globals->get_current_panel() == 0) {
1435 SG_LOG( SG_INPUT, SG_ALERT,
1436 "Error reading new panel from " << panel_path );
1438 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1439 globals->get_current_panel()->init();
1440 globals->get_current_panel()->bind();
1444 ////////////////////////////////////////////////////////////////////
1445 // Initialize the controls subsystem.
1446 ////////////////////////////////////////////////////////////////////
1448 globals->get_controls()->init();
1449 globals->get_controls()->bind();
1452 ////////////////////////////////////////////////////////////////////
1453 // Initialize the input subsystem.
1454 ////////////////////////////////////////////////////////////////////
1456 globals->add_subsystem("input", new FGInput);
1459 ////////////////////////////////////////////////////////////////////
1460 // Initialize the replay subsystem
1461 ////////////////////////////////////////////////////////////////////
1462 globals->add_subsystem("replay", new FGReplay);
1465 ////////////////////////////////////////////////////////////////////
1466 // Bind and initialize subsystems.
1467 ////////////////////////////////////////////////////////////////////
1469 globals->get_subsystem_mgr()->bind();
1470 globals->get_subsystem_mgr()->init();
1472 ////////////////////////////////////////////////////////////////////////
1473 // Initialize the Nasal interpreter.
1474 // Do this last, so that the loaded scripts see initialized state
1475 ////////////////////////////////////////////////////////////////////////
1476 FGNasalSys* nasal = new FGNasalSys();
1477 globals->add_subsystem("nasal", nasal, SGSubsystemMgr::INIT);
1480 // initialize methods that depend on other subsystems.
1481 globals->get_subsystem_mgr()->postinit();
1483 ////////////////////////////////////////////////////////////////////////
1484 // End of subsystem initialization.
1485 ////////////////////////////////////////////////////////////////////
1487 SG_LOG( SG_GENERAL, SG_INFO, endl);
1489 // Save the initial state for future
1491 globals->saveInitialState();
1497 void fgReInitSubsystems()
1499 // static const SGPropertyNode *longitude
1500 // = fgGetNode("/sim/presets/longitude-deg");
1501 // static const SGPropertyNode *latitude
1502 // = fgGetNode("/sim/presets/latitude-deg");
1503 static const SGPropertyNode *altitude
1504 = fgGetNode("/sim/presets/altitude-ft");
1505 static const SGPropertyNode *master_freeze
1506 = fgGetNode("/sim/freeze/master");
1508 SG_LOG( SG_GENERAL, SG_INFO,
1509 "fgReInitSubsystems(): /position/altitude = "
1510 << altitude->getDoubleValue() );
1512 bool freeze = master_freeze->getBoolValue();
1514 fgSetBool("/sim/freeze/master", true);
1516 fgSetBool("/sim/crashed", false);
1518 // Force reupdating the positions of the ai 3d models. They are used for
1519 // initializing ground level for the FDM.
1520 globals->get_subsystem("ai_model")->reinit();
1522 // Initialize the FDM
1523 globals->get_subsystem("flight")->reinit();
1525 // reload offsets from config defaults
1526 globals->get_viewmgr()->reinit();
1528 globals->get_controls()->reset_all();
1530 globals->get_subsystem("time")->reinit();
1531 globals->get_subsystem("tile-manager")->reinit();
1534 fgSetBool("/sim/freeze/master", false);
1536 fgSetBool("/sim/sceneryloaded",false);
1540 void doSimulatorReset(void) // from gui_local.cxx -- TODO merge with fgReInitSubsystems()
1542 static SGPropertyNode_ptr master_freeze = fgGetNode("/sim/freeze/master", true);
1544 bool freeze = master_freeze->getBoolValue();
1546 master_freeze->setBoolValue(true);
1548 fgSetBool("/sim/signals/reinit", true);
1550 globals->get_subsystem("flight")->unbind();
1552 globals->restoreInitialState();
1554 // update our position based on current presets
1557 fgReInitSubsystems();
1559 fgSetBool("/sim/signals/reinit", false);
1562 master_freeze->setBoolValue(false);
1565 ///////////////////////////////////////////////////////////////////////////////
1566 // helper object to implement the --show-aircraft command.
1567 // resides here so we can share the fgFindAircraftInDir template above,
1568 // and hence ensure this command lists exectly the same aircraft as the normal
1575 _minStatus = getNumMaturity(fgGetString("/sim/aircraft-min-status", "all"));
1579 void show(const SGPath& path)
1581 fgFindAircraftInDir(path, this, &ShowAircraft::processAircraft);
1583 std::sort(_aircraft.begin(), _aircraft.end(), ciLessLibC());
1584 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1585 cout << "Available aircraft:" << endl;
1586 for ( unsigned int i = 0; i < _aircraft.size(); i++ ) {
1587 cout << _aircraft[i] << endl;
1592 bool processAircraft(const SGPath& path)
1594 SGPropertyNode root;
1596 readProperties(path.str(), &root);
1597 } catch (sg_exception& ) {
1602 string descStr(" ");
1603 descStr += path.file();
1604 // trim common suffix from file names
1605 int nPos = descStr.rfind("-set.xml");
1606 if (nPos == (int)(descStr.size() - 8)) {
1607 descStr.resize(nPos);
1610 SGPropertyNode *node = root.getNode("sim");
1612 SGPropertyNode* desc = node->getNode("description");
1613 // if a status tag is found, read it in
1614 if (node->hasValue("status")) {
1615 maturity = getNumMaturity(node->getStringValue("status"));
1619 if (descStr.size() <= 27+3) {
1620 descStr.append(29+3-descStr.size(), ' ');
1623 descStr.append( 32, ' ');
1625 descStr += desc->getStringValue();
1627 } // of have 'sim' node
1629 if (maturity < _minStatus) {
1633 _aircraft.push_back(descStr);
1638 int getNumMaturity(const char * str)
1640 // changes should also be reflected in $FG_ROOT/data/options.xml &
1641 // $FG_ROOT/data/Translations/string-default.xml
1642 const char* levels[] = {"alpha","beta","early-production","production"};
1644 if (!strcmp(str, "all")) {
1648 for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
1649 if (strcmp(str,levels[i])==0)
1655 // recommended in Meyers, Effective STL when internationalization and embedded
1656 // NULLs aren't an issue. Much faster than the STL or Boost lex versions.
1657 struct ciLessLibC : public std::binary_function<string, string, bool>
1659 bool operator()(const std::string &lhs, const std::string &rhs) const
1661 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
1666 string_list _aircraft;
1669 void fgShowAircraft(const SGPath &path)
1675 cout << "Hit a key to continue..." << endl;