mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into developEventTrigger
This commit is contained in:
commit
5acb556c74
6
AUTHORS
6
AUTHORS
|
@ -747,6 +747,12 @@ Developers:
|
||||||
ucchen
|
ucchen
|
||||||
Exposed the missing data structures of Spine to JS.
|
Exposed the missing data structures of Spine to JS.
|
||||||
|
|
||||||
|
justmao945
|
||||||
|
Corrected the definition of CMake variables.
|
||||||
|
|
||||||
|
maksqwe
|
||||||
|
Fixed string size check in BitmapDC::utf8ToUtf16 on win32 and assert condition in TriggerMng.
|
||||||
|
|
||||||
Retired Core Developers:
|
Retired Core Developers:
|
||||||
WenSheng Yang
|
WenSheng Yang
|
||||||
Author of windows port, CCTextField,
|
Author of windows port, CCTextField,
|
||||||
|
|
|
@ -6,6 +6,7 @@ cocos2d-x-3.0rc0 Feb.?? 2014
|
||||||
[NEW] Using python to automatically generate script bindings codes.
|
[NEW] Using python to automatically generate script bindings codes.
|
||||||
[NEW] Linux javascript bindings support.
|
[NEW] Linux javascript bindings support.
|
||||||
|
|
||||||
|
[FIX] Supports 'setTimeout' and 'setInterval' in JSB.
|
||||||
[FIX] Exposes the missing data structures of Spine to JS.
|
[FIX] Exposes the missing data structures of Spine to JS.
|
||||||
[FIX] Node::setRotation() moves opposite when node has a physics body.
|
[FIX] Node::setRotation() moves opposite when node has a physics body.
|
||||||
[FIX] A string which only contains CJK characters can't make a line-break when it's needed.
|
[FIX] A string which only contains CJK characters can't make a line-break when it's needed.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
5bde2def1fece71a2464526c90939b9999ed05f3
|
a7af0ccd05e86210026f7c72d6f5a7be8e17fe3d
|
|
@ -446,10 +446,23 @@ Image* RenderTexture::newImage(bool fliimage)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->begin();
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
|
||||||
|
|
||||||
|
//TODO move this to configration, so we don't check it every time
|
||||||
|
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||||
|
*/
|
||||||
|
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
|
||||||
|
{
|
||||||
|
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
|
||||||
|
CHECK_GL_ERROR_DEBUG();
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
|
||||||
|
}
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glReadPixels(0,0,savedBufferWidth, savedBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, tempData);
|
glReadPixels(0,0,savedBufferWidth, savedBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, tempData);
|
||||||
this->end();
|
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);
|
||||||
|
|
||||||
if ( fliimage ) // -- flip is only required when saving image to file
|
if ( fliimage ) // -- flip is only required when saving image to file
|
||||||
{
|
{
|
||||||
|
|
|
@ -541,8 +541,9 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
||||||
{
|
{
|
||||||
auto next = std::next(it);
|
auto next = std::next(it);
|
||||||
|
|
||||||
|
Sprite *spr = nullptr;
|
||||||
for(; next != _descendants.end(); ++next) {
|
for(; next != _descendants.end(); ++next) {
|
||||||
Sprite *spr = *next;
|
spr = *next;
|
||||||
spr->setAtlasIndex( spr->getAtlasIndex() - 1 );
|
spr->setAtlasIndex( spr->getAtlasIndex() - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,10 +650,11 @@ SpriteBatchNode * SpriteBatchNode::addSpriteWithoutQuad(Sprite*child, int z, int
|
||||||
child->setAtlasIndex(z);
|
child->setAtlasIndex(z);
|
||||||
|
|
||||||
// XXX: optimize with a binary search
|
// XXX: optimize with a binary search
|
||||||
auto it = std::begin(_descendants);
|
auto it = _descendants.begin();
|
||||||
for(const auto &sprite: _descendants) {
|
for (; it != _descendants.end(); ++it)
|
||||||
if(sprite->getAtlasIndex() >= z)
|
{
|
||||||
std::next(it);
|
if((*it)->getAtlasIndex() >= z)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_descendants.insert(it, child);
|
_descendants.insert(it, child);
|
||||||
|
|
|
@ -753,7 +753,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format)
|
||||||
if (outTempData != nullptr && outTempData != tempData)
|
if (outTempData != nullptr && outTempData != tempData)
|
||||||
{
|
{
|
||||||
|
|
||||||
delete [] outTempData;
|
free(outTempData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the premultiplied tag
|
// set the premultiplied tag
|
||||||
|
@ -781,32 +781,32 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, s
|
||||||
{
|
{
|
||||||
case PixelFormat::RGBA8888:
|
case PixelFormat::RGBA8888:
|
||||||
*outDataLen = dataLen*4;
|
*outDataLen = dataLen*4;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertI8ToRGBA8888(data, dataLen, *outData);
|
convertI8ToRGBA8888(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB888:
|
case PixelFormat::RGB888:
|
||||||
*outDataLen = dataLen*3;
|
*outDataLen = dataLen*3;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertI8ToRGB888(data, dataLen, *outData);
|
convertI8ToRGB888(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB565:
|
case PixelFormat::RGB565:
|
||||||
*outDataLen = dataLen*2;
|
*outDataLen = dataLen*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertI8ToRGB565(data, dataLen, *outData);
|
convertI8ToRGB565(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::AI88:
|
case PixelFormat::AI88:
|
||||||
*outDataLen = dataLen*2;
|
*outDataLen = dataLen*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertI8ToAI88(data, dataLen, *outData);
|
convertI8ToAI88(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGBA4444:
|
case PixelFormat::RGBA4444:
|
||||||
*outDataLen = dataLen*2;
|
*outDataLen = dataLen*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertI8ToRGBA4444(data, dataLen, *outData);
|
convertI8ToRGBA4444(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB5A1:
|
case PixelFormat::RGB5A1:
|
||||||
*outDataLen = dataLen*2;
|
*outDataLen = dataLen*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertI8ToRGB5A1(data, dataLen, *outData);
|
convertI8ToRGB5A1(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -830,37 +830,37 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data,
|
||||||
{
|
{
|
||||||
case PixelFormat::RGBA8888:
|
case PixelFormat::RGBA8888:
|
||||||
*outDataLen = dataLen*2;
|
*outDataLen = dataLen*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToRGBA8888(data, dataLen, *outData);
|
convertAI88ToRGBA8888(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB888:
|
case PixelFormat::RGB888:
|
||||||
*outDataLen = dataLen/2*3;
|
*outDataLen = dataLen/2*3;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToRGB888(data, dataLen, *outData);
|
convertAI88ToRGB888(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB565:
|
case PixelFormat::RGB565:
|
||||||
*outDataLen = dataLen;
|
*outDataLen = dataLen;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToRGB565(data, dataLen, *outData);
|
convertAI88ToRGB565(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::A8:
|
case PixelFormat::A8:
|
||||||
*outDataLen = dataLen/2;
|
*outDataLen = dataLen/2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToA8(data, dataLen, *outData);
|
convertAI88ToA8(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::I8:
|
case PixelFormat::I8:
|
||||||
*outDataLen = dataLen/2;
|
*outDataLen = dataLen/2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToI8(data, dataLen, *outData);
|
convertAI88ToI8(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGBA4444:
|
case PixelFormat::RGBA4444:
|
||||||
*outDataLen = dataLen;
|
*outDataLen = dataLen;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToRGBA4444(data, dataLen, *outData);
|
convertAI88ToRGBA4444(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB5A1:
|
case PixelFormat::RGB5A1:
|
||||||
*outDataLen = dataLen;
|
*outDataLen = dataLen;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertAI88ToRGB5A1(data, dataLen, *outData);
|
convertAI88ToRGB5A1(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -885,32 +885,32 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat
|
||||||
{
|
{
|
||||||
case PixelFormat::RGBA8888:
|
case PixelFormat::RGBA8888:
|
||||||
*outDataLen = dataLen/3*4;
|
*outDataLen = dataLen/3*4;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGB888ToRGBA8888(data, dataLen, *outData);
|
convertRGB888ToRGBA8888(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB565:
|
case PixelFormat::RGB565:
|
||||||
*outDataLen = dataLen/3*2;
|
*outDataLen = dataLen/3*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGB888ToRGB565(data, dataLen, *outData);
|
convertRGB888ToRGB565(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::I8:
|
case PixelFormat::I8:
|
||||||
*outDataLen = dataLen/3;
|
*outDataLen = dataLen/3;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGB888ToI8(data, dataLen, *outData);
|
convertRGB888ToI8(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::AI88:
|
case PixelFormat::AI88:
|
||||||
*outDataLen = dataLen/3*2;
|
*outDataLen = dataLen/3*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGB888ToAI88(data, dataLen, *outData);
|
convertRGB888ToAI88(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGBA4444:
|
case PixelFormat::RGBA4444:
|
||||||
*outDataLen = dataLen/3*2;
|
*outDataLen = dataLen/3*2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGB888ToRGBA4444(data, dataLen, *outData);
|
convertRGB888ToRGBA4444(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB5A1:
|
case PixelFormat::RGB5A1:
|
||||||
*outDataLen = dataLen;
|
*outDataLen = dataLen;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGB888ToRGB5A1(data, dataLen, *outData);
|
convertRGB888ToRGB5A1(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -934,37 +934,37 @@ Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* d
|
||||||
{
|
{
|
||||||
case PixelFormat::RGB888:
|
case PixelFormat::RGB888:
|
||||||
*outDataLen = dataLen/4*3;
|
*outDataLen = dataLen/4*3;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToRGB888(data, dataLen, *outData);
|
convertRGBA8888ToRGB888(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB565:
|
case PixelFormat::RGB565:
|
||||||
*outDataLen = dataLen/2;
|
*outDataLen = dataLen/2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToRGB565(data, dataLen, *outData);
|
convertRGBA8888ToRGB565(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::A8:
|
case PixelFormat::A8:
|
||||||
*outDataLen = dataLen/4;
|
*outDataLen = dataLen/4;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToA8(data, dataLen, *outData);
|
convertRGBA8888ToA8(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::I8:
|
case PixelFormat::I8:
|
||||||
*outDataLen = dataLen/4;
|
*outDataLen = dataLen/4;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToI8(data, dataLen, *outData);
|
convertRGBA8888ToI8(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::AI88:
|
case PixelFormat::AI88:
|
||||||
*outDataLen = dataLen/2;
|
*outDataLen = dataLen/2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToAI88(data, dataLen, *outData);
|
convertRGBA8888ToAI88(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGBA4444:
|
case PixelFormat::RGBA4444:
|
||||||
*outDataLen = dataLen/2;
|
*outDataLen = dataLen/2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToRGBA4444(data, dataLen, *outData);
|
convertRGBA8888ToRGBA4444(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
case PixelFormat::RGB5A1:
|
case PixelFormat::RGB5A1:
|
||||||
*outDataLen = dataLen/2;
|
*outDataLen = dataLen/2;
|
||||||
*outData = new unsigned char[*outDataLen];
|
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||||
convertRGBA8888ToRGB5A1(data, dataLen, *outData);
|
convertRGBA8888ToRGB5A1(data, dataLen, *outData);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1094,7 +1094,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
|
||||||
|
|
||||||
if (outTempData != nullptr && outTempData != outData.getBytes())
|
if (outTempData != nullptr && outTempData != outData.getBytes())
|
||||||
{
|
{
|
||||||
delete [] outTempData;
|
free(outTempData);
|
||||||
}
|
}
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||||
_hasPremultipliedAlpha = true;
|
_hasPremultipliedAlpha = true;
|
||||||
|
|
|
@ -948,7 +948,7 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
|
||||||
}
|
}
|
||||||
png_read_image(png_ptr, row_pointers);
|
png_read_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
png_read_end(png_ptr, NULL);
|
png_read_end(png_ptr, nullptr);
|
||||||
|
|
||||||
_preMulti = false;
|
_preMulti = false;
|
||||||
|
|
||||||
|
@ -1094,7 +1094,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
|
||||||
tiffMapProc,
|
tiffMapProc,
|
||||||
tiffUnmapProc);
|
tiffUnmapProc);
|
||||||
|
|
||||||
CC_BREAK_IF(NULL == tif);
|
CC_BREAK_IF(nullptr == tif);
|
||||||
|
|
||||||
uint32 w = 0, h = 0;
|
uint32 w = 0, h = 0;
|
||||||
uint16 bitsPerSample = 0, samplePerPixel = 0, planarConfig = 0;
|
uint16 bitsPerSample = 0, samplePerPixel = 0, planarConfig = 0;
|
||||||
|
@ -1116,7 +1116,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
|
||||||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||||
|
|
||||||
uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
|
uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
|
||||||
if (raster != NULL)
|
if (raster != nullptr)
|
||||||
{
|
{
|
||||||
if (TIFFReadRGBAImageOriented(tif, w, h, raster, ORIENTATION_TOPLEFT, 0))
|
if (TIFFReadRGBAImageOriented(tif, w, h, raster, ORIENTATION_TOPLEFT, 0))
|
||||||
{
|
{
|
||||||
|
@ -1851,7 +1851,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
|
||||||
if (WebPDecode(static_cast<const uint8_t*>(data), dataLen, &config) != VP8_STATUS_OK)
|
if (WebPDecode(static_cast<const uint8_t*>(data), dataLen, &config) != VP8_STATUS_OK)
|
||||||
{
|
{
|
||||||
free(_data);
|
free(_data);
|
||||||
_data = NULL;
|
_data = nullptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1941,21 +1941,21 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
||||||
png_bytep *row_pointers;
|
png_bytep *row_pointers;
|
||||||
|
|
||||||
fp = fopen(filePath.c_str(), "wb");
|
fp = fopen(filePath.c_str(), "wb");
|
||||||
CC_BREAK_IF(NULL == fp);
|
CC_BREAK_IF(nullptr == fp);
|
||||||
|
|
||||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
if (NULL == png_ptr)
|
if (nullptr == png_ptr)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (NULL == info_ptr)
|
if (nullptr == info_ptr)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
png_destroy_write_struct(&png_ptr, NULL);
|
png_destroy_write_struct(&png_ptr, nullptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA && CC_TARGET_PLATFORM != CC_PLATFORM_NACL)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA && CC_TARGET_PLATFORM != CC_PLATFORM_NACL)
|
||||||
|
@ -1987,14 +1987,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
|
||||||
row_pointers = (png_bytep *)malloc(_height * sizeof(png_bytep));
|
row_pointers = (png_bytep *)malloc(_height * sizeof(png_bytep));
|
||||||
if(row_pointers == NULL)
|
if(row_pointers == nullptr)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAlpha())
|
if (!hasAlpha())
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)_height; i++)
|
for (int i = 0; i < (int)_height; i++)
|
||||||
{
|
{
|
||||||
|
@ -2004,14 +2004,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
||||||
png_write_image(png_ptr, row_pointers);
|
png_write_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
free(row_pointers);
|
free(row_pointers);
|
||||||
row_pointers = NULL;
|
row_pointers = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (isToRGB)
|
if (isToRGB)
|
||||||
{
|
{
|
||||||
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char*)));
|
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char*)));
|
||||||
if (NULL == pTempData)
|
if (nullptr == pTempData)
|
||||||
{
|
{
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
@ -2036,7 +2036,7 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
||||||
png_write_image(png_ptr, row_pointers);
|
png_write_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
free(row_pointers);
|
free(row_pointers);
|
||||||
row_pointers = NULL;
|
row_pointers = nullptr;
|
||||||
|
|
||||||
if (pTempData != nullptr)
|
if (pTempData != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -2053,14 +2053,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
||||||
png_write_image(png_ptr, row_pointers);
|
png_write_image(png_ptr, row_pointers);
|
||||||
|
|
||||||
free(row_pointers);
|
free(row_pointers);
|
||||||
row_pointers = NULL;
|
row_pointers = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
png_write_end(png_ptr, info_ptr);
|
png_write_end(png_ptr, info_ptr);
|
||||||
|
|
||||||
png_free(png_ptr, palette);
|
png_free(png_ptr, palette);
|
||||||
palette = NULL;
|
palette = nullptr;
|
||||||
|
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
|
||||||
|
@ -2085,7 +2085,7 @@ bool Image::saveImageToJPG(const std::string& filePath)
|
||||||
/* Now we can initialize the JPEG compression object. */
|
/* Now we can initialize the JPEG compression object. */
|
||||||
jpeg_create_compress(&cinfo);
|
jpeg_create_compress(&cinfo);
|
||||||
|
|
||||||
CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == NULL);
|
CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == nullptr);
|
||||||
|
|
||||||
jpeg_stdio_dest(&cinfo, outfile);
|
jpeg_stdio_dest(&cinfo, outfile);
|
||||||
|
|
||||||
|
@ -2103,7 +2103,7 @@ bool Image::saveImageToJPG(const std::string& filePath)
|
||||||
if (hasAlpha())
|
if (hasAlpha())
|
||||||
{
|
{
|
||||||
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char)));
|
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char)));
|
||||||
if (NULL == pTempData)
|
if (nullptr == pTempData)
|
||||||
{
|
{
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
jpeg_destroy_compress(&cinfo);
|
jpeg_destroy_compress(&cinfo);
|
||||||
|
|
|
@ -78,10 +78,6 @@ public:
|
||||||
|
|
||||||
~BitmapDC(void)
|
~BitmapDC(void)
|
||||||
{
|
{
|
||||||
if (_data)
|
|
||||||
{
|
|
||||||
delete [] _data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getBitmapFromJavaShadowStroke( const char *text,
|
bool getBitmapFromJavaShadowStroke( const char *text,
|
||||||
|
@ -163,7 +159,6 @@ public:
|
||||||
int _width;
|
int _width;
|
||||||
int _height;
|
int _height;
|
||||||
unsigned char *_data;
|
unsigned char *_data;
|
||||||
JNIEnv *env;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static BitmapDC& sharedBitmapDC()
|
static BitmapDC& sharedBitmapDC()
|
||||||
|
@ -222,7 +217,7 @@ extern "C"
|
||||||
cocos2d::BitmapDC& bitmapDC = cocos2d::sharedBitmapDC();
|
cocos2d::BitmapDC& bitmapDC = cocos2d::sharedBitmapDC();
|
||||||
bitmapDC._width = width;
|
bitmapDC._width = width;
|
||||||
bitmapDC._height = height;
|
bitmapDC._height = height;
|
||||||
bitmapDC._data = new unsigned char[size];
|
bitmapDC._data = (unsigned char*)malloc(sizeof(unsigned char) * size);
|
||||||
env->GetByteArrayRegion(pixels, 0, size, (jbyte*)bitmapDC._data);
|
env->GetByteArrayRegion(pixels, 0, size, (jbyte*)bitmapDC._data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -326,7 +326,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
|
||||||
dim.height += shadowStrokePaddingY;
|
dim.height += shadowStrokePaddingY;
|
||||||
|
|
||||||
|
|
||||||
unsigned char* data = new unsigned char[(int)(dim.width * dim.height * 4)];
|
unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * (int)(dim.width * dim.height * 4));
|
||||||
memset(data, 0, (int)(dim.width * dim.height * 4));
|
memset(data, 0, (int)(dim.width * dim.height * 4));
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
|
@ -341,7 +341,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
|
||||||
if (!context)
|
if (!context)
|
||||||
{
|
{
|
||||||
CGColorSpaceRelease(colorSpace);
|
CGColorSpaceRelease(colorSpace);
|
||||||
delete[] data;
|
CC_SAFE_FREE(data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ public:
|
||||||
int txtHeight = iMaxLineHeight;
|
int txtHeight = iMaxLineHeight;
|
||||||
iMaxLineHeight = MAX(iMaxLineHeight, nHeight);
|
iMaxLineHeight = MAX(iMaxLineHeight, nHeight);
|
||||||
|
|
||||||
_data = new unsigned char[iMaxLineWidth * iMaxLineHeight * 4];
|
_data = (unsigned char*)malloc(sizeof(unsigned char) * (iMaxLineWidth * iMaxLineHeight * 4));
|
||||||
memset(_data,0, iMaxLineWidth * iMaxLineHeight*4);
|
memset(_data,0, iMaxLineWidth * iMaxLineHeight*4);
|
||||||
|
|
||||||
int iCurYCursor = computeLineStartY(face, eAlignMask, txtHeight, iMaxLineHeight);
|
int iCurYCursor = computeLineStartY(face, eAlignMask, txtHeight, iMaxLineHeight);
|
||||||
|
|
|
@ -118,18 +118,31 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
||||||
NSMutableString *lineBreak = [[[NSMutableString alloc] init] autorelease];
|
NSMutableString *lineBreak = [[[NSMutableString alloc] init] autorelease];
|
||||||
NSUInteger length = [string length];
|
NSUInteger length = [string length];
|
||||||
NSRange range = NSMakeRange(0, 1);
|
NSRange range = NSMakeRange(0, 1);
|
||||||
NSUInteger width = 0;
|
CGSize textSize;
|
||||||
NSUInteger lastBreakLocation = 0;
|
NSUInteger lastBreakLocation = 0;
|
||||||
|
NSUInteger insertCount = 0;
|
||||||
for (NSUInteger i = 0; i < length; i++) {
|
for (NSUInteger i = 0; i < length; i++) {
|
||||||
range.location = i;
|
range.location = i;
|
||||||
NSString *character = [string substringWithRange:range];
|
NSString *character = [string substringWithRange:range];
|
||||||
[lineBreak appendString:character];
|
[lineBreak appendString:character];
|
||||||
if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) { lastBreakLocation = i; }
|
if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) {
|
||||||
width = [lineBreak sizeWithAttributes:tokenAttributesDict].width;
|
lastBreakLocation = i + insertCount;
|
||||||
if (width > info->width) {
|
}
|
||||||
[lineBreak insertString:@"\r\n" atIndex:(lastBreakLocation > 0) ? lastBreakLocation : [lineBreak length] - 1];
|
textSize = [lineBreak sizeWithAttributes:tokenAttributesDict];
|
||||||
|
if(textSize.height > info->height)
|
||||||
|
break;
|
||||||
|
if (textSize.width > info->width) {
|
||||||
|
if(lastBreakLocation > 0) {
|
||||||
|
[lineBreak insertString:@"\r" atIndex:lastBreakLocation];
|
||||||
|
lastBreakLocation = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[lineBreak insertString:@"\r" atIndex:[lineBreak length] - 1];
|
||||||
|
}
|
||||||
|
insertCount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string = lineBreak;
|
string = lineBreak;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +207,7 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
||||||
|
|
||||||
NSUInteger textureSize = POTWide*POTHigh*4;
|
NSUInteger textureSize = POTWide*POTHigh*4;
|
||||||
|
|
||||||
unsigned char* dataNew = new unsigned char[textureSize];
|
unsigned char* dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
|
||||||
if (dataNew) {
|
if (dataNew) {
|
||||||
memcpy(dataNew, data, textureSize);
|
memcpy(dataNew, data, textureSize);
|
||||||
// output params
|
// output params
|
||||||
|
|
|
@ -95,22 +95,22 @@ public:
|
||||||
removeCustomFont();
|
removeCustomFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
wchar_t * utf8ToUtf16(std::string nString)
|
wchar_t * utf8ToUtf16(const std::string& str)
|
||||||
{
|
{
|
||||||
wchar_t * pwszBuffer = NULL;
|
wchar_t * pwszBuffer = NULL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (nString.size() < 0)
|
if (str.empty())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// utf-8 to utf-16
|
// utf-8 to utf-16
|
||||||
int nLen = nString.size();
|
int nLen = str.size();
|
||||||
int nBufLen = nLen + 1;
|
int nBufLen = nLen + 1;
|
||||||
pwszBuffer = new wchar_t[nBufLen];
|
pwszBuffer = new wchar_t[nBufLen];
|
||||||
CC_BREAK_IF(! pwszBuffer);
|
CC_BREAK_IF(! pwszBuffer);
|
||||||
memset(pwszBuffer,0,nBufLen);
|
memset(pwszBuffer,0,nBufLen);
|
||||||
nLen = MultiByteToWideChar(CP_UTF8, 0, nString.c_str(), nLen, pwszBuffer, nBufLen);
|
nLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), nLen, pwszBuffer, nBufLen);
|
||||||
pwszBuffer[nLen] = '\0';
|
pwszBuffer[nLen] = '\0';
|
||||||
} while (0);
|
} while (0);
|
||||||
return pwszBuffer;
|
return pwszBuffer;
|
||||||
|
@ -412,7 +412,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
|
||||||
CC_BREAK_IF(! dc.drawText(text, size, align));
|
CC_BREAK_IF(! dc.drawText(text, size, align));
|
||||||
|
|
||||||
int dataLen = size.cx * size.cy * 4;
|
int dataLen = size.cx * size.cy * 4;
|
||||||
unsigned char* dataBuf = new unsigned char[dataLen];
|
unsigned char* dataBuf = (unsigned char*)malloc(sizeof(unsigned char) * dataLen);
|
||||||
CC_BREAK_IF(! dataBuf);
|
CC_BREAK_IF(! dataBuf);
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
|
|
@ -106,7 +106,7 @@ void TriggerMng::parse(const rapidjson::Value &root)
|
||||||
|
|
||||||
cocos2d::Vector<TriggerObj*>* TriggerMng::get(unsigned int event) const
|
cocos2d::Vector<TriggerObj*>* TriggerMng::get(unsigned int event) const
|
||||||
{
|
{
|
||||||
CCAssert(event >= 0, "Argument must be larger than 0");
|
CCASSERT(event != 0, "Argument must be larger than 0");
|
||||||
|
|
||||||
auto iter = _eventTriggers.find(event);
|
auto iter = _eventTriggers.find(event);
|
||||||
if (iter == _eventTriggers.end())
|
if (iter == _eventTriggers.end())
|
||||||
|
@ -129,7 +129,7 @@ TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
|
||||||
bool TriggerMng::add(unsigned int event, TriggerObj *obj)
|
bool TriggerMng::add(unsigned int event, TriggerObj *obj)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
CCAssert(obj != nullptr, "Argument must be non-nil");
|
CCASSERT(obj != nullptr, "Argument must be non-nil");
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auto iterator = _eventTriggers.find(event);
|
auto iterator = _eventTriggers.find(event);
|
||||||
|
@ -170,7 +170,7 @@ void TriggerMng::removeAll(void)
|
||||||
bool TriggerMng::remove(unsigned int event)
|
bool TriggerMng::remove(unsigned int event)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
CCAssert(event >= 0, "event must be larger than 0");
|
CCASSERT(event != 0, "event must be larger than 0");
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auto iterator = _eventTriggers.find(event);
|
auto iterator = _eventTriggers.find(event);
|
||||||
|
@ -194,8 +194,8 @@ bool TriggerMng::remove(unsigned int event)
|
||||||
bool TriggerMng::remove(unsigned int event, TriggerObj *Obj)
|
bool TriggerMng::remove(unsigned int event, TriggerObj *Obj)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
CCAssert(event >= 0, "event must be larger than 0");
|
CCASSERT(event != 0, "event must be larger than 0");
|
||||||
CCAssert(Obj != 0, "TriggerObj must be not 0");
|
CCASSERT(Obj != 0, "TriggerObj must be not 0");
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auto iterator = _eventTriggers.find(event);
|
auto iterator = _eventTriggers.find(event);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
var cc = cc || {};
|
var cc = cc || {};
|
||||||
|
var window = window || this;
|
||||||
|
|
||||||
cc.TARGET_PLATFORM = {
|
cc.TARGET_PLATFORM = {
|
||||||
WINDOWS:0,
|
WINDOWS:0,
|
||||||
|
@ -821,3 +822,62 @@ cc.VisibleRect = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _windowTimeIntervalId = 0;
|
||||||
|
var _windowTimeFunHash = {};
|
||||||
|
var WindowTimeFun = cc.Class.extend({
|
||||||
|
_code: null,
|
||||||
|
_intervalId: 0,
|
||||||
|
ctor: function (code) {
|
||||||
|
this._intervalId = _windowTimeIntervalId++;
|
||||||
|
this._code = code;
|
||||||
|
},
|
||||||
|
fun: function () {
|
||||||
|
if (!this._code) return;
|
||||||
|
var code = this._code;
|
||||||
|
if (typeof code == "string") {
|
||||||
|
Function(code)();
|
||||||
|
}
|
||||||
|
else if (typeof code == "function") {
|
||||||
|
code();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* overwrite window's setTimeout
|
||||||
|
@param {String|Function} code
|
||||||
|
@param {number} delay
|
||||||
|
@return {number}
|
||||||
|
*/
|
||||||
|
var setTimeout = function (code, delay) {
|
||||||
|
var target = new WindowTimeFun(code);
|
||||||
|
cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, 0, 0, false);
|
||||||
|
_windowTimeFunHash[target._intervalId] = target;
|
||||||
|
return target._intervalId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* overwrite window's setInterval
|
||||||
|
@param {String|Function} code
|
||||||
|
@param {number} delay
|
||||||
|
@return {number}
|
||||||
|
*/
|
||||||
|
var setInterval = function (code, delay) {
|
||||||
|
var target = new WindowTimeFun(code);
|
||||||
|
cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, cc.REPEAT_FOREVER, 0, false);
|
||||||
|
_windowTimeFunHash[target._intervalId] = target;
|
||||||
|
return target._intervalId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* overwrite window's clearInterval
|
||||||
|
@param {number} intervalId
|
||||||
|
*/
|
||||||
|
var clearInterval = function (intervalId) {
|
||||||
|
var target = _windowTimeFunHash[intervalId];
|
||||||
|
if (target) {
|
||||||
|
cc.Director.getInstance().getScheduler().unscheduleCallbackForTarget(target, target.fun);
|
||||||
|
delete _windowTimeFunHash[intervalId];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var clearTimeout = clearInterval;
|
|
@ -18,8 +18,8 @@ endif(DEBUG_MODE)
|
||||||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
|
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
|
||||||
if(USE_CHIPMUNK)
|
if(USE_CHIPMUNK)
|
||||||
message("Using chipmunk ...")
|
message("Using chipmunk ...")
|
||||||
|
|
|
@ -143,14 +143,8 @@ void RenderTextureSave::saveImage(cocos2d::Object *sender)
|
||||||
_target->saveToFile(png, Image::Format::PNG);
|
_target->saveToFile(png, Image::Format::PNG);
|
||||||
_target->saveToFile(jpg, Image::Format::JPG);
|
_target->saveToFile(jpg, Image::Format::JPG);
|
||||||
|
|
||||||
|
std::string fileName = FileUtils::getInstance()->getWritablePath() + jpg;
|
||||||
auto image = _target->newImage();
|
auto sprite = Sprite::create(fileName);
|
||||||
|
|
||||||
auto tex = Director::getInstance()->getTextureCache()->addImage(image, png);
|
|
||||||
|
|
||||||
CC_SAFE_DELETE(image);
|
|
||||||
|
|
||||||
auto sprite = Sprite::createWithTexture(tex);
|
|
||||||
|
|
||||||
sprite->setScale(0.3f);
|
sprite->setScale(0.3f);
|
||||||
addChild(sprite);
|
addChild(sprite);
|
||||||
|
|
|
@ -423,7 +423,11 @@ void TMXOrthoTest4::removeSprite(float dt)
|
||||||
auto s = layer->getLayerSize();
|
auto s = layer->getLayerSize();
|
||||||
|
|
||||||
auto sprite = layer->getTileAt( Point(s.width-1,0) );
|
auto sprite = layer->getTileAt( Point(s.width-1,0) );
|
||||||
|
auto sprite2 = layer->getTileAt(Point(s.width-1, s.height-1));
|
||||||
layer->removeChild(sprite, true);
|
layer->removeChild(sprite, true);
|
||||||
|
auto sprite3 = layer->getTileAt(Point(2, s.height-1));
|
||||||
|
layer->removeChild(sprite3, true);
|
||||||
|
layer->removeChild(sprite2, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TMXOrthoTest4::title() const
|
std::string TMXOrthoTest4::title() const
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require "luaScript/PerformanceTest/PerformanceSpriteTest"
|
require "luaScript/PerformanceTest/PerformanceSpriteTest"
|
||||||
|
|
||||||
local MAX_COUNT = 5
|
local MAX_COUNT = 6
|
||||||
local LINE_SPACE = 40
|
local LINE_SPACE = 40
|
||||||
local kItemTagBasic = 1000
|
local kItemTagBasic = 1000
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ local testsName =
|
||||||
"PerformanceParticleTest",
|
"PerformanceParticleTest",
|
||||||
"PerformanceSpriteTest",
|
"PerformanceSpriteTest",
|
||||||
"PerformanceTextureTest",
|
"PerformanceTextureTest",
|
||||||
"PerformanceTouchesTest"
|
"PerformanceTouchesTest",
|
||||||
|
"PerformanceFuncRelateWithTable",
|
||||||
}
|
}
|
||||||
|
|
||||||
local s = cc.Director:getInstance():getWinSize()
|
local s = cc.Director:getInstance():getWinSize()
|
||||||
|
@ -1020,7 +1021,7 @@ local function runSpriteTest()
|
||||||
|
|
||||||
local function Performanceout20(pSprite)
|
local function Performanceout20(pSprite)
|
||||||
local size = cc.Director:getInstance():getWinSize()
|
local size = cc.Director:getInstance():getWinSize()
|
||||||
|
print("come in")
|
||||||
if math.random() < 0.2 then
|
if math.random() < 0.2 then
|
||||||
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
||||||
else
|
else
|
||||||
|
@ -1651,6 +1652,223 @@ local function runTouchesTest()
|
||||||
return pNewscene
|
return pNewscene
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function runFuncRelateWithTable()
|
||||||
|
-- body
|
||||||
|
local newscene = cc.Scene:create()
|
||||||
|
local layer = cc.Layer:create()
|
||||||
|
local s = cc.Director:getInstance():getWinSize()
|
||||||
|
local scheduler = cc.Director:getInstance():getScheduler()
|
||||||
|
local scheduleEntryID = 0
|
||||||
|
local quantityOfNodes = 10000
|
||||||
|
local socket = require("socket")
|
||||||
|
local maxTime = 0.0
|
||||||
|
local minTime = 99999
|
||||||
|
local averageTime1 = 0.0
|
||||||
|
local averageTime2 = 0.0
|
||||||
|
local totalTime = 0.0
|
||||||
|
local numberOfCalls = 0
|
||||||
|
|
||||||
|
local function GetTitle()
|
||||||
|
return "Func Releated Table Performance Test"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function GetSubtitle()
|
||||||
|
return "See console for results"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function initVar()
|
||||||
|
maxTime = 0.0
|
||||||
|
minTime = 99999
|
||||||
|
averageTime1 = 0.0
|
||||||
|
averageTime2 = 0.0
|
||||||
|
totalTime = 0.0
|
||||||
|
numberOfCalls = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
--Title
|
||||||
|
local title = cc.LabelTTF:create(GetTitle(), "Arial", 28)
|
||||||
|
layer:addChild(title, 1)
|
||||||
|
title:setPosition(cc.p(s.width/2, s.height-32))
|
||||||
|
title:setColor(cc.c3b(255,255,40))
|
||||||
|
--Subtitle
|
||||||
|
local subTitle = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16)
|
||||||
|
layer:addChild(subTitle, 1)
|
||||||
|
subTitle:setPosition(cc.p(s.width/2, s.height-80))
|
||||||
|
|
||||||
|
--"+","-" Menu
|
||||||
|
local function onDecrease()
|
||||||
|
quantityOfNodes = quantityOfNodes - 100
|
||||||
|
if quantityOfNodes == 0 then
|
||||||
|
quantityOfNodes = 100
|
||||||
|
end
|
||||||
|
local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF")
|
||||||
|
local strNum = string.format("%d", quantityOfNodes)
|
||||||
|
numLabel:setString(strNum)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onIncrease()
|
||||||
|
quantityOfNodes = quantityOfNodes + 100
|
||||||
|
local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF")
|
||||||
|
local strNum = string.format("%d", quantityOfNodes)
|
||||||
|
numLabel:setString(strNum)
|
||||||
|
end
|
||||||
|
|
||||||
|
cc.MenuItemFont:setFontSize(65)
|
||||||
|
local decrease = cc.MenuItemFont:create(" - ")
|
||||||
|
decrease:registerScriptTapHandler(onDecrease)
|
||||||
|
decrease:setColor(cc.c3b(0,200,20))
|
||||||
|
local increase = cc.MenuItemFont:create(" + ")
|
||||||
|
increase:registerScriptTapHandler(onIncrease)
|
||||||
|
increase:setColor(cc.c3b(0,200,20))
|
||||||
|
|
||||||
|
local menuAddOrSub = cc.Menu:create()
|
||||||
|
menuAddOrSub:addChild(decrease)
|
||||||
|
menuAddOrSub:addChild(increase)
|
||||||
|
menuAddOrSub:alignItemsHorizontally()
|
||||||
|
menuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
|
||||||
|
layer:addChild(menuAddOrSub,1)
|
||||||
|
|
||||||
|
--num
|
||||||
|
local numLabel = cc.LabelTTF:create("10000", "Marker Felt", 30)
|
||||||
|
numLabel:setColor(cc.c3b(0,200,20))
|
||||||
|
numLabel:setPosition(cc.p(s.width/2, s.height/2-15))
|
||||||
|
layer:addChild(numLabel, 1, NodeChildrenTestParam.kTagInfoLayer)
|
||||||
|
|
||||||
|
--setPosition,getPosition,Point
|
||||||
|
cc.MenuItemFont:setFontSize(18)
|
||||||
|
local setPositionItem = cc.MenuItemFont:create("setPosition")
|
||||||
|
local getPositionItem = cc.MenuItemFont:create("getPosition")
|
||||||
|
local getAnchorPointItem = cc.MenuItemFont:create("getAnchorPoint")
|
||||||
|
local pointItem = cc.MenuItemFont:create("object")
|
||||||
|
local funcToggleItem = cc.MenuItemToggle:create(setPositionItem)
|
||||||
|
funcToggleItem:addSubItem(getPositionItem)
|
||||||
|
funcToggleItem:addSubItem(getAnchorPointItem)
|
||||||
|
funcToggleItem:addSubItem(pointItem)
|
||||||
|
funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5))
|
||||||
|
funcToggleItem:setPosition(cc.p(VisibleRect:left()))
|
||||||
|
local funcMenu = cc.Menu:create(funcToggleItem)
|
||||||
|
funcMenu:setPosition(cc.p(0, 0))
|
||||||
|
layer:addChild(funcMenu)
|
||||||
|
|
||||||
|
local testNode = cc.Node:create()
|
||||||
|
layer:addChild(testNode)
|
||||||
|
|
||||||
|
local function step(dt)
|
||||||
|
print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",quantityOfNodes, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function profileEnd(startTime)
|
||||||
|
local duration = socket.gettime() - startTime
|
||||||
|
totalTime = totalTime + duration
|
||||||
|
averageTime1 = (averageTime1 + duration) / 2
|
||||||
|
averageTime2 = totalTime / numberOfCalls
|
||||||
|
|
||||||
|
if maxTime < duration then
|
||||||
|
maxTime = duration
|
||||||
|
end
|
||||||
|
|
||||||
|
if minTime > duration then
|
||||||
|
minTime = duration
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function callSetPosition()
|
||||||
|
numberOfCalls = numberOfCalls + 1
|
||||||
|
local startTime = socket.gettime()
|
||||||
|
for i=1,quantityOfNodes do
|
||||||
|
testNode:setPosition(cc.p(1,2))
|
||||||
|
end
|
||||||
|
profileEnd(startTime)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function callGetPosition()
|
||||||
|
numberOfCalls = numberOfCalls + 1
|
||||||
|
local startTime = socket.gettime()
|
||||||
|
for i=1,quantityOfNodes do
|
||||||
|
local x,y = testNode:getPosition()
|
||||||
|
end
|
||||||
|
profileEnd(startTime)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function callGetAnchorPoint()
|
||||||
|
numberOfCalls = numberOfCalls + 1
|
||||||
|
local startTime = socket.gettime()
|
||||||
|
for i=1,quantityOfNodes do
|
||||||
|
local anchorPoint = testNode:getAnchorPoint()
|
||||||
|
end
|
||||||
|
profileEnd(startTime)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function callTableObject()
|
||||||
|
numberOfCalls = numberOfCalls + 1
|
||||||
|
local startTime = socket.gettime()
|
||||||
|
for i=1,quantityOfNodes do
|
||||||
|
local pt = cc.p(1,2)
|
||||||
|
end
|
||||||
|
profileEnd(startTime)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function update(dt)
|
||||||
|
|
||||||
|
local funcSelected = funcToggleItem:getSelectedIndex()
|
||||||
|
if 0 == funcSelected then
|
||||||
|
callSetPosition()
|
||||||
|
elseif 1 == funcSelected then
|
||||||
|
callGetPosition()
|
||||||
|
elseif 2 == funcSelected then
|
||||||
|
callGetAnchorPoint()
|
||||||
|
elseif 3 == funcSelected then
|
||||||
|
callTableObject()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onNodeEvent(tag)
|
||||||
|
if tag == "exit" then
|
||||||
|
layer:unscheduleUpdate()
|
||||||
|
scheduler:unscheduleScriptEntry(scheduleEntryID)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
layer:registerScriptHandler(onNodeEvent)
|
||||||
|
|
||||||
|
|
||||||
|
local function startCallback()
|
||||||
|
initVar()
|
||||||
|
decrease:setEnabled(false)
|
||||||
|
increase:setEnabled(false)
|
||||||
|
funcToggleItem:setEnabled(false)
|
||||||
|
layer:unscheduleUpdate()
|
||||||
|
layer:scheduleUpdateWithPriorityLua(update, 0)
|
||||||
|
scheduler:unscheduleScriptEntry(scheduleEntryID)
|
||||||
|
scheduleEntryID = scheduler:scheduleScriptFunc(step,2,false)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function stopCallback()
|
||||||
|
decrease:setEnabled(true)
|
||||||
|
increase:setEnabled(true)
|
||||||
|
funcToggleItem:setEnabled(true)
|
||||||
|
layer:unscheduleUpdate()
|
||||||
|
scheduler:unscheduleScriptEntry(scheduleEntryID)
|
||||||
|
end
|
||||||
|
local startItem = cc.MenuItemFont:create("start")
|
||||||
|
startItem:registerScriptTapHandler(startCallback)
|
||||||
|
local stopItem = cc.MenuItemFont:create("stop")
|
||||||
|
stopItem:registerScriptTapHandler(stopCallback)
|
||||||
|
local startAndStop = cc.Menu:create(startItem,stopItem)
|
||||||
|
startAndStop:alignItemsVertically()
|
||||||
|
startAndStop:setPosition(VisibleRect:right().x - 50, VisibleRect:right().y)
|
||||||
|
layer:addChild(startAndStop)
|
||||||
|
|
||||||
|
--back menu
|
||||||
|
local menu = cc.Menu:create()
|
||||||
|
CreatePerfomBasicLayerMenu(menu)
|
||||||
|
menu:setPosition(cc.p(0, 0))
|
||||||
|
layer:addChild(menu)
|
||||||
|
|
||||||
|
newscene:addChild(layer)
|
||||||
|
return newscene
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
--
|
--
|
||||||
|
@ -1661,7 +1879,8 @@ local CreatePerformancesTestTable =
|
||||||
runParticleTest,
|
runParticleTest,
|
||||||
runSpriteTest,
|
runSpriteTest,
|
||||||
runTextureTest,
|
runTextureTest,
|
||||||
runTouchesTest
|
runTouchesTest,
|
||||||
|
runFuncRelateWithTable,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function CreatePerformancesTestScene(nPerformanceNo)
|
local function CreatePerformancesTestScene(nPerformanceNo)
|
||||||
|
@ -1687,7 +1906,7 @@ local function PerformanceMainLayer()
|
||||||
for i = 1, MAX_COUNT do
|
for i = 1, MAX_COUNT do
|
||||||
local item = cc.MenuItemFont:create(testsName[i])
|
local item = cc.MenuItemFont:create(testsName[i])
|
||||||
item:registerScriptTapHandler(menuCallback)
|
item:registerScriptTapHandler(menuCallback)
|
||||||
item:setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE)
|
item:setPosition(s.width / 2, s.height - i * LINE_SPACE)
|
||||||
menu:addChild(item, kItemTagBasic + i)
|
menu:addChild(item, kItemTagBasic + i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue