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

@@ -113,7 +113,6 @@ namespace BlackSimPlugin
"B737-400 default model",
CAircraftIcaoCode("B734", "L2J")
));
ps_reloadSettings();
}
bool CSimulatorFs9::isConnected() const
@@ -133,6 +132,7 @@ namespace BlackSimPlugin
{
m_fsuipc->connect(); // connect FSUIPC too
}
reloadWeatherSettings();
m_dispatchTimerId = startTimer(50);
return true;
}
@@ -355,16 +355,6 @@ 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(
@@ -388,6 +378,19 @@ namespace BlackSimPlugin
m_fsuipc->write(weatherGrid);
}
void CSimulatorFs9::reloadWeatherSettings()
{
if (m_fsuipc->isConnected())
{
auto selectedWeatherScenario = m_weatherScenarioSettings.get();
if (!CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario))
{
m_lastWeatherPosition = {};
injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario));
}
}
}
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info,
const QSharedPointer<CFs9Host> &fs9Host,
const QSharedPointer<CLobbyClient> &lobbyClient) :

View File

@@ -99,9 +99,6 @@ 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
@@ -112,6 +109,9 @@ namespace BlackSimPlugin
//! Inject weather grid to simulator
void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
//! Reload Weather settings
void reloadWeatherSettings();
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
QMetaObject::Connection m_connectionHostMessages;
int m_dispatchTimerId = -1;
@@ -120,7 +120,7 @@ namespace BlackSimPlugin
QSharedPointer<CLobbyClient> m_lobbyClient;
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
BlackMisc::CSetting<BlackCore::Simulator::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorFs9::ps_reloadSettings };
BlackMisc::CSetting<BlackCore::Simulator::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorFs9::reloadWeatherSettings };
};
//! Listener for FS9

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

View File

@@ -110,7 +110,6 @@ namespace BlackSimPlugin
));
resetData();
ps_reloadSettings();
}
// convert xplane squawk mode to swift squawk mode
@@ -231,16 +230,6 @@ 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;
@@ -263,6 +252,7 @@ namespace BlackSimPlugin
m_service->updateAirportsInRange();
m_traffic->updateInstalledModels();
m_watcher->setConnection(m_conn);
reloadWeatherSettings();
emitSimulatorCombinedStatus();
return true;
}
@@ -646,6 +636,19 @@ 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,

View File

@@ -134,12 +134,11 @@ 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
void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
void reloadWeatherSettings();
QDBusConnection m_conn { "default" };
QDBusServiceWatcher *m_watcher { nullptr };
@@ -152,7 +151,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<BlackCore::Simulator::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorXPlane::ps_reloadSettings };
BlackMisc::CSetting<BlackCore::Simulator::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorXPlane::reloadWeatherSettings };
//! \todo Add units to members? pitchDeg?, altitudeFt?
struct // data is written by DBus async method callbacks