mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T683, "updateOwnSituationAndGroundElevation"
* function to use own positions "on ground" to calculate ground elevation * use this based on settings * adjusted simulators code
This commit is contained in:
committed by
Mat Sutcliffe
parent
fc2f7b4a12
commit
0360704b0b
@@ -1100,6 +1100,39 @@ namespace BlackCore
|
||||
// can be overridden
|
||||
}
|
||||
|
||||
bool ISimulator::updateOwnSituationAndGroundElevation(const CAircraftSituation &situation)
|
||||
{
|
||||
const bool updated = this->updateOwnSituation(situation);
|
||||
|
||||
// do not use every situation, but every deltaMs and only on ground
|
||||
constexpr qint64 deltaMs = 5000;
|
||||
if (situation.isOnGround() && situation.getTimeDifferenceAbsMs(m_lastRecordedGndElevationMs) > deltaMs)
|
||||
{
|
||||
m_lastRecordedGndElevationMs = situation.getMSecsSinceEpoch();
|
||||
const CSimulatorSettings settings = m_multiSettings.getSettings(this->getSimulatorInfo());
|
||||
if (settings.isRecordOwnAircraftGnd())
|
||||
{
|
||||
const CSimulatedAircraft ownAircraft = this->getOwnAircraft();
|
||||
CAltitude elevation = situation.getGroundElevation();
|
||||
if (elevation.isNull())
|
||||
{
|
||||
const CLength cg = ownAircraft.getModel().getCG();
|
||||
elevation = (cg.isNull() || situation.getAltitude().isNull()) ? CAltitude::null() : (situation.getAltitude().withOffset(cg * -1.0));
|
||||
}
|
||||
|
||||
if (!elevation.isNull())
|
||||
{
|
||||
const CCallsign cs = situation.hasCallsign() ? situation.getCallsign() : ownAircraft.getCallsign();
|
||||
const CLength radius = settings.getRecordedGndRadius().isNull() ? CElevationPlane::singlePointRadius() : settings.getRecordedGndRadius();
|
||||
const CElevationPlane ep(situation, radius);
|
||||
const bool remembered = this->rememberGroundElevation(cs, ep, radius);
|
||||
Q_UNUSED(remembered); // false means it was already in that cache, or something else is wrong
|
||||
}
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
CAircraftModelList ISimulator::getModelSet() const
|
||||
{
|
||||
const CSimulatorInfo simulator = this->getSimulatorInfo();
|
||||
|
||||
@@ -431,6 +431,7 @@ namespace BlackCore
|
||||
virtual int physicallyRemoveAllRemoteAircraft();
|
||||
|
||||
//! Set elevation and CG in the providers and for auto publishing
|
||||
//! \sa ISimulator::updateOwnSituationAndGroundElevation
|
||||
void rememberElevationAndSimulatorCG(const BlackMisc::Aviation::CCallsign &callsign, const QString &modelString, const BlackMisc::Geo::CElevationPlane &elevation, const BlackMisc::PhysicalQuantities::CLength &simulatorCG);
|
||||
|
||||
//! Emit the combined status
|
||||
@@ -535,6 +536,9 @@ namespace BlackCore
|
||||
//! Own model has been changed
|
||||
virtual void onOwnModelChanged(const BlackMisc::Simulation::CAircraftModel &newModel);
|
||||
|
||||
//! Update own aircraft position and if suitable use it to update ground elevation
|
||||
bool updateOwnSituationAndGroundElevation(const BlackMisc::Aviation::CAircraftSituation &situation);
|
||||
|
||||
//! Get the model set
|
||||
BlackMisc::Simulation::CAircraftModelList getModelSet() const;
|
||||
|
||||
@@ -554,6 +558,7 @@ namespace BlackCore
|
||||
qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics total update time
|
||||
qint64 m_statsCurrentUpdateTimeMs = 0; //!< statistics current update time
|
||||
qint64 m_statsMaxUpdateTimeMs = 0; //!< statistics max.update time
|
||||
qint64 m_lastRecordedGndElevationMs = 0; //!< when gnd.elevation was last modified
|
||||
qint64 m_statsLastUpdateAircraftRequestedMs = 0; //!< when was the last aircraft update requested
|
||||
qint64 m_statsUpdateAircraftRequestedDeltaMs = 0; //!< delta time between 2 aircraft updates
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ namespace BlackMisc
|
||||
//! Time difference in ms
|
||||
qint64 getTimeDifferenceMs(qint64 compareTime) const { return compareTime - this->getMSecsSinceEpoch(); }
|
||||
|
||||
//! Time difference in ms
|
||||
qint64 getTimeDifferenceAbsMs(qint64 compareTime) const { return qAbs(compareTime - this->getMSecsSinceEpoch()); }
|
||||
|
||||
//! Time difference to now
|
||||
qint64 getTimeDifferenceToNowMs() const { return this->getTimeDifferenceMs(QDateTime::currentMSecsSinceEpoch()); }
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace BlackSimPlugin
|
||||
}
|
||||
}
|
||||
|
||||
return this->updateOwnSituation(situation);
|
||||
return this->updateOwnSituationAndGroundElevation(situation);
|
||||
}
|
||||
|
||||
bool CSimulatorEmulated::changeInternalParts(const CAircraftParts &parts)
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace BlackSimPlugin
|
||||
// Updates
|
||||
// Do not update ICAO codes, as this overrides reverse lookups
|
||||
// updateOwnIcaoCodes(m_flightgearData.aircraftIcaoCode, CAirlineIcaoCode());
|
||||
this->updateOwnSituation(situation);
|
||||
this->updateOwnSituationAndGroundElevation(situation);
|
||||
|
||||
// defaults
|
||||
CSimulatedAircraft myAircraft(getOwnAircraft());
|
||||
|
||||
@@ -381,7 +381,7 @@ namespace BlackSimPlugin
|
||||
}
|
||||
|
||||
const CAircraftSituation aircraftSituation = simDataOwnAircraft.getSituation();
|
||||
this->updateOwnSituation(aircraftSituation);
|
||||
this->updateOwnSituationAndGroundElevation(aircraftSituation);
|
||||
|
||||
if (m_isWeatherActivated)
|
||||
{
|
||||
|
||||
@@ -678,7 +678,7 @@ namespace BlackSimPlugin
|
||||
ts);
|
||||
|
||||
// set values
|
||||
this->updateOwnSituation(aircraftSituation);
|
||||
this->updateOwnSituationAndGroundElevation(aircraftSituation);
|
||||
this->updateOwnParts(parts);
|
||||
|
||||
// When I change cockpit values in the sim (from GUI to simulator, not originating from simulator)
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace BlackSimPlugin
|
||||
// Updates
|
||||
// Do not update ICAO codes, as this overrides reverse lookups
|
||||
// updateOwnIcaoCodes(m_xplaneData.aircraftIcaoCode, CAirlineIcaoCode());
|
||||
this->updateOwn(situation);
|
||||
this->updateOwnSituationAndGroundElevation(situation);
|
||||
|
||||
// defaults
|
||||
CSimulatedAircraft myAircraft(getOwnAircraft());
|
||||
|
||||
Reference in New Issue
Block a user