diff --git a/src/blackcore/settings/simulator.h b/src/blackcore/settings/simulator.h new file mode 100644 index 000000000..c69bc9f4c --- /dev/null +++ b/src/blackcore/settings/simulator.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2016 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKCORE_SETTINGS_SIMULATOR_H +#define BLACKCORE_SETTINGS_SIMULATOR_H + +#include "blackmisc/settingscache.h" +#include "blackmisc/weather/weatherscenario.h" + +namespace BlackCore +{ + namespace Settings + { + namespace Simulator + { + //! Selected weather scenario + struct SelectedWeatherScenario : public BlackMisc::CSettingTrait + { + //! \copydoc BlackCore::CSettingTrait::key + static const char *key() { return "simulator/selectedweatherscenario"; } + + //! \copydoc BlackCore::CSettingTrait::defaultValue + static const BlackMisc::Weather::CWeatherScenario &defaultValue() + { + static const BlackMisc::Weather::CWeatherScenario scenario {}; + return scenario; + } + }; + } // ns + } // ns +} // ns + +#endif diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index ca6e72e18..767620d75 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -113,6 +113,7 @@ namespace BlackSimPlugin "B737-400 default model", CAircraftIcaoCode("B734", "L2J") )); + ps_reloadSettings(); } bool CSimulatorFs9::isConnected() const @@ -332,7 +333,8 @@ namespace BlackSimPlugin updateOwnSituation(aircraftSituation); const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude(), {0} }; - if (calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20 ) + if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && + calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20 ) { m_lastWeatherPosition = currentPosition; const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } }; @@ -353,6 +355,16 @@ namespace BlackSimPlugin } } + void CSimulatorFs9::ps_reloadSettings() + { + auto selectedWeatherScenario = m_weatherScenarioSettings.get(); + if (CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) + { + m_lastWeatherPosition = {}; + injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); + } + } + void CSimulatorFs9::updateOwnAircraftFromSimulator(const CSimulatedAircraft &simDataOwnAircraft) { this->updateCockpit( diff --git a/src/plugins/simulator/fs9/simulatorfs9.h b/src/plugins/simulator/fs9/simulatorfs9.h index 8511893ad..a1ab8556a 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.h +++ b/src/plugins/simulator/fs9/simulatorfs9.h @@ -16,6 +16,7 @@ #include "fs9client.h" #include "lobbyclient.h" #include "../fscommon/simulatorfscommon.h" +#include "blackcore/settings/simulator.h" #include "blackcore/simulator.h" #include "blackmisc/interpolator.h" #include "blackmisc/simulation/simulatedaircraft.h" @@ -98,6 +99,9 @@ namespace BlackSimPlugin //! Process incoming FS9 message void ps_processFs9Message(const QByteArray &message); + //! Reload settings + void ps_reloadSettings(); + private: //! Called when data about our own aircraft are received @@ -116,6 +120,7 @@ namespace BlackSimPlugin 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::ps_reloadSettings }; }; //! Listener for FS9 diff --git a/src/plugins/simulator/fsx/simulatorfsx.cpp b/src/plugins/simulator/fsx/simulatorfsx.cpp index e203f3fb1..5c1c86bfb 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.cpp +++ b/src/plugins/simulator/fsx/simulatorfsx.cpp @@ -59,6 +59,7 @@ namespace BlackSimPlugin "B737-800 default model", CAircraftIcaoCode("B738", "L2J") )); + ps_reloadSettings(); } CSimulatorFsx::~CSimulatorFsx() @@ -428,7 +429,8 @@ namespace BlackSimPlugin } const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude(), {0} }; - if (calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20 ) + if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && + calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20 ) { m_lastWeatherPosition = currentPosition; const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } }; @@ -512,6 +514,16 @@ namespace BlackSimPlugin } } + void CSimulatorFsx::ps_reloadSettings() + { + auto selectedWeatherScenario = m_weatherScenarioSettings.get(); + if (CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) + { + m_lastWeatherPosition = {}; + injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); + } + } + bool CSimulatorFsx::physicallyRemoveRemoteAircraft(const CCallsign &callsign) { // only remove from sim diff --git a/src/plugins/simulator/fsx/simulatorfsx.h b/src/plugins/simulator/fsx/simulatorfsx.h index 710ccfae2..e68ced0eb 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.h +++ b/src/plugins/simulator/fsx/simulatorfsx.h @@ -15,6 +15,7 @@ #include "simconnectdatadefinition.h" #include "simconnectobject.h" #include "../fscommon/simulatorfscommon.h" +#include "blackcore/settings/simulator.h" #include "blackcore/simulator.h" #include "blackmisc/interpolatorlinear.h" #include "blackmisc/simulation/simulatorplugininfo.h" @@ -141,6 +142,9 @@ namespace BlackSimPlugin //! Dispatch SimConnect messages void ps_dispatch(); + //! Reload settings + void ps_reloadSettings(); + private: //! Called when sim has started void onSimRunning(); @@ -202,6 +206,7 @@ namespace BlackSimPlugin int m_statsUpdateAircraftCount = 0; BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last + BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorFsx::ps_reloadSettings }; }; //! Listener for FSX diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 92f22eda3..43b88b38d 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -110,6 +110,7 @@ namespace BlackSimPlugin )); resetData(); + ps_reloadSettings(); } // convert xplane squawk mode to swift squawk mode @@ -165,7 +166,8 @@ namespace BlackSimPlugin ); const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude(), {0} }; - if (calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) + if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && + calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) { m_lastWeatherPosition = currentPosition; const auto weatherGrid = CWeatherGrid { { "", currentPosition } }; @@ -229,6 +231,16 @@ namespace BlackSimPlugin } } + void CSimulatorXPlane::ps_reloadSettings() + { + auto selectedWeatherScenario = m_weatherScenarioSettings.get(); + if (CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) + { + m_lastWeatherPosition = {}; + injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); + } + } + bool CSimulatorXPlane::isConnected() const { return m_service && m_traffic && m_weather; diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index 2eba67f89..42b1ed735 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -14,6 +14,7 @@ #include "blackcore/simulator.h" #include "blackcore/simulatorcommon.h" +#include "blackcore/settings/simulator.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/geo/coordinategeodetic.h" @@ -133,6 +134,8 @@ namespace BlackSimPlugin void ps_fastTimerTimeout(); void ps_slowTimerTimeout(); void ps_installedModelsUpdated(const QStringList &modelStrings, const QStringList &icaos, const QStringList &airlines, const QStringList &liveries); + void ps_reloadSettings(); + private: //! Inject weather grid to simulator @@ -149,6 +152,7 @@ namespace BlackSimPlugin BlackMisc::Simulation::CAircraftModelList m_installedModels; //!< \todo Do we still need this, as we now focus on model set BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last + BlackMisc::CSetting m_weatherScenarioSettings { this, &CSimulatorXPlane::ps_reloadSettings }; //! \todo Add units to members? pitchDeg?, altitudeFt? struct // data is written by DBus async method callbacks