CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::ResourceManager Class Referencefinal

The ResourceManager is the main class responsible for managing and handling all resources in the engine. More...

#include <CeresEngine/Resource/ResourceManager.hpp>

Public Member Functions

 ResourceManager (URLSession &urlSession, ExecutionContext &executionContext, const SerializationContext &serializationContext=SerializationContext::getDefault())
 Creates a new resource manager instance.
 
 ~ResourceManager ()
 Destroys the resource manager and all it's managed resources.
 
template<typename T >
ResourceHandle< TgetResource (const StringView name)
 
template<typename T >
ResourceHandle< TgetResource (const UUID &uuid)
 
HResource getResource (StringView name)
 Locates an existing resource by it's name.
 
HResource getResource (const UUID &uuid)
 Locates an existing resource by it's UUID.
 
template<typename T >
Async< ResourceHandle< T > > locate (const StringView name)
 
Async< HResourcelocate (StringView name)
 Loads a resource by it's name.
 
template<typename T >
Async< ResourceHandle< T > > load (const ResourceURL url, const Optional< ResourceID > resourceID={})
 
template<typename T >
Async< ResourceHandle< T > > load (const ResourceID id)
 
template<typename T >
Async< ResourceHandle< T > > load (InputStream inputStream, const Optional< ResourceID > resourceID={})
 
Async< HResourceload (ResourceURL url, Optional< ResourceID > resourceID={})
 Loads a resource using a URL.
 
Async< HResourceload (ResourceID id)
 Loads a resource using a UUID.
 
Async< HResourceload (InputStream inputStream, Optional< ResourceID > resourceID={})
 Loads a resource using an existing input stream.
 
Async save (ResourceURL url, HResource resource)
 Saves a resource to a URL.
 
Async save (OutputStream outputStream, HResource resource)
 Saves a resource to an output stream.
 
template<typename T , typename... Args>
ResourceHandle< Tcreate (Args &&... args)
 Create a new resource by constructing it with Args and registers it with the manager.
 
HResource create (const ResourcePtr &resource)
 Registers a new resource with the manager.
 
HResource create (ResourcePtr &&resourcePtr)
 Registers a new resource with the manager.
 
template<typename T , typename... Args>
ResourceHandle< TcreateWithID (const UUID &uuid, Args &&... args)
 Create a new resource by constructing it with Args and registers it with the manager.
 
HResource createWithID (const UUID &uuid, const ResourcePtr &resource)
 Registers a new resource with the manager using a known UUID.
 
HResource createWithID (const UUID &uuid, ResourcePtr &&resourcePtr)
 Registers a new resource with the manager.
 
template<typename T >
Async< ResourceHandle< T > > import (const ResourceURL url, UPtr< ResourceImportOptions > &&importOptions=nullptr)
 
Async< HResourceimport (ResourceURL url, UPtr< ResourceImportOptions > &&importOptions=nullptr)
 Imports a new resource from a raw file.
 
const ResourceURLgetBaseURL () const noexcept
 The base URL used to load resources from.
 
void setBaseURL (const ResourceURL &baseURL)
 The base URL used to load resources from.
 
URLSessiongetURLSession () const noexcept
 The URL session to be used to load resources.
 
ExecutionContextgetExecutionContext () const noexcept
 The execution context to perform asynchronous resource operations on.
 
PackageManagergetPackageManager () const noexcept
 The package manager associated with this resource manager.
 

Public Attributes

ResourceImporterRegistry importers
 The registry that keeps track of registered importers.
 

Private Types

using LoadedResourceMap = HashMap< UUID, LoadedResource >
 A map that maps every loaded resource by it's UUID.
 
using LoadingResourcesList = List< LoadingResource >
 A list of loading resources.
 
using SavingResourcesList = List< SavingResource >
 A list of saving resources.
 
using ImportingResourcesList = List< ImportingResource >
 A list of importing resources.
 

Private Member Functions

HResource createInternal (ResourceData &resourceData, ResourcePtr &&resource)
 
ResourceDataPtr createResourceData (const UUID &uuid=UUID())
 Creates a new ResourceData object for a resource.
 
void notifyStrongHandleDestroy (ResourceHandleData *resourceHandleData)
 Notifies the manager that the resource pointed by the resource handle is no longer referenced by any strong handle.
 
void notifyHandleDestroy (const ResourceHandleData *resourceHandleData)
 Notifies the manager that the last resource handle was destroyed.
 

Private Attributes

URLSessionmURLSession
 The URL session to be used to load resources.
 
ExecutionContextmExecutionContext
 The execution context to perform asynchronous resource operations on.
 
const SerializationContextmSerializationContext
 A context for the serializer and deserializer to operate on.
 
PackageManagermPackageManager = nullptr
 The package manager associated with this resource manager.
 
LockedObject< HashMap< UUID, ResourceHandleData * > > mResourceHandles
 A map of active resource handles, mapped by their UUID.
 
ResourceURL mBaseURL
 The base URL used to load resources from.
 
LockedObject< LoadedResourceMapmResources
 A map that maps every loaded resource by it's UUID.
 
LockedObject< LoadingResourcesListmLoadingResources
 A list of loading resources.
 
LockedObject< SavingResourcesListmSavingResources
 A list of saving resources.
 
LockedObject< ImportingResourcesListmImportingResources
 A list of importing resources.
 

Friends

class PackageManager
 
class ResourceData
 
class ResourceHandleData
 

Detailed Description

The ResourceManager is the main class responsible for managing and handling all resources in the engine.

All class methods are thread-safe, unless otherwise specified.

Member Typedef Documentation

◆ ImportingResourcesList

◆ LoadedResourceMap

A map that maps every loaded resource by it's UUID.

◆ LoadingResourcesList

◆ SavingResourcesList

Constructor & Destructor Documentation

◆ ResourceManager()

CeresEngine::ResourceManager::ResourceManager ( URLSession urlSession,
ExecutionContext executionContext,
const SerializationContext serializationContext = SerializationContext::getDefault() 
)

Creates a new resource manager instance.

Parameters
urlSessionThe URL session to be used to load resources.
executionContextThe execution context to perform asynchronous resource operations on.
serializationContextA context for the serializer and deserializer to operate on. Can be empty, in which case the default context is used.

◆ ~ResourceManager()

CeresEngine::ResourceManager::~ResourceManager ( )

Destroys the resource manager and all it's managed resources.

Member Function Documentation

◆ create() [1/3]

template<typename T , typename... Args>
ResourceHandle< T > CeresEngine::ResourceManager::create ( Args &&...  args)
inline

Create a new resource by constructing it with Args and registers it with the manager.

ResourceManager& manager = ...;
const HTexture texture = manager.create<Texture>();
The ResourceManager is the main class responsible for managing and handling all resources in the engi...
Definition ResourceManager.hpp:47
ResourceHandle< T > create(Args &&... args)
Create a new resource by constructing it with Args and registers it with the manager.
Definition ResourceManager.hpp:244
A texture that can be imported into the renderer.
Definition Texture.hpp:89
Template Parameters
TThe resource type to be created.
ArgsThe resource constructor argument types.
Parameters
argsThe resource constructor arguments.
Returns
The newly created resource handle.

◆ create() [2/3]

HResource CeresEngine::ResourceManager::create ( const ResourcePtr resource)
inline

Registers a new resource with the manager.

Parameters
resourceA shared pointer of the resource to be registered.
Returns
A handle for the newly registered resource.

◆ create() [3/3]

HResource CeresEngine::ResourceManager::create ( ResourcePtr &&  resourcePtr)

Registers a new resource with the manager.

Parameters
resourceA shared pointer of the resource to be registered.
Returns
A handle for the newly registered resource.

◆ createInternal()

HResource CeresEngine::ResourceManager::createInternal ( ResourceData resourceData,
ResourcePtr &&  resource 
)
private

◆ createResourceData()

ResourceDataPtr CeresEngine::ResourceManager::createResourceData ( const UUID uuid = UUID())
private

Creates a new ResourceData object for a resource.

◆ createWithID() [1/3]

template<typename T , typename... Args>
ResourceHandle< T > CeresEngine::ResourceManager::createWithID ( const UUID uuid,
Args &&...  args 
)
inline

Create a new resource by constructing it with Args and registers it with the manager.

The resource is registered with a previously known UUID. If the resource with the given UUID is already registered, the resource is replaced.

ResourceManager& manager = ...;
const UUID existingUUID = ...;
const HTexture texture = manager.createWithID<Texture>(existingUUID);
ResourceHandle< T > createWithID(const UUID &uuid, Args &&... args)
Create a new resource by constructing it with Args and registers it with the manager.
Definition ResourceManager.hpp:274
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Represents a universally unique identifier (UUID).
Definition UUID.hpp:27
Template Parameters
TThe resource type to be created.
ArgsThe resource constructor argument types.
Parameters
uuidThe UUID to be used for the new resource. If the resource already exists, it will be replaced.
argsThe resource constructor arguments.
Returns
The newly created resource handle.

◆ createWithID() [2/3]

HResource CeresEngine::ResourceManager::createWithID ( const UUID uuid,
const ResourcePtr resource 
)
inline

Registers a new resource with the manager using a known UUID.

Parameters
resourceA shared pointer of the resource to be registered.
uuidThe UUID to be used for the new resource. If the resource already exists, it will be replaced.
Returns
A handle for the newly registered resource.

◆ createWithID() [3/3]

HResource CeresEngine::ResourceManager::createWithID ( const UUID uuid,
ResourcePtr &&  resourcePtr 
)

Registers a new resource with the manager.

Parameters
resourceA shared pointer of the resource to be registered.
Returns
A handle for the newly registered resource.

◆ getBaseURL()

const ResourceURL & CeresEngine::ResourceManager::getBaseURL ( ) const
inlinenoexcept

The base URL used to load resources from.

◆ getExecutionContext()

ExecutionContext & CeresEngine::ResourceManager::getExecutionContext ( ) const
inlinenoexcept

The execution context to perform asynchronous resource operations on.

◆ getPackageManager()

PackageManager * CeresEngine::ResourceManager::getPackageManager ( ) const
inlinenoexcept

The package manager associated with this resource manager.

The package manager is optional and may not be available in all cases.

◆ getResource() [1/4]

template<typename T >
ResourceHandle< T > CeresEngine::ResourceManager::getResource ( const StringView  name)
inline

◆ getResource() [2/4]

template<typename T >
ResourceHandle< T > CeresEngine::ResourceManager::getResource ( const UUID uuid)
inline

◆ getResource() [3/4]

HResource CeresEngine::ResourceManager::getResource ( const UUID uuid)

Locates an existing resource by it's UUID.

Parameters
uuidThe UUID of the resource to be located.
Returns
The resource handle to the resource, or nullptr if not found.

◆ getResource() [4/4]

HResource CeresEngine::ResourceManager::getResource ( StringView  name)

Locates an existing resource by it's name.

Parameters
nameThe name of the resource to be located.
Returns
The resource handle to the resource, or nullptr if not found.

◆ getURLSession()

URLSession & CeresEngine::ResourceManager::getURLSession ( ) const
inlinenoexcept

The URL session to be used to load resources.

◆ import() [1/2]

template<typename T >
Async< ResourceHandle< T > > CeresEngine::ResourceManager::import ( const ResourceURL  url,
UPtr< ResourceImportOptions > &&  importOptions = nullptr 
)
inline

◆ import() [2/2]

Async< HResource > CeresEngine::ResourceManager::import ( ResourceURL  url,
UPtr< ResourceImportOptions > &&  importOptions = nullptr 
)

Imports a new resource from a raw file.

Parameters
urlThe URL of the raw file to be imported.
importOptionsA set of options given to the importer. Allows controlling how the importer will import the raw data and create the resource.
Returns
A continuable that returns the handle of the imported resource.

◆ load() [1/6]

template<typename T >
Async< ResourceHandle< T > > CeresEngine::ResourceManager::load ( const ResourceID  id)
inline

◆ load() [2/6]

template<typename T >
Async< ResourceHandle< T > > CeresEngine::ResourceManager::load ( const ResourceURL  url,
const Optional< ResourceID resourceID = {} 
)
inline

◆ load() [3/6]

template<typename T >
Async< ResourceHandle< T > > CeresEngine::ResourceManager::load ( InputStream  inputStream,
const Optional< ResourceID resourceID = {} 
)
inline

◆ load() [4/6]

Async< HResource > CeresEngine::ResourceManager::load ( InputStream  inputStream,
Optional< ResourceID resourceID = {} 
)

Loads a resource using an existing input stream.

Please note that if a resource with the same UUID is already loaded, the old resource will be replaced with the contents of the newly loaded resource.

Parameters
inputStreamThe input stream to load a resource from.
Returns
A async object that returns once the resource has been loaded into the engine.

◆ load() [5/6]

Async< HResource > CeresEngine::ResourceManager::load ( ResourceID  id)

Loads a resource using a UUID.

Parameters
idThe UUID to load the resource from.
Returns
A continuable that returns once the resource has been loaded into the engine.

◆ load() [6/6]

Async< HResource > CeresEngine::ResourceManager::load ( ResourceURL  url,
Optional< ResourceID resourceID = {} 
)

Loads a resource using a URL.

Please note that if a resource with the same UUID is already loaded, the old resource will be replaced with the contents of the newly loaded resource.

Parameters
urlThe URL to load the resource from.
Returns
A continuable that returns once the resource has been loaded into the engine.

◆ locate() [1/2]

template<typename T >
Async< ResourceHandle< T > > CeresEngine::ResourceManager::locate ( const StringView  name)
inline

◆ locate() [2/2]

Async< HResource > CeresEngine::ResourceManager::locate ( StringView  name)

Loads a resource by it's name.

If the resource is already created, an existing instance is returned as if getResource(StringView) was called, otherwise it will be loaded and a handle to the loading resource will be returned.

Please note that the resource may not be loaded at the time this method returns, so make sure to check it before using it.

Parameters
nameThe name of the resource to be loaded.
Returns
The resource handle to the resource.

◆ notifyHandleDestroy()

void CeresEngine::ResourceManager::notifyHandleDestroy ( const ResourceHandleData resourceHandleData)
private

Notifies the manager that the last resource handle was destroyed.

Parameters
resourceHandleDataThe resource handle data pointer.

◆ notifyStrongHandleDestroy()

void CeresEngine::ResourceManager::notifyStrongHandleDestroy ( ResourceHandleData resourceHandleData)
private

Notifies the manager that the resource pointed by the resource handle is no longer referenced by any strong handle.

Parameters
resourceHandleDataThe resource handle data pointer.

◆ save() [1/2]

Async CeresEngine::ResourceManager::save ( OutputStream  outputStream,
HResource  resource 
)

Saves a resource to an output stream.

Parameters
outputStreamThe output stream to save the resource to.
resourceThe resource to be saved.
Returns
An async object that can be used to be notified once the save operation has completed.

◆ save() [2/2]

Async CeresEngine::ResourceManager::save ( ResourceURL  url,
HResource  resource 
)

Saves a resource to a URL.

Note that the URL provider must support writing, otherwise the resource saving will fail.

Parameters
urlThe URL to save the resource to.
resourceThe resource to be saved.
Returns
A continuable that can be used to be notified once the save operation has completed.

◆ setBaseURL()

void CeresEngine::ResourceManager::setBaseURL ( const ResourceURL baseURL)

The base URL used to load resources from.

Friends And Related Symbol Documentation

◆ PackageManager

◆ ResourceData

◆ ResourceHandleData

Member Data Documentation

◆ importers

ResourceImporterRegistry CeresEngine::ResourceManager::importers

The registry that keeps track of registered importers.

◆ mBaseURL

ResourceURL CeresEngine::ResourceManager::mBaseURL
private

The base URL used to load resources from.

◆ mExecutionContext

ExecutionContext& CeresEngine::ResourceManager::mExecutionContext
private

The execution context to perform asynchronous resource operations on.

◆ mImportingResources

LockedObject<ImportingResourcesList> CeresEngine::ResourceManager::mImportingResources
private

A list of importing resources.

◆ mLoadingResources

LockedObject<LoadingResourcesList> CeresEngine::ResourceManager::mLoadingResources
private

A list of loading resources.

◆ mPackageManager

PackageManager* CeresEngine::ResourceManager::mPackageManager = nullptr
private

The package manager associated with this resource manager.

The package manager is optional and may not be available in all cases.

◆ mResourceHandles

LockedObject<HashMap<UUID, ResourceHandleData*> > CeresEngine::ResourceManager::mResourceHandles
private

A map of active resource handles, mapped by their UUID.

◆ mResources

LockedObject<LoadedResourceMap> CeresEngine::ResourceManager::mResources
private

A map that maps every loaded resource by it's UUID.

◆ mSavingResources

LockedObject<SavingResourcesList> CeresEngine::ResourceManager::mSavingResources
private

A list of saving resources.

◆ mSerializationContext

const SerializationContext& CeresEngine::ResourceManager::mSerializationContext
private

A context for the serializer and deserializer to operate on.

◆ mURLSession

URLSession& CeresEngine::ResourceManager::mURLSession
private

The URL session to be used to load resources.


The documentation for this class was generated from the following file: