mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T232, aircraft can be re-added or removed via "dot-commands"
* can be used for testing * utility functions to find inconsistent aircraft states * reset highlight state
This commit is contained in:
@@ -107,6 +107,17 @@ namespace BlackCore
|
||||
//! it will physically added to the simulator.
|
||||
virtual bool logicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0;
|
||||
|
||||
//! Removes and adds again the aircraft
|
||||
//! \sa logicallyRemoveRemoteAircraft
|
||||
//! \sa logicallyAddRemoteAircraft
|
||||
virtual bool logicallyReAddRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0;
|
||||
|
||||
//! Find the unrendered enabled aircraft
|
||||
virtual BlackMisc::Aviation::CCallsignSet unrenderedEnabledAircraft() const = 0;
|
||||
|
||||
//! Find the rendered disabled aircraft
|
||||
virtual BlackMisc::Aviation::CCallsignSet renderedDisabledAircraft() const = 0;
|
||||
|
||||
//! Change remote aircraft per property
|
||||
virtual bool changeRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) = 0;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QStringBuilder>
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
@@ -161,16 +162,7 @@ namespace BlackCore
|
||||
}
|
||||
else
|
||||
{
|
||||
// restore
|
||||
for (const CSimulatedAircraft &aircraft : as_const(m_highlightedAircraft))
|
||||
{
|
||||
// get the current state for this aircraft
|
||||
// it might has been removed in the meantime
|
||||
const CCallsign cs(aircraft.getCallsign());
|
||||
this->resetAircraftFromProvider(cs);
|
||||
}
|
||||
m_highlightedAircraft.clear();
|
||||
m_highlightEndTimeMsEpoch = 0;
|
||||
this->stopHighlighting();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,6 +331,45 @@ namespace BlackCore
|
||||
return (!sApp || sApp->isShuttingDown());
|
||||
}
|
||||
|
||||
bool CSimulatorCommon::logicallyReAddRemoteAircraft(const CCallsign &callsign)
|
||||
{
|
||||
if (this->isShuttingDown()) { return false; }
|
||||
if (callsign.isEmpty()) { return false; }
|
||||
this->stopHighlighting();
|
||||
this->logicallyRemoveRemoteAircraft(callsign);
|
||||
if (!this->isAircraftInRange(callsign)) { return false; }
|
||||
QTimer::singleShot(2500, this, [ = ]
|
||||
{
|
||||
if (this->isShuttingDown()) { return; }
|
||||
if (!this->isAircraftInRange(callsign)) { return; }
|
||||
const CSimulatedAircraft aircraft = this->getAircraftInRangeForCallsign(callsign);
|
||||
if (aircraft.isEnabled() && aircraft.hasModelString())
|
||||
{
|
||||
this->logicallyAddRemoteAircraft(aircraft);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
CCallsignSet CSimulatorCommon::unrenderedEnabledAircraft() const
|
||||
{
|
||||
const CSimulatedAircraftList aircraft = this->getAircraftInRange().findByEnabled(true);
|
||||
if (aircraft.isEmpty()) { return CCallsignSet(); }
|
||||
CCallsignSet enabledOnes = aircraft.getCallsigns();
|
||||
const CCallsignSet renderedOnes = this->physicallyRenderedAircraft();
|
||||
enabledOnes.remove(renderedOnes);
|
||||
return enabledOnes;
|
||||
}
|
||||
|
||||
CCallsignSet CSimulatorCommon::renderedDisabledAircraft() const
|
||||
{
|
||||
const CSimulatedAircraftList aircraft = this->getAircraftInRange().findByEnabled(false);
|
||||
if (aircraft.isEmpty()) { return CCallsignSet(); }
|
||||
const CCallsignSet disabledOnes = aircraft.getCallsigns();
|
||||
const CCallsignSet renderedOnes = this->physicallyRenderedAircraft();
|
||||
return renderedOnes.intersection(disabledOnes);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::setInterpolationAndRenderingSetup(const CInterpolationAndRenderingSetup &setup)
|
||||
{
|
||||
{
|
||||
@@ -373,6 +404,8 @@ namespace BlackCore
|
||||
|
||||
int CSimulatorCommon::physicallyRemoveMultipleRemoteAircraft(const CCallsignSet &callsigns)
|
||||
{
|
||||
if (callsigns.isEmpty()) { return 0; }
|
||||
this->stopHighlighting();
|
||||
int removed = 0;
|
||||
for (const CCallsign &callsign : callsigns)
|
||||
{
|
||||
@@ -501,6 +534,42 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parser.hasPart(2) && (part1.startsWith("aircraft") || part1.startsWith("ac")))
|
||||
{
|
||||
const QString part2 = parser.part(2).toLower();
|
||||
if (parser.hasPart(3) && (part2.startsWith("readd") || part2.startsWith("re-add")))
|
||||
{
|
||||
const QString cs = parser.part(3).toUpper();
|
||||
if (cs == "all")
|
||||
{
|
||||
this->physicallyRemoveAllRemoteAircraft();
|
||||
const CStatusMessageList msgs = this->debugVerifyStateAfterAllAircraftRemoved();
|
||||
this->clearAllRemoteAircraftData();
|
||||
if (!msgs.isEmpty()) { emit this->driverMessages(msgs); }
|
||||
const CSimulatedAircraftList aircraft = this->getAircraftInRange();
|
||||
for (const CSimulatedAircraft a : aircraft)
|
||||
{
|
||||
if (a.isEnabled()) { this->logicallyAddRemoteAircraft(a); }
|
||||
}
|
||||
}
|
||||
else if (CCallsign::isValidAircraftCallsign(cs))
|
||||
{
|
||||
this->logicallyReAddRemoteAircraft(cs);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (parser.hasPart(3) && (part2.startsWith("rm") || part2.startsWith("remove")))
|
||||
{
|
||||
const QString cs = parser.part(3).toUpper();
|
||||
if (CCallsign::isValidAircraftCallsign(cs))
|
||||
{
|
||||
this->logicallyRemoveRemoteAircraft(cs);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// driver specific cmd line arguments
|
||||
return this->parseDetails(parser);
|
||||
}
|
||||
@@ -516,10 +585,16 @@ namespace BlackCore
|
||||
CSimpleCommandParser::registerCommand({".drv logint max number", "max.number of entries logged"});
|
||||
CSimpleCommandParser::registerCommand({".drv pos callsign", "show position for callsign"});
|
||||
CSimpleCommandParser::registerCommand({".drv spline|linear callsign", "set spline/linear interpolator for one/all callsign(s)"});
|
||||
CSimpleCommandParser::registerCommand({".drv aircraft readd callsign", "add again a given callsign"});
|
||||
CSimpleCommandParser::registerCommand({".drv aircraft readd all", "add again all aircraft"});
|
||||
CSimpleCommandParser::registerCommand({".drv aircraft rm callsign", "remove a given callsign"});
|
||||
}
|
||||
|
||||
void CSimulatorCommon::resetAircraftStatistics()
|
||||
{
|
||||
m_statsUpdateAircraftCountMs = 0;
|
||||
m_statsUpdateAircraftTimeAvgMs = 0;
|
||||
m_statsUpdateAircraftTimeTotalMs = 0;
|
||||
m_statsPhysicallyAddedAircraft = 0;
|
||||
m_statsPhysicallyRemovedAircraft = 0;
|
||||
m_statsPartsAdded = 0;
|
||||
@@ -610,20 +685,38 @@ namespace BlackCore
|
||||
|
||||
void CSimulatorCommon::reset()
|
||||
{
|
||||
m_statsUpdateAircraftCountMs = 0;
|
||||
m_statsUpdateAircraftTimeAvgMs = 0;
|
||||
m_statsUpdateAircraftTimeTotalMs = 0;
|
||||
this->clearAllRemoteAircraftData();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::resetHighlighting()
|
||||
{
|
||||
m_highlightedAircraft.clear();
|
||||
m_blinkCycle = false;
|
||||
m_highlightEndTimeMsEpoch = false;
|
||||
this->clearAllRemoteAircraftData();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::stopHighlighting()
|
||||
{
|
||||
// restore
|
||||
const CSimulatedAircraftList highlightedAircraft(m_highlightedAircraft);
|
||||
for (const CSimulatedAircraft &aircraft : highlightedAircraft)
|
||||
{
|
||||
// get the current state for this aircraft
|
||||
// it might has been removed in the meantime
|
||||
const CCallsign cs(aircraft.getCallsign());
|
||||
this->resetAircraftFromProvider(cs);
|
||||
}
|
||||
this->resetHighlighting();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::clearAllRemoteAircraftData()
|
||||
{
|
||||
// rendering related stuff
|
||||
m_addAgainAircraftWhenRemoved.clear();
|
||||
m_highlightedAircraft.clear();
|
||||
m_callsignsToBeRendered.clear();
|
||||
m_hints.clear();
|
||||
|
||||
this->resetHighlighting();
|
||||
this->resetAircraftStatistics();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,9 @@ namespace BlackCore
|
||||
virtual void setWeatherActivated(bool activated) override;
|
||||
virtual void unload() override;
|
||||
virtual bool isShuttingDown() const override;
|
||||
virtual bool logicallyReAddRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
virtual BlackMisc::Aviation::CCallsignSet unrenderedEnabledAircraft() const override;
|
||||
virtual BlackMisc::Aviation::CCallsignSet renderedDisabledAircraft() const override;
|
||||
virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override;
|
||||
virtual int physicallyRemoveAllRemoteAircraft() override;
|
||||
virtual void clearAllRemoteAircraftData() override;
|
||||
@@ -97,8 +100,11 @@ namespace BlackCore
|
||||
//! .drv logint off no log information for interpolator BlackCore::CSimulatorCommon
|
||||
//! .drv logint write write interpolator log to file BlackCore::CSimulatorCommon
|
||||
//! .drv logint clear clear current log BlackCore::CSimulatorCommon
|
||||
//! .drv pos callsign shows current position in simulator
|
||||
//! .drv pos callsign shows current position in simulator BlackCore::CSimulatorCommon
|
||||
//! .drv spline|linear callsign interpolator spline or linear BlackCore::CSimulatorCommon
|
||||
//! .drv aircraft readd callsign re-add (add again) aircraft BlackCore::CSimulatorCommon
|
||||
//! .drv aircraft readd all re-add all aircraft BlackCore::CSimulatorCommon
|
||||
//! .drv aircraft rm callsign remove aircraft BlackCore::CSimulatorCommon
|
||||
//! </pre>
|
||||
//! @}
|
||||
//! \copydoc ISimulator::parseCommandLine
|
||||
@@ -168,6 +174,12 @@ namespace BlackCore
|
||||
//! \sa ISimulator::clearAllRemoteAircraftData
|
||||
virtual void reset();
|
||||
|
||||
//! Reset highlighting
|
||||
void resetHighlighting();
|
||||
|
||||
//! Restore all highlighted aircraft
|
||||
void stopHighlighting();
|
||||
|
||||
//! Inject weather grid to simulator
|
||||
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) { Q_UNUSED(weatherGrid); }
|
||||
|
||||
@@ -210,8 +222,8 @@ namespace BlackCore
|
||||
//! Kill timer if id is valid
|
||||
void safeKillTimer();
|
||||
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
bool m_autoCalcAirportDistance = true; //!< automatically calculate airport distance and bearing
|
||||
bool m_pausedSimFreezesInterpolation = false; //!< paused simulator will also pause interpolation (so AI aircraft will hold)
|
||||
bool m_autoCalcAirportDistance = true; //!< automatically calculate airport distance and bearing
|
||||
int m_timerId = -1; //!< dispatch timer id
|
||||
int m_statsUpdateAircraftCountMs = 0; //!< statistics update count
|
||||
qint64 m_statsUpdateAircraftTimeTotalMs = 0; //!< statistics update time
|
||||
|
||||
@@ -206,6 +206,7 @@ namespace BlackSimPlugin
|
||||
|
||||
int CSimulatorFs9::physicallyRemoveAllRemoteAircraft()
|
||||
{
|
||||
resetHighlighting();
|
||||
if (m_hashFs9Clients.isEmpty()) { return 0; }
|
||||
QList<CCallsign> callsigns(m_hashFs9Clients.keys());
|
||||
int r = 0;
|
||||
|
||||
@@ -137,15 +137,9 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorFsCommon::changeRemoteAircraftEnabled(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
if (aircraft.isEnabled())
|
||||
{
|
||||
this->physicallyAddRemoteAircraft(aircraft);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->physicallyRemoveRemoteAircraft(aircraft.getCallsign());
|
||||
}
|
||||
return true;
|
||||
return aircraft.isEnabled() ?
|
||||
this->physicallyAddRemoteAircraft(aircraft) :
|
||||
this->physicallyRemoveRemoteAircraft(aircraft.getCallsign());
|
||||
}
|
||||
|
||||
void CSimulatorFsCommon::onSwiftDbAirportsRead()
|
||||
|
||||
@@ -968,6 +968,7 @@ namespace BlackSimPlugin
|
||||
{
|
||||
// make sure they are not added again
|
||||
// cleaning here is somewhat redundant, but double checks
|
||||
this->resetHighlighting();
|
||||
m_addPendingAircraft.clear();
|
||||
m_addAgainAircraftWhenRemoved.clear();
|
||||
|
||||
@@ -978,7 +979,6 @@ namespace BlackSimPlugin
|
||||
{
|
||||
if (this->physicallyRemoveRemoteAircraft(cs)) { r++; }
|
||||
}
|
||||
this->clearAllRemoteAircraftData();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -577,6 +577,7 @@ namespace BlackSimPlugin
|
||||
{
|
||||
Q_ASSERT(isConnected());
|
||||
//! \todo XP driver obtain number of removed aircraft
|
||||
resetHighlighting();
|
||||
int r = getAircraftInRangeCount();
|
||||
m_traffic->removeAllPlanes();
|
||||
updateMarkAllAsNotRendered();
|
||||
|
||||
Reference in New Issue
Block a user