mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 08:55:43 +08:00
Fixes in model loader and caches
* loader/multi cache can clear caches if that is ever needed * check if cache needs to be synchronized when loaded and if, do it * emit changed signal if caches are set
This commit is contained in:
@@ -42,31 +42,46 @@ namespace BlackMisc
|
|||||||
connect(&m_settings, &CMultiSimulatorSettings::settingsChanged, this, &IAircraftModelLoader::onSettingsChanged);
|
connect(&m_settings, &CMultiSimulatorSettings::settingsChanged, this, &IAircraftModelLoader::onSettingsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString IAircraftModelLoader::enumToString(IAircraftModelLoader::LoadFinishedInfo info)
|
const QString &IAircraftModelLoader::enumToString(IAircraftModelLoader::LoadFinishedInfo info)
|
||||||
{
|
{
|
||||||
|
static const QString loaded("cache loaded");
|
||||||
|
static const QString skipped("loading skipped");
|
||||||
|
static const QString parsed("parsed data");
|
||||||
|
|
||||||
switch (info)
|
switch (info)
|
||||||
{
|
{
|
||||||
case CacheLoaded: return "cache loaded";
|
case CacheLoaded: return loaded;
|
||||||
case LoadingSkipped: return "loading skipped";
|
case LoadingSkipped: return skipped;
|
||||||
case ParsedData: return "parsed data";
|
case ParsedData: return parsed;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return "??";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString IAircraftModelLoader::enumToString(IAircraftModelLoader::LoadModeFlag modeFlag)
|
static const QString unknown("??");
|
||||||
|
return unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &IAircraftModelLoader::enumToString(IAircraftModelLoader::LoadModeFlag modeFlag)
|
||||||
{
|
{
|
||||||
|
static const QString notSet("not set");
|
||||||
|
static const QString directly("load directly");
|
||||||
|
static const QString background("load in background");
|
||||||
|
static const QString cacheFirst("cache first");
|
||||||
|
static const QString cacheSkipped("cache skipped");
|
||||||
|
static const QString cacheOnly("cacheOnly");
|
||||||
|
|
||||||
switch (modeFlag)
|
switch (modeFlag)
|
||||||
{
|
{
|
||||||
case NotSet: return "not set";
|
case NotSet: return notSet;
|
||||||
case LoadDirectly: return "load directly";
|
case LoadDirectly: return directly;
|
||||||
case LoadInBackground: return "load in background";
|
case LoadInBackground: return background;
|
||||||
case CacheFirst: return "cache first";
|
case CacheFirst: return cacheFirst;
|
||||||
case CacheSkipped: return "cache skipped";
|
case CacheSkipped: return cacheSkipped;
|
||||||
case CacheOnly: return "cache only";
|
case CacheOnly: return cacheOnly;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return "??";
|
|
||||||
|
static const QString unknown("??");
|
||||||
|
return unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString IAircraftModelLoader::enumToString(LoadMode mode)
|
QString IAircraftModelLoader::enumToString(LoadMode mode)
|
||||||
@@ -80,6 +95,11 @@ namespace BlackMisc
|
|||||||
return modes.join(", ");
|
return modes.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IAircraftModelLoader::needsCacheSynchronized(LoadMode mode)
|
||||||
|
{
|
||||||
|
return mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly);
|
||||||
|
}
|
||||||
|
|
||||||
IAircraftModelLoader::~IAircraftModelLoader()
|
IAircraftModelLoader::~IAircraftModelLoader()
|
||||||
{
|
{
|
||||||
this->gracefulShutdown();
|
this->gracefulShutdown();
|
||||||
@@ -93,9 +113,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CStatusMessage IAircraftModelLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
CStatusMessage IAircraftModelLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||||
{
|
{
|
||||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator(); // support default value
|
const CSimulatorInfo usedSimulator = simulator.isSingleSimulator() ? simulator : this->getSimulator(); // support default value
|
||||||
this->setObjectInfo(sim);
|
this->setObjectInfo(usedSimulator);
|
||||||
return m_caches.setCachedModels(models, sim);
|
return m_caches.setCachedModels(models, usedSimulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
CStatusMessage IAircraftModelLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
CStatusMessage IAircraftModelLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||||
@@ -202,7 +222,12 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CStatusMessage IAircraftModelLoader::clearCache()
|
CStatusMessage IAircraftModelLoader::clearCache()
|
||||||
{
|
{
|
||||||
return this->setCachedModels(CAircraftModelList());
|
return m_caches.clearCachedModels(m_caches.getCurrentSimulator());
|
||||||
|
}
|
||||||
|
|
||||||
|
CStatusMessage IAircraftModelLoader::clearCache(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
return m_caches.clearCachedModels(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IAircraftModelLoader::startLoading(LoadMode mode, const ModelConsolidationCallback &modelConsolidation, const QStringList &modelDirectories)
|
void IAircraftModelLoader::startLoading(LoadMode mode, const ModelConsolidationCallback &modelConsolidation, const QStringList &modelDirectories)
|
||||||
@@ -211,6 +236,10 @@ namespace BlackMisc
|
|||||||
m_loadingInProgress = true;
|
m_loadingInProgress = true;
|
||||||
m_loadingMessages.clear();
|
m_loadingMessages.clear();
|
||||||
|
|
||||||
|
const CSimulatorInfo simulator = this->getSimulator();
|
||||||
|
const bool needsCacheSynced = IAircraftModelLoader::needsCacheSynchronized(mode);
|
||||||
|
if (needsCacheSynced) { m_caches.synchronizeCache(simulator); }
|
||||||
|
|
||||||
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
|
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
|
||||||
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
|
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
|
||||||
{
|
{
|
||||||
@@ -229,7 +258,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// really load from disk?
|
// really load from disk?
|
||||||
const CSimulatorInfo simulator = this->getSimulator();
|
|
||||||
const QStringList modelDirs = this->getInitializedModelDirectories(modelDirectories, simulator);
|
const QStringList modelDirs = this->getInitializedModelDirectories(modelDirectories, simulator);
|
||||||
if (m_skipLoadingEmptyModelDir && modelDirs.isEmpty())
|
if (m_skipLoadingEmptyModelDir && modelDirs.isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,14 +77,17 @@ namespace BlackMisc
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! Enum as string
|
//! Enum as string
|
||||||
static QString enumToString(LoadFinishedInfo info);
|
static const QString &enumToString(LoadFinishedInfo info);
|
||||||
|
|
||||||
//! Enum as string
|
//! Enum as string
|
||||||
static QString enumToString(LoadModeFlag modeFlag);
|
static const QString &enumToString(LoadModeFlag modeFlag);
|
||||||
|
|
||||||
//! Enum as string
|
//! Enum as string
|
||||||
static QString enumToString(LoadMode mode);
|
static QString enumToString(LoadMode mode);
|
||||||
|
|
||||||
|
//! Is that mode needing caches synchronized?
|
||||||
|
static bool needsCacheSynchronized(LoadMode mode);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~IAircraftModelLoader();
|
virtual ~IAircraftModelLoader();
|
||||||
|
|
||||||
@@ -159,6 +162,12 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Simulation::Data::IMultiSimulatorModelCaches::synchronizeCache
|
//! \copydoc BlackMisc::Simulation::Data::IMultiSimulatorModelCaches::synchronizeCache
|
||||||
void synchronizeModelCache(const CSimulatorInfo &simulator);
|
void synchronizeModelCache(const CSimulatorInfo &simulator);
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::Simulation::Data::IMultiSimulatorModelCaches::clearCache
|
||||||
|
BlackMisc::CStatusMessage clearCache();
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::Simulation::Data::IMultiSimulatorModelCaches::clearCache
|
||||||
|
BlackMisc::CStatusMessage clearCache(const CSimulatorInfo &simulator);
|
||||||
|
|
||||||
//! \copydoc Settings::CMultiSimulatorSettings::getSpecializedSettings
|
//! \copydoc Settings::CMultiSimulatorSettings::getSpecializedSettings
|
||||||
Settings::CSpecializedSimulatorSettings getCurrentSimulatorSettings() const;
|
Settings::CSpecializedSimulatorSettings getCurrentSimulatorSettings() const;
|
||||||
|
|
||||||
@@ -204,9 +213,6 @@ namespace BlackMisc
|
|||||||
//! Any cached data?
|
//! Any cached data?
|
||||||
bool hasCachedData() const;
|
bool hasCachedData() const;
|
||||||
|
|
||||||
//! Clear cache
|
|
||||||
BlackMisc::CStatusMessage clearCache();
|
|
||||||
|
|
||||||
//! Start the loading process from disk
|
//! Start the loading process from disk
|
||||||
virtual void startLoadingFromDisk(LoadMode mode, const ModelConsolidationCallback &modelConsolidation, const QStringList &modelDirectories) = 0;
|
virtual void startLoadingFromDisk(LoadMode mode, const ModelConsolidationCallback &modelConsolidation, const QStringList &modelDirectories) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -218,6 +218,8 @@ namespace BlackMisc
|
|||||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||||
return CStatusMessage();
|
return CStatusMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->emitCacheChanged(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
|
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
|
||||||
@@ -228,6 +230,28 @@ namespace BlackMisc
|
|||||||
return this->getCacheTimestamp(sim);
|
return this->getCacheTimestamp(sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CStatusMessage IMultiSimulatorModelCaches::clearCachedModels(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
static const CAircraftModelList models;
|
||||||
|
return this->setCachedModels(models, simulator);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMultiSimulatorModelCaches::synchronizeMultiCaches(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
for (const CSimulatorInfo &singleSimulator : simulator.asSingleSimulatorSet())
|
||||||
|
{
|
||||||
|
this->synchronizeCache(singleSimulator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMultiSimulatorModelCaches::admitMultiCaches(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
for (const CSimulatorInfo &singleSimulator : simulator.asSingleSimulatorSet())
|
||||||
|
{
|
||||||
|
this->admitMultiCaches(singleSimulator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QDateTime CModelCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
QDateTime CModelCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
@@ -410,6 +434,8 @@ namespace BlackMisc
|
|||||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||||
return CStatusMessage();
|
return CStatusMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->emitCacheChanged(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime CModelSetCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
QDateTime CModelSetCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||||
|
|||||||
@@ -205,9 +205,14 @@ namespace BlackMisc
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
QDateTime getCurrentCacheTimestamp() const;
|
QDateTime getCurrentCacheTimestamp() const;
|
||||||
|
|
||||||
//! Set cache
|
//! Set cached models
|
||||||
|
//! \threadsafe
|
||||||
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||||
|
|
||||||
|
//! Clear cached models
|
||||||
|
//! \threadsafe
|
||||||
|
virtual BlackMisc::CStatusMessage clearCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
//! Synchronize for given simulator
|
//! Synchronize for given simulator
|
||||||
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||||
|
|
||||||
@@ -264,7 +269,6 @@ namespace BlackMisc
|
|||||||
//! Void version of synchronizeCurrentCache
|
//! Void version of synchronizeCurrentCache
|
||||||
void onLastSelectionChanged();
|
void onLastSelectionChanged();
|
||||||
|
|
||||||
private:
|
|
||||||
//! Emit cacheChanged() utility function (allows breakpoint)
|
//! Emit cacheChanged() utility function (allows breakpoint)
|
||||||
void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user