Cogs.Core
|
Base class for engine resources. More...
#include <ResourceBase.h>
Public Member Functions | |
ResourceBase ()=default | |
Constructs a new resource base. | |
ResourceBase (const ResourceBase &other)=delete | |
Disable trivial copies of resources. | |
ResourceBase & | operator= (const ResourceBase &other)=delete |
Disable copy-assignment of resources. | |
ResourceBase (ResourceBase &&other) | |
Move constructs a resource base from other. | |
ResourceBase & | operator= (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. | |
RenderResource * | getAttachedResource () const |
Get the attached resource. | |
void | setOwner (IResourceManager *owner) |
Sets the owner of this resource instance. | |
IResourceManager * | getOwner () 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 RenderResource * | attachment = nullptr |
Attached GPU resource. | |
ResourceInfo * | info = nullptr |
Additional resource info structure. | |
IResourceManager * | owner = 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 |
Base class for engine resources.
Provides reference counting and basic state and lifetime tracking.
Definition at line 106 of file ResourceBase.h.
|
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.
Cogs::Core::ResourceBase::ResourceBase | ( | ResourceBase && | other | ) |
Move constructs a resource base from other.
other | Resource 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.
|
inline |
Destructs the resource.
Definition at line 145 of file ResourceBase.h.
|
inline |
Attach the given GPU resource to the resource.
Any attachments must be removed before destroying the resource.
attachment | Attached resource. |
Definition at line 261 of file ResourceBase.h.
Referenced by Cogs::Core::MeshManager::processSwapping().
|
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.
Definition at line 342 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceHandleBase::~ResourceHandleBase().
|
inline |
Get the attached resource.
Definition at line 275 of file ResourceBase.h.
Referenced by Cogs::Core::MeshManager::processDeletion(), and Cogs::Core::MeshManager::processSwapping().
|
inline |
Get the current flags of the resource.
Definition at line 252 of file ResourceBase.h.
|
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.
Definition at line 380 of file ResourceBase.h.
Referenced by Cogs::Core::InstancedMeshRenderSystem::update().
|
inline |
Get the resource id of this instance.
Definition at line 215 of file ResourceBase.h.
Referenced by Cogs::Core::CurtainView::CurtainViewSystem::createComponent().
|
inline |
Get the name of the resource.
Definition at line 307 of file ResourceBase.h.
Referenced by Cogs::Core::RemapMaterialCommand::apply(), and ResourceBase().
|
inline |
Definition at line 289 of file ResourceBase.h.
|
inline |
Gets the slot where the resource is tracked internally.
Definition at line 386 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceManagerBase::destroy().
|
inline |
Definition at line 310 of file ResourceBase.h.
|
inline |
Gets the type enumeration of the resource.
Definition at line 195 of file ResourceBase.h.
|
inline |
Check if the resource has an attachment.
Definition at line 268 of file ResourceBase.h.
Referenced by Cogs::Core::MeshManager::processSwapping().
|
inline |
Definition at line 167 of file ResourceBase.h.
|
inline |
Definition at line 187 of file ResourceBase.h.
|
inline |
Definition at line 186 of file ResourceBase.h.
|
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().
|
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().
|
inline |
Definition at line 179 of file ResourceBase.h.
|
inline |
Definition at line 182 of file ResourceBase.h.
|
inline |
Definition at line 181 of file ResourceBase.h.
|
inline |
Definition at line 177 of file ResourceBase.h.
|
inline |
Definition at line 178 of file ResourceBase.h.
|
inline |
Definition at line 183 of file ResourceBase.h.
|
inline |
Definition at line 184 of file ResourceBase.h.
|
inline |
Definition at line 180 of file ResourceBase.h.
|
inline |
Check if the given flag is currently set.
flag | Flag to check status of. |
Definition at line 245 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceManagerBase::destroy().
|
inline |
Definition at line 189 of file ResourceBase.h.
Cogs::Core::ResourceBase & Cogs::Core::ResourceBase::operator= | ( | ResourceBase && | other | ) |
Move assign the resource from the given ResourceBase other.
other | ResourceBase to move contents from. Leaves the other resource in the uninitialized state. |
Definition at line 21 of file ResourceBase.cpp.
References Cogs::Core::Active, flags, and Cogs::Core::None.
|
inline |
Get the current reference count.
Definition at line 360 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceManagerBase::destroy(), and Cogs::Core::ModelManager::handleLoad().
|
inline |
Definition at line 172 of file ResourceBase.h.
|
inline |
Definition at line 153 of file ResourceBase.h.
|
inline |
Definition at line 171 of file ResourceBase.h.
|
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.
flag | Resource flag to set. |
Definition at line 225 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceManagerBase::queueResource().
|
inline |
Definition at line 226 of file ResourceBase.h.
|
inline |
Set the resource id of the resource.
resourceId | Identifier to set. |
Definition at line 202 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceManagerBase::setResourceId().
|
inlineprivate |
Definition at line 389 of file ResourceBase.h.
|
inline |
Definition at line 151 of file ResourceBase.h.
|
inline |
Definition at line 175 of file ResourceBase.h.
|
inline |
Definition at line 170 of file ResourceBase.h.
|
inline |
Definition at line 169 of file ResourceBase.h.
|
inline |
Set the user friendly name of the resource.
The name can be used when logging errors or status for the resource.
name | String 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().
|
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.
owner | Pointer 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().
|
inline |
Definition at line 174 of file ResourceBase.h.
|
inline |
Definition at line 173 of file ResourceBase.h.
|
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().
|
inline |
Definition at line 309 of file ResourceBase.h.
|
inline |
Set the type enumeration of the resource.
Definition at line 192 of file ResourceBase.h.
|
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.
flag | Resource 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().
|
friend |
Definition at line 415 of file ResourceBase.h.
|
friend |
Definition at line 413 of file ResourceBase.h.
|
private |
|
private |
|
private |
Generation counter, enables clients to track changed to resources.
Definition at line 410 of file ResourceBase.h.
|
private |
Additional resource info structure.
Definition at line 401 of file ResourceBase.h.
Referenced by Cogs::Core::ResourceManagerBase::destroy(), and ResourceBase().
|
static |
Constant used to signal no attachment.
Definition at line 109 of file ResourceBase.h.
|
private |
Owning resource manager.
Definition at line 404 of file ResourceBase.h.
|
private |
Allocated resource slot.
Definition at line 407 of file ResourceBase.h.
|
private |
Atomic usage count.
Definition at line 392 of file ResourceBase.h.