mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
refs #865, use same function for removing outdated aircraft parts
* in airspace monitor * in XP traffic.cpp
This commit is contained in:
committed by
Mathew Sutcliffe
parent
309d593607
commit
e3d81c6c44
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftSituationList>;
|
||||
@@ -165,6 +165,9 @@ namespace BlackMisc
|
||||
std::function<void(const BlackMisc::Aviation::CCallsign &)> removedAircraftSlot,
|
||||
std::function<void(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &)> aircraftSnapshot
|
||||
) = 0;
|
||||
|
||||
//! Remove outdated aircraft parts
|
||||
void static removeOutdatedParts(Aviation::CAircraftPartsList &partsList);
|
||||
};
|
||||
|
||||
//! Class which can be directly used to access an \sa IRemoteAircraftProvider object
|
||||
|
||||
@@ -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<void*>(&surfaces), 0, sizeof(surfaces));
|
||||
std::memset(static_cast<void *>(&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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user