From d7ac721d09e7a8f22148e0f9b9cfe6363bd2fa3c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 7 Mar 2018 02:11:34 +0100 Subject: [PATCH] Ref T259, Ref T243 setSimulationEnvironmentProvider when simulator changes --- src/blackcore/context/contextnetworkimpl.cpp | 19 ++++++++++++++++++- src/blackcore/context/contextnetworkimpl.h | 4 ++++ .../context/contextsimulatorimpl.cpp | 10 ++++++++-- src/blackcore/context/contextsimulatorimpl.h | 3 +++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index 283079ac7..5b454acc1 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -14,7 +14,7 @@ #include "blackcore/context/contextnetworkimpl.h" #include "blackcore/context/contextownaircraft.h" #include "blackcore/context/contextownaircraftimpl.h" -#include "blackcore/context/contextsimulator.h" +#include "blackcore/context/contextsimulatorimpl.h" #include "blackcore/corefacade.h" #include "blackcore/vatsim/networkvatlib.h" #include "blackcore/webdataservices.h" @@ -451,6 +451,23 @@ namespace BlackCore m_airspace->analyzer()->setSimulatorRenderRestrictionsChanged(restricted, enabled, maxAircraft, maxRenderedDistance); } + void CContextNetwork::xCtxSimulatorStatusChanged(int status) + { + const ISimulator::SimulatorStatus simStatus = static_cast(status); + if (m_network) + { + if (simStatus.testFlag(ISimulator::Connected)) + { + const CContextSimulator *sim = this->getRuntime()->getCContextSimulator(); + m_network->setSimulationEnvironmentProvider(sim ? sim->simulator() : nullptr); + } + else + { + m_network->setSimulationEnvironmentProvider(nullptr); + } + } + } + void CContextNetwork::updateMetars(const BlackMisc::Weather::CMetarList &metars) { if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h index d83016efa..621a09d58 100644 --- a/src/blackcore/context/contextnetworkimpl.h +++ b/src/blackcore/context/contextnetworkimpl.h @@ -238,6 +238,10 @@ namespace BlackCore //! \sa CAirspaceAnalyzer //! \ingroup crosscontextfunction void xCtxSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance); + + //! Status of simulator changed + //! \ingroup crosscontextfunction + void xCtxSimulatorStatusChanged(int status); }; } // ns } // ns diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 5ff541bf3..e426b2945 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -456,7 +456,7 @@ namespace BlackCore sim->disconnect(this); sim->unload(); sim->deleteLater(); - emit simulatorPluginChanged(CSimulatorPluginInfo()); + emit this->simulatorPluginChanged(CSimulatorPluginInfo()); } } } @@ -475,7 +475,7 @@ namespace BlackCore CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr; const CAircraftModel aircraftModel = m_aircraftMatcher.getClosestMatch(remoteAircraft, pMatchingMessages); Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "Mismatching callsigns"); - updateAircraftModel(callsign, aircraftModel, identifier()); + this->updateAircraftModel(callsign, aircraftModel, identifier()); const CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign()); m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied); CMatchingUtils::addLogDetailsToList(pMatchingMessages, callsign, QString("Logically added remote aircraft: %1").arg(aircraftAfterModelApplied.toQString())); @@ -730,6 +730,12 @@ namespace BlackCore return false; } + ISimulator *CContextSimulator::simulator() const + { + if (!this->isSimulatorAvailable()) { return nullptr; } + return m_simulatorPlugin.second; + } + void CContextSimulator::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime) { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << aircraftToHighlight << enableHighlight << displayTime; } diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index cbeb9c66d..54340b67b 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -134,6 +134,9 @@ namespace BlackCore BlackMisc::CSimpleCommandParser::registerCommand({".ris parts on|off", "aircraft parts"}); } + //! Simulator object + ISimulator *simulator() const; + protected: //! Constructor CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);