mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T786, make sure injectWeather is called in the correct thread
This commit is contained in:
committed by
Mat Sutcliffe
parent
cfc748420c
commit
fbf63457c1
@@ -6,7 +6,7 @@ TARGET = simulatorfs9
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += plugin shared
|
||||
CONFIG += blackmisc blackcore blackgui
|
||||
CONFIG += blackmisc blackcore blackgui blackconfig
|
||||
CONFIG += simulatorfscommon simulatorplugincommon
|
||||
|
||||
DEPENDPATH += . $$SourceRoot/src
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/propertyindexallclasses.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QPointer>
|
||||
@@ -35,6 +37,7 @@ using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Weather;
|
||||
using namespace BlackCore;
|
||||
using namespace BlackSimPlugin::FsCommon;
|
||||
using namespace BlackConfig;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
@@ -397,14 +400,13 @@ namespace BlackSimPlugin
|
||||
|
||||
if (m_isWeatherActivated)
|
||||
{
|
||||
const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() };
|
||||
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
|
||||
{
|
||||
if (m_lastWeatherPosition.isNull() ||
|
||||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
|
||||
calculateGreatCircleDistance(m_lastWeatherPosition, aircraftSituation).value(CLengthUnit::mi()) > 20)
|
||||
{
|
||||
m_lastWeatherPosition = currentPosition;
|
||||
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
|
||||
m_lastWeatherPosition = aircraftSituation;
|
||||
const auto weatherGrid = CWeatherGrid { { "GLOB", aircraftSituation } };
|
||||
requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid });
|
||||
}
|
||||
}
|
||||
@@ -465,6 +467,19 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFs9::injectWeatherGrid(const CWeatherGrid &weatherGrid)
|
||||
{
|
||||
if (this->isShuttingDownOrDisconnected()) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread");
|
||||
QPointer<CSimulatorFs9> myself(this);
|
||||
QTimer::singleShot(0, this, [ = ]
|
||||
{
|
||||
if (!myself) { return; }
|
||||
myself->injectWeatherGrid(weatherGrid);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_useFsuipc || !m_fsuipc) { return; }
|
||||
if (!m_fsuipc->isOpened()) { return; }
|
||||
if (weatherGrid.isEmpty())
|
||||
|
||||
@@ -685,7 +685,7 @@ namespace BlackSimPlugin
|
||||
aircraftSituation.setOnGround(dtb(simulatorOwnAircraft.simOnGround) ? CAircraftSituation::OnGround : CAircraftSituation::NotOnGround, CAircraftSituation::OutOnGroundOwnAircraft);
|
||||
|
||||
const CAircraftLights lights(dtb(simulatorOwnAircraft.lightStrobe), dtb(simulatorOwnAircraft.lightLanding), dtb(simulatorOwnAircraft.lightTaxi),
|
||||
dtb(simulatorOwnAircraft.lightBeacon), dtb(simulatorOwnAircraft.lightNav), dtb(simulatorOwnAircraft.lightLogo));
|
||||
dtb(simulatorOwnAircraft.lightBeacon), dtb(simulatorOwnAircraft.lightNav), dtb(simulatorOwnAircraft.lightLogo));
|
||||
|
||||
CAircraftEngineList engines;
|
||||
const QList<bool> helperList
|
||||
@@ -2393,8 +2393,21 @@ namespace BlackSimPlugin
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorFsxCommon::injectWeatherGrid(const Weather::CWeatherGrid &weatherGrid)
|
||||
void CSimulatorFsxCommon::injectWeatherGrid(const CWeatherGrid &weatherGrid)
|
||||
{
|
||||
if (this->isShuttingDownOrDisconnected()) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread");
|
||||
QPointer<CSimulatorFsxCommon> myself(this);
|
||||
QTimer::singleShot(0, this, [ = ]
|
||||
{
|
||||
if (!myself) { return; }
|
||||
myself->injectWeatherGrid(weatherGrid);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// So far, there is only global weather
|
||||
auto glob = weatherGrid.frontOrDefault();
|
||||
glob.setIdentifier("GLOB");
|
||||
|
||||
@@ -364,14 +364,13 @@ namespace BlackSimPlugin
|
||||
|
||||
if (m_isWeatherActivated)
|
||||
{
|
||||
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() };
|
||||
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
|
||||
{
|
||||
if (m_lastWeatherPosition.isNull() ||
|
||||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
|
||||
calculateGreatCircleDistance(m_lastWeatherPosition, situation).value(CLengthUnit::mi()) > 20)
|
||||
{
|
||||
m_lastWeatherPosition = currentPosition;
|
||||
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
|
||||
m_lastWeatherPosition = situation;
|
||||
const auto weatherGrid = CWeatherGrid { { "GLOB", situation } };
|
||||
this->requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
|
||||
}
|
||||
}
|
||||
@@ -896,9 +895,22 @@ namespace BlackSimPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::injectWeatherGrid(const Weather::CWeatherGrid &weatherGrid)
|
||||
void CSimulatorXPlane::injectWeatherGrid(const CWeatherGrid &weatherGrid)
|
||||
{
|
||||
if (this->isShuttingDownOrDisconnected()) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread");
|
||||
QPointer<CSimulatorXPlane> myself(this);
|
||||
QTimer::singleShot(0, this, [ = ]
|
||||
{
|
||||
if (!myself) { return; }
|
||||
myself->injectWeatherGrid(weatherGrid);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// XPlane weather off
|
||||
m_weatherProxy->setUseRealWeather(false);
|
||||
|
||||
//! TODO: find the closest
|
||||
|
||||
Reference in New Issue
Block a user