mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
Ref T270, performance improvement by keeping less elevations cached
Rational: the idea was to keep track of ground elevations of all aircraft and hence using them for other aircraft on ground. But the "hit" ratio is bad, so we only keep a small number of elevations ("the last ones") and use those. The size of the cache is dynamically adjusted. Not moving aircraft are still found in that much smaller list.
This commit is contained in:
@@ -109,7 +109,12 @@ namespace BlackCore
|
|||||||
void ISimulator::rememberElevationAndCG(const CCallsign &callsign, const Geo::CElevationPlane &elevation, const CLength &cg)
|
void ISimulator::rememberElevationAndCG(const CCallsign &callsign, const Geo::CElevationPlane &elevation, const CLength &cg)
|
||||||
{
|
{
|
||||||
if (callsign.isEmpty()) { return; }
|
if (callsign.isEmpty()) { return; }
|
||||||
if (!elevation.isNull()) { this->rememberGroundElevation(elevation); }
|
if (!elevation.isNull())
|
||||||
|
{
|
||||||
|
const int aircraftCount = this->getAircraftInRangeCount();
|
||||||
|
this->setRememberMaxElevations(aircraftCount * 3); // at least 3 elevations per aircraft, even better as not all are requesting elevations
|
||||||
|
this->rememberGroundElevation(elevation);
|
||||||
|
}
|
||||||
if (!cg.isNull() && !this->hasSameCG(cg, callsign)) { this->insertCG(cg, callsign); }
|
if (!cg.isNull() && !this->hasSameCG(cg, callsign)) { this->insertCG(cg, callsign); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,9 +125,11 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
// decouple, follow up of signal can include unloading
|
// decouple, follow up of signal can include unloading
|
||||||
// simulator so this should happen strictly asyncronously (which is like forcing Qt::QueuedConnection)
|
// simulator so this should happen strictly asyncronously (which is like forcing Qt::QueuedConnection)
|
||||||
|
QPointer<ISimulator> myself(this);
|
||||||
QTimer::singleShot(0, this, [ = ]
|
QTimer::singleShot(0, this, [ = ]
|
||||||
{
|
{
|
||||||
emit this->simulatorStatusChanged(newStatus);
|
if (!myself) { return; }
|
||||||
|
emit myself->simulatorStatusChanged(newStatus);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace BlackMisc
|
|||||||
bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const CLength &epsilon)
|
bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const CLength &epsilon)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
// no 2nd elevation nearby
|
||||||
QReadLocker l(&m_lockElvCoordinates);
|
QReadLocker l(&m_lockElvCoordinates);
|
||||||
if (m_elvCoordinates.containsObjectInRange(elevationCoordinate, minRange(epsilon))) { return false; }
|
if (m_elvCoordinates.containsObjectInRange(elevationCoordinate, minRange(epsilon))) { return false; }
|
||||||
}
|
}
|
||||||
@@ -28,7 +29,7 @@ namespace BlackMisc
|
|||||||
// * we assume we find them faster
|
// * we assume we find them faster
|
||||||
// * and need the more frequently (the recent ones)
|
// * and need the more frequently (the recent ones)
|
||||||
QWriteLocker l(&m_lockElvCoordinates);
|
QWriteLocker l(&m_lockElvCoordinates);
|
||||||
if (m_elvCoordinates.size() > MaxElevations) { m_elvCoordinates.pop_back(); }
|
if (m_elvCoordinates.size() > m_maxElevations) { m_elvCoordinates.pop_back(); }
|
||||||
m_elvCoordinates.push_front(elevationCoordinate);
|
m_elvCoordinates.push_front(elevationCoordinate);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -76,9 +77,18 @@ namespace BlackMisc
|
|||||||
return m_elvCoordinates;
|
return m_elvCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CCoordinateGeodeticList ISimulationEnvironmentProvider::getElevationCoordinates(int &maxRemembered) const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockElvCoordinates);
|
||||||
|
maxRemembered = m_maxElevations;
|
||||||
|
return m_elvCoordinates;
|
||||||
|
}
|
||||||
|
|
||||||
int ISimulationEnvironmentProvider::cleanUpElevations(const ICoordinateGeodetic &referenceCoordinate, int maxNumber)
|
int ISimulationEnvironmentProvider::cleanUpElevations(const ICoordinateGeodetic &referenceCoordinate, int maxNumber)
|
||||||
{
|
{
|
||||||
CCoordinateGeodeticList coordinates(this->getElevationCoordinates());
|
int currentMax;
|
||||||
|
CCoordinateGeodeticList coordinates(this->getElevationCoordinates(currentMax));
|
||||||
|
if (maxNumber < 0) { maxNumber = currentMax; }
|
||||||
const int size = coordinates.size();
|
const int size = coordinates.size();
|
||||||
if (size <= maxNumber) { return 0; }
|
if (size <= maxNumber) { return 0; }
|
||||||
coordinates.sortByEuclideanDistanceSquared(referenceCoordinate);
|
coordinates.sortByEuclideanDistanceSquared(referenceCoordinate);
|
||||||
@@ -168,6 +178,19 @@ namespace BlackMisc
|
|||||||
return m_cgs[callsign] == cg;
|
return m_cgs[callsign] == cg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ISimulationEnvironmentProvider::setRememberMaxElevations(int max)
|
||||||
|
{
|
||||||
|
QWriteLocker l(&m_lockElvCoordinates);
|
||||||
|
m_maxElevations = qMax(max, 50);
|
||||||
|
return m_maxElevations;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ISimulationEnvironmentProvider::getRememberMaxElevations() const
|
||||||
|
{
|
||||||
|
QReadLocker l(&m_lockElvCoordinates);
|
||||||
|
return m_maxElevations;
|
||||||
|
}
|
||||||
|
|
||||||
ISimulationEnvironmentProvider::ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo) : m_simulatorPluginInfo(pluginInfo)
|
ISimulationEnvironmentProvider::ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo) : m_simulatorPluginInfo(pluginInfo)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! All remembered coordiantes
|
//! All remembered coordiantes
|
||||||
//! \remark might be a relatively large list
|
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
Geo::CCoordinateGeodeticList getElevationCoordinates() const;
|
Geo::CCoordinateGeodeticList getElevationCoordinates() const;
|
||||||
|
|
||||||
@@ -77,10 +76,22 @@ namespace BlackMisc
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
bool hasSameCG(const PhysicalQuantities::CLength &cg, const Aviation::CCallsign &callsign) const;
|
bool hasSameCG(const PhysicalQuantities::CLength &cg, const Aviation::CCallsign &callsign) const;
|
||||||
|
|
||||||
|
//! Set number of elevations kept
|
||||||
|
//! \threadsafe
|
||||||
|
int setRememberMaxElevations(int max);
|
||||||
|
|
||||||
|
//! Get number of max. number of elevations
|
||||||
|
//! \threadsafe
|
||||||
|
int getRememberMaxElevations() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Ctor
|
//! Ctor
|
||||||
ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo);
|
ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo);
|
||||||
|
|
||||||
|
//! All remembered coordiantes plus max remembered situations
|
||||||
|
//! \threadsafe
|
||||||
|
Geo::CCoordinateGeodeticList getElevationCoordinates(int &maxRemembered) const;
|
||||||
|
|
||||||
//! New plugin info and default model
|
//! New plugin info and default model
|
||||||
//! \remark normally only used by emulated driver
|
//! \remark normally only used by emulated driver
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
@@ -107,7 +118,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Only keep closest ones
|
//! Only keep closest ones
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
int cleanUpElevations(const Geo::ICoordinateGeodetic &referenceCoordinate, int maxNumber = MaxElevations);
|
int cleanUpElevations(const Geo::ICoordinateGeodetic &referenceCoordinate, int maxNumber = -1);
|
||||||
|
|
||||||
//! Remember a given elevation
|
//! Remember a given elevation
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
@@ -129,9 +140,8 @@ namespace BlackMisc
|
|||||||
//! Min.range considered as single point
|
//! Min.range considered as single point
|
||||||
static PhysicalQuantities::CLength minRange(const PhysicalQuantities::CLength &range);
|
static PhysicalQuantities::CLength minRange(const PhysicalQuantities::CLength &range);
|
||||||
|
|
||||||
static constexpr int MaxElevations = 1000; //!< How many elevations we keep
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int m_maxElevations = 100; //!< How many elevations we keep
|
||||||
CAircraftModel m_defaultModel; //!< default model
|
CAircraftModel m_defaultModel; //!< default model
|
||||||
CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object
|
CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object
|
||||||
Geo::CCoordinateGeodeticList m_elvCoordinates;
|
Geo::CCoordinateGeodeticList m_elvCoordinates;
|
||||||
|
|||||||
Reference in New Issue
Block a user