mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
* adjustments to use deferred caches * removed simulator from CAircraftModelSetLoader`s signature as it was not used * only change current simulator when explicitly set (avoid unintended setting) * added function to obtain number of elements from model caches
This commit is contained in:
@@ -51,7 +51,6 @@ namespace BlackCore
|
||||
CEntityFlags::Entity allEntities = entities;
|
||||
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities); // CEntityFlags::InfoObjectEntity will be ignored
|
||||
const bool hasInfoObjects = this->hasInfoObjects();
|
||||
const bool changedUrl = this->hasChangedUrl(currentEntity);
|
||||
while (currentEntity)
|
||||
{
|
||||
const CDatabaseReaderConfig config(this->getConfigForEntity(currentEntity));
|
||||
@@ -59,6 +58,7 @@ namespace BlackCore
|
||||
{
|
||||
if (hasInfoObjects)
|
||||
{
|
||||
const bool changedUrl = this->hasChangedUrl(currentEntity);
|
||||
const QDateTime cacheTs(this->getCacheTimestamp(currentEntity));
|
||||
const QDateTime latestEntityTs(this->getLatestEntityTimestamp(currentEntity));
|
||||
const qint64 cacheTimestamp = cacheTs.isValid() ? cacheTs.toMSecsSinceEpoch() : -1;
|
||||
@@ -76,7 +76,8 @@ namespace BlackCore
|
||||
{
|
||||
if (changedUrl)
|
||||
{
|
||||
CLogMessage(this).info("Data location changed, will override cache");
|
||||
CLogMessage(this).info("Data location changed, will override cache for %1")
|
||||
<< CEntityFlags::flagToString(currentEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -90,7 +91,11 @@ namespace BlackCore
|
||||
{
|
||||
// no info objects, server down
|
||||
this->syncronizeCaches(currentEntity);
|
||||
CLogMessage(this).info("No info object for %1, using cache") << CEntityFlags::flagToString(currentEntity);
|
||||
const int c = this->getCacheCount(currentEntity);
|
||||
CLogMessage(this).info("No info object for %1, using cache with %2 objects")
|
||||
<< CEntityFlags::flagToString(currentEntity)
|
||||
<< c;
|
||||
entities &= ~currentEntity; // do not load from web
|
||||
}
|
||||
}
|
||||
currentEntity = CEntityFlags::iterateDbEntities(allEntities);
|
||||
|
||||
@@ -149,7 +149,10 @@ namespace BlackCore
|
||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
||||
|
||||
//! Cache`s timestamp for given entity
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entities) const = 0;
|
||||
|
||||
//! Cache`s number of entities
|
||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const = 0;
|
||||
|
||||
//! Invalidate the caches for given entities
|
||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) = 0;
|
||||
|
||||
@@ -399,7 +399,7 @@ namespace BlackCore
|
||||
if (entities.testFlag(CEntityFlags::CountryEntity)) {CDataCache::instance()->clearAllValues(this->m_countryCache.getKey()); }
|
||||
}
|
||||
|
||||
QDateTime CIcaoDataReader::getCacheTimestamp(CEntityFlags::Entity entity)
|
||||
QDateTime CIcaoDataReader::getCacheTimestamp(CEntityFlags::Entity entity) const
|
||||
{
|
||||
switch (entity)
|
||||
{
|
||||
@@ -410,6 +410,17 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
int CIcaoDataReader::getCacheCount(CEntityFlags::Entity entity) const
|
||||
{
|
||||
switch (entity)
|
||||
{
|
||||
case CEntityFlags::AircraftIcaoEntity: return this->m_aircraftIcaoCache.getCopy().size();
|
||||
case CEntityFlags::AirlineIcaoEntity: return this->m_airlineIcaoCache.getCopy().size();
|
||||
case CEntityFlags::CountryEntity: return this->m_countryCache.getCopy().size();
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool CIcaoDataReader::hasChangedUrl(CEntityFlags::Entity entity) const
|
||||
{
|
||||
Q_UNUSED(entity);
|
||||
|
||||
@@ -123,7 +123,8 @@ namespace BlackCore
|
||||
//! @{
|
||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) override;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -62,13 +62,20 @@ namespace BlackCore
|
||||
Q_UNUSED(entities);
|
||||
}
|
||||
|
||||
QDateTime CInfoDataReader::getCacheTimestamp(CEntityFlags::Entity entity)
|
||||
QDateTime CInfoDataReader::getCacheTimestamp(CEntityFlags::Entity entity) const
|
||||
{
|
||||
// no caching used here
|
||||
Q_UNUSED(entity);
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
int CInfoDataReader::getCacheCount(CEntityFlags::Entity entity) const
|
||||
{
|
||||
// no caching used here
|
||||
Q_UNUSED(entity);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CInfoDataReader::hasChangedUrl(CEntityFlags::Entity entity) const
|
||||
{
|
||||
// not implemented
|
||||
|
||||
@@ -61,7 +61,8 @@ namespace BlackCore
|
||||
//! @{
|
||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) override;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -437,12 +437,18 @@ namespace BlackCore
|
||||
Q_UNUSED(entities);
|
||||
}
|
||||
|
||||
QDateTime CModelDataReader::getCacheTimestamp(CEntityFlags::Entity entity)
|
||||
QDateTime CModelDataReader::getCacheTimestamp(CEntityFlags::Entity entity) const
|
||||
{
|
||||
Q_UNUSED(entity);
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
int CModelDataReader::getCacheCount(CEntityFlags::Entity entity) const
|
||||
{
|
||||
Q_UNUSED(entity);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CModelDataReader::hasChangedUrl(CEntityFlags::Entity entity) const
|
||||
{
|
||||
Q_UNUSED(entity);
|
||||
|
||||
@@ -128,7 +128,8 @@ namespace BlackCore
|
||||
//! @{
|
||||
virtual void syncronizeCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual void invalidateCaches(BlackMisc::Network::CEntityFlags::Entity entities) override;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) override;
|
||||
virtual QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
virtual bool hasChangedUrl(BlackMisc::Network::CEntityFlags::Entity entity) const override;
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace BlackCore
|
||||
|
||||
//! \todo unclear if this is valid for all simulators or for MS/P3D simulators only
|
||||
BlackCore::CAircraftMatcher m_modelMatcher; //!< Model matcher
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this }; //!< load model set from caches
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches
|
||||
|
||||
private:
|
||||
bool m_debugMessages = false; //!< Display debug messages
|
||||
|
||||
@@ -70,17 +70,15 @@ namespace BlackGui
|
||||
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
|
||||
connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_modelChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_viewModelChanged);
|
||||
connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::ps_onJsonDataLoaded);
|
||||
|
||||
const CSimulatorInfo sim = this->m_modelSetLoader.getSimulator();
|
||||
if (sim.isSingleSimulator())
|
||||
const CSimulatorInfo simulator = this->m_modelSetLoader.getSimulator();
|
||||
if (simulator.isSingleSimulator())
|
||||
{
|
||||
// update display when all is set up
|
||||
this->m_modelSetLoader.syncronizeCache(); // make sure data are loaded
|
||||
QTimer::singleShot(500, [this, sim]()
|
||||
QTimer::singleShot(500, [this]()
|
||||
{
|
||||
this->ps_changeSimulator(sim);
|
||||
this->updateViewToCurrentModels();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -162,7 +160,7 @@ namespace BlackGui
|
||||
"Cannot add data for " + simulator.toQString(true) + " to " + this->getModelSetSimulator().toQString(true), true);
|
||||
}
|
||||
CAircraftModelList updateModels(this->getModelSet());
|
||||
int d = updateModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
const int d = updateModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
|
||||
if (d > 0)
|
||||
{
|
||||
this->ui->tvp_OwnModelSet->updateContainerMaybeAsync(updateModels);
|
||||
@@ -195,7 +193,8 @@ namespace BlackGui
|
||||
{
|
||||
// make sure both tabs display the same simulator
|
||||
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "Missing mapping component");
|
||||
this->getMappingComponent()->setOwnModelsSimulator(this->getModelSetSimulator());
|
||||
const CSimulatorInfo sim(this->getModelSetSimulator());
|
||||
this->getMappingComponent()->setOwnModelsSimulator(sim);
|
||||
if (!this->m_modelSetDialog)
|
||||
{
|
||||
this->m_modelSetDialog.reset(new CDbOwnModelSetDialog(this));
|
||||
@@ -214,7 +213,7 @@ namespace BlackGui
|
||||
}
|
||||
else
|
||||
{
|
||||
static const CStatusMessage m = CStatusMessage(this).error("No model data for %1") << this->m_modelSetDialog->getSimulatorInfo().toQString(true);
|
||||
static const CStatusMessage m = CStatusMessage(this).error("No model data for %1") << sim.toQString(true);
|
||||
this->getMappingComponent()->showOverlayMessage(m);
|
||||
}
|
||||
}
|
||||
@@ -239,8 +238,7 @@ namespace BlackGui
|
||||
if (this->getModelSetSimulator() == simulator) { return; } // avoid endless loops
|
||||
|
||||
this->setModelSetSimulator(simulator);
|
||||
const CAircraftModelList models(this->m_modelSetLoader.getAircraftModels());
|
||||
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
|
||||
this->updateViewToCurrentModels();
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::ps_onSimulatorChanged(const CSimulatorInfo &simulator)
|
||||
@@ -276,7 +274,7 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::ps_preferencesChanged()
|
||||
void CDbOwnModelSetComponent::ps_distributorPreferencesChanged()
|
||||
{
|
||||
const CDistributorListPreferences preferences = this->m_distributorPreferences.get();
|
||||
const CSimulatorInfo simuulator = preferences.getLastUpdatedSimulator();
|
||||
@@ -286,7 +284,7 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::ps_modelChanged()
|
||||
void CDbOwnModelSetComponent::ps_viewModelChanged()
|
||||
{
|
||||
ui->pb_SaveAsSetForSimulator->setEnabled(true);
|
||||
}
|
||||
@@ -298,6 +296,12 @@ namespace BlackGui
|
||||
this->ui->tvp_OwnModelSet->setSaveFileName(name);
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::updateViewToCurrentModels()
|
||||
{
|
||||
const CAircraftModelList models(this->m_modelSetLoader.getAircraftModels());
|
||||
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
|
||||
}
|
||||
|
||||
void CDbOwnModelSetComponent::setModelSetSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (this->m_modelSetLoader.getSimulator() == simulator) { return; } // avoid unnecessary signals
|
||||
|
||||
@@ -123,22 +123,27 @@ namespace BlackGui
|
||||
void ps_onJsonDataLoaded(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Preferences changed
|
||||
void ps_preferencesChanged();
|
||||
void ps_distributorPreferencesChanged();
|
||||
|
||||
//! Model has been changed
|
||||
void ps_modelChanged();
|
||||
//! Model (of view) has been changed
|
||||
void ps_viewModelChanged();
|
||||
|
||||
private:
|
||||
//! Default file name
|
||||
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);
|
||||
|
||||
//! Update view to current models
|
||||
void updateViewToCurrentModels();
|
||||
|
||||
//! Update distributor order
|
||||
void updateDistributorOrder(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
|
||||
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
|
||||
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
|
||||
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_preferencesChanged };
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
|
||||
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_distributorPreferencesChanged };
|
||||
|
||||
// -------------------------- custom menus -----------------------------------
|
||||
|
||||
//! The menu for loading and handling own models for mapping tasks
|
||||
//! \note This is specific for that very component
|
||||
|
||||
@@ -63,7 +63,9 @@ namespace BlackGui
|
||||
int CDbOwnModelSetDialog::exec()
|
||||
{
|
||||
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
|
||||
this->setSimulator(this->getMappingComponent()->getOwnModelsSimulator());
|
||||
const CSimulatorInfo sim(this->getMappingComponent()->getOwnModelsSimulator());
|
||||
Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
this->setSimulator(sim);
|
||||
this->checkData();
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace BlackGui
|
||||
private:
|
||||
BlackGui::COverlayMessagesFrame *m_overlayMessageFrame = nullptr;
|
||||
QScopedPointer<Ui::CDistributorPreferencesComponent> ui;
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
|
||||
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDistributorPreferencesComponent::ps_preferencesChanged };
|
||||
|
||||
void updateContainerMaybeAsync(const BlackMisc::Simulation::CDistributorList &models, bool sortByOrder = true);
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace BlackGui
|
||||
BlackMisc::Simulation::CAircraftModel defaultModel() const;
|
||||
|
||||
QScopedPointer<Ui::CModelMatcherComponent> ui;
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
|
||||
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
|
||||
BlackCore::CAircraftMatcher m_matcher { BlackCore::CAircraftMatcher::All, this };
|
||||
};
|
||||
} // ns
|
||||
|
||||
@@ -18,11 +18,9 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent) :
|
||||
CAircraftModelSetLoader::CAircraftModelSetLoader(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||
this->syncronizeCache();
|
||||
connect(&this->m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace BlackMisc
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr);
|
||||
CAircraftModelSetLoader(QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CAircraftModelSetLoader();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
@@ -28,6 +29,7 @@ namespace BlackMisc
|
||||
CAircraftModelList IMultiSimulatorModelCaches::getCurrentCachedModels() const
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return CAircraftModelList(); }
|
||||
return this->getCachedModels(sim);
|
||||
}
|
||||
@@ -35,6 +37,7 @@ namespace BlackMisc
|
||||
bool IMultiSimulatorModelCaches::syncronizeCurrentCache()
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return false; }
|
||||
this->syncronizeCache(sim);
|
||||
return true;
|
||||
@@ -43,7 +46,10 @@ namespace BlackMisc
|
||||
CModelCaches::CModelCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{
|
||||
this->m_currentSimulator.synchronize();
|
||||
this->syncronizeCache(this->m_currentSimulator.getCopy());
|
||||
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
|
||||
this->syncronizeCache(sim);
|
||||
const QString simStr(sim.toQString(true));
|
||||
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
||||
}
|
||||
|
||||
CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
||||
@@ -56,7 +62,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getCopy();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getCopy();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
return CAircraftModelList();
|
||||
}
|
||||
}
|
||||
@@ -64,8 +70,6 @@ namespace BlackMisc
|
||||
CStatusMessage CModelCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { return m; }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(models);
|
||||
@@ -73,7 +77,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(models);
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(models);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
return CStatusMessage();
|
||||
}
|
||||
}
|
||||
@@ -81,6 +85,7 @@ namespace BlackMisc
|
||||
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
|
||||
{
|
||||
const CSimulatorInfo sim(this->getCurrentSimulator());
|
||||
BLACK_VERIFY_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
|
||||
if (!sim.isSingleSimulator()) { return QDateTime(); }
|
||||
return this->getCacheTimestamp(sim);
|
||||
}
|
||||
@@ -95,7 +100,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getTimestamp();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getTimestamp();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
return QDateTime();
|
||||
}
|
||||
}
|
||||
@@ -103,28 +108,35 @@ namespace BlackMisc
|
||||
void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { CLogMessage::preformatted(m); }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.synchronize(); break;
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.synchronize(); break;
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.synchronize(); break;
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.synchronize(); break;
|
||||
case CSimulatorInfo::FS9: this->m_modelCacheFs9.synchronize(); break;
|
||||
case CSimulatorInfo::FSX: this->m_modelCacheFsx.synchronize(); break;
|
||||
case CSimulatorInfo::P3D: this->m_modelCacheP3D.synchronize(); break;
|
||||
case CSimulatorInfo::XPLANE: this->m_modelCacheXP.synchronize(); break;
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||
const CSimulatorInfo s = this->m_currentSimulator.getCopy();
|
||||
if (s == simulator) { return sameSimMsg; }
|
||||
const BlackMisc::CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
this->syncronizeCache(simulator);
|
||||
return m;
|
||||
}
|
||||
|
||||
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||
{
|
||||
this->m_currentSimulator.synchronize();
|
||||
this->syncronizeCache(this->m_currentSimulator.getCopy());
|
||||
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
|
||||
this->syncronizeCache(sim);
|
||||
const QString simStr(sim.toQString(true));
|
||||
CLogMessage(this).info("Initialized model set caches to %1") << simStr;
|
||||
}
|
||||
|
||||
CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const
|
||||
@@ -137,7 +149,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getCopy();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getCopy();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
return CAircraftModelList();
|
||||
}
|
||||
}
|
||||
@@ -145,8 +157,6 @@ namespace BlackMisc
|
||||
CStatusMessage CModelSetCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { return m; }
|
||||
CAircraftModelList orderedModels(models);
|
||||
if (orderedModels.needsOrder())
|
||||
{
|
||||
@@ -164,7 +174,7 @@ namespace BlackMisc
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(orderedModels);
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(orderedModels);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator");
|
||||
return CStatusMessage();
|
||||
}
|
||||
}
|
||||
@@ -187,8 +197,6 @@ namespace BlackMisc
|
||||
void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
const CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
if (m.isFailure()) { CLogMessage::preformatted(m); }
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: this->m_modelCacheFs9.synchronize(); break;
|
||||
@@ -200,11 +208,15 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||
const CSimulatorInfo s = this->m_currentSimulator.getCopy();
|
||||
if (s == simulator) { return sameSimMsg; }
|
||||
const BlackMisc::CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||
this->syncronizeCache(simulator);
|
||||
return m;
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace BlackMisc
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
|
||||
|
||||
//!Selected simulator
|
||||
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! \copydoc IModelsPerSimulatorSetable::setModels
|
||||
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
@@ -207,6 +207,7 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Bundle of caches for all simulators
|
||||
//! \remark remembers its last simulator selection
|
||||
class CModelCaches : public IMultiSimulatorModelCaches
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -222,7 +223,7 @@ namespace BlackMisc
|
||||
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
|
||||
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
@@ -234,7 +235,7 @@ namespace BlackMisc
|
||||
};
|
||||
|
||||
//! Bundle of caches for model sets of all simulators
|
||||
//! \remark Temp. workaround
|
||||
//! \remark remembers its last simulator selection
|
||||
class CModelSetCaches : public IMultiSimulatorModelCaches
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -250,7 +251,7 @@ namespace BlackMisc
|
||||
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
|
||||
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
|
||||
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
virtual BlackMisc::CStatusMessage setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace BlackMisc
|
||||
|
||||
QString CFsCommonUtil::fs9AircraftDir()
|
||||
{
|
||||
QString dir(fs9AircraftDirFromRegistry());
|
||||
const QString dir(fs9AircraftDirFromRegistry());
|
||||
if (!dir.isEmpty()) { return dir; }
|
||||
//! \todo hardcoded sim parts should come from settings
|
||||
return "C:/Flight Simulator 9/Aircraft";
|
||||
|
||||
Reference in New Issue
Block a user