| 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-2006 Torus Knot Software Ltd | 
|---|
| 8 | Also see acknowledgements in Readme.html | 
|---|
| 9 |  | 
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under | 
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software | 
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later | 
|---|
| 13 | version. | 
|---|
| 14 |  | 
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT | 
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | 
|---|
| 18 |  | 
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with | 
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | 
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to | 
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. | 
|---|
| 23 |  | 
|---|
| 24 | You may alternatively use this source under the terms of a specific version of | 
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from | 
|---|
| 26 | Torus Knot Software Ltd. | 
|---|
| 27 | ----------------------------------------------------------------------------- | 
|---|
| 28 | */ | 
|---|
| 29 | #ifndef _ResourceGroupManager_H__ | 
|---|
| 30 | #define _ResourceGroupManager_H__ | 
|---|
| 31 |  | 
|---|
| 32 | #include "OgrePrerequisites.h" | 
|---|
| 33 | #include "OgreSingleton.h" | 
|---|
| 34 | #include "OgreCommon.h" | 
|---|
| 35 | #include "OgreDataStream.h" | 
|---|
| 36 | #include "OgreResource.h" | 
|---|
| 37 | #include "OgreArchive.h" | 
|---|
| 38 | #include "OgreIteratorWrappers.h" | 
|---|
| 39 |  | 
|---|
| 40 | namespace Ogre { | 
|---|
| 41 |  | 
|---|
| 42 |     /** This abstract class defines an interface which is called back during | 
|---|
| 43 |         resource group loading to indicate the progress of the load.  | 
|---|
| 44 |         @remarks | 
|---|
| 45 |                 Resource group loading is in 2 phases - creating resources from  | 
|---|
| 46 |                 declarations (which includes parsing scripts), and loading | 
|---|
| 47 |                 resources. Note that you don't necessarily have to have both; it | 
|---|
| 48 |                 is quite possible to just parse all the scripts for a group (see | 
|---|
| 49 |                 ResourceGroupManager::initialiseResourceGroup, but not to  | 
|---|
| 50 |                 load the resource group.  | 
|---|
| 51 |                 The sequence of events is (* signifies a repeating item): | 
|---|
| 52 |                 <ul> | 
|---|
| 53 |                 <li>resourceGroupScriptingStarted</li> | 
|---|
| 54 |                 <li>scriptParseStarted (*)</li> | 
|---|
| 55 |         <li>scriptParseEnded (*)</li> | 
|---|
| 56 |                 <li>resourceGroupScriptingEnded</li> | 
|---|
| 57 |                 <li>resourceGroupLoadStarted</li> | 
|---|
| 58 |                 <li>resourceLoadStarted (*)</li> | 
|---|
| 59 |         <li>resourceLoadEnded (*)</li> | 
|---|
| 60 |         <li>worldGeometryStageStarted (*)</li> | 
|---|
| 61 |         <li>worldGeometryStageEnded (*)</li> | 
|---|
| 62 |                 <li>resourceGroupLoadEnded</li> | 
|---|
| 63 |                 </ul> | 
|---|
| 64 |     @note | 
|---|
| 65 |         If OGRE_THREAD_SUPPORT is 1, this class is thread-safe. | 
|---|
| 66 |  | 
|---|
| 67 |     */ | 
|---|
| 68 |     class _OgreExport ResourceGroupListener | 
|---|
| 69 |     { | 
|---|
| 70 |     public: | 
|---|
| 71 |         virtual ~ResourceGroupListener() {} | 
|---|
| 72 |  | 
|---|
| 73 |                 /** This event is fired when a resource group begins parsing scripts. | 
|---|
| 74 |                 @note | 
|---|
| 75 |                         Remember that if you are loading resources through ResourceBackgroundQueue, | 
|---|
| 76 |                         these callbacks will occur in the background thread, so you should | 
|---|
| 77 |                         not perform any thread-unsafe actions in this callback if that's the | 
|---|
| 78 |                         case (check the group name / script name). | 
|---|
| 79 |                 @param groupName The name of the group  | 
|---|
| 80 |                 @param scriptCount The number of scripts which will be parsed | 
|---|
| 81 |                 */ | 
|---|
| 82 |                 virtual void resourceGroupScriptingStarted(const String& groupName, size_t scriptCount) = 0; | 
|---|
| 83 |                 /** This event is fired when a script is about to be parsed. | 
|---|
| 84 |                 @param scriptName Name of the to be parsed | 
|---|
| 85 |                 */ | 
|---|
| 86 |                 virtual void scriptParseStarted(const String& scriptName) = 0; | 
|---|
| 87 |                 /** This event is fired when the script has been fully parsed. | 
|---|
| 88 |                 */ | 
|---|
| 89 |                 virtual void scriptParseEnded(const String& scriptName) = 0; | 
|---|
| 90 |                 /** This event is fired when a resource group finished parsing scripts. */ | 
|---|
| 91 |                 virtual void resourceGroupScriptingEnded(const String& groupName) = 0; | 
|---|
| 92 |  | 
|---|
| 93 |                 /** This event is fired  when a resource group begins loading. | 
|---|
| 94 |                 @param groupName The name of the group being loaded | 
|---|
| 95 |                 @param resourceCount The number of resources which will be loaded, including | 
|---|
| 96 |             a number of stages required to load any linked world geometry | 
|---|
| 97 |                 */ | 
|---|
| 98 |                 virtual void resourceGroupLoadStarted(const String& groupName, size_t resourceCount) = 0; | 
|---|
| 99 |                 /** This event is fired when a declared resource is about to be loaded.  | 
|---|
| 100 |                 @param resource Weak reference to the resource loaded. | 
|---|
| 101 |                 */ | 
|---|
| 102 |                 virtual void resourceLoadStarted(const ResourcePtr& resource) = 0; | 
|---|
| 103 |         /** This event is fired when the resource has been loaded.  | 
|---|
| 104 |         */ | 
|---|
| 105 |         virtual void resourceLoadEnded(void) = 0; | 
|---|
| 106 |         /** This event is fired when a stage of loading linked world geometry  | 
|---|
| 107 |             is about to start. The number of stages required will have been  | 
|---|
| 108 |             included in the resourceCount passed in resourceGroupLoadStarted. | 
|---|
| 109 |         @param description Text description of what was just loaded | 
|---|
| 110 |         */ | 
|---|
| 111 |         virtual void worldGeometryStageStarted(const String& description) = 0; | 
|---|
| 112 |         /** This event is fired when a stage of loading linked world geometry  | 
|---|
| 113 |             has been completed. The number of stages required will have been  | 
|---|
| 114 |             included in the resourceCount passed in resourceGroupLoadStarted. | 
|---|
| 115 |         @param description Text description of what was just loaded | 
|---|
| 116 |         */ | 
|---|
| 117 |         virtual void worldGeometryStageEnded(void) = 0; | 
|---|
| 118 |  | 
|---|
| 119 |                 /** This event is fired when a resource group finished loading. */ | 
|---|
| 120 |                 virtual void resourceGroupLoadEnded(const String& groupName) = 0; | 
|---|
| 121 |  | 
|---|
| 122 |     }; | 
|---|
| 123 |     /** This singleton class manages the list of resource groups, and notifying | 
|---|
| 124 |         the various resource managers of their obligations to load / unload | 
|---|
| 125 |         resources in a group. It also provides facilities to monitor resource | 
|---|
| 126 |         loading per group (to do progress bars etc), provided the resources  | 
|---|
| 127 |         that are required are pre-registered. | 
|---|
| 128 |     @par | 
|---|
| 129 |         Defining new resource groups,  and declaring the resources you intend to | 
|---|
| 130 |         use in advance is optional, however it is a very useful feature. In addition,  | 
|---|
| 131 |                 if a ResourceManager supports the definition of resources through scripts,  | 
|---|
| 132 |                 then this is the class which drives the locating of the scripts and telling | 
|---|
| 133 |                 the ResourceManager to parse them.  | 
|---|
| 134 |         @par | 
|---|
| 135 |                 There are several states that a resource can be in (the concept, not the | 
|---|
| 136 |                 object instance in this case): | 
|---|
| 137 |                 <ol> | 
|---|
| 138 |                 <li><b>Undefined</b>. Nobody knows about this resource yet. It might be | 
|---|
| 139 |                 in the filesystem, but Ogre is oblivious to it at the moment - there  | 
|---|
| 140 |                 is no Resource instance. This might be because it's never been declared | 
|---|
| 141 |                 (either in a script, or using ResourceGroupManager::declareResource), or | 
|---|
| 142 |                 it may have previously been a valid Resource instance but has been  | 
|---|
| 143 |                 removed, either individually through ResourceManager::remove or as a group | 
|---|
| 144 |                 through ResourceGroupManager::clearResourceGroup.</li> | 
|---|
| 145 |                 <li><b>Declared</b>. Ogre has some forewarning of this resource, either | 
|---|
| 146 |                 through calling ResourceGroupManager::declareResource, or by declaring | 
|---|
| 147 |                 the resource in a script file which is on one of the resource locations | 
|---|
| 148 |                 which has been defined for a group. There is still no instance of Resource, | 
|---|
| 149 |                 but Ogre will know to create this resource when  | 
|---|
| 150 |                 ResourceGroupManager::initialiseResourceGroup is called (which is automatic | 
|---|
| 151 |                 if you declare the resource group before Root::initialise).</li> | 
|---|
| 152 |                 <li><b>Unloaded</b>. There is now a Resource instance for this resource,  | 
|---|
| 153 |                 although it is not loaded. This means that code which looks for this | 
|---|
| 154 |                 named resource will find it, but the Resource is not using a lot of memory | 
|---|
| 155 |                 because it is in an unloaded state. A Resource can get into this state | 
|---|
| 156 |                 by having just been created by ResourceGroupManager::initialiseResourceGroup  | 
|---|
| 157 |                 (either from a script, or from a call to declareResource), by  | 
|---|
| 158 |                 being created directly from code (ResourceManager::create), or it may  | 
|---|
| 159 |                 have previously been loaded and has been unloaded, either individually | 
|---|
| 160 |                 through Resource::unload, or as a group through ResourceGroupManager::unloadResourceGroup.</li> | 
|---|
| 161 |                 <li><b>Loaded</b>The Resource instance is fully loaded. This may have | 
|---|
| 162 |                 happened implicitly because something used it, or it may have been  | 
|---|
| 163 |                 loaded as part of a group.</li> | 
|---|
| 164 |                 </ol> | 
|---|
| 165 |                 @see ResourceGroupManager::declareResource | 
|---|
| 166 |                 @see ResourceGroupManager::initialiseResourceGroup | 
|---|
| 167 |                 @see ResourceGroupManager::loadResourceGroup | 
|---|
| 168 |                 @see ResourceGroupManager::unloadResourceGroup | 
|---|
| 169 |                 @see ResourceGroupManager::clearResourceGroup | 
|---|
| 170 |     */ | 
|---|
| 171 |     class _OgreExport ResourceGroupManager : public Singleton<ResourceGroupManager> | 
|---|
| 172 |     { | 
|---|
| 173 |     public: | 
|---|
| 174 |                 OGRE_AUTO_MUTEX // public to allow external locking | 
|---|
| 175 |                 /// Default resource group name | 
|---|
| 176 |                 static String DEFAULT_RESOURCE_GROUP_NAME; | 
|---|
| 177 |         /// Internal resource group name (should be used by OGRE internal only) | 
|---|
| 178 |         static String INTERNAL_RESOURCE_GROUP_NAME; | 
|---|
| 179 |                 /// Bootstrap resource group name (min OGRE resources) | 
|---|
| 180 |                 static String BOOTSTRAP_RESOURCE_GROUP_NAME; | 
|---|
| 181 |                 /// Special resource group name which causes resource group to be automatically determined based on searching for the resource in all groups. | 
|---|
| 182 |                 static String AUTODETECT_RESOURCE_GROUP_NAME; | 
|---|
| 183 |                 /// The number of reference counts held per resource by the resource system | 
|---|
| 184 |                 static size_t RESOURCE_SYSTEM_NUM_REFERENCE_COUNTS; | 
|---|
| 185 |         /// Nested struct defining a resource declaration | 
|---|
| 186 |         struct ResourceDeclaration | 
|---|
| 187 |         { | 
|---|
| 188 |             String resourceName; | 
|---|
| 189 |             String resourceType; | 
|---|
| 190 |             ManualResourceLoader* loader; | 
|---|
| 191 |                         NameValuePairList parameters; | 
|---|
| 192 |         }; | 
|---|
| 193 |         /// List of resource declarations | 
|---|
| 194 |         typedef std::list<ResourceDeclaration> ResourceDeclarationList; | 
|---|
| 195 |                 typedef std::map<String, ResourceManager*> ResourceManagerMap; | 
|---|
| 196 |                 typedef MapIterator<ResourceManagerMap> ResourceManagerIterator; | 
|---|
| 197 |     protected: | 
|---|
| 198 |                 /// Map of resource types (strings) to ResourceManagers, used to notify them to load / unload group contents | 
|---|
| 199 |         ResourceManagerMap mResourceManagerMap; | 
|---|
| 200 |  | 
|---|
| 201 |                 /// Map of loading order (Real) to ScriptLoader, used to order script parsing | 
|---|
| 202 |                 typedef std::multimap<Real, ScriptLoader*> ScriptLoaderOrderMap; | 
|---|
| 203 |                 ScriptLoaderOrderMap mScriptLoaderOrderMap; | 
|---|
| 204 |  | 
|---|
| 205 |                 typedef std::vector<ResourceGroupListener*> ResourceGroupListenerList; | 
|---|
| 206 |         ResourceGroupListenerList mResourceGroupListenerList; | 
|---|
| 207 |  | 
|---|
| 208 |         /// Resource index entry, resourcename->location  | 
|---|
| 209 |         typedef std::map<String, Archive*> ResourceLocationIndex; | 
|---|
| 210 |  | 
|---|
| 211 |                 /// Resource location entry | 
|---|
| 212 |                 struct ResourceLocation | 
|---|
| 213 |                 { | 
|---|
| 214 |                         /// Pointer to the archive which is the destination | 
|---|
| 215 |                         Archive* archive; | 
|---|
| 216 |                         /// Whether this location was added recursively | 
|---|
| 217 |                         bool recursive; | 
|---|
| 218 |                 }; | 
|---|
| 219 |                 /// List of possible file locations | 
|---|
| 220 |                 typedef std::list<ResourceLocation*> LocationList; | 
|---|
| 221 |                 /// List of resources which can be loaded / unloaded | 
|---|
| 222 |                 typedef std::list<ResourcePtr> LoadUnloadResourceList; | 
|---|
| 223 |                 /// Resource group entry | 
|---|
| 224 |                 struct ResourceGroup | 
|---|
| 225 |                 { | 
|---|
| 226 |                         enum Status | 
|---|
| 227 |                         { | 
|---|
| 228 |                                 UNINITIALSED = 0, | 
|---|
| 229 |                                 INITIALISING = 1, | 
|---|
| 230 |                                 INITIALISED = 2, | 
|---|
| 231 |                                 LOADING = 3, | 
|---|
| 232 |                                 LOADED = 4 | 
|---|
| 233 |                         }; | 
|---|
| 234 |                         /// General mutex for dealing with group content | 
|---|
| 235 |                         OGRE_AUTO_MUTEX | 
|---|
| 236 |                         /// Status-specific mutex, separate from content-changing mutex | 
|---|
| 237 |                         OGRE_MUTEX(statusMutex) | 
|---|
| 238 |                         /// Group name | 
|---|
| 239 |                         String name; | 
|---|
| 240 |                         /// Group status | 
|---|
| 241 |                         bool initialised; | 
|---|
| 242 |                         /// List of possible locations to search | 
|---|
| 243 |                         LocationList locationList; | 
|---|
| 244 |                         /// Index of resource names to locations, built for speedy access (case sensitive archives) | 
|---|
| 245 |                         ResourceLocationIndex resourceIndexCaseSensitive; | 
|---|
| 246 |             /// Index of resource names to locations, built for speedy access (case insensitive archives) | 
|---|
| 247 |             ResourceLocationIndex resourceIndexCaseInsensitive; | 
|---|
| 248 |                         /// Pre-declared resources, ready to be created | 
|---|
| 249 |                         ResourceDeclarationList resourceDeclarations; | 
|---|
| 250 |                         /// Created resources which are ready to be loaded / unloaded | 
|---|
| 251 |                         // Group by loading order of the type (defined by ResourceManager) | 
|---|
| 252 |                         // (e.g. skeletons and materials before meshes) | 
|---|
| 253 |                         typedef std::map<Real, LoadUnloadResourceList*> LoadResourceOrderMap; | 
|---|
| 254 |                         LoadResourceOrderMap loadResourceOrderMap; | 
|---|
| 255 |             /// Linked world geometry, as passed to setWorldGeometry | 
|---|
| 256 |             String worldGeometry; | 
|---|
| 257 |             /// Scene manager to use with linked world geometry | 
|---|
| 258 |             SceneManager* worldGeometrySceneManager; | 
|---|
| 259 |                 }; | 
|---|
| 260 |         /// Map from resource group names to groups | 
|---|
| 261 |         typedef std::map<String, ResourceGroup*> ResourceGroupMap; | 
|---|
| 262 |         ResourceGroupMap mResourceGroupMap; | 
|---|
| 263 |  | 
|---|
| 264 |         /// Group name for world resources | 
|---|
| 265 |         String mWorldGroupName; | 
|---|
| 266 |  | 
|---|
| 267 |                 /** Parses all the available scripts found in the resource locations | 
|---|
| 268 |                 for the given group, for all ResourceManagers. | 
|---|
| 269 |                 @remarks | 
|---|
| 270 |                         Called as part of initialiseResourceGroup | 
|---|
| 271 |                 */ | 
|---|
| 272 |                 void parseResourceGroupScripts(ResourceGroup* grp); | 
|---|
| 273 |                 /** Create all the pre-declared resources. | 
|---|
| 274 |                 @remarks | 
|---|
| 275 |                         Called as part of initialiseResourceGroup | 
|---|
| 276 |                 */ | 
|---|
| 277 |                 void createDeclaredResources(ResourceGroup* grp); | 
|---|
| 278 |                 /** Adds a created resource to a group. */ | 
|---|
| 279 |                 void addCreatedResource(ResourcePtr& res, ResourceGroup& group); | 
|---|
| 280 |                 /** Get resource group */ | 
|---|
| 281 |                 ResourceGroup* getResourceGroup(const String& name); | 
|---|
| 282 |                 /** Drops contents of a group, leave group there, notify ResourceManagers. */ | 
|---|
| 283 |                 void dropGroupContents(ResourceGroup* grp); | 
|---|
| 284 |                 /** Delete a group for shutdown - don't notify ResourceManagers. */ | 
|---|
| 285 |                 void deleteGroup(ResourceGroup* grp); | 
|---|
| 286 |                 /// Internal find method for auto groups | 
|---|
| 287 |                 ResourceGroup* findGroupContainingResourceImpl(const String& filename); | 
|---|
| 288 |                 /// Internal event firing method | 
|---|
| 289 |                 void fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount); | 
|---|
| 290 |                 /// Internal event firing method | 
|---|
| 291 |                 void fireScriptStarted(const String& scriptName); | 
|---|
| 292 |         /// Internal event firing method | 
|---|
| 293 |         void fireScriptEnded(const String& scriptName); | 
|---|
| 294 |                 /// Internal event firing method | 
|---|
| 295 |                 void fireResourceGroupScriptingEnded(const String& groupName); | 
|---|
| 296 |                 /// Internal event firing method | 
|---|
| 297 |                 void fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount); | 
|---|
| 298 |         /// Internal event firing method | 
|---|
| 299 |         void fireResourceStarted(const ResourcePtr& resource); | 
|---|
| 300 |                 /// Internal event firing method | 
|---|
| 301 |                 void fireResourceEnded(void); | 
|---|
| 302 |                 /// Internal event firing method | 
|---|
| 303 |                 void fireResourceGroupLoadEnded(const String& groupName); | 
|---|
| 304 |  | 
|---|
| 305 |  | 
|---|
| 306 |  | 
|---|
| 307 |                 /// Stored current group - optimisation for when bulk loading a group | 
|---|
| 308 |                 ResourceGroup* mCurrentGroup; | 
|---|
| 309 |     public: | 
|---|
| 310 |         ResourceGroupManager(); | 
|---|
| 311 |         virtual ~ResourceGroupManager(); | 
|---|
| 312 |  | 
|---|
| 313 |         /** Create a resource group. | 
|---|
| 314 |         @remarks | 
|---|
| 315 |             A resource group allows you to define a set of resources that can  | 
|---|
| 316 |             be loaded / unloaded as a unit. For example, it might be all the  | 
|---|
| 317 |             resources used for the level of a game. There is always one predefined | 
|---|
| 318 |             resource group called ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  | 
|---|
| 319 |                         which is typically used to hold all resources which do not need to  | 
|---|
| 320 |                         be unloaded until shutdown. There is another predefined resource | 
|---|
| 321 |             group called ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME too, | 
|---|
| 322 |             which should be used by OGRE internal only, the resources created | 
|---|
| 323 |             in this group aren't supposed to modify, unload or remove by user. | 
|---|
| 324 |             You can create additional ones so that you can control the life of | 
|---|
| 325 |             your resources in whichever way you wish. | 
|---|
| 326 |                         There is one other predefined value,  | 
|---|
| 327 |                         ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME; using this  | 
|---|
| 328 |                         causes the group name to be derived at load time by searching for  | 
|---|
| 329 |                         the resource in the resource locations of each group in turn. | 
|---|
| 330 |         @par | 
|---|
| 331 |             Once you have defined a resource group, resources which will be loaded | 
|---|
| 332 |                         as part of it are defined in one of 3 ways: | 
|---|
| 333 |                         <ol> | 
|---|
| 334 |                         <li>Manually through declareResource(); this is useful for scripted | 
|---|
| 335 |                                 declarations since it is entirely generalised, and does not  | 
|---|
| 336 |                                 create Resource instances right away</li> | 
|---|
| 337 |                         <li>Through the use of scripts; some ResourceManager subtypes have | 
|---|
| 338 |                                 script formats (e.g. .material, .overlay) which can be used | 
|---|
| 339 |                                 to declare resources</li> | 
|---|
| 340 |                         <li>By calling ResourceManager::create to create a resource manually. | 
|---|
| 341 |                         This resource will go on the list for it's group and will be loaded | 
|---|
| 342 |                         and unloaded with that group</li> | 
|---|
| 343 |                         </ol> | 
|---|
| 344 |                         You must remember to call initialiseResourceGroup if you intend to use | 
|---|
| 345 |                         the first 2 types. | 
|---|
| 346 |         @param name The name to give the resource group. | 
|---|
| 347 |         */ | 
|---|
| 348 |         void createResourceGroup(const String& name); | 
|---|
| 349 |  | 
|---|
| 350 |  | 
|---|
| 351 |         /** Initialises a resource group. | 
|---|
| 352 |                 @remarks | 
|---|
| 353 |                         After creating a resource group, adding some resource locations, and | 
|---|
| 354 |                         perhaps pre-declaring some resources using declareResource(), but  | 
|---|
| 355 |                         before you need to use the resources in the group, you  | 
|---|
| 356 |                         should call this method to initialise the group. By calling this, | 
|---|
| 357 |                         you are triggering the following processes: | 
|---|
| 358 |                         <ol> | 
|---|
| 359 |                         <li>Scripts for all resource types which support scripting are | 
|---|
| 360 |                                 parsed from the resource locations, and resources within them are | 
|---|
| 361 |                                 created (but not loaded yet).</li> | 
|---|
| 362 |                         <li>Creates all the resources which have just pre-declared using | 
|---|
| 363 |                         declareResource (again, these are not loaded yet)</li> | 
|---|
| 364 |                         </ol> | 
|---|
| 365 |                         So what this essentially does is create a bunch of unloaded Resource entries | 
|---|
| 366 |                         in the respective ResourceManagers based on scripts, and resources | 
|---|
| 367 |                         you've pre-declared. That means that code looking for these resources | 
|---|
| 368 |                         will find them, but they won't be taking up much memory yet, until | 
|---|
| 369 |                         they are either used, or they are loaded in bulk using loadResourceGroup. | 
|---|
| 370 |                         Loading the resource group in bulk is entirely optional, but has the  | 
|---|
| 371 |                         advantage of coming with progress reporting as resources are loaded. | 
|---|
| 372 |                 @par | 
|---|
| 373 |                         Failure to call this method means that loadResourceGroup will do  | 
|---|
| 374 |                         nothing, and any resources you define in scripts will not be found. | 
|---|
| 375 |                         Similarly, once you have called this method you won't be able to | 
|---|
| 376 |                         pick up any new scripts or pre-declared resources, unless you | 
|---|
| 377 |                         call clearResourceGroup, set up declared resources, and call this | 
|---|
| 378 |                         method again. | 
|---|
| 379 |                 @note  | 
|---|
| 380 |                         When you call Root::initialise, all resource groups that have already been | 
|---|
| 381 |                         created are automatically initialised too. Therefore you do not need to  | 
|---|
| 382 |                         call this method for groups you define and set up before you call  | 
|---|
| 383 |                         Root::initialise. However, since one of the most useful features of  | 
|---|
| 384 |                         resource groups is to set them up after the main system initialisation | 
|---|
| 385 |                         has occurred (e.g. a group per game level), you must remember to call this | 
|---|
| 386 |                         method for the groups you create after this. | 
|---|
| 387 |  | 
|---|
| 388 |                 @param name The name of the resource group to initialise | 
|---|
| 389 |                 */ | 
|---|
| 390 |                 void initialiseResourceGroup(const String& name); | 
|---|
| 391 |  | 
|---|
| 392 |                 /** Initialise all resource groups which are yet to be initialised. | 
|---|
| 393 |                 @see ResourceGroupManager::intialiseResourceGroup | 
|---|
| 394 |                 */ | 
|---|
| 395 |                 void initialiseAllResourceGroups(void); | 
|---|
| 396 |  | 
|---|
| 397 |                 /** Loads a resource group. | 
|---|
| 398 |         @remarks | 
|---|
| 399 |                         Loads any created resources which are part of the named group. | 
|---|
| 400 |                         Note that resources must have already been created by calling | 
|---|
| 401 |                         ResourceManager::create, or declared using declareResource() or | 
|---|
| 402 |                         in a script (such as .material and .overlay). The latter requires | 
|---|
| 403 |                         that initialiseResourceGroup has been called.  | 
|---|
| 404 |                  | 
|---|
| 405 |                         When this method is called, this class will callback any ResourceGroupListeners | 
|---|
| 406 |                         which have been registered to update them on progress.  | 
|---|
| 407 |         @param name The name to of the resource group to load. | 
|---|
| 408 |                 @param loadMainResources If true, loads normal resources associated  | 
|---|
| 409 |                         with the group (you might want to set this to false if you wanted | 
|---|
| 410 |                         to just load world geometry in bulk) | 
|---|
| 411 |                 @param loadWorldGeom If true, loads any linked world geometry | 
|---|
| 412 |                         @see ResourceGroupManager::linkWorldGeometryToResourceGroup | 
|---|
| 413 |         */ | 
|---|
| 414 |         void loadResourceGroup(const String& name, bool loadMainResources = true,  | 
|---|
| 415 |                         bool loadWorldGeom = true); | 
|---|
| 416 |  | 
|---|
| 417 |         /** Unloads a resource group. | 
|---|
| 418 |         @remarks | 
|---|
| 419 |             This method unloads all the resources that have been declared as | 
|---|
| 420 |             being part of the named resource group. Note that these resources | 
|---|
| 421 |             will still exist in their respective ResourceManager classes, but | 
|---|
| 422 |             will be in an unloaded state. If you want to remove them entirely, | 
|---|
| 423 |             you should use clearResourceGroup or destroyResourceGroup. | 
|---|
| 424 |         @param name The name to of the resource group to unload. | 
|---|
| 425 |         @param reloadableOnly If set to true, only unload the resource that is | 
|---|
| 426 |             reloadable. Because some resources isn't reloadable, they will be | 
|---|
| 427 |             unloaded but can't load them later. Thus, you might not want to them | 
|---|
| 428 |             unloaded. Or, you might unload all of them, and then populate them | 
|---|
| 429 |             manually later. | 
|---|
| 430 |             @see Resource::isReloadable for resource is reloadable. | 
|---|
| 431 |         */ | 
|---|
| 432 |         void unloadResourceGroup(const String& name, bool reloadableOnly = true); | 
|---|
| 433 |  | 
|---|
| 434 |                 /** Unload all resources which are not referenced by any other object. | 
|---|
| 435 |                 @remarks | 
|---|
| 436 |                         This method behaves like unloadResourceGroup, except that it only | 
|---|
| 437 |                         unloads resources in the group which are not in use, ie not referenced | 
|---|
| 438 |                         by other objects. This allows you to free up some memory selectively | 
|---|
| 439 |                         whilst still keeping the group around (and the resources present, | 
|---|
| 440 |                         just not using much memory). | 
|---|
| 441 |                 @param name The name of the group to check for unreferenced resources | 
|---|
| 442 |                 @param reloadableOnly If true (the default), only unloads resources | 
|---|
| 443 |                         which can be subsequently automatically reloaded | 
|---|
| 444 |                 */ | 
|---|
| 445 |                 void unloadUnreferencedResourcesInGroup(const String& name,  | 
|---|
| 446 |                         bool reloadableOnly = true); | 
|---|
| 447 |  | 
|---|
| 448 |                 /** Clears a resource group.  | 
|---|
| 449 |                 @remarks | 
|---|
| 450 |                         This method unloads all resources in the group, but in addition it | 
|---|
| 451 |                         removes all those resources from their ResourceManagers, and then  | 
|---|
| 452 |                         clears all the members from the list. That means after calling this | 
|---|
| 453 |                         method, there are no resources declared as part of the named group | 
|---|
| 454 |                         any more. Resource locations still persist though. | 
|---|
| 455 |         @param name The name to of the resource group to clear. | 
|---|
| 456 |                 */ | 
|---|
| 457 |                 void clearResourceGroup(const String& name); | 
|---|
| 458 |          | 
|---|
| 459 |         /** Destroys a resource group, clearing it first, destroying the resources | 
|---|
| 460 |             which are part of it, and then removing it from | 
|---|
| 461 |             the list of resource groups.  | 
|---|
| 462 |         @param name The name of the resource group to destroy. | 
|---|
| 463 |         */ | 
|---|
| 464 |         void destroyResourceGroup(const String& name); | 
|---|
| 465 |  | 
|---|
| 466 |         /** Method to add a resource location to for a given resource group.  | 
|---|
| 467 |         @remarks | 
|---|
| 468 |             Resource locations are places which are searched to load resource files. | 
|---|
| 469 |             When you choose to load a file, or to search for valid files to load,  | 
|---|
| 470 |             the resource locations are used. | 
|---|
| 471 |         @param name The name of the resource location; probably a directory, zip file, URL etc. | 
|---|
| 472 |         @param locType The codename for the resource type, which must correspond to the  | 
|---|
| 473 |             Archive factory which is providing the implementation. | 
|---|
| 474 |         @param resGroup The name of the resource group for which this location is | 
|---|
| 475 |             to apply. ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME is the  | 
|---|
| 476 |                         default group which always exists, and can | 
|---|
| 477 |             be used for resources which are unlikely to be unloaded until application | 
|---|
| 478 |             shutdown. Otherwise it must be the name of a group; if it | 
|---|
| 479 |             has not already been created with createResourceGroup then it is created | 
|---|
| 480 |             automatically. | 
|---|
| 481 |         @param recursive Whether subdirectories will be searched for files when using  | 
|---|
| 482 |                         a pattern match (such as *.material), and whether subdirectories will be | 
|---|
| 483 |                         indexed. This can slow down initial loading of the archive and searches. | 
|---|
| 484 |                         When opening a resource you still need to use the fully qualified name,  | 
|---|
| 485 |                         this allows duplicate names in alternate paths. | 
|---|
| 486 |         */ | 
|---|
| 487 |         void addResourceLocation(const String& name, const String& locType,  | 
|---|
| 488 |             const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME, bool recursive = false); | 
|---|
| 489 |         /** Removes a resource location from the search path. */  | 
|---|
| 490 |         void removeResourceLocation(const String& name,  | 
|---|
| 491 |                         const String& resGroup = DEFAULT_RESOURCE_GROUP_NAME); | 
|---|
| 492 |  | 
|---|
| 493 |         /** Declares a resource to be a part of a resource group, allowing you  | 
|---|
| 494 |             to load and unload it as part of the group. | 
|---|
| 495 |         @remarks | 
|---|
| 496 |             By declaring resources before you attempt to use them, you can  | 
|---|
| 497 |             more easily control the loading and unloading of those resources | 
|---|
| 498 |             by their group. Declaring them also allows them to be enumerated,  | 
|---|
| 499 |             which means events can be raised to indicate the loading progress | 
|---|
| 500 |             (@see ResourceGroupListener). Note that another way of declaring | 
|---|
| 501 |                         resources is to use a script specific to the resource type, if | 
|---|
| 502 |                         available (e.g. .material). | 
|---|
| 503 |                 @par | 
|---|
| 504 |                         Declared resources are not created as Resource instances (and thus | 
|---|
| 505 |                         are not available through their ResourceManager) until initialiseResourceGroup | 
|---|
| 506 |                         is called, at which point all declared resources will become created  | 
|---|
| 507 |                         (but unloaded) Resource instances, along with any resources declared | 
|---|
| 508 |                         in scripts in resource locations associated with the group. | 
|---|
| 509 |         @param name The resource name.  | 
|---|
| 510 |         @param resourceType The type of the resource. Ogre comes preconfigured with  | 
|---|
| 511 |             a number of resource types:  | 
|---|
| 512 |             <ul> | 
|---|
| 513 |             <li>Font</li> | 
|---|
| 514 |             <li>GpuProgram</li> | 
|---|
| 515 |             <li>HighLevelGpuProgram</li> | 
|---|
| 516 |             <li>Material</li> | 
|---|
| 517 |             <li>Mesh</li> | 
|---|
| 518 |             <li>Skeleton</li> | 
|---|
| 519 |             <li>Texture</li> | 
|---|
| 520 |             </ul> | 
|---|
| 521 |             .. but more can be added by plugin ResourceManager classes. | 
|---|
| 522 |         @param groupName The name of the group to which it will belong. | 
|---|
| 523 |                 @param loadParameters A list of name / value pairs which supply custom | 
|---|
| 524 |                         parameters to the resource which will be required before it can  | 
|---|
| 525 |                         be loaded. These are specific to the resource type. | 
|---|
| 526 |         */ | 
|---|
| 527 |         void declareResource(const String& name, const String& resourceType, | 
|---|
| 528 |             const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, | 
|---|
| 529 |                         const NameValuePairList& loadParameters = NameValuePairList()); | 
|---|
| 530 |         /** Declares a resource to be a part of a resource group, allowing you | 
|---|
| 531 |             to load and unload it as part of the group. | 
|---|
| 532 |         @remarks | 
|---|
| 533 |             By declaring resources before you attempt to use them, you can | 
|---|
| 534 |             more easily control the loading and unloading of those resources | 
|---|
| 535 |             by their group. Declaring them also allows them to be enumerated, | 
|---|
| 536 |             which means events can be raised to indicate the loading progress | 
|---|
| 537 |             (@see ResourceGroupListener). Note that another way of declaring | 
|---|
| 538 |             resources is to use a script specific to the resource type, if | 
|---|
| 539 |             available (e.g. .material). | 
|---|
| 540 |         @par | 
|---|
| 541 |             Declared resources are not created as Resource instances (and thus | 
|---|
| 542 |             are not available through their ResourceManager) until initialiseResourceGroup | 
|---|
| 543 |             is called, at which point all declared resources will become created | 
|---|
| 544 |             (but unloaded) Resource instances, along with any resources declared | 
|---|
| 545 |             in scripts in resource locations associated with the group. | 
|---|
| 546 |         @param name The resource name. | 
|---|
| 547 |         @param resourceType The type of the resource. Ogre comes preconfigured with | 
|---|
| 548 |             a number of resource types: | 
|---|
| 549 |             <ul> | 
|---|
| 550 |             <li>Font</li> | 
|---|
| 551 |             <li>GpuProgram</li> | 
|---|
| 552 |             <li>HighLevelGpuProgram</li> | 
|---|
| 553 |             <li>Material</li> | 
|---|
| 554 |             <li>Mesh</li> | 
|---|
| 555 |             <li>Skeleton</li> | 
|---|
| 556 |             <li>Texture</li> | 
|---|
| 557 |             </ul> | 
|---|
| 558 |             .. but more can be added by plugin ResourceManager classes. | 
|---|
| 559 |         @param groupName The name of the group to which it will belong. | 
|---|
| 560 |         @param loader Pointer to a ManualResourceLoader implementation which will | 
|---|
| 561 |             be called when the Resource wishes to load. If supplied, the resource | 
|---|
| 562 |             is manually loaded, otherwise it'll loading from file automatic. | 
|---|
| 563 |             @note We don't support declare manually loaded resource without loader | 
|---|
| 564 |                 here, since it's meaningless. | 
|---|
| 565 |         @param loadParameters A list of name / value pairs which supply custom | 
|---|
| 566 |             parameters to the resource which will be required before it can | 
|---|
| 567 |             be loaded. These are specific to the resource type. | 
|---|
| 568 |         */ | 
|---|
| 569 |         void declareResource(const String& name, const String& resourceType, | 
|---|
| 570 |             const String& groupName, ManualResourceLoader* loader, | 
|---|
| 571 |             const NameValuePairList& loadParameters = NameValuePairList()); | 
|---|
| 572 |         /** Undeclare a resource. | 
|---|
| 573 |                 @remarks | 
|---|
| 574 |                         Note that this will not cause it to be unloaded | 
|---|
| 575 |             if it is already loaded, nor will it destroy a resource which has  | 
|---|
| 576 |                         already been created if initialiseResourceGroup has been called already. | 
|---|
| 577 |                         Only unloadResourceGroup / clearResourceGroup / destroyResourceGroup  | 
|---|
| 578 |                         will do that.  | 
|---|
| 579 |         @param name The name of the resource.  | 
|---|
| 580 |                 @param groupName The name of the group this resource was declared in.  | 
|---|
| 581 |         */ | 
|---|
| 582 |         void undeclareResource(const String& name, const String& groupName); | 
|---|
| 583 |  | 
|---|
| 584 |                 /** Open a single resource by name and return a DataStream | 
|---|
| 585 |                         pointing at the source of the data. | 
|---|
| 586 |                 @param resourceName The name of the resource to locate. | 
|---|
| 587 |                         Even if resource locations are added recursively, you | 
|---|
| 588 |                         must provide a fully qualified name to this method. You  | 
|---|
| 589 |                         can find out the matching fully qualified names by using the | 
|---|
| 590 |                         find() method if you need to. | 
|---|
| 591 |                 @param groupName The name of the resource group; this determines which  | 
|---|
| 592 |                         locations are searched.  | 
|---|
| 593 |                 @param searchGroupsIfNotFound If true, if the resource is not found in  | 
|---|
| 594 |                         the group specified, other groups will be searched. If you're | 
|---|
| 595 |                         loading a real Resource using this option, you <strong>must</strong> | 
|---|
| 596 |                         also provide the resourceBeingLoaded parameter to enable the  | 
|---|
| 597 |                         group membership to be changed | 
|---|
| 598 |                 @param resourceBeingLoaded Optional pointer to the resource being  | 
|---|
| 599 |                         loaded, which you should supply if you want | 
|---|
| 600 |                 @returns Shared pointer to data stream containing the data, will be | 
|---|
| 601 |                         destroyed automatically when no longer referenced | 
|---|
| 602 |                 */ | 
|---|
| 603 |                 DataStreamPtr openResource(const String& resourceName,  | 
|---|
| 604 |                         const String& groupName = DEFAULT_RESOURCE_GROUP_NAME, | 
|---|
| 605 |                         bool searchGroupsIfNotFound = true, Resource* resourceBeingLoaded = 0); | 
|---|
| 606 |  | 
|---|
| 607 |                 /** Open all resources matching a given pattern (which can contain | 
|---|
| 608 |                         the character '*' as a wildcard), and return a collection of  | 
|---|
| 609 |                         DataStream objects on them. | 
|---|
| 610 |                 @param pattern The pattern to look for. If resource locations have been | 
|---|
| 611 |                         added recursively, subdirectories will be searched too so this | 
|---|
| 612 |                         does not need to be fully qualified. | 
|---|
| 613 |                 @param groupName The resource group; this determines which locations | 
|---|
| 614 |                         are searched. | 
|---|
| 615 |                 @returns Shared pointer to a data stream list , will be | 
|---|
| 616 |                         destroyed automatically when no longer referenced | 
|---|
| 617 |                 */ | 
|---|
| 618 |                 DataStreamListPtr openResources(const String& pattern,  | 
|---|
| 619 |                         const String& groupName = DEFAULT_RESOURCE_GROUP_NAME); | 
|---|
| 620 |                  | 
|---|
| 621 |         /** List all file or directory names in a resource group. | 
|---|
| 622 |         @note | 
|---|
| 623 |         This method only returns filenames, you can also retrieve other | 
|---|
| 624 |         information using listFileInfo. | 
|---|
| 625 |         @param groupName The name of the group | 
|---|
| 626 |         @param dirs If true, directory names will be returned instead of file names | 
|---|
| 627 |         @returns A list of filenames matching the criteria, all are fully qualified | 
|---|
| 628 |         */ | 
|---|
| 629 |         StringVectorPtr listResourceNames(const String& groupName, bool dirs = false); | 
|---|
| 630 |  | 
|---|
| 631 |         /** List all files in a resource group with accompanying information. | 
|---|
| 632 |         @param groupName The name of the group | 
|---|
| 633 |         @param dirs If true, directory names will be returned instead of file names | 
|---|
| 634 |         @returns A list of structures detailing quite a lot of information about | 
|---|
| 635 |         all the files in the archive. | 
|---|
| 636 |         */ | 
|---|
| 637 |         FileInfoListPtr listResourceFileInfo(const String& groupName, bool dirs = false); | 
|---|
| 638 |  | 
|---|
| 639 |         /** Find all file or directory names matching a given pattern in a | 
|---|
| 640 |             resource group. | 
|---|
| 641 |         @note | 
|---|
| 642 |         This method only returns filenames, you can also retrieve other | 
|---|
| 643 |         information using findFileInfo. | 
|---|
| 644 |         @param groupName The name of the group | 
|---|
| 645 |         @param pattern The pattern to search for; wildcards (*) are allowed | 
|---|
| 646 |         @param dirs Set to true if you want the directories to be listed | 
|---|
| 647 |             instead of files | 
|---|
| 648 |         @returns A list of filenames matching the criteria, all are fully qualified | 
|---|
| 649 |         */ | 
|---|
| 650 |         StringVectorPtr findResourceNames(const String& groupName, const String& pattern, | 
|---|
| 651 |             bool dirs = false); | 
|---|
| 652 |  | 
|---|
| 653 |         /** Find out if the named file exists in a group.  | 
|---|
| 654 |         @param group The name of the resource group | 
|---|
| 655 |         @param filename Fully qualified name of the file to test for | 
|---|
| 656 |         */ | 
|---|
| 657 |         bool resourceExists(const String& group, const String& filename); | 
|---|
| 658 |  | 
|---|
| 659 |         /** Find out if the named file exists in a group.  | 
|---|
| 660 |         @param group Pointer to the resource group | 
|---|
| 661 |         @param filename Fully qualified name of the file to test for | 
|---|
| 662 |         */ | 
|---|
| 663 |         bool resourceExists(ResourceGroup* group, const String& filename); | 
|---|
| 664 |                 /** Find the group in which a resource exists. | 
|---|
| 665 |                 @param filename Fully qualified name of the file the resource should be | 
|---|
| 666 |                         found as | 
|---|
| 667 |                 @returns Name of the resource group the resource was found in. An | 
|---|
| 668 |                         exception is thrown if the group could not be determined. | 
|---|
| 669 |                 */ | 
|---|
| 670 |                 const String& findGroupContainingResource(const String& filename); | 
|---|
| 671 |  | 
|---|
| 672 |         /** Find all files or directories matching a given pattern in a group | 
|---|
| 673 |             and get some detailed information about them. | 
|---|
| 674 |         @param group The name of the resource group | 
|---|
| 675 |         @param pattern The pattern to search for; wildcards (*) are allowed | 
|---|
| 676 |         @param dirs Set to true if you want the directories to be listed | 
|---|
| 677 |             instead of files | 
|---|
| 678 |         @returns A list of file information structures for all files matching  | 
|---|
| 679 |         the criteria. | 
|---|
| 680 |         */ | 
|---|
| 681 |         FileInfoListPtr findResourceFileInfo(const String& group, const String& pattern, | 
|---|
| 682 |             bool dirs = false); | 
|---|
| 683 |  | 
|---|
| 684 |          | 
|---|
| 685 |         /** Adds a ResourceGroupListener which will be called back during  | 
|---|
| 686 |             resource loading events.  | 
|---|
| 687 |         */ | 
|---|
| 688 |         void addResourceGroupListener(ResourceGroupListener* l); | 
|---|
| 689 |         /** Removes a ResourceGroupListener */ | 
|---|
| 690 |         void removeResourceGroupListener(ResourceGroupListener* l); | 
|---|
| 691 |  | 
|---|
| 692 |         /** Sets the resource group that 'world' resources will use. | 
|---|
| 693 |         @remarks | 
|---|
| 694 |             This is the group which should be used by SceneManagers implementing | 
|---|
| 695 |             world geometry when looking for their resources. Defaults to the  | 
|---|
| 696 |             DEFAULT_RESOURCE_GROUP_NAME but this can be altered. | 
|---|
| 697 |         */ | 
|---|
| 698 |         void setWorldResourceGroupName(const String& groupName) {mWorldGroupName = groupName;} | 
|---|
| 699 |  | 
|---|
| 700 |         /// Sets the resource group that 'world' resources will use. | 
|---|
| 701 |         const String& getWorldResourceGroupName(void) const { return mWorldGroupName; } | 
|---|
| 702 |  | 
|---|
| 703 |         /** Associates some world geometry with a resource group, causing it to  | 
|---|
| 704 |             be loaded / unloaded with the resource group. | 
|---|
| 705 |         @remarks | 
|---|
| 706 |             You would use this method to essentially defer a call to  | 
|---|
| 707 |             SceneManager::setWorldGeometry to the time when the resource group | 
|---|
| 708 |             is loaded. The advantage of this is that compatible scene managers  | 
|---|
| 709 |             will include the estimate of the number of loading stages for that | 
|---|
| 710 |             world geometry when the resource group begins loading, allowing you | 
|---|
| 711 |             to include that in a loading progress report.  | 
|---|
| 712 |         @param group The name of the resource group | 
|---|
| 713 |         @param worldGeometry The parameter which should be passed to setWorldGeometry | 
|---|
| 714 |         @param sceneManager The SceneManager which should be called | 
|---|
| 715 |         */ | 
|---|
| 716 |         void linkWorldGeometryToResourceGroup(const String& group,  | 
|---|
| 717 |             const String& worldGeometry, SceneManager* sceneManager); | 
|---|
| 718 |  | 
|---|
| 719 |         /** Clear any link to world geometry from a resource group. | 
|---|
| 720 |         @remarks | 
|---|
| 721 |             Basically undoes a previous call to linkWorldGeometryToResourceGroup. | 
|---|
| 722 |         */ | 
|---|
| 723 |         void unlinkWorldGeometryFromResourceGroup(const String& group); | 
|---|
| 724 |  | 
|---|
| 725 |         /** Shutdown all ResourceManagers, performed as part of clean-up. */ | 
|---|
| 726 |         void shutdownAll(void); | 
|---|
| 727 |  | 
|---|
| 728 |  | 
|---|
| 729 |         /** Internal method for registering a ResourceManager (which should be | 
|---|
| 730 |             a singleton). Creators of plugins can register new ResourceManagers | 
|---|
| 731 |             this way if they wish. | 
|---|
| 732 |                 @remarks | 
|---|
| 733 |                         ResourceManagers that wish to parse scripts must also call  | 
|---|
| 734 |                         _registerScriptLoader. | 
|---|
| 735 |         @param resourceType String identifying the resource type, must be unique. | 
|---|
| 736 |         @param rm Pointer to the ResourceManager instance. | 
|---|
| 737 |         */ | 
|---|
| 738 |         void _registerResourceManager(const String& resourceType, ResourceManager* rm); | 
|---|
| 739 |  | 
|---|
| 740 |         /** Internal method for unregistering a ResourceManager. | 
|---|
| 741 |                 @remarks | 
|---|
| 742 |                         ResourceManagers that wish to parse scripts must also call  | 
|---|
| 743 |                         _unregisterScriptLoader. | 
|---|
| 744 |         @param resourceType String identifying the resource type. | 
|---|
| 745 |         */ | 
|---|
| 746 |         void _unregisterResourceManager(const String& resourceType); | 
|---|
| 747 |  | 
|---|
| 748 |                 /** Get an iterator over the registered resource managers. | 
|---|
| 749 |                 */ | 
|---|
| 750 |                 ResourceManagerIterator getResourceManagerIterator() | 
|---|
| 751 |                 { return ResourceManagerIterator( | 
|---|
| 752 |                         mResourceManagerMap.begin(), mResourceManagerMap.end()); } | 
|---|
| 753 |  | 
|---|
| 754 |         /** Internal method for registering a ScriptLoader. | 
|---|
| 755 |                 @remarks ScriptLoaders parse scripts when resource groups are initialised. | 
|---|
| 756 |         @param su Pointer to the ScriptLoader instance. | 
|---|
| 757 |         */ | 
|---|
| 758 |         void _registerScriptLoader(ScriptLoader* su); | 
|---|
| 759 |  | 
|---|
| 760 |         /** Internal method for unregistering a ScriptLoader. | 
|---|
| 761 |         @param su Pointer to the ScriptLoader instance. | 
|---|
| 762 |         */ | 
|---|
| 763 |         void _unregisterScriptLoader(ScriptLoader* su); | 
|---|
| 764 |  | 
|---|
| 765 |                 /** Internal method for getting a registered ResourceManager. | 
|---|
| 766 |                 @param resourceType String identifying the resource type. | 
|---|
| 767 |                 */ | 
|---|
| 768 |                 ResourceManager* _getResourceManager(const String& resourceType); | 
|---|
| 769 |  | 
|---|
| 770 |                 /** Internal method called by ResourceManager when a resource is created. | 
|---|
| 771 |                 @param res Weak reference to resource | 
|---|
| 772 |                 */ | 
|---|
| 773 |                 void _notifyResourceCreated(ResourcePtr& res); | 
|---|
| 774 |  | 
|---|
| 775 |                 /** Internal method called by ResourceManager when a resource is removed. | 
|---|
| 776 |                 @param res Weak reference to resource | 
|---|
| 777 |                 */ | 
|---|
| 778 |                 void _notifyResourceRemoved(ResourcePtr& res); | 
|---|
| 779 |  | 
|---|
| 780 |                 /** Internale method to notify the group manager that a resource has | 
|---|
| 781 |                         changed group (only applicable for autodetect group) */ | 
|---|
| 782 |                 void _notifyResourceGroupChanged(const String& oldGroup, Resource* res); | 
|---|
| 783 |  | 
|---|
| 784 |                 /** Internal method called by ResourceManager when all resources  | 
|---|
| 785 |                         for that manager are removed. | 
|---|
| 786 |                 @param manager Pointer to the manager for which all resources are being removed | 
|---|
| 787 |                 */ | 
|---|
| 788 |                 void _notifyAllResourcesRemoved(ResourceManager* manager); | 
|---|
| 789 |  | 
|---|
| 790 |         /** Notify this manager that one stage of world geometry loading has been  | 
|---|
| 791 |             started. | 
|---|
| 792 |         @remarks | 
|---|
| 793 |             Custom SceneManagers which load custom world geometry should call this  | 
|---|
| 794 |             method the number of times equal to the value they return from  | 
|---|
| 795 |             SceneManager::estimateWorldGeometry while loading their geometry. | 
|---|
| 796 |         */ | 
|---|
| 797 |         void _notifyWorldGeometryStageStarted(const String& description); | 
|---|
| 798 |         /** Notify this manager that one stage of world geometry loading has been  | 
|---|
| 799 |             completed. | 
|---|
| 800 |         @remarks | 
|---|
| 801 |             Custom SceneManagers which load custom world geometry should call this  | 
|---|
| 802 |             method the number of times equal to the value they return from  | 
|---|
| 803 |             SceneManager::estimateWorldGeometry while loading their geometry. | 
|---|
| 804 |         */ | 
|---|
| 805 |         void _notifyWorldGeometryStageEnded(void); | 
|---|
| 806 |  | 
|---|
| 807 |                 /** Get a list of the currently defined resource groups.  | 
|---|
| 808 |                 @note This method intentionally returns a copy rather than a reference in | 
|---|
| 809 |                         order to avoid any contention issues in multithreaded applications. | 
|---|
| 810 |                 @returns A copy of list of currently defined groups. | 
|---|
| 811 |                 */ | 
|---|
| 812 |                 StringVector getResourceGroups(void); | 
|---|
| 813 |                 /** Get the list of resource declarations for the specified group name.  | 
|---|
| 814 |                 @note This method intentionally returns a copy rather than a reference in | 
|---|
| 815 |                         order to avoid any contention issues in multithreaded applications. | 
|---|
| 816 |                 @param groupName The name of the group | 
|---|
| 817 |                 @returns A copy of list of currently defined resources. | 
|---|
| 818 |                 */ | 
|---|
| 819 |                 ResourceDeclarationList getResourceDeclarationList(const String& groupName); | 
|---|
| 820 |  | 
|---|
| 821 |  | 
|---|
| 822 |                 /** Override standard Singleton retrieval. | 
|---|
| 823 |         @remarks | 
|---|
| 824 |         Why do we do this? Well, it's because the Singleton | 
|---|
| 825 |         implementation is in a .h file, which means it gets compiled | 
|---|
| 826 |         into anybody who includes it. This is needed for the | 
|---|
| 827 |         Singleton template to work, but we actually only want it | 
|---|
| 828 |         compiled into the implementation of the class based on the | 
|---|
| 829 |         Singleton, not all of them. If we don't change this, we get | 
|---|
| 830 |         link errors when trying to use the Singleton-based class from | 
|---|
| 831 |         an outside dll. | 
|---|
| 832 |         @par | 
|---|
| 833 |         This method just delegates to the template version anyway, | 
|---|
| 834 |         but the implementation stays in this single compilation unit, | 
|---|
| 835 |         preventing link errors. | 
|---|
| 836 |         */ | 
|---|
| 837 |         static ResourceGroupManager& getSingleton(void); | 
|---|
| 838 |         /** Override standard Singleton retrieval. | 
|---|
| 839 |         @remarks | 
|---|
| 840 |         Why do we do this? Well, it's because the Singleton | 
|---|
| 841 |         implementation is in a .h file, which means it gets compiled | 
|---|
| 842 |         into anybody who includes it. This is needed for the | 
|---|
| 843 |         Singleton template to work, but we actually only want it | 
|---|
| 844 |         compiled into the implementation of the class based on the | 
|---|
| 845 |         Singleton, not all of them. If we don't change this, we get | 
|---|
| 846 |         link errors when trying to use the Singleton-based class from | 
|---|
| 847 |         an outside dll. | 
|---|
| 848 |         @par | 
|---|
| 849 |         This method just delegates to the template version anyway, | 
|---|
| 850 |         but the implementation stays in this single compilation unit, | 
|---|
| 851 |         preventing link errors. | 
|---|
| 852 |         */ | 
|---|
| 853 |         static ResourceGroupManager* getSingletonPtr(void); | 
|---|
| 854 |  | 
|---|
| 855 |     }; | 
|---|
| 856 | } | 
|---|
| 857 |  | 
|---|
| 858 | #endif | 
|---|