mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35: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:
@@ -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