mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
refs #789, improvements when addressing FSX driver issue
* added new utility funtion is model list / aircraft list * added setters/getters for CSimConnectObject * added setters/getters for InterpolationStatus / PartsStatus * added CSimConnectObjects (better encapsulation)
This commit is contained in:
@@ -39,7 +39,7 @@ namespace BlackSimPlugin
|
||||
positionVelocity.lat_f = qAbs((latitude - positionVelocity.lat_i) * 65536);
|
||||
|
||||
// Longitude - integer and decimal places
|
||||
double longitude = newSituation.getPosition().longitude().value(CAngleUnit::deg()) * ( 65536.0 * 65536.0) / 360.0;
|
||||
double longitude = newSituation.getPosition().longitude().value(CAngleUnit::deg()) * (65536.0 * 65536.0) / 360.0;
|
||||
positionVelocity.lon_hi = static_cast<qint32>(longitude);
|
||||
positionVelocity.lon_lo = qAbs((longitude - positionVelocity.lon_hi) * 65536);
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace BlackSimPlugin
|
||||
positionSlewMode.lat_f = qAbs((latitude - positionSlewMode.lat_i) * 65536);
|
||||
|
||||
// Longitude - integer and decimal places
|
||||
double longitude = situation.getPosition().longitude().value(CAngleUnit::deg()) * ( 65536.0 * 65536.0) / 360.0;
|
||||
double longitude = situation.getPosition().longitude().value(CAngleUnit::deg()) * (65536.0 * 65536.0) / 360.0;
|
||||
positionSlewMode.lon_hi = static_cast<qint32>(longitude);
|
||||
positionSlewMode.lon_lo = qAbs((longitude - positionSlewMode.lon_hi) * 65536);
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace BlackSimPlugin
|
||||
}
|
||||
|
||||
CFs9Client::CFs9Client(const CCallsign &callsign, const QString &modelName,
|
||||
BlackMisc::IInterpolator *interpolator, const CTime &updateInterval, QObject *owner) :
|
||||
BlackMisc::IInterpolator *interpolator, const CTime &updateInterval, QObject *owner) :
|
||||
CDirectPlayPeer(owner, callsign),
|
||||
m_updateInterval(updateInterval), m_interpolator(interpolator), m_modelName(modelName)
|
||||
{
|
||||
@@ -174,7 +174,7 @@ namespace BlackSimPlugin
|
||||
CAircraftSituation situation = this->m_interpolator->getInterpolatedSituation(m_callsign, -1, vtolAircraft, status);
|
||||
|
||||
// Test only for successful interpolation. FS9 requires constant positions
|
||||
if (!status.interpolationSucceeded) { return; }
|
||||
if (!status.didInterpolationSucceed()) { return; }
|
||||
|
||||
sendMultiplayerPosition(situation);
|
||||
sendMultiplayerParamaters();
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
|
||||
#include "simconnectobject.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
namespace Fsx
|
||||
@@ -19,9 +22,83 @@ namespace BlackSimPlugin
|
||||
m_aircraft(aircraft), m_requestId(requestId)
|
||||
{ }
|
||||
|
||||
bool CSimConnectObject::hasValidRequestId() const
|
||||
{
|
||||
return this->m_requestId >= 0;
|
||||
}
|
||||
|
||||
bool CSimConnectObject::hasValidobjectId() const
|
||||
{
|
||||
return this->m_objectId >= 0;
|
||||
}
|
||||
|
||||
bool CSimConnectObject::isPendingAdded() const
|
||||
{
|
||||
return !this->hasValidRequestAndObjectId() || !this->m_confirmedAdded;
|
||||
}
|
||||
|
||||
bool CSimConnectObject::isConfirmedAdded() const
|
||||
{
|
||||
Q_ASSERT_X(!m_confirmedAdded || this->hasValidRequestAndObjectId(), Q_FUNC_INFO, "confirmed but invalid ids");
|
||||
return m_confirmedAdded;
|
||||
}
|
||||
|
||||
void CSimConnectObject::setConfirmedAdded(bool confirm)
|
||||
{
|
||||
m_confirmedAdded = confirm;
|
||||
m_aircraft.setRendered(true);
|
||||
}
|
||||
|
||||
void CSimConnectObject::setPendingRemoved(bool pending)
|
||||
{
|
||||
m_pendingRemoved = pending;
|
||||
m_aircraft.setRendered(false);
|
||||
}
|
||||
|
||||
bool CSimConnectObject::hasValidRequestAndObjectId() const
|
||||
{
|
||||
return this->m_requestId >= 0 && this->m_objectId >= 0;
|
||||
return this->hasValidRequestId() && this->hasValidobjectId();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::setSimConnectObjectId(int requestID, int objectId)
|
||||
{
|
||||
// First check, if this request id belongs to us
|
||||
const int requestIntId = static_cast<int>(requestID);
|
||||
auto it = std::find_if(this->begin(), this->end(), [requestIntId](const CSimConnectObject & obj) { return obj.getRequestId() == requestIntId; });
|
||||
if (it == this->end()) { return false; }
|
||||
|
||||
// belongs to us
|
||||
it->setObjectId(objectId);
|
||||
return true;
|
||||
}
|
||||
|
||||
CCallsign CSimConnectObjects::getCallsignForObjectId(int objectId) const
|
||||
{
|
||||
return getSimObjectForObjectId(objectId).getCallsign();
|
||||
}
|
||||
|
||||
CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(int objectId) const
|
||||
{
|
||||
for (const CSimConnectObject &simObject : this->values())
|
||||
{
|
||||
if (simObject.getObjectId() == objectId) { return simObject; }
|
||||
}
|
||||
return CSimConnectObject();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::isKnownSimObjectId(int objectId) const
|
||||
{
|
||||
const CSimConnectObject simObject(getSimObjectForObjectId(objectId));
|
||||
return simObject.hasValidRequestAndObjectId() && objectId == simObject.getObjectId();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::containsPendingAdd() const
|
||||
{
|
||||
for (const CSimConnectObject &simObject : this->values())
|
||||
{
|
||||
if (simObject.isPendingAdded()) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -29,16 +29,16 @@ namespace BlackSimPlugin
|
||||
CSimConnectObject();
|
||||
|
||||
//! Constructor
|
||||
CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft,int requestId);
|
||||
CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, int requestId);
|
||||
|
||||
//! Destructor
|
||||
~CSimConnectObject() {}
|
||||
|
||||
//! Get Callsign
|
||||
BlackMisc::Aviation::CCallsign getCallsign() const { return m_aircraft.getCallsign(); }
|
||||
const BlackMisc::Aviation::CCallsign &getCallsign() const { return m_aircraft.getCallsign(); }
|
||||
|
||||
//! Simulated aircraft (as added)
|
||||
BlackMisc::Simulation::CSimulatedAircraft getAircraft() const { return m_aircraft; }
|
||||
const BlackMisc::Simulation::CSimulatedAircraft &getAircraft() const { return m_aircraft; }
|
||||
|
||||
//! Set Simconnect request id
|
||||
void setRequestId(int id) { m_requestId = id; }
|
||||
@@ -52,6 +52,27 @@ namespace BlackSimPlugin
|
||||
//! Set Simconnect object id
|
||||
int getObjectId() const { return m_objectId; }
|
||||
|
||||
//! Valid request id?
|
||||
bool hasValidRequestId() const;
|
||||
|
||||
//! Valid object id?
|
||||
bool hasValidobjectId() const;
|
||||
|
||||
//! Object is requested, not yet added
|
||||
bool isPendingAdded() const;
|
||||
|
||||
//! Adding is confirmed
|
||||
bool isConfirmedAdded() const;
|
||||
|
||||
//! Marked as confirmed
|
||||
void setConfirmedAdded(bool confirm);
|
||||
|
||||
//! Removing is pending
|
||||
bool isPendingRemoved() const { return m_pendingRemoved; }
|
||||
|
||||
//! Marked as confirmed
|
||||
void setPendingRemoved(bool pending);
|
||||
|
||||
//! VTOL?
|
||||
bool isVtol() const { return m_aircraft.isVtol(); }
|
||||
|
||||
@@ -62,7 +83,30 @@ namespace BlackSimPlugin
|
||||
BlackMisc::Simulation::CSimulatedAircraft m_aircraft;
|
||||
int m_requestId = -1;
|
||||
int m_objectId = -1;
|
||||
bool m_confirmedAdded = false;
|
||||
bool m_pendingRemoved = false;
|
||||
};
|
||||
|
||||
//! Simulator objects (aka AI aircraft
|
||||
class CSimConnectObjects : public QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject>
|
||||
{
|
||||
public:
|
||||
//! Set ID of a SimConnect object, so far we only have an request id in the object
|
||||
bool setSimConnectObjectId(int requestID, int objectId);
|
||||
|
||||
//! Find which callsign belongs to the object id
|
||||
BlackMisc::Aviation::CCallsign getCallsignForObjectId(int objectId) const;
|
||||
|
||||
//! Find which callsign belongs to the object id
|
||||
CSimConnectObject getSimObjectForObjectId(int objectId) const;
|
||||
|
||||
//! Is the object id one of our AI objects?
|
||||
bool isKnownSimObjectId(int objectId) const;
|
||||
|
||||
//! Pending add condition
|
||||
bool containsPendingAdd() const;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user