#endif
#include <GL/glut.h>
-#include <XGL/xgl.h>
+#include <simgear/xgl.h>
#include <stdio.h>
#include <stdlib.h>
# define _G_NO_EXTERN_TEMPLATES
#endif
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
#include STL_STRING
-#include <Debug/logstream.hxx>
+#include <simgear/logstream.hxx>
+#include <simgear/constants.h>
+#include <simgear/fg_geodesy.hxx>
+#include <simgear/point3d.hxx>
+#include <simgear/polar3d.hxx>
+#include <simgear/fgpath.hxx>
+
#include <Aircraft/aircraft.hxx>
#include <Airports/simple.hxx>
#include <Astro/sky.hxx>
#include <Astro/solarsystem.hxx>
#include <Autopilot/autopilot.hxx>
#include <Cockpit/cockpit.hxx>
-#include <Include/fg_constants.h>
+#include <FDM/Balloon.h>
+#include <FDM/External.hxx>
+#include <FDM/JSBsim.hxx>
+#include <FDM/LaRCsim.hxx>
+#include <FDM/MagicCarpet.hxx>
#include <Include/general.hxx>
#include <Joystick/joystick.hxx>
-#include <Math/fg_geodesy.hxx>
-#include <Math/point3d.hxx>
-#include <Math/polar3d.hxx>
-#include <Misc/fgpath.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
#include <Time/event.hxx>
#include <Time/light.hxx>
#include <Time/sunpos.hxx>
#include <Time/moonpos.hxx>
-// #include <Weather/weather.hxx>
-#include <WeatherCM/FGLocalWeatherDatabase.h>
+
+#ifndef FG_OLD_WEATHER
+# include <WeatherCM/FGLocalWeatherDatabase.h>
+#else
+# include <Weather/weather.hxx>
+#endif
#include "fg_init.hxx"
+#include "fg_io.hxx"
#include "options.hxx"
#include "views.hxx"
-#include "fg_serial.hxx"
#if defined(FX) && defined(XMESA)
#include <GL/xmesa.h>
return false;
}
- return true;
+ return true;
}
// General house keeping initializations
bool fgInitGeneral( void ) {
string root;
+
+#if defined(FX) && defined(XMESA)
char *mesa_win_state;
+#endif
FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
<< "being defined." );
exit(-1);
}
- FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << root << endl );
+ FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
#if defined(FX) && defined(XMESA)
// initialize full screen flag
bool fgInitSubsystems( void ) {
FGTime::cur_time_params = new FGTime();
- FGInterface *f; // assigned later
fgLIGHT *l = &cur_light_params;
FGTime *t = FGTime::cur_time_params;
- FGView *v = ¤t_view;
FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
+ if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
+ cur_fdm_state = new FGLaRCsim;
+ } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
+ cur_fdm_state = new FGJSBsim;
+ } else if ( current_options.get_flight_model() ==
+ FGInterface::FG_BALLOONSIM ) {
+ cur_fdm_state = new FGBalloonSim;
+ } else if ( current_options.get_flight_model() ==
+ FGInterface::FG_MAGICCARPET ) {
+ cur_fdm_state = new FGMagicCarpet;
+ } else if ( current_options.get_flight_model() ==
+ FGInterface::FG_EXTERNAL ) {
+ cur_fdm_state = new FGExternal;
+ } else {
+ FG_LOG( FG_GENERAL, FG_ALERT,
+ "No flight model, can't init aircraft" );
+ exit(-1);
+ }
+
// 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.
- f = current_aircraft.fdm_state;
// set the initial position
fgInitPosition();
// now handled inside of the fgTileMgrUpdate()
/*
- geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
+ geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
tmp_abs_view_pos = fgGeodToCart(geod_pos);
FG_LOG( FG_GENERAL, FG_DEBUG,
"Initial abs_view_pos = " << tmp_abs_view_pos );
scenery.cur_elev =
- fgTileMgrCurElev( f->get_Longitude(), f->get_Latitude(),
+ fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
tmp_abs_view_pos );
FG_LOG( FG_GENERAL, FG_DEBUG,
"Altitude after update " << scenery.cur_elev );
scenery.cur_elev );
// Reset our altitude if we are below ground
- FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << f->get_Altitude() );
+ FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
- f->get_Runway_altitude() );
+ cur_fdm_state->get_Runway_altitude() );
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ 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 );
}
FG_LOG( FG_GENERAL, FG_INFO,
"Updated position (after elevation adj): ("
- << (f->get_Latitude() * RAD_TO_DEG) << ", "
- << (f->get_Longitude() * RAD_TO_DEG) << ", "
- << (f->get_Altitude() * FEET_TO_METER) << ")" );
+ << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
// We need to calculate a few more values here that would normally
- // be calculated by the FDM so that the v->UpdateViewMath()
+ // be calculated by the FDM so that the current_view.UpdateViewMath()
// routine doesn't get hosed.
double sea_level_radius_meters;
double lat_geoc;
// Set the FG variables first
- fgGeodToGeoc( f->get_Latitude(), f->get_Altitude(),
+ fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
&sea_level_radius_meters, &lat_geoc);
- f->set_Geocentric_Position( lat_geoc, f->get_Longitude(),
- f->get_Altitude() +
+ cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
+ cur_fdm_state->get_Altitude() +
(sea_level_radius_meters * METER_TO_FEET) );
- f->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
+ cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
- f->set_sin_cos_longitude(f->get_Longitude());
- f->set_sin_cos_latitude(f->get_Latitude());
+ cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
+ cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
- f->set_sin_lat_geocentric(sin(lat_geoc));
- f->set_cos_lat_geocentric(cos(lat_geoc));
+ cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
+ cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
// The following section sets up the flight model EOM parameters
// and should really be read in from one or more files.
// Initial Velocity
- f->set_Velocities_Local( current_options.get_uBody(),
+ cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
current_options.get_vBody(),
current_options.get_wBody());
// Initial Orientation
- f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
+ cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
current_options.get_pitch() * DEG_TO_RAD,
current_options.get_heading() * DEG_TO_RAD );
// Initial Angular Body rates
- f->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
+ cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
- f->set_Earth_position_angle( 0.0 );
+ cur_fdm_state->set_Earth_position_angle( 0.0 );
// Mass properties and geometry values
- f->set_Inertias( 8.547270E+01,
+ cur_fdm_state->set_Inertias( 8.547270E+01,
1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
// CG position w.r.t. ref. point
- f->set_CG_Position( 0.0, 0.0, 0.0 );
+ cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
// Initialize the event manager
global_events.Init();
fgEVENT::FG_EVENT_READY, 60000 );
// Initialize the time dependent variables
- t->init();
- t->update(f);
+ t->init(*cur_fdm_state);
+ t->update(*cur_fdm_state);
// Initialize view parameters
- FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
- v->Init();
- FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
- v->UpdateViewMath(f);
- FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << v->get_abs_view_pos());
- // v->UpdateWorldToEye(f);
+ FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
+ current_view.Init();
+ pilot_view.Init();
+ FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
+ current_view.UpdateViewMath(*cur_fdm_state);
+ pilot_view.UpdateViewMath(*cur_fdm_state);
+ FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
+ // current_view.UpdateWorldToEye(f);
// Build the solar system
//fgSolarSystemInit(*t);
fgMethodCallback<fgLIGHT>( &cur_light_params,
&fgLIGHT::Update),
fgEVENT::FG_EVENT_READY, 30000 );
+ // update the current timezone each 30 minutes
+ global_events.Register( "fgTIME::updateLocal()",
+ fgMethodCallback<FGTime>(FGTime::cur_time_params,
+ &FGTime::updateLocal),
+ fgEVENT::FG_EVENT_READY, 1800000);
// Initialize the weather modeling subsystem
- // current_weather.Init();
+#ifndef FG_OLD_WEATHER
// Initialize the WeatherDatabase
FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
+ sgVec3 position;
+ sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
+ current_aircraft.fdm_state->get_Longitude(),
+ current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
- new FGLocalWeatherDatabase(
- Point3D( current_aircraft.fdm_state->get_Latitude(),
- current_aircraft.fdm_state->get_Longitude(),
- current_aircraft.fdm_state->get_Altitude()
- * FEET_TO_METER) );
+ new FGLocalWeatherDatabase( position );
+ // cout << theFGLocalWeatherDatabase << endl;
+ // cout << "visibility = "
+ // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
-
+
// register the periodic update of the weather
global_events.Register( "weather update", fgUpdateWeatherDatabase,
- fgEVENT::FG_EVENT_READY, 30000);
+ fgEVENT::FG_EVENT_READY, 30000);
+#else
+ current_weather.Init();
+#endif
// Initialize the Cockpit subsystem
if( fgCockpitInit( ¤t_aircraft )) {
// Initialize the flight model subsystem data structures base on
// above values
- fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
- 1.0 / DEFAULT_MODEL_HZ );
+ // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
+ // 1.0 / current_options.get_model_hz() );
+ cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
// I'm just sticking this here for now, it should probably move
// eventually
- scenery.cur_elev = f->get_Runway_altitude() * FEET_TO_METER;
+ scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ 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 );
}
FG_LOG( FG_GENERAL, FG_INFO,
"Updated position (after elevation adj): ("
- << (f->get_Latitude() * RAD_TO_DEG) << ", "
- << (f->get_Longitude() * RAD_TO_DEG) << ", "
- << (f->get_Altitude() * FEET_TO_METER) << ")" );
+ << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
+ << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
// end of thing that I just stuck in that I should probably move
// Joystick support
// Autopilot init added here, by Jeff Goeke-Smith
fgAPInit(¤t_aircraft);
- // Initialize serial ports
+ // Initialize I/O channels
#if ! defined( MACOS )
- fgSerialInit();
+ fgIOInit();
#endif
FG_LOG( FG_GENERAL, FG_INFO, endl);
void fgReInitSubsystems( void )
{
- FGInterface *f = current_aircraft.fdm_state;
- FGView *v = ¤t_view;
FGTime *t = FGTime::cur_time_params;
int toggle_pause = t->getPause();
scenery.cur_elev );
// Reset our altitude if we are below ground
- FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << f->get_Altitude() );
+ FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
- f->get_Runway_altitude() );
+ cur_fdm_state->get_Runway_altitude() );
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ 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;
// Set the FG variables first
- fgGeodToGeoc( f->get_Latitude(), f->get_Altitude(),
+ fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
&sea_level_radius_meters, &lat_geoc);
- f->set_Geocentric_Position( lat_geoc, f->get_Longitude(),
- f->get_Altitude() +
+ cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
+ cur_fdm_state->get_Altitude() +
(sea_level_radius_meters * METER_TO_FEET) );
- f->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
+ cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
- f->set_sin_cos_longitude(f->get_Longitude());
- f->set_sin_cos_latitude(f->get_Latitude());
+ cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
+ cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
- f->set_sin_lat_geocentric(sin(lat_geoc));
- f->set_cos_lat_geocentric(cos(lat_geoc));
+ cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
+ cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
// The following section sets up the flight model EOM parameters
// and should really be read in from one or more files.
// Initial Velocity
- f->set_Velocities_Local( current_options.get_uBody(),
+ cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
current_options.get_vBody(),
current_options.get_wBody());
// Initial Orientation
- f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
+ cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
current_options.get_pitch() * DEG_TO_RAD,
current_options.get_heading() * DEG_TO_RAD );
// Initial Angular Body rates
- f->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
+ cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
- f->set_Earth_position_angle( 0.0 );
+ cur_fdm_state->set_Earth_position_angle( 0.0 );
// Mass properties and geometry values
- f->set_Inertias( 8.547270E+01,
+ cur_fdm_state->set_Inertias( 8.547270E+01,
1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
// CG position w.r.t. ref. point
- f->set_CG_Position( 0.0, 0.0, 0.0 );
+ cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
// Initialize view parameters
- FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
- v->Init();
- FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
- v->UpdateViewMath(f);
- FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << v->get_abs_view_pos());
- // v->UpdateWorldToEye(f);
+ current_view.set_view_offset( 0.0 );
+ current_view.set_goal_view_offset( 0.0 );
+ pilot_view.set_view_offset( 0.0 );
+ pilot_view.set_goal_view_offset( 0.0 );
+
+ FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
+ current_view.UpdateViewMath(*cur_fdm_state);
+ pilot_view.UpdateViewMath(*cur_fdm_state);
+ FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
- fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
- 1.0 / DEFAULT_MODEL_HZ );
+ // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
+ // 1.0 / current_options.get_model_hz() );
+ cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
- scenery.cur_elev = f->get_Runway_altitude() * FEET_TO_METER;
+ scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
- if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
- f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
+ 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();