From 4eecd088e80cd3858a61f1c4044853fd50af03eb Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 12 Mar 2021 14:45:25 +0000 Subject: [PATCH] TimeManager: handle reposition better Extend the timeManager unit-tests to check for some movements, all seems to work correctly now. --- src/Main/fg_init.cxx | 8 +++++--- src/Time/TimeManager.cxx | 6 ++++++ src/Time/TimeManager.hxx | 2 ++ test_suite/unit_tests/Main/test_timeManager.cxx | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index cd6a0d55a..325832405 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1241,9 +1241,11 @@ void fgStartReposition() globals->get_subsystem("xml-autopilot")->reinit(); // need to update the timezone - SGTime *t = globals->get_time_params(); - t->updateLocal(globals->get_aircraft_position(), globals->get_fg_root() / "Timezone"); - + auto timeManager = globals->get_subsystem(); + if (timeManager) { + timeManager->reposition(); + } + // setup state to end re-init fgSetBool("/sim/signals/reinit", false); if ( !freeze ) { diff --git a/src/Time/TimeManager.cxx b/src/Time/TimeManager.cxx index ad1b19d46..279fe9340 100644 --- a/src/Time/TimeManager.cxx +++ b/src/Time/TimeManager.cxx @@ -404,6 +404,12 @@ void TimeManager::throttleUpdateRate() _frameWait->setDoubleValue(frameWaitStart.elapsedMSec()); } +void TimeManager::reposition() +{ + // force a zone check, next update() + _lastTimeZoneCheckPosition = SGVec3d::zeros(); +} + // periodic time updater wrapper void TimeManager::updateLocalTime() { diff --git a/src/Time/TimeManager.hxx b/src/Time/TimeManager.hxx index d29b503c5..2cb292313 100644 --- a/src/Time/TimeManager.hxx +++ b/src/Time/TimeManager.hxx @@ -43,6 +43,8 @@ public: void unbind() override; void update(double dt) override; + void reposition(); + // Subsystem identification. static const char* staticSubsystemClassId() { return "time"; } diff --git a/test_suite/unit_tests/Main/test_timeManager.cxx b/test_suite/unit_tests/Main/test_timeManager.cxx index 86c38af5e..3798607dd 100644 --- a/test_suite/unit_tests/Main/test_timeManager.cxx +++ b/test_suite/unit_tests/Main/test_timeManager.cxx @@ -143,7 +143,7 @@ void TimeManagerTests::testTimeZones() timeManager->update(0.0); - CPPUNIT_ASSERT_EQUAL((time_t) 18000, globals->get_time_params()->get_local_offset()); + CPPUNIT_ASSERT_EQUAL((time_t)19800, globals->get_time_params()->get_local_offset()); auto gmt = globals->get_time_params()->getGmt(); CPPUNIT_ASSERT_EQUAL(79, gmt->tm_year); @@ -152,6 +152,21 @@ void TimeManagerTests::testTimeZones() // relocate to somewhere, check the time values update + + auto eddf = FGAirport::getByIdent("EDDF"); + FGTestApi::setPositionAndStabilise(eddf->geod()); + timeManager->reposition(); + timeManager->update(0.0); + + CPPUNIT_ASSERT_EQUAL((time_t)3600, globals->get_time_params()->get_local_offset()); + + + auto zbaa = FGAirport::getByIdent("ZBAA"); + FGTestApi::setPositionAndStabilise(zbaa->geod()); + timeManager->reposition(); + timeManager->update(0.0); + + CPPUNIT_ASSERT_EQUAL((time_t)28800, globals->get_time_params()->get_local_offset()); } void TimeManagerTests::testSpecifyTimeOffset()