mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
refs #824 Collect and load CSL packages upon connecting to xbus.
This commit is contained in:
@@ -254,6 +254,7 @@ namespace BlackSimPlugin
|
|||||||
m_traffic->updateInstalledModels();
|
m_traffic->updateInstalledModels();
|
||||||
m_watcher->setConnection(m_conn);
|
m_watcher->setConnection(m_conn);
|
||||||
reloadWeatherSettings();
|
reloadWeatherSettings();
|
||||||
|
loadCslPackages();
|
||||||
emitSimulatorCombinedStatus();
|
emitSimulatorCombinedStatus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -434,6 +435,49 @@ 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());
|
||||||
|
for (const auto &model : m_modelSet.getThreadLocal())
|
||||||
|
{
|
||||||
|
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_traffic->loadPlanesPackage(package.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSimulatorXPlane::findCslPackage(const QString &modelFile)
|
||||||
|
{
|
||||||
|
QDir dir = QFileInfo(modelFile).dir();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (dir.exists(QStringLiteral("xsb_aircraft.txt")))
|
||||||
|
{
|
||||||
|
if (dir.cdUp()) { return dir.path(); }
|
||||||
|
}
|
||||||
|
} while(dir.cdUp());
|
||||||
|
CLogMessage(this).warning("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());
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "blackmisc/pq/time.h"
|
#include "blackmisc/pq/time.h"
|
||||||
#include "blackmisc/pq/units.h"
|
#include "blackmisc/pq/units.h"
|
||||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||||
|
#include "blackmisc/simulation/data/modelcaches.h"
|
||||||
#include "blackmisc/simulation/simulatorsettings.h"
|
#include "blackmisc/simulation/simulatorsettings.h"
|
||||||
#include "blackmisc/weather/weathergrid.h"
|
#include "blackmisc/weather/weathergrid.h"
|
||||||
#include "blackmisc/settingscache.h"
|
#include "blackmisc/settingscache.h"
|
||||||
@@ -134,6 +135,9 @@ namespace BlackSimPlugin
|
|||||||
void ps_installedModelsUpdated(const QStringList &modelStrings, const QStringList &icaos, const QStringList &airlines, const QStringList &liveries);
|
void ps_installedModelsUpdated(const QStringList &modelStrings, const QStringList &icaos, const QStringList &airlines, const QStringList &liveries);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void loadCslPackages();
|
||||||
|
QString findCslPackage(const QString &modelFileName);
|
||||||
|
|
||||||
//! Inject weather grid to simulator
|
//! Inject weather grid to simulator
|
||||||
void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
|
void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid);
|
||||||
void reloadWeatherSettings();
|
void reloadWeatherSettings();
|
||||||
@@ -147,6 +151,7 @@ namespace BlackSimPlugin
|
|||||||
QTimer *m_slowTimer { nullptr };
|
QTimer *m_slowTimer { nullptr };
|
||||||
BlackMisc::Aviation::CAirportList m_airportsInRange; //!< aiports in range of own aircraft
|
BlackMisc::Aviation::CAirportList m_airportsInRange; //!< aiports in range of own aircraft
|
||||||
BlackMisc::Simulation::CAircraftModelList m_installedModels; //!< \todo Do we still need this, as we now focus on model set
|
BlackMisc::Simulation::CAircraftModelList m_installedModels; //!< \todo Do we still need this, as we now focus on model set
|
||||||
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelSet { this };
|
||||||
|
|
||||||
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
|
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
|
||||||
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorXPlane::reloadWeatherSettings };
|
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorXPlane::reloadWeatherSettings };
|
||||||
|
|||||||
Reference in New Issue
Block a user