@@ -527,7 +527,14 @@ namespace swift::simplugin::fsxcommon
527527 SIMCONNECT_PERIOD_SECOND , SIMCONNECT_DATA_REQUEST_FLAG_CHANGED ),
528528 " Cannot request title" , Q_FUNC_INFO , " SimConnect_RequestDataOnSimObject" );
529529
530- if (!this ->getSimulatorPluginInfo ().getSimulatorInfo ().isMSFS ())
530+ hr += this ->logAndTraceSendId (
531+ SimConnect_RequestDataOnSimObject (m_hSimConnect, CSimConnectDefinitions::RequestSimEnvironment,
532+ CSimConnectDefinitions::DataSimEnvironment, SIMCONNECT_OBJECT_ID_USER ,
533+ SIMCONNECT_PERIOD_SECOND , SIMCONNECT_DATA_REQUEST_FLAG_CHANGED ),
534+ " Cannot request sim.env." , Q_FUNC_INFO , " SimConnect_RequestDataOnSimObject" );
535+
536+ if (!this ->getSimulatorPluginInfo ().getSimulatorInfo ().isMSFS () &&
537+ !this ->getSimulatorPluginInfo ().getSimulatorInfo ().isMSFS2024 ())
531538 {
532539 // Request the data from SB only when its changed and only ONCE so we don't have to run a 1sec event to
533540 // get/set this info ;) there was a bug with SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET, see
@@ -2208,6 +2215,39 @@ namespace swift::simplugin::fsxcommon
22082215 return ok;
22092216 }
22102217
2218+ void CSimulatorFsxCommon::triggerUpdateAirports (const CAirportList &airports)
2219+ {
2220+ if (this ->isShuttingDownOrDisconnected ()) { return ; }
2221+ if (airports.isEmpty ()) { return ; }
2222+ QPointer<CSimulatorFsxCommon> myself (this );
2223+ QTimer::singleShot (0 , this , [=] {
2224+ if (!myself) { return ; }
2225+ this ->updateAirports (airports);
2226+ });
2227+ }
2228+
2229+ void CSimulatorFsxCommon::updateAirports (const CAirportList &airports)
2230+ {
2231+ if (airports.isEmpty ()) { return ; }
2232+
2233+ static const CLength maxDistance (200.0 , CLengthUnit::NM ());
2234+ const CCoordinateGeodetic posAircraft (this ->getOwnAircraftPosition ());
2235+
2236+ for (const CAirport &airport : airports)
2237+ {
2238+ CAirport consolidatedAirport (airport);
2239+ const CLength d = consolidatedAirport.calculcateAndUpdateRelativeDistanceAndBearing (posAircraft);
2240+ if (d > maxDistance) { continue ; }
2241+ // consolidatedAirport.updateMissingParts(this->getWebServiceAirport(airport.getIcao()));
2242+ // m_airportsInRangeFromSimulator.replaceOrAddByIcao(consolidatedAirport);
2243+ // if (m_airportsInRangeFromSimulator.size() > this->maxAirportsInRange())
2244+ // {
2245+ // m_airportsInRangeFromSimulator.sortByDistanceToReferencePosition();
2246+ // m_airportsInRangeFromSimulator.truncate(this->maxAirportsInRange());
2247+ // }
2248+ }
2249+ }
2250+
22112251 bool CSimulatorFsxCommon::sendRemoteAircraftPartsToSimulator (const CSimConnectObject &simObject,
22122252 const CAircraftParts &parts)
22132253 {
@@ -2511,6 +2551,61 @@ namespace swift::simplugin::fsxcommon
25112551 return true ;
25122552 }
25132553
2554+ void CSimulatorFsxCommon::synchronizeTime (const DataDefinitionSimEnvironment *simEnv)
2555+ {
2556+ if (!m_simTimeSynced) { return ; }
2557+ if (!this ->isConnected ()) { return ; }
2558+ if (m_syncTimeDeferredCounter > 0 )
2559+ {
2560+ --m_syncTimeDeferredCounter;
2561+ return ; // wait some time before we snyc again
2562+ }
2563+
2564+ const int zh = simEnv->zuluTimeSeconds / 3600 ;
2565+ const int zm = (simEnv->zuluTimeSeconds - (zh * 3600 )) / 60 ;
2566+ const QDateTime simDateTime ({ simEnv->zuluYear , simEnv->zuluMonth , simEnv->zuluDayOfMonth }, { zh, zm },
2567+ Qt::UTC );
2568+
2569+ QDateTime currentDateTime = QDateTime::currentDateTimeUtc ();
2570+ if (!m_syncTimeOffset.isZeroEpsilonConsidered ())
2571+ {
2572+ int offsetSeconds = m_syncTimeOffset.valueInteger (CTimeUnit::s ());
2573+ currentDateTime = currentDateTime.addSecs (offsetSeconds);
2574+ }
2575+
2576+ if (qAbs (simDateTime.secsTo (currentDateTime)) < 120 )
2577+ {
2578+ // checked and no relevant difference
2579+ m_syncTimeDeferredCounter = 10 ; // wait some time to check again
2580+ return ;
2581+ }
2582+
2583+ const DWORD h = static_cast <DWORD >(currentDateTime.time ().hour ());
2584+ const DWORD m = static_cast <DWORD >(currentDateTime.time ().minute ());
2585+ const DWORD y = static_cast <DWORD >(currentDateTime.date ().year ());
2586+ const DWORD d = static_cast <DWORD >(currentDateTime.date ().dayOfYear ());
2587+
2588+ const HRESULT hr1 = SimConnect_TransmitClientEvent (m_hSimConnect, 0 , EventSetTimeZuluHours, h,
2589+ SIMCONNECT_GROUP_PRIORITY_STANDARD ,
2590+ SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY );
2591+ const HRESULT hr2 = SimConnect_TransmitClientEvent (m_hSimConnect, 0 , EventSetTimeZuluMinutes, m,
2592+ SIMCONNECT_GROUP_PRIORITY_STANDARD ,
2593+ SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY );
2594+ const HRESULT hr3 = SimConnect_TransmitClientEvent (m_hSimConnect, 0 , EventSetTimeZuluYear, y,
2595+ SIMCONNECT_GROUP_PRIORITY_STANDARD ,
2596+ SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY );
2597+ const HRESULT hr4 =
2598+ SimConnect_TransmitClientEvent (m_hSimConnect, 0 , EventSetTimeZuluDay, d, SIMCONNECT_GROUP_PRIORITY_STANDARD ,
2599+ SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY );
2600+
2601+ if (isFailure (hr1, hr2, hr3, hr4)) { CLogMessage (this ).warning (u" Sending time sync failed!" ); }
2602+ else
2603+ {
2604+ m_syncTimeDeferredCounter = 5 ; // allow some time to sync
2605+ CLogMessage (this ).info (u" Synchronized time to '%1' UTC" ) << currentDateTime.toString ();
2606+ }
2607+ }
2608+
25142609 bool CSimulatorFsxCommon::requestPositionDataForSimObject (const CSimConnectObject &simObject,
25152610 SIMCONNECT_PERIOD period)
25162611 {
@@ -2630,6 +2725,7 @@ namespace swift::simplugin::fsxcommon
26302725 m_simConnected = false ;
26312726 m_simSimulating = false ;
26322727 m_sbDataReceived = 0 ;
2728+ m_syncTimeDeferredCounter = 0 ;
26332729 m_requestIdSimObjAircraft = static_cast <SIMCONNECT_DATA_REQUEST_ID >(RequestSimObjAircraftStart);
26342730 m_dispatchErrors = 0 ;
26352731 m_receiveExceptionCount = 0 ;
@@ -3013,6 +3109,16 @@ namespace swift::simplugin::fsxcommon
30133109 return connectedSimName.contains (" fsx" ) || connectedSimName.contains (" microsoft" ) ||
30143110 connectedSimName.contains (" simulator x" );
30153111 }
3112+ else if (pluginSim.isMSFS ())
3113+ {
3114+ // MSFS 2020 drivers only works with MSFS
3115+ return connectedSimName.contains (" kittyhawk" );
3116+ }
3117+ else if (pluginSim.isMSFS2024 ())
3118+ {
3119+ // MSFS2024 drivers only works with MSFS2024
3120+ return connectedSimName.contains (" sunrise" );
3121+ }
30163122 return false ;
30173123 }
30183124
0 commit comments