mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
committed by
Klaus Basan
parent
f509e600b4
commit
9bc0226fd1
22
src/plugins/simulator/fsx/simconnect_object.cpp
Normal file
22
src/plugins/simulator/fsx/simconnect_object.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "simconnect_object.h"
|
||||
#include "blackcore/interpolator_linear.h"
|
||||
|
||||
using namespace BlackCore;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
namespace Fsx
|
||||
{
|
||||
CSimConnectObject::CSimConnectObject() :
|
||||
m_interpolator(new CInterpolatorLinear()),
|
||||
m_requestId(-1),
|
||||
m_objectId(-1)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
84
src/plugins/simulator/fsx/simconnect_object.h
Normal file
84
src/plugins/simulator/fsx/simconnect_object.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BLACKSIMPLUGIN_SIMCONNECT_OBJECT_H
|
||||
#define BLACKSIMPLUGIN_SIMCONNECT_OBJECT_H
|
||||
|
||||
#include "blackmisc/avcallsign.h"
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
class IInterpolator;
|
||||
}
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
namespace Fsx
|
||||
{
|
||||
//! \brief Class representing a Simconnect object
|
||||
class CSimConnectObject
|
||||
{
|
||||
public:
|
||||
|
||||
//! \brief Constructor
|
||||
CSimConnectObject();
|
||||
|
||||
//! \brief Destructor
|
||||
~CSimConnectObject() {}
|
||||
|
||||
/*!
|
||||
* \brief Set callsign
|
||||
* \param callsign
|
||||
*/
|
||||
void setCallsign(const BlackMisc::Aviation::CCallsign &callsign) { m_callsign = callsign; }
|
||||
|
||||
/*!
|
||||
* \brief Get Callsign
|
||||
* \return
|
||||
*/
|
||||
BlackMisc::Aviation::CCallsign getCallsign() const { return m_callsign; }
|
||||
|
||||
/*!
|
||||
* \brief Set Simconnect request id
|
||||
* \param id
|
||||
*/
|
||||
void setRequestId(int id) { m_requestId = id; }
|
||||
|
||||
/*!
|
||||
* \brief Get Simconnect request id
|
||||
* \return
|
||||
*/
|
||||
int getRequestId() const { return m_requestId; }
|
||||
|
||||
/*!
|
||||
* \brief Set Simconnect object id
|
||||
* \param id
|
||||
*/
|
||||
void setObjectId(int id) { m_objectId = id; }
|
||||
|
||||
/*!
|
||||
* \brief Set Simconnect object id
|
||||
* \return
|
||||
*/
|
||||
int getObjectId() const { return m_objectId; }
|
||||
|
||||
/*!
|
||||
* \brief Get interpolator
|
||||
* \return
|
||||
*/
|
||||
QSharedPointer<BlackCore::IInterpolator> getInterpolator() const { return m_interpolator; }
|
||||
|
||||
private:
|
||||
|
||||
BlackMisc::Aviation::CCallsign m_callsign;
|
||||
QSharedPointer<BlackCore::IInterpolator> m_interpolator;
|
||||
int m_requestId;
|
||||
int m_objectId;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
@@ -137,15 +137,15 @@ namespace BlackSimPlugin
|
||||
initialPosition.Airspeed = 0;
|
||||
initialPosition.OnGround = 0;
|
||||
|
||||
SimConnectObject simObj;
|
||||
simObj.m_callsign = callsign;
|
||||
simObj.m_requestId = m_nextObjID;
|
||||
simObj.m_objectId = 0;
|
||||
simObj.m_interpolator.addAircraftSituation(initialSituation);
|
||||
CSimConnectObject simObj;
|
||||
simObj.setCallsign(callsign);
|
||||
simObj.setRequestId(m_nextObjID);
|
||||
simObj.setObjectId(0);
|
||||
simObj.getInterpolator()->addAircraftSituation(initialSituation);
|
||||
m_simConnectObjects.insert(callsign, simObj);
|
||||
++m_nextObjID;
|
||||
|
||||
HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, "Boeing 737-800 Paint1", callsign.toQString().left(12).toLatin1().constData(), initialPosition, simObj.m_requestId);
|
||||
HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, "Boeing 737-800 Paint1", callsign.toQString().left(12).toLatin1().constData(), initialPosition, simObj.getRequestId());
|
||||
Q_UNUSED(hr);
|
||||
}
|
||||
|
||||
@@ -157,8 +157,8 @@ namespace BlackSimPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
SimConnectObject simObj = m_simConnectObjects.value(callsign);
|
||||
simObj.m_interpolator.addAircraftSituation(situation);
|
||||
CSimConnectObject simObj = m_simConnectObjects.value(callsign);
|
||||
simObj.getInterpolator()->addAircraftSituation(situation);
|
||||
m_simConnectObjects.insert(callsign, simObj);
|
||||
}
|
||||
|
||||
@@ -320,16 +320,16 @@ namespace BlackSimPlugin
|
||||
|
||||
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataDefinitionGearHandlePosition, objectID, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(gearHandle), &gearHandle);
|
||||
|
||||
SimConnectObject simObject;
|
||||
CSimConnectObject simObject;
|
||||
foreach(simObject, m_simConnectObjects)
|
||||
{
|
||||
if (simObject.m_requestId == static_cast<int>(requestID))
|
||||
if (simObject.getRequestId()== static_cast<int>(requestID))
|
||||
{
|
||||
simObject.m_objectId = objectID;
|
||||
simObject.setObjectId(objectID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_simConnectObjects.insert(simObject.m_callsign, simObject);
|
||||
m_simConnectObjects.insert(simObject.getCallsign(), simObject);
|
||||
|
||||
}
|
||||
|
||||
@@ -381,13 +381,13 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFsx::update()
|
||||
{
|
||||
foreach(SimConnectObject simObj, m_simConnectObjects)
|
||||
foreach(CSimConnectObject simObj, m_simConnectObjects)
|
||||
{
|
||||
if (simObj.m_interpolator.hasEnoughAircraftSituations())
|
||||
{
|
||||
|
||||
if (simObj.getInterpolator()->hasEnoughAircraftSituations())
|
||||
{
|
||||
SIMCONNECT_DATA_INITPOSITION position;
|
||||
CAircraftSituation situation = simObj.m_interpolator.getCurrentSituation();
|
||||
CAircraftSituation situation = simObj.getInterpolator()->getCurrentSituation();
|
||||
position.Latitude = situation.latitude().value();
|
||||
position.Longitude = situation.longitude().value();
|
||||
position.Altitude = situation.getAltitude().value(CLengthUnit::ft());
|
||||
@@ -403,12 +403,12 @@ namespace BlackSimPlugin
|
||||
DataDefinitionGearHandlePosition gearHandle;
|
||||
gearHandle.gearHandlePosition = 1;
|
||||
|
||||
if (simObj.m_objectId != 0)
|
||||
if (simObj.getObjectId() != 0)
|
||||
{
|
||||
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataDefinitionRemoteAircraftSituation, simObj.m_objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(ddAircraftSituation), &ddAircraftSituation);
|
||||
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataDefinitionRemoteAircraftSituation, simObj.getObjectId(), SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(ddAircraftSituation), &ddAircraftSituation);
|
||||
|
||||
// With the following SimConnect call all aircrafts loose their red tag. No idea why though.
|
||||
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataDefinitionGearHandlePosition, simObj.m_objectId, SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(gearHandle), &gearHandle);
|
||||
SimConnect_SetDataOnSimObject(m_hSimConnect, CSimConnectDataDefinition::DataDefinitionGearHandlePosition, simObj.getObjectId(), SIMCONNECT_DATA_SET_FLAG_DEFAULT, 0, sizeof(DataDefinitionGearHandlePosition), &gearHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define BLACKSIMPLUGIN_SIMULATOR_FSX_H
|
||||
|
||||
#include "simconnect_datadefinition.h"
|
||||
#include "simconnect_object.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackcore/interpolator_linear.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
@@ -143,13 +144,6 @@ namespace BlackSimPlugin
|
||||
|
||||
private:
|
||||
|
||||
struct SimConnectObject
|
||||
{
|
||||
BlackMisc::Aviation::CCallsign m_callsign;
|
||||
BlackCore::CInterpolatorLinear m_interpolator;
|
||||
int m_requestId;
|
||||
int m_objectId;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Initialize SimConnect system events
|
||||
@@ -171,7 +165,7 @@ namespace BlackSimPlugin
|
||||
uint m_nextObjID;
|
||||
BlackSim::CSimulatorInfo m_simulatorInfo;
|
||||
BlackMisc::Aviation::CAircraft m_ownAircraft; //!< Object representing our own aircraft from simulator
|
||||
QHash<BlackMisc::Aviation::CCallsign, SimConnectObject> m_simConnectObjects;
|
||||
QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects;
|
||||
|
||||
int m_simconnectTimerId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user