mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
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:
committed by
Mathew Sutcliffe
parent
2cea07f174
commit
1a6c7fa192
@@ -139,7 +139,6 @@ namespace BlackSimPlugin
|
||||
{
|
||||
m_fsuipc->connect(); // connect FSUIPC too
|
||||
}
|
||||
reloadWeatherSettings();
|
||||
initInternalsObject();
|
||||
m_dispatchTimerId = startTimer(50);
|
||||
return true;
|
||||
@@ -340,15 +339,17 @@ namespace BlackSimPlugin
|
||||
auto aircraftSituation = aircraftSituationfromFS9(mpPositionVelocity);
|
||||
updateOwnSituation(aircraftSituation);
|
||||
|
||||
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, &CSimulatorFs9::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, &CSimulatorFs9::injectWeatherGrid });
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case CFs9Sdk::MPCHAT_PACKET_ID_CHAT_TEXT_SEND:
|
||||
@@ -390,18 +391,6 @@ namespace BlackSimPlugin
|
||||
m_fsuipc->write(weatherGrid);
|
||||
}
|
||||
|
||||
void CSimulatorFs9::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));
|
||||
}
|
||||
}
|
||||
|
||||
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info,
|
||||
const QSharedPointer<CFs9Host> &fs9Host,
|
||||
const QSharedPointer<CLobbyClient> &lobbyClient) :
|
||||
|
||||
@@ -73,6 +73,11 @@ namespace BlackSimPlugin
|
||||
virtual void timerEvent(QTimerEvent *event) override;
|
||||
//! \@}
|
||||
|
||||
//! \name Base class overrides
|
||||
//! @{
|
||||
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override;
|
||||
//! @}
|
||||
|
||||
private slots:
|
||||
//! Dispatch SimConnect messages
|
||||
void ps_dispatch();
|
||||
@@ -87,21 +92,12 @@ namespace BlackSimPlugin
|
||||
//! Disconnect all clients
|
||||
void disconnectAllClients();
|
||||
|
||||
//! 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;
|
||||
bool m_simConnected = false; //!< Is simulator connected?
|
||||
QSharedPointer<CFs9Host> m_fs9Host;
|
||||
QSharedPointer<CLobbyClient> m_lobbyClient;
|
||||
|
||||
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorFs9::reloadWeatherSettings };
|
||||
};
|
||||
|
||||
//! Listener for FS9
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -165,13 +165,16 @@ namespace BlackSimPlugin
|
||||
identifier()
|
||||
);
|
||||
|
||||
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.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 { { "", currentPosition } };
|
||||
requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
|
||||
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude(), {0} };
|
||||
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()) &&
|
||||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
|
||||
{
|
||||
m_lastWeatherPosition = currentPosition;
|
||||
const auto weatherGrid = CWeatherGrid { { "", currentPosition } };
|
||||
requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,7 +256,6 @@ namespace BlackSimPlugin
|
||||
m_service->updateAirportsInRange();
|
||||
m_traffic->updateInstalledModels();
|
||||
m_watcher->setConnection(m_conn);
|
||||
reloadWeatherSettings();
|
||||
loadCslPackages();
|
||||
emitSimulatorCombinedStatus();
|
||||
return true;
|
||||
@@ -664,19 +666,6 @@ 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,
|
||||
|
||||
@@ -126,6 +126,11 @@ namespace BlackSimPlugin
|
||||
//! \copydoc BlackCore::ISimulator::isSimulating
|
||||
virtual bool isSimulating() const override { return isConnected(); }
|
||||
|
||||
//! \name Base class overrides
|
||||
//! @{
|
||||
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override;
|
||||
//! @}
|
||||
|
||||
private slots:
|
||||
void ps_serviceUnregistered();
|
||||
void ps_setAirportsInRange(const QStringList &icaoCodes, const QStringList &names, const BlackMisc::CSequence<double> &lats, const BlackMisc::CSequence<double> &lons, const BlackMisc::CSequence<double> &alts);
|
||||
@@ -138,10 +143,6 @@ namespace BlackSimPlugin
|
||||
void loadCslPackages();
|
||||
QString findCslPackage(const QString &modelFileName);
|
||||
|
||||
//! Inject weather grid to simulator
|
||||
void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
|
||||
void reloadWeatherSettings();
|
||||
|
||||
QDBusConnection m_conn { "default" };
|
||||
QDBusServiceWatcher *m_watcher { nullptr };
|
||||
CXBusServiceProxy *m_service { nullptr };
|
||||
@@ -153,9 +154,6 @@ namespace BlackSimPlugin
|
||||
BlackMisc::Simulation::CAircraftModelList m_installedModels; //!< \todo Do we still need this, as we now focus on model set
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelSet { this };
|
||||
|
||||
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorXPlane::reloadWeatherSettings };
|
||||
|
||||
//! \todo Add units to members? pitchDeg?, altitudeFt?
|
||||
struct // data is written by DBus async method callbacks
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user