mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-19 03:45:30 +08:00
[XSwiftBus] Add hasMultiplayerPlanesAquired() DBus API
This function will return whether X-Plane multiplayer planes have been acquired by XSwiftBus or if not, who else acquired them.
This commit is contained in:
committed by
Klaus Basan
parent
55c2e2e559
commit
49bd38d722
@@ -41,6 +41,20 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MultiplayerAcquireInfo CXSwiftBusTrafficProxy::acquireMultiplayerPlanes()
|
||||||
|
{
|
||||||
|
QDBusPendingReply<bool, QString> reply = m_dbusInterface->asyncCall(QLatin1String("acquireMultiplayerPlanes"));
|
||||||
|
reply.waitForFinished();
|
||||||
|
if (reply.isError())
|
||||||
|
{
|
||||||
|
BlackMisc::CLogMessage(this).debug("CXSwiftBusTrafficProxy::acquireMultiplayerPlanes returned: %1") << reply.error().message();
|
||||||
|
}
|
||||||
|
MultiplayerAcquireInfo info;
|
||||||
|
info.hasAcquired = reply.argumentAt<0>();
|
||||||
|
info.owner = reply.argumentAt<1>();
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
bool CXSwiftBusTrafficProxy::initialize()
|
bool CXSwiftBusTrafficProxy::initialize()
|
||||||
{
|
{
|
||||||
return m_dbusInterface->callDBusRet<bool>(QLatin1String("initialize"));
|
return m_dbusInterface->callDBusRet<bool>(QLatin1String("initialize"));
|
||||||
|
|||||||
@@ -99,6 +99,13 @@ namespace BlackSimPlugin
|
|||||||
QList<bool> idents; //!< List of active idents
|
QList<bool> idents; //!< List of active idents
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! Multiplayer Acquire Info
|
||||||
|
struct MultiplayerAcquireInfo
|
||||||
|
{
|
||||||
|
bool hasAcquired; //!< Has XSwiftBus acquired multiplayer planes?
|
||||||
|
QString owner; //!< Name of the plugin having multiplayer planes acquired
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Proxy object connected to a real XSwiftBus::CTraffic object via DBus
|
* Proxy object connected to a real XSwiftBus::CTraffic object via DBus
|
||||||
*/
|
*/
|
||||||
@@ -145,6 +152,9 @@ namespace BlackSimPlugin
|
|||||||
void remoteAircraftAddingFailed(const QString &callsign);
|
void remoteAircraftAddingFailed(const QString &callsign);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
//! \copydoc XSwiftBus::CTraffic::acquireMultiplayerPlanes
|
||||||
|
MultiplayerAcquireInfo acquireMultiplayerPlanes();
|
||||||
|
|
||||||
//! \copydoc XSwiftBus::CTraffic::initialize
|
//! \copydoc XSwiftBus::CTraffic::initialize
|
||||||
bool initialize();
|
bool initialize();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
R"(<node>
|
R"(<node>
|
||||||
<interface name="org.swift_project.xswiftbus.traffic">
|
<interface name="org.swift_project.xswiftbus.traffic">
|
||||||
|
<method name="acquireMultiplayerPlanes">
|
||||||
|
<arg name="acquired" type="b" direction="out"/>
|
||||||
|
<arg name="owner" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
<method name="initialize">
|
<method name="initialize">
|
||||||
<arg type="b" direction="out"/>
|
<arg type="b" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include "XPLMGraphics.h"
|
#include "XPLMGraphics.h"
|
||||||
#include <XPLM/XPLMProcessing.h>
|
#include <XPLM/XPLMProcessing.h>
|
||||||
#include <XPLM/XPLMUtilities.h>
|
#include <XPLM/XPLMUtilities.h>
|
||||||
|
#include <XPLM/XPLMPlanes.h>
|
||||||
|
#include <XPLM/XPLMPlugin.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -83,25 +85,50 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
if (! s_legacyDataOK) { return false; }
|
if (! s_legacyDataOK) { return false; }
|
||||||
|
|
||||||
auto err = XPMPMultiplayerInit(preferences, preferences);
|
if (! m_initialized)
|
||||||
if (*err) { cleanup(); return false; }
|
{
|
||||||
m_initialized = true;
|
auto err = XPMPMultiplayerInit(preferences, preferences);
|
||||||
|
if (*err) { cleanup(); }
|
||||||
|
else { m_initialized = true; }
|
||||||
|
}
|
||||||
|
|
||||||
err = XPMPMultiplayerEnable();
|
return m_initialized;
|
||||||
if (*err) { cleanup(); return false; }
|
}
|
||||||
m_enabled = true;
|
|
||||||
|
|
||||||
XPMPLoadPlanesIfNecessary();
|
bool CTraffic::acquireMultiplayerPlanes(std::string *owner)
|
||||||
return true;
|
{
|
||||||
|
if (! m_enabledMultiplayer)
|
||||||
|
{
|
||||||
|
auto err = XPMPMultiplayerEnable();
|
||||||
|
if (*err)
|
||||||
|
{
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_enabledMultiplayer = true;
|
||||||
|
XPMPLoadPlanesIfNecessary();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalAircraft;
|
||||||
|
int activeAircraft;
|
||||||
|
XPLMPluginID controller;
|
||||||
|
XPLMCountAircraft(&totalAircraft, &activeAircraft, &controller);
|
||||||
|
|
||||||
|
char pluginName[256];
|
||||||
|
XPLMGetPluginInfo(controller, pluginName, nullptr, nullptr, nullptr);
|
||||||
|
*owner = std::string(pluginName);
|
||||||
|
return m_enabledMultiplayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTraffic::cleanup()
|
void CTraffic::cleanup()
|
||||||
{
|
{
|
||||||
removeAllPlanes();
|
removeAllPlanes();
|
||||||
|
|
||||||
if (m_enabled)
|
if (m_enabledMultiplayer)
|
||||||
{
|
{
|
||||||
m_enabled = false;
|
m_enabledMultiplayer = false;
|
||||||
XPMPMultiplayerDisable();
|
XPMPMultiplayerDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,7 +501,20 @@ namespace XSwiftBus
|
|||||||
}
|
}
|
||||||
else if (message.getInterfaceName() == XSWIFTBUS_TRAFFIC_INTERFACENAME)
|
else if (message.getInterfaceName() == XSWIFTBUS_TRAFFIC_INTERFACENAME)
|
||||||
{
|
{
|
||||||
if (message.getMethodName() == "initialize")
|
if (message.getMethodName() == "acquireMultiplayerPlanes")
|
||||||
|
{
|
||||||
|
queueDBusCall([ = ]()
|
||||||
|
{
|
||||||
|
std::string owner;
|
||||||
|
bool acquired = acquireMultiplayerPlanes(&owner);
|
||||||
|
CDBusMessage reply = CDBusMessage::createReply(sender, serial);
|
||||||
|
reply.beginArgumentWrite();
|
||||||
|
reply.appendArgument(acquired);
|
||||||
|
reply.appendArgument(owner);
|
||||||
|
sendDBusMessage(reply);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (message.getMethodName() == "initialize")
|
||||||
{
|
{
|
||||||
sendDBusReply(sender, serial, initialize());
|
sendDBusReply(sender, serial, initialize());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ namespace XSwiftBus
|
|||||||
//! Initialize the multiplayer planes rendering and return true if successful
|
//! Initialize the multiplayer planes rendering and return true if successful
|
||||||
bool initialize();
|
bool initialize();
|
||||||
|
|
||||||
|
//! Returns whether multiplayer planes have been acquired. If not, owner will be set to the plugin that acquired it.
|
||||||
|
bool acquireMultiplayerPlanes(std::string *owner = nullptr);
|
||||||
|
|
||||||
//! Reverse the actions of initialize().
|
//! Reverse the actions of initialize().
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
@@ -132,7 +135,7 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_initialized = false;
|
bool m_initialized = false;
|
||||||
bool m_enabled = false;
|
bool m_enabledMultiplayer = false;
|
||||||
CTerrainProbe m_terrainProbe;
|
CTerrainProbe m_terrainProbe;
|
||||||
|
|
||||||
void emitSimFrame();
|
void emitSimFrame();
|
||||||
|
|||||||
Reference in New Issue
Block a user