mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #840, style and const-correctness
This commit is contained in:
committed by
Mathew Sutcliffe
parent
de72a678a2
commit
534b9fb09e
@@ -7,7 +7,7 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/interpolationrenderingsetup.h"
|
||||
#include "interpolationrenderingsetup.h"
|
||||
#include "stringutils.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/interpolator.h"
|
||||
#include "interpolator.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -15,7 +15,6 @@ using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
IInterpolator::IInterpolator(IRemoteAircraftProvider *provider, const QString &objectName, QObject *parent) :
|
||||
QObject(parent),
|
||||
CRemoteAircraftAware(provider)
|
||||
@@ -24,7 +23,7 @@ namespace BlackMisc
|
||||
this->setObjectName(objectName);
|
||||
}
|
||||
|
||||
BlackMisc::Aviation::CAircraftSituation IInterpolator::getInterpolatedSituation(const BlackMisc::Aviation::CCallsign &callsign, qint64 currentTimeSinceEpoc,
|
||||
BlackMisc::Aviation::CAircraftSituation IInterpolator::getInterpolatedSituation(const CCallsign &callsign, qint64 currentTimeSinceEpoc,
|
||||
bool isVtolAircraft, InterpolationStatus &status) const
|
||||
{
|
||||
// has to be thread safe
|
||||
@@ -37,7 +36,7 @@ namespace BlackMisc
|
||||
return currentSituation;
|
||||
}
|
||||
|
||||
CAircraftPartsList IInterpolator::getPartsBeforeTime(const CAircraftPartsList &parts, qint64 cutoffTime, BlackMisc::IInterpolator::PartsStatus &partsStatus) const
|
||||
CAircraftPartsList IInterpolator::getPartsBeforeTime(const CAircraftPartsList &parts, qint64 cutoffTime, IInterpolator::PartsStatus &partsStatus) const
|
||||
{
|
||||
partsStatus.reset();
|
||||
partsStatus.setSupportsParts(true);
|
||||
@@ -46,7 +45,7 @@ namespace BlackMisc
|
||||
return parts.findBefore(cutoffTime);
|
||||
}
|
||||
|
||||
CAircraftPartsList IInterpolator::getPartsBeforeTime(const CCallsign &callsign, qint64 cutoffTime, BlackMisc::IInterpolator::PartsStatus &partsStatus) const
|
||||
CAircraftPartsList IInterpolator::getPartsBeforeTime(const CCallsign &callsign, qint64 cutoffTime, IInterpolator::PartsStatus &partsStatus) const
|
||||
{
|
||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign");
|
||||
partsStatus.reset();
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#ifndef BLACKMISC_INTERPOLATOR_H
|
||||
#define BLACKMISC_INTERPOLATOR_H
|
||||
|
||||
#include "interpolationrenderingsetup.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/interpolationrenderingsetup.h"
|
||||
#include "blackmisc/aviation/aircraftpartslist.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
@@ -41,12 +41,8 @@ namespace BlackMisc
|
||||
static QString getLogCategory() { return "swift.interpolator"; }
|
||||
|
||||
//! Status of interpolation
|
||||
struct BLACKMISC_EXPORT InterpolationStatus
|
||||
struct BLACKMISC_EXPORT InterpolationStatus // does not link without export/allTrue, reset
|
||||
{
|
||||
private:
|
||||
bool m_changedPosition = false; //!< position was changed
|
||||
bool m_interpolationSucceeded = false; //!< interpolation succeeded (means enough values, etc.)
|
||||
|
||||
public:
|
||||
//! Did interpolation succeed?
|
||||
bool didInterpolationSucceed() const { return m_interpolationSucceeded; }
|
||||
@@ -65,14 +61,15 @@ namespace BlackMisc
|
||||
|
||||
//! Reset to default values
|
||||
void reset();
|
||||
|
||||
private:
|
||||
bool m_changedPosition = false; //!< position was changed
|
||||
bool m_interpolationSucceeded = false; //!< interpolation succeeded (means enough values, etc.)
|
||||
};
|
||||
|
||||
//! Status regarding parts
|
||||
struct BLACKMISC_EXPORT PartsStatus
|
||||
struct BLACKMISC_EXPORT PartsStatus // does not link without export/allTrue, resetx
|
||||
{
|
||||
private:
|
||||
bool m_supportsParts = false; //!< supports parts for given callsign
|
||||
|
||||
public:
|
||||
//! all OK
|
||||
bool allTrue() const;
|
||||
@@ -85,6 +82,9 @@ namespace BlackMisc
|
||||
|
||||
//! Reset to default values
|
||||
void reset();
|
||||
|
||||
private:
|
||||
bool m_supportsParts = false; //!< supports parts for given callsign
|
||||
};
|
||||
|
||||
//! Current interpolated situation
|
||||
@@ -114,7 +114,7 @@ namespace BlackMisc
|
||||
|
||||
//! Enable debug messages etc.
|
||||
//! \threadsafe
|
||||
void setInterpolatorSetup(const BlackMisc::CInterpolationAndRenderingSetup &setup);
|
||||
void setInterpolatorSetup(const CInterpolationAndRenderingSetup &setup);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
@@ -122,11 +122,10 @@ namespace BlackMisc
|
||||
|
||||
//! Enable debug messages etc.
|
||||
//! \threadsafe
|
||||
BlackMisc::CInterpolationAndRenderingSetup getInterpolatorSetup() const;
|
||||
CInterpolationAndRenderingSetup getInterpolatorSetup() const;
|
||||
|
||||
BlackMisc::CInterpolationAndRenderingSetup m_setup; //!< allows to disable debug messages
|
||||
CInterpolationAndRenderingSetup m_setup; //!< allows to disable debug messages
|
||||
mutable QReadWriteLock m_lock; //!< lock interpolator
|
||||
};
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -7,20 +7,20 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/interpolatorlinear.h"
|
||||
#include "interpolatorlinear.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
#include "blackmisc/aviation/aircraftsituationlist.h"
|
||||
#include "blackmisc/aviation/altitude.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/aviation/heading.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/geo/coordinategeodetic.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/pq/physicalquantity.h"
|
||||
#include "blackmisc/pq/speed.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/range.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
@@ -29,10 +29,11 @@
|
||||
#include <QList>
|
||||
#include <array>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::Math;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -49,11 +50,11 @@ namespace BlackMisc
|
||||
if (currentTimeMsSinceEpoc < 0) { currentTimeMsSinceEpoc = QDateTime::currentMSecsSinceEpoch(); }
|
||||
|
||||
// find the first situation not in the correct order, keep only the situations before that one
|
||||
auto end = std::is_sorted_until(situations.begin(), situations.end(), [](auto &&a, auto &&b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
||||
auto end = std::is_sorted_until(situations.begin(), situations.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
|
||||
auto validSituations = makeRange(situations.begin(), end);
|
||||
|
||||
// find the first situation earlier than the current time
|
||||
auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto &&s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
||||
auto pivot = std::partition_point(validSituations.begin(), validSituations.end(), [ = ](auto && s) { return s.getAdjustedMSecsSinceEpoch() > currentTimeMsSinceEpoc; });
|
||||
auto situationsNewer = makeRange(validSituations.begin(), pivot);
|
||||
auto situationsOlder = makeRange(pivot, validSituations.end());
|
||||
|
||||
@@ -103,8 +104,8 @@ namespace BlackMisc
|
||||
// < 0 should not happen due to the split, > 1 can happen if new values are delayed beyond split time
|
||||
// 1) values > 1 mean extrapolation
|
||||
// 2) values > 2 mean no new situations coming in
|
||||
double distanceToSplitTime = newSituation.getAdjustedMSecsSinceEpoch() - currentTimeMsSinceEpoc;
|
||||
double simulationTimeFraction = 1.0 - (distanceToSplitTime / deltaTime);
|
||||
const double distanceToSplitTime = newSituation.getAdjustedMSecsSinceEpoch() - currentTimeMsSinceEpoc;
|
||||
const double simulationTimeFraction = 1.0 - (distanceToSplitTime / deltaTime);
|
||||
if (simulationTimeFraction > 2.0)
|
||||
{
|
||||
if (setup.showInterpolatorDebugMessages())
|
||||
@@ -128,9 +129,9 @@ namespace BlackMisc
|
||||
const CAltitude newAlt(newSituation.getAltitude());
|
||||
Q_ASSERT_X(oldAlt.getReferenceDatum() == newAlt.getReferenceDatum(), Q_FUNC_INFO, "mismatch in reference"); // otherwise no calculation is possible
|
||||
currentSituation.setAltitude(CAltitude((newAlt - oldAlt)
|
||||
* simulationTimeFraction
|
||||
+ oldAlt,
|
||||
oldAlt.getReferenceDatum()));
|
||||
* simulationTimeFraction
|
||||
+ oldAlt,
|
||||
oldAlt.getReferenceDatum()));
|
||||
|
||||
if (!setup.isForcingFullInterpolation() && !vtolAiracraft && newVec == oldVec && oldAlt == newAlt)
|
||||
{
|
||||
@@ -139,7 +140,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
// Interpolate heading: HDG = (HdgB - HdgA) * t + HdgA
|
||||
CHeading headingBegin = oldSituation.getHeading();
|
||||
const CHeading headingBegin = oldSituation.getHeading();
|
||||
CHeading headingEnd = newSituation.getHeading();
|
||||
|
||||
if ((headingEnd - headingBegin).value(CAngleUnit::deg()) < -180)
|
||||
@@ -153,14 +154,14 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
currentSituation.setHeading(CHeading((headingEnd - headingBegin)
|
||||
* simulationTimeFraction
|
||||
+ headingBegin,
|
||||
headingBegin.getReferenceNorth()));
|
||||
* simulationTimeFraction
|
||||
+ headingBegin,
|
||||
headingBegin.getReferenceNorth()));
|
||||
|
||||
// Interpolate Pitch: Pitch = (PitchB - PitchA) * t + PitchA
|
||||
CAngle pitchBegin = oldSituation.getPitch();
|
||||
CAngle pitchEnd = newSituation.getPitch();
|
||||
CAngle pitch = (pitchEnd - pitchBegin) * simulationTimeFraction + pitchBegin;
|
||||
const CAngle pitchBegin = oldSituation.getPitch();
|
||||
const CAngle pitchEnd = newSituation.getPitch();
|
||||
const CAngle pitch = (pitchEnd - pitchBegin) * simulationTimeFraction + pitchBegin;
|
||||
currentSituation.setPitch(pitch);
|
||||
|
||||
// Interpolate bank: Bank = (BankB - BankA) * t + BankA
|
||||
@@ -174,5 +175,4 @@ namespace BlackMisc
|
||||
+ oldSituation.getGroundSpeed());
|
||||
return currentSituation;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -12,10 +12,9 @@
|
||||
#ifndef BLACKMISC_INTERPOLATOR_LINEAR_H
|
||||
#define BLACKMISC_INTERPOLATOR_LINEAR_H
|
||||
|
||||
#include "interpolator.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/interpolator.h"
|
||||
#include "blackmisc/aviation/aircraftsituation.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
|
||||
@@ -43,9 +42,7 @@ namespace BlackMisc
|
||||
|
||||
//! Log category
|
||||
static QString getLogCategory() { return "swift.interpolatorlinear"; }
|
||||
};
|
||||
|
||||
} // guard
|
||||
};
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
|
||||
@@ -16,17 +16,20 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfolist.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "blackmisc/simulation/distributorlistpreferences.h"
|
||||
#include "blackmisc/simulation/simulatorinternals.h"
|
||||
#include "blackmisc/simulation/interpolationhints.h"
|
||||
#include "blackmisc/simulation/modelsettings.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/simulatorinfolist.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
#include "blackmisc/simulation/simulatorinternals.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfolist.h"
|
||||
#include "blackmisc/simulation/simulatorsettings.h"
|
||||
#include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h"
|
||||
#include "blackmisc/simulation/fscommon/vpilotmodelruleset.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user