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
相关文章推荐
- cocos2dx 消息推送
- 小小菜之Cocos2d-x游戏开发旅程——Lua之抛物线运动
- 小小菜之Cocos2d-x游戏开发旅程——Lua之摇杆实现
- Cocos2d-x 3.X里的坑(2)——安卓android APP应用名称的修改
- cocos2dx简介
- cocos2dx中lua注册事件函数详解
- cocos2dx创建电子时钟
- Cocos2D-Android-1之源码详解:6.ClickAndMoveTest
- cocos2d-x 3.x相应键盘事件
- Cocos2D-Android-1之源码详解:5.Box2dTest
- 1、Cocos2dx 3.0游戏开发三找一小块前言
- cocos2dx 3.4 测试例 目录
- 【cocos2d-js系列问题】Cannot read property 'x' of null错误解决办法
- Cocos2d-x下Lua调用自定义C++类和函数的最佳实践
- cocos2d html5 教程整理
- cocos2d-x 之sprite布局日记
- quick-cocos2d-x基于源码加密打包功能的更新策略
- Cocos2D-Android-1之源码详解:4.AtlasTest
- cocos游戏框架--1
- cocos2d-x 3.0学习游戏笔记的例子《卡塔防》第五步---开始建立游戏界面