OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-2013 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 #include "OgreHeaderPrefix.h"
40 
41 // If X11/Xlib.h gets included before this header (for example it happens when
42 // including wxWidgets and FLTK), Status is defined as an int which we don't
43 // want as we have an enum named Status.
44 #ifdef Status
45 #undef Status
46 #endif
47 
48 namespace Ogre {
49 
87  {
88  public:
90 
100  virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0;
108  virtual void scriptParseStarted(const String& scriptName, bool& skipThisScript) = 0;
109 
112  virtual void scriptParseEnded(const String& scriptName, bool skipped) = 0;
114  virtual void resourceGroupScriptingEnded(const String& groupName) = 0;
115 
121  virtual void resourceGroupPrepareStarted(const String& groupName, size_t resourceCount)
122  { (void)groupName; (void)resourceCount; }
123 
127  virtual void resourcePrepareStarted(const ResourcePtr& resource)
128  { (void)resource; }
129 
132  virtual void resourcePrepareEnded(void) {}
138  virtual void worldGeometryPrepareStageStarted(const String& description)
139  { (void)description; }
140 
146  virtual void worldGeometryPrepareStageEnded(void) {}
148  virtual void resourceGroupPrepareEnded(const String& groupName)
149  { (void)groupName; }
150 
156  virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0;
160  virtual void resourceLoadStarted(const ResourcePtr& resource) = 0;
163  virtual void resourceLoadEnded(void) = 0;
169  virtual void worldGeometryStageStarted(const String& description) = 0;
175  virtual void worldGeometryStageEnded(void) = 0;
177  virtual void resourceGroupLoadEnded(const String& groupName) = 0;
178  };
179 
186  {
187  public:
189 
191  virtual DataStreamPtr resourceLoading(const String &name, const String &group, Resource *resource) = 0;
192 
198  virtual void resourceStreamOpened(const String &name, const String &group, Resource *resource, DataStreamPtr& dataStream) = 0;
199 
202  virtual bool resourceCollision(Resource *resource, ResourceManager *resourceManager) = 0;
203  };
204 
253  class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager>, public ResourceAlloc
254  {
255  public:
256  OGRE_AUTO_MUTEX // public to allow external locking
267  {
272  };
279  {
283  bool recursive;
284  };
287 
288  protected:
291 
295 
298 
300 
303 
308  {
309  enum Status
310  {
311  UNINITIALSED = 0,
312  INITIALISING = 1,
313  INITIALISED = 2,
314  LOADING = 3,
315  LOADED = 4
316  };
320  OGRE_MUTEX(statusMutex)
322  String name;
324  Status groupStatus;
326  LocationList locationList;
328  ResourceLocationIndex resourceIndexCaseSensitive;
330  ResourceLocationIndex resourceIndexCaseInsensitive;
332  ResourceDeclarationList resourceDeclarations;
334  // Group by loading order of the type (defined by ResourceManager)
335  // (e.g. skeletons and materials before meshes)
337  LoadResourceOrderMap loadResourceOrderMap;
339  String worldGeometry;
341  SceneManager* worldGeometrySceneManager;
342  // in global pool flag - if true the resource will be loaded even a different group was requested in the load method as a parameter.
343  bool inGlobalPool;
344 
345  void addToIndex(const String& filename, Archive* arch);
346  void removeFromIndex(const String& filename, Archive* arch);
347  void removeFromIndex(Archive* arch);
348 
349  };
352  ResourceGroupMap mResourceGroupMap;
353 
355  String mWorldGroupName;
356 
362  void parseResourceGroupScripts(ResourceGroup* grp);
367  void createDeclaredResources(ResourceGroup* grp);
369  void addCreatedResource(ResourcePtr& res, ResourceGroup& group);
371  ResourceGroup* getResourceGroup(const String& name);
373  void dropGroupContents(ResourceGroup* grp);
375  void deleteGroup(ResourceGroup* grp);
377  ResourceGroup* findGroupContainingResourceImpl(const String& filename);
379  void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount);
381  void fireScriptStarted(const String& scriptName, bool &skipScript);
383  void fireScriptEnded(const String& scriptName, bool skipped);
385  void fireResourceGroupScriptingEnded(const String& groupName);
387  void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount);
389  void fireResourceLoadStarted(const ResourcePtr& resource);
391  void fireResourceLoadEnded(void);
393  void fireResourceGroupLoadEnded(const String& groupName);
395  void fireResourceGroupPrepareStarted(const String& groupName, size_t resourceCount);
397  void fireResourcePrepareStarted(const ResourcePtr& resource);
399  void fireResourcePrepareEnded(void);
401  void fireResourceGroupPrepareEnded(const String& groupName);
402 
404  ResourceGroup* mCurrentGroup;
405  public:
407  virtual ~ResourceGroupManager();
408 
446  void createResourceGroup(const String& name, const bool inGlobalPool = true);
447 
448 
488  void initialiseResourceGroup(const String& name);
489 
493  void initialiseAllResourceGroups(void);
494 
512  void prepareResourceGroup(const String& name, bool prepareMainResources = true,
513  bool prepareWorldGeom = true);
514 
532  void loadResourceGroup(const String& name, bool loadMainResources = true,
533  bool loadWorldGeom = true);
534 
550  void unloadResourceGroup(const String& name, bool reloadableOnly = true);
551 
563  void unloadUnreferencedResourcesInGroup(const String& name,
564  bool reloadableOnly = true);
565 
575  void clearResourceGroup(const String& name);
576 
582  void destroyResourceGroup(const String& name);
583 
591  bool isResourceGroupInitialised(const String& name);
592 
600  bool isResourceGroupLoaded(const String& name);
601 
602  /*** Verify if a resource group exists
603  @param name The name of the resource group to look for
604  */
605  bool resourceGroupExists(const String& name);
606 
628  void addResourceLocation(const String& name, const String& locType,
629  const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false);
631  void removeResourceLocation(const String& name,
632  const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
634  bool resourceLocationExists(const String& name,
635  const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME);
636 
671  void declareResource(const String& name, const String& resourceType,
672  const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
673  const NameValuePairList& loadParameters = NameValuePairList());
713  void declareResource(const String& name, const String& resourceType,
714  const String& groupName, ManualResourceLoader* loader,
715  const NameValuePairList& loadParameters = NameValuePairList());
726  void undeclareResource(const String& name, const String& groupName);
727 
747  DataStreamPtr openResource(const String& resourceName,
748  const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
749  bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0);
750 
762  DataStreamListPtr openResources(const String& pattern,
763  const String& groupName = DEFAULT_RESOURCE_GROUP_NAME);
764 
773  StringVectorPtr listResourceNames(const String& groupName, bool dirs = false);
774 
781  FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false);
782 
794  StringVectorPtr findResourceNames(const String& groupName, const String& pattern,
795  bool dirs = false);
796 
801  bool resourceExists(const String& group, const String& filename);
802 
807  bool resourceExists(ResourceGroup* group, const String& filename);
808 
812  bool resourceExistsInAnyGroup(const String& filename);
813 
820  const String& findGroupContainingResource(const String& filename);
821 
831  FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern,
832  bool dirs = false);
833 
835  time_t resourceModifiedTime(const String& group, const String& filename);
840  StringVectorPtr listResourceLocations(const String& groupName);
841 
848  StringVectorPtr findResourceLocation(const String& groupName, const String& pattern);
849 
851  time_t resourceModifiedTime(ResourceGroup* group, const String& filename);
852 
867  DataStreamPtr createResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
868  bool overwrite = false, const String& locationPattern = StringUtil::BLANK);
869 
879  void deleteResource(const String& filename, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
880  const String& locationPattern = StringUtil::BLANK);
881 
891  void deleteMatchingResources(const String& filePattern, const String& groupName = DEFAULT_RESOURCE_GROUP_NAME,
892  const String& locationPattern = StringUtil::BLANK);
893 
897  void addResourceGroupListener(ResourceGroupListener* l);
899  void removeResourceGroupListener(ResourceGroupListener* l);
900 
907  void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;}
908 
910  const String& getWorldResourceGroupName(void) const { return mWorldGroupName; }
911 
925  void linkWorldGeometryToResourceGroup(const String& group,
926  const String& worldGeometry, SceneManager* sceneManager);
927 
932  void unlinkWorldGeometryFromResourceGroup(const String& group);
933 
941  bool isResourceGroupInGlobalPool(const String& name);
942 
944  void shutdownAll(void);
945 
946 
956  void _registerResourceManager(const String& resourceType, ResourceManager* rm);
957 
964  void _unregisterResourceManager(const String& resourceType);
965 
969  { return ResourceManagerIterator(
970  mResourceManagerMap.begin(), mResourceManagerMap.end()); }
971 
976  void _registerScriptLoader(ScriptLoader* su);
977 
981  void _unregisterScriptLoader(ScriptLoader* su);
982 
986  ScriptLoader *_findScriptLoader(const String &pattern);
987 
991  ResourceManager* _getResourceManager(const String& resourceType);
992 
996  void _notifyResourceCreated(ResourcePtr& res);
997 
1001  void _notifyResourceRemoved(ResourcePtr& res);
1002 
1005  void _notifyResourceGroupChanged(const String& oldGroup, Resource* res);
1006 
1011  void _notifyAllResourcesRemoved(ResourceManager* manager);
1012 
1020  void _notifyWorldGeometryStageStarted(const String& description);
1028  void _notifyWorldGeometryStageEnded(void);
1029 
1035  StringVector getResourceGroups(void);
1042  ResourceDeclarationList getResourceDeclarationList(const String& groupName);
1043 
1048  const LocationList& getResourceLocationList(const String& groupName);
1049 
1051  void setLoadingListener(ResourceLoadingListener *listener);
1053  ResourceLoadingListener *getLoadingListener();
1054 
1070  static ResourceGroupManager& getSingleton(void);
1086  static ResourceGroupManager* getSingletonPtr(void);
1087 
1088  };
1091 }
1092 
1093 #include "OgreHeaderSuffix.h"
1094 
1095 #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:233
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:553
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:513
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:75
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:78
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:88
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.