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-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef _ResourceGroupManager_H__ 00029 #define _ResourceGroupManager_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreSingleton.h" 00033 #include "OgreCommon.h" 00034 #include "OgreDataStream.h" 00035 #include "OgreResource.h" 00036 #include "OgreArchive.h" 00037 #include "OgreIteratorWrappers.h" 00038 #include <ctime> 00039 #include "OgreHeaderPrefix.h" 00040 00041 // If X11/Xlib.h gets included before this header (for example it happens when 00042 // including wxWidgets and FLTK), Status is defined as an int which we don't 00043 // want as we have an enum named Status. 00044 #ifdef Status 00045 #undef Status 00046 #endif 00047 00048 namespace Ogre { 00049 00086 class _OgreExport ResourceGroupListener 00087 { 00088 public: 00089 virtual ~ResourceGroupListener() {} 00090 00100 virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0; 00108 virtual void scriptParseStarted(const String& scriptName, bool& skipThisScript) = 0; 00109 00112 virtual void scriptParseEnded(const String& scriptName, bool skipped) = 0; 00114 virtual void resourceGroupScriptingEnded(const String& groupName) = 0; 00115 00121 virtual void resourceGroupPrepareStarted(const String& groupName, size_t resourceCount) 00122 { (void)groupName; (void)resourceCount; } 00123 00127 virtual void resourcePrepareStarted(const ResourcePtr& resource) 00128 { (void)resource; } 00129 00132 virtual void resourcePrepareEnded(void) {} 00138 virtual void worldGeometryPrepareStageStarted(const String& description) 00139 { (void)description; } 00140 00145 virtual void worldGeometryPrepareStageEnded(void) {} 00147 virtual void resourceGroupPrepareEnded(const String& groupName) 00148 { (void)groupName; } 00149 00155 virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0; 00159 virtual void resourceLoadStarted(const ResourcePtr& resource) = 0; 00162 virtual void resourceLoadEnded(void) = 0; 00168 virtual void worldGeometryStageStarted(const String& description) = 0; 00173 virtual void worldGeometryStageEnded(void) = 0; 00175 virtual void resourceGroupLoadEnded(const String& groupName) = 0; 00179 virtual void resourceCreated(const ResourcePtr& resource) 00180 { (void)resource; } 00184 virtual void resourceRemove(const ResourcePtr& resource) 00185 { (void)resource; } 00186 }; 00187 00193 class ResourceLoadingListener 00194 { 00195 public: 00196 virtual ~ResourceLoadingListener() {} 00197 00199 virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0; 00200 00206 virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0; 00207 00210 virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0; 00211 }; 00212 00261 class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc 00262 { 00263 public: 00264 OGRE_AUTO_MUTEX; // public to allow external locking 00266 static String DEFAULT_RESOURCE_GROUP_NAME; 00268 static String INTERNAL_RESOURCE_GROUP_NAME; 00270 static String AUTODETECT_RESOURCE_GROUP_NAME; 00272 static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS; 00274 struct ResourceDeclaration 00275 { 00276 String resourceName; 00277 String resourceType; 00278 ManualResourceLoader* loader; 00279 NameValuePairList parameters; 00280 }; 00282 typedef list<ResourceDeclaration>::type ResourceDeclarationList; 00283 typedef map<String, ResourceManager*>::type ResourceManagerMap; 00284 typedef MapIterator<ResourceManagerMap> ResourceManagerIterator; 00286 struct ResourceLocation 00287 { 00289 Archive* archive; 00291 bool recursive; 00292 }; 00294 typedef list<ResourceLocation*>::type LocationList; 00295 00296 protected: 00298 ResourceManagerMap mResourceManagerMap; 00299 00301 typedef multimap<Real, ScriptLoader*>::type ScriptLoaderOrderMap; 00302 ScriptLoaderOrderMap mScriptLoaderOrderMap; 00303 00304 typedef vector<ResourceGroupListener*>::type ResourceGroupListenerList; 00305 ResourceGroupListenerList mResourceGroupListenerList; 00306 00307 ResourceLoadingListener *mLoadingListener; 00308 00310 typedef map<String, Archive*>::type ResourceLocationIndex; 00311 00313 typedef list<ResourcePtr>::type LoadUnloadResourceList; 00315 struct ResourceGroup 00316 { 00317 enum Status 00318 { 00319 UNINITIALSED = 0, 00320 INITIALISING = 1, 00321 INITIALISED = 2, 00322 LOADING = 3, 00323 LOADED = 4 00324 }; 00326 OGRE_AUTO_MUTEX; 00328 OGRE_MUTEX(statusMutex); 00330 String name; 00332 Status groupStatus; 00334 LocationList locationList; 00336 ResourceLocationIndex resourceIndexCaseSensitive; 00338 ResourceLocationIndex resourceIndexCaseInsensitive; 00340 ResourceDeclarationList resourceDeclarations; 00342 // Group by loading order of the type (defined by ResourceManager) 00343 // (e.g. skeletons and materials before meshes) 00344 typedef map<Real, LoadUnloadResourceList*>::type LoadResourceOrderMap; 00345 LoadResourceOrderMap loadResourceOrderMap; 00347 String worldGeometry; 00349 SceneManager* worldGeometrySceneManager; 00350 // in global pool flag - if true the resource will be loaded even a different group was requested in the load method as a parameter. 00351 bool inGlobalPool; 00352 00353 void addToIndex(const String& filename, Archive* arch); 00354 void removeFromIndex(const String& filename, Archive* arch); 00355 void removeFromIndex(Archive* arch); 00356 00357 }; 00359 typedef map<String, ResourceGroup*>::type ResourceGroupMap; 00360 ResourceGroupMap mResourceGroupMap; 00361 00363 String mWorldGroupName; 00364 00370 void parseResourceGroupScripts(ResourceGroup* grp); 00375 void createDeclaredResources(ResourceGroup* grp); 00377 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); 00379 ResourceGroup* getResourceGroup(const String& name); 00381 void dropGroupContents(ResourceGroup* grp); 00383 void deleteGroup(ResourceGroup* grp); 00385 ResourceGroup* findGroupContainingResourceImpl(const String& filename); 00387 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); 00389 void fireScriptStarted(const String& scriptName, bool &skipScript); 00391 void fireScriptEnded(const String& scriptName, bool skipped); 00393 void fireResourceGroupScriptingEnded(const String& groupName); 00395 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); 00397 void fireResourceLoadStarted(const ResourcePtr& resource); 00399 void fireResourceLoadEnded(void); 00401 void fireResourceGroupLoadEnded(const String& groupName); 00403 void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount); 00405 void fireResourcePrepareStarted(const ResourcePtr& resource); 00407 void fireResourcePrepareEnded(void); 00409 void fireResourceGroupPrepareEnded(const String& groupName); 00411 void fireResourceCreated(const ResourcePtr& resource); 00413 void fireResourceRemove(const ResourcePtr& resource); 00415 time_t resourceModifiedTime(ResourceGroup* group, const String& filename); 00416 00421 bool resourceExists(ResourceGroup* group, const String& filename); 00422 00424 ResourceGroup* mCurrentGroup; 00425 public: 00426 ResourceGroupManager(); 00427 virtual ~ResourceGroupManager(); 00428 00466 void createResourceGroup(const String& name, const bool inGlobalPool = true); 00467 00468 00508 void initialiseResourceGroup(const String& name); 00509 00513 void initialiseAllResourceGroups(void); 00514 00532 void prepareResourceGroup(const String& name, bool prepareMainResources = true, 00533 bool prepareWorldGeom = true); 00534 00552 void loadResourceGroup(const String& name, bool loadMainResources = true, 00553 bool loadWorldGeom = true); 00554 00570 void unloadResourceGroup(const String& name, bool reloadableOnly = true); 00571 00583 void unloadUnreferencedResourcesInGroup(const String& name, 00584 bool reloadableOnly = true); 00585 00595 void clearResourceGroup(const String& name); 00596 00602 void destroyResourceGroup(const String& name); 00603 00611 bool isResourceGroupInitialised(const String& name); 00612 00620 bool isResourceGroupLoaded(const String& name); 00621 00622 /*** Verify if a resource group exists 00623 @param name The name of the resource group to look for 00624 */ 00625 bool resourceGroupExists(const String& name); 00626 00648 void addResourceLocation(const String& name, const String& locType, 00649 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false, bool readOnly = true); 00651 void removeResourceLocation(const String& name, 00652 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00654 bool resourceLocationExists(const String& name, 00655 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00656 00691 void declareResource(const String& name, const String& resourceType, 00692 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00693 const NameValuePairList& loadParameters = NameValuePairList()); 00733 void declareResource(const String& name, const String& resourceType, 00734 const String& groupName, ManualResourceLoader* loader, 00735 const NameValuePairList& loadParameters = NameValuePairList()); 00746 void undeclareResource(const String& name, const String& groupName); 00747 00767 DataStreamPtr openResource(const String& resourceName, 00768 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00769 bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0); 00770 00782 DataStreamListPtr openResources(const String& pattern, 00783 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00784 00793 StringVectorPtr listResourceNames(const String& groupName, bool dirs = false); 00794 00801 FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false); 00802 00814 StringVectorPtr findResourceNames(const String& groupName, const String& pattern, 00815 bool dirs = false); 00816 00821 bool resourceExists(const String& group, const String& filename); 00822 00826 bool resourceExistsInAnyGroup(const String& filename); 00827 00834 const String& findGroupContainingResource(const String& filename); 00835 00845 FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern, 00846 bool dirs = false); 00847 00849 time_t resourceModifiedTime(const String& group, const String& filename); 00854 StringVectorPtr listResourceLocations(const String& groupName); 00855 00862 StringVectorPtr findResourceLocation(const String& groupName, const String& pattern); 00863 00878 DataStreamPtr createResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00879 bool overwrite = false, const String& locationPattern = StringUtil::BLANK); 00880 00890 void deleteResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00891 const String& locationPattern = StringUtil::BLANK); 00892 00902 void deleteMatchingResources(const String& filePattern, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00903 const String& locationPattern = StringUtil::BLANK); 00904 00908 void addResourceGroupListener(ResourceGroupListener* l); 00910 void removeResourceGroupListener(ResourceGroupListener* l); 00911 00918 void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} 00919 00921 const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } 00922 00936 void linkWorldGeometryToResourceGroup(const String& group, 00937 const String& worldGeometry, SceneManager* sceneManager); 00938 00943 void unlinkWorldGeometryFromResourceGroup(const String& group); 00944 00952 bool isResourceGroupInGlobalPool(const String& name); 00953 00955 void shutdownAll(void); 00956 00957 00967 void _registerResourceManager(const String& resourceType, ResourceManager* rm); 00968 00975 void _unregisterResourceManager(const String& resourceType); 00976 00979 ResourceManagerIterator getResourceManagerIterator() 00980 { return ResourceManagerIterator( 00981 mResourceManagerMap.begin(), mResourceManagerMap.end()); } 00982 00987 void _registerScriptLoader(ScriptLoader* su); 00988 00992 void _unregisterScriptLoader(ScriptLoader* su); 00993 00997 ScriptLoader *_findScriptLoader(const String &pattern); 00998 01002 ResourceManager* _getResourceManager(const String& resourceType); 01003 01007 void _notifyResourceCreated(ResourcePtr& res); 01008 01012 void _notifyResourceRemoved(ResourcePtr& res); 01013 01016 void _notifyResourceGroupChanged(const String& oldGroup, Resource* res); 01017 01022 void _notifyAllResourcesRemoved(ResourceManager* manager); 01023 01031 void _notifyWorldGeometryStageStarted(const String& description); 01039 void _notifyWorldGeometryStageEnded(void); 01040 01046 StringVector getResourceGroups(void); 01053 ResourceDeclarationList getResourceDeclarationList(const String& groupName); 01054 01059 const LocationList& getResourceLocationList(const String& groupName); 01060 01062 void setLoadingListener(ResourceLoadingListener *listener); 01064 ResourceLoadingListener *getLoadingListener(); 01065 01081 static ResourceGroupManager& getSingleton(void); 01097 static ResourceGroupManager* getSingletonPtr(void); 01098 01099 }; 01102 } 01103 01104 #include "OgreHeaderSuffix.h" 01105 01106 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45