mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #395, prepared for snapshot handling
* logical / physical add/remote member functions in drivers, renamed functions * added access to snapshot * snapshot generation in analyzer * snapshot handling in driver * moved simulator base class in own files (.h/.cpp) * added functions as required to context
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e9f7810efc
commit
1c3bb8d463
@@ -10,6 +10,7 @@
|
||||
#include "airspaceaircraftsnapshot.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -18,20 +19,66 @@ namespace BlackMisc
|
||||
CAirspaceAircraftSnapshot::CAirspaceAircraftSnapshot()
|
||||
{ }
|
||||
|
||||
CAirspaceAircraftSnapshot::CAirspaceAircraftSnapshot(const CSimulatedAircraftList &allAircraft) :
|
||||
m_timestampMsSinceEpoch(QDateTime::currentMSecsSinceEpoch())
|
||||
CAirspaceAircraftSnapshot::CAirspaceAircraftSnapshot(
|
||||
const CSimulatedAircraftList &allAircraft,
|
||||
bool restricted, int maxAircraft, const CLength &maxRenderedDistance, const CLength &maxRenderedBoundary) :
|
||||
m_timestampMsSinceEpoch(QDateTime::currentMSecsSinceEpoch()),
|
||||
m_restricted(restricted)
|
||||
{
|
||||
if (!allAircraft.isEmpty())
|
||||
m_renderingEnabled = !restricted || (
|
||||
maxAircraft > 0 &&
|
||||
(maxRenderedBoundary.isNull() || maxRenderedBoundary.isPositiveWithEpsilonConsidered()) &&
|
||||
(maxRenderedDistance.isNull() || maxRenderedDistance.isPositiveWithEpsilonConsidered())
|
||||
);
|
||||
if (allAircraft.isEmpty()) { return; }
|
||||
|
||||
CSimulatedAircraftList aircraft(allAircraft);
|
||||
aircraft.sortByDistanceToOwnAircraft();
|
||||
CSimulatedAircraftList vtolAircraft(aircraft.findByVtol(true));
|
||||
m_aircraftCallsignsByDistance = aircraft.getCallsigns();
|
||||
m_vtolAircraftCallsignsByDistance = vtolAircraft.getCallsigns();
|
||||
|
||||
if (!restricted)
|
||||
{
|
||||
CSimulatedAircraftList aircraft(allAircraft);
|
||||
aircraft.sortByDistanceToOwnAircraft();
|
||||
CSimulatedAircraftList vtolAircraft(aircraft.findByVtol(true));
|
||||
m_aircraftCallsignsByDistance = aircraft.getCallsigns();
|
||||
m_enabledAircraftCallsignsByDistance = aircraft.findByEnabled(true).getCallsigns();
|
||||
m_disabledAircraftCallsignsByDistance = aircraft.findByEnabled(false).getCallsigns();
|
||||
m_vtolAircraftCallsignsByDistance = vtolAircraft.getCallsigns();
|
||||
m_enabledVtolAircraftCallsignsByDistance = vtolAircraft.findByEnabled(true).getCallsigns();
|
||||
}
|
||||
else
|
||||
{
|
||||
// if no rendering all aircraft are disabled
|
||||
if (!m_renderingEnabled)
|
||||
{
|
||||
m_disabledAircraftCallsignsByDistance = aircraft.getCallsigns();
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (const CSimulatedAircraft ¤tAircraft : aircraft)
|
||||
{
|
||||
CCallsign cs(currentAircraft.getCallsign());
|
||||
if (currentAircraft.isEnabled())
|
||||
{
|
||||
CLength distance(currentAircraft.getDistanceToOwnAircraft());
|
||||
if (count >= maxAircraft ||
|
||||
(!maxRenderedDistance.isNull() && distance >= maxRenderedBoundary) ||
|
||||
(!maxRenderedBoundary.isNull() && distance >= maxRenderedBoundary))
|
||||
{
|
||||
m_disabledAircraftCallsignsByDistance.push_back(cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
count++;
|
||||
m_enabledAircraftCallsignsByDistance.push_back(cs);
|
||||
if (currentAircraft.isVtol()) { m_enabledVtolAircraftCallsignsByDistance.push_back(cs); }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_disabledAircraftCallsignsByDistance.push_back(cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CAirspaceAircraftSnapshot::isValidSnapshot() const
|
||||
@@ -39,6 +86,18 @@ namespace BlackMisc
|
||||
return m_timestampMsSinceEpoch > 0;
|
||||
}
|
||||
|
||||
void CAirspaceAircraftSnapshot::setRestrictionChanged(const CAirspaceAircraftSnapshot &snapshot)
|
||||
{
|
||||
if (this->isValidSnapshot() == snapshot.isValidSnapshot())
|
||||
{
|
||||
this->m_restrictionChanged = (snapshot.m_restricted != this->m_restricted);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_restrictionChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
CVariant CAirspaceAircraftSnapshot::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toCVariant(); }
|
||||
|
||||
@@ -29,7 +29,13 @@ namespace BlackMisc
|
||||
CAirspaceAircraftSnapshot();
|
||||
|
||||
//! Constructor
|
||||
CAirspaceAircraftSnapshot(const BlackMisc::Simulation::CSimulatedAircraftList &allAircraft);
|
||||
CAirspaceAircraftSnapshot(
|
||||
const BlackMisc::Simulation::CSimulatedAircraftList &allAircraft,
|
||||
bool restricted = false,
|
||||
int maxAircraft = 100,
|
||||
const BlackMisc::PhysicalQuantities::CLength &maxRenderedDistance = BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()),
|
||||
const BlackMisc::PhysicalQuantities::CLength &maxRenderedBoundary = BlackMisc::PhysicalQuantities::CLength(0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit())
|
||||
);
|
||||
|
||||
//! Time when snapshot was taken
|
||||
const QDateTime getTimestamp() const { return QDateTime::fromMSecsSinceEpoch(m_timestampMsSinceEpoch); }
|
||||
@@ -52,6 +58,21 @@ namespace BlackMisc
|
||||
//! Valid snapshot?
|
||||
bool isValidSnapshot() const;
|
||||
|
||||
//! Restricted snapshot?
|
||||
bool isValidRestricted() const { return m_restricted; }
|
||||
|
||||
//! Did restriction change compared to last snapshot
|
||||
void setRestrictionChanged(const CAirspaceAircraftSnapshot &snapshot);
|
||||
|
||||
//! Did the restriction flag change?
|
||||
bool isRestrictionChanged() const { return m_restrictionChanged; }
|
||||
|
||||
//! Restricted values?
|
||||
bool isRestricted() const { return m_restricted; }
|
||||
|
||||
//! Rendering enabled or all aircraft disabled?
|
||||
bool isRenderingEnabled() const { return m_renderingEnabled; }
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
@@ -65,6 +86,9 @@ namespace BlackMisc
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CAirspaceAircraftSnapshot)
|
||||
qint64 m_timestampMsSinceEpoch = -1;
|
||||
bool m_restricted = false;
|
||||
bool m_restrictionChanged = false;
|
||||
bool m_renderingEnabled = true;
|
||||
|
||||
// remark closest aircraft always first
|
||||
BlackMisc::Aviation::CCallsignSet m_aircraftCallsignsByDistance;
|
||||
|
||||
Reference in New Issue
Block a user