mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
[FS9] Stop using Fs9Host and Fs9Client as CContinuousWorkers
Both were continuous workers since a blocking IDirectPlay8Peer::SendTo() method was used. Since we use the default async method now, we don't need the threaded implementation any longer. It still could happen that GUI blocks for too long, but that would happen also for other simulator drivers. ref T433
This commit is contained in:
committed by
Mat Sutcliffe
parent
949e013f0b
commit
d6d2c0cc80
@@ -17,7 +17,6 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QMutexLocker>
|
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
@@ -32,10 +31,9 @@ namespace BlackSimPlugin
|
|||||||
return cats;
|
return cats;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDirectPlayPeer::CDirectPlayPeer(QObject *owner, const CCallsign &callsign)
|
CDirectPlayPeer::CDirectPlayPeer(QObject *parent, const CCallsign &callsign)
|
||||||
: CContinuousWorker(owner, "peer_" + callsign.toQString()),
|
: QObject(parent),
|
||||||
m_callsign(callsign),
|
m_callsign(callsign),
|
||||||
m_mutexHostList(QMutex::Recursive),
|
|
||||||
m_callbackWrapper(this, &CDirectPlayPeer::directPlayMessageHandler)
|
m_callbackWrapper(this, &CDirectPlayPeer::directPlayMessageHandler)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -115,8 +113,6 @@ namespace BlackSimPlugin
|
|||||||
PDPNMSG_ENUM_HOSTS_RESPONSE enumHostsResponseMsg = static_cast<PDPNMSG_ENUM_HOSTS_RESPONSE>(msgBuffer);
|
PDPNMSG_ENUM_HOSTS_RESPONSE enumHostsResponseMsg = static_cast<PDPNMSG_ENUM_HOSTS_RESPONSE>(msgBuffer);
|
||||||
const DPN_APPLICATION_DESC *applicationDescription = enumHostsResponseMsg->pApplicationDescription;
|
const DPN_APPLICATION_DESC *applicationDescription = enumHostsResponseMsg->pApplicationDescription;
|
||||||
|
|
||||||
QMutexLocker locker(&m_mutexHostList);
|
|
||||||
|
|
||||||
auto iterator = std::find_if(m_hostNodeList.begin(), m_hostNodeList.end(), [&](const CHostNode & hostNode)
|
auto iterator = std::find_if(m_hostNodeList.begin(), m_hostNodeList.end(), [&](const CHostNode & hostNode)
|
||||||
{
|
{
|
||||||
return applicationDescription->guidInstance == hostNode.getApplicationDesc().guidInstance;
|
return applicationDescription->guidInstance == hostNode.getApplicationDesc().guidInstance;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include "blackmisc/logcategorylist.h"
|
#include "blackmisc/logcategorylist.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMutex>
|
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <dplay8.h>
|
#include <dplay8.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -31,13 +30,13 @@ namespace BlackSimPlugin
|
|||||||
//! DirectPlay peer implementation
|
//! DirectPlay peer implementation
|
||||||
//! More information can be found in the DirectX9 SDK documentation
|
//! More information can be found in the DirectX9 SDK documentation
|
||||||
//! http://doc.51windows.net/Directx9_SDK/?url=/Directx9_SDK/play/dplay.htm
|
//! http://doc.51windows.net/Directx9_SDK/?url=/Directx9_SDK/play/dplay.htm
|
||||||
class CDirectPlayPeer : public BlackMisc::CContinuousWorker
|
class CDirectPlayPeer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CDirectPlayPeer(QObject *owner, const BlackMisc::Aviation::CCallsign &callsign);
|
CDirectPlayPeer(QObject *parent, const BlackMisc::Aviation::CCallsign &callsign);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CDirectPlayPeer();
|
virtual ~CDirectPlayPeer();
|
||||||
@@ -91,8 +90,6 @@ namespace BlackSimPlugin
|
|||||||
// We need the Id of the users player, because we are sending packets only to him
|
// We need the Id of the users player, because we are sending packets only to him
|
||||||
std::atomic<DPNID> m_playerUser = {0}; //!< User player Id
|
std::atomic<DPNID> m_playerUser = {0}; //!< User player Id
|
||||||
|
|
||||||
QMutex m_mutexHostList; //!< Host list mutex
|
|
||||||
|
|
||||||
using TCallbackWrapper = CallbackWrapper<CDirectPlayPeer, HRESULT, DWORD, void *>; //!< DirectPlay peer message handler wrapper
|
using TCallbackWrapper = CallbackWrapper<CDirectPlayPeer, HRESULT, DWORD, void *>; //!< DirectPlay peer message handler wrapper
|
||||||
TCallbackWrapper m_callbackWrapper; //!< Callback wrapper
|
TCallbackWrapper m_callbackWrapper; //!< Callback wrapper
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
CFs9Client::~CFs9Client()
|
CFs9Client::~CFs9Client()
|
||||||
{
|
{
|
||||||
|
closeConnection();
|
||||||
SafeRelease(m_hostAddress);
|
SafeRelease(m_hostAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +173,13 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CFs9Client::start()
|
||||||
|
{
|
||||||
|
initDirectPlay();
|
||||||
|
createDeviceAddress();
|
||||||
|
connectToSession(m_callsign);
|
||||||
|
}
|
||||||
|
|
||||||
CStatusMessageList CFs9Client::getInterpolationMessages(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
|
CStatusMessageList CFs9Client::getInterpolationMessages(CInterpolationAndRenderingSetupBase::InterpolatorMode mode) const
|
||||||
{
|
{
|
||||||
if (!this->getInterpolator()) { return CStatusMessageList(); }
|
if (!this->getInterpolator()) { return CStatusMessageList(); }
|
||||||
@@ -195,18 +203,6 @@ namespace BlackSimPlugin
|
|||||||
sendMultiplayerParamaters();
|
sendMultiplayerParamaters();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFs9Client::initialize()
|
|
||||||
{
|
|
||||||
initDirectPlay();
|
|
||||||
createDeviceAddress();
|
|
||||||
connectToSession(m_callsign);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFs9Client::cleanup()
|
|
||||||
{
|
|
||||||
closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT CFs9Client::enumDirectPlayHosts()
|
HRESULT CFs9Client::enumDirectPlayHosts()
|
||||||
{
|
{
|
||||||
HRESULT hr = s_ok();
|
HRESULT hr = s_ok();
|
||||||
@@ -278,8 +274,6 @@ namespace BlackSimPlugin
|
|||||||
HRESULT hr = s_ok();
|
HRESULT hr = s_ok();
|
||||||
if (m_clientStatus == Connected) { return hr; }
|
if (m_clientStatus == Connected) { return hr; }
|
||||||
|
|
||||||
QMutexLocker locker(&m_mutexHostList);
|
|
||||||
|
|
||||||
QScopedArrayPointer<wchar_t> wszPlayername(new wchar_t[static_cast<uint>(callsign.toQString().size() + 1)]);
|
QScopedArrayPointer<wchar_t> wszPlayername(new wchar_t[static_cast<uint>(callsign.toQString().size() + 1)]);
|
||||||
callsign.toQString().toWCharArray(wszPlayername.data());
|
callsign.toQString().toWCharArray(wszPlayername.data());
|
||||||
wszPlayername[callsign.toQString().size()] = 0;
|
wszPlayername[callsign.toQString().size()] = 0;
|
||||||
@@ -390,7 +384,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
const ISimulator *CFs9Client::simulator() const
|
const ISimulator *CFs9Client::simulator() const
|
||||||
{
|
{
|
||||||
return qobject_cast<const ISimulator *>(this->owner());
|
return qobject_cast<const ISimulator *>(this->parent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include "blackmisc/aviation/aircraftsituation.h"
|
#include "blackmisc/aviation/aircraftsituation.h"
|
||||||
#include "blackmisc/aviation/callsign.h"
|
#include "blackmisc/aviation/callsign.h"
|
||||||
#include "blackmisc/pq/time.h"
|
#include "blackmisc/pq/time.h"
|
||||||
#include <QMutex>
|
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
|
|
||||||
@@ -52,6 +51,9 @@ namespace BlackSimPlugin
|
|||||||
//! Set DirectPlay host address
|
//! Set DirectPlay host address
|
||||||
void setHostAddress(const QString &hostAddress);
|
void setHostAddress(const QString &hostAddress);
|
||||||
|
|
||||||
|
//! Starts the FS9 client messaging
|
||||||
|
void start();
|
||||||
|
|
||||||
//! Get interpolator @{
|
//! Get interpolator @{
|
||||||
BlackMisc::Simulation::CInterpolatorMulti *getInterpolator() { return &m_interpolator; }
|
BlackMisc::Simulation::CInterpolatorMulti *getInterpolator() { return &m_interpolator; }
|
||||||
const BlackMisc::Simulation::CInterpolatorMulti *getInterpolator() const { return &m_interpolator; }
|
const BlackMisc::Simulation::CInterpolatorMulti *getInterpolator() const { return &m_interpolator; }
|
||||||
@@ -72,12 +74,6 @@ namespace BlackSimPlugin
|
|||||||
//! \copydoc QObject::timerEvent
|
//! \copydoc QObject::timerEvent
|
||||||
virtual void timerEvent(QTimerEvent *event) override;
|
virtual void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
//! \copydoc BlackMisc::CContinuousWorker::initialize
|
|
||||||
virtual void initialize() override;
|
|
||||||
|
|
||||||
//! \copydoc BlackMisc::CContinuousWorker::cleanup
|
|
||||||
virtual void cleanup() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Enumerate all FS9 session hosts
|
//! Enumerate all FS9 session hosts
|
||||||
HRESULT enumDirectPlayHosts();
|
HRESULT enumDirectPlayHosts();
|
||||||
|
|||||||
@@ -27,7 +27,16 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
CFs9Host::CFs9Host(QObject *owner) :
|
CFs9Host::CFs9Host(QObject *owner) :
|
||||||
CDirectPlayPeer(owner, sApp->swiftVersionString())
|
CDirectPlayPeer(owner, sApp->swiftVersionString())
|
||||||
{}
|
{
|
||||||
|
initDirectPlay();
|
||||||
|
createHostAddress();
|
||||||
|
startHosting(sApp->swiftVersionString(), m_callsign.toQString());
|
||||||
|
}
|
||||||
|
|
||||||
|
CFs9Host::~CFs9Host()
|
||||||
|
{
|
||||||
|
stopHosting();
|
||||||
|
}
|
||||||
|
|
||||||
QString CFs9Host::getHostAddress()
|
QString CFs9Host::getHostAddress()
|
||||||
{
|
{
|
||||||
@@ -73,18 +82,6 @@ namespace BlackSimPlugin
|
|||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFs9Host::initialize()
|
|
||||||
{
|
|
||||||
initDirectPlay();
|
|
||||||
createHostAddress();
|
|
||||||
startHosting(sApp->swiftVersionString(), m_callsign.toQString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFs9Host::cleanup()
|
|
||||||
{
|
|
||||||
stopHosting();
|
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT CFs9Host::startHosting(const QString &session, const QString &callsign)
|
HRESULT CFs9Host::startHosting(const QString &session, const QString &callsign)
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace BlackSimPlugin
|
|||||||
CFs9Host(QObject *owner);
|
CFs9Host(QObject *owner);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CFs9Host() {}
|
virtual ~CFs9Host();
|
||||||
|
|
||||||
//! Returns true if the users simulator is connected
|
//! Returns true if the users simulator is connected
|
||||||
bool isConnected() const { return m_playerUser != 0; }
|
bool isConnected() const { return m_playerUser != 0; }
|
||||||
@@ -51,13 +51,6 @@ namespace BlackSimPlugin
|
|||||||
//! Hosting status changed
|
//! Hosting status changed
|
||||||
void statusChanged(BlackSimPlugin::Fs9::CFs9Host::HostStatus);
|
void statusChanged(BlackSimPlugin::Fs9::CFs9Host::HostStatus);
|
||||||
|
|
||||||
protected:
|
|
||||||
//! \copydoc BlackMisc::CContinuousWorker::initialize
|
|
||||||
virtual void initialize() override;
|
|
||||||
|
|
||||||
//! \copydoc BlackMisc::CContinuousWorker::cleanup
|
|
||||||
virtual void cleanup() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Start host session
|
//! Start host session
|
||||||
HRESULT startHosting(const QString &session, const QString &callsign);
|
HRESULT startHosting(const QString &session, const QString &callsign);
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ namespace BlackSimPlugin
|
|||||||
if (!m_hashFs9Clients.contains(callsign)) { return false; }
|
if (!m_hashFs9Clients.contains(callsign)) { return false; }
|
||||||
|
|
||||||
auto fs9Client = m_hashFs9Clients.value(callsign);
|
auto fs9Client = m_hashFs9Clients.value(callsign);
|
||||||
fs9Client->quit();
|
delete fs9Client;
|
||||||
m_hashFs9Clients.remove(callsign);
|
m_hashFs9Clients.remove(callsign);
|
||||||
updateAircraftRendered(callsign, false);
|
updateAircraftRendered(callsign, false);
|
||||||
CLogMessage(this).info(u"FS9: Removed aircraft %1") << callsign.toQString();
|
CLogMessage(this).info(u"FS9: Removed aircraft %1") << callsign.toQString();
|
||||||
@@ -466,7 +466,7 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
static void cleanupFs9Host(CFs9Host *host)
|
static void cleanupFs9Host(CFs9Host *host)
|
||||||
{
|
{
|
||||||
host->quitAndWait();
|
delete host;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorFs9Factory::CSimulatorFs9Factory(QObject *parent) :
|
CSimulatorFs9Factory::CSimulatorFs9Factory(QObject *parent) :
|
||||||
@@ -478,8 +478,6 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
/* After FS9 is disconnected, reset its data stored in the host */
|
/* After FS9 is disconnected, reset its data stored in the host */
|
||||||
connect(m_lobbyClient.data(), &CLobbyClient::disconnected, m_fs9Host.data(), &CFs9Host::reset);
|
connect(m_lobbyClient.data(), &CLobbyClient::disconnected, m_fs9Host.data(), &CFs9Host::reset);
|
||||||
|
|
||||||
m_fs9Host->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorFs9Factory::~CSimulatorFs9Factory()
|
CSimulatorFs9Factory::~CSimulatorFs9Factory()
|
||||||
|
|||||||
Reference in New Issue
Block a user