Cogs.Core
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Cogs::Core::ResourceBase Struct Reference

Base class for engine resources. More...

#include <ResourceBase.h>

Inheritance diagram for Cogs::Core::ResourceBase:
Cogs::Core::Animation Cogs::Core::Asset Cogs::Core::BlueNoise Cogs::Core::BufferResource Cogs::Core::Effect Cogs::Core::Font Cogs::Core::GuiDocument Cogs::Core::Material Cogs::Core::MaterialInstance Cogs::Core::Mesh Cogs::Core::Model Cogs::Core::Sound Cogs::Core::Texture

Public Member Functions

 ResourceBase ()=default
 Constructs a new resource base.
 
 ResourceBase (const ResourceBase &other)=delete
 Disable trivial copies of resources.
 
ResourceBaseoperator= (const ResourceBase &other)=delete
 Disable copy-assignment of resources.
 
 ResourceBase (ResourceBase &&other)
 Move constructs a resource base from other.
 
ResourceBaseoperator= (ResourceBase &&other)
 Move assign the resource from the given ResourceBase other.
 
 ~ResourceBase ()
 Destructs the resource.
 
void setInitialized ()
 
void setChanged ()
 
bool hasChanged () const
 
void setLoading ()
 
void setLoaded ()
 
void setFailedLoad ()
 
void setActive ()
 
void setResident ()
 
void setProxy ()
 
void setKeepStorage ()
 
bool isInitialized () const
 
bool isLoaded () const
 
bool isActive () const
 
bool isResident () const
 
bool isDependency () const
 
bool isDeleted () const
 
bool isOrphaned () const
 
bool isProxy () const
 
bool hasFailedLoad () const
 
bool hasFailedActivation () const
 
bool keepStorage () const
 
void setType (ResourceTypes type)
 Set the type enumeration of the resource.
 
ResourceTypes getType () const
 Gets the type enumeration of the resource.
 
void setId (ResourceId resourceId)
 Set the resource id of the resource.
 
ResourceId getId () const
 Get the resource id of this instance.
 
void setFlag (ResourceFlags flags)
 Set the given resource flag.
 
void setFlags (ResourceFlags flags)
 
void unsetFlag (ResourceFlags flag)
 Unset the given flag.
 
bool isSet (ResourceFlags flag) const
 Check if the given flag is currently set.
 
ResourceFlags getFlags () const
 Get the current flags of the resource.
 
void attachResource (RenderResource *attachment)
 Attach the given GPU resource to the resource.
 
bool hasAttachedResource () const
 Check if the resource has an attachment.
 
RenderResourcegetAttachedResource () const
 Get the attached resource.
 
void setOwner (IResourceManager *owner)
 Sets the owner of this resource instance.
 
IResourceManagergetOwner () const
 
void setName (const StringView &name)
 Set the user friendly name of the resource.
 
StringView getName () const
 Get the name of the resource.
 
void setSource (const StringView &source)
 
StringView getSource () const
 
void increment ()
 Increments the reference count of the resource.
 
void decrement ()
 Decrement the reference count of the resource.
 
uint32_t referenceCount () const
 Get the current reference count.
 
void incrementGeneration ()
 Increment the generation count.
 
uint32_t getGeneration () const
 Get the generation count.
 
void setSlot (uint32_t slot)
 Sets the slot at which the resource is internally tracked.
 
uint32_t getSlot () const
 Gets the slot where the resource is tracked internally.
 

Static Public Attributes

static const uint32_t NoAttachment = 0xFFFFFFFF
 Constant used to signal no attachment.
 

Private Member Functions

void setInfo (ResourceInfo *info)
 

Private Attributes

Atomic< uint32_t > usage { 0 }
 Atomic usage count.
 
Atomic< uint32_t > flags = static_cast<uint32_t>(ResourceFlags::None)
 Resource flags.
 
struct RenderResourceattachment = nullptr
 Attached GPU resource.
 
ResourceInfoinfo = nullptr
 Additional resource info structure.
 
IResourceManagerowner = nullptr
 Owning resource manager.
 
uint32_t slot = 0xFFFFFFFF
 Allocated resource slot.
 
uint32_t generation = 0
 Generation counter, enables clients to track changed to resources.
 

Friends

template<typename U >
struct ResourcePool
 
class ResourceManagerBase
 

Detailed Description

Base class for engine resources.

Provides reference counting and basic state and lifetime tracking.

Definition at line 106 of file ResourceBase.h.

Constructor & Destructor Documentation

◆ ResourceBase() [1/2]

Cogs::Core::ResourceBase::ResourceBase ( )
default

Constructs a new resource base.

The resource is left in the uninitialized state, leaving the derived resource and manager to manage resource contents and initialization.

◆ ResourceBase() [2/2]

Cogs::Core::ResourceBase::ResourceBase ( ResourceBase &&  other)

Move constructs a resource base from other.

Parameters
otherResource to move contents from. Will be left in a uninitialized state.

Definition at line 3 of file ResourceBase.cpp.

References attachment, Cogs::StringView::empty(), getName(), info, Cogs::Core::ResourceInfo::name, and Cogs::Core::None.

◆ ~ResourceBase()

Cogs::Core::ResourceBase::~ResourceBase ( )
inline

Destructs the resource.

Definition at line 145 of file ResourceBase.h.

Member Function Documentation

◆ attachResource()

void Cogs::Core::ResourceBase::attachResource ( RenderResource attachment)
inline

Attach the given GPU resource to the resource.

Any attachments must be removed before destroying the resource.

Parameters
attachmentAttached resource.

Definition at line 261 of file ResourceBase.h.

Referenced by Cogs::Core::MeshManager::processSwapping().

◆ decrement()

void Cogs::Core::ResourceBase::decrement ( )
inline

Decrement the reference count of the resource.

This method is used by handles to automatically increment and decrement the reference count of the resource, keeping track of when the resource can be deleted.

If the resource count reaches zero when calling this method, the resource is flagged as orphaned. If the resource is in addition flagged with automatic lifetime management, the state is set to pending deletion and the owner, if present, is notified of the change.

See also
increment()

Definition at line 342 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceHandleBase::~ResourceHandleBase().

◆ getAttachedResource()

RenderResource * Cogs::Core::ResourceBase::getAttachedResource ( ) const
inline

Get the attached resource.

Returns
Attached resource, nullptr if no attachment is present.

Definition at line 275 of file ResourceBase.h.

Referenced by Cogs::Core::MeshManager::processDeletion(), and Cogs::Core::MeshManager::processSwapping().

◆ getFlags()

ResourceFlags Cogs::Core::ResourceBase::getFlags ( ) const
inline

Get the current flags of the resource.

Returns
Resource flags.

Definition at line 252 of file ResourceBase.h.

◆ getGeneration()

uint32_t Cogs::Core::ResourceBase::getGeneration ( ) const
inline

Get the generation count.

The generation count ensures the resource has the same content as the last time it was encountered with the same count.

Returns
Integer representing generation count.

Definition at line 380 of file ResourceBase.h.

Referenced by Cogs::Core::InstancedMeshRenderSystem::update().

◆ getId()

ResourceId Cogs::Core::ResourceBase::getId ( ) const
inline

Get the resource id of this instance.

Returns
The identifier of the resource.

Definition at line 215 of file ResourceBase.h.

Referenced by Cogs::Core::CurtainView::CurtainViewSystem::createComponent().

◆ getName()

StringView Cogs::Core::ResourceBase::getName ( ) const
inline

Get the name of the resource.

Returns
A string containing the name of the resource.
See also
setName()

Definition at line 307 of file ResourceBase.h.

Referenced by Cogs::Core::RemapMaterialCommand::apply(), and ResourceBase().

◆ getOwner()

IResourceManager * Cogs::Core::ResourceBase::getOwner ( ) const
inline

Definition at line 289 of file ResourceBase.h.

◆ getSlot()

uint32_t Cogs::Core::ResourceBase::getSlot ( ) const
inline

Gets the slot where the resource is tracked internally.

Definition at line 386 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy().

◆ getSource()

StringView Cogs::Core::ResourceBase::getSource ( ) const
inline

Definition at line 310 of file ResourceBase.h.

◆ getType()

ResourceTypes Cogs::Core::ResourceBase::getType ( ) const
inline

Gets the type enumeration of the resource.

Definition at line 195 of file ResourceBase.h.

◆ hasAttachedResource()

bool Cogs::Core::ResourceBase::hasAttachedResource ( ) const
inline

Check if the resource has an attachment.

Returns
A boolean indicating if the resource has an attachment or not.

Definition at line 268 of file ResourceBase.h.

Referenced by Cogs::Core::MeshManager::processSwapping().

◆ hasChanged()

bool Cogs::Core::ResourceBase::hasChanged ( ) const
inline

Definition at line 167 of file ResourceBase.h.

◆ hasFailedActivation()

bool Cogs::Core::ResourceBase::hasFailedActivation ( ) const
inline

Definition at line 187 of file ResourceBase.h.

◆ hasFailedLoad()

bool Cogs::Core::ResourceBase::hasFailedLoad ( ) const
inline

Definition at line 186 of file ResourceBase.h.

◆ increment()

void Cogs::Core::ResourceBase::increment ( )
inline

Increments the reference count of the resource.

This method is used by handles to automatically increment and decrement the reference count of the resource, keeping track of when the resource can be deleted.

If the flag ResourceFlags::Orphaned is set, and the current reference count is zero, this flag will be unset after this call.

Note: This should only be used manually if you are very sure about what you are doing.

Definition at line 323 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceHandleBase::reset().

◆ incrementGeneration()

void Cogs::Core::ResourceBase::incrementGeneration ( )
inline

Increment the generation count.

The generation count is used to track resources being changed, for example swapped for new contents.

Definition at line 367 of file ResourceBase.h.

Referenced by Cogs::Core::MeshManager::processSwapping().

◆ isActive()

bool Cogs::Core::ResourceBase::isActive ( ) const
inline

Definition at line 179 of file ResourceBase.h.

◆ isDeleted()

bool Cogs::Core::ResourceBase::isDeleted ( ) const
inline

Definition at line 182 of file ResourceBase.h.

◆ isDependency()

bool Cogs::Core::ResourceBase::isDependency ( ) const
inline

Definition at line 181 of file ResourceBase.h.

◆ isInitialized()

bool Cogs::Core::ResourceBase::isInitialized ( ) const
inline

Definition at line 177 of file ResourceBase.h.

◆ isLoaded()

bool Cogs::Core::ResourceBase::isLoaded ( ) const
inline

Definition at line 178 of file ResourceBase.h.

◆ isOrphaned()

bool Cogs::Core::ResourceBase::isOrphaned ( ) const
inline

Definition at line 183 of file ResourceBase.h.

◆ isProxy()

bool Cogs::Core::ResourceBase::isProxy ( ) const
inline

Definition at line 184 of file ResourceBase.h.

◆ isResident()

bool Cogs::Core::ResourceBase::isResident ( ) const
inline

Definition at line 180 of file ResourceBase.h.

◆ isSet()

bool Cogs::Core::ResourceBase::isSet ( ResourceFlags  flag) const
inline

Check if the given flag is currently set.

Parameters
flagFlag to check status of.
Returns
A boolean indicating true if the given flag is set, false if not.

Definition at line 245 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy().

◆ keepStorage()

bool Cogs::Core::ResourceBase::keepStorage ( ) const
inline

Definition at line 189 of file ResourceBase.h.

◆ operator=()

Cogs::Core::ResourceBase & Cogs::Core::ResourceBase::operator= ( ResourceBase &&  other)

Move assign the resource from the given ResourceBase other.

Parameters
otherResourceBase to move contents from. Leaves the other resource in the uninitialized state.
Returns
A reference to this instance.

Definition at line 21 of file ResourceBase.cpp.

References Cogs::Core::Active, flags, and Cogs::Core::None.

◆ referenceCount()

uint32_t Cogs::Core::ResourceBase::referenceCount ( ) const
inline

Get the current reference count.

Returns
An unsigned 32-bit integer containing the number of current references to this instance.

Definition at line 360 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy(), and Cogs::Core::ModelManager::handleLoad().

◆ setActive()

void Cogs::Core::ResourceBase::setActive ( )
inline

Definition at line 172 of file ResourceBase.h.

◆ setChanged()

void Cogs::Core::ResourceBase::setChanged ( )
inline

Definition at line 153 of file ResourceBase.h.

◆ setFailedLoad()

void Cogs::Core::ResourceBase::setFailedLoad ( )
inline

Definition at line 171 of file ResourceBase.h.

◆ setFlag()

void Cogs::Core::ResourceBase::setFlag ( ResourceFlags  flags)
inline

Set the given resource flag.

The given flag is combined with any previously set flags to determine the flags of the resource. If the given flag is already set, the call has no effect.

Parameters
flagResource flag to set.

Definition at line 225 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::queueResource().

◆ setFlags()

void Cogs::Core::ResourceBase::setFlags ( ResourceFlags  flags)
inline

Definition at line 226 of file ResourceBase.h.

◆ setId()

void Cogs::Core::ResourceBase::setId ( ResourceId  resourceId)
inline

Set the resource id of the resource.

Parameters
resourceIdIdentifier to set.

Definition at line 202 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::setResourceId().

◆ setInfo()

void Cogs::Core::ResourceBase::setInfo ( ResourceInfo info)
inlineprivate

Definition at line 389 of file ResourceBase.h.

◆ setInitialized()

void Cogs::Core::ResourceBase::setInitialized ( )
inline

Definition at line 151 of file ResourceBase.h.

◆ setKeepStorage()

void Cogs::Core::ResourceBase::setKeepStorage ( )
inline

Definition at line 175 of file ResourceBase.h.

◆ setLoaded()

void Cogs::Core::ResourceBase::setLoaded ( )
inline

Definition at line 170 of file ResourceBase.h.

◆ setLoading()

void Cogs::Core::ResourceBase::setLoading ( )
inline

Definition at line 169 of file ResourceBase.h.

◆ setName()

void Cogs::Core::ResourceBase::setName ( const StringView name)
inline

Set the user friendly name of the resource.

The name can be used when logging errors or status for the resource.

Parameters
nameString containing the name to use when referring to the resource.

Definition at line 298 of file ResourceBase.h.

Referenced by Cogs::Core::TextureManager::initialize(), Cogs::Core::SeaCurrentsSystem::initialize(), Cogs::Core::BasicOceanSystem::initialize(), and Cogs::Core::Text3DSystem::update().

◆ setOwner()

void Cogs::Core::ResourceBase::setOwner ( IResourceManager owner)
inline

Sets the owner of this resource instance.

A resource can exist without an explicit owner, but no state transition notifications will then be handled.

Parameters
ownerPointer to an owning resource manager, responsible for managing the state and lifetime of the resource. The owner will receive notification whenever the resource transitions from one state to another.

Definition at line 287 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy().

◆ setProxy()

void Cogs::Core::ResourceBase::setProxy ( )
inline

Definition at line 174 of file ResourceBase.h.

◆ setResident()

void Cogs::Core::ResourceBase::setResident ( )
inline

Definition at line 173 of file ResourceBase.h.

◆ setSlot()

void Cogs::Core::ResourceBase::setSlot ( uint32_t  slot)
inline

Sets the slot at which the resource is internally tracked.

Definition at line 383 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy().

◆ setSource()

void Cogs::Core::ResourceBase::setSource ( const StringView source)
inline

Definition at line 309 of file ResourceBase.h.

◆ setType()

void Cogs::Core::ResourceBase::setType ( ResourceTypes  type)
inline

Set the type enumeration of the resource.

Definition at line 192 of file ResourceBase.h.

◆ unsetFlag()

void Cogs::Core::ResourceBase::unsetFlag ( ResourceFlags  flag)
inline

Unset the given flag.

The given flag, if present, is removed from the set of active flags. Calling isSet() with the same flag will return false after this call.

Parameters
flagResource flag to unset.

Definition at line 236 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy(), Cogs::Core::ResourceManagerBase::loadResourceInternal(), and Cogs::Core::ResourceManagerBase::setProcessed().

Friends And Related Function Documentation

◆ ResourceManagerBase

friend class ResourceManagerBase
friend

Definition at line 415 of file ResourceBase.h.

◆ ResourcePool

template<typename U >
friend struct ResourcePool
friend

Definition at line 413 of file ResourceBase.h.

Member Data Documentation

◆ attachment

struct RenderResource* Cogs::Core::ResourceBase::attachment = nullptr
private

Attached GPU resource.

Definition at line 398 of file ResourceBase.h.

Referenced by ResourceBase().

◆ flags

Atomic<uint32_t> Cogs::Core::ResourceBase::flags = static_cast<uint32_t>(ResourceFlags::None)
private

Resource flags.

Definition at line 395 of file ResourceBase.h.

Referenced by operator=().

◆ generation

uint32_t Cogs::Core::ResourceBase::generation = 0
private

Generation counter, enables clients to track changed to resources.

Definition at line 410 of file ResourceBase.h.

◆ info

ResourceInfo* Cogs::Core::ResourceBase::info = nullptr
private

Additional resource info structure.

Definition at line 401 of file ResourceBase.h.

Referenced by Cogs::Core::ResourceManagerBase::destroy(), and ResourceBase().

◆ NoAttachment

const uint32_t Cogs::Core::ResourceBase::NoAttachment = 0xFFFFFFFF
static

Constant used to signal no attachment.

Definition at line 109 of file ResourceBase.h.

◆ owner

IResourceManager* Cogs::Core::ResourceBase::owner = nullptr
private

Owning resource manager.

Definition at line 404 of file ResourceBase.h.

◆ slot

uint32_t Cogs::Core::ResourceBase::slot = 0xFFFFFFFF
private

Allocated resource slot.

Definition at line 407 of file ResourceBase.h.

◆ usage

Atomic<uint32_t> Cogs::Core::ResourceBase::usage { 0 }
private

Atomic usage count.

Definition at line 392 of file ResourceBase.h.


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