Nebula
Loading...
Searching...
No Matches
Resources::ResourceLoader Class Referenceabstract

#include <resourceloader.h>

Inherits Core::RefCounted.

Inherited by Characters::SkeletonLoader, CoreAnimation::AnimationLoader, CoreGraphics::MeshLoader, CoreGraphics::ShaderLoader, CoreGraphics::TextureLoader, Materials::MaterialLoader, Models::ModelLoader, and Physics::StreamActorPool.

Classes

struct  _Callbacks
 callback functions to run when an associated resource is loaded (can be stacked) More...
 
struct  _LoadMetaData
 
struct  _PendingResourceLoad
 struct for pending resources which are about to be loaded More...
 
struct  _PendingResourceUnload
 
struct  _PendingStreamLod
 struct for pending stream More...
 
struct  _PlaceholderResource
 
struct  _StreamData
 
struct  LoadState
 
struct  ResourceInitOutput
 
struct  ResourceLoadJob
 
struct  ResourceLoadOutput
 
struct  ResourceStreamOutput
 

Public Member Functions

 ResourceLoader ()
 constructor
 
virtual ~ResourceLoader ()
 destructor
 
virtual void Setup ()
 setup resource loader, initiates the placeholder and error resources if valid, so don't forget to run!
 
virtual void Discard ()
 discard resource loader
 
virtual void LoadFallbackResources ()
 load placeholder and error resources
 
Resources::ResourceId CreateResource (const Resources::ResourceName &res, const void *loadInfo, SizeT loadInfoSize, const Util::StringAtom &tag, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed, bool immediate, bool stream)
 create a container with a tag associated with it, if no tag is provided, the resource will be untagged
 
void DiscardResource (const Resources::ResourceId id)
 discard container
 
void DiscardByTag (const Util::StringAtom &tag)
 discard all resources associated with a tag
 
void CreateListener (const Resources::ResourceId res, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed)
 Create new listener on resource.
 
const Resources::ResourceNameGetName (const Resources::ResourceId id) const
 get resource name
 
const uint32_t GetUsage (const Resources::ResourceId id) const
 get resource usage from resource id
 
const Util::StringAtom GetTag (const Resources::ResourceId id) const
 get resource tag was first registered with
 
const Resource::State GetState (const Resources::ResourceId id) const
 get resource state
 
const Resources::ResourceId GetId (const Resources::ResourceName &name) const
 get resource id by name, use with care
 
const Util::Dictionary< Resources::ResourceName, Ids::Id32 > & GetResources () const
 get the dictionary of all resource-id pairs
 
const bool HasResource (const Resources::ResourceId id) const
 returns true if pool has resource
 
const int32_t & GetUniqueId () const
 get the global identifier for this pool
 
void ReloadResource (const Resources::ResourceName &res, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed)
 reload resource using resource name
 
void ReloadResource (const Resources::ResourceId &id, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed)
 reload resource using resource id
 
void SetMinLod (const Resources::ResourceId &id, const float lod, bool immediate)
 begin updating a resources lod
 
- Public Member Functions inherited from Core::RefCounted
 RefCounted ()
 constructor
 
int GetRefCount () const
 get the current refcount
 
void AddRef ()
 increment refcount by one
 
void Release ()
 decrement refcount and destroy object if refcount is zero
 
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
 
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
 
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
 
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
 
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
 
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
 
const Util::StringGetClassName () const
 get the class name
 
Util::FourCC GetClassFourCC () const
 get the class FourCC code
 

Protected Member Functions

virtual void UpdateLoaderSyncState ()
 Update loader internal state.
 
virtual ResourceInitOutput InitializeResource (const ResourceLoadJob &job, const Ptr< IO::Stream > &stream)=0
 Initialize and create the resource, optionally load if no subresource management is necessary.
 
virtual ResourceStreamOutput StreamResource (const ResourceLoadJob &job)
 Stream resource.
 
virtual Resource::State ReloadFromStream (const Resources::ResourceId id, const Ptr< IO::Stream > &stream)
 perform a reload
 
virtual uint LodMask (const _StreamData &stream, float lod, bool async) const
 Create load mask based on LOD. This will be used to determine if the resoure is fully loaded.
 
virtual void RequestLOD (const Ids::Id32 entry, float lod) const
 Set lod factor for resource.
 
virtual void Unload (const Resources::ResourceId id)=0
 unload resource (overload to implement resource deallocation)
 
virtual void Update (IndexT frameIndex)
 update the resource loader, this is done every frame
 
void SetupIdFromEntry (const Ids::Id32 entry, ResourceId &cacheEntry)
 Construct resource ID based on loader entry.
 
void RunCallbacks (Resource::State status, const Resources::ResourceId id)
 run callbacks
 
void EnqueueJob (const std::function< void()> &func)
 Issue async job.
 
Resources::ResourceId GetPlaceholder (const Resources::ResourceName &name)
 get placeholder based on resource name
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Protected Attributes

Util::FixedArray< _PlaceholderResourceplaceholders
 
Util::StringAtom placeholderResourceName
 these types need to be properly initiated in a subclass Setup function
 
Util::StringAtom failResourceName
 
Resources::ResourceId placeholderResourceId
 
Resources::ResourceId failResourceId
 
bool async
 
Ptr< ResourceLoaderThreadstreamerThread
 
std::function< void()> preJobFunc
 
std::function< void()> postJobFunc
 
Util::StringAtom streamerThreadName
 
Util::Array< IndexTpendingLoads
 
Util::Array< _PendingResourceUnloadpendingUnloads
 
Util::Array< _PendingStreamLodpendingStreamLods
 
Threading::SafeQueue< _PendingStreamLodpendingStreamQueue
 
Threading::SafeQueue< ResourceLoadOutputloadOutputs
 
Util::Array< ResourceLoadJobdependentJobs
 
Util::Dictionary< Resources::ResourceName, uint32_t > ids
 
Ids::IdPool resourceInstanceIndexPool
 
Util::FixedArray< Resources::ResourceNamenames
 
Util::FixedArray< uint32_t > usage
 
Util::FixedArray< Util::StringAtomtags
 
Util::FixedArray< Resource::Statestates
 
Util::FixedArray< LoadStateloadStates
 
Util::FixedArray< ResourceId > resources
 
Util::FixedArray< Util::Array< _Callbacks > > callbacks
 
Util::FixedArray< _PendingResourceLoadloads
 
Util::FixedArray< _LoadMetaDatametaData
 
Util::FixedArray< _StreamDatastreamDatas
 
uint32_t uniqueResourceId
 
int32_t uniqueId
 id in resource manager
 
Threading::CriticalSection asyncSection
 async section to sync callbacks and pending list with thread
 
Threading::ThreadId creatorThread
 

Static Protected Attributes

static const uint32_t ResourceIndexGrow = 512
 

Private Member Functions

 __DeclareAbstractClass (ResourceLoader)
 

Friends

class ResourceServer
 
void ApplyLoadOutput (ResourceLoader *loader, const ResourceLoader::ResourceLoadOutput &output)
 
void DispatchJob (ResourceLoader *loader, const ResourceLoader::ResourceLoadJob &job)
 
ResourceLoadOutput _LoadInternal (ResourceLoader *loader, ResourceLoader::ResourceLoadJob job)
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
 

Constructor & Destructor Documentation

◆ ResourceLoader()

Resources::ResourceLoader::ResourceLoader ( )

constructor

◆ ~ResourceLoader()

Resources::ResourceLoader::~ResourceLoader ( )
virtual

destructor

Member Function Documentation

◆ __DeclareAbstractClass()

Resources::ResourceLoader::__DeclareAbstractClass ( ResourceLoader )
private

◆ CreateListener()

void Resources::ResourceLoader::CreateListener ( const Resources::ResourceId res,
std::function< void(const Resources::ResourceId)> success,
std::function< void(const Resources::ResourceId)> failed )

Create new listener on resource.

◆ CreateResource()

Resources::ResourceId Resources::ResourceLoader::CreateResource ( const Resources::ResourceName & res,
const void * loadInfo,
SizeT loadInfoSize,
const Util::StringAtom & tag,
std::function< void(const Resources::ResourceId)> success,
std::function< void(const Resources::ResourceId)> failed,
bool immediate,
bool stream )

create a container with a tag associated with it, if no tag is provided, the resource will be untagged

◆ Discard()

void Resources::ResourceLoader::Discard ( )
virtual

discard resource loader

◆ DiscardByTag()

void Resources::ResourceLoader::DiscardByTag ( const Util::StringAtom & tag)

discard all resources associated with a tag

◆ DiscardResource()

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

discard container

◆ EnqueueJob()

void Resources::ResourceLoader::EnqueueJob ( const std::function< void()> & func)
protected

Issue async job.

◆ GetId()

const Resources::ResourceId Resources::ResourceLoader::GetId ( const Resources::ResourceName & name) const
inline

get resource id by name, use with care

◆ GetName()

const Resources::ResourceName & Resources::ResourceLoader::GetName ( const Resources::ResourceId id) const
inline

get resource name

◆ GetPlaceholder()

Resources::ResourceId Resources::ResourceLoader::GetPlaceholder ( const Resources::ResourceName & name)
protected

get placeholder based on resource name

◆ GetResources()

const Util::Dictionary< Resources::ResourceName, Ids::Id32 > & Resources::ResourceLoader::GetResources ( ) const
inline

get the dictionary of all resource-id pairs

◆ GetState()

const Resources::Resource::State Resources::ResourceLoader::GetState ( const Resources::ResourceId id) const
inline

get resource state

◆ GetTag()

const Util::StringAtom Resources::ResourceLoader::GetTag ( const Resources::ResourceId id) const
inline

get resource tag was first registered with

◆ GetUniqueId()

const int32_t & Resources::ResourceLoader::GetUniqueId ( ) const
inline

get the global identifier for this pool

◆ GetUsage()

const uint32_t Resources::ResourceLoader::GetUsage ( const Resources::ResourceId id) const
inline

get resource usage from resource id

◆ HasResource()

const bool Resources::ResourceLoader::HasResource ( const Resources::ResourceId id) const
inline

returns true if pool has resource

◆ InitializeResource()

virtual ResourceInitOutput Resources::ResourceLoader::InitializeResource ( const ResourceLoadJob & job,
const Ptr< IO::Stream > & stream )
protectedpure virtual

◆ LoadFallbackResources()

void Resources::ResourceLoader::LoadFallbackResources ( )
virtual

load placeholder and error resources

◆ LodMask()

uint Resources::ResourceLoader::LodMask ( const _StreamData & stream,
float lod,
bool async ) const
protectedvirtual

Create load mask based on LOD. This will be used to determine if the resoure is fully loaded.

Reimplemented in CoreGraphics::MeshLoader, CoreGraphics::TextureLoader, and Models::ModelLoader.

◆ ReloadFromStream()

Resource::State Resources::ResourceLoader::ReloadFromStream ( const Resources::ResourceId id,
const Ptr< IO::Stream > & stream )
protectedvirtual

perform a reload

Reimplemented in CoreGraphics::ShaderLoader.

◆ ReloadResource() [1/2]

void Resources::ResourceLoader::ReloadResource ( const Resources::ResourceId & id,
std::function< void(const Resources::ResourceId)> success,
std::function< void(const Resources::ResourceId)> failed )

reload resource using resource id

◆ ReloadResource() [2/2]

void Resources::ResourceLoader::ReloadResource ( const Resources::ResourceName & res,
std::function< void(const Resources::ResourceId)> success,
std::function< void(const Resources::ResourceId)> failed )

reload resource using resource name

◆ RequestLOD()

void Resources::ResourceLoader::RequestLOD ( const Ids::Id32 entry,
float lod ) const
protectedvirtual

Set lod factor for resource.

◆ RunCallbacks()

void Resources::ResourceLoader::RunCallbacks ( Resource::State status,
const Resources::ResourceId id )
protected

run callbacks

Run all callbacks pending on a resource, must be within the critical section!

◆ SetMinLod()

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

begin updating a resources lod

◆ Setup()

void Resources::ResourceLoader::Setup ( )
virtual

setup resource loader, initiates the placeholder and error resources if valid, so don't forget to run!

Reimplemented in Materials::MaterialLoader, Models::ModelLoader, and Physics::StreamActorPool.

◆ SetupIdFromEntry()

void Resources::ResourceLoader::SetupIdFromEntry ( const Ids::Id32 entry,
ResourceId & cacheEntry )
protected

Construct resource ID based on loader entry.

◆ StreamResource()

ResourceLoader::ResourceStreamOutput Resources::ResourceLoader::StreamResource ( const ResourceLoadJob & job)
protectedvirtual

◆ Unload()

virtual void Resources::ResourceLoader::Unload ( const Resources::ResourceId id)
protectedpure virtual

◆ Update()

void Resources::ResourceLoader::Update ( IndexT frameIndex)
protectedvirtual

update the resource loader, this is done every frame

◆ UpdateLoaderSyncState()

void Resources::ResourceLoader::UpdateLoaderSyncState ( )
protectedvirtual

Update loader internal state.

Reimplemented in CoreGraphics::MeshLoader, and CoreGraphics::TextureLoader.

Friends And Related Symbol Documentation

◆ _LoadInternal

ResourceLoadOutput _LoadInternal ( ResourceLoader * loader,
ResourceLoader::ResourceLoadJob job )
friend

Enqueue resource load output

◆ ApplyLoadOutput

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

◆ DispatchJob

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

◆ ResourceServer

friend class ResourceServer
friend

Member Data Documentation

◆ async

bool Resources::ResourceLoader::async
protected

◆ asyncSection

Threading::CriticalSection Resources::ResourceLoader::asyncSection
protected

async section to sync callbacks and pending list with thread

◆ callbacks

Util::FixedArray<Util::Array<_Callbacks> > Resources::ResourceLoader::callbacks
protected

◆ creatorThread

Threading::ThreadId Resources::ResourceLoader::creatorThread
protected

◆ dependentJobs

Util::Array<ResourceLoadJob> Resources::ResourceLoader::dependentJobs
protected

◆ failResourceId

Resources::ResourceId Resources::ResourceLoader::failResourceId
protected

◆ failResourceName

Util::StringAtom Resources::ResourceLoader::failResourceName
protected

◆ ids

Util::Dictionary<Resources::ResourceName, uint32_t> Resources::ResourceLoader::ids
protected

◆ loadOutputs

Threading::SafeQueue<ResourceLoadOutput> Resources::ResourceLoader::loadOutputs
protected

◆ loads

Util::FixedArray<_PendingResourceLoad> Resources::ResourceLoader::loads
protected

◆ loadStates

Util::FixedArray<LoadState> Resources::ResourceLoader::loadStates
protected

◆ metaData

Util::FixedArray<_LoadMetaData> Resources::ResourceLoader::metaData
protected

◆ names

Util::FixedArray<Resources::ResourceName> Resources::ResourceLoader::names
protected

◆ pendingLoads

Util::Array<IndexT> Resources::ResourceLoader::pendingLoads
protected

◆ pendingStreamLods

Util::Array<_PendingStreamLod> Resources::ResourceLoader::pendingStreamLods
protected

◆ pendingStreamQueue

Threading::SafeQueue<_PendingStreamLod> Resources::ResourceLoader::pendingStreamQueue
protected

◆ pendingUnloads

Util::Array<_PendingResourceUnload> Resources::ResourceLoader::pendingUnloads
protected

◆ placeholderResourceId

Resources::ResourceId Resources::ResourceLoader::placeholderResourceId
protected

◆ placeholderResourceName

Util::StringAtom Resources::ResourceLoader::placeholderResourceName
protected

these types need to be properly initiated in a subclass Setup function

◆ placeholders

Util::FixedArray<_PlaceholderResource> Resources::ResourceLoader::placeholders
protected

◆ postJobFunc

std::function<void()> Resources::ResourceLoader::postJobFunc
protected

◆ preJobFunc

std::function<void()> Resources::ResourceLoader::preJobFunc
protected

◆ ResourceIndexGrow

const uint32_t Resources::ResourceLoader::ResourceIndexGrow = 512
staticprotected

◆ resourceInstanceIndexPool

Ids::IdPool Resources::ResourceLoader::resourceInstanceIndexPool
protected

◆ resources

Util::FixedArray<ResourceId> Resources::ResourceLoader::resources
protected

◆ states

Util::FixedArray<Resource::State> Resources::ResourceLoader::states
protected

◆ streamDatas

Util::FixedArray<_StreamData> Resources::ResourceLoader::streamDatas
protected

◆ streamerThread

Ptr<ResourceLoaderThread> Resources::ResourceLoader::streamerThread
protected

◆ streamerThreadName

Util::StringAtom Resources::ResourceLoader::streamerThreadName
protected

◆ tags

Util::FixedArray<Util::StringAtom> Resources::ResourceLoader::tags
protected

◆ uniqueId

int32_t Resources::ResourceLoader::uniqueId
protected

id in resource manager

◆ uniqueResourceId

uint32_t Resources::ResourceLoader::uniqueResourceId
protected

◆ usage

Util::FixedArray<uint32_t> Resources::ResourceLoader::usage
protected

The documentation for this class was generated from the following files: