OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreResourceManager.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _ResourceManager_H__
29 #define _ResourceManager_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreResource.h"
35 #include "OgreIteratorWrappers.h"
36 #include "OgreCommon.h"
37 #include "OgreDataStream.h"
38 #include "OgreStringVector.h"
39 #include "OgreScriptLoader.h"
40 
41 namespace Ogre {
42 
74  {
75  public:
76  OGRE_AUTO_MUTEX // public to allow external locking
78  virtual ~ResourceManager();
79 
99  virtual ResourcePtr create(const String& name, const String& group,
100  bool isManual = false, ManualResourceLoader* loader = 0,
101  const NameValuePairList* createParams = 0);
102 
103  typedef std::pair<ResourcePtr, bool> ResourceCreateOrRetrieveResult;
117  virtual ResourceCreateOrRetrieveResult createOrRetrieve(const String& name,
118  const String& group, bool isManual = false,
119  ManualResourceLoader* loader = 0,
120  const NameValuePairList* createParams = 0);
121 
129  virtual void setMemoryBudget( size_t bytes);
130 
133  virtual size_t getMemoryBudget(void) const;
134 
136  virtual size_t getMemoryUsage(void) const { return mMemoryUsage; }
137 
144  virtual void unload(const String& name);
145 
152  virtual void unload(ResourceHandle handle);
153 
166  virtual void unloadAll(bool reloadableOnly = true);
167 
179  virtual void reloadAll(bool reloadableOnly = true);
180 
195  virtual void unloadUnreferencedResources(bool reloadableOnly = true);
196 
210  virtual void reloadUnreferencedResources(bool reloadableOnly = true);
211 
229  virtual void remove(ResourcePtr& r);
230 
248  virtual void remove(const String& name);
249 
267  virtual void remove(ResourceHandle handle);
282  virtual void removeAll(void);
283 
298  virtual void removeUnreferencedResources(bool reloadableOnly = true);
299 
302  virtual ResourcePtr getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
305  virtual ResourcePtr getByHandle(ResourceHandle handle);
306 
308  virtual bool resourceExists(const String& name)
309  {
310  return !getByName(name).isNull();
311  }
313  virtual bool resourceExists(ResourceHandle handle)
314  {
315  return !getByHandle(handle).isNull();
316  }
317 
321  virtual void _notifyResourceTouched(Resource* res);
322 
326  virtual void _notifyResourceLoaded(Resource* res);
327 
331  virtual void _notifyResourceUnloaded(Resource* res);
332 
348  virtual ResourcePtr prepare(const String& name,
349  const String& group, bool isManual = false,
350  ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0,
351  bool backgroundThread = false);
352 
368  virtual ResourcePtr load(const String& name,
369  const String& group, bool isManual = false,
370  ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0,
371  bool backgroundThread = false);
372 
388  virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; }
389 
403  virtual void parseScript(DataStreamPtr& stream, const String& groupName)
404  { (void)stream; (void)groupName; }
405 
412  virtual Real getLoadingOrder(void) const { return mLoadOrder; }
413 
415  const String& getResourceType(void) const { return mResourceType; }
416 
418  virtual void setVerbose(bool v) { mVerbose = v; }
419 
421  virtual bool getVerbose(void) { return mVerbose; }
422 
429  class _OgreExport ResourcePool : public Pool<ResourcePtr>, public ResourceAlloc
430  {
431  protected:
433  public:
434  ResourcePool(const String& name);
435  ~ResourcePool();
437  const String& getName() const;
438  void clear();
439  };
440 
442  ResourcePool* getResourcePool(const String& name);
444  void destroyResourcePool(ResourcePool* pool);
446  void destroyResourcePool(const String& name);
448  void destroyAllResourcePools();
449 
450 
451 
452 
453  protected:
454 
456  ResourceHandle getNextHandle(void);
457 
479  virtual Resource* createImpl(const String& name, ResourceHandle handle,
480  const String& group, bool isManual, ManualResourceLoader* loader,
481  const NameValuePairList* createParams) = 0;
483  virtual void addImpl( ResourcePtr& res );
485  virtual void removeImpl( ResourcePtr& res );
488  virtual void checkUsage(void);
489 
490 
491  public:
492  typedef HashMap< String, ResourcePtr > ResourceMap;
493  typedef HashMap< String, ResourceMap > ResourceWithGroupMap;
495  protected:
500  size_t mMemoryBudget; // In bytes
501  size_t mMemoryUsage; // In bytes
502 
503  bool mVerbose;
504 
505  // IMPORTANT - all subclasses must populate the fields below
506 
513 
514  public:
521  {
522  return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
523  }
524 
525  protected:
528 
529 
530 
531 
532  };
536 }
537 
538 #endif
virtual bool getVerbose(void)
Gets whether this manager and its resources habitually produce log output.
#define OGRE_AUTO_MUTEX
String mResourceType
String identifying the resource type this manager handles.
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:203
HashMap< String, ResourcePtr > ResourceMap
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:524
virtual const StringVector & getScriptPatterns(void) const
Gets the file patterns which should be used to find scripts for this ResourceManager.
StringVector mScriptPatterns
Patterns to use to look for scripts if supported (e.g. *.overlay)
const String & getResourceType(void) const
Gets a string identifying the type of resource this manager handles.
static String AUTODETECT_RESOURCE_GROUP_NAME
Special resource group name which causes resource group to be automatically determined based on searc...
ResourceMapIterator getResourceIterator(void)
Returns an iterator over all resources in this manager.
HashMap< String, ResourceMap > ResourceWithGroupMap
Interface describing a manual resource loader.
Definition: OgreResource.h:512
virtual Real getLoadingOrder(void) const
Gets the relative loading order of resources of this type.
virtual void parseScript(DataStreamPtr &stream, const String &groupName)
Parse the definition of a set of resources from a script file.
ResourceHandleMap mResourcesByHandle
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
map< ResourceHandle, ResourcePtr >::type ResourceHandleMap
Abstract class defining the interface used by classes which wish to perform script loading to define ...
Template class describing a simple pool of items.
Definition: OgreCommon.h:792
virtual void setVerbose(bool v)
Sets whether this manager and its resources habitually produce log output.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
std::pair< ResourcePtr, bool > ResourceCreateOrRetrieveResult
ResourcePoolMap mResourcePoolMap
vector< String >::type StringVector
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
Definition of a pool of resources, which users can use to reuse similar resources many times without ...
virtual bool resourceExists(ResourceHandle handle)
Returns whether a resource with the given handle exists in this manager.
ResourceWithGroupMap mResourcesWithGroup
virtual size_t getMemoryUsage(void) const
Gets the current memory usage, in bytes.
Real mLoadOrder
Loading order relative to other managers, higher is later.
Defines a generic resource handler.
_StringBase String
MapIterator< ResourceHandleMap > ResourceMapIterator
map< String, ResourcePool * >::type ResourcePoolMap
virtual bool resourceExists(const String &name)
Returns whether the named resource exists in this manager.