mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Ref T268, simulator improvements
* use virtual function to emit setup signal * callback public so it can be used from "log display" for testing * sim. environment provider statistics
This commit is contained in:
@@ -17,7 +17,7 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const CLength &epsilon)
|
||||
bool ISimulationEnvironmentProvider::rememberGroundElevation(const CCallsign &requestedForCallsign, const ICoordinateGeodetic &elevationCoordinate, const CLength &epsilon)
|
||||
{
|
||||
{
|
||||
// no 2nd elevation nearby?
|
||||
@@ -29,17 +29,26 @@ namespace BlackMisc
|
||||
// we keep latest at front
|
||||
// * we assume we find them faster
|
||||
// * and need the more frequently (the recent ones)
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
QWriteLocker l(&m_lockElvCoordinates);
|
||||
if (m_elvCoordinates.size() > m_maxElevations) { m_elvCoordinates.pop_back(); }
|
||||
m_elvCoordinates.push_front(elevationCoordinate);
|
||||
if (m_pendingElevationRequests.contains(requestedForCallsign))
|
||||
{
|
||||
const qint64 startedMs = m_pendingElevationRequests.value(requestedForCallsign);
|
||||
const qint64 deltaMs = now - startedMs;
|
||||
m_pendingElevationRequests.remove(requestedForCallsign);
|
||||
m_statsCurrentElevRequestTimeMs = deltaMs;
|
||||
if (m_statsMaxElevRequestTimeMs < deltaMs) { m_statsMaxElevRequestTimeMs = deltaMs; }
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ISimulationEnvironmentProvider::rememberGroundElevation(const CElevationPlane &elevationPlane)
|
||||
bool ISimulationEnvironmentProvider::rememberGroundElevation(const CCallsign &requestedForCallsign, const CElevationPlane &elevationPlane)
|
||||
{
|
||||
if (!elevationPlane.hasMSLGeodeticHeight()) { return false; }
|
||||
return this->rememberGroundElevation(elevationPlane, elevationPlane.getRadius());
|
||||
return this->rememberGroundElevation(requestedForCallsign, elevationPlane, elevationPlane.getRadius());
|
||||
}
|
||||
|
||||
bool ISimulationEnvironmentProvider::insertCG(const CLength &cg, const CCallsign &cs)
|
||||
@@ -122,7 +131,7 @@ namespace BlackMisc
|
||||
CElevationPlane ISimulationEnvironmentProvider::findClosestElevationWithinRange(const ICoordinateGeodetic &reference, const CLength &range) const
|
||||
{
|
||||
// for single point we use a slightly optimized version
|
||||
const bool singlePoint = (&range == &CElevationPlane::singlePointRadius() || range <= CElevationPlane::singlePointRadius());
|
||||
const bool singlePoint = (&range == &CElevationPlane::singlePointRadius() || range.isNull() || range <= CElevationPlane::singlePointRadius());
|
||||
const CCoordinateGeodetic coordinate = singlePoint ?
|
||||
this->getElevationCoordinates().findFirstWithinRangeOrDefault(reference, CElevationPlane::singlePointRadius()) :
|
||||
this->getElevationCoordinates().findClosestWithinRange(reference, range);
|
||||
@@ -147,11 +156,19 @@ namespace BlackMisc
|
||||
const CElevationPlane ep = ISimulationEnvironmentProvider::findClosestElevationWithinRange(reference, range);
|
||||
if (ep.isNull())
|
||||
{
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
this->requestElevation(reference, callsign);
|
||||
QWriteLocker l(&m_lockElvCoordinates);
|
||||
m_pendingElevationRequests[callsign] = now;
|
||||
}
|
||||
return ep;
|
||||
}
|
||||
|
||||
bool ISimulationEnvironmentProvider::requestElevationBySituation(const CAircraftSituation &situation)
|
||||
{
|
||||
return this->requestElevation(situation, situation.getCallsign());
|
||||
}
|
||||
|
||||
QPair<int, int> ISimulationEnvironmentProvider::getElevationsFoundMissed() const
|
||||
{
|
||||
QReadLocker l(&m_lockElvCoordinates);
|
||||
@@ -168,6 +185,20 @@ namespace BlackMisc
|
||||
return info.arg(f).arg(m).arg(QString::number(hitRatioPercent, 'f', 1));
|
||||
}
|
||||
|
||||
QPair<qint64, qint64> ISimulationEnvironmentProvider::getElevationRequestTimes() const
|
||||
{
|
||||
QReadLocker l(&m_lockElvCoordinates);
|
||||
return QPair<qint64, qint64>(m_statsCurrentElevRequestTimeMs, m_statsMaxElevRequestTimeMs);
|
||||
}
|
||||
|
||||
QString ISimulationEnvironmentProvider::getElevationRequestTimesInfo() const
|
||||
{
|
||||
static const QString info("%1ms/%2ms");
|
||||
QPair<qint64, qint64> times = this->getElevationRequestTimes();
|
||||
if (times.first < 0 || times.second < 0) { return QStringLiteral("no req. times"); }
|
||||
return info.arg(times.first).arg(times.second);
|
||||
}
|
||||
|
||||
CSimulatorPluginInfo ISimulationEnvironmentProvider::getSimulatorPluginInfo() const
|
||||
{
|
||||
QReadLocker l(&m_lockSimInfo);
|
||||
@@ -217,19 +248,27 @@ namespace BlackMisc
|
||||
return m_cgsPerCallsign[callsign] == cg;
|
||||
}
|
||||
|
||||
int ISimulationEnvironmentProvider::setRememberMaxElevations(int max)
|
||||
int ISimulationEnvironmentProvider::setMaxElevationsRemembered(int max)
|
||||
{
|
||||
QWriteLocker l(&m_lockElvCoordinates);
|
||||
m_maxElevations = qMax(max, 50);
|
||||
return m_maxElevations;
|
||||
}
|
||||
|
||||
int ISimulationEnvironmentProvider::getRememberMaxElevations() const
|
||||
int ISimulationEnvironmentProvider::getMaxElevationsRemembered() const
|
||||
{
|
||||
QReadLocker l(&m_lockElvCoordinates);
|
||||
return m_maxElevations;
|
||||
}
|
||||
|
||||
void ISimulationEnvironmentProvider::resetSimulationEnvironmentStatistics()
|
||||
{
|
||||
QWriteLocker l(&m_lockElvCoordinates);
|
||||
m_statsCurrentElevRequestTimeMs = -1;
|
||||
m_statsMaxElevRequestTimeMs = -1;
|
||||
m_elvFound = m_elvMissed = 0;
|
||||
}
|
||||
|
||||
ISimulationEnvironmentProvider::ISimulationEnvironmentProvider(const CSimulatorPluginInfo &pluginInfo) : m_simulatorPluginInfo(pluginInfo)
|
||||
{ }
|
||||
|
||||
@@ -284,6 +323,9 @@ namespace BlackMisc
|
||||
{
|
||||
QWriteLocker l(&m_lockElvCoordinates);
|
||||
m_elvCoordinates.clear();
|
||||
m_pendingElevationRequests.clear();
|
||||
m_statsCurrentElevRequestTimeMs = -1;
|
||||
m_statsMaxElevRequestTimeMs = -1;
|
||||
m_elvFound = m_elvMissed = 0;
|
||||
}
|
||||
|
||||
@@ -299,6 +341,7 @@ namespace BlackMisc
|
||||
this->clearDefaultModel();
|
||||
this->clearElevations();
|
||||
this->clearCGs();
|
||||
this->resetSimulationEnvironmentStatistics();
|
||||
}
|
||||
|
||||
CElevationPlane CSimulationEnvironmentAware::findClosestElevationWithinRange(const ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range) const
|
||||
@@ -331,6 +374,18 @@ namespace BlackMisc
|
||||
return this->provider()->getElevationsFoundMissedInfo();
|
||||
}
|
||||
|
||||
QPair<qint64, qint64> CSimulationEnvironmentAware::getElevationRequestTimes() const
|
||||
{
|
||||
if (!this->hasProvider()) { return QPair<qint64, qint64>(-1, -1); }
|
||||
return this->provider()->getElevationRequestTimes();
|
||||
}
|
||||
|
||||
QString CSimulationEnvironmentAware::getElevationRequestTimesInfo() const
|
||||
{
|
||||
if (!this->hasProvider()) { return QString(); }
|
||||
return this->provider()->getElevationRequestTimesInfo();
|
||||
}
|
||||
|
||||
CSimulatorPluginInfo CSimulationEnvironmentAware::getSimulatorPluginInfo() const
|
||||
{
|
||||
if (!this->hasProvider()) { return CSimulatorPluginInfo(); }
|
||||
|
||||
@@ -14,10 +14,13 @@
|
||||
|
||||
#include "simulatorplugininfo.h"
|
||||
#include "aircraftmodel.h"
|
||||
#include "blackmisc/provider.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/aviation/percallsign.h"
|
||||
#include "blackmisc/geo/coordinategeodeticlist.h"
|
||||
#include "blackmisc/geo/elevationplane.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/provider.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
@@ -47,14 +50,26 @@ namespace BlackMisc
|
||||
//! \threadsafe
|
||||
virtual bool requestElevation(const Geo::ICoordinateGeodetic &reference, const Aviation::CCallsign &callsign) = 0;
|
||||
|
||||
//! Request elevation, there is no guarantee the requested elevation will be available in the provider
|
||||
//! \threadsafe
|
||||
bool requestElevationBySituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Elevations found/missed statistics
|
||||
//! \threadsafe
|
||||
QPair<int, int> getElevationsFoundMissed() const;
|
||||
|
||||
//! The elevation request times
|
||||
//! \threadsafe
|
||||
QPair<qint64, qint64> getElevationRequestTimes() const;
|
||||
|
||||
//! Elevations found/missed statistics info as string
|
||||
//! \threadsafe
|
||||
QString getElevationsFoundMissedInfo() const;
|
||||
|
||||
//! Elevation request times
|
||||
//! \threadsafe
|
||||
QString getElevationRequestTimesInfo() const;
|
||||
|
||||
//! Get the represented plugin
|
||||
//! \threadsafe
|
||||
CSimulatorPluginInfo getSimulatorPluginInfo() const;
|
||||
@@ -85,11 +100,15 @@ namespace BlackMisc
|
||||
|
||||
//! Set number of elevations kept
|
||||
//! \threadsafe
|
||||
int setRememberMaxElevations(int max);
|
||||
int setMaxElevationsRemembered(int max);
|
||||
|
||||
//! Get number of max. number of elevations
|
||||
//! \threadsafe
|
||||
int getRememberMaxElevations() const;
|
||||
int getMaxElevationsRemembered() const;
|
||||
|
||||
//! Reset statistics
|
||||
//! \threadsafe
|
||||
void resetSimulationEnvironmentStatistics();
|
||||
|
||||
protected:
|
||||
//! Ctor
|
||||
@@ -145,11 +164,11 @@ namespace BlackMisc
|
||||
|
||||
//! Remember a given elevation
|
||||
//! \threadsafe
|
||||
bool rememberGroundElevation(const Geo::ICoordinateGeodetic &elevationCoordinate, const PhysicalQuantities::CLength &epsilon = Geo::CElevationPlane::singlePointRadius()) ;
|
||||
bool rememberGroundElevation(const Aviation::CCallsign &requestedForCallsign, const Geo::ICoordinateGeodetic &elevationCoordinate, const PhysicalQuantities::CLength &epsilon = Geo::CElevationPlane::singlePointRadius());
|
||||
|
||||
//! Remember a given elevation
|
||||
//! \threadsafe
|
||||
bool rememberGroundElevation(const Geo::CElevationPlane &elevationPlane) ;
|
||||
bool rememberGroundElevation(const Aviation::CCallsign &requestedForCallsign, const Geo::CElevationPlane &elevationPlane) ;
|
||||
|
||||
//! Insert or replace a CG
|
||||
//! \remark passing a NULL value will remove the CG
|
||||
@@ -180,12 +199,15 @@ namespace BlackMisc
|
||||
QString m_simulatorVersion; //!< Simulator version
|
||||
CAircraftModel m_defaultModel; //!< default model
|
||||
int m_maxElevations = 100; //!< How many elevations we keep
|
||||
Geo::CCoordinateGeodeticList m_elvCoordinates;
|
||||
QHash<Aviation::CCallsign, PhysicalQuantities::CLength> m_cgsPerCallsign; //! CGs per callsign
|
||||
QHash<QString, PhysicalQuantities::CLength> m_cgsPerModel; //!< CGs per model string
|
||||
Geo::CCoordinateGeodeticList m_elvCoordinates; //!< elevation cache
|
||||
Aviation::CTimestampPerCallsign m_pendingElevationRequests; //!< pending elevation requests
|
||||
Aviation::CLengthPerCallsign m_cgsPerCallsign; //!< CGs per callsign
|
||||
QHash<QString, PhysicalQuantities::CLength> m_cgsPerModel; //!< CGs per model string
|
||||
qint64 m_statsMaxElevRequestTimeMs = -1;
|
||||
qint64 m_statsCurrentElevRequestTimeMs = -1;
|
||||
mutable int m_elvFound = 0; //!< statistics only
|
||||
mutable int m_elvMissed = 0; //!< statistics only
|
||||
mutable QReadWriteLock m_lockElvCoordinates; //!< lock m_coordinates
|
||||
mutable QReadWriteLock m_lockElvCoordinates; //!< lock m_coordinates, m_pendingElevationRequests
|
||||
mutable QReadWriteLock m_lockCG; //!< lock CGs
|
||||
mutable QReadWriteLock m_lockModel; //!< lock models
|
||||
mutable QReadWriteLock m_lockSimInfo; //!< lock plugin info
|
||||
@@ -213,6 +235,12 @@ namespace BlackMisc
|
||||
//! \copydoc ISimulationEnvironmentProvider::getElevationsFoundMissedInfo
|
||||
QString getElevationsFoundMissedInfo() const;
|
||||
|
||||
//! \copydoc ISimulationEnvironmentProvider::getElevationRequestTimes
|
||||
QPair<qint64, qint64> getElevationRequestTimes() const;
|
||||
|
||||
//! \copydoc ISimulationEnvironmentProvider::getElevationRequestTimesInfo
|
||||
QString getElevationRequestTimesInfo() const;
|
||||
|
||||
//! \copydoc ISimulationEnvironmentProvider::getSimulatorPluginInfo
|
||||
CSimulatorPluginInfo getSimulatorPluginInfo() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user