# 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-2005 The OGRE Team
    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 */
    00025 #ifndef _ResourceManager_H__
    00026 #define _ResourceManager_H__
    00027
    00028 #include "OgrePrerequisites.h"
    00029
    00030 #include "OgreResource.h"
    00031 #include "OgreResourceGroupManager.h"
    00032 #include "OgreIteratorWrappers.h"
    00033 #include "OgreCommon.h"
    00034 #include "OgreDataStream.h"
    00035 #include "OgreStringVector.h"
    00036 #include "OgreScriptLoader.h"
    00037
    00038 namespace Ogre {
    00039
    00064     class _OgreExport ResourceManager : public ScriptLoader
    00065     {
    00066     public:
    00067         OGRE_AUTO_MUTEX // public to allow external locking
    00068         ResourceManager();
    00069         virtual ~ResourceManager();
    00070
    00090         virtual ResourcePtr create(const String& name, const String& group,
    00091             bool isManual = false, ManualResourceLoader* loader = 0,
    00092             const NameValuePairList* createParams = 0);
    00100         virtual void setMemoryBudget( size_t bytes);
    00101
    00104         virtual size_t getMemoryBudget(void) const;
    00105
    00112         virtual void unload(const String& name);
    00113
    00120         virtual void unload(ResourceHandle handle);
    00121
    00128         virtual void unloadAll(void);
    00134         virtual void reloadAll(void);
    00135
    00153         virtual void remove(ResourcePtr& r);
    00154
    00172         virtual void remove(const String& name);
    00173
    00191         virtual void remove(ResourceHandle handle);
    00206         virtual void removeAll(void);
    00207
    00210         virtual ResourcePtr getByName(const String& name);
    00213         virtual ResourcePtr getByHandle(ResourceHandle handle);
    00214
    00216         virtual bool resourceExists(const String& name)
    00217         {
    00218             return !getByName(name).isNull();
    00219         }
    00221         virtual bool resourceExists(ResourceHandle handle)
    00222         {
    00223             return !getByHandle(handle).isNull();
    00224         }
    00225
    00229         virtual void _notifyResourceTouched(Resource* res);
    00230
    00234         virtual void _notifyResourceLoaded(Resource* res);
    00235
    00239         virtual void _notifyResourceUnloaded(Resource* res);
    00240
    00254         virtual ResourcePtr load(const String& name,
    00255             const String& group, bool isManual = false,
    00256             ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0);
    00257
    00273         virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; }
    00274
    00288         virtual void parseScript(DataStreamPtr& stream, const String& groupName) {}
    00289
    00296         virtual Real getLoadingOrder(void) const { return mLoadOrder; }
    00297
    00299         const String& getResourceType(void) const { return mResourceType; }
    00300
    00301     protected:
    00302
    00304         ResourceHandle getNextHandle(void);
    00305
    00327         virtual Resource* createImpl(const String& name, ResourceHandle handle,
    00328             const String& group, bool isManual, ManualResourceLoader* loader,
    00329             const NameValuePairList* createParams) = 0;
    00331         virtual void addImpl( ResourcePtr& res );
    00333         virtual void removeImpl( ResourcePtr& res );
    00336         virtual void checkUsage(void);
    00338         virtual size_t getMemoryUsage(void) const { return mMemoryUsage; }
    00339
    00340
    00341     public:
    00342         typedef HashMap< String, ResourcePtr > ResourceMap;
    00343         typedef std::map<ResourceHandle, ResourcePtr> ResourceHandleMap;
    00344     protected:
    00345         ResourceHandleMap mResourcesByHandle;
    00346         ResourceMap mResources;
    00347         ResourceHandle mNextHandle;
    00348         size_t mMemoryBudget; // In bytes
    00349         size_t mMemoryUsage; // In bytes
    00350
    00351         // IMPORTANT - all subclasses must populate the fields below
    00352
    00354         StringVector mScriptPatterns;
    00356         Real mLoadOrder;
    00358         String mResourceType;
    00359
    00360     public:
    00361         typedef MapIterator<ResourceHandleMap> ResourceMapIterator;
    00366         ResourceMapIterator getResourceIterator(void)
    00367         {
    00368             return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
    00369         }
    00370
    00371
    00372
    00373     };
    00374
    00375 }
    00376
    00377 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:51 2006