Fix the initial weather request in case last position is null

calculateGreatCircleDistance returns false immediately if any of the
arguments was null.

ref T324
This commit is contained in:
Roland Winklmeier
2018-09-06 15:04:40 +02:00
committed by Klaus Basan
parent 7a7f1f2df0
commit 3804612bed
6 changed files with 34 additions and 22 deletions

View File

@@ -533,7 +533,7 @@ namespace BlackCore
// weather // weather
bool m_isWeatherActivated = false; //!< Is simulator weather activated? 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::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &ISimulator::reloadWeatherSettings }; //!< Selected weather scenario BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &ISimulator::reloadWeatherSettings }; //!< Selected weather scenario
private: private:
// remote aircraft provider ("rap") bound // remote aircraft provider ("rap") bound

View File

@@ -174,7 +174,7 @@ namespace BlackGui
if (CWeatherScenario::isRealWeatherScenario(scenario)) if (CWeatherScenario::isRealWeatherScenario(scenario))
{ {
if (!useOwnAcftPosition || if (m_lastOwnAircraftPosition.isNull() ||
calculateGreatCircleDistance(position, m_lastOwnAircraftPosition).value(CLengthUnit::km()) > 20) calculateGreatCircleDistance(position, m_lastOwnAircraftPosition).value(CLengthUnit::km()) > 20)
{ {
requestWeatherGrid(position); requestWeatherGrid(position);

View File

@@ -229,7 +229,9 @@ namespace BlackSimPlugin
if (m_isWeatherActivated) if (m_isWeatherActivated)
{ {
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() }; const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() };
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
{
if (m_lastWeatherPosition.isNull() ||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
{ {
m_lastWeatherPosition = currentPosition; m_lastWeatherPosition = currentPosition;
@@ -237,6 +239,7 @@ namespace BlackSimPlugin
requestWeatherGrid(weatherGrid, { this, &CSimulatorEmulated::injectWeatherGrid }); requestWeatherGrid(weatherGrid, { this, &CSimulatorEmulated::injectWeatherGrid });
} }
} }
}
return this->updateOwnSituation(situation); return this->updateOwnSituation(situation);
} }

View File

@@ -334,7 +334,9 @@ namespace BlackSimPlugin
if (m_isWeatherActivated) if (m_isWeatherActivated)
{ {
const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() }; const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() };
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
{
if (m_lastWeatherPosition.isNull() ||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
{ {
m_lastWeatherPosition = currentPosition; m_lastWeatherPosition = currentPosition;
@@ -342,6 +344,7 @@ namespace BlackSimPlugin
requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid }); requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid });
} }
} }
}
break; break;
} }
case CFs9Sdk::MPCHAT_PACKET_ID_CHAT_TEXT_SEND: case CFs9Sdk::MPCHAT_PACKET_ID_CHAT_TEXT_SEND:

View File

@@ -621,7 +621,9 @@ namespace BlackSimPlugin
if (m_isWeatherActivated) if (m_isWeatherActivated)
{ {
const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() }; const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() };
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
{
if (m_lastWeatherPosition.isNull() ||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
{ {
m_lastWeatherPosition = currentPosition; m_lastWeatherPosition = currentPosition;
@@ -629,6 +631,7 @@ namespace BlackSimPlugin
requestWeatherGrid(weatherGrid, { this, &CSimulatorFsxCommon::injectWeatherGrid }); requestWeatherGrid(weatherGrid, { this, &CSimulatorFsxCommon::injectWeatherGrid });
} }
} }
}
if (this->m_useFsxTerrainProbe && m_addedProbes < 1) if (this->m_useFsxTerrainProbe && m_addedProbes < 1)
{ {

View File

@@ -234,16 +234,19 @@ namespace BlackSimPlugin
if (m_isWeatherActivated) if (m_isWeatherActivated)
{ {
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() }; const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() };
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) && if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
{
if (m_lastWeatherPosition.isNull() ||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
{ {
m_lastWeatherPosition = currentPosition; m_lastWeatherPosition = currentPosition;
const auto weatherGrid = CWeatherGrid { { "", currentPosition } }; const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid }); requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
} }
} }
} }
} }
}
void CSimulatorXPlane::slowTimerTimeout() void CSimulatorXPlane::slowTimerTimeout()
{ {