ezEngine  Milestone 7
ezResource< SELF, SELF_DESCRIPTOR > Class Template Reference

The class from which all resource types need to derive. More...

#include <Resource.h>

Inheritance diagram for ezResource< SELF, SELF_DESCRIPTOR >:

Public Types

typedef SELF_DESCRIPTOR DescriptorType
 

Public Member Functions

void SetFallbackResource (const ezResourceHandle< SELF > &hResource)
 Sets the fallback resource that can be used while this resource is not yet loaded. More...
 
- Public Member Functions inherited from ezResourceBase
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.
 
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.
 
ezResourceState GetLoadingState () const
 Returns the current state in which this resource is in.
 
ezUInt8 GetNumQualityLevelsDiscardable () const
 Returns the current maximum quality level that the resource could have. More...
 
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...
 
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...
 
const ezBitflags
< ezResourceFlags > & 
GetBaseResourceFlags () const
 Returns the basic flags for the resource type. Mostly used the resource manager.
 
const MemoryUsageGetMemoryUsage () const
 Returns the information about the current memory usage of the resource.
 
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.
 
ezInt32 GetReferenceCount () const
 Returns the reference count of this resource.
 
const ezTimestampGetLoadedFileModificationTime () const
 Returns the modification date of the file from which this resource was loaded. More...
 
- Public Member Functions inherited from ezReflectedClass
EZ_FORCE_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_FORCE_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.
 
virtual void Serialize (ezArchiveWriter &stream) const
 This function is called to serialize the instance. More...
 
virtual void Deserialize (ezArchiveReader &stream)
 This function is called to deserialize the instance. More...
 
virtual void OnDeserialized ()
 This function is called after all objects are deserialized and thus all references to other objects are valid. More...
 

Static Public Member Functions

static void SetTypeFallbackResource (const ezResourceHandle< SELF > &hResource)
 
static void SetTypeMissingResource (const ezResourceHandle< SELF > &hResource)
 
static const ezResourceHandle
< SELF > & 
GetTypeFallbackResource ()
 
static const ezResourceHandle
< SELF > & 
GetTypeMissingResource ()
 

Protected Member Functions

 ezResource (DoUpdate ResourceUpdateThread, ezUInt8 uiQualityLevelsLoadable)
 
- Protected Member Functions inherited from ezResourceBase
 ezResourceBase (DoUpdate ResourceUpdateThread, ezUInt8 uiQualityLevelsLoadable)
 Default constructor.
 
virtual ~ezResourceBase ()
 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...
 

Private Member Functions

void CallCreateResource (const SELF_DESCRIPTOR &descriptor)
 
virtual ezResourceLoadDesc CreateResource (const SELF_DESCRIPTOR &descriptor)
 Override this function to implement resource creation. This is called by ezResourceManager::CreateResource. More...
 

Static Private Member Functions

static void ManagerEventHandler (const ezResourceManager::ManagerEvent &e)
 

Private Attributes

ezResourceHandle< SELF > m_hFallback
 

Static Private Attributes

static bool s_bAddedManagerEventHandler = false
 
static ezResourceHandle< SELF > s_TypeFallbackResource
 
static ezResourceHandle< SELF > s_TypeMissingResource
 

Friends

class ezResourceManager
 

Additional Inherited Members

- Protected Types inherited from ezResourceBase
enum  DoUpdate { OnMainThread, OnAnyThread }
 
enum  Unload { AllQualityLevels, OneQualityLevel }
 

Detailed Description

template<typename SELF, typename SELF_DESCRIPTOR>
class ezResource< SELF, SELF_DESCRIPTOR >

The class from which all resource types need to derive.

Pass the resources own type as the first template parameter. Pass the type name of the resource descriptor struct as the second template parameter. This may be any custom struct that stores the required information for creating a resource.

Member Function Documentation

template<typename SELF, typename SELF_DESCRIPTOR>
virtual ezResourceLoadDesc ezResource< SELF, SELF_DESCRIPTOR >::CreateResource ( const SELF_DESCRIPTOR &  descriptor)
inlineprivatevirtual

Override this function to implement resource creation. This is called by ezResourceManager::CreateResource.

'Creating' a resource is different from 'loading' a resource. Most resource types are never created. For example a mesh or a sound might not support being created and thus your implementation for such resources should be empty, except for an assert that always fires. However, some resources can be created (or even can only be created, but not loaded). For example textures might support to be created as render targets. In this case the descriptor needs to provide all the necessary information. Another example would be a procedurally generated mesh. The descriptor needs to provide all the parameters, such that 'CreateResource' can set up the resource. Note that created resources should always set its loading state to 'Loaded' and its current and max quality to 1, otherwise the resource manager might try to load even more into the resource afterwards. However, since this might be a valid use case for some resource types, it is not enforced by the resource manager.

Reimplemented in ezMeshBufferResource, ezMaterialResource, ezConstantBufferResource, ezTextureResource, and ezMeshResource.

template<typename SELF, typename SELF_DESCRIPTOR>
void ezResource< SELF, SELF_DESCRIPTOR >::SetFallbackResource ( const ezResourceHandle< SELF > &  hResource)
inline

Sets the fallback resource that can be used while this resource is not yet loaded.

By default there is no fallback resource, so all resource will block the application when requested for the first time.


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