48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
// Copyright (c) 2022 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "Asset.hpp"
|
|
|
|
namespace Dawn {
|
|
class AssetManager {
|
|
private:
|
|
/** List of pointers to assets, mapped by their asset key. */
|
|
std::map<std::string, Asset*> assets;
|
|
std::map<std::string, Asset*> assetsNotLoaded;
|
|
|
|
public:
|
|
void init();
|
|
void update();
|
|
|
|
/**
|
|
* Creates and queue an asset to load.
|
|
*
|
|
* @param name Name of the asset to load.
|
|
* @return The asset element to be loaded.
|
|
*/
|
|
template<class T>
|
|
T * load(std::string name) {
|
|
assertTrue(name.size() > 0);
|
|
|
|
auto existing = this->assets.find(name);
|
|
if(existing != this->assets.end()) {
|
|
return (T*)existing->second;
|
|
}
|
|
auto asset = new T(this, name);
|
|
this->assets[name] = asset;
|
|
this->assetsNotLoaded[name] = asset;
|
|
return asset;
|
|
}
|
|
|
|
template<class T>
|
|
void unload(std::string name) {
|
|
assertUnreachable();
|
|
//should delete the asset for you
|
|
}
|
|
|
|
~AssetManager();
|
|
};
|
|
} |