class ResourceHandle

Inherits: IReflectable

Represents a handle to a resource.

Handles are similar to a smart pointers, but they have two advantages:

  • When loading a resource asynchronously you can be immediately returned the handle that you may use throughout the engine. The handle will be made valid as soon as the resource is loaded.
  • Handles can be serialized and deserialized, therefore saving/restoring references to their original resource.

Public

Methods

IsLoaded

bool IsLoaded(bool checkDependencies = true) const

Checks if the resource is loaded.

Until resource is loaded this handle is invalid and you may not get the internal resource from it.

checkDependencies
If true, and if resource has any dependencies, this method will also check if they are loaded.

IsValid

bool IsValid() const

Checks if the resource handle is not null and resource is loaded.

BlockUntilLoaded

void BlockUntilLoaded(bool waitForDependencies = true) const

Blocks the current thread until the resource is fully loaded.

Destroy

void Destroy() const

Forces the resource to be unloaded and destroyed, regardless of reference count.

ReleaseInternalReference

void ReleaseInternalReference()

Releases an internal reference to this resource held by the resources system, if there is one.

GetReferenceCount

u32 GetReferenceCount() const

Returns the number of strong references on the resource pointed by the handle.

GetId

const UUID &GetId() const

Returns the UUID of the resource the handle is referring to.

Internal

Methods

GetHandleData

ResourceHandleData *GetHandleData() const

Gets the handle data.

For internal use only.

Protected

Methods

AssociateResourceWithHandle

void AssociateResourceWithHandle(const SPtr<Resource> &resource, const UUID &resourceId)

Sets the created flag to true and assigns the resource pointer.

Called by the constructors, or if you constructed just using a UUID, then you need to call this manually before you can access the resource from this handle.

IncrementStrongReferenceCount

void IncrementStrongReferenceCount() const

Increments the strong reference count.

As long as strong reference count is non-zero the handle will keep the managed resource alive.

DecrementStrongReferenceCount

void DecrementStrongReferenceCount() const

Decrements the strong reference count.

If the strong reference count reaches zero the managed resource will be destroyed. Additionally if there are no weak resource handles alive either, resource handle data will also be destroyed.

IncrementWeakReferenceCount

void IncrementWeakReferenceCount() const

Increments the weak reference count.

This keeps the resource handle data alive, but not the managed resource itself.

DecrementWeakReferenceCount

void DecrementWeakReferenceCount() const

Decrements the weak reference count.

If this was the last weak reference and there are no strong references either, handle data will be destroyed.

NotifyLoadComplete

void NotifyLoadComplete()

Notification sent by the resource system when the resource is done with the loading process.

This will trigger even if the load fails.

ReportIfNotLoaded

void ReportIfNotLoaded() const

Fields

mData