Cogs.Core
|
Mesh manager handling the creation, processing and lifetime of Mesh resources. More...
#include <MeshManager.h>
Public Member Functions | |
MeshManager (Context *context) | |
Constructs a MeshManager in the given context. | |
~MeshManager () override | |
Destructs the MeshManager. | |
void | initialize () override |
size_t | currentSwapQueueSize () const |
MeshHandle | getMesh (const StringView &name) |
void | handleLoad (ResourceLoadInfoBase *loadInfo) override |
Handler for resource loading. | |
ActivationResult | handleActivation (ResourceHandle handle, Mesh *mesh) override |
Overridden to handle mesh activation, updating the resource in the renderer. | |
void | handleDeletion (Mesh *mesh) override |
Overridden to handle mesh deletion, removing the resource from the renderer. | |
void | processSwapping () override |
Overridden to dispatch async updates for swapping resources if enabled. | |
void | processDeletion () override |
Process resources pending deallocation. | |
void | destroyInternal (ResourceBase *resource) override |
ResourceBufferHandle | createBuffer () |
![]() | |
ResourceManager (Context *context, Collections::ElementOffset capacity=1024) | |
Constructs a resource manager with the given context. | |
~ResourceManager () override | |
Destructs a resource manager, provided for destruction via base pointer. | |
void | clear () override |
Clear the resource manager, cleaning up resources held by member handles. | |
void | clearSwapping () override |
Clear the swap queue, ensuring indirect resource references are released. | |
ResourceHandle | create () |
Create a new resource. | |
ResourceHandle | release (ResourceId resourceId) |
ResourceHandle | loadResource (ResourceLoadInfoBase *loadInfo) |
ResourceProxy | createLocked () |
Creates a new resource, but returns a ResourceProxy for thread safe editing instead of a handle to the actual resource. | |
ResourceProxy | lock (const ResourceHandle &handle) |
Takes the handle given and returns a resource proxy to edit the contents of the held resource safely on other threads than the main thread. | |
void | unlockProxy (const ResourceHandle &handle, const ResourceHandle &proxy) |
Unlock the given resource proxy. | |
ResourceHandle | generateHandle (ResourceBase *resource) |
Generate a handle to the given resource. | |
virtual void | handleLoad (ResourceLoadInfoBase *) |
Handler for resource loading. | |
virtual void | handleFailedLoad (const ResourceLoadInfoBase *) |
Handler for failed resource loads using the given loadInfo. | |
virtual ActivationResult | handleActivation (ResourceHandle, Mesh *) |
Handler for activation of resources. | |
virtual void | handleDeletion (Mesh *) |
Handler for deletion of resources. | |
Mesh * | get (const ResourceHandleBase &handle) |
Resolve the given handle to a resource. | |
void | processSwapping () override |
Process queued swap operations, exchanging resource contents of the destination resources by those indicated in the operation data. | |
ResourceHandle | getHandle (const ResourceId id) const |
Get a resource handle to the resource with the given id. | |
void | registerLoader (IResourceLoader< Mesh, ResourceLoadInfoBase > *loader) |
Register a resource loader capable of handling resources of the template type. | |
void | destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo) override |
ResourceLoadInfoBase * | createLoadInfo () |
![]() | |
ResourceManagerBase (Context *context) | |
void | initialize () override |
void | clear () override |
void | reportLeaks (std::string_view typeName) |
std::string | getReport () |
Return a string with current resource usage. | |
bool | checkPreloaded (ResourceLoadInfoBase *loadInfo) |
ResourceHandleBase | releaseInternal (ResourceId resourceId) |
Releases a resourceId -> ResourceHandle mapping. | |
ResourceHandleBase | loadResourceInternal (ResourceLoadInfoBase *loadInfo) |
Load a resource using the given loadInfo. | |
void | processLoading () final |
Process loading resources. | |
void | setProcessed (ResourceLoadInfoBase *loadInfo, bool swapping=false) |
Signal the resource being loaded as done loading and ready for activation etc. | |
void | activateResources () final |
virtual void | processDeletion () override |
Process resources pending deallocation. | |
void | fillDeletionQueue (std::vector< ResourceBase * > &deletion) |
void | destroyLocked (ResourceBase *resource) |
void | safeDestroy (ResourceBase *resource) |
ResourceId | getNextResourceId () override |
Get the next unique resource id. | |
void | resourceChanged (ResourceBase *resource) override |
void | resourceDeleted (ResourceBase *resource) override |
void | setResourceId (ResourceBase *resource, ResourceId id) override |
Assign the given id to a previously created resource. | |
void | queueResource (ResourceLoadInfoBase *loadInfo) |
Re-queue the given loadInfo to defer loading to the next time the processLoading() phase is performed. | |
virtual void | handleLoadInternal (ResourceLoadInfoBase *loadInfo)=0 |
virtual ActivationResult | handleActivationInternal (ResourceHandleBase r, ResourceBase *resource)=0 |
virtual void | handleDeletionInternal (ResourceBase *resource)=0 |
virtual void | handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo)=0 |
virtual void | destroyLoadInfoInternal (ResourceLoadInfoBase *loadInfo)=0 |
virtual bool | shouldAutoReload () const |
virtual bool | shouldMergeBySource () const |
virtual void | handleReload (ResourceHandleBase) |
std::vector< ResourceBase * > | getAllocatedResources () const |
ResourceHandleBase | getOrCreate (ResourceId id) |
ResourceHandleBase | getByName (std::string_view name) const |
ResourceHandleBase | getBySource (std::string_view source) const |
ResourceHandleBase | createResource () |
virtual ResourceBase * | createInternal ()=0 |
virtual void | destroyInternal (ResourceBase *resource)=0 |
virtual void | destroyInternalLocked (ResourceBase *resource)=0 |
ResourceHandleBase | generateHandle (ResourceBase *resource) |
void | clearUpdated () |
virtual int | getUpdateQuota () const |
size_t | updatedResourceCount () |
size_t | orphanedResourceCount () |
size_t | allocatedResourceCount () |
virtual void | initialize ()=0 |
virtual void | clear ()=0 |
virtual void | clearSwapping ()=0 |
virtual void | processLoading ()=0 |
virtual void | processSwapping ()=0 |
virtual void | activateResources ()=0 |
virtual void | processDeletion ()=0 |
virtual void | resourceChanged (ResourceBase *resource)=0 |
virtual void | resourceDeleted (ResourceBase *resource)=0 |
virtual ResourceId | getNextResourceId ()=0 |
virtual void | setResourceId (ResourceBase *resource, ResourceId id)=0 |
Private Attributes | |
std::unique_ptr< struct MeshManagerData > | data |
Additional Inherited Members | |
![]() | |
using | ResourceHandle = ResourceHandle_t< Mesh > |
Type of handle used to hold resources. | |
using | ResourceProxy = ResourceProxy< Mesh, ResourceManager > |
Type of resource proxy objects, specialized on the type of resource. | |
![]() | |
Mesh * | createInternal () override |
void | destroyInternal (ResourceBase *resource) override |
void | handleLoadInternal (ResourceLoadInfoBase *loadInfo) override |
ActivationResult | handleActivationInternal (ResourceHandleBase r, ResourceBase *resource) override |
void | handleDeletionInternal (ResourceBase *resource) override |
void | handleFailedLoadInternal (ResourceLoadInfoBase *loadInfo) override |
IResourceLoader< Mesh, ResourceLoadInfoBase > * | findLoader (const ResourceLoadInfoBase *loadInfo) |
Find a loader capable of loading the resource given by loadInfo. | |
![]() | |
ResourceHandleBase | getResourceHandle (ResourceId id) const |
Get existing resource handle. | |
bool | isValidResource (ResourceId id) const |
Check if resource handle points to. | |
virtual void | postProcessLoading () |
Hook for resource managers to run code at the tail of processLoading. | |
![]() | |
Mutex | swapMutex |
Collections::Pool< Mesh > | resources |
std::vector< IResourceLoader< Mesh, ResourceLoadInfoBase > * > | loaders |
std::deque< SwapOperation > | swapQueue |
ResourceHandle | defaultResource |
![]() | |
std::unique_ptr< ResourceManagerBaseStorage > | storage |
Context * | context = nullptr |
ResourceTypes | resourceType = ResourceTypes::Unknown |
Mesh manager handling the creation, processing and lifetime of Mesh resources.
The mesh manager provides no wrappers for loading Mesh data, this is expected to be handled manually by creating Mesh resources with create() and setting data to the resource.
Definition at line 17 of file MeshManager.h.
Cogs::Core::MeshManager::MeshManager | ( | Context * | context | ) |
Constructs a MeshManager in the given context.
Definition at line 200 of file MeshManager.cpp.
References Cogs::Core::TaskManager::ResourceQueue, and Cogs::Core::Context::taskManager.
|
override |
Destructs the MeshManager.
Definition at line 205 of file MeshManager.cpp.
Cogs::Core::ResourceBufferHandle Cogs::Core::MeshManager::createBuffer | ( | ) |
Definition at line 252 of file MeshManager.cpp.
|
inline |
Definition at line 30 of file MeshManager.h.
|
overridevirtual |
Implements Cogs::Core::ResourceManagerBase.
Definition at line 245 of file MeshManager.cpp.
Cogs::Core::MeshHandle Cogs::Core::MeshManager::getMesh | ( | const StringView & | name | ) |
Definition at line 227 of file MeshManager.cpp.
|
override |
Overridden to handle mesh activation, updating the resource in the renderer.
Definition at line 417 of file MeshManager.cpp.
|
overridevirtual |
Overridden to handle mesh deletion, removing the resource from the renderer.
Reimplemented from Cogs::Core::ResourceManager< Mesh, ResourceLoadInfoBase >.
Definition at line 238 of file MeshManager.cpp.
|
overridevirtual |
Handler for resource loading.
Should be overridden by derived resource managers to handle custom loading logic.
loadInfo | Load information struct containing resource load data. |
Reimplemented from Cogs::Core::ResourceManager< Mesh, ResourceLoadInfoBase >.
Definition at line 232 of file MeshManager.cpp.
References Cogs::Core::ResourceLoadInfoBase::handle.
|
overridevirtual |
Initialize the MeshManager, creating default Mesh resources. Vertex formats will be initialized and ready to use after the mesh manager is initialized.
Implements Cogs::Core::IResourceManager.
Definition at line 213 of file MeshManager.cpp.
|
overridevirtual |
Process resources pending deallocation.
Processes resources in the orphaned queue and invokes destroy() for resources ready for destruction.
Reimplemented from Cogs::Core::ResourceManagerBase.
Definition at line 257 of file MeshManager.cpp.
References Cogs::Core::ResourceBase::getAttachedResource().
|
overridevirtual |
Overridden to dispatch async updates for swapping resources if enabled.
Implements Cogs::Core::IResourceManager.
Definition at line 329 of file MeshManager.cpp.
References Cogs::Core::ResourceBase::attachResource(), Cogs::Core::ResourceBase::getAttachedResource(), Cogs::Core::ResourceBase::hasAttachedResource(), Cogs::Core::ResourceBase::incrementGeneration(), and Cogs::Core::ResourceManager< ResourceType, LoadInfoType >::processSwapping().
|
private |
Definition at line 52 of file MeshManager.h.