mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
Ref T709, only update settings if changed
This commit is contained in:
committed by
Mat Sutcliffe
parent
5a8f41611b
commit
cd06c52cb7
@@ -7,14 +7,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xswiftbussettingsqtfree.h"
|
#include "xswiftbussettingsqtfree.h"
|
||||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
|
||||||
|
|
||||||
#include "rapidjson/document.h" // rapidjson's DOM-style API
|
#include "rapidjson/document.h" // rapidjson's DOM-style API
|
||||||
#include "rapidjson/prettywriter.h" // for stringify JSON
|
#include "rapidjson/prettywriter.h" // for stringify JSON
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
using namespace BlackMisc::Simulation::Settings;
|
using namespace BlackMisc::Simulation::Settings;
|
||||||
@@ -37,14 +34,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
// Qt free version
|
|
||||||
bool isFuzzyEqual(double v1, double v2)
|
|
||||||
{
|
|
||||||
// we can be a little fuzzy here
|
|
||||||
static const double Epsilon = 5 * std::numeric_limits<double>::min();
|
|
||||||
return (fabs(v1 - v2) < Epsilon);
|
|
||||||
}
|
|
||||||
|
|
||||||
CXSwiftBusSettingsQtFree::CXSwiftBusSettingsQtFree()
|
CXSwiftBusSettingsQtFree::CXSwiftBusSettingsQtFree()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -53,27 +42,6 @@ namespace BlackMisc
|
|||||||
this->parseXSwiftBusString(json);
|
this->parseXSwiftBusString(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CXSwiftBusSettingsQtFree::setMaxPlanes(int planes)
|
|
||||||
{
|
|
||||||
if (planes == m_maxPlanes) { return false; }
|
|
||||||
m_maxPlanes = planes;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CXSwiftBusSettingsQtFree::setFollowAircraftDistanceM(int meters)
|
|
||||||
{
|
|
||||||
if (meters == m_followAircraftDistanceM) { return false; }
|
|
||||||
m_followAircraftDistanceM = meters;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CXSwiftBusSettingsQtFree::setMaxDrawDistanceNM(double nauticalMiles)
|
|
||||||
{
|
|
||||||
if (isFuzzyEqual(nauticalMiles, m_maxDrawDistanceNM)) { return false; }
|
|
||||||
m_maxDrawDistanceNM = nauticalMiles;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CXSwiftBusSettingsQtFree::parseXSwiftBusString(const std::string &json)
|
bool CXSwiftBusSettingsQtFree::parseXSwiftBusString(const std::string &json)
|
||||||
{
|
{
|
||||||
if (json.empty()) { return false; }
|
if (json.empty()) { return false; }
|
||||||
@@ -159,7 +127,7 @@ namespace BlackMisc
|
|||||||
if (m_maxPlanes != newValues.m_maxPlanes) { m_maxPlanes = newValues.m_maxPlanes; changed++; }
|
if (m_maxPlanes != newValues.m_maxPlanes) { m_maxPlanes = newValues.m_maxPlanes; changed++; }
|
||||||
if (m_msSinceEpochQtFree != newValues.m_msSinceEpochQtFree) { m_msSinceEpochQtFree = newValues.m_msSinceEpochQtFree; changed++; }
|
if (m_msSinceEpochQtFree != newValues.m_msSinceEpochQtFree) { m_msSinceEpochQtFree = newValues.m_msSinceEpochQtFree; changed++; }
|
||||||
if (m_followAircraftDistanceM != newValues.m_followAircraftDistanceM) { m_followAircraftDistanceM = newValues.m_followAircraftDistanceM; changed++; }
|
if (m_followAircraftDistanceM != newValues.m_followAircraftDistanceM) { m_followAircraftDistanceM = newValues.m_followAircraftDistanceM; changed++; }
|
||||||
if (!isFuzzyEqual(m_maxDrawDistanceNM, newValues.m_maxDrawDistanceNM)) { m_maxDrawDistanceNM = newValues.m_maxDrawDistanceNM; changed++; }
|
if (!QtFreeUtils::isFuzzyEqual(m_maxDrawDistanceNM, newValues.m_maxDrawDistanceNM)) { m_maxDrawDistanceNM = newValues.m_maxDrawDistanceNM; changed++; }
|
||||||
|
|
||||||
if (changed > 0) { this->objectUpdated(); } // post processing
|
if (changed > 0) { this->objectUpdated(); } // post processing
|
||||||
return changed;
|
return changed;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
|
#ifndef BLACKMISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
|
||||||
#define BLACKMISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
|
#define BLACKMISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
|
||||||
|
|
||||||
|
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -46,13 +47,23 @@ namespace BlackMisc
|
|||||||
bool isDrawingLabels() const { return m_drawingLabels; }
|
bool isDrawingLabels() const { return m_drawingLabels; }
|
||||||
|
|
||||||
//! Set the maximum number of aircraft.
|
//! Set the maximum number of aircraft.
|
||||||
bool setMaxPlanes(int planes);
|
bool setMaxPlanes(int planes)
|
||||||
|
{
|
||||||
|
if (planes == m_maxPlanes) { return false; }
|
||||||
|
m_maxPlanes = planes;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Get the maximum number of aircraft.
|
//! Get the maximum number of aircraft.
|
||||||
int getMaxPlanes() const { return m_maxPlanes; }
|
int getMaxPlanes() const { return m_maxPlanes; }
|
||||||
|
|
||||||
//! Set follow aircraft distance
|
//! Set follow aircraft distance
|
||||||
bool setFollowAircraftDistanceM(int meters);
|
bool setFollowAircraftDistanceM(int meters)
|
||||||
|
{
|
||||||
|
if (meters == m_followAircraftDistanceM) { return false; }
|
||||||
|
m_followAircraftDistanceM = meters;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Get follow aircraft distance
|
//! Get follow aircraft distance
|
||||||
int getFollowAircraftDistanceM() const { return m_followAircraftDistanceM; }
|
int getFollowAircraftDistanceM() const { return m_followAircraftDistanceM; }
|
||||||
@@ -61,7 +72,12 @@ namespace BlackMisc
|
|||||||
double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
|
double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
|
||||||
|
|
||||||
//! Set the maximum distance at which to draw aircraft (nautical miles).
|
//! Set the maximum distance at which to draw aircraft (nautical miles).
|
||||||
bool setMaxDrawDistanceNM(double nauticalMiles);
|
bool setMaxDrawDistanceNM(double nauticalMiles)
|
||||||
|
{
|
||||||
|
if (BlackMisc::Simulation::XPlane::QtFreeUtils::isFuzzyEqual(nauticalMiles, m_maxDrawDistanceNM)) { return false; }
|
||||||
|
m_maxDrawDistanceNM = nauticalMiles;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//! Load and parse config file
|
//! Load and parse config file
|
||||||
bool parseXSwiftBusString(const std::string &json);
|
bool parseXSwiftBusString(const std::string &json);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
// Strict header only X-Plane model parser utils shared between BlackMisc and XSwiftBus.
|
// Strict header only X-Plane model parser utils shared between BlackMisc and XSwiftBus.
|
||||||
@@ -155,6 +156,15 @@ namespace BlackMisc
|
|||||||
return t ? tr : fa;
|
return t ? tr : fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Qt free version of fuzzy compare
|
||||||
|
inline bool isFuzzyEqual(double v1, double v2)
|
||||||
|
{
|
||||||
|
// we allow some epsilon here
|
||||||
|
// static const double Epsilon = 5 * std::numeric_limits<double>::min();
|
||||||
|
static const double Epsilon = 1E-08;
|
||||||
|
return (fabs(v1 - v2) < Epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
//! Trim whitespace from the beginning and end, and replace sequences of whitespace with single space characters
|
//! Trim whitespace from the beginning and end, and replace sequences of whitespace with single space characters
|
||||||
inline std::string simplifyWhitespace(const std::string &s)
|
inline std::string simplifyWhitespace(const std::string &s)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -279,12 +279,14 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
void CTraffic::setMaxPlanes(int planes)
|
void CTraffic::setMaxPlanes(int planes)
|
||||||
{
|
{
|
||||||
s_settingsProvider->getSettings().setMaxPlanes(planes);
|
CSettings s = this->getSettings();
|
||||||
|
if (s.setMaxPlanes(planes)) { this->setSettings(s); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTraffic::setMaxDrawDistance(double nauticalMiles)
|
void CTraffic::setMaxDrawDistance(double nauticalMiles)
|
||||||
{
|
{
|
||||||
s_settingsProvider->getSettings().setMaxDrawDistanceNM(nauticalMiles);
|
CSettings s = this->getSettings();
|
||||||
|
if (s.setMaxDrawDistanceNM(nauticalMiles)) { this->setSettings(s); }
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user