From: david Date: Sat, 11 May 2002 16:28:50 +0000 (+0000) Subject: Major overhaul: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5a849b66e855a643c600ad4cfcce1f82e0fcdeb3;p=flightgear.git Major overhaul: - changed FGSubsystem::update(int) to FGSubsystem::update(delta_time_sec); the argument is now delta time in seconds rather than milliseconds - added FGSubsystem::suspend(), FGSubsystem::suspend(bool), FGSubsystem::resume(), and FGSubsystem::is_suspended(), all with default implementations; is_suspended takes account of the master freeze as well as the subsystem's individual suspended state - the FDMs now use the delta time argument the same as the rest of FlightGear; formerly, main.cxx made a special case and passed a multiloop argument - FDMs now calculate multiloop internally instead of relying on main.cxx There are probably some problems -- I've done basic testing with the major FDMs and subsystems, but we'll probably need a few weeks to sniff out bugs. --- diff --git a/src/ATC/ATCdisplay.cxx b/src/ATC/ATCdisplay.cxx index 0bfce155d..287b845b3 100644 --- a/src/ATC/ATCdisplay.cxx +++ b/src/ATC/ATCdisplay.cxx @@ -54,7 +54,7 @@ void FGATCDisplay::unbind() { } // update - this actually draws the visuals and should be called from the main Flightgear rendering loop. -void FGATCDisplay::update(int dt) { +void FGATCDisplay::update(double dt) { // These strings are used for temporary storage of the transmission string in order // that the string we view only changes when the next repetition starts scrolling diff --git a/src/ATC/ATCdisplay.hxx b/src/ATC/ATCdisplay.hxx index 9c2c9805f..c17d36c06 100644 --- a/src/ATC/ATCdisplay.hxx +++ b/src/ATC/ATCdisplay.hxx @@ -71,7 +71,7 @@ public: void unbind(); // Display any registered messages - void update(int dt); + void update(double dt); // Register a single message for display after a delay of delay seconds // Will automatically stop displaying after a suitable interval. diff --git a/src/ATC/ATCmgr.cxx b/src/ATC/ATCmgr.cxx index 5a7e1b8ea..eb6441de8 100644 --- a/src/ATC/ATCmgr.cxx +++ b/src/ATC/ATCmgr.cxx @@ -88,7 +88,7 @@ void FGATCMgr::init() { airport_atc_map[(string)"KEMT"] = a; } -void FGATCMgr::update(int dt) { +void FGATCMgr::update(double dt) { //Traverse the list of active stations. //Only update one class per update step to avoid the whole ATC system having to calculate between frames. //Eventually we should only update every so many steps. diff --git a/src/ATC/ATCmgr.hxx b/src/ATC/ATCmgr.hxx index 03ac392e6..30e06294f 100644 --- a/src/ATC/ATCmgr.hxx +++ b/src/ATC/ATCmgr.hxx @@ -154,7 +154,7 @@ public: void unbind(); - void update(int dt); + void update(double dt); // Returns true if the airport is found in the map bool GetAirportATCDetails(string icao, AirportATC* a); diff --git a/src/Autopilot/newauto.cxx b/src/Autopilot/newauto.cxx index a2d188a6a..7e12850c0 100644 --- a/src/Autopilot/newauto.cxx +++ b/src/Autopilot/newauto.cxx @@ -421,7 +421,7 @@ static double LinearExtrapolate( double x, double x1, double y1, double x2, doub void -FGAutopilot::update (int dt) +FGAutopilot::update (double dt) { // Remove the following lines when the calling funcitons start // passing in the data pointer diff --git a/src/Autopilot/newauto.hxx b/src/Autopilot/newauto.hxx index 2c1124d12..c16125e03 100644 --- a/src/Autopilot/newauto.hxx +++ b/src/Autopilot/newauto.hxx @@ -152,7 +152,7 @@ public: void init (); void bind (); void unbind (); - void update (int dt); + void update (double dt); // Reset the autopilot system void reset(void); diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index 6e78219c8..bee42a477 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -269,7 +269,7 @@ FGPanel::unbind () * Update the panel. */ void -FGPanel::update (int dt) +FGPanel::update (double dt) { // TODO: cache the nodes _visibility = fgGetBool("/sim/panel/visibility"); diff --git a/src/Cockpit/panel.hxx b/src/Cockpit/panel.hxx index 70fb1a122..c17b89735 100644 --- a/src/Cockpit/panel.hxx +++ b/src/Cockpit/panel.hxx @@ -141,7 +141,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); virtual void update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh); // transfer pointer ownership!!! diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index 62669ae93..3215f0096 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -143,7 +143,7 @@ FGRadioStack::init () blink.stamp(); search(); - update(1); // FIXME: use dt + update(0); // FIXME: use dt // Search radio database once per second global_events.Register( "fgRadioSearch()", @@ -404,7 +404,7 @@ double FGRadioStack::adjustILSRange( double stationElev, double aircraftElev, // Update the various nav values based on position and valid tuned in navs void -FGRadioStack::update(int dt) +FGRadioStack::update(double dt) { double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; diff --git a/src/Cockpit/radiostack.hxx b/src/Cockpit/radiostack.hxx index 331d97c8d..9b5f136e8 100644 --- a/src/Cockpit/radiostack.hxx +++ b/src/Cockpit/radiostack.hxx @@ -212,7 +212,7 @@ public: void init (); void bind (); void unbind (); - void update (int dt); + void update (double dt); // Update nav/adf radios based on current postition void search (); diff --git a/src/Cockpit/steam.cxx b/src/Cockpit/steam.cxx index cd78bf303..22ed726b3 100644 --- a/src/Cockpit/steam.cxx +++ b/src/Cockpit/steam.cxx @@ -98,8 +98,9 @@ int FGSteam::_UpdatesPending = 1000000; /* Forces filter to reset */ // FIXME: no need to use static // functions any longer. -void FGSteam::update ( int timesteps ) +void FGSteam::update (double dt) { + int timesteps = int(dt * 1000); if (!isTied) { isTied = true; fgTie("/steam/airspeed-kt", FGSteam::get_ASI_kias); diff --git a/src/Cockpit/steam.hxx b/src/Cockpit/steam.hxx index 862433ffa..cb3e0c5a3 100644 --- a/src/Cockpit/steam.hxx +++ b/src/Cockpit/steam.hxx @@ -53,7 +53,7 @@ class FGSteam { public: - static void update ( int timesteps ); + static void update ( double dt ); // Position static double get_ALT_ft (); diff --git a/src/Controls/controls.cxx b/src/Controls/controls.cxx index a3fc7df78..8c2ab5066 100644 --- a/src/Controls/controls.cxx +++ b/src/Controls/controls.cxx @@ -206,7 +206,7 @@ FGControls::unbind () void -FGControls::update (int dt) +FGControls::update (double dt) { } diff --git a/src/Controls/controls.hxx b/src/Controls/controls.hxx index 208ad8c36..e865a5975 100644 --- a/src/Controls/controls.hxx +++ b/src/Controls/controls.hxx @@ -83,7 +83,7 @@ public: void init (); void bind (); void unbind (); - void update (int dt); + void update (double dt); // Reset function void reset_all(void); diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index 0d57267f6..ae28932b7 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -116,7 +116,7 @@ FGUserDefEnvironmentCtrl::init () } void -FGUserDefEnvironmentCtrl::update (int dt) +FGUserDefEnvironmentCtrl::update (double dt) { double base_wind_speed = _base_wind_speed_node->getDoubleValue(); double gust_wind_speed = _gust_wind_speed_node->getDoubleValue(); diff --git a/src/Environment/environment_ctrl.hxx b/src/Environment/environment_ctrl.hxx index d50dba79e..17ed581d7 100644 --- a/src/Environment/environment_ctrl.hxx +++ b/src/Environment/environment_ctrl.hxx @@ -62,7 +62,7 @@ public: virtual double getElevationFt () const { return _elev_ft; } virtual void init () = 0; - virtual void update (int dt) = 0; + virtual void update (double dt) = 0; protected: @@ -85,7 +85,7 @@ public: virtual ~FGUserDefEnvironmentCtrl (); virtual void init (); - virtual void update (int dt); + virtual void update (double dt); private: diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index 4f3388954..8a4e8d495 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -95,7 +95,7 @@ FGEnvironmentMgr::unbind () } void -FGEnvironmentMgr::update (int dt) +FGEnvironmentMgr::update (double dt) { _controller->update(dt); // FIXME: the FDMs should update themselves diff --git a/src/Environment/environment_mgr.hxx b/src/Environment/environment_mgr.hxx index d8757900b..63d3f725a 100644 --- a/src/Environment/environment_mgr.hxx +++ b/src/Environment/environment_mgr.hxx @@ -51,7 +51,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); /** * Get the environment information for the plane's current position. diff --git a/src/FDM/ADA.cxx b/src/FDM/ADA.cxx index 0fc0aeee8..65de05599 100644 --- a/src/FDM/ADA.cxx +++ b/src/FDM/ADA.cxx @@ -156,7 +156,7 @@ struct { FGADA::FGADA( double dt ) { - set_delta_t( dt ); +// set_delta_t( dt ); } @@ -198,9 +198,12 @@ void FGADA::init() { // Run an iteration of the EOM. This is essentially a NOP here // because these values are getting filled in elsewhere based on // external input. -void FGADA::update( int multiloop ) { +void FGADA::update( double dt ) { // cout << "FGADA::update()" << endl; + if (is_suspended()) + return; + char Buffer[numberofbytes]; char OutBuffer[nbytes]; diff --git a/src/FDM/ADA.hxx b/src/FDM/ADA.hxx index bef66d88b..7374c479d 100644 --- a/src/FDM/ADA.hxx +++ b/src/FDM/ADA.hxx @@ -79,7 +79,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update(int dt); + void update(double dt); }; diff --git a/src/FDM/Balloon.cxx b/src/FDM/Balloon.cxx index dd5bc016d..1bd64a871 100644 --- a/src/FDM/Balloon.cxx +++ b/src/FDM/Balloon.cxx @@ -113,9 +113,14 @@ void FGBalloonSim::init() { // Run an iteration of the EOM (equations of motion) -void FGBalloonSim::update( int multiloop ) { +void FGBalloonSim::update( double dt ) { double save_alt = 0.0; + if (is_suspended()) + return; + + int multiloop = _calc_multiloop(dt); + // lets try to avoid really screwing up the BalloonSim model if ( get_Altitude() < -9000 ) { save_alt = get_Altitude(); diff --git a/src/FDM/Balloon.h b/src/FDM/Balloon.h index b180a3a53..84ff1ce6b 100644 --- a/src/FDM/Balloon.h +++ b/src/FDM/Balloon.h @@ -75,7 +75,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update( int multiloop ); + void update( double dt ); }; diff --git a/src/FDM/External.cxx b/src/FDM/External.cxx index cc6c1a2f9..b4794c7dd 100644 --- a/src/FDM/External.cxx +++ b/src/FDM/External.cxx @@ -25,7 +25,7 @@ FGExternal::FGExternal( double dt ) { - set_delta_t( dt ); +// set_delta_t( dt ); } @@ -47,7 +47,7 @@ void FGExternal::init() { // Run an iteration of the EOM. This is essentially a NOP here // because these values are getting filled in elsewhere based on // external input. -void FGExternal::update( int multiloop ) { +void FGExternal::update( double dt ) { // cout << "FGExternal::update()" << endl; // double time_step = (1.0 / fgGetInt("/sim/model-hz")) diff --git a/src/FDM/External.hxx b/src/FDM/External.hxx index 2cc20b425..61bc9a3ab 100644 --- a/src/FDM/External.hxx +++ b/src/FDM/External.hxx @@ -38,7 +38,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update( int multiloop ); + void update( double dt ); }; diff --git a/src/FDM/ExternalNet.cxx b/src/FDM/ExternalNet.cxx index 62c23edc4..97374d84e 100644 --- a/src/FDM/ExternalNet.cxx +++ b/src/FDM/ExternalNet.cxx @@ -234,7 +234,7 @@ static void net2global( FGNetFDM *net ) { FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp ) { - set_delta_t( dt ); +// set_delta_t( dt ); valid = true; @@ -330,10 +330,13 @@ void FGExternalNet::init() { // Run an iteration of the EOM. This is a NOP here because the flight // model values are getting filled in elsewhere (most likely from some // external source.) -void FGExternalNet::update( int multiloop ) { +void FGExternalNet::update( double dt ) { int length; int result; + if (is_suspended()) + return; + // Send control positions to remote fdm length = sizeof(ctrls); global2raw( &ctrls ); diff --git a/src/FDM/ExternalNet.hxx b/src/FDM/ExternalNet.hxx index 1d8c0487e..2901ca0f9 100644 --- a/src/FDM/ExternalNet.hxx +++ b/src/FDM/ExternalNet.hxx @@ -87,7 +87,7 @@ public: void init(); // update the fdm - void update( int multiloop ); + void update( double dt ); }; diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index 27b40ab83..4136e6b32 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -98,7 +98,6 @@ FGJSBsim::FGJSBsim( double dt ) SGPath engine_path( globals->get_fg_root() ); engine_path.append( "Engine" ); - set_delta_t( dt ); State->Setdt( dt ); result = fdmex->LoadModel( aircraft_path.str(), @@ -261,7 +260,12 @@ void FGJSBsim::init() { // Run an iteration of the EOM (equations of motion) void -FGJSBsim::update( int multiloop ) { +FGJSBsim::update( double dt ) { + + if (is_suspended()) + return; + + int multiloop = _calc_multiloop(dt); int i; diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx index 2f8b362c8..e0e66b119 100644 --- a/src/FDM/JSBSim/JSBSim.hxx +++ b/src/FDM/JSBSim/JSBSim.hxx @@ -207,9 +207,8 @@ public: /** Update the position based on inputs, positions, velocities, etc. - @param multiloop number of times to loop through the FDM - @return true if successful */ - void update( int multiloop ); + @param dt delta time in seconds. */ + void update(double dt); bool ToggleDataLogging(bool state); bool ToggleDataLogging(void); void do_trim(void); diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index a7a2435a0..8051ef49f 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -41,7 +41,7 @@ #include "LaRCsim.hxx" FGLaRCsim::FGLaRCsim( double dt ) { - set_delta_t( dt ); +// set_delta_t( dt ); speed_up = fgGetNode("/sim/speed-up", true); aero = fgGetNode("/sim/aero", true); @@ -60,10 +60,10 @@ FGLaRCsim::FGLaRCsim( double dt ) { I_xz = 0.000000E+00; } - ls_set_model_dt( get_delta_t() ); + ls_set_model_dt(dt); // Initialize our little engine that hopefully might - eng.init( get_delta_t() ); + eng.init(dt); // dcl - in passing dt to init rather than update I am assuming // that the LaRCsim dt is fixed at one value (yes it is 120hz CLO) } @@ -84,7 +84,12 @@ void FGLaRCsim::init() { // Run an iteration of the EOM (equations of motion) -void FGLaRCsim::update( int multiloop ) { +void FGLaRCsim::update( double dt ) { + + if (is_suspended()) + return; + + int multiloop = _calc_multiloop(dt); if ( !strcmp(aero->getStringValue(), "c172") ) { // set control inputs @@ -142,11 +147,11 @@ void FGLaRCsim::update( int multiloop ) { fgSetDouble("/consumables/fuel/tank[0]/level-gal_us", fgGetDouble("/consumables/fuel/tank[0]/level-gal_us") - (eng.get_fuel_flow_gals_hr() / (2 * 3600)) - * get_delta_t()); + * dt); fgSetDouble("/consumables/fuel/tank[1]/level-gal_us", fgGetDouble("/consumables/fuel/tank[1]/level-gal_us") - (eng.get_fuel_flow_gals_hr() / (2 * 3600)) - * get_delta_t()); + * dt); } F_X_engine = eng.get_prop_thrust_lbs(); diff --git a/src/FDM/LaRCsim.hxx b/src/FDM/LaRCsim.hxx index f5299c974..df2b5389c 100644 --- a/src/FDM/LaRCsim.hxx +++ b/src/FDM/LaRCsim.hxx @@ -58,7 +58,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update( int multiloop ); + void update( double dt ); // Positions void set_Latitude(double lat); //geocentric diff --git a/src/FDM/MagicCarpet.cxx b/src/FDM/MagicCarpet.cxx index 738e1e564..3e5a22f5d 100644 --- a/src/FDM/MagicCarpet.cxx +++ b/src/FDM/MagicCarpet.cxx @@ -33,7 +33,7 @@ FGMagicCarpet::FGMagicCarpet( double dt ) { - set_delta_t( dt ); +// set_delta_t( dt ); } @@ -49,10 +49,15 @@ void FGMagicCarpet::init() { // Run an iteration of the EOM (equations of motion) -void FGMagicCarpet::update( int multiloop ) { +void FGMagicCarpet::update( double dt ) { // cout << "FGLaRCsim::update()" << endl; - double time_step = get_delta_t() * multiloop; + if (is_suspended()) + return; + + int multiloop = _calc_multiloop(dt); + + double time_step = dt * multiloop; // speed and distance traveled double speed = globals->get_controls()->get_throttle( 0 ) * 2000; // meters/sec diff --git a/src/FDM/MagicCarpet.hxx b/src/FDM/MagicCarpet.hxx index 32fa71f24..aa35b020d 100644 --- a/src/FDM/MagicCarpet.hxx +++ b/src/FDM/MagicCarpet.hxx @@ -38,7 +38,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update( int multiloop ); + void update( double dt ); }; diff --git a/src/FDM/NullFDM.cxx b/src/FDM/NullFDM.cxx index 700824578..e02735893 100644 --- a/src/FDM/NullFDM.cxx +++ b/src/FDM/NullFDM.cxx @@ -25,7 +25,7 @@ FGNullFDM::FGNullFDM( double dt ) { - set_delta_t( dt ); +// set_delta_t( dt ); } @@ -43,6 +43,6 @@ void FGNullFDM::init() { // Run an iteration of the EOM. This is a NOP here because the flight // model values are getting filled in elsewhere (most likely from some // external source.) -void FGNullFDM::update( int multiloop ) { +void FGNullFDM::update( double dt ) { // cout << "FGNullFDM::update()" << endl; } diff --git a/src/FDM/NullFDM.hxx b/src/FDM/NullFDM.hxx index 1d2dd2844..f2e4f1f8a 100644 --- a/src/FDM/NullFDM.hxx +++ b/src/FDM/NullFDM.hxx @@ -39,7 +39,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update( int multiloop ); + void update( double dt ); }; diff --git a/src/FDM/UFO.cxx b/src/FDM/UFO.cxx index efa296d82..3223e35f9 100644 --- a/src/FDM/UFO.cxx +++ b/src/FDM/UFO.cxx @@ -40,7 +40,7 @@ FGUFO::FGUFO( double dt ) Aileron(0.0), Elevator(0.0) { - set_delta_t( dt ); +// set_delta_t( dt ); } @@ -56,10 +56,15 @@ void FGUFO::init() { // Run an iteration of the EOM (equations of motion) -void FGUFO::update( int multiloop ) { +void FGUFO::update( double dt ) { // cout << "FGLaRCsim::update()" << endl; - double time_step = get_delta_t() * multiloop; + if (is_suspended()) + return; + + int multiloop = _calc_multiloop(dt); + + double time_step = dt * multiloop; // read the throttle double th = globals->get_controls()->get_throttle( 0 ); diff --git a/src/FDM/UFO.hxx b/src/FDM/UFO.hxx index 8ceecf135..077332c6c 100644 --- a/src/FDM/UFO.hxx +++ b/src/FDM/UFO.hxx @@ -40,7 +40,7 @@ public: void init(); // update position based on inputs, positions, velocities, etc. - void update( int multiloop ); + void update( double dt ); }; diff --git a/src/FDM/YASim/YASim.cxx b/src/FDM/YASim/YASim.cxx index 5c93abad3..faaaf5fe7 100644 --- a/src/FDM/YASim/YASim.cxx +++ b/src/FDM/YASim/YASim.cxx @@ -57,7 +57,7 @@ void YASim::printDEBUG() YASim::YASim(double dt) { - set_delta_t(dt); +// set_delta_t(dt); _fdm = new FGFDM(); _dt = dt; @@ -194,8 +194,13 @@ void YASim::init() set_inited(true); } -void YASim::update(int iterations) +void YASim::update(double dt) { + if (is_suspended()) + return; + + int iterations = _calc_multiloop(dt); + // If we're crashed, then we don't care if(_fdm->getAirplane()->getModel()->isCrashed()) return; diff --git a/src/FDM/YASim/YASim.hxx b/src/FDM/YASim/YASim.hxx index 02f9440bc..1498d5126 100644 --- a/src/FDM/YASim/YASim.hxx +++ b/src/FDM/YASim/YASim.hxx @@ -14,7 +14,7 @@ public: virtual void bind(); // Run an iteration - virtual void update(int iterations); + virtual void update(double dt); private: void report(); diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 991e150dd..76f93e2a4 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -57,8 +57,9 @@ FGInterface::FGInterface() { FGInterface::FGInterface( double dt ) { _setup(); - delta_t = dt; - remainder = elapsed = multi_loop = 0; +// delta_t = dt; +// remainder = elapsed = multi_loop = 0; + remainder = 0; } // Destructor @@ -67,6 +68,21 @@ FGInterface::~FGInterface() { } +int +FGInterface::_calc_multiloop (double dt) +{ + int hz = fgGetInt("/sim/model-hz"); + int speedup = fgGetInt("/sim/speed-up"); + + dt += remainder; + remainder = 0; + double ml = dt * hz; + int multiloop = int(floor(ml)); + remainder = (ml - multiloop) / hz; + return (multiloop * speedup); +} + + /** * Set default values for the state of the FDM. * @@ -163,8 +179,8 @@ FGInterface::common_init () set_inited( true ); - stamp(); - set_remainder( 0 ); +// stamp(); +// set_remainder( 0 ); // Set initial position SG_LOG( SG_FLIGHT, SG_INFO, "...initializing position..." ); @@ -254,14 +270,14 @@ FGInterface::bind () bound = true; // Time management (read-only) - fgTie("/fdm/time/delta_t", this, - &FGInterface::get_delta_t); // read-only - fgTie("/fdm/time/elapsed", this, - &FGInterface::get_elapsed); // read-only - fgTie("/fdm/time/remainder", this, - &FGInterface::get_remainder); // read-only - fgTie("/fdm/time/multi_loop", this, - &FGInterface::get_multi_loop); // read-only +// fgTie("/fdm/time/delta_t", this, +// &FGInterface::get_delta_t); // read-only +// fgTie("/fdm/time/elapsed", this, +// &FGInterface::get_elapsed); // read-only +// fgTie("/fdm/time/remainder", this, +// &FGInterface::get_remainder); // read-only +// fgTie("/fdm/time/multi_loop", this, +// &FGInterface::get_multi_loop); // read-only // Aircraft position fgTie("/position/latitude-deg", this, @@ -405,7 +421,7 @@ FGInterface::unbind () * Update the state of the FDM (i.e. run the equations of motion). */ void -FGInterface::update (int dt) +FGInterface::update (double dt) { SG_LOG(SG_FLIGHT, SG_ALERT, "dummy update() ... SHOULDN'T BE CALLED!"); } diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index fe0a11edd..afc4ded02 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -90,7 +90,7 @@ #include #include -#include +// #include #include
@@ -124,11 +124,11 @@ private: // next elapsed time. This yields a small amount of temporal // jitter ( < dt ) but in practice seems to work well. - double delta_t; // delta "t" - SGTimeStamp time_stamp; // time stamp of last run - long elapsed; // time elapsed since last run - long remainder; // remainder time from last run - int multi_loop; // number of iterations of "delta_t" to run +// double delta_t; // delta "t" +// SGTimeStamp time_stamp; // time stamp of last run +// long elapsed; // time elapsed since last run + double remainder; // remainder time from last run +// int multi_loop; // number of iterations of "delta_t" to run // Pilot location rel to ref pt FG_VECTOR_3 d_pilot_rp_body_v; @@ -224,7 +224,10 @@ private: // SGTimeStamp valid_stamp; // time this record is valid // SGTimeStamp next_stamp; // time this record is valid -// protected: +protected: + + int _calc_multiloop (double dt); + public: // deliberately not virtual so that @@ -400,7 +403,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update(int dt); + virtual void update(double dt); virtual bool ToggleDataLogging(bool state) { return false; } virtual bool ToggleDataLogging(void) { return false; } @@ -443,17 +446,17 @@ public: void common_init(); // time and update management values - inline double get_delta_t() const { return delta_t; } - inline void set_delta_t( double dt ) { delta_t = dt; } - inline SGTimeStamp get_time_stamp() const { return time_stamp; } - inline void set_time_stamp( SGTimeStamp s ) { time_stamp = s; } - inline void stamp() { time_stamp.stamp(); } - inline long get_elapsed() const { return elapsed; } - inline void set_elapsed( long e ) { elapsed = e; } - inline long get_remainder() const { return remainder; } - inline void set_remainder( long r ) { remainder = r; } - inline int get_multi_loop() const { return multi_loop; } - inline void set_multi_loop( int ml ) { multi_loop = ml; } +// inline double get_delta_t() const { return delta_t; } +// inline void set_delta_t( double dt ) { delta_t = dt; } +// inline SGTimeStamp get_time_stamp() const { return time_stamp; } +// inline void set_time_stamp( SGTimeStamp s ) { time_stamp = s; } +// inline void stamp() { time_stamp.stamp(); } +// inline long get_elapsed() const { return elapsed; } +// inline void set_elapsed( long e ) { elapsed = e; } +// inline long get_remainder() const { return remainder; } +// inline void set_remainder( long r ) { remainder = r; } +// inline int get_multi_loop() const { return multi_loop; } +// inline void set_multi_loop( int ml ) { multi_loop = ml; } // Positions virtual void set_Latitude(double lat); // geocentric diff --git a/src/Input/input.cxx b/src/Input/input.cxx index bf6f44617..f7ce15856 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -217,7 +217,7 @@ FGInput::unbind () } void -FGInput::update (int dt) +FGInput::update (double dt) { _update_keyboard(); _update_joystick(); diff --git a/src/Input/input.hxx b/src/Input/input.hxx index a5ff74dbe..2ea4217e9 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -191,7 +191,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); /** diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 152dbae1e..2b55d705d 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -265,9 +265,9 @@ setAircraftDir (const char * dir) * Return the number of milliseconds elapsed since simulation started. */ static double -getElapsedTime_ms () +getElapsedTime_sec () { - return globals->get_sim_time_ms(); + return globals->get_sim_time_sec(); } @@ -580,7 +580,7 @@ fgInitProps () fgTie("/sim/freeze/master", getFreeze, setFreeze); fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir); - fgTie("/sim/time/elapsed-ms", getElapsedTime_ms); + fgTie("/sim/time/elapsed-sec", getElapsedTime_sec); fgTie("/sim/time/gmt", getDateString, setDateString); fgSetArchivable("/sim/time/gmt"); fgTie("/sim/time/gmt-string", getGMTString); diff --git a/src/Main/fgfs.cxx b/src/Main/fgfs.cxx index 33e281f6a..77c8dd5f5 100644 --- a/src/Main/fgfs.cxx +++ b/src/Main/fgfs.cxx @@ -3,6 +3,7 @@ #include #include "globals.hxx" +#include "fg_props.hxx" @@ -11,10 +12,39 @@ //////////////////////////////////////////////////////////////////////// +FGSubsystem::FGSubsystem () + : _suspended(false) +{ +} + FGSubsystem::~FGSubsystem () { - // NO-OP } +void +FGSubsystem::suspend () +{ + _suspended = true; +} + +void +FGSubsystem::suspend (bool suspended) +{ + _suspended = suspended; +} + +void +FGSubsystem::resume () +{ + _suspended = false; +} + +bool +FGSubsystem::is_suspended () const +{ + if (!_freeze_master_node.valid()) + _freeze_master_node = fgGetNode("/sim/freeze/master", true); + return _suspended || _freeze_master_node->getBoolValue(); +} // end of fgfs.cxx diff --git a/src/Main/fgfs.hxx b/src/Main/fgfs.hxx index f7aa373e1..8f1270219 100644 --- a/src/Main/fgfs.hxx +++ b/src/Main/fgfs.hxx @@ -38,6 +38,8 @@ # include #endif +#include + /** @@ -91,7 +93,7 @@ * _errorNode = fgGetNode("/display/error-margin-pct", true); * } * - * void MySubsystem::update () + * void MySubsystem::update (double delta_time_sec) * { * do_something(_errorNode.getFloatValue()); * } @@ -100,11 +102,23 @@ *

The node returned will always be a pointer to SGPropertyNode, * and the subsystem should not delete it in its destructor * (the pointer belongs to the property tree, not the subsystem).

+ * + *

The program may ask the subsystem to suspend or resume + * sim-time-dependent operations; by default, the suspend() and + * resume() methods set the protected variable _suspended, + * which the subsystem can reference in its update() method, but + * subsystems may also override the suspend() and resume() methods to + * take different actions.

*/ class FGSubsystem { public: + /** + * Default constructor. + */ + FGSubsystem (); + /** * Virtual destructor to ensure that subclass destructors are called. */ @@ -147,10 +161,61 @@ public: * Update the subsystem. * *

FlightGear invokes this method every time the subsystem should - * update its state. If the subsystem requires delta time information, - * it should track it itself.

+ * update its state.

+ * + * @param delta_time_sec The delta time, in seconds, since the last + * update. On first update, delta time will be 0. + */ + virtual void update (double delta_time_sec) = 0; + + + /** + * Suspend operation of this subsystem. + * + *

This method instructs the subsystem to suspend + * sim-time-dependent operations until asked to resume. The update + * method will still be invoked so that the subsystem can take any + * non-time-dependent actions, such as updating the display.

+ * + *

It is not an error for the suspend method to be invoked when + * the subsystem is already suspended; the invocation should simply + * be ignored.

+ */ + virtual void suspend (); + + + /** + * Suspend or resum operation of this subsystem. + * + * @param suspended true if the subsystem should be suspended, false + * otherwise. + */ + virtual void suspend (bool suspended); + + + /** + * Resume operation of this subsystem. + * + *

This method instructs the subsystem to resume + * sim-time-depended operations. It is not an error for the resume + * method to be invoked when the subsystem is not suspended; the + * invocation should simply be ignored.

*/ - virtual void update (int dt) = 0; + virtual void resume (); + + + /** + * Test whether this subsystem is suspended. + * + * @return true if the subsystem is suspended, false if it is not. + */ + virtual bool is_suspended () const; + + +protected: + + mutable SGPropertyNode_ptr _freeze_master_node; + bool _suspended; }; diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 44ba968c4..4394485eb 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -42,7 +42,7 @@ FGGlobals *globals; // Constructor FGGlobals::FGGlobals() : - sim_time_ms(0.0), + sim_time_sec(0.0), #if defined(FX) && defined(XMESA) fullscreen( true ), #endif diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index ee8036c88..5a02dbd10 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -80,7 +80,7 @@ class FGGlobals private: // Number of milliseconds elapsed since the start of the program. - double sim_time_ms; + double sim_time_sec; // Root of FlightGear data tree string fg_root; @@ -174,9 +174,9 @@ public: FGGlobals(); ~FGGlobals(); - inline double get_sim_time_ms () const { return sim_time_ms; } - inline void inc_sim_time_ms (double dt) { sim_time_ms += dt; } - inline void set_sim_time_ms (double t) { sim_time_ms = t; } + inline double get_sim_time_sec () const { return sim_time_sec; } + inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; } + inline void set_sim_time_sec (double t) { sim_time_sec = t; } inline const string &get_fg_root () const { return fg_root; } inline void set_fg_root (const string &root) { fg_root = root; } diff --git a/src/Main/logger.cxx b/src/Main/logger.cxx index 250b4b053..afd32db2c 100644 --- a/src/Main/logger.cxx +++ b/src/Main/logger.cxx @@ -77,13 +77,13 @@ FGLogger::unbind () } void -FGLogger::update (int dt) +FGLogger::update (double dt) { - double sim_time_ms = globals->get_sim_time_ms(); + double sim_time_ms = globals->get_sim_time_sec() * 1000; for (unsigned int i = 0; i < _logs.size(); i++) { if ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) { _logs[i].last_time_ms = sim_time_ms; - (*_logs[i].output) << globals->get_sim_time_ms(); + (*_logs[i].output) << sim_time_ms; for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) { (*_logs[i].output) << _logs[i].delimiter << _logs[i].nodes[j]->getStringValue(); diff --git a/src/Main/logger.hxx b/src/Main/logger.hxx index 2929c421c..b585210d9 100644 --- a/src/Main/logger.hxx +++ b/src/Main/logger.hxx @@ -44,7 +44,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); private: diff --git a/src/Main/main.cxx b/src/Main/main.cxx index d7c12fe53..9d1c8d903 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -148,6 +148,8 @@ sgVec3 rway_ols; float scene_nearplane = 0.5f; float scene_farplane = 120000.0f; +static double delta_time_sec = 0; + #ifndef FG_NEW_ENVIRONMENT # include @@ -391,16 +393,10 @@ void trRenderFrame( void ) { // Update all Visuals (redraws anything graphics related) -void fgRenderFrame( void ) { +void fgRenderFrame() { - // Update the elapsed time. - current_time_stamp.stamp(); - int dt_ms = (current_time_stamp - last_time_stamp) / 1000L; - globals->inc_sim_time_ms( dt_ms ); - last_time_stamp = current_time_stamp; - // Process/manage pending events - global_events.update( dt_ms ); + global_events.update( delta_time_sec ); static const SGPropertyNode *longitude = fgGetNode("/position/longitude-deg"); @@ -442,7 +438,7 @@ void fgRenderFrame( void ) { fgSplashUpdate(0.0); } // Keep resetting sim time while the sim is initializing - globals->set_sim_time_ms( 0.0 ); + globals->set_sim_time_sec( 0.0 ); } else { // idle_state is now 1000 meaning we've finished all our // initializations and are running the main loop, so this will @@ -722,21 +718,21 @@ void fgRenderFrame( void ) { // glDisable( GL_TEXTURE_2D ); // update the input subsystem - current_input.update(dt_ms); + current_input.update(delta_time_sec); // update the controls subsystem - globals->get_controls()->update(dt_ms); + globals->get_controls()->update(delta_time_sec); hud_and_panel->apply(); fgCockpitUpdate(); // Use the hud_and_panel ssgSimpleState for rendering the ATC output // This only works properly if called before the panel call - globals->get_ATC_display()->update(dt_ms); + globals->get_ATC_display()->update(delta_time_sec); // update the panel subsystem if ( current_panel != NULL ) { - current_panel->update(dt_ms); + current_panel->update(delta_time_sec); } // We can do translucent menus, so why not. :-) @@ -747,7 +743,7 @@ void fgRenderFrame( void ) { // glEnable( GL_FOG ); - globals->get_logger()->update(dt_ms); + globals->get_logger()->update(delta_time_sec); } glutSwapBuffers(); @@ -787,51 +783,45 @@ void fgUpdateTimeDepCalcs() { // instance ... if ( !cur_fdm_state->get_inited() ) { // do nothing, fdm isn't inited yet - } else if ( master_freeze->getBoolValue() ) { - // we are frozen, run the fdm's with 0 time slices in case - // they want to do something with that. - - cur_fdm_state->update( 0 ); - FGSteam::update( 0 ); } else { - // we have been inited, and we are not frozen, we are good to go ... + // we have been inited, and we are good to go ... if ( !inited ) { - cur_fdm_state->stamp(); +// cur_fdm_state->stamp(); inited = true; } - SGTimeStamp current; - current.stamp(); - long elapsed = current - cur_fdm_state->get_time_stamp(); - cur_fdm_state->set_time_stamp( current ); - elapsed += cur_fdm_state->get_remainder(); - // cout << "elapsed = " << elapsed << endl; - // cout << "dt = " << cur_fdm_state->get_delta_t() << endl; - multi_loop = (long)(((double)elapsed * 0.000001) / - cur_fdm_state->get_delta_t() ); - cur_fdm_state->set_multi_loop( multi_loop ); - long remainder = elapsed - (long)( (multi_loop*1000000) * - cur_fdm_state->get_delta_t() ); - cur_fdm_state->set_remainder( remainder ); - // cout << "remainder = " << remainder << endl; - - // chop max interations to something reasonable if the sim was - // delayed for an excesive amount of time - if ( multi_loop > 2.0 / cur_fdm_state->get_delta_t() ) { - multi_loop = (int)(2.0 / cur_fdm_state->get_delta_t()); - cur_fdm_state->set_remainder( 0 ); - } - - // cout << "multi_loop = " << multi_loop << endl; - for ( i = 0; i < multi_loop * fgGetInt("/sim/speed-up"); ++i ) { - // run Autopilot system - globals->get_autopilot()->update(0); // FIXME: use real dt +// SGTimeStamp current; +// current.stamp(); +// long elapsed = current - cur_fdm_state->get_time_stamp(); +// cur_fdm_state->set_time_stamp( current ); +// elapsed += cur_fdm_state->get_remainder(); +// // cout << "elapsed = " << elapsed << endl; +// // cout << "dt = " << cur_fdm_state->get_delta_t() << endl; +// multi_loop = (long)(((double)elapsed * 0.000001) / +// cur_fdm_state->get_delta_t() ); +// cur_fdm_state->set_multi_loop( multi_loop ); +// long remainder = elapsed - (long)( (multi_loop*1000000) * +// cur_fdm_state->get_delta_t() ); +// cur_fdm_state->set_remainder( remainder ); +// // cout << "remainder = " << remainder << endl; + +// // chop max interations to something reasonable if the sim was +// // delayed for an excesive amount of time +// if ( multi_loop > 2.0 / cur_fdm_state->get_delta_t() ) { +// multi_loop = (int)(2.0 / cur_fdm_state->get_delta_t()); +// cur_fdm_state->set_remainder( 0 ); +// } + +// // cout << "multi_loop = " << multi_loop << endl; +// for ( i = 0; i < multi_loop * fgGetInt("/sim/speed-up"); ++i ) { +// // run Autopilot system + globals->get_autopilot()->update(delta_time_sec); // update FDM - cur_fdm_state->update( 1 ); - } - FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") ); + cur_fdm_state->update(delta_time_sec); +// } + FGSteam::update(delta_time_sec); } if ( !strcmp(fgGetString("/sim/view-mode"), "pilot") ) { @@ -840,11 +830,11 @@ void fgUpdateTimeDepCalcs() { } - globals->get_model_mgr()->update(multi_loop); - globals->get_aircraft_model()->update(multi_loop); + globals->get_model_mgr()->update(delta_time_sec); + globals->get_aircraft_model()->update(delta_time_sec); // update the view angle - globals->get_viewmgr()->update(multi_loop); + globals->get_viewmgr()->update(delta_time_sec); l->UpdateAdjFog(); @@ -854,7 +844,7 @@ void fgUpdateTimeDepCalcs() { cur_fdm_state->get_Latitude() ); // Update radio stack model - current_radiostack->update(multi_loop); + current_radiostack->update(delta_time_sec); } @@ -870,6 +860,13 @@ static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER; // What should we do when we have nothing else to do? Let's get ready // for the next move and update the display? static void fgMainLoop( void ) { + + // Update the elapsed time. + current_time_stamp.stamp(); + delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0; + last_time_stamp = current_time_stamp; + globals->inc_sim_time_sec( delta_time_sec ); + static const SGPropertyNode *longitude = fgGetNode("/position/longitude-deg"); static const SGPropertyNode *latitude @@ -1035,10 +1032,10 @@ static void fgMainLoop( void ) { #endif // Run ATC subsystem - globals->get_ATC_mgr()->update(1); // FIXME - use real dt. + globals->get_ATC_mgr()->update(delta_time_sec); // Run the AI subsystem - // globals->get_AI_mgr()->update(1); // FIXME - use real dt. + // globals->get_AI_mgr()->update(delta_time_sec); // Run flight model diff --git a/src/Main/viewer.cxx b/src/Main/viewer.cxx index f9e62dbcf..c099de9fa 100644 --- a/src/Main/viewer.cxx +++ b/src/Main/viewer.cxx @@ -722,10 +722,11 @@ FGViewer::get_v_fov() } void -FGViewer::update (int dt) +FGViewer::update (double dt) { int i; - for ( i = 0; i < dt; i++ ) { + int dt_ms = int(dt * 1000); + for ( i = 0; i < dt_ms; i++ ) { if ( fabs( _goal_heading_offset_deg - _heading_offset_deg) < 1 ) { setHeadingOffset_deg( _goal_heading_offset_deg ); break; @@ -754,7 +755,7 @@ FGViewer::update (int dt) } } - for ( i = 0; i < dt; i++ ) { + for ( i = 0; i < dt_ms; i++ ) { if ( fabs( _goal_pitch_offset_deg - _pitch_offset_deg ) < 1 ) { setPitchOffset_deg( _goal_pitch_offset_deg ); break; diff --git a/src/Main/viewer.hxx b/src/Main/viewer.hxx index 0fc7125d9..bb0eae4ef 100644 --- a/src/Main/viewer.hxx +++ b/src/Main/viewer.hxx @@ -76,7 +76,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - void update (int dt); + void update (double dt); ////////////////////////////////////////////////////////////////////// diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index ded790eba..7dbb9a159 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -172,7 +172,7 @@ FGViewMgr::unbind () } void -FGViewMgr::update (int dt) +FGViewMgr::update (double dt) { char stridx [20]; double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg; diff --git a/src/Main/viewmgr.hxx b/src/Main/viewmgr.hxx index 6c509f9ae..9cccf8c5f 100644 --- a/src/Main/viewmgr.hxx +++ b/src/Main/viewmgr.hxx @@ -59,7 +59,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); // getters inline int size() const { return views.size(); } diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index 64ef9e747..b56578a9b 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -70,7 +70,7 @@ FGAircraftModel::unbind () } void -FGAircraftModel::update (int dt) +FGAircraftModel::update (double dt) { int view_number = globals->get_viewmgr()->get_current(); diff --git a/src/Model/acmodel.hxx b/src/Model/acmodel.hxx index 2898c2e93..4e691ca0a 100644 --- a/src/Model/acmodel.hxx +++ b/src/Model/acmodel.hxx @@ -34,7 +34,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); virtual void draw (); virtual FG3DModel * get3DModel() { return _aircraft; } diff --git a/src/Model/model.cxx b/src/Model/model.cxx index 1baf88673..f13c8e13a 100644 --- a/src/Model/model.cxx +++ b/src/Model/model.cxx @@ -242,7 +242,7 @@ FG3DModel::init (const string &path) } void -FG3DModel::update (int dt) +FG3DModel::update (double dt) { unsigned int i; @@ -412,7 +412,7 @@ FG3DModel::NullAnimation::init (ssgEntity * object, } void -FG3DModel::NullAnimation::update (int dt) +FG3DModel::NullAnimation::update (double dt) { } @@ -445,7 +445,7 @@ FG3DModel::RangeAnimation::init (ssgEntity * object, } void -FG3DModel::RangeAnimation::update (int dt) +FG3DModel::RangeAnimation::update (double dt) { } @@ -477,7 +477,7 @@ FG3DModel::BillboardAnimation::init (ssgEntity * object, } void -FG3DModel::BillboardAnimation::update (int dt) +FG3DModel::BillboardAnimation::update (double dt) { } @@ -512,7 +512,7 @@ FG3DModel::SelectAnimation::init (ssgEntity * object, } void -FG3DModel::SelectAnimation::update (int dt) +FG3DModel::SelectAnimation::update (double dt) { if (_condition != 0 && _condition->test()) _selector->select(0xffff); @@ -559,9 +559,9 @@ FG3DModel::SpinAnimation::init (ssgEntity * object, } void -FG3DModel::SpinAnimation::update (int dt) +FG3DModel::SpinAnimation::update (double dt) { - float velocity_rpms = (_prop->getDoubleValue() * _factor / 60000.0); + float velocity_rpms = (_prop->getDoubleValue() * _factor / 60.0); _position_deg += (dt * velocity_rpms * 360); while (_position_deg < 0) _position_deg += 360.0; @@ -627,7 +627,7 @@ FG3DModel::RotateAnimation::init (ssgEntity * object, } void -FG3DModel::RotateAnimation::update (int dt) +FG3DModel::RotateAnimation::update (double dt) { if (_table == 0) { _position_deg = (_prop->getDoubleValue() + _offset_deg) * _factor; @@ -695,7 +695,7 @@ FG3DModel::TranslateAnimation::init (ssgEntity * object, } void -FG3DModel::TranslateAnimation::update (int dt) +FG3DModel::TranslateAnimation::update (double dt) { if (_table == 0) { _position_m = (_prop->getDoubleValue() + _offset_m) * _factor; diff --git a/src/Model/model.hxx b/src/Model/model.hxx index 266702622..bc48663ac 100644 --- a/src/Model/model.hxx +++ b/src/Model/model.hxx @@ -47,7 +47,7 @@ public: virtual ~FG3DModel (); virtual void init (const string &path); - virtual void update (int dt); + virtual void update (double dt); virtual bool getVisible () const; virtual void setVisible (bool visible); @@ -130,9 +130,9 @@ private: /** * Update the animation. * - * @param dt The elapsed time in milliseconds since the last call. + * @param dt The elapsed time in seconds since the last call. */ - virtual void update (int dt) = 0; + virtual void update (double dt) = 0; }; @@ -146,7 +146,7 @@ private: NullAnimation (); virtual ~NullAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: ssgBranch * _branch; }; @@ -161,7 +161,7 @@ private: RangeAnimation (); virtual ~RangeAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: ssgRangeSelector * _branch; }; @@ -176,7 +176,7 @@ private: BillboardAnimation (); virtual ~BillboardAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: ssgCutout * _branch; }; @@ -191,7 +191,7 @@ private: SelectAnimation (); virtual ~SelectAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: FGCondition * _condition; ssgSelector * _selector; @@ -209,7 +209,7 @@ private: SpinAnimation (); virtual ~SpinAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: SGPropertyNode * _prop; double _factor; @@ -232,7 +232,7 @@ private: RotateAnimation (); virtual ~RotateAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: SGPropertyNode * _prop; double _offset_deg; @@ -259,7 +259,7 @@ private: TranslateAnimation (); virtual ~TranslateAnimation (); virtual void init (ssgEntity * object, SGPropertyNode * props); - virtual void update (int dt); + virtual void update (double dt); private: SGPropertyNode * _prop; double _offset_m; diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 680230897..ead08801c 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -97,7 +97,7 @@ FGModelMgr::unbind () } void -FGModelMgr::update (int dt) +FGModelMgr::update (double dt) { for (int i = 0; i < _instances.size(); i++) { Instance * instance = _instances[i]; diff --git a/src/Model/modelmgr.hxx b/src/Model/modelmgr.hxx index 84e25839c..8f953875a 100644 --- a/src/Model/modelmgr.hxx +++ b/src/Model/modelmgr.hxx @@ -36,7 +36,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); virtual void draw (); diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index 0f78f66ac..51891c062 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -61,7 +61,7 @@ FGScenery::~FGScenery() { void FGScenery::init() { } -void FGScenery::update(int dt) { +void FGScenery::update(double dt) { } void FGScenery::bind() { diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx index 4e4531dfe..45ae6a9d7 100644 --- a/src/Scenery/scenery.hxx +++ b/src/Scenery/scenery.hxx @@ -67,7 +67,7 @@ public: void init (); void bind (); void unbind (); - void update (int dt); + void update (double dt); inline double get_cur_elev() const { return cur_elev; } inline void set_cur_elev( double e ) { cur_elev = e; } diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 0c31746c0..f8d05d4c2 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -95,7 +95,7 @@ FGFX::unbind () } void -FGFX::update (int dt) +FGFX::update (double dt) { for (unsigned int i = 0; i < _sound.size(); i++ ) _sound[i]->update(dt); diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 6e59abb67..aaed5ae06 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -47,7 +47,7 @@ public: virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); private: diff --git a/src/Sound/fg_sound.cxx b/src/Sound/fg_sound.cxx index 51b7ecb72..8890d796e 100644 --- a/src/Sound/fg_sound.cxx +++ b/src/Sound/fg_sound.cxx @@ -251,7 +251,7 @@ FGSound::unbind () } void -FGSound::update (int dt) +FGSound::update (double dt) { double curr_value = 0.0; diff --git a/src/Sound/fg_sound.hxx b/src/Sound/fg_sound.hxx index 04dda074b..8774562b2 100644 --- a/src/Sound/fg_sound.hxx +++ b/src/Sound/fg_sound.hxx @@ -48,7 +48,7 @@ public: virtual void init (SGPropertyNode *); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); protected: diff --git a/src/Sound/soundmgr.cxx b/src/Sound/soundmgr.cxx index fb805428d..2b7e25576 100644 --- a/src/Sound/soundmgr.cxx +++ b/src/Sound/soundmgr.cxx @@ -191,7 +191,8 @@ void FGSoundMgr::unbind () // run the audio scheduler -void FGSoundMgr::update(int dt) { +void FGSoundMgr::update(double dt) { + // FIXME: use dt supplied (seconds) SGTimeStamp current; current.stamp(); diff --git a/src/Sound/soundmgr.hxx b/src/Sound/soundmgr.hxx index a46f31f53..d9e9dd8fb 100644 --- a/src/Sound/soundmgr.hxx +++ b/src/Sound/soundmgr.hxx @@ -144,7 +144,7 @@ public: /** * Run the audio scheduler. */ - void update(int dt); + void update(double dt); /** diff --git a/src/Time/FGEventMgr.cxx b/src/Time/FGEventMgr.cxx index 0dfb7f260..f9cc429a1 100644 --- a/src/Time/FGEventMgr.cxx +++ b/src/Time/FGEventMgr.cxx @@ -142,9 +142,11 @@ FGEventMgr::unbind() } void -FGEventMgr::update( int dt ) +FGEventMgr::update( double dt ) { - if (dt < 0) + int dt_ms = int(dt * 1000); + + if (dt_ms < 0) { SG_LOG( SG_GENERAL, SG_ALERT, "FGEventMgr::update() called with negative delta T" ); @@ -159,7 +161,7 @@ FGEventMgr::update( int dt ) // Scan all events. Run one whose interval has expired. while (first != last) { - if (first->update( dt )) + if (first->update( dt_ms )) { if (first->value() < min_value) { diff --git a/src/Time/FGEventMgr.hxx b/src/Time/FGEventMgr.hxx index 497711810..54ec6ae7b 100644 --- a/src/Time/FGEventMgr.hxx +++ b/src/Time/FGEventMgr.hxx @@ -129,9 +129,9 @@ public: /* * Update the elapsed time for all events. - * @param dt elapsed time in milliseconds. + * @param dt elapsed time in seconds. */ - void update( int dt ); + void update( double dt ); /** * Register a free standing function to be executed some time in the future.