mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-20 13:25:10 +00:00
generic cache system
This commit is contained in:
@@ -12,7 +12,8 @@
|
||||
|
||||
namespace RAY::Drawables::Drawables3D {
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<::Model>> Model::_modelsCache;
|
||||
RAY::Cache<::Model> Model::_modelsCache(LoadModel, UnloadModel);
|
||||
|
||||
Model::Model(const std::string &filename,
|
||||
std::optional<std::pair<MaterialType, std::string>> texture,
|
||||
const RAY::Vector3 &position,
|
||||
@@ -20,7 +21,7 @@ namespace RAY::Drawables::Drawables3D {
|
||||
float rotationAngle,
|
||||
const RAY::Vector3 &scale)
|
||||
: ADrawable3D(position, WHITE),
|
||||
_model(fetchModelInCache(filename)),
|
||||
_model(_modelsCache.fetch(filename)),
|
||||
_rotationAxis(rotationAxis),
|
||||
_rotationAngle(rotationAngle),
|
||||
_scale(scale)
|
||||
@@ -105,15 +106,4 @@ namespace RAY::Drawables::Drawables3D {
|
||||
{
|
||||
DrawModelEx(*this->_model, this->_position, this->_rotationAxis, this->_rotationAngle, this->_scale, this->_color);
|
||||
}
|
||||
|
||||
std::shared_ptr<::Model> Model::fetchModelInCache(const std::string &path)
|
||||
{
|
||||
if (Model::_modelsCache.find(path) == Model::_modelsCache.end())
|
||||
Model::_modelsCache.emplace(path, std::shared_ptr<::Model>(
|
||||
new ::Model(LoadModel(path.c_str())), [](::Model *p) {
|
||||
UnloadModel(*p);
|
||||
delete p;
|
||||
}));
|
||||
return _modelsCache[path];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user