mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #395, signatures for max.aircraft and max.range
(!) This in an intermediate step, the feature is not yet fully operational * max distance for rendering as simulator property * set max distance / aircraft from GUI As result of the latest meeting * changed CCallsignList to CCollection * fixed some warning with elevated compiler settings (e.g. removed qint values -> int)
This commit is contained in:
@@ -9,7 +9,9 @@
|
||||
|
||||
#include "simulator.h"
|
||||
#include "interpolator.h"
|
||||
#include "blackmisc/collection.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
@@ -23,7 +25,9 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
CSimulatorCommon::CSimulatorCommon(const BlackSim::CSimulatorInfo &simInfo, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent)
|
||||
: ISimulator(parent), COwnAircraftProviderSupport(ownAircraftProvider), CRemoteAircraftProviderSupport(remoteAircraftProvider), m_simulatorInfo(simInfo)
|
||||
: ISimulator(parent),
|
||||
COwnAircraftProviderSupport(ownAircraftProvider),
|
||||
CRemoteAircraftProviderSupport(remoteAircraftProvider), m_simulatorInfo(simInfo)
|
||||
{
|
||||
m_oneSecondTimer = new QTimer(this);
|
||||
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
|
||||
@@ -65,6 +69,27 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorCommon::recalculateRestrictedAircraft()
|
||||
{
|
||||
if (!isMaxAircraftRestricted()) { return; }
|
||||
if (!isRenderingEnabled()) { return; }
|
||||
|
||||
//! \todo Simulator, why is there no difference on CSequence?
|
||||
CSimulatedAircraftList newAircraftInRange(remoteAircraft().getClosestObjects(getMaxRenderedAircraft()));
|
||||
CCallsignList newAircraftCallsigns(newAircraftInRange.getCallsigns());
|
||||
CCallsignList toBeRemovedCallsigns(m_callsignsToBeRendered.difference(newAircraftCallsigns));
|
||||
CCallsignList toBeAddedCallsigns(newAircraftCallsigns.difference(m_callsignsToBeRendered));
|
||||
for (const CCallsign &cs : toBeRemovedCallsigns)
|
||||
{
|
||||
removeRemoteAircraft(cs);
|
||||
}
|
||||
for (const CCallsign &cs : toBeAddedCallsigns)
|
||||
{
|
||||
addRemoteAircraft(newAircraftInRange.findFirstByCallsign(cs));
|
||||
}
|
||||
this->m_callsignsToBeRendered = newAircraftCallsigns;
|
||||
}
|
||||
|
||||
void CSimulatorCommon::resetAircraftFromBacked(const CCallsign &callsign)
|
||||
{
|
||||
CSimulatedAircraft aircraft(this->remoteAircraft().findFirstByCallsign(callsign));
|
||||
@@ -101,13 +126,65 @@ namespace BlackCore
|
||||
|
||||
int CSimulatorCommon::getMaxRenderedAircraft() const
|
||||
{
|
||||
return m_maxRenderedAircraft;
|
||||
return (m_maxRenderedAircraft <= MaxAircraftInfinite) ? m_maxRenderedAircraft : MaxAircraftInfinite;
|
||||
}
|
||||
|
||||
void CSimulatorCommon::setMaxRenderedAircraft(int maxRenderedAircraft, const BlackMisc::Aviation::CCallsignList &callsigns)
|
||||
void CSimulatorCommon::setMaxRenderedAircraft(int maxRenderedAircraft)
|
||||
{
|
||||
m_maxRenderedAircraft = maxRenderedAircraft;
|
||||
m_callsignsToBeRendered = callsigns;
|
||||
if (maxRenderedAircraft == m_maxRenderedAircraft) { return; }
|
||||
if (maxRenderedAircraft < 1)
|
||||
{
|
||||
m_maxRenderedAircraft = 0;
|
||||
}
|
||||
else if (maxRenderedAircraft >= MaxAircraftInfinite)
|
||||
{
|
||||
m_maxRenderedAircraft = MaxAircraftInfinite;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_maxRenderedAircraft = maxRenderedAircraft;
|
||||
}
|
||||
|
||||
bool r = isRenderingRestricted();
|
||||
emit restrictedRenderingChanged(r);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::setMaxRenderedDistance(CLength &distance)
|
||||
{
|
||||
if (distance == m_maxRenderedDistance) { return; }
|
||||
if (distance.isNull() || distance >= getRenderedDistanceBoundary())
|
||||
{
|
||||
m_maxRenderedDistance = CLength(0.0, CLengthUnit::nullUnit());
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_ASSERT(distance.isPositiveWithEpsilonConsidered());
|
||||
m_maxRenderedDistance = distance;
|
||||
}
|
||||
|
||||
bool r = isRenderingRestricted();
|
||||
emit restrictedRenderingChanged(r);
|
||||
}
|
||||
|
||||
CLength CSimulatorCommon::getMaxRenderedDistance() const
|
||||
{
|
||||
if (m_maxRenderedDistance.isNull()) { return getRenderedDistanceBoundary(); }
|
||||
return m_maxRenderedDistance;
|
||||
}
|
||||
|
||||
CLength CSimulatorCommon::getRenderedDistanceBoundary() const
|
||||
{
|
||||
return CLength(20.0, CLengthUnit::NM());
|
||||
}
|
||||
|
||||
bool CSimulatorCommon::isMaxAircraftRestricted() const
|
||||
{
|
||||
return m_maxRenderedAircraft < MaxAircraftInfinite && isRenderingEnabled();
|
||||
}
|
||||
|
||||
bool CSimulatorCommon::isMaxDistanceRestricted() const
|
||||
{
|
||||
return !m_maxRenderedDistance.isNull();
|
||||
}
|
||||
|
||||
CSimulatorInfo CSimulatorCommon::getSimulatorInfo() const
|
||||
@@ -140,12 +217,35 @@ namespace BlackCore
|
||||
|
||||
bool CSimulatorCommon::isRenderingEnabled() const
|
||||
{
|
||||
return m_maxRenderedAircraft < 1;
|
||||
if (m_maxRenderedAircraft < 1) { return false; }
|
||||
if (!isMaxDistanceRestricted()) { return true; }
|
||||
|
||||
return m_maxRenderedDistance.valueRounded(CLengthUnit::NM(), 2) > 0.1;
|
||||
}
|
||||
|
||||
bool CSimulatorCommon::isRenderingRestricted() const
|
||||
{
|
||||
return this->isMaxDistanceRestricted() || this->isMaxAircraftRestricted();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::deleteAllRenderingRestrictions()
|
||||
{
|
||||
if (!isRenderingEnabled()) { return; }
|
||||
this->m_maxRenderedDistance = CLength(0, CLengthUnit::nullUnit());
|
||||
this->m_maxRenderedAircraft = MaxAircraftInfinite;
|
||||
emit restrictedRenderingChanged(false);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::ps_oneSecondTimer()
|
||||
{
|
||||
m_timerCounter++;
|
||||
blinkHighlightedAircraft();
|
||||
|
||||
// any <n> seconds
|
||||
if (m_timerCounter % 10 == 0)
|
||||
{
|
||||
recalculateRestrictedAircraft();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user