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 00134 virtual void unloadAll(bool reloadableOnly = true); 00135 00147 virtual void reloadAll(bool reloadableOnly = true); 00148 00163 virtual void unloadUnreferencedResources(bool reloadableOnly = true); 00164 00178 virtual void reloadUnreferencedResources(bool reloadableOnly = true); 00179 00197 virtual void remove(ResourcePtr& r); 00198 00216 virtual void remove(const String& name); 00217 00235 virtual void remove(ResourceHandle handle); 00250 virtual void removeAll(void); 00251 00254 virtual ResourcePtr getByName(const String& name); 00257 virtual ResourcePtr getByHandle(ResourceHandle handle); 00258 00260 virtual bool resourceExists(const String& name) 00261 { 00262 return !getByName(name).isNull(); 00263 } 00265 virtual bool resourceExists(ResourceHandle handle) 00266 { 00267 return !getByHandle(handle).isNull(); 00268 } 00269 00273 virtual void _notifyResourceTouched(Resource* res); 00274 00278 virtual void _notifyResourceLoaded(Resource* res); 00279 00283 virtual void _notifyResourceUnloaded(Resource* res); 00284 00298 virtual ResourcePtr load(const String& name, 00299 const String& group, bool isManual = false, 00300 ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0); 00301 00317 virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; } 00318 00332 virtual void parseScript(DataStreamPtr& stream, const String& groupName) {} 00333 00340 virtual Real getLoadingOrder(void) const { return mLoadOrder; } 00341 00343 const String& getResourceType(void) const { return mResourceType; } 00344 00345 protected: 00346 00348 ResourceHandle getNextHandle(void); 00349 00371 virtual Resource* createImpl(const String& name, ResourceHandle handle, 00372 const String& group, bool isManual, ManualResourceLoader* loader, 00373 const NameValuePairList* createParams) = 0; 00375 virtual void addImpl( ResourcePtr& res ); 00377 virtual void removeImpl( ResourcePtr& res ); 00380 virtual void checkUsage(void); 00382 virtual size_t getMemoryUsage(void) const { return mMemoryUsage; } 00383 00384 00385 public: 00386 typedef HashMap< String, ResourcePtr > ResourceMap; 00387 typedef std::map<ResourceHandle, ResourcePtr> ResourceHandleMap; 00388 protected: 00389 ResourceHandleMap mResourcesByHandle; 00390 ResourceMap mResources; 00391 ResourceHandle mNextHandle; 00392 size_t mMemoryBudget; // In bytes 00393 size_t mMemoryUsage; // In bytes 00394 00395 // IMPORTANT - all subclasses must populate the fields below 00396 00398 StringVector mScriptPatterns; 00400 Real mLoadOrder; 00402 String mResourceType; 00403 00404 public: 00405 typedef MapIterator<ResourceHandleMap> ResourceMapIterator; 00410 ResourceMapIterator getResourceIterator(void) 00411 { 00412 return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end()); 00413 } 00414 00415 00416 00417 }; 00418 00419 } 00420 00421 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:48 2006