mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 01:05:35 +08:00
Ref T259, Ref T243 adjusted simulator classes to use new setup provider
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "multiplayerpacketparser.h"
|
#include "multiplayerpacketparser.h"
|
||||||
#include "directplayerror.h"
|
#include "directplayerror.h"
|
||||||
#include "directplayutils.h"
|
#include "directplayutils.h"
|
||||||
|
#include "blackcore/simulator.h"
|
||||||
#include "blackmisc/simulation/interpolationhints.h"
|
#include "blackmisc/simulation/interpolationhints.h"
|
||||||
#include "blackmisc/aviation/aircraftsituation.h"
|
#include "blackmisc/aviation/aircraftsituation.h"
|
||||||
#include "blackmisc/geo/coordinategeodetic.h"
|
#include "blackmisc/geo/coordinategeodetic.h"
|
||||||
@@ -25,11 +26,23 @@ using namespace BlackMisc::Aviation;
|
|||||||
using namespace BlackMisc::Simulation;
|
using namespace BlackMisc::Simulation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Geo;
|
using namespace BlackMisc::Geo;
|
||||||
|
using namespace BlackCore;
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
{
|
{
|
||||||
namespace Fs9
|
namespace Fs9
|
||||||
{
|
{
|
||||||
|
CFs9Client::CFs9Client(const CCallsign &callsign, const QString &modelName, const CTime &updateInterval,
|
||||||
|
CInterpolationLogger *logger, ISimulator *owner) :
|
||||||
|
CDirectPlayPeer(owner, callsign),
|
||||||
|
m_updateInterval(updateInterval),
|
||||||
|
m_interpolator(callsign),
|
||||||
|
m_modelName(modelName)
|
||||||
|
{
|
||||||
|
m_interpolator.attachLogger(logger);
|
||||||
|
Q_ASSERT_X(this->simulator(), Q_FUNC_INFO, "Wrong owner, expect simulator object");
|
||||||
|
}
|
||||||
|
|
||||||
MPPositionVelocity aircraftSituationToFS9(const CAircraftSituation &oldSituation, const CAircraftSituation &newSituation, double updateInterval)
|
MPPositionVelocity aircraftSituationToFS9(const CAircraftSituation &oldSituation, const CAircraftSituation &newSituation, double updateInterval)
|
||||||
{
|
{
|
||||||
MPPositionVelocity positionVelocity;
|
MPPositionVelocity positionVelocity;
|
||||||
@@ -70,12 +83,12 @@ namespace BlackSimPlugin
|
|||||||
// We want the distance in Latitude direction. Longitude must be equal for old and new position.
|
// We want the distance in Latitude direction. Longitude must be equal for old and new position.
|
||||||
helperPosition.setLatitude(newPosition.latitude());
|
helperPosition.setLatitude(newPosition.latitude());
|
||||||
helperPosition.setLongitude(oldPosition.longitude());
|
helperPosition.setLongitude(oldPosition.longitude());
|
||||||
CLength distanceLatitudeObj = calculateGreatCircleDistance(oldPosition, helperPosition);
|
const CLength distanceLatitudeObj = calculateGreatCircleDistance(oldPosition, helperPosition);
|
||||||
|
|
||||||
// Now we want the Longitude distance. Latitude must be equal for old and new position.
|
// Now we want the Longitude distance. Latitude must be equal for old and new position.
|
||||||
helperPosition.setLatitude(oldPosition.latitude());
|
helperPosition.setLatitude(oldPosition.latitude());
|
||||||
helperPosition.setLongitude(newSituation.longitude());
|
helperPosition.setLongitude(newSituation.longitude());
|
||||||
CLength distanceLongitudeObj = calculateGreatCircleDistance(oldPosition, helperPosition);
|
const CLength distanceLongitudeObj = calculateGreatCircleDistance(oldPosition, helperPosition);
|
||||||
|
|
||||||
// Latitude and Longitude velocity
|
// Latitude and Longitude velocity
|
||||||
positionVelocity.lat_velocity = distanceLatitudeObj.value(CLengthUnit::ft()) * 65536.0 / updateInterval;
|
positionVelocity.lat_velocity = distanceLatitudeObj.value(CLengthUnit::ft()) * 65536.0 / updateInterval;
|
||||||
@@ -91,12 +104,12 @@ namespace BlackSimPlugin
|
|||||||
MPPositionSlewMode positionSlewMode;
|
MPPositionSlewMode positionSlewMode;
|
||||||
|
|
||||||
// Latitude - integer and decimal places
|
// Latitude - integer and decimal places
|
||||||
double latitude = situation.getPosition().latitude().value(CAngleUnit::deg()) * 10001750.0 / 90.0;
|
const double latitude = situation.getPosition().latitude().value(CAngleUnit::deg()) * 10001750.0 / 90.0;
|
||||||
positionSlewMode.lat_i = static_cast<qint32>(latitude);
|
positionSlewMode.lat_i = static_cast<qint32>(latitude);
|
||||||
positionSlewMode.lat_f = qAbs((latitude - positionSlewMode.lat_i) * 65536);
|
positionSlewMode.lat_f = qAbs((latitude - positionSlewMode.lat_i) * 65536);
|
||||||
|
|
||||||
// Longitude - integer and decimal places
|
// Longitude - integer and decimal places
|
||||||
double longitude = situation.getPosition().longitude().value(CAngleUnit::deg()) * (65536.0 * 65536.0) / 360.0;
|
const double longitude = situation.getPosition().longitude().value(CAngleUnit::deg()) * (65536.0 * 65536.0) / 360.0;
|
||||||
positionSlewMode.lon_hi = static_cast<qint32>(longitude);
|
positionSlewMode.lon_hi = static_cast<qint32>(longitude);
|
||||||
positionSlewMode.lon_lo = qAbs((longitude - positionSlewMode.lon_hi) * 65536);
|
positionSlewMode.lon_lo = qAbs((longitude - positionSlewMode.lon_hi) * 65536);
|
||||||
|
|
||||||
@@ -118,16 +131,6 @@ namespace BlackSimPlugin
|
|||||||
return positionSlewMode;
|
return positionSlewMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFs9Client::CFs9Client(const CCallsign &callsign, const QString &modelName, const CTime &updateInterval,
|
|
||||||
BlackMisc::Simulation::CInterpolationLogger *logger, QObject *owner) :
|
|
||||||
CDirectPlayPeer(owner, callsign),
|
|
||||||
m_updateInterval(updateInterval),
|
|
||||||
m_interpolator(callsign),
|
|
||||||
m_modelName(modelName)
|
|
||||||
{
|
|
||||||
m_interpolator.attachLogger(logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
CFs9Client::~CFs9Client()
|
CFs9Client::~CFs9Client()
|
||||||
{
|
{
|
||||||
SafeRelease(m_hostAddress);
|
SafeRelease(m_hostAddress);
|
||||||
@@ -165,28 +168,16 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFs9Client::setInterpolationSetup(const CInterpolationAndRenderingSetup &setup)
|
|
||||||
{
|
|
||||||
QWriteLocker lock(&m_interpolationSetupMutex);
|
|
||||||
m_interpolationSetup = setup;
|
|
||||||
}
|
|
||||||
|
|
||||||
CInterpolationAndRenderingSetup CFs9Client::getInterpolationSetup() const
|
|
||||||
{
|
|
||||||
QReadLocker lock(&m_interpolationSetupMutex);
|
|
||||||
return m_interpolationSetup;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFs9Client::timerEvent(QTimerEvent *event)
|
void CFs9Client::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
||||||
if (m_clientStatus == Disconnected) { return; }
|
if (m_clientStatus == Disconnected) { return; }
|
||||||
|
|
||||||
CInterpolationStatus status;
|
CInterpolationStatus status;
|
||||||
CInterpolationHints hints; // \fixme 201701 #865 KB if there is an elevation provider for FS9 add it here or set elevation
|
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));
|
CInterpolationAndRenderingSetupPerCallsign setup = this->simulator()->getInterpolationSetupPerCallsignOrDefault(m_callsign);
|
||||||
const CAircraftSituation situation = m_interpolator.getInterpolatedSituation(-1, m_interpolationSetup, hints, status);
|
hints.setLoggingInterpolation(setup.logInterpolation());
|
||||||
|
const CAircraftSituation situation = m_interpolator.getInterpolatedSituation(-1, setup, hints, status);
|
||||||
|
|
||||||
// Test only for successful position. FS9 requires constant positions
|
// Test only for successful position. FS9 requires constant positions
|
||||||
if (!status.hasValidSituation()) { return; }
|
if (!status.hasValidSituation()) { return; }
|
||||||
@@ -218,7 +209,7 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now set up the Application Description
|
// Now set up the Application Description
|
||||||
DPN_APPLICATION_DESC dpAppDesc;
|
DPN_APPLICATION_DESC dpAppDesc;
|
||||||
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
|
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
|
||||||
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
|
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
|
||||||
dpAppDesc.guidApplication = CFs9Sdk::guid();
|
dpAppDesc.guidApplication = CFs9Sdk::guid();
|
||||||
@@ -339,7 +330,7 @@ namespace BlackSimPlugin
|
|||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
if (m_clientStatus == Disconnected) { return hr; }
|
if (m_clientStatus == Disconnected) { return hr; }
|
||||||
BlackMisc::CLogMessage(this).debug() << "Closing DirectPlay connection for " << m_callsign;
|
CLogMessage(this).debug() << "Closing DirectPlay connection for " << m_callsign;
|
||||||
if (FAILED(hr = m_directPlayPeer->Close(0)))
|
if (FAILED(hr = m_directPlayPeer->Close(0)))
|
||||||
{
|
{
|
||||||
return logDirectPlayError(hr);
|
return logDirectPlayError(hr);
|
||||||
@@ -387,5 +378,10 @@ namespace BlackSimPlugin
|
|||||||
message = MultiPlayerPacketParser::writeMessage(message, mpChangePlayerPlane);
|
message = MultiPlayerPacketParser::writeMessage(message, mpChangePlayerPlane);
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ISimulator *CFs9Client::simulator() const
|
||||||
|
{
|
||||||
|
return qobject_cast<const ISimulator *>(this->owner());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,15 @@
|
|||||||
#include "directplaypeer.h"
|
#include "directplaypeer.h"
|
||||||
#include "blackmisc/simulation/interpolatormulti.h"
|
#include "blackmisc/simulation/interpolatormulti.h"
|
||||||
#include "blackmisc/aviation/aircraftsituation.h"
|
#include "blackmisc/aviation/aircraftsituation.h"
|
||||||
#include "blackmisc/pq/time.h"
|
|
||||||
#include "blackmisc/aviation/callsign.h"
|
#include "blackmisc/aviation/callsign.h"
|
||||||
|
#include "blackmisc/pq/time.h"
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
|
||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
|
namespace BlackCore { class ISimulator; }
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
{
|
{
|
||||||
namespace Fs9
|
namespace Fs9
|
||||||
@@ -54,10 +55,6 @@ namespace BlackSimPlugin
|
|||||||
//! Get interpolator
|
//! Get interpolator
|
||||||
BlackMisc::Simulation::CInterpolatorMulti *getInterpolator() { return &m_interpolator; }
|
BlackMisc::Simulation::CInterpolatorMulti *getInterpolator() { return &m_interpolator; }
|
||||||
|
|
||||||
//! Set interpolation setup
|
|
||||||
//! \threadsafe
|
|
||||||
void setInterpolationSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Send new text message
|
//! Send new text message
|
||||||
void sendTextMessage(const QString &textMessage);
|
void sendTextMessage(const QString &textMessage);
|
||||||
@@ -94,12 +91,10 @@ namespace BlackSimPlugin
|
|||||||
void sendMultiplayerParamaters();
|
void sendMultiplayerParamaters();
|
||||||
void sendMultiplayerChangePlayerPlane();
|
void sendMultiplayerChangePlayerPlane();
|
||||||
|
|
||||||
BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationSetup() const;
|
const BlackCore::ISimulator *simulator() const;
|
||||||
|
|
||||||
BlackMisc::PhysicalQuantities::CTime m_updateInterval;
|
BlackMisc::PhysicalQuantities::CTime m_updateInterval;
|
||||||
BlackMisc::Simulation::CInterpolatorMulti m_interpolator;
|
BlackMisc::Simulation::CInterpolatorMulti m_interpolator;
|
||||||
BlackMisc::Simulation::CInterpolationAndRenderingSetup m_interpolationSetup;
|
|
||||||
mutable QReadWriteLock m_interpolationSetupMutex;
|
|
||||||
QString m_modelName;
|
QString m_modelName;
|
||||||
int m_timerId = 0;
|
int m_timerId = 0;
|
||||||
|
|
||||||
@@ -109,8 +104,8 @@ namespace BlackSimPlugin
|
|||||||
PLAYER_INFO_STRUCT m_playerInfo;
|
PLAYER_INFO_STRUCT m_playerInfo;
|
||||||
DPN_PLAYER_INFO m_player;
|
DPN_PLAYER_INFO m_player;
|
||||||
};
|
};
|
||||||
}
|
} // ns
|
||||||
}
|
} // ns
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlackSimPlugin::Fs9::CFs9Client::ClientStatus)
|
Q_DECLARE_METATYPE(BlackSimPlugin::Fs9::CFs9Client::ClientStatus)
|
||||||
|
|
||||||
|
|||||||
@@ -1098,12 +1098,11 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
// interpolate and send to simulator
|
// interpolate and send to simulator
|
||||||
m_interpolationRequest++;
|
m_interpolationRequest++;
|
||||||
const bool enableAircraftParts = m_interpolationRenderingSetup.isAircraftPartsEnabled();
|
const CCallsignSet aircraftWithParts = this->remoteAircraftSupportingParts(); // optimization, fetch all parts supporting aircraft in one step (one lock)
|
||||||
const CCallsignSet aircraftWithParts = enableAircraftParts ? this->remoteAircraftSupportingParts() : CCallsignSet(); // optimization, fetch all parts supporting aircraft in one step (one lock)
|
|
||||||
|
|
||||||
// values used for position and parts
|
// values used for position and parts
|
||||||
const qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
|
const qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
|
||||||
const CCallsignSet callsignsToLog(m_interpolationRenderingSetup.getLogCallsigns());
|
const CCallsignSet callsignsToLog(this->getLogCallsigns());
|
||||||
|
|
||||||
// interpolation for all remote aircraft
|
// interpolation for all remote aircraft
|
||||||
const QList<CSimConnectObject> simObjects(m_simConnectObjects.values());
|
const QList<CSimConnectObject> simObjects(m_simConnectObjects.values());
|
||||||
@@ -1119,9 +1118,9 @@ namespace BlackSimPlugin
|
|||||||
Q_ASSERT_X(simObject.hasValidRequestAndObjectId(), Q_FUNC_INFO, "Missing ids");
|
Q_ASSERT_X(simObject.hasValidRequestAndObjectId(), Q_FUNC_INFO, "Missing ids");
|
||||||
|
|
||||||
// fetch parts, as they are needed for ground interpolation
|
// fetch parts, as they are needed for ground interpolation
|
||||||
const bool useAircraftParts = enableAircraftParts && aircraftWithParts.contains(callsign);
|
const CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign);
|
||||||
|
const bool useAircraftParts = setup.isAircraftPartsEnabled() && aircraftWithParts.contains(callsign);
|
||||||
const bool logInterpolationAndParts = callsignsToLog.contains(callsign);
|
const bool logInterpolationAndParts = callsignsToLog.contains(callsign);
|
||||||
const CInterpolationAndRenderingSetup setup(this->getInterpolationAndRenderingSetup());
|
|
||||||
CPartsStatus partsStatus(useAircraftParts);
|
CPartsStatus partsStatus(useAircraftParts);
|
||||||
const CAircraftParts parts = useAircraftParts ? simObject.getInterpolatedParts(currentTimestamp, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
|
const CAircraftParts parts = useAircraftParts ? simObject.getInterpolatedParts(currentTimestamp, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
|
||||||
|
|
||||||
|
|||||||
@@ -826,12 +826,10 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
// interpolate and send to simulator
|
// interpolate and send to simulator
|
||||||
m_interpolationRequest++;
|
m_interpolationRequest++;
|
||||||
const bool enableAircraftParts = m_interpolationRenderingSetup.isAircraftPartsEnabled();
|
const CCallsignSet aircraftWithParts = this->remoteAircraftSupportingParts(); // optimization, fetch all parts supporting aircraft in one step (one lock)
|
||||||
const CCallsignSet aircraftWithParts = enableAircraftParts ? this->remoteAircraftSupportingParts() : CCallsignSet(); // optimization, fetch all parts supporting aircraft in one step (one lock)
|
|
||||||
|
|
||||||
// values used for position and parts
|
// values used for position and parts
|
||||||
const qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
|
const qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
|
||||||
const CCallsignSet callsignsToLog(m_interpolationRenderingSetup.getLogCallsigns());
|
|
||||||
|
|
||||||
// interpolation for all remote aircraft
|
// interpolation for all remote aircraft
|
||||||
const QList<CXPlaneMPAircraft> xplaneAircrafts(m_xplaneAircraftObjects.values());
|
const QList<CXPlaneMPAircraft> xplaneAircrafts(m_xplaneAircraftObjects.values());
|
||||||
@@ -841,9 +839,9 @@ namespace BlackSimPlugin
|
|||||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "missing callsign");
|
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "missing callsign");
|
||||||
|
|
||||||
// fetch parts, as they are needed for ground interpolation
|
// fetch parts, as they are needed for ground interpolation
|
||||||
const bool useAircraftParts = enableAircraftParts && aircraftWithParts.contains(callsign);
|
const CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign);
|
||||||
const bool logInterpolationAndParts = callsignsToLog.contains(callsign);
|
const bool useAircraftParts = aircraftWithParts.contains(callsign) && setup.isAircraftPartsEnabled();
|
||||||
const CInterpolationAndRenderingSetup setup(this->getInterpolationAndRenderingSetup());
|
const bool logInterpolationAndParts = setup.logInterpolation();
|
||||||
CPartsStatus partsStatus(useAircraftParts);
|
CPartsStatus partsStatus(useAircraftParts);
|
||||||
const CAircraftParts parts = useAircraftParts ? xplaneAircraft.getInterpolatedParts(currentTimestamp, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
|
const CAircraftParts parts = useAircraftParts ? xplaneAircraft.getInterpolatedParts(currentTimestamp, setup, partsStatus, logInterpolationAndParts) : CAircraftParts();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user