13using namespace swift::config;
15using namespace swift::misc::aviation;
16using namespace swift::misc::simulation;
19namespace swift::simplugin::fsxcommon
32 : m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true),
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;
55 m_aircraft.setModelString(modelString);
70 m_validRequestId =
true;
81 Q_ASSERT_X(same, Q_FUNC_INFO,
"Type mismatch");
89 case AircraftSimulatedObject:
92 return os + m_requestId;
98 m_validObjectId =
true;
109 if (currentMsSinceEpoch < 0)
117 const qint64 delta = currentMsSinceEpoch - m_tsCreated;
118 return delta > thresholdMs;
124 return m_confirmedAdded;
129 m_confirmedAdded = confirm;
130 m_removedWhileAdding =
false;
131 m_addedWhileRemoving =
false;
132 m_aircraft.setRendered(
true);
139 m_removedWhileAdding = removedWhileAdding;
144 return !this->
isPending() && !m_addedWhileRemoving && !m_removedWhileAdding;
149 m_pendingRemoved = pending;
150 m_removedWhileAdding =
false;
151 m_addedWhileRemoving =
false;
152 m_aircraft.setRendered(
false);
157 m_cameraPosition.x = 0;
158 m_cameraPosition.y = 0;
159 m_cameraPosition.z = 0;
160 m_cameraRotation.Pitch = 0;
161 m_cameraRotation.Bank = 0;
162 m_cameraRotation.Heading = 0;
167 m_pendingRemoved =
false;
168 m_confirmedAdded =
false;
169 m_removedWhileAdding =
false;
170 m_addedWhileRemoving =
false;
176 m_addingExceptions = 0;
177 m_validRequestId =
false;
178 m_validObjectId =
false;
197 m_addingExceptions = otherObject.m_addingExceptions;
198 m_addingDirectlyRemoved = otherObject.m_addingDirectlyRemoved;
203 Q_ASSERT(m_interpolator);
204 return m_interpolator->getInterpolatorInfo(mode);
209 Q_ASSERT(m_interpolator);
210 m_interpolator->attachLogger(logger);
215 uint32_t aircraftNumber)
const
221 return m_interpolator->getInterpolation(currentTimeSinceEpoch, setup, aircraftNumber);
231 return m_interpolator->getLastInterpolatedSituation(mode);
242 return m_interpolator->getInterpolationMessages(mode);
248 "CS: '%1' obj: %2 req: %3 conf.added: %4 pend.rem.: %5 rwa: %6 awr: %7 aEx: %8 aRem: %9");
254 .
arg(m_addingExceptions)
255 .
arg(m_addingDirectlyRemoved);
266 return AircraftNonAtc;
268 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong range");
269 return AircraftNonAtc;
274 static const QString a1(
"aircraft (non ATC)");
275 static const QString a2(
"aircraft (sim.object)");
276 static const QString p(
"probe");
277 static const QString u(
"unknown");
280 case AircraftNonAtc:
return a1;
281 case AircraftSimulatedObject:
return a2;
282 case TerrainProbe:
return p;
299 return CSimConnectObject::AircraftNonAtc == type || CSimConnectObject::AircraftSimulatedObject == type;
324 auto it = std::find_if(this->
begin(), this->
end(),
326 if (it == this->
end())
332 it->setObjectId(objectId);
400 oldestSimObj = simObj;
460 this->
remove(probe.getCallsign());
521 if (simObject.isConfirmedAdded())
560 if (simObject.
getType() == type)
579 if (simObject.
getType() == CSimConnectObject::TerrainProbe && !simObject.
isPending())
592 if (simObject.
getType() == CSimConnectObject::TerrainProbe && !simObject.
isPending())
597 oldestProbe = simObject;
608 if (simObject.
getType() == type)
618 return this->
containsType(CSimConnectObject::AircraftNonAtc) ||
619 this->
containsType(CSimConnectObject::AircraftSimulatedObject);
641 if (type != CSimConnectObject::AllTypes && simObject.getType() != type)
645 if (!simObject.isOutdatedPendingAdded(5000, ts))
649 removedObjects.
insert(simObject);
650 removeCallsignsSet.
insert(simObject.getCallsign());
652 if (!removeCallsignsSet.
isEmpty())
656 return removedObjects;
static bool isLocalDeveloperDebugBuild()
Local build for developers.
iterator insert(const_iterator hint, const T &value)
For compatibility with std::inserter.
bool isEmpty() const
Synonym for empty.
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.
static const CAircraftSituation & null()
Null 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 isTerrainProbe() const
Terrain probe?
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping).
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::CCallsign & getCallsign() const
Get callsign.
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.
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.
QList< CSimConnectObject > getProbes() const
All probes.
bool containsPendingAdded() const
Pending add condition.
int removeAllProbes()
Remove all the probes.
int removeCallsigns(const swift::misc::aviation::CCallsignSet &callsigns)
Remove callsigns.
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.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
qint64 currentMSecsSinceEpoch()
QHash< swift::misc::aviation::CCallsign, CSimConnectObject >::iterator begin()
QHash< swift::misc::aviation::CCallsign, CSimConnectObject >::iterator end()
bool isEmpty() const const
QList< swift::misc::aviation::CCallsign > keys() const const
bool remove(const swift::misc::aviation::CCallsign &key)
void append(QList< T > &&value)
void push_back(QList< T >::parameter_type value)
QString arg(Args &&... args) const const
bool isEmpty() const const
QByteArray toLatin1() const const
QString join(QChar separator) const const
unsigned long DWORD
Fake Windows DWORD.