class Resource

Base class for all resources.

Public

Constructors

Resource

Resource(bool createRenderProxy = true, const String &name = StringUtility::kBlank)

Methods

~Resource

virtual ~Resource() noexcept = default

GetName

const String &GetName() const

Returns the name of the resource.

SetName

virtual void SetName(const String &name)

Sets the name of the resource.

GetId

const UUID &GetId() const

Returns a globally unique identifier of the resource.

GetHandle

TResourceHandle<Resource> GetHandle() const

Get a handle to this resource, if there is any associated.

GetMetaData

SPtr<ResourceMetaData> GetMetaData() const

Retrieves meta-data containing various information describing a resource.

AllowAsyncLoading

virtual bool AllowAsyncLoading() const

Returns whether or not this resource is allowed to be asynchronously loaded.

Destroy

void Destroy() override

Frees all the data held by this object.

If the object has a render proxy, the internal reference to the render proxy will be released, but the proxy will not be destroyed unless this was the last reference. If render proxy destruction does happen, it is not immediate, but rather queued for destruction on the render thread.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const

Returns an interface you can use to access class' Run Time Type Information.

Internal

Methods

SetHandle

void SetHandle(const TWeakResourceHandle<Resource> &handle)

Associates a handle with the resource.

Should be called right after the handle for the resource is created, or right after resource load completes.

SetId

void SetId(const UUID &id)

Associates a new id with the resource.

If the resource can be referenced via a handle, the UUID must match the handle UUID.

NotifyDidDuplicate

void NotifyDidDuplicate()

Call this on the resource after it has been duplicated (on the duplicated object).

Protected

Methods

GetResourceDependencies

void GetResourceDependencies(FrameVector<HResource> &dependencies) const

Retrieves a list of all resources that this resource depends on.

AreDependenciesLoaded

bool AreDependenciesLoaded() const

Checks if all the resources this object is dependent on are fully loaded.

AddResourceDependency

void AddResourceDependency(const HResource &resource)

Registers a new resource that this resource is dependent on.

RemoveResourceDependency

void RemoveResourceDependency(const HResource &resource)

Unregisters a previously registered dependency.

OnDidDuplicate

virtual void OnDidDuplicate()

Called on the resource after it has been duplicated (called on the duplicated object).

IsCompressible

virtual bool IsCompressible() const

Returns true if the resource can be compressed using a generic compression when saved on a storage device.

Certain resources already have their contents compressed (like audio files) and will not benefit from further compression. Resources supporting streaming should never be compressed, instead such resources can handle compression/decompression locally through their streams.

Fields

mId

UUID mId

mSelfHandle

TWeakResourceHandle<Resource> mSelfHandle

mName

String mName

mMetaData

SPtr<ResourceMetaData> mMetaData

mKeepSourceData

bool mKeepSourceData

Signal to the resource implementation if original data should be kept in memory.

This is sometimes needed if the resource destroys original data during normal usage, but it might still be required for special purposes (like saving in the editor).

mDependencies

Vector<TWeakResourceHandle<Resource>> mDependencies

A list of all other resources this resource depends on.

mDependenciesMutex

Mutex mDependenciesMutex

Mutex ensuring dependencies list updates and queries are thread safe.