Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3_3_fix

This commit is contained in:
samuele3hu 2014-08-13 10:31:12 +08:00
commit 5b1ceb5e5d
6 changed files with 27 additions and 20 deletions

View File

@ -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

View File

@ -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<void (RenderTexture*, const std::string&)> 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<void (RenderTexture*, const std::string&)> 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);
}

View File

@ -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<void (RenderTexture*, const std::string&)> 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<void (RenderTexture*, const std::string&)> 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<void (RenderTexture*, const std::string&)> _saveFileCallback;
protected:
//renderer caches and callbacks
void onBegin();

View File

@ -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);

View File

@ -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++;
}

@ -1 +1 @@
Subproject commit 5db5a4283aa22e362901e2924146ad66c2e1484f
Subproject commit 4b020e4900e601a2d5845095f2e6970c13c59613