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 
00193         static void cleanupCommonArchive () ;
00194 
00195     protected:
00196 
00198         ResourceHandle getNextHandle(void);
00199 
00200         typedef HashMap< String, ArchiveEx * > FileMap;
00201         typedef HashMap< String, Resource* > ResourceMap;
00202 
00203 
00204         static FileMap mCommonArchiveFiles;
00205         FileMap mArchiveFiles;
00206 
00207     public:
00208         typedef std::map<ResourceHandle, Resource*> ResourceHandleMap;
00209     protected:
00210         ResourceHandleMap mResourcesByHandle;
00211         ResourceMap mResources;
00212 
00213         ResourceHandle mNextHandle;
00214 
00215         size_t mMemoryBudget; // In bytes
00216         size_t mMemoryUsage; // In bytes, at last checkUsage() call
00217 
00220         void checkUsage(void);
00221 
00223         static std::vector<ArchiveEx*> mCommonVFS;
00224 
00226         std::vector<ArchiveEx*> mVFS;
00227 
00228     public:
00229         typedef MapIterator<ResourceHandleMap> ResourceMapIterator;
00231         ResourceMapIterator getResourceIterator(void) 
00232         {
00233             return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end());
00234         }
00235     
00236 
00237     };
00238 
00239 }
00240 
00241 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:43 2004