refactor(fs): Move FSUIPC from fscommon to FS9

With default settings, FSUIPC was not really used
by FS simulators (except FS9) as the transponder
mode readout was done with SB offsets through SimConnect.
For simplification, this removes FSUIPC from fscommon and moves it to FS9.
Therefor this also removes the option for FSX/P3D users to toggle FSUIPC.
This commit is contained in:
Lars Toenning
2024-04-11 23:25:40 +02:00
parent 93af5fef1c
commit 18d0b1eefc
9 changed files with 14 additions and 148 deletions

View File

@@ -45,7 +45,8 @@ namespace BlackSimPlugin::Fs9
IClientProvider *clientProvider,
QObject *parent) : CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent),
m_fs9Host(fs9Host),
m_lobbyClient(lobbyClient)
m_lobbyClient(lobbyClient),
m_fsuipc(new CFsuipc(this))
{
// disabled CG/elevation parts
this->setSimulationProviderEnabled(false, false);
@@ -73,7 +74,8 @@ namespace BlackSimPlugin::Fs9
Q_ASSERT_X(m_fsuipc, Q_FUNC_INFO, "No FSUIPC");
m_connectionHostMessages = connect(m_fs9Host.data(), &CFs9Host::customPacketReceived, this, &CSimulatorFs9::processFs9Message);
useFsuipc(true);
m_fsuipc->open();
this->initSimulatorInternals();
m_timerId = startTimer(50);
return true;
@@ -88,7 +90,9 @@ namespace BlackSimPlugin::Fs9
safeKillTimer();
disconnectAllClients();
// disconnect FSUIPC and status
if (m_fsuipc) { m_fsuipc->close(); }
// emit status
CSimulatorFsCommon::disconnectFrom();
m_simConnected = false;
emitSimulatorCombinedStatus();
@@ -246,7 +250,7 @@ namespace BlackSimPlugin::Fs9
void CSimulatorFs9::dispatch()
{
if (m_useFsuipc && m_fsuipc && m_fsuipc->isOpened())
if (m_fsuipc && m_fsuipc->isOpened())
{
CSimulatedAircraft fsuipcAircraft(getOwnAircraft());
const bool ok = m_fsuipc->read(fsuipcAircraft, true, true, true);
@@ -410,7 +414,7 @@ namespace BlackSimPlugin::Fs9
{
if (!m_simTimeSynced) { return; }
if (!this->isConnected()) { return; }
if (!m_useFsuipc || !m_fsuipc) { return; }
if (!m_fsuipc) { return; }
if (!m_fsuipc->isOpened()) { return; }
QDateTime myDateTime = QDateTime::currentDateTimeUtc();
@@ -442,7 +446,7 @@ namespace BlackSimPlugin::Fs9
return;
}
if (!m_useFsuipc || !m_fsuipc) { return; }
if (!m_fsuipc) { return; }
if (!m_fsuipc->isOpened()) { return; }
if (weatherGrid.isEmpty())
{

View File

@@ -16,6 +16,7 @@
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/pixmap.h"
#include "plugins/simulator/fscommon/fsuipc.h"
#include <QObject>
#include <QtPlugin>
#include <QList>
@@ -96,6 +97,7 @@ namespace BlackSimPlugin::Fs9
//! Sync time with user's computer
void synchronizeTime();
BlackSimPlugin::FsCommon::CFsuipc *m_fsuipc = nullptr; //!< FSUIPC
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
QMetaObject::Connection m_connectionHostMessages;
bool m_simConnected = false; //!< Is simulator connected?

View File

@@ -26,8 +26,7 @@ namespace BlackSimPlugin::FsCommon
IRemoteAircraftProvider *renderedAircraftProvider,
IWeatherGridProvider *weatherGridProvider,
IClientProvider *clientProvider,
QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, renderedAircraftProvider, weatherGridProvider, clientProvider, parent),
m_fsuipc(new CFsuipc(this))
QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, renderedAircraftProvider, weatherGridProvider, clientProvider, parent)
{
CSimulatorFsCommon::registerHelp();
}
@@ -38,26 +37,6 @@ namespace BlackSimPlugin::FsCommon
{
CSimulatorPluginCommon::initSimulatorInternals();
m_simulatorInternals.setSimulatorVersion(this->getSimulatorVersion());
m_simulatorInternals.setValue("fscommon/fsuipc", boolToOnOff(m_useFsuipc));
if (m_fsuipc)
{
const QString v(m_fsuipc->getVersion());
if (!v.isEmpty()) { m_simulatorInternals.setValue("fscommon/fsuipcversion", v); }
m_simulatorInternals.setValue("fscommon/fsuipcopen", boolToYesNo(m_fsuipc->isOpened()));
}
}
bool CSimulatorFsCommon::parseDetails(const CSimpleCommandParser &parser)
{
// .driver fsuipc on|off
if (parser.matchesPart(1, "fsuipc") && parser.hasPart(2))
{
const bool on = parser.toBool(2);
const bool s = this->useFsuipc(on);
CLogMessage(this, CLogCategories::cmdLine()).info(u"FSUIPC is '%1'") << boolToOnOff(s);
return s;
}
return CSimulatorPluginCommon::parseDetails(parser);
}
void CSimulatorFsCommon::reset()
@@ -72,13 +51,10 @@ namespace BlackSimPlugin::FsCommon
{
if (CSimpleCommandParser::registered("BlackSimPlugin::FsCommon::CSimulatorFsCommon")) { return; }
CSimpleCommandParser::registerCommand({ ".drv", "alias: .driver .plugin" });
CSimpleCommandParser::registerCommand({ ".drv fsuipc on|off", "FSUIPC on|off if applicable" });
}
bool CSimulatorFsCommon::disconnectFrom()
{
if (m_fsuipc) { m_fsuipc->close(); }
// reset flags
m_simPaused = false;
const bool r = CSimulatorPluginCommon::disconnectFrom();
@@ -86,29 +62,6 @@ namespace BlackSimPlugin::FsCommon
return r;
}
bool CSimulatorFsCommon::isFsuipcOpened() const
{
return m_fsuipc && m_fsuipc->isOpened();
}
bool CSimulatorFsCommon::useFsuipc(bool on)
{
if (!m_fsuipc) { return false; } // no FSUIPC available
if (m_useFsuipc == on) { return m_useFsuipc; } // nothing changed
m_useFsuipc = on;
if (on)
{
m_useFsuipc = m_fsuipc->open();
}
else
{
m_fsuipc->close();
}
this->initSimulatorInternals(); // update internals
return m_useFsuipc;
}
CTime CSimulatorFsCommon::getTimeSynchronizationOffset() const
{
return m_syncTimeOffset;

View File

@@ -6,7 +6,6 @@
#ifndef BLACKSIMPLUGIN_FSCOMMON_SIMULATORFSCOMMON_H
#define BLACKSIMPLUGIN_FSCOMMON_SIMULATORFSCOMMON_H
#include "plugins/simulator/fscommon/fsuipc.h"
#include "plugins/simulator/plugincommon/simulatorplugincommon.h"
#include "blackmisc/simulation/interpolator.h"
#include "blackmisc/simulation/fscommon/aircraftcfgparser.h"
@@ -29,12 +28,6 @@ namespace BlackSimPlugin::FsCommon
//! Destructor
virtual ~CSimulatorFsCommon() override;
//! FSUIPC connected?
bool isFsuipcOpened() const;
//! FSUIPC on/off, correctly disconnecting/connecting
bool useFsuipc(bool on);
// ---------------------- ISimulator ------------------
virtual bool disconnectFrom() override;
virtual bool isPaused() const override { return m_simPaused; }
@@ -59,22 +52,14 @@ namespace BlackSimPlugin::FsCommon
//! When swift DB data are read
virtual void onSwiftDbAirportsRead() override;
//! \ingroup swiftdotcommands
//! <pre>
//! .drv fsuipc on|off FSUIPC on/off
//! </pre>
virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser) override;
//! \copydoc BlackCore::ISimulator::reset
virtual void reset() override;
//! Register help
static void registerHelp();
CFsuipc *m_fsuipc = nullptr; //!< FSUIPC
int m_ownAircraftUpdateCycles = 0; //!< own aircraft updates, even with 50 updates/sec long enough even for 32bit
int m_skipCockpitUpdateCycles = 0; //!< skip some update cycles to allow changes in simulator cockpit to be set
bool m_useFsuipc = false; //!< use FSUIPC
bool m_simPaused = false; //!< simulator paused?
bool m_simTimeSynced = false; //!< time synchronized?
BlackMisc::PhysicalQuantities::CTime m_syncTimeOffset; //!< time offset

View File

@@ -30,7 +30,6 @@ namespace BlackSimPlugin::FsxCommon
connect(ui->cb_AddingAsSimulatedObject, &QCheckBox::released, this, &CFsxSettingsComponent::onSimulatedObjectChanged);
connect(ui->cb_TraceSimConnectCalls, &QCheckBox::released, this, &CFsxSettingsComponent::onSimConnectTraceChanged);
connect(ui->cb_EnableTerrainProbe, &QCheckBox::released, this, &CFsxSettingsComponent::onEnableTerrainProbeChanged);
connect(ui->cb_UseFsuipc, &QCheckBox::released, this, &CFsxSettingsComponent::onFsuipcChanged);
connect(ui->cb_SBOffsets, &QCheckBox::released, this, &CFsxSettingsComponent::onSBOffsetsChanged);
connect(ui->pb_CopyTerrainProbe, &QPushButton::released, this, &CFsxSettingsComponent::copyTerrainProbe);
connect(ui->pb_Refresh, &QPushButton::released, this, &CFsxSettingsComponent::refresh);
@@ -66,7 +65,6 @@ namespace BlackSimPlugin::FsxCommon
ui->cb_TraceSimConnectCalls->setChecked(fsxOrP3D->isTraceSendId());
ui->cb_EnableTerrainProbe->setChecked(fsxOrP3D->isUsingFsxTerrainProbe());
ui->cb_SBOffsets->setChecked(fsxOrP3D->isUsingSbOffsetValues());
ui->cb_UseFsuipc->setChecked(fsxOrP3D->isFsuipcOpened());
ui->cb_AddingAsSimulatedObject->setChecked(fsxOrP3D->isAddingAsSimulatedObjectEnabled());
}
@@ -74,7 +72,6 @@ namespace BlackSimPlugin::FsxCommon
ui->cb_TraceSimConnectCalls->setEnabled(localSim);
ui->cb_EnableTerrainProbe->setEnabled(localSim);
ui->cb_SBOffsets->setEnabled(localSim);
ui->cb_UseFsuipc->setEnabled(localSim);
const bool terrainProbe = CBuildConfig::isRunningOnWindowsNtPlatform() && (CBuildConfig::buildWordSize() == 32);
ui->cb_EnableTerrainProbe->setEnabled(terrainProbe);
@@ -102,13 +99,6 @@ namespace BlackSimPlugin::FsxCommon
fsxOrP3D->setUsingFsxTerrainProbe(ui->cb_EnableTerrainProbe->isChecked());
}
void CFsxSettingsComponent::onFsuipcChanged()
{
CSimulatorFsxCommon *fsxOrP3D = this->getFsxOrP3DSimulator();
if (!fsxOrP3D) { return; }
fsxOrP3D->useFsuipc(ui->cb_UseFsuipc->isChecked());
}
void CFsxSettingsComponent::onSBOffsetsChanged()
{
CSimulatorFsxCommon *fsxOrP3D = this->getFsxOrP3DSimulator();

View File

@@ -55,9 +55,6 @@ namespace BlackSimPlugin::FsxCommon
//! Using simulated objects
void onSimulatedObjectChanged();
//! FSUIPC setting changed
void onFsuipcChanged();
//! Offsets on/off
void onSBOffsetsChanged();

View File

@@ -51,13 +51,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cb_UseFsuipc">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="cb_AddingAsSimulatedObject">
<property name="text">
@@ -105,13 +98,6 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="lbl_UseFsuipc">
<property name="text">
<string>Enable FSUIPC support</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="cb_EnableTerrainProbe">
<property name="text">
@@ -140,7 +126,6 @@
</widget>
<tabstops>
<tabstop>cb_TraceSimConnectCalls</tabstop>
<tabstop>cb_UseFsuipc</tabstop>
<tabstop>cb_SBOffsets</tabstop>
<tabstop>cb_AddingAsSimulatedObject</tabstop>
<tabstop>cb_EnableTerrainProbe</tabstop>

View File

@@ -59,7 +59,6 @@ namespace BlackSimPlugin::FsxCommon
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object");
m_simObjectTimer.setInterval(AddPendingAircraftIntervalMs);
m_useFsuipc = false;
// default model will be set in derived class
CSimulatorFsxCommon::registerHelp();
@@ -69,7 +68,6 @@ namespace BlackSimPlugin::FsxCommon
CSimulatorFsxCommon::~CSimulatorFsxCommon()
{
this->disconnectFrom();
// fsuipc is disconnected in CSimulatorFsCommon
}
bool CSimulatorFsxCommon::isConnected() const
@@ -95,12 +93,6 @@ namespace BlackSimPlugin::FsxCommon
return false;
}
// FSUIPC too
if (m_useFsuipc)
{
m_fsuipc->open();
}
// set structures and move on
this->triggerAutoTraceSendId(); // we trace the init phase, so in case something goes wrong there
this->initEvents();
@@ -127,7 +119,7 @@ namespace BlackSimPlugin::FsxCommon
m_simConnected = false;
}
// emit status and disconnect FSUIPC
// emit status
return CSimulatorFsCommon::disconnectFrom();
}
@@ -181,7 +173,6 @@ namespace BlackSimPlugin::FsxCommon
if (newTransponder.getTransponderMode() != m_simTransponder.getTransponderMode())
{
// use one way to transfer XPDR ident/mode not both
if (m_useSbOffsets)
{
byte ident = newTransponder.isIdentifying() ? 1U : 0U; // 1 is ident
@@ -205,11 +196,6 @@ namespace BlackSimPlugin::FsxCommon
}
changed = true;
}
else if (m_useFsuipc && m_fsuipc)
{
m_fsuipc->write(newTransponder);
changed = true;
}
}
// avoid changes of cockpit back to old values due to an outdated read back value
@@ -959,18 +945,6 @@ namespace BlackSimPlugin::FsxCommon
this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), xpdr, this->identifier());
}
void CSimulatorFsxCommon::updateOwnAircraftFromSimulatorFsuipc(const CTransponder &xpdr)
{
if (!m_useFsuipc) { return; }
if (m_skipCockpitUpdateCycles > 0) { return; }
const CSimulatedAircraft myAircraft(this->getOwnAircraft());
const bool changed = (myAircraft.getTransponderMode() != xpdr.getTransponderMode());
if (!changed) { return; }
CTransponder myXpdr = myAircraft.getTransponder();
myXpdr.setTransponderMode(xpdr.getTransponderMode());
this->updateCockpit(myAircraft.getCom1System(), myAircraft.getCom2System(), myXpdr, this->identifier());
}
bool CSimulatorFsxCommon::simulatorReportedObjectAdded(DWORD objectId)
{
if (this->isShuttingDownOrDisconnected()) { return true; } // pretend everything is fine
@@ -1518,26 +1492,6 @@ namespace BlackSimPlugin::FsxCommon
return;
}
m_dispatchErrors = 0;
if (m_useFsuipc && m_fsuipc)
{
if (m_dispatchProcCount % 10 == 0)
{
// slow updates, here only when SB/SimConnect is disabled as those do the same thing
if (!m_useSbOffsets)
{
CSimulatedAircraft fsuipcAircraft(this->getOwnAircraft());
const bool ok = m_fsuipc->read(fsuipcAircraft, true, false, false);
if (ok)
{
this->updateOwnAircraftFromSimulatorFsuipc(fsuipcAircraft.getTransponder());
}
}
}
else
{
// fast
}
}
}
bool CSimulatorFsxCommon::physicallyAddRemoteAircraftImpl(const CSimulatedAircraft &newRemoteAircraft, CSimulatorFsxCommon::AircraftAddMode addMode, const CSimConnectObject &correspondingSimObject)

View File

@@ -480,10 +480,6 @@ namespace BlackSimPlugin::FsxCommon
//! \threadsafe
void updateOwnAircraftFromSimulator(const DataDefinitionClientAreaSb &sbDataArea);
//! Update from FSUIPC
//! \threadsafe
void updateOwnAircraftFromSimulatorFsuipc(const BlackMisc::Aviation::CTransponder &xpdr);
//! An AI aircraft was added in the simulator
bool simulatorReportedObjectAdded(DWORD objectId);