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, public ResourceAlloc 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 prepare(const String& name, 00326 const String& group, bool isManual = false, 00327 ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0); 00328 00342 virtual ResourcePtr load(const String& name, 00343 const String& group, bool isManual = false, 00344 ManualResourceLoader* loader = 0, const NameValuePairList* loadParams = 0); 00345 00361 virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; } 00362 00376 virtual void parseScript(DataStreamPtr& stream, const String& groupName) {} 00377 00384 virtual Real getLoadingOrder(void) const { return mLoadOrder; } 00385 00387 const String& getResourceType(void) const { return mResourceType; } 00388 00390 virtual void setVerbose(bool v) { mVerbose = v; } 00391 00393 virtual bool getVerbose(void) { return mVerbose; } 00394 00395 protected: 00396 00398 ResourceHandle getNextHandle(void); 00399 00421 virtual Resource* createImpl(const String& name, ResourceHandle handle, 00422 const String& group, bool isManual, ManualResourceLoader* loader, 00423 const NameValuePairList* createParams) = 0; 00425 virtual void addImpl( ResourcePtr& res ); 00427 virtual void removeImpl( ResourcePtr& res ); 00430 virtual void checkUsage(void); 00431 00432 00433 public: 00434 typedef HashMap< String, ResourcePtr > ResourceMap; 00435 typedef std::map<ResourceHandle, ResourcePtr> ResourceHandleMap; 00436 protected: 00437 ResourceHandleMap mResourcesByHandle; 00438 ResourceMap mResources; 00439 ResourceHandle mNextHandle; 00440 size_t mMemoryBudget; // In bytes 00441 size_t mMemoryUsage; // In bytes 00442 00443 bool mVerbose; 00444 00445 // IMPORTANT - all subclasses must populate the fields below 00446 00448 StringVector mScriptPatterns; 00450 Real mLoadOrder; 00452 String mResourceType; 00453 00454 public: 00455 typedef MapIterator<ResourceHandleMap> ResourceMapIterator; 00460 ResourceMapIterator getResourceIterator(void) 00461 { 00462 return ResourceMapIterator(mResourcesByHandle.begin(), mResourcesByHandle.end()); 00463 } 00464 00465 00466 00467 }; 00468 00469 } 00470 00471 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:25 2009