您的位置:首页 > 移动开发 > Cocos引擎

COCOS2D-3.9 FileUtils 分析(二) 变量深入

2015-12-09 23:00 477 查看

std::string _defaultResRootPath;

作用 默认的资源文件的第一级目录,资源打包时都放入这个目录。

virtual bool init();

在获取单实例对象时,会先调用子类该方法,初始化 _defaultResRootPath ,然后调用父类该方法完成 _searchPathArray和_searchResolutionsOrderArray初始化

_searchPathArray 中添加 _defaultResRootPath 用A于基本的资源搜索路径。

_searchResolutionsOrderArray 初始化为空字符串。(这个空字符串相对来说在搜索时也是一个路径)

_searchPathArray的相关操作:

virtual void setSearchPaths(const std::vector<std::string>& searchPaths);

用于 _searchPathArray 的设置,传入一个绝对或者相对路径数组。

在调用该函数时,首先清空 _fullPathCache _searchPathArray 容器中的内容,保证不会出现旧数据。

然后将 searchPaths 中的类容添加到 _searchPathArray,添加时需要判断是否为绝对路径,

若为绝对路径则直接将类容添加到 _searchPathArray 中,否则添加以 _defaultResRootPath 目录的相对路径,

判断该添加的路径是否为 _defaultResRootPath,保证有且只有一个 _defaultResRootPath

void addSearchPath(const std::string & path, const bool front=false);

单个的添加搜索路径到 _searchPathArray , 并标记优先级。若 path 为空则会重复添加 _defaultResRootPath

_searchResolutionsOrderArray的相关操作:

virtual void setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder);

用于 _searchResolutionsOrderArray 的设置,传入一个相对的路径数组。

在调用该函数时,首先清空 _fullPathCache _searchResolutionsOrderArray 容器中的内容,保证不会出现旧数据。

然后将 searchResolutionsOrder 中的类容添加到 _searchResolutionsOrderArray,添加时需要判断是否添加了空路径,

保证空路径在 _searchResolutionsOrderArray 中

virtual void addSearchResolutionsOrder(const std::string &order,const bool front=false);

单个的添加资源适配路径到 _searchResolutionsOrderArray,并标记优先级。若 order 为空则会重复添加 空路径。

_filenameLookupDict 的相关操作:

这是一个通过文件名查找文件路径的集合, FILE-PATH 的对应关系。

virtual void setFilenameLookupDictionary(const ValueMap& filenameLookupDict);

首先清空 _fullPathCache 保证数据及时更新, _filenameLookupDict 赋值为最新字典数据。

filenameLookupDict 则从字典数据文件中解析获取代码设置。

_fullPathCache 相关调用

作用:用于保存相关文件的绝对路径的 KEY-VALUE,通过文件名直接获取路径,加快文件搜索。

mutable std::unordered_map<std::string, std::string> _fullPathCache;

随时都可变的的 unordered_map 类型的数据。保证数据任意地方都能更新。

virtual void purgeCachedEntries();

该函数作用是清空所有缓存的绝对路径。 _fullPathCache 清空

virtual void setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder);

设置适配搜索路径,由于文件的绝对路径可能会变所以清空 _fullPathCache

virtual void setSearchPaths(const std::vector<std::string>& searchPaths);

设置资源搜索路径,由于文件的绝对路径可能会变所以清空 _fullPathCache

virtual void setFilenameLookupDictionary(const ValueMap& filenameLookupDict);

设置文件的搜索字典,由于文件的绝对路径可能会变所以清空 _fullPathCache
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: