mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 23:05:34 +08:00
Ref T270, interpolator optimization by passing aircraft number
Rational: Except for FS9 we interpolate all aircraft in one loop at the same time. This can cause that some steps are always done at the same time for all aircraft of that loop. By passing the number we can more equally distribute such tasks, avoiding peaks.
This commit is contained in:
@@ -142,18 +142,19 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
CInterpolationResult CInterpolator<Derived>::getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup)
|
||||
CInterpolationResult CInterpolator<Derived>::getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber)
|
||||
{
|
||||
CInterpolationResult result;
|
||||
do
|
||||
{
|
||||
// make sure we can also interpolate parts only (needed in unit tests)
|
||||
const bool init = this->initIniterpolationStepData(currentTimeSinceEpoc, setup);
|
||||
if (aircraftNumber < 0) { aircraftNumber = 0; }
|
||||
const bool init = this->initIniterpolationStepData(currentTimeSinceEpoc, setup, aircraftNumber);
|
||||
if (!m_unitTest && !init) { break; } // failure in real scenarios, unit tests move on
|
||||
|
||||
Q_ASSERT_X(m_currentTimeMsSinceEpoch > 0, Q_FUNC_INFO, "No valid timestamp, interpolator initialized?");
|
||||
const CAircraftSituation interpolatedSituation = this->getInterpolatedSituation();
|
||||
const CAircraftParts interpolatedParts = this->getInterpolatedOrGuessedParts();
|
||||
const CAircraftParts interpolatedParts = this->getInterpolatedOrGuessedParts(aircraftNumber);
|
||||
|
||||
result.setValues(interpolatedSituation, interpolatedParts);
|
||||
}
|
||||
@@ -168,12 +169,12 @@ namespace BlackMisc
|
||||
{
|
||||
if (m_currentSituations.isEmpty())
|
||||
{
|
||||
m_lastInterpolation = CAircraftSituation::null();
|
||||
m_lastSituation = CAircraftSituation::null();
|
||||
return CAircraftSituation::null();
|
||||
}
|
||||
|
||||
const CAircraftSituation latest = m_currentSituations.front();
|
||||
CAircraftSituation currentSituation = m_lastInterpolation.isNull() ? latest : m_lastInterpolation;
|
||||
CAircraftSituation currentSituation = m_lastSituation.isNull() ? latest : m_lastSituation;
|
||||
if (currentSituation.getCallsign() != m_callsign)
|
||||
{
|
||||
BLACK_VERIFY_X(false, Q_FUNC_INFO, "Wrong callsign");
|
||||
@@ -246,7 +247,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
// bye
|
||||
m_lastInterpolation = currentSituation;
|
||||
m_lastSituation = currentSituation;
|
||||
return currentSituation;
|
||||
}
|
||||
|
||||
@@ -286,8 +287,14 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
CAircraftParts CInterpolator<Derived>::getInterpolatedOrGuessedParts()
|
||||
CAircraftParts CInterpolator<Derived>::getInterpolatedOrGuessedParts(int aircraftNumber)
|
||||
{
|
||||
Q_ASSERT_X(m_partsToSituationInterpolationRatio >= 1 && m_partsToSituationInterpolationRatio < 11, Q_FUNC_INFO, "Wrong ratio");
|
||||
if (!m_unitTest && !m_lastParts.isNull() && ((m_interpolatedSituationsCounter + aircraftNumber) % m_partsToSituationInterpolationRatio) == 0)
|
||||
{
|
||||
return m_lastParts;
|
||||
}
|
||||
|
||||
CAircraftParts parts;
|
||||
if (m_currentSetup.isAircraftPartsEnabled())
|
||||
{
|
||||
@@ -300,9 +307,11 @@ namespace BlackMisc
|
||||
if (!m_currentPartsStatus.isSupportingParts())
|
||||
{
|
||||
// check if model has been thru model matching
|
||||
parts.guessParts(m_lastInterpolation, m_currentSituationChange, m_model);
|
||||
parts.guessParts(m_lastSituation, m_currentSituationChange, m_model);
|
||||
this->logParts(parts, 0, false);
|
||||
}
|
||||
|
||||
m_lastParts = parts;
|
||||
return parts;
|
||||
}
|
||||
|
||||
@@ -335,13 +344,13 @@ namespace BlackMisc
|
||||
QStringLiteral(" parts: ") %
|
||||
QString::number(this->remoteAircraftPartsCount(m_callsign)) %
|
||||
QStringLiteral(" 1st interpolation: ") %
|
||||
boolToYesNo(m_lastInterpolation.isNull());
|
||||
boolToYesNo(m_lastSituation.isNull());
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
void CInterpolator<Derived>::resetLastInterpolation()
|
||||
{
|
||||
m_lastInterpolation.setNull();
|
||||
m_lastSituation.setNull();
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
@@ -361,12 +370,12 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
bool CInterpolator<Derived>::initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup)
|
||||
bool CInterpolator<Derived>::initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber)
|
||||
{
|
||||
Q_ASSERT_X(!m_callsign.isEmpty(), Q_FUNC_INFO, "Missing callsign");
|
||||
|
||||
const qint64 lastModifed = this->situationsLastModified(m_callsign);
|
||||
const bool slowUpdateStep = ((m_interpolatedSituationsCounter % 25) == 0); // flag when parts are updated, which need not to be updated every time
|
||||
const bool slowUpdateStep = (((m_interpolatedSituationsCounter + aircraftNumber) % 25) == 0); // flag when parts are updated, which need not to be updated every time
|
||||
const bool changedSetup = m_currentSetup != setup;
|
||||
const bool changedSituations = lastModifed > m_situationsLastModified;
|
||||
|
||||
@@ -392,7 +401,7 @@ namespace BlackMisc
|
||||
if (m_currentSituations.isEmpty())
|
||||
{
|
||||
const bool inRange = this->isAircraftInRange(m_callsign);
|
||||
m_lastInterpolation = CAircraftSituation::null(); // no interpolation possible for that step
|
||||
m_lastSituation = CAircraftSituation::null(); // no interpolation possible for that step
|
||||
m_currentInterpolationStatus.setExtraInfo(inRange ?
|
||||
QString("No situations, but remote aircraft '%1'").arg(m_callsign.asString()) :
|
||||
QString("Unknown remote aircraft: '%1'").arg(m_callsign.asString()));
|
||||
@@ -400,7 +409,7 @@ namespace BlackMisc
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
m_interpolatedSituationsCounter++;
|
||||
m_interpolatedSituationsCounter++; // counter updated in initIniterpolationStepData
|
||||
|
||||
// with the latest updates of T243 the order and the offsets are supposed to be correct
|
||||
// so even mixing fast/slow updates shall work
|
||||
|
||||
@@ -167,10 +167,10 @@ namespace BlackMisc
|
||||
static const CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Latest interpolation result
|
||||
const Aviation::CAircraftSituation &getLastInterpolatedSituation() const { return m_lastInterpolation; }
|
||||
const Aviation::CAircraftSituation &getLastInterpolatedSituation() const { return m_lastSituation; }
|
||||
|
||||
//! Parts and situation interpolated
|
||||
CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup);
|
||||
CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber = -1);
|
||||
|
||||
//! Takes input between 0 and 1 and returns output between 0 and 1 smoothed with an S-shaped curve.
|
||||
//!
|
||||
@@ -214,7 +214,10 @@ namespace BlackMisc
|
||||
CInterpolationLogger *logger);
|
||||
|
||||
//! Inits all data for this current interpolation step
|
||||
bool initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup);
|
||||
//! \param currentTimeSinceEpoc
|
||||
//! \param setup
|
||||
//! \param aircraftNumber passing the aircraft number allows to equally distribute among the steps and not to do it always together for all aircraft
|
||||
bool initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber);
|
||||
|
||||
//! Current interpolated situation
|
||||
Aviation::CAircraftSituation getInterpolatedSituation();
|
||||
@@ -223,7 +226,7 @@ namespace BlackMisc
|
||||
Aviation::CAircraftParts getInterpolatedParts();
|
||||
|
||||
//! Interpolated parts, if not available guessed parts
|
||||
Aviation::CAircraftParts getInterpolatedOrGuessedParts();
|
||||
Aviation::CAircraftParts getInterpolatedOrGuessedParts(int aircraftNumber);
|
||||
|
||||
//! Center of gravity
|
||||
const PhysicalQuantities::CLength &getModelCG() const { return m_model.getCG(); }
|
||||
@@ -245,12 +248,14 @@ namespace BlackMisc
|
||||
CInterpolationAndRenderingSetupPerCallsign m_currentSetup; //!< used setup
|
||||
CInterpolationStatus m_currentInterpolationStatus; //!< this step's status
|
||||
CPartsStatus m_currentPartsStatus; //!< this step's status
|
||||
Aviation::CAircraftSituation m_lastInterpolation { Aviation::CAircraftSituation::null() }; //!< latest interpolation
|
||||
int m_partsToSituationInterpolationRatio = 2; //!< ratio between parts and situation interpolation, 1..always, 2..every 2nd situation
|
||||
Aviation::CAircraftSituation m_lastSituation { Aviation::CAircraftSituation::null() }; //!< latest interpolation
|
||||
Aviation::CAircraftParts m_lastParts { Aviation::CAircraftParts::null() }; //!< latest parts
|
||||
PhysicalQuantities::CLength m_currentSceneryOffset { PhysicalQuantities::CLength::null() }; //!< calculated scenery offset if any
|
||||
|
||||
qint64 m_situationsLastModified { -1 }; //!< when situations were last modified
|
||||
qint64 m_situationsLastModifiedUsed { -1 }; //!< interpolant based on situations last updated
|
||||
int m_interpolatedSituationsCounter { 0 }; //!< counter for each interpolated situations: statistics, every n-th interpolation ....
|
||||
int m_interpolatedSituationsCounter { 0 }; //!< counter for each interpolated situations: used for statistics, every n-th interpolation ....
|
||||
|
||||
bool m_unitTest = false; //!< mark as unit test
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ namespace BlackMisc
|
||||
m_linear(callsign, p1, p2, p3, logger)
|
||||
{}
|
||||
|
||||
CInterpolationResult CInterpolatorMulti::getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup)
|
||||
CInterpolationResult CInterpolatorMulti::getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber)
|
||||
{
|
||||
switch (setup.getInterpolatorMode())
|
||||
{
|
||||
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getInterpolation(currentTimeSinceEpoc, setup);
|
||||
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getInterpolation(currentTimeSinceEpoc, setup);
|
||||
case CInterpolationAndRenderingSetupBase::Linear: return m_linear.getInterpolation(currentTimeSinceEpoc, setup, aircraftNumber);
|
||||
case CInterpolationAndRenderingSetupBase::Spline: return m_spline.getInterpolation(currentTimeSinceEpoc, setup, aircraftNumber);
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace BlackMisc
|
||||
CInterpolationLogger *logger = nullptr);
|
||||
|
||||
//! \copydoc CInterpolator::getInterpolation
|
||||
CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup);
|
||||
CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber);
|
||||
|
||||
//! \copydoc CInterpolator::getLastInterpolatedSituation
|
||||
const Aviation::CAircraftSituation &getLastInterpolatedSituation(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const;
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace BlackMisc
|
||||
// m_s[0] .. oldest -> m_[2] .. latest
|
||||
// general idea, we interpolate from current situation -> latest situation
|
||||
|
||||
if (m_lastInterpolation.isNull())
|
||||
if (m_lastSituation.isNull())
|
||||
{
|
||||
if (!m_currentSituations.isEmpty())
|
||||
{
|
||||
@@ -117,7 +117,7 @@ namespace BlackMisc
|
||||
}
|
||||
else
|
||||
{
|
||||
m_s[0] = m_s[1] = m_s[2] = m_lastInterpolation; // current
|
||||
m_s[0] = m_s[1] = m_s[2] = m_lastSituation; // current
|
||||
m_s[0].addMsecs(-CFsdSetup::c_positionTimeOffsetMsec); // oldest
|
||||
m_s[2].addMsecs(CFsdSetup::c_positionTimeOffsetMsec); // latest
|
||||
if (m_currentSituations.isEmpty()) { return true; }
|
||||
|
||||
Reference in New Issue
Block a user