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: 00070 virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0; 00074 virtual void scriptParseStarted(const String& scriptName) = 0; 00077 virtual void scriptParseEnded(void) = 0; 00079 virtual void resourceGroupScriptingEnded(const String& groupName) = 0; 00080 00086 virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0; 00090 virtual void resourceLoadStarted(const ResourcePtr& resource) = 0; 00093 virtual void resourceLoadEnded(void) = 0; 00099 virtual void worldGeometryStageStarted(const String& description) = 0; 00105 virtual void worldGeometryStageEnded(void) = 0; 00106 00108 virtual void resourceGroupLoadEnded(const String& groupName) = 0; 00109 00110 }; 00159 class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager> 00160 { 00161 public: 00162 OGRE_AUTO_MUTEX // public to allow external locking 00164 static String DEFAULT_RESOURCE_GROUP_NAME; 00166 static String BOOTSTRAP_RESOURCE_GROUP_NAME; 00168 struct ResourceDeclaration 00169 { 00170 String resourceName; 00171 String resourceType; 00172 NameValuePairList parameters; 00173 }; 00175 typedef std::list<ResourceDeclaration> ResourceDeclarationList; 00176 protected: 00178 typedef std::map<String, ResourceManager*> ResourceManagerMap; 00179 ResourceManagerMap mResourceManagerMap; 00180 00182 typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap; 00183 ScriptLoaderOrderMap mScriptLoaderOrderMap; 00184 00185 typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList; 00186 ResourceGroupListenerList mResourceGroupListenerList; 00187 00189 typedef std::map<String, Archive*> ResourceLocationIndex; 00190 00192 struct ResourceLocation 00193 { 00195 Archive* archive; 00197 bool recursive; 00198 }; 00200 typedef std::list<ResourceLocation*> LocationList; 00202 typedef std::list<ResourcePtr> LoadUnloadResourceList; 00204 struct ResourceGroup 00205 { 00206 OGRE_AUTO_MUTEX 00208 String name; 00210 bool initialised; 00212 LocationList locationList; 00214 ResourceLocationIndex resourceIndexCaseSensitive; 00216 ResourceLocationIndex resourceIndexCaseInsensitive; 00218 ResourceDeclarationList resourceDeclarations; 00220 // Group by loading order of the type (defined by ResourceManager) 00221 // (e.g. skeletons and materials before meshes) 00222 typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap; 00223 LoadResourceOrderMap loadResourceOrderMap; 00225 String worldGeometry; 00227 SceneManager* worldGeometrySceneManager; 00228 }; 00230 typedef std::map<String, ResourceGroup*> ResourceGroupMap; 00231 ResourceGroupMap mResourceGroupMap; 00232 00234 String mWorldGroupName; 00235 00241 void parseResourceGroupScripts(ResourceGroup* grp); 00246 void createDeclaredResources(ResourceGroup* grp); 00248 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); 00250 ResourceGroup* getResourceGroup(const String& name); 00252 void dropGroupContents(ResourceGroup* grp); 00254 void deleteGroup(ResourceGroup* grp); 00256 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); 00258 void fireScriptStarted(const String& scriptName); 00260 void fireScriptEnded(void); 00262 void fireResourceGroupScriptingEnded(const String& groupName); 00264 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); 00266 void fireResourceStarted(const ResourcePtr& resource); 00268 void fireResourceEnded(void); 00270 void fireResourceGroupLoadEnded(const String& groupName); 00271 00272 00273 00275 ResourceGroup* mCurrentGroup; 00276 public: 00277 ResourceGroupManager(); 00278 virtual ~ResourceGroupManager(); 00279 00307 void createResourceGroup(const String& name); 00308 00309 00349 void initialiseResourceGroup(const String& name); 00350 00354 void initialiseAllResourceGroups(void); 00355 00373 void loadResourceGroup(const String& name, bool loadMainResources = true, 00374 bool loadWorldGeom = true); 00375 00385 void unloadResourceGroup(const String& name); 00386 00396 void clearResourceGroup(const String& name); 00397 00403 void destroyResourceGroup(const String& name); 00404 00405 00427 void addResourceLocation(const String& name, const String& locType, 00428 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false); 00430 void removeResourceLocation(const String& name, 00431 const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); 00432 00465 void declareResource(const String& name, const String& resourceType, 00466 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, 00467 const NameValuePairList& loadParameters = NameValuePairList()); 00478 void undeclareResource(const String& name, const String& groupName); 00479 00492 DataStreamPtr openResource(const String& resourceName, 00493 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00494 00506 DataStreamListPtr openResources(const String& pattern, 00507 const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); 00508 00516 StringVectorPtr listResourceNames(const String& groupName); 00517 00523 FileInfoListPtr listResourceFileInfo(const String& groupName); 00524 00533 StringVectorPtr findResourceNames(const String& groupName, const String& pattern); 00534 00539 bool resourceExists(const String& group, const String& filename); 00540 00548 FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern); 00549 00550 00554 void addResourceGroupListener(ResourceGroupListener* l); 00556 void removeResourceGroupListener(ResourceGroupListener* l); 00557 00564 void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} 00565 00567 const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } 00568 00582 void linkWorldGeometryToResourceGroup(const String& group, 00583 const String& worldGeometry, SceneManager* sceneManager); 00584 00589 void unlinkWorldGeometryFromResourceGroup(const String& group); 00590 00592 void shutdownAll(void); 00593 00594 00604 void _registerResourceManager(const String& resourceType, ResourceManager* rm); 00605 00612 void _unregisterResourceManager(const String& resourceType); 00613 00614 00619 void _registerScriptLoader(ScriptLoader* su); 00620 00624 void _unregisterScriptLoader(ScriptLoader* su); 00625 00629 ResourceManager* _getResourceManager(const String& resourceType); 00630 00634 void _notifyResourceCreated(ResourcePtr& res); 00635 00639 void _notifyResourceRemoved(ResourcePtr& res); 00640 00645 void _notifyAllResourcesRemoved(ResourceManager* manager); 00646 00654 void _notifyWorldGeometryStageStarted(const String& description); 00662 void _notifyWorldGeometryStageEnded(void); 00663 00679 static ResourceGroupManager& getSingleton(void); 00695 static ResourceGroupManager* getSingletonPtr(void); 00696 00697 }; 00698 } 00699 00700 #endif
Copyright © 2000-2005 by The OGRE Team
Last modified Sun Apr 10 23:21:21 2005