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-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef _ResourceGroupManager_H__
    00029 #define _ResourceGroupManager_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032 #include "OgreSingleton.h"
    00033 #include "OgreCommon.h"
    00034 #include "OgreDataStream.h"
    00035 #include "OgreResource.h"
    00036 #include "OgreArchive.h"
    00037 #include "OgreIteratorWrappers.h"
    00038 #include <ctime>
    00039
    00040 // If X11/Xlib.h gets included before this header (for example it happens when
    00041 // including wxWidgets and FLTK), Status is defined as an int which we don't
    00042 // want as we have an enum named Status.
    00043 #ifdef Status
    00044 #undef Status
    00045 #endif
    00046
    00047 namespace Ogre {
    00048
    00085     class _OgreExport ResourceGroupListener
    00086     {
    00087     public:
    00088         virtual ~ResourceGroupListener() {}
    00089
    00099         virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0;
    00107         virtual void scriptParseStarted(const String& scriptName, bool& skipThisScript) = 0;
    00108
    00111         virtual void scriptParseEnded(const String& scriptName, bool skipped) = 0;
    00113         virtual void resourceGroupScriptingEnded(const String& groupName) = 0;
    00114
    00120         virtual void resourceGroupPrepareStarted(const String& groupName, size_t resourceCount)
    00121                 { (void)groupName; (void)resourceCount; }
    00122
    00126         virtual void resourcePrepareStarted(const ResourcePtr& resource)
    00127                 { (void)resource; }
    00128
    00131         virtual void resourcePrepareEnded(void) {}
    00137         virtual void worldGeometryPrepareStageStarted(const String& description)
    00138         { (void)description; }
    00139
    00145         virtual void worldGeometryPrepareStageEnded(void) {}
    00147         virtual void resourceGroupPrepareEnded(const String& groupName)
    00148         { (void)groupName; }
    00149
    00155         virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0;
    00159         virtual void resourceLoadStarted(const ResourcePtr& resource) = 0;
    00162         virtual void resourceLoadEnded(void) = 0;
    00168         virtual void worldGeometryStageStarted(const String& description) = 0;
    00174         virtual void worldGeometryStageEnded(void) = 0;
    00176         virtual void resourceGroupLoadEnded(const String& groupName) = 0;
    00177     };
    00178
    00184     class ResourceLoadingListener
    00185     {
    00186     public:
    00187         virtual ~ResourceLoadingListener() {}
    00188
    00190         virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0;
    00191
    00197         virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0;
    00198
    00201         virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0;
    00202     };
    00203
    00252     class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc
    00253     {
    00254     public:
    00255         OGRE_AUTO_MUTEX // public to allow external locking
    00257         static String DEFAULT_RESOURCE_GROUP_NAME;
    00259         static String INTERNAL_RESOURCE_GROUP_NAME;
    00261         static String AUTODETECT_RESOURCE_GROUP_NAME;
    00263         static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS;
    00265         struct ResourceDeclaration
    00266         {
    00267             String resourceName;
    00268             String resourceType;
    00269             ManualResourceLoader* loader;
    00270             NameValuePairList parameters;
    00271         };
    00273         typedef list<ResourceDeclaration>::type ResourceDeclarationList;
    00274         typedef map<String, ResourceManager*>::type ResourceManagerMap;
    00275         typedef MapIterator<ResourceManagerMap> ResourceManagerIterator;
    00277         struct ResourceLocation
    00278         {
    00280             Archive* archive;
    00282             bool recursive;
    00283         };
    00285         typedef list<ResourceLocation*>::type LocationList;
    00286
    00287     protected:
    00289         ResourceManagerMap mResourceManagerMap;
    00290
    00292         typedef multimap<Real, ScriptLoader*>::type ScriptLoaderOrderMap;
    00293         ScriptLoaderOrderMap mScriptLoaderOrderMap;
    00294
    00295         typedef vector<ResourceGroupListener*>::type ResourceGroupListenerList;
    00296         ResourceGroupListenerList mResourceGroupListenerList;
    00297
    00298         ResourceLoadingListener *mLoadingListener;
    00299
    00301         typedef map<String, Archive*>::type ResourceLocationIndex;
    00302
    00304         typedef list<ResourcePtr>::type LoadUnloadResourceList;
    00306         struct ResourceGroup
    00307         {
    00308             enum Status
    00309             {
    00310                 UNINITIALSED = 0,
    00311                 INITIALISING = 1,
    00312                 INITIALISED = 2,
    00313                 LOADING = 3,
    00314                 LOADED = 4
    00315             };
    00317             OGRE_AUTO_MUTEX
    00319             OGRE_MUTEX(statusMutex)
    00321             String name;
    00323             Status groupStatus;
    00325             LocationList locationList;
    00327             ResourceLocationIndex resourceIndexCaseSensitive;
    00329             ResourceLocationIndex resourceIndexCaseInsensitive;
    00331             ResourceDeclarationList resourceDeclarations;
    00333             // Group by loading order of the type (defined by ResourceManager)
    00334             // (e.g. skeletons and materials before meshes)
    00335             typedef map<Real, LoadUnloadResourceList*>::type LoadResourceOrderMap;
    00336             LoadResourceOrderMap loadResourceOrderMap;
    00338             String worldGeometry;
    00340             SceneManager* worldGeometrySceneManager;
    00341             // in global pool flag - if true the resource will be loaded even a different   group was requested in the load method as a parameter.
    00342             bool inGlobalPool;
    00343
    00344             void addToIndex(const String& filename, Archive* arch);
    00345             void removeFromIndex(const String& filename, Archive* arch);
    00346             void removeFromIndex(Archive* arch);
    00347
    00348         };
    00350         typedef map<String, ResourceGroup*>::type ResourceGroupMap;
    00351         ResourceGroupMap mResourceGroupMap;
    00352
    00354         String mWorldGroupName;
    00355
    00361         void parseResourceGroupScripts(ResourceGroup* grp);
    00366         void createDeclaredResources(ResourceGroup* grp);
    00368         void addCreatedResource(ResourcePtr& res, ResourceGroup& group);
    00370         ResourceGroup* getResourceGroup(const String& name);
    00372         void dropGroupContents(ResourceGroup* grp);
    00374         void deleteGroup(ResourceGroup* grp);
    00376         ResourceGroup* findGroupContainingResourceImpl(const String& filename);
    00378         void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount);
    00380         void fireScriptStarted(const String& scriptName, bool &skipScript);
    00382         void fireScriptEnded(const String& scriptName, bool skipped);
    00384         void fireResourceGroupScriptingEnded(const String& groupName);
    00386         void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount);
    00388         void fireResourceLoadStarted(const ResourcePtr& resource);
    00390         void fireResourceLoadEnded(void);
    00392         void fireResourceGroupLoadEnded(const String& groupName);
    00394         void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount);
    00396         void fireResourcePrepareStarted(const ResourcePtr& resource);
    00398         void fireResourcePrepareEnded(void);
    00400         void fireResourceGroupPrepareEnded(const String& groupName);
    00401
    00403         ResourceGroup* mCurrentGroup;
    00404     public:
    00405         ResourceGroupManager();
    00406         virtual ~ResourceGroupManager();
    00407
    00445         void createResourceGroup(const String& name, const bool inGlobalPool = true);
    00446
    00447
    00487         void initialiseResourceGroup(const String& name);
    00488
    00492         void initialiseAllResourceGroups(void);
    00493
    00511         void prepareResourceGroup(const String& name, bool prepareMainResources = true,
    00512             bool prepareWorldGeom = true);
    00513
    00531         void loadResourceGroup(const String& name, bool loadMainResources = true,
    00532             bool loadWorldGeom = true);
    00533
    00549         void unloadResourceGroup(const String& name, bool reloadableOnly = true);
    00550
    00562         void unloadUnreferencedResourcesInGroup(const String& name,
    00563             bool reloadableOnly = true);
    00564
    00574         void clearResourceGroup(const String& name);
    00575
    00581         void destroyResourceGroup(const String& name);
    00582
    00590         bool isResourceGroupInitialised(const String& name);
    00591
    00599         bool isResourceGroupLoaded(const String& name);
    00600
    00601         /*** Verify if a resource group exists
    00602         @param name The name of the resource group to look for
    00603         */
    00604         bool resourceGroupExists(const String& name);
    00605
    00627         void addResourceLocation(const String& name, const String& locType,
    00628             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false);
    00630         void removeResourceLocation(const String& name,
    00631             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
    00633         bool resourceLocationExists(const String& name,
    00634             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
    00635
    00670         void declareResource(const String& name, const String& resourceType,
    00671             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00672             const NameValuePairList& loadParameters = NameValuePairList());
    00712         void declareResource(const String& name, const String& resourceType,
    00713             const String& groupName, ManualResourceLoader* loader,
    00714             const NameValuePairList& loadParameters = NameValuePairList());
    00725         void undeclareResource(const String& name, const String& groupName);
    00726
    00746         DataStreamPtr openResource(const String& resourceName,
    00747             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00748             bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0);
    00749
    00761         DataStreamListPtr openResources(const String& pattern,
    00762             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
    00763
    00772         StringVectorPtr listResourceNames(const String& groupName, bool dirs = false);
    00773
    00780         FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false);
    00781
    00793         StringVectorPtr findResourceNames(const String& groupName, const String& pattern,
    00794             bool dirs = false);
    00795
    00800         bool resourceExists(const String& group, const String& filename);
    00801
    00806         bool resourceExists(ResourceGroup* group, const String& filename);
    00807
    00811         bool resourceExistsInAnyGroup(const String& filename);
    00812
    00819         const String& findGroupContainingResource(const String& filename);
    00820
    00830         FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern,
    00831             bool dirs = false);
    00832
    00834         time_t resourceModifiedTime(const String& group, const String& filename);
    00839         StringVectorPtr listResourceLocations(const String& groupName);
    00840
    00847         StringVectorPtr findResourceLocation(const String& groupName, const String& pattern);
    00848
    00850         time_t resourceModifiedTime(ResourceGroup* group, const String& filename);
    00851
    00866         DataStreamPtr createResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00867             bool overwrite = false, const String& locationPattern = StringUtil::BLANK);
    00868
    00878         void deleteResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00879             const String& locationPattern = StringUtil::BLANK);
    00880
    00890         void deleteMatchingResources(const String& filePattern, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
    00891             const String& locationPattern = StringUtil::BLANK);
    00892
    00896         void addResourceGroupListener(ResourceGroupListener* l);
    00898         void removeResourceGroupListener(ResourceGroupListener* l);
    00899
    00906         void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
    00907
    00909         const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
    00910
    00924         void linkWorldGeometryToResourceGroup(const String& group,
    00925             const String& worldGeometry, SceneManager* sceneManager);
    00926
    00931         void unlinkWorldGeometryFromResourceGroup(const String& group);
    00932
    00940         bool isResourceGroupInGlobalPool(const String& name);
    00941
    00943         void shutdownAll(void);
    00944
    00945
    00955         void _registerResourceManager(const String& resourceType, ResourceManager* rm);
    00956
    00963         void _unregisterResourceManager(const String& resourceType);
    00964
    00967         ResourceManagerIterator getResourceManagerIterator()
    00968         { return ResourceManagerIterator(
    00969             mResourceManagerMap.begin(), mResourceManagerMap.end()); }
    00970
    00975         void _registerScriptLoader(ScriptLoader* su);
    00976
    00980         void _unregisterScriptLoader(ScriptLoader* su);
    00981
    00985         ScriptLoader *_findScriptLoader(const String &pattern);
    00986
    00990         ResourceManager* _getResourceManager(const String& resourceType);
    00991
    00995         void _notifyResourceCreated(ResourcePtr& res);
    00996
    01000         void _notifyResourceRemoved(ResourcePtr& res);
    01001
    01004         void _notifyResourceGroupChanged(const String& oldGroup, Resource* res);
    01005
    01010         void _notifyAllResourcesRemoved(ResourceManager* manager);
    01011
    01019         void _notifyWorldGeometryStageStarted(const String& description);
    01027         void _notifyWorldGeometryStageEnded(void);
    01028
    01034         StringVector getResourceGroups(void);
    01041         ResourceDeclarationList getResourceDeclarationList(const String& groupName);
    01042
    01047         const LocationList& getResourceLocationList(const String& groupName);
    01048
    01050         void setLoadingListener(ResourceLoadingListener *listener);
    01052         ResourceLoadingListener *getLoadingListener();
    01053
    01069         static ResourceGroupManager& getSingleton(void);
    01085         static ResourceGroupManager* getSingletonPtr(void);
    01086
    01087     };
    01090 }
    01091
    01092 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:23