Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Ogre::ResourceManager Class Reference

Defines a generic resource handler. More...

#include <OgreResourceManager.h>

Inheritance diagram for Ogre::ResourceManager:

Inheritance graph
[legend]
List of all members.

Public Types

typedef std::map< ResourceHandle,
Resource * > 
ResourceHandleMap
typedef MapIterator< ResourceHandleMapResourceMapIterator

Public Methods

 ResourceManager ()
virtual ~ResourceManager ()
virtual void setMemoryBudget (size_t bytes)
 Set a limit on the amount of memory this resource handler may use.

virtual Resourcecreate (const String &name)=0
 Creates a new blank resource, compatible with this manager.

virtual void load (Resource *res, int priority)
 Load a resource.

virtual void add (Resource *res)
 Add a resource to this manager; normally only done by subclasses.

virtual void unload (Resource *res)
 Unloads a Resource from the managed resources list, calling it's unload() method.

virtual void unloadAndDestroyAll (void)
 Unloads all Resources from memory.

virtual ResourcegetByName (const String &name)
 Retrieves a pointer to a resource by name, or null if the resource does not exist.

virtual ResourcegetByHandle (ResourceHandle handle)
 Retrieves a pointer to a resource by handle, or null if the resource does not exist.

void addSearchPath (const String &path)
 Adds a relative path to search for resources of this type.

void addArchiveEx (const String &strName, const String &strDriverName)
 Adds an archive to the search path for this type of resource.

bool _findResourceData (const String &filename, DataChunk &refChunk)
 Internal method, used for locating resource data in the file system / archives.

std::set< String_getAllNamesLike (const String &startPath, const String &extension)
 Returns a collection of files with the given extension in all resource paths, common and specific to this resource type.

ResourceMapIterator getResourceIterator (void)
 Returns an iterator over all resources in this manager.


Static Public Methods

void addCommonSearchPath (const String &path)
 Adds a relative search path for resources of ALL types.

void addCommonArchiveEx (const String &strName, const String &strDriverName)
 Adds an archive to the search path for all resources.

std::set< String_getAllCommonNamesLike (const String &startPath, const String &extension)
 Returns a collection of files with the given extension in the common resource paths.

bool _findCommonResourceData (const String &filename, DataChunk &refChunk)
 Internal method, used for locating common resource data in the file system / archives.


Protected Types

typedef HashMap< String, ArchiveEx *,
_StringHash
FileMap
typedef HashMap< String, Resource *,
_StringHash
ResourceMap

Protected Methods

ResourceHandle getNextHandle (void)
 Allocates the next handle.

void checkUsage (void)
 Checks memory usage and pages out if required.


Protected Attributes

FileMap mArchiveFiles
ResourceHandleMap mResourcesByHandle
ResourceMap mResources
ResourceHandle mNextHandle
size_t mMemoryBudget
size_t mMemoryUsage
std::vector< ArchiveEx * > mVFS
 Collection of searchable ArchiveEx classes (virtual file system) for this resource type.


Static Protected Attributes

FileMap mCommonArchiveFiles
std::vector< ArchiveEx * > mCommonVFS
 Collection of searchable ArchiveEx classes (virtual file system) for all resource types.


Detailed Description

Defines a generic resource handler.

Remarks:
A resource manager is responsible for managing a pool of resources of a particular type. It must index them, look them up, load and destroy them. It may also need to stay within a defined memory budget, and temporaily unload some resources if it needs to to stay within this budget.

Resource managers use a priority system to determine what can be unloaded, and a Least Recently Used (LRU) policy within resources of the same priority.

Definition at line 50 of file OgreResourceManager.h.


Member Typedef Documentation

typedef HashMap< String, ArchiveEx *, _StringHash > Ogre::ResourceManager::FileMap [protected]
 

Definition at line 195 of file OgreResourceManager.h.

typedef std::map<ResourceHandle, Resource*> Ogre::ResourceManager::ResourceHandleMap
 

Definition at line 203 of file OgreResourceManager.h.

typedef HashMap< String, Resource*, _StringHash > Ogre::ResourceManager::ResourceMap [protected]
 

Definition at line 196 of file OgreResourceManager.h.

typedef MapIterator<ResourceHandleMap> Ogre::ResourceManager::ResourceMapIterator
 

Definition at line 224 of file OgreResourceManager.h.


Constructor & Destructor Documentation

Ogre::ResourceManager::ResourceManager  
 

Definition at line 53 of file OgreResourceManager.cpp.

References mMemoryBudget, mMemoryUsage, and mNextHandle.

Ogre::ResourceManager::~ResourceManager   [virtual]
 

Definition at line 61 of file OgreResourceManager.cpp.

References unloadAndDestroyAll().


Member Function Documentation

bool Ogre::ResourceManager::_findCommonResourceData const String   filename,
DataChunk   refChunk
[static]
 

Internal method, used for locating common resource data in the file system / archives.

Remarks:
This is a static version of _findResourceData specifically designed to only search in the common resource archives, and is therefore usable from non-ResourceManager subclasses.
Parameters:
filename  File to find
refChunk  Reference to a DataChunk object to fill with the data from the file
Returns:
On success, true is returned

On failiure, false is returned

Definition at line 294 of file OgreResourceManager.cpp.

References Except, mCommonArchiveFiles, and mCommonVFS.

bool Ogre::ResourceManager::_findResourceData const String   filename,
DataChunk   refChunk
 

Internal method, used for locating resource data in the file system / archives.

Parameters:
filename  File to find
refChunk  Reference to a DataChunk object to fill with the data from the file
Returns:
On success, true is returned

On failiure, false is returnec

Definition at line 212 of file OgreResourceManager.cpp.

References Except, mArchiveFiles, mCommonArchiveFiles, mCommonVFS, and mVFS.

std::set< String > Ogre::ResourceManager::_getAllCommonNamesLike const String   startPath,
const String   extension
[static]
 

Returns a collection of files with the given extension in the common resource paths.

Remarks:
This is a convenience method to allow non-subclasses to search for files in the common paths.
Parameters:
startPath  The path, relative to each common resource start, to search in (use "./" for the root)
extension  The extension of file to search for.
Returns:
A set of String filenames (it is a set because duplicates will be ignored)

Definition at line 255 of file OgreResourceManager.cpp.

References mCommonVFS, and Ogre::StringVector.

std::set< String > Ogre::ResourceManager::_getAllNamesLike const String   startPath,
const String   extension
 

Returns a collection of files with the given extension in all resource paths, common and specific to this resource type.

Parameters:
startPath  The path, relative to each common resource start, to search in (use "./" for the root)
extension  The extension of file to search for.
Returns:
A set of String filenames (it is a set because duplicates will be ignored)

Definition at line 274 of file OgreResourceManager.cpp.

References mVFS, and Ogre::StringVector.

void Ogre::ResourceManager::add Resource   res [virtual]
 

Add a resource to this manager; normally only done by subclasses.

Definition at line 75 of file OgreResourceManager.cpp.

References Except, Ogre::Resource::getName(), getNextHandle(), Ogre::Resource::mHandle, mResources, and mResourcesByHandle.

Referenced by Ogre::Quake3ShaderManager::create(), Ogre::MaterialManager::create(), Ogre::MeshManager::createManual(), Ogre::HighLevelGpuProgramManager::createProgram(), and load().

void Ogre::ResourceManager::addArchiveEx const String   strName,
const String   strDriverName
 

Adds an archive to the search path for this type of resource.

Remarks:
Ogre can load resources from archives. This method adds the named archive to the search path for the type of resource managed by the specific resource manager. Archives are not searched for themselves so a complete path must be specified here (or relative to the current path). Archives take precedence over files in the filesystem.

Definition at line 188 of file OgreResourceManager.cpp.

References Ogre::ArchiveEx::getAllNamesLike(), mArchiveFiles, mVFS, and Ogre::StringVector.

Referenced by addSearchPath().

void Ogre::ResourceManager::addCommonArchiveEx const String   strName,
const String   strDriverName
[static]
 

Adds an archive to the search path for all resources.

Remarks:
As ResourceManager::addArchive, except this archive is used for all types of resources, not just the type managed by the resource manager in question.

Definition at line 200 of file OgreResourceManager.cpp.

References Ogre::ArchiveEx::getAllNamesLike(), mCommonArchiveFiles, mCommonVFS, and Ogre::StringVector.

Referenced by addCommonSearchPath().

void Ogre::ResourceManager::addCommonSearchPath const String   path [static]
 

Adds a relative search path for resources of ALL types.

This method has the same effect as ResourceManager::addSearchPath, except that the path added applies to ALL resources, not just the one managed by the subclass in question.

Definition at line 182 of file OgreResourceManager.cpp.

References addCommonArchiveEx(), and Ogre::convertPath().

void Ogre::ResourceManager::addSearchPath const String   path
 

Adds a relative path to search for resources of this type.

Remarks:
This method adds the supplied path to the list of relative locations that that will be searched for a single type of resource only. Each subclass of ResourceManager will maintain it's own list of specific subpaths, which it will append to the current path as it searches for matching files.

Definition at line 176 of file OgreResourceManager.cpp.

References addArchiveEx(), and Ogre::convertPath().

void Ogre::ResourceManager::checkUsage void    [protected]
 

Checks memory usage and pages out if required.

Definition at line 170 of file OgreResourceManager.cpp.

Referenced by setMemoryBudget().

virtual Resource* Ogre::ResourceManager::create const String   name [pure virtual]
 

Creates a new blank resource, compatible with this manager.

Remarks:
Resource managers handle disparate types of resources. This method returns a pointer to a valid new instance of the kind of resource managed here. The caller should complete the details of the returned resource and call ResourceManager::load to load the resource. Note that it is the CALLERS responsibility to destroy this object when it is no longer required (after calling ResourceManager::unload if it had been loaded).

Implemented in Ogre::ArchiveManager, Ogre::DynLibManager, Ogre::FontManager, Ogre::GpuProgramManager, Ogre::HighLevelGpuProgramManager, Ogre::MaterialManager, Ogre::MeshManager, Ogre::OverlayManager, Ogre::SkeletonManager, Ogre::TextureManager, Ogre::BspResourceManager, and Ogre::Quake3ShaderManager.

Resource * Ogre::ResourceManager::getByHandle ResourceHandle    handle [virtual]
 

Retrieves a pointer to a resource by handle, or null if the resource does not exist.

Definition at line 151 of file OgreResourceManager.cpp.

References mResourcesByHandle, and Ogre::ResourceHandle.

Resource * Ogre::ResourceManager::getByName const String   name [virtual]
 

Retrieves a pointer to a resource by name, or null if the resource does not exist.

Definition at line 139 of file OgreResourceManager.cpp.

References mResources.

Referenced by Ogre::MaterialManager::create(), Ogre::FontManager::create(), Ogre::MeshManager::createBezierPatch(), Ogre::MeshManager::createManual(), Ogre::SceneManager::createSkyboxPlane(), Ogre::SceneManager::createSkydomePlane(), Ogre::TextureManager::load(), Ogre::SkeletonManager::load(), Ogre::MeshManager::load(), Ogre::DynLibManager::load(), Ogre::ArchiveManager::load(), Ogre::SceneManager::setSkyBox(), and Ogre::TextureManager::unload().

ResourceHandle Ogre::ResourceManager::getNextHandle void    [protected]
 

Allocates the next handle.

Definition at line 165 of file OgreResourceManager.cpp.

References mNextHandle, and Ogre::ResourceHandle.

Referenced by add().

ResourceMapIterator Ogre::ResourceManager::getResourceIterator void   
 

Returns an iterator over all resources in this manager.

Definition at line 226 of file OgreResourceManager.h.

void Ogre::ResourceManager::load Resource   res,
int    priority
[virtual]
 

Load a resource.

Resources will be subclasses.

Reimplemented in Ogre::TextureManager.

Definition at line 67 of file OgreResourceManager.cpp.

References add(), Ogre::Resource::load(), and Ogre::Resource::touch().

Referenced by Ogre::OverlayManager::create().

void Ogre::ResourceManager::setMemoryBudget size_t    bytes [virtual]
 

Set a limit on the amount of memory this resource handler may use.

Remarks:
If, when asked to load a new resource, the manager believes it will exceed this memory budget, it will temporarily unload a resource to make room for the new one. This unloading is not permanent and the Resource is not destroyed; it simply needs to be reloaded when next used.

Definition at line 97 of file OgreResourceManager.cpp.

References checkUsage(), and mMemoryBudget.

void Ogre::ResourceManager::unload Resource   res [virtual]
 

Unloads a Resource from the managed resources list, calling it's unload() method.

Remarks:
This method removes a resource from the list maintained by this manager, and unloads it from memory. It does NOT destroy the resource itself, although the memory used by it will be largely freed up. This would allow you to reload the resource again if you wished.

Permanently destroying the resource is, as mentioned in ResourceManager::create, the library user's responsibility.

Definition at line 105 of file OgreResourceManager.cpp.

References Ogre::Resource::getHandle(), Ogre::Resource::getName(), Ogre::Resource::getSize(), mMemoryUsage, mResources, mResourcesByHandle, and Ogre::Resource::unload().

Referenced by Ogre::SceneManager::createSkyboxPlane(), and Ogre::SceneManager::createSkydomePlane().

void Ogre::ResourceManager::unloadAndDestroyAll void    [virtual]
 

Unloads all Resources from memory.

Remarks:
Note that unlike ResourceManager::unload, Resource objects are DESTROYED as well as unloaded. This is because you are unlikely to be managing the deletion of the objects individually in this case.

Reimplemented in Ogre::D3D9TextureManager, and Ogre::GLTextureManager.

Definition at line 122 of file OgreResourceManager.cpp.

References mResources, and mResourcesByHandle.

Referenced by Ogre::BspResourceManager::load(), Ogre::D3DTextureManager::~D3DTextureManager(), and ~ResourceManager().


Member Data Documentation

FileMap Ogre::ResourceManager::mArchiveFiles [protected]
 

Definition at line 200 of file OgreResourceManager.h.

Referenced by _findResourceData(), and addArchiveEx().

ResourceManager::FileMap Ogre::ResourceManager::mCommonArchiveFiles [static, protected]
 

Definition at line 37 of file OgreResourceManager.cpp.

Referenced by _findCommonResourceData(), _findResourceData(), and addCommonArchiveEx().

std::vector< ArchiveEx * > Ogre::ResourceManager::mCommonVFS [static, protected]
 

Collection of searchable ArchiveEx classes (virtual file system) for all resource types.

Definition at line 36 of file OgreResourceManager.cpp.

Referenced by _findCommonResourceData(), _findResourceData(), _getAllCommonNamesLike(), addCommonArchiveEx(), Ogre::OverlayManager::loadAndParseOverlayFile(), Ogre::Quake3ShaderManager::parseAllSources(), Ogre::OverlayManager::parseAllSources(), Ogre::MaterialManager::parseAllSources(), and Ogre::FontManager::parseAllSources().

size_t Ogre::ResourceManager::mMemoryBudget [protected]
 

Definition at line 210 of file OgreResourceManager.h.

Referenced by ResourceManager(), and setMemoryBudget().

size_t Ogre::ResourceManager::mMemoryUsage [protected]
 

Definition at line 211 of file OgreResourceManager.h.

Referenced by ResourceManager(), and unload().

ResourceHandle Ogre::ResourceManager::mNextHandle [protected]
 

Definition at line 208 of file OgreResourceManager.h.

Referenced by getNextHandle(), and ResourceManager().

ResourceMap Ogre::ResourceManager::mResources [protected]
 

Definition at line 206 of file OgreResourceManager.h.

Referenced by Ogre::OverlayManager::_queueOverlaysForRendering(), add(), Ogre::FontManager::create(), Ogre::MeshManager::createPrefabPlane(), Ogre::TextureManager::enable32BitTextures(), getByName(), Ogre::OverlayManager::getPositionTargetAt(), Ogre::TextureManager::loadImage(), Ogre::TextureManager::loadRawData(), unload(), unloadAndDestroyAll(), Ogre::GLTextureManager::unloadAndDestroyAll(), Ogre::D3D9TextureManager::unloadAndDestroyAll(), Ogre::ArchiveManager::~ArchiveManager(), and Ogre::DynLibManager::~DynLibManager().

ResourceHandleMap Ogre::ResourceManager::mResourcesByHandle [protected]
 

Definition at line 205 of file OgreResourceManager.h.

Referenced by add(), getByHandle(), unload(), and unloadAndDestroyAll().

std::vector<ArchiveEx*> Ogre::ResourceManager::mVFS [protected]
 

Collection of searchable ArchiveEx classes (virtual file system) for this resource type.

Definition at line 221 of file OgreResourceManager.h.

Referenced by _findResourceData(), _getAllNamesLike(), addArchiveEx(), Ogre::OverlayManager::loadAndParseOverlayFile(), Ogre::Quake3ShaderManager::parseAllSources(), Ogre::OverlayManager::parseAllSources(), Ogre::MaterialManager::parseAllSources(), and Ogre::FontManager::parseAllSources().


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

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:27:05 2004