mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #810, using DWORD instead of int to avoid possible issues (signed vs. unsigned)
Requires flags as negative flags do not indicate invalid
This commit is contained in:
@@ -18,20 +18,10 @@ namespace BlackSimPlugin
|
||||
{
|
||||
CSimConnectObject::CSimConnectObject() { }
|
||||
|
||||
CSimConnectObject::CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, int requestId) :
|
||||
m_aircraft(aircraft), m_requestId(requestId)
|
||||
CSimConnectObject::CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, DWORD requestId) :
|
||||
m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true)
|
||||
{ }
|
||||
|
||||
bool CSimConnectObject::hasValidRequestId() const
|
||||
{
|
||||
return this->m_requestId >= 0;
|
||||
}
|
||||
|
||||
bool CSimConnectObject::hasValidobjectId() const
|
||||
{
|
||||
return this->m_objectId >= 0;
|
||||
}
|
||||
|
||||
bool CSimConnectObject::isPendingAdded() const
|
||||
{
|
||||
return !this->hasValidRequestAndObjectId() || !this->m_confirmedAdded;
|
||||
@@ -57,14 +47,13 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimConnectObject::hasValidRequestAndObjectId() const
|
||||
{
|
||||
return this->hasValidRequestId() && this->hasValidobjectId();
|
||||
return this->hasValidRequestId() && this->hasValidObjectId();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::setSimConnectObjectId(int requestID, int objectId)
|
||||
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId)
|
||||
{
|
||||
// First check, if this request id belongs to us
|
||||
const int requestIntId = static_cast<int>(requestID);
|
||||
auto it = std::find_if(this->begin(), this->end(), [requestIntId](const CSimConnectObject & obj) { return obj.getRequestId() == requestIntId; });
|
||||
auto it = std::find_if(this->begin(), this->end(), [requestId](const CSimConnectObject & obj) { return obj.getRequestId() == requestId; });
|
||||
if (it == this->end()) { return false; }
|
||||
|
||||
// belongs to us
|
||||
@@ -72,12 +61,12 @@ namespace BlackSimPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
CCallsign CSimConnectObjects::getCallsignForObjectId(int objectId) const
|
||||
CCallsign CSimConnectObjects::getCallsignForObjectId(DWORD objectId) const
|
||||
{
|
||||
return getSimObjectForObjectId(objectId).getCallsign();
|
||||
}
|
||||
|
||||
CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(int objectId) const
|
||||
CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(DWORD objectId) const
|
||||
{
|
||||
for (const CSimConnectObject &simObject : this->values())
|
||||
{
|
||||
@@ -86,7 +75,7 @@ namespace BlackSimPlugin
|
||||
return CSimConnectObject();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::isKnownSimObjectId(int objectId) const
|
||||
bool CSimConnectObjects::isKnownSimObjectId(DWORD objectId) const
|
||||
{
|
||||
const CSimConnectObject simObject(getSimObjectForObjectId(objectId));
|
||||
return simObject.hasValidRequestAndObjectId() && objectId == simObject.getObjectId();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKSIMPLUGIN_SIMCONNECT_OBJECT_H
|
||||
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "simconnect/SimConnect.h"
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace BlackMisc { class IInterpolator; }
|
||||
@@ -29,7 +30,7 @@ namespace BlackSimPlugin
|
||||
CSimConnectObject();
|
||||
|
||||
//! Constructor
|
||||
CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, int requestId);
|
||||
CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, DWORD requestId);
|
||||
|
||||
//! Destructor
|
||||
~CSimConnectObject() {}
|
||||
@@ -44,22 +45,22 @@ namespace BlackSimPlugin
|
||||
const QString &getAircraftModelString() const { return m_aircraft.getModelString(); }
|
||||
|
||||
//! Set Simconnect request id
|
||||
void setRequestId(int id) { m_requestId = id; }
|
||||
void setRequestId(DWORD id) { m_requestId = id; m_validRequestId = true; }
|
||||
|
||||
//! Get Simconnect request id
|
||||
int getRequestId() const { return m_requestId; }
|
||||
DWORD getRequestId() const { return m_requestId; }
|
||||
|
||||
//! Set Simconnect object id
|
||||
void setObjectId(int id) { m_objectId = id; }
|
||||
void setObjectId(DWORD id) { m_objectId = id; m_validObjectId = true; }
|
||||
|
||||
//! Set Simconnect object id
|
||||
int getObjectId() const { return m_objectId; }
|
||||
DWORD getObjectId() const { return m_objectId; }
|
||||
|
||||
//! Valid request id?
|
||||
bool hasValidRequestId() const;
|
||||
bool hasValidRequestId() const { return this->m_validRequestId; }
|
||||
|
||||
//! Valid object id?
|
||||
bool hasValidobjectId() const;
|
||||
bool hasValidObjectId() const { return this->m_validObjectId; }
|
||||
|
||||
//! Object is requested, not yet added
|
||||
bool isPendingAdded() const;
|
||||
@@ -84,32 +85,33 @@ namespace BlackSimPlugin
|
||||
|
||||
private:
|
||||
BlackMisc::Simulation::CSimulatedAircraft m_aircraft;
|
||||
int m_requestId = -1;
|
||||
int m_objectId = -1;
|
||||
DWORD m_requestId = 0;
|
||||
DWORD m_objectId = 0;
|
||||
bool m_validRequestId = false;
|
||||
bool m_validObjectId = false;
|
||||
bool m_confirmedAdded = false;
|
||||
bool m_pendingRemoved = false;
|
||||
};
|
||||
|
||||
//! Simulator objects (aka AI aircraft
|
||||
//! Simulator objects (aka AI aircraft)
|
||||
class CSimConnectObjects : public QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject>
|
||||
{
|
||||
public:
|
||||
//! Set ID of a SimConnect object, so far we only have an request id in the object
|
||||
bool setSimConnectObjectId(int requestID, int objectId);
|
||||
bool setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId);
|
||||
|
||||
//! Find which callsign belongs to the object id
|
||||
BlackMisc::Aviation::CCallsign getCallsignForObjectId(int objectId) const;
|
||||
BlackMisc::Aviation::CCallsign getCallsignForObjectId(DWORD objectId) const;
|
||||
|
||||
//! Find which callsign belongs to the object id
|
||||
CSimConnectObject getSimObjectForObjectId(int objectId) const;
|
||||
CSimConnectObject getSimObjectForObjectId(DWORD objectId) const;
|
||||
|
||||
//! Is the object id one of our AI objects?
|
||||
bool isKnownSimObjectId(int objectId) const;
|
||||
bool isKnownSimObjectId(DWORD objectId) const;
|
||||
|
||||
//! Pending add condition
|
||||
bool containsPendingAdd() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace BlackSimPlugin
|
||||
// initial position if interpolator has data, otherwise do nothing
|
||||
setInitialAircraftSituation(addedAircraft); // set interpolated data/parts if available
|
||||
|
||||
const int requestId = m_requestId++;
|
||||
const DWORD requestId = m_requestId++;
|
||||
SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxPosition(addedAircraft.getSituation());
|
||||
const QString modelString(addedAircraft.getModelString());
|
||||
|
||||
@@ -504,23 +504,23 @@ namespace BlackSimPlugin
|
||||
|
||||
Q_ASSERT_X(simObject.isPendingAdded(), Q_FUNC_INFO, "already confirmed");
|
||||
simObject.setConfirmedAdded(true);
|
||||
DWORD objectID = static_cast<DWORD>(simObject.getObjectId());
|
||||
const DWORD objectId = simObject.getObjectId();
|
||||
|
||||
if (m_interpolationRenderingSetup.showSimulatorDebugMessages())
|
||||
{
|
||||
CLogMessage(this).debug() << "Adding AI" << callsign.toQString() << "confirmed" << "id" << static_cast<int>(objectID) << "model" << simObject.getAircraftModelString();
|
||||
CLogMessage(this).debug() << "Adding AI" << callsign.toQString() << "confirmed" << "id" << objectId << "model" << simObject.getAircraftModelString();
|
||||
}
|
||||
|
||||
// P3D also has SimConnect_AIReleaseControlEx;
|
||||
const int requestId = m_requestId++;
|
||||
HRESULT hr = SimConnect_AIReleaseControl(m_hSimConnect, objectID, static_cast<SIMCONNECT_DATA_REQUEST_ID>(requestId));
|
||||
DWORD requestId = m_requestId++;
|
||||
HRESULT hr = SimConnect_AIReleaseControl(m_hSimConnect, objectId, static_cast<SIMCONNECT_DATA_REQUEST_ID>(requestId));
|
||||
if (hr == S_OK)
|
||||
{
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EventFreezeLat, 1,
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeLat, 1,
|
||||
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EventFreezeAlt, 1,
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeAlt, 1,
|
||||
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectID, EventFreezeAtt, 1,
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeAtt, 1,
|
||||
SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
}
|
||||
else
|
||||
@@ -589,11 +589,11 @@ namespace BlackSimPlugin
|
||||
if (!simObject.getAircraftModelString().isEmpty())
|
||||
{
|
||||
this->m_outOfRealityBubble.push_back(simObject.getAircraft());
|
||||
CLogMessage(this).info("Aircraft '%1' '%2' '%3' out of reality bubble") << callsign.toQString() << simObject.getAircraftModelString() << static_cast<int>(objectID);
|
||||
CLogMessage(this).info("Aircraft '%1' '%2' '%3' out of reality bubble") << callsign.toQString() << simObject.getAircraftModelString() << objectID;
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).warning("Removed %1 from simulator, but was not initiated by us: %1 '%2' object id %3") << callsign.toQString() << simObject.getAircraftModelString() << static_cast<int>(objectID);
|
||||
CLogMessage(this).warning("Removed %1 from simulator, but was not initiated by us: %1 '%2' object id %3") << callsign.toQString() << simObject.getAircraftModelString() << objectID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorFsx::setSimConnectObjectId(DWORD requestID, DWORD objectID)
|
||||
{
|
||||
return this->m_simConnectObjects.setSimConnectObjectId(static_cast<int>(requestID), static_cast<int>(objectID));
|
||||
return this->m_simConnectObjects.setSimConnectObjectIdForRequestId(requestID, objectID);
|
||||
}
|
||||
|
||||
void CSimulatorFsx::timerEvent(QTimerEvent *event)
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace BlackSimPlugin
|
||||
const CSimConnectObjects &getSimConnectObjects() const { return m_simConnectObjects; }
|
||||
|
||||
protected:
|
||||
//! \name Interface overrides
|
||||
//! \name Interface implementations
|
||||
//! @{
|
||||
virtual bool isConnected() const override;
|
||||
virtual bool isSimulating() const override;
|
||||
@@ -134,7 +134,7 @@ namespace BlackSimPlugin
|
||||
//! @{
|
||||
virtual void reset() override;
|
||||
virtual void clearAllAircraft() override;
|
||||
virtual void initInternalsObject();
|
||||
virtual void initInternalsObject() override;
|
||||
//! @}
|
||||
|
||||
//! Timer event (our SimConnect event loop), runs ps_dispatch
|
||||
@@ -216,9 +216,9 @@ namespace BlackSimPlugin
|
||||
int m_skipCockpitUpdateCycles = 0; //!< Skip some update cycles to allow changes in simulator cockpit to be set
|
||||
int m_interpolationRequest = 0; //!< current interpolation request
|
||||
int m_interpolationsSkipped = 0; //!< number of skipped interpolation request
|
||||
int m_requestId = 1; //!< request id
|
||||
int m_dispatchErrors = 0; //!< number of dispatched failed, \sa ps_dispatch
|
||||
int m_receiveExceptionCount = 0; //!< exceptions
|
||||
DWORD m_requestId = 1; //!< request id
|
||||
HANDLE m_hSimConnect = nullptr; //!< Handle to SimConnect object
|
||||
CSimConnectObjects m_simConnectObjects; //!< AI objects and their object / request ids
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_outOfRealityBubble; //!< aircraft removed by FSX because they are out of reality bubble
|
||||
|
||||
Reference in New Issue
Block a user