mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #395, improved snapshot handling
* disabled sets distance and max.aircraft to 0 * fixed changed snapshot detection * added rendering enabled to signal, only one function to decide (instead of duplicated logic)
This commit is contained in:
@@ -64,10 +64,11 @@ namespace BlackCore
|
||||
return m_latestAircraftSnapshot;
|
||||
}
|
||||
|
||||
void CAirspaceAnalyzer::setSimulatorRenderRestrictionsChanged(bool restricted, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary)
|
||||
void CAirspaceAnalyzer::setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary)
|
||||
{
|
||||
QWriteLocker l(&m_lockRestrictions);
|
||||
this->m_simulatorRenderedAircraftRestricted = restricted;
|
||||
this->m_simulatorRenderingEnabled = enabled;
|
||||
this->m_simulatorMaxRenderedAircraft = maxAircraft;
|
||||
this->m_simulatorMaxRenderedDistance = maxRenderedDistance;
|
||||
this->m_simulatorMaxRenderedBoundary = maxRenderedBoundary;
|
||||
@@ -177,33 +178,37 @@ namespace BlackCore
|
||||
Q_ASSERT_X(!isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background thread");
|
||||
Q_ASSERT_X(!isApplicationThreadObjectThread(this), Q_FUNC_INFO, "Expect to run in background thread affinity");
|
||||
|
||||
bool restricted;
|
||||
bool restricted, enabled;
|
||||
int maxAircraft;
|
||||
CLength maxRenderedDistance, maxRenderedBoundary;
|
||||
{
|
||||
QReadLocker l(&m_lockRestrictions);
|
||||
restricted = this->m_simulatorRenderedAircraftRestricted;
|
||||
enabled = this->m_simulatorRenderingEnabled,
|
||||
maxAircraft = this->m_simulatorMaxRenderedAircraft;
|
||||
maxRenderedDistance = this->m_simulatorMaxRenderedDistance;
|
||||
maxRenderedBoundary = this->m_simulatorMaxRenderedBoundary;
|
||||
}
|
||||
|
||||
//! \todo Analyzer: generate only when restricted?
|
||||
//! \fixme Analyzer: generate only when restricted?
|
||||
|
||||
CSimulatedAircraftList aircraftInRange(getAircraftInRange()); // thread safe copy from provider
|
||||
CAirspaceAircraftSnapshot snapshot(
|
||||
aircraftInRange,
|
||||
restricted, maxAircraft, maxRenderedDistance, maxRenderedBoundary
|
||||
restricted, enabled,
|
||||
maxAircraft, maxRenderedDistance, maxRenderedBoundary
|
||||
);
|
||||
|
||||
// lock block
|
||||
{
|
||||
QWriteLocker l(&m_lockSnapshot);
|
||||
bool wasValid = m_latestAircraftSnapshot.isValidSnapshot();
|
||||
if (wasValid)
|
||||
{
|
||||
snapshot.setRestrictionChanged(m_latestAircraftSnapshot);
|
||||
}
|
||||
m_latestAircraftSnapshot = snapshot;
|
||||
|
||||
if (!wasValid) { return; } // ignore the 1st snapshot
|
||||
snapshot.setRestrictionChanged(m_latestAircraftSnapshot);
|
||||
}
|
||||
|
||||
emit airspaceAircraftSnapshot(snapshot);
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackCore
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const;
|
||||
|
||||
//! Render restrictions in simulator
|
||||
void setSimulatorRenderRestrictionsChanged(bool restricted, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
void setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
|
||||
//! Gracefully shut down, e.g. for thread safety
|
||||
void gracefulShutdown();
|
||||
@@ -102,7 +102,7 @@ namespace BlackCore
|
||||
//! Analyze the airspace
|
||||
void analyzeAirspace();
|
||||
|
||||
QTimer m_timer{this}; //!< multi purpose timer for snapshots and watchdog
|
||||
QTimer m_timer {this}; //!< multi purpose timer for snapshots and watchdog
|
||||
|
||||
// watchdog
|
||||
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
|
||||
@@ -114,6 +114,7 @@ namespace BlackCore
|
||||
// snapshot
|
||||
BlackMisc::Simulation::CAirspaceAircraftSnapshot m_latestAircraftSnapshot;
|
||||
bool m_simulatorRenderedAircraftRestricted = false;
|
||||
bool m_simulatorRenderingEnabled = true;
|
||||
int m_simulatorMaxRenderedAircraft = -1;
|
||||
BlackMisc::PhysicalQuantities::CLength m_simulatorMaxRenderedDistance { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit() };
|
||||
BlackMisc::PhysicalQuantities::CLength m_simulatorMaxRenderedBoundary { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit() };
|
||||
|
||||
@@ -447,11 +447,12 @@ namespace BlackCore
|
||||
emit this->connectionStatusChanged(from, to);
|
||||
}
|
||||
|
||||
void CContextNetwork::ps_simulatorRenderRestrictionsChanged(bool restricted, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary)
|
||||
void CContextNetwork::ps_simulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary)
|
||||
{
|
||||
// mainly passing changed restrictions from simulator to network
|
||||
if (!m_airspace) { return; }
|
||||
if (!m_airspace->analyzer()) { return; }
|
||||
m_airspace->analyzer()->setSimulatorRenderRestrictionsChanged(restricted, maxAircraft, maxRenderedDistance, maxRenderedBoundary);
|
||||
m_airspace->analyzer()->setSimulatorRenderRestrictionsChanged(restricted, enabled, maxAircraft, maxRenderedDistance, maxRenderedBoundary);
|
||||
}
|
||||
|
||||
void CContextNetwork::ps_dataFileRead(int lines)
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace BlackCore
|
||||
|
||||
//! Render restrictions have been changed, used with analyzer
|
||||
//! \sa CAirspaceAnalyzer
|
||||
void ps_simulatorRenderRestrictionsChanged(bool restricted, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
void ps_simulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
|
||||
};
|
||||
} // ns
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace BlackCore
|
||||
void simulatorPluginChanged(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
//! Render restrictions have been changed
|
||||
void renderRestrictionsChanged(bool restricted, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
void renderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
|
||||
//! Installed aircraft models ready or changed
|
||||
void installedAircraftModelsChanged();
|
||||
|
||||
@@ -255,11 +255,7 @@ namespace BlackCore
|
||||
int CContextSimulator::getMaxRenderedAircraft() const
|
||||
{
|
||||
if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!m_simulatorPlugin) { return 0; }
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return m_simulatorPlugin->simulator->getMaxRenderedAircraft();
|
||||
}
|
||||
@@ -267,22 +263,18 @@ namespace BlackCore
|
||||
void CContextSimulator::setMaxRenderedAircraft(int number)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; }
|
||||
if (!m_simulatorPlugin) { return; }
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
m_simulatorPlugin->simulator->setMaxRenderedAircraft(number);
|
||||
|
||||
if (m_simulatorPlugin)
|
||||
{
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
m_simulatorPlugin->simulator->setMaxRenderedAircraft(number);
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::setMaxRenderedDistance(CLength &distance)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << distance; }
|
||||
if (m_simulatorPlugin)
|
||||
{
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
this->m_simulatorPlugin->simulator->setMaxRenderedDistance(distance);
|
||||
}
|
||||
if (!m_simulatorPlugin) { return; }
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
this->m_simulatorPlugin->simulator->setMaxRenderedDistance(distance);
|
||||
}
|
||||
|
||||
QString CContextSimulator::getRenderRestrictionText() const
|
||||
@@ -308,10 +300,7 @@ namespace BlackCore
|
||||
CLength CContextSimulator::getMaxRenderedDistance() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
return CLength(0, CLengthUnit::nullUnit());
|
||||
}
|
||||
if (!m_simulatorPlugin) { return CLength(0, CLengthUnit::nullUnit()); }
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return this->m_simulatorPlugin->simulator->getMaxRenderedDistance();
|
||||
}
|
||||
|
||||
@@ -101,15 +101,15 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::setMaxRenderedAircraft
|
||||
virtual void setMaxRenderedAircraft(int number) override;
|
||||
|
||||
//! \copydoc IContextSimulator::getMaxRenderedDistance
|
||||
virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::setMaxRenderedDistance
|
||||
virtual void setMaxRenderedDistance(BlackMisc::PhysicalQuantities::CLength &distance) override;
|
||||
|
||||
//! \copydoc IContextSimulator::getRenderRestrictionText
|
||||
virtual QString getRenderRestrictionText() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getMaxRenderedDistance
|
||||
virtual BlackMisc::PhysicalQuantities::CLength getMaxRenderedDistance() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getRenderedDistanceBoundary
|
||||
virtual BlackMisc::PhysicalQuantities::CLength getRenderedDistanceBoundary() const override;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BlackCore
|
||||
"modelMatchingCompleted", this, SIGNAL(modelMatchingCompleted(BlackMisc::Simulation::CSimulatedAircraft)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"renderRestrictionsChanged", this, SIGNAL(renderRestrictionsChanged(bool, int, BlackMisc::PhysicalQuantities::CLength, BlackMisc::PhysicalQuantities::CLength)));
|
||||
"renderRestrictionsChanged", this, SIGNAL(renderRestrictionsChanged(bool, bool, int, BlackMisc::PhysicalQuantities::CLength, BlackMisc::PhysicalQuantities::CLength)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(),
|
||||
"simulatorPluginChanged", this, SIGNAL(simulatorPluginChanged(BlackMisc::Simulation::CSimulatorPluginInfo)));
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace BlackCore
|
||||
void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft);
|
||||
|
||||
//! Render restrictions have been changed
|
||||
void renderRestrictionsChanged(bool restricted, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance, const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary);
|
||||
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);
|
||||
|
||||
@@ -157,7 +157,9 @@ namespace BlackCore
|
||||
if (maxRenderedAircraft == m_maxRenderedAircraft) { return; }
|
||||
if (maxRenderedAircraft < 1)
|
||||
{
|
||||
// disable, we set both values to 0
|
||||
m_maxRenderedAircraft = 0;
|
||||
m_maxRenderedDistance = CLength(0.0, CLengthUnit::NM());
|
||||
}
|
||||
else if (maxRenderedAircraft >= MaxAircraftInfinite)
|
||||
{
|
||||
@@ -169,7 +171,8 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
bool r = isRenderingRestricted();
|
||||
emit renderRestrictionsChanged(r, getMaxRenderedAircraft(), getMaxRenderedDistance(), getRenderedDistanceBoundary());
|
||||
bool e = isRenderingEnabled();
|
||||
emit renderRestrictionsChanged(r, e, getMaxRenderedAircraft(), getMaxRenderedDistance(), getRenderedDistanceBoundary());
|
||||
}
|
||||
|
||||
void CSimulatorCommon::setMaxRenderedDistance(CLength &distance)
|
||||
@@ -179,6 +182,12 @@ namespace BlackCore
|
||||
{
|
||||
m_maxRenderedDistance = CLength(0.0, CLengthUnit::nullUnit());
|
||||
}
|
||||
else if (distance.isZeroEpsilonConsidered())
|
||||
{
|
||||
// zero means disabled, we disable max aircraft too
|
||||
this->m_maxRenderedAircraft = 0;
|
||||
this->m_maxRenderedDistance = CLength(0.0, CLengthUnit::NM());
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT(!distance.isNegativeWithEpsilonConsidered());
|
||||
@@ -186,7 +195,8 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
bool r = isRenderingRestricted();
|
||||
emit renderRestrictionsChanged(r, getMaxRenderedAircraft(), getMaxRenderedDistance(), getRenderedDistanceBoundary());
|
||||
bool e = isRenderingEnabled();
|
||||
emit renderRestrictionsChanged(r, e, getMaxRenderedAircraft(), getMaxRenderedDistance(), getRenderedDistanceBoundary());
|
||||
}
|
||||
|
||||
CLength CSimulatorCommon::getMaxRenderedDistance() const
|
||||
@@ -273,7 +283,7 @@ namespace BlackCore
|
||||
{
|
||||
this->m_maxRenderedDistance = CLength(0, CLengthUnit::nullUnit());
|
||||
this->m_maxRenderedAircraft = MaxAircraftInfinite;
|
||||
emit renderRestrictionsChanged(false, getMaxRenderedAircraft(), getMaxRenderedDistance(), getRenderedDistanceBoundary());
|
||||
emit renderRestrictionsChanged(false, true, getMaxRenderedAircraft(), getMaxRenderedDistance(), getRenderedDistanceBoundary());
|
||||
}
|
||||
|
||||
int CSimulatorCommon::physicallyRemoveMultipleRemoteAircraft(const CCallsignSet &callsigns)
|
||||
|
||||
Reference in New Issue
Block a user