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 _ResourceGroupManager_H__ 00030 #define _ResourceGroupManager_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreSingleton.h" 00034 #include "OgreCommon.h" 00035 #include "OgreDataStream.h" 00036 #include "OgreResource.h" 00037 #include "OgreArchive.h" 00038 #include "OgreIteratorWrappers.h" 00039 #include <ctime> 00040 00041 namespace Ogre { 00042 00073 class _OgreExport ResourceGroupListener 00074 { 00075 public: 00076 virtual ~ResourceGroupListener() {} 00077 00087 virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0; 00095 virtual void scriptParseStarted(const String& scriptName, bool& skipThisScript) = 0; 00096 00099 virtual void scriptParseEnded(const String& scriptName, bool skipped) = 0; 00101 virtual void resourceGroupScriptingEnded(const String& groupName) = 0; 00102 00108 virtual void resourceGroupPrepareStarted(const String& groupName, size_t resourceCount) {} 00112 virtual void resourcePrepareStarted(const ResourcePtr& resource) {} 00115 virtual void resourcePrepareEnded(void) {} 00121 virtual void worldGeometryPrepareStageStarted(const String& description) {} 00127 virtual void worldGeometryPrepareStageEnded(void) {} 00129 virtual void resourceGroupPrepareEnded(const String& groupName) {} 00130 00136 virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0; 00140 virtual void resourceLoadStarted(const ResourcePtr& resource) = 0; 00143 virtual void resourceLoadEnded(void) = 0; 00149 virtual void worldGeometryStageStarted(const String& description) = 0; 00155 virtual void worldGeometryStageEnded(void) = 0; 00157 virtual void resourceGroupLoadEnded(const String& groupName) = 0; 00158 }; 00159 00165 class ResourceLoadingListener 00166 { 00167 public: 00168 virtual ~ResourceLoadingListener() {} 00169 00171 virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0; 00172 00178 virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0; 00179 00182 virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0; 00183 }; 00184 00233 class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc 00234 { 00235 public: 00236 OGRE_AUTO_MUTEX // public to allow external locking 00238 static String DEFAULT_RESOURCE_GROUP_NAME; 00240 static String INTERNAL_RESOURCE_GROUP_NAME; 00242 static String BOOTSTRAP_RESOURCE_GROUP_NAME; 00244 static String AUTODETECT_RESOURCE_GROUP_NAME; 00246 static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS; 00248 struct ResourceDeclaration 00249 { 00250 String resourceName; 00251 String resourceType; 00252 ManualResourceLoader* loader; 00253 NameValuePairList parameters; 00254 }; 00256 typedef std::list<ResourceDeclaration> ResourceDeclarationList; 00257 typedef std::map<String, ResourceManager*> ResourceManagerMap; 00258 typedef MapIterator<ResourceManagerMap> ResourceManagerIterator; 00259 protected: 00261 ResourceManagerMap mResourceManagerMap; 00262 00264 typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap; 00265 ScriptLoaderOrderMap mScriptLoaderOrderMap; 00266 00267 typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList; 00268 ResourceGroupListenerList mResourceGroupListenerList; 00269 00270 ResourceLoadingListener *mLoadingListener; 00271 00273 typedef std::map<String, Archive*> ResourceLocationIndex; 00274 00276 struct ResourceLocation 00277 { 00279 Archive* archive; 00281 bool recursive; 00282 }; 00284 typedef std::list<ResourceLocation*> LocationList; 00286 typedef std::list<ResourcePtr> LoadUnloadResourceList; 00288 struct ResourceGroup 00289 { 00290 enum Status 00291 { 00292 UNINITIALSED = 0, 00293 INITIALISING = 1, 00294 INITIALISED = 2, 00295 LOADING = 3, 00296 LOADED = 4 00297 }; 00299 OGRE_AUTO_MUTEX 00301 OGRE_MUTEX(statusMutex) 00303 String name; 00305 Status groupStatus; 00307 LocationList locationList; 00309 ResourceLocationIndex resourceIndexCaseSensitive; 00311 ResourceLocationIndex resourceIndexCaseInsensitive; 00313 ResourceDeclarationList resourceDeclarations; 00315 // Group by loading order of the type (defined by ResourceManager) 00316 // (e.g. skeletons and materials before meshes) 00317 typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap; 00318 LoadResourceOrderMap loadResourceOrderMap; 00320 String worldGeometry; 00322 SceneManager* worldGeometrySceneManager; 00323 }; 00325 typedef std::map<String, ResourceGroup*> ResourceGroupMap; 00326 ResourceGroupMap mResourceGroupMap; 00327 00329 String mWorldGroupName; 00330 00336 void parseResourceGroupScripts(ResourceGroup* grp); 00341 void createDeclaredResources(ResourceGroup* grp); 00343 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); 00345 ResourceGroup* getResourceGroup(const String& name); 00347 void dropGroupContents(ResourceGroup* grp); 00349 void deleteGroup(ResourceGroup* grp); 00351 ResourceGroup* findGroupContainingResourceImpl(const String& filename); 00353 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); 00355 void fireScriptStarted(const String& scriptName, bool &skipScript); 00357 void fireScriptEnded(const String& scriptName, bool skipped); 00359 void fireResourceGroupScriptingEnded(const String& groupName); 00361 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); 00363 void fireResourceLoadStarted(const ResourcePtr& resource); 00365 void fireResourceLoadEnded(void); 00367 void fireResourceGroupLoadEnded(const String& groupName); 00369 void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount); 00371 void fireResourcePrepareStarted(const ResourcePtr& resource); 00373 void fireResourcePrepareEnded(void); 00375 void fireResourceGroupPrepareEnded(const String& groupName); 00376 00378 ResourceGroup* mCurrentGroup; 00379 public: 00380 ResourceGroupManager(); 00381 virtual ~ResourceGroupManager(); 00382 00418 void createResourceGroup(const String& name); 00419 00420 00460 void initialiseResourceGroup(const String& name); 00461 00465 void initialiseAllResourceGroups(void); 00466 00484 void prepareResourceGroup(const String& name, bool prepareMainResources = true, 00485 bool prepareWorldGeom = true); 00486 00504 void loadResourceGroup(const String& name, bool loadMainResources = true, 00505 bool loadWorldGeom = true); 00506 00522 void unloadResourceGroup(const String& name, bool reloadableOnly = true); 00523 00535 void unloadUnreferencedResourcesInGroup(const String& name, 00536 bool reloadableOnly = true); 00537 00547 void clearResourceGroup(const String& name); 00548 00554 void destroyResourceGroup(const String& name); 00555 00563 bool isResourceGroupInitialised(const String& name); 00564 00572 bool isResourceGroupLoaded(const String& name); 00573 00595 void addResourceLocation(const String& name, const String& locType, 00596 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false); 00598 void removeResourceLocation(const String& name, 00599 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00600 00635 void declareResource(const String& name, const String& resourceType, 00636 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00637 const NameValuePairList& loadParameters = NameValuePairList()); 00677 void declareResource(const String& name, const String& resourceType, 00678 const String& groupName, ManualResourceLoader* loader, 00679 const NameValuePairList& loadParameters = NameValuePairList()); 00690 void undeclareResource(const String& name, const String& groupName); 00691 00711 DataStreamPtr openResource(const String& resourceName, 00712 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00713 bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0); 00714 00726 DataStreamListPtr openResources(const String& pattern, 00727 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00728 00737 StringVectorPtr listResourceNames(const String& groupName, bool dirs = false); 00738 00745 FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false); 00746 00758 StringVectorPtr findResourceNames(const String& groupName, const String& pattern, 00759 bool dirs = false); 00760 00765 bool resourceExists(const String& group, const String& filename); 00766 00771 bool resourceExists(ResourceGroup* group, const String& filename); 00778 const String& findGroupContainingResource(const String& filename); 00779 00789 FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern, 00790 bool dirs = false); 00791 00793 time_t resourceModifiedTime(const String& group, const String& filename); 00794 00796 time_t resourceModifiedTime(ResourceGroup* group, const String& filename); 00797 00801 void addResourceGroupListener(ResourceGroupListener* l); 00803 void removeResourceGroupListener(ResourceGroupListener* l); 00804 00811 void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} 00812 00814 const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } 00815 00829 void linkWorldGeometryToResourceGroup(const String& group, 00830 const String& worldGeometry, SceneManager* sceneManager); 00831 00836 void unlinkWorldGeometryFromResourceGroup(const String& group); 00837 00839 void shutdownAll(void); 00840 00841 00851 void _registerResourceManager(const String& resourceType, ResourceManager* rm); 00852 00859 void _unregisterResourceManager(const String& resourceType); 00860 00863 ResourceManagerIterator getResourceManagerIterator() 00864 { return ResourceManagerIterator( 00865 mResourceManagerMap.begin(), mResourceManagerMap.end()); } 00866 00871 void _registerScriptLoader(ScriptLoader* su); 00872 00876 void _unregisterScriptLoader(ScriptLoader* su); 00877 00881 ResourceManager* _getResourceManager(const String& resourceType); 00882 00886 void _notifyResourceCreated(ResourcePtr& res); 00887 00891 void _notifyResourceRemoved(ResourcePtr& res); 00892 00895 void _notifyResourceGroupChanged(const String& oldGroup, Resource* res); 00896 00901 void _notifyAllResourcesRemoved(ResourceManager* manager); 00902 00910 void _notifyWorldGeometryPrepareStageStarted(const String& description); 00918 void _notifyWorldGeometryPrepareStageEnded(void); 00919 00927 void _notifyWorldGeometryStageStarted(const String& description); 00935 void _notifyWorldGeometryStageEnded(void); 00936 00942 StringVector getResourceGroups(void); 00949 ResourceDeclarationList getResourceDeclarationList(const String& groupName); 00950 00952 void setLoadingListener(ResourceLoadingListener *listener); 00954 ResourceLoadingListener *getLoadingListener(); 00955 00971 static ResourceGroupManager& getSingleton(void); 00987 static ResourceGroupManager* getSingletonPtr(void); 00988 00989 }; 00990 } 00991 00992 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Jan 22 21:26:12 2009