diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index 5c6595968..121afd4a9 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -77,6 +77,14 @@ namespace BlackCore //! \brief Aircraft list has been changed void changedAircraftsInRange(); + /*! + * \brief Aircraft situation update + * \param callsign + * \param situation + * \return + */ + void aircraftSituationUpdate(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation); + //! \brief Terminated connection void connectionTerminated(); diff --git a/src/blackcore/context_network_aircraft.cpp b/src/blackcore/context_network_aircraft.cpp index bb06404b2..c9bbe13c2 100644 --- a/src/blackcore/context_network_aircraft.cpp +++ b/src/blackcore/context_network_aircraft.cpp @@ -57,6 +57,8 @@ namespace BlackCore void CContextNetwork::psFsdAircraftUpdateReceived(const CCallsign &callsign, const CAircraftSituation &situation, const CTransponder &transponder) { // this->log(Q_FUNC_INFO, callsign.toQString(), situation.toQString(), transponder.toQString()); + + CAircraftList list = this->m_aircraftsInRange.findByCallsign(callsign); if (list.isEmpty()) { @@ -90,6 +92,8 @@ namespace BlackCore this->m_aircraftsInRange.applyIf(BlackMisc::Predicates::MemberEqual(&CAircraft::getCallsign, callsign), vm); emit this->changedAircraftsInRange(); } + + aircraftSituationUpdate(callsign, situation); } /* diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index 84a359bed..f8554b855 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -30,7 +30,6 @@ namespace BlackCore m_simulator = new BlackCore::FSX::CSimulatorFSX(this); connect(m_simulator, &ISimulator::connectionChanged, this, &CContextSimulator::setConnectionStatus); #endif - connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft); } @@ -52,6 +51,17 @@ namespace BlackCore return m_ownAircraft; } + void CContextSimulator::init() + { + if (!m_contextNetwork) + { + m_contextNetwork = getRuntime()->getIContextNetwork(); + } + + if (m_simulator) + connect(m_contextNetwork, &IContextNetwork::aircraftSituationUpdate, m_simulator, &ISimulator::addAircraftSituation); + } + void CContextSimulator::updateOwnAircraft() { if (!m_simulator) @@ -59,10 +69,7 @@ namespace BlackCore m_ownAircraft = m_simulator->getOwnAircraft(); - if (!m_contextNetwork) - { - m_contextNetwork = getRuntime()->getIContextNetwork(); - } + m_contextNetwork->updateOwnSituation(m_ownAircraft.getSituation()); m_contextNetwork->updateOwnCockpit(m_ownAircraft.getCom1System(), m_ownAircraft.getCom2System(), m_ownAircraft.getTransponder()); diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index f407551ec..a8de7ada0 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -57,6 +57,9 @@ namespace BlackCore return static_cast(this->parent()); } + //! \brief Initialze the context + void init(); + //! \copydoc IContextSimulator::usingLocalObjects() virtual bool usingLocalObjects() const override { return true; } @@ -67,6 +70,8 @@ namespace BlackCore //! \copydoc IContextSimulator::getOwnAircraft() virtual BlackMisc::Aviation::CAircraft getOwnAircraft() const override; + + private slots: //! \copydoc IContextSimulator::updateOwnAircraft() virtual void updateOwnAircraft(); diff --git a/src/blackcore/coreruntime.cpp b/src/blackcore/coreruntime.cpp index eb2885cce..1c0965c08 100644 --- a/src/blackcore/coreruntime.cpp +++ b/src/blackcore/coreruntime.cpp @@ -50,6 +50,7 @@ void CCoreRuntime::init(bool withDbus) if (withDbus) this->m_contextAudio->registerWithDBus(this->m_dbusServer); this->m_contextSimulator = new CContextSimulator(this); + this->m_contextSimulator->init(); if (withDbus) this->m_contextSimulator->registerWithDBus(this->m_dbusServer); m_contextAudio->init();