Loading...
Searching...
No Matches
ml::ResourceManager< Manifest, Resource, loadFunction > Class Template Reference

Generic manifest-driven resource cache. More...

#include <ResourceManager.h>

Inheritance diagram for ml::ResourceManager< Manifest, Resource, loadFunction >:

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.

Detailed Description

template<typename Manifest, typename Resource, bool(*)(Resource &, const std::string &) loadFunction = &fileLoader>
class ml::ResourceManager< Manifest, Resource, loadFunction >

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.

Template Parameters
ManifestA Manifest subclass whose enum keys map to file paths.
ResourceThe SFML resource type to load and cache.
loadFunctionFunction pointer bool(Resource&, const std::string&).
See also
TextureManager, FontManager, SoundManager, AssetsManager, Manifest

ResourceManager.

Definition at line 41 of file ResourceManager.h.

Member Function Documentation

◆ get()

template<typename Manifest, typename Resource, bool(*)(Resource &, const std::string &) loadFunction = &fileLoader>
template<typename Asset>
const Resource & ml::ResourceManager< Manifest, Resource, loadFunction >::get ( const Asset & asset)
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.

Template Parameters
AssetAn enum type declared inside Manifest.
Parameters
assetThe specific enum value to load.
Returns
Const reference to the cached Resource.

◆ unload()

template<typename Manifest, typename Resource, bool(*)(Resource &, const std::string &) loadFunction = &fileLoader>
template<typename Asset>
void ml::ResourceManager< Manifest, Resource, loadFunction >::unload ( Asset asset)
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.

Template Parameters
AssetThe enum type of the key to remove.
Parameters
assetThe specific enum value to evict from the cache.

The documentation for this class was generated from the following file: