# OgreResourceManager.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef _ResourceManager_H__
    00029 #define _ResourceManager_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032
    00033 #include "OgreResource.h"
    00034 #include "OgreResourceGroupManager.h"
    00035 #include "OgreIteratorWrappers.h"
    00036 #include "OgreCommon.h"
    00037 #include "OgreDataStream.h"
    00038 #include "OgreStringVector.h"
    00039 #include "OgreScriptLoader.h"
    00040
    00041 namespace Ogre {
    00042
    00073     class _OgreExport ResourceManager : public ScriptLoader, public ResourceAlloc
    00074     {
    00075     public:
    00076         OGRE_AUTO_MUTEX // public to allow external locking
    00077         ResourceManager();
    00078         virtual ~ResourceManager();
    00079
    00099         virtual ResourcePtr create(const String& name, const String& group,
    00100             bool isManual = false, ManualResourceLoader* loader = 0,
    00101             const NameValuePairList* createParams = 0);
    00102
    00103         typedef std::pair<ResourcePtr, bool> ResourceCreateOrRetrieveResult;
    00117         virtual ResourceCreateOrRetrieveResult createOrRetrieve(const String& name,
    00118             const String& group, bool isManual = false,
    00119             ManualResourceLoader* loader = 0,
    00120             const NameValuePairList* createParams = 0);
    00121
    00129         virtual void setMemoryBudget( size_t bytes);
    00130
    00133         virtual size_t getMemoryBudget(void) const;
    00134
    00136         virtual size_t getMemoryUsage(void) const { return mMemoryUsage; }
    00137
    00144         virtual void unload(const String& name);
    00145
    00152         virtual void unload(ResourceHandle handle);
    00153
    00166         virtual void unloadAll(bool reloadableOnly = true);
    00167
    00179         virtual void reloadAll(bool reloadableOnly = true);
    00180
    00195         virtual void unloadUnreferencedResources(bool reloadableOnly = true);
    00196
    00210         virtual void reloadUnreferencedResources(bool reloadableOnly = true);
    00211
    00229         virtual void remove(ResourcePtr& r);
    00230
    00248         virtual void remove(const String& name);
    00249
    00267         virtual void remove(ResourceHandle handle);
    00282         virtual void removeAll(void);
    00283
    00298         virtual void removeUnreferencedResources(bool reloadableOnly = true);
    00299
    00302         virtual ResourcePtr getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
    00305         virtual ResourcePtr getByHandle(ResourceHandle handle);
    00306
    00308         virtual bool resourceExists(const String& name)
    00309         {
    00310             return !getByName(name).isNull();
    00311         }
    00313         virtual bool resourceExists(ResourceHandle handle)
    00314         {
    00315             return !getByHandle(handle).isNull();
    00316         }
    00317
    00321         virtual void _notifyResourceTouched(Resource* res);
    00322
    00326         virtual void _notifyResourceLoaded(Resource* res);
    00327
    00331         virtual void _notifyResourceUnloaded(Resource* res);
    00332
    00348         virtual ResourcePtr prepare(const String& name,
    00349             const String& group, bool isManual = false,
    00350             ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0,
    00351             bool backgroundThread = false);
    00352
    00368         virtual ResourcePtr load(const String& name,
    00369             const String& group, bool isManual = false,
    00370             ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0,
    00371             bool backgroundThread = false);
    00372
    00388         virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; }
    00389
    00403         virtual void parseScript(DataStreamPtr& stream, const String& groupName)
    00404                 { (void)stream; (void)groupName; }
    00405
    00412         virtual Real getLoadingOrder(void) const { return mLoadOrder; }
    00413
    00415         const String& getResourceType(void) const { return mResourceType; }
    00416
    00418         virtual void setVerbose(bool v) { mVerbose = v; }
    00419
    00421         virtual bool getVerbose(void) { return mVerbose; }
    00422
    00429         class _OgreExport ResourcePool : public Pool<ResourcePtr>, public ResourceAlloc
    00430         {
    00431         protected:
    00432             String mName;
    00433         public:
    00434             ResourcePool(const String& name);
    00435             ~ResourcePool();
    00437             const String& getName() const;
    00438             void clear();
    00439         };
    00440
    00442         ResourcePool* getResourcePool(const String& name);
    00444         void destroyResourcePool(ResourcePool* pool);
    00446         void destroyResourcePool(const String& name);
    00448         void destroyAllResourcePools();
    00449
    00450
    00451
    00452
    00453     protected:
    00454
    00456         ResourceHandle getNextHandle(void);
    00457
    00479         virtual Resource* createImpl(const String& name, ResourceHandle handle,
    00480             const String& group, bool isManual, ManualResourceLoader* loader,
    00481             const NameValuePairList* createParams) = 0;
    00483         virtual void addImpl( ResourcePtr& res );
    00485         virtual void removeImpl( ResourcePtr& res );
    00488         virtual void checkUsage(void);
    00489
    00490
    00491     public:
    00492         typedef HashMap< String, ResourcePtr > ResourceMap;
    00493         typedef HashMap< String, ResourceMap > ResourceWithGroupMap;
    00494         typedef map<ResourceHandle, ResourcePtr>::type ResourceHandleMap;
    00495     protected:
    00496         ResourceHandleMap mResourcesByHandle;
    00497         ResourceMap mResources;
    00498         ResourceWithGroupMap mResourcesWithGroup;
    00499         ResourceHandle mNextHandle;
    00500         size_t mMemoryBudget; // In bytes
    00501         size_t mMemoryUsage; // In bytes
    00502
    00503         bool mVerbose;
    00504
    00505         // IMPORTANT - all subclasses must populate the fields below
    00506
    00508         StringVector mScriptPatterns;
    00510         Real mLoadOrder;
    00512         String mResourceType;
    00513
    00514     public:
    00515         typedef MapIterator<ResourceHandleMap> ResourceMapIterator;
    00520         ResourceMapIterator getResourceIterator(void)
    00521         {
    00522             return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
    00523         }
    00524
    00525     protected:
    00526         typedef map<String, ResourcePool*>::type ResourcePoolMap;
    00527         ResourcePoolMap mResourcePoolMap;
    00528
    00529
    00530
    00531
    00532     };
    00536 }
    00537
    00538 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52