# 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 #include <ctime>
    00040
    00044 #ifdef Status
    00045 #undef Status
    00046 #endif
    00047
    00048 namespace Ogre {
    00049
    00080     class _OgreExport ResourceGroupListener
    00081     {
    00082     public:
    00083         virtual ~ResourceGroupListener() {}
    00084
    00094         virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0;
    00102         virtual void scriptParseStarted(const String& scriptName, bool& skipThisScript) = 0;
    00103
    00106         virtual void scriptParseEnded(const String& scriptName, bool skipped) = 0;
    00108         virtual void resourceGroupScriptingEnded(const String& groupName) = 0;
    00109
    00115         virtual void resourceGroupPrepareStarted(const String& groupName, size_t resourceCount) {}
    00119         virtual void resourcePrepareStarted(const ResourcePtr& resource) {}
    00122         virtual void resourcePrepareEnded(void) {}
    00128         virtual void worldGeometryPrepareStageStarted(const String& description) {}
    00134         virtual void worldGeometryPrepareStageEnded(void) {}
    00136         virtual void resourceGroupPrepareEnded(const String& groupName) {}
    00137
    00143         virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0;
    00147         virtual void resourceLoadStarted(const ResourcePtr& resource) = 0;
    00150         virtual void resourceLoadEnded(void) = 0;
    00156         virtual void worldGeometryStageStarted(const String& description) = 0;
    00162         virtual void worldGeometryStageEnded(void) = 0;
    00164         virtual void resourceGroupLoadEnded(const String& groupName) = 0;
    00165     };
    00166
    00172     class ResourceLoadingListener
    00173     {
    00174     public:
    00175         virtual ~ResourceLoadingListener() {}
    00176
    00178         virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0;
    00179
    00185         virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0;
    00186
    00189         virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0;
    00190     };
    00191
    00240     class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc
    00241     {
    00242     public:
    00243         OGRE_AUTO_MUTEX // public to allow external locking
    00245         static String DEFAULT_RESOURCE_GROUP_NAME;
    00247         static String INTERNAL_RESOURCE_GROUP_NAME;
    00249         static String BOOTSTRAP_RESOURCE_GROUP_NAME;
    00251         static String AUTODETECT_RESOURCE_GROUP_NAME;
    00253         static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS;
    00255         struct ResourceDeclaration
    00256         {
    00257             String resourceName;
    00258             String resourceType;
    00259             ManualResourceLoader* loader;
    00260             NameValuePairList parameters;
    00261         };
    00263         typedef std::list<ResourceDeclaration> ResourceDeclarationList;
    00264         typedef std::map<String, ResourceManager*> ResourceManagerMap;
    00265         typedef MapIterator<ResourceManagerMap> ResourceManagerIterator;
    00266     protected:
    00268         ResourceManagerMap mResourceManagerMap;
    00269
    00271         typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap;
    00272         ScriptLoaderOrderMap mScriptLoaderOrderMap;
    00273
    00274         typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList;
    00275         ResourceGroupListenerList mResourceGroupListenerList;
    00276
    00277         ResourceLoadingListener *mLoadingListener;
    00278
    00280         typedef std::map<String, Archive*> ResourceLocationIndex;
    00281
    00283         struct ResourceLocation
    00284         {
    00286             Archive* archive;
    00288             bool recursive;
    00289         };
    00291         typedef std::list<ResourceLocation*> LocationList;
    00293         typedef std::list<ResourcePtr> LoadUnloadResourceList;
    00295         struct ResourceGroup
    00296         {
    00297             enum Status
    00298             {
    00299                 UNINITIALSED = 0,
    00300                 INITIALISING = 1,
    00301                 INITIALISED = 2,
    00302                 LOADING = 3,
    00303                 LOADED = 4
    00304             };
    00306             OGRE_AUTO_MUTEX
    00308             OGRE_MUTEX(statusMutex)
    00310             String name;
    00312             Status groupStatus;
    00314             LocationList locationList;
    00316             ResourceLocationIndex resourceIndexCaseSensitive;
    00318             ResourceLocationIndex resourceIndexCaseInsensitive;
    00320             ResourceDeclarationList resourceDeclarations;
    00322             // Group by loading order of the type (defined by ResourceManager)
    00323             // (e.g. skeletons and materials before meshes)
    00324             typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap;
    00325             LoadResourceOrderMap loadResourceOrderMap;
    00327             String worldGeometry;
    00329             SceneManager* worldGeometrySceneManager;
    00330         };
    00332         typedef std::map<String, ResourceGroup*> ResourceGroupMap;
    00333         ResourceGroupMap mResourceGroupMap;
    00334
    00336         String mWorldGroupName;
    00337
    00343         void parseResourceGroupScripts(ResourceGroup* grp);
    00348         void createDeclaredResources(ResourceGroup* grp);
    00350         void addCreatedResource(ResourcePtr& res, ResourceGroup& group);
    00352         ResourceGroup* getResourceGroup(const String& name);
    00354         void dropGroupContents(ResourceGroup* grp);
    00356         void deleteGroup(ResourceGroup* grp);
    00358         ResourceGroup* findGroupContainingResourceImpl(const String& filename);
    00360         void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount);
    00362         void fireScriptStarted(const String& scriptName, bool &skipScript);
    00364         void fireScriptEnded(const String& scriptName, bool skipped);
    00366         void fireResourceGroupScriptingEnded(const String& groupName);
    00368         void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount);
    00370         void fireResourceLoadStarted(const ResourcePtr& resource);
    00372         void fireResourceLoadEnded(void);
    00374         void fireResourceGroupLoadEnded(const String& groupName);
    00376         void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount);
    00378         void fireResourcePrepareStarted(const ResourcePtr& resource);
    00380         void fireResourcePrepareEnded(void);
    00382         void fireResourceGroupPrepareEnded(const String& groupName);
    00383
    00385         ResourceGroup* mCurrentGroup;
    00386     public:
    00387         ResourceGroupManager();
    00388         virtual ~ResourceGroupManager();
    00389
    00425         void createResourceGroup(const String& name);
    00426
    00427
    00467         void initialiseResourceGroup(const String& name);
    00468
    00472         void initialiseAllResourceGroups(void);
    00473
    00491         void prepareResourceGroup(const String& name, bool prepareMainResources = true,
    00492             bool prepareWorldGeom = true);
    00493
    00511         void loadResourceGroup(const String& name, bool loadMainResources = true,
    00512             bool loadWorldGeom = true);
    00513
    00529         void unloadResourceGroup(const String& name, bool reloadableOnly = true);
    00530
    00542         void unloadUnreferencedResourcesInGroup(const String& name,
    00543             bool reloadableOnly = true);
    00544
    00554         void clearResourceGroup(const String& name);
    00555
    00561         void destroyResourceGroup(const String& name);
    00562
    00570         bool isResourceGroupInitialised(const String& name);
    00571
    00579         bool isResourceGroupLoaded(const String& name);
    00580
    00602         void addResourceLocation(const String& name, const String& locType,
    00603             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false);
    00605         void removeResourceLocation(const String& name,
    00606             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
    00607
    00642         void declareResource(const String& name, const String& resourceType,
    00643             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00644             const NameValuePairList& loadParameters = NameValuePairList());
    00684         void declareResource(const String& name, const String& resourceType,
    00685             const String& groupName, ManualResourceLoader* loader,
    00686             const NameValuePairList& loadParameters = NameValuePairList());
    00697         void undeclareResource(const String& name, const String& groupName);
    00698
    00718         DataStreamPtr openResource(const String& resourceName,
    00719             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00720             bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0);
    00721
    00733         DataStreamListPtr openResources(const String& pattern,
    00734             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
    00735
    00744         StringVectorPtr listResourceNames(const String& groupName, bool dirs = false);
    00745
    00752         FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false);
    00753
    00765         StringVectorPtr findResourceNames(const String& groupName, const String& pattern,
    00766             bool dirs = false);
    00767
    00772         bool resourceExists(const String& group, const String& filename);
    00773
    00778         bool resourceExists(ResourceGroup* group, const String& filename);
    00785         const String& findGroupContainingResource(const String& filename);
    00786
    00796         FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern,
    00797             bool dirs = false);
    00798
    00800         time_t resourceModifiedTime(const String& group, const String& filename);
    00801
    00803         time_t resourceModifiedTime(ResourceGroup* group, const String& filename);
    00804
    00808         void addResourceGroupListener(ResourceGroupListener* l);
    00810         void removeResourceGroupListener(ResourceGroupListener* l);
    00811
    00818         void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
    00819
    00821         const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
    00822
    00836         void linkWorldGeometryToResourceGroup(const String& group,
    00837             const String& worldGeometry, SceneManager* sceneManager);
    00838
    00843         void unlinkWorldGeometryFromResourceGroup(const String& group);
    00844
    00846         void shutdownAll(void);
    00847
    00848
    00858         void _registerResourceManager(const String& resourceType, ResourceManager* rm);
    00859
    00866         void _unregisterResourceManager(const String& resourceType);
    00867
    00870         ResourceManagerIterator getResourceManagerIterator()
    00871         { return ResourceManagerIterator(
    00872             mResourceManagerMap.begin(), mResourceManagerMap.end()); }
    00873
    00878         void _registerScriptLoader(ScriptLoader* su);
    00879
    00883         void _unregisterScriptLoader(ScriptLoader* su);
    00884
    00888         ResourceManager* _getResourceManager(const String& resourceType);
    00889
    00893         void _notifyResourceCreated(ResourcePtr& res);
    00894
    00898         void _notifyResourceRemoved(ResourcePtr& res);
    00899
    00902         void _notifyResourceGroupChanged(const String& oldGroup, Resource* res);
    00903
    00908         void _notifyAllResourcesRemoved(ResourceManager* manager);
    00909
    00917         void _notifyWorldGeometryStageStarted(const String& description);
    00925         void _notifyWorldGeometryStageEnded(void);
    00926
    00932         StringVector getResourceGroups(void);
    00939         ResourceDeclarationList getResourceDeclarationList(const String& groupName);
    00940
    00942         void setLoadingListener(ResourceLoadingListener *listener);
    00944         ResourceLoadingListener *getLoadingListener();
    00945
    00961         static ResourceGroupManager& getSingleton(void);
    00977         static ResourceGroupManager* getSingletonPtr(void);
    00978
    00979     };
    00980 }
    00981
    00982 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:19 2009