From adc95a4b5533649d6c5b620b38dab4e42117620f Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 17 Nov 2012 20:01:19 +0100 Subject: [PATCH] #600, for Curt... ;-) allow speed-up value to use fractions "speed-up" can now also be used for slow-motion (i.e. 0.5 / 0.25 / ...) or fractional speeds (3.141...). This was already working for instruments (for replay) before, now it's also considered by FDM simulation. --- src/FDM/LaRCsim/LaRCsim.cxx | 4 ++-- src/FDM/flight.cxx | 9 ++++++--- src/FDM/flight.hxx | 1 + src/Main/options.cxx | 4 ++-- src/Network/native_ctrls.cxx | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/FDM/LaRCsim/LaRCsim.cxx b/src/FDM/LaRCsim/LaRCsim.cxx index 850532f34..60f54a146 100644 --- a/src/FDM/LaRCsim/LaRCsim.cxx +++ b/src/FDM/LaRCsim/LaRCsim.cxx @@ -269,10 +269,10 @@ void FGLaRCsim::update( double dt ) { } // copy control positions into the LaRCsim structure - Lat_control = globals->get_controls()->get_aileron() / speed_up->getIntValue(); + Lat_control = globals->get_controls()->get_aileron() / speed_up->getDoubleValue(); Long_control = globals->get_controls()->get_elevator(); Long_trim = globals->get_controls()->get_elevator_trim(); - Rudder_pedal = globals->get_controls()->get_rudder() / speed_up->getIntValue(); + Rudder_pedal = globals->get_controls()->get_rudder() / speed_up->getDoubleValue(); // IO360.cxx for the C172 thrust is broken (not sure why). // So force C172 to use engine model in c172_engine.c instead of the IO360.cxx. diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 9826d6417..c65a009a6 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -69,9 +69,11 @@ FGInterface::_calc_multiloop (double dt) // roundoff problems when we already have nearly accurate values. // Only the speedup thing must be still handled here int hz = fgGetInt("/sim/model-hz"); - int multiloop = SGMiscd::roundToInt(dt*hz); - int speedup = fgGetInt("/sim/speed-up"); - return multiloop * speedup; + double speedup = fgGetDouble("/sim/speed-up"); + double loops = dt * hz * speedup + delta_loops; + int iloops = SGMiscd::roundToInt(loops); + delta_loops = loops-iloops; // delta_loops required for speed-ups < 1 (to do one iteration every n-th step) + return iloops; } @@ -119,6 +121,7 @@ FGInterface::_setup () climb_rate=0; altitude_agl=0; track=0; + delta_loops = 0.0; } void diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 0cd39520b..bf1bf28bb 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -191,6 +191,7 @@ private: double climb_rate; // in feet per second double altitude_agl; double track; + double delta_loops; simgear::TiedPropertyList _tiedProperties; diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 4221df758..ae38bdc75 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -190,7 +190,7 @@ fgSetDefaults () fgSetString("/sim/flight-model", "jsb"); fgSetString("/sim/aero", "c172"); fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ); - fgSetInt("/sim/speed-up", 1); + fgSetDouble("/sim/speed-up", 1.0); // Rendering options fgSetString("/sim/rendering/fog", "nicest"); @@ -1392,7 +1392,7 @@ struct OptionDesc { {"aircraft-dir", true, OPTION_IGNORE, "", false, "", 0 }, {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 }, {"max-fps", true, OPTION_DOUBLE, "/sim/frame-rate-throttle-hz", false, "", 0 }, - {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 }, + {"speed", true, OPTION_DOUBLE, "/sim/speed-up", false, "", 0 }, {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 }, {"notrim", false, OPTION_BOOL, "/sim/presets/trim", false, "", 0 }, {"on-ground", false, OPTION_BOOL, "/sim/presets/onground", true, "", 0 }, diff --git a/src/Network/native_ctrls.cxx b/src/Network/native_ctrls.cxx index f468b9449..19a1a482d 100644 --- a/src/Network/native_ctrls.cxx +++ b/src/Network/native_ctrls.cxx @@ -452,7 +452,7 @@ void FGNetCtrls2Props( FGNetCtrls *net, bool honor_freezes, node->setDoubleValue( "nav/frequencies/selected-mhz[0]", net->nav_1 ); node->setDoubleValue( "nav[1]/frequencies/selected-mhz[0]", net->nav_2 ); - fgSetInt( "/sim/speed-up", net->speedup ); + fgSetDouble( "/sim/speed-up", net->speedup ); if ( honor_freezes ) { node = fgGetNode( "/sim/freeze", true ); -- 2.39.5