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/interpolator.hxx>
62 #include <simgear/scene/material/matlib.hxx>
63 #include <simgear/scene/model/particles.hxx>
64 #include <simgear/sound/soundmgr_openal.hxx>
66 #include <Aircraft/controls.hxx>
67 #include <Aircraft/replay.hxx>
68 #include <Airports/apt_loader.hxx>
69 #include <Airports/runways.hxx>
70 #include <Airports/simple.hxx>
71 #include <Airports/dynamics.hxx>
73 #include <AIModel/AIManager.hxx>
76 # include <ATCDCL/ATCmgr.hxx>
77 # include "ATCDCL/commlist.hxx"
79 # include "ATC/atis.hxx"
80 # include "ATC/atcutils.hxx"
83 #include <Autopilot/route_mgr.hxx>
84 #include <Autopilot/autopilotgroup.hxx>
86 #include <Cockpit/cockpit.hxx>
87 #include <Cockpit/panel.hxx>
88 #include <Cockpit/panel_io.hxx>
90 #include <GUI/new_gui.hxx>
91 #include <Input/input.hxx>
92 #include <Instrumentation/instrument_mgr.hxx>
93 #include <Model/acmodel.hxx>
94 #include <AIModel/submodel.hxx>
95 #include <AIModel/AIManager.hxx>
96 #include <Navaids/navdb.hxx>
97 #include <Navaids/navlist.hxx>
98 #include <Navaids/fix.hxx>
99 #include <Navaids/fixlist.hxx>
100 #include <Navaids/airways.hxx>
101 #include <Scenery/scenery.hxx>
102 #include <Scenery/tilemgr.hxx>
103 #include <Scripting/NasalSys.hxx>
104 #include <Sound/voice.hxx>
105 #include <Systems/system_mgr.hxx>
106 #include <Time/light.hxx>
107 #include <Traffic/TrafficMgr.hxx>
108 #include <MultiPlayer/multiplaymgr.hxx>
109 #include <FDM/fdm_shell.hxx>
111 #include <Environment/environment_mgr.hxx>
113 #include "fg_init.hxx"
115 #include "fg_commands.hxx"
116 #include "fg_props.hxx"
117 #include "options.hxx"
118 #include "globals.hxx"
119 #include "logger.hxx"
120 #include "renderer.hxx"
121 #include "viewmgr.hxx"
126 # include <CoreFoundation/CoreFoundation.h>
130 using namespace boost::algorithm;
132 extern const char *default_root;
135 // Scan the command line options for the specified option and return
137 static string fgScanForOption( const string& option, int argc, char **argv ) {
140 if (hostname == NULL)
143 if( gethostname(_hostname, 256) >= 0 ) {
144 hostname = strdup(_hostname);
145 free_hostname = true;
149 SG_LOG(SG_GENERAL, SG_INFO, "Scanning command line for: " << option );
151 int len = option.length();
154 SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] );
156 string arg = argv[i];
157 if ( arg.find( option ) == 0 ) {
158 return arg.substr( len );
168 // Scan the user config files for the specified option and return
170 static string fgScanForOption( const string& option, const string& path ) {
171 sg_gzifstream in( path );
172 if ( !in.is_open() ) {
176 SG_LOG( SG_GENERAL, SG_INFO, "Scanning " << path << " for: " << option );
178 int len = option.length();
181 while ( ! in.eof() ) {
183 getline( in, line, '\n' );
185 // catch extraneous (DOS) line ending character
186 if ( line[line.length() - 1] < 32 ) {
187 line = line.substr( 0, line.length()-1 );
190 if ( line.find( option ) == 0 ) {
191 return line.substr( len );
200 // Scan the user config files for the specified option and return
202 static string fgScanForOption( const string& option ) {
205 #if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
206 // Next check home directory for .fgfsrc.hostname file
208 if ( homedir != NULL && hostname != NULL && strlen(hostname) > 0) {
209 SGPath config( homedir );
210 config.append( ".fgfsrc" );
211 config.concat( "." );
212 config.concat( hostname );
213 arg = fgScanForOption( option, config.str() );
218 // Next check home directory for .fgfsrc file
220 if ( homedir != NULL ) {
221 SGPath config( homedir );
222 config.append( ".fgfsrc" );
223 arg = fgScanForOption( option, config.str() );
228 // Check for $fg_root/system.fgfsrc
229 SGPath config( globals->get_fg_root() );
230 config.append( "system.fgfsrc" );
231 arg = fgScanForOption( option, config.str() );
238 // Read in configuration (files and command line options) but only set
239 // fg_root and aircraft_paths, which are needed *before* do_options() is called
242 bool fgInitFGRoot ( int argc, char **argv ) {
245 // First parse command line options looking for --fg-root=, this
246 // will override anything specified in a config file
247 root = fgScanForOption( "--fg-root=", argc, argv);
249 // Check in one of the user configuration files.
251 root = fgScanForOption( "--fg-root=" );
253 // Next check if fg-root is set as an env variable
254 if ( root.empty() ) {
255 char *envp = ::getenv( "FG_ROOT" );
256 if ( envp != NULL ) {
261 // Otherwise, default to a random compiled-in location if we can't
262 // find fg-root any other way.
263 if ( root.empty() ) {
264 #if defined( __CYGWIN__ )
266 #elif defined( _WIN32 )
268 #elif defined(__APPLE__)
270 The following code looks for the base package inside the application
271 bundle, in the standard Contents/Resources location.
273 CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
275 // look for a 'data' subdir
276 CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true);
278 // now convert down to a path, and the a c-string
279 CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
280 root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
282 CFRelease(resourcesUrl);
290 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
291 globals->set_fg_root(root);
297 // Read in configuration (files and command line options) but only set
299 bool fgInitFGAircraft ( int argc, char **argv ) {
301 string aircraftDir = fgScanForOption("--fg-aircraft=", argc, argv);
302 if (aircraftDir.empty()) {
303 aircraftDir = fgScanForOption("--fg-aircraft=");
306 const char* envp = ::getenv("FG_AIRCRAFT");
307 if (aircraftDir.empty() && envp) {
308 globals->append_aircraft_paths(envp);
311 if (!aircraftDir.empty()) {
312 globals->append_aircraft_paths(aircraftDir);
317 // First parse command line options looking for --aircraft=, this
318 // will override anything specified in a config file
319 aircraft = fgScanForOption( "--aircraft=", argc, argv );
320 if ( aircraft.empty() ) {
321 // check synonym option
322 aircraft = fgScanForOption( "--vehicle=", argc, argv );
325 // Check in one of the user configuration files.
326 if ( aircraft.empty() ) {
327 aircraft = fgScanForOption( "--aircraft=" );
329 if ( aircraft.empty() ) {
330 aircraft = fgScanForOption( "--vehicle=" );
333 // if an aircraft was specified, set the property name
334 if ( !aircraft.empty() ) {
335 SG_LOG(SG_INPUT, SG_INFO, "aircraft = " << aircraft );
336 fgSetString("/sim/aircraft", aircraft.c_str() );
338 SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
345 // Return the current base package version
346 string fgBasePackageVersion() {
347 SGPath base_path( globals->get_fg_root() );
348 base_path.append("version");
350 sg_gzifstream in( base_path.str() );
351 if ( !in.is_open() ) {
352 SGPath old_path( globals->get_fg_root() );
353 old_path.append( "Thanks" );
354 sg_gzifstream old( old_path.str() );
355 if ( !old.is_open() ) {
358 return "[old version]";
369 // Initialize the localization
370 SGPropertyNode *fgInitLocale(const char *language) {
371 SGPropertyNode *c_node = NULL, *d_node = NULL;
372 SGPropertyNode *intl = fgGetNode("/sim/intl");
374 SG_LOG(SG_GENERAL, SG_INFO, "Selecting language: " << language );
376 // localization not defined
381 // Select the proper language from the list
383 vector<SGPropertyNode_ptr> locale = intl->getChildren("locale");
384 for (unsigned int i = 0; i < locale.size(); i++) {
386 vector<SGPropertyNode_ptr> lang = locale[i]->getChildren("lang");
387 for (unsigned int j = 0; j < lang.size(); j++) {
389 if (!strcmp(lang[j]->getStringValue(), language)) {
398 d_node = intl->getChild("locale");
402 // Check for localized font
403 SGPropertyNode *font_n = c_node->getNode("font", true);
404 if ( !strcmp(font_n->getStringValue(), "") )
405 font_n->setStringValue(d_node->getStringValue("font", "typewriter.txf"));
409 // Load the default strings
411 SGPath d_path( globals->get_fg_root() );
413 const char *d_path_str = d_node->getStringValue("strings");
415 SG_LOG(SG_GENERAL, SG_ALERT, "No path in " << d_node->getPath() << "/strings.");
419 d_path.append(d_path_str);
420 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from " << d_path.str());
422 SGPropertyNode *strings = c_node->getNode("strings");
424 readProperties(d_path.str(), strings);
425 } catch (const sg_exception &) {
426 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to read the localized strings");
431 // Load the language specific strings
433 if (c_node != d_node) {
434 SGPath c_path( globals->get_fg_root() );
436 const char *c_path_str = c_node->getStringValue("strings");
438 SG_LOG(SG_GENERAL, SG_ALERT, "No path in " << c_node->getPath() << "/strings");
442 c_path.append(c_path_str);
443 SG_LOG(SG_GENERAL, SG_INFO, "Reading localized strings from " << c_path.str());
446 readProperties(c_path.str(), strings);
447 } catch (const sg_exception &) {
448 SG_LOG(SG_GENERAL, SG_ALERT,
449 "Unable to read the localized strings from " << c_path.str());
459 // Initialize the localization routines
460 bool fgDetectLanguage() {
461 const char *language = ::getenv("LANG");
463 if (language == NULL) {
464 SG_LOG(SG_GENERAL, SG_INFO, "Unable to detect the language" );
468 SGPropertyNode *locale = fgInitLocale(language);
470 SG_LOG(SG_GENERAL, SG_ALERT,
471 "No internationalization settings specified in preferences.xml" );
476 globals->set_locale( locale );
481 // Attempt to locate and parse the various non-XML config files in order
482 // from least precidence to greatest precidence
484 do_options (int argc, char ** argv)
486 // Check for $fg_root/system.fgfsrc
487 SGPath config( globals->get_fg_root() );
488 config.append( "system.fgfsrc" );
489 fgParseOptions(config.str());
491 #if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
492 if( hostname != NULL && strlen(hostname) > 0 ) {
493 config.concat( "." );
494 config.concat( hostname );
495 fgParseOptions(config.str());
499 // Check for ~/.fgfsrc
500 if ( homedir != NULL ) {
501 config.set( homedir );
502 config.append( ".fgfsrc" );
503 fgParseOptions(config.str());
506 #if defined( unix ) || defined( __CYGWIN__ ) || defined(_MSC_VER)
507 if( hostname != NULL && strlen(hostname) > 0 ) {
508 // Check for ~/.fgfsrc.hostname
509 config.concat( "." );
510 config.concat( hostname );
511 fgParseOptions(config.str());
515 // Parse remaining command line options
516 // These will override anything specified in a config file
517 fgParseArgs(argc, argv);
521 bool fgFindAircraftInDir(const SGPath& dirPath, T* obj, bool (T::*pred)(const SGPath& p))
523 if (!dirPath.exists()) {
524 SG_LOG(SG_GENERAL, SG_WARN, "fgFindAircraftInDir: no such path:" << dirPath.str());
529 simgear::Dir dir(dirPath);
530 simgear::PathList setFiles(dir.children(simgear::Dir::TYPE_FILE, "-set.xml"));
531 simgear::PathList::iterator p;
532 for (p = setFiles.begin(); p != setFiles.end(); ++p) {
533 // check file name ends with -set.xml
535 // if we found a -set.xml at this level, don't recurse any deeper
538 bool done = (obj->*pred)(*p);
542 } // of -set.xml iteration
548 simgear::PathList subdirs(dir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT));
549 for (p = subdirs.begin(); p != subdirs.end(); ++p) {
550 if (p->file() == "CVS") {
554 if (fgFindAircraftInDir(*p, obj, pred)) {
557 } // of subdirs iteration
563 void fgFindAircraft(T* obj, bool (T::*pred)(const SGPath& p))
565 const string_list& paths(globals->get_aircraft_paths());
566 string_list::const_iterator it = paths.begin();
567 for (; it != paths.end(); ++it) {
568 bool done = fgFindAircraftInDir(SGPath(*it), obj, pred);
572 } // of aircraft paths iteration
574 // if we reach this point, search the default location (always last)
575 SGPath rootAircraft(globals->get_fg_root());
576 rootAircraft.append("Aircraft");
577 fgFindAircraftInDir(rootAircraft, obj, pred);
580 class FindAndCacheAircraft
583 FindAndCacheAircraft(SGPropertyNode* autoSave)
585 _cache = autoSave->getNode("sim/startup/path-cache", true);
590 std::string aircraft = fgGetString( "/sim/aircraft", "");
591 if (aircraft.empty()) {
592 SG_LOG(SG_GENERAL, SG_ALERT, "no aircraft specified");
596 _searchAircraft = aircraft + "-set.xml";
598 // prepare cache for re-scan
599 SGPropertyNode *n = _cache->getNode("fg-root", true);
600 n->setStringValue(globals->get_fg_root().c_str());
601 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
602 _cache->removeChildren("aircraft");
604 fgFindAircraft(this, &FindAndCacheAircraft::checkAircraft);
607 if (_foundPath.str().empty()) {
608 SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find specified aircraft: " << aircraft );
612 SG_LOG(SG_GENERAL, SG_INFO, "Loading aircraft -set file from:" << _foundPath.str());
613 fgSetString( "/sim/aircraft-dir", _foundPath.dir().c_str());
614 if (!_foundPath.exists()) {
615 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to find -set file:" << _foundPath.str());
620 readProperties(_foundPath.str(), globals->get_props());
621 } catch ( const sg_exception &e ) {
622 SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
632 if (globals->get_fg_root() != _cache->getStringValue("fg-root", "")) {
633 return false; // cache mismatch
636 vector<SGPropertyNode_ptr> cache = _cache->getChildren("aircraft");
637 for (unsigned int i = 0; i < cache.size(); i++) {
638 const char *name = cache[i]->getStringValue("file", "");
639 if (!boost::equals(_searchAircraft, name, is_iequal())) {
643 SGPath xml(cache[i]->getStringValue("path", ""));
651 } // of aircraft in cache iteration
656 bool checkAircraft(const SGPath& p)
661 if (!_cache->getChild("aircraft", i++, false))
665 SGPropertyNode *n, *entry = _cache->getChild("aircraft", --i, true);
667 std::string fileName(p.file());
668 n = entry->getNode("file", true);
669 n->setStringValue(fileName);
670 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
672 n = entry->getNode("path", true);
673 n->setStringValue(p.dir());
674 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
676 if ( boost::equals(fileName, _searchAircraft.c_str(), is_iequal()) ) {
684 std::string _searchAircraft;
686 SGPropertyNode* _cache;
689 // Read in configuration (file and command line)
690 bool fgInitConfig ( int argc, char **argv ) {
692 // First, set some sane default values
695 // Read global preferences from $FG_ROOT/preferences.xml
696 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
697 fgLoadProps("preferences.xml", globals->get_props());
698 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
700 // Detect the required language as early as possible
701 if ( !fgDetectLanguage() ) {
705 SGPropertyNode autosave;
707 char *envp = ::getenv( "APPDATA" );
709 SGPath config( envp );
710 config.append( "flightgear.org" );
712 if ( homedir != NULL ) {
713 SGPath config( homedir );
714 config.append( ".fgfs" );
716 const char *fg_home = getenv("FG_HOME");
720 SGPath home_export(config.str());
721 home_export.append("Export/dummy");
722 home_export.create_dir(0777);
724 // Set /sim/fg-home and don't allow malign code to override it until
725 // Nasal security is set up. Use FG_HOME if necessary.
726 SGPropertyNode *home = fgGetNode("/sim", true);
727 home->removeChild("fg-home", 0, false);
728 home = home->getChild("fg-home", 0, true);
729 home->setStringValue(config.c_str());
730 home->setAttribute(SGPropertyNode::WRITE, false);
732 config.append( "autosave.xml" );
733 if (config.exists()) {
734 SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
736 readProperties(config.str(), &autosave, SGPropertyNode::USERARCHIVE);
737 } catch (sg_exception& e) {
738 SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
739 << "(from " << e.getOrigin() << ")");
744 // Scan user config files and command line for a specified aircraft.
745 fgInitFGAircraft(argc, argv);
746 FindAndCacheAircraft f(&autosave);
747 if (!f.loadAircraft()) {
751 copyProperties(&autosave, globals->get_props());
753 // parse options after loading aircraft to ensure any user
754 // overrides of defaults are honored.
755 do_options(argc, argv);
760 // Set current tower position lon/lat given an airport id
761 static bool fgSetTowerPosFromAirportID( const string& id) {
762 const FGAirport *a = fgFindAirportID( id);
764 SGGeod tower = a->getTowerLocation();
765 fgSetDouble("/sim/tower/longitude-deg", tower.getLongitudeDeg());
766 fgSetDouble("/sim/tower/latitude-deg", tower.getLatitudeDeg());
767 fgSetDouble("/sim/tower/altitude-ft", tower.getElevationFt());
775 struct FGTowerLocationListener : SGPropertyChangeListener {
776 void valueChanged(SGPropertyNode* node) {
777 const string id(node->getStringValue());
778 fgSetTowerPosFromAirportID(id);
782 void fgInitTowerLocationListener() {
783 fgGetNode("/sim/tower/airport-id", true)
784 ->addChangeListener( new FGTowerLocationListener(), true );
787 static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double aTargetHeading = HUGE_VAL)
789 SGGeod startPos(aStartPos);
790 if (aTargetHeading == HUGE_VAL) {
791 aTargetHeading = aHeading;
794 if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON ) {
795 double offsetDistance = fgGetDouble("/sim/presets/offset-distance-nm");
796 offsetDistance *= SG_NM_TO_METER;
797 double offsetAzimuth = aHeading;
798 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth-deg")) > SG_EPSILON ) {
799 offsetAzimuth = fgGetDouble("/sim/presets/offset-azimuth-deg");
800 aHeading = aTargetHeading;
805 SGGeodesy::direct(startPos, offsetAzimuth + 180, offsetDistance, offset, az2);
810 fgSetDouble("/sim/presets/longitude-deg", startPos.getLongitudeDeg() );
811 fgSetDouble("/sim/presets/latitude-deg", startPos.getLatitudeDeg() );
812 fgSetDouble("/sim/presets/heading-deg", aHeading );
814 // other code depends on the actual values being set ...
815 fgSetDouble("/position/longitude-deg", startPos.getLongitudeDeg() );
816 fgSetDouble("/position/latitude-deg", startPos.getLatitudeDeg() );
817 fgSetDouble("/orientation/heading-deg", aHeading );
820 // Set current_options lon/lat given an airport id and heading (degrees)
821 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
825 // set initial position from runway and heading
826 SG_LOG( SG_GENERAL, SG_INFO,
827 "Attempting to set starting position from airport code "
828 << id << " heading " << tgt_hdg );
830 const FGAirport* apt = fgFindAirportID(id);
831 if (!apt) return false;
832 FGRunway* r = apt->findBestRunwayForHeading(tgt_hdg);
833 fgSetString("/sim/atc/runway", r->ident().c_str());
835 SGGeod startPos = r->pointOnCenterline(fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
836 fgApplyStartOffset(startPos, r->headingDeg(), tgt_hdg);
840 // Set current_options lon/lat given an airport id and parkig position name
841 static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) {
845 // can't see an easy way around this const_cast at the moment
846 FGAirport* apt = const_cast<FGAirport*>(fgFindAirportID(id));
848 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport " << id );
851 FGAirportDynamics* dcs = apt->getDynamics();
853 SG_LOG( SG_GENERAL, SG_ALERT,
854 "Failed to find parking position " << parkpos <<
855 " at airport " << id );
859 int park_index = dcs->getNrOfParkings() - 1;
860 while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) park_index--;
861 if (park_index < 0) {
862 SG_LOG( SG_GENERAL, SG_ALERT,
863 "Failed to find parking position " << parkpos <<
864 " at airport " << id );
867 FGParking* parking = dcs->getParking(park_index);
868 parking->setAvailable(false);
870 SGGeod::fromDeg(parking->getLongitude(), parking->getLatitude()),
871 parking->getHeading());
876 // Set current_options lon/lat given an airport id and runway number
877 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, bool rwy_req ) {
881 // set initial position from airport and runway number
882 SG_LOG( SG_GENERAL, SG_INFO,
883 "Attempting to set starting position for "
884 << id << ":" << rwy );
886 const FGAirport* apt = fgFindAirportID(id);
888 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport:" << id);
892 if (!apt->hasRunwayWithIdent(rwy)) {
893 SG_LOG( SG_GENERAL, rwy_req ? SG_ALERT : SG_INFO,
894 "Failed to find runway " << rwy <<
895 " at airport " << id << ". Using default runway." );
899 FGRunway* r(apt->getRunwayByIdent(rwy));
900 fgSetString("/sim/atc/runway", r->ident().c_str());
901 SGGeod startPos = r->pointOnCenterline( fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
902 fgApplyStartOffset(startPos, r->headingDeg());
907 static void fgSetDistOrAltFromGlideSlope() {
908 // cout << "fgSetDistOrAltFromGlideSlope()" << endl;
909 string apt_id = fgGetString("/sim/presets/airport-id");
910 double gs = fgGetDouble("/sim/presets/glideslope-deg")
911 * SG_DEGREES_TO_RADIANS ;
912 double od = fgGetDouble("/sim/presets/offset-distance-nm");
913 double alt = fgGetDouble("/sim/presets/altitude-ft");
915 double apt_elev = 0.0;
916 if ( ! apt_id.empty() ) {
917 apt_elev = fgGetAirportElev( apt_id );
918 if ( apt_elev < -9990.0 ) {
925 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
926 // set altitude from glideslope and offset-distance
927 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
928 alt = fabs(od*tan(gs)) + apt_elev;
929 fgSetDouble("/sim/presets/altitude-ft", alt);
930 fgSetBool("/sim/presets/onground", false);
931 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
933 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
934 // set offset-distance from glideslope and altitude
935 od = (alt - apt_elev) / tan(gs);
936 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
937 fgSetDouble("/sim/presets/offset-distance-nm", od);
938 fgSetBool("/sim/presets/onground", false);
939 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
941 } else if( fabs(gs) > 0.01 ) {
942 SG_LOG( SG_GENERAL, SG_ALERT,
943 "Glideslope given but not altitude or offset-distance." );
944 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
945 fgSetDouble("/sim/presets/glideslope-deg", 0);
946 fgSetBool("/sim/presets/onground", true);
951 // Set current_options lon/lat given an airport id and heading (degrees)
952 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
954 = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq );
957 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
958 << id << ":" << freq );
962 fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
966 // Set current_options lon/lat given an aircraft carrier id
967 static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
969 // set initial position from runway and heading
973 if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) {
974 double lon = geodPos.getLongitudeDeg();
975 double lat = geodPos.getLatitudeDeg();
976 double alt = geodPos.getElevationFt();
978 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
979 << carrier << " at lat = " << lat << ", lon = " << lon
980 << ", alt = " << alt << ", heading = " << heading);
982 fgSetDouble("/sim/presets/longitude-deg", lon);
983 fgSetDouble("/sim/presets/latitude-deg", lat);
984 fgSetDouble("/sim/presets/altitude-ft", alt);
985 fgSetDouble("/sim/presets/heading-deg", heading);
986 fgSetDouble("/position/longitude-deg", lon);
987 fgSetDouble("/position/latitude-deg", lat);
988 fgSetDouble("/position/altitude-ft", alt);
989 fgSetDouble("/orientation/heading-deg", heading);
991 fgSetString("/sim/presets/speed-set", "UVW");
992 fgSetDouble("/velocities/uBody-fps", uvw(0));
993 fgSetDouble("/velocities/vBody-fps", uvw(1));
994 fgSetDouble("/velocities/wBody-fps", uvw(2));
995 fgSetDouble("/sim/presets/uBody-fps", uvw(0));
996 fgSetDouble("/sim/presets/vBody-fps", uvw(1));
997 fgSetDouble("/sim/presets/wBody-fps", uvw(2));
999 fgSetBool("/sim/presets/onground", true);
1003 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = "
1009 // Set current_options lon/lat given an airport id and heading (degrees)
1010 static bool fgSetPosFromFix( const string& id )
1012 FGPositioned::TypeFilter fixFilter(FGPositioned::FIX);
1013 FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter);
1015 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id );
1019 fgApplyStartOffset(fix->geod(), fgGetDouble("/sim/presets/heading-deg"));
1024 * Initialize vor/ndb/ils/fix list management and query systems (as
1025 * well as simple airport db list)
1030 SG_LOG(SG_GENERAL, SG_INFO, "Loading Airport Database ...");
1032 SGPath aptdb( globals->get_fg_root() );
1033 aptdb.append( "Airports/apt.dat" );
1035 SGPath p_metar( globals->get_fg_root() );
1036 p_metar.append( "Airports/metar.dat" );
1038 // Initialise the frequency search map BEFORE reading
1039 // the airport database:
1043 current_commlist = new FGCommList;
1044 current_commlist->init( globals->get_fg_root() );
1045 fgAirportDBLoad( aptdb.str(), current_commlist, p_metar.str() );
1047 FGNavList *navlist = new FGNavList;
1048 FGNavList *loclist = new FGNavList;
1049 FGNavList *gslist = new FGNavList;
1050 FGNavList *dmelist = new FGNavList;
1051 FGNavList *tacanlist = new FGNavList;
1052 FGNavList *carrierlist = new FGNavList;
1053 FGTACANList *channellist = new FGTACANList;
1055 globals->set_navlist( navlist );
1056 globals->set_loclist( loclist );
1057 globals->set_gslist( gslist );
1058 globals->set_dmelist( dmelist );
1059 globals->set_tacanlist( tacanlist );
1060 globals->set_carrierlist( carrierlist );
1061 globals->set_channellist( channellist );
1063 if ( !fgNavDBInit(navlist, loclist, gslist, dmelist, tacanlist, carrierlist, channellist) ) {
1064 SG_LOG( SG_GENERAL, SG_ALERT,
1065 "Problems loading one or more navigational database" );
1068 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1069 SGPath p_fix( globals->get_fg_root() );
1070 p_fix.append( "Navaids/fix.dat" );
1072 fixlist.init( p_fix ); // adds fixes to the DB in positioned.cxx
1074 SG_LOG(SG_GENERAL, SG_INFO, " Airways");
1076 SGPath p_awy( globals->get_fg_root() );
1077 p_awy.append( "Navaids/awy.dat" );
1078 FGAirwayNetwork *awyNet = new FGAirwayNetwork;
1079 //cerr << "Loading Airways" << endl;
1080 awyNet->load (p_awy );
1082 //cerr << "initializing airways" << endl;
1083 globals->set_airwaynet( awyNet );
1085 flightgear::Airway::load();
1091 // Set the initial position based on presets (or defaults)
1092 bool fgInitPosition() {
1093 // cout << "fgInitPosition()" << endl;
1094 double gs = fgGetDouble("/sim/presets/glideslope-deg")
1095 * SG_DEGREES_TO_RADIANS ;
1096 double od = fgGetDouble("/sim/presets/offset-distance-nm");
1097 double alt = fgGetDouble("/sim/presets/altitude-ft");
1099 bool set_pos = false;
1101 // If glideslope is specified, then calculate offset-distance or
1102 // altitude relative to glide slope if either of those was not
1104 if ( fabs( gs ) > 0.01 ) {
1105 fgSetDistOrAltFromGlideSlope();
1109 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1110 // If not, check for an airport-id and use that.
1111 // If not, default to the middle of the KSFO field.
1112 // The default values for lon/lat are deliberately out of range
1113 // so that the airport-id can take effect; valid lon/lat will
1114 // override airport-id, however.
1115 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1116 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1117 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1118 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1123 string apt = fgGetString("/sim/presets/airport-id");
1124 string rwy_no = fgGetString("/sim/presets/runway");
1125 bool rwy_req = fgGetBool("/sim/presets/runway-requested");
1126 string vor = fgGetString("/sim/presets/vor-id");
1127 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1128 string ndb = fgGetString("/sim/presets/ndb-id");
1129 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1130 string carrier = fgGetString("/sim/presets/carrier");
1131 string parkpos = fgGetString("/sim/presets/parkpos");
1132 string fix = fgGetString("/sim/presets/fix");
1133 SGPropertyNode *hdg_preset = fgGetNode("/sim/presets/heading-deg", true);
1134 double hdg = hdg_preset->getDoubleValue();
1136 // save some start parameters, so that we can later say what the
1137 // user really requested. TODO generalize that and move it to options.cxx
1138 static bool start_options_saved = false;
1139 if (!start_options_saved) {
1140 start_options_saved = true;
1141 SGPropertyNode *opt = fgGetNode("/sim/startup/options", true);
1143 opt->setDoubleValue("latitude-deg", lat_deg);
1144 opt->setDoubleValue("longitude-deg", lon_deg);
1145 opt->setDoubleValue("heading-deg", hdg);
1146 opt->setStringValue("airport", apt.c_str());
1147 opt->setStringValue("runway", rwy_no.c_str());
1151 hdg = fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270);
1153 if ( !set_pos && !apt.empty() && !parkpos.empty() ) {
1154 // An airport + parking position is requested
1155 if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
1156 // set tower position
1157 fgSetString("/sim/tower/airport-id", apt.c_str());
1162 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1163 // An airport + runway is requested
1164 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
1165 // set tower position (a little off the heading for single
1167 fgSetString("/sim/tower/airport-id", apt.c_str());
1172 if ( !set_pos && !apt.empty() ) {
1173 // An airport is requested (find runway closest to hdg)
1174 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1175 // set tower position (a little off the heading for single
1177 fgSetString("/sim/tower/airport-id", apt.c_str());
1182 if (hdg_preset->getDoubleValue() > 9990.0)
1183 hdg_preset->setDoubleValue(hdg);
1185 if ( !set_pos && !vor.empty() ) {
1186 // a VOR is requested
1187 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1192 if ( !set_pos && !ndb.empty() ) {
1193 // an NDB is requested
1194 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1199 if ( !set_pos && !carrier.empty() ) {
1200 // an aircraft carrier is requested
1201 if ( fgSetPosFromCarrier( carrier, parkpos ) ) {
1206 if ( !set_pos && !fix.empty() ) {
1207 // a Fix is requested
1208 if ( fgSetPosFromFix( fix ) ) {
1214 // No lon/lat specified, no airport specified, default to
1215 // middle of KSFO field.
1216 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1217 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1220 fgSetDouble( "/position/longitude-deg",
1221 fgGetDouble("/sim/presets/longitude-deg") );
1222 fgSetDouble( "/position/latitude-deg",
1223 fgGetDouble("/sim/presets/latitude-deg") );
1224 fgSetDouble( "/orientation/heading-deg", hdg_preset->getDoubleValue());
1226 // determine if this should be an on-ground or in-air start
1227 if ((fabs(gs) > 0.01 || fabs(od) > 0.1 || alt > 0.1) && carrier.empty()) {
1228 fgSetBool("/sim/presets/onground", false);
1230 fgSetBool("/sim/presets/onground", true);
1237 // General house keeping initializations
1238 bool fgInitGeneral() {
1241 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1242 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1244 root = globals->get_fg_root();
1245 if ( ! root.length() ) {
1246 // No root path set? Then bail ...
1247 SG_LOG( SG_GENERAL, SG_ALERT,
1248 "Cannot continue without a path to the base package "
1249 << "being defined." );
1252 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1254 globals->set_browser(fgGetString("/sim/startup/browser-app", "firefox %u"));
1256 char buf[512], *cwd = getcwd(buf, 511);
1258 SGPropertyNode *curr = fgGetNode("/sim", true);
1259 curr->removeChild("fg-current", 0, false);
1260 curr = curr->getChild("fg-current", 0, true);
1261 curr->setStringValue(cwd ? cwd : "");
1262 curr->setAttribute(SGPropertyNode::WRITE, false);
1264 fgSetBool("/sim/startup/stdout-to-terminal", isatty(1) != 0 );
1265 fgSetBool("/sim/startup/stderr-to-terminal", isatty(2) != 0 );
1269 // This is the top level init routine which calls all the other
1270 // initialization routines. If you are adding a subsystem to flight
1271 // gear, its initialization call should located in this routine.
1272 // Returns non-zero if a problem encountered.
1273 bool fgInitSubsystems() {
1274 // static const SGPropertyNode *longitude
1275 // = fgGetNode("/sim/presets/longitude-deg");
1276 // static const SGPropertyNode *latitude
1277 // = fgGetNode("/sim/presets/latitude-deg");
1278 // static const SGPropertyNode *altitude
1279 // = fgGetNode("/sim/presets/altitude-ft");
1281 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1282 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1284 ////////////////////////////////////////////////////////////////////
1285 // Initialize the event manager subsystem.
1286 ////////////////////////////////////////////////////////////////////
1288 globals->get_event_mgr()->init();
1289 globals->get_event_mgr()->setRealtimeProperty(fgGetNode("/sim/time/delta-realtime-sec", true));
1291 ////////////////////////////////////////////////////////////////////
1292 // Initialize the property interpolator subsystem. Put into the INIT
1293 // group because the "nasal" subsystem may need it at GENERAL take-down.
1294 ////////////////////////////////////////////////////////////////////
1295 globals->add_subsystem("interpolator", new SGInterpolator, SGSubsystemMgr::INIT);
1298 ////////////////////////////////////////////////////////////////////
1299 // Add the FlightGear property utilities.
1300 ////////////////////////////////////////////////////////////////////
1301 globals->add_subsystem("properties", new FGProperties);
1303 ////////////////////////////////////////////////////////////////////
1304 // Initialize the material property subsystem.
1305 ////////////////////////////////////////////////////////////////////
1307 SGPath mpath( globals->get_fg_root() );
1308 mpath.append( "materials.xml" );
1309 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
1310 globals->get_props()) ) {
1311 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1316 ////////////////////////////////////////////////////////////////////
1317 // Initialize the scenery management subsystem.
1318 ////////////////////////////////////////////////////////////////////
1320 globals->add_subsystem("tile-manager", globals->get_tile_mgr(),
1321 SGSubsystemMgr::DISPLAY);
1323 globals->get_scenery()->get_scene_graph()
1324 ->addChild(simgear::Particles::getCommonRoot());
1325 simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
1327 ////////////////////////////////////////////////////////////////////
1328 // Initialize the flight model subsystem.
1329 ////////////////////////////////////////////////////////////////////
1331 globals->add_subsystem("flight", new FDMShell, SGSubsystemMgr::FDM);
1333 ////////////////////////////////////////////////////////////////////
1334 // Initialize the weather subsystem.
1335 ////////////////////////////////////////////////////////////////////
1337 // Initialize the weather modeling subsystem
1338 globals->add_subsystem("environment", new FGEnvironmentMgr);
1340 ////////////////////////////////////////////////////////////////////
1341 // Initialize the aircraft systems and instrumentation (before the
1343 ////////////////////////////////////////////////////////////////////
1345 globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM);
1346 globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM);
1348 ////////////////////////////////////////////////////////////////////
1349 // Initialize the XML Autopilot subsystem.
1350 ////////////////////////////////////////////////////////////////////
1352 globals->add_subsystem( "xml-autopilot", FGXMLAutopilotGroup::createInstance(), SGSubsystemMgr::FDM );
1353 globals->add_subsystem( "route-manager", new FGRouteMgr );
1355 ////////////////////////////////////////////////////////////////////
1356 // Initialize the Input-Output subsystem
1357 ////////////////////////////////////////////////////////////////////
1358 globals->add_subsystem( "io", new FGIO );
1360 ////////////////////////////////////////////////////////////////////
1361 // Create and register the logger.
1362 ////////////////////////////////////////////////////////////////////
1364 globals->add_subsystem("logger", new FGLogger);
1366 ////////////////////////////////////////////////////////////////////
1367 // Create and register the XML GUI.
1368 ////////////////////////////////////////////////////////////////////
1370 globals->add_subsystem("gui", new NewGUI, SGSubsystemMgr::INIT);
1372 ////////////////////////////////////////////////////////////////////
1373 // Initialize the lighting subsystem.
1374 ////////////////////////////////////////////////////////////////////
1376 globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
1378 //////////////////////////////////////////////////////////////////////
1379 // Initialize the 2D cloud subsystem.
1380 ////////////////////////////////////////////////////////////////////
1381 fgGetBool("/sim/rendering/bump-mapping", false);
1383 #ifdef ENABLE_AUDIO_SUPPORT
1384 ////////////////////////////////////////////////////////////////////
1385 // Initialize the sound-effects subsystem.
1386 ////////////////////////////////////////////////////////////////////
1387 globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);
1390 ////////////////////////////////////////////////////////////////////
1391 // Initialise the ATC Manager
1392 ////////////////////////////////////////////////////////////////////
1395 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1396 globals->set_ATC_mgr(new FGATCMgr);
1397 globals->get_ATC_mgr()->init();
1399 ////////////////////////////////////////////////////////////////////
1400 // Initialise the ATIS Manager
1401 ////////////////////////////////////////////////////////////////////
1402 globals->add_subsystem("atis", new FGAtisManager, SGSubsystemMgr::POST_FDM);
1406 ////////////////////////////////////////////////////////////////////
1407 // Initialize multiplayer subsystem
1408 ////////////////////////////////////////////////////////////////////
1410 globals->add_subsystem("mp", new FGMultiplayMgr, SGSubsystemMgr::POST_FDM);
1412 ////////////////////////////////////////////////////////////////////
1413 // Initialise the AI Model Manager
1414 ////////////////////////////////////////////////////////////////////
1415 SG_LOG(SG_GENERAL, SG_INFO, " AI Model Manager");
1416 globals->add_subsystem("ai_model", new FGAIManager, SGSubsystemMgr::POST_FDM);
1417 globals->add_subsystem("submodel_mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);
1420 // It's probably a good idea to initialize the top level traffic manager
1421 // After the AI and ATC systems have been initialized properly.
1422 // AI Traffic manager
1423 globals->add_subsystem("Traffic Manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
1426 if( fgCockpitInit()) {
1427 // Cockpit initialized ok.
1429 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1434 ////////////////////////////////////////////////////////////////////
1435 // Add a new 2D panel.
1436 ////////////////////////////////////////////////////////////////////
1438 string panel_path = fgGetString("/sim/panel/path",
1439 "Panels/Default/default.xml");
1441 globals->set_current_panel( fgReadPanel(panel_path) );
1442 if (globals->get_current_panel() == 0) {
1443 SG_LOG( SG_INPUT, SG_ALERT,
1444 "Error reading new panel from " << panel_path );
1446 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1447 globals->get_current_panel()->init();
1448 globals->get_current_panel()->bind();
1452 ////////////////////////////////////////////////////////////////////
1453 // Initialize the controls subsystem.
1454 ////////////////////////////////////////////////////////////////////
1456 globals->get_controls()->init();
1457 globals->get_controls()->bind();
1460 ////////////////////////////////////////////////////////////////////
1461 // Initialize the input subsystem.
1462 ////////////////////////////////////////////////////////////////////
1464 globals->add_subsystem("input", new FGInput);
1467 ////////////////////////////////////////////////////////////////////
1468 // Initialize the replay subsystem
1469 ////////////////////////////////////////////////////////////////////
1470 globals->add_subsystem("replay", new FGReplay);
1473 ////////////////////////////////////////////////////////////////////
1474 // Bind and initialize subsystems.
1475 ////////////////////////////////////////////////////////////////////
1477 globals->get_subsystem_mgr()->bind();
1478 globals->get_subsystem_mgr()->init();
1480 ////////////////////////////////////////////////////////////////////////
1481 // Initialize the Nasal interpreter.
1482 // Do this last, so that the loaded scripts see initialized state
1483 ////////////////////////////////////////////////////////////////////////
1484 FGNasalSys* nasal = new FGNasalSys();
1485 globals->add_subsystem("nasal", nasal, SGSubsystemMgr::INIT);
1488 // initialize methods that depend on other subsystems.
1489 globals->get_subsystem_mgr()->postinit();
1491 ////////////////////////////////////////////////////////////////////////
1492 // End of subsystem initialization.
1493 ////////////////////////////////////////////////////////////////////
1495 SG_LOG( SG_GENERAL, SG_INFO, endl);
1497 // Save the initial state for future
1499 globals->saveInitialState();
1505 void fgReInitSubsystems()
1507 // static const SGPropertyNode *longitude
1508 // = fgGetNode("/sim/presets/longitude-deg");
1509 // static const SGPropertyNode *latitude
1510 // = fgGetNode("/sim/presets/latitude-deg");
1511 static const SGPropertyNode *altitude
1512 = fgGetNode("/sim/presets/altitude-ft");
1513 static const SGPropertyNode *master_freeze
1514 = fgGetNode("/sim/freeze/master");
1516 SG_LOG( SG_GENERAL, SG_INFO,
1517 "fgReInitSubsystems(): /position/altitude = "
1518 << altitude->getDoubleValue() );
1520 bool freeze = master_freeze->getBoolValue();
1522 fgSetBool("/sim/freeze/master", true);
1524 fgSetBool("/sim/crashed", false);
1526 // Force reupdating the positions of the ai 3d models. They are used for
1527 // initializing ground level for the FDM.
1528 globals->get_subsystem("ai_model")->reinit();
1530 // Initialize the FDM
1531 globals->get_subsystem("flight")->reinit();
1533 // reload offsets from config defaults
1534 globals->get_viewmgr()->reinit();
1536 globals->get_controls()->reset_all();
1538 globals->get_subsystem("time")->reinit();
1539 globals->get_subsystem("tile-manager")->reinit();
1542 fgSetBool("/sim/freeze/master", false);
1544 fgSetBool("/sim/sceneryloaded",false);
1548 void doSimulatorReset(void) // from gui_local.cxx -- TODO merge with fgReInitSubsystems()
1550 static SGPropertyNode_ptr master_freeze = fgGetNode("/sim/freeze/master", true);
1552 bool freeze = master_freeze->getBoolValue();
1554 master_freeze->setBoolValue(true);
1556 fgSetBool("/sim/signals/reinit", true);
1558 globals->get_subsystem("flight")->unbind();
1560 globals->restoreInitialState();
1562 // update our position based on current presets
1565 fgReInitSubsystems();
1567 fgSetBool("/sim/signals/reinit", false);
1570 master_freeze->setBoolValue(false);
1573 ///////////////////////////////////////////////////////////////////////////////
1574 // helper object to implement the --show-aircraft command.
1575 // resides here so we can share the fgFindAircraftInDir template above,
1576 // and hence ensure this command lists exectly the same aircraft as the normal
1583 _minStatus = getNumMaturity(fgGetString("/sim/aircraft-min-status", "all"));
1587 void show(const SGPath& path)
1589 fgFindAircraftInDir(path, this, &ShowAircraft::processAircraft);
1591 std::sort(_aircraft.begin(), _aircraft.end(), ciLessLibC());
1592 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1593 cout << "Available aircraft:" << endl;
1594 for ( unsigned int i = 0; i < _aircraft.size(); i++ ) {
1595 cout << _aircraft[i] << endl;
1600 bool processAircraft(const SGPath& path)
1602 SGPropertyNode root;
1604 readProperties(path.str(), &root);
1605 } catch (sg_exception& ) {
1610 string descStr(" ");
1611 descStr += path.file();
1612 // trim common suffix from file names
1613 int nPos = descStr.rfind("-set.xml");
1614 if (nPos == (int)(descStr.size() - 8)) {
1615 descStr.resize(nPos);
1618 SGPropertyNode *node = root.getNode("sim");
1620 SGPropertyNode* desc = node->getNode("description");
1621 // if a status tag is found, read it in
1622 if (node->hasValue("status")) {
1623 maturity = getNumMaturity(node->getStringValue("status"));
1627 if (descStr.size() <= 27+3) {
1628 descStr.append(29+3-descStr.size(), ' ');
1631 descStr.append( 32, ' ');
1633 descStr += desc->getStringValue();
1635 } // of have 'sim' node
1637 if (maturity < _minStatus) {
1641 _aircraft.push_back(descStr);
1646 int getNumMaturity(const char * str)
1648 // changes should also be reflected in $FG_ROOT/data/options.xml &
1649 // $FG_ROOT/data/Translations/string-default.xml
1650 const char* levels[] = {"alpha","beta","early-production","production"};
1652 if (!strcmp(str, "all")) {
1656 for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
1657 if (strcmp(str,levels[i])==0)
1663 // recommended in Meyers, Effective STL when internationalization and embedded
1664 // NULLs aren't an issue. Much faster than the STL or Boost lex versions.
1665 struct ciLessLibC : public std::binary_function<string, string, bool>
1667 bool operator()(const std::string &lhs, const std::string &rhs) const
1669 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
1674 string_list _aircraft;
1677 void fgShowAircraft(const SGPath &path)
1683 cout << "Hit a key to continue..." << endl;