Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreResourceGroupManager.h

Go to the documentation of this file.
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 
00467         void declareResource(const String& name, const String& resourceType,
00468             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
00469             const NameValuePairList& loadParameters = NameValuePairList());
00480         void undeclareResource(const String& name, const String& groupName);
00481 
00494         DataStreamPtr openResource(const String& resourceName, 
00495             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
00496 
00508         DataStreamListPtr openResources(const String& pattern, 
00509             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
00510         
00518         StringVectorPtr listResourceNames(const String& groupName);
00519 
00525         FileInfoListPtr listResourceFileInfo(const String& groupName);
00526 
00535         StringVectorPtr findResourceNames(const String& groupName, const String& pattern);
00536 
00541         bool resourceExists(const String& group, const String& filename);
00542 
00550         FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern);
00551 
00552         
00556         void addResourceGroupListener(ResourceGroupListener* l);
00558         void removeResourceGroupListener(ResourceGroupListener* l);
00559 
00566         void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
00567 
00569         const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
00570 
00584         void linkWorldGeometryToResourceGroup(const String& group, 
00585             const String& worldGeometry, SceneManager* sceneManager);
00586 
00591         void unlinkWorldGeometryFromResourceGroup(const String& group);
00592 
00594         void shutdownAll(void);
00595 
00596 
00606         void _registerResourceManager(const String& resourceType, ResourceManager* rm);
00607 
00614         void _unregisterResourceManager(const String& resourceType);
00615 
00616 
00621         void _registerScriptLoader(ScriptLoader* su);
00622 
00626         void _unregisterScriptLoader(ScriptLoader* su);
00627 
00631         ResourceManager* _getResourceManager(const String& resourceType);
00632 
00636         void _notifyResourceCreated(ResourcePtr& res);
00637 
00641         void _notifyResourceRemoved(ResourcePtr& res);
00642 
00647         void _notifyAllResourcesRemoved(ResourceManager* manager);
00648 
00656         void _notifyWorldGeometryStageStarted(const String& description);
00664         void _notifyWorldGeometryStageEnded(void);
00665 
00671         StringVector getResourceGroups(void);
00678         ResourceDeclarationList getResourceDeclarationList(const String& groupName);
00679 
00695         static ResourceGroupManager& getSingleton(void);
00711         static ResourceGroupManager* getSingletonPtr(void);
00712 
00713     };
00714 }
00715 
00716 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Sep 25 17:36:00 2005