mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
Ref T261, FSX driver improvements
* sending gnd flag can be disabled * check position before adding object * do not stop requested data if aircraft is pending -> causes FSX SimConnect exception
This commit is contained in:
committed by
Roland Winklmeier
parent
9c7134ff56
commit
ac953de6fd
@@ -924,7 +924,7 @@ namespace BlackSimPlugin
|
|||||||
m_addPendingSimObjTimer.start(AddPendingAircraftIntervalMs); // restart
|
m_addPendingSimObjTimer.start(AddPendingAircraftIntervalMs); // restart
|
||||||
|
|
||||||
const bool hasPendingAdded = m_simConnectObjects.containsPendingAdded();
|
const bool hasPendingAdded = m_simConnectObjects.containsPendingAdded();
|
||||||
const bool canAdd = m_simSimulating && m_simConnected && !hasPendingAdded;
|
bool canAdd = m_simSimulating && m_simConnected && !hasPendingAdded;
|
||||||
|
|
||||||
Q_ASSERT_X(!hasPendingAdded || m_simConnectObjects.countPendingAdded() < 2, Q_FUNC_INFO, "There must be only 0..1 pending objects");
|
Q_ASSERT_X(!hasPendingAdded || m_simConnectObjects.countPendingAdded() < 2, Q_FUNC_INFO, "There must be only 0..1 pending objects");
|
||||||
if (this->showDebugLogMessage())
|
if (this->showDebugLogMessage())
|
||||||
@@ -954,6 +954,25 @@ namespace BlackSimPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// situation check
|
||||||
|
CAircraftSituation situation(newRemoteAircraft.getSituation());
|
||||||
|
if (canAdd && situation.isPositionOrAltitudeNull())
|
||||||
|
{
|
||||||
|
// invalid position
|
||||||
|
const CAircraftSituationList situations(this->remoteAircraftSituations(callsign));
|
||||||
|
if (situations.isEmpty())
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("No valid situations for '%1', will be added as pending") << callsign.asString();
|
||||||
|
canAdd = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("Invalid aircraft situation for new aircraft '%1', use situation") << callsign.asString();
|
||||||
|
situation = situations.findClosestTimeDistanceAdjusted(QDateTime::currentMSecsSinceEpoch());
|
||||||
|
Q_ASSERT_X(!situation.isPositionOrAltitudeNull(), Q_FUNC_INFO, "Invalid situation for new aircraft");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if we can add, do not add if simulator is stopped or other objects pending
|
// check if we can add, do not add if simulator is stopped or other objects pending
|
||||||
if (!canAdd)
|
if (!canAdd)
|
||||||
{
|
{
|
||||||
@@ -964,11 +983,21 @@ namespace BlackSimPlugin
|
|||||||
this->removeFromAddPendingAndAddAgainAircraft(callsign);
|
this->removeFromAddPendingAndAddAgainAircraft(callsign);
|
||||||
|
|
||||||
// create AI
|
// create AI
|
||||||
bool adding = false;
|
if (!this->isAircraftInRange(callsign))
|
||||||
const CSimulatedAircraft addedAircraft(newRemoteAircraft);
|
{
|
||||||
|
CLogMessage(this).info("Skipping adding of '%1' since it is no longer in range") << callsign.asString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup
|
||||||
|
const CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupConsolidated(callsign);
|
||||||
|
const bool sendGround = setup.sendGndFlagToSimulator();
|
||||||
|
|
||||||
|
// FSX/P3D adding
|
||||||
|
bool adding = false; // will be added flag
|
||||||
const SIMCONNECT_DATA_REQUEST_ID requestId = this->obtainRequestIdForSimData();
|
const SIMCONNECT_DATA_REQUEST_ID requestId = this->obtainRequestIdForSimData();
|
||||||
const SIMCONNECT_DATA_INITPOSITION initialPosition = CSimulatorFsxCommon::aircraftSituationToFsxPosition(addedAircraft.getSituation());
|
const SIMCONNECT_DATA_INITPOSITION initialPosition = CSimulatorFsxCommon::aircraftSituationToFsxPosition(newRemoteAircraft.getSituation(), sendGround);
|
||||||
const QString modelString(addedAircraft.getModelString());
|
const QString modelString(newRemoteAircraft.getModelString());
|
||||||
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);
|
||||||
@@ -976,13 +1005,13 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
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);
|
||||||
emit this->physicallyAddingRemoteModelFailed(addedAircraft, msg);
|
emit this->physicallyAddingRemoteModelFailed(newRemoteAircraft, msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we will request a new aircraft by request ID, later we will receive its object id
|
// we will request a new aircraft by request ID, later we will receive its object id
|
||||||
// so far this object id is -1
|
// so far this object id is -1
|
||||||
const CSimConnectObject simObject = this->insertNewSimConnectObject(addedAircraft, requestId);
|
const CSimConnectObject simObject = this->insertNewSimConnectObject(newRemoteAircraft, requestId);
|
||||||
if (m_traceSendId) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
|
if (m_traceSendId) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);}
|
||||||
adding = true;
|
adding = true;
|
||||||
}
|
}
|
||||||
@@ -1039,9 +1068,6 @@ namespace BlackSimPlugin
|
|||||||
CSimConnectObject &simObject = m_simConnectObjects[callsign];
|
CSimConnectObject &simObject = m_simConnectObjects[callsign];
|
||||||
if (simObject.isPendingRemoved()) { return true; }
|
if (simObject.isPendingRemoved()) { return true; }
|
||||||
|
|
||||||
// avoid further data from simulator
|
|
||||||
this->stopRequestingDataForSimObject(simObject);
|
|
||||||
|
|
||||||
const bool pendingAdded = simObject.isPendingAdded();
|
const bool pendingAdded = simObject.isPendingAdded();
|
||||||
const bool stillWaitingForLights = !simObject.hasCurrentLightsInSimulator();
|
const bool stillWaitingForLights = !simObject.hasCurrentLightsInSimulator();
|
||||||
if (pendingAdded || stillWaitingForLights)
|
if (pendingAdded || stillWaitingForLights)
|
||||||
@@ -1058,6 +1084,8 @@ namespace BlackSimPlugin
|
|||||||
return false; // not yet deleted
|
return false; // not yet deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// avoid further data from simulator
|
||||||
|
this->stopRequestingDataForSimObject(simObject);
|
||||||
simObject.setPendingRemoved(true);
|
simObject.setPendingRemoved(true);
|
||||||
if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("Cs: '%1' request/object id: %2/%3").arg(callsign.toQString()).arg(simObject.getRequestId()).arg(simObject.getObjectId())); }
|
if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("Cs: '%1' request/object id: %2/%3").arg(callsign.toQString()).arg(simObject.getRequestId()).arg(simObject.getObjectId())); }
|
||||||
|
|
||||||
@@ -1222,7 +1250,6 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
// interpolate and send to simulator
|
// interpolate and send to simulator
|
||||||
m_interpolationRequest++;
|
m_interpolationRequest++;
|
||||||
const CCallsignSet aircraftWithParts = this->remoteAircraftSupportingParts(); // optimization, fetch all parts supporting aircraft in one step (one lock)
|
|
||||||
|
|
||||||
// values used for position and parts
|
// values used for position and parts
|
||||||
const qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
|
const qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch();
|
||||||
@@ -1250,15 +1277,10 @@ namespace BlackSimPlugin
|
|||||||
CInterpolationStatus interpolatorStatus;
|
CInterpolationStatus interpolatorStatus;
|
||||||
const CAircraftSituation interpolatedSituation = simObject.getInterpolatedSituation(currentTimestamp, setup, interpolatorStatus);
|
const CAircraftSituation interpolatedSituation = simObject.getInterpolatedSituation(currentTimestamp, setup, interpolatorStatus);
|
||||||
|
|
||||||
// Interpolated parts
|
|
||||||
CPartsStatus partsStatus;
|
|
||||||
const CAircraftParts parts = simObject.getInterpolatedOrGuessedParts(currentTimestamp, setup, partsStatus, logInterpolationAndParts);
|
|
||||||
|
|
||||||
if (interpolatorStatus.hasValidSituation())
|
if (interpolatorStatus.hasValidSituation())
|
||||||
{
|
{
|
||||||
// update situation
|
// update situation
|
||||||
SIMCONNECT_DATA_INITPOSITION position = this->aircraftSituationToFsxPosition(interpolatedSituation);
|
SIMCONNECT_DATA_INITPOSITION position = this->aircraftSituationToFsxPosition(interpolatedSituation, sendGround);
|
||||||
if (!sendGround) { position.OnGround = 0.0; }
|
|
||||||
if (!simObject.isSameAsSent(position))
|
if (!simObject.isSameAsSent(position))
|
||||||
{
|
{
|
||||||
m_simConnectObjects[simObject.getCallsign()].setPositionAsSent(position);
|
m_simConnectObjects[simObject.getCallsign()].setPositionAsSent(position);
|
||||||
@@ -1277,11 +1299,13 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("Invalid situation for SimObject '%1' callsign: '%2' info: '%3'")
|
static const QString so("SimObject id: %1");
|
||||||
<< simObject.getObjectId() << callsign
|
CLogMessage(this).warning(this->getInvalidSituationLogMessage(callsign, interpolatorStatus, so.arg(simObject.getObjectId())));
|
||||||
<< interpolatorStatus.toQString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interpolated parts
|
||||||
|
CPartsStatus partsStatus;
|
||||||
|
const CAircraftParts parts = simObject.getInterpolatedOrGuessedParts(currentTimestamp, setup, partsStatus, logInterpolationAndParts);
|
||||||
this->updateRemoteAircraftParts(simObject, parts, partsStatus);
|
this->updateRemoteAircraftParts(simObject, parts, partsStatus);
|
||||||
|
|
||||||
} // all callsigns
|
} // all callsigns
|
||||||
@@ -1403,9 +1427,9 @@ namespace BlackSimPlugin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SIMCONNECT_DATA_INITPOSITION CSimulatorFsxCommon::aircraftSituationToFsxPosition(const CAircraftSituation &situation)
|
SIMCONNECT_DATA_INITPOSITION CSimulatorFsxCommon::aircraftSituationToFsxPosition(const CAircraftSituation &situation, bool sendGnd)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!situation.isGeodeticHeightNull(), Q_FUNC_INFO, "Missing height");
|
Q_ASSERT_X(!situation.isGeodeticHeightNull(), Q_FUNC_INFO, "Missing height (altitude)");
|
||||||
Q_ASSERT_X(!situation.isPositionNull(), Q_FUNC_INFO, "Missing position");
|
Q_ASSERT_X(!situation.isPositionNull(), Q_FUNC_INFO, "Missing position");
|
||||||
|
|
||||||
SIMCONNECT_DATA_INITPOSITION position = CSimulatorFsxCommon::coordinateToFsxPosition(situation);
|
SIMCONNECT_DATA_INITPOSITION position = CSimulatorFsxCommon::coordinateToFsxPosition(situation);
|
||||||
@@ -1417,7 +1441,7 @@ namespace BlackSimPlugin
|
|||||||
position.Bank = -situation.getBank().value(CAngleUnit::deg());
|
position.Bank = -situation.getBank().value(CAngleUnit::deg());
|
||||||
position.OnGround = 0U;
|
position.OnGround = 0U;
|
||||||
|
|
||||||
if (situation.isOnGroundInfoAvailable())
|
if (sendGnd && situation.isOnGroundInfoAvailable())
|
||||||
{
|
{
|
||||||
const bool onGround = (situation.getOnGround() == CAircraftSituation::OnGround);
|
const bool onGround = (situation.getOnGround() == CAircraftSituation::OnGround);
|
||||||
position.OnGround = onGround ? 1U : 0U;
|
position.OnGround = onGround ? 1U : 0U;
|
||||||
|
|||||||
@@ -327,7 +327,8 @@ namespace BlackSimPlugin
|
|||||||
const CSimConnectObjects &getSimConnectProbes() const { return m_simConnectProbes; }
|
const CSimConnectObjects &getSimConnectProbes() const { return m_simConnectProbes; }
|
||||||
|
|
||||||
//! Format conversion
|
//! Format conversion
|
||||||
SIMCONNECT_DATA_INITPOSITION aircraftSituationToFsxPosition(const BlackMisc::Aviation::CAircraftSituation &situation);
|
//! \note must be valid situation
|
||||||
|
SIMCONNECT_DATA_INITPOSITION aircraftSituationToFsxPosition(const BlackMisc::Aviation::CAircraftSituation &situation, bool sendGnd = true);
|
||||||
|
|
||||||
//! Format conversion
|
//! Format conversion
|
||||||
SIMCONNECT_DATA_INITPOSITION coordinateToFsxPosition(const BlackMisc::Geo::ICoordinateGeodetic &coordinate);
|
SIMCONNECT_DATA_INITPOSITION coordinateToFsxPosition(const BlackMisc::Geo::ICoordinateGeodetic &coordinate);
|
||||||
|
|||||||
Reference in New Issue
Block a user