mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-06 02:16:04 +08:00
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:
@@ -43,6 +43,7 @@ namespace BlackSimPlugin
|
|||||||
m_interpolator(QSharedPointer<CInterpolatorMulti>::create(aircraft.getCallsign(), simEnvProvider, setupProvider, remoteAircraftProvider, logger))
|
m_interpolator(QSharedPointer<CInterpolatorMulti>::create(aircraft.getCallsign(), simEnvProvider, setupProvider, remoteAircraftProvider, logger))
|
||||||
{
|
{
|
||||||
this->resetCameraPositions();
|
this->resetCameraPositions();
|
||||||
|
m_type = aircraft.isTerrainProbe() ? TerrainProbe : Aircraft;
|
||||||
m_interpolator->initCorrespondingModel(aircraft.getModel());
|
m_interpolator->initCorrespondingModel(aircraft.getModel());
|
||||||
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
|
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
|
||||||
}
|
}
|
||||||
@@ -106,6 +107,14 @@ namespace BlackSimPlugin
|
|||||||
return !this->hasValidRequestAndObjectId() || !m_confirmedAdded;
|
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
|
bool CSimConnectObject::isConfirmedAdded() const
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!m_confirmedAdded || this->hasValidRequestAndObjectId(), Q_FUNC_INFO, "confirmed but invalid ids");
|
Q_ASSERT_X(!m_confirmedAdded || this->hasValidRequestAndObjectId(), Q_FUNC_INFO, "confirmed but invalid ids");
|
||||||
@@ -120,7 +129,7 @@ namespace BlackSimPlugin
|
|||||||
m_aircraft.setRendered(true);
|
m_aircraft.setRendered(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimConnectObject::setAddedWhileRemoved(bool addedWileRemoved)
|
void CSimConnectObject::setAddedWhileRemoving(bool addedWileRemoved)
|
||||||
{
|
{
|
||||||
m_addedWhileRemoving = addedWileRemoved;
|
m_addedWhileRemoving = addedWileRemoved;
|
||||||
}
|
}
|
||||||
@@ -167,6 +176,7 @@ namespace BlackSimPlugin
|
|||||||
m_lightsRequestedAt = -1;
|
m_lightsRequestedAt = -1;
|
||||||
m_validRequestId = false;
|
m_validRequestId = false;
|
||||||
m_validObjectId = false;
|
m_validObjectId = false;
|
||||||
|
m_tsCreated = QDateTime::currentMSecsSinceEpoch();
|
||||||
this->resetCameraPositions();
|
this->resetCameraPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,9 +253,15 @@ namespace BlackSimPlugin
|
|||||||
return this->getSimObjectForObjectId(objectId).getCallsign();
|
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
|
QStringList CSimConnectObjects::getAllCallsignStrings(bool sorted) const
|
||||||
@@ -288,6 +304,17 @@ namespace BlackSimPlugin
|
|||||||
return CSimConnectObject();
|
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
|
bool CSimConnectObjects::isKnownSimObjectId(DWORD objectId) const
|
||||||
{
|
{
|
||||||
const CSimConnectObject simObject(this->getSimObjectForObjectId(objectId));
|
const CSimConnectObject simObject(this->getSimObjectForObjectId(objectId));
|
||||||
@@ -301,6 +328,24 @@ namespace BlackSimPlugin
|
|||||||
return c > 0;
|
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
|
bool CSimConnectObjects::containsPendingAdded() const
|
||||||
{
|
{
|
||||||
for (const CSimConnectObject &simObject : this->values())
|
for (const CSimConnectObject &simObject : this->values())
|
||||||
@@ -379,6 +424,15 @@ namespace BlackSimPlugin
|
|||||||
return objs;
|
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
|
bool CSimConnectObjects::containsType(CSimConnectObject::SimObjectType type) const
|
||||||
{
|
{
|
||||||
for (const CSimConnectObject &simObject : this->values())
|
for (const CSimConnectObject &simObject : this->values())
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ namespace BlackSimPlugin
|
|||||||
//! Get callsign
|
//! Get callsign
|
||||||
const BlackMisc::Aviation::CCallsign &getCallsign() const { return m_aircraft.getCallsign(); }
|
const BlackMisc::Aviation::CCallsign &getCallsign() const { return m_aircraft.getCallsign(); }
|
||||||
|
|
||||||
|
//! Callsign?
|
||||||
|
bool hasCallsign() const { return !this->getCallsign().isEmpty(); }
|
||||||
|
|
||||||
//! 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; }
|
||||||
|
|
||||||
@@ -62,6 +65,12 @@ namespace BlackSimPlugin
|
|||||||
//! Object type
|
//! Object type
|
||||||
SimObjectType getType() const { return m_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
|
//! Set the type
|
||||||
void setType(SimObjectType type) { m_type = type; }
|
void setType(SimObjectType type) { m_type = type; }
|
||||||
|
|
||||||
@@ -125,6 +134,9 @@ namespace BlackSimPlugin
|
|||||||
//! Object is requested in simulator, not yet confirmed added
|
//! Object is requested in simulator, not yet confirmed added
|
||||||
bool isPendingAdded() const;
|
bool isPendingAdded() const;
|
||||||
|
|
||||||
|
//! Still pending
|
||||||
|
bool isOutdatedPendingAdded(qint64 thresholdMs = 2000, qint64 currentMsSinceEpoch = -1) const;
|
||||||
|
|
||||||
//! Adding is confirmed
|
//! Adding is confirmed
|
||||||
bool isConfirmedAdded() const;
|
bool isConfirmedAdded() const;
|
||||||
|
|
||||||
@@ -133,7 +145,9 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
//! Special states
|
//! 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);
|
void setRemovedWhileAdding(bool removedWhileAdding);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
@@ -170,9 +184,18 @@ 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 the timestamp
|
||||||
|
void resetTimestamp() { m_tsCreated = QDateTime::currentMSecsSinceEpoch(); }
|
||||||
|
|
||||||
//! VTOL?
|
//! VTOL?
|
||||||
bool isVtol() const { return m_aircraft.isVtol(); }
|
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
|
//! Engine count
|
||||||
int getEngineCount() const { return m_aircraft.getEnginesCount(); }
|
int getEngineCount() const { return m_aircraft.getEnginesCount(); }
|
||||||
|
|
||||||
@@ -219,6 +242,7 @@ namespace BlackSimPlugin
|
|||||||
bool m_removedWhileAdding = false;
|
bool m_removedWhileAdding = false;
|
||||||
bool m_addedWhileRemoving = false;
|
bool m_addedWhileRemoving = false;
|
||||||
int m_lightsRequestedAt = -1;
|
int m_lightsRequestedAt = -1;
|
||||||
|
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;
|
||||||
@@ -242,18 +266,27 @@ namespace BlackSimPlugin
|
|||||||
//! Get object per object id
|
//! Get object per object id
|
||||||
CSimConnectObject getSimObjectForObjectId(DWORD objectId) const;
|
CSimConnectObject getSimObjectForObjectId(DWORD objectId) const;
|
||||||
|
|
||||||
//! Mark as added if existing
|
|
||||||
CSimConnectObject markObjectAsAdded(DWORD objectId);
|
|
||||||
|
|
||||||
//! Get object per request id
|
//! Get object per request id
|
||||||
CSimConnectObject getSimObjectForRequestId(DWORD requestId) const;
|
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?
|
//! Is the object id one of our AI objects?
|
||||||
bool isKnownSimObjectId(DWORD objectId) const;
|
bool isKnownSimObjectId(DWORD objectId) const;
|
||||||
|
|
||||||
//! Remove by id
|
//! Remove by id
|
||||||
bool removeByObjectId(DWORD objectId);
|
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
|
//! Pending add condition
|
||||||
bool containsPendingAdded() const;
|
bool containsPendingAdded() const;
|
||||||
|
|
||||||
@@ -270,7 +303,7 @@ namespace BlackSimPlugin
|
|||||||
int countConfirmedAdded();
|
int countConfirmedAdded();
|
||||||
|
|
||||||
//! Get all callsigns
|
//! Get all callsigns
|
||||||
BlackMisc::Aviation::CCallsignSet getAllCallsigns() 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) const;
|
||||||
@@ -287,6 +320,12 @@ namespace BlackSimPlugin
|
|||||||
//! Get by type
|
//! Get by type
|
||||||
QList<CSimConnectObject> getByType(CSimConnectObject::SimObjectType type) const;
|
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
|
//! Contains object of type
|
||||||
bool containsType(CSimConnectObject::SimObjectType type) const;
|
bool containsType(CSimConnectObject::SimObjectType type) const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user