mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
[FSD] Avoid that all matchings are triggered "at the same time"
* the signal from CAirspaceMonitor is connected internally * this signal is closely related to receive the FSD ICAO data * and then it is emitted from the context again but staggered
This commit is contained in:
committed by
Mat Sutcliffe
parent
0fd1e34d03
commit
59c6a7ad93
@@ -75,7 +75,6 @@ namespace BlackCore
|
||||
connect(m_fsdClient, &CFSDClient::textMessagesReceived, this, &CContextNetwork::textMessagesReceived);
|
||||
connect(m_fsdClient, &CFSDClient::textMessageSent, this, &CContextNetwork::textMessageSent);
|
||||
connect(m_fsdClient, &CFSDClient::severeNetworkError, this, &CContextNetwork::severeNetworkError);
|
||||
// connect(m_fsdClient, &FSDClient::textMessagesReceived, this, &CContextNetwork::checkForSupervisiorTextMessage);
|
||||
|
||||
// 2. Update timer for data (network data such as frequency)
|
||||
// we use 2 timers so we can query at different times (not too many queirs at once)
|
||||
@@ -89,7 +88,13 @@ namespace BlackCore
|
||||
m_requestAtisTimer->start(13 * 1000); // should not be called at the same time as above
|
||||
m_requestAtisTimer->setObjectName("CContextNetwork::m_requestAtisTimer");
|
||||
|
||||
// 3. Airspace contents
|
||||
// 3. send staggered model matching signals, to avoid to many matchings at the same time
|
||||
m_staggeredMatchingTimer = new QTimer(this);
|
||||
connect(m_staggeredMatchingTimer, &QTimer::timeout, this, &CContextNetwork::emitReadyForMatching);
|
||||
m_staggeredMatchingTimer->start(200);
|
||||
m_staggeredMatchingTimer->setObjectName("CContextNetwork::m_staggeredMatchingTimer");
|
||||
|
||||
// 4. Airspace contents
|
||||
Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local");
|
||||
Q_ASSERT_X(this->getRuntime()->getCContextSimulator(), Q_FUNC_INFO, "this and own simulator context must be local");
|
||||
m_airspace = new CAirspaceMonitor(
|
||||
@@ -97,14 +102,14 @@ namespace BlackCore
|
||||
this->getRuntime()->getCContextSimulator(),
|
||||
m_fsdClient, this);
|
||||
m_fsdClient->setClientProvider(m_airspace);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAircraftInRange, this, &CContextNetwork::changedAircraftInRange, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::removedAircraft, this, &IContextNetwork::removedAircraft, Qt::QueuedConnection); // DBus
|
||||
connect(m_airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextNetwork::readyForModelMatching, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::addedAircraft, this, &CContextNetwork::addedAircraft, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAtisReceived, this, &CContextNetwork::onChangedAtisReceived, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAircraftInRange, this, &CContextNetwork::changedAircraftInRange, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::removedAircraft, this, &IContextNetwork::removedAircraft, Qt::QueuedConnection); // DBus
|
||||
connect(m_airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextNetwork::onReadyForModelMatching);
|
||||
connect(m_airspace, &CAirspaceMonitor::addedAircraft, this, &CContextNetwork::addedAircraft, Qt::QueuedConnection);
|
||||
connect(m_airspace, &CAirspaceMonitor::changedAtisReceived, this, &CContextNetwork::onChangedAtisReceived, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
CContextNetwork *CContextNetwork::registerWithDBus(BlackMisc::CDBusServer *server)
|
||||
@@ -256,7 +261,7 @@ namespace BlackCore
|
||||
clientKey = CBuildConfig::vatsimPrivateKey();
|
||||
}
|
||||
|
||||
m_fsdClient->setClientIdAndKey(clientId, clientKey.toLocal8Bit());
|
||||
m_fsdClient->setClientIdAndKey(static_cast<quint16>(clientId), clientKey.toLocal8Bit());
|
||||
m_fsdClient->setClientCapabilities(Capabilities::AircraftInfo | Capabilities::FastPos | Capabilities::AtcInfo | Capabilities::AircraftConfig);
|
||||
m_fsdClient->setServer(server);
|
||||
|
||||
@@ -622,6 +627,21 @@ namespace BlackCore
|
||||
emit this->connectionStatusChanged(from, to);
|
||||
}
|
||||
|
||||
void CContextNetwork::onReadyForModelMatching(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
m_readyForModelMatching.enqueue(aircraft);
|
||||
}
|
||||
|
||||
void CContextNetwork::emitReadyForMatching()
|
||||
{
|
||||
if (m_readyForModelMatching.isEmpty()) { return; }
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
|
||||
const CSimulatedAircraft aircraft = m_readyForModelMatching.dequeue();
|
||||
if (!this->isAircraftInRange(aircraft.getCallsign())) { return; }
|
||||
emit this->readyForModelMatching(aircraft);
|
||||
}
|
||||
|
||||
void CContextNetwork::createRelayMessageToPartnerCallsign(const CTextMessage &textMessage, const CCallsign &partnerCallsign, CTextMessageList &relayedMessages)
|
||||
{
|
||||
if (textMessage.isEmpty()) { return; }
|
||||
@@ -663,7 +683,7 @@ namespace BlackCore
|
||||
|
||||
void CContextNetwork::onChangedAtisReceived(const CCallsign &callsign)
|
||||
{
|
||||
Q_UNUSED(callsign);
|
||||
Q_UNUSED(callsign)
|
||||
m_dsAtcStationsOnlineChanged.inputSignal(); // the ATIS data are stored in the station object
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QQueue>
|
||||
#include <functional>
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
@@ -135,8 +136,8 @@ namespace BlackCore
|
||||
virtual BlackMisc::Network::CClient getClientOrDefaultForCallsign(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
virtual bool hasClientInfo(const BlackMisc::Aviation::CCallsign &callsign) const override;
|
||||
virtual bool addNewClient(const BlackMisc::Network::CClient &client) override;
|
||||
virtual int updateOrAddClient(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CPropertyIndexVariantMap &vm, bool skipEqualValues = true) override;
|
||||
virtual int removeClient(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
virtual int updateOrAddClient(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CPropertyIndexVariantMap &vm, bool skipEqualValues = true) override;
|
||||
virtual int removeClient(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
virtual bool autoAdjustCientGndCapability(const BlackMisc::Aviation::CAircraftSituation &situation) override;
|
||||
virtual bool addClientGndCapability(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
virtual bool setClientGndCapability(const BlackMisc::Aviation::CCallsign &callsign, bool supportGndFlag) override;
|
||||
@@ -295,17 +296,20 @@ namespace BlackCore
|
||||
void setSimulationEnvironmentProvider(BlackMisc::Simulation::ISimulationEnvironmentProvider *provider);
|
||||
|
||||
private:
|
||||
CAirspaceMonitor *m_airspace = nullptr;
|
||||
Fsd::CFSDClient *m_fsdClient = nullptr;
|
||||
BlackMisc::Network::CLoginMode m_currentMode = BlackMisc::Network::CLoginMode::Pilot; //!< current modeM
|
||||
QTimer *m_requestAircraftDataTimer = nullptr; //!< general updates such as frequencies, see requestAircraftDataUpdates()
|
||||
QTimer *m_requestAtisTimer = nullptr; //!< general updates such as ATIS
|
||||
CAirspaceMonitor *m_airspace = nullptr;
|
||||
Fsd::CFSDClient *m_fsdClient = nullptr;
|
||||
QTimer *m_requestAircraftDataTimer = nullptr; //!< general updates such as frequencies, see requestAircraftDataUpdates()
|
||||
QTimer *m_requestAtisTimer = nullptr; //!< general updates such as ATIS
|
||||
QTimer *m_staggeredMatchingTimer = nullptr; //!< staggered update
|
||||
|
||||
// Digest signals, only sending after some time
|
||||
BlackMisc::CDigestSignal m_dsAtcStationsBookedChanged { this, &IContextNetwork::changedAtcStationsBooked, &IContextNetwork::changedAtcStationsBookedDigest, 1000, 2 };
|
||||
BlackMisc::CDigestSignal m_dsAtcStationsOnlineChanged { this, &IContextNetwork::changedAtcStationsOnline, &IContextNetwork::changedAtcStationsOnlineDigest, 1000, 4 };
|
||||
BlackMisc::CDigestSignal m_dsAircraftsInRangeChanged { this, &IContextNetwork::changedAircraftInRange, &IContextNetwork::changedAircraftInRangeDigest, 1000, 4 };
|
||||
|
||||
QQueue<BlackMisc::Simulation::CSimulatedAircraft> m_readyForModelMatching; //!< ready for matching
|
||||
|
||||
//! Own aircraft from \sa CContextOwnAircraft
|
||||
const BlackMisc::Simulation::CSimulatedAircraft ownAircraft() const;
|
||||
|
||||
@@ -321,6 +325,12 @@ namespace BlackCore
|
||||
//! Connection status changed
|
||||
void onFsdConnectionStatusChanged(const BlackMisc::Network::CConnectionStatus &from, const BlackMisc::Network::CConnectionStatus &to);
|
||||
|
||||
//! Ready for matching
|
||||
void onReadyForModelMatching(const BlackMisc::Simulation::CSimulatedAircraft &aircraft);
|
||||
|
||||
//! Emit ready for matching
|
||||
void emitReadyForMatching();
|
||||
|
||||
//! Relay to partner callsign
|
||||
void createRelayMessageToPartnerCallsign(const BlackMisc::Network::CTextMessage &textMessage, const BlackMisc::Aviation::CCallsign &partnerCallsign, BlackMisc::Network::CTextMessageList &relayedMessages);
|
||||
|
||||
|
||||
@@ -711,6 +711,8 @@ namespace BlackCore
|
||||
emit this->aircraftRenderingChanged(brokenAircraft);
|
||||
return;
|
||||
}
|
||||
|
||||
// here the model is added to the simulator
|
||||
m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied);
|
||||
CLogUtilities::addLogDetailsToList(pMatchingMessages, callsign, QStringLiteral("Logically added remote aircraft: %1").arg(aircraftAfterModelApplied.toQString()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user