diff --git a/src/xswiftbus/plugin.cpp b/src/xswiftbus/plugin.cpp index 6be2adecf..eb10c0a44 100644 --- a/src/xswiftbus/plugin.cpp +++ b/src/xswiftbus/plugin.cpp @@ -26,6 +26,8 @@ namespace namespace XSwiftBus { + CSettings CPlugin::s_pluginSettings = CSettings(); + CPlugin::CPlugin() : m_dbusConnection(std::make_shared()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus")) { @@ -97,9 +99,9 @@ namespace XSwiftBus readConfig(); - m_service = std::make_unique(m_pluginSettings); - m_traffic = std::make_unique(m_pluginSettings); - m_weather = std::make_unique(m_pluginSettings); + m_service = std::make_unique(&CPlugin::s_pluginSettings); + m_traffic = std::make_unique(&CPlugin::s_pluginSettings); + m_weather = std::make_unique(&CPlugin::s_pluginSettings); m_traffic->setPlaneViewMenu(m_planeViewSubMenu); diff --git a/src/xswiftbus/plugin.h b/src/xswiftbus/plugin.h index 532f444a1..c19bc7aba 100644 --- a/src/xswiftbus/plugin.h +++ b/src/xswiftbus/plugin.h @@ -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 m_dbusP2PServer; std::shared_ptr m_dbusConnection; std::unique_ptr m_service; diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 92cd08df5..5c4a84740 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -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"); } diff --git a/src/xswiftbus/service.h b/src/xswiftbus/service.h index 2a68b27f8..061077f58 100644 --- a/src/xswiftbus/service.h +++ b/src/xswiftbus/service.h @@ -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 m_airports; - CSettings &m_pluginSettings; + static CSettings *s_pluginSettings; void readAirportsDatabase(); std::vector findClosestAirports(int number, double latitude, double longitude); diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 0aa450007..e7a829749 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -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(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(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(x) / static_cast(w); - traffic->m_deltaCameraPosition.pitch = 20.0 * ((static_cast(y) / static_cast(h)) * 2.0 - 1.0); + traffic->m_deltaCameraPosition.pitch = 20.0 * ((static_cast(y) / static_cast(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(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; } diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index 8382c6fb8..37aee918a 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -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); diff --git a/src/xswiftbus/weather.cpp b/src/xswiftbus/weather.cpp index b46e86e10..70a201afd 100644 --- a/src/xswiftbus/weather.cpp +++ b/src/xswiftbus/weather.cpp @@ -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 diff --git a/src/xswiftbus/weather.h b/src/xswiftbus/weather.h index 2bf8cf5c0..212aae9bb 100644 --- a/src/xswiftbus/weather.h +++ b/src/xswiftbus/weather.h @@ -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 m_useRealWeather; DataRef m_visibilityM;