Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# 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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _ResourceManager_H__
    00030 #define _ResourceManager_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreResource.h"
    00035 #include "OgreResourceGroupManager.h"
    00036 #include "OgreIteratorWrappers.h"
    00037 #include "OgreCommon.h"
    00038 #include "OgreDataStream.h"
    00039 #include "OgreStringVector.h"
    00040 #include "OgreScriptLoader.h"
    00041
    00042 namespace Ogre {
    00043
    00068     class _OgreExport ResourceManager : public ScriptLoader
    00069     {
    00070     public:
    00071         OGRE_AUTO_MUTEX // public to allow external locking
    00072         ResourceManager();
    00073         virtual ~ResourceManager();
    00074
    00094         virtual ResourcePtr create(const String& name, const String& group,
    00095             bool isManual = false, ManualResourceLoader* loader = 0,
    00096             const NameValuePairList* createParams = 0);
    00097
    00098         typedef std::pair<ResourcePtr, bool> ResourceCreateOrRetrieveResult;
    00112         virtual ResourceCreateOrRetrieveResult createOrRetrieve(const String& name,
    00113             const String& group, bool isManual = false,
    00114             ManualResourceLoader* loader = 0,
    00115             const NameValuePairList* createParams = 0);
    00116
    00124         virtual void setMemoryBudget( size_t bytes);
    00125
    00128         virtual size_t getMemoryBudget(void) const;
    00129
    00131         virtual size_t getMemoryUsage(void) const { return mMemoryUsage; }
    00132
    00139         virtual void unload(const String& name);
    00140
    00147         virtual void unload(ResourceHandle handle);
    00148
    00161         virtual void unloadAll(bool reloadableOnly = true);
    00162
    00174         virtual void reloadAll(bool reloadableOnly = true);
    00175
    00190         virtual void unloadUnreferencedResources(bool reloadableOnly = true);
    00191
    00205         virtual void reloadUnreferencedResources(bool reloadableOnly = true);
    00206
    00224         virtual void remove(ResourcePtr& r);
    00225
    00243         virtual void remove(const String& name);
    00244
    00262         virtual void remove(ResourceHandle handle);
    00277         virtual void removeAll(void);
    00278
    00281         virtual ResourcePtr getByName(const String& name);
    00284         virtual ResourcePtr getByHandle(ResourceHandle handle);
    00285
    00287         virtual bool resourceExists(const String& name)
    00288         {
    00289             return !getByName(name).isNull();
    00290         }
    00292         virtual bool resourceExists(ResourceHandle handle)
    00293         {
    00294             return !getByHandle(handle).isNull();
    00295         }
    00296
    00300         virtual void _notifyResourceTouched(Resource* res);
    00301
    00305         virtual void _notifyResourceLoaded(Resource* res);
    00306
    00310         virtual void _notifyResourceUnloaded(Resource* res);
    00311
    00325         virtual ResourcePtr load(const String& name,
    00326             const String& group, bool isManual = false,
    00327             ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0);
    00328
    00344         virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; }
    00345
    00359         virtual void parseScript(DataStreamPtr& stream, const String& groupName) {}
    00360
    00367         virtual Real getLoadingOrder(void) const { return mLoadOrder; }
    00368
    00370         const String& getResourceType(void) const { return mResourceType; }
    00371
    00372     protected:
    00373
    00375         ResourceHandle getNextHandle(void);
    00376
    00398         virtual Resource* createImpl(const String& name, ResourceHandle handle,
    00399             const String& group, bool isManual, ManualResourceLoader* loader,
    00400             const NameValuePairList* createParams) = 0;
    00402         virtual void addImpl( ResourcePtr& res );
    00404         virtual void removeImpl( ResourcePtr& res );
    00407         virtual void checkUsage(void);
    00408
    00409
    00410     public:
    00411         typedef HashMap< String, ResourcePtr > ResourceMap;
    00412         typedef std::map<ResourceHandle, ResourcePtr> ResourceHandleMap;
    00413     protected:
    00414         ResourceHandleMap mResourcesByHandle;
    00415         ResourceMap mResources;
    00416         ResourceHandle mNextHandle;
    00417         size_t mMemoryBudget; // In bytes
    00418         size_t mMemoryUsage; // In bytes
    00419
    00420         // IMPORTANT - all subclasses must populate the fields below
    00421
    00423         StringVector mScriptPatterns;
    00425         Real mLoadOrder;
    00427         String mResourceType;
    00428
    00429     public:
    00430         typedef MapIterator<ResourceHandleMap> ResourceMapIterator;
    00435         ResourceMapIterator getResourceIterator(void)
    00436         {
    00437             return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
    00438         }
    00439
    00440
    00441
    00442     };
    00443
    00444 }
    00445
    00446 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Mar 6 09:46:26 2008