Ref T335, improved probe support for CSimConnectObject/CSimConnectObjects. We will no longer use 2 separate object lists for probes/aircraft.

This commit is contained in:
Klaus Basan
2018-09-06 23:38:54 +02:00
parent 24deffca74
commit 2020c04f52
2 changed files with 102 additions and 9 deletions

View File

@@ -43,6 +43,7 @@ namespace BlackSimPlugin
m_interpolator(QSharedPointer<CInterpolatorMulti>::create(aircraft.getCallsign(), simEnvProvider, setupProvider, remoteAircraftProvider, logger))
{
this->resetCameraPositions();
m_type = aircraft.isTerrainProbe() ? TerrainProbe : Aircraft;
m_interpolator->initCorrespondingModel(aircraft.getModel());
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
}
@@ -106,6 +107,14 @@ namespace BlackSimPlugin
return !this->hasValidRequestAndObjectId() || !m_confirmedAdded;
}
bool CSimConnectObject::isOutdatedPendingAdded(qint64 thresholdMs, qint64 currentMsSinceEpoch) const
{
if (!this->isPendingAdded()) { return false; }
if (currentMsSinceEpoch < 0) { currentMsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); }
const qint64 delta = currentMsSinceEpoch - m_tsCreated;
return delta > thresholdMs;
}
bool CSimConnectObject::isConfirmedAdded() const
{
Q_ASSERT_X(!m_confirmedAdded || this->hasValidRequestAndObjectId(), Q_FUNC_INFO, "confirmed but invalid ids");
@@ -120,7 +129,7 @@ namespace BlackSimPlugin
m_aircraft.setRendered(true);
}
void CSimConnectObject::setAddedWhileRemoved(bool addedWileRemoved)
void CSimConnectObject::setAddedWhileRemoving(bool addedWileRemoved)
{
m_addedWhileRemoving = addedWileRemoved;
}
@@ -167,6 +176,7 @@ namespace BlackSimPlugin
m_lightsRequestedAt = -1;
m_validRequestId = false;
m_validObjectId = false;
m_tsCreated = QDateTime::currentMSecsSinceEpoch();
this->resetCameraPositions();
}
@@ -243,9 +253,15 @@ namespace BlackSimPlugin
return this->getSimObjectForObjectId(objectId).getCallsign();
}
CCallsignSet CSimConnectObjects::getAllCallsigns() const
CCallsignSet CSimConnectObjects::getAllCallsigns(bool withoutProbes) const
{
return CCallsignSet(this->keys());
if (!withoutProbes) { return CCallsignSet(this->keys()); }
CCallsignSet callsigns;
for (const CSimConnectObject &simObject : this->values())
{
if (simObject.isAircraft()) { callsigns.insert(simObject.getCallsign().asString()); }
}
return callsigns;
}
QStringList CSimConnectObjects::getAllCallsignStrings(bool sorted) const
@@ -288,6 +304,17 @@ namespace BlackSimPlugin
return CSimConnectObject();
}
CSimConnectObject CSimConnectObjects::getSimObjectForOtherSimObject(const CSimConnectObject &otherSimObj) const
{
if (otherSimObj.hasValidObjectId())
{
CSimConnectObject obj = this->getSimObjectForObjectId(otherSimObj.getObjectId());
if (!obj.isInvalid()) { return obj; }
}
if (!otherSimObj.hasValidRequestId()) { return CSimConnectObject(); }
return this->getSimObjectForRequestId(otherSimObj.getRequestId());
}
bool CSimConnectObjects::isKnownSimObjectId(DWORD objectId) const
{
const CSimConnectObject simObject(this->getSimObjectForObjectId(objectId));
@@ -301,6 +328,24 @@ namespace BlackSimPlugin
return c > 0;
}
bool CSimConnectObjects::removeByOtherSimObject(const CSimConnectObject &otherSimObj)
{
const int c = this->remove(otherSimObj.getCallsign());
return c > 0;
}
int CSimConnectObjects::removeAllProbes()
{
const QList<CSimConnectObject> probes = this->getProbes();
int c = 0;
for (const CSimConnectObject &probe : probes)
{
this->remove(probe.getCallsign());
c++;
}
return c;
}
bool CSimConnectObjects::containsPendingAdded() const
{
for (const CSimConnectObject &simObject : this->values())
@@ -379,6 +424,15 @@ namespace BlackSimPlugin
return objs;
}
CSimConnectObject CSimConnectObjects::getNotPendingProbe() const
{
for (const CSimConnectObject &simObject : this->values())
{
if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending()) { return simObject; }
}
return CSimConnectObject();
}
bool CSimConnectObjects::containsType(CSimConnectObject::SimObjectType type) const
{
for (const CSimConnectObject &simObject : this->values())

View File

@@ -53,6 +53,9 @@ namespace BlackSimPlugin
//! Get callsign
const BlackMisc::Aviation::CCallsign &getCallsign() const { return m_aircraft.getCallsign(); }
//! Callsign?
bool hasCallsign() const { return !this->getCallsign().isEmpty(); }
//! Simulated aircraft (as added)
const BlackMisc::Simulation::CSimulatedAircraft &getAircraft() const { return m_aircraft; }
@@ -62,6 +65,12 @@ namespace BlackSimPlugin
//! Object type
SimObjectType getType() const { return m_type; }
//! Aircraft?
bool isAircraft() const { return this->getType() == Aircraft; }
//! Probe?
bool isTerrainProbe() const { return this->getType() == TerrainProbe; }
//! Set the type
void setType(SimObjectType type) { m_type = type; }
@@ -125,6 +134,9 @@ namespace BlackSimPlugin
//! Object is requested in simulator, not yet confirmed added
bool isPendingAdded() const;
//! Still pending
bool isOutdatedPendingAdded(qint64 thresholdMs = 2000, qint64 currentMsSinceEpoch = -1) const;
//! Adding is confirmed
bool isConfirmedAdded() const;
@@ -133,7 +145,9 @@ namespace BlackSimPlugin
//! Special states
//! @{
void setAddedWhileRemoved(bool addedWileRemoved);
bool isAddedWhileRemoving() { return m_addedWhileRemoving; }
void setAddedWhileRemoving(bool addedWileRemoved);
bool isRemovedWhileAdding() const { return m_removedWhileAdding; }
void setRemovedWhileAdding(bool removedWhileAdding);
//! @}
@@ -170,9 +184,18 @@ namespace BlackSimPlugin
//! Reset the state (like it was a new onject) without affecting interpolator and aircraft
void resetState();
//! Reset the timestamp
void resetTimestamp() { m_tsCreated = QDateTime::currentMSecsSinceEpoch(); }
//! VTOL?
bool isVtol() const { return m_aircraft.isVtol(); }
//! Valid?
bool isValid() const { return !this->isInvalid(); }
//! Invalid?
bool isInvalid() const { return !this->hasValidObjectId() && !this->hasValidRequestId(); }
//! Engine count
int getEngineCount() const { return m_aircraft.getEnginesCount(); }
@@ -218,7 +241,8 @@ namespace BlackSimPlugin
bool m_camera = false;
bool m_removedWhileAdding = false;
bool m_addedWhileRemoving = false;
int m_lightsRequestedAt = -1;
int m_lightsRequestedAt = -1;
qint64 m_tsCreated = -1;
GUID m_cameraGuid;
SIMCONNECT_DATA_XYZ m_cameraPosition;
SIMCONNECT_DATA_PBH m_cameraRotation;
@@ -242,18 +266,27 @@ namespace BlackSimPlugin
//! Get object per object id
CSimConnectObject getSimObjectForObjectId(DWORD objectId) const;
//! Mark as added if existing
CSimConnectObject markObjectAsAdded(DWORD objectId);
//! Get object per request id
CSimConnectObject getSimObjectForRequestId(DWORD requestId) const;
//! Get by request or object id, just as possible
CSimConnectObject getSimObjectForOtherSimObject(const CSimConnectObject &otherSimObj) const;
//! Mark as added if existing
CSimConnectObject markObjectAsAdded(DWORD objectId);
//! Is the object id one of our AI objects?
bool isKnownSimObjectId(DWORD objectId) const;
//! Remove by id
bool removeByObjectId(DWORD objectId);
//! Remove by object id or request id
bool removeByOtherSimObject(const CSimConnectObject &otherSimObj);
//! Remove all the probes
int removeAllProbes();
//! Pending add condition
bool containsPendingAdded() const;
@@ -270,7 +303,7 @@ namespace BlackSimPlugin
int countConfirmedAdded();
//! Get all callsigns
BlackMisc::Aviation::CCallsignSet getAllCallsigns() const;
BlackMisc::Aviation::CCallsignSet getAllCallsigns(bool withoutProbes = true) const;
//! Get all callsign strings
QStringList getAllCallsignStrings(bool sorted = false) const;
@@ -287,6 +320,12 @@ namespace BlackSimPlugin
//! Get by type
QList<CSimConnectObject> getByType(CSimConnectObject::SimObjectType type) const;
//! All probes
QList<CSimConnectObject> getProbes() const { return this->getByType(CSimConnectObject::TerrainProbe); }
//! Get a non pending probe
CSimConnectObject getNotPendingProbe() const;
//! Contains object of type
bool containsType(CSimConnectObject::SimObjectType type) const;
};