6 #include "../fscommon/simulatorfscommonfunctions.h"
7 #include "../fsxcommon/simconnectsymbols.h"
13 using namespace swift::config;
15 using namespace swift::misc::aviation;
16 using namespace swift::misc::physical_quantities;
17 using namespace swift::misc::geo;
18 using namespace swift::misc::network;
19 using namespace swift::misc::simulation;
20 using namespace swift::misc::simulation::fscommon;
21 using namespace swift::simplugin::fsxcommon;
23 using namespace swift::simplugin::fscommon;
25 namespace swift::simplugin::p3d
30 :
CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent)
33 if (CBuildConfig::isCompiledWithP3DSupport() && CBuildConfig::isRunningOnWindowsNtPlatform() &&
34 CBuildConfig::buildWordSize() == 64)
47 if (!loadAndResolveP3DSimConnectByString(m_p3dVersion.
get())) {
return false; }
48 return CSimulatorFsxCommon::connectTo();
51 return CSimulatorFsxCommon::connectTo();
59 Q_ASSERT_X(simulatorP3D, Q_FUNC_INFO,
"Cannot convert context to CSimulatorP3D");
69 case SIMCONNECT_RECV_ID_GROUND_INFO:
72 const SIMCONNECT_RECV_GROUND_INFO *pObjData =
static_cast<SIMCONNECT_RECV_GROUND_INFO *
>(pData);
73 const DWORD requestId = pObjData->dwRequestID;
74 if (!CSimulatorFsxCommon::isRequestForSimObjTerrainProbe(requestId)) {
break; }
77 if (pObjData->dwArraySize != 1) {
break; }
78 const SIMCONNECT_DATA_GROUND_INFO gi = pObjData->rgData[0];
79 if (!gi.bIsValid) {
break; }
80 const CLatitude lat(gi.fLat, CAngleUnit::deg());
81 const CLongitude lng(gi.fLon, CAngleUnit::deg());
82 const CAltitude alt(gi.fAlt, CAltitude::MeanSeaLevel, CAltitude::TrueAltitude, CLengthUnit::ft());
84 const CElevationPlane ep(coordinate, CElevationPlane::singlePointRadius());
90 default: CSimulatorFsxCommon::SimConnectProc(pData, cbData, pContext);
break;
97 if (reference.
isNull()) {
return false; }
101 Q_ASSERT_X(CThreadUtils::isInThisThread(
this), Q_FUNC_INFO,
"thread");
103 const double latDeg = reference.
latitude().
value(CAngleUnit::deg());
104 const double lngDeg = reference.
longitude().
value(CAngleUnit::deg());
105 const double maxAltFt = hasHeight ? reference.
geodeticHeight().
value(CLengthUnit::ft()) : 50000;
106 const DWORD dwGridWidth = 1.0;
107 const DWORD dwGridHeight = 1.0;
109 const SIMCONNECT_DATA_REQUEST_ID requestId =
114 SimConnect_RequestGroundInfo(
m_hSimConnect, requestId, latDeg, lngDeg, 0, latDeg, lngDeg, maxAltFt,
115 dwGridWidth, dwGridHeight, SIMCONNECT_GROUND_INFO_LATLON_FORMAT_DEGREES,
116 SIMCONNECT_GROUND_INFO_ALT_FORMAT_FEET,
117 SIMCONNECT_GROUND_INFO_SOURCE_FLAG_PLATFORMS),
118 Q_FUNC_INFO,
"SimConnect_RequestGroundInfo");
130 << requestId << callsign.
asString();
131 CLogMessage::preformatted(msg);
188 if (situation.
isNull()) {
return false; }
189 SIMCONNECT_DATA_OBSERVER obs;
194 obs.Regime = SIMCONNECT_OBSERVER_REGIME_GHOST;
195 obs.RotateOnTarget = TRUE;
196 obs.FocusFixed = TRUE;
197 obs.FieldOfViewH = 30;
198 obs.FieldOfViewV = 30;
200 obs.AngularStep = 10;
203 hr = SimConnect_CreateObserver(
m_hSimConnect, observerName, obs);
206 SIMCONNECT_DATA_XYZ offset;
207 offset.x = offset.y = 30;
212 SimConnect_SetObserverLookAt(
m_hSimConnect, observerName, obs.Position);
237 if (!simObject.hasCamera()) {
return; }
238 simObject.removeCamera();
255 const SIMCONNECT_OBJECT_ID objectId = simObject.
getObjectId();
258 "Release control", Q_FUNC_INFO,
"SimConnect_AIReleaseControlEx");
261 SIMCONNECT_GROUP_PRIORITY_HIGHEST,
262 SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY),
263 simObject,
"EventFreezeLatLng", Q_FUNC_INFO,
"SimConnect_TransmitClientEvent");
266 SIMCONNECT_GROUP_PRIORITY_HIGHEST,
267 SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY),
268 simObject,
"EventFreezeAlt", Q_FUNC_INFO,
"SimConnect_TransmitClientEvent");
271 SIMCONNECT_GROUP_PRIORITY_HIGHEST,
272 SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY),
273 simObject,
"EventFreezeAtt", Q_FUNC_INFO,
"SimConnect_TransmitClientEvent");
275 return isOk(hr1, hr2, hr3, hr4);
282 CSimulatorFsxCommon::SimConnectProc(pData, cbData, pContext);
289 if (!loadAndResolveP3DSimConnectByString(m_p3dVersion.
get())) {
return; }
290 CSimulatorFsxCommonListener::startImpl();
293 CSimulatorFsxCommonListener::startImpl();
virtual void callbackReceivedRequestedElevation(const swift::misc::geo::CElevationPlane &plane, const swift::misc::aviation::CCallsign &callsign, bool isWater)
A requested elevation has been received.
virtual bool followAircraft(const swift::misc::aviation::CCallsign &callsign)
Follow aircraft.
virtual bool isShuttingDown() const
Is overall (swift) application shutting down.
void requestedElevation(const swift::misc::aviation::CCallsign &callsign)
Requested elevation, call pending.
virtual bool isShuttingDownOrDisconnected() const
Shutting down or disconnected?
swift::misc::aviation::CAircraftSituationPerCallsign m_lastSentSituations
last situations sent to simulator
T get() const
Get a copy of the current value.
Class for emitting a log message.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Streamable status message, e.g.
Value object for ICAO classification.
Value object encapsulating information of an aircraft's situation.
virtual bool isNull() const
Null situation.
Altitude as used in aviation, can be AGL or MSL altitude.
Value object encapsulating information of a callsign.
const QString & asString() const
Get callsign (normalized)
Plane of same elevation, can be a single point or larger area (e.g. airport)
Geodetic coordinate, a position in 3D space relative to the reference geoid.
bool hasMSLGeodeticHeight() const
Geodetic height not null and aviation::CAltitude::MeanSeaLevel.
virtual CLongitude longitude() const =0
Longitude.
virtual bool isNull() const
Is null, means vector x, y, z == 0.
virtual const aviation::CAltitude & geodeticHeight() const =0
Height, ellipsoidal or geodetic height (used in GPS)
virtual CLatitude latitude() const =0
Latitude.
Direct in memory access to client (network client) data.
double value(MU unit) const
Value in given unit.
Aircraft model (used by another pilot, my models on disk)
Describing a simulator plugin.
Direct threadsafe in memory access to own aircraft.
Direct thread safe in memory access to remote aircraft.
void setDefaultModel(const CAircraftModel &defaultModel)
Default model.
Class representing a SimConnect object.
DWORD getObjectId() const
Get SimConnect object id.
bool hasValidRequestAndObjectId() const
Was the object really added to simulator.
const QByteArray & getCallsignByteArray() const
Callsign as LATIN1.
void setObserverName(const QString &observer)
Set observer.
const QString & getObserverName() const
Observer name.
FSX Simulator Implementation.
SIMCONNECT_DATA_REQUEST_ID obtainRequestIdForSimObjTerrainProbe()
Get new request id, overflow safe.
CSimConnectObjects m_simConnectObjects
AI objects and their object and request ids.
QMap< DWORD, swift::misc::aviation::CCallsign > m_pendingProbeRequests
pending elevation requests: requestId/aircraft callsign
virtual bool requestElevation(const swift::misc::geo::ICoordinateGeodetic &reference, const swift::misc::aviation::CCallsign &aircraftCallsign)
Request elevation, there is no guarantee the requested elevation will be available in the provider.
HRESULT logAndTraceSendId(HRESULT hr, const QString &warningMsg, const QString &functionName, const QString &functionDetails={})
Trace if required, log errors.
virtual void removeCamera(CSimConnectObject &simObject)
Remove camera if any.
HANDLE m_hSimConnect
handle to SimConnect object
DispatchProc m_dispatchProc
called function for dispatch, can be overriden by specialized P3D function
virtual void removeObserver(CSimConnectObject &simObject)
Remove observer if any.
virtual bool releaseAIControl(const CSimConnectObject &simObject, SIMCONNECT_DATA_REQUEST_ID requestId)
Release AI control.
swift::misc::aviation::CCallsign getCallsignForPendingProbeRequests(DWORD requestId, bool remove)
Callsign for pending request.
void setUsingFsxTerrainProbe(bool use)
FSX terrain probe.
virtual bool isConnected() const
Are we connected to the simulator?
static SIMCONNECT_DATA_LATLONALT coordinateToFsxLatLonAlt(const swift::misc::geo::ICoordinateGeodetic &coordinate)
Format conversion.
P3D Simulator Implementation.
static void CALLBACK SimConnectProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
SimConnect Callback.
virtual HRESULT initEventsP3D()
Specific P3D events.
virtual bool connectTo()
Connect to simulator.
virtual void startImpl()
Plugin specific implementation to start listener.
Backend services of the swift project, like dealing with the network or the simulators.
Free functions in swift::misc.
FSXCOMMON_EXPORT bool loadAndResolveFsxSimConnect(bool manifestProbing)
Load and resolve FSX SimConnect.
unsigned long DWORD
Fake Windows DWORD.
HRESULT s_ok()
Correctly casted values/checks.
bool isFailure(HRESULT result)
Correctly casted values/checks.
HRESULT s_false()
Correctly casted values/checks.
adding struct SIMCONNECT_DATA_PBH not existing in SimConnect FSX