mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #619, use a combined cache class
* moved caches to blackmisc * used CModelCaches in loader * applied changes in simulator specific loader classes * renamed find function to findFirstByModelStringOrDefault * made merge function static so it can be used elsewhere
This commit is contained in:
@@ -109,7 +109,7 @@ namespace BlackMisc
|
||||
CAircraftModelList models;
|
||||
if (ok)
|
||||
{
|
||||
models = (aircraftCfgEntriesList.toAircraftModelList(this->supportedSimulators()));
|
||||
models = (aircraftCfgEntriesList.toAircraftModelList(this->getSimulator()));
|
||||
this->mergeWithDbData(models, dbModels);
|
||||
}
|
||||
return std::make_tuple(aircraftCfgEntriesList, models, ok);
|
||||
@@ -139,7 +139,7 @@ namespace BlackMisc
|
||||
{
|
||||
bool ok;
|
||||
this->m_parsedCfgEntriesList = performParsing(m_rootDirectory, m_excludedDirectories, &ok);
|
||||
CAircraftModelList models(this->m_parsedCfgEntriesList.toAircraftModelList(this->supportedSimulators()));
|
||||
CAircraftModelList models(this->m_parsedCfgEntriesList.toAircraftModelList(this->getSimulator()));
|
||||
this->mergeWithDbData(models, dbModels);
|
||||
const bool hasData = !models.isEmpty();
|
||||
if (hasData)
|
||||
@@ -164,24 +164,6 @@ namespace BlackMisc
|
||||
return !m_parserWorker || m_parserWorker->isFinished();
|
||||
}
|
||||
|
||||
QDateTime CAircraftCfgParser::getCacheTimestamp() const
|
||||
{
|
||||
if (this->m_simulatorInfo.fsx())
|
||||
{
|
||||
return m_modelCacheFsx.getTimestamp();
|
||||
}
|
||||
else if (this->m_simulatorInfo.fs9())
|
||||
{
|
||||
return m_modelCacheFs9.getTimestamp();
|
||||
}
|
||||
else if (this->m_simulatorInfo.p3d())
|
||||
{
|
||||
return m_modelCacheP3D.getTimestamp();
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Illegal simulator info");
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
bool CAircraftCfgParser::areModelFilesUpdated() const
|
||||
{
|
||||
const QDateTime cacheTs(getCacheTimestamp());
|
||||
@@ -189,61 +171,6 @@ namespace BlackMisc
|
||||
return CFileUtils::containsFileNewerThan(cacheTs, this->getRootDirectory(), true, { fileFilter() }, this->m_excludedDirectories);
|
||||
}
|
||||
|
||||
bool CAircraftCfgParser::hasCachedData() const
|
||||
{
|
||||
if (this->m_simulatorInfo.fsx())
|
||||
{
|
||||
return !m_modelCacheFsx.get().isEmpty();
|
||||
}
|
||||
else if (this->m_simulatorInfo.fs9())
|
||||
{
|
||||
return !m_modelCacheFs9.get().isEmpty();
|
||||
}
|
||||
else if (this->m_simulatorInfo.p3d())
|
||||
{
|
||||
return !m_modelCacheP3D.get().isEmpty();
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Illegal simulator info");
|
||||
return false;
|
||||
}
|
||||
|
||||
const CAircraftModelList &CAircraftCfgParser::getAircraftModels() const
|
||||
{
|
||||
static const CAircraftModelList empty;
|
||||
if (this->m_simulatorInfo.fsx())
|
||||
{
|
||||
return m_modelCacheFsx.get();
|
||||
}
|
||||
else if (this->m_simulatorInfo.fs9())
|
||||
{
|
||||
return m_modelCacheFs9.get();
|
||||
}
|
||||
else if (this->m_simulatorInfo.p3d())
|
||||
{
|
||||
return m_modelCacheP3D.get();
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Illegal simulator info");
|
||||
return empty;
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftCfgParser::setModelsInCache(const CAircraftModelList &models)
|
||||
{
|
||||
if (this->m_simulatorInfo.fsx())
|
||||
{
|
||||
return m_modelCacheFsx.set(models);
|
||||
}
|
||||
else if (this->m_simulatorInfo.fs9())
|
||||
{
|
||||
return m_modelCacheFs9.set(models);
|
||||
}
|
||||
else if (this->m_simulatorInfo.p3d())
|
||||
{
|
||||
return m_modelCacheP3D.set(models);
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Illegal simulator info");
|
||||
return CStatusMessage(this, CStatusMessage::SeverityError, "Wrong simulator type");
|
||||
}
|
||||
|
||||
CAircraftCfgEntriesList CAircraftCfgParser::performParsing(const QString &directory, const QStringList &excludeDirectories, bool *ok)
|
||||
{
|
||||
//
|
||||
|
||||
@@ -48,18 +48,12 @@ namespace BlackMisc
|
||||
virtual BlackMisc::CPixmap iconForModel(const QString &modelName, BlackMisc::CStatusMessage &statusMessage) const override;
|
||||
virtual bool isLoadingFinished() const override;
|
||||
virtual bool areModelFilesUpdated() const override;
|
||||
virtual bool hasCachedData() const override;
|
||||
virtual QDateTime getCacheTimestamp() const override;
|
||||
virtual const BlackMisc::Simulation::CAircraftModelList &getAircraftModels() const override;
|
||||
//! @}
|
||||
|
||||
//! Create an parser object for given simulator
|
||||
static std::unique_ptr<CAircraftCfgParser> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
|
||||
|
||||
protected:
|
||||
//! Set cached values
|
||||
BlackMisc::CStatusMessage setModelsInCache(const BlackMisc::Simulation::CAircraftModelList &models);
|
||||
|
||||
//! \name Interface functions
|
||||
//! @{
|
||||
virtual void startLoadingFromDisk(LoadMode mode, const BlackMisc::Simulation::CAircraftModelList &dbModels) override;
|
||||
@@ -94,11 +88,7 @@ namespace BlackMisc
|
||||
CAircraftCfgEntriesList m_parsedCfgEntriesList; //!< parsed entries
|
||||
QPointer<BlackMisc::CWorker> m_parserWorker; //!< worker will destroy itself, so weak pointer
|
||||
|
||||
//! \todo KB/MS Is there nothing better than having 3 cache members?
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFsx> m_modelCacheFsx {this, &CAircraftCfgParser::ps_cacheChanged}; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this, &CAircraftCfgParser::ps_cacheChanged}; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CAircraftCfgParser::ps_cacheChanged}; //!< P3D cache
|
||||
|
||||
//! Files to be used
|
||||
static const QString &fileFilter();
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user