A resource is a container for some type of file which is loaded.
The ResourceServer marks the central entry point into the Resource subsystem.
Saves resource to stream.
Loads resources as streams and is updated for every ResourceServer::Update().
The ResourceId type is just a StringAtom, but is primarily meant for resources.
Resources can be loaded asynchronously, and through the ResourceContainer class, a resource can be used before it is loaded.
- Copyright
- (C) 2017-2020 Individual contributors, see AUTHORS file
The first 32 bits of the resource id is used internally for the pool to relate the shared resource with the pool, since a pool can share allocator with another pool. The 24 following bytes is the actual resource handle, which can be used with the many different pools to fetch the data underlying that resource. The last 8 bits is the type of the loader, which makes it fast to lookup and delete said resource instance.
24 bytes ------------—8 bytes ------------— 24 bytes -----------— 8 bytes Pool storage id Pool id Allocator id Allocator resource type
The pool storage id is the resource level index, the pool id is the global id of the resource pool, allocator id is instance level id, and the allocator resource type is just a flag we can use to check the type of the id, in case we are confused.
Example: If we allocate a texture and want to use TextureId, then we take the 24 bytes part (id.id24) and use it to construct a Texture id, but we still need the ResourceId if we want to deallocate that texture at some later point. To convert to such an id, use the SpecializedId.
- Copyright
- (C) 2017-2020 Individual contributors, see AUTHORS file
Contains the names for the placeholder and failed-to-load resource names. When inheriting from this class, make sure to provide proper resource ids for:
- Placeholder resource
- Error resource
If no placeholder resource is provided, the loader cannot execute asynchronously. If no error resource is provided and the resource fails to load, then the ResourceServer will raise an assertion.
Each resource pool also keeps a list of the resources loaded by it. Therefore, the ResourceServer is not responsible for maintaining which resources are loaded.
The pool associates a resource name (StringAtom) with an id, such that it can be quickly retrieved.
When creating an instance of a resource, an ID is returned, this ID contains the following: 32 bits (resource instance id), 24 bits (resource id) and 8 bits (loader id). The instance id is a recyclable number which uniquely identifies a single allocation. The next 24 bits is the internal ID for the resource, which is only loaded once. The last 8 bits identifies which loader created the resource.
Resources created with tags must also be removed using the tag. A tagged resource can only be discarded by using that tag. If a resource is loaded with a tag, it will remain bound to that tag, no matter what consecutive loads say.
- Copyright
- (C) 2017-2020 Individual contributors, see AUTHORS file
-
(C) 2017-2020 Individual contributors, see AUTHORS file
It contains a set of convenience functions (which is just a proxy for the Singleton), and should be updated at least once per frame using Update().
- Copyright
- (C) 2017-2020 Individual contributors, see AUTHORS file
|
| ID_24_8_24_8_NAMED_TYPE (ResourceId, loaderInstanceId, loaderIndex, resourceId, generation, loader, resource) |
|
| __ImplementAbstractClass (Resources::ResourceLoader, 'RSLO', Core::RefCounted) |
|
void | ApplyLoadOutput (ResourceLoader *loader, const ResourceLoader::ResourceLoadOutput &output) |
|
void | DispatchJob (ResourceLoader *loader, const ResourceLoader::ResourceLoadJob &job) |
|
ResourceLoader::ResourceLoadOutput | _LoadInternal (ResourceLoader *loader, ResourceLoader::ResourceLoadJob job) |
|
| __ImplementEnumBitOperators (LoadFlags) |
|
| __ImplementClass (Resources::ResourceLoaderThread, 'RETH', Threading::Thread) |
|
| __ImplementAbstractClass (Resources::ResourceSaver, 'RESA', Core::RefCounted) |
|
| __ImplementClass (Resources::ResourceServer, 'RMGR', Core::RefCounted) |
|
| __ImplementInterfaceSingleton (Resources::ResourceServer) |
|
Resources::ResourceId | CreateResource (const ResourceName &res, const Util::StringAtom &tag, std::function< void(const Resources::ResourceId)> success=nullptr, std::function< void(const Resources::ResourceId)> failed=nullptr, bool immediate=false, bool stream=true) |
|
template<class METADATA > |
Resources::ResourceId | CreateResource (const ResourceName &res, const METADATA &metaData, const Util::StringAtom &tag, std::function< void(const Resources::ResourceId)> success=nullptr, std::function< void(const Resources::ResourceId)> failed=nullptr, bool immediate=false, bool stream=true) |
|
void | CreateResourceListener (const ResourceId &id, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed=nullptr) |
|
void | SetMinLod (const ResourceId &id, float lod, bool immediate) |
|
void | DiscardResource (const Resources::ResourceId id) |
|
void | ReloadResource (const ResourceName &res) |
|
void | WaitForLoaderThread () |
|
template<class POOL_TYPE > |
POOL_TYPE * | GetStreamLoader () |
|