26 template<
typename T,
typename... Args>
27 std::shared_ptr<T>
GetOrLoad(
const std::string& key,
28 const std::string& filename,
30 static_assert(std::is_base_of<IResource, T>::value,
31 "T debe heredar de IResource");
36 auto existing = std::dynamic_pointer_cast<T>(it->second);
43 std::shared_ptr<T> resource = std::make_shared<T>(key, std::forward<Args>(args)...);
45 if (!resource->load(filename)) {
50 if (!resource->init()) {
61 std::shared_ptr<T>
Get(
const std::string& key)
const
66 return std::dynamic_pointer_cast<T>(it->second);
91 std::unordered_map<std::string, std::shared_ptr<IResource>>
m_resources;
Declara la API de IResource dentro del subsistema Core.
Declara la API de Prerequisites dentro del subsistema Core.
ResourceManager()=default
void Unload(const std::string &key)
Liberar un recurso específico.
std::shared_ptr< T > GetOrLoad(const std::string &key, const std::string &filename, Args &&... args)
Obtener o cargar un recurso de tipo T (T debe heredar de IResource).
~ResourceManager()=default
std::shared_ptr< T > Get(const std::string &key) const
Obtener un recurso ya cargado, sin cargarlo si no existe.
ResourceManager(const ResourceManager &)=delete
ResourceManager & operator=(const ResourceManager &)=delete
void UnloadAll()
Liberar todos los recursos.
static ResourceManager & getInstance()
std::unordered_map< std::string, std::shared_ptr< IResource > > m_resources