Ref T259, Ref T243 misc. smaller improvements of simulator environment provider

This commit is contained in:
Klaus Basan
2018-03-22 16:49:29 +01:00
parent 4ec3a76ed4
commit bb34beed26
2 changed files with 44 additions and 8 deletions

View File

@@ -17,15 +17,20 @@ namespace BlackMisc
{ {
namespace Simulation namespace Simulation
{ {
bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const PhysicalQuantities::CLength &epsilon) bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const CLength &epsilon)
{ {
{ {
QReadLocker l(&m_lockElvCoordinates); QReadLocker l(&m_lockElvCoordinates);
if (m_elvCoordinates.containsObjectInRange(elevationCoordinate, epsilon)) { return false; } if (m_elvCoordinates.containsObjectInRange(elevationCoordinate, minRange(epsilon))) { return false; }
} }
{ {
// we keep latest at fron
// * we assume we find them faster
// * and need the more frequently (the recent ones)
QWriteLocker l(&m_lockElvCoordinates); QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinates.push_back(elevationCoordinate); if (m_elvCoordinates.size() > MaxElevations) { m_elvCoordinates.pop_back(); }
m_elvCoordinates.push_front(elevationCoordinate);
} }
return true; return true;
} }
@@ -40,13 +45,14 @@ namespace BlackMisc
{ {
if (cs.isEmpty()) { return false; } if (cs.isEmpty()) { return false; }
const bool remove = cg.isNull(); const bool remove = cg.isNull();
QWriteLocker l(&m_lockCG);
if (remove) if (remove)
{ {
QWriteLocker l(&m_lockCG);
m_cgs.remove(cs); m_cgs.remove(cs);
} }
else else
{ {
QWriteLocker l(&m_lockCG);
m_cgs[cs] = cg; m_cgs[cs] = cg;
} }
return true; return true;
@@ -58,6 +64,13 @@ namespace BlackMisc
return m_cgs.remove(cs); return m_cgs.remove(cs);
} }
CLength ISimulationEnvironmentProvider::minRange(const CLength &range)
{
return (range < CElevationPlane::singlePointRadius()) ?
CElevationPlane::singlePointRadius() :
range;
}
CCoordinateGeodeticList ISimulationEnvironmentProvider::getElevationCoordinates() const CCoordinateGeodeticList ISimulationEnvironmentProvider::getElevationCoordinates() const
{ {
QReadLocker l(&m_lockElvCoordinates); QReadLocker l(&m_lockElvCoordinates);
@@ -72,15 +85,17 @@ namespace BlackMisc
coordinates.sortByEuclideanDistanceSquared(referenceCoordinate); coordinates.sortByEuclideanDistanceSquared(referenceCoordinate);
coordinates.truncate(maxNumber); coordinates.truncate(maxNumber);
const int delta = size - coordinates.size(); const int delta = size - coordinates.size();
{
QWriteLocker l(&m_lockElvCoordinates); QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinates = coordinates; m_elvCoordinates = coordinates;
}
return delta; return delta;
} }
CElevationPlane ISimulationEnvironmentProvider::findClosestElevationWithinRange(const ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range) const CElevationPlane ISimulationEnvironmentProvider::findClosestElevationWithinRange(const ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range) const
{ {
const CLength r = range < CElevationPlane::singlePointRadius() ? CElevationPlane::singlePointRadius() : range; const CCoordinateGeodetic coordinate = this->getElevationCoordinates().findClosestWithinRange(reference, minRange(range));
return this->getElevationCoordinates().findClosestWithinRange(reference, r); return CElevationPlane(coordinate, reference); // plane with radis = distnace to reference
} }
CSimulatorPluginInfo ISimulationEnvironmentProvider::getSimulatorPluginInfo() const CSimulatorPluginInfo ISimulationEnvironmentProvider::getSimulatorPluginInfo() const
@@ -109,10 +124,18 @@ namespace BlackMisc
bool ISimulationEnvironmentProvider::hasCG(const Aviation::CCallsign &callsign) const bool ISimulationEnvironmentProvider::hasCG(const Aviation::CCallsign &callsign) const
{ {
if (callsign.isEmpty()) { return false; }
QReadLocker l(&m_lockCG); QReadLocker l(&m_lockCG);
return m_cgs.contains(callsign); return m_cgs.contains(callsign);
} }
bool ISimulationEnvironmentProvider::hasSameCG(const CLength &cg, const CCallsign &callsign) const
{
if (callsign.isEmpty()) { return false; }
QReadLocker l(&m_lockCG);
return m_cgs[callsign] == cg;
}
ISimulationEnvironmentProvider::ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo) : m_simulatorPluginInfo(pluginInfo) ISimulationEnvironmentProvider::ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo) : m_simulatorPluginInfo(pluginInfo)
{ } { }

View File

@@ -52,29 +52,39 @@ namespace BlackMisc
CAircraftModel getDefaultModel() const; CAircraftModel getDefaultModel() const;
//! Get CG per callsign, NULL if not found //! Get CG per callsign, NULL if not found
//! \threadsafe
PhysicalQuantities::CLength getCG(const Aviation::CCallsign &callsign) const; PhysicalQuantities::CLength getCG(const Aviation::CCallsign &callsign) const;
//! Has a CG? //! Has a CG?
//! \threadsafe
bool hasCG(const Aviation::CCallsign &callsign) const; bool hasCG(const Aviation::CCallsign &callsign) const;
//! Has the same CG?
//! \threadsafe
bool hasSameCG(const PhysicalQuantities::CLength &cg, const Aviation::CCallsign &callsign) const;
protected: protected:
//! Ctor //! Ctor
ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo); ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo);
//! 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
void setNewPluginInfo(const CSimulatorPluginInfo &info, const CAircraftModel &defaultModel); void setNewPluginInfo(const CSimulatorPluginInfo &info, const CAircraftModel &defaultModel);
//! Default model //! Default model
//! \threadsafe
void setDefaultModel(const CAircraftModel &defaultModel); void setDefaultModel(const CAircraftModel &defaultModel);
//! Clear default model //! Clear default model
//! \threadsafe
void clearDefaultModel(); void clearDefaultModel();
//! Clear elevations //! Clear elevations
void clearElevations(); void clearElevations();
//! Clear CGs //! Clear CGs
//! \threadsafe
void clearCGs(); void clearCGs();
//! Clear data //! Clear data
@@ -102,6 +112,9 @@ namespace BlackMisc
//! \threadsafe //! \threadsafe
int removeCG(const Aviation::CCallsign &cs); int removeCG(const Aviation::CCallsign &cs);
//! Min.range considered as single point
static PhysicalQuantities::CLength minRange(const PhysicalQuantities::CLength &range);
static constexpr int MaxElevations = 1000; //!< How many elevations we keep static constexpr int MaxElevations = 1000; //!< How many elevations we keep
private: private: