mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T709, only update settings if changed
This commit is contained in:
committed by
Mat Sutcliffe
parent
79f347cc1b
commit
447152bd13
@@ -7,14 +7,11 @@
|
||||
*/
|
||||
|
||||
#include "xswiftbussettingsqtfree.h"
|
||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
|
||||
#include "rapidjson/document.h" // rapidjson's DOM-style API
|
||||
#include "rapidjson/prettywriter.h" // for stringify JSON
|
||||
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
|
||||
using namespace BlackMisc::Simulation::Settings;
|
||||
@@ -37,14 +34,6 @@ namespace BlackMisc
|
||||
{
|
||||
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()
|
||||
{}
|
||||
|
||||
@@ -53,27 +42,6 @@ namespace BlackMisc
|
||||
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)
|
||||
{
|
||||
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_msSinceEpochQtFree != newValues.m_msSinceEpochQtFree) { m_msSinceEpochQtFree = newValues.m_msSinceEpochQtFree; 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
|
||||
return changed;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_CXSWIFTBUSSETTINGSQTFREE_H
|
||||
|
||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
#include <string>
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -46,13 +47,23 @@ namespace BlackMisc
|
||||
bool isDrawingLabels() const { return m_drawingLabels; }
|
||||
|
||||
//! 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.
|
||||
int getMaxPlanes() const { return m_maxPlanes; }
|
||||
|
||||
//! 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
|
||||
int getFollowAircraftDistanceM() const { return m_followAircraftDistanceM; }
|
||||
@@ -61,7 +72,12 @@ namespace BlackMisc
|
||||
double getMaxDrawDistanceNM() const { return m_maxDrawDistanceNM; }
|
||||
|
||||
//! 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
|
||||
bool parseXSwiftBusString(const std::string &json);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
// Strict header only X-Plane model parser utils shared between BlackMisc and XSwiftBus.
|
||||
@@ -155,6 +156,15 @@ namespace BlackMisc
|
||||
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
|
||||
inline std::string simplifyWhitespace(const std::string &s)
|
||||
{
|
||||
|
||||
@@ -279,12 +279,14 @@ namespace XSwiftBus
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user