Clang QtC warnings fixed for FSX common

This commit is contained in:
Klaus Basan
2018-08-16 02:51:20 +02:00
parent e21328a5a6
commit 7d2c063aba
2 changed files with 75 additions and 65 deletions

View File

@@ -47,6 +47,13 @@ namespace BlackSimPlugin
{ {
namespace FsxCommon namespace FsxCommon
{ {
//! Correctly casted values/checks @{
static HRESULT inline s_ok() { return S_OK; }
static bool inline isOk(HRESULT result) { return result == s_ok(); }
static bool inline isFailure(HRESULT result) { return !isOk(result); }
static bool inline dtb(double doubleBool) { return static_cast<bool>(qRound(doubleBool)); }
//! @}
CSimulatorFsxCommon::CSimulatorFsxCommon(const CSimulatorPluginInfo &info, CSimulatorFsxCommon::CSimulatorFsxCommon(const CSimulatorPluginInfo &info,
IOwnAircraftProvider *ownAircraftProvider, IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider,
@@ -90,7 +97,7 @@ namespace BlackSimPlugin
if (!loadAndResolveSimConnect(true)) { return false; } if (!loadAndResolveSimConnect(true)) { return false; }
if (FAILED(SimConnect_Open(&m_hSimConnect, sApp->swiftVersionChar(), nullptr, 0, 0, 0))) if (FAILED(SimConnect_Open(&m_hSimConnect, sApp->swiftVersionChar(), nullptr, 0, nullptr, 0)))
{ {
// reset state as expected for unconnected // reset state as expected for unconnected
return false; return false;
@@ -186,11 +193,11 @@ namespace BlackSimPlugin
{ {
byte ident = newTransponder.isIdentifying() ? 1U : 0U; // 1 is ident byte ident = newTransponder.isIdentifying() ? 1U : 0U; // 1 is ident
byte standby = newTransponder.isInStandby() ? 1U : 0U; // 1 is standby byte standby = newTransponder.isInStandby() ? 1U : 0U; // 1 is standby
HRESULT hr = S_OK; HRESULT hr = s_ok();
hr += SimConnect_SetClientData(m_hSimConnect, ClientAreaSquawkBox, CSimConnectDefinitions::DataClientAreaSbIdent, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT, 0, 1, &ident); hr += SimConnect_SetClientData(m_hSimConnect, ClientAreaSquawkBox, CSimConnectDefinitions::DataClientAreaSbIdent, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT, 0, 1, &ident);
hr += SimConnect_SetClientData(m_hSimConnect, ClientAreaSquawkBox, CSimConnectDefinitions::DataClientAreaSbStandby, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT, 0, 1, &standby); hr += SimConnect_SetClientData(m_hSimConnect, ClientAreaSquawkBox, CSimConnectDefinitions::DataClientAreaSbStandby, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT, 0, 1, &standby);
if (hr != S_OK) if (isFailure(hr))
{ {
this->triggerAutoTraceSendId(); this->triggerAutoTraceSendId();
CLogMessage(this).warning("Setting transponder mode failed (SB offsets)"); CLogMessage(this).warning("Setting transponder mode failed (SB offsets)");
@@ -268,7 +275,7 @@ namespace BlackSimPlugin
return specificInfo. return specificInfo.
arg(m_dispatchProcCount).arg(m_dispatchProcEmptyCount). arg(m_dispatchProcCount).arg(m_dispatchProcEmptyCount).
arg(m_dispatchTimeMs).arg(m_dispatchProcTimeMs).arg(m_dispatchMaxTimeMs).arg(m_dispatchProcMaxTimeMs). arg(m_dispatchTimeMs).arg(m_dispatchProcTimeMs).arg(m_dispatchMaxTimeMs).arg(m_dispatchProcMaxTimeMs).
arg(CSimConnectUtilities::simConnectReceiveIdToString(m_dispatchReceiveIdMaxTime), requestIdToString(m_dispatchRequestIdMaxTime)). arg(CSimConnectUtilities::simConnectReceiveIdToString(static_cast<DWORD>(m_dispatchReceiveIdMaxTime)), requestIdToString(m_dispatchRequestIdMaxTime)).
arg(m_requestSimObjectDataCount); arg(m_requestSimObjectDataCount);
} }
@@ -291,7 +298,7 @@ namespace BlackSimPlugin
sizeof(SIMCONNECT_DATA_INITPOSITION), &position); sizeof(SIMCONNECT_DATA_INITPOSITION), &position);
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO); } if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO); }
if (hr == S_OK) if (isOk(hr))
{ {
this->requestTerrainProbeData(callsign); this->requestTerrainProbeData(callsign);
emit this->requestedElevation(callsign); emit this->requestedElevation(callsign);
@@ -302,7 +309,7 @@ namespace BlackSimPlugin
const CStatusMessage msg = CStatusMessage(this).error("Cannot request AI position: '%1'") << callsign.asString(); const CStatusMessage msg = CStatusMessage(this).error("Cannot request AI position: '%1'") << callsign.asString();
CLogMessage::preformatted(msg); CLogMessage::preformatted(msg);
} }
return hr == S_OK; return isOk(hr);
} }
bool CSimulatorFsxCommon::isTracingSendId() const bool CSimulatorFsxCommon::isTracingSendId() const
@@ -411,7 +418,7 @@ namespace BlackSimPlugin
CSimConnectDefinitions::DataSimEnvironment, CSimConnectDefinitions::DataSimEnvironment,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED); SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED);
if (hr != S_OK) if (isFailure(hr))
{ {
this->triggerAutoTraceSendId(); this->triggerAutoTraceSendId();
CLogMessage(this).error("FSX plugin: SimConnect_RequestDataOnSimObject failed"); CLogMessage(this).error("FSX plugin: SimConnect_RequestDataOnSimObject failed");
@@ -422,7 +429,7 @@ namespace BlackSimPlugin
hr += SimConnect_RequestClientData(m_hSimConnect, ClientAreaSquawkBox, CSimConnectDefinitions::RequestSbData, hr += SimConnect_RequestClientData(m_hSimConnect, ClientAreaSquawkBox, CSimConnectDefinitions::RequestSbData,
CSimConnectDefinitions::DataClientAreaSb, SIMCONNECT_CLIENT_DATA_PERIOD_SECOND, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED); CSimConnectDefinitions::DataClientAreaSb, SIMCONNECT_CLIENT_DATA_PERIOD_SECOND, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED);
if (hr != S_OK) if (isFailure(hr))
{ {
this->triggerAutoTraceSendId(); this->triggerAutoTraceSendId();
CLogMessage(this).error("FSX plugin: SimConnect_RequestClientData failed"); CLogMessage(this).error("FSX plugin: SimConnect_RequestClientData failed");
@@ -537,16 +544,16 @@ namespace BlackSimPlugin
aircraftSituation.setPressureAltitude(CAltitude(simulatorOwnAircraft.pressureAltitude, CAltitude::MeanSeaLevel, CAltitude::PressureAltitude, CLengthUnit::m())); aircraftSituation.setPressureAltitude(CAltitude(simulatorOwnAircraft.pressureAltitude, CAltitude::MeanSeaLevel, CAltitude::PressureAltitude, CLengthUnit::m()));
// set on ground also in situation for consistency and future usage // set on ground also in situation for consistency and future usage
// it is duplicated in parts // it is duplicated in parts
aircraftSituation.setOnGround(simulatorOwnAircraft.simOnGround ? CAircraftSituation::OnGround : CAircraftSituation::NotOnGround, CAircraftSituation::OutOnGroundOwnAircraft); aircraftSituation.setOnGround(dtb(simulatorOwnAircraft.simOnGround) ? CAircraftSituation::OnGround : CAircraftSituation::NotOnGround, CAircraftSituation::OutOnGroundOwnAircraft);
const CAircraftLights lights(simulatorOwnAircraft.lightStrobe, simulatorOwnAircraft.lightLanding, simulatorOwnAircraft.lightTaxi, const CAircraftLights lights(dtb(simulatorOwnAircraft.lightStrobe), dtb(simulatorOwnAircraft.lightLanding), dtb(simulatorOwnAircraft.lightTaxi),
simulatorOwnAircraft.lightBeacon, simulatorOwnAircraft.lightNav, simulatorOwnAircraft.lightLogo); dtb(simulatorOwnAircraft.lightBeacon), dtb(simulatorOwnAircraft.lightNav), dtb(simulatorOwnAircraft.lightLogo));
CAircraftEngineList engines; CAircraftEngineList engines;
const QList<bool> helperList const QList<bool> helperList
{ {
simulatorOwnAircraft.engine1Combustion != 0, simulatorOwnAircraft.engine2Combustion != 0, dtb(simulatorOwnAircraft.engine1Combustion), dtb(simulatorOwnAircraft.engine2Combustion),
simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0 dtb(simulatorOwnAircraft.engine3Combustion), dtb(simulatorOwnAircraft.engine4Combustion)
}; };
for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index) for (int index = 0; index < simulatorOwnAircraft.numberOfEngines; ++index)
@@ -554,11 +561,12 @@ namespace BlackSimPlugin
engines.push_back(CAircraftEngine(index + 1, helperList.at(index))); engines.push_back(CAircraftEngine(index + 1, helperList.at(index)));
} }
const CAircraftParts parts(lights, simulatorOwnAircraft.gearHandlePosition, const CAircraftParts parts(lights,
simulatorOwnAircraft.flapsHandlePosition * 100, dtb(simulatorOwnAircraft.gearHandlePosition),
simulatorOwnAircraft.spoilersHandlePosition, qRound(simulatorOwnAircraft.flapsHandlePosition * 100),
dtb(simulatorOwnAircraft.spoilersHandlePosition),
engines, engines,
simulatorOwnAircraft.simOnGround); dtb(simulatorOwnAircraft.simOnGround));
// set values // set values
this->updateOwnSituation(aircraftSituation); this->updateOwnSituation(aircraftSituation);
@@ -585,7 +593,7 @@ namespace BlackSimPlugin
const bool changedCom2 = myAircraft.getCom2System() != com2; const bool changedCom2 = myAircraft.getCom2System() != com2;
m_simCom2 = com2; m_simCom2 = com2;
transponder.setTransponderCode(simulatorOwnAircraft.transponderCode); transponder.setTransponderCode(qRound(simulatorOwnAircraft.transponderCode));
const bool changedXpr = (myAircraft.getTransponderCode() != transponder.getTransponderCode()); const bool changedXpr = (myAircraft.getTransponderCode() != transponder.getTransponderCode());
if (changedCom1 || changedCom2 || changedXpr) if (changedCom1 || changedCom2 || changedXpr)
@@ -785,7 +793,7 @@ namespace BlackSimPlugin
hr += SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeAlt, 1, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY); hr += SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeAlt, 1, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
hr += SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeAtt, 1, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY); hr += SimConnect_TransmitClientEvent(m_hSimConnect, objectId, EventFreezeAtt, 1, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
if (hr != S_OK) if (isFailure(hr))
{ {
msg = CStatusMessage(this).error("Cannot confirm object %1, cs: '%2' model: '%3'") << objectId << remoteAircraft.getCallsignAsString() << remoteAircraft.getModelString(); msg = CStatusMessage(this).error("Cannot confirm object %1, cs: '%2' model: '%3'") << objectId << remoteAircraft.getCallsignAsString() << remoteAircraft.getModelString();
break; break;
@@ -800,14 +808,13 @@ namespace BlackSimPlugin
const bool updated = this->updateAircraftRendered(callsign, true); const bool updated = this->updateAircraftRendered(callsign, true);
if (updated) if (updated)
{ {
emit aircraftRenderingChanged(simObject.getAircraft()); emit this->aircraftRenderingChanged(simObject.getAircraft());
static const QString debugMsg("CS: '%1' model: '%2' verified, request/object id: %3 %4"); static const QString debugMsg("CS: '%1' model: '%2' verified, request/object id: %3 %4");
if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, debugMsg.arg(callsign.toQString(), remoteAircraft.getModelString()).arg(requestId).arg(objectId)); } if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, debugMsg.arg(callsign.toQString(), remoteAircraft.getModelString()).arg(requestId).arg(objectId)); }
} }
else else
{ {
CLogMessage(this).warning("Verified aircraft '%1' model '%2', request/object id: %3 %4 already rendered") << CLogMessage(this).warning("Verified aircraft '%1' model '%2', request/object id: %3 %4 already rendered") << callsign.asString() << remoteAircraft.getModelString() << requestId << objectId;
callsign.asString() << remoteAircraft.getModelString() << objectId;
} }
} }
while (false); while (false);
@@ -971,6 +978,11 @@ namespace BlackSimPlugin
this->dispatch(); this->dispatch();
} }
HRESULT CSimulatorFsxCommon::initEventsP3D()
{
return s_ok();
}
bool CSimulatorFsxCommon::parseDetails(const CSimpleCommandParser &parser) bool CSimulatorFsxCommon::parseDetails(const CSimpleCommandParser &parser)
{ {
// .driver sendid on|off // .driver sendid on|off
@@ -1041,7 +1053,7 @@ namespace BlackSimPlugin
} }
// error handling // error handling
if (hr != S_OK) if (isFailure(hr))
{ {
m_dispatchErrors++; m_dispatchErrors++;
this->triggerAutoTraceSendId(); this->triggerAutoTraceSendId();
@@ -1173,7 +1185,7 @@ namespace BlackSimPlugin
if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("CS: '%1' model: '%2' request: %3, init pos: %4").arg(callsign.toQString(), modelString).arg(requestId).arg(fsxPositionToString(initialPosition))); } if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("CS: '%1' model: '%2' request: %3, init pos: %4").arg(callsign.toQString(), modelString).arg(requestId).arg(fsxPositionToString(initialPosition))); }
const HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, qPrintable(modelString), qPrintable(callsign.toQString().left(12)), initialPosition, requestId); const HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, qPrintable(modelString), qPrintable(callsign.toQString().left(12)), initialPosition, requestId);
if (hr != S_OK) if (isFailure(hr))
{ {
const CStatusMessage msg = CStatusMessage(this).error("SimConnect, can not create AI traffic: '%1' '%2'") << callsign.toQString() << modelString; const CStatusMessage msg = CStatusMessage(this).error("SimConnect, can not create AI traffic: '%1' '%2'") << callsign.toQString() << modelString;
CLogMessage::preformatted(msg); CLogMessage::preformatted(msg);
@@ -1207,7 +1219,7 @@ namespace BlackSimPlugin
if (this->isTracingSendId()) { this->traceSendId(0, Q_FUNC_INFO, QString("Adding probe, req.id: %1").arg(requestId));} if (this->isTracingSendId()) { this->traceSendId(0, Q_FUNC_INFO, QString("Adding probe, req.id: %1").arg(requestId));}
bool ok = false; bool ok = false;
if (hr == S_OK) if (isOk(hr))
{ {
ok = true; ok = true;
const CAircraftModel model(modelString, CAircraftModel::TypeTerrainProbe, QStringLiteral("swift terrain probe"), CAircraftIcaoCode::unassignedIcao()); const CAircraftModel model(modelString, CAircraftModel::TypeTerrainProbe, QStringLiteral("swift terrain probe"), CAircraftIcaoCode::unassignedIcao());
@@ -1270,7 +1282,7 @@ namespace BlackSimPlugin
// call in SIM // call in SIM
const SIMCONNECT_DATA_REQUEST_ID requestId = simObject.getRequestId(CSimConnectDefinitions::SimObjectRemove); const SIMCONNECT_DATA_REQUEST_ID requestId = simObject.getRequestId(CSimConnectDefinitions::SimObjectRemove);
const HRESULT result = SimConnect_AIRemoveObject(m_hSimConnect, static_cast<SIMCONNECT_OBJECT_ID>(simObject.getObjectId()), requestId); const HRESULT result = SimConnect_AIRemoveObject(m_hSimConnect, static_cast<SIMCONNECT_OBJECT_ID>(simObject.getObjectId()), requestId);
if (result == S_OK) if (isOk(result))
{ {
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);} if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
} }
@@ -1320,7 +1332,7 @@ namespace BlackSimPlugin
HRESULT CSimulatorFsxCommon::initEvents() HRESULT CSimulatorFsxCommon::initEvents()
{ {
HRESULT hr = S_OK; HRESULT hr = s_ok();
// System events, see http://msdn.microsoft.com/en-us/library/cc526983.aspx#SimConnect_SubscribeToSystemEvent // System events, see http://msdn.microsoft.com/en-us/library/cc526983.aspx#SimConnect_SubscribeToSystemEvent
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventSimStatus, "Sim"); hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventSimStatus, "Sim");
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventObjectAdded, "ObjectAdded"); hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventObjectAdded, "ObjectAdded");
@@ -1328,7 +1340,7 @@ namespace BlackSimPlugin
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventFrame, "Frame"); hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventFrame, "Frame");
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventPause, "Pause"); hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventPause, "Pause");
hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventFlightLoaded, "FlightLoaded"); hr += SimConnect_SubscribeToSystemEvent(m_hSimConnect, SystemEventFlightLoaded, "FlightLoaded");
if (hr != S_OK) if (isFailure(hr))
{ {
CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_SubscribeToSystemEvent failed"; CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_SubscribeToSystemEvent failed";
return hr; return hr;
@@ -1372,7 +1384,7 @@ namespace BlackSimPlugin
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventToggleTaxiLights, "TOGGLE_TAXI_LIGHTS"); hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventToggleTaxiLights, "TOGGLE_TAXI_LIGHTS");
hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventToggleWingLights, "TOGGLE_WING_LIGHTS"); hr += SimConnect_MapClientEventToSimEvent(m_hSimConnect, EventToggleWingLights, "TOGGLE_WING_LIGHTS");
if (hr != S_OK) if (isFailure(hr))
{ {
CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_MapClientEventToSimEvent failed"; CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_MapClientEventToSimEvent failed";
return hr; return hr;
@@ -1381,7 +1393,7 @@ namespace BlackSimPlugin
// facility // facility
SIMCONNECT_DATA_REQUEST_ID requestId = static_cast<SIMCONNECT_DATA_REQUEST_ID>(CSimConnectDefinitions::RequestFacility); SIMCONNECT_DATA_REQUEST_ID requestId = static_cast<SIMCONNECT_DATA_REQUEST_ID>(CSimConnectDefinitions::RequestFacility);
hr += SimConnect_SubscribeToFacilities(m_hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE_AIRPORT, requestId); hr += SimConnect_SubscribeToFacilities(m_hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE_AIRPORT, requestId);
if (hr != S_OK) if (isFailure(hr))
{ {
CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_SubscribeToFacilities failed"; CLogMessage(this).error("FSX plugin error: %1") << "SimConnect_SubscribeToFacilities failed";
return hr; return hr;
@@ -1399,7 +1411,7 @@ namespace BlackSimPlugin
// called when connected // called when connected
HRESULT hr = this->initEvents(); HRESULT hr = this->initEvents();
if (hr != S_OK) if (isFailure(hr))
{ {
CLogMessage(this).error("FSX plugin: initEvents failed"); CLogMessage(this).error("FSX plugin: initEvents failed");
return hr; return hr;
@@ -1407,7 +1419,7 @@ namespace BlackSimPlugin
// init data definitions and SB data area // init data definitions and SB data area
hr += this->initDataDefinitionsWhenConnected(); hr += this->initDataDefinitionsWhenConnected();
if (hr != S_OK) if (isFailure(hr))
{ {
CLogMessage(this).error("FSX plugin: initDataDefinitionsWhenConnected failed"); CLogMessage(this).error("FSX plugin: initDataDefinitionsWhenConnected failed");
return hr; return hr;
@@ -1464,7 +1476,7 @@ namespace BlackSimPlugin
const HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftSetPosition, const HRESULT hr = SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::DataRemoteAircraftSetPosition,
static_cast<SIMCONNECT_OBJECT_ID>(objectId), 0, 0, static_cast<SIMCONNECT_OBJECT_ID>(objectId), 0, 0,
sizeof(SIMCONNECT_DATA_INITPOSITION), &position); sizeof(SIMCONNECT_DATA_INITPOSITION), &position);
if (hr == S_OK) if (isOk(hr))
{ {
this->rememberLastSent(result); // remember this->rememberLastSent(result); // remember
if (this->isTracingSendId()) { this->traceSendId(objectId, Q_FUNC_INFO, simObject.toQString()); } if (this->isTracingSendId()) { this->traceSendId(objectId, Q_FUNC_INFO, simObject.toQString()); }
@@ -1549,7 +1561,7 @@ namespace BlackSimPlugin
objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0,
sizeof(DataDefinitionRemoteAircraftPartsWithoutLights), &ddRemoteAircraftPartsWithoutLights); sizeof(DataDefinitionRemoteAircraftPartsWithoutLights), &ddRemoteAircraftPartsWithoutLights);
if (hr == S_OK && m_simConnectObjects.contains(simObject.getCallsign())) if (isOk(hr) && m_simConnectObjects.contains(simObject.getCallsign()))
{ {
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);} if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
} }
@@ -1567,7 +1579,7 @@ namespace BlackSimPlugin
this->sendToggledLightsToSimulator(simObject, lights); this->sendToggledLightsToSimulator(simObject, lights);
// done // done
const bool ok = (hr == S_OK); const bool ok = isOk(hr);
if (!ok) { this->triggerAutoTraceSendId(); } if (!ok) { this->triggerAutoTraceSendId(); }
return ok; return ok;
} }
@@ -1641,7 +1653,7 @@ namespace BlackSimPlugin
SIMCONNECT_DATA_INITPOSITION position = CSimulatorFsxCommon::coordinateToFsxPosition(situation); SIMCONNECT_DATA_INITPOSITION position = CSimulatorFsxCommon::coordinateToFsxPosition(situation);
position.Heading = situation.getHeading().value(CAngleUnit::deg()); position.Heading = situation.getHeading().value(CAngleUnit::deg());
position.Airspeed = situation.getGroundSpeed().value(CSpeedUnit::kts()); position.Airspeed = static_cast<DWORD>(situation.getGroundSpeed().valueInteger(CSpeedUnit::kts()));
// MSFS has inverted pitch and bank angles // MSFS has inverted pitch and bank angles
position.Pitch = -situation.getPitch().value(CAngleUnit::deg()); position.Pitch = -situation.getPitch().value(CAngleUnit::deg());
@@ -1683,21 +1695,21 @@ namespace BlackSimPlugin
QDateTime myDateTime = QDateTime::currentDateTimeUtc(); QDateTime myDateTime = QDateTime::currentDateTimeUtc();
if (!m_syncTimeOffset.isZeroEpsilonConsidered()) if (!m_syncTimeOffset.isZeroEpsilonConsidered())
{ {
int offsetSeconds = m_syncTimeOffset.valueRounded(CTimeUnit::s(), 0); int offsetSeconds = m_syncTimeOffset.valueInteger(CTimeUnit::s());
myDateTime = myDateTime.addSecs(offsetSeconds); myDateTime = myDateTime.addSecs(offsetSeconds);
} }
const QTime myTime = myDateTime.time(); const QTime myTime = myDateTime.time();
const DWORD h = static_cast<DWORD>(myTime.hour()); const DWORD h = static_cast<DWORD>(myTime.hour());
const DWORD m = static_cast<DWORD>(myTime.minute()); const DWORD m = static_cast<DWORD>(myTime.minute());
const int targetMins = myTime.hour() * 60 + myTime.minute(); const int targetMins = myTime.hour() * 60 + myTime.minute();
const int simMins = zuluTimeSim.valueRounded(CTimeUnit::min()); const int simMins = zuluTimeSim.valueInteger(CTimeUnit::min());
const int diffMins = qAbs(targetMins - simMins); const int diffMins = qAbs(targetMins - simMins);
if (diffMins < 2) { return; } if (diffMins < 2) { return; }
HRESULT hr = S_OK; HRESULT hr = s_ok();
hr += SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluHours, h, SIMCONNECT_GROUP_PRIORITY_STANDARD, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY); hr += SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluHours, h, SIMCONNECT_GROUP_PRIORITY_STANDARD, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
hr += SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluMinutes, m, SIMCONNECT_GROUP_PRIORITY_STANDARD, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY); hr += SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluMinutes, m, SIMCONNECT_GROUP_PRIORITY_STANDARD, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
if (hr != S_OK) if (isFailure(hr))
{ {
CLogMessage(this).warning("Sending time sync failed!"); CLogMessage(this).warning("Sending time sync failed!");
} }
@@ -1734,7 +1746,7 @@ namespace BlackSimPlugin
CSimConnectDefinitions::DataRemoteAircraftGetPosition, CSimConnectDefinitions::DataRemoteAircraftGetPosition,
simObject.getObjectId(), period); simObject.getObjectId(), period);
if (result == S_OK) if (isOk(result))
{ {
m_requestSimObjectDataCount++; m_requestSimObjectDataCount++;
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);} if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
@@ -1760,7 +1772,7 @@ namespace BlackSimPlugin
CSimConnectDefinitions::DataRemoteAircraftGetPosition, CSimConnectDefinitions::DataRemoteAircraftGetPosition,
objectId, SIMCONNECT_PERIOD_ONCE); objectId, SIMCONNECT_PERIOD_ONCE);
if (result == S_OK) if (isOk(result))
{ {
if (this->isTracingSendId()) { this->traceSendId(requestId, Q_FUNC_INFO); } if (this->isTracingSendId()) { this->traceSendId(requestId, Q_FUNC_INFO); }
m_pendingProbeRequests.insert(requestId, callsign); m_pendingProbeRequests.insert(requestId, callsign);
@@ -1781,7 +1793,7 @@ namespace BlackSimPlugin
m_hSimConnect, requestId, m_hSimConnect, requestId,
CSimConnectDefinitions::DataRemoteAircraftLights, simObject.getObjectId(), CSimConnectDefinitions::DataRemoteAircraftLights, simObject.getObjectId(),
SIMCONNECT_PERIOD_SECOND); SIMCONNECT_PERIOD_SECOND);
if (result == S_OK) if (isOk(result))
{ {
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);} if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
return true; return true;
@@ -1801,7 +1813,7 @@ namespace BlackSimPlugin
m_hSimConnect, requestId, m_hSimConnect, requestId,
CSimConnectDefinitions::DataRemoteAircraftModelData, simObject.getObjectId(), CSimConnectDefinitions::DataRemoteAircraftModelData, simObject.getObjectId(),
SIMCONNECT_PERIOD_ONCE); SIMCONNECT_PERIOD_ONCE);
if (result == S_OK) if (isOk(result))
{ {
if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);} if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
return true; return true;
@@ -1821,14 +1833,14 @@ namespace BlackSimPlugin
m_hSimConnect, requestId, m_hSimConnect, requestId,
CSimConnectDefinitions::DataRemoteAircraftGetPosition, CSimConnectDefinitions::DataRemoteAircraftGetPosition,
simObject.getObjectId(), SIMCONNECT_PERIOD_NEVER); simObject.getObjectId(), SIMCONNECT_PERIOD_NEVER);
if (result == S_OK) { if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO, "Position");} } if (isOk(result)) { if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO, "Position");} }
requestId = simObject.getRequestId(CSimConnectDefinitions::SimObjectLights); requestId = simObject.getRequestId(CSimConnectDefinitions::SimObjectLights);
result = SimConnect_RequestDataOnSimObject( result = SimConnect_RequestDataOnSimObject(
m_hSimConnect, requestId, m_hSimConnect, requestId,
CSimConnectDefinitions::DataRemoteAircraftLights, simObject.getObjectId(), CSimConnectDefinitions::DataRemoteAircraftLights, simObject.getObjectId(),
SIMCONNECT_PERIOD_NEVER); SIMCONNECT_PERIOD_NEVER);
if (result == S_OK) { if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO, "Lights");} } if (isOk(result)) { if (this->isTracingSendId()) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO, "Lights");} }
Q_UNUSED(result); Q_UNUSED(result);
return true; return true;
} }
@@ -1892,7 +1904,7 @@ namespace BlackSimPlugin
if (MaxSendIdTraces < 1) { return; } if (MaxSendIdTraces < 1) { return; }
DWORD dwLastId = 0; DWORD dwLastId = 0;
const HRESULT hr = SimConnect_GetLastSentPacketID(m_hSimConnect, &dwLastId); const HRESULT hr = SimConnect_GetLastSentPacketID(m_hSimConnect, &dwLastId);
if (hr != S_OK) { return; } if (isFailure(hr)) { return; }
if (m_sendIdTraces.size() > MaxSendIdTraces) { m_sendIdTraces.removeFirst(); } if (m_sendIdTraces.size() > MaxSendIdTraces) { m_sendIdTraces.removeFirst(); }
const TraceFsxSendId trace(dwLastId, simObjectId, const TraceFsxSendId trace(dwLastId, simObjectId,
details.isEmpty() ? function : details + ", " + function); details.isEmpty() ? function : details + ", " + function);
@@ -1922,7 +1934,7 @@ namespace BlackSimPlugin
if (!probeSimObject.isConfirmedAdded()) { continue; } if (!probeSimObject.isConfirmedAdded()) { continue; }
const SIMCONNECT_DATA_REQUEST_ID requestId = probeSimObject.getRequestId(CSimConnectDefinitions::SimObjectRemove); const SIMCONNECT_DATA_REQUEST_ID requestId = probeSimObject.getRequestId(CSimConnectDefinitions::SimObjectRemove);
const HRESULT result = SimConnect_AIRemoveObject(m_hSimConnect, static_cast<SIMCONNECT_OBJECT_ID>(probeSimObject.getObjectId()), requestId); const HRESULT result = SimConnect_AIRemoveObject(m_hSimConnect, static_cast<SIMCONNECT_OBJECT_ID>(probeSimObject.getObjectId()), requestId);
if (result == S_OK) if (isOk(result))
{ {
c++; c++;
} }
@@ -2051,15 +2063,15 @@ namespace BlackSimPlugin
if (this->isShuttingDown()) { return; } if (this->isShuttingDown()) { return; }
Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background"); Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background");
HANDLE hSimConnect; HANDLE hSimConnect;
HRESULT result = SimConnect_Open(&hSimConnect, sApp->swiftVersionChar(), nullptr, 0, 0, 0); HRESULT result = SimConnect_Open(&hSimConnect, sApp->swiftVersionChar(), nullptr, 0, nullptr, 0);
bool check = false; bool check = false;
if (result == S_OK) if (isOk(result))
{ {
for (int i = 0; !check && i < 3 && !this->isShuttingDown(); i++) for (int i = 0; !check && i < 3 && !this->isShuttingDown(); i++)
{ {
// result not always in first dispatch as we first have to obtain simulator name // result not always in first dispatch as we first have to obtain simulator name
result = SimConnect_CallDispatch(hSimConnect, CSimulatorFsxCommonListener::SimConnectProc, this); result = SimConnect_CallDispatch(hSimConnect, CSimulatorFsxCommonListener::SimConnectProc, this);
if (result != S_OK) { break; } // means serious failure if (isFailure(result)) { break; } // means serious failure
check = this->checkVersionAndSimulator(); check = this->checkVersionAndSimulator();
if (!check) { sApp->processEventsFor(500); } if (!check) { sApp->processEventsFor(500); }
} }
@@ -2114,10 +2126,8 @@ namespace BlackSimPlugin
CLogMessage(static_cast<CSimulatorFsxCommonListener *>(nullptr)).info("Connect to %1: '%2'") << simListener->getPluginInfo().getIdentifier() << simListener->backendInfo(); CLogMessage(static_cast<CSimulatorFsxCommonListener *>(nullptr)).info("Connect to %1: '%2'") << simListener->getPluginInfo().getIdentifier() << simListener->backendInfo();
break; break;
} }
case SIMCONNECT_RECV_ID_EXCEPTION: case SIMCONNECT_RECV_ID_EXCEPTION: break;
break; default: break;
default:
break;
} }
} }
} // namespace } // namespace

View File

@@ -183,7 +183,7 @@ namespace BlackSimPlugin
virtual void timerEvent(QTimerEvent *event) override; virtual void timerEvent(QTimerEvent *event) override;
//! Specific P3D events //! Specific P3D events
virtual HRESULT initEventsP3D() { return S_OK; } virtual HRESULT initEventsP3D();
//! \addtogroup swiftdotcommands //! \addtogroup swiftdotcommands
//! @{ //! @{
@@ -422,8 +422,8 @@ namespace BlackSimPlugin
static constexpr int SkipUpdateCyclesForCockpit = 10; //!< skip x cycles before updating cockpit again static constexpr int SkipUpdateCyclesForCockpit = 10; //!< skip x cycles before updating cockpit again
static constexpr int IgnoreReceiveExceptions = 10; //!< skip exceptions when displayed more than x times static constexpr int IgnoreReceiveExceptions = 10; //!< skip exceptions when displayed more than x times
static constexpr int MaxSendIdTraces = 10000; //!< max.traces of send id static constexpr int MaxSendIdTraces = 10000; //!< max.traces of send id
static constexpr int MaxSimObjAircraft = 10000; //!< max.number of SimObjects at the same time static constexpr DWORD MaxSimObjAircraft = 10000; //!< max.number of SimObjects at the same time
static constexpr int MaxSimObjProbes = 100; //!< max. probes static constexpr DWORD MaxSimObjProbes = 100; //!< max. probes
// -- range for sim data, each sim object will get its own request id and use the offset ranges // -- range for sim data, each sim object will get its own request id and use the offset ranges
static constexpr int RequestSimObjAircraftStart = static_cast<int>(CSimConnectDefinitions::RequestEndMarker); static constexpr int RequestSimObjAircraftStart = static_cast<int>(CSimConnectDefinitions::RequestEndMarker);
@@ -462,8 +462,8 @@ namespace BlackSimPlugin
SIMCONNECT_RECV_ID m_dispatchReceiveIdLast = SIMCONNECT_RECV_ID_NULL; //!< last receive id from dispatching SIMCONNECT_RECV_ID m_dispatchReceiveIdLast = SIMCONNECT_RECV_ID_NULL; //!< last receive id from dispatching
SIMCONNECT_RECV_ID m_dispatchReceiveIdMaxTime = SIMCONNECT_RECV_ID_NULL; //!< receive id corresponding to max.time SIMCONNECT_RECV_ID m_dispatchReceiveIdMaxTime = SIMCONNECT_RECV_ID_NULL; //!< receive id corresponding to max.time
DWORD m_dispatchRequestIdLast = -1; //!< request id if any DWORD m_dispatchRequestIdLast = CSimConnectDefinitions::RequestEndMarker; //!< request id if any for last request
DWORD m_dispatchRequestIdMaxTime = -1; //!< max.time request DWORD m_dispatchRequestIdMaxTime = CSimConnectDefinitions::RequestEndMarker; //!< request id corresponding to max.time
// sending via SimConnect // sending via SimConnect
QList<TraceFsxSendId> m_sendIdTraces; //!< Send id traces for debugging QList<TraceFsxSendId> m_sendIdTraces; //!< Send id traces for debugging
@@ -482,8 +482,8 @@ namespace BlackSimPlugin
public: public:
//! Offsets @{ //! Offsets @{
static DWORD offsetSimObjAircraft(CSimConnectDefinitions::SimObjectRequest req) { return MaxSimObjAircraft * req; } static DWORD offsetSimObjAircraft(CSimConnectDefinitions::SimObjectRequest req) { return MaxSimObjAircraft * static_cast<DWORD>(req); }
static DWORD offsetSimObjTerrainProbe(CSimConnectDefinitions::SimObjectRequest req) { return MaxSimObjProbes * req; } static DWORD offsetSimObjTerrainProbe(CSimConnectDefinitions::SimObjectRequest req) { return MaxSimObjProbes * static_cast<DWORD>(req); }
//! @} //! @}
}; };
@@ -516,7 +516,7 @@ namespace BlackSimPlugin
bool checkSimConnectDll() const; bool checkSimConnectDll() const;
private: private:
QTimer m_timer { this }; QTimer m_timer;
QString m_simulatorVersion; QString m_simulatorVersion;
QString m_simConnectVersion; QString m_simConnectVersion;
QString m_simulatorName; QString m_simulatorName;