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; } if (callsign.isEmpty()) { return situation; }
CAircraftSituation correctedSituation(allowTestOffset ? this->addTestAltitudeOffsetToSituation(situation) : situation); CAircraftSituation correctedSituation(allowTestOffset ? this->addTestAltitudeOffsetToSituation(situation) : situation);
bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation();
bool needToRequestElevation = false; bool needToRequestElevation = false;
bool canLikelySkipNearGround = correctedSituation.canLikelySkipNearGroundInterpolation();
if (!correctedSituation.hasGroundElevation()) do
{ {
if (canLikelySkipNearGround || correctedSituation.hasGroundElevation()) { break; }
// set a defined state // set a defined state
correctedSituation.resetGroundElevation(); 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 // Check if we can bail out and ignore all elevation handling
// //
// rational: // rational:
// a) elevation handling is expensive, and might even requests elevation from sim. // a) elevation handling is expensive, and might even requests elevation from sim.
// b) elevations not needed pollute the cache with "useless" values // 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()) if (!changesBeforeStoring.isNull())
{ {
canLikelySkipNearGround = changesBeforeStoring.isConstAscending(); canLikelySkipNearGround = changesBeforeStoring.isConstAscending();
if (canLikelySkipNearGround) { break; }
} }
if (!canLikelySkipNearGround) // we NEED elevation
{
const CLength dpt = correctedSituation.getDistancePerTime(100, CElevationPlane::singlePointRadius()); const CLength dpt = correctedSituation.getDistancePerTime(100, CElevationPlane::singlePointRadius());
const CAircraftSituationList situationsBeforeStoring = this->remoteAircraftSituations(callsign); const CAircraftSituationList situationsBeforeStoring = this->remoteAircraftSituations(callsign);
const CAircraftSituation situationWithElvBeforeStoring = situationsBeforeStoring.findClosestElevationWithinRange(correctedSituation, dpt); const CAircraftSituation situationWithElvBeforeStoring = situationsBeforeStoring.findClosestElevationWithinRange(correctedSituation, dpt);
@@ -1472,10 +1490,8 @@ namespace BlackCore
Q_UNUSED(couldNotExtrapolate) Q_UNUSED(couldNotExtrapolate)
} }
} // gnd. elevation } // gnd. elevation
}
} // can skip? while (false); // do we need elevation, find on
} // can skip?
} // have already elevation?
// do we already have ground details? // do we already have ground details?
if (situation.getOnGroundDetails() == CAircraftSituation::NotSetGroundDetails) if (situation.getOnGroundDetails() == CAircraftSituation::NotSetGroundDetails)

View File

@@ -248,7 +248,7 @@ namespace BlackMisc
// init to defaults // init to defaults
CLength guessedCG = CLength(1.5, CLengthUnit::m()); 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 int engines = this->getEnginesCount();
const QChar engineType = this->getEngineTypeChar().toUpper(); const QChar engineType = this->getEngineTypeChar().toUpper();
@@ -283,6 +283,16 @@ namespace BlackMisc
break; 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); while (false);