[FSD] "dot" command to restrict max. range for FSD positions

Allows to limit the range in which we handle FSD positions
(This also means FSD planes range)
This commit is contained in:
Klaus Basan
2019-11-14 19:21:34 +01:00
committed by Mat Sutcliffe
parent 2adf169a0e
commit f6f719a67e
4 changed files with 107 additions and 48 deletions

View File

@@ -118,6 +118,9 @@ namespace BlackCore
// timer
connect(&m_processTimer, &QTimer::timeout, this, &CAirspaceMonitor::process);
m_processTimer.start(ProcessIntervalMs);
// dot command
CAirspaceMonitor::registerHelp();
}
bool CAirspaceMonitor::updateFastPositionEnabled(const CCallsign &callsign, bool enableFastPositonUpdates)
@@ -392,6 +395,28 @@ namespace BlackCore
return s.join(", ");
}
bool CAirspaceMonitor::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
{
Q_UNUSED(originator;)
if (commandLine.isEmpty()) { return false; }
static const QStringList cmds({ ".fsd" });
CSimpleCommandParser parser(cmds);
parser.parse(commandLine);
if (!parser.isKnownCommand()) { return false; }
if (parser.matchesCommand(".fsd"))
{
if (parser.countParts() < 2) { return false; }
if (parser.matchesPart(1, "range") && parser.countParts() > 2)
{
const QString r = parser.part(2);
CLength d;
d.parseFromString(r);
this->setMaxRange(d);
}
}
return false;
}
void CAirspaceMonitor::process()
{
if (this->isConnectedAndNotShuttingDown())
@@ -426,6 +451,19 @@ namespace BlackCore
return aircraft.size();
}
void CAirspaceMonitor::setMaxRange(const CLength &range)
{
int rInt = 125;
if (!range.isNull())
{
rInt = range.valueInteger(CLengthUnit::NM());
}
CLogMessage(this).info(u"Set airspace max. range to %1NM") << rInt;
m_maxDistanceNM = rInt;
m_maxDistanceNMHysteresis = qRound(rInt * 1.1);
}
void CAirspaceMonitor::onRealNameReplyReceived(const CCallsign &callsign, const QString &realname)
{
if (!this->isConnectedAndNotShuttingDown() || realname.isEmpty()) { return; }
@@ -1099,9 +1137,16 @@ namespace BlackCore
return c;
}
void CAirspaceMonitor::copilotDetected()
bool CAirspaceMonitor::handleMaxRange(const CAircraftSituation &situation)
{
// for future usage
if (situation.isNull()) { return false; }
const int distanceNM = this->getOwnAircraft().calculateGreatCircleDistance(situation).valueInteger(CLengthUnit::NM());
if (distanceNM > m_maxDistanceNMHysteresis)
{
this->removeAircraft(situation.getCallsign());
return false;
}
return distanceNM <= m_maxDistanceNM;
}
bool CAirspaceMonitor::recallFsInnPacket(const CCallsign &callsign)
@@ -1144,9 +1189,6 @@ namespace BlackCore
void CAirspaceMonitor::onAircraftUpdateReceived(const CAircraftSituation &situation, const CTransponder &transponder)
{
static constexpr int MaxDistanceNM = 125;
static constexpr int MaxDistanceNMHysteresis = qRound(1.1 * MaxDistanceNM);
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread");
if (!this->isConnectedAndNotShuttingDown()) { return; }
@@ -1156,14 +1198,8 @@ namespace BlackCore
if (this->isCopilotAircraft(callsign)) { return; }
const bool existsInRange = this->isAircraftInRange(callsign);
// hardcoded range (FSD overload issue)
const int distanceNM = this->getOwnAircraft().calculateGreatCircleDistance(situation).valueInteger(CLengthUnit::NM());
if (existsInRange && distanceNM > MaxDistanceNMHysteresis)
{
this->removeClient(callsign);
return;
}
if (distanceNM > MaxDistanceNM) { return; }
// range (FSD overload issue)
if (!this->handleMaxRange(situation)) { return; }
// update client info
this->autoAdjustCientGndCapability(situation);
@@ -1208,7 +1244,8 @@ namespace BlackCore
// checks
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "Empty callsign");
if (isCopilotAircraft(callsign)) { return; }
if (isCopilotAircraft(callsign)) { return; }
if (!this->isAircraftInRange(callsign)) { return; }
if (CBuildConfig::isLocalDeveloperDebugBuild())
{
@@ -1231,9 +1268,6 @@ namespace BlackCore
// store situation history
this->storeAircraftSituation(interimSituation);
// if we have no aircraft in range yet, we stop here
if (!this->isAircraftInRange(callsign)) { return; }
const bool samePosition = lastSituation.equalNormalVectorDouble(interimSituation);
if (samePosition) { return; } // nothing to update
@@ -1334,7 +1368,7 @@ namespace BlackCore
if (oldSituations.size() > 1)
{
const bool extrapolated = correctedSituation.extrapolateElevation(oldSituations[0], oldSituations[1], oldChanges.frontOrDefault());
Q_UNUSED(extrapolated);
Q_UNUSED(extrapolated)
}
}
} // gnd. elevation

View File

@@ -14,9 +14,6 @@
#include "blackcore/blackcoreexport.h"
#include "blackmisc/simulation/settings/modelmatchersettings.h"
#include "blackmisc/simulation/aircraftmodelsetprovider.h"
#include "blackmisc/network/server.h"
#include "blackmisc/network/ecosystem.h"
#include "blackmisc/network/connectionstatus.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
#include "blackmisc/simulation/matchinglog.h"
@@ -24,18 +21,22 @@
#include "blackmisc/simulation/remoteaircraftprovider.h"
#include "blackmisc/simulation/simulationenvironmentprovider.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/network/server.h"
#include "blackmisc/network/ecosystem.h"
#include "blackmisc/network/connectionstatus.h"
#include "blackmisc/network/clientprovider.h"
#include "blackmisc/network/userlist.h"
#include "blackmisc/geo/coordinategeodetic.h"
#include "blackmisc/aviation/aircraftpartslist.h"
#include "blackmisc/aviation/aircraftsituationlist.h"
#include "blackmisc/aviation/atcstation.h"
#include "blackmisc/aviation/atcstationlist.h"
#include "blackmisc/aviation/callsignset.h"
#include "blackmisc/aviation/flightplan.h"
#include "blackmisc/geo/coordinategeodetic.h"
#include "blackmisc/pq/frequency.h"
#include "blackmisc/pq/length.h"
#include "blackmisc/pq/angle.h"
#include "blackmisc/simplecommandparser.h"
#include "blackmisc/identifier.h"
#include <QJsonObject>
@@ -52,10 +53,7 @@
namespace BlackCore
{
namespace Fsd
{
class CFSDClient;
}
namespace Fsd { class CFSDClient; }
class CAirspaceAnalyzer;
//! Keeps track of other entities in the airspace: aircraft, ATC stations, etc.
@@ -145,6 +143,9 @@ namespace BlackCore
//! Re-init all aircrft
int reInitializeAllAircraft();
//! Max (FSD) range
void setMaxRange(const BlackMisc::PhysicalQuantities::CLength &range);
//! Create dummy entries for performance tests
//! \private for testing purposes
void testCreateDummyOnlineAtcStations(int number);
@@ -171,6 +172,22 @@ namespace BlackCore
static QString enumToString(MatchingReadiness r);
//! @}
//! \addtogroup swiftdotcommands
//! @{
//! <pre>
//! .fsd range distance max.range e.g. ".fsd range 100NM"
//! </pre>
//! @}
//! \copydoc BlackCore::Context::IContextNetwork::parseCommandLine
bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator);
//! Register help
static void registerHelp()
{
if (BlackMisc::CSimpleCommandParser::registered("BlackCore::Fsd::CFSDClient")) { return; }
BlackMisc::CSimpleCommandParser::registerCommand({".fsd range distance", "FSD max. range"});
}
signals:
//! Online ATC stations were changed
void changedAtcStationsOnline();
@@ -271,11 +288,18 @@ namespace BlackCore
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TModelMatching> m_matchingSettings { this }; //!< settings
QQueue<BlackMisc::Aviation::CCallsign> m_queryAtis; //!< query the ATIS
QQueue<BlackMisc::Aviation::CCallsign> m_queryPilot; //!< query the pilot data
Fsd::CFSDClient *m_fsdClient = nullptr; //!< corresponding network interface
CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer
bool m_bookingsRequested = false; //!< bookings have been requested, it can happen we receive an BlackCore::Vatsim::CVatsimBookingReader::atcBookingsReadUnchanged signal
QTimer m_processTimer;
Fsd::CFSDClient *m_fsdClient = nullptr; //!< corresponding network interface
CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer
bool m_bookingsRequested = false; //!< bookings have been requested, it can happen we receive an BlackCore::Vatsim::CVatsimBookingReader::atcBookingsReadUnchanged signal
int m_maxDistanceNM = 125; //!< position range / FSD range
int m_maxDistanceNMHysteresis = qRound(1.1 * m_maxDistanceNM);
// Processing interval
static constexpr int ProcessIntervalMs = 50; // in ms
QTimer m_processTimer;
//! Processing by timer
void process();
// model matching times
static constexpr qint64 MMCheckAgainMs = 2000;
@@ -283,9 +307,6 @@ namespace BlackCore
static constexpr qint64 MMMaxAgeThresholdMs = MMCheckAgainMs * 10;
static constexpr qint64 MMVerifyMs = MMCheckAgainMs * 12;
//! Processing by timer
void process();
//! Remove ATC online stations
void removeAllOnlineAtcStations();
@@ -356,8 +377,8 @@ namespace BlackCore
//! Update booked station by callsign
int updateBookedStation(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::CPropertyIndexVariantMap &vm, bool skipEqualValues = true, bool sendSignal = true);
//! Co-pilot detected
void copilotDetected();
//! Handle max.range
bool handleMaxRange(const BlackMisc::Aviation::CAircraftSituation &situation);
//! Call CAirspaceMonitor::onCustomFSInnPacketReceived with stored packet
bool recallFsInnPacket(const BlackMisc::Aviation::CCallsign &callsign);

View File

@@ -314,7 +314,7 @@ namespace BlackCore
{
Q_UNUSED(originator;)
if (commandLine.isEmpty()) { return false; }
static const QStringList cmds({ ".msg", ".m", ".chat", ".altos", ".altoffset", ".addtimeos", ".addtimeoffset", ".wallop", ".watchdog", ".reinit", ".reinitialize", ".enable", ".disable", ".ignore", ".unignore" });
static const QStringList cmds({ ".msg", ".m", ".chat", ".altos", ".altoffset", ".addtimeos", ".addtimeoffset", ".wallop", ".watchdog", ".reinit", ".reinitialize", ".enable", ".disable", ".ignore", ".unignore", ".fsd" });
CSimpleCommandParser parser(cmds);
parser.parse(commandLine);
if (!parser.isKnownCommand()) { return false; }
@@ -470,8 +470,8 @@ namespace BlackCore
else if (parser.matchesCommand(".wallop"))
{
if (parser.countParts() < 2) { return false; }
if (!m_fsdClient) { return false; }
if (!this->isConnected()) { return false; }
if (!m_fsdClient) { return false; }
if (!this->isConnected()) { return false; }
const QString wallopMsg = parser.part(1).simplified().trimmed();
m_fsdClient->sendTextMessage(TextMessageGroups::AllSups, wallopMsg);
return true;
@@ -479,19 +479,23 @@ namespace BlackCore
else if (parser.matchesCommand(".enable", ".unignore"))
{
if (parser.countParts() < 2) { return false; }
if (!m_fsdClient) { return false; }
if (!this->isConnected()) { return false; }
if (!m_fsdClient) { return false; }
if (!this->isConnected()) { return false; }
const CCallsign cs(parser.part(1));
if (cs.isValid()) { this->updateAircraftEnabled(cs, true); }
}
else if (parser.matchesCommand(".disable", ".ignore"))
{
if (parser.countParts() < 2) { return false; }
if (!m_fsdClient) { return false; }
if (!this->isConnected()) { return false; }
if (!m_fsdClient) { return false; }
if (!this->isConnected()) { return false; }
const CCallsign cs(parser.part(1));
if (cs.isValid()) { this->updateAircraftEnabled(cs, false); }
}
else if (m_airspace && parser.matchesCommand(".fsd"))
{
return m_airspace->parseCommandLine(commandLine, originator);
}
return false;
}

View File

@@ -219,12 +219,12 @@ namespace BlackCore
//! \addtogroup swiftdotcommands
//! @{
//! <pre>
//! .m .msg .chat message text
//! .altos .altoffset altitude offset for testing
//! .addtimeos .addtimeoffse additional offset time for testing
//! .reinit .reinitialize re-initialize all aircraft
//! .watchdog on|off watchdog on/off
//! .wallop message send wallop message
//! .m .msg .chat callsign|freq. message message text
//! .altos .altoffset altitude offset for testing
//! .addtimeos .addtimeoffset additional offset time for testing
//! .reinit .reinitialize re-initialize all aircraft
//! .watchdog on|off watchdog on/off
//! .wallop message send wallop message
//! </pre>
//! @}
//! \copydoc IContextNetwork::parseCommandLine