Delay initial weather injection until simulator is connected

Up to know, the initial weather injection was done in the constructor
of ISimulator implementation. This was to early, since in the best case
the injection was not doing anything and in the worst case, crashed
the application because the plugin wasn't ready yet.
This change also replaces ps_reloadSettings with a specific non-slot
version to avoid code duplication.
This commit is contained in:
Roland Winklmeier
2016-08-13 13:38:11 +02:00
committed by Mathew Sutcliffe
parent e3fc72d775
commit 4e6c4a076a
6 changed files with 52 additions and 44 deletions

View File

@@ -59,7 +59,6 @@ namespace BlackSimPlugin
"B737-800 default model",
CAircraftIcaoCode("B738", "L2J")
));
ps_reloadSettings();
}
CSimulatorFsx::~CSimulatorFsx()
@@ -95,6 +94,7 @@ namespace BlackSimPlugin
initEvents();
initDataDefinitionsWhenConnected();
m_simconnectTimerId = startTimer(10);
reloadWeatherSettings();
return true;
}
@@ -518,16 +518,6 @@ 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
@@ -854,6 +844,19 @@ namespace BlackSimPlugin
m_fsuipc->write(weatherGrid);
}
void CSimulatorFsx::reloadWeatherSettings()
{
if (m_fsuipc->isConnected())
{
auto selectedWeatherScenario = m_weatherScenarioSettings.get();
if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario))
{
m_lastWeatherPosition = {};
injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario));
}
}
}
CSimulatorFsxListener::CSimulatorFsxListener(const CSimulatorPluginInfo &info) :
ISimulatorListener(info),
m_timer(new QTimer(this))

View File

@@ -142,9 +142,6 @@ namespace BlackSimPlugin
//! Dispatch SimConnect messages
void ps_dispatch();
//! Reload settings
void ps_reloadSettings();
private:
//! Call this method to declare the simulator connected
void setSimConnected();
@@ -189,6 +186,9 @@ namespace BlackSimPlugin
//! Inject weather grid to simulator
void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
//! Reload weather settings
void reloadWeatherSettings();
static constexpr int SkipUpdateCyclesForCockpit = 10; //!< skip x cycles before updating cockpit again
bool m_simConnected = false; //!< Is simulator connected?
bool m_simSimulating = false; //!< Simulator running?
@@ -209,7 +209,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<BlackCore::Simulator::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorFsx::ps_reloadSettings };
BlackMisc::CSetting<BlackCore::Simulator::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorFsx::reloadWeatherSettings };
};
//! Listener for FSX