mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 02:35:38 +08:00
refactor: Remove clear() method from CInterpolator
clear() was only required by a unittest to execute two tests directly after another. This can also be done in a cleaner way by creating a new CInterpolator instead of requiring a separate method for resetting the interpolator.
This commit is contained in:
@@ -673,25 +673,6 @@ namespace BlackMisc::Simulation
|
|||||||
m_lastSituation.setNull();
|
m_lastSituation.setNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Derived>
|
|
||||||
void CInterpolator<Derived>::clear()
|
|
||||||
{
|
|
||||||
this->resetLastInterpolation();
|
|
||||||
m_model = CAircraftModel();
|
|
||||||
m_currentSceneryOffset = CLength::null();
|
|
||||||
m_pastSituationsChange = CAircraftSituationChange::null();
|
|
||||||
m_currentSituations.clear();
|
|
||||||
m_currentTimeMsSinceEpoch = -1;
|
|
||||||
m_situationsLastModified = -1;
|
|
||||||
m_situationsLastModifiedUsed = -1;
|
|
||||||
m_currentInterpolationStatus.reset();
|
|
||||||
m_currentPartsStatus.reset();
|
|
||||||
m_interpolatedSituationsCounter = 0;
|
|
||||||
m_invalidSituations = 0;
|
|
||||||
m_lastInvalidLogTs = -1;
|
|
||||||
m_interpolationMessages.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Derived>
|
template <typename Derived>
|
||||||
bool CInterpolator<Derived>::initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber)
|
bool CInterpolator<Derived>::initIniterpolationStepData(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, int aircraftNumber)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -195,16 +195,6 @@ namespace BlackMisc
|
|||||||
//! Parts and situation interpolated
|
//! Parts and situation interpolated
|
||||||
CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, uint32_t aircraftNumber);
|
CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetupPerCallsign &setup, uint32_t aircraftNumber);
|
||||||
|
|
||||||
//! Takes input between 0 and 1 and returns output between 0 and 1 smoothed with an S-shaped curve.
|
|
||||||
//!
|
|
||||||
//! Useful for making interpolation seem smoother, efficiently as it just uses simple arithmetic.
|
|
||||||
//! \see https://en.wikipedia.org/wiki/Smoothstep
|
|
||||||
//! \see http://sol.gfxile.net/interpolation/
|
|
||||||
static double smootherStep(double x)
|
|
||||||
{
|
|
||||||
return x * x * x * (x * (x * 6.0 - 15.0) + 10.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Attach an observer to read the interpolator's state for debugging
|
//! Attach an observer to read the interpolator's state for debugging
|
||||||
//! \remark parts logging has a \c bool \c log flag
|
//! \remark parts logging has a \c bool \c log flag
|
||||||
void attachLogger(CInterpolationLogger *logger) { m_logger = logger; }
|
void attachLogger(CInterpolationLogger *logger) { m_logger = logger; }
|
||||||
@@ -219,11 +209,6 @@ namespace BlackMisc
|
|||||||
//! \remark mainly needed in UNIT tests
|
//! \remark mainly needed in UNIT tests
|
||||||
void resetLastInterpolation();
|
void resetLastInterpolation();
|
||||||
|
|
||||||
//! Clear all data
|
|
||||||
//! \remark mainly needed in UNIT tests
|
|
||||||
//! \private
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
//! Init, or re-init the corressponding model
|
//! Init, or re-init the corressponding model
|
||||||
//! \remark either by passing a model or using the provider
|
//! \remark either by passing a model or using the provider
|
||||||
void initCorrespondingModel(const CAircraftModel &model = {});
|
void initCorrespondingModel(const CAircraftModel &model = {});
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ namespace BlackMiscTest
|
|||||||
const CInterpolationAndRenderingSetupPerCallsign setup(cs, gSetup);
|
const CInterpolationAndRenderingSetupPerCallsign setup(cs, gSetup);
|
||||||
|
|
||||||
CRemoteAircraftProviderDummy provider;
|
CRemoteAircraftProviderDummy provider;
|
||||||
CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider);
|
|
||||||
interpolator.markAsUnitTest();
|
|
||||||
|
|
||||||
// fixed time so everything can be debugged
|
// fixed time so everything can be debugged
|
||||||
const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch()
|
const qint64 ts = 1425000000000; // QDateTime::currentMSecsSinceEpoch()
|
||||||
@@ -70,32 +68,41 @@ namespace BlackMiscTest
|
|||||||
|
|
||||||
// Testing for a time >> last time
|
// Testing for a time >> last time
|
||||||
// all on ground flags true
|
// all on ground flags true
|
||||||
provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here
|
{
|
||||||
QVERIFY2(provider.remoteAircraftPartsCount(cs) == parts.size(), "Wrong parts size");
|
CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider);
|
||||||
|
interpolator.markAsUnitTest();
|
||||||
|
|
||||||
CInterpolationResult result = interpolator.getInterpolation(farFuture, setup);
|
provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here
|
||||||
CAircraftParts p = result;
|
QVERIFY2(provider.remoteAircraftPartsCount(cs) == parts.size(), "Wrong parts size");
|
||||||
qint64 pTs = p.getAdjustedMSecsSinceEpoch();
|
|
||||||
QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
|
CInterpolationResult result = interpolator.getInterpolation(farFuture, setup, 0);
|
||||||
QVERIFY2(pTs == ts, "Expect latest ts");
|
CAircraftParts p = result;
|
||||||
result = interpolator.getInterpolation(farPast, setup);
|
qint64 pTs = p.getAdjustedMSecsSinceEpoch();
|
||||||
p = result;
|
QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
|
||||||
pTs = p.getAdjustedMSecsSinceEpoch();
|
QVERIFY2(pTs == ts, "Expect latest ts");
|
||||||
QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
|
result = interpolator.getInterpolation(farPast, setup, 0);
|
||||||
QVERIFY2(pTs == oldestTs, "Expect oldest ts");
|
p = result;
|
||||||
|
pTs = p.getAdjustedMSecsSinceEpoch();
|
||||||
|
QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
|
||||||
|
QVERIFY2(pTs == oldestTs, "Expect oldest ts");
|
||||||
|
}
|
||||||
|
|
||||||
// Testing for a time >> last time
|
// Testing for a time >> last time
|
||||||
// all on ground flags true
|
// all on ground flags false
|
||||||
interpolator.clear();
|
{
|
||||||
provider.clear();
|
provider.clear();
|
||||||
|
|
||||||
parts.setOnGround(false);
|
CInterpolatorSpline interpolator(cs, nullptr, nullptr, &provider);
|
||||||
provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here
|
interpolator.markAsUnitTest();
|
||||||
result = interpolator.getInterpolation(farFuture, setup);
|
|
||||||
p = result;
|
parts.setOnGround(false);
|
||||||
pTs = p.getAdjustedMSecsSinceEpoch();
|
provider.insertNewAircraftParts(cs, parts, false); // we work with 0 offsets here
|
||||||
QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
|
CInterpolationResult result = interpolator.getInterpolation(farFuture, setup, 0);
|
||||||
QVERIFY2(p.getAdjustedMSecsSinceEpoch() == pTs, "Expect latest ts");
|
CAircraftParts p = result;
|
||||||
|
qint64 pTs = p.getAdjustedMSecsSinceEpoch();
|
||||||
|
QVERIFY2(result.getPartsStatus().isSupportingParts(), "Should support parts");
|
||||||
|
QVERIFY2(p.getAdjustedMSecsSinceEpoch() == pTs, "Expect latest ts");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTestInterpolatorParts::partsToSituationGndFlag()
|
void CTestInterpolatorParts::partsToSituationGndFlag()
|
||||||
|
|||||||
Reference in New Issue
Block a user