OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreResourceGroupManager.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _ResourceGroupManager_H__
29 #define _ResourceGroupManager_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreSingleton.h"
33 #include "OgreCommon.h"
34 #include "OgreDataStream.h"
35 #include "OgreResource.h"
36 #include "OgreArchive.h"
37 #include "OgreIteratorWrappers.h"
38 #include <ctime>
39 
40 // If X11/Xlib.h gets included before this header (for example it happens when
41 // including wxWidgets and FLTK), Status is defined as an int which we don't
42 // want as we have an enum named Status.
43 #ifdef Status
44 #undef Status
45 #endif
46 
47 namespace Ogre {
48 
86  {
87  public:
89 
99  virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0;
107  virtual void scriptParseStarted(const String& scriptName, bool& skipThisScript) = 0;
108 
111  virtual void scriptParseEnded(const String& scriptName, bool skipped) = 0;
113  virtual void resourceGroupScriptingEnded(const String& groupName) = 0;
114 
120  virtual void resourceGroupPrepareStarted(const String& groupName, size_t resourceCount)
121  { (void)groupName; (void)resourceCount; }
122 
126  virtual void resourcePrepareStarted(const ResourcePtr& resource)
127  { (void)resource; }
128 
131  virtual void resourcePrepareEnded(void) {}
137  virtual void worldGeometryPrepareStageStarted(const String& description)
138  { (void)description; }
139 
145  virtual void worldGeometryPrepareStageEnded(void) {}
147  virtual void resourceGroupPrepareEnded(const String& groupName)
148  { (void)groupName; }
149 
155  virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0;
159  virtual void resourceLoadStarted(const ResourcePtr& resource) = 0;
162  virtual void resourceLoadEnded(void) = 0;
168  virtual void worldGeometryStageStarted(const String& description) = 0;
174  virtual void worldGeometryStageEnded(void) = 0;
176  virtual void resourceGroupLoadEnded(const String& groupName) = 0;
177  };
178 
185  {
186  public:
188 
190  virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0;
191 
197  virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0;
198 
201  virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0;
202  };
203 
252  class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc
253  {
254  public:
255  OGRE_AUTO_MUTEX // public to allow external locking
266  {
271  };
278  {
282  bool recursive;
283  };
286 
287  protected:
290 
294 
297 
299 
302 
307  {
308  enum Status
309  {
310  UNINITIALSED = 0,
311  INITIALISING = 1,
312  INITIALISED = 2,
313  LOADING = 3,
314  LOADED = 4
315  };
319  OGRE_MUTEX(statusMutex)
321  String name;
323  Status groupStatus;
325  LocationList locationList;
327  ResourceLocationIndex resourceIndexCaseSensitive;
329  ResourceLocationIndex resourceIndexCaseInsensitive;
331  ResourceDeclarationList resourceDeclarations;
333  // Group by loading order of the type (defined by ResourceManager)
334  // (e.g. skeletons and materials before meshes)
336  LoadResourceOrderMap loadResourceOrderMap;
338  String worldGeometry;
340  SceneManager* worldGeometrySceneManager;
341  // in global pool flag - if true the resource will be loaded even a different group was requested in the load method as a parameter.
342  bool inGlobalPool;
343 
344  void addToIndex(const String& filename, Archive* arch);
345  void removeFromIndex(const String& filename, Archive* arch);
346  void removeFromIndex(Archive* arch);
347 
348  };
351  ResourceGroupMap mResourceGroupMap;
352 
354  String mWorldGroupName;
355 
361  void parseResourceGroupScripts(ResourceGroup* grp);
366  void createDeclaredResources(ResourceGroup* grp);
368  void addCreatedResource(ResourcePtr& res, ResourceGroup& group);
370  ResourceGroup* getResourceGroup(const String& name);
372  void dropGroupContents(ResourceGroup* grp);
374  void deleteGroup(ResourceGroup* grp);
376  ResourceGroup* findGroupContainingResourceImpl(const String& filename);
378  void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount);
380  void fireScriptStarted(const String& scriptName, bool &skipScript);
382  void fireScriptEnded(const String& scriptName, bool skipped);
384  void fireResourceGroupScriptingEnded(const String& groupName);
386  void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount);
388  void fireResourceLoadStarted(const ResourcePtr& resource);
390  void fireResourceLoadEnded(void);
392  void fireResourceGroupLoadEnded(const String& groupName);
394  void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount);
396  void fireResourcePrepareStarted(const ResourcePtr& resource);
398  void fireResourcePrepareEnded(void);
400  void fireResourceGroupPrepareEnded(const String& groupName);
401 
403  ResourceGroup* mCurrentGroup;
404  public:
406  virtual ~ResourceGroupManager();
407 
445  void createResourceGroup(const String& name, const bool inGlobalPool = true);
446 
447 
487  void initialiseResourceGroup(const String& name);
488 
492  void initialiseAllResourceGroups(void);
493 
511  void prepareResourceGroup(const String& name, bool prepareMainResources = true,
512  bool prepareWorldGeom = true);
513 
531  void loadResourceGroup(const String& name, bool loadMainResources = true,
532  bool loadWorldGeom = true);
533 
549  void unloadResourceGroup(const String& name, bool reloadableOnly = true);
550 
562  void unloadUnreferencedResourcesInGroup(const String& name,
563  bool reloadableOnly = true);
564 
574  void clearResourceGroup(const String& name);
575 
581  void destroyResourceGroup(const String& name);
582 
590  bool isResourceGroupInitialised(const String& name);
591 
599  bool isResourceGroupLoaded(const String& name);
600 
601  /*** Verify if a resource group exists
602  @param name The name of the resource group to look for
603  */
604  bool resourceGroupExists(const String& name);
605 
627  void addResourceLocation(const String& name, const String& locType,
628  const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false);
630  void removeResourceLocation(const String& name,
631  const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
633  bool resourceLocationExists(const String& name,
634  const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
635 
670  void declareResource(const String& name, const String& resourceType,
671  const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
672  const NameValuePairList& loadParameters = NameValuePairList());
712  void declareResource(const String& name, const String& resourceType,
713  const String& groupName, ManualResourceLoader* loader,
714  const NameValuePairList& loadParameters = NameValuePairList());
725  void undeclareResource(const String& name, const String& groupName);
726 
746  DataStreamPtr openResource(const String& resourceName,
747  const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
748  bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0);
749 
761  DataStreamListPtr openResources(const String& pattern,
762  const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
763 
772  StringVectorPtr listResourceNames(const String& groupName, bool dirs = false);
773 
780  FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false);
781 
793  StringVectorPtr findResourceNames(const String& groupName, const String& pattern,
794  bool dirs = false);
795 
800  bool resourceExists(const String& group, const String& filename);
801 
806  bool resourceExists(ResourceGroup* group, const String& filename);
807 
811  bool resourceExistsInAnyGroup(const String& filename);
812 
819  const String& findGroupContainingResource(const String& filename);
820 
830  FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern,
831  bool dirs = false);
832 
834  time_t resourceModifiedTime(const String& group, const String& filename);
839  StringVectorPtr listResourceLocations(const String& groupName);
840 
847  StringVectorPtr findResourceLocation(const String& groupName, const String& pattern);
848 
850  time_t resourceModifiedTime(ResourceGroup* group, const String& filename);
851 
866  DataStreamPtr createResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
867  bool overwrite = false, const String& locationPattern = StringUtil::BLANK);
868 
878  void deleteResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
879  const String& locationPattern = StringUtil::BLANK);
880 
890  void deleteMatchingResources(const String& filePattern, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
891  const String& locationPattern = StringUtil::BLANK);
892 
896  void addResourceGroupListener(ResourceGroupListener* l);
898  void removeResourceGroupListener(ResourceGroupListener* l);
899 
906  void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
907 
909  const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
910 
924  void linkWorldGeometryToResourceGroup(const String& group,
925  const String& worldGeometry, SceneManager* sceneManager);
926 
931  void unlinkWorldGeometryFromResourceGroup(const String& group);
932 
940  bool isResourceGroupInGlobalPool(const String& name);
941 
943  void shutdownAll(void);
944 
945 
955  void _registerResourceManager(const String& resourceType, ResourceManager* rm);
956 
963  void _unregisterResourceManager(const String& resourceType);
964 
968  { return ResourceManagerIterator(
969  mResourceManagerMap.begin(), mResourceManagerMap.end()); }
970 
975  void _registerScriptLoader(ScriptLoader* su);
976 
980  void _unregisterScriptLoader(ScriptLoader* su);
981 
985  ScriptLoader *_findScriptLoader(const String &pattern);
986 
990  ResourceManager* _getResourceManager(const String& resourceType);
991 
995  void _notifyResourceCreated(ResourcePtr& res);
996 
1000  void _notifyResourceRemoved(ResourcePtr& res);
1001 
1004  void _notifyResourceGroupChanged(const String& oldGroup, Resource* res);
1005 
1010  void _notifyAllResourcesRemoved(ResourceManager* manager);
1011 
1019  void _notifyWorldGeometryStageStarted(const String& description);
1027  void _notifyWorldGeometryStageEnded(void);
1028 
1034  StringVector getResourceGroups(void);
1041  ResourceDeclarationList getResourceDeclarationList(const String& groupName);
1042 
1047  const LocationList& getResourceLocationList(const String& groupName);
1048 
1050  void setLoadingListener(ResourceLoadingListener *listener);
1052  ResourceLoadingListener *getLoadingListener();
1053 
1069  static ResourceGroupManager& getSingleton(void);
1085  static ResourceGroupManager* getSingletonPtr(void);
1086 
1087  };
1090 }
1091 
1092 #endif
virtual void resourcePrepareEnded(void)
This event is fired when the resource has been prepared.
#define OGRE_AUTO_MUTEX
float Real
Software floating point type.
map< Real, LoadUnloadResourceList * >::type LoadResourceOrderMap
Created resources which are ready to be loaded / unloaded.
virtual void resourcePrepareStarted(const ResourcePtr &resource)
This event is fired when a declared resource is about to be prepared.
#define _OgreExport
Definition: OgrePlatform.h:203
virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager)=0
This event is called when a resource collides with another existing one in a resource manager...
virtual void worldGeometryPrepareStageEnded(void)
This event is fired when a stage of preparing linked world geometry has been completed.
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:524
list< ResourceLocation * >::type LocationList
List of possible file locations.
Template class for creating single-instance global classes.
Definition: OgreSingleton.h:64
map< String, ResourceManager * >::type ResourceManagerMap
Manages the organisation and rendering of a 'scene' i.e.
static String AUTODETECT_RESOURCE_GROUP_NAME
Special resource group name which causes resource group to be automatically determined based on searc...
MapIterator< ResourceManagerMap > ResourceManagerIterator
ResourceManagerMap mResourceManagerMap
Map of resource types (strings) to ResourceManagers, used to notify them to load / unload group conte...
ScriptLoaderOrderMap mScriptLoaderOrderMap
#define OGRE_MUTEX(name)
map< String, ResourceGroup * >::type ResourceGroupMap
Map from resource group names to groups.
Interface describing a manual resource loader.
Definition: OgreResource.h:512
virtual void worldGeometryPrepareStageStarted(const String &description)
This event is fired when a stage of preparing linked world geometry is about to start.
ResourceGroupListenerList mResourceGroupListenerList
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
static String INTERNAL_RESOURCE_GROUP_NAME
Internal resource group name (should be used by OGRE internal only)
virtual void resourceGroupPrepareEnded(const String &groupName)
This event is fired when a resource group finished preparing.
virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr &dataStream)=0
This event is called when a resource stream has been opened, but not processed yet.
Abstract class defining the interface used by classes which wish to perform script loading to define ...
static OGRE_AUTO_MUTEX String DEFAULT_RESOURCE_GROUP_NAME
Default resource group name.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
list< ResourcePtr >::type LoadUnloadResourceList
List of resources which can be loaded / unloaded.
Utility class for manipulating Strings.
Definition: OgreString.h:74
bool recursive
Whether this location was added recursively.
vector< ResourceGroupListener * >::type ResourceGroupListenerList
Archive * archive
Pointer to the archive which is the destination.
vector< String >::type StringVector
list< ResourceDeclaration >::type ResourceDeclarationList
List of resource declarations.
ResourceManagerIterator getResourceManagerIterator()
Get an iterator over the registered resource managers.
map< String, Archive * >::type ResourceLocationIndex
Resource index entry, resourcename->location.
multimap< Real, ScriptLoader * >::type ScriptLoaderOrderMap
Map of loading order (Real) to ScriptLoader, used to order script parsing.
Abstract class representing a loadable resource (e.g.
Definition: OgreResource.h:77
virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource)=0
This event is called when a resource beings loading.
Nested struct defining a resource declaration.
This singleton class manages the list of resource groups, and notifying the various resource managers...
Defines a generic resource handler.
static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS
The number of reference counts held per resource by the resource system.
Archive-handling class.
Definition: OgreArchive.h:87
This abstract class defines an interface which is called back during resource group loading to indica...
ResourceLoadingListener * mLoadingListener
_StringBase String
const String & getWorldResourceGroupName(void) const
Gets the resource group that 'world' resources will use.
virtual void resourceGroupPrepareStarted(const String &groupName, size_t resourceCount)
This event is fired when a resource group begins preparing.