Ref T650, SimObject can handle SimulatedObject type (compared to NonATC)

This commit is contained in:
Klaus Basan
2019-05-06 14:59:02 +02:00
parent 6d936dc1cc
commit 4522cb5fe5
2 changed files with 66 additions and 14 deletions

View File

@@ -42,7 +42,7 @@ namespace BlackSimPlugin
m_interpolator(QSharedPointer<CInterpolatorMulti>::create(aircraft.getCallsign(), simEnvProvider, setupProvider, remoteAircraftProvider, logger))
{
this->resetCameraPositions();
m_type = aircraft.isTerrainProbe() ? TerrainProbe : Aircraft;
m_type = aircraft.isTerrainProbe() ? TerrainProbe : AircraftNonAtc;
m_interpolator->initCorrespondingModel(aircraft.getModel());
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
}
@@ -51,7 +51,7 @@ namespace BlackSimPlugin
{
m_aircraft = aircraft;
m_callsignByteArray = aircraft.getCallsignAsString().toLatin1();
m_type = aircraft.isTerrainProbe() ? TerrainProbe : Aircraft;
m_type = aircraft.isTerrainProbe() ? TerrainProbe : AircraftNonAtc;
}
void CSimConnectObject::setAircraftModelString(const QString &modelString)
@@ -79,7 +79,8 @@ namespace BlackSimPlugin
if (CBuildConfig::isLocalDeveloperDebugBuild())
{
const SimObjectType type = requestIdToType(m_requestId);
Q_ASSERT_X(type == this->getType(), Q_FUNC_INFO, "Type mismatch");
const bool same = CSimConnectObject::isSameTypeGroup(type, this->getType());
Q_ASSERT_X(same, Q_FUNC_INFO, "Type mismatch");
}
DWORD os = 0;
@@ -88,7 +89,8 @@ namespace BlackSimPlugin
case TerrainProbe:
os = static_cast<DWORD>(CSimulatorFsxCommon::offsetSimObjTerrainProbe(offset));
break;
case Aircraft:
case AircraftNonAtc:
case AircraftSimulatedObject:
default:
os = static_cast<DWORD>(CSimulatorFsxCommon::offsetSimObjAircraft(offset));
break;
@@ -239,25 +241,38 @@ namespace BlackSimPlugin
CSimConnectObject::SimObjectType CSimConnectObject::requestIdToType(DWORD requestId)
{
if (CSimulatorFsxCommon::isRequestForSimObjTerrainProbe(requestId)) { return TerrainProbe; }
if (CSimulatorFsxCommon::isRequestForSimObjAircraft(requestId)) { return Aircraft; }
if (CSimulatorFsxCommon::isRequestForSimObjAircraft(requestId)) { return AircraftNonAtc; }
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong range");
return Aircraft;
return AircraftNonAtc;
}
const QString &CSimConnectObject::typeToString(CSimConnectObject::SimObjectType type)
{
static const QString a("aircraft");
static const QString a1("aircraft (non ATC)");
static const QString a2("aircraft (sim.object)");
static const QString p("probe");
static const QString u("unknown");
switch (type)
{
case Aircraft: return a;
case TerrainProbe: return p;
case AircraftNonAtc: return a1;
case AircraftSimulatedObject: return a2;
case TerrainProbe: return p;
default: break;
}
return u;
}
bool CSimConnectObject::isSameTypeGroup(CSimConnectObject::SimObjectType t1, CSimConnectObject::SimObjectType t2)
{
if (t1 == t2) { return true; }
return isAircraft(t1) && isAircraft(t2);
}
bool CSimConnectObject::isAircraft(CSimConnectObject::SimObjectType type)
{
return CSimConnectObject::AircraftNonAtc == type || CSimConnectObject::AircraftSimulatedObject;
}
bool CSimConnectObjects::insert(const CSimConnectObject &simObject, bool updateTimestamp)
{
if (!simObject.hasCallsign()) { return false; }
@@ -465,6 +480,13 @@ namespace BlackSimPlugin
return objs;
}
QList<CSimConnectObject> CSimConnectObjects::getAircraft() const
{
QList<CSimConnectObject> l = this->getByType(CSimConnectObject::AircraftNonAtc);
l.append(this->getByType(CSimConnectObject::AircraftSimulatedObject));
return l;
}
CSimConnectObject CSimConnectObjects::getNotPendingProbe() const
{
for (const CSimConnectObject &simObject : *this)
@@ -499,6 +521,11 @@ namespace BlackSimPlugin
return false;
}
bool CSimConnectObjects::containsAircraft() const
{
return this->containsType(CSimConnectObject::AircraftNonAtc) || this->containsType(CSimConnectObject::AircraftSimulatedObject);
}
int CSimConnectObjects::removeCallsigns(const CCallsignSet &callsigns)
{
int c = 0;

View File

@@ -30,7 +30,8 @@ namespace BlackSimPlugin
//! Type
enum SimObjectType
{
Aircraft,
AircraftNonAtc,
AircraftSimulatedObject,
TerrainProbe,
AllTypes
};
@@ -69,8 +70,17 @@ namespace BlackSimPlugin
//! Object type
SimObjectType getType() const { return m_type; }
//! Type as string
const QString &getTypeAsString() const { return typeToString(m_type); }
//! Aircraft?
bool isAircraft() const { return this->getType() == Aircraft; }
bool isAircraft() const { return this->getType() == AircraftNonAtc || this->getType() == AircraftSimulatedObject; }
//! Aircraft simulated object?
bool isAircraftSimulatedObject() const { return this->getType() == AircraftSimulatedObject; }
//! Aircraft NON ATC?
bool isAircraftNonAtc() const { return this->getType() == AircraftNonAtc; }
//! Probe?
bool isTerrainProbe() const { return this->getType() == TerrainProbe; }
@@ -282,9 +292,15 @@ namespace BlackSimPlugin
//! Type to string
static const QString &typeToString(SimObjectType type);
//! Same type
static bool isSameTypeGroup(SimObjectType t1, SimObjectType t2);
//! Aircraft?
static bool isAircraft(SimObjectType type);
private:
BlackMisc::Simulation::CSimulatedAircraft m_aircraft; //!< corresponding aircraft
SimObjectType m_type = Aircraft;
SimObjectType m_type = AircraftNonAtc;
DWORD m_requestId = 0;
DWORD m_objectId = 0;
bool m_validRequestId = false;
@@ -297,13 +313,13 @@ namespace BlackSimPlugin
int m_addingExceptions = 0; //!< exception when added
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_PBH m_cameraRotation;
QByteArray m_callsignByteArray;
QString m_observerName;
BlackMisc::Aviation::CAircraftLights m_currentLightsInSim { nullptr }; //!< current lights to know state for toggling
BlackMisc::Aviation::CAircraftLights m_lightsAsSent { nullptr }; //!< lights as sent to simulator
BlackMisc::Aviation::CAircraftLights m_lightsAsSent { nullptr }; //!< lights as sent to simulator
SIMCONNECT_PERIOD m_requestSimDataPeriod = SIMCONNECT_PERIOD_NEVER; //!< how often do we query ground elevation
QSharedPointer<BlackMisc::Simulation::CInterpolatorMulti> m_interpolator; //!< shared pointer because CSimConnectObject can be copied
};
@@ -387,6 +403,9 @@ namespace BlackSimPlugin
//! All probes
QList<CSimConnectObject> getProbes() const { return this->getByType(CSimConnectObject::TerrainProbe); }
//! All aircraft
QList<CSimConnectObject> getAircraft() const;
//! Get a non pending probe
CSimConnectObject getNotPendingProbe() const;
@@ -395,6 +414,12 @@ namespace BlackSimPlugin
//! Contains object of type
bool containsType(CSimConnectObject::SimObjectType type) const;
//! Probe?
bool containsProbe() const { return this->containsType(CSimConnectObject::TerrainProbe); }
//! Aircraft?
bool containsAircraft() const;
};
} // namespace
} // namespace