Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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 © 2000-2002 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 "OgreDataChunk.h"
00032 #include "OgreArchiveEx.h"
00033 #include "OgreIteratorWrappers.h"
00034 
00035 
00036 namespace Ogre {
00037 
00050     class _OgreExport ResourceManager
00051     {
00052     public:
00053         ResourceManager();
00054         virtual ~ResourceManager();
00055 
00063         virtual void setMemoryBudget( size_t bytes);
00064 
00073         virtual Resource* create( const String& name ) = 0;
00074 
00077         virtual void load( Resource *res, int priority );
00078 
00081         virtual void add( Resource *res );
00091         virtual void unload( Resource *res );
00092 
00098         virtual void unloadAndDestroyAll(void);
00099 
00102         virtual Resource* getByName(const String& name);
00105         virtual Resource* getByHandle(ResourceHandle handle);
00106 
00113         void addSearchPath( const String& path );
00114 
00122         static void addCommonSearchPath( const String& path );
00123 
00132         void addArchiveEx( const String& strName, const String& strDriverName );
00133 
00139         static void addCommonArchiveEx( const String& strName, const String& strDriverName );
00140 
00151         bool _findResourceData( const String& filename, DataChunk& refChunk );
00152 
00163         static std::set<String> _getAllCommonNamesLike( const String& startPath, const String& extension );
00164 
00173         std::set<String> _getAllNamesLike( const String& startPath, const String& extension );
00174 
00188         static bool _findCommonResourceData( const String& filename, DataChunk& refChunk );
00189 
00190     protected:
00191 
00193         ResourceHandle getNextHandle(void);
00194 
00195         typedef HashMap< String, ArchiveEx *, _StringHash > FileMap;
00196         typedef HashMap< String, Resource*, _StringHash > ResourceMap;
00197 
00198 
00199         static FileMap mCommonArchiveFiles;
00200         FileMap mArchiveFiles;
00201 
00202     public:
00203         typedef std::map<ResourceHandle, Resource*> ResourceHandleMap;
00204     protected:
00205         ResourceHandleMap mResourcesByHandle;
00206         ResourceMap mResources;
00207 
00208         ResourceHandle mNextHandle;
00209 
00210         size_t mMemoryBudget; // In bytes
00211         size_t mMemoryUsage; // In bytes, at last checkUsage() call
00212 
00215         void checkUsage(void);
00216 
00218         static std::vector<ArchiveEx*> mCommonVFS;
00219 
00221         std::vector<ArchiveEx*> mVFS;
00222 
00223     public:
00224         typedef MapIterator<ResourceHandleMap> ResourceMapIterator;
00226         ResourceMapIterator getResourceIterator(void) 
00227         {
00228             return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
00229         }
00230     
00231 
00232     };
00233 
00234 }
00235 
00236 #endif

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