diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index d8f7c3111..192e1c9bd 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -1288,10 +1288,11 @@ namespace BlackCore // list from new to old QWriteLocker lock(&m_lockSituations); CAircraftSituationList &situationList = m_situationsByCallsign[callsign]; - situationList.push_frontMaxElements(situation, MaxSituationsPerCallsign); + situationList.push_frontMaxElements(situation, IRemoteAircraftProvider::MaxSituationsPerCallsign); // check sort order - Q_ASSERT_X(situationList.size() < 2 || situationList[0].getMSecsSinceEpoch() >= situationList[1].getMSecsSinceEpoch(), Q_FUNC_INFO, "wrong sort order"); + Q_ASSERT_X(situationList.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "wrong sort order"); + Q_ASSERT_X(situationList.size() <= IRemoteAircraftProvider::MaxSituationsPerCallsign, Q_FUNC_INFO, "Wrong size"); } void CAirspaceMonitor::storeAircraftParts(const CCallsign &callsign, const CAircraftParts &parts) @@ -1311,7 +1312,8 @@ namespace BlackCore m_aircraftSupportingParts.insert(callsign); // mark as callsign which supports parts // check sort order - Q_ASSERT_X(partsList.size() < 2 || partsList[0].getMSecsSinceEpoch() >= partsList[1].getMSecsSinceEpoch(), Q_FUNC_INFO, "wrong sort order"); + Q_ASSERT_X(partsList.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "wrong sort order"); + Q_ASSERT_X(partsList.size() <= IRemoteAircraftProvider::MaxPartsPerCallsign, Q_FUNC_INFO, "Wrong size"); } void CAirspaceMonitor::sendInitialAtcQueries(const CCallsign &callsign) diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index 7c85143c5..01ee6e159 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -236,9 +236,15 @@ namespace BlackMisc return emptyParts; } - // find the first parts not in the correct order, keep only the parts before that one - const auto end = std::is_sorted_until(m_aircraftParts.begin(), m_aircraftParts.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); - const auto validParts = makeRange(m_aircraftParts.begin(), end); + // with the latest updates of T243 the order and the offsets are supposed to be correct + // so even mixing fast/slow updates shall work + Q_ASSERT_X(m_aircraftParts.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order"); + + // Ref T243, KB 2018-02, can be removed in future, we verify parts above + // Parts are supposed to be in correct order + // const auto end = std::is_sorted_until(m_aircraftParts.begin(), m_aircraftParts.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); + // const auto validParts = makeRange(m_aircraftParts.begin(), end); + const CAircraftPartsList &validParts = m_aircraftParts; // stop if we don't have any parts if (validParts.isEmpty()) { return {}; } diff --git a/src/blackmisc/simulation/interpolatorlinear.cpp b/src/blackmisc/simulation/interpolatorlinear.cpp index 2c7986df7..b1a918fc0 100644 --- a/src/blackmisc/simulation/interpolatorlinear.cpp +++ b/src/blackmisc/simulation/interpolatorlinear.cpp @@ -17,6 +17,7 @@ #include "blackmisc/simulation/interpolationhints.h" #include "blackmisc/logmessage.h" #include "blackmisc/compare.h" +#include "blackmisc/verify.h" #include "blackmisc/range.h" #include "blackmisc/sequence.h" #include "blackmisc/statusmessage.h" @@ -55,12 +56,18 @@ namespace BlackMisc Q_UNUSED(hints); status.reset(); - // find the first situation not in the correct order, keep only the situations before that one - // any updates in wrong chronological order are discounted - const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); - const auto validSituations = makeRange(m_aircraftSituations.begin(), end); + // with the latest updates of T243 the order and the offsets are supposed to be correct + // so even mixing fast/slow updates shall work + BLACK_VERIFY_X(m_aircraftSituations.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order"); + Q_ASSERT_X(m_aircraftSituations.size() <= IRemoteAircraftProvider::MaxSituationsPerCallsign, Q_FUNC_INFO, "Wrong size"); + + // Ref T243, KB 2018-02, can be removed in future, we verify situations above + // Situations are supposed to be in correct order + // const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); + // const auto validSituations = makeRange(m_aircraftSituations.begin(), end); // find the first situation earlier than the current time + const CAircraftSituationList &validSituations = m_aircraftSituations; // if needed, we could also copy here const auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; }); const auto situationsNewer = makeRange(validSituations.begin(), pivot); const auto situationsOlder = makeRange(pivot, validSituations.end()); diff --git a/src/blackmisc/simulation/interpolatorspline.cpp b/src/blackmisc/simulation/interpolatorspline.cpp index 867cf3f30..3ee7da5ab 100644 --- a/src/blackmisc/simulation/interpolatorspline.cpp +++ b/src/blackmisc/simulation/interpolatorspline.cpp @@ -10,6 +10,7 @@ #include "blackmisc/simulation/interpolatorspline.h" #include "blackmisc/simulation/interpolationhints.h" #include "blackmisc/logmessage.h" +#include "blackmisc/verify.h" using namespace BlackMisc::Aviation; using namespace BlackMisc::Geo; @@ -104,15 +105,18 @@ namespace BlackMisc // recalculate derivatives only if they changed if (currentTimeMsSinceEpoc > m_nextSampleAdjustedTime) { - // find the first situation not in the correct order, keep only the situations before that one - //! \todo KB 2-2018, IMHO the sorting by adjusted times is wrong. we should sort by received time - // when mixing fast/slow updates, the postion is represented when it is sent, not when it is used - // see example below - // so why do we check here only, and do not sort - const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); - const auto validSituations = makeRange(m_aircraftSituations.begin(), end); + // with the latest updates of T243 the order and the offsets are supposed to be correct + // so even mixing fast/slow updates shall work + Q_ASSERT_X(m_aircraftSituations.isSortedAdjustedLatestFirst(), Q_FUNC_INFO, "Wrong sort order"); + Q_ASSERT_X(m_aircraftSituations.size() <= IRemoteAircraftProvider::MaxSituationsPerCallsign, Q_FUNC_INFO, "Wrong size"); + + // Ref T243, KB 2018-02, can be removed in future, we verify situations above + // Situations are supposed to be in correct order + // const auto end = std::is_sorted_until(m_aircraftSituations.begin(), m_aircraftSituations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); }); + // const auto validSituations = makeRange(m_aircraftSituations.begin(), end); // find the first situation earlier than the current time + const CAircraftSituationList &validSituations = m_aircraftSituations; // if needed, we could also copy here const auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; }); const auto situationsNewer = makeRange(validSituations.begin(), pivot); const auto situationsOlder = makeRange(pivot, validSituations.end());