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>
58 #include <simgear/constants.h>
59 #include <simgear/debug/logstream.hxx>
60 #include <simgear/math/point3d.hxx>
61 #include <simgear/math/polar3d.hxx>
62 #include <simgear/math/sg_geodesy.hxx>
63 #include <simgear/misc/sg_path.hxx>
64 #include <simgear/timing/sg_time.hxx>
66 #include <Aircraft/aircraft.hxx>
67 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
68 #include <Airports/runways.hxx>
69 #include <Airports/simple.hxx>
70 #include <Autopilot/auto_gui.hxx>
71 #include <Autopilot/newauto.hxx>
72 #include <Cockpit/cockpit.hxx>
73 #include <Cockpit/radiostack.hxx>
74 #include <Cockpit/panel.hxx>
75 #include <Cockpit/panel_io.hxx>
76 #include <FDM/ADA.hxx>
77 #include <FDM/Balloon.h>
78 #include <FDM/External.hxx>
79 #include <FDM/JSBSim.hxx>
80 #include <FDM/LaRCsim.hxx>
81 #include <FDM/MagicCarpet.hxx>
82 #include <Include/general.hxx>
83 #include <Input/input.hxx>
84 // #include <Joystick/joystick.hxx>
85 #include <Objects/matlib.hxx>
86 #include <Navaids/fixlist.hxx>
87 #include <Navaids/ilslist.hxx>
88 #include <Navaids/mkrbeacons.hxx>
89 #include <Navaids/navlist.hxx>
90 #include <Scenery/scenery.hxx>
91 #include <Scenery/tilemgr.hxx>
92 #include <Time/event.hxx>
93 #include <Time/light.hxx>
94 #include <Time/sunpos.hxx>
95 #include <Time/moonpos.hxx>
96 #include <Time/tmp.hxx>
98 #ifndef FG_OLD_WEATHER
99 # include <WeatherCM/FGLocalWeatherDatabase.h>
101 # include <Weather/weather.hxx>
104 #include "fg_init.hxx"
106 #include "fg_commands.hxx"
107 #include "fg_props.hxx"
108 #include "options.hxx"
109 #include "globals.hxx"
111 #if defined(FX) && defined(XMESA)
112 #include <GL/xmesa.h>
115 SG_USING_STD(string);
117 extern const char *default_root;
120 // Read in configuration (file and command line) and just set fg_root
121 bool fgInitFGRoot ( int argc, char **argv ) {
125 // First parse command line options looking for fg-root, this will
126 // override anything specified in a config file
127 root = fgScanForRoot(argc, argv);
129 #if defined( unix ) || defined( __CYGWIN__ )
130 // Next check home directory for .fgfsrc.hostname file
132 envp = ::getenv( "HOME" );
133 if ( envp != NULL ) {
134 SGPath config( envp );
135 config.append( ".fgfsrc" );
137 gethostname( name, 256 );
138 config.concat( "." );
139 config.concat( name );
140 root = fgScanForRoot(config.str());
145 // Next check home directory for .fgfsrc file
147 envp = ::getenv( "HOME" );
148 if ( envp != NULL ) {
149 SGPath config( envp );
150 config.append( ".fgfsrc" );
151 root = fgScanForRoot(config.str());
155 // Next check if fg-root is set as an env variable
157 envp = ::getenv( "FG_ROOT" );
158 if ( envp != NULL ) {
163 // Otherwise, default to a random compiled-in location if we can't
164 // find fg-root any other way.
166 #if defined( __CYGWIN__ )
167 root = "/FlightGear";
168 #elif defined( WIN32 )
169 root = "\\FlightGear";
170 #elif defined( macintosh )
177 SG_LOG(SG_INPUT, SG_INFO, "fg_root = " << root );
178 globals->set_fg_root(root);
184 // Return the current base package version
185 string fgBasePackageVersion() {
186 SGPath base_path( globals->get_fg_root() );
187 base_path.append("version");
189 sg_gzifstream in( base_path.str() );
190 if ( !in.is_open() ) {
191 SGPath old_path( globals->get_fg_root() );
192 old_path.append( "Thanks" );
193 sg_gzifstream old( old_path.str() );
194 if ( !old.is_open() ) {
197 return "[old version]";
208 // Read in configuration (file and command line)
209 bool fgInitConfig ( int argc, char **argv ) {
211 // First, set some sane default values
214 // Read global preferences from $FG_ROOT/preferences.xml
215 SGPath props_path(globals->get_fg_root());
216 props_path.append("preferences.xml");
217 SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
218 if (!readProperties(props_path.str(), globals->get_props())) {
219 SG_LOG(SG_INPUT, SG_ALERT, "Failed to read global preferences from "
220 << props_path.str());
222 SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
225 // Attempt to locate and parse the various config files in order
226 // from least precidence to greatest precidence
228 // Check for $fg_root/system.fgfsrc
229 SGPath config( globals->get_fg_root() );
230 config.append( "system.fgfsrc" );
231 fgParseOptions(config.str());
234 #if defined( unix ) || defined( __CYGWIN__ )
235 // Check for $fg_root/system.fgfsrc.hostname
236 gethostname( name, 256 );
237 config.concat( "." );
238 config.concat( name );
239 fgParseOptions(config.str());
242 // Check for ~/.fgfsrc
243 char* envp = ::getenv( "HOME" );
244 if ( envp != NULL ) {
246 config.append( ".fgfsrc" );
247 fgParseOptions(config.str());
250 #if defined( unix ) || defined( __CYGWIN__ )
251 // Check for ~/.fgfsrc.hostname
252 gethostname( name, 256 );
253 config.concat( "." );
254 config.concat( name );
255 fgParseOptions(config.str());
258 // Parse remaining command line options
259 // These will override anything specified in a config file
260 fgParseOptions(argc, argv);
266 // find basic airport location info from airport database
267 bool fgFindAirportID( const string& id, FGAirport *a ) {
269 SGPath path( globals->get_fg_root() );
270 path.append( "Airports" );
271 path.append( "simple.mk4" );
272 FGAirports airports( path.c_str() );
274 SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
276 if ( ! airports.search( id, a ) ) {
277 SG_LOG( SG_GENERAL, SG_ALERT,
278 "Failed to find " << id << " in " << path.str() );
285 SG_LOG( SG_GENERAL, SG_INFO,
286 "Position for " << id << " is ("
287 << a->longitude << ", "
288 << a->latitude << ")" );
294 // Set current_options lon/lat given an airport id
295 bool fgSetPosFromAirportID( const string& id ) {
299 SG_LOG( SG_GENERAL, SG_INFO,
300 "Attempting to set starting position from airport code " << id );
302 if ( fgFindAirportID( id, &a ) ) {
303 fgSetDouble("/position/longitude-deg", a.longitude );
304 fgSetDouble("/position/latitude-deg", a.latitude );
305 SG_LOG( SG_GENERAL, SG_INFO,
306 "Position for " << id << " is ("
307 << a.longitude << ", "
308 << a.latitude << ")" );
318 // Set current_options lon/lat given an airport id and heading (degrees)
319 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
322 double found_dir = 0.0;
325 // set initial position from runway and heading
327 SGPath path( globals->get_fg_root() );
328 path.append( "Airports" );
329 path.append( "runways.mk4" );
330 FGRunways runways( path.c_str() );
332 SG_LOG( SG_GENERAL, SG_INFO,
333 "Attempting to set starting position from runway code "
334 << id << " heading " << tgt_hdg );
336 // SGPath inpath( globals->get_fg_root() );
337 // inpath.append( "Airports" );
338 // inpath.append( "apt_simple" );
339 // airports.load( inpath.c_str() );
341 // SGPath outpath( globals->get_fg_root() );
342 // outpath.append( "Airports" );
343 // outpath.append( "simple.gdbm" );
344 // airports.dump_gdbm( outpath.c_str() );
346 if ( ! runways.search( id, &r ) ) {
347 SG_LOG( SG_GENERAL, SG_ALERT,
348 "Failed to find " << id << " in database." );
353 double min_diff = 360.0;
355 while ( r.id == id ) {
357 diff = tgt_hdg - r.heading;
358 while ( diff < -180.0 ) { diff += 360.0; }
359 while ( diff > 180.0 ) { diff -= 360.0; }
361 SG_LOG( SG_GENERAL, SG_INFO,
362 "Runway " << r.rwy_no << " heading = " << r.heading <<
363 " diff = " << diff );
364 if ( diff < min_diff ) {
371 diff = tgt_hdg - r.heading - 180.0;
372 while ( diff < -180.0 ) { diff += 360.0; }
373 while ( diff > 180.0 ) { diff -= 360.0; }
375 SG_LOG( SG_GENERAL, SG_INFO,
376 "Runway -" << r.rwy_no << " heading = " <<
378 " diff = " << diff );
379 if ( diff < min_diff ) {
388 SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << found_r.rwy_no
389 << " + " << found_dir );
395 double heading = found_r.heading + found_dir;
396 while ( heading >= 360.0 ) { heading -= 360.0; }
398 double lat2, lon2, az2;
399 double azimuth = found_r.heading + found_dir + 180.0;
400 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
402 SG_LOG( SG_GENERAL, SG_INFO,
403 "runway = " << found_r.lon << ", " << found_r.lat
404 << " length = " << found_r.length * SG_FEET_TO_METER * 0.5
405 << " heading = " << azimuth );
407 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
408 azimuth, found_r.length * SG_FEET_TO_METER * 0.5 - 5.0,
409 &lat2, &lon2, &az2 );
411 if ( fabs( fgGetDouble("/sim/startup/offset-distance") ) > SG_EPSILON ) {
413 double odist = fgGetDouble("/sim/startup/offset-distance");
414 odist *= SG_NM_TO_METER;
415 double oaz = azimuth;
416 if ( fabs(fgGetDouble("/sim/startup/offset-azimuth")) > SG_EPSILON ) {
417 oaz = fgGetDouble("/sim/startup/offset-azimuth") + 180;
419 while ( oaz >= 360.0 ) { oaz -= 360.0; }
420 geo_direct_wgs_84 ( 0, lat2, lon2, oaz, odist, &olat, &olon, &az2 );
424 fgSetDouble("/position/longitude-deg", lon2 );
425 fgSetDouble("/position/latitude-deg", lat2 );
426 fgSetDouble("/orientation/heading-deg", heading );
428 SG_LOG( SG_GENERAL, SG_INFO,
429 "Position for " << id << " is ("
431 << lat2 << ") new heading is "
438 // General house keeping initializations
439 bool fgInitGeneral( void ) {
442 #if defined(FX) && defined(XMESA)
443 char *mesa_win_state;
446 SG_LOG( SG_GENERAL, SG_INFO, "General Initialization" );
447 SG_LOG( SG_GENERAL, SG_INFO, "======= ==============" );
449 root = globals->get_fg_root();
450 if ( ! root.length() ) {
451 // No root path set? Then bail ...
452 SG_LOG( SG_GENERAL, SG_ALERT,
453 "Cannot continue without environment variable FG_ROOT"
454 << "being defined." );
457 SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
459 #if defined(FX) && defined(XMESA)
460 // initialize full screen flag
461 global_fullscreen = false;
462 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
463 // Test for the MESA_GLX_FX env variable
464 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
465 // test if we are fullscreen mesa/glide
466 if ( (mesa_win_state[0] == 'f') ||
467 (mesa_win_state[0] == 'F') ) {
468 global_fullscreen = true;
478 // This is the top level init routine which calls all the other
479 // initialization routines. If you are adding a subsystem to flight
480 // gear, its initialization call should located in this routine.
481 // Returns non-zero if a problem encountered.
482 bool fgInitSubsystems( void ) {
483 fgLIGHT *l = &cur_light_params;
485 SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
486 SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
489 ////////////////////////////////////////////////////////////////////
490 // Initialize the material property subsystem.
491 ////////////////////////////////////////////////////////////////////
493 SGPath mpath( globals->get_fg_root() );
494 mpath.append( "materials" );
495 if ( material_lib.load( mpath.str() ) ) {
497 SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
502 ////////////////////////////////////////////////////////////////////
503 // Initialize the scenery management subsystem.
504 ////////////////////////////////////////////////////////////////////
506 if ( fgSceneryInit() ) {
507 // Material lib initialized ok.
509 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
513 if ( global_tile_mgr.init() ) {
514 // Load the local scenery data
515 global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
516 fgGetDouble("/position/latitude-deg") );
518 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
522 SG_LOG( SG_GENERAL, SG_DEBUG,
523 "Current terrain elevation after tile mgr init " <<
527 ////////////////////////////////////////////////////////////////////
528 // Initialize the flight model subsystem.
529 ////////////////////////////////////////////////////////////////////
531 double dt = 1.0 / fgGetInt("/sim/model-hz");
532 // cout << "dt = " << dt << endl;
534 aircraft_dir = fgGetString("/sim/aircraft-dir");
535 const string &model = fgGetString("/sim/flight-model");
537 if (model == "larcsim") {
538 cur_fdm_state = new FGLaRCsim( dt );
539 } else if (model == "jsb") {
540 cur_fdm_state = new FGJSBsim( dt );
541 } else if (model == "ada") {
542 cur_fdm_state = new FGADA( dt );
543 } else if (model == "balloon") {
544 cur_fdm_state = new FGBalloonSim( dt );
545 } else if (model == "magic") {
546 cur_fdm_state = new FGMagicCarpet( dt );
547 } else if (model == "external") {
548 cur_fdm_state = new FGExternal( dt );
550 SG_LOG(SG_GENERAL, SG_ALERT,
551 "Unrecognized flight model '" << model
552 << ", can't init aircraft");
556 SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
560 cur_fdm_state->init();
561 cur_fdm_state->bind();
563 // allocates structures so must happen before any of the flight
564 // model or control parameters are set
565 fgAircraftInit(); // In the future this might not be the case.
568 ////////////////////////////////////////////////////////////////////
569 // Initialize the event manager subsystem.
570 ////////////////////////////////////////////////////////////////////
572 global_events.Init();
574 // Output event stats every 60 seconds
575 global_events.Register( "fgEVENT_MGR::PrintStats()",
576 fgMethodCallback<fgEVENT_MGR>( &global_events,
577 &fgEVENT_MGR::PrintStats),
578 fgEVENT::FG_EVENT_READY, 60000 );
581 ////////////////////////////////////////////////////////////////////
582 // Initialize the view manager subsystem.
583 ////////////////////////////////////////////////////////////////////
585 // Initialize win_ratio parameters
586 for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
587 globals->get_viewmgr()->get_view(i)->
588 set_win_ratio( fgGetInt("/sim/startup/xsize") /
589 fgGetInt("/sim/startup/ysize") );
592 // Initialize pilot view
593 FGViewerRPH *pilot_view =
594 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
596 pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
597 cur_fdm_state->get_Lat_geocentric(),
598 cur_fdm_state->get_Altitude() *
600 pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
602 pilot_view->set_rph( cur_fdm_state->get_Phi(),
603 cur_fdm_state->get_Theta(),
604 cur_fdm_state->get_Psi() );
606 // set current view to 0 (first) which is our main pilot view
607 globals->set_current_view( pilot_view );
609 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
610 << globals->get_current_view()->get_abs_view_pos());
613 ////////////////////////////////////////////////////////////////////
614 // Initialize the lighting subsystem.
615 ////////////////////////////////////////////////////////////////////
617 // fgUpdateSunPos() needs a few position and view parameters set
618 // so it can calculate local relative sun angle and a few other
619 // things for correctly orienting the sky.
622 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
623 fgEVENT::FG_EVENT_READY, 60000);
624 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
625 fgEVENT::FG_EVENT_READY, 60000);
627 // Initialize Lighting interpolation tables
630 // update the lighting parameters (based on sun angle)
631 global_events.Register( "fgLight::Update()",
632 fgMethodCallback<fgLIGHT>( &cur_light_params,
634 fgEVENT::FG_EVENT_READY, 30000 );
637 ////////////////////////////////////////////////////////////////////
638 // Initialize the local time subsystem.
639 ////////////////////////////////////////////////////////////////////
641 // update the current timezone each 30 minutes
642 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
643 fgEVENT::FG_EVENT_READY, 1800000);
646 ////////////////////////////////////////////////////////////////////
647 // Initialize the weather subsystem.
648 ////////////////////////////////////////////////////////////////////
650 // Initialize the weather modeling subsystem
651 #ifndef FG_OLD_WEATHER
652 // Initialize the WeatherDatabase
653 SG_LOG(SG_GENERAL, SG_INFO, "Creating LocalWeatherDatabase");
655 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
656 current_aircraft.fdm_state->get_Longitude(),
657 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER );
658 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
659 new FGLocalWeatherDatabase( position,
660 globals->get_fg_root() );
661 // cout << theFGLocalWeatherDatabase << endl;
662 // cout << "visibility = "
663 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
665 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
667 double init_vis = fgGetDouble("/environment/visibility-m");
668 if ( init_vis > 0 ) {
669 WeatherDatabase->setWeatherVisibility( init_vis );
672 // register the periodic update of the weather
673 global_events.Register( "weather update", fgUpdateWeatherDatabase,
674 fgEVENT::FG_EVENT_READY, 30000);
676 current_weather.Init();
679 ////////////////////////////////////////////////////////////////////
680 // Initialize vor/ndb/ils/fix list management and query systems
681 ////////////////////////////////////////////////////////////////////
683 SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
685 SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
686 current_navlist = new FGNavList;
687 SGPath p_nav( globals->get_fg_root() );
688 p_nav.append( "Navaids/default.nav" );
689 current_navlist->init( p_nav );
691 SG_LOG(SG_GENERAL, SG_INFO, " ILS and Marker Beacons");
692 current_beacons = new FGMarkerBeacons;
693 current_beacons->init();
694 current_ilslist = new FGILSList;
695 SGPath p_ils( globals->get_fg_root() );
696 p_ils.append( "Navaids/default.ils" );
697 current_ilslist->init( p_ils );
699 SG_LOG(SG_GENERAL, SG_INFO, " Fixes");
700 current_fixlist = new FGFixList;
701 SGPath p_fix( globals->get_fg_root() );
702 p_fix.append( "Navaids/default.fix" );
703 current_fixlist->init( p_fix );
706 ////////////////////////////////////////////////////////////////////
707 // Initialize the built-in commands.
708 ////////////////////////////////////////////////////////////////////
712 ////////////////////////////////////////////////////////////////////
713 // Initialize the radio stack subsystem.
714 ////////////////////////////////////////////////////////////////////
716 // A textbook example of how FGSubsystem
718 current_radiostack = new FGRadioStack;
719 current_radiostack->init();
720 current_radiostack->bind();
723 ////////////////////////////////////////////////////////////////////
724 // Initialize the cockpit subsystem
725 ////////////////////////////////////////////////////////////////////
727 if( fgCockpitInit( ¤t_aircraft )) {
728 // Cockpit initialized ok.
730 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Cockpit initialization!" );
735 ////////////////////////////////////////////////////////////////////
736 // Initialize the joystick subsystem.
737 ////////////////////////////////////////////////////////////////////
739 // if ( ! fgJoystickInit() ) {
740 // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
744 ////////////////////////////////////////////////////////////////////
745 // Initialize the autopilot subsystem.
746 ////////////////////////////////////////////////////////////////////
748 current_autopilot = new FGAutopilot;
749 current_autopilot->init();
751 // initialize the gui parts of the autopilot
758 ////////////////////////////////////////////////////////////////////
759 // Initialize I/O subsystem.
760 ////////////////////////////////////////////////////////////////////
762 #if ! defined( macintosh )
766 // Initialize the 2D panel.
767 string panel_path = fgGetString("/sim/panel/path",
768 "Panels/Default/default.xml");
769 current_panel = fgReadPanel(panel_path);
770 if (current_panel == 0) {
771 SG_LOG( SG_INPUT, SG_ALERT,
772 "Error reading new panel from " << panel_path );
774 SG_LOG( SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path );
775 current_panel->init();
776 current_panel->bind();
780 ////////////////////////////////////////////////////////////////////
781 // Initialize the default (kludged) properties.
782 ////////////////////////////////////////////////////////////////////
787 ////////////////////////////////////////////////////////////////////
788 // Initialize the controls subsystem.
789 ////////////////////////////////////////////////////////////////////
795 ////////////////////////////////////////////////////////////////////
796 // Initialize the input subsystem.
797 ////////////////////////////////////////////////////////////////////
799 current_input.init();
800 current_input.bind();
803 ////////////////////////////////////////////////////////////////////////
804 // End of subsystem initialization.
805 ////////////////////////////////////////////////////////////////////
807 SG_LOG( SG_GENERAL, SG_INFO, endl);
809 // Save the initial state for future
811 globals->saveInitialState();
817 void fgReInitSubsystems( void )
819 SG_LOG( SG_GENERAL, SG_INFO,
820 "/position/altitude = " << fgGetDouble("/position/altitude-ft") );
822 bool freeze = globals->get_freeze();
824 globals->set_freeze( true );
826 // Initialize the Scenery Management subsystem
827 if ( ! fgSceneryInit() ) {
828 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
832 if( global_tile_mgr.init() ) {
833 // Load the local scenery data
834 global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
835 fgGetDouble("/position/latitude-deg") );
837 SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
841 // Initialize view parameters
842 FGViewerRPH *pilot_view =
843 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
845 pilot_view->set_view_offset( 0.0 );
846 pilot_view->set_goal_view_offset( 0.0 );
848 pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
849 cur_fdm_state->get_Lat_geocentric(),
850 cur_fdm_state->get_Altitude() *
852 pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
854 pilot_view->set_rph( cur_fdm_state->get_Phi(),
855 cur_fdm_state->get_Theta(),
856 cur_fdm_state->get_Psi() );
858 // set current view to 0 (first) which is our main pilot view
859 globals->set_current_view( pilot_view );
861 SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
862 << globals->get_current_view()->get_abs_view_pos());
864 cur_fdm_state->init();
866 controls.reset_all();
867 current_autopilot->reset();
871 cur_light_params.Update();
875 globals->set_freeze( false );