13 using namespace swift::config;
15 using namespace swift::misc::aviation;
16 using namespace swift::misc::simulation;
19 namespace swift::simplugin::fsxcommon
21 CSimConnectObject::CSimConnectObject() { this->resetCameraPositions(); }
32 : m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true),
33 m_interpolator(QSharedPointer<
CInterpolatorMulti>::create(aircraft.getCallsign(), simEnvProvider,
34 setupProvider, remoteAircraftProvider, logger))
37 m_type = aircraft.
isTerrainProbe() ? TerrainProbe : AircraftNonAtc;
38 m_interpolator->initCorrespondingModel(aircraft.
getModel());
44 m_aircraft = aircraft;
46 m_type = aircraft.
isTerrainProbe() ? TerrainProbe : AircraftNonAtc;
51 if (modelString.isEmpty()) {
return; }
57 if (cg.
isNull()) {
return; }
64 m_validRequestId =
true;
71 if (CBuildConfig::isLocalDeveloperDebugBuild())
75 Q_ASSERT_X(same, Q_FUNC_INFO,
"Type mismatch");
83 case AircraftSimulatedObject:
86 return os + m_requestId;
92 m_validObjectId =
true;
100 if (currentMsSinceEpoch < 0) { currentMsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); }
101 if (m_tsCreated < 0) {
return true; }
102 const qint64 delta = currentMsSinceEpoch - m_tsCreated;
103 return delta > thresholdMs;
109 return m_confirmedAdded;
114 m_confirmedAdded = confirm;
115 m_removedWhileAdding =
false;
116 m_addedWhileRemoving =
false;
124 m_removedWhileAdding = removedWhileAdding;
129 return !this->
isPending() && !m_addedWhileRemoving && !m_removedWhileAdding;
134 m_pendingRemoved = pending;
135 m_removedWhileAdding =
false;
136 m_addedWhileRemoving =
false;
142 m_cameraPosition.x = 0;
143 m_cameraPosition.y = 0;
144 m_cameraPosition.z = 0;
145 m_cameraRotation.
Pitch = 0;
146 m_cameraRotation.
Bank = 0;
152 m_pendingRemoved =
false;
153 m_confirmedAdded =
false;
154 m_removedWhileAdding =
false;
155 m_addedWhileRemoving =
false;
161 m_addingExceptions = 0;
162 m_validRequestId =
false;
163 m_validObjectId =
false;
182 m_addingExceptions = otherObject.m_addingExceptions;
183 m_addingDirectlyRemoved = otherObject.m_addingDirectlyRemoved;
188 Q_ASSERT(m_interpolator);
189 return m_interpolator->getInterpolatorInfo(mode);
194 Q_ASSERT(m_interpolator);
195 m_interpolator->attachLogger(logger);
200 uint32_t aircraftNumber)
const
202 if (!m_interpolator) {
return {}; }
203 return m_interpolator->getInterpolation(currentTimeSinceEpoch, setup, aircraftNumber);
209 if (!m_interpolator) {
return CAircraftSituation::null(); }
210 return m_interpolator->getLastInterpolatedSituation(mode);
217 if (!m_interpolator) {
return empty; }
218 return m_interpolator->getInterpolationMessages(mode);
223 static const QString s(
224 "CS: '%1' obj: %2 req: %3 conf.added: %4 pend.rem.: %5 rwa: %6 awr: %7 aEx: %8 aRem: %9");
228 .arg(boolToYesNo(m_confirmedAdded), boolToYesNo(m_pendingRemoved), boolToYesNo(m_removedWhileAdding),
229 boolToYesNo(m_addedWhileRemoving))
230 .arg(m_addingExceptions)
231 .arg(m_addingDirectlyRemoved);
238 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong range");
239 return AircraftNonAtc;
244 static const QString a1(
"aircraft (non ATC)");
245 static const QString a2(
"aircraft (sim.object)");
246 static const QString p(
"probe");
247 static const QString u(
"unknown");
250 case AircraftNonAtc:
return a1;
251 case AircraftSimulatedObject:
return a2;
252 case TerrainProbe:
return p;
260 if (t1 == t2) {
return true; }
266 return CSimConnectObject::AircraftNonAtc == type || CSimConnectObject::AircraftSimulatedObject;
278 else { (*this)[simObject.
getCallsign()] = simObject; }
285 auto it = std::find_if(this->
begin(), this->
end(),
287 if (it == this->
end()) {
return false; }
290 it->setObjectId(objectId);
302 if (!withoutProbes) {
return CCallsignSet(this->keys()); }
325 if (simObject.
getObjectId() == objectId) {
return simObject; }
340 oldestSimObj = simObj;
350 if (simObject.
getRequestId() == requestId) {
return simObject; }
375 const int c = this->remove(simObject.
getCallsign());
381 const int c = this->remove(otherSimObj.
getCallsign());
387 const QList<CSimConnectObject> probes = this->
getProbes();
391 this->remove(probe.getCallsign());
440 if (simObject.isConfirmedAdded()) { c++; }
467 QList<CSimConnectObject> objs;
470 if (simObject.
getType() == type) { objs.push_back(simObject); }
477 QList<CSimConnectObject> l = this->
getByType(CSimConnectObject::AircraftNonAtc);
478 l.append(this->
getByType(CSimConnectObject::AircraftSimulatedObject));
486 if (simObject.
getType() == CSimConnectObject::TerrainProbe && !simObject.
isPending()) {
return simObject; }
496 if (simObject.
getType() == CSimConnectObject::TerrainProbe && !simObject.
isPending())
501 oldestProbe = simObject;
512 if (simObject.
getType() == type) {
return true; }
519 return this->
containsType(CSimConnectObject::AircraftNonAtc) ||
520 this->
containsType(CSimConnectObject::AircraftSimulatedObject);
526 for (
const CCallsign &cs : callsigns) { c += this->remove(cs); }
535 const qint64 ts = QDateTime::currentMSecsSinceEpoch();
539 if (type != CSimConnectObject::AllTypes && simObject.getType() != type) {
continue; }
540 if (!simObject.isOutdatedPendingAdded(5000, ts)) {
continue; }
541 removedObjects.
insert(simObject);
545 return removedObjects;
iterator insert(const_iterator hint, const T &value)
For compatibility with std::inserter.
iterator push_back(const T &value)
Synonym for insert.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information about aircraft's lights.
Value object encapsulating information of an aircraft's situation.
Value object encapsulating information of a callsign.
const QString & asString() const
Get callsign (normalized)
Value object for a set of callsigns.
QStringList getCallsignStrings(bool sorted=false) const
The callsign strings.
Physical unit length (length)
bool isNull() const
Is quantity null?
InterpolatorMode
Interpolator type.
Value object for interpolator and rendering per callsign.
Record internal state of interpolator for debugging.
Multiplexed interpolator which allows switching between modes at runtime.
Comprehensive information of an aircraft.
bool setCG(const physical_quantities::CLength &cg)
Set the center of gravity.
void setModelString(const QString &modelString)
Set model string.
bool setRendered(bool rendered)
Rendered?
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping)
bool isTerrainProbe() const
Terrain probe?
QString getCallsignAsString() const
Get callsign.
Direct in memory access to interpolation setup, normally implemented by simulator.
Direct thread safe in memory access to remote aircraft.
Direct in memory access to elevation data.
SimObjectRequest
SimObject requests used for AI aircraft and probes.
Class representing a SimConnect object.
bool isPendingAdded() const
Object is requested in simulator, not yet confirmed added.
bool isConfirmedAdded() const
Adding is confirmed.
bool hasValidRequestId() const
Valid request id?
void setConfirmedAdded(bool confirm)
Marked as confirmed, means the simulator has "confirmed" the objectId as added and not instantly remo...
void resetCameraPositions()
Reset camera positions.
void setAddedWhileRemoving(bool addedWileRemoved)
Special states.
const swift::misc::aviation::CAircraftSituation & getLastInterpolatedSituation(swift::misc::simulation::CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
Latest interpolation result.
bool isInvalid() const
Invalid?
DWORD getObjectId() const
Get SimConnect object id.
static bool isSameTypeGroup(SimObjectType t1, SimObjectType t2)
Same type.
QString toQString() const
SimObject as string.
bool hasValidRequestAndObjectId() const
Was the object really added to simulator.
void resetTimestampToNow()
Reset the timestamp.
swift::misc::simulation::CInterpolationResult getInterpolation(qint64 currentTimeSinceEpoch, const swift::misc::simulation::CInterpolationAndRenderingSetupPerCallsign &setup, uint32_t aircraftNumber) const
Get interpolated situation.
bool isPending() const
Pending added or removed?
void setRequestId(DWORD id)
Set Simconnect request id.
static SimObjectType requestIdToType(DWORD requestId)
Type of id.
static const QString & typeToString(SimObjectType type)
Type to string.
void resetToAddAgain()
Reset so it can be added again.
DWORD getRequestId() const
Get SimConnect request id.
void setAircraftCG(const swift::misc::physical_quantities::CLength &cg)
Set CG.
const swift::misc::aviation::CCallsign & getCallsign() const
Get callsign.
void attachInterpolatorLogger(swift::misc::simulation::CInterpolationLogger *logger) const
Attach an observer to read the interpolator's state for debugging.
void resetState()
Reset the state (like it was a new onject) without affecting interpolator and aircraft.
CSimConnectObject()
Constructor.
bool isOutdatedPendingAdded(qint64 thresholdMs=5000, qint64 currentMsSinceEpoch=-1) const
Still pending.
qint64 getCreatedTimestamp() const
Created timestamp.
void setRemovedWhileAdding(bool removedWhileAdding)
Special states.
void setAircraftModelString(const QString &modelString)
Set model string.
void setType(SimObjectType type)
Set the type.
void setAircraft(const swift::misc::simulation::CSimulatedAircraft &aircraft)
Set the aircraft.
bool isPendingRemoved() const
Removing is pending.
void copyAddingFailureCounters(const CSimConnectObject &otherObject)
Copy the counters from another object.
bool hasCreatedTimestamp() const
Created timestamp?
QString getInterpolatorInfo(swift::misc::simulation::CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
Get an interpolator info string (for debug info)
void setPendingRemoved(bool pending)
Marked as pending for removal.
SimObjectType getType() const
Object type.
void setObjectId(DWORD id)
Set Simconnect object id.
const swift::misc::CStatusMessageList & getInterpolationMessages(swift::misc::simulation::CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
Interpolation messages.
bool isAircraft() const
Aircraft?
bool hasCallsign() const
Callsign?
bool hasValidObjectId() const
Valid object id?
bool isReadyToSend() const
Object which can be used for sending, not pending and valid ids.
Simulator objects (aka AI aircraft)
bool containsPendingRemoved() const
Pending removed condition.
CSimConnectObject getSimObjectForRequestId(DWORD requestId) const
Get object per request id.
bool removeByOtherSimObject(const CSimConnectObject &otherSimObj)
Remove by object id or request id.
int countPendingAdded() const
Number of pending added.
int countPendingRemoved() const
Number of pending removed.
swift::misc::aviation::CCallsignSet getAllCallsigns(bool withoutProbes=true) const
Get all callsigns.
CSimConnectObject getSimObjectForObjectId(DWORD objectId) const
Get object per object id.
bool removeByObjectId(DWORD objectId)
Remove by id.
int countConfirmedAdded()
Objects not pending.
bool insert(const CSimConnectObject &simObject, bool updateTimestamp=false)
Insert.
swift::misc::aviation::CCallsignSet getPendingRemovedCallsigns() const
Callsigns of pending removed callsigns.
CSimConnectObject getSimObjectForOtherSimObject(const CSimConnectObject &otherSimObj) const
Get by request or object id, just as possible.
bool setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId)
Set ID of a SimConnect object, so far we only have an request id in the object.
CSimConnectObject getOldestNotPendingProbe() const
Get a non pending probe.
CSimConnectObject getNotPendingProbe() const
Get a non pending probe.
bool containsAircraft() const
Aircraft?
swift::misc::aviation::CCallsignSet getPendingAddedCallsigns() const
Callsigns of pending added callsigns.
QList< CSimConnectObject > getByType(CSimConnectObject::SimObjectType type) const
Get by type.
CSimConnectObject getOldestObject() const
Get the oldest object.
bool containsType(CSimConnectObject::SimObjectType type) const
Contains object of type.
bool isKnownSimObjectId(DWORD objectId) const
Is the object id one of our AI objects?
QString getAllCallsignStringsAsString(bool sorted=false, const QString &separator=", ") const
Get all callsign strings as string.
bool containsPendingAdded() const
Pending add condition.
int removeAllProbes()
Remove all the probes.
int removeCallsigns(const swift::misc::aviation::CCallsignSet &callsigns)
Remove callsigns.
QList< CSimConnectObject > getProbes() const
All probes.
CSimConnectObjects removeOutdatedPendingAdded(CSimConnectObject::SimObjectType type)
Remove all pending added objects.
QList< CSimConnectObject > getAircraft() const
All aircraft.
swift::misc::aviation::CCallsign getCallsignForObjectId(DWORD objectId) const
Find which callsign belongs to the object id.
QStringList getAllCallsignStrings(bool sorted=false, bool withoutProbes=true) const
Get all callsign strings.
static DWORD offsetSimObjAircraft(CSimConnectDefinitions::SimObjectRequest req)
Offsets.
static bool isRequestForSimObjTerrainProbe(DWORD requestId)
Request for probe (elevation)?
static bool isRequestForSimObjAircraft(DWORD requestId)
Request for sim data (request in range of sim data)?
static DWORD offsetSimObjTerrainProbe(CSimConnectDefinitions::SimObjectRequest req)
Offsets.
Backend services of the swift project, like dealing with the network or the simulators.
Free functions in swift::misc.
T::const_iterator begin(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
unsigned long DWORD
Fake Windows DWORD.