mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
refs #667 XBus: use the thread-agnostic interpolator method, to avoid an unnecessary dynamic memory allocation.
This commit is contained in:
@@ -42,30 +42,9 @@ namespace XBus
|
|||||||
surfaces.lights.timeOffset = static_cast<quint16>(qrand() % 0xffff);
|
surfaces.lights.timeOffset = static_cast<quint16>(qrand() % 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CTraffic::AircraftProvider : public BlackMisc::Simulation::CRemoteAircraftProviderDummy
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//! Constructor.
|
|
||||||
AircraftProvider(QObject *parent = nullptr) : CRemoteAircraftProviderDummy(parent) {}
|
|
||||||
|
|
||||||
//! \copydoc IRemoteAircraftProvider::remoteAircraftSituations
|
|
||||||
//! \todo return reference not copy, thread safety not needed
|
|
||||||
virtual BlackMisc::Aviation::CAircraftSituationList remoteAircraftSituations(const BlackMisc::Aviation::CCallsign &) const override { return *m_situations; }
|
|
||||||
|
|
||||||
//! \copydoc IRemoteAircraftProvider::remoteAircraftSituationsCount
|
|
||||||
virtual int remoteAircraftSituationsCount(const BlackMisc::Aviation::CCallsign &) const override { return m_situations->size(); }
|
|
||||||
|
|
||||||
//! Inject the situations to be interpolated (for performance, no lookup by callsign).
|
|
||||||
void setSituations(const BlackMisc::Aviation::CAircraftSituationList *situations) { m_situations = situations; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const BlackMisc::Aviation::CAircraftSituationList *m_situations = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
CTraffic::CTraffic(QObject *parent) :
|
CTraffic::CTraffic(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_provider(new AircraftProvider(this)),
|
m_interpolator(new BlackMisc::CInterpolatorLinear(new BlackMisc::Simulation::CRemoteAircraftProviderDummy(this), this))
|
||||||
m_interpolator(new BlackMisc::CInterpolatorLinear(m_provider, this))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,8 +307,7 @@ namespace XBus
|
|||||||
case xpmpDataType_Position:
|
case xpmpDataType_Position:
|
||||||
{
|
{
|
||||||
BlackMisc::IInterpolator::InterpolationStatus status;
|
BlackMisc::IInterpolator::InterpolationStatus status;
|
||||||
m_provider->setSituations(&plane->situations);
|
auto situation = m_interpolator->getInterpolatedSituation(plane->situations, -1, false, status);
|
||||||
auto situation = m_interpolator->getInterpolatedSituation(plane->callsign, -1, false, status);
|
|
||||||
if (! status.interpolationSucceeded) { return xpmpData_Unavailable; }
|
if (! status.interpolationSucceeded) { return xpmpData_Unavailable; }
|
||||||
if (! status.changedPosition) { return xpmpData_Unchanged; }
|
if (! status.changedPosition) { return xpmpData_Unchanged; }
|
||||||
|
|
||||||
|
|||||||
@@ -144,8 +144,6 @@ namespace XBus
|
|||||||
return static_cast<CTraffic *>(self)->getPlaneData(id, dataType, io_data);
|
return static_cast<CTraffic *>(self)->getPlaneData(id, dataType, io_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AircraftProvider;
|
|
||||||
AircraftProvider *m_provider = nullptr;
|
|
||||||
BlackMisc::IInterpolator *m_interpolator = nullptr;
|
BlackMisc::IInterpolator *m_interpolator = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user