![]() |
Lysa
0.0
Lysa 3D Engine
|
Generic object/resources manager using ID-based access.
Manages a contiguous pool (vector) of resources of type T addressed by a small integral unique identifier (unique_id). Instances are created into available slots and retrieved via their ID. Destruction returns the slot to a free list for reuse.
The manager does not perform dynamic growth; capacity is fixed at construction. All accessors are O(1) by direct indexing. This class is intended to be used as a base for concrete resource managers (e.g., textures, meshes, materials).
Public Member Functions | |
| template<typename... Args> | |
| T & | create (Args &&...args) |
| T & | operator[] (const unique_id id) |
| const T & | operator[] (const unique_id id) const |
| virtual | ~ResourcesManager () |
| ResourcesManager (ResourcesManager &) = delete | |
| ResourcesManager & | operator= (ResourcesManager &) = delete |
| virtual bool | destroy (const unique_id id) |
| virtual bool | destroy (const T &res) |
| void | destroy (const std::vector< unique_id > &ids) |
| void | use (const unique_id id) |
| bool | have (const unique_id id) const |
| unique_id | getCapacity () const |
| template<typename Func > | |
| void | forEach (Func &&func) |
| template<typename Func > | |
| void | forEach (Func &&func) const |
Protected Member Functions | |
| ResourcesManager (const size_t capacity, const std::string &name) | |
| T & | allocate (std::unique_ptr< T > instance) |
| bool | isFull () const |
Protected Attributes | |
| std::vector< std::unique_ptr< T > > | resources |
| std::mutex | resourcesMutex |
|
inlinevirtual |
|
delete |
|
inlineprotected |
|
inlineprotected |
|
inline |
Create a new unique resource
|
inline |
Releases a batch of resources by ID. Each resource is destroyed individually; slots are freed as their reference counters reach zero.
| ids | List of unique identifiers to destroy. |
|
inlinevirtual |
Releases a resource by reference, decrementing its reference counter.
| res | Resource to destroy. |
Reimplemented in lysa::MeshManager::destroy(), lysa::ImageManager::destroy()
|
inlinevirtual |
Releases a resource by ID, decrementing its reference counter. The slot is returned to the free list only when the counter reaches zero.
| id | Unique identifier of the resource to destroy. |
Reimplemented in lysa::MaterialManager::destroy(), lysa::MeshManager::destroy(), lysa::ImageManager::destroy()
|
inline |
|
inline |
|
inline |
|
inline |
returns true if the id is valid
|
inlineprotected |
|
delete |
|
inline |
Bracket operator for mutable access without bounds checking.
| id | The unique identifier of the resource. |
|
inline |
Bracket operator for const access without bounds checking.
| id | The unique identifier of the resource. |
|
inline |
Increments the reference counter of the resources
|
protected |
|
protected |