|
|
|
|
@ -30,7 +30,59 @@ namespace Magnum {
|
|
|
|
|
/**
|
|
|
|
|
@brief Base for resource loaders |
|
|
|
|
|
|
|
|
|
Provides asynchronous resource loading for ResourceManager. |
|
|
|
|
Provides (a)synchronous resource loading for ResourceManager. |
|
|
|
|
|
|
|
|
|
@section AbstractResourceLoader-usage Usage and subclassing |
|
|
|
|
|
|
|
|
|
Usage is done by subclassing. Subclass instances can be added to |
|
|
|
|
ResourceManager using ResourceManager::setLoader(). After adding the loader, |
|
|
|
|
each call to ResourceManager::get() will call load() implementation unless the |
|
|
|
|
resource is already loaded (or loading is in progress). Note that resources |
|
|
|
|
requested before the loader was added are not be affected by the loader. |
|
|
|
|
|
|
|
|
|
Subclassing is done by implementing at least load() function. The loading can |
|
|
|
|
be done synchronously or asynchronously (i.e., in another thread). The base |
|
|
|
|
implementation provides interface to ResourceManager and manages loading |
|
|
|
|
progress (which is then available through functions requestedCount(), |
|
|
|
|
loadedCount() and notFoundCount()). You shouldn't access the ResourceManager |
|
|
|
|
directly when loading the data. |
|
|
|
|
|
|
|
|
|
Your load() implementation must call the base implementation at the beginning |
|
|
|
|
so ResourceManager is informed about loading state. Then, after your resources |
|
|
|
|
are loaded, call set() to pass them to ResourceManager or call setNotFound() |
|
|
|
|
to indicate that the resource was not found. |
|
|
|
|
|
|
|
|
|
You can also implement name() to provide meaningful names for resource keys. |
|
|
|
|
|
|
|
|
|
Example implementation for synchronous mesh loader: |
|
|
|
|
@code |
|
|
|
|
class MeshResourceLoader: public AbstractResourceLoader<Mesh> { |
|
|
|
|
public: |
|
|
|
|
void load(ResourceKey key) { |
|
|
|
|
// Indicate that loading has begun
|
|
|
|
|
AbstractResourceLoader<Mesh>::load(key); |
|
|
|
|
|
|
|
|
|
// Load the mesh...
|
|
|
|
|
|
|
|
|
|
// Not found
|
|
|
|
|
if(!found) { |
|
|
|
|
setNotFound(key); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Found, pass it to resource manager
|
|
|
|
|
set(key, mesh, state, policy); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
@endcode |
|
|
|
|
|
|
|
|
|
You can then add it to resource manager instance like this: |
|
|
|
|
@code |
|
|
|
|
MyResourceManager manager; |
|
|
|
|
MeshResourceLoader loader; |
|
|
|
|
|
|
|
|
|
manager->setLoader(loader); |
|
|
|
|
@endcode |
|
|
|
|
*/ |
|
|
|
|
template<class T> class AbstractResourceLoader { |
|
|
|
|
friend class Implementation::ResourceManagerData<T>; |
|
|
|
|
@ -78,11 +130,12 @@ template<class T> class AbstractResourceLoader {
|
|
|
|
|
* |
|
|
|
|
* If the resource isn't yet loaded or loading, state of the resource |
|
|
|
|
* is set to @ref Resource::ResourceState "ResourceState::Loading" and count of |
|
|
|
|
* requested features is incremented. |
|
|
|
|
* requested features is incremented. Depending on implementation the |
|
|
|
|
* resource might be loaded synchronously or asynchronously. |
|
|
|
|
* |
|
|
|
|
* See class documentation for reimplementation guide. |
|
|
|
|
* |
|
|
|
|
* The resource might be loaded asynchronously and added to |
|
|
|
|
* ResourceManager when loading is done. |
|
|
|
|
* @see ResourceManager::state(), requestedCount(), notFountCount(), |
|
|
|
|
* @see ResourceManager::state(), requestedCount(), notFoundCount(), |
|
|
|
|
* loadedCount() |
|
|
|
|
*/ |
|
|
|
|
virtual void load(ResourceKey key) = 0; |
|
|
|
|
|