mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +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
|
TEMPLATE = lib
|
||||||
|
|
||||||
CONFIG += plugin shared
|
CONFIG += plugin shared
|
||||||
CONFIG += blackmisc blackcore blackgui
|
CONFIG += blackmisc blackcore blackgui blackconfig
|
||||||
CONFIG += simulatorfscommon simulatorplugincommon
|
CONFIG += simulatorfscommon simulatorplugincommon
|
||||||
|
|
||||||
DEPENDPATH += . $$SourceRoot/src
|
DEPENDPATH += . $$SourceRoot/src
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/propertyindexallclasses.h"
|
#include "blackmisc/propertyindexallclasses.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
#include "blackconfig/buildconfig.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@@ -35,6 +37,7 @@ using namespace BlackMisc::Simulation::FsCommon;
|
|||||||
using namespace BlackMisc::Weather;
|
using namespace BlackMisc::Weather;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
using namespace BlackSimPlugin::FsCommon;
|
using namespace BlackSimPlugin::FsCommon;
|
||||||
|
using namespace BlackConfig;
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
{
|
{
|
||||||
@@ -397,14 +400,13 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
if (m_isWeatherActivated)
|
if (m_isWeatherActivated)
|
||||||
{
|
{
|
||||||
const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() };
|
|
||||||
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
|
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
|
||||||
{
|
{
|
||||||
if (m_lastWeatherPosition.isNull() ||
|
if (m_lastWeatherPosition.isNull() ||
|
||||||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
|
calculateGreatCircleDistance(m_lastWeatherPosition, aircraftSituation).value(CLengthUnit::mi()) > 20)
|
||||||
{
|
{
|
||||||
m_lastWeatherPosition = currentPosition;
|
m_lastWeatherPosition = aircraftSituation;
|
||||||
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
|
const auto weatherGrid = CWeatherGrid { { "GLOB", aircraftSituation } };
|
||||||
requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid });
|
requestWeatherGrid(weatherGrid, { this, &CSimulatorFs9::injectWeatherGrid });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,6 +467,19 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFs9::injectWeatherGrid(const CWeatherGrid &weatherGrid)
|
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_useFsuipc || !m_fsuipc) { return; }
|
||||||
if (!m_fsuipc->isOpened()) { return; }
|
if (!m_fsuipc->isOpened()) { return; }
|
||||||
if (weatherGrid.isEmpty())
|
if (weatherGrid.isEmpty())
|
||||||
|
|||||||
@@ -685,7 +685,7 @@ namespace BlackSimPlugin
|
|||||||
aircraftSituation.setOnGround(dtb(simulatorOwnAircraft.simOnGround) ? CAircraftSituation::OnGround : CAircraftSituation::NotOnGround, CAircraftSituation::OutOnGroundOwnAircraft);
|
aircraftSituation.setOnGround(dtb(simulatorOwnAircraft.simOnGround) ? CAircraftSituation::OnGround : CAircraftSituation::NotOnGround, CAircraftSituation::OutOnGroundOwnAircraft);
|
||||||
|
|
||||||
const CAircraftLights lights(dtb(simulatorOwnAircraft.lightStrobe), dtb(simulatorOwnAircraft.lightLanding), dtb(simulatorOwnAircraft.lightTaxi),
|
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;
|
CAircraftEngineList engines;
|
||||||
const QList<bool> helperList
|
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
|
// So far, there is only global weather
|
||||||
auto glob = weatherGrid.frontOrDefault();
|
auto glob = weatherGrid.frontOrDefault();
|
||||||
glob.setIdentifier("GLOB");
|
glob.setIdentifier("GLOB");
|
||||||
|
|||||||
@@ -364,14 +364,13 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
if (m_isWeatherActivated)
|
if (m_isWeatherActivated)
|
||||||
{
|
{
|
||||||
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() };
|
|
||||||
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
|
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
|
||||||
{
|
{
|
||||||
if (m_lastWeatherPosition.isNull() ||
|
if (m_lastWeatherPosition.isNull() ||
|
||||||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
|
calculateGreatCircleDistance(m_lastWeatherPosition, situation).value(CLengthUnit::mi()) > 20)
|
||||||
{
|
{
|
||||||
m_lastWeatherPosition = currentPosition;
|
m_lastWeatherPosition = situation;
|
||||||
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
|
const auto weatherGrid = CWeatherGrid { { "GLOB", situation } };
|
||||||
this->requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
|
this->requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -896,9 +895,22 @@ namespace BlackSimPlugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorXPlane::injectWeatherGrid(const Weather::CWeatherGrid &weatherGrid)
|
void CSimulatorXPlane::injectWeatherGrid(const CWeatherGrid &weatherGrid)
|
||||||
{
|
{
|
||||||
if (this->isShuttingDownOrDisconnected()) { return; }
|
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);
|
m_weatherProxy->setUseRealWeather(false);
|
||||||
|
|
||||||
//! TODO: find the closest
|
//! TODO: find the closest
|
||||||
|
|||||||
Reference in New Issue
Block a user