Ref T335, improved CSimConnectObject

- support for outdated objects
- count exceptions/directly removed incidents
This commit is contained in:
Klaus Basan
2018-09-12 16:27:58 +02:00
parent c43b51056b
commit 3ee17120b7
2 changed files with 142 additions and 12 deletions

View File

@@ -111,6 +111,7 @@ namespace BlackSimPlugin
{ {
if (!this->isPendingAdded()) { return false; } if (!this->isPendingAdded()) { return false; }
if (currentMsSinceEpoch < 0) { currentMsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); } if (currentMsSinceEpoch < 0) { currentMsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); }
if (m_tsCreated < 0) { return true; } // no valid timestamp
const qint64 delta = currentMsSinceEpoch - m_tsCreated; const qint64 delta = currentMsSinceEpoch - m_tsCreated;
return delta > thresholdMs; return delta > thresholdMs;
} }
@@ -173,18 +174,31 @@ namespace BlackSimPlugin
m_lightsAsSent = CAircraftLights(); m_lightsAsSent = CAircraftLights();
m_requestId = 0; m_requestId = 0;
m_objectId = 0; m_objectId = 0;
m_lightsRequestedAt = -1; m_addingExceptions = 0;
m_validRequestId = false; m_validRequestId = false;
m_validObjectId = false; m_validObjectId = false;
m_tsCreated = QDateTime::currentMSecsSinceEpoch(); m_tsCreated = -1;
this->resetCameraPositions(); this->resetCameraPositions();
} }
void CSimConnectObject::resetToAddAgain()
{
const CSimConnectObject old(*this);
this->resetState();
this->copyAddingFailureCounters(old);
}
bool CSimConnectObject::hasValidRequestAndObjectId() const bool CSimConnectObject::hasValidRequestAndObjectId() const
{ {
return this->hasValidRequestId() && this->hasValidObjectId(); return this->hasValidRequestId() && this->hasValidObjectId();
} }
void CSimConnectObject::copyAddingFailureCounters(const CSimConnectObject &otherObject)
{
m_addingExceptions = otherObject.m_addingExceptions;
m_addingDirectlyRemoved = otherObject.m_addingDirectlyRemoved;
}
QString CSimConnectObject::getInterpolatorInfo(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const QString CSimConnectObject::getInterpolatorInfo(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
{ {
Q_ASSERT(m_interpolator); Q_ASSERT(m_interpolator);
@@ -211,8 +225,13 @@ namespace BlackSimPlugin
QString CSimConnectObject::toQString() const QString CSimConnectObject::toQString() const
{ {
static const QString s("CS: '%1' obj: %2 req: %3 conf.added: %4 pend.rem.: %5 rwa: %6 awr: %7"); static const QString s("CS: '%1' obj: %2 req: %3 conf.added: %4 pend.rem.: %5 rwa: %6 awr: %7 aEx: %8 aRem: %9");
return s.arg(this->getCallsign().asString()).arg(m_objectId).arg(m_requestId).arg(boolToYesNo(m_confirmedAdded), boolToYesNo(m_pendingRemoved), boolToYesNo(m_removedWhileAdding), boolToYesNo(m_addedWhileRemoving)); return s.arg(this->getCallsign().asString()). arg(m_objectId).arg(m_requestId).arg(boolToYesNo(m_confirmedAdded), boolToYesNo(m_pendingRemoved), boolToYesNo(m_removedWhileAdding), boolToYesNo(m_addedWhileRemoving)).arg(m_addingExceptions).arg(m_addingDirectlyRemoved);
}
CStatusMessageList CSimConnectObject::addingVerificationMessages()
{
return this->getAircraftModel().verifyModelData();
} }
CSimConnectObject::SimObjectType CSimConnectObject::requestIdToType(DWORD requestId) CSimConnectObject::SimObjectType CSimConnectObject::requestIdToType(DWORD requestId)
@@ -237,6 +256,22 @@ namespace BlackSimPlugin
return u; return u;
} }
bool CSimConnectObjects::insert(const CSimConnectObject &simObject, bool updateTimestamp)
{
if (!simObject.hasCallsign()) { return false; }
if (updateTimestamp)
{
CSimConnectObject simObj(simObject);
simObj.resetTimestampToNow();
(*this)[simObj.getCallsign()] = simObj;
}
else
{
(*this)[simObject.getCallsign()] = simObject;
}
return true;
}
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId) bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId)
{ {
// First check, if this request id belongs to us // First check, if this request id belongs to us
@@ -264,9 +299,9 @@ namespace BlackSimPlugin
return callsigns; return callsigns;
} }
QStringList CSimConnectObjects::getAllCallsignStrings(bool sorted) const QStringList CSimConnectObjects::getAllCallsignStrings(bool sorted, bool withoutProbes) const
{ {
return this->getAllCallsigns().getCallsignStrings(sorted); return this->getAllCallsigns(withoutProbes).getCallsignStrings(sorted);
} }
QString CSimConnectObjects::getAllCallsignStringsAsString(bool sorted, const QString &separator) const QString CSimConnectObjects::getAllCallsignStringsAsString(bool sorted, const QString &separator) const
@@ -295,6 +330,20 @@ namespace BlackSimPlugin
return CSimConnectObject(); return CSimConnectObject();
} }
CSimConnectObject CSimConnectObjects::getOldestObject() const
{
CSimConnectObject oldestSimObj = *this->begin();
for (const CSimConnectObject &simObj : this->values())
{
if (!simObj.hasCreatedTimestamp()) { continue; }
if (!oldestSimObj.hasCreatedTimestamp() || oldestSimObj.getCreatedTimestamp() > simObj.getCreatedTimestamp())
{
oldestSimObj = simObj;
}
}
return oldestSimObj;
}
CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : this->values())
@@ -441,5 +490,36 @@ namespace BlackSimPlugin
} }
return false; return false;
} }
int CSimConnectObjects::removeCallsigns(const CCallsignSet &callsigns)
{
int c = 0;
for (const CCallsign &cs : callsigns)
{
c += this->remove(cs);
}
return c;
}
CSimConnectObjects CSimConnectObjects::removeOutdatedPendingAdded(CSimConnectObject::SimObjectType type)
{
CCallsignSet removeCallsigns;
CSimConnectObjects removedObjects;
const qint64 ts = QDateTime::currentMSecsSinceEpoch();
for (const CSimConnectObject &simObject : this->values())
{
// verification takes at least a second, so we need some time before outdating
if (type != CSimConnectObject::AllTypes && simObject.getType() != type) { continue; }
if (!simObject.isOutdatedPendingAdded(5000, ts)) { continue; }
removedObjects.insert(simObject);
removeCallsigns.insert(simObject.getCallsign());
}
if (!removeCallsigns.isEmpty())
{
this->removeCallsigns(removeCallsigns);
}
return removedObjects;
}
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -31,7 +31,8 @@ namespace BlackSimPlugin
enum SimObjectType enum SimObjectType
{ {
Aircraft, Aircraft,
TerrainProbe TerrainProbe,
AllTypes
}; };
//! Constructor //! Constructor
@@ -59,6 +60,9 @@ namespace BlackSimPlugin
//! Simulated aircraft (as added) //! Simulated aircraft (as added)
const BlackMisc::Simulation::CSimulatedAircraft &getAircraft() const { return m_aircraft; } const BlackMisc::Simulation::CSimulatedAircraft &getAircraft() const { return m_aircraft; }
//! Simulated aircraft model
const BlackMisc::Simulation::CAircraftModel &getAircraftModel() const { return m_aircraft.getModel(); }
//! Simulated aircraft model string //! Simulated aircraft model string
const QString &getAircraftModelString() const { return m_aircraft.getModelString(); } const QString &getAircraftModelString() const { return m_aircraft.getModelString(); }
@@ -135,7 +139,7 @@ namespace BlackSimPlugin
bool isPendingAdded() const; bool isPendingAdded() const;
//! Still pending //! Still pending
bool isOutdatedPendingAdded(qint64 thresholdMs = 2000, qint64 currentMsSinceEpoch = -1) const; bool isOutdatedPendingAdded(qint64 thresholdMs = 5000, qint64 currentMsSinceEpoch = -1) const;
//! Adding is confirmed //! Adding is confirmed
bool isConfirmedAdded() const; bool isConfirmedAdded() const;
@@ -184,8 +188,11 @@ namespace BlackSimPlugin
//! Reset the state (like it was a new onject) without affecting interpolator and aircraft //! Reset the state (like it was a new onject) without affecting interpolator and aircraft
void resetState(); void resetState();
//! Reset so it can be added again
void resetToAddAgain();
//! Reset the timestamp //! Reset the timestamp
void resetTimestamp() { m_tsCreated = QDateTime::currentMSecsSinceEpoch(); } void resetTimestampToNow() { m_tsCreated = QDateTime::currentMSecsSinceEpoch(); }
//! VTOL? //! VTOL?
bool isVtol() const { return m_aircraft.isVtol(); } bool isVtol() const { return m_aircraft.isVtol(); }
@@ -196,12 +203,39 @@ namespace BlackSimPlugin
//! Invalid? //! Invalid?
bool isInvalid() const { return !this->hasValidObjectId() && !this->hasValidRequestId(); } bool isInvalid() const { return !this->hasValidObjectId() && !this->hasValidRequestId(); }
//! Created timestamp?
bool hasCreatedTimestamp() const { return m_tsCreated >= 0; }
//! Created timestamp
qint64 getCreatedTimestamp() const { return m_tsCreated; }
//! Engine count //! Engine count
int getEngineCount() const { return m_aircraft.getEnginesCount(); } int getEngineCount() const { return m_aircraft.getEnginesCount(); }
//! Was the object really added to simulator //! Was the object really added to simulator
bool hasValidRequestAndObjectId() const; bool hasValidRequestAndObjectId() const;
//! Adding has been failed before
int getAddingExceptions() const { return m_addingExceptions; }
//! Set adding failed before
void setAddingExceptions(int number) { m_addingExceptions = number; }
//! Increase adding exception
void increaseAddingExceptions() { m_addingExceptions++; }
//! Adding and directly removed
int getAddingDirectlyRemoved() const { return m_addingDirectlyRemoved; }
//! Set adding and directly removed
void setAddingDirectlyRemoved(int number) { m_addingDirectlyRemoved = number; }
//! Increase adding and directly removed
void increaseAddingDirectlyRemoved() { m_addingDirectlyRemoved++; }
//! Copy the counters from another object
void copyAddingFailureCounters(const CSimConnectObject &otherObject);
//! Callsign as LATIN1 //! Callsign as LATIN1
const QByteArray &getCallsignByteArray() const { return m_callsignByteArray; } const QByteArray &getCallsignByteArray() const { return m_callsignByteArray; }
@@ -223,6 +257,9 @@ namespace BlackSimPlugin
//! SimObject as string //! SimObject as string
QString toQString() const; QString toQString() const;
//! Verification message when adding failed
BlackMisc::CStatusMessageList addingVerificationMessages();
//! Type of id //! Type of id
static SimObjectType requestIdToType(DWORD requestId); static SimObjectType requestIdToType(DWORD requestId);
@@ -241,8 +278,9 @@ namespace BlackSimPlugin
bool m_camera = false; bool m_camera = false;
bool m_removedWhileAdding = false; bool m_removedWhileAdding = false;
bool m_addedWhileRemoving = false; bool m_addedWhileRemoving = false;
int m_lightsRequestedAt = -1; int m_addingExceptions = 0; //!< exception when added
qint64 m_tsCreated = -1; int m_addingDirectlyRemoved = 0; //!< added, but removed directly afterwards
qint64 m_tsCreated = -1;
GUID m_cameraGuid; GUID m_cameraGuid;
SIMCONNECT_DATA_XYZ m_cameraPosition; SIMCONNECT_DATA_XYZ m_cameraPosition;
SIMCONNECT_DATA_PBH m_cameraRotation; SIMCONNECT_DATA_PBH m_cameraRotation;
@@ -257,6 +295,9 @@ namespace BlackSimPlugin
class CSimConnectObjects : public QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> class CSimConnectObjects : public QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject>
{ {
public: public:
//! Insert
bool insert(const CSimConnectObject &simObject, bool updateTimestamp = false);
//! Set ID of a SimConnect object, so far we only have an request id in the object //! Set ID of a SimConnect object, so far we only have an request id in the object
bool setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId); bool setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId);
@@ -275,6 +316,9 @@ namespace BlackSimPlugin
//! Mark as added if existing //! Mark as added if existing
CSimConnectObject markObjectAsAdded(DWORD objectId); CSimConnectObject markObjectAsAdded(DWORD objectId);
//! Get the oldest object
CSimConnectObject getOldestObject() const;
//! Is the object id one of our AI objects? //! Is the object id one of our AI objects?
bool isKnownSimObjectId(DWORD objectId) const; bool isKnownSimObjectId(DWORD objectId) const;
@@ -287,6 +331,12 @@ namespace BlackSimPlugin
//! Remove all the probes //! Remove all the probes
int removeAllProbes(); int removeAllProbes();
//! Remove callsigns
int removeCallsigns(const BlackMisc::Aviation::CCallsignSet &callsigns);
//! Remove all pending added objects
CSimConnectObjects removeOutdatedPendingAdded(CSimConnectObject::SimObjectType type);
//! Pending add condition //! Pending add condition
bool containsPendingAdded() const; bool containsPendingAdded() const;
@@ -306,7 +356,7 @@ namespace BlackSimPlugin
BlackMisc::Aviation::CCallsignSet getAllCallsigns(bool withoutProbes = true) const; BlackMisc::Aviation::CCallsignSet getAllCallsigns(bool withoutProbes = true) const;
//! Get all callsign strings //! Get all callsign strings
QStringList getAllCallsignStrings(bool sorted = false) const; QStringList getAllCallsignStrings(bool sorted = false, bool withoutProbes = true) const;
//! Get all callsign strings as string //! Get all callsign strings as string
QString getAllCallsignStringsAsString(bool sorted = false, const QString &separator = ", ") const; QString getAllCallsignStringsAsString(bool sorted = false, const QString &separator = ", ") const;