diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index 3621f4da5..51b5a8aa7 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -96,6 +96,9 @@ namespace BlackCore //! A single model has been matched for given aircraft void modelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + //! Aircraft rendering changed + void aircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + //! Emitted when own aircraft model changes void ownAircraftModelChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index e1a2ad099..c62922aee 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -149,7 +149,7 @@ namespace BlackCore } Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getInstalledModels(); + return m_modelMatcher.getModelSet(); } int CContextSimulator::getInstalledModelsCount() const @@ -158,7 +158,7 @@ namespace BlackCore if (m_simulatorPlugin.first.isUnspecified()) { return 0; } Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getInstalledModels().size(); + return getInstalledModels().size(); } CAircraftModelList CContextSimulator::getInstalledModelsStartingWith(const QString modelString) const @@ -170,7 +170,7 @@ namespace BlackCore } Q_ASSERT(m_simulatorPlugin.second); - return m_simulatorPlugin.second->getInstalledModels().findModelsStartingWith(modelString); + return getInstalledModels().findModelsStartingWith(modelString); } void CContextSimulator::reloadInstalledModels() @@ -350,11 +350,17 @@ namespace BlackCore ISimulator *simulator = factory->create(simulatorPluginInfo, ownAircraftProvider, renderedAircraftProvider, &m_weatherManager); Q_ASSERT_X(simulator, Q_FUNC_INFO, "no simulator driver can be created"); + setRemoteAircraftProvider(renderedAircraftProvider); + const CSimulatorInfo simInfo(simulatorPluginInfo.getIdentifier()); + m_modelSetLoader.changeSimulator(simInfo); + m_modelMatcher.setModelSet(m_modelSetLoader.getAircraftModels()); + m_modelMatcher.setDefaultModel(simulator->getDefaultModel()); + bool c = connect(simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged); Q_ASSERT(c); c = connect(simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); Q_ASSERT(c); - c = connect(simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted); + c = connect(simulator, &ISimulator::aircraftRenderingChanged, this, &IContextSimulator::aircraftRenderingChanged); Q_ASSERT(c); c = connect(simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged); Q_ASSERT(c); @@ -476,7 +482,13 @@ namespace BlackCore if (!isSimulatorSimulating()) { return; } Q_ASSERT(!remoteAircraft.getCallsign().isEmpty()); - m_simulatorPlugin.second->logicallyAddRemoteAircraft(remoteAircraft); + CCallsign callsign = remoteAircraft.getCallsign(); + CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(remoteAircraft); + Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns"); + updateAircraftModel(callsign, aircraftModel, identifier()); + CSimulatedAircraft aircraftAfterModelApplied = getAircraftInRangeForCallsign(remoteAircraft.getCallsign()); + m_simulatorPlugin.second->logicallyAddRemoteAircraft(aircraftAfterModelApplied); + emit modelMatchingCompleted(remoteAircraft); } void CContextSimulator::ps_removedRemoteAircraft(const CCallsign &callsign) @@ -500,7 +512,7 @@ namespace BlackCore for (const CSimulatedAircraft &simulatedAircraft : aircrafts) { Q_ASSERT(!simulatedAircraft.getCallsign().isEmpty()); - m_simulatorPlugin.second->logicallyAddRemoteAircraft(simulatedAircraft); + ps_addRemoteAircraft(simulatedAircraft); } m_initallyAddAircrafts = false; } @@ -569,7 +581,13 @@ namespace BlackCore { if (m_simulatorPlugin.first.isUnspecified()) { return CPixmap(); } Q_ASSERT_X(m_simulatorPlugin.second, Q_FUNC_INFO, "Missing simulator"); - return m_simulatorPlugin.second->iconForModel(modelString); + const CAircraftModel model(this->m_modelSetLoader.getModelForModelString(modelString)); + + // load from file + CStatusMessage msg; + const CPixmap pm(model.loadIcon(msg)); + if (!msg.isEmpty()) { CLogMessage::preformatted(msg);} + return pm; } void CContextSimulator::enableDebugMessages(bool driver, bool interpolator) diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index ff598bc49..036114bc3 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -12,6 +12,7 @@ #ifndef BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H #define BLACKCORE_CONTEXT_CONTEXTSIMULATOR_IMPL_H +#include "blackcore/aircraftmatcher.h" #include "blackcore/blackcoreexport.h" #include "blackcore/context/contextsimulator.h" #include "blackcore/corefacadeconfig.h" @@ -25,6 +26,8 @@ #include "blackmisc/pq/time.h" #include "blackmisc/settingscache.h" #include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/aircraftmodelsetloader.h" +#include "blackmisc/simulation/remoteaircraftprovider.h" #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorplugininfolist.h" #include "blackmisc/simulation/simulatorsetup.h" @@ -52,6 +55,7 @@ namespace BlackCore //! Network simulator concrete implementation class BLACKCORE_EXPORT CContextSimulator : public IContextSimulator, + public BlackMisc::Simulation::CRemoteAircraftAware, // gain access to in memory remote aircraft data public BlackMisc::CIdentifiable { Q_OBJECT @@ -209,6 +213,9 @@ namespace BlackCore BlackCore::CWeatherManager m_weatherManager { this }; BlackMisc::CSetting m_enabledSimulators { this, &CContextSimulator::restoreSimulatorPlugins }; bool m_initallyAddAircrafts = false; + + BlackCore::CAircraftMatcher m_modelMatcher; //!< Model matcher + BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches }; } // namespace } // namespace diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 4c907d52a..7c74fe7b0 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -88,6 +88,9 @@ namespace BlackCore //! Disconnect from simulator virtual bool disconnectFrom() = 0; + //! Get default aircraft model + virtual BlackMisc::Simulation::CAircraftModel getDefaultModel() const = 0; + //! Logically add a new aircraft. Depending on max. aircraft, enabled status etc. //! it will physically added to the simulator. //! \sa physicallyAddRemoteAircraft @@ -112,12 +115,6 @@ namespace BlackCore //! Display a text message virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const = 0; - //! Aircraft models for available remote aircrafts - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const = 0; - - //! Count of aircraft models for available remote aircrafts - virtual int getInstalledModelsCount() const = 0; - //! Reload the installed models from disk virtual void reloadInstalledModels() = 0; @@ -131,9 +128,6 @@ namespace BlackCore //! Time synchronization offset virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; - //! Representing icon for model string - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const = 0; - //! Max. rendered aircraft virtual int getMaxRenderedAircraft() const = 0; @@ -199,8 +193,8 @@ namespace BlackCore //! Render restrictions have been changed void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary); - //! A single model has been matched - void modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft aircraft); + //! Aircraft rendering changed + void aircraftRenderingChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft); //! Installed aircraft models ready or changed void installedAircraftModelsChanged(); diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index 43aabeadc..9172600c7 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -61,11 +61,6 @@ namespace BlackCore connect(&m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer); this->m_oneSecondTimer.start(1000); - // init mapper - const CSimulatorInfo sim(info.getIdentifier()); - this->m_modelSetLoader.changeSimulator(sim); - this->m_modelMatcher.setModelSet(this->m_modelSetLoader.getAircraftModels()); - // info CLogMessage(this).info("Initialized simulator driver %1") << m_simulatorPluginInfo.toQString(); } @@ -167,6 +162,11 @@ namespace BlackCore } } + CAircraftModel CSimulatorCommon::getDefaultModel() const + { + return m_defaultModel; + } + int CSimulatorCommon::getMaxRenderedAircraft() const { return (m_maxRenderedAircraft <= MaxAircraftInfinite) ? m_maxRenderedAircraft : MaxAircraftInfinite; @@ -267,11 +267,6 @@ namespace BlackCore Q_UNUSED(interpolatorMessages); } - int CSimulatorCommon::getInstalledModelsCount() const - { - return getInstalledModels().size(); - } - void CSimulatorCommon::highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) { CCallsign cs(aircraftToHighlight.getCallsign()); diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 0d09a3c31..7b3c4aae2 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -67,6 +67,7 @@ namespace BlackCore //! \name ISimulator implementations //! @{ + virtual BlackMisc::Simulation::CAircraftModel getDefaultModel() const override; virtual int getMaxRenderedAircraft() const override; virtual void setMaxRenderedAircraft(int maxRenderedAircraft) override; virtual void setMaxRenderedDistance(const BlackMisc::PhysicalQuantities::CLength &distance) override; @@ -75,7 +76,6 @@ namespace BlackCore virtual bool isMaxAircraftRestricted() const override; virtual bool isMaxDistanceRestricted() const override; virtual void enableDebugMessages(bool driverMessages, bool interpolatorMessages) override; - virtual int getInstalledModelsCount() const override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; virtual bool isRenderingEnabled() const override; virtual bool isRenderingRestricted() const override; @@ -130,10 +130,7 @@ namespace BlackCore BlackMisc::IInterpolator *m_interpolator = nullptr; //!< interpolator instance bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold) BlackMisc::Simulation::CSimulatorSetup m_simulatorSetup; //!< setup object - - //! \todo unclear if this is valid for all simulators or for MS/P3D simulators only - BlackCore::CAircraftMatcher m_modelMatcher; //!< Model matcher - BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches + BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< default model private: bool m_debugMessages = false; //!< Display debug messages diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index 5a81ba235..a010bc75c 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -99,6 +99,7 @@ namespace BlackGui connect(sGui->getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CMappingComponent::ps_onAircraftModelsLoaded); connect(sGui->getIContextSimulator(), &IContextSimulator::modelMatchingCompleted, this, &CMappingComponent::ps_onModelMatchingCompleted); + connect(sGui->getIContextSimulator(), &IContextSimulator::aircraftRenderingChanged, this, &CMappingComponent::ps_onAircraftRenderingChanged); connect(sGui->getIContextSimulator(), &IContextSimulator::airspaceSnapshotHandled, this, &CMappingComponent::ps_onAirspaceSnapshotHandled); connect(sGui->getIContextNetwork(), &IContextNetwork::changedRemoteAircraftModel, this, &CMappingComponent::ps_onRemoteAircraftModelChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::changedRemoteAircraftEnabled, this, &CMappingComponent::ps_onChangedAircraftEnabled); @@ -151,6 +152,12 @@ namespace BlackGui this->ps_onSimulatedAircraftUpdateRequested(); } + void CMappingComponent::ps_onAircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) + { + Q_UNUSED(aircraft); + this->ps_onSimulatedAircraftUpdateRequested(); + } + void CMappingComponent::ps_onRowCountChanged(int count, bool withFilter) { Q_UNUSED(count); diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index 19be07e7e..547ec532a 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -81,6 +81,9 @@ namespace BlackGui //! Model matched void ps_onModelMatchingCompleted(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + //! Model matched + void ps_onAircraftRenderingChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + //! Changed count void ps_onRowCountChanged(int count, bool withFilter); diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index d3c086b0a..ddda4f7b7 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -107,12 +107,12 @@ namespace BlackSimPlugin { connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0)); this->m_interpolator = new BlackMisc::CInterpolatorLinear(remoteAircraftProvider, this); - m_modelMatcher.setDefaultModel(CAircraftModel( - "Boeing 737-400", - CAircraftModel::TypeModelMatchingDefaultModel, - "B737-400 default model", - CAircraftIcaoCode("B734", "L2J") - )); + m_defaultModel = { + "Boeing 737-400", + CAircraftModel::TypeModelMatchingDefaultModel, + "B737-400 default model", + CAircraftIcaoCode("B734", "L2J") + }; } bool CSimulatorFs9::isConnected() const @@ -163,23 +163,19 @@ namespace BlackSimPlugin this->physicallyRemoveRemoteAircraft(callsign); } - CSimulatedAircraft newRemoteAircraftCopy(newRemoteAircraft); - // matched models - CAircraftModel aircraftModel = getClosestMatch(newRemoteAircraftCopy); - Q_ASSERT(newRemoteAircraft.getCallsign() == aircraftModel.getCallsign()); - updateAircraftModel(newRemoteAircraft.getCallsign(), aircraftModel); - updateAircraftRendered(newRemoteAircraft.getCallsign(), true); - CSimulatedAircraft aircraftAfterModelApplied(getAircraftInRangeForCallsign(newRemoteAircraft.getCallsign())); - aircraftAfterModelApplied.setRendered(true); - emit modelMatchingCompleted(aircraftAfterModelApplied); - - CFs9Client *client = new CFs9Client(callsign, aircraftModel.getModelString(), m_interpolator, CTime(25, CTimeUnit::ms()), this); + bool rendered = true; + updateAircraftRendered(callsign, rendered); + CFs9Client *client = new CFs9Client(callsign, newRemoteAircraft.getModelString(), m_interpolator, CTime(25, CTimeUnit::ms()), this); client->setHostAddress(m_fs9Host->getHostAddress()); client->setPlayerUserId(m_fs9Host->getPlayerUserId()); - client->start(); + + m_hashFs9Clients.insert(callsign, client); - updateAircraftRendered(callsign, true); + updateAircraftRendered(callsign, rendered); + CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); + remoteAircraftCopy.setRendered(rendered); + emit aircraftRenderingChanged(remoteAircraftCopy); CLogMessage(this).info("FS9: Added aircraft %1") << callsign.toQString(); return true; } diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.cpp b/src/plugins/simulator/fscommon/simulatorfscommon.cpp index b4e7fe130..414d084a5 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.cpp +++ b/src/plugins/simulator/fscommon/simulatorfscommon.cpp @@ -85,27 +85,6 @@ namespace BlackSimPlugin } } - CAircraftModel CSimulatorFsCommon::getClosestMatch(const CSimulatedAircraft &remoteAircraft) - { - return m_modelMatcher.getClosestMatch(remoteAircraft); - } - - CAircraftModelList CSimulatorFsCommon::getInstalledModels() const - { - return m_modelMatcher.getModelSet(); - } - - CPixmap CSimulatorFsCommon::iconForModel(const QString &modelString) const - { - const CAircraftModel model(this->m_modelSetLoader.getModelForModelString(modelString)); - - // load from file - CStatusMessage msg; - const CPixmap pm(model.loadIcon(msg)); - if (!msg.isEmpty()) { CLogMessage::preformatted(msg);} - return pm; - } - bool CSimulatorFsCommon::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft) { // remove upfront, and then enable / disable again diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.h b/src/plugins/simulator/fscommon/simulatorfscommon.h index 33b7afb1e..ae1e257ce 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.h +++ b/src/plugins/simulator/fscommon/simulatorfscommon.h @@ -36,9 +36,6 @@ namespace BlackSimPlugin //! FSUIPC connected? bool isFsuipcConnected() const; - //! Experimental model matching - BlackMisc::Simulation::CAircraftModel getClosestMatch(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft); - //! \copydoc BlackCore::ISimulator::isPaused virtual bool isPaused() const override { return m_simPaused; } @@ -54,12 +51,6 @@ namespace BlackSimPlugin //! \copydoc BlackCore::ISimulator::getAirportsInRange virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; - //! \copydoc BlackCore::ISimulator::getInstalledModels - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; - - //! \copydoc BlackCore::Context::IContextSimulator::iconForModel - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; - //! \copydoc BlackCore::ISimulator::changeRemoteAircraftModel virtual bool changeRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) override; diff --git a/src/plugins/simulator/fsx/simulatorfsx.cpp b/src/plugins/simulator/fsx/simulatorfsx.cpp index e0ddd264d..215c63fc6 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.cpp +++ b/src/plugins/simulator/fsx/simulatorfsx.cpp @@ -53,12 +53,12 @@ namespace BlackSimPlugin m_useFsuipc = true; // Temporarily enabled until Simconnect Weather is implemented. this->m_interpolator = new CInterpolatorLinear(remoteAircraftProvider, this); - m_modelMatcher.setDefaultModel(CAircraftModel( - "Boeing 737-800 Paint1", - CAircraftModel::TypeModelMatchingDefaultModel, - "B737-800 default model", - CAircraftIcaoCode("B738", "L2J") - )); + m_defaultModel = { + "Boeing 737-800 Paint1", + CAircraftModel::TypeModelMatchingDefaultModel, + "B737-800 default model", + CAircraftIcaoCode("B738", "L2J") + }; } CSimulatorFsx::~CSimulatorFsx() @@ -129,6 +129,7 @@ namespace BlackSimPlugin bool CSimulatorFsx::physicallyAddRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft) { CCallsign callsign(newRemoteAircraft.getCallsign()); + Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "thread"); Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "empty callsign"); if (callsign.isEmpty()) { return false; } @@ -144,21 +145,17 @@ namespace BlackSimPlugin CSimConnectObject simObj(callsign, m_nextObjID, 0, newRemoteAircraft.isVtol()); ++m_nextObjID; - // matched models - CAircraftModel aircraftModel = getClosestMatch(newRemoteAircraft); - Q_ASSERT_X(newRemoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns"); - - this->updateAircraftModel(callsign, aircraftModel); - CSimulatedAircraft aircraftAfterModelApplied(getAircraftInRangeForCallsign(newRemoteAircraft.getCallsign())); + CAircraftModel aircraftModel = newRemoteAircraft.getModel(); // create AI + CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); bool rendered = false; if (isConnected()) { // initial position - this->setInitialAircraftSituation(aircraftAfterModelApplied); // set interpolated data/parts if available + this->setInitialAircraftSituation(remoteAircraftCopy); // set interpolated data/parts if available - SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxInitPosition(aircraftAfterModelApplied.getSituation()); + SIMCONNECT_DATA_INITPOSITION initialPosition = aircraftSituationToFsxInitPosition(remoteAircraftCopy.getSituation()); QByteArray m = aircraftModel.getModelString().toLocal8Bit(); HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, m.constData(), qPrintable(callsign.toQString().left(12)), initialPosition, static_cast(simObj.getRequestId())); if (hr != S_OK) { CLogMessage(this).error("SimConnect, can not create AI traffic"); } @@ -171,9 +168,9 @@ namespace BlackSimPlugin CLogMessage(this).warning("FSX: Not connected, not added aircraft %1") << callsign.toQString(); } - aircraftAfterModelApplied.setRendered(rendered); + remoteAircraftCopy.setRendered(rendered); this->updateAircraftRendered(callsign, rendered); - emit modelMatchingCompleted(aircraftAfterModelApplied); + emit aircraftRenderingChanged(remoteAircraftCopy); return rendered; } diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index e33fa3215..252788771 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -102,12 +102,12 @@ namespace BlackSimPlugin m_fastTimer->start(100); m_slowTimer->start(1000); - m_modelMatcher.setDefaultModel(CAircraftModel( - "Jets A320_a A320_a_Austrian_Airlines A320_a_Austrian_Airlines", - CAircraftModel::TypeModelMatchingDefaultModel, - "A320 AUA", - CAircraftIcaoCode("A320", "L2J") - )); + m_defaultModel = { + "Jets A320_a A320_a_Austrian_Airlines A320_a_Austrian_Airlines", + CAircraftModel::TypeModelMatchingDefaultModel, + "A320 AUA", + CAircraftIcaoCode("A320", "L2J") + }; resetData(); } @@ -351,12 +351,6 @@ namespace BlackSimPlugin m_service->addTextMessage(message.getSenderCallsign().toQString() + ": " + message.getMessage(), color.redF(), color.greenF(), color.blueF()); } - CAircraftModelList CSimulatorXPlane::getInstalledModels() const - { - Q_ASSERT(isConnected()); - return m_installedModels; - } - void CSimulatorXPlane::ps_setAirportsInRange(const QStringList &icaos, const QStringList &names, const BlackMisc::CSequence &lats, const BlackMisc::CSequence &lons, const BlackMisc::CSequence &alts) { m_airportsInRange.clear(); @@ -390,12 +384,6 @@ namespace BlackSimPlugin return false; } - CPixmap CSimulatorXPlane::iconForModel(const QString &modelString) const - { - Q_UNUSED(modelString); - return CPixmap(); - } - QDBusConnection CSimulatorXPlane::connectionFromString(const QString &str) { if (str == BlackMisc::CDBusServer::sessionBusAddress()) @@ -452,26 +440,23 @@ namespace BlackSimPlugin //! \todo XPlane driver check if already exists, how? //! \todo XPlane driver set correct return value - // matched models - CAircraftModel aircraftModel = m_modelMatcher.getClosestMatch(newRemoteAircraft); - Q_ASSERT_X(newRemoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns"); - CCallsign callsign(newRemoteAircraft.getCallsign()); - this->updateAircraftModel(callsign, aircraftModel); - CSimulatedAircraft aircraftAfterModelApplied(getAircraftInRangeForCallsign(newRemoteAircraft.getCallsign())); + CAircraftModel aircraftModel = newRemoteAircraft.getModel(); QString livery = aircraftModel.getLivery().getCombinedCode(); //! \todo livery resolution for XP m_traffic->addPlane(newRemoteAircraft.getCallsign().asString(), aircraftModel.getModelString(), newRemoteAircraft.getAircraftIcaoCode().getDesignator(), newRemoteAircraft.getAirlineIcaoCode().getDesignator(), livery); - updateAircraftRendered(newRemoteAircraft.getCallsign(), true); + CLogMessage(this).info("XP: Added aircraft %1") << newRemoteAircraft.getCallsign().toQString(); bool rendered = true; - aircraftAfterModelApplied.setRendered(rendered); - this->updateAircraftRendered(callsign, rendered); - emit modelMatchingCompleted(aircraftAfterModelApplied); + updateAircraftRendered(newRemoteAircraft.getCallsign(), rendered); + + CSimulatedAircraft remoteAircraftCopy(newRemoteAircraft); + remoteAircraftCopy.setRendered(rendered); + emit aircraftRenderingChanged(remoteAircraftCopy); return rendered; } diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index 00b0d7514..d071f2ae9 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -93,11 +93,9 @@ namespace BlackSimPlugin virtual bool updateOwnSimulatorCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator) override; virtual void displayStatusMessage(const BlackMisc::CStatusMessage &message) const override; virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override; - virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override; virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override; virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override { return BlackMisc::PhysicalQuantities::CTime(0, BlackMisc::PhysicalQuantities::CTimeUnit::hrmin()); } - virtual BlackMisc::CPixmap iconForModel(const QString &modelString) const override; //! @} //! Creates an appropriate dbus connection from the string describing it