refs #863 Change callsign parameter to be a member instead.

This commit is contained in:
Mathew Sutcliffe
2017-02-06 19:20:37 +00:00
parent 8d351d8279
commit e67b5fccc4
9 changed files with 29 additions and 27 deletions

View File

@@ -37,14 +37,15 @@ namespace BlackMisc
namespace Simulation
{
template <typename Derived>
CInterpolator<Derived>::CInterpolator(const QString &objectName, QObject *parent) :
QObject(parent)
CInterpolator<Derived>::CInterpolator(const QString &objectName, const BlackMisc::Aviation::CCallsign &callsign, QObject *parent) :
QObject(parent),
m_callsign(callsign)
{
this->setObjectName(objectName);
}
template <typename Derived>
CAircraftSituation CInterpolator<Derived>::getInterpolatedSituation(const CCallsign &callsign, qint64 currentTimeMsSinceEpoc,
CAircraftSituation CInterpolator<Derived>::getInterpolatedSituation(qint64 currentTimeMsSinceEpoc,
const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, CInterpolationStatus &status)
{
status.reset();
@@ -113,7 +114,7 @@ namespace BlackMisc
if (hints.isLoggingInterpolation())
{
log.timestamp = currentTimeMsSinceEpoc;
log.callsign = callsign;
log.callsign = m_callsign;
log.vtolAircraft = hints.isVtolAircraft();
log.currentSituation = currentSituation;
log.useParts = hints.hasAircraftParts();
@@ -173,7 +174,7 @@ namespace BlackMisc
}
template <typename Derived>
CAircraftParts CInterpolator<Derived>::getInterpolatedParts(const CCallsign &callsign, qint64 currentTimeMsSinceEpoch,
CAircraftParts CInterpolator<Derived>::getInterpolatedParts(qint64 currentTimeMsSinceEpoch,
const CInterpolationAndRenderingSetup &setup, CPartsStatus &partsStatus, bool log)
{
Q_UNUSED(setup);
@@ -227,7 +228,7 @@ namespace BlackMisc
if (log)
{
PartsLog log;
log.callsign = callsign;
log.callsign = m_callsign;
log.timestamp = currentTimeMsSinceEpoch;
log.parts = currentParts;
CInterpolator::logParts(log);

View File

@@ -44,13 +44,11 @@ namespace BlackMisc
//! Current interpolated situation
BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, CInterpolationStatus &status);
qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, CInterpolationStatus &status);
//! Parts before given offset time (aka pending parts)
BlackMisc::Aviation::CAircraftParts getInterpolatedParts(
const Aviation::CCallsign &callsign, qint64 cutoffTime,
const CInterpolationAndRenderingSetup &setup, CPartsStatus &partsStatus, bool log = false);
qint64 cutoffTime, const CInterpolationAndRenderingSetup &setup, CPartsStatus &partsStatus, bool log = false);
//! Add a new aircraft situation
void addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
@@ -81,6 +79,7 @@ namespace BlackMisc
protected:
BlackMisc::Aviation::CAircraftSituationList m_aircraftSituations; //!< recent situations
BlackMisc::Aviation::CAircraftPartsList m_aircraftParts; //!< recent parts
BlackMisc::Aviation::CCallsign m_callsign; //!< callsign
//! Log for interpolation
struct InterpolationLog
@@ -108,7 +107,7 @@ namespace BlackMisc
};
//! Constructor
CInterpolator(const QString &objectName, QObject *parent);
CInterpolator(const QString &objectName, const BlackMisc::Aviation::CCallsign &callsign, QObject *parent);
//! Log current interpolation cycle, only stores in memory, for performance reasons
//! \remark const to allow const interpolator functions

View File

@@ -32,8 +32,8 @@ namespace BlackMisc
public:
//! Constructor
CInterpolatorLinear(QObject *parent = nullptr) :
CInterpolator("CInterpolatorLinear", parent)
CInterpolatorLinear(const BlackMisc::Aviation::CCallsign &callsign, QObject *parent = nullptr) :
CInterpolator("CInterpolatorLinear", callsign, parent)
{}
//! Linear function that performs the actual interpolation

View File

@@ -29,8 +29,8 @@ namespace BlackMisc
public:
//! Constructor
CInterpolatorSpline(QObject *parent = nullptr) :
CInterpolator("CInterpolatorSpline", parent)
CInterpolatorSpline(const BlackMisc::Aviation::CCallsign &callsign, QObject *parent = nullptr) :
CInterpolator("CInterpolatorSpline", callsign, parent)
{}
//! Cubic function that performs the actual interpolation

View File

@@ -122,6 +122,7 @@ namespace BlackSimPlugin
const CTime &updateInterval, QObject *owner) :
CDirectPlayPeer(owner, callsign),
m_updateInterval(updateInterval),
m_interpolator(callsign),
m_modelName(modelName)
{
}
@@ -184,7 +185,7 @@ namespace BlackSimPlugin
CInterpolationStatus status;
CInterpolationHints hints; // \fixme 201701 #865 KB if there is an elevation provider for FS9 add it here or set elevation
hints.setLoggingInterpolation(this->getInterpolationSetup().getLogCallsigns().contains(m_callsign));
const CAircraftSituation situation = this->m_interpolator.getInterpolatedSituation(m_callsign, -1, this->m_interpolationSetup, hints, status);
const CAircraftSituation situation = this->m_interpolator.getInterpolatedSituation(-1, this->m_interpolationSetup, hints, status);
// Test only for successful interpolation. FS9 requires constant positions
if (!status.didInterpolationSucceed()) { return; }

View File

@@ -22,7 +22,7 @@ namespace BlackSimPlugin
CSimConnectObject::CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, DWORD requestId) :
m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true),
m_interpolator(QSharedPointer<BlackMisc::Simulation::CInterpolatorLinear>::create())
m_interpolator(QSharedPointer<BlackMisc::Simulation::CInterpolatorLinear>::create(aircraft.getCallsign()))
{ }
bool CSimConnectObject::isPendingAdded() const

View File

@@ -903,14 +903,14 @@ namespace BlackSimPlugin
partsStatus.setSupportsParts(useAircraftParts);
const CInterpolationAndRenderingSetup setup(getInterpolationAndRenderingSetup());
const CAircraftParts parts = useAircraftParts ? simObj.getInterpolator()->getInterpolatedParts(callsign, -1, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
const CAircraftParts parts = useAircraftParts ? simObj.getInterpolator()->getInterpolatedParts(-1, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
// get interpolated situation
CInterpolationStatus interpolatorStatus;
CInterpolationHints hints(m_hints[simObj.getCallsign()]);
hints.setAircraftParts(useAircraftParts ? parts : CAircraftParts(), useAircraftParts);
hints.setLoggingInterpolation(logInterpolationAndParts);
const CAircraftSituation interpolatedSituation = simObj.getInterpolator()->getInterpolatedSituation(callsign, currentTimestamp, setup, hints, interpolatorStatus);
const CAircraftSituation interpolatedSituation = simObj.getInterpolator()->getInterpolatedSituation(currentTimestamp, setup, hints, interpolatorStatus);
if (interpolatorStatus.allTrue())
{

View File

@@ -16,6 +16,7 @@
#include "utils.h"
#include "blackmisc/simulation/interpolator.h"
#include "blackmisc/simulation/interpolationhints.h"
#include "blackmisc/aviation/callsign.h"
#include "XPMPMultiplayer.h"
#include <XPLM/XPLMProcessing.h>
#include <XPLM/XPLMUtilities.h>
@@ -28,7 +29,7 @@ namespace XBus
{
CTraffic::Plane::Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_)
: id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_)
: id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_), interpolator(callsign)
{
std::memset(static_cast<void *>(&surfaces), 0, sizeof(surfaces));
surfaces.lights.bcnLights = surfaces.lights.landLights = surfaces.lights.navLights = surfaces.lights.strbLights = 1;
@@ -49,7 +50,7 @@ namespace XBus
BlackMisc::Simulation::CInterpolationAndRenderingSetup setup;
BlackMisc::Simulation::CInterpolationHints hints;
BlackMisc::Simulation::CPartsStatus status;
hints.setAircraftParts(interpolator.getInterpolatedParts(callsign, -1, setup, status));
hints.setAircraftParts(interpolator.getInterpolatedParts(-1, setup, status));
hints.setElevationProvider([this](const auto & situation)
{
using namespace BlackMisc::PhysicalQuantities;
@@ -333,7 +334,7 @@ namespace XBus
{
BlackMisc::Simulation::CInterpolationAndRenderingSetup setup;
BlackMisc::Simulation::CInterpolationStatus status;
const auto situation = plane->interpolator.getInterpolatedSituation(plane->callsign, -1, setup, plane->hints(), status);
const auto situation = plane->interpolator.getInterpolatedSituation(-1, setup, plane->hints(), status);
if (! status.didInterpolationSucceed()) { return xpmpData_Unavailable; }
if (! status.hasChangedPosition()) { return xpmpData_Unchanged; }

View File

@@ -56,13 +56,13 @@ namespace BlackMiscTest
void CTestInterpolator::linearInterpolator()
{
CInterpolatorLinear interpolator;
CCallsign cs("SWIFT");
CInterpolatorLinear interpolator(cs);
// fixed time so everything can be debugged
const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch();
const qint64 deltaT = 5000; // ms
const qint64 offset = 5000;
CCallsign cs("SWIFT");
for (int i = 0; i < IRemoteAircraftProvider::MaxSituationsPerCallsign; i++)
{
CAircraftSituation s(getTestSituation(cs, i, ts, deltaT, offset));
@@ -95,7 +95,7 @@ namespace BlackMiscTest
// from: ts - 2 * deltaT + offset
// to: ts + offset
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
(cs, currentTime, setup, hints, status)
(currentTime, setup, hints, status)
);
QVERIFY2(status.didInterpolationSucceed(), "Interpolation was not succesful");
QVERIFY2(status.hasChangedPosition(), "Interpolation did not changed");
@@ -125,7 +125,7 @@ namespace BlackMiscTest
// from: ts - 2* deltaT + offset
// to: ts + offset
CAircraftSituation currentSituation(interpolator.getInterpolatedSituation
(cs, currentTime, setup, hints, status)
(currentTime, setup, hints, status)
);
QVERIFY2(status.allTrue(), "Failed interpolation");
QVERIFY2(currentSituation.getCallsign() == cs, "Wrong callsign");
@@ -145,7 +145,7 @@ namespace BlackMiscTest
for (qint64 currentTime = ts - 2 * deltaT; currentTime < ts; currentTime += 250)
{
CPartsStatus partsStatus;
CAircraftParts pl(interpolator.getInterpolatedParts(cs, ts, setup, partsStatus));
CAircraftParts pl(interpolator.getInterpolatedParts(ts, setup, partsStatus));
fetchedParts++;
QVERIFY2(partsStatus.isSupportingParts(), "Parts not supported");
}