mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #395, changed own aircraft provider to thread safe member functions
(similar to remote aircraft provider)
* removed references
* made own aircraft context thread safe (reg. own aircrat data)
* removed the read only versions of the provider
* adjusted consuming methods
* renamed some functions ("ownAircraft...") to avoid ambiguity (with remote aircraft)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
7200f2e29c
commit
3ecf37dda4
@@ -215,7 +215,7 @@ namespace BlackSimPlugin
|
||||
{
|
||||
if (m_useFsuipc && m_fsuipc)
|
||||
{
|
||||
CSimulatedAircraft fsuipcAircraft(ownAircraft());
|
||||
CSimulatedAircraft fsuipcAircraft(getOwnAircraft());
|
||||
bool ok = m_fsuipc->read(fsuipcAircraft, true, true, true);
|
||||
if (ok)
|
||||
{
|
||||
@@ -244,7 +244,7 @@ namespace BlackSimPlugin
|
||||
{
|
||||
MPPositionVelocity mpPositionVelocity;
|
||||
MultiPlayerPacketParser::readMessage(message, mpPositionVelocity);
|
||||
ownAircraft().setSituation(aircraftSituationfromFS9(mpPositionVelocity));
|
||||
updateOwnSituation(aircraftSituationfromFS9(mpPositionVelocity));
|
||||
break;
|
||||
}
|
||||
case CFs9Sdk::MPCHAT_PACKET_ID_CHAT_TEXT_SEND:
|
||||
@@ -261,7 +261,7 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFs9::updateOwnAircraftFromSimulator(const CAircraft &simDataOwnAircraft)
|
||||
{
|
||||
this->providerUpdateCockpit(
|
||||
this->updateCockpit(
|
||||
simDataOwnAircraft.getCom1System(),
|
||||
simDataOwnAircraft.getCom2System(),
|
||||
simDataOwnAircraft.getTransponder(),
|
||||
|
||||
@@ -77,20 +77,20 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFsCommon::setOwnAircraftModel(const QString &modelName)
|
||||
{
|
||||
CAircraftModel model = ownAircraft().getModel();
|
||||
CAircraftModel model = getOwnAircraftModel();
|
||||
model.setModelString(modelName);
|
||||
this->setOwnAircraftModel(model);
|
||||
}
|
||||
|
||||
void CSimulatorFsCommon::setOwnAircraftModel(const BlackMisc::Simulation::CAircraftModel &model)
|
||||
{
|
||||
if (ownAircraft().getModel() != model)
|
||||
if (getOwnAircraftModel() != model)
|
||||
{
|
||||
CAircraftModel newModel(model);
|
||||
newModel.setModelType(CAircraftModel::TypeOwnSimulatorModel);
|
||||
CSimulatorFsCommon::reverseLookupIcaoData(newModel);
|
||||
ownAircraft().setModel(newModel);
|
||||
emit ownAircraftModelChanged(ownAircraft());
|
||||
updateOwnModel(newModel);
|
||||
emit ownAircraftModelChanged(getOwnAircraft());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -358,6 +358,7 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFsx::updateOwnAircraftFromSimulator(DataDefinitionOwnAircraft simulatorOwnAircraft)
|
||||
{
|
||||
CSimulatedAircraft myAircraft(getOwnAircraft());
|
||||
BlackMisc::Geo::CCoordinateGeodetic position;
|
||||
position.setLatitude(CLatitude(simulatorOwnAircraft.latitude, CAngleUnit::deg()));
|
||||
position.setLongitude(CLongitude(simulatorOwnAircraft.longitude, CAngleUnit::deg()));
|
||||
@@ -369,7 +370,6 @@ namespace BlackSimPlugin
|
||||
aircraftSituation.setHeading(CHeading(simulatorOwnAircraft.trueHeading, CHeading::True, CAngleUnit::deg()));
|
||||
aircraftSituation.setGroundspeed(CSpeed(simulatorOwnAircraft.velocity, CSpeedUnit::kts()));
|
||||
aircraftSituation.setAltitude(CAltitude(simulatorOwnAircraft.altitude, CAltitude::MeanSeaLevel, CLengthUnit::ft()));
|
||||
ownAircraft().setSituation(aircraftSituation);
|
||||
|
||||
CAircraftLights lights(simulatorOwnAircraft.lightStrobe,
|
||||
simulatorOwnAircraft.lightLanding,
|
||||
@@ -378,8 +378,8 @@ namespace BlackSimPlugin
|
||||
simulatorOwnAircraft.lightNav,
|
||||
simulatorOwnAircraft.lightLogo);
|
||||
|
||||
QList<bool> helperList { simulatorOwnAircraft.engine1Combustion != 0, simulatorOwnAircraft.engine2Combustion != 0,
|
||||
simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0
|
||||
QList<bool> helperList {simulatorOwnAircraft.engine1Combustion != 0, simulatorOwnAircraft.engine2Combustion != 0,
|
||||
simulatorOwnAircraft.engine3Combustion != 0, simulatorOwnAircraft.engine4Combustion != 0
|
||||
};
|
||||
|
||||
CAircraftEngineList engines;
|
||||
@@ -394,33 +394,37 @@ namespace BlackSimPlugin
|
||||
engines,
|
||||
simulatorOwnAircraft.simOnGround);
|
||||
|
||||
ownAircraft().setParts(parts);
|
||||
|
||||
CComSystem com1 = ownAircraft().getCom1System(); // set defaults
|
||||
CComSystem com2 = ownAircraft().getCom2System();
|
||||
CTransponder transponder = ownAircraft().getTransponder();
|
||||
// set values
|
||||
updateOwnSituation(aircraftSituation);
|
||||
updateOwnParts(parts);
|
||||
|
||||
// When I change cockpit values in the sim (from GUI to simulator, not originating from simulator)
|
||||
// it takes a little while before these values are set in the simulator.
|
||||
// To avoid jitters, I wait some update cylces to stabilize the values
|
||||
if (m_skipCockpitUpdateCycles < 1)
|
||||
{
|
||||
// defaults
|
||||
CComSystem com1(myAircraft.getCom1System()); // set defaults
|
||||
CComSystem com2(myAircraft.getCom2System());
|
||||
CTransponder transponder(myAircraft.getTransponder());
|
||||
|
||||
// updates
|
||||
com1.setFrequencyActive(CFrequency(simulatorOwnAircraft.com1ActiveMHz, CFrequencyUnit::MHz()));
|
||||
com1.setFrequencyStandby(CFrequency(simulatorOwnAircraft.com1StandbyMHz, CFrequencyUnit::MHz()));
|
||||
bool changedCom1 = ownAircraft().getCom1System() != com1;
|
||||
bool changedCom1 = myAircraft.getCom1System() != com1;
|
||||
this->m_simCom1 = com1;
|
||||
|
||||
com2.setFrequencyActive(CFrequency(simulatorOwnAircraft.com2ActiveMHz, CFrequencyUnit::MHz()));
|
||||
com2.setFrequencyStandby(CFrequency(simulatorOwnAircraft.com2StandbyMHz, CFrequencyUnit::MHz()));
|
||||
bool changedCom2 = ownAircraft().getCom2System() != com2;
|
||||
bool changedCom2 = myAircraft.getCom2System() != com2;
|
||||
this->m_simCom2 = com2;
|
||||
|
||||
transponder.setTransponderCode(simulatorOwnAircraft.transponderCode);
|
||||
bool changedXpr = (ownAircraft().getTransponderCode() != transponder.getTransponderCode());
|
||||
bool changedXpr = (myAircraft.getTransponderCode() != transponder.getTransponderCode());
|
||||
|
||||
if (changedCom1 || changedCom2 || changedXpr)
|
||||
{
|
||||
this->providerUpdateCockpit(com1, com2, transponder, simulatorOriginator());
|
||||
this->updateCockpit(com1, com2, transponder, simulatorOriginator());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -440,11 +444,12 @@ namespace BlackSimPlugin
|
||||
{
|
||||
newMode = sbDataArea.isStandby() ? CTransponder::StateStandby : CTransponder::ModeC;
|
||||
}
|
||||
bool changed = (this->ownAircraft().getTransponderMode() != newMode);
|
||||
CSimulatedAircraft myAircraft(this->getOwnAircraft());
|
||||
bool changed = (myAircraft.getTransponderMode() != newMode);
|
||||
if (!changed) { return; }
|
||||
CTransponder xpdr = this->ownAircraft().getTransponder();
|
||||
CTransponder xpdr = myAircraft.getTransponder();
|
||||
xpdr.setTransponderMode(newMode);
|
||||
this->providerUpdateCockpit(ownAircraft().getCom1System(), ownAircraft().getCom2System(), xpdr, this->simulatorOriginator());
|
||||
this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), xpdr, this->simulatorOriginator());
|
||||
}
|
||||
|
||||
void CSimulatorFsx::setSimConnectObjectID(DWORD requestID, DWORD objectID)
|
||||
@@ -476,7 +481,7 @@ namespace BlackSimPlugin
|
||||
SimConnect_CallDispatch(m_hSimConnect, SimConnectProc, this);
|
||||
if (m_useFsuipc && m_fsuipc)
|
||||
{
|
||||
CSimulatedAircraft fsuipcAircraft(ownAircraft());
|
||||
CSimulatedAircraft fsuipcAircraft(getOwnAircraft());
|
||||
//! \todo split in high / low frequency reads
|
||||
bool ok = m_fsuipc->read(fsuipcAircraft, true, true, true);
|
||||
if (ok)
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace BlackSimPlugin
|
||||
protected:
|
||||
//! Timer event (our SimConnect event loop), runs \sa ps_dispatch
|
||||
//! \sa m_simconnectTimerId
|
||||
virtual void timerEvent(QTimerEvent *event);
|
||||
virtual void timerEvent(QTimerEvent *event) override;
|
||||
|
||||
private slots:
|
||||
//! Dispatch SimConnect messages
|
||||
@@ -220,8 +220,7 @@ namespace BlackSimPlugin
|
||||
virtual void stop() override;
|
||||
|
||||
private:
|
||||
QTimer *m_timer;
|
||||
|
||||
QTimer *m_timer { nullptr };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace BlackSimPlugin
|
||||
case SIMCONNECT_RECV_ID_AIRPORT_LIST:
|
||||
{
|
||||
const CLength maxDistance(200.0, CLengthUnit::NM());
|
||||
const CCoordinateGeodetic posAircraft = simulatorFsx->ownAircraft().getPosition();
|
||||
const CCoordinateGeodetic posAircraft(simulatorFsx->getOwnAircraftPosition());
|
||||
SIMCONNECT_RECV_AIRPORT_LIST *pAirportList = (SIMCONNECT_RECV_AIRPORT_LIST *) pData;
|
||||
for (unsigned i = 0; i < pAirportList->dwArraySize; ++i)
|
||||
{
|
||||
|
||||
@@ -111,11 +111,16 @@ namespace BlackSimPlugin
|
||||
situation.setPitch({ m_xplaneData.pitch, CAngleUnit::deg() });
|
||||
situation.setBank({ m_xplaneData.roll, CAngleUnit::deg() });
|
||||
situation.setGroundspeed({ m_xplaneData.groundspeed, CSpeedUnit::m_s() });
|
||||
ownAircraft().setSituation(situation);
|
||||
ownAircraft().setIcaoInfo(Aviation::CAircraftIcao { m_xplaneData.aircraftIcaoCode });
|
||||
ownAircraft().setCom1System(Aviation::CComSystem::getCom1System({ m_xplaneData.com1Active, CFrequencyUnit::kHz() }, { m_xplaneData.com1Standby, CFrequencyUnit::kHz() }));
|
||||
ownAircraft().setCom2System(Aviation::CComSystem::getCom2System({ m_xplaneData.com2Active, CFrequencyUnit::kHz() }, { m_xplaneData.com2Standby, CFrequencyUnit::kHz() }));
|
||||
ownAircraft().setTransponder(Aviation::CTransponder::getStandardTransponder(m_xplaneData.xpdrCode, xpdrMode(m_xplaneData.xpdrMode, m_xplaneData.xpdrIdent)));
|
||||
|
||||
// updates
|
||||
updateOwnIcaoData(Aviation::CAircraftIcao { m_xplaneData.aircraftIcaoCode });
|
||||
updateOwnSituation(situation);
|
||||
updateCockpit(
|
||||
Aviation::CComSystem::getCom1System({ m_xplaneData.com1Active, CFrequencyUnit::kHz() }, { m_xplaneData.com1Standby, CFrequencyUnit::kHz() }),
|
||||
Aviation::CComSystem::getCom2System({ m_xplaneData.com2Active, CFrequencyUnit::kHz() }, { m_xplaneData.com2Standby, CFrequencyUnit::kHz() }),
|
||||
Aviation::CTransponder::getStandardTransponder(m_xplaneData.xpdrCode, xpdrMode(m_xplaneData.xpdrMode, m_xplaneData.xpdrIdent)),
|
||||
simulatorOriginator()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +156,7 @@ namespace BlackSimPlugin
|
||||
{ m_xplaneData.gearReployRatio > 0 }, { static_cast<int>(m_xplaneData.flapsReployRatio * 100) },
|
||||
{ m_xplaneData.speedBrakeRatio > 0.5 }, engines, { m_xplaneData.onGroundAll }
|
||||
};
|
||||
ownAircraft().setParts(parts);
|
||||
updateOwnParts(parts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,14 +241,16 @@ namespace BlackSimPlugin
|
||||
//! \todo XP, change as appropriate
|
||||
// try to set correct model and ICAO values here
|
||||
// thy show up in GUI
|
||||
CAircraftModel model(ownAircraft().getModel());
|
||||
CAircraftModel model(getOwnAircraftModel());
|
||||
model.setModelType(CAircraftModel::TypeOwnSimulatorModel);
|
||||
model.setFileName(path + "/" + filename);
|
||||
CAircraftIcao aircraftIcao(icao);
|
||||
aircraftIcao.setLivery(livery);
|
||||
ownAircraft().setIcaoInfo(aircraftIcao);
|
||||
ownAircraft().setModel(model);
|
||||
emit ownAircraftModelChanged(ownAircraft());
|
||||
|
||||
// updates
|
||||
updateOwnIcaoData(aircraftIcao);
|
||||
updateOwnModel(model);
|
||||
emit ownAircraftModelChanged(getOwnAircraft());
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::displayStatusMessage(const BlackMisc::CStatusMessage &message) const
|
||||
|
||||
Reference in New Issue
Block a user