Nebula
Loading...
Searching...
No Matches
Resources Namespace Reference

Detailed Description

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.

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.

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:

  1. Placeholder resource
  2. 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.

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().

Classes

class  Resource
 
class  ResourceLoader
 
class  ResourceLoaderThread
 
class  ResourceSaver
 
class  ResourceServer
 
struct  ResourceUnknownId
 

Typedefs

typedef Util::StringAtom ResourceName
 

Enumerations

enum  LoadFlags { None = 0x0 , Create = 0x1 , Update = 0x2 }
 

Functions

 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 ()
 

Variables

 id
 

Typedef Documentation

◆ ResourceName

Enumeration Type Documentation

◆ LoadFlags

Enumerator
None 
Create 
Update 

Function Documentation

◆ __ImplementAbstractClass() [1/2]

Resources::__ImplementAbstractClass ( Resources::ResourceLoader ,
'RSLO' ,
Core::RefCounted  )

◆ __ImplementAbstractClass() [2/2]

Resources::__ImplementAbstractClass ( Resources::ResourceSaver ,
'RESA' ,
Core::RefCounted  )

◆ __ImplementClass() [1/2]

Resources::__ImplementClass ( Resources::ResourceLoaderThread ,
'RETH' ,
Threading::Thread  )

◆ __ImplementClass() [2/2]

Resources::__ImplementClass ( Resources::ResourceServer ,
'RMGR' ,
Core::RefCounted  )

◆ __ImplementEnumBitOperators()

Resources::__ImplementEnumBitOperators ( LoadFlags )

◆ __ImplementInterfaceSingleton()

Resources::__ImplementInterfaceSingleton ( Resources::ResourceServer )

◆ _LoadInternal()

Enqueue resource load output

◆ ApplyLoadOutput()

void Resources::ApplyLoadOutput ( ResourceLoader * loader,
const ResourceLoader::ResourceLoadOutput & output )

◆ CreateResource() [1/2]

template<class METADATA >
Resources::ResourceId Resources::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 )
inline

◆ CreateResource() [2/2]

Resources::ResourceId Resources::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 )
inline

◆ CreateResourceListener()

void Resources::CreateResourceListener ( const ResourceId & id,
std::function< void(const Resources::ResourceId)> success,
std::function< void(const Resources::ResourceId)> failed = nullptr )
inline

◆ DiscardResource()

void Resources::DiscardResource ( const Resources::ResourceId id)
inline

◆ DispatchJob()

void Resources::DispatchJob ( ResourceLoader * loader,
const ResourceLoader::ResourceLoadJob & job )

◆ GetStreamLoader()

template<class POOL_TYPE >
POOL_TYPE * Resources::GetStreamLoader ( )
inline

◆ ID_24_8_24_8_NAMED_TYPE()

Resources::ID_24_8_24_8_NAMED_TYPE ( ResourceId ,
loaderInstanceId ,
loaderIndex ,
resourceId ,
generation ,
loader ,
resource  )

◆ ReloadResource()

void Resources::ReloadResource ( const ResourceName & res)
inline

◆ SetMinLod()

void Resources::SetMinLod ( const ResourceId & id,
float lod,
bool immediate )
inline

◆ WaitForLoaderThread()

void Resources::WaitForLoaderThread ( )
inline

Variable Documentation

◆ id

Resources::id