mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
fix: msfs2020 simconnect interface restored
This commit is contained in:
@@ -527,7 +527,14 @@ namespace swift::simplugin::fsxcommon
|
||||
SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED),
|
||||
"Cannot request title", Q_FUNC_INFO, "SimConnect_RequestDataOnSimObject");
|
||||
|
||||
if (!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS())
|
||||
hr += this->logAndTraceSendId(
|
||||
SimConnect_RequestDataOnSimObject(m_hSimConnect, CSimConnectDefinitions::RequestSimEnvironment,
|
||||
CSimConnectDefinitions::DataSimEnvironment, SIMCONNECT_OBJECT_ID_USER,
|
||||
SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED),
|
||||
"Cannot request sim.env.", Q_FUNC_INFO, "SimConnect_RequestDataOnSimObject");
|
||||
|
||||
if (!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS() &&
|
||||
!this->getSimulatorPluginInfo().getSimulatorInfo().isMSFS2024())
|
||||
{
|
||||
// Request the data from SB only when its changed and only ONCE so we don't have to run a 1sec event to
|
||||
// get/set this info ;) there was a bug with SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET, see
|
||||
@@ -2208,6 +2215,39 @@ namespace swift::simplugin::fsxcommon
|
||||
return ok;
|
||||
}
|
||||
|
||||
void CSimulatorFsxCommon::triggerUpdateAirports(const CAirportList &airports)
|
||||
{
|
||||
if (this->isShuttingDownOrDisconnected()) { return; }
|
||||
if (airports.isEmpty()) { return; }
|
||||
QPointer<CSimulatorFsxCommon> myself(this);
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
if (!myself) { return; }
|
||||
this->updateAirports(airports);
|
||||
});
|
||||
}
|
||||
|
||||
void CSimulatorFsxCommon::updateAirports(const CAirportList &airports)
|
||||
{
|
||||
if (airports.isEmpty()) { return; }
|
||||
|
||||
static const CLength maxDistance(200.0, CLengthUnit::NM());
|
||||
const CCoordinateGeodetic posAircraft(this->getOwnAircraftPosition());
|
||||
|
||||
for (const CAirport &airport : airports)
|
||||
{
|
||||
CAirport consolidatedAirport(airport);
|
||||
const CLength d = consolidatedAirport.calculcateAndUpdateRelativeDistanceAndBearing(posAircraft);
|
||||
if (d > maxDistance) { continue; }
|
||||
// consolidatedAirport.updateMissingParts(this->getWebServiceAirport(airport.getIcao()));
|
||||
// m_airportsInRangeFromSimulator.replaceOrAddByIcao(consolidatedAirport);
|
||||
// if (m_airportsInRangeFromSimulator.size() > this->maxAirportsInRange())
|
||||
//{
|
||||
// m_airportsInRangeFromSimulator.sortByDistanceToReferencePosition();
|
||||
// m_airportsInRangeFromSimulator.truncate(this->maxAirportsInRange());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimulatorFsxCommon::sendRemoteAircraftPartsToSimulator(const CSimConnectObject &simObject,
|
||||
const CAircraftParts &parts)
|
||||
{
|
||||
@@ -2511,6 +2551,61 @@ namespace swift::simplugin::fsxcommon
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorFsxCommon::synchronizeTime(const DataDefinitionSimEnvironment *simEnv)
|
||||
{
|
||||
if (!m_simTimeSynced) { return; }
|
||||
if (!this->isConnected()) { return; }
|
||||
if (m_syncTimeDeferredCounter > 0)
|
||||
{
|
||||
--m_syncTimeDeferredCounter;
|
||||
return; // wait some time before we snyc again
|
||||
}
|
||||
|
||||
const int zh = simEnv->zuluTimeSeconds / 3600;
|
||||
const int zm = (simEnv->zuluTimeSeconds - (zh * 3600)) / 60;
|
||||
const QDateTime simDateTime({ simEnv->zuluYear, simEnv->zuluMonth, simEnv->zuluDayOfMonth }, { zh, zm },
|
||||
Qt::UTC);
|
||||
|
||||
QDateTime currentDateTime = QDateTime::currentDateTimeUtc();
|
||||
if (!m_syncTimeOffset.isZeroEpsilonConsidered())
|
||||
{
|
||||
int offsetSeconds = m_syncTimeOffset.valueInteger(CTimeUnit::s());
|
||||
currentDateTime = currentDateTime.addSecs(offsetSeconds);
|
||||
}
|
||||
|
||||
if (qAbs(simDateTime.secsTo(currentDateTime)) < 120)
|
||||
{
|
||||
// checked and no relevant difference
|
||||
m_syncTimeDeferredCounter = 10; // wait some time to check again
|
||||
return;
|
||||
}
|
||||
|
||||
const DWORD h = static_cast<DWORD>(currentDateTime.time().hour());
|
||||
const DWORD m = static_cast<DWORD>(currentDateTime.time().minute());
|
||||
const DWORD y = static_cast<DWORD>(currentDateTime.date().year());
|
||||
const DWORD d = static_cast<DWORD>(currentDateTime.date().dayOfYear());
|
||||
|
||||
const HRESULT hr1 = SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluHours, h,
|
||||
SIMCONNECT_GROUP_PRIORITY_STANDARD,
|
||||
SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
const HRESULT hr2 = SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluMinutes, m,
|
||||
SIMCONNECT_GROUP_PRIORITY_STANDARD,
|
||||
SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
const HRESULT hr3 = SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluYear, y,
|
||||
SIMCONNECT_GROUP_PRIORITY_STANDARD,
|
||||
SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
const HRESULT hr4 =
|
||||
SimConnect_TransmitClientEvent(m_hSimConnect, 0, EventSetTimeZuluDay, d, SIMCONNECT_GROUP_PRIORITY_STANDARD,
|
||||
SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
|
||||
|
||||
if (isFailure(hr1, hr2, hr3, hr4)) { CLogMessage(this).warning(u"Sending time sync failed!"); }
|
||||
else
|
||||
{
|
||||
m_syncTimeDeferredCounter = 5; // allow some time to sync
|
||||
CLogMessage(this).info(u"Synchronized time to '%1' UTC") << currentDateTime.toString();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimulatorFsxCommon::requestPositionDataForSimObject(const CSimConnectObject &simObject,
|
||||
SIMCONNECT_PERIOD period)
|
||||
{
|
||||
@@ -2630,6 +2725,7 @@ namespace swift::simplugin::fsxcommon
|
||||
m_simConnected = false;
|
||||
m_simSimulating = false;
|
||||
m_sbDataReceived = 0;
|
||||
m_syncTimeDeferredCounter = 0;
|
||||
m_requestIdSimObjAircraft = static_cast<SIMCONNECT_DATA_REQUEST_ID>(RequestSimObjAircraftStart);
|
||||
m_dispatchErrors = 0;
|
||||
m_receiveExceptionCount = 0;
|
||||
@@ -3013,6 +3109,16 @@ namespace swift::simplugin::fsxcommon
|
||||
return connectedSimName.contains("fsx") || connectedSimName.contains("microsoft") ||
|
||||
connectedSimName.contains("simulator x");
|
||||
}
|
||||
else if (pluginSim.isMSFS())
|
||||
{
|
||||
// MSFS 2020 drivers only works with MSFS
|
||||
return connectedSimName.contains("kittyhawk");
|
||||
}
|
||||
else if (pluginSim.isMSFS2024())
|
||||
{
|
||||
// MSFS2024 drivers only works with MSFS2024
|
||||
return connectedSimName.contains("sunrise");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user