XII Release 0.1.0
Loading...
Searching...
No Matches
xiiResource Class Referenceabstract

The base class for all resources. More...

#include <Resource.h>

Inheritance diagram for xiiResource:
[legend]

Classes

struct  MemoryUsage
 

Public Types

enum class  DoUpdate { OnMainThread , OnAnyThread , OnGraphicsResourceThreads }
 

Public Member Functions

XII_ALWAYS_INLINE xiiStringView GetResourceID () const
 Returns the unique ID that identifies this resource. On a file resource this might be a path. Can also be a GUID or any other scheme that uniquely identifies the resource.
 
XII_ALWAYS_INLINE xiiUInt64 GetResourceIDHash () const
 Returns the hash of the unique ID.
 
void SetResourceDescription (xiiStringView sDescription)
 The resource description allows to store an additional string that might be more descriptive during debugging, than the unique ID.
 
const xiiStringGetResourceDescription () const
 The resource description allows to store an additional string that might be more descriptive during debugging, than the unique ID.
 
const xiiStringGetResourceIdOrDescription () const
 The returns the resource description, if available, otherwise the resource ID.
 
XII_ALWAYS_INLINE xiiResourceState GetLoadingState () const
 Returns the current state in which this resource is in.
 
XII_ALWAYS_INLINE xiiUInt8 GetNumQualityLevelsDiscardable () const
 Returns the current maximum quality level that the resource could have.
 
XII_ALWAYS_INLINE xiiUInt8 GetNumQualityLevelsLoadable () const
 Returns how many quality levels the resource may additionally load.
 
float GetLoadingPriority (xiiTime now) const
 Returns the priority that is used by the resource manager to determine which resource to load next.
 
xiiResourcePriority GetPriority () const
 Returns the current resource priority.
 
void SetPriority (xiiResourcePriority priority)
 Changes the current resource priority.
 
XII_ALWAYS_INLINE const xiiBitflags< xiiResourceFlags > & GetBaseResourceFlags () const
 Returns the basic flags for the resource type. Mostly used the resource manager.
 
XII_ALWAYS_INLINE const MemoryUsageGetMemoryUsage () const
 Returns the information about the current memory usage of the resource.
 
XII_ALWAYS_INLINE xiiTime GetLastAcquireTime () const
 Returns the time at which the resource was (tried to be) acquired last. If a resource is acquired using xiiResourceAcquireMode::PointerOnly, this does not update the last acquired time, since the resource is not acquired for full use.
 
XII_ALWAYS_INLINE xiiInt32 GetReferenceCount () const
 Returns the reference count of this resource.
 
XII_ALWAYS_INLINE const xiiTimestampGetLoadedFileModificationTime () const
 Returns the modification date of the file from which this resource was loaded.
 
XII_ALWAYS_INLINE xiiUInt32 GetCurrentResourceChangeCounter () const
 Returns the current value of the resource change counter. Can be used to detect whether the resource has changed since using it last time.
 
XII_ALWAYS_INLINE void IncResourceChangeCounter ()
 Allows to manually increase the resource change counter to signal that dependent code might need to update.
 
virtual void ResetResource ()
 If the resource has modifications from the original state, it should reset itself to that state now (or force a reload on itself).
 
void PrintHandleStackTraces ()
 Prints the stack-traces for all handles that currently reference this resource.
 
- Public Member Functions inherited from xiiReflectedClass
virtual const xiiRTTIGetDynamicRTTI () const
 
bool IsInstanceOf (const xiiRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T>
XII_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Public Attributes

xiiEvent< const xiiResourceEvent &, xiiMutexm_ResourceEvents
 

Static Public Attributes

static DoUpdate UpdateGraphicsResource = xiiResource::DoUpdate::OnAnyThread
 

Protected Types

enum class  Unload { AllQualityLevels , OneQualityLevel }
 

Protected Member Functions

 xiiResource (DoUpdate ResourceUpdateThread, xiiUInt8 uiQualityLevelsLoadable)
 Default constructor.
 
virtual ~xiiResource ()
 virtual destructor.
 
MemoryUsageModifyMemoryUsage ()
 Non-const version for resources that want to write this variable directly.
 
void SetIsReloadable (bool bIsReloadable)
 Call this to specify whether a resource is reloadable.
 
void SetHasLoadingFallback (bool bHasLoadingFallback)
 Used internally by the code injection macros.
 

Private Member Functions

virtual xiiResourceLoadDesc UnloadData (Unload WhatToUnload)=0
 Requests the resource to unload another quality level. If bFullUnload is true, the resource should unload all data, because it is going to be deleted afterwards.
 
virtual xiiResourceLoadDesc UpdateContent (xiiStreamReader *pStream)=0
 Called whenever more data for the resource is available. The resource must read the stream to update it's data.
 
virtual xiiResourceTypeLoaderGetDefaultResourceTypeLoader () const
 Returns the resource type loader that should be used for this type of resource, unless it has been overridden on the xiiResourceManager.
 
virtual void UpdateMemoryUsage (MemoryUsage &out_NewMemoryUsage)=0
 This function must be overridden by all resource types.
 

Friends

class xiiResourceManager
 
class xiiResourceManagerWorkerDataLoad
 
class xiiResourceManagerWorkerUpdateContent
 
template<typename ResourceType>
class xiiTypedResourceHandle
 
XII_CORE_DLL_FRIEND void IncreaseResourceRefCount (xiiResource *pResource, const void *pOwner)
 
XII_CORE_DLL_FRIEND void DecreaseResourceRefCount (xiiResource *pResource, const void *pOwner)
 

Additional Inherited Members

- Static Public Member Functions inherited from xiiNoBase
static const xiiRTTIGetStaticRTTI ()
 

Detailed Description

The base class for all resources.

Member Enumeration Documentation

◆ DoUpdate

enum class xiiResource::DoUpdate
strong
Enumerator
OnGraphicsResourceThreads 

If set, the setting from UpdateGraphicsResource is used. This must be configured by the active renderer.

Member Function Documentation

◆ GetCurrentResourceChangeCounter()

XII_ALWAYS_INLINE xiiUInt32 xiiResource::GetCurrentResourceChangeCounter ( ) const
inline

Returns the current value of the resource change counter. Can be used to detect whether the resource has changed since using it last time.

The resource change counter is increased by calling IncResourceChangeCounter() or whenever the resource content is updated.

◆ GetDefaultResourceTypeLoader()

xiiResourceTypeLoader * xiiResource::GetDefaultResourceTypeLoader ( ) const
privatevirtual

Returns the resource type loader that should be used for this type of resource, unless it has been overridden on the xiiResourceManager.

By default, this redirects to xiiResourceManager::GetDefaultResourceLoader. So there is one global default loader, that can be set on the resource manager. Overriding this function will then allow to use a different resource loader on a specific type. Additionally, one can override the resource loader from the outside, by setting it via xiiResourceManager::SetResourceTypeLoader. That last method always takes precedence and allows to modify the behavior without modifying the code for the resource. But in the default case, the resource defines which loader is used.

Reimplemented in xiiShaderPermutationResource.

◆ GetLoadedFileModificationTime()

XII_ALWAYS_INLINE const xiiTimestamp & xiiResource::GetLoadedFileModificationTime ( ) const
inline

Returns the modification date of the file from which this resource was loaded.

The date may be invalid, if it cannot be retrieved or the resource was created and not loaded.

◆ GetNumQualityLevelsDiscardable()

XII_ALWAYS_INLINE xiiUInt8 xiiResource::GetNumQualityLevelsDiscardable ( ) const
inline

Returns the current maximum quality level that the resource could have.

This is used to scale the amount data used. Once a resource is in the 'Loaded' state, it can still have different quality levels. E.g. a texture can be fully used with n mipmap levels, but there might be more that could be loaded. On the other hand a resource could have a higher 'loaded quality level' then the 'max quality level', if the user just changed settings and reduced the maximum quality level that should be used. In this case the resource manager will instruct the resource to unload some of its data soon.

The quality level is a purely logical concept that can be handled very different by different resource types. E.g. a texture resource could theoretically use one quality level per available mipmap level. However, since the resource should generally be able to load and unload each quality level separately, it might make more sense for a texture resource, to use one quality level for everything up to 64*64, and then one quality level for each mipmap above that, which would result in 5 quality levels for a 1024*1024 texture.

Most resource will have zero or one quality levels (which is the same) as they are either loaded or not.

◆ GetResourceIdOrDescription()

const xiiString & xiiResource::GetResourceIdOrDescription ( ) const
inline

The returns the resource description, if available, otherwise the resource ID.

This is mainly for logging, where you want the more user friendly description, but the ID, if no description is available.

◆ PrintHandleStackTraces()

void xiiResource::PrintHandleStackTraces ( )

Prints the stack-traces for all handles that currently reference this resource.

Only implemented if XII_RESOURCEHANDLE_STACK_TRACES is XII_ON. Otherwise the function does nothing.

◆ ResetResource()

virtual void xiiResource::ResetResource ( )
inlinevirtual

If the resource has modifications from the original state, it should reset itself to that state now (or force a reload on itself).

Reimplemented in xiiMaterialResource.

◆ SetIsReloadable()

void xiiResource::SetIsReloadable ( bool bIsReloadable)
inlineprotected

Call this to specify whether a resource is reloadable.

By default all created resources are flagged as not reloadable. All resources loaded from file are automatically flagged as reloadable.

◆ UnloadData()

◆ UpdateContent()

◆ UpdateMemoryUsage()


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