|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
Typed resource pool with reference counting. More...
#include <ResourcePool.hpp>

Classes | |
| struct | Entry |
| Entry storing a resource with metadata. More... | |
Public Member Functions | |
| ResourcePool () | |
| ~ResourcePool () override=default | |
| ResourcePool (const ResourcePool &)=delete | |
| ResourcePool & | operator= (const ResourcePool &)=delete |
| ResourcePool (ResourcePool &&)=default | |
| ResourcePool & | operator= (ResourcePool &&)=default |
| Handle< T > | add (Unique< T > resource, const std::string &path="", usize bytes=0) |
| Adds a resource to the pool. | |
| template<typename Fn> | |
| void | forEachAlive (Fn &&fn) |
| Visits every live resource, with the handle naming it. | |
| template<typename Fn> | |
| void | forEachAlive (Fn &&fn) const |
| T * | get (Handle< T > handle) |
| Gets a resource by handle. | |
| const T * | get (Handle< T > handle) const |
| Gets a resource by handle (const). | |
| Handle< T > | findByPath (const std::string &path) const |
| Finds a resource by its cached path. | |
| void | setPath (Handle< T > handle, const std::string &path) |
| Associates a path with an existing resource. | |
| void | addRef (Handle< T > handle) |
| Increments the reference count for a resource. | |
| void | release (u32 id) override |
| Decrements the reference count and frees if zero. | |
| usize | size () const override |
| Gets the number of active resources. | |
| void | clear () override |
| Releases all resources. | |
| void | setBudget (usize bytes) |
| Sets the resident-byte budget. 0 (default) disables caching — a resource is freed the instant its refCount hits 0 (legacy behavior). When > 0, refCount==0 resources are retained as evictable cache entries and dropped (oldest-first) only when over budget. | |
| usize | budget () const |
| The current resident-byte budget (0 = caching disabled). | |
| usize | trimEvictables () |
| Frees every evictable (refCount==0) cache entry immediately. | |
| bool | invalidatePath (const std::string &path) |
| Severs a path's cache identity so the entry can't be revived. | |
| usize | residentBytes () const |
| Bytes currently resident (held + evictable entries). | |
| usize | evictableCount () const |
| Number of evictable (refCount==0, cached) entries. | |
| bool | isEvictable (Handle< T > handle) const |
| True if the handle's entry is alive but evictable (cached). | |
| u32 | getRefCount (Handle< T > handle) const |
| Gets the current reference count for a resource. | |
| const std::string & | getPath (Handle< T > handle) const |
| Gets the cached path for a resource. | |
| Public Member Functions inherited from esengine::resource::ResourcePoolBase | |
| virtual | ~ResourcePoolBase ()=default |
Typed resource pool with reference counting.
Stores resources in a dense array with a free list for recycling slots. Supports optional path-based caching for deduplication.
| T | The resource type to manage (must be movable) |
Definition at line 85 of file ResourcePool.hpp.
|
inline |
Definition at line 101 of file ResourcePool.hpp.
Referenced by ResourcePool(), ResourcePool(), operator=(), and operator=().
|
overridedefault |
|
delete |
References ResourcePool().
|
default |
References ResourcePool().
|
inline |
Adds a resource to the pool.
| resource | The resource to add (takes ownership) |
| path | Optional path for cache lookup |
| bytes | Resource size for the eviction budget (0 = untracked) |
Definition at line 119 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::fromParts().
|
inline |
Increments the reference count for a resource.
| handle | The resource handle |
Definition at line 236 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
inline |
The current resident-byte budget (0 = caching disabled).
Definition at line 317 of file ResourcePool.hpp.
|
inlineoverridevirtual |
Releases all resources.
Implements esengine::resource::ResourcePoolBase.
Definition at line 291 of file ResourcePool.hpp.
|
inline |
Number of evictable (refCount==0, cached) entries.
Definition at line 366 of file ResourcePool.hpp.
|
inline |
Finds a resource by its cached path.
| path | The path to look up |
Definition at line 202 of file ResourcePool.hpp.
|
inline |
Visits every live resource, with the handle naming it.
For sweeps that must reach resources by identity rather than by path, including the ones created from pixels and never given one.
Definition at line 147 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::fromParts(), esengine::resource::ResourcePool< T >::Entry::generation, and esengine::resource::ResourcePool< T >::Entry::resource.
|
inline |
Definition at line 156 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::fromParts(), esengine::resource::ResourcePool< T >::Entry::generation, and esengine::resource::ResourcePool< T >::Entry::resource.
|
inline |
Gets a resource by handle.
| handle | The resource handle |
Definition at line 170 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
inline |
Gets a resource by handle (const).
| handle | The resource handle |
Definition at line 186 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
inline |
Gets the cached path for a resource.
| handle | The resource handle |
Definition at line 400 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
inline |
Gets the current reference count for a resource.
| handle | The resource handle |
Definition at line 386 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
inline |
Severs a path's cache identity so the entry can't be revived.
For hot reload: the bytes behind path changed, so the cached resource must never be handed out for that path again. Removes the path mapping; an evictable entry is freed immediately, a held entry stays alive for its current holders but loses its path, so its final release frees it instead of caching it.
| path | The path to invalidate |
Definition at line 346 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::extractGeneration(), and esengine::resource::Handle< T >::extractIndex().
|
inline |
True if the handle's entry is alive but evictable (cached).
Definition at line 373 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
delete |
References ResourcePool().
|
default |
References ResourcePool().
|
inlineoverridevirtual |
Decrements the reference count and frees if zero.
| id | The resource identifier |
Implements esengine::resource::ResourcePoolBase.
Definition at line 257 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::extractGeneration(), and esengine::resource::Handle< T >::extractIndex().
|
inline |
Bytes currently resident (held + evictable entries).
Definition at line 363 of file ResourcePool.hpp.
|
inline |
Sets the resident-byte budget. 0 (default) disables caching — a resource is freed the instant its refCount hits 0 (legacy behavior). When > 0, refCount==0 resources are retained as evictable cache entries and dropped (oldest-first) only when over budget.
Definition at line 311 of file ResourcePool.hpp.
|
inline |
Associates a path with an existing resource.
| handle | The resource handle |
| path | The path to associate |
Definition at line 218 of file ResourcePool.hpp.
References esengine::resource::Handle< T >::generation(), esengine::resource::Handle< T >::id(), esengine::resource::Handle< T >::index(), and esengine::resource::Handle< T >::isValid().
|
inlineoverridevirtual |
Gets the number of active resources.
Implements esengine::resource::ResourcePoolBase.
Definition at line 284 of file ResourcePool.hpp.
|
inline |
Frees every evictable (refCount==0) cache entry immediately.
The memory-pressure response: held resources are untouched, but the whole warm cache is dropped regardless of the budget. The budget itself is unchanged — the cache refills as resources are released afterwards.
Definition at line 327 of file ResourcePool.hpp.