-// 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 {
- FG_LOG(FG_GENERAL, FG_ALERT,
- "Unrecognized value for /sim/startup/speed-set: " << speedset);
- current_aircraft.fdm_state->set_V_calibrated_kts(0.0);
- }
-}
-
-
+// Initialize the flight model subsystem. This just creates the
+// object. The actual fdm initialization is delayed until we get a
+// proper scenery elevation hit. This is checked for in main.cxx
+
+void fgInitFDM() {
+
+ if ( cur_fdm_state ) {
+ delete cur_fdm_state;
+ cur_fdm_state = 0;
+ }
+
+ double dt = 1.0 / fgGetInt("/sim/model-hz");
+ aircraft_dir = fgGetString("/sim/aircraft-dir");
+ const string &model = fgGetString("/sim/flight-model");
+
+ 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 == "ufo" ) {
+ cur_fdm_state = new FGUFO( dt );
+ } else if ( model == "external" ) {
+ cur_fdm_state = new FGExternal( dt );
+ } else if ( model.find("network") == 0 ) {
+ string host = "localhost";
+ int port1 = 5501;
+ int port2 = 5502;
+ int port3 = 5503;
+ string net_options = model.substr(8);
+ string::size_type begin, end;
+ begin = 0;
+ // host
+ end = net_options.find( ",", begin );
+ if ( end != string::npos ) {
+ host = net_options.substr(begin, end - begin);
+ begin = end + 1;
+ }
+ // port1
+ end = net_options.find( ",", begin );
+ if ( end != string::npos ) {
+ port1 = atoi( net_options.substr(begin, end - begin).c_str() );
+ begin = end + 1;
+ }
+ // port2
+ end = net_options.find( ",", begin );
+ if ( end != string::npos ) {
+ port2 = atoi( net_options.substr(begin, end - begin).c_str() );
+ begin = end + 1;
+ }
+ // port3
+ end = net_options.find( ",", begin );
+ if ( end != string::npos ) {
+ port3 = atoi( net_options.substr(begin, end - begin).c_str() );
+ begin = end + 1;
+ }
+ cur_fdm_state = new FGExternalNet( dt, host, port1, port2, port3 );
+ } else if ( model == "null" ) {
+ cur_fdm_state = new FGNullFDM( dt );
+ } else if ( model == "yasim" ) {
+ cur_fdm_state = new YASim( dt );
+ } else {
+ SG_LOG(SG_GENERAL, SG_ALERT,
+ "Unrecognized flight model '" << model
+ << "', cannot init flight dynamics model.");
+ exit(-1);
+ }
+ } catch ( ... ) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
+ exit(-1);
+ }
+}
+
+
+// Initialize view parameters
+void fgInitView() {
+ // force update of model so that viewer can get some data...
+ globals->get_aircraft_model()->update(0);
+ // run update for current view so that data is current...
+ globals->get_viewmgr()->update(0);
+}
+
+
+SGTime *fgInitTime() {
+ // Initialize time
+ static const SGPropertyNode *longitude
+ = fgGetNode("/position/longitude-deg");
+ static const SGPropertyNode *latitude
+ = fgGetNode("/position/latitude-deg");
+ static const SGPropertyNode *cur_time_override
+ = fgGetNode("/sim/time/cur-time-override", true);
+
+ SGPath zone( globals->get_fg_root() );
+ zone.append( "Timezone" );
+ SGTime *t = new SGTime( longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ zone.str(),
+ cur_time_override->getLongValue() );
+
+ // Handle potential user specified time offsets
+ time_t cur_time = t->get_cur_time();
+ time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
+ time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
+ time_t aircraftLocalTime =
+ sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
+
+ // Okay, we now have six possible scenarios
+ int offset = fgGetInt("/sim/startup/time-offset");
+ const string &offset_type = fgGetString("/sim/startup/time-offset-type");
+ if (offset_type == "system-offset") {
+ globals->set_warp( offset );
+ } else if (offset_type == "gmt-offset") {
+ globals->set_warp( offset - (currGMT - systemLocalTime) );
+ } else if (offset_type == "latitude-offset") {
+ globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
+ } else if (offset_type == "system") {
+ globals->set_warp( offset - cur_time );
+ } else if (offset_type == "gmt") {
+ globals->set_warp( offset - currGMT );
+ } else if (offset_type == "latitude") {
+ globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) -
+ cur_time );
+ } else {
+ SG_LOG( SG_GENERAL, SG_ALERT,
+ "FG_TIME::Unsupported offset type " << offset_type );
+ exit( -1 );
+ }
+
+ SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = "
+ << globals->get_warp() );
+
+ globals->set_warp_delta( 0 );
+
+ t->update( 0.0, 0.0,
+ cur_time_override->getLongValue(),
+ globals->get_warp() );
+
+ return t;
+}
+
+