From 1a6c7fa192de336e252caecfbc312b6b3d991172 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 7 Jan 2017 21:06:56 +0100 Subject: [PATCH] Add control button to activate and deactivate swift weather - GUI changes - Context and ISimulator APIs - Refactored settings and static weather injection in CSimulatorCommon refs #807 --- src/blackcore/context/contextsimulator.h | 3 ++ src/blackcore/context/contextsimulatorempty.h | 7 +++++ .../context/contextsimulatorimpl.cpp | 11 +++++++ src/blackcore/context/contextsimulatorimpl.h | 2 ++ .../context/contextsimulatorproxy.cpp | 5 ++++ src/blackcore/context/contextsimulatorproxy.h | 1 + src/blackcore/simulator.h | 3 ++ src/blackcore/simulatorcommon.cpp | 25 ++++++++++++++++ src/blackcore/simulatorcommon.h | 12 ++++++++ src/blackgui/components/weathercomponent.cpp | 18 ++++++++++++ src/blackgui/components/weathercomponent.h | 2 ++ src/blackgui/components/weathercomponent.ui | 9 +++++- src/plugins/simulator/fs9/simulatorfs9.cpp | 29 ++++++------------- src/plugins/simulator/fs9/simulatorfs9.h | 14 ++++----- src/plugins/simulator/fsx/simulatorfsx.cpp | 28 ++++++------------ src/plugins/simulator/fsx/simulatorfsx.h | 9 +----- .../simulator/xplane/simulatorxplane.cpp | 29 ++++++------------- .../simulator/xplane/simulatorxplane.h | 12 ++++---- 18 files changed, 135 insertions(+), 84 deletions(-) diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index 1fdb728bd..0c41c3c24 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -199,6 +199,9 @@ namespace BlackCore //! Reset model by matching it again virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0; + //! Activates or deactivates simulator weather + virtual void setWeatherActivated(bool activated) = 0; + //! Request weather grid. Argument identifier is past in the signal to identify the requestor virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index daee576f1..42ad90fdf 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -185,6 +185,13 @@ namespace BlackCore return false; } + //! \copydoc IContextSimulator::setWeatherActivated + virtual void setWeatherActivated(bool activated) override + { + Q_UNUSED(activated); + logEmptyContextWarning(Q_FUNC_INFO); + } + //! \copydoc IContextSimulator::requestWeatherGrid virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override { diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index d5b4e11f3..dbf9d4110 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -324,6 +324,8 @@ namespace BlackCore emit simulatorPluginChanged(simulatorPluginInfo); CLogMessage(this).info("Simulator plugin loaded: %1") << simulatorPluginInfo.toQString(true); + simulator->setWeatherActivated(m_isWeatherActivated); + m_matchingMessages.clear(); return true; } @@ -646,6 +648,15 @@ namespace BlackCore return true; } + void CContextSimulator::setWeatherActivated(bool activated) + { + m_isWeatherActivated = activated; + + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } + if (m_simulatorPlugin.first.isUnspecified()) { return; } + m_simulatorPlugin.second->setWeatherActivated(activated); + } + void CContextSimulator::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << identifier; } diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 4da392740..90eff82a5 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -96,6 +96,7 @@ namespace BlackCore virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; + virtual void setWeatherActivated(bool activated) override; virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool isMatchingMessagesEnabled() const override; @@ -207,6 +208,7 @@ namespace BlackCore bool m_initallyAddAircrafts = false; bool m_enableMatchingMessages = true; QString m_networkSessionId; //! Network session, if not connected empty + bool m_isWeatherActivated = false; }; } // namespace } // namespace diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index 1c66a9013..7e8418be5 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -174,6 +174,11 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1Literal("resetToModelMatchingAircraft"), callsign, callsign); } + void CContextSimulatorProxy::setWeatherActivated(bool activated) + { + m_dBusInterface->callDBus(QLatin1Literal("setWeatherActivated"), activated); + } + void CContextSimulatorProxy::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) { m_dBusInterface->callDBus(QLatin1Literal("requestWeatherGrid"), weatherGrid, identifier); diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 0af824933..aeb859001 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -74,6 +74,7 @@ namespace BlackCore virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; + virtual void setWeatherActivated(bool activated) override; virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool isMatchingMessagesEnabled() const override; diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index e31118bf9..751c9e235 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -141,6 +141,9 @@ namespace BlackCore //! Highlight the aircraft for given time (or disable highlight) virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; + //! Activates or deactivates simulator weather + virtual void setWeatherActivated(bool activated) = 0; + //! Driver will be unloaded virtual void unload() = 0; diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index 5db2a1a50..b10ab9f7f 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -194,6 +194,17 @@ namespace BlackCore } } + void CSimulatorCommon::reloadWeatherSettings() + { + if (!m_isWeatherActivated) { return; } + const auto selectedWeatherScenario = m_weatherScenarioSettings.get(); + if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) + { + m_lastWeatherPosition = {}; + injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); + } + } + void CSimulatorCommon::reverseLookupAndUpdateOwnAircraftModel(const QString &modelString) { CAircraftModel model = getOwnAircraftModel(); @@ -246,6 +257,20 @@ namespace BlackCore return airports.findClosest(maxAirportsInRange(), ownPosition); } + void CSimulatorCommon::setWeatherActivated(bool activated) + { + m_isWeatherActivated = activated; + if (m_isWeatherActivated) + { + const auto selectedWeatherScenario = m_weatherScenarioSettings.get(); + if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) + { + m_lastWeatherPosition = {}; + injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); + } + } + } + CAircraftModel CSimulatorCommon::reverseLookupModel(const CAircraftModel &model) { bool modified = false; diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 43efa3241..eb45aa6aa 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -27,6 +27,7 @@ #include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorinternals.h" +#include "blackmisc/simulation/simulatorsettings.h" #include "blackmisc/simulation/interpolationrenderingsetup.h" #include "blackmisc/simulation/interpolationhints.h" #include "blackmisc/weather/weathergridprovider.h" @@ -79,6 +80,7 @@ namespace BlackCore virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const override; virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const override; virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; + virtual void setWeatherActivated(bool activated) override; virtual void unload() override; virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override; virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; @@ -135,6 +137,9 @@ namespace BlackCore //! Clear all aircraft related data virtual void clearAllAircraft(); + //! Inject weather grid to simulator + virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) { Q_UNUSED(weatherGrid); } + //! Airports from web services BlackMisc::Aviation::CAirportList getWebServiceAirports() const; @@ -156,6 +161,9 @@ namespace BlackCore //! Set own model void reverseLookupAndUpdateOwnAircraftModel(const QString &modelString); + //! Reload weather settings + void reloadWeatherSettings(); + //! Parse driver specific details for ISimulator::parseCommandLine virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser); @@ -172,6 +180,10 @@ namespace BlackCore BlackMisc::Simulation::CSimulatedAircraftList m_aircraftToAddAgainWhenRemoved; //!< add this model again when removed, normally used to change model QHash m_hints; //!< last ground elevation fetched + bool m_isWeatherActivated = false; //!< Is simulator weather activated? + BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last + BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorCommon::reloadWeatherSettings }; //!< Selected weather scenario + //! Lookup against DB data static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model); diff --git a/src/blackgui/components/weathercomponent.cpp b/src/blackgui/components/weathercomponent.cpp index 9af403b03..93c61fab1 100644 --- a/src/blackgui/components/weathercomponent.cpp +++ b/src/blackgui/components/weathercomponent.cpp @@ -52,6 +52,8 @@ namespace BlackGui auto scenario = m_weatherScenarioSetting.get(); ui->cb_weatherScenario->setCurrentIndex(scenario.getIndex()); + ui->pb_ActivateWeather->setIcon(CIcons::metar()); + setupConnections(); setupInputValidators(); setupCompleter(); @@ -107,6 +109,21 @@ namespace BlackGui } } + void CWeatherComponent::toggleWeatherActivation() + { + if (m_isWeatherActivated) + { + m_isWeatherActivated = false; + ui->pb_ActivateWeather->setText("Activate"); + } + else + { + m_isWeatherActivated = true; + ui->pb_ActivateWeather->setText("Deactivate"); + } + sGui->getIContextSimulator()->setWeatherActivated(m_isWeatherActivated); + } + void CWeatherComponent::setWeatherScenario(int index) { if (index == -1) { return; } @@ -198,6 +215,7 @@ namespace BlackGui connect(ui->le_Lon, &QLineEdit::returnPressed, this, &CWeatherComponent::updateWeatherInformation); connect(ui->cb_UseOwnAcftPosition, &QCheckBox::toggled, this, &CWeatherComponent::toggleUseOwnAircraftPosition); connect(&m_weatherUpdateTimer, &QTimer::timeout, this, &CWeatherComponent::updateWeatherInformation); + connect(ui->pb_ActivateWeather, &QPushButton::clicked, this, &CWeatherComponent::toggleWeatherActivation); // Context connections Q_ASSERT(sGui->getIContextSimulator()); diff --git a/src/blackgui/components/weathercomponent.h b/src/blackgui/components/weathercomponent.h index 729cbb525..4ae7a2739 100644 --- a/src/blackgui/components/weathercomponent.h +++ b/src/blackgui/components/weathercomponent.h @@ -59,6 +59,7 @@ namespace BlackGui private: void toggleUseOwnAircraftPosition(bool checked); + void toggleWeatherActivation(); void setWeatherScenario(int index); void updateWeatherInformation(); @@ -76,6 +77,7 @@ namespace BlackGui QTimer m_weatherUpdateTimer { this }; BlackMisc::Geo::CCoordinateGeodetic m_lastOwnAircraftPosition; BlackMisc::CSetting m_weatherScenarioSetting { this }; + bool m_isWeatherActivated = false; }; } // namespace } // namespace diff --git a/src/blackgui/components/weathercomponent.ui b/src/blackgui/components/weathercomponent.ui index d625f52e9..886adb5de 100644 --- a/src/blackgui/components/weathercomponent.ui +++ b/src/blackgui/components/weathercomponent.ui @@ -35,9 +35,16 @@ Weather Control - + + + + + Activate + + + diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index ef6ff904e..b34091245 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -139,7 +139,6 @@ namespace BlackSimPlugin { m_fsuipc->connect(); // connect FSUIPC too } - reloadWeatherSettings(); initInternalsObject(); m_dispatchTimerId = startTimer(50); return true; @@ -340,15 +339,17 @@ namespace BlackSimPlugin auto aircraftSituation = aircraftSituationfromFS9(mpPositionVelocity); updateOwnSituation(aircraftSituation); - const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude(), {0} }; - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && - calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + if (m_isWeatherActivated) { - m_lastWeatherPosition = currentPosition; - const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } }; - requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid }); + const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude(), {0} }; + if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && + calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + { + m_lastWeatherPosition = currentPosition; + const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } }; + requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid }); + } } - break; } case CFs9Sdk::MPCHAT_PACKET_ID_CHAT_TEXT_SEND: @@ -390,18 +391,6 @@ namespace BlackSimPlugin m_fsuipc->write(weatherGrid); } - void CSimulatorFs9::reloadWeatherSettings() - { - if (!m_useFsuipc || !m_fsuipc) { return; } - if (!m_fsuipc->isConnected()) { return; } - const auto selectedWeatherScenario = m_weatherScenarioSettings.get(); - if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) - { - m_lastWeatherPosition = {}; - injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); - } - } - CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info, const QSharedPointer &fs9Host, const QSharedPointer &lobbyClient) : diff --git a/src/plugins/simulator/fs9/simulatorfs9.h b/src/plugins/simulator/fs9/simulatorfs9.h index 2247d7ce2..3647b6b7b 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.h +++ b/src/plugins/simulator/fs9/simulatorfs9.h @@ -73,6 +73,11 @@ namespace BlackSimPlugin virtual void timerEvent(QTimerEvent *event) override; //! \@} + //! \name Base class overrides + //! @{ + virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; + //! @} + private slots: //! Dispatch SimConnect messages void ps_dispatch(); @@ -87,21 +92,12 @@ namespace BlackSimPlugin //! Disconnect all clients void disconnectAllClients(); - //! Inject weather grid to simulator - void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - - //! Reload Weather settings - void reloadWeatherSettings(); - QHash> m_hashFs9Clients; QMetaObject::Connection m_connectionHostMessages; int m_dispatchTimerId = -1; bool m_simConnected = false; //!< Is simulator connected? QSharedPointer m_fs9Host; QSharedPointer m_lobbyClient; - - BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last - BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorFs9::reloadWeatherSettings }; }; //! Listener for FS9 diff --git a/src/plugins/simulator/fsx/simulatorfsx.cpp b/src/plugins/simulator/fsx/simulatorfsx.cpp index 47204aaac..667279b73 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.cpp +++ b/src/plugins/simulator/fsx/simulatorfsx.cpp @@ -97,7 +97,6 @@ namespace BlackSimPlugin initDataDefinitionsWhenConnected(); m_simConnectTimerId = startTimer(10); m_realityBubbleTimer.start(); - reloadWeatherSettings(); return true; } @@ -470,13 +469,16 @@ namespace BlackSimPlugin --m_skipCockpitUpdateCycles; } - const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude(), {0} }; - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && - calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + if (m_isWeatherActivated) { - m_lastWeatherPosition = currentPosition; - const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } }; - requestWeatherGrid(weatherGrid, { this, &CSimulatorFsx::injectWeatherGrid }); + const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude(), {0} }; + if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && + calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + { + m_lastWeatherPosition = currentPosition; + const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } }; + requestWeatherGrid(weatherGrid, { this, &CSimulatorFsx::injectWeatherGrid }); + } } } @@ -1060,18 +1062,6 @@ namespace BlackSimPlugin m_fsuipc->write(weatherGrid); } - void CSimulatorFsx::reloadWeatherSettings() - { - if (!m_useFsuipc || !m_fsuipc) { return; } - if (!m_fsuipc->isConnected()) { return; } - const auto selectedWeatherScenario = m_weatherScenarioSettings.get(); - if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) - { - m_lastWeatherPosition = {}; - injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); - } - } - bool CSimulatorFsx::requestDataForSimObject(const CSimConnectObject &simObject, SIMCONNECT_PERIOD period) { if (!simObject.hasValidRequestAndObjectId()) { return false; } diff --git a/src/plugins/simulator/fsx/simulatorfsx.h b/src/plugins/simulator/fsx/simulatorfsx.h index 8048bdaea..8708935b0 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.h +++ b/src/plugins/simulator/fsx/simulatorfsx.h @@ -114,6 +114,7 @@ namespace BlackSimPlugin virtual void reset() override; virtual void clearAllAircraft() override; virtual void initInternalsObject() override; + virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; //! @} //! Timer event (our SimConnect event loop), runs ps_dispatch @@ -200,12 +201,6 @@ namespace BlackSimPlugin //! Sync time with user's computer void synchronizeTime(const BlackMisc::PhysicalQuantities::CTime &zuluTimeSim, const BlackMisc::PhysicalQuantities::CTime &localTimeSim); - //! Inject weather grid to simulator - void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - - //! Reload weather settings - void reloadWeatherSettings(); - //! Request data for a simObject (aka remote aircraft) bool requestDataForSimObject(const CSimConnectObject &simObject, SIMCONNECT_PERIOD period = SIMCONNECT_PERIOD_SECOND); @@ -233,8 +228,6 @@ namespace BlackSimPlugin HANDLE m_hSimConnect = nullptr; //!< handle to SimConnect object CSimConnectObjects m_simConnectObjects; //!< AI objects and their object / request ids BlackMisc::Simulation::CSimulatedAircraftList m_outOfRealityBubble; //!< aircraft removed by FSX because they are out of reality bubble - BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last - BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorFsx::reloadWeatherSettings }; QTimer m_realityBubbleTimer { this }; //!< updating of aircraft out of reality bubble }; diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 2ad7a30e4..10a469793 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -165,13 +165,16 @@ namespace BlackSimPlugin identifier() ); - const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude(), {0} }; - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && - calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + if (m_isWeatherActivated) { - m_lastWeatherPosition = currentPosition; - const auto weatherGrid = CWeatherGrid { { "", currentPosition } }; - requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid }); + const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude(), {0} }; + if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && + calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + { + m_lastWeatherPosition = currentPosition; + const auto weatherGrid = CWeatherGrid { { "", currentPosition } }; + requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid }); + } } } } @@ -253,7 +256,6 @@ namespace BlackSimPlugin m_service->updateAirportsInRange(); m_traffic->updateInstalledModels(); m_watcher->setConnection(m_conn); - reloadWeatherSettings(); loadCslPackages(); emitSimulatorCombinedStatus(); return true; @@ -664,19 +666,6 @@ namespace BlackSimPlugin m_weather->setThunderstormRatio(0.0); } - void CSimulatorXPlane::reloadWeatherSettings() - { - if (m_weather) - { - auto selectedWeatherScenario = m_weatherScenarioSettings.get(); - if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) - { - m_lastWeatherPosition = {}; - injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); - } - } - } - BlackCore::ISimulator *CSimulatorXPlaneFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index c46578755..89f61758a 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -126,6 +126,11 @@ namespace BlackSimPlugin //! \copydoc BlackCore::ISimulator::isSimulating virtual bool isSimulating() const override { return isConnected(); } + //! \name Base class overrides + //! @{ + virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; + //! @} + private slots: void ps_serviceUnregistered(); void ps_setAirportsInRange(const QStringList &icaoCodes, const QStringList &names, const BlackMisc::CSequence &lats, const BlackMisc::CSequence &lons, const BlackMisc::CSequence &alts); @@ -138,10 +143,6 @@ namespace BlackSimPlugin void loadCslPackages(); QString findCslPackage(const QString &modelFileName); - //! Inject weather grid to simulator - void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - void reloadWeatherSettings(); - QDBusConnection m_conn { "default" }; QDBusServiceWatcher *m_watcher { nullptr }; CXBusServiceProxy *m_service { nullptr }; @@ -153,9 +154,6 @@ namespace BlackSimPlugin BlackMisc::Simulation::CAircraftModelList m_installedModels; //!< \todo Do we still need this, as we now focus on model set BlackMisc::CData m_modelSet { this }; - BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last - BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorXPlane::reloadWeatherSettings }; - //! \todo Add units to members? pitchDeg?, altitudeFt? struct // data is written by DBus async method callbacks {