mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
case CacheLoaded: return "cache loaded";
|
||||
case LoadingSkipped: return "loading skipped";
|
||||
case ParsedData: return "parsed data";
|
||||
case CacheLoaded: return loaded;
|
||||
case LoadingSkipped: return skipped;
|
||||
case ParsedData: return parsed;
|
||||
default: break;
|
||||
}
|
||||
return "??";
|
||||
|
||||
static const QString unknown("??");
|
||||
return unknown;
|
||||
}
|
||||
|
||||
QString IAircraftModelLoader::enumToString(IAircraftModelLoader::LoadModeFlag modeFlag)
|
||||
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)
|
||||
{
|
||||
case NotSet: return "not set";
|
||||
case LoadDirectly: return "load directly";
|
||||
case LoadInBackground: return "load in background";
|
||||
case CacheFirst: return "cache first";
|
||||
case CacheSkipped: return "cache skipped";
|
||||
case CacheOnly: return "cache only";
|
||||
case NotSet: return notSet;
|
||||
case LoadDirectly: return directly;
|
||||
case LoadInBackground: return background;
|
||||
case CacheFirst: return cacheFirst;
|
||||
case CacheSkipped: return cacheSkipped;
|
||||
case CacheOnly: return cacheOnly;
|
||||
default: break;
|
||||
}
|
||||
return "??";
|
||||
|
||||
static const QString unknown("??");
|
||||
return unknown;
|
||||
}
|
||||
|
||||
QString IAircraftModelLoader::enumToString(LoadMode mode)
|
||||
@@ -80,6 +95,11 @@ namespace BlackMisc
|
||||
return modes.join(", ");
|
||||
}
|
||||
|
||||
bool IAircraftModelLoader::needsCacheSynchronized(LoadMode mode)
|
||||
{
|
||||
return mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly);
|
||||
}
|
||||
|
||||
IAircraftModelLoader::~IAircraftModelLoader()
|
||||
{
|
||||
this->gracefulShutdown();
|
||||
@@ -93,9 +113,9 @@ namespace BlackMisc
|
||||
|
||||
CStatusMessage IAircraftModelLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator(); // support default value
|
||||
this->setObjectInfo(sim);
|
||||
return m_caches.setCachedModels(models, sim);
|
||||
const CSimulatorInfo usedSimulator = simulator.isSingleSimulator() ? simulator : this->getSimulator(); // support default value
|
||||
this->setObjectInfo(usedSimulator);
|
||||
return m_caches.setCachedModels(models, usedSimulator);
|
||||
}
|
||||
|
||||
CStatusMessage IAircraftModelLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
@@ -202,7 +222,12 @@ namespace BlackMisc
|
||||
|
||||
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)
|
||||
@@ -211,6 +236,10 @@ namespace BlackMisc
|
||||
m_loadingInProgress = true;
|
||||
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();
|
||||
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
|
||||
{
|
||||
@@ -229,7 +258,6 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
// really load from disk?
|
||||
const CSimulatorInfo simulator = this->getSimulator();
|
||||
const QStringList modelDirs = this->getInitializedModelDirectories(modelDirectories, simulator);
|
||||
if (m_skipLoadingEmptyModelDir && modelDirs.isEmpty())
|
||||
{
|
||||
|
||||
@@ -77,14 +77,17 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Enum as string
|
||||
static QString enumToString(LoadFinishedInfo info);
|
||||
static const QString &enumToString(LoadFinishedInfo info);
|
||||
|
||||
//! Enum as string
|
||||
static QString enumToString(LoadModeFlag modeFlag);
|
||||
static const QString &enumToString(LoadModeFlag modeFlag);
|
||||
|
||||
//! Enum as string
|
||||
static QString enumToString(LoadMode mode);
|
||||
|
||||
//! Is that mode needing caches synchronized?
|
||||
static bool needsCacheSynchronized(LoadMode mode);
|
||||
|
||||
//! Destructor
|
||||
virtual ~IAircraftModelLoader();
|
||||
|
||||
@@ -159,6 +162,12 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Simulation::Data::IMultiSimulatorModelCaches::synchronizeCache
|
||||
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
|
||||
Settings::CSpecializedSimulatorSettings getCurrentSimulatorSettings() const;
|
||||
|
||||
@@ -204,9 +213,6 @@ namespace BlackMisc
|
||||
//! Any cached data?
|
||||
bool hasCachedData() const;
|
||||
|
||||
//! Clear cache
|
||||
BlackMisc::CStatusMessage clearCache();
|
||||
|
||||
//! Start the loading process from disk
|
||||
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");
|
||||
return CStatusMessage();
|
||||
}
|
||||
|
||||
this->emitCacheChanged(simulator);
|
||||
}
|
||||
|
||||
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
|
||||
@@ -228,6 +230,28 @@ namespace BlackMisc
|
||||
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
|
||||
{
|
||||
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");
|
||||
return CStatusMessage();
|
||||
}
|
||||
|
||||
this->emitCacheChanged(simulator);
|
||||
}
|
||||
|
||||
QDateTime CModelSetCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||
|
||||
@@ -205,9 +205,14 @@ namespace BlackMisc
|
||||
//! \threadsafe
|
||||
QDateTime getCurrentCacheTimestamp() const;
|
||||
|
||||
//! Set cache
|
||||
//! Set cached models
|
||||
//! \threadsafe
|
||||
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
|
||||
virtual void synchronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
|
||||
@@ -264,7 +269,6 @@ namespace BlackMisc
|
||||
//! Void version of synchronizeCurrentCache
|
||||
void onLastSelectionChanged();
|
||||
|
||||
private:
|
||||
//! Emit cacheChanged() utility function (allows breakpoint)
|
||||
void emitCacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user