现在的位置: 首页 > 综合 > 正文

菜鸟学习OGRE和天龙八部之十八: 获得档案(Archive)文件列表

2013年06月10日 ⁄ 综合 ⁄ 共 2427字 ⁄ 字号 评论关闭

要获得档案文件的文件列表,只要获得Archive的指针,就可以调用list()函数获得文件列表

 

但是如何获得Archive的指针呢,先看看资源的载入过程:

 

先从resources.cfg文件获取资源的路径,资源组,资源文件类型,这3个数据:

 ConfigFile cf;
 cf.load("resources.cfg");

 

再把这3个数据传入资源定位的函数:

ResourceGroupManager::getSingleton().addResourceLocation(archName, typeName, secName);

资源定位到底做了什么,看看源码:

  1.   void ResourceGroupManager::addResourceLocation(const String& name,   
  2.       const String& locType, const String& resGroup, bool recursive)  
  3.   {  
  4.       ResourceGroup* grp = getResourceGroup(resGroup);  
  5.       if (!grp)  
  6.       {  
  7.           createResourceGroup(resGroup);  
  8.           grp = getResourceGroup(resGroup);  
  9.       }  
  10.   
  11. OGRE_LOCK_MUTEX(grp->OGRE_AUTO_MUTEX_NAME) // lock group mutex  
  12.   
  13.       // Get archive  
  14.       Archive* pArch = ArchiveManager::getSingleton().load( name, locType );  
  15.       // Add to location list  
  16. ResourceLocation* loc = new ResourceLocation();  
  17. loc->archive = pArch;  
  18. loc->recursive = recursive;  
  19.       grp->locationList.push_back(loc);  
  20.       // Index resources  
  21.       StringVectorPtr vec = pArch->find("*", recursive);  
  22.       for( StringVector::iterator it = vec->begin(); it != vec->end(); ++it )  
  23.       {  
  24.     // Index under full name, case sensitive  
  25.           grp->resourceIndexCaseSensitive[(*it)] = pArch;  
  26.           if (!pArch->isCaseSensitive())  
  27.           {  
  28.            // Index under lower case name too for case insensitive match  
  29.             String indexName = (*it);  
  30.               StringUtil::toLowerCase(indexName);  
  31.            grp->resourceIndexCaseInsensitive[indexName] = pArch;  
  32.           }  
  33.       }  
  34.   
  35. StringUtil::StrStreamType msg;  
  36. msg << "Added resource location '" << name << "' of type '" << locType  
  37.     << "' to resource group '" << resGroup << "'";  
  38. if (recursive)  
  39.     msg << " with recursive option";  
  40. LogManager::getSingleton().logMessage(msg.str());  
  41.   
  42.   }  

 

我们可以看到

        // 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 );

如果已经载入了一次,我们再载入一次,会发现什么情况

  1. Archive* ArchiveManager::load( const String& filename, 

抱歉!评论已关闭.