From e3d81c6c44cc6f989ffb96acdc5808217b23c69b Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 26 Jan 2017 17:18:27 +0100 Subject: [PATCH] refs #865, use same function for removing outdated aircraft parts * in airspace monitor * in XP traffic.cpp --- src/blackcore/airspacemonitor.cpp | 10 ++++------ src/blackmisc/simulation/remoteaircraftprovider.cpp | 6 ++++++ src/blackmisc/simulation/remoteaircraftprovider.h | 5 ++++- src/xbus/traffic.cpp | 13 +++++-------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 368937c33..ecf2ffbdf 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -1240,14 +1240,12 @@ namespace BlackCore QWriteLocker lock(&m_lockParts); CAircraftPartsList &partsList = this->m_partsByCallsign[callsign]; partsList.push_front(parts); - - // remove outdated parts (but never remove the most recent one) - const auto predicate = [now = parts.getMSecsSinceEpoch()](const auto & p) { return p.getMSecsSinceEpoch() >= now - PartsPerCallsignMaxAgeInSeconds * 1000; }; - const auto newEnd = std::find_if(partsList.rbegin(), partsList.rend(), predicate).base(); - partsList.erase(newEnd, partsList.end()); - partsList.front().setTimeOffsetMs(timeOffsetMs); + // remove outdated parts (but never remove the most recent one) + IRemoteAircraftProvider::removeOutdatedParts(partsList); + + // aircraft supporting parts if (!m_aircraftSupportingParts.contains(callsign)) { m_aircraftSupportingParts.push_back(callsign); // mark as callsign which supports parts diff --git a/src/blackmisc/simulation/remoteaircraftprovider.cpp b/src/blackmisc/simulation/remoteaircraftprovider.cpp index 77c3ff936..86abeb112 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.cpp +++ b/src/blackmisc/simulation/remoteaircraftprovider.cpp @@ -118,5 +118,11 @@ namespace BlackMisc return this->m_remoteAircraftProvider->updateAircraftEnabled(callsign, enabledForRedering); } + void IRemoteAircraftProvider::removeOutdatedParts(CAircraftPartsList &partsList) + { + const auto predicate = [now = partsList.front().getMSecsSinceEpoch()](const auto & p) { return p.getMSecsSinceEpoch() >= now - PartsPerCallsignMaxAgeInSeconds * 1000; }; + const auto newEnd = std::find_if(partsList.rbegin(), partsList.rend(), predicate).base(); + partsList.erase(newEnd, partsList.end()); + } } // namespace } // namespace diff --git a/src/blackmisc/simulation/remoteaircraftprovider.h b/src/blackmisc/simulation/remoteaircraftprovider.h index b6088d420..faef2450c 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.h +++ b/src/blackmisc/simulation/remoteaircraftprovider.h @@ -48,7 +48,7 @@ namespace BlackMisc { public: static constexpr int MaxSituationsPerCallsign = 6; //!< How many situations per callsign - static constexpr int PartsPerCallsignMaxAgeInSeconds = 20; //!< How many seconds to keep parts for + static constexpr int PartsPerCallsignMaxAgeInSeconds = 20; //!< How many seconds to keep parts for interpolation //! Situations per callsign using CSituationsPerCallsign = QHash; @@ -165,6 +165,9 @@ namespace BlackMisc std::function removedAircraftSlot, std::function aircraftSnapshot ) = 0; + + //! Remove outdated aircraft parts + void static removeOutdatedParts(Aviation::CAircraftPartsList &partsList); }; //! Class which can be directly used to access an \sa IRemoteAircraftProvider object diff --git a/src/xbus/traffic.cpp b/src/xbus/traffic.cpp index 267413ed4..c6f8d1d23 100644 --- a/src/xbus/traffic.cpp +++ b/src/xbus/traffic.cpp @@ -32,7 +32,7 @@ namespace XBus CTraffic::Plane::Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_) : id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_) { - std::memset(static_cast(&surfaces), 0, sizeof(surfaces)); + std::memset(static_cast(&surfaces), 0, sizeof(surfaces)); surfaces.lights.bcnLights = surfaces.lights.landLights = surfaces.lights.navLights = surfaces.lights.strbLights = 1; surfaces.size = sizeof(surfaces); @@ -51,7 +51,7 @@ namespace XBus BlackMisc::Simulation::CInterpolationHints hints; BlackMisc::Simulation::IInterpolator::PartsStatus status; hints.setAircraftParts(interpolator->getInterpolatedParts(callsign, parts, -1, status)); - hints.setElevationProvider([this](const auto &situation) + hints.setElevationProvider([this](const auto & situation) { using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Aviation; @@ -85,7 +85,7 @@ namespace XBus auto dir = g_xplanePath + "Resources" + g_sep + "plugins" + g_sep + "xbus" + g_sep + "LegacyData" + g_sep; auto err = XPMPMultiplayerInitLegacyData(qPrintable(dir + "CSL"), qPrintable(dir + "related.txt"), - qPrintable(dir + "lights.png"), qPrintable(dir + "Doc8643.txt"), "C172", preferences, preferences); + qPrintable(dir + "lights.png"), qPrintable(dir + "Doc8643.txt"), "C172", preferences, preferences); if (*err) { s_legacyDataOK = false; } } @@ -274,7 +274,7 @@ namespace XBus } void CTraffic::addPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, - double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime) + double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime) { const auto plane = m_planesByCallsign.value(callsign, nullptr); if (plane) @@ -301,10 +301,7 @@ namespace XBus plane->parts.front().setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch()); // remove outdated parts (but never remove the most recent one) - enum { maxAgeMs = BlackMisc::Simulation::IRemoteAircraftProvider::PartsPerCallsignMaxAgeInSeconds * 1000 }; // enum because MSVC constexpr bug - const auto predicate = [now = plane->parts.front().getMSecsSinceEpoch()](auto && p) { return p.getMSecsSinceEpoch() >= now - maxAgeMs; }; - const auto newEnd = std::find_if(plane->parts.rbegin(), plane->parts.rend(), predicate).base(); - plane->parts.erase(newEnd, plane->parts.end()); + BlackMisc::Simulation::IRemoteAircraftProvider::removeOutdatedParts(plane->parts); } }