mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #863 Each aircraft gets its own interpolator instance,
so each one can cache calculations from one frame to the next. The recent situations and parts are members of the interpolator.
This commit is contained in:
@@ -27,24 +27,19 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
IInterpolator::IInterpolator(IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent) :
|
||||
QObject(parent),
|
||||
CRemoteAircraftAware(provider)
|
||||
IInterpolator::IInterpolator(const QString &objectName, QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
Q_ASSERT_X(provider, Q_FUNC_INFO, "missing provider");
|
||||
this->setObjectName(objectName);
|
||||
}
|
||||
|
||||
BlackMisc::Aviation::CAircraftSituation IInterpolator::getInterpolatedSituation(
|
||||
const CCallsign &callsign, qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetup &setup,
|
||||
qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetup &setup,
|
||||
const CInterpolationHints &hints, InterpolationStatus &status) const
|
||||
{
|
||||
// has to be thread safe
|
||||
|
||||
status.reset();
|
||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign");
|
||||
|
||||
auto currentSituation = this->getInterpolatedSituation(callsign, this->remoteAircraftSituations(callsign), currentTimeSinceEpoc, setup, hints, status);
|
||||
auto currentSituation = this->getInterpolatedSituation(callsign, this->m_aircraftSituations, currentTimeSinceEpoc, setup, hints, status);
|
||||
currentSituation.setCallsign(callsign); // make sure callsign is correct
|
||||
return currentSituation;
|
||||
}
|
||||
@@ -116,9 +111,19 @@ namespace BlackMisc
|
||||
CAircraftParts IInterpolator::getInterpolatedParts(const CCallsign &callsign, qint64 currentTimeMsSinceEpoch,
|
||||
const CInterpolationAndRenderingSetup &setup, IInterpolator::PartsStatus &partsStatus, bool log) const
|
||||
{
|
||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign");
|
||||
partsStatus.reset();
|
||||
return this->getInterpolatedParts(callsign, this->remoteAircraftParts(callsign, -1), currentTimeMsSinceEpoch, setup, partsStatus, log);
|
||||
return this->getInterpolatedParts(callsign, this->m_aircraftParts, currentTimeMsSinceEpoch, setup, partsStatus, log);
|
||||
}
|
||||
|
||||
void IInterpolator::addAircraftSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
m_aircraftSituations.push_frontMaxElements(situation, IRemoteAircraftProvider::MaxSituationsPerCallsign);
|
||||
}
|
||||
|
||||
void IInterpolator::addAircraftParts(const CAircraftParts &parts)
|
||||
{
|
||||
m_aircraftParts.push_front(parts);
|
||||
IRemoteAircraftProvider::removeOutdatedParts(m_aircraftParts);
|
||||
}
|
||||
|
||||
CWorker *IInterpolator::writeLogInBackground()
|
||||
|
||||
@@ -32,9 +32,7 @@ namespace BlackMisc
|
||||
class CInterpolationHints;
|
||||
|
||||
//! Interpolator, calculation inbetween positions
|
||||
class BLACKMISC_EXPORT IInterpolator :
|
||||
public QObject,
|
||||
public BlackMisc::Simulation::CRemoteAircraftAware
|
||||
class BLACKMISC_EXPORT IInterpolator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -90,32 +88,33 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Current interpolated situation
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
|
||||
const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, InterpolationStatus &status) const;
|
||||
|
||||
//! Current interpolated situation, to be implemented by subclass
|
||||
//! \threadsafe
|
||||
//! \remark public only for XP driver
|
||||
virtual BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
|
||||
const BlackMisc::Aviation::CCallsign &callsign,
|
||||
const BlackMisc::Aviation::CAircraftSituationList &situations, qint64 currentTimeSinceEpoc,
|
||||
const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, InterpolationStatus &status) const = 0;
|
||||
|
||||
//! Parts before given offset time (aka pending parts)
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftParts getInterpolatedParts(
|
||||
const Aviation::CCallsign &callsign,
|
||||
const BlackMisc::Aviation::CAircraftPartsList &parts, qint64 cutoffTime,
|
||||
const CInterpolationAndRenderingSetup &setup, PartsStatus &partsStatus, bool log = false) const;
|
||||
|
||||
//! Parts before given offset time (aka pending parts)
|
||||
//! \threadsafe
|
||||
virtual BlackMisc::Aviation::CAircraftParts getInterpolatedParts(
|
||||
const BlackMisc::Aviation::CCallsign &callsign, qint64 cutoffTime,
|
||||
const CInterpolationAndRenderingSetup &setup, PartsStatus &partsStatus, bool log = false) const;
|
||||
|
||||
//! Add a new aircraft situation
|
||||
void addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Add a new aircraft parts
|
||||
void addAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts);
|
||||
|
||||
//! Write a log in background
|
||||
//! \threadsafe
|
||||
BlackMisc::CWorker *writeLogInBackground();
|
||||
@@ -137,6 +136,9 @@ namespace BlackMisc
|
||||
static QStringList getLatestLogFiles();
|
||||
|
||||
protected:
|
||||
BlackMisc::Aviation::CAircraftSituationList m_aircraftSituations; //!< recent situations
|
||||
BlackMisc::Aviation::CAircraftPartsList m_aircraftParts; //!< recent parts
|
||||
|
||||
//! Log for interpolation
|
||||
struct InterpolationLog
|
||||
{
|
||||
@@ -163,7 +165,7 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
IInterpolator(BlackMisc::Simulation::IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent);
|
||||
IInterpolator(const QString &objectName, QObject *parent);
|
||||
|
||||
//! Log current interpolation cycle, only stores in memory, for performance reasons
|
||||
//! \remark const to allow const interpolator functions
|
||||
|
||||
@@ -43,9 +43,6 @@ namespace BlackMisc
|
||||
CAircraftSituation CInterpolatorLinear::getInterpolatedSituation(const CCallsign &callsign, const CAircraftSituationList &situations, qint64 currentTimeMsSinceEpoc,
|
||||
const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, InterpolationStatus &status) const
|
||||
{
|
||||
//
|
||||
// function has to be thread safe
|
||||
//
|
||||
status.reset();
|
||||
|
||||
// any data at all?
|
||||
|
||||
@@ -25,15 +25,13 @@ namespace BlackMisc
|
||||
namespace Aviation { class CCallsign; }
|
||||
namespace Simulation
|
||||
{
|
||||
class IRemoteAircraftProvider;
|
||||
|
||||
//! Linear interpolator, calculation inbetween positions
|
||||
class BLACKMISC_EXPORT CInterpolatorLinear : public IInterpolator
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CInterpolatorLinear(BlackMisc::Simulation::IRemoteAircraftProvider *provider, QObject *parent = nullptr) :
|
||||
IInterpolator(provider, "CInterpolatorLinear", parent)
|
||||
CInterpolatorLinear(QObject *parent = nullptr) :
|
||||
IInterpolator("CInterpolatorLinear", parent)
|
||||
{}
|
||||
|
||||
// public base class signature
|
||||
|
||||
Reference in New Issue
Block a user