mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 05:28:09 +08:00
Ref T709, review points
* overload "normalize" * renamed to CSettingsProvider
This commit is contained in:
committed by
Mat Sutcliffe
parent
d5b1eab55a
commit
08ba4d8f65
@@ -9,11 +9,11 @@
|
|||||||
#include "dbusobject.h"
|
#include "dbusobject.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
XSwiftBus::ISettingsProvider *XSwiftBus::CDBusObject::s_settingsProvider = nullptr;
|
XSwiftBus::CSettingsProvider *XSwiftBus::CDBusObject::s_settingsProvider = nullptr;
|
||||||
|
|
||||||
namespace XSwiftBus
|
namespace XSwiftBus
|
||||||
{
|
{
|
||||||
CDBusObject::CDBusObject(ISettingsProvider *settingsProvider)
|
CDBusObject::CDBusObject(CSettingsProvider *settingsProvider)
|
||||||
{
|
{
|
||||||
if (!CDBusObject::s_settingsProvider)
|
if (!CDBusObject::s_settingsProvider)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CDBusObject(ISettingsProvider *settingsProvider);
|
CDBusObject(CSettingsProvider *settingsProvider);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CDBusObject();
|
virtual ~CDBusObject();
|
||||||
@@ -86,7 +86,7 @@ namespace XSwiftBus
|
|||||||
//! Set the settings
|
//! Set the settings
|
||||||
bool setSettings(const CSettings &s);
|
bool setSettings(const CSettings &s);
|
||||||
|
|
||||||
static ISettingsProvider *s_settingsProvider; //!< get the settings from here, still protected for the static functions
|
static CSettingsProvider *s_settingsProvider; //!< get the settings from here, still protected for the static functions
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
|
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace XSwiftBus
|
|||||||
/*!
|
/*!
|
||||||
* Main plugin class
|
* Main plugin class
|
||||||
*/
|
*/
|
||||||
class CPlugin : public ISettingsProvider
|
class CPlugin : public CSettingsProvider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
|
|||||||
|
|
||||||
namespace XSwiftBus
|
namespace XSwiftBus
|
||||||
{
|
{
|
||||||
CService::CService(ISettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
CService::CService(CSettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
||||||
{
|
{
|
||||||
updateAirportsInRange();
|
updateAirportsInRange();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CService(ISettingsProvider *settingsProvider);
|
CService(CSettingsProvider *settingsProvider);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CService() override = default;
|
virtual ~CService() override = default;
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ namespace XSwiftBus
|
|||||||
// void
|
// void
|
||||||
}
|
}
|
||||||
|
|
||||||
CSettings ISettingsProvider::getSettings() const
|
CSettings CSettingsProvider::getSettings() const
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> l(m_settingsMutex);
|
std::lock_guard<std::mutex> l(m_settingsMutex);
|
||||||
return m_pluginSettings;
|
return m_pluginSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISettingsProvider::setSettings(const CSettings &settings)
|
void CSettingsProvider::setSettings(const CSettings &settings)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> l(m_settingsMutex);
|
std::lock_guard<std::mutex> l(m_settingsMutex);
|
||||||
m_pluginSettings = settings;
|
m_pluginSettings = settings;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace XSwiftBus
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! Something owning the settings
|
//! Something owning the settings
|
||||||
class ISettingsProvider
|
class CSettingsProvider
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! By value
|
//! By value
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace XSwiftBus
|
|||||||
}
|
}
|
||||||
|
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
CTraffic::CTraffic(ISettingsProvider *settingsProvider) :
|
CTraffic::CTraffic(CSettingsProvider *settingsProvider) :
|
||||||
CDBusObject(settingsProvider),
|
CDBusObject(settingsProvider),
|
||||||
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(); })
|
||||||
@@ -945,7 +945,7 @@ namespace XSwiftBus
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
traffic->m_deltaCameraPosition.headingDeg = normalizeToZero360DegD(360.0 * static_cast<double>(x) / static_cast<double>(w)); // range 0-360
|
traffic->m_deltaCameraPosition.headingDeg = normalizeToZero360Deg(360.0 * static_cast<double>(x) / static_cast<double>(w)); // range 0-360
|
||||||
double usedCameraPitchDeg = 60.0 - (60.0 * 2.0 * static_cast<double>(y) / static_cast<double>(h)); // range +-
|
double usedCameraPitchDeg = 60.0 - (60.0 * 2.0 * static_cast<double>(y) / static_cast<double>(h)); // range +-
|
||||||
|
|
||||||
// make sure we can use it with tan in range +-90 degrees and the result of tan not getting too high
|
// make sure we can use it with tan in range +-90 degrees and the result of tan not getting too high
|
||||||
@@ -1022,8 +1022,8 @@ namespace XSwiftBus
|
|||||||
cameraPosition->z = static_cast<float>(lz + traffic->m_deltaCameraPosition.dz);
|
cameraPosition->z = static_cast<float>(lz + traffic->m_deltaCameraPosition.dz);
|
||||||
// cameraPosition->pitch = static_cast<float>(traffic->m_deltaCameraPosition.pitch);
|
// cameraPosition->pitch = static_cast<float>(traffic->m_deltaCameraPosition.pitch);
|
||||||
// cameraPosition->heading = static_cast<float>(traffic->m_deltaCameraPosition.heading);
|
// cameraPosition->heading = static_cast<float>(traffic->m_deltaCameraPosition.heading);
|
||||||
cameraPosition->pitch = CTraffic::normalizeToPlusMinus180DegF(static_cast<float>(traffic->m_deltaCameraPosition.pitchDeg));
|
cameraPosition->pitch = CTraffic::normalizeToPlusMinus180Deg(static_cast<float>(traffic->m_deltaCameraPosition.pitchDeg));
|
||||||
cameraPosition->heading = CTraffic::normalizeToPlusMinus180DegF(static_cast<float>(traffic->m_deltaCameraPosition.headingDeg));
|
cameraPosition->heading = CTraffic::normalizeToPlusMinus180Deg(static_cast<float>(traffic->m_deltaCameraPosition.headingDeg));
|
||||||
cameraPosition->roll = 0.0;
|
cameraPosition->roll = 0.0;
|
||||||
cameraPosition->zoom = 1.0;
|
cameraPosition->zoom = 1.0;
|
||||||
|
|
||||||
@@ -1119,13 +1119,13 @@ namespace XSwiftBus
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CTraffic::normalizeToPlusMinus180DegF(float v)
|
float CTraffic::normalizeToPlusMinus180Deg(float v)
|
||||||
{
|
{
|
||||||
if (std::isnan(v)) { return 0.0f; }
|
if (std::isnan(v)) { return 0.0f; }
|
||||||
return static_cast<float>(normalizeToPlusMinus180DegD(static_cast<double>(v)));
|
return static_cast<float>(normalizeToPlusMinus180Deg(static_cast<double>(v)));
|
||||||
}
|
}
|
||||||
|
|
||||||
double CTraffic::normalizeToPlusMinus180DegD(double v)
|
double CTraffic::normalizeToPlusMinus180Deg(double v)
|
||||||
{
|
{
|
||||||
if (std::isnan(v)) { return 0.0; }
|
if (std::isnan(v)) { return 0.0; }
|
||||||
const double n = normalizeValue(v, -180.0, 180.0);
|
const double n = normalizeValue(v, -180.0, 180.0);
|
||||||
@@ -1134,14 +1134,14 @@ namespace XSwiftBus
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CTraffic::normalizeToZero360DegF(float v)
|
float CTraffic::normalizeToZero360Deg(float v)
|
||||||
{
|
{
|
||||||
if (std::isnan(v)) { return 0.0f; }
|
if (std::isnan(v)) { return 0.0f; }
|
||||||
return static_cast<float>(normalizeToZero360DegD(static_cast<double>(v)));
|
return static_cast<float>(normalizeToZero360Deg(static_cast<double>(v)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double CTraffic::normalizeToZero360DegD(double v)
|
double CTraffic::normalizeToZero360Deg(double v)
|
||||||
{
|
{
|
||||||
if (std::isnan(v)) { return 0.0; }
|
if (std::isnan(v)) { return 0.0; }
|
||||||
const double n = normalizeValue(v, 0, 360.0);
|
const double n = normalizeValue(v, 0, 360.0);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CTraffic(ISettingsProvider *settingsProvider);
|
CTraffic(CSettingsProvider *settingsProvider);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CTraffic() override;
|
virtual ~CTraffic() override;
|
||||||
@@ -197,10 +197,10 @@ namespace XSwiftBus
|
|||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Normalize to (-180, 180] or [0, 360) degrees @{
|
//! Normalize to (-180, 180] or [0, 360) degrees @{
|
||||||
static float normalizeToPlusMinus180DegF(float v);
|
static float normalizeToPlusMinus180Deg(float v);
|
||||||
static double normalizeToPlusMinus180DegD(double v);
|
static double normalizeToPlusMinus180Deg(double v);
|
||||||
static float normalizeToZero360DegF(float v);
|
static float normalizeToZero360Deg(float v);
|
||||||
static double normalizeToZero360DegD(double v);
|
static double normalizeToZero360Deg(double v);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Check the position if values are valid @{
|
//! Check the position if values are valid @{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
namespace XSwiftBus
|
namespace XSwiftBus
|
||||||
{
|
{
|
||||||
CWeather::CWeather(ISettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
CWeather::CWeather(CSettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
||||||
{
|
{
|
||||||
// void
|
// void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CWeather(ISettingsProvider *settingsProvider);
|
CWeather(CSettingsProvider *settingsProvider);
|
||||||
|
|
||||||
//! DBus interface name
|
//! DBus interface name
|
||||||
static const std::string &InterfaceName()
|
static const std::string &InterfaceName()
|
||||||
|
|||||||
Reference in New Issue
Block a user