-
-// 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");
- 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 );
-#if ENABLE_SP_FDM
- } else if ( model == "ada" ) {
- cur_fdm_state = new FGADA( dt );
- } else if ( model == "acms" ) {
- cur_fdm_state = new FGACMS( dt );
- } else if ( model == "balloon" ) {
- cur_fdm_state = new FGBalloonSim( dt );
- } else if ( model == "magic" ) {
- cur_fdm_state = new FGMagicCarpet( dt );
-#endif
- } else if ( model == "ufo" ) {
- cur_fdm_state = new FGUFO( dt );
- } else if ( model == "external" ) {
- // external is a synonym for "--fdm=null" and is
- // maintained here for backwards compatibility
- cur_fdm_state = new FGNullFDM( 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.find("pipe") == 0 ) {
- // /* old */ string pipe_path = model.substr(5);
- // /* old */ cur_fdm_state = new FGExternalPipe( dt, pipe_path );
- string pipe_path = "";
- string pipe_protocol = "";
- string pipe_options = model.substr(5);
- string::size_type begin, end;
- begin = 0;
- // pipe file path
- end = pipe_options.find( ",", begin );
- if ( end != string::npos ) {
- pipe_path = pipe_options.substr(begin, end - begin);
- begin = end + 1;
- }
- // protocol (last option)
- pipe_protocol = pipe_options.substr(begin);
- cur_fdm_state = new FGExternalPipe( dt, pipe_path, pipe_protocol );
- } else if ( model == "null" ) {
- cur_fdm_state = new FGNullFDM( dt );
- } else if ( model == "yasim" ) {
- cur_fdm_state = new YASim( dt );
- } else {
- throw sg_exception(string("Unrecognized flight model '") + model
- + "', cannot init flight dynamics model.");
- }
-}
-
-// 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() );
-
- globals->set_warp_delta( 0 );
-
- t->update( 0.0, 0.0,
- cur_time_override->getLongValue(),
- globals->get_warp() );
-
- return t;
-}
-
-
-// set up a time offset (aka warp) if one is specified
-void fgInitTimeOffset() {
- 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);
-
- // Handle potential user specified time offsets
- int orig_warp = globals->get_warp();
- SGTime *t = globals->get_time_params();
- 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 several possible scenarios
- int offset = fgGetInt("/sim/startup/time-offset");
- string offset_type = fgGetString("/sim/startup/time-offset-type");
-
- int warp = 0;
- if ( offset_type == "real" ) {
- warp = 0;
- } else if ( offset_type == "dawn" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 90.0, true );
- } else if ( offset_type == "morning" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 75.0, true );
- } else if ( offset_type == "noon" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 0.0, true );
- } else if ( offset_type == "afternoon" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 60.0, false );
- } else if ( offset_type == "dusk" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 90.0, false );
- } else if ( offset_type == "evening" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 100.0, false );
- } else if ( offset_type == "midnight" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time,
- longitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue()
- * SGD_DEGREES_TO_RADIANS,
- 180.0, false );
- } else if ( offset_type == "system-offset" ) {
- warp = offset;
- orig_warp = 0;
- } else if ( offset_type == "gmt-offset" ) {
- warp = offset - (currGMT - systemLocalTime);
- orig_warp = 0;
- } else if ( offset_type == "latitude-offset" ) {
- warp = offset - (aircraftLocalTime - systemLocalTime);
- orig_warp = 0;
- } else if ( offset_type == "system" ) {
- warp = offset - (systemLocalTime - currGMT) - cur_time;
- } else if ( offset_type == "gmt" ) {
- warp = offset - cur_time;
- } else if ( offset_type == "latitude" ) {
- warp = offset - (aircraftLocalTime - currGMT)- cur_time;
- } else {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "FG_TIME::Unsupported offset type " << offset_type );
- exit( -1 );
- }
- globals->set_warp( orig_warp + warp );
- t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
- latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
- cur_time_override->getLongValue(),
- globals->get_warp() );
-
- SG_LOG( SG_GENERAL, SG_INFO, "After fgInitTimeOffset(): warp = "
- << globals->get_warp() );
-}
-
-