From 6c0c925fa23b0fcf43d49faace19dbd452349ffb Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 4 Jun 2018 17:49:13 +0200 Subject: [PATCH] Ref T273, Ref T275 compare equal parts/situation functions --- src/blackcore/simulatorcommon.cpp | 32 +++++++++++++++++++++++++++++++ src/blackcore/simulatorcommon.h | 30 ++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index b1298daec..5a4633f4e 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -650,6 +650,33 @@ namespace BlackCore m_statsLastUpdateAircraftRequested = startTime; } + bool CSimulatorCommon::isEqualLastSent(const CAircraftSituation &compare) const + { + Q_ASSERT_X(compare.hasCallsign(), Q_FUNC_INFO, "Need callsign"); + if (!m_lastSentSituation.contains(compare.getCallsign())) { return false; } + if (compare.isNull()) { return false; } + return compare.equalPbhAndVector(m_lastSentSituation.value(compare.getCallsign())); + } + + bool CSimulatorCommon::isEqualLastSent(const CAircraftParts &compare, const CCallsign &callsign) const + { + if (callsign.isEmpty()) { return false; } + if (!m_lastSentParts.contains(callsign)) { return false; } + return compare.equalValues(m_lastSentParts.value(callsign)); + } + + void CSimulatorCommon::rememberLastSent(const CAircraftSituation &sent) + { + Q_ASSERT_X(sent.hasCallsign(), Q_FUNC_INFO, "Need callsign"); + m_lastSentSituation.insert(sent.getCallsign(), sent); + } + + void CSimulatorCommon::rememberLastSent(const CAircraftParts &sent, const CCallsign &callsign) + { + Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Need callsign"); + m_lastSentParts.insert(callsign, sent); + } + void CSimulatorCommon::onRecalculatedRenderedAircraft(const CAirspaceAircraftSnapshot &snapshot) { if (!snapshot.isValidSnapshot()) { return;} @@ -732,6 +759,8 @@ namespace BlackCore m_addAgainAircraftWhenRemoved.clear(); m_callsignsToBeRendered.clear(); m_clampedLogMsg.clear(); + m_lastSentParts.clear(); + m_lastSentSituation.clear(); m_updateRemoteAircraftInProgress = false; this->resetHighlighting(); @@ -772,6 +801,9 @@ namespace BlackCore { m_statsPhysicallyRemovedAircraft++; m_clampedLogMsg.clear(); + m_lastSentParts.remove(remoteCallsign); + m_lastSentSituation.remove(remoteCallsign); + m_clampedLogMsg.remove(remoteCallsign); this->physicallyRemoveRemoteAircraft(remoteCallsign); } diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 0cb10e41b..a7ae46193 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -16,6 +16,7 @@ #include #include #include +#include #include "blackcore/aircraftmatcher.h" #include "blackcore/blackcoreexport.h" @@ -103,6 +104,13 @@ namespace BlackCore //! @} //! \copydoc ISimulator::parseCommandLine virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; + + //! \name Interface implementations, called from context + //! @{ + virtual bool logicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override; + virtual bool logicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; + //! @} + // --------- ISimulator implementations ------------ //! Register help @@ -142,12 +150,6 @@ namespace BlackCore BlackMisc::Network::IClientProvider *clientProvider, QObject *parent); - //! \name Interface implementations, called from context - //! @{ - virtual bool logicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override; - virtual bool logicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; - //! @} - //! \name When swift DB data are read //! @{ virtual void onSwiftDbAllDataRead(); @@ -235,6 +237,18 @@ namespace BlackCore //! Update stats and flags void setStatsRemoteAircraftUpdate(qint64 startTime); + //! Equal to last sent situation + bool isEqualLastSent(const BlackMisc::Aviation::CAircraftSituation &compare) const; + + //! Equal to last sent situation + bool isEqualLastSent(const BlackMisc::Aviation::CAircraftParts &compare, const BlackMisc::Aviation::CCallsign &callsign) const; + + //! Remember as last sent + void rememberLastSent(const BlackMisc::Aviation::CAircraftSituation &sent); + + //! Remember as last sent + void rememberLastSent(const BlackMisc::Aviation::CAircraftParts &sent, const BlackMisc::Aviation::CCallsign &callsign); + //! Lookup against DB data static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model); @@ -250,7 +264,9 @@ namespace BlackCore BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object BlackMisc::Simulation::CInterpolationLogger m_interpolationLogger; //!< log.interpolation - QMap m_clampedLogMsg; //!< when logged last so there, can be used so there is no log message overflow + QMap m_clampedLogMsg; //!< when logged last for this callsign, can be used so there is no log message overflow + QMap m_lastSentSituation; //!< last situation sent to simulator + QMap m_lastSentParts; //!< last parts sent to simulator // some optional functionality which can be used by the simulators as needed BlackMisc::Simulation::CSimulatedAircraftList m_addAgainAircraftWhenRemoved; //!< add this model again when removed, normally used to change model