Ref T778, improved "canLikelySkipNearGround" in airspace monitor

* use CAircraftIcaoCode::guessModelParameters as this gives us an impression of speed
* use "breakable" do/while block / fewer nested "if" levels
This commit is contained in:
Klaus Basan
2020-03-27 22:56:59 +01:00
committed by Mat Sutcliffe
parent 5bc09ed2c8
commit e6a12d45c4
2 changed files with 123 additions and 97 deletions

View File

@@ -1370,32 +1370,50 @@ namespace BlackCore
if (callsign.isEmpty()) { return situation; }
CAircraftSituation correctedSituation(allowTestOffset ? this->addTestAltitudeOffsetToSituation(situation) : situation);
bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation();
bool needToRequestElevation = false;
if (!correctedSituation.hasGroundElevation())
bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation();
do
{
if (canLikelySkipNearGround || correctedSituation.hasGroundElevation()) { break; }
// set a defined state
correctedSituation.resetGroundElevation();
if (!canLikelySkipNearGround)
{
// fetch from cache or request
const CAircraftSituationChange changesBeforeStoring = this->remoteAircraftSituationChanges(callsign).frontOrDefault();
// Check if we can bail out and ignore all elevation handling
//
// rational:
// a) elevation handling is expensive, and might even requests elevation from sim.
// b) elevations not needed pollute the cache with "useless" values
//
if (canLikelySkipNearGround) { break; }
// Guessing gives better values, also for smaller planes
// and avoids unnecessary elevation fetching for low flying smaller GA aircraft
const CAircraftIcaoCode icao = this->getAircraftInRangeModelForCallsign(callsign).getAircraftIcaoCode();
if (!icao.hasDesignator()) { break; } // what is that?
if (!icao.isVtol())
{
// Not for VTOLs
CLength cg(nullptr);
CSpeed rotateSpeed(nullptr);
icao.guessModelParameters(cg, rotateSpeed);
if (!rotateSpeed.isNull())
{
rotateSpeed *= 1.2; // some margin
if (situation.getGroundSpeed() > rotateSpeed) { break; }
}
}
// fetch from cache or request
const CAircraftSituationChange changesBeforeStoring = this->remoteAircraftSituationChanges(callsign).frontOrDefault();
if (!changesBeforeStoring.isNull())
{
canLikelySkipNearGround = changesBeforeStoring.isConstAscending();
if (canLikelySkipNearGround) { break; }
}
if (!canLikelySkipNearGround)
{
// we NEED elevation
const CLength dpt = correctedSituation.getDistancePerTime(100, CElevationPlane::singlePointRadius());
const CAircraftSituationList situationsBeforeStoring = this->remoteAircraftSituations(callsign);
const CAircraftSituation situationWithElvBeforeStoring = situationsBeforeStoring.findClosestElevationWithinRange(correctedSituation, dpt);
@@ -1472,10 +1490,8 @@ namespace BlackCore
Q_UNUSED(couldNotExtrapolate)
}
} // gnd. elevation
} // can skip?
} // can skip?
} // have already elevation?
}
while (false); // do we need elevation, find on
// do we already have ground details?
if (situation.getOnGroundDetails() == CAircraftSituation::NotSetGroundDetails)

View File

@@ -248,7 +248,7 @@ namespace BlackMisc
// init to defaults
CLength guessedCG = CLength(1.5, CLengthUnit::m());
CSpeed guessedVRotate = this->isVtol() ? CSpeed::null() : CSpeed(70, CSpeedUnit::km_h());
CSpeed guessedVRotate = CSpeed(70, CSpeedUnit::km_h());
const int engines = this->getEnginesCount();
const QChar engineType = this->getEngineTypeChar().toUpper();
@@ -283,6 +283,16 @@ namespace BlackMisc
break;
}
}
if (engineType == 'J')
{
// MIL Jets a bit faster
if (this->isMilitary()) { guessedVRotate *= 1.20; }
else if (this->matchesDesignator("CONC")) { guessedVRotate = CSpeed(199, CSpeedUnit::kts()); }
}
// VTOL
if (this->isVtol()) { guessedVRotate = CSpeed(0, CSpeedUnit::kts()); }
}
while (false);