mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user