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:
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         struct ResourceDeclaration
00167         {
00168             String resourceName;
00169             String resourceType;
00170             NameValuePairList parameters;
00171         };
00173         typedef std::list<ResourceDeclaration> ResourceDeclarationList;
00174     protected:
00176         typedef std::map<String, ResourceManager*> ResourceManagerMap;
00177         ResourceManagerMap mResourceManagerMap;
00178 
00180         typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap;
00181         ScriptLoaderOrderMap mScriptLoaderOrderMap;
00182 
00183         typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList;
00184         ResourceGroupListenerList mResourceGroupListenerList;
00185 
00187         typedef std::map<String, Archive*> ResourceLocationIndex;
00188 
00190         struct ResourceLocation
00191         {
00193             Archive* archive;
00195             bool recursive;
00196         };
00198         typedef std::list<ResourceLocation*> LocationList;
00200         typedef std::list<ResourcePtr> LoadUnloadResourceList;
00202         struct ResourceGroup
00203         {
00204             OGRE_AUTO_MUTEX
00206             String name;
00208             bool initialised;
00210             LocationList locationList;
00212             ResourceLocationIndex resourceIndexCaseSensitive;
00214             ResourceLocationIndex resourceIndexCaseInsensitive;
00216             ResourceDeclarationList resourceDeclarations;
00218             // Group by loading order of the type (defined by ResourceManager)
00219             // (e.g. skeletons and materials before meshes)
00220             typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap;
00221             LoadResourceOrderMap loadResourceOrderMap;
00223             String worldGeometry;
00225             SceneManager* worldGeometrySceneManager;
00226         };
00228         typedef std::map<String, ResourceGroup*> ResourceGroupMap;
00229         ResourceGroupMap mResourceGroupMap;
00230 
00232         String mWorldGroupName;
00233 
00239         void parseResourceGroupScripts(ResourceGroup* grp);
00244         void createDeclaredResources(ResourceGroup* grp);
00246         void addCreatedResource(ResourcePtr& res, ResourceGroup& group);
00248         ResourceGroup* getResourceGroup(const String& name);
00250         void dropGroupContents(ResourceGroup* grp);
00252         void deleteGroup(ResourceGroup* grp);
00254         void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount);
00256         void fireScriptStarted(const String& scriptName);
00258         void fireScriptEnded(void);
00260         void fireResourceGroupScriptingEnded(const String& groupName);
00262         void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount);
00264         void fireResourceStarted(const ResourcePtr& resource);
00266         void fireResourceEnded(void);
00268         void fireResourceGroupLoadEnded(const String& groupName);
00269 
00270 
00271 
00273         ResourceGroup* mCurrentGroup;
00274     public:
00275         ResourceGroupManager();
00276         virtual ~ResourceGroupManager();
00277 
00305         void createResourceGroup(const String& name);
00306 
00307 
00347         void initialiseResourceGroup(const String& name);
00348 
00352         void initialiseAllResourceGroups(void);
00353 
00371         void loadResourceGroup(const String& name, bool loadMainResources = true, 
00372             bool loadWorldGeom = true);
00373 
00383         void unloadResourceGroup(const String& name);
00384 
00394         void clearResourceGroup(const String& name);
00395         
00401         void destroyResourceGroup(const String& name);
00402 
00403 
00425         void addResourceLocation(const String& name, const String& locType, 
00426             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false);
00428         void removeResourceLocation(const String& name, 
00429             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
00430 
00463         void declareResource(const String& name, const String& resourceType,
00464             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
00465             const NameValuePairList& loadParameters = NameValuePairList());
00476         void undeclareResource(const String& name, const String& groupName);
00477 
00490         DataStreamPtr openResource(const String& resourceName, 
00491             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
00492 
00504         DataStreamListPtr openResources(const String& pattern, 
00505             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
00506         
00514         StringVectorPtr listResourceNames(const String& groupName);
00515 
00521         FileInfoListPtr listResourceFileInfo(const String& groupName);
00522 
00531         StringVectorPtr findResourceNames(const String& groupName, const String& pattern);
00532 
00537         bool resourceExists(const String& group, const String& filename);
00538 
00546         FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern);
00547 
00548         
00552         void addResourceGroupListener(ResourceGroupListener* l);
00554         void removeResourceGroupListener(ResourceGroupListener* l);
00555 
00562         void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
00563 
00565         const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
00566 
00580         void linkWorldGeometryToResourceGroup(const String& group, 
00581             const String& worldGeometry, SceneManager* sceneManager);
00582 
00587         void unlinkWorldGeometryFromResourceGroup(const String& group);
00588 
00590         void shutdownAll(void);
00591 
00592 
00602         void _registerResourceManager(const String& resourceType, ResourceManager* rm);
00603 
00610         void _unregisterResourceManager(const String& resourceType);
00611 
00612 
00617         void _registerScriptLoader(ScriptLoader* su);
00618 
00622         void _unregisterScriptLoader(ScriptLoader* su);
00623 
00627         ResourceManager* _getResourceManager(const String& resourceType);
00628 
00632         void _notifyResourceCreated(ResourcePtr& res);
00633 
00637         void _notifyResourceRemoved(ResourcePtr& res);
00638 
00643         void _notifyAllResourcesRemoved(ResourceManager* manager);
00644 
00652         void _notifyWorldGeometryStageStarted(const String& description);
00660         void _notifyWorldGeometryStageEnded(void);
00661 
00677         static ResourceGroupManager& getSingleton(void);
00693         static ResourceGroupManager* getSingletonPtr(void);
00694 
00695     };
00696 }
00697 
00698 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Wed Feb 23 00:19:12 2005