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 <Time/event.hxx>
94 #include <Time/light.hxx>
95 #include <Time/sunpos.hxx>
96 #include <Time/moonpos.hxx>
97 #include <Time/tmp.hxx>
99 #ifndef FG_OLD_WEATHER
100 # include <WeatherCM/FGLocalWeatherDatabase.h>
102 # include <Weather/weather.hxx>
105 #include "fg_init.hxx"
107 #include "fg_commands.hxx"
108 #include "fg_props.hxx"
109 #include "options.hxx"
110 #include "globals.hxx"
112 #if defined(FX) && defined(XMESA)
113 #include <GL/xmesa.h>
116 SG_USING_STD(string);
118 extern const char *default_root;
121 // Read in configuration (file and command line) and just set fg_root
122 bool fgInitFGRoot ( int argc, char **argv ) {
126 // First parse command line options looking for fg-root, this will
127 // override anything specified in a config file
128 root = fgScanForRoot(argc, argv);
130 #if defined( unix ) || defined( __CYGWIN__ )
131 // Next check home directory for .fgfsrc.hostname file
133 envp = ::getenv( "HOME" );
134 if ( envp != NULL ) {
135 SGPath config( envp );
136 config.append( ".fgfsrc" );
138 gethostname( name, 256 );
139 config.concat( "." );
140 config.concat( name );
141 root = fgScanForRoot(config.str());
146 // Next check home directory for .fgfsrc file
148 envp = ::getenv( "HOME" );
149 if ( envp != NULL ) {
150 SGPath config( envp );
151 config.append( ".fgfsrc" );
152 root = fgScanForRoot(config.str());
156 // Next check if fg-root is set as an env variable
158 envp = ::getenv( "FG_ROOT" );
159 if ( envp != NULL ) {
164 // Otherwise, default to a random compiled-in location if we can't
165 // find fg-root any other way.
167 #if defined( __CYGWIN__ )
168 root = "/FlightGear";
169 #elif defined( WIN32 )
170 root = "\\FlightGear";
171 #elif defined( macintosh )
178 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
179 globals->set_fg_root(root);
185 // Return the current base package version
186 string fgBasePackageVersion() {
187 SGPath base_path( globals->get_fg_root() );
188 base_path.append("version");
190 sg_gzifstream in( base_path.str() );
191 if ( !in.is_open() ) {
192 SGPath old_path( globals->get_fg_root() );
193 old_path.append( "Thanks" );
194 sg_gzifstream old( old_path.str() );
195 if ( !old.is_open() ) {
198 return "[old version]";
209 // Read in configuration (file and command line)
210 bool fgInitConfig ( int argc, char **argv ) {
212 // First, set some sane default values
215 // Read global preferences from $FG_ROOT/preferences.xml
216 SGPath props_path(globals->get_fg_root());
217 props_path.append("preferences.xml");
218 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
220 readProperties(props_path.str(), globals->get_props());
221 } catch (const sg_io_exception &e) {
222 string message = "Error reading global preferences: ";
223 message += e.getMessage();
225 message += e.getLocation().asString();
226 SG_LOG(SG_INPUT, SG_ALERT, message);
229 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
231 // Attempt to locate and parse the various config files in order
232 // from least precidence to greatest precidence
234 // Check for $fg_root/system.fgfsrc
235 SGPath config( globals->get_fg_root() );
236 config.append( "system.fgfsrc" );
237 fgParseOptions(config.str());
240 #if defined( unix ) || defined( __CYGWIN__ )
241 // Check for $fg_root/system.fgfsrc.hostname
242 gethostname( name, 256 );
243 config.concat( "." );
244 config.concat( name );
245 fgParseOptions(config.str());
248 // Check for ~/.fgfsrc
249 char* envp = ::getenv( "HOME" );
250 if ( envp != NULL ) {
252 config.append( ".fgfsrc" );
253 fgParseOptions(config.str());
256 #if defined( unix ) || defined( __CYGWIN__ )
257 // Check for ~/.fgfsrc.hostname
258 gethostname( name, 256 );
259 config.concat( "." );
260 config.concat( name );
261 fgParseOptions(config.str());
264 // Parse remaining command line options
265 // These will override anything specified in a config file
266 fgParseOptions(argc, argv);
272 // find basic airport location info from airport database
273 bool fgFindAirportID( const string& id, FGAirport *a ) {
275 SGPath path( globals->get_fg_root() );
276 path.append( "Airports" );
277 path.append( "simple.mk4" );
278 FGAirports airports( path.c_str() );
280 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
282 if ( ! airports.search( id, a ) ) {
283 SG_LOG( SG_GENERAL, SG_ALERT,
284 "Failed to find " << id << " in " << path.str() );
291 SG_LOG( SG_GENERAL, SG_INFO,
292 "Position for " << id << " is ("
293 << a->longitude << ", "
294 << a->latitude << ")" );
300 // Set current_options lon/lat given an airport id
301 bool fgSetPosFromAirportID( const string& id ) {
305 SG_LOG( SG_GENERAL, SG_INFO,
306 "Attempting to set starting position from airport code " << id );
308 if ( fgFindAirportID( id, &a ) ) {
309 fgSetDouble("/position/longitude-deg", a.longitude );
310 fgSetDouble("/position/latitude-deg", a.latitude );
311 SG_LOG( SG_GENERAL, SG_INFO,
312 "Position for " << id << " is ("
313 << a.longitude << ", "
314 << a.latitude << ")" );
324 // Set current_options lon/lat given an airport id and heading (degrees)
325 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
328 double found_dir = 0.0;
331 // set initial position from runway and heading
333 SGPath path( globals->get_fg_root() );
334 path.append( "Airports" );
335 path.append( "runways.mk4" );
336 FGRunways runways( path.c_str() );
338 SG_LOG( SG_GENERAL, SG_INFO,
339 "Attempting to set starting position from runway code "
340 << id << " heading " << tgt_hdg );
342 // SGPath inpath( globals->get_fg_root() );
343 // inpath.append( "Airports" );
344 // inpath.append( "apt_simple" );
345 // airports.load( inpath.c_str() );
347 // SGPath outpath( globals->get_fg_root() );
348 // outpath.append( "Airports" );
349 // outpath.append( "simple.gdbm" );
350 // airports.dump_gdbm( outpath.c_str() );
352 if ( ! runways.search( id, &r ) ) {
353 SG_LOG( SG_GENERAL, SG_ALERT,
354 "Failed to find " << id << " in database." );
359 double min_diff = 360.0;
361 while ( r.id == id ) {
363 diff = tgt_hdg - r.heading;
364 while ( diff < -180.0 ) { diff += 360.0; }
365 while ( diff > 180.0 ) { diff -= 360.0; }
367 SG_LOG( SG_GENERAL, SG_INFO,
368 "Runway " << r.rwy_no << " heading = " << r.heading <<
369 " diff = " << diff );
370 if ( diff < min_diff ) {
377 diff = tgt_hdg - r.heading - 180.0;
378 while ( diff < -180.0 ) { diff += 360.0; }
379 while ( diff > 180.0 ) { diff -= 360.0; }
381 SG_LOG( SG_GENERAL, SG_INFO,
382 "Runway -" << r.rwy_no << " heading = " <<
384 " diff = " << diff );
385 if ( diff < min_diff ) {
394 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
395 << " + " << found_dir );
401 double heading = found_r.heading + found_dir;
402 while ( heading >= 360.0 ) { heading -= 360.0; }
404 double lat2, lon2, az2;
405 double azimuth = found_r.heading + found_dir + 180.0;
406 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
408 SG_LOG( SG_GENERAL, SG_INFO,
409 "runway = " << found_r.lon << ", " << found_r.lat
410 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
411 << " heading = " << azimuth );
413 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
414 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
415 &lat2, &lon2, &az2 );
417 if ( fabs( fgGetDouble("/sim/startup/offset-distance") ) > SG_EPSILON ) {
419 double odist = fgGetDouble("/sim/startup/offset-distance");
420 odist *= SG_NM_TO_METER;
421 double oaz = azimuth;
422 if ( fabs(fgGetDouble("/sim/startup/offset-azimuth")) > SG_EPSILON ) {
423 oaz = fgGetDouble("/sim/startup/offset-azimuth") + 180;
425 while ( oaz >= 360.0 ) { oaz -= 360.0; }
426 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
430 fgSetDouble("/position/longitude-deg", lon2 );
431 fgSetDouble("/position/latitude-deg", lat2 );
432 fgSetDouble("/orientation/heading-deg", heading );
434 SG_LOG( SG_GENERAL, SG_INFO,
435 "Position for " << id << " is ("
437 << lat2 << ") new heading is "
444 // General house keeping initializations
445 bool fgInitGeneral( void ) {
448 #if defined(FX) && defined(XMESA)
449 char *mesa_win_state;
452 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
453 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
455 root = globals->get_fg_root();
456 if ( ! root.length() ) {
457 // No root path set? Then bail ...
458 SG_LOG( SG_GENERAL, SG_ALERT,
459 "Cannot continue without environment variable FG_ROOT"
460 << "being defined." );
463 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
465 #if defined(FX) && defined(XMESA)
466 // initialize full screen flag
467 global_fullscreen = false;
468 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
469 // Test for the MESA_GLX_FX env variable
470 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
471 // test if we are fullscreen mesa/glide
472 if ( (mesa_win_state[0] == 'f') ||
473 (mesa_win_state[0] == 'F') ) {
474 global_fullscreen = true;
484 // This is the top level init routine which calls all the other
485 // initialization routines. If you are adding a subsystem to flight
486 // gear, its initialization call should located in this routine.
487 // Returns non-zero if a problem encountered.
488 bool fgInitSubsystems( void ) {
489 fgLIGHT *l = &cur_light_params;
491 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
492 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
495 ////////////////////////////////////////////////////////////////////
496 // Initialize the material property subsystem.
497 ////////////////////////////////////////////////////////////////////
499 SGPath mpath( globals->get_fg_root() );
500 mpath.append( "materials" );
501 if ( material_lib.load( mpath.str() ) ) {
503 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
508 ////////////////////////////////////////////////////////////////////
509 // Initialize the scenery management subsystem.
510 ////////////////////////////////////////////////////////////////////
512 if ( fgSceneryInit() ) {
513 // Material lib initialized ok.
515 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
519 if ( global_tile_mgr.init() ) {
520 // Load the local scenery data
521 global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
522 fgGetDouble("/position/latitude-deg") );
524 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
528 SG_LOG( SG_GENERAL, SG_DEBUG,
529 "Current terrain elevation after tile mgr init " <<
533 ////////////////////////////////////////////////////////////////////
534 // Initialize the flight model subsystem.
535 ////////////////////////////////////////////////////////////////////
537 double dt = 1.0 / fgGetInt("/sim/model-hz");
538 // cout << "dt = " << dt << endl;
540 aircraft_dir = fgGetString("/sim/aircraft-dir");
541 const string &model = fgGetString("/sim/flight-model");
543 if (model == "larcsim") {
544 cur_fdm_state = new FGLaRCsim( dt );
545 } else if (model == "jsb") {
546 cur_fdm_state = new FGJSBsim( dt );
547 } else if (model == "ada") {
548 cur_fdm_state = new FGADA( dt );
549 } else if (model == "balloon") {
550 cur_fdm_state = new FGBalloonSim( dt );
551 } else if (model == "magic") {
552 cur_fdm_state = new FGMagicCarpet( dt );
553 } else if (model == "external") {
554 cur_fdm_state = new FGExternal( dt );
556 SG_LOG(SG_GENERAL, SG_ALERT,
557 "Unrecognized flight model '" << model
558 << ", can't init aircraft");
562 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
566 cur_fdm_state->init();
567 cur_fdm_state->bind();
569 // allocates structures so must happen before any of the flight
570 // model or control parameters are set
571 fgAircraftInit(); // In the future this might not be the case.
574 ////////////////////////////////////////////////////////////////////
575 // Initialize the event manager subsystem.
576 ////////////////////////////////////////////////////////////////////
578 global_events.Init();
580 // Output event stats every 60 seconds
581 global_events.Register( "fgEVENT_MGR::PrintStats()",
582 fgMethodCallback<fgEVENT_MGR>( &global_events,
583 &fgEVENT_MGR::PrintStats),
584 fgEVENT::FG_EVENT_READY, 60000 );
587 ////////////////////////////////////////////////////////////////////
588 // Initialize the view manager subsystem.
589 ////////////////////////////////////////////////////////////////////
591 // Initialize win_ratio parameters
592 for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
593 globals->get_viewmgr()->get_view(i)->
594 set_win_ratio( fgGetInt("/sim/startup/xsize") /
595 fgGetInt("/sim/startup/ysize") );
598 // Initialize pilot view
599 FGViewerRPH *pilot_view =
600 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
602 pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
603 cur_fdm_state->get_Lat_geocentric(),
604 cur_fdm_state->get_Altitude() *
606 pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
608 pilot_view->set_rph( cur_fdm_state->get_Phi(),
609 cur_fdm_state->get_Theta(),
610 cur_fdm_state->get_Psi() );
612 // set current view to 0 (first) which is our main pilot view
613 globals->set_current_view( pilot_view );
615 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
616 << globals->get_current_view()->get_abs_view_pos());
619 ////////////////////////////////////////////////////////////////////
620 // Initialize the lighting subsystem.
621 ////////////////////////////////////////////////////////////////////
623 // fgUpdateSunPos() needs a few position and view parameters set
624 // so it can calculate local relative sun angle and a few other
625 // things for correctly orienting the sky.
628 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
629 fgEVENT::FG_EVENT_READY, 60000);
630 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
631 fgEVENT::FG_EVENT_READY, 60000);
633 // Initialize Lighting interpolation tables
636 // update the lighting parameters (based on sun angle)
637 global_events.Register( "fgLight::Update()",
638 fgMethodCallback<fgLIGHT>( &cur_light_params,
640 fgEVENT::FG_EVENT_READY, 30000 );
643 ////////////////////////////////////////////////////////////////////
644 // Initialize the local time subsystem.
645 ////////////////////////////////////////////////////////////////////
647 // update the current timezone each 30 minutes
648 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
649 fgEVENT::FG_EVENT_READY, 1800000);
652 ////////////////////////////////////////////////////////////////////
653 // Initialize the weather subsystem.
654 ////////////////////////////////////////////////////////////////////
656 // Initialize the weather modeling subsystem
657 #ifndef FG_OLD_WEATHER
658 // Initialize the WeatherDatabase
659 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
661 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
662 current_aircraft.fdm_state->get_Longitude(),
663 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
664 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
665 new FGLocalWeatherDatabase( position,
666 globals->get_fg_root() );
667 // cout << theFGLocalWeatherDatabase << endl;
668 // cout << "visibility = "
669 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
671 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
673 double init_vis = fgGetDouble("/environment/visibility-m");
674 if ( init_vis > 0 ) {
675 WeatherDatabase->setWeatherVisibility( init_vis );
678 // register the periodic update of the weather
679 global_events.Register( "weather update", fgUpdateWeatherDatabase,
680 fgEVENT::FG_EVENT_READY, 30000);
682 current_weather.Init();
685 ////////////////////////////////////////////////////////////////////
686 // Initialize vor/ndb/ils/fix list management and query systems
687 ////////////////////////////////////////////////////////////////////
689 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
691 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
692 current_navlist = new FGNavList;
693 SGPath p_nav( globals->get_fg_root() );
694 p_nav.append( "Navaids/default.nav" );
695 current_navlist->init( p_nav );
697 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
698 current_beacons = new FGMarkerBeacons;
699 current_beacons->init();
700 current_ilslist = new FGILSList;
701 SGPath p_ils( globals->get_fg_root() );
702 p_ils.append( "Navaids/default.ils" );
703 current_ilslist->init( p_ils );
705 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
706 current_fixlist = new FGFixList;
707 SGPath p_fix( globals->get_fg_root() );
708 p_fix.append( "Navaids/default.fix" );
709 current_fixlist->init( p_fix );
712 ////////////////////////////////////////////////////////////////////
713 // Initialize the built-in commands.
714 ////////////////////////////////////////////////////////////////////
718 ////////////////////////////////////////////////////////////////////
719 // Initialize the radio stack subsystem.
720 ////////////////////////////////////////////////////////////////////
722 // A textbook example of how FGSubsystem
724 current_radiostack = new FGRadioStack;
725 current_radiostack->init();
726 current_radiostack->bind();
729 ////////////////////////////////////////////////////////////////////
730 // Initialize the cockpit subsystem
731 ////////////////////////////////////////////////////////////////////
733 if( fgCockpitInit( ¤t_aircraft )) {
734 // Cockpit initialized ok.
736 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
741 ////////////////////////////////////////////////////////////////////
742 // Initialize the joystick subsystem.
743 ////////////////////////////////////////////////////////////////////
745 // if ( ! fgJoystickInit() ) {
746 // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
750 ////////////////////////////////////////////////////////////////////
751 // Initialize the autopilot subsystem.
752 ////////////////////////////////////////////////////////////////////
754 current_autopilot = new FGAutopilot;
755 current_autopilot->init();
757 // initialize the gui parts of the autopilot
764 ////////////////////////////////////////////////////////////////////
765 // Initialize I/O subsystem.
766 ////////////////////////////////////////////////////////////////////
768 #if ! defined( macintosh )
772 // Initialize the 2D panel.
773 string panel_path = fgGetString("/sim/panel/path",
774 "Panels/Default/default.xml");
775 current_panel = fgReadPanel(panel_path);
776 if (current_panel == 0) {
777 SG_LOG( SG_INPUT, SG_ALERT,
778 "Error reading new panel from " << panel_path );
780 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
781 current_panel->init();
782 current_panel->bind();
786 ////////////////////////////////////////////////////////////////////
787 // Initialize the default (kludged) properties.
788 ////////////////////////////////////////////////////////////////////
793 ////////////////////////////////////////////////////////////////////
794 // Initialize the controls subsystem.
795 ////////////////////////////////////////////////////////////////////
801 ////////////////////////////////////////////////////////////////////
802 // Initialize the input subsystem.
803 ////////////////////////////////////////////////////////////////////
805 current_input.init();
806 current_input.bind();
809 ////////////////////////////////////////////////////////////////////////
810 // End of subsystem initialization.
811 ////////////////////////////////////////////////////////////////////
813 SG_LOG( SG_GENERAL, SG_INFO, endl);
815 // Save the initial state for future
817 globals->saveInitialState();
823 void fgReInitSubsystems( void )
825 SG_LOG( SG_GENERAL, SG_INFO,
826 "/position/altitude = " << fgGetDouble("/position/altitude-ft") );
828 bool freeze = globals->get_freeze();
830 globals->set_freeze( true );
832 // Initialize the Scenery Management subsystem
833 if ( ! fgSceneryInit() ) {
834 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
838 if( global_tile_mgr.init() ) {
839 // Load the local scenery data
840 global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
841 fgGetDouble("/position/latitude-deg") );
843 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
847 // Initialize view parameters
848 FGViewerRPH *pilot_view =
849 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
851 pilot_view->set_view_offset( 0.0 );
852 pilot_view->set_goal_view_offset( 0.0 );
854 pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
855 cur_fdm_state->get_Lat_geocentric(),
856 cur_fdm_state->get_Altitude() *
858 pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
860 pilot_view->set_rph( cur_fdm_state->get_Phi(),
861 cur_fdm_state->get_Theta(),
862 cur_fdm_state->get_Psi() );
864 // set current view to 0 (first) which is our main pilot view
865 globals->set_current_view( pilot_view );
867 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
868 << globals->get_current_view()->get_abs_view_pos());
870 cur_fdm_state->init();
872 controls.reset_all();
873 current_autopilot->reset();
877 cur_light_params.Update();
881 globals->set_freeze( false );