X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Ffg_init.cxx;h=5419fcd040a421a6c6c44a009cee0d98375fe68e;hb=2fbab0d702c9b1331aeec3c66167b813d101b593;hp=7866a35f358bddd1602e29c02b509716d299d3a2;hpb=65f6e343ab83b6c48ee8a74dbf3261715543b3dd;p=flightgear.git diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 7866a35f3..5419fcd04 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -31,8 +31,11 @@ # include #endif +#ifdef HAVE_WINDOWS_H +# include +#endif + #include -#include #include #include @@ -49,6 +52,7 @@ #endif #include +#include #include STL_STRING @@ -77,7 +81,8 @@ #include #include #include -#include +#include +// #include #include #include #include @@ -99,9 +104,11 @@ #include "fg_init.hxx" #include "fg_io.hxx" +#include "fg_commands.hxx" +#include "fg_props.hxx" #include "options.hxx" #include "globals.hxx" -#include "bfi.hxx" +#include "viewmgr.hxx" #if defined(FX) && defined(XMESA) #include @@ -158,7 +165,9 @@ bool fgInitFGRoot ( int argc, char **argv ) { // Otherwise, default to a random compiled-in location if we can't // find fg-root any other way. if ( root == "" ) { -#if defined( WIN32 ) +#if defined( __CYGWIN__ ) + root = "/FlightGear"; +#elif defined( WIN32 ) root = "\\FlightGear"; #elif defined( macintosh ) root = ""; @@ -174,6 +183,30 @@ bool fgInitFGRoot ( int argc, char **argv ) { } +// Return the current base package version +string fgBasePackageVersion() { + SGPath base_path( globals->get_fg_root() ); + base_path.append("version"); + + sg_gzifstream in( base_path.str() ); + if ( !in.is_open() ) { + SGPath old_path( globals->get_fg_root() ); + old_path.append( "Thanks" ); + sg_gzifstream old( old_path.str() ); + if ( !old.is_open() ) { + return "[none]"; + } else { + return "[old version]"; + } + } + + string version; + in >> version; + + return version; +} + + // Read in configuration (file and command line) bool fgInitConfig ( int argc, char **argv ) { @@ -184,12 +217,15 @@ bool fgInitConfig ( int argc, char **argv ) { SGPath props_path(globals->get_fg_root()); props_path.append("preferences.xml"); SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); - if (!readProperties(props_path.str(), globals->get_props())) { - SG_LOG(SG_INPUT, SG_ALERT, "Failed to read global preferences from " - << props_path.str()); - } else { - SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); + try { + readProperties(props_path.str(), globals->get_props()); + } catch (const sg_exception &e) { + string message = "Error reading global preferences: "; + message += e.getFormattedMessage(); + SG_LOG(SG_INPUT, SG_ALERT, message); + exit(2); } + SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); // Attempt to locate and parse the various config files in order // from least precidence to greatest precidence @@ -269,8 +305,8 @@ bool fgSetPosFromAirportID( const string& id ) { "Attempting to set starting position from airport code " << id ); if ( fgFindAirportID( id, &a ) ) { - fgSetDouble("/position/longitude", a.longitude ); - fgSetDouble("/position/latitude", a.latitude ); + fgSetDouble("/position/longitude-deg", a.longitude ); + fgSetDouble("/position/latitude-deg", a.latitude ); SG_LOG( SG_GENERAL, SG_INFO, "Position for " << id << " is (" << a.longitude << ", " @@ -390,9 +426,9 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) { lat2=olat; lon2=olon; } - fgSetDouble("/position/longitude", lon2 ); - fgSetDouble("/position/latitude", lat2 ); - fgSetDouble("/orientation/heading", heading ); + fgSetDouble("/position/longitude-deg", lon2 ); + fgSetDouble("/position/latitude-deg", lat2 ); + fgSetDouble("/orientation/heading-deg", heading ); SG_LOG( SG_GENERAL, SG_INFO, "Position for " << id << " is (" @@ -481,8 +517,8 @@ bool fgInitSubsystems( void ) { if ( global_tile_mgr.init() ) { // Load the local scenery data - global_tile_mgr.update( fgGetDouble("/position/longitude"), - fgGetDouble("/position/latitude") ); + global_tile_mgr.update( fgGetDouble("/position/longitude-deg"), + fgGetDouble("/position/latitude-deg") ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); exit(-1); @@ -502,24 +538,30 @@ bool fgInitSubsystems( void ) { aircraft_dir = fgGetString("/sim/aircraft-dir"); const string &model = fgGetString("/sim/flight-model"); - if (model == "larcsim") { - cur_fdm_state = new FGLaRCsim( dt ); - } else if (model == "jsb") { - cur_fdm_state = new FGJSBsim( dt ); - } else if (model == "ada") { - cur_fdm_state = new FGADA( dt ); - } else if (model == "balloon") { - cur_fdm_state = new FGBalloonSim( dt ); - } else if (model == "magic") { - cur_fdm_state = new FGMagicCarpet( dt ); - } else if (model == "external") { - cur_fdm_state = new FGExternal( dt ); - } else { - SG_LOG(SG_GENERAL, SG_ALERT, - "Unrecognized flight model '" << model - << ", can't init aircraft"); + try { + if (model == "larcsim") { + cur_fdm_state = new FGLaRCsim( dt ); + } else if (model == "jsb") { + cur_fdm_state = new FGJSBsim( dt ); + } else if (model == "ada") { + cur_fdm_state = new FGADA( dt ); + } else if (model == "balloon") { + cur_fdm_state = new FGBalloonSim( dt ); + } else if (model == "magic") { + cur_fdm_state = new FGMagicCarpet( dt ); + } else if (model == "external") { + cur_fdm_state = new FGExternal( dt ); + } else { + SG_LOG(SG_GENERAL, SG_ALERT, + "Unrecognized flight model '" << model + << ", can't init aircraft"); + exit(-1); + } + } catch ( ... ) { + SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n"); exit(-1); } + cur_fdm_state->init(); cur_fdm_state->bind(); @@ -618,19 +660,35 @@ bool fgInitSubsystems( void ) { sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(), current_aircraft.fdm_state->get_Longitude(), current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER ); - FGLocalWeatherDatabase::theFGLocalWeatherDatabase = + double init_vis = fgGetDouble("/environment/visibility-m"); + + FGLocalWeatherDatabase::DatabaseWorkingType working_type; + + if (fgGetString("/environment/weather/working-type") == "internet") + { + working_type = FGLocalWeatherDatabase::use_internet; + } else { + working_type = FGLocalWeatherDatabase::default_mode; + } + + if ( init_vis > 0 ) { + FGLocalWeatherDatabase::theFGLocalWeatherDatabase = new FGLocalWeatherDatabase( position, - globals->get_fg_root() ); + globals->get_fg_root(), + working_type, + init_vis ); + } else { + FGLocalWeatherDatabase::theFGLocalWeatherDatabase = + new FGLocalWeatherDatabase( position, + globals->get_fg_root(), + working_type ); + } + // cout << theFGLocalWeatherDatabase << endl; // cout << "visibility = " // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl; WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase; - - double init_vis = fgGetDouble("/environment/visibility"); - if ( init_vis > 0 ) { - WeatherDatabase->setWeatherVisibility( init_vis ); - } // register the periodic update of the weather global_events.Register( "weather update", fgUpdateWeatherDatabase, @@ -666,6 +724,12 @@ bool fgInitSubsystems( void ) { current_fixlist->init( p_fix ); + //////////////////////////////////////////////////////////////////// + // Initialize the built-in commands. + //////////////////////////////////////////////////////////////////// + fgInitCommands(); + + //////////////////////////////////////////////////////////////////// // Initialize the radio stack subsystem. //////////////////////////////////////////////////////////////////// @@ -693,9 +757,9 @@ bool fgInitSubsystems( void ) { // Initialize the joystick subsystem. //////////////////////////////////////////////////////////////////// - if ( ! fgJoystickInit() ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" ); - } + // if ( ! fgJoystickInit() ) { + // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" ); + // } //////////////////////////////////////////////////////////////////// @@ -735,18 +799,26 @@ bool fgInitSubsystems( void ) { //////////////////////////////////////////////////////////////////// - // Initialize the BFI. + // Initialize the default (kludged) properties. //////////////////////////////////////////////////////////////////// - FGBFI::init(); + fgInitProps(); //////////////////////////////////////////////////////////////////// // Initialize the controls subsystem. //////////////////////////////////////////////////////////////////// - controls.init(); - controls.bind(); + globals->get_controls()->init(); + globals->get_controls()->bind(); + + + //////////////////////////////////////////////////////////////////// + // Initialize the input subsystem. + //////////////////////////////////////////////////////////////////// + + current_input.init(); + current_input.bind(); //////////////////////////////////////////////////////////////////////// @@ -766,7 +838,7 @@ bool fgInitSubsystems( void ) { void fgReInitSubsystems( void ) { SG_LOG( SG_GENERAL, SG_INFO, - "/position/altitude = " << fgGetDouble("/position/altitude") ); + "/position/altitude = " << fgGetDouble("/position/altitude-ft") ); bool freeze = globals->get_freeze(); if( !freeze ) @@ -780,8 +852,8 @@ void fgReInitSubsystems( void ) if( global_tile_mgr.init() ) { // Load the local scenery data - global_tile_mgr.update( fgGetDouble("/position/longitude"), - fgGetDouble("/position/latitude") ); + global_tile_mgr.update( fgGetDouble("/position/longitude-deg"), + fgGetDouble("/position/latitude-deg") ); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" ); exit(-1); @@ -812,9 +884,14 @@ void fgReInitSubsystems( void ) cur_fdm_state->init(); - controls.reset_all(); + globals->get_controls()->reset_all(); current_autopilot->reset(); + fgUpdateSunPos(); + fgUpdateMoonPos(); + cur_light_params.Update(); + fgUpdateLocalTime(); + if( !freeze ) globals->set_freeze( false ); }