|
CeresEngine 0.2.0
A game development framework
|
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< T > | getResource (const StringView name) |
| template<typename T > | |
| ResourceHandle< T > | getResource (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< HResource > | locate (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< HResource > | load (ResourceURL url, Optional< ResourceID > resourceID={}) |
| Loads a resource using a URL. | |
| Async< HResource > | load (ResourceID id) |
| Loads a resource using a UUID. | |
| Async< HResource > | load (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< T > | create (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< T > | createWithID (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< HResource > | import (ResourceURL url, UPtr< ResourceImportOptions > &&importOptions=nullptr) |
| Imports a new resource from a raw file. | |
| const ResourceURL & | getBaseURL () const noexcept |
| The base URL used to load resources from. | |
| void | setBaseURL (const ResourceURL &baseURL) |
| The base URL used to load resources from. | |
| URLSession & | getURLSession () const noexcept |
| The URL session to be used to load resources. | |
| ExecutionContext & | getExecutionContext () const noexcept |
| The execution context to perform asynchronous resource operations on. | |
| PackageManager * | getPackageManager () 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 | |
| URLSession & | mURLSession |
| The URL session to be used to load resources. | |
| ExecutionContext & | mExecutionContext |
| The execution context to perform asynchronous resource operations on. | |
| const SerializationContext & | mSerializationContext |
| A context for the serializer and deserializer to operate on. | |
| PackageManager * | mPackageManager = 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< LoadedResourceMap > | mResources |
| A map that maps every loaded resource by it's UUID. | |
| LockedObject< LoadingResourcesList > | mLoadingResources |
| A list of loading resources. | |
| LockedObject< SavingResourcesList > | mSavingResources |
| A list of saving resources. | |
| LockedObject< ImportingResourcesList > | mImportingResources |
| A list of importing resources. | |
Friends | |
| class | PackageManager |
| class | ResourceData |
| class | ResourceHandleData |
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.
A list of importing resources.
A map that maps every loaded resource by it's UUID.
A list of loading resources.
A list of saving resources.
| CeresEngine::ResourceManager::ResourceManager | ( | URLSession & | urlSession, |
| ExecutionContext & | executionContext, | ||
| const SerializationContext & | serializationContext = SerializationContext::getDefault() |
||
| ) |
Creates a new resource manager instance.
| urlSession | The URL session to be used to load resources. |
| executionContext | The execution context to perform asynchronous resource operations on. |
| serializationContext | A context for the serializer and deserializer to operate on. Can be empty, in which case the default context is used. |
| CeresEngine::ResourceManager::~ResourceManager | ( | ) |
Destroys the resource manager and all it's managed resources.
|
inline |
Create a new resource by constructing it with Args and registers it with the manager.
| T | The resource type to be created. |
| Args | The resource constructor argument types. |
| args | The resource constructor arguments. |
|
inline |
Registers a new resource with the manager.
| resource | A shared pointer of the resource to be registered. |
| HResource CeresEngine::ResourceManager::create | ( | ResourcePtr && | resourcePtr | ) |
Registers a new resource with the manager.
| resource | A shared pointer of the resource to be registered. |
|
private |
|
private |
Creates a new ResourceData object for a resource.
|
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.
| T | The resource type to be created. |
| Args | The resource constructor argument types. |
| uuid | The UUID to be used for the new resource. If the resource already exists, it will be replaced. |
| args | The resource constructor arguments. |
|
inline |
| HResource CeresEngine::ResourceManager::createWithID | ( | const UUID & | uuid, |
| ResourcePtr && | resourcePtr | ||
| ) |
Registers a new resource with the manager.
| resource | A shared pointer of the resource to be registered. |
|
inlinenoexcept |
The base URL used to load resources from.
|
inlinenoexcept |
The execution context to perform asynchronous resource operations on.
|
inlinenoexcept |
The package manager associated with this resource manager.
The package manager is optional and may not be available in all cases.
|
inline |
|
inline |
| HResource CeresEngine::ResourceManager::getResource | ( | StringView | name | ) |
Locates an existing resource by it's name.
| name | The name of the resource to be located. |
nullptr if not found.
|
inlinenoexcept |
The URL session to be used to load resources.
|
inline |
| Async< HResource > CeresEngine::ResourceManager::import | ( | ResourceURL | url, |
| UPtr< ResourceImportOptions > && | importOptions = nullptr |
||
| ) |
Imports a new resource from a raw file.
| url | The URL of the raw file to be imported. |
| importOptions | A set of options given to the importer. Allows controlling how the importer will import the raw data and create the resource. |
|
inline |
|
inline |
|
inline |
| 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.
| inputStream | The input stream to load a resource from. |
| Async< HResource > CeresEngine::ResourceManager::load | ( | ResourceID | id | ) |
| 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.
| url | The URL to load the resource from. |
|
inline |
| 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.
| name | The name of the resource to be loaded. |
|
private |
Notifies the manager that the last resource handle was destroyed.
| resourceHandleData | The resource handle data pointer. |
|
private |
Notifies the manager that the resource pointed by the resource handle is no longer referenced by any strong handle.
| resourceHandleData | The resource handle data pointer. |
| Async CeresEngine::ResourceManager::save | ( | OutputStream | outputStream, |
| HResource | resource | ||
| ) |
Saves a resource to an output stream.
| outputStream | The output stream to save the resource to. |
| resource | The resource to be saved. |
| 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.
| url | The URL to save the resource to. |
| resource | The resource to be saved. |
| void CeresEngine::ResourceManager::setBaseURL | ( | const ResourceURL & | baseURL | ) |
The base URL used to load resources from.
|
friend |
|
friend |
|
friend |
| ResourceImporterRegistry CeresEngine::ResourceManager::importers |
The registry that keeps track of registered importers.
|
private |
The base URL used to load resources from.
|
private |
The execution context to perform asynchronous resource operations on.
|
private |
A list of importing resources.
|
private |
A list of loading resources.
|
private |
The package manager associated with this resource manager.
The package manager is optional and may not be available in all cases.
|
private |
A map of active resource handles, mapped by their UUID.
|
private |
A map that maps every loaded resource by it's UUID.
|
private |
A list of saving resources.
|
private |
A context for the serializer and deserializer to operate on.
|
private |
The URL session to be used to load resources.