diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 7b0472cce..8b5b4def3 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -19,7 +19,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Simulation; +using namespace BlackMisc::Network; using namespace BlackMisc::Weather; namespace BlackCore @@ -34,6 +34,14 @@ namespace BlackCore return status; } + CInterpolationAndRenderingSetupPerCallsign ISimulator::getInterpolationSetupConsolidated(const CCallsign &callsign) const + { + CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign); + const CClient client = this->getClientOrDefaultForCallsign(callsign); + setup.consolidateWithClient(client); + return setup; + } + void ISimulator::registerHelp() { if (CSimpleCommandParser::registered("BlackCore::ISimulator")) { return; } @@ -64,6 +72,7 @@ namespace BlackCore CRemoteAircraftAware(remoteAircraftProvider), CWeatherGridAware(weatherGridProvider), ISimulationEnvironmentProvider(pluginInfo), + IInterpolationSetupProvider(), CIdentifiable(this) { ISimulator::registerHelp(); diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index ca686e432..65ca2a372 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -22,8 +22,10 @@ #include "blackmisc/simulation/ownaircraftprovider.h" #include "blackmisc/simulation/remoteaircraftprovider.h" #include "blackmisc/simulation/simulationenvironmentprovider.h" +#include "blackmisc/simulation/interpolationsetupprovider.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/callsignset.h" +#include "blackmisc/network/clientprovider.h" #include "blackmisc/weather/weathergridprovider.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/time.h" @@ -52,12 +54,14 @@ namespace BlackCore public BlackMisc::Simulation::COwnAircraftAware, // gain access to in memory own aircraft data public BlackMisc::Simulation::CRemoteAircraftAware, // gain access to in memory remote aircraft data public BlackMisc::Weather::CWeatherGridAware, // gain access to in memory weather grid - public BlackMisc::Simulation::ISimulationEnvironmentProvider, // give access to elevation + public BlackMisc::Network::CClientAware, // the network client with its capabilities + public BlackMisc::Simulation::ISimulationEnvironmentProvider, // give access to elevation etc. + public BlackMisc::Simulation::IInterpolationSetupProvider, // setup public BlackMisc::CIdentifiable { Q_OBJECT Q_INTERFACES(BlackMisc::Simulation::ISimulationEnvironmentProvider) - Q_INTERFACES(BlackMisc::IProvider) + Q_INTERFACES(BlackMisc::Simulation::IInterpolationSetupProvider) public: //! ISimulator status @@ -141,13 +145,13 @@ namespace BlackCore //! Time synchronization offset virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0; - //! Debugging messages etc. + //! Consolidate setup with other data like from BlackMisc::Simulation::IRemoteAircraftProvider //! \threadsafe - virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const = 0; + BlackMisc::Simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationSetupConsolidated(const BlackMisc::Aviation::CCallsign &callsign) const; //! Enable debugging messages etc. //! \threadsafe - virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) = 0; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) = 0; //! Is the aircraft rendered (displayed in simulator)? //! This shall only return true if the aircraft is really visible in the simulator diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index 13a459b15..3aac00237 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -100,7 +100,7 @@ namespace BlackCore Q_ASSERT_X(remoteAircraft.hasModelString(), Q_FUNC_INFO, "Missing model string"); Q_ASSERT_X(remoteAircraft.hasCallsign(), Q_FUNC_INFO, "Missing callsign"); - const bool renderingRestricted = this->getInterpolationAndRenderingSetup().isRenderingRestricted(); + const bool renderingRestricted = this->getInterpolationSetupGlobal().isRenderingRestricted(); if (this->showDebugLogMessage()) { this->debugLogMessage(Q_FUNC_INFO, QString("Restricted: %1 cs: '%2' enabled: %3").arg(boolToYesNo(renderingRestricted), remoteAircraft.getCallsignAsString(), boolToYesNo(remoteAircraft.isEnabled()))); } if (!remoteAircraft.isEnabled()) { return false; } @@ -114,7 +114,7 @@ namespace BlackCore bool CSimulatorCommon::logicallyRemoveRemoteAircraft(const CCallsign &callsign) { // if not restriced, directly change - if (!this->getInterpolationAndRenderingSetup().isRenderingRestricted()) + if (!this->getInterpolationSetupGlobal().isRenderingRestricted()) { m_statsPhysicallyAddedAircraft++; this->callPhysicallyRemoveRemoteAircraft(callsign); return true; @@ -214,7 +214,7 @@ namespace BlackCore bool CSimulatorCommon::showDebugLogMessage() const { - return this->getInterpolationAndRenderingSetup().showSimulatorDebugMessages(); + return this->getInterpolationSetupGlobal().showSimulatorDebugMessages(); } void CSimulatorCommon::reverseLookupAndUpdateOwnAircraftModel(const BlackMisc::Simulation::CAircraftModel &model) @@ -350,26 +350,15 @@ namespace BlackCore return renderedOnes.intersection(disabledOnes); } - void CSimulatorCommon::setInterpolationAndRenderingSetup(const CInterpolationAndRenderingSetup &setup) + void CSimulatorCommon::setInterpolationAndRenderingSetup(const CInterpolationAndRenderingSetupGlobal &setup) { - { - QWriteLocker lock(&m_interpolationRenderingSetupMutex); - if (m_interpolationRenderingSetup == setup) { return; } - m_interpolationRenderingSetup = setup; - } - + if (!this->setInterpolationSetupGlobal(setup)) { return; } const bool r = setup.isRenderingRestricted(); const bool e = setup.isRenderingEnabled(); emit this->renderRestrictionsChanged(r, e, setup.getMaxRenderedAircraft(), setup.getMaxRenderedDistance()); } - CInterpolationAndRenderingSetup CSimulatorCommon::getInterpolationAndRenderingSetup() const - { - QReadLocker lock(&m_interpolationRenderingSetupMutex); - return m_interpolationRenderingSetup; - } - void CSimulatorCommon::highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) { const CCallsign cs(aircraftToHighlight.getCallsign()); @@ -424,16 +413,14 @@ namespace BlackCore if (part2 == "off" || part2 == "false") { CStatusMessage(this).info("Disabled interpolation logging"); - QWriteLocker l(&m_interpolationRenderingSetupMutex); - m_interpolationRenderingSetup.clearInterpolatorLogCallsigns(); + this->clearInterpolationLogCallsigns(); return true; } if (part2 == "clear" || part2 == "clr") { m_interpolationLogger.clearLog(); CStatusMessage(this).info("Cleared interpolation logging"); - QWriteLocker l(&m_interpolationRenderingSetupMutex); - m_interpolationRenderingSetup.clearInterpolatorLogCallsigns(); + this->clearInterpolationLogCallsigns(); return true; } if (part2.startsWith("max")) @@ -449,10 +436,7 @@ namespace BlackCore if (part2 == "write" || part2 == "save") { // stop logging of other log - { - QWriteLocker l(&m_interpolationRenderingSetupMutex); - m_interpolationRenderingSetup.clearInterpolatorLogCallsigns(); - } + this->clearInterpolationLogCallsigns(); // write m_interpolationLogger.writeLogInBackground(); @@ -479,8 +463,7 @@ namespace BlackCore if (this->getAircraftInRangeCallsigns().contains(cs)) { CLogMessage(this).info("Will log interpolation for '%1'") << cs.asString(); - QWriteLocker l(&m_interpolationRenderingSetupMutex); - m_interpolationRenderingSetup.addCallsignToLog(cs); + this->setLogCallsign(true, cs); return true; } else @@ -494,38 +477,25 @@ namespace BlackCore { const CCallsign cs(parser.hasPart(2) ? parser.part(2) : ""); const bool changed = this->setInterpolatorMode(CInterpolatorMulti::modeFromString(part1), cs); - CLogMessage(this).info(changed ? - "Changed interpolation mode" : - "Unchanged interpolation mode"); + CLogMessage(this).info(changed ? "Changed interpolation mode" : "Unchanged interpolation mode"); return true; } // spline/linear if (part1.startsWith("pos")) { CCallsign cs(parser.part(2).toUpper()); - const CInterpolationAndRenderingSetup s = this->getInterpolationAndRenderingSetup(); if (!cs.isValid()) { - - if (s.getLogCallsigns().size() != 1) { return false; } + const CCallsignSet csSet = this->getLogCallsigns(); + if (csSet.size() != 1) { return false; } // if there is just one we take that one - cs = s.getLogCallsigns().toQList().front(); - } - - bool addedCallsign = false; - { - const bool isLoggedCallsign = s.isLogCallsign(cs); - QWriteLocker l(&m_interpolationRenderingSetupMutex); - if (!isLoggedCallsign) - { - m_interpolationRenderingSetup.addCallsignToLog(cs); - addedCallsign = true; - } + cs = *csSet.begin(); } + this->setLogCallsign(true, cs); CLogMessage(this).info("Display position for '%1'") << cs.asString(); - this->displayLoggedSituationInSimulator(cs, addedCallsign); + this->displayLoggedSituationInSimulator(cs, true); return true; } @@ -769,8 +739,8 @@ namespace BlackCore { if (cs.isEmpty()) { return; } if (this->isShuttingDown()) { return; } - const CInterpolationAndRenderingSetup setup = this->getInterpolationAndRenderingSetup(); - const bool logsCs = setup.isLogCallsign(cs); + const CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(cs); + const bool logsCs = setup.logInterpolation(); if (!logsCs) { return; } stopLogging = stopLogging || !this->isSimulating(); // stop when sim was stopped @@ -781,8 +751,7 @@ namespace BlackCore if (!stopLogging && !inRange) { return; } if (stopLogging && (times < 1 || !inRange)) { - QWriteLocker wl(&m_interpolationRenderingSetupMutex); - m_interpolationRenderingSetup.removeCallsignFromLog(cs); + this->setLogCallsign(false, cs); return; } diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index 5e5f78fc4..21245c87a 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -67,8 +67,7 @@ namespace BlackCore virtual ~CSimulatorCommon(); // --------- ISimulator implementations ------------ - virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetup &setup) override; - virtual BlackMisc::Simulation::CInterpolationAndRenderingSetup getInterpolationAndRenderingSetup() const override; + virtual void setInterpolationAndRenderingSetup(const BlackMisc::Simulation::CInterpolationAndRenderingSetupGlobal &setup) override; virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const override; virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; @@ -220,10 +219,6 @@ namespace BlackCore BlackMisc::Simulation::CSimulatorInternals m_simulatorInternals; //!< setup object BlackMisc::Simulation::CInterpolationLogger m_interpolationLogger; //!< log interpolation - // setup for logging etc. - mutable QReadWriteLock m_interpolationRenderingSetupMutex; //!< mutex protecting setup object - BlackMisc::Simulation::CInterpolationAndRenderingSetup m_interpolationRenderingSetup; //!< logging, rendering etc. - // some optional functionality which can be used by the simulators as needed BlackMisc::Simulation::CSimulatedAircraftList m_addAgainAircraftWhenRemoved; //!< add this model again when removed, normally used to change model QHash m_hints; //!< hints for callsign, contains last ground elevation fetched