From 337d0d1be6b831b71ff2f1673eaaf7c54ae9f8fb Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 20 Nov 2004 12:44:42 +0000 Subject: [PATCH] Add some missing bits from Mathias' carrier code. --- src/FDM/flight.cxx | 4 +++- src/Main/main.cxx | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index bd5a61ef9..a81ed437c 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -79,7 +79,9 @@ FGInterface::_calc_multiloop (double dt) dt += remainder; remainder = 0; double ml = dt * hz; - int multiloop = int(floor(ml)); + // Avoid roundoff problems by adding the roundoff itself. + // ... ok, two times the roundoff to have enough room. + int multiloop = int(floor(ml * (1.0 + 2.0*DBL_EPSILON))); remainder = (ml - multiloop) / hz; return (multiloop * speedup); } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 9bb5ff0f7..0d43799a6 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -240,6 +240,18 @@ static void fgMainLoop( void ) { real_delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0; + // round the real time down to a multiple of 1/model-hz. + // this way all systems are updated the _same_ amount of dt. + { + static double rem = 0.0; + real_delta_time_sec += rem; + double hz = model_hz; + double nit = floor(real_delta_time_sec*hz); + rem = real_delta_time_sec - nit/hz; + real_delta_time_sec = nit/hz; + } + + if ( clock_freeze->getBoolValue() ) { delta_time_sec = 0; } else { -- 2.39.5