84 void CreateListener(
const Resources::ResourceId res, std::function<
void(
const Resources::ResourceId)> success, std::function<
void(
const Resources::ResourceId)> failed);
89 const uint32_t
GetUsage(
const Resources::ResourceId
id)
const;
99 const bool HasResource(
const Resources::ResourceId
id)
const;
107 void ReloadResource(
const Resources::ResourceId&
id, std::function<
void(
const Resources::ResourceId)> success, std::function<
void(
const Resources::ResourceId)> failed);
110 void SetMinLod(
const Resources::ResourceId&
id,
const float lod,
bool immediate);
145 :
id(InvalidResourceUnknownId)
226 Resources::ResourceId
id;
241 std::function<void(
const Resources::ResourceId)>
success;
242 std::function<void(
const Resources::ResourceId)>
failed;
261 virtual void Unload(
const Resources::ResourceId
id) = 0;
272 void EnqueueJob(
const std::function<
void()>& func);
336 return this->
names[
id.loaderInstanceId];
345 return this->
usage[
id.loaderInstanceId];
354 return this->
tags[
id.loaderInstanceId];
363 return this->
states[
id.loaderInstanceId];
369inline const Resources::ResourceId
373 if (i ==
InvalidIndex)
return Resources::ResourceId::Invalid();
The common base class of Nebula.
Definition refcounted.h:38
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
State
Definition resource.h:26
Definition resourceloader.h:60
Ptr< ResourceLoaderThread > streamerThread
Definition resourceloader.h:293
Util::FixedArray< ResourceId > resources
Definition resourceloader.h:314
Util::FixedArray< Resources::ResourceName > names
Definition resourceloader.h:309
void EnqueueJob(const std::function< void()> &func)
Issue async job.
Definition resourceloader.cc:327
Util::Array< _PendingResourceUnload > pendingUnloads
Definition resourceloader.h:299
Util::Dictionary< Resources::ResourceName, uint32_t > ids
Definition resourceloader.h:306
__DeclareAbstractClass(ResourceLoader)
Util::FixedArray< Util::StringAtom > tags
Definition resourceloader.h:311
friend ResourceLoadOutput _LoadInternal(ResourceLoader *loader, ResourceLoadJob res)
Definition resourceloader.cc:346
std::function< void()> postJobFunc
Definition resourceloader.h:295
virtual void Setup()
setup resource loader, initiates the placeholder and error resources if valid, so don't forget to run...
Definition resourceloader.cc:42
Resources::ResourceId placeholderResourceId
Definition resourceloader.h:288
Util::StringAtom placeholderResourceName
these types need to be properly initiated in a subclass Setup function
Definition resourceloader.h:285
virtual Resource::State ReloadFromStream(const Resources::ResourceId id, const Ptr< IO::Stream > &stream)
perform a reload
Definition resourceloader.cc:117
Util::StringAtom streamerThreadName
Definition resourceloader.h:296
void DiscardByTag(const Util::StringAtom &tag)
discard all resources associated with a tag
Definition resourceloader.cc:651
void DiscardResource(const Resources::ResourceId id)
discard container
Util::FixedArray< _StreamData > streamDatas
Definition resourceloader.h:318
void RunCallbacks(Resource::State status, const Resources::ResourceId id)
run callbacks
Definition resourceloader.cc:307
Util::Array< ResourceLoadJob > dependentJobs
Definition resourceloader.h:304
uint32_t uniqueResourceId
Definition resourceloader.h:319
Threading::SafeQueue< _PendingStreamLod > pendingStreamQueue
Definition resourceloader.h:301
const Util::StringAtom GetTag(const Resources::ResourceId id) const
get resource tag was first registered with
Definition resourceloader.h:352
bool async
Definition resourceloader.h:291
int32_t uniqueId
id in resource manager
Definition resourceloader.h:322
ResourceLoader()
constructor
Definition resourceloader.cc:19
Util::FixedArray< Resource::State > states
Definition resourceloader.h:312
static const uint32_t ResourceIndexGrow
Definition resourceloader.h:246
const Util::Dictionary< Resources::ResourceName, Ids::Id32 > & GetResources() const
get the dictionary of all resource-id pairs
Definition resourceloader.h:381
virtual void RequestLOD(const Ids::Id32 entry, float lod) const
Set lod factor for resource.
Definition resourceloader.cc:136
Threading::SafeQueue< ResourceLoadOutput > loadOutputs
Definition resourceloader.h:303
Resources::ResourceId GetPlaceholder(const Resources::ResourceName &name)
get placeholder based on resource name
Definition resourceloader.cc:336
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.
Definition resourceloader.cc:670
Util::Array< IndexT > pendingLoads
Definition resourceloader.h:298
Util::FixedArray< LoadState > loadStates
Definition resourceloader.h:313
const int32_t & GetUniqueId() const
get the global identifier for this pool
Definition resourceloader.h:399
Threading::ThreadId creatorThread
Definition resourceloader.h:326
Resources::ResourceId failResourceId
Definition resourceloader.h:289
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 void UpdateLoaderSyncState()
Update loader internal state.
Definition resourceloader.cc:98
friend void DispatchJob(ResourceLoader *loader, const ResourceLoader::ResourceLoadJob &job)
Definition resourceloader.cc:158
virtual void LoadFallbackResources()
load placeholder and error resources
Definition resourceloader.cc:70
Util::FixedArray< _PendingResourceLoad > loads
Definition resourceloader.h:316
void SetMinLod(const Resources::ResourceId &id, const float lod, bool immediate)
begin updating a resources lod
Definition resourceloader.cc:756
const Resources::ResourceId GetId(const Resources::ResourceName &name) const
get resource id by name, use with care
Definition resourceloader.h:370
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 untagge...
void SetupIdFromEntry(const Ids::Id32 entry, ResourceId &cacheEntry)
Construct resource ID based on loader entry.
Definition resourceloader.cc:281
Util::Array< _PendingStreamLod > pendingStreamLods
Definition resourceloader.h:300
virtual ResourceStreamOutput StreamResource(const ResourceLoadJob &job)
Stream resource.
Definition resourceloader.cc:107
const bool HasResource(const Resources::ResourceId id) const
returns true if pool has resource
Definition resourceloader.h:390
virtual void Discard()
discard resource loader
Definition resourceloader.cc:60
Util::FixedArray< _PlaceholderResource > placeholders
Definition resourceloader.h:279
virtual ~ResourceLoader()
destructor
Definition resourceloader.cc:32
const Resources::ResourceName & GetName(const Resources::ResourceId id) const
get resource name
Definition resourceloader.h:334
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.
Definition resourceloader.cc:127
Util::FixedArray< uint32_t > usage
Definition resourceloader.h:310
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
Definition resourceloader.cc:701
Ids::IdPool resourceInstanceIndexPool
Definition resourceloader.h:307
Util::FixedArray< Util::Array< _Callbacks > > callbacks
Definition resourceloader.h:315
const Resource::State GetState(const Resources::ResourceId id) const
get resource state
Definition resourceloader.h:361
Util::FixedArray< _LoadMetaData > metaData
Definition resourceloader.h:317
virtual void Unload(const Resources::ResourceId id)=0
unload resource (overload to implement resource deallocation)
Threading::CriticalSection asyncSection
async section to sync callbacks and pending list with thread
Definition resourceloader.h:325
std::function< void()> preJobFunc
Definition resourceloader.h:294
Util::StringAtom failResourceName
Definition resourceloader.h:286
const uint32_t GetUsage(const Resources::ResourceId id) const
get resource usage from resource id
Definition resourceloader.h:343
friend void ApplyLoadOutput(ResourceLoader *loader, const ResourceLoader::ResourceLoadOutput &output)
Definition resourceloader.cc:145
Definition resourceloaderthread.h:23
Definition resourceserver.h:22
Critical section objects are used to protect a portion of code from parallel execution.
Thread-safe version of Util::Queue.
Definition safequeue.h:27
Nebula's dynamic array class.
Definition array.h:60
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
SizeT Size() const
return number of key/value pairs in the dictionary
Definition dictionary.h:193
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
IndexT FindIndex(const TYPE &val) const
find index of identical element in unsorted array (slow)
Definition fixedarray.h:633
A StringAtom.
Definition stringatom.h:22
const char * Value() const
get contained string as char ptr (fast)
Definition stringatom.h:362
uint32_t Id32
Definition id.h:138
A resource is a container for some type of file which is loaded.
Definition resource.cc:9
LoadFlags
Definition resourceloader.h:50
@ Update
Definition resourceloader.h:53
@ None
Definition resourceloader.h:51
@ Create
Definition resourceloader.h:52
pthread_t ThreadId
Definition linuxthreadid.h:15
#define __ImplementEnumBitOperators(type)
callback functions to run when an associated resource is loaded (can be stacked)
Definition resourceloader.h:240
std::function< void(const Resources::ResourceId)> success
Definition resourceloader.h:241
std::function< void(const Resources::ResourceId)> failed
Definition resourceloader.h:242
struct for pending resources which are about to be loaded
Definition resourceloader.h:114
Ids::Id32 entry
Definition resourceloader.h:115
bool inflight
Definition resourceloader.h:117
IndexT frame
Definition resourceloader.h:120
bool reload
Definition resourceloader.h:119
bool immediate
Definition resourceloader.h:118
float lod
Definition resourceloader.h:121
_PendingResourceLoad()
Definition resourceloader.h:124
LoadFlags flags
Definition resourceloader.h:122
Util::StringAtom tag
Definition resourceloader.h:116
Definition resourceloader.h:234
Resources::ResourceId resourceId
Definition resourceloader.h:235
struct for pending stream
Definition resourceloader.h:225
_PendingStreamLod()
Definition resourceloader.h:230
bool immediate
Definition resourceloader.h:228
Resources::ResourceId id
Definition resourceloader.h:226
float lod
Definition resourceloader.h:227
Definition resourceloader.h:275
Resources::ResourceName placeholderName
Definition resourceloader.h:276
Resources::ResourceId placeholderId
Definition resourceloader.h:277
Definition resourceloader.h:134
Ptr< IO::Stream > stream
Definition resourceloader.h:135
void * data
Definition resourceloader.h:136
Definition resourceloader.h:157
uint loadedBits
Definition resourceloader.h:160
uint requestedBits
Definition resourceloader.h:158
uint pendingBits
Definition resourceloader.h:159
Definition resourceloader.h:140
ResourceInitOutput()
Definition resourceloader.h:144
ResourceUnknownId id
Definition resourceloader.h:141
_StreamData loaderStreamData
Definition resourceloader.h:142
Definition resourceloader.h:164
LoadState loadState
Definition resourceloader.h:169
float lod
Definition resourceloader.h:173
_StreamData streamData
Definition resourceloader.h:170
bool immediate
Definition resourceloader.h:172
static ResourceLoadJob FromPending(ResourceLoader *loader, IndexT frameIndex, const _PendingResourceLoad &load)
Definition resourceloader.h:177
IndexT frameIndex
Definition resourceloader.h:174
LoadFlags flags
Definition resourceloader.h:175
Util::String name
Definition resourceloader.h:165
Resource::State state
Definition resourceloader.h:167
Util::String tag
Definition resourceloader.h:166
_LoadMetaData metadata
Definition resourceloader.h:171
ResourceId id
Definition resourceloader.h:168
Definition resourceloader.h:196
LoadState loadState
Definition resourceloader.h:198
void UpdateLoaderState(ResourceLoader *loader) const
Definition resourceloader.h:203
ResourceId id
Definition resourceloader.h:200
Resource::State state
Definition resourceloader.h:199
ResourceLoadJob remainderJob
Definition resourceloader.h:201
_StreamData streamData
Definition resourceloader.h:197
Definition resourceloader.h:151
uint loadedBits
Definition resourceloader.h:152
uint pendingBits
Definition resourceloader.h:153
Definition resourceid.h:37
Nebula's universal string class.
Definition string.h:50
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48