Ref T709, changed to "static" settings as it needs to be used in static functions such as "CTraffic::preferences"

This commit is contained in:
Klaus Basan
2019-07-27 02:28:02 +02:00
committed by Mat Sutcliffe
parent f2f9ee8818
commit 1440c4d2e9
8 changed files with 50 additions and 32 deletions

View File

@@ -26,6 +26,8 @@ namespace
namespace XSwiftBus namespace XSwiftBus
{ {
CSettings CPlugin::s_pluginSettings = CSettings();
CPlugin::CPlugin() CPlugin::CPlugin()
: m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus")) : m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus"))
{ {
@@ -97,9 +99,9 @@ namespace XSwiftBus
readConfig(); readConfig();
m_service = std::make_unique<CService>(m_pluginSettings); m_service = std::make_unique<CService>(&CPlugin::s_pluginSettings);
m_traffic = std::make_unique<CTraffic>(m_pluginSettings); m_traffic = std::make_unique<CTraffic>(&CPlugin::s_pluginSettings);
m_weather = std::make_unique<CWeather>(m_pluginSettings); m_weather = std::make_unique<CWeather>(&CPlugin::s_pluginSettings);
m_traffic->setPlaneViewMenu(m_planeViewSubMenu); m_traffic->setPlaneViewMenu(m_planeViewSubMenu);

View File

@@ -57,9 +57,10 @@ namespace XSwiftBus
void onAircraftRepositioned(); void onAircraftRepositioned();
private: private:
static CSettings s_pluginSettings; //!< needs to used in static in static functions
CConfig m_pluginConfig; CConfig m_pluginConfig;
CDBusDispatcher m_dbusDispatcher; CDBusDispatcher m_dbusDispatcher;
CSettings m_pluginSettings;
std::unique_ptr<CDBusServer> m_dbusP2PServer; std::unique_ptr<CDBusServer> m_dbusP2PServer;
std::shared_ptr<CDBusConnection> m_dbusConnection; std::shared_ptr<CDBusConnection> m_dbusConnection;
std::unique_ptr<CService> m_service; std::unique_ptr<CService> m_service;

View File

@@ -6,7 +6,6 @@
* or distributed except according to the terms contained in the LICENSE file. * or distributed except according to the terms contained in the LICENSE file.
*/ */
#include "service.h" #include "service.h"
#include "utils.h" #include "utils.h"
#include "blackmisc/simulation/xplane/qtfreeutils.h" #include "blackmisc/simulation/xplane/qtfreeutils.h"
@@ -22,8 +21,11 @@ using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
namespace XSwiftBus 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(); updateAirportsInRange();
} }
@@ -159,15 +161,15 @@ namespace XSwiftBus
std::string CService::getSettings() const std::string CService::getSettings() const
{ {
return m_pluginSettings.toXSwiftBusJsonString(); return CService::s_pluginSettings->toXSwiftBusJsonString();
} }
void CService::setSettings(const std::string &jsonString) void CService::setSettings(const std::string &jsonString)
{ {
m_pluginSettings.parseXSwiftBusString(jsonString); CService::s_pluginSettings->parseXSwiftBusString(jsonString);
XPLMDebugString("Received settings "); XPLMDebugString("Received settings ");
XPLMDebugString(m_pluginSettings.convertToString().c_str()); XPLMDebugString(CService::s_pluginSettings->convertToString().c_str());
XPLMDebugString("\n"); XPLMDebugString("\n");
} }

View File

@@ -38,7 +38,7 @@ namespace XSwiftBus
{ {
public: public:
//! Constructor //! Constructor
CService(CSettings &settings); CService(CSettings *staticSettings);
//! Destructor //! Destructor
~CService() override = default; ~CService() override = default;
@@ -260,7 +260,7 @@ namespace XSwiftBus
bool m_disappearMessageWindow = true; bool m_disappearMessageWindow = true;
std::chrono::system_clock::time_point m_disappearMessageWindowTime; std::chrono::system_clock::time_point m_disappearMessageWindowTime;
std::vector<CNavDataReference> m_airports; std::vector<CNavDataReference> m_airports;
CSettings &m_pluginSettings; static CSettings *s_pluginSettings;
void readAirportsDatabase(); void readAirportsDatabase();
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude); std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);

View File

@@ -31,6 +31,8 @@
namespace XSwiftBus 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_) 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_) : id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_), modelName(modelName_)
{ {
@@ -46,14 +48,17 @@ namespace XSwiftBus
} }
// *INDENT-OFF* // *INDENT-OFF*
CTraffic::CTraffic(CSettings &settings) : CTraffic::CTraffic(CSettings *staticSettings) :
CDBusObject(), 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_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(); }) 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); XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this); XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
// init labels
this->setDrawingLabels(CTraffic::s_pluginSettings->isDrawingLabels());
} }
// *INDENT-ON* // *INDENT-ON*
@@ -204,18 +209,21 @@ namespace XSwiftBus
m_followPlaneViewCallsign = *callsignIt; m_followPlaneViewCallsign = *callsignIt;
} }
static int g_maxPlanes = 100; // changed T709
static float g_drawDistance = 50.0f; // static int g_maxPlanes = 100;
// static float g_drawDistance = 50.0f;
int CTraffic::preferences(const char *section, const char *name, int def) int CTraffic::preferences(const char *section, const char *name, int def)
{ {
if (strcmp(section, "planes") == 0 && strcmp(name, "max_full_count") == 0) 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) 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; return def;
} }
@@ -224,7 +232,7 @@ namespace XSwiftBus
{ {
if (strcmp(section, "planes") == 0 && strcmp(name, "full_distance") == 0) if (strcmp(section, "planes") == 0 && strcmp(name, "full_distance") == 0)
{ {
return g_drawDistance; return static_cast<float>(CTraffic::s_pluginSettings->getMaxDrawDistanceNM());
} }
return def; return def;
} }
@@ -248,6 +256,7 @@ namespace XSwiftBus
void CTraffic::setDrawingLabels(bool drawing) void CTraffic::setDrawingLabels(bool drawing)
{ {
CTraffic::s_pluginSettings->setDrawingLabels(drawing);
if (drawing) if (drawing)
{ {
XPMPEnableAircraftLabels(); XPMPEnableAircraftLabels();
@@ -265,12 +274,12 @@ namespace XSwiftBus
void CTraffic::setMaxPlanes(int planes) void CTraffic::setMaxPlanes(int planes)
{ {
g_maxPlanes = planes; CTraffic::s_pluginSettings->setMaxPlanes(planes);
} }
void CTraffic::setMaxDrawDistance(double nauticalMiles) 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) void CTraffic::addPlane(const std::string &callsign, const std::string &modelName, const std::string &aircraftIcao, const std::string &airlineIcao, const std::string &livery)
@@ -886,13 +895,14 @@ namespace XSwiftBus
traffic->m_deltaCameraPosition.heading = 360.0 * static_cast<double>(x) / static_cast<double>(w); 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 // meters from the plane and pointing at the plane at the pitch and
// heading we wanted above. // heading we wanted above.
const double distanceMeterM = static_cast<double>(std::max(10, CTraffic::s_pluginSettings->getFollowAircraftDistanceM()));
static const double PI = std::acos(-1); static const double PI = std::acos(-1);
traffic->m_deltaCameraPosition.dx = -50.0 * sin(traffic->m_deltaCameraPosition.heading * PI / 180.0); traffic->m_deltaCameraPosition.dx = -distanceMeterM * 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.dz = distanceMeterM * 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.dy = -distanceMeterM * tan(traffic->m_deltaCameraPosition.pitch * PI / 180.0);
traffic->m_deltaCameraPosition.isInitialized = true; traffic->m_deltaCameraPosition.isInitialized = true;
} }

View File

@@ -37,7 +37,7 @@ namespace XSwiftBus
{ {
public: public:
//! Constructor //! Constructor
CTraffic(CSettings &settings); CTraffic(CSettings *staticSettings);
//! Destructor //! Destructor
~CTraffic() override; ~CTraffic() override;
@@ -144,10 +144,11 @@ namespace XSwiftBus
bool isInitialized = false; bool isInitialized = false;
}; };
static CSettings *s_pluginSettings; //!< needs to be static for static functions
bool m_initialized = false; bool m_initialized = false;
bool m_enabledMultiplayer = false; bool m_enabledMultiplayer = false;
CTerrainProbe m_terrainProbe; CTerrainProbe m_terrainProbe;
CSettings &m_pluginSettings;
void emitSimFrame(); void emitSimFrame();
void emitPlaneAdded(const std::string &callsign); void emitPlaneAdded(const std::string &callsign);

View File

@@ -13,9 +13,11 @@
namespace XSwiftBus 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 //! Set cloud layer

View File

@@ -32,7 +32,7 @@ namespace XSwiftBus
{ {
public: public:
//! Constructor //! Constructor
CWeather(CSettings &settings); CWeather(CSettings *staticSettings);
//! DBus interface name //! DBus interface name
static const std::string &InterfaceName() static const std::string &InterfaceName()
@@ -103,7 +103,7 @@ namespace XSwiftBus
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override; virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override;
private: 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::use_real_weather_bool> m_useRealWeather;
DataRef<xplane::data::sim::weather::visibility_reported_m> m_visibilityM; DataRef<xplane::data::sim::weather::visibility_reported_m> m_visibilityM;