From c6f3d4e2f224edc1b4bfaa134486099d36b10f71 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 2 Jun 2018 14:16:50 +0200 Subject: [PATCH] Ref T270, mark interpolator as unit test * if we use "recycled" parts, we have to store also the last status * mark unit test so "recycling" is disabled * status flag for "reused" --- src/blackmisc/simulation/interpolator.cpp | 4 ++++ src/blackmisc/simulation/interpolator.h | 8 ++++++++ tests/blackmisc/testinterpolatorlinear.cpp | 5 +++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index e8f8f3667..779336eaf 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -292,6 +292,8 @@ namespace BlackMisc Q_ASSERT_X(m_partsToSituationInterpolationRatio >= 1 && m_partsToSituationInterpolationRatio < 11, Q_FUNC_INFO, "Wrong ratio"); if (!m_unitTest && !m_lastParts.isNull() && ((m_interpolatedSituationsCounter + aircraftNumber) % m_partsToSituationInterpolationRatio) == 0) { + m_currentPartsStatus = m_lastPartsStatus; + m_currentPartsStatus.setReusedParts(true); return m_lastParts; } @@ -312,6 +314,7 @@ namespace BlackMisc } m_lastParts = parts; + m_lastPartsStatus = m_currentPartsStatus; return parts; } @@ -513,6 +516,7 @@ namespace BlackMisc void CPartsStatus::reset() { m_supportsParts = false; + m_resusedParts = false; } // see here for the reason of thess forward instantiations diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h index 5255fc26a..41217bd43 100644 --- a/src/blackmisc/simulation/interpolator.h +++ b/src/blackmisc/simulation/interpolator.h @@ -96,11 +96,18 @@ namespace BlackMisc //! Set support flag void setSupportsParts(bool supports) { m_supportsParts = supports; } + //! Is a reused parts, means using last value again + bool isReusedPArts() const { return m_resusedParts; } + + //! Mark as reused + void setReusedParts(bool reused) { m_resusedParts = reused; } + //! Reset to default values void reset(); private: bool m_supportsParts = false; //!< supports parts for given callsign + bool m_resusedParts = false; //!< reusing from last step }; //! Combined results @@ -248,6 +255,7 @@ namespace BlackMisc CInterpolationAndRenderingSetupPerCallsign m_currentSetup; //!< used setup CInterpolationStatus m_currentInterpolationStatus; //!< this step's status CPartsStatus m_currentPartsStatus; //!< this step's status + CPartsStatus m_lastPartsStatus; //!< status for last parts, used when last parts are re-used because of m_partsToSituationInterpolationRatio int m_partsToSituationInterpolationRatio = 2; //!< ratio between parts and situation interpolation, 1..always, 2..every 2nd situation Aviation::CAircraftSituation m_lastSituation { Aviation::CAircraftSituation::null() }; //!< latest interpolation Aviation::CAircraftParts m_lastParts { Aviation::CAircraftParts::null() }; //!< latest parts diff --git a/tests/blackmisc/testinterpolatorlinear.cpp b/tests/blackmisc/testinterpolatorlinear.cpp index 9d787a5d7..e6c26bd36 100644 --- a/tests/blackmisc/testinterpolatorlinear.cpp +++ b/tests/blackmisc/testinterpolatorlinear.cpp @@ -54,10 +54,10 @@ namespace BlackMiscTest { void CTestInterpolatorLinear::basicInterpolatorTests() { - CCallsign cs("SWIFT"); + const CCallsign cs("SWIFT"); CRemoteAircraftProviderDummy provider; CInterpolatorLinear interpolator(cs, nullptr, nullptr, &provider); - // interpolator.markAsUnitTest(); + interpolator.markAsUnitTest(); // fixed time so everything can be debugged const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch(); @@ -115,6 +115,7 @@ namespace BlackMiscTest // With one callsign in the lists (of dummy provider) it is somehow expected to be roughly the same performance interpolator.resetLastInterpolation(); + interpolator.markAsUnitTest(); for (int loops = 0; loops < 20; loops++) { for (qint64 currentTime = startTimeMsSinceEpoch + offset; currentTime < ts + offset; currentTime += (deltaT / 20))