OgreResourceManager.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _ResourceManager_H__
#define _ResourceManager_H__
#include "OgrePrerequisites.h"
#include "OgreResource.h"
#include "OgreResourceGroupManager.h"
#include "OgreIteratorWrappers.h"
#include "OgreCommon.h"
#include "OgreDataStream.h"
#include "OgreStringVector.h"
#include "OgreScriptLoader.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
template <typename T>
class Pool
{
protected:
typedef typename list<T>::type ItemList;
ItemList mItems;
OGRE_AUTO_MUTEX;
public:
Pool() {}
virtual ~Pool() {}
virtual std::pair<bool, T> removeItem()
{
OGRE_LOCK_AUTO_MUTEX;
std::pair<bool, T> ret;
if (mItems.empty())
{
ret.first = false;
}
else
{
ret.first = true;
ret.second = mItems.front();
mItems.pop_front();
}
return ret;
}
virtual void addItem(const T& i)
{
OGRE_LOCK_AUTO_MUTEX;
mItems.push_front(i);
}
virtual void clear()
{
OGRE_LOCK_AUTO_MUTEX;
mItems.clear();
}
};
class _OgreExport ResourceManager : public ScriptLoader, public ResourceAlloc
{
public:
OGRE_AUTO_MUTEX; // public to allow external locking
ResourceManager();
virtual ~ResourceManager();
virtual ResourcePtr createResource(const String& name, const String& group,
bool isManual = false, ManualResourceLoader* loader = 0,
const NameValuePairList* createParams = 0);
typedef std::pair<ResourcePtr, bool> ResourceCreateOrRetrieveResult;
virtual ResourceCreateOrRetrieveResult createOrRetrieve(const String& name,
const String& group, bool isManual = false,
ManualResourceLoader* loader = 0,
const NameValuePairList* createParams = 0);
virtual void setMemoryBudget(size_t bytes);
virtual size_t getMemoryBudget(void) const;
virtual size_t getMemoryUsage(void) const { return mMemoryUsage.get(); }
virtual void unload(const String& name);
virtual void unload(ResourceHandle handle);
virtual void unloadAll(bool reloadableOnly = true);
virtual void reloadAll(bool reloadableOnly = true);
virtual void unloadUnreferencedResources(bool reloadableOnly = true);
virtual void reloadUnreferencedResources(bool reloadableOnly = true);
virtual void remove(ResourcePtr& r);
virtual void remove(const String& name);
virtual void remove(ResourceHandle handle);
virtual void removeAll(void);
virtual void removeUnreferencedResources(bool reloadableOnly = true);
virtual ResourcePtr getResourceByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
virtual ResourcePtr getByHandle(ResourceHandle handle);
virtual bool resourceExists(const String& name)
{
return !getResourceByName(name).isNull();
}
virtual bool resourceExists(ResourceHandle handle)
{
return !getByHandle(handle).isNull();
}
virtual void _notifyResourceTouched(Resource* res);
virtual void _notifyResourceLoaded(Resource* res);
virtual void _notifyResourceUnloaded(Resource* res);
virtual ResourcePtr prepare(const String& name,
const String& group, bool isManual = false,
ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0,
bool backgroundThread = false);
virtual ResourcePtr load(const String& name,
const String& group, bool isManual = false,
ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0,
bool backgroundThread = false);
virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; }
virtual void parseScript(DataStreamPtr& stream, const String& groupName)
{ (void)stream; (void)groupName; }
virtual Real getLoadingOrder(void) const { return mLoadOrder; }
const String& getResourceType(void) const { return mResourceType; }
virtual void setVerbose(bool v) { mVerbose = v; }
virtual bool getVerbose(void) { return mVerbose; }
class _OgreExport ResourcePool : public Pool<ResourcePtr>, public ResourceAlloc
{
protected:
String mName;
public:
ResourcePool(const String& name);
~ResourcePool();
const String& getName() const;
void clear();
};
ResourcePool* getResourcePool(const String& name);
void destroyResourcePool(ResourcePool* pool);
void destroyResourcePool(const String& name);
void destroyAllResourcePools();
protected:
ResourceHandle getNextHandle(void);
virtual Resource* createImpl(const String& name, ResourceHandle handle,
const String& group, bool isManual, ManualResourceLoader* loader,
const NameValuePairList* createParams) = 0;
virtual void addImpl( ResourcePtr& res );
virtual void removeImpl( ResourcePtr& res );
virtual void checkUsage(void);
public:
typedef HashMap< String, ResourcePtr > ResourceMap;
typedef HashMap< String, ResourceMap > ResourceWithGroupMap;
typedef map<ResourceHandle, ResourcePtr>::type ResourceHandleMap;
protected:
ResourceHandleMap mResourcesByHandle;
ResourceMap mResources;
ResourceWithGroupMap mResourcesWithGroup;
size_t mMemoryBudget;
AtomicScalar<ResourceHandle> mNextHandle;
AtomicScalar<size_t> mMemoryUsage;
bool mVerbose;
// IMPORTANT - all subclasses must populate the fields below
StringVector mScriptPatterns;
Real mLoadOrder;
String mResourceType;
public:
typedef MapIterator<ResourceHandleMap> ResourceMapIterator;
ResourceMapIterator getResourceIterator(void)
{
return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
}
protected:
typedef map<String, ResourcePool*>::type ResourcePoolMap;
ResourcePoolMap mResourcePoolMap;
};
}
#include "OgreHeaderSuffix.h"
#endif
OgreScriptLoader.h
Ogre::ResourceManager::ResourceCreateOrRetrieveResult
std::pair< ResourcePtr, bool > ResourceCreateOrRetrieveResult
Definition: OgreResourceManager.h:152
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::ScriptLoader
Abstract class defining the interface used by classes which wish to perform script loading to define ...
Definition: OgreScriptLoader.h:59
Ogre::list
Definition: OgrePrerequisites.h:505
Ogre::Pool::ItemList
list< T >::type ItemList
Definition: OgreResourceManager.h:50
Ogre::Pool::~Pool
virtual ~Pool()
Definition: OgreResourceManager.h:55
OgreResource.h
Ogre::ResourceManager::getResourceType
const String & getResourceType(void) const
Gets a string identifying the type of resource this manager handles.
Definition: OgreResourceManager.h:464
Ogre::ResourceManager::getLoadingOrder
virtual Real getLoadingOrder(void) const
Gets the relative loading order of resources of this type.
Definition: OgreResourceManager.h:461
Ogre::ResourceManager::parseScript
virtual void parseScript(DataStreamPtr &stream, const String &groupName)
Parse the definition of a set of resources from a script file.
Definition: OgreResourceManager.h:452
Ogre::ResourceManager::resourceExists
virtual bool resourceExists(const String &name)
Returns whether the named resource exists in this manager.
Definition: OgreResourceManager.h:357
Ogre::Pool
Template class describing a simple pool of items.
Definition: OgreResourceManager.h:47
Ogre::MapIterator
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:319
Ogre::ResourceManager::ResourceMapIterator
MapIterator< ResourceHandleMap > ResourceMapIterator
Definition: OgreResourceManager.h:564
Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME
static String AUTODETECT_RESOURCE_GROUP_NAME
Special resource group name which causes resource group to be automatically determined based on searc...
Definition: OgreResourceGroupManager.h:270
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::ResourceManager::mResourcePoolMap
ResourcePoolMap mResourcePoolMap
Definition: OgreResourceManager.h:576
Ogre::Pool::removeItem
virtual std::pair< bool, T > removeItem()
Get the next item from the pool.
Definition: OgreResourceManager.h:60
Ogre::StringVector
vector< String >::type StringVector
Definition: OgreStringVector.h:45
Ogre::Resource
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:79
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Ogre::SharedPtr::isNull
bool isNull(void) const
Definition: OgreSharedPtr.h:275
OgreDataStream.h
Ogre::ResourceManager::mLoadOrder
Real mLoadOrder
Loading order relative to other managers, higher is later.
Definition: OgreResourceManager.h:559
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
OGRE_LOCK_AUTO_MUTEX
#define OGRE_LOCK_AUTO_MUTEX
Definition: OgreThreadDefinesBoost.h:33
Ogre::Pool::clear
virtual void clear()
Clear the pool.
Definition: OgreResourceManager.h:85
Ogre::ResourceManager::mMemoryBudget
size_t mMemoryBudget
Definition: OgreResourceManager.h:548
Ogre::ResourceManager::mVerbose
bool mVerbose
In bytes.
Definition: OgreResourceManager.h:552
OgreCommon.h
Ogre::ResourceManager::ResourceHandleMap
map< ResourceHandle, ResourcePtr >::type ResourceHandleMap
Definition: OgreResourceManager.h:543
Ogre::ResourceManager::ResourcePool::mName
String mName
Definition: OgreResourceManager.h:481
Ogre::Pool::mItems
ItemList mItems
Definition: OgreResourceManager.h:51
OgrePrerequisites.h
Ogre::ResourceManager::ResourceMap
HashMap< String, ResourcePtr > ResourceMap
Definition: OgreResourceManager.h:541
Ogre::ResourceManager::getVerbose
virtual bool getVerbose(void)
Gets whether this manager and its resources habitually produce log output.
Definition: OgreResourceManager.h:470
Ogre::Pool::addItem
virtual void addItem(const T &i)
Add a new item to the pool.
Definition: OgreResourceManager.h:79
Ogre::NameValuePairList
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:550
Ogre::ResourceManager::getResourceIterator
ResourceMapIterator getResourceIterator(void)
Returns an iterator over all resources in this manager.
Definition: OgreResourceManager.h:569
OgreStringVector.h
Ogre::ResourceManager::mMemoryUsage
AtomicScalar< size_t > mMemoryUsage
Definition: OgreResourceManager.h:550
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::ResourceManager::mResourceType
String mResourceType
String identifying the resource type this manager handles.
Definition: OgreResourceManager.h:561
Ogre::ResourceManager::mResources
ResourceMap mResources
Definition: OgreResourceManager.h:546
OgreHeaderSuffix.h
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:122
Ogre::ResourceManager::resourceExists
virtual bool resourceExists(ResourceHandle handle)
Returns whether a resource with the given handle exists in this manager.
Definition: OgreResourceManager.h:362
OgreIteratorWrappers.h
Ogre::AtomicScalar< ResourceHandle >
Ogre::ResourceManager::ResourceWithGroupMap
HashMap< String, ResourceMap > ResourceWithGroupMap
Definition: OgreResourceManager.h:542
Ogre::ResourceManager::getScriptPatterns
virtual const StringVector & getScriptPatterns(void) const
Gets the file patterns which should be used to find scripts for this ResourceManager.
Definition: OgreResourceManager.h:437
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Pool::Pool
Pool()
Definition: OgreResourceManager.h:54
Ogre::SharedPtr< Resource >
OgreHeaderPrefix.h
Ogre::ResourceManager::ResourcePool
Definition of a pool of resources, which users can use to reuse similar resources many times without ...
Definition: OgreResourceManager.h:478
Ogre::ResourceManager::mNextHandle
AtomicScalar< ResourceHandle > mNextHandle
In bytes.
Definition: OgreResourceManager.h:549
OgreResourceGroupManager.h
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::ResourceManager::mResourcesByHandle
ResourceHandleMap mResourcesByHandle
Definition: OgreResourceManager.h:545
Ogre::ResourceManager::mResourcesWithGroup
ResourceWithGroupMap mResourcesWithGroup
Definition: OgreResourceManager.h:547
Ogre::Pool::OGRE_AUTO_MUTEX
OGRE_AUTO_MUTEX
Definition: OgreResourceManager.h:52
Ogre::ResourceManager::ResourcePoolMap
map< String, ResourcePool * >::type ResourcePoolMap
Definition: OgreResourceManager.h:575
Ogre::ResourceManager::OGRE_AUTO_MUTEX
OGRE_AUTO_MUTEX
Definition: OgreResourceManager.h:125
Ogre::ResourceManager::getMemoryUsage
virtual size_t getMemoryUsage(void) const
Gets the current memory usage, in bytes.
Definition: OgreResourceManager.h:185
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::ResourceManager::mScriptPatterns
StringVector mScriptPatterns
Patterns to use to look for scripts if supported (e.g. *.overlay)
Definition: OgreResourceManager.h:557
Ogre::ResourceManager::setVerbose
virtual void setVerbose(bool v)
Sets whether this manager and its resources habitually produce log output.
Definition: OgreResourceManager.h:467

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.