// // 资源加载类 // #ifndef RUResLoader_h #define RUResLoader_h #include "cocos2d.h" #include "RUDefine.h" NS_RU_BEGIN enum class kLoaderState { WAIT = 0, //等待加载 LOADING, //加载中 PAUSE, //暂停加载 LOADED //加载完成 }; #define gResLoader(key) redutils::ResLoader::instance(key) class ResLoader : public Ref { public: static ResLoader* instance(std::string key4Loader); // 增加各种资源提前加载 void addImgs2Load(const vector& imgs); void addPlists2Load(const vector& plists); void addAudios2Load(const vector& audios); void addShaders2Compile(const vector>& shaders); void addFuncs2Load(const std::vector>& funcs); // 开始同步加载资源 void startLoad(); // 开始异步加载资源 void startLoadAsync(std::function cbUpdateProgress, std::function cbWhileFinished); // 加载是否完成 bool isFinished(); // 暂停、重启加载 void pauseLoading(); void resumeLoading(); private: ResLoader(); ~ResLoader(); void _imgTextureAsyncCallback(cocos2d::Texture2D* texture); void _plistImageAsyncCallback(cocos2d::Texture2D* texture); void _loadNextResourceAsyns(); private: static std::unordered_map _gResLoaders; std::string _loaderName; //仅起log输出用 std::function _cbWhileFinihsed = nullptr; std::function _cbUpdateProgress = nullptr; // 资源纯图片 vector _vecImgs; int _idx4Img = 0; // 资源plist vector _vecPlists; int _idx4Plist = 0; // shader的预编译 vector> _cfgShaders; int _idx4Shader = 0; std::string _strFrag; std::string _strVert; // 音效文件的加载 vector _vecSounds; int _idx4Sound = 0; // 函数加载 std::vector> _vecFuncs; int _idx4Func = 0; kLoaderState _state = kLoaderState::WAIT; int _progresssTotal = 0; int _progressNow = 0; }; NS_RU_END #endif /* RUResLoader_h */