mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 21:45:34 +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:
@@ -381,8 +381,9 @@ namespace BlackCore
|
||||
}
|
||||
if (p == "clear" || p == "clr")
|
||||
{
|
||||
this->m_interpolator->clearLog();
|
||||
CStatusMessage(this).info("Cleared interpolation logging");
|
||||
//! \todo refactoring broken by rebase
|
||||
//this->m_interpolator->clearLog();
|
||||
//CStatusMessage(this).info("Cleared interpolation logging");
|
||||
return true;
|
||||
}
|
||||
if (p == "write" || p == "save")
|
||||
@@ -391,8 +392,9 @@ namespace BlackCore
|
||||
this->m_interpolationRenderingSetup.clearInterpolatorLogCallsigns();
|
||||
|
||||
// write
|
||||
this->m_interpolator->writeLogInBackground();
|
||||
CLogMessage(this).info("Started writing interpolation log");
|
||||
//! \todo refactoring broken by rebase
|
||||
//this->m_interpolator->writeLogInBackground();
|
||||
//CLogMessage(this).info("Started writing interpolation log");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,6 @@ namespace BlackCore
|
||||
//! Parse driver specific details for ISimulator::parseCommandLine
|
||||
virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser);
|
||||
|
||||
BlackMisc::Simulation::IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< default model
|
||||
qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -119,9 +119,10 @@ namespace BlackSimPlugin
|
||||
}
|
||||
|
||||
CFs9Client::CFs9Client(const CCallsign &callsign, const QString &modelName,
|
||||
BlackMisc::Simulation::IInterpolator *interpolator, const CTime &updateInterval, QObject *owner) :
|
||||
const CTime &updateInterval, QObject *owner) :
|
||||
CDirectPlayPeer(owner, callsign),
|
||||
m_updateInterval(updateInterval), m_interpolator(interpolator), m_modelName(modelName)
|
||||
m_updateInterval(updateInterval),
|
||||
m_modelName(modelName)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -177,14 +178,13 @@ namespace BlackSimPlugin
|
||||
void CFs9Client::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
Q_ASSERT_X(m_interpolator, Q_FUNC_INFO, "Missing interpolator");
|
||||
|
||||
if (m_clientStatus == Disconnected) { return; }
|
||||
|
||||
IInterpolator::InterpolationStatus status;
|
||||
CInterpolationHints hints; // \fixme 201701 #865 KB if there is an elevation provider for FS9 add it here or set elevation
|
||||
hints.setLoggingInterpolation(this->m_interpolator->getInterpolatorSetup().getLogCallsigns().contains(m_callsign));
|
||||
const CAircraftSituation situation = this->m_interpolator->getInterpolatedSituation(m_callsign, -1, this->m_interpolationSetup, hints, status);
|
||||
hints.setLoggingInterpolation(this->getInterpolationSetup().getLogCallsigns().contains(m_callsign));
|
||||
const CAircraftSituation situation = this->m_interpolator.getInterpolatedSituation(m_callsign, -1, this->m_interpolationSetup, hints, status);
|
||||
|
||||
// Test only for successful interpolation. FS9 requires constant positions
|
||||
if (!status.didInterpolationSucceed()) { return; }
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define DIRECTPLAY_CLIENT_H
|
||||
|
||||
#include "directplaypeer.h"
|
||||
#include "blackmisc/simulation/interpolator.h"
|
||||
#include "blackmisc/simulation/interpolatorlinear.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
@@ -41,8 +41,7 @@ namespace BlackSimPlugin
|
||||
|
||||
//! Constructor
|
||||
CFs9Client(const BlackMisc::Aviation::CCallsign &callsign, const QString &modelName,
|
||||
BlackMisc::Simulation::IInterpolator *interpolator, const BlackMisc::PhysicalQuantities::CTime &updateInterval,
|
||||
QObject *owner);
|
||||
const BlackMisc::PhysicalQuantities::CTime &updateInterval, QObject *owner);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CFs9Client();
|
||||
@@ -50,6 +49,9 @@ namespace BlackSimPlugin
|
||||
//! Set DirectPlay host address
|
||||
void setHostAddress(const QString &hostAddress);
|
||||
|
||||
//! Get interpolator
|
||||
BlackMisc::Simulation::IInterpolator *getInterpolator() { return &m_interpolator; }
|
||||
|
||||
//! Set interpolation setup
|
||||
//! \threadsafe
|
||||
void setInterpolationSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup);
|
||||
@@ -95,7 +97,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationSetup() const;
|
||||
|
||||
BlackMisc::PhysicalQuantities::CTime m_updateInterval;
|
||||
BlackMisc::Simulation::IInterpolator *m_interpolator = nullptr;
|
||||
BlackMisc::Simulation::CInterpolatorLinear m_interpolator;
|
||||
BlackMisc::Simulation::CInterpolationAndRenderingSetup m_interpolationSetup;
|
||||
mutable QReadWriteLock m_interpolationSetupMutex;
|
||||
QString m_modelName;
|
||||
|
||||
@@ -112,7 +112,6 @@ namespace BlackSimPlugin
|
||||
m_lobbyClient(lobbyClient)
|
||||
{
|
||||
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
|
||||
m_interpolator = new CInterpolatorLinear(remoteAircraftProvider, this);
|
||||
m_defaultModel =
|
||||
{
|
||||
"Boeing 737-400",
|
||||
@@ -172,7 +171,7 @@ namespace BlackSimPlugin
|
||||
|
||||
bool rendered = true;
|
||||
updateAircraftRendered(callsign, rendered);
|
||||
CFs9Client *client = new CFs9Client(callsign, newRemoteAircraft.getModelString(), m_interpolator, CTime(25, CTimeUnit::ms()), this);
|
||||
CFs9Client *client = new CFs9Client(callsign, newRemoteAircraft.getModelString(), CTime(25, CTimeUnit::ms()), this);
|
||||
client->setHostAddress(m_fs9Host->getHostAddress());
|
||||
client->setPlayerUserId(m_fs9Host->getPlayerUserId());
|
||||
client->start();
|
||||
@@ -391,6 +390,20 @@ namespace BlackSimPlugin
|
||||
m_fsuipc->write(weatherGrid);
|
||||
}
|
||||
|
||||
void CSimulatorFs9::ps_remoteProviderAddAircraftSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
const auto it = m_hashFs9Clients.find(situation.getCallsign());
|
||||
if (it == m_hashFs9Clients.end()) { return; }
|
||||
QTimer::singleShot(0, it->data(), [client = *it, situation] { client->getInterpolator()->addAircraftSituation(situation); });
|
||||
}
|
||||
|
||||
void CSimulatorFs9::ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftParts &parts)
|
||||
{
|
||||
const auto it = m_hashFs9Clients.find(callsign);
|
||||
if (it == m_hashFs9Clients.end()) { return; }
|
||||
QTimer::singleShot(0, it->data(), [client = *it, parts] { client->getInterpolator()->addAircraftParts(parts); });
|
||||
}
|
||||
|
||||
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info,
|
||||
const QSharedPointer<CFs9Host> &fs9Host,
|
||||
const QSharedPointer<CLobbyClient> &lobbyClient) :
|
||||
|
||||
@@ -76,6 +76,8 @@ namespace BlackSimPlugin
|
||||
//! \name Base class overrides
|
||||
//! @{
|
||||
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override;
|
||||
virtual void ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
|
||||
virtual void ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts) override;
|
||||
//! @}
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "simconnectobject.h"
|
||||
#include "blackmisc/simulation/interpolatorlinear.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
@@ -16,10 +17,12 @@ namespace BlackSimPlugin
|
||||
{
|
||||
namespace Fsx
|
||||
{
|
||||
CSimConnectObject::CSimConnectObject() { }
|
||||
CSimConnectObject::CSimConnectObject()
|
||||
{ }
|
||||
|
||||
CSimConnectObject::CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, DWORD requestId) :
|
||||
m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true)
|
||||
m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true),
|
||||
m_interpolator(QSharedPointer<BlackMisc::Simulation::CInterpolatorLinear>::create())
|
||||
{ }
|
||||
|
||||
bool CSimConnectObject::isPendingAdded() const
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace BlackSimPlugin
|
||||
//! Simulated aircraft model string
|
||||
const QString &getAircraftModelString() const { return m_aircraft.getModelString(); }
|
||||
|
||||
//! Interpolator
|
||||
BlackMisc::Simulation::IInterpolator *getInterpolator() const { return m_interpolator.data(); }
|
||||
|
||||
//! Get current lights (requested from simulator)
|
||||
const BlackMisc::Aviation::CAircraftLights &getCurrentLightsInSimulator() const { return m_currentLightsInSim; }
|
||||
|
||||
@@ -119,6 +122,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::Aviation::CAircraftLights m_currentLightsInSim { nullptr }; //!< current lights to know state for toggling
|
||||
BlackMisc::Aviation::CAircraftLights m_lightsAsSent { nullptr }; //!< lights as sent to simulator
|
||||
SIMCONNECT_PERIOD m_requestSimDataPeriod = SIMCONNECT_PERIOD_NEVER; //!< how often do we query ground elevation
|
||||
QSharedPointer<BlackMisc::Simulation::IInterpolator> m_interpolator; //!< shared pointer because CSimConnectObject can be copied
|
||||
};
|
||||
|
||||
//! Simulator objects (aka AI aircraft)
|
||||
|
||||
@@ -55,7 +55,6 @@ namespace BlackSimPlugin
|
||||
connect(&m_realityBubbleTimer, &QTimer::timeout, this, &CSimulatorFsx::ps_addAircraftCurrentlyOutOfBubble);
|
||||
|
||||
m_useFsuipc = false; // Temporarily enabled until Simconnect Weather is implemented.
|
||||
m_interpolator = new CInterpolatorLinear(remoteAircraftProvider, this);
|
||||
m_defaultModel =
|
||||
{
|
||||
"Boeing 737-800 Paint1",
|
||||
@@ -153,9 +152,6 @@ namespace BlackSimPlugin
|
||||
CSimulatedAircraft addedAircraft(newRemoteAircraft);
|
||||
if (isConnected())
|
||||
{
|
||||
// initial position if interpolator has data, otherwise do nothing
|
||||
setInitialAircraftSituation(addedAircraft); // set interpolated data/parts if available
|
||||
|
||||
const DWORD requestId = obtainRequestIdSimData();
|
||||
SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxPosition(addedAircraft.getSituation());
|
||||
const QString modelString(addedAircraft.getModelString());
|
||||
@@ -872,7 +868,6 @@ namespace BlackSimPlugin
|
||||
void CSimulatorFsx::updateRemoteAircraft()
|
||||
{
|
||||
static_assert(sizeof(DataDefinitionRemoteAircraftParts) == sizeof(double) * 10, "DataDefinitionRemoteAircraftParts has an incorrect size.");
|
||||
Q_ASSERT_X(this->m_interpolator, Q_FUNC_INFO, "missing interpolator");
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "thread");
|
||||
|
||||
// nothing to do, reset request id and exit
|
||||
@@ -908,14 +903,14 @@ namespace BlackSimPlugin
|
||||
partsStatus.setSupportsParts(useAircraftParts);
|
||||
|
||||
const CInterpolationAndRenderingSetup setup(getInterpolationAndRenderingSetup());
|
||||
const CAircraftParts parts = useAircraftParts ? this->m_interpolator->getInterpolatedParts(callsign, -1, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
|
||||
const CAircraftParts parts = useAircraftParts ? simObj.getInterpolator()->getInterpolatedParts(callsign, -1, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
|
||||
|
||||
// get interpolated situation
|
||||
IInterpolator::InterpolationStatus interpolatorStatus;
|
||||
CInterpolationHints hints(m_hints[simObj.getCallsign()]);
|
||||
hints.setAircraftParts(useAircraftParts ? parts : CAircraftParts(), useAircraftParts);
|
||||
hints.setLoggingInterpolation(logInterpolationAndParts);
|
||||
const CAircraftSituation interpolatedSituation = this->m_interpolator->getInterpolatedSituation(callsign, currentTimestamp, setup, hints, interpolatorStatus);
|
||||
const CAircraftSituation interpolatedSituation = simObj.getInterpolator()->getInterpolatedSituation(callsign, currentTimestamp, setup, hints, interpolatorStatus);
|
||||
|
||||
if (interpolatorStatus.allTrue())
|
||||
{
|
||||
@@ -1274,6 +1269,18 @@ namespace BlackSimPlugin
|
||||
CSimulatorFsCommon::clearAllAircraft();
|
||||
}
|
||||
|
||||
void CSimulatorFsx::ps_remoteProviderAddAircraftSituation(const CAircraftSituation &situation)
|
||||
{
|
||||
if (!m_simConnectObjects.contains(situation.getCallsign())) { return; }
|
||||
m_simConnectObjects[situation.getCallsign()].getInterpolator()->addAircraftSituation(situation);
|
||||
}
|
||||
|
||||
void CSimulatorFsx::ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const CAircraftParts &parts)
|
||||
{
|
||||
if (!m_simConnectObjects.contains(callsign)) { return; }
|
||||
m_simConnectObjects[callsign].getInterpolator()->addAircraftParts(parts);
|
||||
}
|
||||
|
||||
QString CSimulatorFsx::fsxPositionToString(const SIMCONNECT_DATA_INITPOSITION &position)
|
||||
{
|
||||
const QString positionStr("Lat: %1 lng: %2 alt: %3ft pitch: %4 bank: %5 hdg: %6 airspeed: %7kts onGround: %8");
|
||||
|
||||
@@ -133,6 +133,8 @@ namespace BlackSimPlugin
|
||||
virtual void clearAllAircraft() override;
|
||||
virtual void initSimulatorInternals() override;
|
||||
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override;
|
||||
virtual void ps_remoteProviderAddAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
|
||||
virtual void ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts) override;
|
||||
//! @}
|
||||
|
||||
//! Timer event (our SimConnect event loop), runs ps_dispatch
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "blackmisc/simulation/interpolator.h"
|
||||
#include "blackmisc/simulation/interpolationhints.h"
|
||||
#include "blackmisc/simulation/interpolatorlinear.h"
|
||||
#include "blackmisc/simulation/remoteaircraftproviderdummy.h"
|
||||
#include "XPMPMultiplayer.h"
|
||||
#include <XPLM/XPLMProcessing.h>
|
||||
#include <XPLM/XPLMUtilities.h>
|
||||
@@ -42,7 +41,7 @@ namespace XBus
|
||||
surfaces.lights.timeOffset = static_cast<quint16>(qrand() % 0xffff);
|
||||
}
|
||||
|
||||
BlackMisc::Simulation::CInterpolationHints CTraffic::Plane::hints(BlackMisc::Simulation::IInterpolator *interpolator) const
|
||||
BlackMisc::Simulation::CInterpolationHints CTraffic::Plane::hints() const
|
||||
{
|
||||
// \todo MS 865 CInterpolationAndRenderingSetup allows to setup interpolation in the GUI, e.g.
|
||||
// also to disable aircraft parts / or logging parts (log file). I wonder if you want to consider it here
|
||||
@@ -50,8 +49,8 @@ namespace XBus
|
||||
// if the setup is needed more than once, store it here to avoid multiple locks
|
||||
BlackMisc::Simulation::CInterpolationAndRenderingSetup setup;
|
||||
BlackMisc::Simulation::CInterpolationHints hints;
|
||||
BlackMisc::Simulation::IInterpolator::PartsStatus status;
|
||||
hints.setAircraftParts(interpolator->getInterpolatedParts(callsign, parts, -1, setup, status));
|
||||
BlackMisc::Simulation::IInterpolator::CPartsStatus status;
|
||||
hints.setAircraftParts(interpolator.getInterpolatedParts(callsign, -1, setup, status));
|
||||
hints.setElevationProvider([this](const auto & situation)
|
||||
{
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
@@ -68,8 +67,7 @@ namespace XBus
|
||||
}
|
||||
|
||||
CTraffic::CTraffic(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_interpolator(new BlackMisc::Simulation::CInterpolatorLinear(new BlackMisc::Simulation::CRemoteAircraftProviderDummy(this), this))
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -260,17 +258,16 @@ namespace XBus
|
||||
{
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
constexpr int maxSituationCount = 6;
|
||||
plane->situations.push_frontMaxElements(
|
||||
{
|
||||
CAircraftSituation situation(
|
||||
callsign,
|
||||
BlackMisc::Geo::CCoordinateGeodetic(latitude, longitude, altitude),
|
||||
CHeading(heading, CHeading::True, CAngleUnit::deg()),
|
||||
CAngle(pitch, CAngleUnit::deg()),
|
||||
CAngle(roll, CAngleUnit::deg()),
|
||||
CSpeed(0, CSpeedUnit::kts())
|
||||
}, maxSituationCount);
|
||||
plane->situations.front().setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch());
|
||||
);
|
||||
situation.setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch());
|
||||
plane->interpolator.addAircraftSituation(situation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,12 +294,10 @@ namespace XBus
|
||||
plane->surfaces.lights.navLights = navLight;
|
||||
plane->surfaces.lights.flashPattern = lightPattern;
|
||||
|
||||
plane->parts.push_front({});
|
||||
plane->parts.front().setOnGround(onGround);
|
||||
plane->parts.front().setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch());
|
||||
|
||||
// remove outdated parts (but never remove the most recent one)
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider::removeOutdatedParts(plane->parts);
|
||||
BlackMisc::Aviation::CAircraftParts parts;
|
||||
parts.setOnGround(onGround);
|
||||
parts.setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch());
|
||||
plane->interpolator.addAircraftParts(parts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,11 +332,9 @@ namespace XBus
|
||||
{
|
||||
case xpmpDataType_Position:
|
||||
{
|
||||
if (plane->situations.size() < 3) { return xpmpData_Unavailable; } // avoid sudden movements when a pilot connects
|
||||
|
||||
BlackMisc::Simulation::CInterpolationAndRenderingSetup setup;
|
||||
BlackMisc::Simulation::IInterpolator::InterpolationStatus status;
|
||||
const auto situation = m_interpolator->getInterpolatedSituation(plane->callsign, plane->situations, -1, setup, plane->hints(m_interpolator), status);
|
||||
BlackMisc::Simulation::IInterpolator::CInterpolationStatus status;
|
||||
const auto situation = plane->interpolator.getInterpolatedSituation(plane->callsign, -1, setup, plane->hints(), status);
|
||||
if (! status.didInterpolationSucceed()) { return xpmpData_Unavailable; }
|
||||
if (! status.hasChangedPosition()) { return xpmpData_Unchanged; }
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "terrainprobe.h"
|
||||
#include "blackmisc/aviation/aircraftsituationlist.h"
|
||||
#include "blackmisc/aviation/aircraftpartslist.h"
|
||||
#include "blackmisc/simulation/interpolatorlinear.h"
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QVector>
|
||||
@@ -137,10 +138,9 @@ namespace XBus
|
||||
bool hasSurfaces = false;
|
||||
bool hasXpdr = false;
|
||||
char label[32] {};
|
||||
BlackMisc::Aviation::CAircraftSituationList situations;
|
||||
BlackMisc::Aviation::CAircraftPartsList parts;
|
||||
BlackMisc::Simulation::CInterpolatorLinear interpolator;
|
||||
CTerrainProbe terrainProbe;
|
||||
BlackMisc::Simulation::CInterpolationHints hints(BlackMisc::Simulation::IInterpolator *) const;
|
||||
BlackMisc::Simulation::CInterpolationHints hints() const;
|
||||
XPMPPlaneSurfaces_t surfaces;
|
||||
XPMPPlaneRadar_t xpdr;
|
||||
Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_);
|
||||
@@ -153,8 +153,6 @@ namespace XBus
|
||||
{
|
||||
return static_cast<CTraffic *>(self)->getPlaneData(id, dataType, io_data);
|
||||
}
|
||||
|
||||
BlackMisc::Simulation::IInterpolator *m_interpolator = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user