mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
FS9 plugin cleanup
* Make host & lobby client plugin-global * Post-rebase cleanups (FSX too)
This commit is contained in:
committed by
Roland Winklmeier
parent
b3b3f65ee3
commit
3897fb2d1a
@@ -214,6 +214,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
//! \sa ISimulatorFactory::createListener().
|
//! \sa ISimulatorFactory::createListener().
|
||||||
|
//! \note msvc2015: use inherited constructor
|
||||||
ISimulatorListener(QObject* parent);
|
ISimulatorListener(QObject* parent);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
|
|||||||
@@ -34,62 +34,42 @@ using namespace BlackSimPlugin::Fs9;
|
|||||||
using namespace BlackSimPlugin::FsCommon;
|
using namespace BlackSimPlugin::FsCommon;
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/* These instances should be global, as they are shared between all classes
|
||||||
|
* this file contains. They are instantied by CFs9Factory. */
|
||||||
|
QSharedPointer<CFs9Host> fs9Host;
|
||||||
|
QSharedPointer<CLobbyClient> lobbyClient;
|
||||||
|
}
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
{
|
{
|
||||||
namespace Fs9
|
namespace Fs9
|
||||||
{
|
{
|
||||||
CSimulatorFs9Factory::CSimulatorFs9Factory(QObject *parent) :
|
|
||||||
QObject(parent),
|
|
||||||
m_fs9Host(new CFs9Host(this), [](CFs9Host* host){
|
|
||||||
host->quit();
|
|
||||||
host->deleteLater();
|
|
||||||
}),
|
|
||||||
m_lobbyClient(new CLobbyClient(this))
|
|
||||||
{
|
|
||||||
registerMetadata();
|
|
||||||
}
|
|
||||||
|
|
||||||
BlackCore::ISimulator *CSimulatorFs9Factory::create(
|
|
||||||
IOwnAircraftProvider *ownAircraftProvider,
|
|
||||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
|
||||||
QObject *parent)
|
|
||||||
{
|
|
||||||
return new Fs9::CSimulatorFs9(ownAircraftProvider, remoteAircraftProvider, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(QObject *parent)
|
|
||||||
{
|
|
||||||
return new CSimulatorFs9Listener(m_fs9Host, m_lobbyClient, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
BlackSim::CSimulatorInfo CSimulatorFs9Factory::getSimulatorInfo() const
|
|
||||||
{
|
|
||||||
return CSimulatorInfo::FS9();
|
|
||||||
}
|
|
||||||
|
|
||||||
CSimulatorFs9::CSimulatorFs9(IOwnAircraftProvider *ownAircraftProvider,
|
CSimulatorFs9::CSimulatorFs9(IOwnAircraftProvider *ownAircraftProvider,
|
||||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent) :
|
||||||
const QSharedPointer<CFs9Host> &fs9Host,
|
CSimulatorFsCommon(CSimulatorInfo::FS9(), ownAircraftProvider, remoteAircraftProvider, parent)
|
||||||
const QSharedPointer<CLobbyClient> &lobbyClient, QObject *parent) :
|
|
||||||
CSimulatorFsCommon(CSimulatorInfo::FS9(), ownAircraftProvider, remoteAircraftProvider, parent),
|
|
||||||
m_fs9Host(new CFs9Host(this)),
|
|
||||||
m_lobbyClient(new CLobbyClient(this))
|
|
||||||
{
|
{
|
||||||
connect(m_lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
|
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
|
||||||
connect(m_fs9Host.data(), &CFs9Host::customPacketReceived, this, &CSimulatorFs9::ps_processFs9Message);
|
connect(fs9Host.data(), &CFs9Host::customPacketReceived, this, &CSimulatorFs9::ps_processFs9Message);
|
||||||
|
|
||||||
this->m_interpolator = new BlackCore::CInterpolatorLinear(remoteAircraftProvider, this);
|
this->m_interpolator = new BlackCore::CInterpolatorLinear(remoteAircraftProvider, this);
|
||||||
this->m_interpolator->start();
|
this->m_interpolator->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFs9::isConnected() const
|
bool CSimulatorFs9::isConnected() const
|
||||||
{
|
{
|
||||||
return m_fs9Host->isConnected();
|
return fs9Host->isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorFs9::connectTo()
|
bool CSimulatorFs9::connectTo()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_fs9Host->isConnected());
|
Q_ASSERT(m_fsuipc);
|
||||||
m_fsuipc->connect(); // connect FSUIPC too
|
Q_ASSERT(fs9Host->isConnected());
|
||||||
|
|
||||||
|
if (m_useFsuipc)
|
||||||
|
{
|
||||||
|
m_fsuipc->connect(); // connect FSUIPC too
|
||||||
|
}
|
||||||
startTimer(50);
|
startTimer(50);
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
|
|
||||||
@@ -119,8 +99,8 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
CFs9Client *client = new CFs9Client(m_interpolator, this, callsign.toQString(), CTime(25, CTimeUnit::ms()));
|
CFs9Client *client = new CFs9Client(m_interpolator, this, callsign.toQString(), CTime(25, CTimeUnit::ms()));
|
||||||
client->setHostAddress(m_fs9Host->getHostAddress());
|
client->setHostAddress(fs9Host->getHostAddress());
|
||||||
client->setPlayerUserId(m_fs9Host->getPlayerUserId());
|
client->setPlayerUserId(fs9Host->getPlayerUserId());
|
||||||
|
|
||||||
client->start();
|
client->start();
|
||||||
m_hashFs9Clients.insert(callsign, client);
|
m_hashFs9Clients.insert(callsign, client);
|
||||||
@@ -207,7 +187,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
if (message.getSeverity() != BlackMisc::CStatusMessage::SeverityDebug)
|
if (message.getSeverity() != BlackMisc::CStatusMessage::SeverityDebug)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(m_fs9Host.data(), "sendTextMessage", Q_ARG(QString, message.toQString()));
|
QMetaObject::invokeMethod(fs9Host.data(), "sendTextMessage", Q_ARG(QString, message.toQString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +255,7 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFs9::updateOwnAircraftFromSim(const CAircraft &ownAircraft)
|
void CSimulatorFs9::updateOwnAircraftFromSimulator(const CAircraft &simDataOwnAircraft)
|
||||||
{
|
{
|
||||||
this->providerUpdateCockpit(
|
this->providerUpdateCockpit(
|
||||||
simDataOwnAircraft.getCom1System(),
|
simDataOwnAircraft.getCom1System(),
|
||||||
@@ -293,37 +273,30 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorFs9Listener::CSimulatorFs9Listener(const QSharedPointer<CFs9Host> &fs9Host,
|
CSimulatorFs9Listener::CSimulatorFs9Listener(QObject *parent) :
|
||||||
const QSharedPointer<CLobbyClient> &lobbyClient,
|
|
||||||
QObject *parent) :
|
|
||||||
BlackCore::ISimulatorListener(parent),
|
BlackCore::ISimulatorListener(parent),
|
||||||
m_timer(new QTimer(this)),
|
m_timer(new QTimer(this))
|
||||||
m_fs9Host(fs9Host),
|
|
||||||
m_lobbyClient(lobbyClient)
|
|
||||||
{
|
{
|
||||||
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
||||||
m_timer->setInterval(QueryInterval);
|
m_timer->setInterval(QueryInterval);
|
||||||
|
|
||||||
connect(m_timer, &QTimer::timeout, [this]()
|
connect(m_timer, &QTimer::timeout, [this]()
|
||||||
{
|
{
|
||||||
if (m_fs9Host->getHostAddress().isEmpty()) // host not yet set up
|
if (fs9Host->getHostAddress().isEmpty()) // host not yet set up
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_lobbyConnected || m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress()) == S_OK) {
|
if (m_lobbyConnected || lobbyClient->connectFs9ToHost(fs9Host->getHostAddress()) == S_OK)
|
||||||
|
{
|
||||||
m_lobbyConnected = true;
|
m_lobbyConnected = true;
|
||||||
CLogMessage(this).info("Swift is joining FS9 to the multiplayer session...");
|
CLogMessage(this).info("Swift is joining FS9 to the multiplayer session...");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_lobbyConnected && m_fs9Host->isConnected()) {
|
if (m_lobbyConnected && fs9Host->isConnected())
|
||||||
|
{
|
||||||
emit simulatorStarted(m_simulatorInfo);
|
emit simulatorStarted(m_simulatorInfo);
|
||||||
m_lobbyConnected = false;
|
m_lobbyConnected = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
m_fs9Host->start();
|
|
||||||
|
|
||||||
// After FS9 is disconnected, reset its data stored in the host
|
|
||||||
connect(m_lobbyClient.data(), &CLobbyClient::disconnected, m_fs9Host.data(), &CFs9Host::reset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorFs9Listener::start()
|
void CSimulatorFs9Listener::start()
|
||||||
@@ -335,5 +308,46 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
CSimulatorFs9Factory::CSimulatorFs9Factory(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
/* Nobody should have created the host before */
|
||||||
|
Q_ASSERT(!fs9Host);
|
||||||
|
|
||||||
|
registerMetadata();
|
||||||
|
|
||||||
|
fs9Host.reset(new CFs9Host(this));
|
||||||
|
lobbyClient.reset(new CLobbyClient(this));
|
||||||
|
|
||||||
|
/* After FS9 is disconnected, reset its data stored in the host */
|
||||||
|
connect(lobbyClient.data(), &CLobbyClient::disconnected, fs9Host.data(), &CFs9Host::reset);
|
||||||
|
|
||||||
|
fs9Host->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
CSimulatorFs9Factory::~CSimulatorFs9Factory()
|
||||||
|
{
|
||||||
|
fs9Host->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackCore::ISimulator *CSimulatorFs9Factory::create(
|
||||||
|
IOwnAircraftProvider *ownAircraftProvider,
|
||||||
|
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||||
|
QObject *parent)
|
||||||
|
{
|
||||||
|
return new CSimulatorFs9(ownAircraftProvider, remoteAircraftProvider, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackSim::CSimulatorInfo CSimulatorFs9Factory::getSimulatorInfo() const
|
||||||
|
{
|
||||||
|
return CSimulatorInfo::FS9();
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(QObject *parent)
|
||||||
|
{
|
||||||
|
return new CSimulatorFs9Listener(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
namespace Fs9
|
namespace Fs9
|
||||||
{
|
{
|
||||||
//! FSX Simulator Implementation
|
//! FS9 Simulator Implementation
|
||||||
class CSimulatorFs9 : public BlackSimPlugin::FsCommon::CSimulatorFsCommon
|
class CSimulatorFs9 : public BlackSimPlugin::FsCommon::CSimulatorFsCommon
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -105,9 +105,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void disconnectAllClients();
|
void disconnectAllClients();
|
||||||
|
|
||||||
QSharedPointer<CFs9Host> m_fs9Host;
|
|
||||||
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
|
QHash<BlackMisc::Aviation::CCallsign, QPointer<CFs9Client>> m_hashFs9Clients;
|
||||||
QSharedPointer<CLobbyClient> m_lobbyClient;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Listener for FS9
|
//! Listener for FS9
|
||||||
@@ -119,7 +117,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CSimulatorFs9Listener(const QSharedPointer<CFs9Host> &fs9Host, const QSharedPointer<CLobbyClient> &lobbyClient, QObject* parent);
|
CSimulatorFs9Listener(QObject* parent);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! \copydoc BlackCore::ISimulatorListener::start
|
//! \copydoc BlackCore::ISimulatorListener::start
|
||||||
@@ -131,8 +129,6 @@ namespace BlackSimPlugin
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
QTimer* m_timer = nullptr;
|
QTimer* m_timer = nullptr;
|
||||||
QSharedPointer<CFs9Host> m_fs9Host;
|
|
||||||
QSharedPointer<CLobbyClient> m_lobbyClient;
|
|
||||||
bool m_lobbyConnected = false;
|
bool m_lobbyConnected = false;
|
||||||
const BlackSim::CSimulatorInfo m_simulatorInfo = BlackSim::CSimulatorInfo::FS9();
|
const BlackSim::CSimulatorInfo m_simulatorInfo = BlackSim::CSimulatorInfo::FS9();
|
||||||
|
|
||||||
@@ -148,19 +144,20 @@ namespace BlackSimPlugin
|
|||||||
public:
|
public:
|
||||||
CSimulatorFs9Factory(QObject* parent = nullptr);
|
CSimulatorFs9Factory(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
virtual ~CSimulatorFs9Factory();
|
||||||
|
|
||||||
//! \copydoc BlackCore::ISimulatorFactory::create()
|
//! \copydoc BlackCore::ISimulatorFactory::create()
|
||||||
virtual BlackCore::ISimulator *create(QObject *parent) override;
|
virtual BlackCore::ISimulator *create(
|
||||||
|
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||||
|
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||||
|
QObject *parent) override;
|
||||||
|
|
||||||
//! Simulator info
|
//! Simulator info
|
||||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||||
|
|
||||||
//! \copydoc BlackCore::ISimulatorFactory::getListener
|
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
||||||
|
|
||||||
private:
|
|
||||||
QSharedPointer<CFs9Host> m_fs9Host;
|
|
||||||
QSharedPointer<CLobbyClient> m_lobbyClient;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace Fs9
|
} // namespace Fs9
|
||||||
} // namespace BlackCore
|
} // namespace BlackCore
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace BlackSimPlugin
|
|||||||
.arg(QLatin1Char(48 + (0x0f & (FSUIPC_Version >> 16))))
|
.arg(QLatin1Char(48 + (0x0f & (FSUIPC_Version >> 16))))
|
||||||
.arg((FSUIPC_Version & 0xffff) ? "a" + (FSUIPC_Version & 0xff) - 1 : "");
|
.arg((FSUIPC_Version & 0xffff) ? "a" + (FSUIPC_Version & 0xff) - 1 : "");
|
||||||
this->m_fsuipcVersion = QString("FSUIPC %1 (%2)").arg(ver).arg(sim);
|
this->m_fsuipcVersion = QString("FSUIPC %1 (%2)").arg(ver).arg(sim);
|
||||||
CLogMessage(this).info("FSUIPC connected: %1") << this->m_fsuipcVersion;
|
// CLogMessage(this).info("FSUIPC connected: %1") << this->m_fsuipcVersion;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user