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 <Include/general.hxx>
92 #include <Input/input.hxx>
93 #include <Instrumentation/instrument_mgr.hxx>
94 #include <Model/acmodel.hxx>
95 #include <AIModel/submodel.hxx>
96 #include <AIModel/AIManager.hxx>
97 #include <Navaids/navdb.hxx>
98 #include <Navaids/navlist.hxx>
99 #include <Navaids/fix.hxx>
100 #include <Navaids/fixlist.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>
112 #include <Environment/ridge_lift.hxx>
114 #include "fg_init.hxx"
116 #include "fg_commands.hxx"
117 #include "fg_props.hxx"
118 #include "options.hxx"
119 #include "globals.hxx"
120 #include "logger.hxx"
121 #include "renderer.hxx"
122 #include "viewmgr.hxx"
127 # include <CoreFoundation/CoreFoundation.h>
131 using namespace boost::algorithm;
133 extern const char *default_root;
136 // Scan the command line options for the specified option and return
138 static string fgScanForOption( const string& option, int argc, char **argv ) {
141 if (hostname == NULL)
144 gethostname(_hostname, 256);
145 hostname = strdup(_hostname);
146 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__ )
206 // Next check home directory for .fgfsrc.hostname file
208 if ( homedir != NULL ) {
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__ )
492 config.concat( "." );
493 config.concat( hostname );
494 fgParseOptions(config.str());
497 // Check for ~/.fgfsrc
498 if ( homedir != NULL ) {
499 config.set( homedir );
500 config.append( ".fgfsrc" );
501 fgParseOptions(config.str());
504 #if defined( unix ) || defined( __CYGWIN__ )
505 // Check for ~/.fgfsrc.hostname
506 config.concat( "." );
507 config.concat( hostname );
508 fgParseOptions(config.str());
511 // Parse remaining command line options
512 // These will override anything specified in a config file
513 fgParseArgs(argc, argv);
517 bool fgFindAircraftInDir(const SGPath& dirPath, T* obj, bool (T::*pred)(const SGPath& p))
519 if (!dirPath.exists()) {
520 SG_LOG(SG_GENERAL, SG_WARN, "fgFindAircraftInDir: no such path:" << dirPath.str());
525 simgear::Dir dir(dirPath);
526 simgear::PathList setFiles(dir.children(simgear::Dir::TYPE_FILE, "-set.xml"));
527 simgear::PathList::iterator p;
528 for (p = setFiles.begin(); p != setFiles.end(); ++p) {
529 // check file name ends with -set.xml
531 // if we found a -set.xml at this level, don't recurse any deeper
534 bool done = (obj->*pred)(*p);
538 } // of -set.xml iteration
544 simgear::PathList subdirs(dir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT));
545 for (p = subdirs.begin(); p != subdirs.end(); ++p) {
546 if (p->file() == "CVS") {
550 if (fgFindAircraftInDir(*p, obj, pred)) {
553 } // of subdirs iteration
559 void fgFindAircraft(T* obj, bool (T::*pred)(const SGPath& p))
561 const string_list& paths(globals->get_aircraft_paths());
562 string_list::const_iterator it = paths.begin();
563 for (; it != paths.end(); ++it) {
564 bool done = fgFindAircraftInDir(SGPath(*it), obj, pred);
568 } // of aircraft paths iteration
570 // if we reach this point, search the default location (always last)
571 SGPath rootAircraft(globals->get_fg_root());
572 rootAircraft.append("Aircraft");
573 fgFindAircraftInDir(rootAircraft, obj, pred);
576 class FindAndCacheAircraft
579 FindAndCacheAircraft(SGPropertyNode* autoSave)
581 _cache = autoSave->getNode("sim/startup/path-cache", true);
586 std::string aircraft = fgGetString( "/sim/aircraft", "");
587 if (aircraft.empty()) {
588 SG_LOG(SG_GENERAL, SG_ALERT, "no aircraft specified");
592 _searchAircraft = aircraft + "-set.xml";
594 // prepare cache for re-scan
595 SGPropertyNode *n = _cache->getNode("fg-root", true);
596 n->setStringValue(globals->get_fg_root().c_str());
597 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
598 _cache->removeChildren("aircraft");
600 fgFindAircraft(this, &FindAndCacheAircraft::checkAircraft);
603 if (_foundPath.str().empty()) {
604 SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find specified aircraft: " << aircraft );
608 SG_LOG(SG_GENERAL, SG_INFO, "Loading aircraft -set file from:" << _foundPath.str());
609 fgSetString( "/sim/aircraft-dir", _foundPath.dir().c_str());
610 if (!_foundPath.exists()) {
611 SG_LOG(SG_GENERAL, SG_ALERT, "Unable to find -set file:" << _foundPath.str());
616 readProperties(_foundPath.str(), globals->get_props());
617 } catch ( const sg_exception &e ) {
618 SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage());
628 if (globals->get_fg_root() != _cache->getStringValue("fg-root", "")) {
629 return false; // cache mismatch
632 vector<SGPropertyNode_ptr> cache = _cache->getChildren("aircraft");
633 for (unsigned int i = 0; i < cache.size(); i++) {
634 const char *name = cache[i]->getStringValue("file", "");
635 if (!boost::equals(_searchAircraft, name, is_iequal())) {
639 SGPath xml(cache[i]->getStringValue("path", ""));
647 } // of aircraft in cache iteration
652 bool checkAircraft(const SGPath& p)
657 if (!_cache->getChild("aircraft", i++, false))
661 SGPropertyNode *n, *entry = _cache->getChild("aircraft", --i, true);
663 std::string fileName(p.file());
664 n = entry->getNode("file", true);
665 n->setStringValue(fileName);
666 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
668 n = entry->getNode("path", true);
669 n->setStringValue(p.dir());
670 n->setAttribute(SGPropertyNode::USERARCHIVE, true);
672 if ( boost::equals(fileName, _searchAircraft.c_str(), is_iequal()) ) {
680 std::string _searchAircraft;
682 SGPropertyNode* _cache;
685 // Read in configuration (file and command line)
686 bool fgInitConfig ( int argc, char **argv ) {
688 // First, set some sane default values
691 // Read global preferences from $FG_ROOT/preferences.xml
692 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
693 fgLoadProps("preferences.xml", globals->get_props());
694 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
696 // Detect the required language as early as possible
697 if ( !fgDetectLanguage() ) {
701 SGPropertyNode autosave;
703 char *envp = ::getenv( "APPDATA" );
705 SGPath config( envp );
706 config.append( "flightgear.org" );
708 if ( homedir != NULL ) {
709 SGPath config( homedir );
710 config.append( ".fgfs" );
712 const char *fg_home = getenv("FG_HOME");
716 SGPath home_export(config.str());
717 home_export.append("Export/dummy");
718 home_export.create_dir(0777);
720 // Set /sim/fg-home and don't allow malign code to override it until
721 // Nasal security is set up. Use FG_HOME if necessary.
722 SGPropertyNode *home = fgGetNode("/sim", true);
723 home->removeChild("fg-home", 0, false);
724 home = home->getChild("fg-home", 0, true);
725 home->setStringValue(config.c_str());
726 home->setAttribute(SGPropertyNode::WRITE, false);
728 config.append( "autosave.xml" );
729 if (config.exists()) {
730 SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
732 readProperties(config.str(), &autosave, SGPropertyNode::USERARCHIVE);
733 } catch (sg_exception& e) {
734 SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
735 << "(from " << e.getOrigin() << ")");
740 // Scan user config files and command line for a specified aircraft.
741 fgInitFGAircraft(argc, argv);
742 FindAndCacheAircraft f(&autosave);
743 if (!f.loadAircraft()) {
747 copyProperties(&autosave, globals->get_props());
749 // parse options after loading aircraft to ensure any user
750 // overrides of defaults are honored.
751 do_options(argc, argv);
756 // Set current tower position lon/lat given an airport id
757 static bool fgSetTowerPosFromAirportID( const string& id) {
758 const FGAirport *a = fgFindAirportID( id);
760 SGGeod tower = a->getTowerLocation();
761 fgSetDouble("/sim/tower/longitude-deg", tower.getLongitudeDeg());
762 fgSetDouble("/sim/tower/latitude-deg", tower.getLatitudeDeg());
763 fgSetDouble("/sim/tower/altitude-ft", tower.getElevationFt());
771 struct FGTowerLocationListener : SGPropertyChangeListener {
772 void valueChanged(SGPropertyNode* node) {
773 const string id(node->getStringValue());
774 fgSetTowerPosFromAirportID(id);
778 void fgInitTowerLocationListener() {
779 fgGetNode("/sim/tower/airport-id", true)
780 ->addChangeListener( new FGTowerLocationListener(), true );
783 static void fgApplyStartOffset(const SGGeod& aStartPos, double aHeading, double aTargetHeading = HUGE_VAL)
785 SGGeod startPos(aStartPos);
786 if (aTargetHeading == HUGE_VAL) {
787 aTargetHeading = aHeading;
790 if ( fabs( fgGetDouble("/sim/presets/offset-distance-nm") ) > SG_EPSILON ) {
791 double offsetDistance = fgGetDouble("/sim/presets/offset-distance-nm");
792 offsetDistance *= SG_NM_TO_METER;
793 double offsetAzimuth = aHeading;
794 if ( fabs(fgGetDouble("/sim/presets/offset-azimuth-deg")) > SG_EPSILON ) {
795 offsetAzimuth = fgGetDouble("/sim/presets/offset-azimuth-deg");
796 aHeading = aTargetHeading;
801 SGGeodesy::direct(startPos, offsetAzimuth + 180, offsetDistance, offset, az2);
806 fgSetDouble("/sim/presets/longitude-deg", startPos.getLongitudeDeg() );
807 fgSetDouble("/sim/presets/latitude-deg", startPos.getLatitudeDeg() );
808 fgSetDouble("/sim/presets/heading-deg", aHeading );
810 // other code depends on the actual values being set ...
811 fgSetDouble("/position/longitude-deg", startPos.getLongitudeDeg() );
812 fgSetDouble("/position/latitude-deg", startPos.getLatitudeDeg() );
813 fgSetDouble("/orientation/heading-deg", aHeading );
816 // Set current_options lon/lat given an airport id and heading (degrees)
817 static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
821 // set initial position from runway and heading
822 SG_LOG( SG_GENERAL, SG_INFO,
823 "Attempting to set starting position from airport code "
824 << id << " heading " << tgt_hdg );
826 const FGAirport* apt = fgFindAirportID(id);
827 if (!apt) return false;
828 FGRunway* r = apt->findBestRunwayForHeading(tgt_hdg);
829 fgSetString("/sim/atc/runway", r->ident().c_str());
831 SGGeod startPos = r->pointOnCenterline(fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
832 fgApplyStartOffset(startPos, r->headingDeg(), tgt_hdg);
836 // Set current_options lon/lat given an airport id and parkig position name
837 static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) {
841 // can't see an easy way around this const_cast at the moment
842 FGAirport* apt = const_cast<FGAirport*>(fgFindAirportID(id));
844 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport " << id );
847 FGAirportDynamics* dcs = apt->getDynamics();
849 SG_LOG( SG_GENERAL, SG_ALERT,
850 "Failed to find parking position " << parkpos <<
851 " at airport " << id );
855 int park_index = dcs->getNrOfParkings() - 1;
856 while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) park_index--;
857 if (park_index < 0) {
858 SG_LOG( SG_GENERAL, SG_ALERT,
859 "Failed to find parking position " << parkpos <<
860 " at airport " << id );
863 FGParking* parking = dcs->getParking(park_index);
864 parking->setAvailable(false);
866 SGGeod::fromDeg(parking->getLongitude(), parking->getLatitude()),
867 parking->getHeading());
872 // Set current_options lon/lat given an airport id and runway number
873 static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, bool rwy_req ) {
877 // set initial position from airport and runway number
878 SG_LOG( SG_GENERAL, SG_INFO,
879 "Attempting to set starting position for "
880 << id << ":" << rwy );
882 const FGAirport* apt = fgFindAirportID(id);
884 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport:" << id);
888 if (!apt->hasRunwayWithIdent(rwy)) {
889 SG_LOG( SG_GENERAL, rwy_req ? SG_ALERT : SG_INFO,
890 "Failed to find runway " << rwy <<
891 " at airport " << id << ". Using default runway." );
895 FGRunway* r(apt->getRunwayByIdent(rwy));
896 fgSetString("/sim/atc/runway", r->ident().c_str());
897 SGGeod startPos = r->pointOnCenterline( fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
898 fgApplyStartOffset(startPos, r->headingDeg());
903 static void fgSetDistOrAltFromGlideSlope() {
904 // cout << "fgSetDistOrAltFromGlideSlope()" << endl;
905 string apt_id = fgGetString("/sim/presets/airport-id");
906 double gs = fgGetDouble("/sim/presets/glideslope-deg")
907 * SG_DEGREES_TO_RADIANS ;
908 double od = fgGetDouble("/sim/presets/offset-distance-nm");
909 double alt = fgGetDouble("/sim/presets/altitude-ft");
911 double apt_elev = 0.0;
912 if ( ! apt_id.empty() ) {
913 apt_elev = fgGetAirportElev( apt_id );
914 if ( apt_elev < -9990.0 ) {
921 if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
922 // set altitude from glideslope and offset-distance
923 od *= SG_NM_TO_METER * SG_METER_TO_FEET;
924 alt = fabs(od*tan(gs)) + apt_elev;
925 fgSetDouble("/sim/presets/altitude-ft", alt);
926 fgSetBool("/sim/presets/onground", false);
927 SG_LOG( SG_GENERAL, SG_INFO, "Calculated altitude as: "
929 } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
930 // set offset-distance from glideslope and altitude
931 od = (alt - apt_elev) / tan(gs);
932 od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
933 fgSetDouble("/sim/presets/offset-distance-nm", od);
934 fgSetBool("/sim/presets/onground", false);
935 SG_LOG( SG_GENERAL, SG_INFO, "Calculated offset distance as: "
937 } else if( fabs(gs) > 0.01 ) {
938 SG_LOG( SG_GENERAL, SG_ALERT,
939 "Glideslope given but not altitude or offset-distance." );
940 SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
941 fgSetDouble("/sim/presets/glideslope-deg", 0);
942 fgSetBool("/sim/presets/onground", true);
947 // Set current_options lon/lat given an airport id and heading (degrees)
948 static bool fgSetPosFromNAV( const string& id, const double& freq ) {
950 = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq );
953 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = "
954 << id << ":" << freq );
958 fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg"));
962 // Set current_options lon/lat given an aircraft carrier id
963 static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) {
965 // set initial position from runway and heading
969 if (FGAIManager::getStartPosition(carrier, posid, geodPos, heading, uvw)) {
970 double lon = geodPos.getLongitudeDeg();
971 double lat = geodPos.getLatitudeDeg();
972 double alt = geodPos.getElevationFt();
974 SG_LOG( SG_GENERAL, SG_INFO, "Attempting to set starting position for "
975 << carrier << " at lat = " << lat << ", lon = " << lon
976 << ", alt = " << alt << ", heading = " << heading);
978 fgSetDouble("/sim/presets/longitude-deg", lon);
979 fgSetDouble("/sim/presets/latitude-deg", lat);
980 fgSetDouble("/sim/presets/altitude-ft", alt);
981 fgSetDouble("/sim/presets/heading-deg", heading);
982 fgSetDouble("/position/longitude-deg", lon);
983 fgSetDouble("/position/latitude-deg", lat);
984 fgSetDouble("/position/altitude-ft", alt);
985 fgSetDouble("/orientation/heading-deg", heading);
987 fgSetString("/sim/presets/speed-set", "UVW");
988 fgSetDouble("/velocities/uBody-fps", uvw(0));
989 fgSetDouble("/velocities/vBody-fps", uvw(1));
990 fgSetDouble("/velocities/wBody-fps", uvw(2));
991 fgSetDouble("/sim/presets/uBody-fps", uvw(0));
992 fgSetDouble("/sim/presets/vBody-fps", uvw(1));
993 fgSetDouble("/sim/presets/wBody-fps", uvw(2));
995 fgSetBool("/sim/presets/onground", true);
999 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate aircraft carrier = "
1005 // Set current_options lon/lat given an airport id and heading (degrees)
1006 static bool fgSetPosFromFix( const string& id )
1008 FGPositioned::TypeFilter fixFilter(FGPositioned::FIX);
1009 FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter);
1011 SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id );
1015 fgApplyStartOffset(fix->geod(), fgGetDouble("/sim/presets/heading-deg"));
1020 * Initialize vor/ndb/ils/fix list management and query systems (as
1021 * well as simple airport db list)
1026 SG_LOG(SG_GENERAL, SG_INFO, "Loading Airport Database ...");
1028 SGPath aptdb( globals->get_fg_root() );
1029 aptdb.append( "Airports/apt.dat" );
1031 SGPath p_metar( globals->get_fg_root() );
1032 p_metar.append( "Airports/metar.dat" );
1034 // Initialise the frequency search map BEFORE reading
1035 // the airport database:
1039 current_commlist = new FGCommList;
1040 current_commlist->init( globals->get_fg_root() );
1041 fgAirportDBLoad( aptdb.str(), current_commlist, p_metar.str() );
1043 FGNavList *navlist = new FGNavList;
1044 FGNavList *loclist = new FGNavList;
1045 FGNavList *gslist = new FGNavList;
1046 FGNavList *dmelist = new FGNavList;
1047 FGNavList *tacanlist = new FGNavList;
1048 FGNavList *carrierlist = new FGNavList;
1049 FGTACANList *channellist = new FGTACANList;
1051 globals->set_navlist( navlist );
1052 globals->set_loclist( loclist );
1053 globals->set_gslist( gslist );
1054 globals->set_dmelist( dmelist );
1055 globals->set_tacanlist( tacanlist );
1056 globals->set_carrierlist( carrierlist );
1057 globals->set_channellist( channellist );
1059 if ( !fgNavDBInit(navlist, loclist, gslist, dmelist, tacanlist, carrierlist, channellist) ) {
1060 SG_LOG( SG_GENERAL, SG_ALERT,
1061 "Problems loading one or more navigational database" );
1064 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
1065 SGPath p_fix( globals->get_fg_root() );
1066 p_fix.append( "Navaids/fix.dat" );
1068 fixlist.init( p_fix ); // adds fixes to the DB in positioned.cxx
1070 SG_LOG(SG_GENERAL, SG_INFO, " Airways");
1071 SGPath p_awy( globals->get_fg_root() );
1072 p_awy.append( "Navaids/awy.dat" );
1073 FGAirwayNetwork *awyNet = new FGAirwayNetwork;
1074 //cerr << "Loading Airways" << endl;
1075 awyNet->load (p_awy );
1077 //cerr << "initializing airways" << endl;
1078 globals->set_airwaynet( awyNet );
1084 // Set the initial position based on presets (or defaults)
1085 bool fgInitPosition() {
1086 // cout << "fgInitPosition()" << endl;
1087 double gs = fgGetDouble("/sim/presets/glideslope-deg")
1088 * SG_DEGREES_TO_RADIANS ;
1089 double od = fgGetDouble("/sim/presets/offset-distance-nm");
1090 double alt = fgGetDouble("/sim/presets/altitude-ft");
1092 bool set_pos = false;
1094 // If glideslope is specified, then calculate offset-distance or
1095 // altitude relative to glide slope if either of those was not
1097 if ( fabs( gs ) > 0.01 ) {
1098 fgSetDistOrAltFromGlideSlope();
1102 // If we have an explicit, in-range lon/lat, don't change it, just use it.
1103 // If not, check for an airport-id and use that.
1104 // If not, default to the middle of the KSFO field.
1105 // The default values for lon/lat are deliberately out of range
1106 // so that the airport-id can take effect; valid lon/lat will
1107 // override airport-id, however.
1108 double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
1109 double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
1110 if ( lon_deg >= -180.0 && lon_deg <= 180.0
1111 && lat_deg >= -90.0 && lat_deg <= 90.0 )
1116 string apt = fgGetString("/sim/presets/airport-id");
1117 string rwy_no = fgGetString("/sim/presets/runway");
1118 bool rwy_req = fgGetBool("/sim/presets/runway-requested");
1119 string vor = fgGetString("/sim/presets/vor-id");
1120 double vor_freq = fgGetDouble("/sim/presets/vor-freq");
1121 string ndb = fgGetString("/sim/presets/ndb-id");
1122 double ndb_freq = fgGetDouble("/sim/presets/ndb-freq");
1123 string carrier = fgGetString("/sim/presets/carrier");
1124 string parkpos = fgGetString("/sim/presets/parkpos");
1125 string fix = fgGetString("/sim/presets/fix");
1126 SGPropertyNode *hdg_preset = fgGetNode("/sim/presets/heading-deg", true);
1127 double hdg = hdg_preset->getDoubleValue();
1129 // save some start parameters, so that we can later say what the
1130 // user really requested. TODO generalize that and move it to options.cxx
1131 static bool start_options_saved = false;
1132 if (!start_options_saved) {
1133 start_options_saved = true;
1134 SGPropertyNode *opt = fgGetNode("/sim/startup/options", true);
1136 opt->setDoubleValue("latitude-deg", lat_deg);
1137 opt->setDoubleValue("longitude-deg", lon_deg);
1138 opt->setDoubleValue("heading-deg", hdg);
1139 opt->setStringValue("airport", apt.c_str());
1140 opt->setStringValue("runway", rwy_no.c_str());
1144 hdg = fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270);
1146 if ( !set_pos && !apt.empty() && !parkpos.empty() ) {
1147 // An airport + parking position is requested
1148 if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
1149 // set tower position
1150 fgSetString("/sim/tower/airport-id", apt.c_str());
1155 if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
1156 // An airport + runway is requested
1157 if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {
1158 // set tower position (a little off the heading for single
1160 fgSetString("/sim/tower/airport-id", apt.c_str());
1165 if ( !set_pos && !apt.empty() ) {
1166 // An airport is requested (find runway closest to hdg)
1167 if ( fgSetPosFromAirportIDandHdg( apt, hdg ) ) {
1168 // set tower position (a little off the heading for single
1170 fgSetString("/sim/tower/airport-id", apt.c_str());
1175 if (hdg_preset->getDoubleValue() > 9990.0)
1176 hdg_preset->setDoubleValue(hdg);
1178 if ( !set_pos && !vor.empty() ) {
1179 // a VOR is requested
1180 if ( fgSetPosFromNAV( vor, vor_freq ) ) {
1185 if ( !set_pos && !ndb.empty() ) {
1186 // an NDB is requested
1187 if ( fgSetPosFromNAV( ndb, ndb_freq ) ) {
1192 if ( !set_pos && !carrier.empty() ) {
1193 // an aircraft carrier is requested
1194 if ( fgSetPosFromCarrier( carrier, parkpos ) ) {
1199 if ( !set_pos && !fix.empty() ) {
1200 // a Fix is requested
1201 if ( fgSetPosFromFix( fix ) ) {
1207 // No lon/lat specified, no airport specified, default to
1208 // middle of KSFO field.
1209 fgSetDouble("/sim/presets/longitude-deg", -122.374843);
1210 fgSetDouble("/sim/presets/latitude-deg", 37.619002);
1213 fgSetDouble( "/position/longitude-deg",
1214 fgGetDouble("/sim/presets/longitude-deg") );
1215 fgSetDouble( "/position/latitude-deg",
1216 fgGetDouble("/sim/presets/latitude-deg") );
1217 fgSetDouble( "/orientation/heading-deg", hdg_preset->getDoubleValue());
1219 // determine if this should be an on-ground or in-air start
1220 if ((fabs(gs) > 0.01 || fabs(od) > 0.1 || alt > 0.1) && carrier.empty()) {
1221 fgSetBool("/sim/presets/onground", false);
1223 fgSetBool("/sim/presets/onground", true);
1230 // General house keeping initializations
1231 bool fgInitGeneral() {
1234 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
1235 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
1237 root = globals->get_fg_root();
1238 if ( ! root.length() ) {
1239 // No root path set? Then bail ...
1240 SG_LOG( SG_GENERAL, SG_ALERT,
1241 "Cannot continue without a path to the base package "
1242 << "being defined." );
1245 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
1247 globals->set_browser(fgGetString("/sim/startup/browser-app", "firefox %u"));
1249 char buf[512], *cwd = getcwd(buf, 511);
1251 SGPropertyNode *curr = fgGetNode("/sim", true);
1252 curr->removeChild("fg-current", 0, false);
1253 curr = curr->getChild("fg-current", 0, true);
1254 curr->setStringValue(cwd ? cwd : "");
1255 curr->setAttribute(SGPropertyNode::WRITE, false);
1257 fgSetBool("/sim/startup/stdout-to-terminal", isatty(1));
1258 fgSetBool("/sim/startup/stderr-to-terminal", isatty(2));
1262 // Initialize view parameters
1264 // force update of model so that viewer can get some data...
1265 globals->get_aircraft_model()->update(0);
1266 // run update for current view so that data is current...
1267 globals->get_viewmgr()->update(0);
1270 // This is the top level init routine which calls all the other
1271 // initialization routines. If you are adding a subsystem to flight
1272 // gear, its initialization call should located in this routine.
1273 // Returns non-zero if a problem encountered.
1274 bool fgInitSubsystems() {
1275 // static const SGPropertyNode *longitude
1276 // = fgGetNode("/sim/presets/longitude-deg");
1277 // static const SGPropertyNode *latitude
1278 // = fgGetNode("/sim/presets/latitude-deg");
1279 // static const SGPropertyNode *altitude
1280 // = fgGetNode("/sim/presets/altitude-ft");
1282 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
1283 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
1285 ////////////////////////////////////////////////////////////////////
1286 // Initialize the event manager subsystem.
1287 ////////////////////////////////////////////////////////////////////
1289 globals->get_event_mgr()->init();
1290 globals->get_event_mgr()->setRealtimeProperty(fgGetNode("/sim/time/delta-realtime-sec", true));
1292 ////////////////////////////////////////////////////////////////////
1293 // Initialize the property interpolator subsystem. Put into the INIT
1294 // group because the "nasal" subsystem may need it at GENERAL take-down.
1295 ////////////////////////////////////////////////////////////////////
1296 globals->add_subsystem("interpolator", new SGInterpolator, SGSubsystemMgr::INIT);
1299 ////////////////////////////////////////////////////////////////////
1300 // Add the FlightGear property utilities.
1301 ////////////////////////////////////////////////////////////////////
1302 globals->add_subsystem("properties", new FGProperties);
1304 ////////////////////////////////////////////////////////////////////
1305 // Initialize the material property subsystem.
1306 ////////////////////////////////////////////////////////////////////
1308 SGPath mpath( globals->get_fg_root() );
1309 mpath.append( "materials.xml" );
1310 if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
1311 globals->get_props()) ) {
1312 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
1317 ////////////////////////////////////////////////////////////////////
1318 // Initialize the scenery management subsystem.
1319 ////////////////////////////////////////////////////////////////////
1321 if ( globals->get_tile_mgr()->init() ) {
1322 // Load the local scenery data
1323 double visibility_meters = fgGetDouble("/environment/visibility-m");
1324 globals->get_tile_mgr()->update( visibility_meters );
1326 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
1330 globals->get_scenery()->get_scene_graph()
1331 ->addChild(simgear::Particles::getCommonRoot());
1332 simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
1334 ////////////////////////////////////////////////////////////////////
1335 // Initialize the flight model subsystem.
1336 ////////////////////////////////////////////////////////////////////
1338 globals->add_subsystem("flight", new FDMShell, SGSubsystemMgr::FDM);
1340 ////////////////////////////////////////////////////////////////////
1341 // Initialize the weather subsystem.
1342 ////////////////////////////////////////////////////////////////////
1344 // Initialize the weather modeling subsystem
1345 globals->add_subsystem("environment", new FGEnvironmentMgr);
1347 ////////////////////////////////////////////////////////////////////
1348 // Initialize the ridge lift simulation.
1349 ////////////////////////////////////////////////////////////////////
1351 // Initialize the ridgelift subsystem
1352 globals->add_subsystem("ridgelift", new FGRidgeLift);
1354 ////////////////////////////////////////////////////////////////////
1355 // Initialize the aircraft systems and instrumentation (before the
1357 ////////////////////////////////////////////////////////////////////
1359 globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM);
1360 globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM);
1362 ////////////////////////////////////////////////////////////////////
1363 // Initialize the XML Autopilot subsystem.
1364 ////////////////////////////////////////////////////////////////////
1366 globals->add_subsystem( "xml-autopilot", new FGXMLAutopilotGroup, SGSubsystemMgr::FDM );
1367 globals->add_subsystem( "route-manager", new FGRouteMgr );
1369 ////////////////////////////////////////////////////////////////////
1370 // Initialize the view manager subsystem.
1371 ////////////////////////////////////////////////////////////////////
1375 ////////////////////////////////////////////////////////////////////
1376 // Initialize the Input-Output subsystem
1377 ////////////////////////////////////////////////////////////////////
1378 globals->add_subsystem( "io", new FGIO );
1380 ////////////////////////////////////////////////////////////////////
1381 // Create and register the logger.
1382 ////////////////////////////////////////////////////////////////////
1384 globals->add_subsystem("logger", new FGLogger);
1386 ////////////////////////////////////////////////////////////////////
1387 // Create and register the XML GUI.
1388 ////////////////////////////////////////////////////////////////////
1390 globals->add_subsystem("gui", new NewGUI, SGSubsystemMgr::INIT);
1392 ////////////////////////////////////////////////////////////////////
1393 // Initialize the lighting subsystem.
1394 ////////////////////////////////////////////////////////////////////
1396 globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
1398 //////////////////////////////////////////////////////////////////////
1399 // Initialize the 2D cloud subsystem.
1400 ////////////////////////////////////////////////////////////////////
1401 fgGetBool("/sim/rendering/bump-mapping", false);
1403 #ifdef ENABLE_AUDIO_SUPPORT
1404 ////////////////////////////////////////////////////////////////////
1405 // Initialize the sound-effects subsystem.
1406 ////////////////////////////////////////////////////////////////////
1407 globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);
1410 ////////////////////////////////////////////////////////////////////
1411 // Initialise the ATC Manager
1412 ////////////////////////////////////////////////////////////////////
1415 SG_LOG(SG_GENERAL, SG_INFO, " ATC Manager");
1416 globals->set_ATC_mgr(new FGATCMgr);
1417 globals->get_ATC_mgr()->init();
1419 ////////////////////////////////////////////////////////////////////
1420 // Initialise the ATIS Manager
1421 ////////////////////////////////////////////////////////////////////
1422 globals->add_subsystem("atis", new FGAtisManager, SGSubsystemMgr::POST_FDM);
1424 ////////////////////////////////////////////////////////////////////
1425 // Initialise the AI Model Manager
1426 ////////////////////////////////////////////////////////////////////
1427 SG_LOG(SG_GENERAL, SG_INFO, " AI Model Manager");
1428 globals->add_subsystem("ai_model", new FGAIManager, SGSubsystemMgr::POST_FDM);
1429 globals->add_subsystem("submodel_mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);
1432 // It's probably a good idea to initialize the top level traffic manager
1433 // After the AI and ATC systems have been initialized properly.
1434 // AI Traffic manager
1435 globals->add_subsystem("Traffic Manager", new FGTrafficManager, SGSubsystemMgr::POST_FDM);
1438 if( fgCockpitInit()) {
1439 // Cockpit initialized ok.
1441 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
1446 ////////////////////////////////////////////////////////////////////
1447 // Add a new 2D panel.
1448 ////////////////////////////////////////////////////////////////////
1450 string panel_path = fgGetString("/sim/panel/path",
1451 "Panels/Default/default.xml");
1453 globals->set_current_panel( fgReadPanel(panel_path) );
1454 if (globals->get_current_panel() == 0) {
1455 SG_LOG( SG_INPUT, SG_ALERT,
1456 "Error reading new panel from " << panel_path );
1458 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
1459 globals->get_current_panel()->init();
1460 globals->get_current_panel()->bind();
1464 ////////////////////////////////////////////////////////////////////
1465 // Initialize the controls subsystem.
1466 ////////////////////////////////////////////////////////////////////
1468 globals->get_controls()->init();
1469 globals->get_controls()->bind();
1472 ////////////////////////////////////////////////////////////////////
1473 // Initialize the input subsystem.
1474 ////////////////////////////////////////////////////////////////////
1476 globals->add_subsystem("input", new FGInput);
1479 ////////////////////////////////////////////////////////////////////
1480 // Initialize the replay subsystem
1481 ////////////////////////////////////////////////////////////////////
1482 globals->add_subsystem("replay", new FGReplay);
1485 ////////////////////////////////////////////////////////////////////
1486 // Bind and initialize subsystems.
1487 ////////////////////////////////////////////////////////////////////
1489 globals->get_subsystem_mgr()->bind();
1490 globals->get_subsystem_mgr()->init();
1492 ////////////////////////////////////////////////////////////////////
1493 // Initialize multiplayer subsystem
1494 ////////////////////////////////////////////////////////////////////
1496 globals->set_multiplayer_mgr(new FGMultiplayMgr);
1497 globals->get_multiplayer_mgr()->init();
1499 ////////////////////////////////////////////////////////////////////////
1500 // Initialize the Nasal interpreter.
1501 // Do this last, so that the loaded scripts see initialized state
1502 ////////////////////////////////////////////////////////////////////////
1503 FGNasalSys* nasal = new FGNasalSys();
1504 globals->add_subsystem("nasal", nasal, SGSubsystemMgr::INIT);
1507 // initialize methods that depend on other subsystems.
1508 globals->get_subsystem_mgr()->postinit();
1510 ////////////////////////////////////////////////////////////////////////
1511 // End of subsystem initialization.
1512 ////////////////////////////////////////////////////////////////////
1514 SG_LOG( SG_GENERAL, SG_INFO, endl);
1516 // Save the initial state for future
1518 globals->saveInitialState();
1524 void fgReInitSubsystems()
1526 // static const SGPropertyNode *longitude
1527 // = fgGetNode("/sim/presets/longitude-deg");
1528 // static const SGPropertyNode *latitude
1529 // = fgGetNode("/sim/presets/latitude-deg");
1530 static const SGPropertyNode *altitude
1531 = fgGetNode("/sim/presets/altitude-ft");
1532 static const SGPropertyNode *master_freeze
1533 = fgGetNode("/sim/freeze/master");
1535 SG_LOG( SG_GENERAL, SG_INFO,
1536 "fgReInitSubsystems(): /position/altitude = "
1537 << altitude->getDoubleValue() );
1539 bool freeze = master_freeze->getBoolValue();
1541 fgSetBool("/sim/freeze/master", true);
1543 fgSetBool("/sim/crashed", false);
1545 // Force reupdating the positions of the ai 3d models. They are used for
1546 // initializing ground level for the FDM.
1547 globals->get_subsystem("ai_model")->reinit();
1549 // Initialize the FDM
1550 globals->get_subsystem("flight")->reinit();
1552 // reload offsets from config defaults
1553 globals->get_viewmgr()->reinit();
1557 globals->get_controls()->reset_all();
1559 globals->get_subsystem("time")->reinit();
1562 fgSetBool("/sim/freeze/master", false);
1564 fgSetBool("/sim/sceneryloaded",false);
1568 void doSimulatorReset(void) // from gui_local.cxx -- TODO merge with fgReInitSubsystems()
1570 static SGPropertyNode_ptr master_freeze = fgGetNode("/sim/freeze/master", true);
1572 bool freeze = master_freeze->getBoolValue();
1574 master_freeze->setBoolValue(true);
1576 fgSetBool("/sim/signals/reinit", true);
1578 globals->get_subsystem("flight")->unbind();
1580 globals->restoreInitialState();
1582 // update our position based on current presets
1585 fgReInitSubsystems();
1587 globals->get_tile_mgr()->update(fgGetDouble("/environment/visibility-m"));
1588 fgSetBool("/sim/signals/reinit", false);
1591 master_freeze->setBoolValue(false);
1594 ///////////////////////////////////////////////////////////////////////////////
1595 // helper object to implement the --show-aircraft command.
1596 // resides here so we can share the fgFindAircraftInDir template above,
1597 // and hence ensure this command lists exectly the same aircraft as the normal
1604 _minStatus = getNumMaturity(fgGetString("/sim/aircraft-min-status", "all"));
1608 void show(const SGPath& path)
1610 fgFindAircraftInDir(path, this, &ShowAircraft::processAircraft);
1612 std::sort(_aircraft.begin(), _aircraft.end(), ciLessLibC());
1613 SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
1614 cout << "Available aircraft:" << endl;
1615 for ( unsigned int i = 0; i < _aircraft.size(); i++ ) {
1616 cout << _aircraft[i] << endl;
1621 bool processAircraft(const SGPath& path)
1623 SGPropertyNode root;
1625 readProperties(path.str(), &root);
1626 } catch (sg_exception& e) {
1631 string descStr(" ");
1632 descStr += path.file();
1633 // trim common suffix from file names
1634 int nPos = descStr.rfind("-set.xml");
1635 if (nPos == (int)(descStr.size() - 8)) {
1636 descStr.resize(nPos);
1639 SGPropertyNode *node = root.getNode("sim");
1641 SGPropertyNode* desc = node->getNode("description");
1642 // if a status tag is found, read it in
1643 if (node->hasValue("status")) {
1644 maturity = getNumMaturity(node->getStringValue("status"));
1648 if (descStr.size() <= 27+3) {
1649 descStr.append(29+3-descStr.size(), ' ');
1652 descStr.append( 32, ' ');
1654 descStr += desc->getStringValue();
1656 } // of have 'sim' node
1658 if (maturity < _minStatus) {
1662 _aircraft.push_back(descStr);
1667 int getNumMaturity(const char * str)
1669 // changes should also be reflected in $FG_ROOT/data/options.xml &
1670 // $FG_ROOT/data/Translations/string-default.xml
1671 const char* levels[] = {"alpha","beta","early-production","production"};
1673 if (!strcmp(str, "all")) {
1677 for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
1678 if (strcmp(str,levels[i])==0)
1684 // recommended in Meyers, Effective STL when internationalization and embedded
1685 // NULLs aren't an issue. Much faster than the STL or Boost lex versions.
1686 struct ciLessLibC : public std::binary_function<string, string, bool>
1688 bool operator()(const std::string &lhs, const std::string &rhs) const
1690 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
1695 string_list _aircraft;
1698 void fgShowAircraft(const SGPath &path)
1704 cout << "Hit a key to continue..." << endl;