diff --git a/CHANGELOG b/CHANGELOG index 2475f2bd49..d06c1028ae 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ cocos2d-x-3.3 ?? [NEW] FileUtilsApple: allow setting bundle to use in file utils on iOS and Mac OS X [NEW] Image: support of software PVRTC v1 decompression [NEW] Physics Integration: can invoke update in demand + [NEW] RenderTexture: add a call back function for saveToFile() [NEW] RotateTo: added 3D rotation support [NEW] ScrollView: added `setMinScale()` and `setMaxScale()` [NEW] SpriteFrameCache: load from plist file content data diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 8a60335503..9cee8b1434 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -67,6 +67,7 @@ RenderTexture::RenderTexture() , _rtTextureRect(Rect::ZERO) , _fullRect(Rect::ZERO) , _fullviewPort(Rect::ZERO) +, _saveFileCallback(nullptr) { #if CC_ENABLE_CACHE_TEXTURE_DATA // Listen this event to save render texture before come to background. @@ -415,33 +416,36 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3 _orderOfArrival = 0; } -bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA) +bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, std::function callback) { std::string basename(filename); std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower); if (basename.find(".png") != std::string::npos) { - return saveToFile(filename, Image::Format::PNG, isRGBA); + return saveToFile(filename, Image::Format::PNG, isRGBA, callback); } else if (basename.find(".jpg") != std::string::npos) { if (isRGBA) CCLOG("RGBA is not supported for JPG format."); - return saveToFile(filename, Image::Format::JPG, false); + return saveToFile(filename, Image::Format::JPG, false, callback); } else { CCLOG("Only PNG and JPG format are supported now!"); } - return saveToFile(filename, Image::Format::JPG, false); + return saveToFile(filename, Image::Format::JPG, false, callback); } -bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA) + +bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback) { CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, "the image can only be saved as JPG or PNG format"); if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); + _saveFileCallback = callback; + std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); _saveToFileCommand.func = CC_CALLBACK_0(RenderTexture::onSaveToFile, this, fullpath, isRGBA); @@ -457,7 +461,10 @@ void RenderTexture::onSaveToFile(const std::string& filename, bool isRGBA) { image->saveToFile(filename.c_str(), !isRGBA); } - + if(_saveFileCallback) + { + _saveFileCallback(this, filename); + } CC_SAFE_DELETE(image); } diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 187acc18b3..3d016b0be6 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -103,12 +103,12 @@ public: /** saves the texture into a file using JPEG format. The file will be saved in the Documents folder. Returns true if the operation is successful. */ - bool saveToFile(const std::string& filename, bool isRGBA = true); + bool saveToFile(const std::string& filename, bool isRGBA = true, std::function callback = nullptr); /** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder. Returns true if the operation is successful. */ - bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true); + bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true, std::function callback = nullptr); /** Listen "come to background" message, and save render texture. It only has effect on Android. @@ -214,6 +214,7 @@ protected: CustomCommand _beginCommand; CustomCommand _endCommand; CustomCommand _saveToFileCommand; + std::function _saveFileCallback; protected: //renderer caches and callbacks void onBegin(); diff --git a/extensions/assets-manager/AssetsManager.cpp b/extensions/assets-manager/AssetsManager.cpp index 52073d2f07..06df43b5a2 100644 --- a/extensions/assets-manager/AssetsManager.cpp +++ b/extensions/assets-manager/AssetsManager.cpp @@ -159,6 +159,7 @@ bool AssetsManager::checkUpdate() curl_easy_setopt(_curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(_curl, CURLOPT_LOW_SPEED_LIMIT, LOW_SPEED_LIMIT); curl_easy_setopt(_curl, CURLOPT_LOW_SPEED_TIME, LOW_SPEED_TIME); + curl_easy_setopt(_curl, CURLOPT_FOLLOWLOCATION, 1 ); res = curl_easy_perform(_curl); if (res != 0) @@ -209,6 +210,8 @@ void AssetsManager::downloadAndUncompress() if (! uncompress()) { Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{ + UserDefault::getInstance()->setStringForKey(this->keyOfDownloadedVersion().c_str(),""); + UserDefault::getInstance()->flush(); if (this->_delegate) this->_delegate->onError(ErrorCode::UNCOMPRESS); }); @@ -525,6 +528,7 @@ bool AssetsManager::downLoad() curl_easy_setopt(_curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(_curl, CURLOPT_LOW_SPEED_LIMIT, LOW_SPEED_LIMIT); curl_easy_setopt(_curl, CURLOPT_LOW_SPEED_TIME, LOW_SPEED_TIME); + curl_easy_setopt(_curl, CURLOPT_FOLLOWLOCATION, 1 ); res = curl_easy_perform(_curl); curl_easy_cleanup(_curl); diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index 334d578b79..c75eb75cd3 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -135,25 +135,19 @@ void RenderTextureSave::saveImage(cocos2d::Ref *sender) char png[20]; sprintf(png, "image-%d.png", counter); - char jpg[20]; - sprintf(jpg, "image-%d.jpg", counter); - - _target->saveToFile(png, Image::Format::PNG); - _target->saveToFile(jpg, Image::Format::JPG); - std::string fileName = FileUtils::getInstance()->getWritablePath() + jpg; - auto action1 = DelayTime::create(1); - auto func = [&,fileName]() + auto callback = [&](RenderTexture* rt, const std::string& path) { - auto sprite = Sprite::create(fileName); + auto sprite = Sprite::create(path); addChild(sprite); sprite->setScale(0.3f); sprite->setPosition(Vec2(40, 40)); sprite->setRotation(counter * 3); }; - runAction(Sequence::create(action1, CallFunc::create(func), nullptr)); + + _target->saveToFile(png, Image::Format::PNG, true, callback); - CCLOG("Image saved %s and %s", png, jpg); + CCLOG("Image saved %s", png); counter++; } diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 5db5a4283a..4b020e4900 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 5db5a4283aa22e362901e2924146ad66c2e1484f +Subproject commit 4b020e4900e601a2d5845095f2e6970c13c59613