mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +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:
144
src/blackmisc/simulation/data/modelcaches.cpp
Normal file
144
src/blackmisc/simulation/data/modelcaches.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "modelcaches.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Data
|
||||
{
|
||||
CModelCaches::CModelCaches(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
CAircraftModelList CModelCaches::getModels(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.get();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.get();
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.get();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.get();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
return CAircraftModelList();
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessage CModelCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(models);
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(models);
|
||||
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");
|
||||
return CStatusMessage();
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime CModelCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.getTimestamp();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.getTimestamp();
|
||||
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");
|
||||
return QDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
void CModelCaches::syncronize(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
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;
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
}
|
||||
}
|
||||
|
||||
CModelSetCaches::CModelSetCaches(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
CAircraftModelList CModelSetCaches::getModels(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.get();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.get();
|
||||
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.get();
|
||||
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.get();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
return CAircraftModelList();
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessage CModelSetCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(models);
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(models);
|
||||
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");
|
||||
return CStatusMessage();
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime CModelSetCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.getTimestamp();
|
||||
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.getTimestamp();
|
||||
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");
|
||||
return QDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
void CModelSetCaches::syncronize(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
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;
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
}
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
@@ -32,33 +32,137 @@ namespace BlackMisc
|
||||
}
|
||||
};
|
||||
|
||||
//! Trait for XP model cache
|
||||
//! \name Caches for own models on disk, loaded by BlackMisc::Simulation::IAircraftModelLoader
|
||||
//! @{
|
||||
|
||||
//! XPlane
|
||||
struct ModelCacheXP : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelcachexp"; }
|
||||
};
|
||||
|
||||
//! Trait for FSX model cache
|
||||
//! FSX
|
||||
struct ModelCacheFsx : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelcachefsx"; }
|
||||
};
|
||||
|
||||
//! Trait for FS9 model cache
|
||||
//! FS9
|
||||
struct ModelCacheFs9 : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelcachefs9"; }
|
||||
};
|
||||
|
||||
//! Trait for P3D model cache
|
||||
//! P3D
|
||||
struct ModelCacheP3D : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelcachep3d"; }
|
||||
};
|
||||
//! @}
|
||||
|
||||
|
||||
//! \name Caches for choosen model sets
|
||||
//! @{
|
||||
|
||||
//! XPlane
|
||||
struct ModelSetCacheXP : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelsetxp"; }
|
||||
};
|
||||
|
||||
//! FSX
|
||||
struct ModelSetCacheFsx : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelsetfsx"; }
|
||||
};
|
||||
|
||||
//! FS9
|
||||
struct ModelSetCacheFs9 : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelsetfs9"; }
|
||||
};
|
||||
|
||||
//! P3D
|
||||
struct ModelSetCacheP3D : public ModelCache
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "modelsetp3d"; }
|
||||
};
|
||||
//! @}
|
||||
|
||||
|
||||
//! Trait for vPilot derived models
|
||||
struct VPilotAircraftModels : public BlackMisc::CDataTrait<BlackMisc::Simulation::CAircraftModelList>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "vpilot/models"; }
|
||||
};
|
||||
|
||||
//! Bundle of caches for all simulators
|
||||
//! \remark Temp. workaround
|
||||
class CModelCaches : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Construtor
|
||||
CModelCaches(QObject *parent = nullptr);
|
||||
|
||||
//! Models
|
||||
CAircraftModelList getModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Set models
|
||||
BlackMisc::CStatusMessage setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Cache timestamp
|
||||
QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Syncronize
|
||||
void syncronize(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
private:
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFsx> m_modelCacheFsx {this }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this }; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheXP> m_modelCacheXP {this }; //!< XP cache
|
||||
};
|
||||
|
||||
|
||||
//! Bundle of caches for model sets of all simulators
|
||||
//! \remark Temp. workaround
|
||||
class CModelSetCaches : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Construtor
|
||||
CModelSetCaches(QObject *parent = nullptr);
|
||||
|
||||
//! Models
|
||||
CAircraftModelList getModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Set models
|
||||
BlackMisc::CStatusMessage setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Cache timestamp
|
||||
QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Syncronize
|
||||
void syncronize(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
private:
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFsx> m_modelCacheFsx {this }; //!< FSX cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFs9> m_modelCacheFs9 {this }; //!< FS9 cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheP3D> m_modelCacheP3D {this }; //!< P3D cache
|
||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheXP> m_modelCacheXP {this }; //!< XP cache
|
||||
};
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user