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

# By James Chen (4) and others
# Via James Chen
* 'develop' of https://github.com/cocos2d/cocos2d-x:
  Update AUTHORS [ci skip]
  Update AUTHORS [ci skip]
  fix string concatenation
  closed #4054: Adds test for removing child from TMXLayer.
  closed #4054: Removing child from TMXLayer may cause crash.
  closed #4048:fixed LabelTTFMultiline test case show nothing on mac.
  fix string size check and assert condition
This commit is contained in:
bmanGH 2014-02-17 22:16:03 +08:00
commit 32317fb4da
7 changed files with 47 additions and 22 deletions

View File

@ -746,6 +746,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

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

View File

@ -112,24 +112,37 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
font, NSFontAttributeName, font, NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil]; paragraphStyle, NSParagraphStyleAttributeName, nil];
// linebreak // linebreak
if (info->width > 0) { if (info->width > 0) {
if ([string sizeWithAttributes:tokenAttributesDict].width > info->width) { if ([string sizeWithAttributes:tokenAttributesDict].width > info->width) {
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;
} }
} }

View File

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

View File

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

View File

@ -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 ...")

View File

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