Ref T245, experimental camera support for P3D

* removed deprecated functions of SimObject
* specific P3D initEvent function
This commit is contained in:
Klaus Basan
2018-06-21 18:04:17 +02:00
parent 69193f089a
commit e9e68de255
7 changed files with 151 additions and 74 deletions

View File

@@ -20,7 +20,14 @@ namespace BlackSimPlugin
namespace FsxCommon
{
CSimConnectObject::CSimConnectObject()
{ }
{
this->resetCameraPositions();
}
CSimConnectObject::CSimConnectObject(CSimConnectObject::SimObjectType type) : m_type(type)
{
this->resetCameraPositions();
}
CSimConnectObject::CSimConnectObject(const CSimulatedAircraft &aircraft,
DWORD requestId,
@@ -29,32 +36,15 @@ namespace BlackSimPlugin
m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true),
m_interpolator(QSharedPointer<CInterpolatorMulti>::create(aircraft.getCallsign(), simEnvProvider, setupProvider, remoteAircraftProvider, logger))
{
this->resetCameraPositions();
m_interpolator->initCorrespondingModel(aircraft.getModel());
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
}
void CSimConnectObject::invalidatePartsAsSent()
void CSimConnectObject::setAircraft(const CSimulatedAircraft &aircraft)
{
DataDefinitionRemoteAircraftPartsWithoutLights dd;
dd.resetToInvalid();
m_partsAsSent = dd;
}
bool CSimConnectObject::isSameAsSent(const SIMCONNECT_DATA_INITPOSITION &position) const
{
return std::tie(m_positionAsSent.Airspeed, m_positionAsSent.Altitude, m_positionAsSent.Bank, m_positionAsSent.Heading, m_positionAsSent.Latitude, m_positionAsSent.Longitude, m_positionAsSent.Pitch, m_positionAsSent.OnGround) ==
std::tie(position.Airspeed, position.Altitude, position.Bank, position.Heading, position.Latitude, position.Longitude, position.Pitch, position.OnGround);
}
void CSimConnectObject::invalidatePositionAsSent()
{
m_positionAsSent.Airspeed = 0;
m_positionAsSent.Altitude = -1;
m_positionAsSent.Bank = -1;
m_positionAsSent.Heading = -1;
m_positionAsSent.Latitude = -1;
m_positionAsSent.Longitude = -1;
m_positionAsSent.OnGround = 0;
m_positionAsSent.Pitch = -1;
m_aircraft = aircraft;
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
}
void CSimConnectObject::setObjectId(DWORD id)
@@ -86,10 +76,21 @@ namespace BlackSimPlugin
m_aircraft.setRendered(false);
}
void CSimConnectObject::resetCameraPositions()
{
m_cameraPosition.x = 0;
m_cameraPosition.y = 0;
m_cameraPosition.z = 0;
m_cameraRotation.Pitch = 0;
m_cameraRotation.Bank = 0;
m_cameraRotation.Heading = 0;
}
void CSimConnectObject::resetState()
{
m_pendingRemoved = false;
m_confirmedAdded = false;
m_camera = false;
m_currentLightsInSim = CAircraftLights();
m_lightsAsSent = CAircraftLights();
m_requestId = -1;
@@ -97,8 +98,7 @@ namespace BlackSimPlugin
m_lightsRequestedAt = -1;
m_validRequestId = false;
m_validObjectId = false;
this->invalidatePartsAsSent();
this->invalidatePositionAsSent();
this->resetCameraPositions();
}
bool CSimConnectObject::hasValidRequestAndObjectId() const
@@ -130,7 +130,7 @@ namespace BlackSimPlugin
return m_interpolator->getLastInterpolatedSituation(mode);
}
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId, bool resetSentParts)
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId)
{
// First check, if this request id belongs to us
auto it = std::find_if(this->begin(), this->end(), [requestId](const CSimConnectObject & obj) { return obj.getRequestId() == requestId; });
@@ -138,7 +138,6 @@ namespace BlackSimPlugin
// belongs to us
it->setObjectId(objectId);
if (resetSentParts) { it->invalidatePartsAsSent(); }
return true;
}

View File

@@ -17,6 +17,7 @@
#include "simconnectdatadefinition.h"
#include <QSharedPointer>
#include <QStringList>
#include <QByteArray>
namespace BlackSimPlugin
{
@@ -37,7 +38,7 @@ namespace BlackSimPlugin
CSimConnectObject();
//! Constructor
CSimConnectObject(SimObjectType type) : m_type(type) {}
CSimConnectObject(SimObjectType type);
//! Constructor providing initial situation/parts
CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft,
@@ -65,7 +66,7 @@ namespace BlackSimPlugin
void setType(SimObjectType type) { m_type = type; }
//! Set the aircraft
void setAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) { m_aircraft = aircraft; }
void setAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
//! Get current lights (requested from simulator)
const BlackMisc::Aviation::CAircraftLights &getCurrentLightsInSimulator() const { return m_currentLightsInSim; }
@@ -79,34 +80,6 @@ namespace BlackSimPlugin
//! Pretend to have received lights from simulator
void fakeCurrentLightsInSimulator() { m_currentLightsInSim.setNull(false); }
//! Parts as sent to simulator
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
const DataDefinitionRemoteAircraftPartsWithoutLights &getPartsAsSent() const { return m_partsAsSent; }
//! Parts as sent to simulator
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
void setPartsAsSent(const DataDefinitionRemoteAircraftPartsWithoutLights &parts) { m_partsAsSent = parts; }
//! Invalidate parts as sent
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
void invalidatePartsAsSent();
//! Parts as sent to simulator
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
const SIMCONNECT_DATA_INITPOSITION &getPositionAsSent() const { return m_positionAsSent; }
//! Position as sent
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
void setPositionAsSent(const SIMCONNECT_DATA_INITPOSITION &position) { m_positionAsSent = position; }
//! Same as sent
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
bool isSameAsSent(const SIMCONNECT_DATA_INITPOSITION &position) const;
//! Invalidate position as sent
//! \deprecated KB T273 use BlackCore::CSimulatorCommon isEqual / remember functions
void invalidatePositionAsSent();
//! Lights as sent to simulator
const BlackMisc::Aviation::CAircraftLights &getLightsAsSent() const { return m_lightsAsSent; }
@@ -158,6 +131,24 @@ namespace BlackSimPlugin
//! Pending added or removed?
bool isPending() const { return this->isPendingAdded() || this->isPendingRemoved(); }
//! Has camera?
bool hasCamera() const { return m_camera; }
//! Reset camera positions
void resetCameraPositions();
//! Camera position
const SIMCONNECT_DATA_XYZ &cameraPosition() const { return m_cameraPosition; }
//! Camera rotation;
const SIMCONNECT_DATA_PBH &cameraRotation() const { return m_cameraRotation; }
//! Camera GUID
GUID getCameraGUID() const { return m_cameraGuid; }
//! Set camera GUID
void setCameraGUID(GUID guid) { m_cameraGuid = guid; m_camera = true; }
//! Reset the state (like it was a new onject) without affecting interpolator and aircraft
void resetState();
@@ -170,6 +161,9 @@ namespace BlackSimPlugin
//! Was the object really added to simulator
bool hasValidRequestAndObjectId() const;
//! Callsign as LATIN1
const QByteArray &getCallsignByteArray() const { return m_callsignByteArray; }
//! \copydoc BlackMisc::Simulation::CInterpolator::getInterpolatorInfo
QString getInterpolatorInfo(BlackMisc::Simulation::CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const;
@@ -194,9 +188,12 @@ namespace BlackSimPlugin
bool m_validObjectId = false;
bool m_confirmedAdded = false;
bool m_pendingRemoved = false;
bool m_camera = false;
int m_lightsRequestedAt = -1;
DataDefinitionRemoteAircraftPartsWithoutLights m_partsAsSent {}; //!< parts as sent
SIMCONNECT_DATA_INITPOSITION m_positionAsSent {}; //!< position as sent
GUID m_cameraGuid;
SIMCONNECT_DATA_XYZ m_cameraPosition;
SIMCONNECT_DATA_PBH m_cameraRotation;
QByteArray m_callsignByteArray;
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
@@ -208,7 +205,7 @@ namespace BlackSimPlugin
{
public:
//! Set ID of a SimConnect object, so far we only have an request id in the object
bool setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId, bool resetSentParts = false);
bool setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId);
//! Find which callsign belongs to the object id
BlackMisc::Aviation::CCallsign getCallsignForObjectId(DWORD objectId) const;

View File

@@ -93,7 +93,9 @@ namespace BlackSimPlugin
// set structures and move on
this->initEvents();
this->initEventsP3D();
this->initDataDefinitionsWhenConnected();
m_timerId = this->startTimer(DispatchIntervalMs);
// do not start m_addPendingAircraftTimer here, it will be started when object was added
return true;
@@ -275,7 +277,7 @@ namespace BlackSimPlugin
if (m_simConnectProbes.isEmpty()) { return this->physicallyAddAITerrainProbe(pos); }
if (m_simConnectProbes.countConfirmedAdded() < 1) { return false; } // pending probes
CSimConnectObject simObject = m_simConnectProbes.values().front();
const CSimConnectObject simObject = m_simConnectProbes.values().front();
SIMCONNECT_DATA_INITPOSITION position = this->coordinateToFsxPosition(pos);
const HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftSetPosition,
@@ -873,12 +875,12 @@ namespace BlackSimPlugin
bool CSimulatorFsxCommon::setSimConnectObjectId(DWORD requestId, DWORD objectId)
{
return m_simConnectObjects.setSimConnectObjectIdForRequestId(requestId, objectId, true);
return m_simConnectObjects.setSimConnectObjectIdForRequestId(requestId, objectId);
}
bool CSimulatorFsxCommon::setSimConnectProbeId(DWORD requestId, DWORD objectId)
{
return m_simConnectProbes.setSimConnectObjectIdForRequestId(requestId, objectId, true);
return m_simConnectProbes.setSimConnectObjectIdForRequestId(requestId, objectId);
}
bool CSimulatorFsxCommon::setCurrentLights(const CCallsign &callsign, const CAircraftLights &lights)
@@ -1386,7 +1388,6 @@ namespace BlackSimPlugin
if (!this->isEqualLastSent(result))
{
SIMCONNECT_DATA_INITPOSITION position = this->aircraftSituationToFsxPosition(result, sendGround);
m_simConnectObjects[callsign].setPositionAsSent(position);
const HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftSetPosition,
static_cast<SIMCONNECT_OBJECT_ID>(objectId), 0, 0,
sizeof(SIMCONNECT_DATA_INITPOSITION), &position);
@@ -1478,10 +1479,6 @@ namespace BlackSimPlugin
if (hr == S_OK && m_simConnectObjects.contains(simObject.getCallsign()))
{
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
// Update data
CSimConnectObject &objUdpate = m_simConnectObjects[simObject.getCallsign()];
objUdpate.setPartsAsSent(ddRemoteAircraftPartsWithoutLights);
}
else
{

View File

@@ -79,7 +79,8 @@ namespace BlackSimPlugin
EventToggleNavLights,
EventToggleRecognitionLights,
EventToggleTaxiLights,
EventToggleWingLights
EventToggleWingLights,
EventFSXEndMarker
};
//! Struct to trace send ids
@@ -167,6 +168,9 @@ namespace BlackSimPlugin
//! \sa CSimulatorFsxCommon::dispatch
virtual void timerEvent(QTimerEvent *event) override;
//! Specific P3D events
virtual HRESULT initEventsP3D() { return S_OK; }
//! \addtogroup swiftdotcommands
//! @{
//! <pre>
@@ -202,6 +206,8 @@ namespace BlackSimPlugin
static constexpr qint64 AutoTraceOffsetMs = 10 * 1000; //!< how long do we trace?
HANDLE m_hSimConnect = nullptr; //!< handle to SimConnect object
DispatchProc m_dispatchProc = &CSimulatorFsxCommon::SimConnectProc; //!< called function for dispatch, can be overriden by specialized P3D function
CSimConnectObjects m_simConnectObjects; //!< AI objects and their object / request ids
CSimConnectObjects m_simConnectProbes; //!< AI terrain probes and their object / request ids
QMap<DWORD, BlackMisc::Aviation::CCallsign> m_pendingProbeRequests; //!< pending elevation requests
private:
@@ -441,11 +447,9 @@ namespace BlackSimPlugin
int m_requestSimObjectDataCount = 0; //!< requested SimObjects
// objects
CSimConnectObjects m_simConnectObjects; //!< AI objects and their object / request ids
CSimConnectObjects m_simConnectProbes; //!< AI terrain probes and their object / request ids
CSimConnectObjects m_simConnectObjectsPositionAndPartsTraces; //!< position/parts received, but object not yet added, excluded, disabled etc.
SIMCONNECT_DATA_REQUEST_ID m_requestIdSimData = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestIdSimDataStart); //!< request id, use obtainRequestIdForSimData() to get id
SIMCONNECT_DATA_REQUEST_ID m_requestIdProbe = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestIdTerrainProbeStart); //!< request id, use obtainRequestIdForProbe() to get id
SIMCONNECT_DATA_REQUEST_ID m_requestIdSimData = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestIdSimDataStart); //!< request id, use obtainRequestIdForSimData() to get id
SIMCONNECT_DATA_REQUEST_ID m_requestIdProbe = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestIdTerrainProbeStart); //!< request id, use obtainRequestIdForProbe() to get id
BlackMisc::Simulation::CSimulatedAircraftList m_addPendingAircraft; //!< aircraft awaiting to be added
QTimer m_addPendingSimObjTimer; //!< updating of SimObjects awaiting to be added
};
@@ -489,7 +493,7 @@ namespace BlackSimPlugin
//! \sa CSimConnectObjects::SimConnectProc
static void CALLBACK SimConnectProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext);
};
}
} // namespace
} // namespace
#endif // guard