mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
refs #873, FSX: do not send parts if they are equal
* == operator for struct * do not send when equal * fixed missing init of guessed parts struct
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3090413849
commit
f701d6ad4a
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "simconnectdatadefinition.h"
|
#include "simconnectdatadefinition.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
|
|
||||||
@@ -178,5 +179,17 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DataDefinitionRemoteAircraftParts::operator==(const DataDefinitionRemoteAircraftParts &rhs) const
|
||||||
|
{
|
||||||
|
return std::tie(lightBeacon, lightLanding, lightLogo, lightNav, lightStrobe,
|
||||||
|
flapsLeadingEdgeLeftPercent, flapsLeadingEdgeRightPercent, flapsTrailingEdgeLeftPercent, flapsTrailingEdgeRightPercent,
|
||||||
|
gearHandlePosition, spoilersHandlePosition,
|
||||||
|
engine1Combustion, engine2Combustion, engine3Combustion, engine4Combustion) ==
|
||||||
|
std::tie(rhs.lightBeacon, rhs.lightLanding, rhs.lightLogo, rhs.lightNav, rhs.lightStrobe,
|
||||||
|
rhs.flapsLeadingEdgeLeftPercent, rhs.flapsLeadingEdgeRightPercent, rhs.flapsTrailingEdgeLeftPercent, rhs.flapsTrailingEdgeRightPercent,
|
||||||
|
rhs.gearHandlePosition, rhs.spoilersHandlePosition,
|
||||||
|
rhs.engine1Combustion, rhs.engine2Combustion, rhs.engine3Combustion, rhs.engine4Combustion);
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ namespace BlackSimPlugin
|
|||||||
double engine2Combustion; //!< Engine 2 combustion flag
|
double engine2Combustion; //!< Engine 2 combustion flag
|
||||||
double engine3Combustion; //!< Engine 3 combustion flag
|
double engine3Combustion; //!< Engine 3 combustion flag
|
||||||
double engine4Combustion; //!< Engine 4 combustion flag
|
double engine4Combustion; //!< Engine 4 combustion flag
|
||||||
|
|
||||||
|
//! Equal to other parts
|
||||||
|
bool operator==(const DataDefinitionRemoteAircraftParts &rhs) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Data for AI object sent back from simulator
|
//! Data for AI object sent back from simulator
|
||||||
|
|||||||
@@ -735,6 +735,7 @@ namespace BlackSimPlugin
|
|||||||
// call in SIM
|
// call in SIM
|
||||||
SimConnect_AIRemoveObject(m_hSimConnect, static_cast<SIMCONNECT_OBJECT_ID>(simObject.getObjectId()), static_cast<SIMCONNECT_DATA_REQUEST_ID>(m_requestId++));
|
SimConnect_AIRemoveObject(m_hSimConnect, static_cast<SIMCONNECT_OBJECT_ID>(simObject.getObjectId()), static_cast<SIMCONNECT_DATA_REQUEST_ID>(m_requestId++));
|
||||||
m_hints.remove(simObject.getCallsign());
|
m_hints.remove(simObject.getCallsign());
|
||||||
|
m_lastPartsSendToSim.remove(simObject.getObjectId());
|
||||||
|
|
||||||
// mark in provider
|
// mark in provider
|
||||||
bool updated = updateAircraftRendered(callsign, false);
|
bool updated = updateAircraftRendered(callsign, false);
|
||||||
@@ -911,7 +912,11 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->guessAndUpdateRemoteAircraftParts(simObj, interpolatedSituation, interpolatorStatus);
|
// guess on position, but not every frame
|
||||||
|
if (m_interpolationRequest % 20 == 0)
|
||||||
|
{
|
||||||
|
this->guessAndUpdateRemoteAircraftParts(simObj, interpolatedSituation, interpolatorStatus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // all callsigns
|
} // all callsigns
|
||||||
const qint64 dt = QDateTime::currentMSecsSinceEpoch() - currentTimestamp;
|
const qint64 dt = QDateTime::currentMSecsSinceEpoch() - currentTimestamp;
|
||||||
@@ -920,13 +925,12 @@ namespace BlackSimPlugin
|
|||||||
m_statsUpdateAircraftTimeAvgMs = m_statsUpdateAircraftTimeTotalMs / m_statsUpdateAircraftCountMs;
|
m_statsUpdateAircraftTimeAvgMs = m_statsUpdateAircraftTimeTotalMs / m_statsUpdateAircraftCountMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFsx::guessAndUpdateRemoteAircraftParts(const CSimConnectObject &simObj, const CAircraftSituation &interpolatedSituation, const IInterpolator::InterpolationStatus &interpolationStatus) const
|
bool CSimulatorFsx::guessAndUpdateRemoteAircraftParts(const CSimConnectObject &simObj, const CAircraftSituation &interpolatedSituation, const IInterpolator::InterpolationStatus &interpolationStatus)
|
||||||
{
|
{
|
||||||
if (!simObj.hasValidRequestAndObjectId()) { return false; }
|
if (!simObj.hasValidRequestAndObjectId()) { return false; }
|
||||||
if (!interpolationStatus.didInterpolationSucceed()) { return false; }
|
if (!interpolationStatus.didInterpolationSucceed()) { return false; }
|
||||||
if (this->m_interpolationRequest % 20 != 0) { return false; } // only update every 20th cycle
|
|
||||||
|
|
||||||
DataDefinitionRemoteAircraftParts ddRemoteAircraftParts;
|
DataDefinitionRemoteAircraftParts ddRemoteAircraftParts = {}; // init members
|
||||||
const bool isOnGround = interpolatedSituation.isOnGround() == CAircraftSituation::OnGround;
|
const bool isOnGround = interpolatedSituation.isOnGround() == CAircraftSituation::OnGround;
|
||||||
ddRemoteAircraftParts.gearHandlePosition = isOnGround ? 1 : 0;
|
ddRemoteAircraftParts.gearHandlePosition = isOnGround ? 1 : 0;
|
||||||
|
|
||||||
@@ -969,12 +973,12 @@ namespace BlackSimPlugin
|
|||||||
return this->sendRemoteAircraftPartsToSim(simObj, ddRemoteAircraftParts);
|
return this->sendRemoteAircraftPartsToSim(simObj, ddRemoteAircraftParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFsx::updateRemoteAircraftParts(const CSimConnectObject &simObj, const CAircraftParts &parts, const IInterpolator::PartsStatus &partsStatus) const
|
bool CSimulatorFsx::updateRemoteAircraftParts(const CSimConnectObject &simObj, const CAircraftParts &parts, const IInterpolator::PartsStatus &partsStatus)
|
||||||
{
|
{
|
||||||
if (!simObj.hasValidRequestAndObjectId()) { return false; }
|
if (!simObj.hasValidRequestAndObjectId()) { return false; }
|
||||||
if (!partsStatus.isSupportingParts()) { return false; }
|
if (!partsStatus.isSupportingParts()) { return false; }
|
||||||
|
|
||||||
DataDefinitionRemoteAircraftParts ddRemoteAircraftParts;
|
DataDefinitionRemoteAircraftParts ddRemoteAircraftParts; // no init, all values will be set
|
||||||
|
|
||||||
ddRemoteAircraftParts.lightStrobe = parts.getLights().isStrobeOn() ? 1 : 0;
|
ddRemoteAircraftParts.lightStrobe = parts.getLights().isStrobeOn() ? 1 : 0;
|
||||||
ddRemoteAircraftParts.lightLanding = parts.getLights().isLandingOn() ? 1 : 0;
|
ddRemoteAircraftParts.lightLanding = parts.getLights().isLandingOn() ? 1 : 0;
|
||||||
@@ -996,13 +1000,20 @@ namespace BlackSimPlugin
|
|||||||
return this->sendRemoteAircraftPartsToSim(simObj, ddRemoteAircraftParts);
|
return this->sendRemoteAircraftPartsToSim(simObj, ddRemoteAircraftParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFsx::sendRemoteAircraftPartsToSim(const CSimConnectObject &simObj, DataDefinitionRemoteAircraftParts &ddRemoteAircraftParts) const
|
bool CSimulatorFsx::sendRemoteAircraftPartsToSim(const CSimConnectObject &simObj, DataDefinitionRemoteAircraftParts &ddRemoteAircraftParts)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_hSimConnect);
|
Q_ASSERT(m_hSimConnect);
|
||||||
HRESULT hr = S_OK;
|
const DWORD objectId = simObj.getObjectId();
|
||||||
hr += SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftParts,
|
if (m_lastPartsSendToSim.contains(objectId))
|
||||||
static_cast<SIMCONNECT_OBJECT_ID>(simObj.getObjectId()), 0, 0,
|
{
|
||||||
sizeof(DataDefinitionRemoteAircraftParts), &ddRemoteAircraftParts);
|
// no need to send same parts
|
||||||
|
if (m_lastPartsSendToSim[objectId] == ddRemoteAircraftParts) { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastPartsSendToSim[objectId] = ddRemoteAircraftParts;
|
||||||
|
HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftParts,
|
||||||
|
objectId, 0, 0,
|
||||||
|
sizeof(DataDefinitionRemoteAircraftParts), &ddRemoteAircraftParts);
|
||||||
|
|
||||||
if (hr != S_OK) { CLogMessage(this).warning("Failed so set parts on SimObject '%1' callsign: '%2'") << simObj.getObjectId() << simObj.getCallsign(); }
|
if (hr != S_OK) { CLogMessage(this).warning("Failed so set parts on SimObject '%1' callsign: '%2'") << simObj.getObjectId() << simObj.getCallsign(); }
|
||||||
return hr == S_OK;
|
return hr == S_OK;
|
||||||
@@ -1126,6 +1137,7 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
m_simConnectObjects.clear();
|
m_simConnectObjects.clear();
|
||||||
m_outOfRealityBubble.clear();
|
m_outOfRealityBubble.clear();
|
||||||
|
m_lastPartsSendToSim.clear();
|
||||||
CSimulatorFsCommon::clearAllAircraft();
|
CSimulatorFsCommon::clearAllAircraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,14 +169,14 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
//! Update remote aircraft parts (send to FSX)
|
//! Update remote aircraft parts (send to FSX)
|
||||||
bool updateRemoteAircraftParts(const CSimConnectObject &simObj,
|
bool updateRemoteAircraftParts(const CSimConnectObject &simObj,
|
||||||
const BlackMisc::Aviation::CAircraftParts &parts, const BlackMisc::Simulation::IInterpolator::PartsStatus &partsStatus) const;
|
const BlackMisc::Aviation::CAircraftParts &parts, const BlackMisc::Simulation::IInterpolator::PartsStatus &partsStatus);
|
||||||
|
|
||||||
//! Update remote aircraft parts by guessing (send to FSX)
|
//! Update remote aircraft parts by guessing (send to FSX)
|
||||||
bool guessAndUpdateRemoteAircraftParts(const CSimConnectObject &simObj,
|
bool guessAndUpdateRemoteAircraftParts(const CSimConnectObject &simObj,
|
||||||
const BlackMisc::Aviation::CAircraftSituation &interpolatedSituation, const BlackMisc::Simulation::IInterpolator::InterpolationStatus &interpolationStatus) const;
|
const BlackMisc::Aviation::CAircraftSituation &interpolatedSituation, const BlackMisc::Simulation::IInterpolator::InterpolationStatus &interpolationStatus);
|
||||||
|
|
||||||
//! Send parts to sim
|
//! Send parts to sim
|
||||||
bool sendRemoteAircraftPartsToSim(const CSimConnectObject &simObj, DataDefinitionRemoteAircraftParts &ddRemoteAircraftParts) const;
|
bool sendRemoteAircraftPartsToSim(const CSimConnectObject &simObj, DataDefinitionRemoteAircraftParts &ddRemoteAircraftParts);
|
||||||
|
|
||||||
//! Called when data about our own aircraft are received
|
//! Called when data about our own aircraft are received
|
||||||
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
void updateOwnAircraftFromSimulator(const DataDefinitionOwnAircraft &simulatorOwnAircraft);
|
||||||
@@ -235,7 +235,8 @@ namespace BlackSimPlugin
|
|||||||
HANDLE m_hSimConnect = nullptr; //!< handle to SimConnect object
|
HANDLE m_hSimConnect = nullptr; //!< handle to SimConnect object
|
||||||
CSimConnectObjects m_simConnectObjects; //!< AI objects and their object / request ids
|
CSimConnectObjects m_simConnectObjects; //!< AI objects and their object / request ids
|
||||||
QTimer m_realityBubbleTimer { this }; //!< updating of aircraft out of reality bubble
|
QTimer m_realityBubbleTimer { this }; //!< updating of aircraft out of reality bubble
|
||||||
BlackMisc::Simulation::CSimulatedAircraftList m_outOfRealityBubble; //!< aircraft removed by FSX because they are out of reality bubble
|
BlackMisc::Simulation::CSimulatedAircraftList m_outOfRealityBubble; //!< aircraft removed by FSX because they are out of reality bubble
|
||||||
|
QHash<DWORD, DataDefinitionRemoteAircraftParts> m_lastPartsSendToSim; //!< Last parts send to simulator, avoid always sending same parts
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Listener for FSX
|
//! Listener for FSX
|
||||||
|
|||||||
Reference in New Issue
Block a user