mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T709, changed to "static" settings as it needs to be used in static functions such as "CTraffic::preferences"
This commit is contained in:
committed by
Mat Sutcliffe
parent
f2f9ee8818
commit
1440c4d2e9
@@ -26,6 +26,8 @@ namespace
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CSettings CPlugin::s_pluginSettings = CSettings();
|
||||
|
||||
CPlugin::CPlugin()
|
||||
: m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus"))
|
||||
{
|
||||
@@ -97,9 +99,9 @@ namespace XSwiftBus
|
||||
|
||||
readConfig();
|
||||
|
||||
m_service = std::make_unique<CService>(m_pluginSettings);
|
||||
m_traffic = std::make_unique<CTraffic>(m_pluginSettings);
|
||||
m_weather = std::make_unique<CWeather>(m_pluginSettings);
|
||||
m_service = std::make_unique<CService>(&CPlugin::s_pluginSettings);
|
||||
m_traffic = std::make_unique<CTraffic>(&CPlugin::s_pluginSettings);
|
||||
m_weather = std::make_unique<CWeather>(&CPlugin::s_pluginSettings);
|
||||
|
||||
m_traffic->setPlaneViewMenu(m_planeViewSubMenu);
|
||||
|
||||
|
||||
@@ -57,9 +57,10 @@ namespace XSwiftBus
|
||||
void onAircraftRepositioned();
|
||||
|
||||
private:
|
||||
static CSettings s_pluginSettings; //!< needs to used in static in static functions
|
||||
|
||||
CConfig m_pluginConfig;
|
||||
CDBusDispatcher m_dbusDispatcher;
|
||||
CSettings m_pluginSettings;
|
||||
std::unique_ptr<CDBusServer> m_dbusP2PServer;
|
||||
std::shared_ptr<CDBusConnection> m_dbusConnection;
|
||||
std::unique_ptr<CService> m_service;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "service.h"
|
||||
#include "utils.h"
|
||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
@@ -22,8 +21,11 @@ using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CService::CService(CSettings &settings) : CDBusObject(), m_pluginSettings(settings)
|
||||
CSettings *CService::s_pluginSettings = nullptr;
|
||||
|
||||
CService::CService(CSettings *staticSettings) : CDBusObject()
|
||||
{
|
||||
CService::s_pluginSettings = staticSettings;
|
||||
updateAirportsInRange();
|
||||
}
|
||||
|
||||
@@ -159,15 +161,15 @@ namespace XSwiftBus
|
||||
|
||||
std::string CService::getSettings() const
|
||||
{
|
||||
return m_pluginSettings.toXSwiftBusJsonString();
|
||||
return CService::s_pluginSettings->toXSwiftBusJsonString();
|
||||
}
|
||||
|
||||
void CService::setSettings(const std::string &jsonString)
|
||||
{
|
||||
m_pluginSettings.parseXSwiftBusString(jsonString);
|
||||
CService::s_pluginSettings->parseXSwiftBusString(jsonString);
|
||||
|
||||
XPLMDebugString("Received settings ");
|
||||
XPLMDebugString(m_pluginSettings.convertToString().c_str());
|
||||
XPLMDebugString(CService::s_pluginSettings->convertToString().c_str());
|
||||
XPLMDebugString("\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CService(CSettings &settings);
|
||||
CService(CSettings *staticSettings);
|
||||
|
||||
//! Destructor
|
||||
~CService() override = default;
|
||||
@@ -260,7 +260,7 @@ namespace XSwiftBus
|
||||
bool m_disappearMessageWindow = true;
|
||||
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
|
||||
std::vector<CNavDataReference> m_airports;
|
||||
CSettings &m_pluginSettings;
|
||||
static CSettings *s_pluginSettings;
|
||||
|
||||
void readAirportsDatabase();
|
||||
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CSettings *CTraffic::s_pluginSettings = nullptr;
|
||||
|
||||
CTraffic::Plane::Plane(void *id_, const std::string &callsign_, const std::string &aircraftIcao_, const std::string &airlineIcao_, const std::string &livery_, const std::string &modelName_)
|
||||
: id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_), modelName(modelName_)
|
||||
{
|
||||
@@ -46,14 +48,17 @@ namespace XSwiftBus
|
||||
}
|
||||
|
||||
// *INDENT-OFF*
|
||||
CTraffic::CTraffic(CSettings &settings) :
|
||||
CTraffic::CTraffic(CSettings *staticSettings) :
|
||||
CDBusObject(),
|
||||
m_pluginSettings(settings),
|
||||
m_followPlaneViewNextCommand("org/swift-project/xswiftbus/follow_next_plane", "Changes plane view to follow next plane in sequence", [this] { followNextPlane(); }),
|
||||
m_followPlaneViewPreviousCommand("org/swift-project/xswiftbus/follow_previous_plane", "Changes plane view to follow previous plane in sequence", [this] { followPreviousPlane(); })
|
||||
{
|
||||
CTraffic::s_pluginSettings = staticSettings;
|
||||
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
||||
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
|
||||
|
||||
// init labels
|
||||
this->setDrawingLabels(CTraffic::s_pluginSettings->isDrawingLabels());
|
||||
}
|
||||
// *INDENT-ON*
|
||||
|
||||
@@ -78,7 +83,7 @@ namespace XSwiftBus
|
||||
std::string csl = dir + "CSL";
|
||||
std::string related = dir + "related.txt";
|
||||
std::string doc8643 = dir + "Doc8643.txt";
|
||||
std::string lights = dir + "lights.png";
|
||||
std::string lights = dir + "lights.png";
|
||||
auto err = XPMPMultiplayerInitLegacyData(csl.c_str(), related.c_str(), lights.c_str(), doc8643.c_str(),
|
||||
"C172", preferences, preferences);
|
||||
if (*err) { s_legacyDataOK = false; }
|
||||
@@ -204,18 +209,21 @@ namespace XSwiftBus
|
||||
m_followPlaneViewCallsign = *callsignIt;
|
||||
}
|
||||
|
||||
static int g_maxPlanes = 100;
|
||||
static float g_drawDistance = 50.0f;
|
||||
// changed T709
|
||||
// static int g_maxPlanes = 100;
|
||||
// static float g_drawDistance = 50.0f;
|
||||
|
||||
int CTraffic::preferences(const char *section, const char *name, int def)
|
||||
{
|
||||
if (strcmp(section, "planes") == 0 && strcmp(name, "max_full_count") == 0)
|
||||
{
|
||||
return g_maxPlanes;
|
||||
return CTraffic::s_pluginSettings->getMaxPlanes();
|
||||
}
|
||||
else if (strcmp(section, "debug") == 0 && strcmp(name, "allow_obj8_async_load") == 0)
|
||||
{
|
||||
return true;
|
||||
// the setting allow_obj8_async_load (in the debug section) controls
|
||||
// whether or not async loading is enabled: 1 means enabled, 0 means disabled
|
||||
return 1;
|
||||
}
|
||||
return def;
|
||||
}
|
||||
@@ -224,7 +232,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (strcmp(section, "planes") == 0 && strcmp(name, "full_distance") == 0)
|
||||
{
|
||||
return g_drawDistance;
|
||||
return static_cast<float>(CTraffic::s_pluginSettings->getMaxDrawDistanceNM());
|
||||
}
|
||||
return def;
|
||||
}
|
||||
@@ -248,6 +256,7 @@ namespace XSwiftBus
|
||||
|
||||
void CTraffic::setDrawingLabels(bool drawing)
|
||||
{
|
||||
CTraffic::s_pluginSettings->setDrawingLabels(drawing);
|
||||
if (drawing)
|
||||
{
|
||||
XPMPEnableAircraftLabels();
|
||||
@@ -265,12 +274,12 @@ namespace XSwiftBus
|
||||
|
||||
void CTraffic::setMaxPlanes(int planes)
|
||||
{
|
||||
g_maxPlanes = planes;
|
||||
CTraffic::s_pluginSettings->setMaxPlanes(planes);
|
||||
}
|
||||
|
||||
void CTraffic::setMaxDrawDistance(double nauticalMiles)
|
||||
{
|
||||
g_drawDistance = static_cast<float>(nauticalMiles);
|
||||
CTraffic::s_pluginSettings->setMaxDrawDistanceNM(nauticalMiles);
|
||||
}
|
||||
|
||||
void CTraffic::addPlane(const std::string &callsign, const std::string &modelName, const std::string &aircraftIcao, const std::string &airlineIcao, const std::string &livery)
|
||||
@@ -884,15 +893,16 @@ namespace XSwiftBus
|
||||
XPLMGetScreenSize(&w, &h);
|
||||
XPLMGetMouseLocation(&x, &y);
|
||||
traffic->m_deltaCameraPosition.heading = 360.0 * static_cast<double>(x) / static_cast<double>(w);
|
||||
traffic->m_deltaCameraPosition.pitch = 20.0 * ((static_cast<double>(y) / static_cast<double>(h)) * 2.0 - 1.0);
|
||||
traffic->m_deltaCameraPosition.pitch = 20.0 * ((static_cast<double>(y) / static_cast<double>(h)) * 2.0 - 1.0);
|
||||
|
||||
// Now calculate where the camera should be positioned to be 200
|
||||
// Now calculate where the camera should be positioned to be x
|
||||
// meters from the plane and pointing at the plane at the pitch and
|
||||
// heading we wanted above.
|
||||
const double distanceMeterM = static_cast<double>(std::max(10, CTraffic::s_pluginSettings->getFollowAircraftDistanceM()));
|
||||
static const double PI = std::acos(-1);
|
||||
traffic->m_deltaCameraPosition.dx = -50.0 * sin(traffic->m_deltaCameraPosition.heading * PI / 180.0);
|
||||
traffic->m_deltaCameraPosition.dz = 50.0 * cos(traffic->m_deltaCameraPosition.heading * PI / 180.0);
|
||||
traffic->m_deltaCameraPosition.dy = -50.0 * tan(traffic->m_deltaCameraPosition.pitch * PI / 180.0);
|
||||
traffic->m_deltaCameraPosition.dx = -distanceMeterM * sin(traffic->m_deltaCameraPosition.heading * PI / 180.0);
|
||||
traffic->m_deltaCameraPosition.dz = distanceMeterM * cos(traffic->m_deltaCameraPosition.heading * PI / 180.0);
|
||||
traffic->m_deltaCameraPosition.dy = -distanceMeterM * tan(traffic->m_deltaCameraPosition.pitch * PI / 180.0);
|
||||
|
||||
traffic->m_deltaCameraPosition.isInitialized = true;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CTraffic(CSettings &settings);
|
||||
CTraffic(CSettings *staticSettings);
|
||||
|
||||
//! Destructor
|
||||
~CTraffic() override;
|
||||
@@ -144,10 +144,11 @@ namespace XSwiftBus
|
||||
bool isInitialized = false;
|
||||
};
|
||||
|
||||
static CSettings *s_pluginSettings; //!< needs to be static for static functions
|
||||
|
||||
bool m_initialized = false;
|
||||
bool m_enabledMultiplayer = false;
|
||||
CTerrainProbe m_terrainProbe;
|
||||
CSettings &m_pluginSettings;
|
||||
|
||||
void emitSimFrame();
|
||||
void emitPlaneAdded(const std::string &callsign);
|
||||
|
||||
@@ -13,9 +13,11 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CWeather::CWeather(CSettings &settings) : m_pluginSettings(settings)
|
||||
CSettings *CWeather::s_pluginSettings = nullptr;
|
||||
|
||||
CWeather::CWeather(CSettings *staticSettings)
|
||||
{
|
||||
// void
|
||||
CWeather::s_pluginSettings = staticSettings;
|
||||
}
|
||||
|
||||
//! Set cloud layer
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CWeather(CSettings &settings);
|
||||
CWeather(CSettings *staticSettings);
|
||||
|
||||
//! DBus interface name
|
||||
static const std::string &InterfaceName()
|
||||
@@ -103,7 +103,7 @@ namespace XSwiftBus
|
||||
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override;
|
||||
|
||||
private:
|
||||
CSettings &m_pluginSettings;
|
||||
static CSettings *s_pluginSettings; //!< needs to be static for static functions;
|
||||
|
||||
DataRef<xplane::data::sim::weather::use_real_weather_bool> m_useRealWeather;
|
||||
DataRef<xplane::data::sim::weather::visibility_reported_m> m_visibilityM;
|
||||
|
||||
Reference in New Issue
Block a user