ezEngine  Milestone 9
ezResource Class Referenceabstract

The base class for all resources. More...

#include <Resource.h>

Inheritance diagram for ezResource:

Classes

struct  MemoryUsage
 

Public Member Functions

EZ_ALWAYS_INLINE const ezStringGetResourceID () 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.
 
EZ_ALWAYS_INLINE ezUInt32 GetResourceIDHash () const
 Returns the hash of the unique ID.
 
void SetResourceDescription (const char *szDescription)
 The resource description allows to store an additional string that might be more descriptive during debugging, than the unique ID.
 
const ezStringGetResourceDescription () const
 The resource description allows to store an additional string that might be more descriptive during debugging, than the unique ID.
 
EZ_ALWAYS_INLINE ezResourceState GetLoadingState () const
 Returns the current state in which this resource is in.
 
EZ_ALWAYS_INLINE ezUInt8 GetNumQualityLevelsDiscardable () const
 Returns the current maximum quality level that the resource could have. More...
 
EZ_ALWAYS_INLINE ezUInt8 GetNumQualityLevelsLoadable () const
 Returns how many quality levels the resource may additionally load.
 
void SetPriority (ezResourcePriority priority)
 Sets the current priority of this resource. More...
 
EZ_ALWAYS_INLINE ezResourcePriority GetPriority () const
 Returns the currently user-specified priority of this resource. More...
 
void SetDueDate (ezTime date=ezTime::Seconds(60.0 *60.0 *24.0 *365.0 *1000.0))
 Specifies the time (usually in the future) at which this resource is needed and should be fully loaded. More...
 
virtual ezTime GetLoadingDeadline (ezTime tNow) const
 Returns the deadline (tNow + x) at which this resource is required to be loaded. More...
 
EZ_ALWAYS_INLINE const ezBitflags< ezResourceFlags > & GetBaseResourceFlags () const
 Returns the basic flags for the resource type. Mostly used the resource manager.
 
EZ_ALWAYS_INLINE const MemoryUsageGetMemoryUsage () const
 Returns the information about the current memory usage of the resource.
 
EZ_ALWAYS_INLINE ezTime GetLastAcquireTime () const
 Returns the time at which the resource was (tried to be) acquired last. If a resource is acquired using ezResourceAcquireMode::PointerOnly, this does not update the last acquired time, since the resource is not acquired for full use.
 
EZ_ALWAYS_INLINE ezInt32 GetReferenceCount () const
 Returns the reference count of this resource.
 
EZ_ALWAYS_INLINE const ezTimestampGetLoadedFileModificationTime () const
 Returns the modification date of the file from which this resource was loaded. More...
 
EZ_ALWAYS_INLINE ezUInt32 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. More...
 
EZ_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).
 
- Public Member Functions inherited from ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
 
EZ_ALWAYS_INLINE bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
 
template<typename T >
EZ_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 

Public Attributes

ezEvent< const ezResourceEvent & > m_ResourceEvents
 

Protected Types

enum  DoUpdate { OnMainThread, OnAnyThread }
 
enum  Unload { AllQualityLevels, OneQualityLevel }
 

Protected Member Functions

 ezResource (DoUpdate ResourceUpdateThread, ezUInt8 uiQualityLevelsLoadable)
 Default constructor.
 
virtual ~ezResource ()
 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. More...
 
void SetHasLoadingFallback (bool bHasLoadingFallback)
 Used internally by the code injection macros.
 

Friends

class ezResourceManager
 
class ezResourceManagerWorkerDiskRead
 
class ezResourceManagerWorkerMainThread
 
template<typename ResourceType >
class ezTypedResourceHandle
 
EZ_CORE_DLL void IncreaseResourceRefCount (ezResource *pResource)
 
EZ_CORE_DLL void DecreaseResourceRefCount (ezResource *pResource)
 

Additional Inherited Members

- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()
 

Detailed Description

The base class for all resources.

Member Function Documentation

◆ GetCurrentResourceChangeCounter()

EZ_ALWAYS_INLINE ezUInt32 ezResource::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.

◆ GetLoadedFileModificationTime()

EZ_ALWAYS_INLINE const ezTimestamp& ezResource::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.

◆ GetLoadingDeadline()

ezTime ezResource::GetLoadingDeadline ( ezTime  tNow) const
virtual

Returns the deadline (tNow + x) at which this resource is required to be loaded.

This represents the final priority that is used by the resource manager to determine which resource to load next.

Note
It is fully valid to return a time in the past.
Although it is possible to override this function, it is advised not to do so. The default algorithm is tweaked well enough already, it should not be necessary to modify it.

◆ GetNumQualityLevelsDiscardable()

EZ_ALWAYS_INLINE ezUInt8 ezResource::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.

◆ GetPriority()

EZ_ALWAYS_INLINE ezResourcePriority ezResource::GetPriority ( ) const
inline

Returns the currently user-specified priority of this resource.

See also
SetPriority

◆ SetDueDate()

void ezResource::SetDueDate ( ezTime  date = ezTime::Seconds(60.0 * 60.0 * 24.0 * 365.0 * 1000.0))

Specifies the time (usually in the future) at which this resource is needed and should be fully loaded.

This is another way in which the loading priority of the resource can be influenced by the runtime. By specifying a 'due date' or 'deadline', the resource manager is instructed to make sure that this resource gets loaded in due time. The closer that the due date is, the higher the priority for loading this resource becomes.

Calling this function without parameters 'resets' the due date to a date into the far future, which practically disables it.

The due date is an absolute deadline, whereas the priority is a relative value compared to other resources. Both can be combined. The due date always take precedence when it approaches, however as long as it is further away, priority has the most influence.

See also
SetPriority

◆ SetIsReloadable()

void ezResource::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.

◆ SetPriority()

void ezResource::SetPriority ( ezResourcePriority  priority)

Sets the current priority of this resource.

This is one way for the engine to specify how important this resource is, in relation to others. The runtime can use any arbitrary scheme to compute the priority for resources, e.g. it could use distance to the camera, on screen size, or random chance. However, it should be consistent with the priority computation of other resources, to prevent preferring or penalizing other resources too much.

Also make sure to always update the priority of resources when it becomes unimportant. If a resource is set to high priority and then never changed back, it will be kept loaded longer than others.

The due date is an absolute deadline, whereas the priority is a relative value compared to other resources. Both can be combined. The due date always take precedence when it approaches, however as long as it is further away, priority has the most influence.

See also
SetDueDate

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