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: 00169 virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0; 00170 00176 virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0; 00177 00180 virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0; 00181 }; 00182 00231 class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc 00232 { 00233 public: 00234 OGRE_AUTO_MUTEX // public to allow external locking 00236 static String DEFAULT_RESOURCE_GROUP_NAME; 00238 static String INTERNAL_RESOURCE_GROUP_NAME; 00240 static String BOOTSTRAP_RESOURCE_GROUP_NAME; 00242 static String AUTODETECT_RESOURCE_GROUP_NAME; 00244 static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS; 00246 struct ResourceDeclaration 00247 { 00248 String resourceName; 00249 String resourceType; 00250 ManualResourceLoader* loader; 00251 NameValuePairList parameters; 00252 }; 00254 typedef std::list<ResourceDeclaration> ResourceDeclarationList; 00255 typedef std::map<String, ResourceManager*> ResourceManagerMap; 00256 typedef MapIterator<ResourceManagerMap> ResourceManagerIterator; 00257 protected: 00259 ResourceManagerMap mResourceManagerMap; 00260 00262 typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap; 00263 ScriptLoaderOrderMap mScriptLoaderOrderMap; 00264 00265 typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList; 00266 ResourceGroupListenerList mResourceGroupListenerList; 00267 00268 ResourceLoadingListener *mLoadingListener; 00269 00271 typedef std::map<String, Archive*> ResourceLocationIndex; 00272 00274 struct ResourceLocation 00275 { 00277 Archive* archive; 00279 bool recursive; 00280 }; 00282 typedef std::list<ResourceLocation*> LocationList; 00284 typedef std::list<ResourcePtr> LoadUnloadResourceList; 00286 struct ResourceGroup 00287 { 00288 enum Status 00289 { 00290 UNINITIALSED = 0, 00291 INITIALISING = 1, 00292 INITIALISED = 2, 00293 LOADING = 3, 00294 LOADED = 4 00295 }; 00297 OGRE_AUTO_MUTEX 00299 OGRE_MUTEX(statusMutex) 00301 String name; 00303 Status groupStatus; 00305 LocationList locationList; 00307 ResourceLocationIndex resourceIndexCaseSensitive; 00309 ResourceLocationIndex resourceIndexCaseInsensitive; 00311 ResourceDeclarationList resourceDeclarations; 00313 // Group by loading order of the type (defined by ResourceManager) 00314 // (e.g. skeletons and materials before meshes) 00315 typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap; 00316 LoadResourceOrderMap loadResourceOrderMap; 00318 String worldGeometry; 00320 SceneManager* worldGeometrySceneManager; 00321 }; 00323 typedef std::map<String, ResourceGroup*> ResourceGroupMap; 00324 ResourceGroupMap mResourceGroupMap; 00325 00327 String mWorldGroupName; 00328 00334 void parseResourceGroupScripts(ResourceGroup* grp); 00339 void createDeclaredResources(ResourceGroup* grp); 00341 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); 00343 ResourceGroup* getResourceGroup(const String& name); 00345 void dropGroupContents(ResourceGroup* grp); 00347 void deleteGroup(ResourceGroup* grp); 00349 ResourceGroup* findGroupContainingResourceImpl(const String& filename); 00351 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); 00353 void fireScriptStarted(const String& scriptName, bool &skipScript); 00355 void fireScriptEnded(const String& scriptName, bool skipped); 00357 void fireResourceGroupScriptingEnded(const String& groupName); 00359 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); 00361 void fireResourceLoadStarted(const ResourcePtr& resource); 00363 void fireResourceLoadEnded(void); 00365 void fireResourceGroupLoadEnded(const String& groupName); 00367 void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount); 00369 void fireResourcePrepareStarted(const ResourcePtr& resource); 00371 void fireResourcePrepareEnded(void); 00373 void fireResourceGroupPrepareEnded(const String& groupName); 00374 00376 ResourceGroup* mCurrentGroup; 00377 public: 00378 ResourceGroupManager(); 00379 virtual ~ResourceGroupManager(); 00380 00416 void createResourceGroup(const String& name); 00417 00418 00458 void initialiseResourceGroup(const String& name); 00459 00463 void initialiseAllResourceGroups(void); 00464 00482 void prepareResourceGroup(const String& name, bool prepareMainResources = true, 00483 bool prepareWorldGeom = true); 00484 00502 void loadResourceGroup(const String& name, bool loadMainResources = true, 00503 bool loadWorldGeom = true); 00504 00520 void unloadResourceGroup(const String& name, bool reloadableOnly = true); 00521 00533 void unloadUnreferencedResourcesInGroup(const String& name, 00534 bool reloadableOnly = true); 00535 00545 void clearResourceGroup(const String& name); 00546 00552 void destroyResourceGroup(const String& name); 00553 00561 bool isResourceGroupInitialised(const String& name); 00562 00570 bool isResourceGroupLoaded(const String& name); 00571 00593 void addResourceLocation(const String& name, const String& locType, 00594 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false); 00596 void removeResourceLocation(const String& name, 00597 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00598 00633 void declareResource(const String& name, const String& resourceType, 00634 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00635 const NameValuePairList& loadParameters = NameValuePairList()); 00675 void declareResource(const String& name, const String& resourceType, 00676 const String& groupName, ManualResourceLoader* loader, 00677 const NameValuePairList& loadParameters = NameValuePairList()); 00688 void undeclareResource(const String& name, const String& groupName); 00689 00709 DataStreamPtr openResource(const String& resourceName, 00710 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00711 bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0); 00712 00724 DataStreamListPtr openResources(const String& pattern, 00725 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00726 00735 StringVectorPtr listResourceNames(const String& groupName, bool dirs = false); 00736 00743 FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false); 00744 00756 StringVectorPtr findResourceNames(const String& groupName, const String& pattern, 00757 bool dirs = false); 00758 00763 bool resourceExists(const String& group, const String& filename); 00764 00769 bool resourceExists(ResourceGroup* group, const String& filename); 00776 const String& findGroupContainingResource(const String& filename); 00777 00787 FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern, 00788 bool dirs = false); 00789 00791 time_t resourceModifiedTime(const String& group, const String& filename); 00792 00794 time_t resourceModifiedTime(ResourceGroup* group, const String& filename); 00795 00799 void addResourceGroupListener(ResourceGroupListener* l); 00801 void removeResourceGroupListener(ResourceGroupListener* l); 00802 00809 void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} 00810 00812 const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } 00813 00827 void linkWorldGeometryToResourceGroup(const String& group, 00828 const String& worldGeometry, SceneManager* sceneManager); 00829 00834 void unlinkWorldGeometryFromResourceGroup(const String& group); 00835 00837 void shutdownAll(void); 00838 00839 00849 void _registerResourceManager(const String& resourceType, ResourceManager* rm); 00850 00857 void _unregisterResourceManager(const String& resourceType); 00858 00861 ResourceManagerIterator getResourceManagerIterator() 00862 { return ResourceManagerIterator( 00863 mResourceManagerMap.begin(), mResourceManagerMap.end()); } 00864 00869 void _registerScriptLoader(ScriptLoader* su); 00870 00874 void _unregisterScriptLoader(ScriptLoader* su); 00875 00879 ResourceManager* _getResourceManager(const String& resourceType); 00880 00884 void _notifyResourceCreated(ResourcePtr& res); 00885 00889 void _notifyResourceRemoved(ResourcePtr& res); 00890 00893 void _notifyResourceGroupChanged(const String& oldGroup, Resource* res); 00894 00899 void _notifyAllResourcesRemoved(ResourceManager* manager); 00900 00908 void _notifyWorldGeometryPrepareStageStarted(const String& description); 00916 void _notifyWorldGeometryPrepareStageEnded(void); 00917 00925 void _notifyWorldGeometryStageStarted(const String& description); 00933 void _notifyWorldGeometryStageEnded(void); 00934 00940 StringVector getResourceGroups(void); 00947 ResourceDeclarationList getResourceDeclarationList(const String& groupName); 00948 00950 void setLoadingListener(ResourceLoadingListener *listener); 00952 ResourceLoadingListener *getLoadingListener(); 00953 00969 static ResourceGroupManager& getSingleton(void); 00985 static ResourceGroupManager* getSingletonPtr(void); 00986 00987 }; 00988 } 00989 00990 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Aug 28 20:53:51 2008