mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 01:35:45 +08:00
Make FSX works with ISimulatorListener.
SimConnect tries to connect to FSX every 5 seconds. TODO: Use WinAPI to wait for FSX process to show up
This commit is contained in:
committed by
Roland Winklmeier
parent
5b4c2377b6
commit
edc0646ab2
@@ -21,7 +21,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
void ISimulator::emitSimulatorCombinedStatus()
|
void ISimulator::emitSimulatorCombinedStatus()
|
||||||
{
|
{
|
||||||
quint8 status =
|
int status =
|
||||||
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
|
||||||
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
|
||||||
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0))
|
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0))
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Simulator combined status
|
//! Simulator combined status
|
||||||
void simulatorStatusChanged(quint8 status);
|
void simulatorStatusChanged(int status);
|
||||||
|
|
||||||
//! Emitted when own aircraft model has changed
|
//! Emitted when own aircraft model has changed
|
||||||
void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft);
|
void ownAircraftModelChanged(BlackMisc::Simulation::CSimulatedAircraft aircraft);
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ namespace BlackSim
|
|||||||
{
|
{
|
||||||
Q_ASSERT(json["IID"].toString() == "net.vatsim.PilotClient.BlackCore.SimulatorInterface");
|
Q_ASSERT(json["IID"].toString() == "net.vatsim.PilotClient.BlackCore.SimulatorInterface");
|
||||||
QJsonObject data = json["MetaData"].toObject();
|
QJsonObject data = json["MetaData"].toObject();
|
||||||
m_fullName = data["full_name"].toString("Unknown");
|
m_fullName = data["full_name"].toString();
|
||||||
m_shortName = data["short_name"].toString("Unknown");
|
m_shortName = data["short_name"].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
CVariant CSimulatorInfo::getSimulatorSetupValue(int index) const
|
CVariant CSimulatorInfo::getSimulatorSetupValue(int index) const
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ namespace BlackSimPlugin
|
|||||||
if (m_simConnected) { return true; }
|
if (m_simConnected) { return true; }
|
||||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0)))
|
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0)))
|
||||||
{
|
{
|
||||||
emit connectionStatusChanged(ConnectionFailed);
|
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -84,7 +83,6 @@ namespace BlackSimPlugin
|
|||||||
m_simconnectTimerId = startTimer(10);
|
m_simconnectTimerId = startTimer(10);
|
||||||
m_simConnected = true;
|
m_simConnected = true;
|
||||||
|
|
||||||
emit connectionStatusChanged(Connected);
|
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -123,7 +121,6 @@ namespace BlackSimPlugin
|
|||||||
m_simconnectTimerId = -1;
|
m_simconnectTimerId = -1;
|
||||||
m_simConnected = false;
|
m_simConnected = false;
|
||||||
|
|
||||||
emit connectionStatusChanged(Disconnected);
|
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -332,17 +329,16 @@ namespace BlackSimPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit simulatorStarted();
|
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsx::onSimStopped()
|
void CSimulatorFsx::onSimStopped()
|
||||||
{
|
{
|
||||||
if (!m_simRunning) { return; }
|
if (m_simRunning) {
|
||||||
m_simRunning = false;
|
m_simRunning = false;
|
||||||
mapperInstance()->gracefulShutdown(); // stop background reading if ongoing
|
mapperInstance()->gracefulShutdown(); // stop background reading if ongoing
|
||||||
emit simulatorStopped();
|
}
|
||||||
emitSimulatorCombinedStatus(); // 3 states together
|
emitSimulatorCombinedStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFsx::onSimFrame()
|
void CSimulatorFsx::onSimFrame()
|
||||||
@@ -352,6 +348,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorFsx::onSimExit()
|
void CSimulatorFsx::onSimExit()
|
||||||
{
|
{
|
||||||
|
m_simConnected = false;
|
||||||
this->onSimStopped();
|
this->onSimStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,13 +492,11 @@ namespace BlackSimPlugin
|
|||||||
m_simconnectTimerId = startTimer(10);
|
m_simconnectTimerId = startTimer(10);
|
||||||
m_simConnected = true;
|
m_simConnected = true;
|
||||||
|
|
||||||
emit connectionStatusChanged(Connected);
|
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_simConnected = false;
|
m_simConnected = false;
|
||||||
emit connectionStatusChanged(ConnectionFailed);
|
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -812,5 +807,31 @@ namespace BlackSimPlugin
|
|||||||
CLogMessage(this).info("Synchronized time to UTC: %1") << myTime.toString();
|
CLogMessage(this).info("Synchronized time to UTC: %1") << myTime.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSimulatorFsxListener::CSimulatorFsxListener(QObject *parent) : ISimulatorListener(parent),
|
||||||
|
m_timer(new QTimer(this))
|
||||||
|
{
|
||||||
|
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
||||||
|
m_timer->setInterval(QueryInterval);
|
||||||
|
|
||||||
|
connect(m_timer, &QTimer::timeout, [this]() {
|
||||||
|
HANDLE hSimConnect;
|
||||||
|
HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0);
|
||||||
|
SimConnect_Close(hSimConnect);
|
||||||
|
|
||||||
|
if (result == S_OK)
|
||||||
|
emit simulatorStarted(m_simulatorInfo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSimulatorFsxListener::start()
|
||||||
|
{
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSimulatorFsxListener::stop()
|
||||||
|
{
|
||||||
|
m_timer->stop();
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -201,6 +201,25 @@ namespace BlackSimPlugin
|
|||||||
qint64 m_statsUpdateAircraftTimeAvg = 0;
|
qint64 m_statsUpdateAircraftTimeAvg = 0;
|
||||||
int m_statsUpdateAircraftCount = 0;
|
int m_statsUpdateAircraftCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CSimulatorFsxListener : public BlackCore::ISimulatorListener {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CSimulatorFsxListener(QObject* parent);
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::ISimulatorListener::start
|
||||||
|
virtual void start() override;
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::ISimulatorListener::stop
|
||||||
|
virtual void stop() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer* m_timer;
|
||||||
|
const BlackSim::CSimulatorInfo m_simulatorInfo = BlackSim::CSimulatorInfo::FSX();
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace BlackCore
|
} // namespace BlackCore
|
||||||
|
|||||||
@@ -14,9 +14,6 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
using namespace BlackSim;
|
|
||||||
using namespace BlackCore;
|
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
{
|
{
|
||||||
namespace Fsx
|
namespace Fsx
|
||||||
@@ -27,9 +24,14 @@ namespace BlackSimPlugin
|
|||||||
return new CSimulatorFsx(ownAircraftProvider, renderedAircraftProvider, parent);
|
return new CSimulatorFsx(ownAircraftProvider, renderedAircraftProvider, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorInfo CSimulatorFsxFactory::getSimulatorInfo() const
|
BlackSim::CSimulatorInfo CSimulatorFsxFactory::getSimulatorInfo() const
|
||||||
{
|
{
|
||||||
return CSimulatorInfo::FSX();
|
return BlackSim::CSimulatorInfo::FSX();
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(QObject *parent)
|
||||||
|
{
|
||||||
|
return new CSimulatorFsxListener(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
//! \copydoc BlackCore::ISimulatorFactory::getSimulatorInfo
|
//! \copydoc BlackCore::ISimulatorFactory::getSimulatorInfo
|
||||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::ISimulatorFactory::getListener
|
||||||
|
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user