refs #895, reset to "invalid" sentParts when object is added

(makes sure the parts are sent at least once)
This commit is contained in:
Klaus Basan
2017-03-04 01:45:04 +01:00
committed by Mathew Sutcliffe
parent 6a63bcf666
commit 8b1c8c068b
5 changed files with 36 additions and 5 deletions

View File

@@ -215,6 +215,20 @@ namespace BlackSimPlugin
spoilersHandlePosition = 0;
}
void DataDefinitionRemoteAircraftPartsWithoutLights::resetToInvalid()
{
flapsLeadingEdgeLeftPercent = -1;
flapsLeadingEdgeRightPercent = -1;
flapsTrailingEdgeLeftPercent = -1;
flapsTrailingEdgeRightPercent = -1;
gearHandlePosition = -1;
spoilersHandlePosition = -1;
engine1Combustion = -1;
engine2Combustion = -1;
engine3Combustion = -1;
engine4Combustion = -1;
}
CAircraftLights DataDefinitionRemoteAircraftLights::toLights() const
{
return CAircraftLights(lightStrobe, lightLanding, lightTaxi, lightBeacon, lightNav, lightLogo, lightRecognition, lightCabin);

View File

@@ -99,6 +99,9 @@ namespace BlackSimPlugin
//! Reset spoilers
void resetSpoilers();
//! Reset to invalid values
void resetToInvalid();
};
//! Data for aircraft lighs

View File

@@ -30,6 +30,13 @@ namespace BlackSimPlugin
m_interpolator->attachLogger(logger);
}
void CSimConnectObject::invalidatePartsAsSent()
{
DataDefinitionRemoteAircraftPartsWithoutLights dd;
dd.resetToInvalid();
m_partsAsSent = dd;
}
bool CSimConnectObject::isPendingAdded() const
{
return !this->hasValidRequestAndObjectId() || !this->m_confirmedAdded;
@@ -58,7 +65,7 @@ namespace BlackSimPlugin
return this->hasValidRequestId() && this->hasValidObjectId();
}
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId)
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId, bool resetSentParts)
{
// 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; });
@@ -66,6 +73,7 @@ namespace BlackSimPlugin
// belongs to us
it->setObjectId(objectId);
if (resetSentParts) { it->invalidatePartsAsSent(); }
return true;
}

View File

@@ -68,6 +68,9 @@ namespace BlackSimPlugin
//! Parts as sent to simulator
void setPartsAsSent(const DataDefinitionRemoteAircraftPartsWithoutLights &parts) { m_partsAsSent = parts; }
//! Invalidate parts as sent
void invalidatePartsAsSent();
//! Lights as sent to simulator
const BlackMisc::Aviation::CAircraftLights &getLightsAsSent() const { return m_lightsAsSent; }
@@ -141,7 +144,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 setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId, bool resetSentParts = false);
//! Find which callsign belongs to the object id
BlackMisc::Aviation::CCallsign getCallsignForObjectId(DWORD objectId) const;

View File

@@ -659,7 +659,7 @@ namespace BlackSimPlugin
bool CSimulatorFsxCommon::setSimConnectObjectId(DWORD requestID, DWORD objectID)
{
return this->m_simConnectObjects.setSimConnectObjectIdForRequestId(requestID, objectID);
return this->m_simConnectObjects.setSimConnectObjectIdForRequestId(requestID, objectID, true);
}
bool CSimulatorFsxCommon::setCurrentLights(const CCallsign &callsign, const CAircraftLights &lights)
@@ -868,7 +868,7 @@ namespace BlackSimPlugin
void CSimulatorFsxCommon::updateRemoteAircraft()
{
static_assert(sizeof(DataDefinitionRemoteAircraftPartsWithoutLights) == sizeof(double) * 10, "DataDefinitionRemoteAircraftParts has an incorrect size.");
static_assert(sizeof(DataDefinitionRemoteAircraftPartsWithoutLights) == sizeof(double) * 10, "DataDefinitionRemoteAircraftPartsWithoutLights has an incorrect size.");
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "thread");
// nothing to do, reset request id and exit
@@ -1049,7 +1049,10 @@ namespace BlackSimPlugin
// same as in simulator or same as already send to simulator?
const CAircraftLights sentLights(simObj.getLightsAsSent());
if (simObj.getPartsAsSent() == ddRemoteAircraftPartsWithoutLights && sentLights == lights) { return true; }
if (simObj.getPartsAsSent() == ddRemoteAircraftPartsWithoutLights && sentLights == lights)
{
return true;
}
// in case we sent, we sent everything
const HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftParts,