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 _ResourceGroupManager_H__ 00026 #define _ResourceGroupManager_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 #include "OgreSingleton.h" 00030 #include "OgreCommon.h" 00031 #include "OgreDataStream.h" 00032 #include "OgreResource.h" 00033 #include "OgreArchive.h" 00034 00035 namespace Ogre { 00036 00063 class _OgreExport ResourceGroupListener 00064 { 00065 public: 00066 virtual ~ResourceGroupListener() {} 00067 00072 virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0; 00076 virtual void scriptParseStarted(const String& scriptName) = 0; 00079 virtual void scriptParseEnded(void) = 0; 00081 virtual void resourceGroupScriptingEnded(const String& groupName) = 0; 00082 00088 virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0; 00092 virtual void resourceLoadStarted(const ResourcePtr& resource) = 0; 00095 virtual void resourceLoadEnded(void) = 0; 00101 virtual void worldGeometryStageStarted(const String& description) = 0; 00107 virtual void worldGeometryStageEnded(void) = 0; 00108 00110 virtual void resourceGroupLoadEnded(const String& groupName) = 0; 00111 00112 }; 00161 class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager> 00162 { 00163 public: 00164 OGRE_AUTO_MUTEX // public to allow external locking 00166 static String DEFAULT_RESOURCE_GROUP_NAME; 00168 static String INTERNAL_RESOURCE_GROUP_NAME; 00170 static String BOOTSTRAP_RESOURCE_GROUP_NAME; 00172 static String AUTODETECT_RESOURCE_GROUP_NAME; 00174 static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS; 00176 struct ResourceDeclaration 00177 { 00178 String resourceName; 00179 String resourceType; 00180 ManualResourceLoader* loader; 00181 NameValuePairList parameters; 00182 }; 00184 typedef std::list<ResourceDeclaration> ResourceDeclarationList; 00185 protected: 00187 typedef std::map<String, ResourceManager*> ResourceManagerMap; 00188 ResourceManagerMap mResourceManagerMap; 00189 00191 typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap; 00192 ScriptLoaderOrderMap mScriptLoaderOrderMap; 00193 00194 typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList; 00195 ResourceGroupListenerList mResourceGroupListenerList; 00196 00198 typedef std::map<String, Archive*> ResourceLocationIndex; 00199 00201 struct ResourceLocation 00202 { 00204 Archive* archive; 00206 bool recursive; 00207 }; 00209 typedef std::list<ResourceLocation*> LocationList; 00211 typedef std::list<ResourcePtr> LoadUnloadResourceList; 00213 struct ResourceGroup 00214 { 00215 OGRE_AUTO_MUTEX 00217 String name; 00219 bool initialised; 00221 LocationList locationList; 00223 ResourceLocationIndex resourceIndexCaseSensitive; 00225 ResourceLocationIndex resourceIndexCaseInsensitive; 00227 ResourceDeclarationList resourceDeclarations; 00229 // Group by loading order of the type (defined by ResourceManager) 00230 // (e.g. skeletons and materials before meshes) 00231 typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap; 00232 LoadResourceOrderMap loadResourceOrderMap; 00234 String worldGeometry; 00236 SceneManager* worldGeometrySceneManager; 00237 }; 00239 typedef std::map<String, ResourceGroup*> ResourceGroupMap; 00240 ResourceGroupMap mResourceGroupMap; 00241 00243 String mWorldGroupName; 00244 00250 void parseResourceGroupScripts(ResourceGroup* grp); 00255 void createDeclaredResources(ResourceGroup* grp); 00257 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); 00259 ResourceGroup* getResourceGroup(const String& name); 00261 void dropGroupContents(ResourceGroup* grp); 00263 void deleteGroup(ResourceGroup* grp); 00265 ResourceGroup* findGroupContainingResourceImpl(const String& filename); 00267 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); 00269 void fireScriptStarted(const String& scriptName); 00271 void fireScriptEnded(void); 00273 void fireResourceGroupScriptingEnded(const String& groupName); 00275 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); 00277 void fireResourceStarted(const ResourcePtr& resource); 00279 void fireResourceEnded(void); 00281 void fireResourceGroupLoadEnded(const String& groupName); 00282 00283 00284 00286 ResourceGroup* mCurrentGroup; 00287 public: 00288 ResourceGroupManager(); 00289 virtual ~ResourceGroupManager(); 00290 00326 void createResourceGroup(const String& name); 00327 00328 00368 void initialiseResourceGroup(const String& name); 00369 00373 void initialiseAllResourceGroups(void); 00374 00392 void loadResourceGroup(const String& name, bool loadMainResources = true, 00393 bool loadWorldGeom = true); 00394 00410 void unloadResourceGroup(const String& name, bool reloadableOnly = true); 00411 00423 void unloadUnreferencedResourcesInGroup(const String& name, 00424 bool reloadableOnly = true); 00425 00435 void clearResourceGroup(const String& name); 00436 00442 void destroyResourceGroup(const String& name); 00443 00465 void addResourceLocation(const String& name, const String& locType, 00466 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false); 00468 void removeResourceLocation(const String& name, 00469 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00470 00505 void declareResource(const String& name, const String& resourceType, 00506 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00507 const NameValuePairList& loadParameters = NameValuePairList()); 00547 void declareResource(const String& name, const String& resourceType, 00548 const String& groupName, ManualResourceLoader* loader, 00549 const NameValuePairList& loadParameters = NameValuePairList()); 00560 void undeclareResource(const String& name, const String& groupName); 00561 00581 DataStreamPtr openResource(const String& resourceName, 00582 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00583 bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0); 00584 00596 DataStreamListPtr openResources(const String& pattern, 00597 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00598 00606 StringVectorPtr listResourceNames(const String& groupName); 00607 00613 FileInfoListPtr listResourceFileInfo(const String& groupName); 00614 00623 StringVectorPtr findResourceNames(const String& groupName, const String& pattern); 00624 00629 bool resourceExists(const String& group, const String& filename); 00630 00635 bool resourceExists(ResourceGroup* group, const String& filename); 00642 const String& findGroupContainingResource(const String& filename); 00643 00651 FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern); 00652 00653 00657 void addResourceGroupListener(ResourceGroupListener* l); 00659 void removeResourceGroupListener(ResourceGroupListener* l); 00660 00667 void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} 00668 00670 const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } 00671 00685 void linkWorldGeometryToResourceGroup(const String& group, 00686 const String& worldGeometry, SceneManager* sceneManager); 00687 00692 void unlinkWorldGeometryFromResourceGroup(const String& group); 00693 00695 void shutdownAll(void); 00696 00697 00707 void _registerResourceManager(const String& resourceType, ResourceManager* rm); 00708 00715 void _unregisterResourceManager(const String& resourceType); 00716 00717 00722 void _registerScriptLoader(ScriptLoader* su); 00723 00727 void _unregisterScriptLoader(ScriptLoader* su); 00728 00732 ResourceManager* _getResourceManager(const String& resourceType); 00733 00737 void _notifyResourceCreated(ResourcePtr& res); 00738 00742 void _notifyResourceRemoved(ResourcePtr& res); 00743 00746 void _notifyResourceGroupChanged(const String& oldGroup, Resource* res); 00747 00752 void _notifyAllResourcesRemoved(ResourceManager* manager); 00753 00761 void _notifyWorldGeometryStageStarted(const String& description); 00769 void _notifyWorldGeometryStageEnded(void); 00770 00776 StringVector getResourceGroups(void); 00783 ResourceDeclarationList getResourceDeclarationList(const String& groupName); 00784 00800 static ResourceGroupManager& getSingleton(void); 00816 static ResourceGroupManager* getSingletonPtr(void); 00817 00818 }; 00819 } 00820 00821 #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