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
This commit is contained in:
Roland Winklmeier
2017-01-07 21:06:56 +01:00
committed by Mathew Sutcliffe
parent 2cea07f174
commit 1a6c7fa192
18 changed files with 135 additions and 84 deletions

View File

@@ -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; }

View File

@@ -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<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorFsx::reloadWeatherSettings };
QTimer m_realityBubbleTimer { this }; //!< updating of aircraft out of reality bubble
};