Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef _ResourceGroupManager_H__
    00030 #define _ResourceGroupManager_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreSingleton.h"
    00034 #include "OgreCommon.h"
    00035 #include "OgreDataStream.h"
    00036 #include "OgreResource.h"
    00037 #include "OgreArchive.h"
    00038 #include "OgreIteratorWrappers.h"
    00039
    00040 namespace Ogre {
    00041
    00068     class _OgreExport ResourceGroupListener
    00069     {
    00070     public:
    00071         virtual ~ResourceGroupListener() {}
    00072
    00082         virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0;
    00086         virtual void scriptParseStarted(const String& scriptName) = 0;
    00089         virtual void scriptParseEnded(const String& scriptName) = 0;
    00091         virtual void resourceGroupScriptingEnded(const String& groupName) = 0;
    00092
    00098         virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0;
    00102         virtual void resourceLoadStarted(const ResourcePtr& resource) = 0;
    00105         virtual void resourceLoadEnded(void) = 0;
    00111         virtual void worldGeometryStageStarted(const String& description) = 0;
    00117         virtual void worldGeometryStageEnded(void) = 0;
    00118
    00120         virtual void resourceGroupLoadEnded(const String& groupName) = 0;
    00121
    00122     };
    00171     class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>
    00172     {
    00173     public:
    00174         OGRE_AUTO_MUTEX // public to allow external locking
    00176         static String DEFAULT_RESOURCE_GROUP_NAME;
    00178         static String INTERNAL_RESOURCE_GROUP_NAME;
    00180         static String BOOTSTRAP_RESOURCE_GROUP_NAME;
    00182         static String AUTODETECT_RESOURCE_GROUP_NAME;
    00184         static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS;
    00186         struct ResourceDeclaration
    00187         {
    00188             String resourceName;
    00189             String resourceType;
    00190             ManualResourceLoader* loader;
    00191             NameValuePairList parameters;
    00192         };
    00194         typedef std::list<ResourceDeclaration> ResourceDeclarationList;
    00195         typedef std::map<String, ResourceManager*> ResourceManagerMap;
    00196         typedef MapIterator<ResourceManagerMap> ResourceManagerIterator;
    00197     protected:
    00199         ResourceManagerMap mResourceManagerMap;
    00200
    00202         typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap;
    00203         ScriptLoaderOrderMap mScriptLoaderOrderMap;
    00204
    00205         typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList;
    00206         ResourceGroupListenerList mResourceGroupListenerList;
    00207
    00209         typedef std::map<String, Archive*> ResourceLocationIndex;
    00210
    00212         struct ResourceLocation
    00213         {
    00215             Archive* archive;
    00217             bool recursive;
    00218         };
    00220         typedef std::list<ResourceLocation*> LocationList;
    00222         typedef std::list<ResourcePtr> LoadUnloadResourceList;
    00224         struct ResourceGroup
    00225         {
    00226             enum Status
    00227             {
    00228                 UNINITIALSED = 0,
    00229                 INITIALISING = 1,
    00230                 INITIALISED = 2,
    00231                 LOADING = 3,
    00232                 LOADED = 4
    00233             };
    00235             OGRE_AUTO_MUTEX
    00237             OGRE_MUTEX(statusMutex)
    00239             String name;
    00241             bool initialised;
    00243             LocationList locationList;
    00245             ResourceLocationIndex resourceIndexCaseSensitive;
    00247             ResourceLocationIndex resourceIndexCaseInsensitive;
    00249             ResourceDeclarationList resourceDeclarations;
    00251             // Group by loading order of the type (defined by ResourceManager)
    00252             // (e.g. skeletons and materials before meshes)
    00253             typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap;
    00254             LoadResourceOrderMap loadResourceOrderMap;
    00256             String worldGeometry;
    00258             SceneManager* worldGeometrySceneManager;
    00259         };
    00261         typedef std::map<String, ResourceGroup*> ResourceGroupMap;
    00262         ResourceGroupMap mResourceGroupMap;
    00263
    00265         String mWorldGroupName;
    00266
    00272         void parseResourceGroupScripts(ResourceGroup* grp);
    00277         void createDeclaredResources(ResourceGroup* grp);
    00279         void addCreatedResource(ResourcePtr& res, ResourceGroup& group);
    00281         ResourceGroup* getResourceGroup(const String& name);
    00283         void dropGroupContents(ResourceGroup* grp);
    00285         void deleteGroup(ResourceGroup* grp);
    00287         ResourceGroup* findGroupContainingResourceImpl(const String& filename);
    00289         void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount);
    00291         void fireScriptStarted(const String& scriptName);
    00293         void fireScriptEnded(const String& scriptName);
    00295         void fireResourceGroupScriptingEnded(const String& groupName);
    00297         void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount);
    00299         void fireResourceStarted(const ResourcePtr& resource);
    00301         void fireResourceEnded(void);
    00303         void fireResourceGroupLoadEnded(const String& groupName);
    00304
    00305
    00306
    00308         ResourceGroup* mCurrentGroup;
    00309     public:
    00310         ResourceGroupManager();
    00311         virtual ~ResourceGroupManager();
    00312
    00348         void createResourceGroup(const String& name);
    00349
    00350
    00390         void initialiseResourceGroup(const String& name);
    00391
    00395         void initialiseAllResourceGroups(void);
    00396
    00414         void loadResourceGroup(const String& name, bool loadMainResources = true,
    00415             bool loadWorldGeom = true);
    00416
    00432         void unloadResourceGroup(const String& name, bool reloadableOnly = true);
    00433
    00445         void unloadUnreferencedResourcesInGroup(const String& name,
    00446             bool reloadableOnly = true);
    00447
    00457         void clearResourceGroup(const String& name);
    00458
    00464         void destroyResourceGroup(const String& name);
    00465
    00487         void addResourceLocation(const String& name, const String& locType,
    00488             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false);
    00490         void removeResourceLocation(const String& name,
    00491             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
    00492
    00527         void declareResource(const String& name, const String& resourceType,
    00528             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00529             const NameValuePairList& loadParameters = NameValuePairList());
    00569         void declareResource(const String& name, const String& resourceType,
    00570             const String& groupName, ManualResourceLoader* loader,
    00571             const NameValuePairList& loadParameters = NameValuePairList());
    00582         void undeclareResource(const String& name, const String& groupName);
    00583
    00603         DataStreamPtr openResource(const String& resourceName,
    00604             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00605             bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0);
    00606
    00618         DataStreamListPtr openResources(const String& pattern,
    00619             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
    00620
    00629         StringVectorPtr listResourceNames(const String& groupName, bool dirs = false);
    00630
    00637         FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false);
    00638
    00650         StringVectorPtr findResourceNames(const String& groupName, const String& pattern,
    00651             bool dirs = false);
    00652
    00657         bool resourceExists(const String& group, const String& filename);
    00658
    00663         bool resourceExists(ResourceGroup* group, const String& filename);
    00670         const String& findGroupContainingResource(const String& filename);
    00671
    00681         FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern,
    00682             bool dirs = false);
    00683
    00684
    00688         void addResourceGroupListener(ResourceGroupListener* l);
    00690         void removeResourceGroupListener(ResourceGroupListener* l);
    00691
    00698         void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
    00699
    00701         const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
    00702
    00716         void linkWorldGeometryToResourceGroup(const String& group,
    00717             const String& worldGeometry, SceneManager* sceneManager);
    00718
    00723         void unlinkWorldGeometryFromResourceGroup(const String& group);
    00724
    00726         void shutdownAll(void);
    00727
    00728
    00738         void _registerResourceManager(const String& resourceType, ResourceManager* rm);
    00739
    00746         void _unregisterResourceManager(const String& resourceType);
    00747
    00750         ResourceManagerIterator getResourceManagerIterator()
    00751         { return ResourceManagerIterator(
    00752             mResourceManagerMap.begin(), mResourceManagerMap.end()); }
    00753
    00758         void _registerScriptLoader(ScriptLoader* su);
    00759
    00763         void _unregisterScriptLoader(ScriptLoader* su);
    00764
    00768         ResourceManager* _getResourceManager(const String& resourceType);
    00769
    00773         void _notifyResourceCreated(ResourcePtr& res);
    00774
    00778         void _notifyResourceRemoved(ResourcePtr& res);
    00779
    00782         void _notifyResourceGroupChanged(const String& oldGroup, Resource* res);
    00783
    00788         void _notifyAllResourcesRemoved(ResourceManager* manager);
    00789
    00797         void _notifyWorldGeometryStageStarted(const String& description);
    00805         void _notifyWorldGeometryStageEnded(void);
    00806
    00812         StringVector getResourceGroups(void);
    00819         ResourceDeclarationList getResourceDeclarationList(const String& groupName);
    00820
    00821
    00837         static ResourceGroupManager& getSingleton(void);
    00853         static ResourceGroupManager* getSingletonPtr(void);
    00854
    00855     };
    00856 }
    00857
    00858 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:57 2007