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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 | #include "OgreStableHeaders.h"
|
---|
26 | #include "OgreResourceGroupManager.h"
|
---|
27 | #include "OgreException.h"
|
---|
28 | #include "OgreArchive.h"
|
---|
29 | #include "OgreArchiveManager.h"
|
---|
30 | #include "OgreLogManager.h"
|
---|
31 | #include "OgreScriptLoader.h"
|
---|
32 | #include "OgreSceneManager.h"
|
---|
33 |
|
---|
34 | namespace Ogre {
|
---|
35 |
|
---|
36 | //-----------------------------------------------------------------------
|
---|
37 | template<> ResourceGroupManager* Singleton<ResourceGroupManager>::ms_Singleton = 0;
|
---|
38 | ResourceGroupManager* ResourceGroupManager::getSingletonPtr(void)
|
---|
39 | {
|
---|
40 | return ms_Singleton;
|
---|
41 | }
|
---|
42 | ResourceGroupManager& ResourceGroupManager::getSingleton(void)
|
---|
43 | {
|
---|
44 | assert( ms_Singleton ); return ( *ms_Singleton );
|
---|
45 | }
|
---|
46 | String ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME = "General";
|
---|
47 | String ResourceGroupManager::BOOTSTRAP_RESOURCE_GROUP_NAME = "Bootstrap";
|
---|
48 | //-----------------------------------------------------------------------
|
---|
49 | //-----------------------------------------------------------------------
|
---|
50 | ResourceGroupManager::ResourceGroupManager()
|
---|
51 | : mCurrentGroup(0)
|
---|
52 | {
|
---|
53 | // Create the 'General' group
|
---|
54 | createResourceGroup(DEFAULT_RESOURCE_GROUP_NAME);
|
---|
55 | // default world group to the default group
|
---|
56 | mWorldGroupName = DEFAULT_RESOURCE_GROUP_NAME;
|
---|
57 | }
|
---|
58 | //-----------------------------------------------------------------------
|
---|
59 | ResourceGroupManager::~ResourceGroupManager()
|
---|
60 | {
|
---|
61 | // delete all resource groups
|
---|
62 | ResourceGroupMap::iterator i, iend;
|
---|
63 | iend = mResourceGroupMap.end();
|
---|
64 | for (i = mResourceGroupMap.begin(); i != iend; ++i)
|
---|
65 | {
|
---|
66 | deleteGroup(i->second);
|
---|
67 | }
|
---|
68 | mResourceGroupMap.clear();
|
---|
69 | }
|
---|
70 | //-----------------------------------------------------------------------
|
---|
71 | void ResourceGroupManager::createResourceGroup(const String& name)
|
---|
72 | {
|
---|
73 | OGRE_LOCK_AUTO_MUTEX
|
---|
74 |
|
---|
75 | LogManager::getSingleton().logMessage("Creating resource group " + name);
|
---|
76 | if (getResourceGroup(name))
|
---|
77 | {
|
---|
78 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
|
---|
79 | "Resource group with name '" + name + "' already exists!",
|
---|
80 | "ResourceGroupManager::createResourceGroup");
|
---|
81 | }
|
---|
82 | ResourceGroup* grp = new ResourceGroup();
|
---|
83 | grp->initialised = false;
|
---|
84 | grp->name = name;
|
---|
85 | grp->worldGeometrySceneManager = 0;
|
---|
86 | mResourceGroupMap.insert(
|
---|
87 | ResourceGroupMap::value_type(name, grp));
|
---|
88 | }
|
---|
89 | //-----------------------------------------------------------------------
|
---|
90 | void ResourceGroupManager::initialiseResourceGroup(const String& name)
|
---|
91 | {
|
---|
92 | OGRE_LOCK_AUTO_MUTEX
|
---|
93 | LogManager::getSingleton().logMessage("Initialising resource group " + name);
|
---|
94 | ResourceGroup* grp = getResourceGroup(name);
|
---|
95 | if (!grp)
|
---|
96 | {
|
---|
97 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
98 | "Cannot find a group named " + name,
|
---|
99 | "ResourceGroupManager::parseResourceGroupScripts");
|
---|
100 | }
|
---|
101 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
102 |
|
---|
103 | if (!grp->initialised)
|
---|
104 | {
|
---|
105 | // Set current group
|
---|
106 | mCurrentGroup = grp;
|
---|
107 | parseResourceGroupScripts(grp);
|
---|
108 | createDeclaredResources(grp);
|
---|
109 | grp->initialised = true;
|
---|
110 |
|
---|
111 | // Reset current group
|
---|
112 | mCurrentGroup = 0;
|
---|
113 | }
|
---|
114 | }
|
---|
115 | //-----------------------------------------------------------------------
|
---|
116 | void ResourceGroupManager::initialiseAllResourceGroups(void)
|
---|
117 | {
|
---|
118 | OGRE_LOCK_AUTO_MUTEX
|
---|
119 |
|
---|
120 | // Intialise all declared resource groups
|
---|
121 | ResourceGroupMap::iterator i, iend;
|
---|
122 | iend = mResourceGroupMap.end();
|
---|
123 | for (i = mResourceGroupMap.begin(); i != iend; ++i)
|
---|
124 | {
|
---|
125 | ResourceGroup* grp = i->second;
|
---|
126 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
127 | if (!grp->initialised)
|
---|
128 | {
|
---|
129 | // Set current group
|
---|
130 | mCurrentGroup = grp;
|
---|
131 | parseResourceGroupScripts(grp);
|
---|
132 | createDeclaredResources(grp);
|
---|
133 | grp->initialised = true;
|
---|
134 | // Reset current group
|
---|
135 | mCurrentGroup = 0;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 | //-----------------------------------------------------------------------
|
---|
140 | void ResourceGroupManager::loadResourceGroup(const String& name,
|
---|
141 | bool loadMainResources, bool loadWorldGeom)
|
---|
142 | {
|
---|
143 | // Can only bulk-load one group at a time (reasonable limitation I think)
|
---|
144 | OGRE_LOCK_AUTO_MUTEX
|
---|
145 |
|
---|
146 | StringUtil::StrStreamType str;
|
---|
147 | str << "Loading resource group '" << name << "' - Resources: "
|
---|
148 | << loadMainResources << " World Geometry: " << loadWorldGeom;
|
---|
149 | LogManager::getSingleton().logMessage(str.str());
|
---|
150 | // load all created resources
|
---|
151 | ResourceGroup* grp = getResourceGroup(name);
|
---|
152 | if (!grp)
|
---|
153 | {
|
---|
154 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
155 | "Cannot find a group named " + name,
|
---|
156 | "ResourceGroupManager::loadResourceGroup");
|
---|
157 | }
|
---|
158 |
|
---|
159 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
160 | // Set current group
|
---|
161 | mCurrentGroup = grp;
|
---|
162 |
|
---|
163 | // Count up resources for starting event
|
---|
164 | ResourceGroup::LoadResourceOrderMap::iterator oi;
|
---|
165 | size_t resourceCount = 0;
|
---|
166 | if (loadMainResources)
|
---|
167 | {
|
---|
168 | for (oi = grp->loadResourceOrderMap.begin(); oi != grp->loadResourceOrderMap.end(); ++oi)
|
---|
169 | {
|
---|
170 | resourceCount += oi->second->size();
|
---|
171 | }
|
---|
172 | }
|
---|
173 | // Estimate world geometry size
|
---|
174 | if (grp->worldGeometrySceneManager && loadWorldGeom)
|
---|
175 | {
|
---|
176 | resourceCount +=
|
---|
177 | grp->worldGeometrySceneManager->estimateWorldGeometry(
|
---|
178 | grp->worldGeometry);
|
---|
179 | }
|
---|
180 |
|
---|
181 | fireResourceGroupLoadStarted(name, resourceCount);
|
---|
182 |
|
---|
183 | // Now load for real
|
---|
184 | if (loadMainResources)
|
---|
185 | {
|
---|
186 | for (oi = grp->loadResourceOrderMap.begin();
|
---|
187 | oi != grp->loadResourceOrderMap.end(); ++oi)
|
---|
188 | {
|
---|
189 | for (LoadUnloadResourceList::iterator l = oi->second->begin();
|
---|
190 | l != oi->second->end(); ++l)
|
---|
191 | {
|
---|
192 | // If loading one of these resources cascade-loads another resource,
|
---|
193 | // the list will get longer! But these should be loaded immediately
|
---|
194 | if (!(*l)->isLoaded())
|
---|
195 | {
|
---|
196 | fireResourceStarted(*l);
|
---|
197 | (*l)->load();
|
---|
198 | fireResourceEnded();
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|
202 | }
|
---|
203 | // Load World Geometry
|
---|
204 | if (grp->worldGeometrySceneManager && loadWorldGeom)
|
---|
205 | {
|
---|
206 | grp->worldGeometrySceneManager->setWorldGeometry(
|
---|
207 | grp->worldGeometry);
|
---|
208 | }
|
---|
209 | fireResourceGroupLoadEnded(name);
|
---|
210 |
|
---|
211 | // reset current group
|
---|
212 | mCurrentGroup = 0;
|
---|
213 |
|
---|
214 | LogManager::getSingleton().logMessage("Finished loading resource group " + name);
|
---|
215 | }
|
---|
216 | //-----------------------------------------------------------------------
|
---|
217 | void ResourceGroupManager::unloadResourceGroup(const String& name)
|
---|
218 | {
|
---|
219 | // Can only bulk-unload one group at a time (reasonable limitation I think)
|
---|
220 | OGRE_LOCK_AUTO_MUTEX
|
---|
221 |
|
---|
222 | LogManager::getSingleton().logMessage("Unloading resource group " + name);
|
---|
223 | ResourceGroup* grp = getResourceGroup(name);
|
---|
224 | if (!grp)
|
---|
225 | {
|
---|
226 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
227 | "Cannot find a group named " + name,
|
---|
228 | "ResourceGroupManager::unloadResourceGroup");
|
---|
229 | }
|
---|
230 | // Set current group
|
---|
231 | mCurrentGroup = grp;
|
---|
232 |
|
---|
233 | // Count up resources for starting event
|
---|
234 | ResourceGroup::LoadResourceOrderMap::reverse_iterator oi;
|
---|
235 | // unload in reverse order
|
---|
236 | for (oi = grp->loadResourceOrderMap.rbegin(); oi != grp->loadResourceOrderMap.rend(); ++oi)
|
---|
237 | {
|
---|
238 | for (LoadUnloadResourceList::iterator l = oi->second->begin();
|
---|
239 | l != oi->second->end(); ++l)
|
---|
240 | {
|
---|
241 | (*l)->unload();
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | // reset current group
|
---|
246 | mCurrentGroup = 0;
|
---|
247 | LogManager::getSingleton().logMessage("Finished unloading resource group " + name);
|
---|
248 | }
|
---|
249 | //-----------------------------------------------------------------------
|
---|
250 | void ResourceGroupManager::clearResourceGroup(const String& name)
|
---|
251 | {
|
---|
252 | // Can only bulk-clear one group at a time (reasonable limitation I think)
|
---|
253 | OGRE_LOCK_AUTO_MUTEX
|
---|
254 |
|
---|
255 | LogManager::getSingleton().logMessage("Clearing resource group " + name);
|
---|
256 | ResourceGroup* grp = getResourceGroup(name);
|
---|
257 | if (!grp)
|
---|
258 | {
|
---|
259 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
260 | "Cannot find a group named " + name,
|
---|
261 | "ResourceGroupManager::clearResourceGroup");
|
---|
262 | }
|
---|
263 | // set current group
|
---|
264 | mCurrentGroup = grp;
|
---|
265 | dropGroupContents(grp);
|
---|
266 | // clear initialised flag
|
---|
267 | grp->initialised = false;
|
---|
268 | // reset current group
|
---|
269 | mCurrentGroup = 0;
|
---|
270 | LogManager::getSingleton().logMessage("Finished clearing resource group " + name);
|
---|
271 | }
|
---|
272 | //-----------------------------------------------------------------------
|
---|
273 | void ResourceGroupManager::destroyResourceGroup(const String& name)
|
---|
274 | {
|
---|
275 | // Can only bulk-destroy one group at a time (reasonable limitation I think)
|
---|
276 | OGRE_LOCK_AUTO_MUTEX
|
---|
277 |
|
---|
278 | LogManager::getSingleton().logMessage("Destroying resource group " + name);
|
---|
279 | ResourceGroup* grp = getResourceGroup(name);
|
---|
280 | if (!grp)
|
---|
281 | {
|
---|
282 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
283 | "Cannot find a group named " + name,
|
---|
284 | "ResourceGroupManager::destroyResourceGroup");
|
---|
285 | }
|
---|
286 | // set current group
|
---|
287 | mCurrentGroup = grp;
|
---|
288 | unloadResourceGroup(name); // will throw an exception if name not valid
|
---|
289 | dropGroupContents(grp);
|
---|
290 | deleteGroup(grp);
|
---|
291 | mResourceGroupMap.erase(mResourceGroupMap.find(name));
|
---|
292 | // reset current group
|
---|
293 | mCurrentGroup = 0;
|
---|
294 | }
|
---|
295 | //-----------------------------------------------------------------------
|
---|
296 | void ResourceGroupManager::addResourceLocation(const String& name,
|
---|
297 | const String& locType, const String& resGroup, bool recursive)
|
---|
298 | {
|
---|
299 | ResourceGroup* grp = getResourceGroup(resGroup);
|
---|
300 | if (!grp)
|
---|
301 | {
|
---|
302 | createResourceGroup(resGroup);
|
---|
303 | grp = getResourceGroup(resGroup);
|
---|
304 | }
|
---|
305 |
|
---|
306 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
307 |
|
---|
308 | // Get archive
|
---|
309 | Archive* pArch = ArchiveManager::getSingleton().load( name, locType );
|
---|
310 | // Add to location list
|
---|
311 | ResourceLocation* loc = new ResourceLocation();
|
---|
312 | loc->archive = pArch;
|
---|
313 | loc->recursive = recursive;
|
---|
314 | grp->locationList.push_back(loc);
|
---|
315 | // Index resources
|
---|
316 | StringVectorPtr vec = pArch->find("*", recursive);
|
---|
317 | for( StringVector::iterator it = vec->begin(); it != vec->end(); ++it )
|
---|
318 | {
|
---|
319 | // Index under full name, case sensitive
|
---|
320 | grp->resourceIndexCaseSensitive[(*it)] = pArch;
|
---|
321 | if (!pArch->isCaseSensitive())
|
---|
322 | {
|
---|
323 | // Index under lower case name too for case insensitive match
|
---|
324 | String indexName = (*it);
|
---|
325 | StringUtil::toLowerCase(indexName);
|
---|
326 | grp->resourceIndexCaseInsensitive[indexName] = pArch;
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | StringUtil::StrStreamType msg;
|
---|
331 | msg << "Added resource location '" << name << "' of type '" << locType
|
---|
332 | << "' to resource group '" << resGroup << "'";
|
---|
333 | if (recursive)
|
---|
334 | msg << " with recursive option";
|
---|
335 | LogManager::getSingleton().logMessage(msg.str());
|
---|
336 |
|
---|
337 | }
|
---|
338 | //-----------------------------------------------------------------------
|
---|
339 | void ResourceGroupManager::removeResourceLocation(const String& name,
|
---|
340 | const String& resGroup)
|
---|
341 | {
|
---|
342 | ResourceGroup* grp = getResourceGroup(resGroup);
|
---|
343 | if (!grp)
|
---|
344 | {
|
---|
345 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
346 | "Cannot locate a resource group called '" + resGroup + "'",
|
---|
347 | "ResourceGroupManager::addResourceLocation");
|
---|
348 | }
|
---|
349 |
|
---|
350 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
351 |
|
---|
352 | // Remove from location list
|
---|
353 | LocationList::iterator li, liend;
|
---|
354 | liend = grp->locationList.end();
|
---|
355 | for (li = grp->locationList.begin(); li != liend; ++li)
|
---|
356 | {
|
---|
357 | Archive* pArch = (*li)->archive;
|
---|
358 | if (pArch->getName() == name)
|
---|
359 | {
|
---|
360 | // Delete indexes
|
---|
361 | ResourceLocationIndex::iterator rit, ritend;
|
---|
362 | ritend = grp->resourceIndexCaseInsensitive.end();
|
---|
363 | for (rit = grp->resourceIndexCaseInsensitive.begin(); rit != ritend;)
|
---|
364 | {
|
---|
365 | if (rit->second == pArch)
|
---|
366 | {
|
---|
367 | ResourceLocationIndex::iterator del = rit++;
|
---|
368 | grp->resourceIndexCaseInsensitive.erase(del);
|
---|
369 | }
|
---|
370 | else
|
---|
371 | {
|
---|
372 | ++rit;
|
---|
373 | }
|
---|
374 | }
|
---|
375 | ritend = grp->resourceIndexCaseSensitive.end();
|
---|
376 | for (rit = grp->resourceIndexCaseSensitive.begin(); rit != ritend;)
|
---|
377 | {
|
---|
378 | if (rit->second == pArch)
|
---|
379 | {
|
---|
380 | ResourceLocationIndex::iterator del = rit++;
|
---|
381 | grp->resourceIndexCaseSensitive.erase(del);
|
---|
382 | }
|
---|
383 | else
|
---|
384 | {
|
---|
385 | ++rit;
|
---|
386 | }
|
---|
387 | }
|
---|
388 | // Erase list entry
|
---|
389 | delete *li;
|
---|
390 | grp->locationList.erase(li);
|
---|
391 | break;
|
---|
392 | }
|
---|
393 |
|
---|
394 | }
|
---|
395 |
|
---|
396 | LogManager::getSingleton().logMessage("Removed resource location " + name);
|
---|
397 |
|
---|
398 |
|
---|
399 | }
|
---|
400 | //-----------------------------------------------------------------------
|
---|
401 | void ResourceGroupManager::declareResource(const String& name,
|
---|
402 | const String& resourceType, const String& groupName,
|
---|
403 | const NameValuePairList& loadParameters)
|
---|
404 | {
|
---|
405 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
406 | if (!grp)
|
---|
407 | {
|
---|
408 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
409 | "Cannot find a group named " + groupName,
|
---|
410 | "ResourceGroupManager::declareResource");
|
---|
411 | }
|
---|
412 |
|
---|
413 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
414 |
|
---|
415 | ResourceDeclaration dcl;
|
---|
416 | dcl.parameters = loadParameters;
|
---|
417 | dcl.resourceName = name;
|
---|
418 | dcl.resourceType = resourceType;
|
---|
419 | grp->resourceDeclarations.push_back(dcl);
|
---|
420 | }
|
---|
421 | //-----------------------------------------------------------------------
|
---|
422 | void ResourceGroupManager::undeclareResource(const String& name,
|
---|
423 | const String& groupName)
|
---|
424 | {
|
---|
425 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
426 | if (!grp)
|
---|
427 | {
|
---|
428 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
429 | "Cannot find a group named " + groupName,
|
---|
430 | "ResourceGroupManager::undeclareResource");
|
---|
431 | }
|
---|
432 |
|
---|
433 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
434 |
|
---|
435 | for (ResourceDeclarationList::iterator i = grp->resourceDeclarations.begin();
|
---|
436 | i != grp->resourceDeclarations.end(); ++i)
|
---|
437 | {
|
---|
438 | if (i->resourceName == name)
|
---|
439 | {
|
---|
440 | grp->resourceDeclarations.erase(i);
|
---|
441 | break;
|
---|
442 | }
|
---|
443 | }
|
---|
444 | }
|
---|
445 | //-----------------------------------------------------------------------
|
---|
446 | DataStreamPtr ResourceGroupManager::openResource(
|
---|
447 | const String& resourceName, const String& groupName)
|
---|
448 | {
|
---|
449 | // Try to find in resource index first
|
---|
450 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
451 | if (!grp)
|
---|
452 | {
|
---|
453 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
454 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
455 | "ResourceGroupManager::openResource");
|
---|
456 | }
|
---|
457 |
|
---|
458 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
459 |
|
---|
460 | Archive* pArch = 0;
|
---|
461 | ResourceLocationIndex::iterator rit = grp->resourceIndexCaseSensitive.find(resourceName);
|
---|
462 | if (rit != grp->resourceIndexCaseSensitive.end())
|
---|
463 | {
|
---|
464 | // Found in the index
|
---|
465 | pArch = rit->second;
|
---|
466 | return pArch->open(resourceName);
|
---|
467 | }
|
---|
468 | else
|
---|
469 | {
|
---|
470 | // try case insensitive
|
---|
471 | String lcResourceName = resourceName;
|
---|
472 | StringUtil::toLowerCase(lcResourceName);
|
---|
473 | rit = grp->resourceIndexCaseInsensitive.find(lcResourceName);
|
---|
474 | if (rit != grp->resourceIndexCaseInsensitive.end())
|
---|
475 | {
|
---|
476 | // Found in the index
|
---|
477 | pArch = rit->second;
|
---|
478 | return pArch->open(resourceName);
|
---|
479 | }
|
---|
480 | else
|
---|
481 | {
|
---|
482 | // Search the hard way
|
---|
483 | LocationList::iterator li, liend;
|
---|
484 | liend = grp->locationList.end();
|
---|
485 | for (li = grp->locationList.begin(); li != liend; ++li)
|
---|
486 | {
|
---|
487 | Archive* arch = (*li)->archive;
|
---|
488 | if (arch->exists(resourceName))
|
---|
489 | {
|
---|
490 | DataStreamPtr ptr = arch->open(resourceName);
|
---|
491 | return ptr;
|
---|
492 | }
|
---|
493 | }
|
---|
494 | }
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | // Not found
|
---|
499 | OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, "Cannot locate resource " +
|
---|
500 | resourceName + " in resource group " + groupName + ".",
|
---|
501 | "ResourceGroupManager::openResource");
|
---|
502 |
|
---|
503 | // Keep compiler happy
|
---|
504 | return DataStreamPtr();
|
---|
505 |
|
---|
506 |
|
---|
507 | }
|
---|
508 | //-----------------------------------------------------------------------
|
---|
509 | DataStreamListPtr ResourceGroupManager::openResources(
|
---|
510 | const String& pattern, const String& groupName)
|
---|
511 | {
|
---|
512 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
513 | if (!grp)
|
---|
514 | {
|
---|
515 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
516 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
517 | "ResourceGroupManager::openResources");
|
---|
518 | }
|
---|
519 |
|
---|
520 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
521 |
|
---|
522 | // Iterate through all the archives and build up a combined list of
|
---|
523 | // streams
|
---|
524 | DataStreamListPtr ret = DataStreamListPtr(new DataStreamList());
|
---|
525 |
|
---|
526 | LocationList::iterator li, liend;
|
---|
527 | liend = grp->locationList.end();
|
---|
528 | for (li = grp->locationList.begin(); li != liend; ++li)
|
---|
529 | {
|
---|
530 | Archive* arch = (*li)->archive;
|
---|
531 | // Find all the names based on whether this archive is recursive
|
---|
532 | StringVectorPtr names = arch->find(pattern, (*li)->recursive);
|
---|
533 |
|
---|
534 | // Iterate over the names and load a stream for each
|
---|
535 | for (StringVector::iterator ni = names->begin(); ni != names->end(); ++ni)
|
---|
536 | {
|
---|
537 | DataStreamPtr ptr = arch->open(*ni);
|
---|
538 | if (!ptr.isNull())
|
---|
539 | {
|
---|
540 | ret->push_back(ptr);
|
---|
541 | }
|
---|
542 | }
|
---|
543 | }
|
---|
544 | return ret;
|
---|
545 |
|
---|
546 | }
|
---|
547 | //-----------------------------------------------------------------------
|
---|
548 | void ResourceGroupManager::addResourceGroupListener(ResourceGroupListener* l)
|
---|
549 | {
|
---|
550 | OGRE_LOCK_AUTO_MUTEX
|
---|
551 |
|
---|
552 | mResourceGroupListenerList.push_back(l);
|
---|
553 | }
|
---|
554 | //-----------------------------------------------------------------------
|
---|
555 | void ResourceGroupManager::removeResourceGroupListener(ResourceGroupListener* l)
|
---|
556 | {
|
---|
557 | OGRE_LOCK_AUTO_MUTEX
|
---|
558 |
|
---|
559 | for (ResourceGroupListenerList::iterator i = mResourceGroupListenerList.begin();
|
---|
560 | i != mResourceGroupListenerList.end(); ++i)
|
---|
561 | {
|
---|
562 | if (*i == l)
|
---|
563 | {
|
---|
564 | mResourceGroupListenerList.erase(i);
|
---|
565 | break;
|
---|
566 | }
|
---|
567 | }
|
---|
568 | }
|
---|
569 | //-----------------------------------------------------------------------
|
---|
570 | void ResourceGroupManager::_registerResourceManager(
|
---|
571 | const String& resourceType, ResourceManager* rm)
|
---|
572 | {
|
---|
573 | OGRE_LOCK_AUTO_MUTEX
|
---|
574 |
|
---|
575 | LogManager::getSingleton().logMessage(
|
---|
576 | "Registering ResourceManager for type " + resourceType);
|
---|
577 | mResourceManagerMap[resourceType] = rm;
|
---|
578 | }
|
---|
579 | //-----------------------------------------------------------------------
|
---|
580 | void ResourceGroupManager::_unregisterResourceManager(
|
---|
581 | const String& resourceType)
|
---|
582 | {
|
---|
583 | OGRE_LOCK_AUTO_MUTEX
|
---|
584 |
|
---|
585 | LogManager::getSingleton().logMessage(
|
---|
586 | "Unregistering ResourceManager for type " + resourceType);
|
---|
587 |
|
---|
588 | ResourceManagerMap::iterator i = mResourceManagerMap.find(resourceType);
|
---|
589 | if (i != mResourceManagerMap.end())
|
---|
590 | {
|
---|
591 | mResourceManagerMap.erase(i);
|
---|
592 | }
|
---|
593 | }
|
---|
594 | //-----------------------------------------------------------------------
|
---|
595 | void ResourceGroupManager::_registerScriptLoader(ScriptLoader* su)
|
---|
596 | {
|
---|
597 | OGRE_LOCK_AUTO_MUTEX
|
---|
598 |
|
---|
599 | mScriptLoaderOrderMap.insert(
|
---|
600 | ScriptLoaderOrderMap::value_type(su->getLoadingOrder(), su));
|
---|
601 | }
|
---|
602 | //-----------------------------------------------------------------------
|
---|
603 | void ResourceGroupManager::_unregisterScriptLoader(ScriptLoader* su)
|
---|
604 | {
|
---|
605 | OGRE_LOCK_AUTO_MUTEX
|
---|
606 |
|
---|
607 | Real order = su->getLoadingOrder();
|
---|
608 | ScriptLoaderOrderMap::iterator oi = mScriptLoaderOrderMap.find(order);
|
---|
609 | while (oi != mScriptLoaderOrderMap.end() && oi->first == order)
|
---|
610 | {
|
---|
611 | if (oi->second == su)
|
---|
612 | {
|
---|
613 | // erase does not invalidate on multimap, except current
|
---|
614 | ScriptLoaderOrderMap::iterator del = oi++;
|
---|
615 | mScriptLoaderOrderMap.erase(del);
|
---|
616 | }
|
---|
617 | else
|
---|
618 | {
|
---|
619 | ++oi;
|
---|
620 | }
|
---|
621 | }
|
---|
622 | }
|
---|
623 | //-----------------------------------------------------------------------
|
---|
624 | void ResourceGroupManager::parseResourceGroupScripts(ResourceGroup* grp)
|
---|
625 | {
|
---|
626 |
|
---|
627 | LogManager::getSingleton().logMessage(
|
---|
628 | "Parsing scripts for resource group " + grp->name);
|
---|
629 |
|
---|
630 | // Count up the number of scripts we have to parse
|
---|
631 | typedef std::list<FileInfoListPtr> FileListList;
|
---|
632 | typedef SharedPtr<FileListList> FileListListPtr;
|
---|
633 | typedef std::pair<ScriptLoader*, FileListListPtr> LoaderFileListPair;
|
---|
634 | typedef std::list<LoaderFileListPair> ScriptLoaderFileList;
|
---|
635 | ScriptLoaderFileList scriptLoaderFileList;
|
---|
636 | size_t scriptCount = 0;
|
---|
637 | // Iterate over script users in loading order and get streams
|
---|
638 | ScriptLoaderOrderMap::iterator oi;
|
---|
639 | for (oi = mScriptLoaderOrderMap.begin();
|
---|
640 | oi != mScriptLoaderOrderMap.end(); ++oi)
|
---|
641 | {
|
---|
642 | ScriptLoader* su = oi->second;
|
---|
643 | FileListListPtr fileListList(new FileListList);
|
---|
644 |
|
---|
645 | // Get all the patterns and search them
|
---|
646 | const StringVector& patterns = su->getScriptPatterns();
|
---|
647 | for (StringVector::const_iterator p = patterns.begin(); p != patterns.end(); ++p)
|
---|
648 | {
|
---|
649 | FileInfoListPtr fileList = findResourceFileInfo(grp->name, *p);
|
---|
650 | scriptCount += fileList->size();
|
---|
651 | fileListList->push_back(fileList);
|
---|
652 | }
|
---|
653 | scriptLoaderFileList.push_back(
|
---|
654 | LoaderFileListPair(su, fileListList));
|
---|
655 | }
|
---|
656 | // Fire scripting event
|
---|
657 | fireResourceGroupScriptingStarted(grp->name, scriptCount);
|
---|
658 |
|
---|
659 | // Iterate over scripts and parse
|
---|
660 | // Note we respect original ordering
|
---|
661 | for (ScriptLoaderFileList::iterator slfli = scriptLoaderFileList.begin();
|
---|
662 | slfli != scriptLoaderFileList.end(); ++slfli)
|
---|
663 | {
|
---|
664 | ScriptLoader* su = slfli->first;
|
---|
665 | // Iterate over each list
|
---|
666 | for (FileListList::iterator flli = slfli->second->begin(); flli != slfli->second->end(); ++flli)
|
---|
667 | {
|
---|
668 | // Iterate over each item in the list
|
---|
669 | for (FileInfoList::iterator fii = (*flli)->begin(); fii != (*flli)->end(); ++fii)
|
---|
670 | {
|
---|
671 | LogManager::getSingleton().logMessage(
|
---|
672 | "Parsing script " + fii->filename);
|
---|
673 | fireScriptStarted(fii->filename);
|
---|
674 | {
|
---|
675 | DataStreamPtr stream = fii->archive->open(fii->filename);
|
---|
676 | if (!stream.isNull())
|
---|
677 | {
|
---|
678 | su->parseScript(stream, grp->name);
|
---|
679 | }
|
---|
680 | }
|
---|
681 | fireScriptEnded();
|
---|
682 | }
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 | fireResourceGroupScriptingEnded(grp->name);
|
---|
687 | LogManager::getSingleton().logMessage(
|
---|
688 | "Finished parsing scripts for resource group " + grp->name);
|
---|
689 | }
|
---|
690 | //-----------------------------------------------------------------------
|
---|
691 | void ResourceGroupManager::createDeclaredResources(ResourceGroup* grp)
|
---|
692 | {
|
---|
693 |
|
---|
694 | for (ResourceDeclarationList::iterator i = grp->resourceDeclarations.begin();
|
---|
695 | i != grp->resourceDeclarations.end(); ++i)
|
---|
696 | {
|
---|
697 | ResourceDeclaration& dcl = *i;
|
---|
698 | // Retrieve the appropriate manager
|
---|
699 | ResourceManager* mgr = _getResourceManager(dcl.resourceType);
|
---|
700 | // Create the resource
|
---|
701 | ResourcePtr res = mgr->create(dcl.resourceName, grp->name);
|
---|
702 | // Set custom parameters
|
---|
703 | res->setParameterList(dcl.parameters);
|
---|
704 | // Add resource to load list
|
---|
705 | ResourceGroup::LoadResourceOrderMap::iterator li =
|
---|
706 | grp->loadResourceOrderMap.find(mgr->getLoadingOrder());
|
---|
707 | LoadUnloadResourceList* loadList;
|
---|
708 | if (li == grp->loadResourceOrderMap.end())
|
---|
709 | {
|
---|
710 | loadList = new LoadUnloadResourceList();
|
---|
711 | grp->loadResourceOrderMap[mgr->getLoadingOrder()] = loadList;
|
---|
712 | }
|
---|
713 | else
|
---|
714 | {
|
---|
715 | loadList = li->second;
|
---|
716 | }
|
---|
717 | loadList->push_back(res);
|
---|
718 |
|
---|
719 | }
|
---|
720 |
|
---|
721 | }
|
---|
722 | //-----------------------------------------------------------------------
|
---|
723 | void ResourceGroupManager::_notifyResourceCreated(ResourcePtr& res)
|
---|
724 | {
|
---|
725 | if (mCurrentGroup)
|
---|
726 | {
|
---|
727 | // Use current group (batch loading)
|
---|
728 | addCreatedResource(res, *mCurrentGroup);
|
---|
729 | }
|
---|
730 | else
|
---|
731 | {
|
---|
732 | // Find group
|
---|
733 | ResourceGroup* grp = getResourceGroup(res->getGroup());
|
---|
734 | if (grp)
|
---|
735 | {
|
---|
736 | addCreatedResource(res, *grp);
|
---|
737 | }
|
---|
738 | }
|
---|
739 | }
|
---|
740 | //-----------------------------------------------------------------------
|
---|
741 | void ResourceGroupManager::_notifyResourceRemoved(ResourcePtr& res)
|
---|
742 | {
|
---|
743 | if (mCurrentGroup)
|
---|
744 | {
|
---|
745 | // Do nothing - we're batch unloading so list will be cleared
|
---|
746 | }
|
---|
747 | else
|
---|
748 | {
|
---|
749 | // Find group
|
---|
750 | ResourceGroup* grp = getResourceGroup(res->getGroup());
|
---|
751 | if (grp)
|
---|
752 | {
|
---|
753 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
754 | ResourceGroup::LoadResourceOrderMap::iterator i =
|
---|
755 | grp->loadResourceOrderMap.find(
|
---|
756 | res->getCreator()->getLoadingOrder());
|
---|
757 | if (i != grp->loadResourceOrderMap.end())
|
---|
758 | {
|
---|
759 | // Iterate over the resource list and remove
|
---|
760 | LoadUnloadResourceList* resList = i->second;
|
---|
761 | for (LoadUnloadResourceList::iterator l = resList->begin();
|
---|
762 | l != resList->end(); ++ l)
|
---|
763 | {
|
---|
764 | if ((*l).getPointer() == res.getPointer())
|
---|
765 | {
|
---|
766 | // this is the one
|
---|
767 | resList->erase(l);
|
---|
768 | break;
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 | }
|
---|
773 | }
|
---|
774 | }
|
---|
775 | //-----------------------------------------------------------------------
|
---|
776 | void ResourceGroupManager::_notifyAllResourcesRemoved(ResourceManager* manager)
|
---|
777 | {
|
---|
778 | OGRE_LOCK_AUTO_MUTEX
|
---|
779 |
|
---|
780 | // Iterate over all groups
|
---|
781 | for (ResourceGroupMap::iterator grpi = mResourceGroupMap.begin();
|
---|
782 | grpi != mResourceGroupMap.end(); ++grpi)
|
---|
783 | {
|
---|
784 | OGRE_LOCK_MUTEX(grpi->second->OGRE_AUTO_MUTEX_NAME)
|
---|
785 | // Iterate over all priorities
|
---|
786 | for (ResourceGroup::LoadResourceOrderMap::iterator oi = grpi->second->loadResourceOrderMap.begin();
|
---|
787 | oi != grpi->second->loadResourceOrderMap.end(); ++oi)
|
---|
788 | {
|
---|
789 | // Iterate over all resources
|
---|
790 | for (LoadUnloadResourceList::iterator l = oi->second->begin();
|
---|
791 | l != oi->second->end(); )
|
---|
792 | {
|
---|
793 | if ((*l)->getCreator() == manager)
|
---|
794 | {
|
---|
795 | // Increment first since iterator will be invalidated
|
---|
796 | LoadUnloadResourceList::iterator del = l++;
|
---|
797 | oi->second->erase(del);
|
---|
798 | }
|
---|
799 | else
|
---|
800 | {
|
---|
801 | ++l;
|
---|
802 | }
|
---|
803 | }
|
---|
804 | }
|
---|
805 |
|
---|
806 | }
|
---|
807 | }
|
---|
808 | //-----------------------------------------------------------------------
|
---|
809 | void ResourceGroupManager::addCreatedResource(ResourcePtr& res, ResourceGroup& grp)
|
---|
810 | {
|
---|
811 | OGRE_LOCK_MUTEX(grp.OGRE_AUTO_MUTEX_NAME)
|
---|
812 | Real order = res->getCreator()->getLoadingOrder();
|
---|
813 |
|
---|
814 | ResourceGroup::LoadResourceOrderMap::iterator i = grp.loadResourceOrderMap.find(order);
|
---|
815 | LoadUnloadResourceList* loadList;
|
---|
816 | if (i == grp.loadResourceOrderMap.end())
|
---|
817 | {
|
---|
818 | loadList = new LoadUnloadResourceList();
|
---|
819 | grp.loadResourceOrderMap[order] = loadList;
|
---|
820 | }
|
---|
821 | else
|
---|
822 | {
|
---|
823 | loadList = i->second;
|
---|
824 | }
|
---|
825 | loadList->push_back(res);
|
---|
826 | }
|
---|
827 | //-----------------------------------------------------------------------
|
---|
828 | ResourceGroupManager::ResourceGroup* ResourceGroupManager::getResourceGroup(const String& name)
|
---|
829 | {
|
---|
830 | OGRE_LOCK_AUTO_MUTEX
|
---|
831 |
|
---|
832 | ResourceGroupMap::iterator i = mResourceGroupMap.find(name);
|
---|
833 | if (i != mResourceGroupMap.end())
|
---|
834 | {
|
---|
835 | return i->second;
|
---|
836 | }
|
---|
837 | return 0;
|
---|
838 |
|
---|
839 | }
|
---|
840 | //-----------------------------------------------------------------------
|
---|
841 | ResourceManager* ResourceGroupManager::_getResourceManager(const String& resourceType)
|
---|
842 | {
|
---|
843 | OGRE_LOCK_AUTO_MUTEX
|
---|
844 |
|
---|
845 | ResourceManagerMap::iterator i = mResourceManagerMap.find(resourceType);
|
---|
846 | if (i == mResourceManagerMap.end())
|
---|
847 | {
|
---|
848 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
849 | "Cannot locate resource manager for resource type '" +
|
---|
850 | resourceType + "'", "ResourceGroupManager::_getResourceManager");
|
---|
851 | }
|
---|
852 | return i->second;
|
---|
853 |
|
---|
854 | }
|
---|
855 | //-----------------------------------------------------------------------
|
---|
856 | void ResourceGroupManager::dropGroupContents(ResourceGroup* grp)
|
---|
857 | {
|
---|
858 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME)
|
---|
859 |
|
---|
860 | bool groupSet = false;
|
---|
861 | if (!mCurrentGroup)
|
---|
862 | {
|
---|
863 | // Set current group to indicate ignoring of notifications
|
---|
864 | mCurrentGroup = grp;
|
---|
865 | groupSet = true;
|
---|
866 | }
|
---|
867 | // delete all the load list entries
|
---|
868 | ResourceGroup::LoadResourceOrderMap::iterator j, jend;
|
---|
869 | jend = grp->loadResourceOrderMap.end();
|
---|
870 | for (j = grp->loadResourceOrderMap.begin(); j != jend; ++j)
|
---|
871 | {
|
---|
872 | // Iterate over resources
|
---|
873 | for (LoadUnloadResourceList::iterator k = j->second->begin();
|
---|
874 | k != j->second->end(); ++k)
|
---|
875 | {
|
---|
876 | (*k)->getCreator()->remove((*k)->getHandle());
|
---|
877 | }
|
---|
878 | delete j->second;
|
---|
879 | }
|
---|
880 | grp->loadResourceOrderMap.clear();
|
---|
881 |
|
---|
882 | if (groupSet)
|
---|
883 | {
|
---|
884 | mCurrentGroup = 0;
|
---|
885 | }
|
---|
886 | }
|
---|
887 | //-----------------------------------------------------------------------
|
---|
888 | void ResourceGroupManager::deleteGroup(ResourceGroup* grp)
|
---|
889 | {
|
---|
890 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME)
|
---|
891 | // delete all the load list entries
|
---|
892 | ResourceGroup::LoadResourceOrderMap::iterator j, jend;
|
---|
893 | jend = grp->loadResourceOrderMap.end();
|
---|
894 | for (j = grp->loadResourceOrderMap.begin(); j != jend; ++j)
|
---|
895 | {
|
---|
896 | // Don't iterate over resources to drop with ResourceManager
|
---|
897 | // Assume this is being done anyway since this is a shutdown method
|
---|
898 | delete j->second;
|
---|
899 | }
|
---|
900 | // Drop location list
|
---|
901 | for (LocationList::iterator ll = grp->locationList.begin();
|
---|
902 | ll != grp->locationList.end(); ++ll)
|
---|
903 | {
|
---|
904 | delete *ll;
|
---|
905 | }
|
---|
906 |
|
---|
907 | // delete ResourceGroup
|
---|
908 | delete grp;
|
---|
909 | }
|
---|
910 | //-----------------------------------------------------------------------
|
---|
911 | void ResourceGroupManager::fireResourceGroupScriptingStarted(const String& groupName, size_t scriptCount)
|
---|
912 | {
|
---|
913 | OGRE_LOCK_AUTO_MUTEX
|
---|
914 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
915 | l != mResourceGroupListenerList.end(); ++l)
|
---|
916 | {
|
---|
917 | (*l)->resourceGroupScriptingStarted(groupName, scriptCount);
|
---|
918 | }
|
---|
919 | }
|
---|
920 | //-----------------------------------------------------------------------
|
---|
921 | void ResourceGroupManager::fireScriptStarted(const String& scriptName)
|
---|
922 | {
|
---|
923 | OGRE_LOCK_AUTO_MUTEX
|
---|
924 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
925 | l != mResourceGroupListenerList.end(); ++l)
|
---|
926 | {
|
---|
927 | (*l)->scriptParseStarted(scriptName);
|
---|
928 | }
|
---|
929 | }
|
---|
930 | //-----------------------------------------------------------------------
|
---|
931 | void ResourceGroupManager::fireScriptEnded(void)
|
---|
932 | {
|
---|
933 | OGRE_LOCK_AUTO_MUTEX
|
---|
934 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
935 | l != mResourceGroupListenerList.end(); ++l)
|
---|
936 | {
|
---|
937 | (*l)->scriptParseEnded();
|
---|
938 | }
|
---|
939 | }
|
---|
940 | //-----------------------------------------------------------------------
|
---|
941 | void ResourceGroupManager::fireResourceGroupScriptingEnded(const String& groupName)
|
---|
942 | {
|
---|
943 | OGRE_LOCK_AUTO_MUTEX
|
---|
944 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
945 | l != mResourceGroupListenerList.end(); ++l)
|
---|
946 | {
|
---|
947 | (*l)->resourceGroupScriptingEnded(groupName);
|
---|
948 | }
|
---|
949 | }
|
---|
950 | //-----------------------------------------------------------------------
|
---|
951 | void ResourceGroupManager::fireResourceGroupLoadStarted(const String& groupName, size_t resourceCount)
|
---|
952 | {
|
---|
953 | OGRE_LOCK_AUTO_MUTEX
|
---|
954 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
955 | l != mResourceGroupListenerList.end(); ++l)
|
---|
956 | {
|
---|
957 | (*l)->resourceGroupLoadStarted(groupName, resourceCount);
|
---|
958 | }
|
---|
959 | }
|
---|
960 | //-----------------------------------------------------------------------
|
---|
961 | void ResourceGroupManager::fireResourceStarted(const ResourcePtr& resource)
|
---|
962 | {
|
---|
963 | OGRE_LOCK_AUTO_MUTEX
|
---|
964 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
965 | l != mResourceGroupListenerList.end(); ++l)
|
---|
966 | {
|
---|
967 | (*l)->resourceLoadStarted(resource);
|
---|
968 | }
|
---|
969 | }
|
---|
970 | //-----------------------------------------------------------------------
|
---|
971 | void ResourceGroupManager::fireResourceEnded(void)
|
---|
972 | {
|
---|
973 | OGRE_LOCK_AUTO_MUTEX
|
---|
974 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
975 | l != mResourceGroupListenerList.end(); ++l)
|
---|
976 | {
|
---|
977 | (*l)->resourceLoadEnded();
|
---|
978 | }
|
---|
979 | }
|
---|
980 | //-----------------------------------------------------------------------
|
---|
981 | void ResourceGroupManager::_notifyWorldGeometryStageStarted(const String& desc)
|
---|
982 | {
|
---|
983 | OGRE_LOCK_AUTO_MUTEX
|
---|
984 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
985 | l != mResourceGroupListenerList.end(); ++l)
|
---|
986 | {
|
---|
987 | (*l)->worldGeometryStageStarted(desc);
|
---|
988 | }
|
---|
989 | }
|
---|
990 | //-----------------------------------------------------------------------
|
---|
991 | void ResourceGroupManager::_notifyWorldGeometryStageEnded(void)
|
---|
992 | {
|
---|
993 | OGRE_LOCK_AUTO_MUTEX
|
---|
994 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
995 | l != mResourceGroupListenerList.end(); ++l)
|
---|
996 | {
|
---|
997 | (*l)->worldGeometryStageEnded();
|
---|
998 | }
|
---|
999 | }
|
---|
1000 | //-----------------------------------------------------------------------
|
---|
1001 | void ResourceGroupManager::fireResourceGroupLoadEnded(const String& groupName)
|
---|
1002 | {
|
---|
1003 | OGRE_LOCK_AUTO_MUTEX
|
---|
1004 | for (ResourceGroupListenerList::iterator l = mResourceGroupListenerList.begin();
|
---|
1005 | l != mResourceGroupListenerList.end(); ++l)
|
---|
1006 | {
|
---|
1007 | (*l)->resourceGroupLoadEnded(groupName);
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 | //-----------------------------------------------------------------------
|
---|
1011 | void ResourceGroupManager::shutdownAll(void)
|
---|
1012 | {
|
---|
1013 | OGRE_LOCK_AUTO_MUTEX
|
---|
1014 |
|
---|
1015 | ResourceManagerMap::iterator i, iend;
|
---|
1016 | iend = mResourceManagerMap.end();
|
---|
1017 | for (i = mResourceManagerMap.begin(); i != iend; ++i)
|
---|
1018 | {
|
---|
1019 | i->second->removeAll();
|
---|
1020 | }
|
---|
1021 | }
|
---|
1022 | //-----------------------------------------------------------------------
|
---|
1023 | StringVectorPtr ResourceGroupManager::listResourceNames(const String& groupName)
|
---|
1024 | {
|
---|
1025 | OGRE_LOCK_AUTO_MUTEX
|
---|
1026 | StringVectorPtr vec(new StringVector());
|
---|
1027 |
|
---|
1028 | // Try to find in resource index first
|
---|
1029 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
1030 | if (!grp)
|
---|
1031 | {
|
---|
1032 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1033 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
1034 | "ResourceGroupManager::listResourceNames");
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1038 |
|
---|
1039 | // Iterate over the archives
|
---|
1040 | LocationList::iterator i, iend;
|
---|
1041 | iend = grp->locationList.end();
|
---|
1042 | for (i = grp->locationList.begin(); i != iend; ++i)
|
---|
1043 | {
|
---|
1044 | StringVectorPtr lst = (*i)->archive->list((*i)->recursive);
|
---|
1045 | vec->insert(vec->end(), lst->begin(), lst->end());
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | return vec;
|
---|
1049 |
|
---|
1050 |
|
---|
1051 | }
|
---|
1052 | //-----------------------------------------------------------------------
|
---|
1053 | FileInfoListPtr ResourceGroupManager::listResourceFileInfo(const String& groupName)
|
---|
1054 | {
|
---|
1055 | OGRE_LOCK_AUTO_MUTEX
|
---|
1056 | FileInfoListPtr vec(new FileInfoList());
|
---|
1057 |
|
---|
1058 | // Try to find in resource index first
|
---|
1059 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
1060 | if (!grp)
|
---|
1061 | {
|
---|
1062 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1063 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
1064 | "ResourceGroupManager::listResourceFileInfo");
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1068 |
|
---|
1069 | // Iterate over the archives
|
---|
1070 | LocationList::iterator i, iend;
|
---|
1071 | iend = grp->locationList.end();
|
---|
1072 | for (i = grp->locationList.begin(); i != iend; ++i)
|
---|
1073 | {
|
---|
1074 | FileInfoListPtr lst = (*i)->archive->listFileInfo((*i)->recursive);
|
---|
1075 | vec->insert(vec->end(), lst->begin(), lst->end());
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | return vec;
|
---|
1079 |
|
---|
1080 | }
|
---|
1081 | //-----------------------------------------------------------------------
|
---|
1082 | StringVectorPtr ResourceGroupManager::findResourceNames(const String& groupName,
|
---|
1083 | const String& pattern)
|
---|
1084 | {
|
---|
1085 | OGRE_LOCK_AUTO_MUTEX
|
---|
1086 | StringVectorPtr vec(new StringVector());
|
---|
1087 |
|
---|
1088 | // Try to find in resource index first
|
---|
1089 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
1090 | if (!grp)
|
---|
1091 | {
|
---|
1092 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1093 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
1094 | "ResourceGroupManager::findResourceNames");
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1098 |
|
---|
1099 | // Iterate over the archives
|
---|
1100 | LocationList::iterator i, iend;
|
---|
1101 | iend = grp->locationList.end();
|
---|
1102 | for (i = grp->locationList.begin(); i != iend; ++i)
|
---|
1103 | {
|
---|
1104 | StringVectorPtr lst = (*i)->archive->find(pattern, (*i)->recursive);
|
---|
1105 | vec->insert(vec->end(), lst->begin(), lst->end());
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | return vec;
|
---|
1109 | }
|
---|
1110 | //-----------------------------------------------------------------------
|
---|
1111 | FileInfoListPtr ResourceGroupManager::findResourceFileInfo(const String& groupName,
|
---|
1112 | const String& pattern)
|
---|
1113 | {
|
---|
1114 | OGRE_LOCK_AUTO_MUTEX
|
---|
1115 | FileInfoListPtr vec(new FileInfoList());
|
---|
1116 |
|
---|
1117 | // Try to find in resource index first
|
---|
1118 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
1119 | if (!grp)
|
---|
1120 | {
|
---|
1121 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1122 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
1123 | "ResourceGroupManager::findResourceFileInfo");
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1127 |
|
---|
1128 | // Iterate over the archives
|
---|
1129 | LocationList::iterator i, iend;
|
---|
1130 | iend = grp->locationList.end();
|
---|
1131 | for (i = grp->locationList.begin(); i != iend; ++i)
|
---|
1132 | {
|
---|
1133 | FileInfoListPtr lst = (*i)->archive->findFileInfo(pattern, (*i)->recursive);
|
---|
1134 | vec->insert(vec->end(), lst->begin(), lst->end());
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | return vec;
|
---|
1138 | }
|
---|
1139 | //-----------------------------------------------------------------------
|
---|
1140 | bool ResourceGroupManager::resourceExists(const String& groupName, const String& resourceName)
|
---|
1141 | {
|
---|
1142 | OGRE_LOCK_AUTO_MUTEX
|
---|
1143 |
|
---|
1144 | // Try to find in resource index first
|
---|
1145 | ResourceGroup* grp = getResourceGroup(groupName);
|
---|
1146 | if (!grp)
|
---|
1147 | {
|
---|
1148 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1149 | "Cannot locate a resource group called '" + groupName + "'",
|
---|
1150 | "ResourceGroupManager::resourceExists");
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1154 |
|
---|
1155 | // Try indexes first
|
---|
1156 | ResourceLocationIndex::iterator rit = grp->resourceIndexCaseSensitive.find(resourceName);
|
---|
1157 | if (rit != grp->resourceIndexCaseSensitive.end())
|
---|
1158 | {
|
---|
1159 | // Found in the index
|
---|
1160 | return true;
|
---|
1161 | }
|
---|
1162 | else
|
---|
1163 | {
|
---|
1164 | // try case insensitive
|
---|
1165 | String lcResourceName = resourceName;
|
---|
1166 | StringUtil::toLowerCase(lcResourceName);
|
---|
1167 | rit = grp->resourceIndexCaseInsensitive.find(lcResourceName);
|
---|
1168 | if (rit != grp->resourceIndexCaseInsensitive.end())
|
---|
1169 | {
|
---|
1170 | // Found in the index
|
---|
1171 | return true;
|
---|
1172 | }
|
---|
1173 | else
|
---|
1174 | {
|
---|
1175 | // Search the hard way
|
---|
1176 | LocationList::iterator li, liend;
|
---|
1177 | liend = grp->locationList.end();
|
---|
1178 | for (li = grp->locationList.begin(); li != liend; ++li)
|
---|
1179 | {
|
---|
1180 | Archive* arch = (*li)->archive;
|
---|
1181 | if (arch->exists(resourceName))
|
---|
1182 | {
|
---|
1183 | return true;
|
---|
1184 | }
|
---|
1185 | }
|
---|
1186 | }
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | return false;
|
---|
1190 |
|
---|
1191 | }
|
---|
1192 | //-----------------------------------------------------------------------
|
---|
1193 | void ResourceGroupManager::linkWorldGeometryToResourceGroup(const String& group,
|
---|
1194 | const String& worldGeometry, SceneManager* sceneManager)
|
---|
1195 | {
|
---|
1196 | OGRE_LOCK_AUTO_MUTEX
|
---|
1197 | ResourceGroup* grp = getResourceGroup(group);
|
---|
1198 | if (!grp)
|
---|
1199 | {
|
---|
1200 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1201 | "Cannot locate a resource group called '" + group + "'",
|
---|
1202 | "ResourceGroupManager::linkWorldGeometryToResourceGroup");
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1206 |
|
---|
1207 | grp->worldGeometry = worldGeometry;
|
---|
1208 | grp->worldGeometrySceneManager = sceneManager;
|
---|
1209 | }
|
---|
1210 | //-----------------------------------------------------------------------
|
---|
1211 | void ResourceGroupManager::unlinkWorldGeometryFromResourceGroup(const String& group)
|
---|
1212 | {
|
---|
1213 | OGRE_LOCK_AUTO_MUTEX
|
---|
1214 | ResourceGroup* grp = getResourceGroup(group);
|
---|
1215 | if (!grp)
|
---|
1216 | {
|
---|
1217 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1218 | "Cannot locate a resource group called '" + group + "'",
|
---|
1219 | "ResourceGroupManager::unlinkWorldGeometryFromResourceGroup");
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1223 | grp->worldGeometry = StringUtil::BLANK;
|
---|
1224 | grp->worldGeometrySceneManager = 0;
|
---|
1225 | }
|
---|
1226 | //-----------------------------------------------------------------------
|
---|
1227 | StringVector ResourceGroupManager::getResourceGroups(void)
|
---|
1228 | {
|
---|
1229 | OGRE_LOCK_AUTO_MUTEX
|
---|
1230 | StringVector vec;
|
---|
1231 | for (ResourceGroupMap::iterator i = mResourceGroupMap.begin();
|
---|
1232 | i != mResourceGroupMap.end(); ++i)
|
---|
1233 | {
|
---|
1234 | vec.push_back(i->second->name);
|
---|
1235 | }
|
---|
1236 | return vec;
|
---|
1237 | }
|
---|
1238 | //-----------------------------------------------------------------------
|
---|
1239 | ResourceGroupManager::ResourceDeclarationList
|
---|
1240 | ResourceGroupManager::getResourceDeclarationList(const String& group)
|
---|
1241 | {
|
---|
1242 | OGRE_LOCK_AUTO_MUTEX
|
---|
1243 | ResourceGroup* grp = getResourceGroup(group);
|
---|
1244 | if (!grp)
|
---|
1245 | {
|
---|
1246 | OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
|
---|
1247 | "Cannot locate a resource group called '" + group + "'",
|
---|
1248 | "ResourceGroupManager::unlinkWorldGeometryFromResourceGroup");
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
|
---|
1252 | return grp->resourceDeclarations;
|
---|
1253 | }
|
---|
1254 | //-----------------------------------------------------------------------
|
---|
1255 | ScriptLoader::~ScriptLoader()
|
---|
1256 | {
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 |
|
---|
1260 | }
|
---|