13using namespace swift::config;
15using namespace swift::misc::aviation;
16using namespace swift::misc::physical_quantities;
17using namespace swift::misc::geo;
18using namespace swift::misc::network;
19using namespace swift::misc::simulation;
20using namespace swift::misc::simulation::fscommon;
21using namespace swift::simplugin::fsxcommon;
23using namespace swift::simplugin::fscommon;
25namespace swift::simplugin::p3d
47 if (!loadAndResolveP3DSimConnectByString(m_p3dVersion.get()))
53 if (!loadAndResolveFsxSimConnect(
true))
65 Q_ASSERT_X(simulatorP3D, Q_FUNC_INFO,
"Cannot convert context to CSimulatorP3D");
75 case SIMCONNECT_RECV_ID_GROUND_INFO:
78 const SIMCONNECT_RECV_GROUND_INFO *pObjData =
static_cast<SIMCONNECT_RECV_GROUND_INFO *
>(pData);
79 const DWORD requestId = pObjData->dwRequestID;
86 if (pObjData->dwArraySize != 1)
90 const SIMCONNECT_DATA_GROUND_INFO gi = pObjData->rgData[0];
130 const DWORD dwGridWidth = 1.0;
131 const DWORD dwGridHeight = 1.0;
133 const SIMCONNECT_DATA_REQUEST_ID requestId =
138 SimConnect_RequestGroundInfo(
m_hSimConnect, requestId, latDeg, lngDeg, 0, latDeg, lngDeg, maxAltFt,
139 dwGridWidth, dwGridHeight, SIMCONNECT_GROUND_INFO_LATLON_FORMAT_DEGREES,
140 SIMCONNECT_GROUND_INFO_ALT_FORMAT_FEET,
141 SIMCONNECT_GROUND_INFO_SOURCE_FLAG_PLATFORMS),
142 Q_FUNC_INFO,
"SimConnect_RequestGroundInfo");
153 const CStatusMessage msg = CStatusMessage(
this).error(u
"SimConnect, can not request ground info: '%1' '%2'")
154 << requestId << callsign.
asString();
225 SIMCONNECT_DATA_OBSERVER obs;
226 SIMCONNECT_DATA_PBH pbh;
230 obs.Regime = SIMCONNECT_OBSERVER_REGIME_GHOST;
231 obs.RotateOnTarget = TRUE;
232 obs.FocusFixed = TRUE;
233 obs.FieldOfViewH = 30;
234 obs.FieldOfViewV = 30;
236 obs.AngularStep = 10;
239 hr = SimConnect_CreateObserver(
m_hSimConnect, observerName, obs);
242 SIMCONNECT_DATA_XYZ offset;
243 offset.x = offset.y = 30;
248 SimConnect_SetObserverLookAt(
m_hSimConnect, observerName, obs.Position);
265 CLogMessage(
this).error(u
"P3D plugin error: %1") <<
"initEventsP3D failed";
297 const SIMCONNECT_OBJECT_ID objectId = simObject.
getObjectId();
300 "Release control", Q_FUNC_INFO,
"SimConnect_AIReleaseControlEx");
303 SIMCONNECT_GROUP_PRIORITY_HIGHEST,
304 SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY),
305 simObject,
"EventFreezeLatLng", Q_FUNC_INFO,
"SimConnect_TransmitClientEvent");
308 SIMCONNECT_GROUP_PRIORITY_HIGHEST,
309 SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY),
310 simObject,
"EventFreezeAlt", Q_FUNC_INFO,
"SimConnect_TransmitClientEvent");
313 SIMCONNECT_GROUP_PRIORITY_HIGHEST,
314 SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY),
315 simObject,
"EventFreezeAtt", Q_FUNC_INFO,
"SimConnect_TransmitClientEvent");
317 return isOk(hr1, hr2, hr3, hr4);
331 if (!loadAndResolveP3DSimConnectByString(m_p3dVersion.get()))
337 if (!loadAndResolveFsxSimConnect(
true))
static CAngleUnit deg()
Degrees.
static constexpr bool isRunningOnWindowsNtPlatform()
Running on Windows NT platform?
static constexpr bool isCompiledWithP3DSupport()
with P3D support?
static int buildWordSize()
Whether this swift application is build as 32 or 64bit application.
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.
bool requestElevation(const swift::misc::geo::ICoordinateGeodetic &reference, const swift::misc::aviation::CCallsign &callsign)
Request elevation, there is no guarantee the requested elevation will be available in the provider.
virtual bool isShuttingDownOrDisconnected() const
Shutting down or disconnected?
swift::misc::aviation::CAircraftSituationPerCallsign m_lastSentSituations
last situations sent to simulator
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
static bool isInThisThread(const QObject *toBeTested)
Is the current thread the object's thread?
Value object for ICAO classification.
bool isNull() const
Null situation.
Altitude as used in aviation, can be AGL or MSL altitude.
@ TrueAltitude
Height of the airplane above Mean Sea Level (MSL).
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).
static const physical_quantities::CLength & singlePointRadius()
Radius for single point.
bool hasMSLGeodeticHeight() const
Geodetic height not null and aviation::CAltitude::MeanSeaLevel.
virtual CLongitude longitude() const =0
Longitude.
virtual const aviation::CAltitude & geodeticHeight() const =0
Height, ellipsoidal or geodetic height (used in GPS).
virtual bool isNull() const
Is null, means vector x, y, z == 0.
virtual CLatitude latitude() const =0
Latitude.
Direct in memory access to client (network client) data.
static CLengthUnit ft()
Foot ft.
double value(MU unit) const
Value in given unit.
Aircraft model (used by another pilot, my models on disk).
@ TypeModelMatchingDefaultModel
a default model assigned by model matching
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.
const QByteArray & getCallsignByteArray() const
Callsign as LATIN1.
bool hasCamera() const
Has camera?
DWORD getObjectId() const
Get SimConnect object id.
bool hasValidRequestAndObjectId() const
Was the object really added to simulator.
void removeCamera()
No camera anymore.
const QString & getObserverName() const
Observer name.
void setObserverName(const QString &observer)
Set observer.
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
static bool isRequestForSimObjTerrainProbe(DWORD requestId)
Request for probe (elevation)?
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.
CSimulatorFsxCommon(const swift::misc::simulation::CSimulatorPluginInfo &info, swift::misc::simulation::IOwnAircraftProvider *ownAircraftProvider, swift::misc::simulation::IRemoteAircraftProvider *remoteAircraftProvider, swift::misc::network::IClientProvider *clientProvider, QObject *parent=nullptr)
Constructor, parameters as in.
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.
static void CALLBACK SimConnectProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
SimConnect callback.
virtual bool connectTo()
Connect to simulator.
virtual void startImpl()
Plugin specific implementation to start listener.
P3D Simulator Implementation.
static void CALLBACK SimConnectProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
SimConnect Callback.
CSimulatorP3D(const swift::misc::simulation::CSimulatorPluginInfo &info, swift::misc::simulation::IOwnAircraftProvider *ownAircraftProvider, swift::misc::simulation::IRemoteAircraftProvider *remoteAircraftProvider, swift::misc::network::IClientProvider *clientProvider, QObject *parent=nullptr)
Constructor, parameters as in.
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.
const char * constData() const const
bool isEmpty() const const
QObject * parent() const const
bool isEmpty() const const
QByteArray toLatin1() const const
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.