Generic manifest-driven resource cache. More...
#include <ResourceManager.h>
Static Public Member Functions | |
| template<typename Asset> | |
| static const Resource & | get (const Asset &asset) |
| Retrieve the cached resource for an asset enum value. | |
| template<typename Asset> | |
| static void | unload (Asset asset) |
| Remove a resource from the cache. | |
Generic manifest-driven resource cache.
ResourceManager<Manifest, Resource, loadFunction> is the base for all Malena asset managers. It maps enum keys (declared in Manifest) to loaded Resource instances, loading each resource lazily on first access and caching it for subsequent calls.
The load function is a compile-time parameter, allowing each resource type to use the appropriate SFML loading API without virtual dispatch.
| Manifest | A Manifest subclass whose enum keys map to file paths. |
| Resource | The SFML resource type to load and cache. |
| loadFunction | Function pointer bool(Resource&, const std::string&). |
Definition at line 41 of file ResourceManager.h.
|
static |
Retrieve the cached resource for an asset enum value.
Loads and caches on first access. Throws std::runtime_error if the path is not registered or loading fails.
| Asset | An enum type declared inside Manifest. |
| asset | The specific enum value to load. |
Resource.
|
static |
Remove a resource from the cache.
The next get(asset) call will reload from disk. If called during draw(), the unload is deferred until after the frame completes to prevent mid-frame dangling references.
| Asset | The enum type of the key to remove. |
| asset | The specific enum value to evict from the cache. |