From a91d7cb8520180c4c3f6331799fbcc6910869fc1 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 23 Feb 2019 17:51:42 +0100 Subject: [PATCH] Emit takeoff/touchdown signals in own aircraft context --- src/blackcore/context/contextownaircraft.h | 4 +- .../context/contextownaircraftimpl.cpp | 51 +++++++++++-------- .../context/contextownaircraftproxy.cpp | 4 +- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/blackcore/context/contextownaircraft.h b/src/blackcore/context/contextownaircraft.h index 6c935bf85..26cb9b407 100644 --- a/src/blackcore/context/contextownaircraft.h +++ b/src/blackcore/context/contextownaircraft.h @@ -107,10 +107,10 @@ namespace BlackCore void movedAircraft(); //! Just airborne - void airborne(); + void isTakingOff(); //! Just landed - void touchdown(); + void isTouchingDown(); public slots: //! Get own aircraft diff --git a/src/blackcore/context/contextownaircraftimpl.cpp b/src/blackcore/context/contextownaircraftimpl.cpp index 02a16911e..33e89af2c 100644 --- a/src/blackcore/context/contextownaircraftimpl.cpp +++ b/src/blackcore/context/contextownaircraftimpl.cpp @@ -203,30 +203,41 @@ namespace BlackCore { if (!m_history) { return; } if (!this->getIContextSimulator()) { return; } + if (!this->getIContextSimulator()->isSimulatorSimulating()) { return; } - if (this->getIContextSimulator()->isSimulatorSimulating()) + QReadLocker rl(&m_lockAircraft); + const CAircraftSituationList situations = m_situationHistory; // latest first + rl.unlock(); + + constexpr int minElements = qRound(MaxHistoryElements * 0.75); + if (m_situationHistory.size() < minElements) { return; } + + // using copy to minimize lock time + // 500km/h => 1sec: 0.1388 km + static const CLength maxDistance(25, CLengthUnit::km()); + const bool jumpDetected = situations.containsObjectOutsideRange(situations.front(), maxDistance); + + if (jumpDetected) { - if (!m_situationHistory.isEmpty()) { - QReadLocker rl(&m_lockAircraft); - const CAircraftSituationList situations = m_situationHistory; - rl.unlock(); - - // using copy to minimize lock time - // 500km/h => 1sec: 0.1388 km - static const CLength maxDistance(25, CLengthUnit::km()); - const bool jumpDetected = situations.containsObjectOutsideRange(situations.front(), maxDistance); - - if (jumpDetected) - { - { - QWriteLocker wl(&m_lockAircraft); - m_situationHistory.clear(); - } - emit this->movedAircraft(); - } + QWriteLocker wl(&m_lockAircraft); + m_situationHistory.clear(); } - } // only if simulating + emit this->movedAircraft(); + } + else + { + const bool to = situations.isTakingOff(true); + if (to) + { + emit this->isTakingOff(); + } + else + { + const bool td = situations.isTouchingDown(true); + if (td) { emit this->isTouchingDown(); } + } + } } CAircraftModel CContextOwnAircraft::reverseLookupModel(const CAircraftModel &model) diff --git a/src/blackcore/context/contextownaircraftproxy.cpp b/src/blackcore/context/contextownaircraftproxy.cpp index 2bdb6f5e8..226452aee 100644 --- a/src/blackcore/context/contextownaircraftproxy.cpp +++ b/src/blackcore/context/contextownaircraftproxy.cpp @@ -54,10 +54,10 @@ namespace BlackCore "movedAircraft", this, SIGNAL(movedAircraft())); Q_ASSERT(s); s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), - "airborne", this, SIGNAL(airborne())); + "isTakingOff", this, SIGNAL(isTakingOff())); Q_ASSERT(s); s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), - "touchdown", this, SIGNAL(touchdown())); + "isTouchingDown", this, SIGNAL(isTouchingDown())); Q_ASSERT(s); this->relayBaseClassSignals(serviceName, connection, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName());