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
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:
WenSheng Yang

View File

@ -541,8 +541,9 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
{
auto next = std::next(it);
Sprite *spr = nullptr;
for(; next != _descendants.end(); ++next) {
Sprite *spr = *next;
spr = *next;
spr->setAtlasIndex( spr->getAtlasIndex() - 1 );
}
@ -649,10 +650,11 @@ SpriteBatchNode * SpriteBatchNode::addSpriteWithoutQuad(Sprite*child, int z, int
child->setAtlasIndex(z);
// XXX: optimize with a binary search
auto it = std::begin(_descendants);
for(const auto &sprite: _descendants) {
if(sprite->getAtlasIndex() >= z)
std::next(it);
auto it = _descendants.begin();
for (; it != _descendants.end(); ++it)
{
if((*it)->getAtlasIndex() >= z)
break;
}
_descendants.insert(it, child);

View File

@ -112,24 +112,37 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
font, NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
// linebreak
// linebreak
if (info->width > 0) {
if ([string sizeWithAttributes:tokenAttributesDict].width > info->width) {
NSMutableString *lineBreak = [[[NSMutableString alloc] init] autorelease];
NSUInteger length = [string length];
NSRange range = NSMakeRange(0, 1);
NSUInteger width = 0;
CGSize textSize;
NSUInteger lastBreakLocation = 0;
NSUInteger insertCount = 0;
for (NSUInteger i = 0; i < length; i++) {
range.location = i;
NSString *character = [string substringWithRange:range];
[lineBreak appendString:character];
if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) { lastBreakLocation = i; }
width = [lineBreak sizeWithAttributes:tokenAttributesDict].width;
if (width > info->width) {
[lineBreak insertString:@"\r\n" atIndex:(lastBreakLocation > 0) ? lastBreakLocation : [lineBreak length] - 1];
if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) {
lastBreakLocation = i + insertCount;
}
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;
}
}

View File

@ -95,22 +95,22 @@ public:
removeCustomFont();
}
wchar_t * utf8ToUtf16(std::string nString)
wchar_t * utf8ToUtf16(const std::string& str)
{
wchar_t * pwszBuffer = NULL;
do
{
if (nString.size() < 0)
if (str.empty())
{
break;
}
// utf-8 to utf-16
int nLen = nString.size();
int nLen = str.size();
int nBufLen = nLen + 1;
pwszBuffer = new wchar_t[nBufLen];
CC_BREAK_IF(! pwszBuffer);
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';
} while (0);
return pwszBuffer;

View File

@ -106,7 +106,7 @@ void TriggerMng::parse(const rapidjson::Value &root)
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);
if (iter == _eventTriggers.end())
@ -129,7 +129,7 @@ TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
bool TriggerMng::add(unsigned int event, TriggerObj *obj)
{
bool ret = false;
CCAssert(obj != nullptr, "Argument must be non-nil");
CCASSERT(obj != nullptr, "Argument must be non-nil");
do
{
auto iterator = _eventTriggers.find(event);
@ -170,7 +170,7 @@ void TriggerMng::removeAll(void)
bool TriggerMng::remove(unsigned int event)
{
bool bRet = false;
CCAssert(event >= 0, "event must be larger than 0");
CCASSERT(event != 0, "event must be larger than 0");
do
{
auto iterator = _eventTriggers.find(event);
@ -194,8 +194,8 @@ bool TriggerMng::remove(unsigned int event)
bool TriggerMng::remove(unsigned int event, TriggerObj *Obj)
{
bool bRet = false;
CCAssert(event >= 0, "event must be larger than 0");
CCAssert(Obj != 0, "TriggerObj must be not 0");
CCASSERT(event != 0, "event must be larger than 0");
CCASSERT(Obj != 0, "TriggerObj must be not 0");
do
{
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_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(USE_CHIPMUNK)
message("Using chipmunk ...")

View File

@ -423,7 +423,11 @@ void TMXOrthoTest4::removeSprite(float dt)
auto s = layer->getLayerSize();
auto sprite = layer->getTileAt( Point(s.width-1,0) );
auto sprite2 = layer->getTileAt(Point(s.width-1, s.height-1));
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