Ref T307, using "isReadyToSend" to detect if we can send AI object updates

This commit is contained in:
Klaus Basan
2018-08-21 15:59:48 +02:00
parent 4850e20160
commit a1470200eb
2 changed files with 11 additions and 4 deletions

View File

@@ -134,6 +134,9 @@ namespace BlackSimPlugin
//! Removing is pending //! Removing is pending
bool isPendingRemoved() const { return m_pendingRemoved; } bool isPendingRemoved() const { return m_pendingRemoved; }
//! Object which can be used for sending, not pending and valid ids
bool isReadyToSend() const { return !this->isPending() && this->hasValidRequestAndObjectId(); }
//! Marked as pending for removal //! Marked as pending for removal
void setPendingRemoved(bool pending); void setPendingRemoved(bool pending);

View File

@@ -902,6 +902,7 @@ namespace BlackSimPlugin
if (this->isShuttingDownOrDisconnected()) { return false; } if (this->isShuttingDownOrDisconnected()) { return false; }
const CSimConnectObject simObject = m_simConnectObjects.getSimObjectForObjectId(objectID); const CSimConnectObject simObject = m_simConnectObjects.getSimObjectForObjectId(objectID);
if (!simObject.hasValidRequestAndObjectId()) { return false; } // object id from somewhere else if (!simObject.hasValidRequestAndObjectId()) { return false; } // object id from somewhere else
const CCallsign callsign(simObject.getCallsign()); const CCallsign callsign(simObject.getCallsign());
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign for removed object"); Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign for removed object");
@@ -1464,8 +1465,7 @@ namespace BlackSimPlugin
for (const CSimConnectObject &simObject : simObjects) for (const CSimConnectObject &simObject : simObjects)
{ {
// happening if aircraft is not yet added to simulator or to be deleted // happening if aircraft is not yet added to simulator or to be deleted
if (simObject.isPendingAdded()) { continue; } if (!simObject.isReadyToSend()) { continue; }
if (simObject.isPendingRemoved()) { continue; }
if (!simObject.hasCurrentLightsInSimulator()) { continue; } // wait until we have light state if (!simObject.hasCurrentLightsInSimulator()) { continue; } // wait until we have light state
const CCallsign callsign(simObject.getCallsign()); const CCallsign callsign(simObject.getCallsign());
@@ -1562,6 +1562,9 @@ namespace BlackSimPlugin
bool CSimulatorFsxCommon::sendRemoteAircraftPartsToSimulator(const CSimConnectObject &simObject, DataDefinitionRemoteAircraftPartsWithoutLights &ddRemoteAircraftPartsWithoutLights, const CAircraftLights &lights) bool CSimulatorFsxCommon::sendRemoteAircraftPartsToSimulator(const CSimConnectObject &simObject, DataDefinitionRemoteAircraftPartsWithoutLights &ddRemoteAircraftPartsWithoutLights, const CAircraftLights &lights)
{ {
Q_ASSERT(m_hSimConnect); Q_ASSERT(m_hSimConnect);
if (!simObject.isReadyToSend()) { return false; }
const DWORD objectId = simObject.getObjectId(); const DWORD objectId = simObject.getObjectId();
const bool traceId = this->isTracingSendId(); const bool traceId = this->isTracingSendId();
@@ -1594,7 +1597,8 @@ namespace BlackSimPlugin
void CSimulatorFsxCommon::sendToggledLightsToSimulator(const CSimConnectObject &simObj, const CAircraftLights &lightsWanted, bool force) void CSimulatorFsxCommon::sendToggledLightsToSimulator(const CSimConnectObject &simObj, const CAircraftLights &lightsWanted, bool force)
{ {
if (!simObj.hasValidRequestAndObjectId()) { return; } // stale if (!simObj.isReadyToSend()) { return; } // stale
const CAircraftLights lightsIsState = simObj.getCurrentLightsInSimulator(); const CAircraftLights lightsIsState = simObj.getCurrentLightsInSimulator();
if (lightsWanted == lightsIsState) { return; } if (lightsWanted == lightsIsState) { return; }
if (!force && lightsWanted == simObj.getLightsAsSent()) { return; } if (!force && lightsWanted == simObj.getLightsAsSent()) { return; }
@@ -1661,7 +1665,7 @@ namespace BlackSimPlugin
if (!myself) { return; } if (!myself) { return; }
if (!m_simConnectObjects.contains(callsign)) { return; } if (!m_simConnectObjects.contains(callsign)) { return; }
const CSimConnectObject currentSimObject = m_simConnectObjects[callsign]; const CSimConnectObject currentSimObject = m_simConnectObjects[callsign];
if (!currentSimObject.hasValidRequestAndObjectId()) { return; } // stale if (!currentSimObject.isReadyToSend()) { return; } // stale
if (lightsWanted != currentSimObject.getLightsAsSent()) { return; } // changed in between, so another call sendToggledLightsToSimulator is pending if (lightsWanted != currentSimObject.getLightsAsSent()) { return; } // changed in between, so another call sendToggledLightsToSimulator is pending
if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("Resending light state for '%1', model '%2'").arg(callsign.asString(), simObj.getAircraftModelString())); } if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("Resending light state for '%1', model '%2'").arg(callsign.asString(), simObj.getAircraftModelString())); }
this->sendToggledLightsToSimulator(currentSimObject, lightsWanted, true); this->sendToggledLightsToSimulator(currentSimObject, lightsWanted, true);