refs #865, use same function for removing outdated aircraft parts

* in airspace monitor
* in XP traffic.cpp
This commit is contained in:
Klaus Basan
2017-01-26 17:18:27 +01:00
committed by Mathew Sutcliffe
parent 309d593607
commit e3d81c6c44
4 changed files with 19 additions and 15 deletions

View File

@@ -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