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 BOOTSTRAP_RESOURCE_GROUP_NAME; 00170 struct ResourceDeclaration 00171 { 00172 String resourceName; 00173 String resourceType; 00174 NameValuePairList parameters; 00175 }; 00177 typedef std::list<ResourceDeclaration> ResourceDeclarationList; 00178 protected: 00180 typedef std::map<String, ResourceManager*> ResourceManagerMap; 00181 ResourceManagerMap mResourceManagerMap; 00182 00184 typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap; 00185 ScriptLoaderOrderMap mScriptLoaderOrderMap; 00186 00187 typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList; 00188 ResourceGroupListenerList mResourceGroupListenerList; 00189 00191 typedef std::map<String, Archive*> ResourceLocationIndex; 00192 00194 struct ResourceLocation 00195 { 00197 Archive* archive; 00199 bool recursive; 00200 }; 00202 typedef std::list<ResourceLocation*> LocationList; 00204 typedef std::list<ResourcePtr> LoadUnloadResourceList; 00206 struct ResourceGroup 00207 { 00208 OGRE_AUTO_MUTEX 00210 String name; 00212 bool initialised; 00214 LocationList locationList; 00216 ResourceLocationIndex resourceIndexCaseSensitive; 00218 ResourceLocationIndex resourceIndexCaseInsensitive; 00220 ResourceDeclarationList resourceDeclarations; 00222 // Group by loading order of the type (defined by ResourceManager) 00223 // (e.g. skeletons and materials before meshes) 00224 typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap; 00225 LoadResourceOrderMap loadResourceOrderMap; 00227 String worldGeometry; 00229 SceneManager* worldGeometrySceneManager; 00230 }; 00232 typedef std::map<String, ResourceGroup*> ResourceGroupMap; 00233 ResourceGroupMap mResourceGroupMap; 00234 00236 String mWorldGroupName; 00237 00243 void parseResourceGroupScripts(ResourceGroup* grp); 00248 void createDeclaredResources(ResourceGroup* grp); 00250 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); 00252 ResourceGroup* getResourceGroup(const String& name); 00254 void dropGroupContents(ResourceGroup* grp); 00256 void deleteGroup(ResourceGroup* grp); 00258 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); 00260 void fireScriptStarted(const String& scriptName); 00262 void fireScriptEnded(void); 00264 void fireResourceGroupScriptingEnded(const String& groupName); 00266 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); 00268 void fireResourceStarted(const ResourcePtr& resource); 00270 void fireResourceEnded(void); 00272 void fireResourceGroupLoadEnded(const String& groupName); 00273 00274 00275 00277 ResourceGroup* mCurrentGroup; 00278 public: 00279 ResourceGroupManager(); 00280 virtual ~ResourceGroupManager(); 00281 00309 void createResourceGroup(const String& name); 00310 00311 00351 void initialiseResourceGroup(const String& name); 00352 00356 void initialiseAllResourceGroups(void); 00357 00375 void loadResourceGroup(const String& name, bool loadMainResources = true, 00376 bool loadWorldGeom = true); 00377 00387 void unloadResourceGroup(const String& name); 00388 00398 void clearResourceGroup(const String& name); 00399 00405 void destroyResourceGroup(const String& name); 00406 00407 00429 void addResourceLocation(const String& name, const String& locType, 00430 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false); 00432 void removeResourceLocation(const String& name, 00433 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00434 00469 void declareResource(const String& name, const String& resourceType, 00470 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00471 const NameValuePairList& loadParameters = NameValuePairList()); 00482 void undeclareResource(const String& name, const String& groupName); 00483 00496 DataStreamPtr openResource(const String& resourceName, 00497 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00498 00510 DataStreamListPtr openResources(const String& pattern, 00511 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00512 00520 StringVectorPtr listResourceNames(const String& groupName); 00521 00527 FileInfoListPtr listResourceFileInfo(const String& groupName); 00528 00537 StringVectorPtr findResourceNames(const String& groupName, const String& pattern); 00538 00543 bool resourceExists(const String& group, const String& filename); 00544 00552 FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern); 00553 00554 00558 void addResourceGroupListener(ResourceGroupListener* l); 00560 void removeResourceGroupListener(ResourceGroupListener* l); 00561 00568 void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} 00569 00571 const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } 00572 00586 void linkWorldGeometryToResourceGroup(const String& group, 00587 const String& worldGeometry, SceneManager* sceneManager); 00588 00593 void unlinkWorldGeometryFromResourceGroup(const String& group); 00594 00596 void shutdownAll(void); 00597 00598 00608 void _registerResourceManager(const String& resourceType, ResourceManager* rm); 00609 00616 void _unregisterResourceManager(const String& resourceType); 00617 00618 00623 void _registerScriptLoader(ScriptLoader* su); 00624 00628 void _unregisterScriptLoader(ScriptLoader* su); 00629 00633 ResourceManager* _getResourceManager(const String& resourceType); 00634 00638 void _notifyResourceCreated(ResourcePtr& res); 00639 00643 void _notifyResourceRemoved(ResourcePtr& res); 00644 00649 void _notifyAllResourcesRemoved(ResourceManager* manager); 00650 00658 void _notifyWorldGeometryStageStarted(const String& description); 00666 void _notifyWorldGeometryStageEnded(void); 00667 00673 StringVector getResourceGroups(void); 00680 ResourceDeclarationList getResourceDeclarationList(const String& groupName); 00681 00697 static ResourceGroupManager& getSingleton(void); 00713 static ResourceGroupManager* getSingletonPtr(void); 00714 00715 }; 00716 } 00717 00718 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:51 2006