要获得档案文件的文件列表,只要获得Archive的指针,就可以调用list()函数获得文件列表
但是如何获得Archive的指针呢,先看看资源的载入过程:
先从resources.cfg文件获取资源的路径,资源组,资源文件类型,这3个数据:
ConfigFile cf;
cf.load("resources.cfg");
再把这3个数据传入资源定位的函数:
ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);
资源定位到底做了什么,看看源码:
- void ResourceGroupManager::addResourceLocation(const String& name,
- const String& locType, const String& resGroup, bool recursive)
- {
- ResourceGroup* grp = getResourceGroup(resGroup);
- if (!grp)
- {
- createResourceGroup(resGroup);
- grp = getResourceGroup(resGroup);
- }
- OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex
- // Get archive
- Archive* pArch = ArchiveManager::getSingleton().load( name, locType );
- // Add to location list
- ResourceLocation* loc = new ResourceLocation();
- loc->archive = pArch;
- loc->recursive = recursive;
- grp->locationList.push_back(loc);
- // Index resources
- StringVectorPtr vec = pArch->find("*", recursive);
- for( StringVector::iterator it = vec->begin(); it != vec->end(); ++it )
- {
- // Index under full name, case sensitive
- grp->resourceIndexCaseSensitive[(*it)] = pArch;
- if (!pArch->isCaseSensitive())
- {
- // Index under lower case name too for case insensitive match
- String indexName = (*it);
- StringUtil::toLowerCase(indexName);
- grp->resourceIndexCaseInsensitive[indexName] = pArch;
- }
- }
- StringUtil::StrStreamType msg;
- msg << "Added resource location '" << name << "' of type '" << locType
- << "' to resource group '" << resGroup << "'";
- if (recursive)
- msg << " with recursive option";
- LogManager::getSingleton().logMessage(msg.str());
- }
我们可以看到
// Get archive
Archive* pArch = ArchiveManager::getSingleton().load( name, locType );
这里,载入档案的时候就返回了档案的指针,这就是我们需要的,接下来他把这个指针传到了2个地方
// Add to location list
ResourceLocation* loc = new ResourceLocation();
loc->archive = pArch; // 这里传入一次
// Index under full name, case sensitive
grp->resourceIndexCaseSensitive[(*it)] = pArch; // 这里再传入一次
理论上我们可以从这2个数据结构中获取指针,但是不幸的是,这些都是protected成员,获取不了的
而这个类又没有提供相关的获取函数,怎么办呢?难道又要改OGRE源码么?
看看前面的这个函数
// Get archive
Archive* pArch = ArchiveManager::getSingleton().load( name, locType );
如果已经载入了一次,我们再载入一次,会发现什么情况
- Archive* ArchiveManager::load( const String& filename,