mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #808, set internals object for FSX
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/simulation/fscommon/bcdconversions.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
#include "blackmisc/simulation/fsx/fsxsimulatorinternals.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackmisc/aviation/airportlist.h"
|
||||
@@ -50,7 +49,6 @@ namespace BlackSimPlugin
|
||||
Q_ASSERT_X(ownAircraftProvider, Q_FUNC_INFO, "Missing provider");
|
||||
Q_ASSERT_X(remoteAircraftProvider, Q_FUNC_INFO, "Missing provider");
|
||||
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object");
|
||||
this->m_simulatorSetup = CFsxSimulatorInternals::getInitializedInternals();
|
||||
this->m_realityBubbleTimer.setInterval(20 * 1000);
|
||||
connect(&m_realityBubbleTimer, &QTimer::timeout, this, &CSimulatorFsx::ps_addAircraftCurrentlyOutOfBubble);
|
||||
|
||||
@@ -310,7 +308,12 @@ namespace BlackSimPlugin
|
||||
void CSimulatorFsx::setSimConnected()
|
||||
{
|
||||
m_simConnected = true;
|
||||
this->initInternalsObject();
|
||||
emitSimulatorCombinedStatus();
|
||||
|
||||
// Internals depends on sim data which take a while to be read
|
||||
// this is a trich and I re-init again after a while (which is not really expensive)
|
||||
QTimer::singleShot(1000, this, [this] { this->initInternalsObject(); });
|
||||
}
|
||||
|
||||
void CSimulatorFsx::onSimRunning()
|
||||
@@ -1037,6 +1040,18 @@ namespace BlackSimPlugin
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorFsx::initInternalsObject()
|
||||
{
|
||||
CSimulatorFsCommon::initInternalsObject();
|
||||
CSimulatorInternals s = this->m_simulatorInternals;
|
||||
const QString fsxPath = CFsCommonUtil::fsxDirFromRegistry(); // can be empty for remote FSX
|
||||
if (!fsxPath.isEmpty()) { s.setSimulatorInstallationDirectory(fsxPath); }
|
||||
|
||||
s.setValue("fsx/simConnectCfgFilename", CSimConnectUtilities::getLocalSimConnectCfgFilename());
|
||||
s.setValue("fsx/simConnectVersion", this->m_simConnectVersion);
|
||||
this->m_simulatorInternals = s;
|
||||
}
|
||||
|
||||
void CSimulatorFsx::reset()
|
||||
{
|
||||
if (m_simconnectTimerId >= 0) { killTimer(m_simconnectTimerId); }
|
||||
|
||||
@@ -124,11 +124,18 @@ namespace BlackSimPlugin
|
||||
const CSimConnectObjects &getSimConnectObjects() const { return m_simConnectObjects; }
|
||||
|
||||
protected:
|
||||
//! \copydoc BlackCore::ISimulator::isConnected()
|
||||
//! \name Interface overrides
|
||||
//! @{
|
||||
virtual bool isConnected() const override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::isSimulating
|
||||
virtual bool isSimulating() const override;
|
||||
//! @}
|
||||
|
||||
//! \name Base class overrides
|
||||
//! @{
|
||||
virtual void reset() override;
|
||||
virtual void clearAllAircraft() override;
|
||||
virtual void initInternalsObject();
|
||||
//! @}
|
||||
|
||||
//! Timer event (our SimConnect event loop), runs ps_dispatch
|
||||
//! \sa m_simconnectTimerId
|
||||
@@ -192,12 +199,6 @@ namespace BlackSimPlugin
|
||||
//! Reload weather settings
|
||||
void reloadWeatherSettings();
|
||||
|
||||
//! Reset values when restarted
|
||||
virtual void reset() override;
|
||||
|
||||
//! Clear all aircraft lists
|
||||
virtual void clearAllAircraft() override;
|
||||
|
||||
//! FSX position as string
|
||||
static QString fsxPositionToString(const SIMCONNECT_DATA_INITPOSITION &position);
|
||||
|
||||
@@ -206,6 +207,7 @@ namespace BlackSimPlugin
|
||||
|
||||
static constexpr int SkipUpdateCyclesForCockpit = 10; //!< skip x cycles before updating cockpit again
|
||||
static constexpr int IgnoreReceiveExceptions = 10; //!< skip exceptions when displayed more than x times
|
||||
QString m_simConnectVersion; //!< SimConnect version
|
||||
bool m_simConnected = false; //!< Is simulator connected?
|
||||
bool m_simSimulating = false; //!< Simulator running?
|
||||
bool m_useSbOffsets = true; //!< with SB offsets
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "simconnectdatadefinition.h"
|
||||
#include "blackmisc/simulation/fscommon/bcdconversions.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
#include "blackmisc/simulation/fsx/fsxsimulatorinternals.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/aviation/airportlist.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
@@ -40,10 +39,10 @@ namespace BlackSimPlugin
|
||||
case SIMCONNECT_RECV_ID_OPEN:
|
||||
{
|
||||
SIMCONNECT_RECV_OPEN *event = (SIMCONNECT_RECV_OPEN *)pData;
|
||||
simulatorFsx->simulatorDetails = QString("Open: AppName=\"%1\" AppVersion=%2.%3.%4.%5 SimConnectVersion=%6.%7.%8.%9")
|
||||
.arg(event->szApplicationName)
|
||||
.arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor)
|
||||
.arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor);
|
||||
simulatorFsx->m_simulatorVersion = QString("%1.%2.%3.%4").arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor);
|
||||
simulatorFsx->m_simConnectVersion = QString("%1.%2.%3.%4").arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor);
|
||||
simulatorFsx->m_simulatorName = QString(event->szApplicationName);
|
||||
simulatorFsx->m_simulatorDetails = QString("Open: AppName=\"%1\" AppVersion=%2 SimConnectVersion=%3").arg(simulatorFsx->m_simulatorName, simulatorFsx->m_simulatorVersion, simulatorFsx->m_simConnectVersion);
|
||||
CLogMessage(static_cast<CSimulatorFsx *>(nullptr)).info("Connect to FSX: %1") << sApp->swiftVersionString();
|
||||
simulatorFsx->setSimConnected();
|
||||
break;
|
||||
@@ -52,10 +51,10 @@ namespace BlackSimPlugin
|
||||
{
|
||||
if (!simulatorFsx->stillDisplayReceiveExceptions()) { break; }
|
||||
SIMCONNECT_RECV_EXCEPTION *exception = (SIMCONNECT_RECV_EXCEPTION *)pData;
|
||||
const int exceptionId = static_cast<int>(exception->dwException);
|
||||
const int sendId = static_cast<int>(exception->dwSendID);
|
||||
const int index = static_cast<int>(exception->dwIndex);
|
||||
const int data = static_cast<int>(cbData);
|
||||
const DWORD exceptionId = exception->dwException;
|
||||
const DWORD sendId = exception->dwSendID;
|
||||
const DWORD index = exception->dwIndex;
|
||||
const DWORD data = cbData;
|
||||
QString ex;
|
||||
ex.sprintf("Exception=%d SendID=%d Index=%d cbData=%d", exceptionId, sendId, index, data);
|
||||
switch (exceptionId)
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "blackcore/context/contextsimulator.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/simulation/fsx/fsxsimulatorinternals.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
#include <QFileInfo>
|
||||
#include <QDesktopServices>
|
||||
@@ -50,27 +49,26 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimConnectSettingsComponent::openSimConnectCfgFile()
|
||||
{
|
||||
QFileInfo info(CSimConnectUtilities::getLocalSimConnectCfgFilename());
|
||||
QString path = QDir::toNativeSeparators(info.absolutePath());
|
||||
const QFileInfo info(CSimConnectUtilities::getLocalSimConnectCfgFilename());
|
||||
const QString path = QDir::toNativeSeparators(info.absolutePath());
|
||||
QDesktopServices::openUrl(QUrl(QStringLiteral("file:///") % path));
|
||||
}
|
||||
|
||||
void CSimConnectSettingsComponent::deleteSimConnectCfgFile()
|
||||
{
|
||||
QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
|
||||
bool result = sGui->getIContextApplication()->removeFile(fileName);
|
||||
const QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
|
||||
const bool result = sGui->getIContextApplication()->removeFile(fileName);
|
||||
if (result)
|
||||
{
|
||||
QMessageBox::information(qApp->activeWindow(), tr("File deleted"),
|
||||
tr("File %1 deleted successfully.").arg(fileName));
|
||||
}
|
||||
|
||||
checkSimConnectCfgFile();
|
||||
}
|
||||
|
||||
void CSimConnectSettingsComponent::checkSimConnectCfgFile()
|
||||
{
|
||||
QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
|
||||
const QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
|
||||
if (sGui->getIContextApplication()->existsFile(fileName))
|
||||
{
|
||||
ui->le_SettingsFsxExistsSimconncetCfg->setText(fileName);
|
||||
@@ -83,8 +81,8 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimConnectSettingsComponent::testSimConnectConnection()
|
||||
{
|
||||
QString address = ui->le_SettingsFsxAddress->text().trimmed();
|
||||
QString port = ui->le_SettingsFsxPort->text().trimmed();
|
||||
const QString address = ui->le_SettingsFsxAddress->text().trimmed();
|
||||
const QString port = ui->le_SettingsFsxPort->text().trimmed();
|
||||
|
||||
if (address.isEmpty() || port.isEmpty())
|
||||
{
|
||||
@@ -145,7 +143,8 @@ namespace BlackSimPlugin
|
||||
|
||||
if (sGui->getIContextSimulator())
|
||||
{
|
||||
fileName = sGui->getIContextSimulator()->getSimulatorInternals().getStringValue(CFsxSimulatorInternals::KeyLocalSimConnectCfgFilename());
|
||||
const BlackMisc::Simulation::CSimulatorInternals internals(sGui->getIContextSimulator()->getSimulatorInternals());
|
||||
fileName = internals.getStringValue("fsx/simConnectCfgFilename");
|
||||
}
|
||||
|
||||
if (fileName.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user