# include <math.h>
#endif
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
#include <GL/glut.h>
-#include <simgear/xgl/xgl.h>
#include <stdio.h>
#include <stdlib.h>
#include <FDM/LaRCsim.hxx>
#include <FDM/MagicCarpet.hxx>
#include <Include/general.hxx>
-#include <Joystick/joystick.hxx>
+#include <Input/input.hxx>
+// #include <Joystick/joystick.hxx>
#include <Objects/matlib.hxx>
#include <Navaids/fixlist.hxx>
#include <Navaids/ilslist.hxx>
#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"
#if defined(FX) && defined(XMESA)
#include <GL/xmesa.h>
// 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 = "";
}
+// 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 ) {
"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 << ", "
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 ("
}
-// Set initial position and orientation
-bool fgInitPosition( void ) {
- FGInterface *f = current_aircraft.fdm_state;
- string id = fgGetString("/sim/startup/airport-id");
-
- // set initial position from default or command line coordinates
- f->set_Longitude( fgGetDouble("/position/longitude") * SGD_DEGREES_TO_RADIANS );
- f->set_Latitude( fgGetDouble("/position/latitude") * SGD_DEGREES_TO_RADIANS );
-
- SG_LOG( SG_GENERAL, SG_INFO,
- "scenery.cur_elev = " << scenery.cur_elev );
- SG_LOG( SG_GENERAL, SG_INFO,
- "/position/altitude = " << fgGetDouble("/position/altitude") );
-
- // if we requested on ground startups
- if ( fgGetBool( "/sim/startup/onground" ) ) {
- fgSetDouble( "/position/altitude", (scenery.cur_elev + 1)
- * METERS_TO_FEET );
- }
-
- // if requested altitude is below ground level
- if ( fgGetDouble( "/position/altitude" ) < (scenery.cur_elev + 1)
- * METERS_TO_FEET ) {
- fgSetDouble( "/position/altitude",
- (scenery.cur_elev + 1) * METERS_TO_FEET );
- }
-
- SG_LOG( SG_GENERAL, SG_INFO,
- "starting altitude is = " <<
- fgGetDouble("/position/altitude") );
-
- f->set_Altitude( fgGetDouble("/position/altitude") );
- SG_LOG( SG_GENERAL, SG_INFO,
- "Initial position is: ("
- << (f->get_Longitude() * SGD_RADIANS_TO_DEGREES) << ", "
- << (f->get_Latitude() * SGD_RADIANS_TO_DEGREES) << ", "
- << (f->get_Altitude() * SG_FEET_TO_METER) << ")" );
-
- return true;
-}
-
-
// General house keeping initializations
bool fgInitGeneral( void ) {
string root;
}
-// set initial aircraft speed
-void
-fgVelocityInit( void )
-{
- if (!fgHasValue("/sim/startup/speed-set")) {
- current_aircraft.fdm_state->set_V_calibrated_kts(0.0);
- return;
- }
-
- const string speedset = fgGetString("/sim/startup/speed-set");
- if (speedset == "knots" || speedset == "KNOTS") {
- current_aircraft.fdm_state
- ->set_V_calibrated_kts(fgGetDouble("/velocities/airspeed"));
- } else if (speedset == "mach" || speedset == "MACH") {
- current_aircraft.fdm_state
- ->set_Mach_number(fgGetDouble("/velocities/mach"));
- } else if (speedset == "UVW" || speedset == "uvw") {
- current_aircraft.fdm_state
- ->set_Velocities_Wind_Body(fgGetDouble("/velocities/uBody"),
- fgGetDouble("/velocities/vBody"),
- fgGetDouble("/velocities/wBody"));
- } else if (speedset == "NED" || speedset == "ned") {
- current_aircraft.fdm_state
- ->set_Velocities_Local(fgGetDouble("/velocities/speed-north"),
- fgGetDouble("/velocities/speed-east"),
- fgGetDouble("/velocities/speed-down"));
- } else {
- SG_LOG(SG_GENERAL, SG_ALERT,
- "Unrecognized value for /sim/startup/speed-set: " << speedset);
- current_aircraft.fdm_state->set_V_calibrated_kts(0.0);
- }
-}
-
-
// This is the top level init routine which calls all the other
// initialization routines. If you are adding a subsystem to flight
// gear, its initialization call should located in this routine.
SG_LOG( SG_GENERAL, SG_INFO, "Initialize Subsystems");
SG_LOG( SG_GENERAL, SG_INFO, "========== ==========");
- // Initialize the material property lib
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the material property subsystem.
+ ////////////////////////////////////////////////////////////////////
+
SGPath mpath( globals->get_fg_root() );
mpath.append( "materials" );
if ( material_lib.load( mpath.str() ) ) {
exit(-1);
}
- // Initialize the Scenery Management subsystem
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the scenery management subsystem.
+ ////////////////////////////////////////////////////////////////////
+
if ( fgSceneryInit() ) {
// Material lib initialized ok.
} else {
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);
"Current terrain elevation after tile mgr init " <<
scenery.cur_elev );
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the flight model subsystem.
+ ////////////////////////////////////////////////////////////////////
+
double dt = 1.0 / fgGetInt("/sim/model-hz");
// cout << "dt = " << dt << endl;
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->stamp();
- cur_fdm_state->set_remainder( 0 );
+ cur_fdm_state->init();
+ cur_fdm_state->bind();
+
// allocates structures so must happen before any of the flight
// model or control parameters are set
fgAircraftInit(); // In the future this might not be the case.
- fgFDMSetGroundElevation( fgGetString("/sim/flight-model"),
- scenery.cur_elev );
-
- // set the initial position
- fgInitPosition();
-
- // Calculate ground elevation at starting point (we didn't have
- // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
- //
- // calculalate a cartesian point somewhere along the line between
- // the center of the earth and our view position. Doesn't have to
- // be the exact elevation (this is good because we don't know it
- // yet :-)
-
- // now handled inside of the fgTileMgrUpdate()
-
- // Reset our altitude if we are below ground
- SG_LOG( SG_GENERAL, SG_DEBUG, "Current altitude = "
- << cur_fdm_state->get_Altitude() );
- SG_LOG( SG_GENERAL, SG_DEBUG, "Current runway altitude = " <<
- cur_fdm_state->get_Runway_altitude() );
-
- if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() +
- 3.758099) {
- cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
- 3.758099 );
- }
- SG_LOG( SG_GENERAL, SG_INFO,
- "Updated position (after elevation adj): ("
- << (cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES) << ", "
- << (cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES) << ", "
- << (cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) << ")" );
-
- // We need to calculate a few sea_level_radius here so we can pass
- // the correct value to the view class
- double sea_level_radius_meters;
- double lat_geoc;
- sgGeodToGeoc( cur_fdm_state->get_Latitude(),
- cur_fdm_state->get_Altitude(),
- &sea_level_radius_meters, &lat_geoc);
- cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters *
- SG_METER_TO_FEET );
-
- // The following section sets up the flight model EOM parameters
- // and should really be read in from one or more files.
-
- // Initial Velocity
- fgVelocityInit();
-
- // Initial Orientation
-// cur_fdm_state->
-// set_Euler_Angles( fgGetDouble("/orientation/roll") * SGD_DEGREES_TO_RADIANS,
-// fgGetDouble("/orientation/pitch") * SGD_DEGREES_TO_RADIANS,
-// fgGetDouble("/orientation/heading") * SGD_DEGREES_TO_RADIANS );
-
- // Initialize the event manager
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the event manager subsystem.
+ ////////////////////////////////////////////////////////////////////
+
global_events.Init();
// Output event stats every 60 seconds
&fgEVENT_MGR::PrintStats),
fgEVENT::FG_EVENT_READY, 60000 );
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the view manager subsystem.
+ ////////////////////////////////////////////////////////////////////
+
// Initialize win_ratio parameters
for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
globals->get_viewmgr()->get_view(i)->
SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
<< globals->get_current_view()->get_abs_view_pos());
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the lighting subsystem.
+ ////////////////////////////////////////////////////////////////////
+
// fgUpdateSunPos() needs a few position and view parameters set
// so it can calculate local relative sun angle and a few other
// things for correctly orienting the sky.
fgMethodCallback<fgLIGHT>( &cur_light_params,
&fgLIGHT::Update),
fgEVENT::FG_EVENT_READY, 30000 );
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the local time subsystem.
+ ////////////////////////////////////////////////////////////////////
+
// update the current timezone each 30 minutes
global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
fgEVENT::FG_EVENT_READY, 1800000);
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the weather subsystem.
+ ////////////////////////////////////////////////////////////////////
+
// Initialize the weather modeling subsystem
#ifndef FG_OLD_WEATHER
// Initialize the WeatherDatabase
WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
- double init_vis = fgGetDouble("/environment/visibility");
+ double init_vis = fgGetDouble("/environment/visibility-m");
if ( init_vis > 0 ) {
WeatherDatabase->setWeatherVisibility( init_vis );
}
current_weather.Init();
#endif
+ ////////////////////////////////////////////////////////////////////
// Initialize vor/ndb/ils/fix list management and query systems
+ ////////////////////////////////////////////////////////////////////
+
SG_LOG(SG_GENERAL, SG_INFO, "Loading Navaids");
SG_LOG(SG_GENERAL, SG_INFO, " VOR/NDB");
p_fix.append( "Navaids/default.fix" );
current_fixlist->init( p_fix );
- // Radio stack subsystem.
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the built-in commands.
+ ////////////////////////////////////////////////////////////////////
+ fgInitCommands();
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the radio stack subsystem.
+ ////////////////////////////////////////////////////////////////////
+
+ // A textbook example of how FGSubsystem
+ // should work...
current_radiostack = new FGRadioStack;
current_radiostack->init();
current_radiostack->bind();
- // Initialize the Cockpit subsystem
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the cockpit subsystem
+ ////////////////////////////////////////////////////////////////////
+
if( fgCockpitInit( ¤t_aircraft )) {
// Cockpit initialized ok.
} else {
exit(-1);
}
- // Initialize the flight model subsystem data structures base on
- // above values
- cur_fdm_state->init();
- cur_fdm_state->bind();
-// if ( cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") ) ) {
-// // fdm init successful
-// } else {
-// SG_LOG( SG_GENERAL, SG_ALERT, "FDM init() failed! Cannot continue." );
-// exit(-1);
-// }
-
- // *ABCD* I'm just sticking this here for now, it should probably
- // move eventually
- scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
-
- if ( cur_fdm_state->get_Altitude() <
- cur_fdm_state->get_Runway_altitude() + 3.758099)
- {
- cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
- 3.758099 );
- }
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the joystick subsystem.
+ ////////////////////////////////////////////////////////////////////
- SG_LOG( SG_GENERAL, SG_INFO,
- "Updated position (after elevation adj): ("
- << (cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES) << ", "
- << (cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES) << ", "
- << (cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) << ")" );
- // *ABCD* end of thing that I just stuck in that I should probably
- // move
-
- // Joystick support
- if ( ! fgJoystickInit() ) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
- }
+ // if ( ! fgJoystickInit() ) {
+ // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Joystick initialization!" );
+ // }
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the autopilot subsystem.
+ ////////////////////////////////////////////////////////////////////
- // Autopilot init
current_autopilot = new FGAutopilot;
current_autopilot->init();
NewHeadingInit();
NewAltitudeInit();
- // Initialize I/O channels
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize I/O subsystem.
+ ////////////////////////////////////////////////////////////////////
+
#if ! defined( macintosh )
fgIOInit();
#endif
current_panel->bind();
}
- // Initialize the BFI
- FGBFI::init();
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the default (kludged) properties.
+ ////////////////////////////////////////////////////////////////////
+
+ fgInitProps();
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the controls subsystem.
+ ////////////////////////////////////////////////////////////////////
controls.init();
controls.bind();
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize the input subsystem.
+ ////////////////////////////////////////////////////////////////////
+
+ current_input.init();
+ current_input.bind();
+
+
+ ////////////////////////////////////////////////////////////////////////
+ // End of subsystem initialization.
+ ////////////////////////////////////////////////////////////////////
+
SG_LOG( SG_GENERAL, SG_INFO, endl);
// Save the initial state for future
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 )
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);
}
- // cout << "current scenery elev = " << scenery.cur_elev << endl;
-
- fgFDMSetGroundElevation( fgGetString("/sim/flight-model"),
- scenery.cur_elev );
- fgInitPosition();
-
- // Reset our altitude if we are below ground
- SG_LOG( SG_GENERAL, SG_DEBUG, "Current altitude = "
- << cur_fdm_state->get_Altitude() );
- SG_LOG( SG_GENERAL, SG_DEBUG, "Current runway altitude = "
- << cur_fdm_state->get_Runway_altitude() );
-
- if ( cur_fdm_state->get_Altitude() <
- cur_fdm_state->get_Runway_altitude() + 3.758099)
- {
- cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
- 3.758099 );
- }
- double sea_level_radius_meters;
- double lat_geoc;
- sgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
- &sea_level_radius_meters, &lat_geoc);
- cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters *
- SG_METER_TO_FEET );
-
- // The following section sets up the flight model EOM parameters
- // and should really be read in from one or more files.
-
- // Initial Velocity
- fgVelocityInit();
-
- // Initial Orientation
-// cur_fdm_state->
-// set_Euler_Angles( fgGetDouble("/orientation/roll") * SGD_DEGREES_TO_RADIANS,
-// fgGetDouble("/orientation/pitch") * SGD_DEGREES_TO_RADIANS,
-// fgGetDouble("/orientation/heading") * SGD_DEGREES_TO_RADIANS );
-
// Initialize view parameters
FGViewerRPH *pilot_view =
(FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
<< globals->get_current_view()->get_abs_view_pos());
cur_fdm_state->init();
-// cur_fdm_state->bind();
-// cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
-
- scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER;
-
- if ( cur_fdm_state->get_Altitude() <
- cur_fdm_state->get_Runway_altitude() + 3.758099)
- {
- cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
- 3.758099 );
- }
controls.reset_all();
current_autopilot->reset();
+ fgUpdateSunPos();
+ fgUpdateMoonPos();
+ cur_light_params.Update();
+ fgUpdateLocalTime();
+
if( !freeze )
globals->set_freeze( false );
}