mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +08:00
[xSwiftBus] Automatically find and load CSL packages
ref T657
This commit is contained in:
committed by
Klaus Basan
parent
a7509669f9
commit
61adfefa7a
@@ -380,7 +380,6 @@ namespace BlackSimPlugin
|
|||||||
connect(m_trafficProxy, &CXSwiftBusTrafficProxy::remoteAircraftAddingFailed, this, &CSimulatorXPlane::onRemoteAircraftAddingFailed);
|
connect(m_trafficProxy, &CXSwiftBusTrafficProxy::remoteAircraftAddingFailed, this, &CSimulatorXPlane::onRemoteAircraftAddingFailed);
|
||||||
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
|
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
|
||||||
m_trafficProxy->removeAllPlanes();
|
m_trafficProxy->removeAllPlanes();
|
||||||
this->loadCslPackages();
|
|
||||||
this->emitSimulatorCombinedStatus();
|
this->emitSimulatorCombinedStatus();
|
||||||
|
|
||||||
this->initSimulatorInternals();
|
this->initSimulatorInternals();
|
||||||
@@ -545,53 +544,6 @@ namespace BlackSimPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorXPlane::loadCslPackages()
|
|
||||||
{
|
|
||||||
struct Prefix { QString s; };
|
|
||||||
struct PrefixComparator
|
|
||||||
{
|
|
||||||
bool operator()(const Prefix &a, const QString &b) const { return QStringRef(&a.s) < b.leftRef(a.s.size()); }
|
|
||||||
bool operator()(const QString &a, const Prefix &b) const { return a.leftRef(b.s.size()) < QStringRef(&b.s); }
|
|
||||||
};
|
|
||||||
QList<Prefix> packages;
|
|
||||||
|
|
||||||
Q_ASSERT(isConnected());
|
|
||||||
const CAircraftModelList models = this->getModelSet();
|
|
||||||
for (const auto &model : models)
|
|
||||||
{
|
|
||||||
const QString &modelFile = model.getFileName();
|
|
||||||
if (modelFile.isEmpty() || ! QFile::exists(modelFile)) { continue; }
|
|
||||||
auto it = std::lower_bound(packages.begin(), packages.end(), modelFile, PrefixComparator());
|
|
||||||
if (it != packages.end() && modelFile.startsWith(it->s)) { continue; }
|
|
||||||
QString package = findCslPackage(modelFile);
|
|
||||||
if (package.isEmpty()) { continue; }
|
|
||||||
packages.insert(it, { package.append('/') });
|
|
||||||
}
|
|
||||||
for (auto &package : packages)
|
|
||||||
{
|
|
||||||
Q_ASSERT(package.s.endsWith('/'));
|
|
||||||
package.s.chop(1);
|
|
||||||
m_trafficProxy->loadPlanesPackage(package.s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CSimulatorXPlane::findCslPackage(const QString &modelFile)
|
|
||||||
{
|
|
||||||
//! \todo KB 2018-02 KB when I have removed the CSL dir (acciedently) there was no warning here
|
|
||||||
const QFileInfo info(modelFile);
|
|
||||||
QDir dir = info.isDir() ? QDir(modelFile) : info.dir();
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (dir.exists(QStringLiteral("xsb_aircraft.txt")))
|
|
||||||
{
|
|
||||||
if (dir.cdUp()) { return dir.path(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (dir.cdUp());
|
|
||||||
CLogMessage(this).warning(u"Failed to find CSL package for %1") << modelFile;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSimulatorXPlane::physicallyAddRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft)
|
bool CSimulatorXPlane::physicallyAddRemoteAircraft(const CSimulatedAircraft &newRemoteAircraft)
|
||||||
{
|
{
|
||||||
Q_ASSERT(isConnected());
|
Q_ASSERT(isConnected());
|
||||||
|
|||||||
@@ -179,9 +179,6 @@ namespace BlackSimPlugin
|
|||||||
void fastTimerTimeout();
|
void fastTimerTimeout();
|
||||||
void slowTimerTimeout();
|
void slowTimerTimeout();
|
||||||
|
|
||||||
void loadCslPackages();
|
|
||||||
QString findCslPackage(const QString &modelFileName);
|
|
||||||
|
|
||||||
//! Update remote aircraft
|
//! Update remote aircraft
|
||||||
//! \remark this is where the interpolated data are set
|
//! \remark this is where the interpolated data are set
|
||||||
void updateRemoteAircraft();
|
void updateRemoteAircraft();
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ R"(<node>
|
|||||||
</method>
|
</method>
|
||||||
<method name="cleanup">
|
<method name="cleanup">
|
||||||
</method>
|
</method>
|
||||||
<method name="loadPlanesPackage">
|
|
||||||
<arg name="path" type="s" direction="in"/>
|
|
||||||
<arg type="b" direction="out"/>
|
|
||||||
</method>
|
|
||||||
<method name="setDefaultIcao">
|
<method name="setDefaultIcao">
|
||||||
<arg name="defaultIcao" type="s" direction="in"/>
|
<arg name="defaultIcao" type="s" direction="in"/>
|
||||||
</method>
|
</method>
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
if (! s_legacyDataOK) { return false; }
|
if (! s_legacyDataOK) { return false; }
|
||||||
|
|
||||||
|
findAllCslPackages(g_xplanePath);
|
||||||
|
for (const auto &package : m_cslPackages)
|
||||||
|
{
|
||||||
|
loadPlanesPackage(package);
|
||||||
|
}
|
||||||
|
|
||||||
if (! m_initialized)
|
if (! m_initialized)
|
||||||
{
|
{
|
||||||
auto err = XPMPMultiplayerInit(preferences, preferences);
|
auto err = XPMPMultiplayerInit(preferences, preferences);
|
||||||
@@ -139,6 +145,34 @@ namespace XSwiftBus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTraffic::findAllCslPackages(const std::string &path)
|
||||||
|
{
|
||||||
|
char nameBuffer[65536];
|
||||||
|
char *indices[4096];
|
||||||
|
int returnedFiles;
|
||||||
|
int totalFiles;
|
||||||
|
|
||||||
|
// Remove trailing /
|
||||||
|
std::string dir = path.substr(0, path.size() - 1);
|
||||||
|
XPLMGetDirectoryContents(dir.c_str(), 0, nameBuffer, sizeof(nameBuffer), indices, sizeof(indices) / sizeof(char*), &totalFiles, &returnedFiles);
|
||||||
|
for (int i = 0; i < returnedFiles; i++)
|
||||||
|
{
|
||||||
|
std::string fileName(indices[i]);
|
||||||
|
if (fileName == "xsb_aircraft.txt")
|
||||||
|
{
|
||||||
|
const std::string seperator = "/\\";
|
||||||
|
const std::size_t sepPos = dir.find_last_of(seperator);
|
||||||
|
std::string parentPath = dir.substr(0, sepPos);
|
||||||
|
m_cslPackages.insert(parentPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string filePath(path + fileName + g_sep);
|
||||||
|
findAllCslPackages(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CTraffic::emitSimFrame()
|
void CTraffic::emitSimFrame()
|
||||||
{
|
{
|
||||||
if (m_emitSimFrame) { sendDBusSignal("simFrame"); }
|
if (m_emitSimFrame) { sendDBusSignal("simFrame"); }
|
||||||
@@ -526,16 +560,6 @@ namespace XSwiftBus
|
|||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (message.getMethodName() == "loadPlanesPackage")
|
|
||||||
{
|
|
||||||
std::string path;
|
|
||||||
message.beginArgumentRead();
|
|
||||||
message.getArgument(path);
|
|
||||||
queueDBusCall([ = ]()
|
|
||||||
{
|
|
||||||
sendDBusReply(sender, serial, loadPlanesPackage(path));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (message.getMethodName() == "setDefaultIcao")
|
else if (message.getMethodName() == "setDefaultIcao")
|
||||||
{
|
{
|
||||||
std::string defaultIcao;
|
std::string defaultIcao;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <XPLM/XPLMDisplay.h>
|
#include <XPLM/XPLMDisplay.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
//! \cond PRIVATE
|
//! \cond PRIVATE
|
||||||
#define XSWIFTBUS_TRAFFIC_INTERFACENAME "org.swift_project.xswiftbus.traffic"
|
#define XSWIFTBUS_TRAFFIC_INTERFACENAME "org.swift_project.xswiftbus.traffic"
|
||||||
@@ -146,7 +147,9 @@ namespace XSwiftBus
|
|||||||
bool m_initialized = false;
|
bool m_initialized = false;
|
||||||
bool m_enabledMultiplayer = false;
|
bool m_enabledMultiplayer = false;
|
||||||
CTerrainProbe m_terrainProbe;
|
CTerrainProbe m_terrainProbe;
|
||||||
|
std::set<std::string> m_cslPackages;
|
||||||
|
|
||||||
|
void findAllCslPackages(const std::string &path);
|
||||||
void emitSimFrame();
|
void emitSimFrame();
|
||||||
void emitPlaneAdded(const std::string &callsign);
|
void emitPlaneAdded(const std::string &callsign);
|
||||||
void emitPlaneAddingFailed(const std::string &callsign);
|
void emitPlaneAddingFailed(const std::string &callsign);
|
||||||
|
|||||||
Reference in New Issue
Block a user