Open type-erased resource registry with typed handles and generational lifetimes.
More...
|
| template<typename ResourceType> |
| auto | add (ResourceType &&resource) |
| | Put resource in the graph under its name, stamping its identity.
|
| template<typename ResourceType> |
| auto | add (ResourceType &&resource, std::string name) |
| | add() under name.
|
| template<typename ResourceType> |
| auto | addPrivate (ResourceType &&resource, std::string name) |
| | add() under name, setting Resource::isHidden: kept from the user and scene saves.
|
| template<typename HandleType> |
| void | remove (const HandleType &handle) |
| | Remove a resource: its name mapping, storage and handle slot.
|
| template<typename HandleType> |
| bool | isAlive (const HandleType &handle) const |
| | Whether handle still names a live resource of its type.
|
| template<typename HandleType> |
| const auto & | get (const HandleType &handle) const |
| | The resource handle names; asserts it is live (see isAlive(), tryGet()).
|
| template<typename HandleType> |
| const auto * | tryGet (const HandleType &handle) const |
| | The asset handle names, or null when it names none.
|
| template<typename HandleType> |
| auto * | tryEdit (const HandleType &handle) |
| | The asset handle names for editing, or null when it names none.
|
| template<typename HandleType> |
| auto & | edit (const HandleType &handle) |
| | Mutable access to the resource handle names.
|
| template<typename HandleType> |
| void | rename (const HandleType &handle, std::string newName) |
| | Rename a resource, keeping findByName consistent.
|
| template<typename HandleType> |
| void | swapValue (const HandleType &handle, typename HandleType::resource_t &value) |
| | Exchange the contents of the asset at handle with value, each keeping its identity, and commit.
|
| template<typename HandleType> |
| void | commit (const HandleType &handle) |
| | Bump the asset's version, which GLView::sync keys its GPU re-upload on.
|
| template<typename T> |
| Handle< T > | findByName (const std::string &name) const |
| | Find a resource by the name it was added or renamed under, in O(1).
|
| template<typename T> |
| Handle< T > | find (const AssetRef< T > &ref) const |
| | Resolve an authored reference to the asset it names.
|
| template<typename T, typename Fn> |
| void | forEachOfType (Fn &&fn) const |
| | Visit every live resource of type T; a linear scan for tooling, not hot paths.
|
| template<typename T> |
| size_t | countOfType () const |
| | How many resources of type T the graph holds.
|
| void | clear () |
| | Drop every resource but the fonts, by swap() with an empty manager.
|
| void | swap (ResourceManager &other) noexcept |
| | Swap the asset graph with another ResourceManager, fonts excepted.
|
| uint64_t | epoch () const |
| | Identity of the current asset graph, bumped by every swap.
|
Open type-erased resource registry with typed handles and generational lifetimes.
Per type, as in Scene: a SlotAllocator, a SparseSet<T> and a name index.
Only the engine's asset types (IS_ENGINE_ASSET) are stored, each slot made in vkm_core at construction. A SparseSet<T> carries the vtable of the binary that made it, so a slot a gameplay module made would outlive the module past dlclose; any other type is a compile error. See scripting.md, "Nothing may hold module code across the swap".
template<typename ResourceType>
| auto Vkm::Engine::ResourceManager::add |
( |
ResourceType && | resource | ) |
|
|
inline |
Put resource in the graph under its name, stamping its identity.
The name is the identity (what a scene file stores), so naming one that exists replaces its contents in place and returns the existing handle; this keeps adding repeatable across a script reload, where onStart runs again. An unnamed asset gets a free name ("asset", "asset (2)", ...) instead. Either way it gets a fresh uid, so an async completion minted against a previous occupant can tell.
- Template Parameters
-
| ResourceType | The asset type, deriving from Resource. |
- Parameters
-
| resource | The asset to add (moved from). |
- Returns
- The handle naming the asset - the existing one on a replace.
template<typename HandleType>
| void Vkm::Engine::ResourceManager::swapValue |
( |
const HandleType & | handle, |
|
|
typename HandleType::resource_t & | value ) |
|
inline |
Exchange the contents of the asset at handle with value, each keeping its identity, and commit.
Rebuilds an asset without reissuing it: handles and findByName keep naming it. The value's name, uid, hidden flag and version are traded back rather than riding in, which would break the name index and replay a version the backend has seen; value can be removed afterwards like any other asset.
- Template Parameters
-
| HandleType | Handle type identifying the resource type. |
- Parameters
-
| handle | The asset to rebuild; must still be live. |
| value | The new contents; receives the old ones. |