1 // fg_init.cxx -- Flight Gear top level initialization routines
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 // For BC 5.01 this must be included before OpenGL includes.
30 #ifdef SG_MATH_EXCEPTION_CLASH
44 #if defined( unix ) || defined( __CYGWIN__ )
45 # include <unistd.h> // for gethostname()
48 // work around a stdc++ lib bug in some versions of linux, but doesn't
49 // seem to hurt to have this here for all versions of Linux.
51 # define _G_NO_EXTERN_TEMPLATES
54 #include <simgear/compiler.h>
55 #include <simgear/misc/exception.hxx>
59 #include <simgear/constants.h>
60 #include <simgear/debug/logstream.hxx>
61 #include <simgear/math/point3d.hxx>
62 #include <simgear/math/polar3d.hxx>
63 #include <simgear/math/sg_geodesy.hxx>
64 #include <simgear/misc/sg_path.hxx>
65 #include <simgear/timing/sg_time.hxx>
67 #include <Aircraft/aircraft.hxx>
68 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
69 #include <Airports/runways.hxx>
70 #include <Airports/simple.hxx>
71 #include <Autopilot/auto_gui.hxx>
72 #include <Autopilot/newauto.hxx>
73 #include <Cockpit/cockpit.hxx>
74 #include <Cockpit/radiostack.hxx>
75 #include <Cockpit/panel.hxx>
76 #include <Cockpit/panel_io.hxx>
77 #include <FDM/ADA.hxx>
78 #include <FDM/Balloon.h>
79 #include <FDM/External.hxx>
80 #include <FDM/JSBSim.hxx>
81 #include <FDM/LaRCsim.hxx>
82 #include <FDM/MagicCarpet.hxx>
83 #include <Include/general.hxx>
84 #include <Input/input.hxx>
85 // #include <Joystick/joystick.hxx>
86 #include <Objects/matlib.hxx>
87 #include <Navaids/fixlist.hxx>
88 #include <Navaids/ilslist.hxx>
89 #include <Navaids/mkrbeacons.hxx>
90 #include <Navaids/navlist.hxx>
91 #include <Scenery/scenery.hxx>
92 #include <Scenery/tilemgr.hxx>
93 #include <Sound/fg_fx.hxx>
94 #include <Sound/soundmgr.hxx>
95 #include <Time/event.hxx>
96 #include <Time/light.hxx>
97 #include <Time/sunpos.hxx>
98 #include <Time/moonpos.hxx>
99 #include <Time/tmp.hxx>
101 #ifndef FG_OLD_WEATHER
102 # include <WeatherCM/FGLocalWeatherDatabase.h>
104 # include <Weather/weather.hxx>
107 #include "fg_init.hxx"
109 #include "fg_commands.hxx"
110 #include "fg_props.hxx"
111 #include "options.hxx"
112 #include "globals.hxx"
113 #include "viewmgr.hxx"
115 #if defined(FX) && defined(XMESA)
116 #include <GL/xmesa.h>
119 SG_USING_STD(string);
121 extern const char *default_root;
124 // Read in configuration (file and command line) and just set fg_root
125 bool fgInitFGRoot ( int argc, char **argv ) {
129 // First parse command line options looking for fg-root, this will
130 // override anything specified in a config file
131 root = fgScanForRoot(argc, argv);
133 #if defined( unix ) || defined( __CYGWIN__ )
134 // Next check home directory for .fgfsrc.hostname file
136 envp = ::getenv( "HOME" );
137 if ( envp != NULL ) {
138 SGPath config( envp );
139 config.append( ".fgfsrc" );
141 gethostname( name, 256 );
142 config.concat( "." );
143 config.concat( name );
144 root = fgScanForRoot(config.str());
149 // Next check home directory for .fgfsrc file
151 envp = ::getenv( "HOME" );
152 if ( envp != NULL ) {
153 SGPath config( envp );
154 config.append( ".fgfsrc" );
155 root = fgScanForRoot(config.str());
159 // Next check if fg-root is set as an env variable
161 envp = ::getenv( "FG_ROOT" );
162 if ( envp != NULL ) {
167 // Otherwise, default to a random compiled-in location if we can't
168 // find fg-root any other way.
170 #if defined( __CYGWIN__ )
171 root = "/FlightGear";
172 #elif defined( WIN32 )
173 root = "\\FlightGear";
174 #elif defined( macintosh )
181 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
182 globals->set_fg_root(root);
188 // Return the current base package version
189 string fgBasePackageVersion() {
190 SGPath base_path( globals->get_fg_root() );
191 base_path.append("version");
193 sg_gzifstream in( base_path.str() );
194 if ( !in.is_open() ) {
195 SGPath old_path( globals->get_fg_root() );
196 old_path.append( "Thanks" );
197 sg_gzifstream old( old_path.str() );
198 if ( !old.is_open() ) {
201 return "[old version]";
212 // Read in configuration (file and command line)
213 bool fgInitConfig ( int argc, char **argv ) {
215 // First, set some sane default values
218 // Read global preferences from $FG_ROOT/preferences.xml
219 SGPath props_path(globals->get_fg_root());
220 props_path.append("preferences.xml");
221 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
223 readProperties(props_path.str(), globals->get_props());
224 } catch (const sg_exception &e) {
225 string message = "Error reading global preferences: ";
226 message += e.getFormattedMessage();
227 SG_LOG(SG_INPUT, SG_ALERT, message);
230 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
232 // Attempt to locate and parse the various config files in order
233 // from least precidence to greatest precidence
235 // Check for $fg_root/system.fgfsrc
236 SGPath config( globals->get_fg_root() );
237 config.append( "system.fgfsrc" );
238 fgParseOptions(config.str());
241 #if defined( unix ) || defined( __CYGWIN__ )
242 // Check for $fg_root/system.fgfsrc.hostname
243 gethostname( name, 256 );
244 config.concat( "." );
245 config.concat( name );
246 fgParseOptions(config.str());
249 // Check for ~/.fgfsrc
250 char* envp = ::getenv( "HOME" );
251 if ( envp != NULL ) {
253 config.append( ".fgfsrc" );
254 fgParseOptions(config.str());
257 #if defined( unix ) || defined( __CYGWIN__ )
258 // Check for ~/.fgfsrc.hostname
259 gethostname( name, 256 );
260 config.concat( "." );
261 config.concat( name );
262 fgParseOptions(config.str());
265 // Parse remaining command line options
266 // These will override anything specified in a config file
267 fgParseOptions(argc, argv);
273 // find basic airport location info from airport database
274 bool fgFindAirportID( const string& id, FGAirport *a ) {
276 SGPath path( globals->get_fg_root() );
277 path.append( "Airports" );
278 path.append( "simple.mk4" );
279 FGAirports airports( path.c_str() );
281 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
283 if ( ! airports.search( id, a ) ) {
284 SG_LOG( SG_GENERAL, SG_ALERT,
285 "Failed to find " << id << " in " << path.str() );
292 SG_LOG( SG_GENERAL, SG_INFO,
293 "Position for " << id << " is ("
294 << a->longitude << ", "
295 << a->latitude << ")" );
301 // Set current_options lon/lat given an airport id
302 bool fgSetPosFromAirportID( const string& id ) {
306 SG_LOG( SG_GENERAL, SG_INFO,
307 "Attempting to set starting position from airport code " << id );
309 if ( fgFindAirportID( id, &a ) ) {
310 fgSetDouble("/position/longitude-deg", a.longitude );
311 fgSetDouble("/position/latitude-deg", a.latitude );
312 SG_LOG( SG_GENERAL, SG_INFO,
313 "Position for " << id << " is ("
314 << a.longitude << ", "
315 << a.latitude << ")" );
325 // Set current_options lon/lat given an airport id and heading (degrees)
326 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
329 double found_dir = 0.0;
332 // set initial position from runway and heading
334 SGPath path( globals->get_fg_root() );
335 path.append( "Airports" );
336 path.append( "runways.mk4" );
337 FGRunways runways( path.c_str() );
339 SG_LOG( SG_GENERAL, SG_INFO,
340 "Attempting to set starting position from runway code "
341 << id << " heading " << tgt_hdg );
343 // SGPath inpath( globals->get_fg_root() );
344 // inpath.append( "Airports" );
345 // inpath.append( "apt_simple" );
346 // airports.load( inpath.c_str() );
348 // SGPath outpath( globals->get_fg_root() );
349 // outpath.append( "Airports" );
350 // outpath.append( "simple.gdbm" );
351 // airports.dump_gdbm( outpath.c_str() );
353 if ( ! runways.search( id, &r ) ) {
354 SG_LOG( SG_GENERAL, SG_ALERT,
355 "Failed to find " << id << " in database." );
360 double min_diff = 360.0;
362 while ( r.id == id ) {
364 diff = tgt_hdg - r.heading;
365 while ( diff < -180.0 ) { diff += 360.0; }
366 while ( diff > 180.0 ) { diff -= 360.0; }
368 SG_LOG( SG_GENERAL, SG_INFO,
369 "Runway " << r.rwy_no << " heading = " << r.heading <<
370 " diff = " << diff );
371 if ( diff < min_diff ) {
378 diff = tgt_hdg - r.heading - 180.0;
379 while ( diff < -180.0 ) { diff += 360.0; }
380 while ( diff > 180.0 ) { diff -= 360.0; }
382 SG_LOG( SG_GENERAL, SG_INFO,
383 "Runway -" << r.rwy_no << " heading = " <<
385 " diff = " << diff );
386 if ( diff < min_diff ) {
395 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
396 << " + " << found_dir );
402 double heading = found_r.heading + found_dir;
403 while ( heading >= 360.0 ) { heading -= 360.0; }
405 double lat2, lon2, az2;
406 double azimuth = found_r.heading + found_dir + 180.0;
407 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
409 SG_LOG( SG_GENERAL, SG_INFO,
410 "runway = " << found_r.lon << ", " << found_r.lat
411 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
412 << " heading = " << azimuth );
414 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
415 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
416 &lat2, &lon2, &az2 );
418 if ( fabs( fgGetDouble("/sim/startup/offset-distance") ) > SG_EPSILON ) {
420 double odist = fgGetDouble("/sim/startup/offset-distance");
421 odist *= SG_NM_TO_METER;
422 double oaz = azimuth;
423 if ( fabs(fgGetDouble("/sim/startup/offset-azimuth")) > SG_EPSILON ) {
424 oaz = fgGetDouble("/sim/startup/offset-azimuth") + 180;
426 while ( oaz >= 360.0 ) { oaz -= 360.0; }
427 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
431 fgSetDouble("/position/longitude-deg", lon2 );
432 fgSetDouble("/position/latitude-deg", lat2 );
433 fgSetDouble("/orientation/heading-deg", heading );
435 SG_LOG( SG_GENERAL, SG_INFO,
436 "Position for " << id << " is ("
438 << lat2 << ") new heading is "
445 // General house keeping initializations
446 bool fgInitGeneral( void ) {
449 #if defined(FX) && defined(XMESA)
450 char *mesa_win_state;
453 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
454 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
456 root = globals->get_fg_root();
457 if ( ! root.length() ) {
458 // No root path set? Then bail ...
459 SG_LOG( SG_GENERAL, SG_ALERT,
460 "Cannot continue without a path to the base package "
461 << "being defined." );
464 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
466 #if defined(FX) && defined(XMESA)
467 // initialize full screen flag
468 global_fullscreen = false;
469 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
470 // Test for the MESA_GLX_FX env variable
471 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
472 // test if we are fullscreen mesa/glide
473 if ( (mesa_win_state[0] == 'f') ||
474 (mesa_win_state[0] == 'F') ) {
475 global_fullscreen = true;
485 // This is the top level init routine which calls all the other
486 // initialization routines. If you are adding a subsystem to flight
487 // gear, its initialization call should located in this routine.
488 // Returns non-zero if a problem encountered.
489 bool fgInitSubsystems( void ) {
490 static const SGPropertyNode *longitude
491 = fgGetNode("/position/longitude-deg");
492 static const SGPropertyNode *latitude
493 = fgGetNode("/position/latitude-deg");
494 static const SGPropertyNode *altitude
495 = fgGetNode("/position/altitude-ft");
497 fgLIGHT *l = &cur_light_params;
499 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
500 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
503 ////////////////////////////////////////////////////////////////////
504 // Initialize the material property subsystem.
505 ////////////////////////////////////////////////////////////////////
507 SGPath mpath( globals->get_fg_root() );
508 mpath.append( "materials" );
509 if ( material_lib.load( mpath.str() ) ) {
511 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
516 ////////////////////////////////////////////////////////////////////
517 // Initialize the scenery management subsystem.
518 ////////////////////////////////////////////////////////////////////
523 if ( global_tile_mgr.init() ) {
524 // Load the local scenery data
525 global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
526 fgGetDouble("/position/latitude-deg") );
528 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
532 SG_LOG( SG_GENERAL, SG_DEBUG,
533 "Current terrain elevation after tile mgr init " <<
534 scenery.get_cur_elev() );
537 ////////////////////////////////////////////////////////////////////
538 // Initialize the flight model subsystem.
539 ////////////////////////////////////////////////////////////////////
541 double dt = 1.0 / fgGetInt("/sim/model-hz");
542 // cout << "dt = " << dt << endl;
544 aircraft_dir = fgGetString("/sim/aircraft-dir");
545 const string &model = fgGetString("/sim/flight-model");
547 if (model == "larcsim") {
548 cur_fdm_state = new FGLaRCsim( dt );
549 } else if (model == "jsb") {
550 cur_fdm_state = new FGJSBsim( dt );
551 } else if (model == "ada") {
552 cur_fdm_state = new FGADA( dt );
553 } else if (model == "balloon") {
554 cur_fdm_state = new FGBalloonSim( dt );
555 } else if (model == "magic") {
556 cur_fdm_state = new FGMagicCarpet( dt );
557 } else if (model == "external") {
558 cur_fdm_state = new FGExternal( dt );
560 SG_LOG(SG_GENERAL, SG_ALERT,
561 "Unrecognized flight model '" << model
562 << ", can't init aircraft");
566 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
570 // Actual fdm initialization is delayed until we get a proper
571 // scenery elevation hit. This is checked for in main.cxx
572 // cur_fdm_state->init();
573 // cur_fdm_state->bind();
575 // allocates structures so must happen before any of the flight
576 // model or control parameters are set
577 fgAircraftInit(); // In the future this might not be the case.
580 ////////////////////////////////////////////////////////////////////
581 // Initialize the event manager subsystem.
582 ////////////////////////////////////////////////////////////////////
584 global_events.Init();
586 // Output event stats every 60 seconds
587 global_events.Register( "fgEVENT_MGR::PrintStats()",
588 fgMethodCallback<fgEVENT_MGR>( &global_events,
589 &fgEVENT_MGR::PrintStats),
590 fgEVENT::FG_EVENT_READY, 60000 );
593 ////////////////////////////////////////////////////////////////////
594 // Initialize the view manager subsystem.
595 ////////////////////////////////////////////////////////////////////
597 #if 0 /* As this wrongly does an integer division and gets x and y the wrong way around, I guess it's not needed. JAF */
598 // Initialize win_ratio parameters
599 for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
600 globals->get_viewmgr()->get_view(i)->
601 set_win_ratio( fgGetInt("/sim/startup/xsize") /
602 fgGetInt("/sim/startup/ysize") );
606 // Initialize pilot view
607 FGViewerRPH *pilot_view =
608 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
610 pilot_view->set_geod_view_pos( longitude->getDoubleValue()
611 * SGD_DEGREES_TO_RADIANS,
612 latitude->getDoubleValue()
613 * SGD_DEGREES_TO_RADIANS,
614 altitude->getDoubleValue()
615 * SG_FEET_TO_METER );
616 pilot_view->set_rph( cur_fdm_state->get_Phi(),
617 cur_fdm_state->get_Theta(),
618 cur_fdm_state->get_Psi() );
620 // set current view to 0 (first) which is our main pilot view
621 globals->set_current_view( pilot_view );
623 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
624 << globals->get_current_view()->get_abs_view_pos());
627 ////////////////////////////////////////////////////////////////////
628 // Initialize the lighting subsystem.
629 ////////////////////////////////////////////////////////////////////
631 // fgUpdateSunPos() needs a few position and view parameters set
632 // so it can calculate local relative sun angle and a few other
633 // things for correctly orienting the sky.
636 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
637 fgEVENT::FG_EVENT_READY, 60000);
638 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
639 fgEVENT::FG_EVENT_READY, 60000);
641 // Initialize Lighting interpolation tables
644 // update the lighting parameters (based on sun angle)
645 global_events.Register( "fgLight::Update()",
646 fgMethodCallback<fgLIGHT>( &cur_light_params,
648 fgEVENT::FG_EVENT_READY, 30000 );
651 ////////////////////////////////////////////////////////////////////
652 // Initialize the local time subsystem.
653 ////////////////////////////////////////////////////////////////////
655 // update the current timezone each 30 minutes
656 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
657 fgEVENT::FG_EVENT_READY, 1800000);
660 ////////////////////////////////////////////////////////////////////
661 // Initialize the weather subsystem.
662 ////////////////////////////////////////////////////////////////////
664 // Initialize the weather modeling subsystem
665 #ifndef FG_OLD_WEATHER
666 // Initialize the WeatherDatabase
667 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
669 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
670 current_aircraft.fdm_state->get_Longitude(),
671 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
672 double init_vis = fgGetDouble("/environment/visibility-m");
674 FGLocalWeatherDatabase::DatabaseWorkingType working_type;
676 if (fgGetString("/environment/weather/working-type") == "internet")
678 working_type = FGLocalWeatherDatabase::use_internet;
680 working_type = FGLocalWeatherDatabase::default_mode;
683 if ( init_vis > 0 ) {
684 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
685 new FGLocalWeatherDatabase( position,
686 globals->get_fg_root(),
690 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
691 new FGLocalWeatherDatabase( position,
692 globals->get_fg_root(),
696 // cout << theFGLocalWeatherDatabase << endl;
697 // cout << "visibility = "
698 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
700 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
702 // register the periodic update of the weather
703 global_events.Register( "weather update", fgUpdateWeatherDatabase,
704 fgEVENT::FG_EVENT_READY, 30000);
706 current_weather.Init();
709 ////////////////////////////////////////////////////////////////////
710 // Initialize vor/ndb/ils/fix list management and query systems
711 ////////////////////////////////////////////////////////////////////
713 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
715 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
716 current_navlist = new FGNavList;
717 SGPath p_nav( globals->get_fg_root() );
718 p_nav.append( "Navaids/default.nav" );
719 current_navlist->init( p_nav );
721 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
722 current_beacons = new FGMarkerBeacons;
723 current_beacons->init();
724 current_ilslist = new FGILSList;
725 SGPath p_ils( globals->get_fg_root() );
726 p_ils.append( "Navaids/default.ils" );
727 current_ilslist->init( p_ils );
729 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
730 current_fixlist = new FGFixList;
731 SGPath p_fix( globals->get_fg_root() );
732 p_fix.append( "Navaids/default.fix" );
733 current_fixlist->init( p_fix );
736 ////////////////////////////////////////////////////////////////////
737 // Initialize the built-in commands.
738 ////////////////////////////////////////////////////////////////////
742 ////////////////////////////////////////////////////////////////////
743 // Initialize the sound subsystem.
744 ////////////////////////////////////////////////////////////////////
746 globals->set_soundmgr(new FGSoundMgr);
747 globals->get_soundmgr()->init();
748 globals->get_soundmgr()->bind();
751 ////////////////////////////////////////////////////////////////////
752 // Initialize the sound-effects subsystem.
753 ////////////////////////////////////////////////////////////////////
754 globals->set_fx(new FGFX);
755 globals->get_fx()->init();
756 globals->get_fx()->bind();
759 ////////////////////////////////////////////////////////////////////
760 // Initialize the radio stack subsystem.
761 ////////////////////////////////////////////////////////////////////
763 // A textbook example of how FGSubsystem
765 current_radiostack = new FGRadioStack;
766 current_radiostack->init();
767 current_radiostack->bind();
770 ////////////////////////////////////////////////////////////////////
771 // Initialize the cockpit subsystem
772 ////////////////////////////////////////////////////////////////////
774 if( fgCockpitInit( ¤t_aircraft )) {
775 // Cockpit initialized ok.
777 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
782 ////////////////////////////////////////////////////////////////////
783 // Initialize the joystick subsystem.
784 ////////////////////////////////////////////////////////////////////
786 // if ( ! fgJoystickInit() ) {
787 // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
791 ////////////////////////////////////////////////////////////////////
792 // Initialize the autopilot subsystem.
793 ////////////////////////////////////////////////////////////////////
795 current_autopilot = new FGAutopilot;
796 current_autopilot->init();
798 // initialize the gui parts of the autopilot
805 ////////////////////////////////////////////////////////////////////
806 // Initialize I/O subsystem.
807 ////////////////////////////////////////////////////////////////////
809 #if ! defined( macintosh )
813 // Initialize the 2D panel.
814 string panel_path = fgGetString("/sim/panel/path",
815 "Panels/Default/default.xml");
816 current_panel = fgReadPanel(panel_path);
817 if (current_panel == 0) {
818 SG_LOG( SG_INPUT, SG_ALERT,
819 "Error reading new panel from " << panel_path );
821 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
822 current_panel->init();
823 current_panel->bind();
827 ////////////////////////////////////////////////////////////////////
828 // Initialize the default (kludged) properties.
829 ////////////////////////////////////////////////////////////////////
834 ////////////////////////////////////////////////////////////////////
835 // Initialize the controls subsystem.
836 ////////////////////////////////////////////////////////////////////
838 globals->get_controls()->init();
839 globals->get_controls()->bind();
842 ////////////////////////////////////////////////////////////////////
843 // Initialize the input subsystem.
844 ////////////////////////////////////////////////////////////////////
846 current_input.init();
847 current_input.bind();
850 ////////////////////////////////////////////////////////////////////////
851 // End of subsystem initialization.
852 ////////////////////////////////////////////////////////////////////
854 SG_LOG( SG_GENERAL, SG_INFO, endl);
856 // Save the initial state for future
858 globals->saveInitialState();
864 void fgReInitSubsystems( void )
866 static const SGPropertyNode *longitude
867 = fgGetNode("/position/longitude-deg");
868 static const SGPropertyNode *latitude
869 = fgGetNode("/position/latitude-deg");
870 static const SGPropertyNode *altitude
871 = fgGetNode("/position/altitude-ft");
873 SG_LOG( SG_GENERAL, SG_INFO,
874 "/position/altitude = " << altitude->getDoubleValue() );
876 bool freeze = globals->get_freeze();
878 globals->set_freeze( true );
881 // Initialize the Scenery Management subsystem
884 // if( global_tile_mgr.init() ) {
885 // Load the local scenery data
886 global_tile_mgr.update( longitude->getDoubleValue(),
887 latitude->getDoubleValue() );
889 // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
893 // Delete then Initialize the flight model subsystem.
894 delete cur_fdm_state;
896 double dt = 1.0 / fgGetInt("/sim/model-hz");
897 aircraft_dir = fgGetString("/sim/aircraft-dir");
898 const string &model = fgGetString("/sim/flight-model");
900 if (model == "larcsim") {
901 cur_fdm_state = new FGLaRCsim( dt );
902 } else if (model == "jsb") {
903 cur_fdm_state = new FGJSBsim( dt );
904 } else if (model == "ada") {
905 cur_fdm_state = new FGADA( dt );
906 } else if (model == "balloon") {
907 cur_fdm_state = new FGBalloonSim( dt );
908 } else if (model == "magic") {
909 cur_fdm_state = new FGMagicCarpet( dt );
910 } else if (model == "external") {
911 cur_fdm_state = new FGExternal( dt );
913 SG_LOG(SG_GENERAL, SG_ALERT,
914 "Unrecognized flight model '" << model
915 << ", can't init aircraft");
919 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
923 // Initialize view parameters
924 FGViewerRPH *pilot_view =
925 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
927 pilot_view->set_view_offset( 0.0 );
928 pilot_view->set_goal_view_offset( 0.0 );
930 pilot_view->set_geod_view_pos( longitude->getDoubleValue()
931 * SGD_DEGREES_TO_RADIANS,
932 latitude->getDoubleValue()
933 * SGD_DEGREES_TO_RADIANS,
934 cur_fdm_state->get_Altitude()
935 * SG_FEET_TO_METER );
936 pilot_view->set_rph( cur_fdm_state->get_Phi(),
937 cur_fdm_state->get_Theta(),
938 cur_fdm_state->get_Psi() );
940 // set current view to 0 (first) which is our main pilot view
941 globals->set_current_view( pilot_view );
943 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
944 << globals->get_current_view()->get_abs_view_pos());
946 globals->get_controls()->reset_all();
947 current_autopilot->reset();
951 cur_light_params.Update();
955 globals->set_freeze( false );