Quick-cocos2d-x 3.3 Multi-AssetManager simultaneous download progress issues
In quick-cocos2d-x 3.3, my code for starting and listening to assetsmanager is as follows:
Local function onProgress (event) Progress listener ....... endlocal assetsManager = cc. assetsManager: new (PackageUrl, versionFileUrl, pathToSave) assetsManager: retain () assetsManager: setDelegate (onProgress, cc. ASSETSMANAGER_PROTOCOL_PROGRESS) assetsManager: setConnectionTimeout (3) assetsManager: update ()
In my project, I need to download multiple plug-ins at the same time (create multiple assetsmanager for download at the same time). I encountered a problem.
See Post: http://www.cocoachina.com/bbs/read.php? Tid-280644.html
That is, when I create two assetsmanager objects at the same time (that is, two objects are being downloaded at the same time ), the returned values of the two assetsmanager objects in the onProgress function seem to be mutually dropped (that is, the Progress returned value event of my first assetsmanager listener may be changed to the Progress value event of the second assetsmanager ), as a result, percent is constantly changing.
My solution is: Find the assetsmanager. cpp file in the source code and open it. Find the following function:
int assetsManagerProgressFunc(void *ptr, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded){ static int percent = 0; int tmp = (int)(nowDownloaded / totalToDownload * 100); if (percent != tmp) { percent = tmp; Director::getInstance()->getScheduler()->performFunctionInCocosThread([=]{ auto manager = static_cast(ptr); if (manager->_delegate) manager->_delegate->onProgress(percent); }); CCLOG("downloading... %d%%", percent); } return 0;}Here, percent is the returned value of onProgress, But I have created multiple assetsmanager objects. Therefore, this percent should be only the attributes of objects and should not be the attributes of classes, so it cannot be a static variable. Replace the static variable with int percent = 0. recompile it ~ Otherwise, many assetsmanager objects will modify the common static percent. As a result, the value of percent is constantly changing, which leads to my previous problems ~
I personally think this should be a small bug of quick, but there is no such modification error.