From 69c004108b1305a63cf821a0446a3072dabacdd6 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Sat, 11 Jan 2014 22:33:07 +0800 Subject: [PATCH 01/24] issue#3630:Adjust some method for more easily create and change type. --- cocos/2d/CCLabel.cpp | 230 ++++++++++++------ cocos/2d/CCLabel.h | 44 +++- .../cocos2d_specifics.cpp.REMOVED.git-id | 2 +- .../Classes/LabelTest/LabelTestNew.cpp | 121 ++++----- .../NewEventDispatcherTest.cpp | 10 +- .../PerformanceTest/PerformanceLabelTest.cpp | 35 +-- tools/tojs/cocos2dx.ini | 2 +- 7 files changed, 276 insertions(+), 168 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index d7125bcd30..4775fd2ae8 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -32,73 +32,58 @@ NS_CC_BEGIN -Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) +Label* Label::create() { - FontAtlas *tmpAtlas = nullptr; - if(useDistanceField) - tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), DISTANCEFIELD_ATLAS_FONTSIZE, glyphs, customGlyphs,true); - else - tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs,false); + Label *ret = new Label(); - if (!tmpAtlas) - return nullptr; - - // create the actual label - Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize, useDistanceField,true); - - if (templabel) - { - if(useDistanceField) - templabel->setFontSize(fontSize); - templabel->setText(label, lineSize, alignment, false); - return templabel; - } - - return nullptr; -} - -Label* Label::createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment, int lineSize) -{ - - FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath.c_str()); - - if (!tmpAtlas) - return 0; - - Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize); - - if (templabel) - { - templabel->setText(label, lineSize, alignment, false); - return templabel; - } - else - { - return 0; - } - - return 0; -} - -Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int lineSize, bool useDistanceField,bool useA8Shader) -{ - Label *ret = new Label(atlas, alignment, useDistanceField,useA8Shader); - if (!ret) - return 0; - - if( ret->init() ) + return nullptr; + + ret->autorelease(); + + return ret; +} + +Label* Label::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setTTFConfig(ttfConfig)) { + if(ttfConfig.distanceFieldEnable) + ret->setFontSize(ttfConfig.fontSize); + ret->setText(text,alignment,lineSize); ret->autorelease(); return ret; } else { delete ret; - return 0; + return nullptr; + } +} + +Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setBMFontFilePath(bmfontFilePath)) + { + ret->setText(text,alignment,lineSize); + ret->autorelease(); + return ret; + } + else + { + delete ret; + return nullptr; } - - return ret; } Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,bool useA8Shader) @@ -108,8 +93,8 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b , _lineBreakWithoutSpaces(false) , _width(0.0f) , _alignment(alignment) -, _currentUTF16String(0) -, _originalUTF16String(0) +, _currentUTF16String(nullptr) +, _originalUTF16String(nullptr) , _advances(nullptr) , _fontAtlas(atlas) , _isOpacityModifyRGB(true) @@ -118,6 +103,7 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b , _fontSize(0) , _uniformEffectColor(0) { + _cascadeColorEnabled = true; } Label::~Label() @@ -137,10 +123,13 @@ bool Label::init() bool ret = true; if(_fontAtlas) { - _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); - _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); - ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); - _reusedLetter->retain(); + if (_reusedLetter == nullptr) + { + _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); + _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); + _reusedLetter->retain(); + } + ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); } if (_useDistanceField) setLabelEffect(LabelEffect::NORMAL,Color3B::BLACK); @@ -148,24 +137,119 @@ bool Label::init() setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR)); else setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + return ret; } -void Label::setString(const std::string &stringToRender) +bool Label::setTTFConfig(const TTFConfig& ttfConfig) +{ + FontAtlas *newAtlas = nullptr; + if(ttfConfig.distanceFieldEnable) + newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, DISTANCEFIELD_ATLAS_FONTSIZE, ttfConfig.glyphs, ttfConfig.customGlyphs,true); + else + newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, ttfConfig.fontSize, ttfConfig.glyphs, ttfConfig.customGlyphs,false); + + if (!newAtlas) + return false; + + FontAtlas *oldAtlas = _fontAtlas; + bool oldDistanceFieldEnable = _useDistanceField; + bool oldA8ShaderEnabel = _useA8Shader; + + _fontAtlas = newAtlas; + _useDistanceField = ttfConfig.distanceFieldEnable; + _useA8Shader = true; + + bool ret = Label::init(); + if (oldAtlas) + { + if (ret) + { + FontAtlasCache::releaseFontAtlas(oldAtlas); + } + else + { + _fontAtlas = oldAtlas; + _useDistanceField = oldDistanceFieldEnable; + _useA8Shader = oldA8ShaderEnabel; + Label::init(); + + FontAtlasCache::releaseFontAtlas(newAtlas); + } + } + + if (_fontAtlas) + { + _commonLineHeight = _fontAtlas->getCommonLineHeight(); + if (_currentUTF16String) + { + alignText(); + } + } + + return ret; +} + +bool Label::setBMFontFilePath(const std::string& bmfontFilePath) +{ + FontAtlas *newAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath); + + if (!newAtlas) + return false; + + FontAtlas *oldAtlas = _fontAtlas; + bool oldDistanceFieldEnable = _useDistanceField; + bool oldA8ShaderEnabel = _useA8Shader; + + _fontAtlas = newAtlas; + _useDistanceField = false; + _useA8Shader = false; + + bool ret = Label::init(); + if (oldAtlas) + { + if (ret) + { + FontAtlasCache::releaseFontAtlas(oldAtlas); + } + else + { + _fontAtlas = oldAtlas; + _useDistanceField = oldDistanceFieldEnable; + _useA8Shader = oldA8ShaderEnabel; + Label::init(); + + FontAtlasCache::releaseFontAtlas(newAtlas); + } + } + + if (_fontAtlas) + { + _commonLineHeight = _fontAtlas->getCommonLineHeight(); + if (_currentUTF16String) + { + alignText(); + } + } + + return ret; +} + +void Label::setString(const std::string &text) { _multilineEnable = true; - setText(stringToRender, _width, TextHAlignment::CENTER, false); + setText(text, TextHAlignment::CENTER, _width, false); } -void Label::setString(const std::string &stringToRender,bool multilineEnable) +void Label::setString(const std::string &text,bool multilineEnable) { _multilineEnable = multilineEnable; - setText(stringToRender, _width, TextHAlignment::CENTER, false); + setText(text, TextHAlignment::CENTER, _width, false); } -bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces) +bool Label::setText(const std::string& text, const TextHAlignment& alignment /* = TextHAlignment::LEFT */, float lineWidth /* = 0 */, bool lineBreakWithoutSpaces /* = false */) { - if (!_fontAtlas) + if (!_fontAtlas || _commonLineHeight <= 0) return false; // carloX @@ -176,18 +260,10 @@ bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAli _alignment = alignment; _lineBreakWithoutSpaces = lineBreakWithoutSpaces; - // store locally common line height - _commonLineHeight = _fontAtlas->getCommonLineHeight(); - if (_commonLineHeight <= 0) - return false; - -// int numLetter = 0; - unsigned short* utf16String = cc_utf8_to_utf16(stringToRender.c_str()); + unsigned short* utf16String = cc_utf8_to_utf16(text.c_str()); if(!utf16String) return false; - _cascadeColorEnabled = true; - setCurrentString(utf16String); setOriginalString(utf16String); diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index ea7462ab50..4b8de8163e 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -54,23 +54,44 @@ enum class LabelEffect { struct FontLetterDefinition; class FontAtlas; +typedef struct _ttfConfig +{ + std::string fontFilePath; + int fontSize; + GlyphCollection glyphs; + const char *customGlyphs; + bool distanceFieldEnable; + _ttfConfig(const char* filePath,int fontSize = 36, const GlyphCollection& glyphs = GlyphCollection::NEHE, + const char *customGlyphs = nullptr,bool useDistanceField = false) + :fontFilePath(filePath) + ,fontSize(fontSize) + ,glyphs(glyphs) + ,customGlyphs(customGlyphs) + ,distanceFieldEnable(useDistanceField) + {} +}TTFConfig; class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public LabelTextFormatProtocol { public: - - // static create - static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false); - - static Label* createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0); - - bool setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false); + static Label* create(); + static Label* createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment = TextHAlignment::CENTER, int lineWidth = 0); + + static Label* createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment = TextHAlignment::CENTER, int lineWidth = 0); + + bool setTTFConfig(const TTFConfig& ttfConfig); + + bool setBMFontFilePath(const std::string& bmfontFilePath); + + bool setText(const std::string& text, const TextHAlignment& alignment = TextHAlignment::LEFT, float lineWidth = 0, bool lineBreakWithoutSpaces = false); + + //only support for TTF void setLabelEffect(LabelEffect effect,const Color3B& effectColor); - virtual void setString(const std::string &stringToRender) override; - void setString(const std::string &stringToRender,bool multilineEnable); + virtual void setString(const std::string &text) override; + void setString(const std::string &text,bool multilineEnable); virtual void setAlignment(TextHAlignment alignment); virtual void setWidth(float width); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); @@ -127,15 +148,13 @@ private: /** * @js NA */ - Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField = false,bool useA8Shader = false); + Label(FontAtlas *atlas = nullptr, TextHAlignment alignment = TextHAlignment::CENTER, bool useDistanceField = false,bool useA8Shader = false); /** * @js NA * @lua NA */ ~Label(); - static Label* createWithAtlas(FontAtlas *atlas, TextHAlignment alignment = TextHAlignment::LEFT, int lineSize = 0, bool useDistanceField = false,bool useA8Shader = false); - void setFontSize(int fontSize); bool init(); @@ -151,7 +170,6 @@ private: virtual void updateColor() override; - //! used for optimization Sprite *_reusedLetter; std::vector _lettersInfo; diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index a33c70d7bd..4c9597201a 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -16af4ad046f4db00af7a229d89c406054d8616c3 \ No newline at end of file +52164446e797e85d5d6d746eb85e915c8eb7df15 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index 9d3d063102..d779ae6a86 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -158,20 +158,19 @@ LabelTTFAlignmentNew::LabelTTFAlignmentNew() { auto s = Director::getInstance()->getWinSize(); - auto ttf0 = Label::createWithTTF("Alignment 0\nnew line", "fonts/tahoma.ttf", 32); - ttf0->setAlignment(TextHAlignment::LEFT); + TTFConfig config("fonts/tahoma.ttf",32); + + auto ttf0 = Label::createWithTTF(config,"Alignment 0\nnew line",TextHAlignment::LEFT); ttf0->setPosition(Point(s.width/2,(s.height/6)*2 - 30)); ttf0->setAnchorPoint(Point(0.5f,0.5f)); this->addChild(ttf0); - auto ttf1 = Label::createWithTTF("Alignment 1\nnew line", "fonts/tahoma.ttf", 32); - ttf1->setAlignment(TextHAlignment::CENTER); + auto ttf1 = Label::createWithTTF(config,"Alignment 1\nnew line",TextHAlignment::CENTER); ttf1->setPosition(Point(s.width/2,(s.height/6)*3 - 30)); ttf1->setAnchorPoint(Point(0.5f,0.5f)); this->addChild(ttf1); - auto ttf2 = Label::createWithTTF("Alignment 2\nnew line", "fonts/tahoma.ttf", 32); - ttf1->setAlignment(TextHAlignment::RIGHT); + auto ttf2 = Label::createWithTTF(config,"Alignment 2\nnew line",TextHAlignment::RIGHT); ttf2->setPosition(Point(s.width/2,(s.height/6)*4 - 30)); ttf2->setAnchorPoint(Point(0.5f,0.5f)); this->addChild(ttf2); @@ -194,7 +193,7 @@ LabelFNTColorAndOpacity::LabelFNTColorAndOpacity() auto col = LayerColor::create( Color4B(128,128,128,255) ); addChild(col, -10); - auto label1 = Label::createWithBMFont("Test", "fonts/bitmapFontTest2.fnt"); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test"); label1->setAnchorPoint( Point(0,0) ); addChild(label1, 0, kTagBitmapAtlas1); @@ -204,13 +203,13 @@ LabelFNTColorAndOpacity::LabelFNTColorAndOpacity() auto repeat = RepeatForever::create(seq); label1->runAction(repeat); - auto label2 = Label::createWithBMFont("Test", "fonts/bitmapFontTest2.fnt"); + auto label2 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test"); label2->setAnchorPoint( Point(0.5f, 0.5f) ); label2->setColor( Color3B::RED ); addChild(label2, 0, kTagBitmapAtlas2); label2->runAction( repeat->clone() ); - auto label3 = Label::createWithBMFont("Test", "fonts/bitmapFontTest2.fnt"); + auto label3 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test"); label3->setAnchorPoint( Point(1,1) ); addChild(label3, 0, kTagBitmapAtlas3); @@ -252,7 +251,7 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() _time = 0; // Upper Label - auto label = Label::createWithBMFont("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas"); addChild(label); auto s = Director::getInstance()->getWinSize(); @@ -289,7 +288,7 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() // Bottom Label - auto label2 = Label::createWithBMFont("00.0", "fonts/bitmapFontTest.fnt"); + auto label2 = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "00.0"); addChild(label2, 0, kTagBitmapAtlas2); label2->setPosition( Point(s.width/2.0f, 80) ); @@ -341,7 +340,7 @@ std::string LabelFNTSpriteActions::subtitle() const LabelFNTPadding::LabelFNTPadding() { - auto label = Label::createWithBMFont("abcdefg", "fonts/bitmapFontTest4.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "abcdefg"); addChild(label); auto s = Director::getInstance()->getWinSize(); @@ -365,17 +364,17 @@ LabelFNTOffset::LabelFNTOffset() auto s = Director::getInstance()->getWinSize(); Label* label = NULL; - label = Label::createWithBMFont("FaFeFiFoFu", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "FaFeFiFoFu"); addChild(label); label->setPosition( Point(s.width/2, s.height/2+50) ); label->setAnchorPoint( Point(0.5f, 0.5f) ) ; - label = Label::createWithBMFont("fafefifofu", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "fafefifofu"); addChild(label); label->setPosition( Point(s.width/2, s.height/2) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); - label = Label::createWithBMFont("aeiou", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "aeiou"); addChild(label); label->setPosition( Point(s.width/2, s.height/2-50) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); @@ -396,19 +395,19 @@ LabelFNTColor::LabelFNTColor() auto s = Director::getInstance()->getWinSize(); Label* label = NULL; - label = Label::createWithBMFont("Blue", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Blue"); label->setColor( Color3B::BLUE ); addChild(label); label->setPosition( Point(s.width/2, s.height/4) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); - label = Label::createWithBMFont("Red", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Red"); addChild(label); label->setPosition( Point(s.width/2, 2*s.height/4) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); label->setColor( Color3B::RED ); - label = Label::createWithBMFont("G", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Green"); addChild(label); label->setPosition( Point(s.width/2, 3*s.height/4) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); @@ -433,7 +432,7 @@ LabelFNTHundredLabels::LabelFNTHundredLabels() { char str[6] = {0}; sprintf(str, "-%d-", i); - auto label = Label::createWithBMFont(str, "fonts/bitmapFontTest.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", str); addChild(label); auto s = Director::getInstance()->getWinSize(); @@ -459,7 +458,7 @@ LabelFNTMultiLine::LabelFNTMultiLine() Size s; // Left - auto label1 = Label::createWithBMFont(" Multi line\nLeft", "fonts/bitmapFontTest3.fnt"); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", " Multi line\nLeft"); label1->setAnchorPoint(Point(0,0)); addChild(label1, 0, kTagBitmapAtlas1); @@ -468,7 +467,7 @@ LabelFNTMultiLine::LabelFNTMultiLine() // Center - auto label2 = Label::createWithBMFont("Multi line\nCenter", "fonts/bitmapFontTest3.fnt"); + auto label2 = Label::createWithBMFont( "fonts/bitmapFontTest3.fnt", "Multi line\nCenter"); label2->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label2, 0, kTagBitmapAtlas2); @@ -476,7 +475,7 @@ LabelFNTMultiLine::LabelFNTMultiLine() CCLOG("content size: %.2fx%.2f", s.width, s.height); // right - auto label3 = Label::createWithBMFont("Multi line\nRight\nThree lines Three", "fonts/bitmapFontTest3.fnt"); + auto label3 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "Multi line\nRight\nThree lines Three"); label3->setAnchorPoint(Point(1, 1)); addChild(label3, 0, kTagBitmapAtlas3); @@ -504,19 +503,18 @@ LabelFNTandTTFEmpty::LabelFNTandTTFEmpty() float delta = s.height/4; // LabelBMFont - auto label1 = Label::createWithBMFont("", "fonts/bitmapFontTest3.fnt", TextHAlignment::CENTER, s.width); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "", TextHAlignment::CENTER, s.width); addChild(label1, 0, kTagBitmapAtlas1); label1->setAnchorPoint(Point(0.5f, 0.5f)); label1->setPosition(Point(s.width/2, delta)); // LabelTTF - auto label2 = Label::createWithTTF("", "fonts/arial.ttf", 48, s.width, TextHAlignment::CENTER,GlyphCollection::NEHE); + TTFConfig ttfConfig("fonts/arial.ttf",48); + auto label2 = Label::createWithTTF(ttfConfig,"", TextHAlignment::CENTER,s.width); addChild(label2, 0, kTagBitmapAtlas2); label2->setAnchorPoint(Point(0.5f, 0.5f)); label2->setPosition(Point(s.width/2, delta * 2)); - - schedule(schedule_selector(LabelFNTandTTFEmpty::updateStrings), 1.0f); setEmpty = false; @@ -558,7 +556,7 @@ LabelFNTRetina::LabelFNTRetina() auto s = Director::getInstance()->getWinSize(); // LabelBMFont - auto label1 = Label::createWithBMFont("TESTING RETINA DISPLAY", "fonts/konqa32.fnt"); + auto label1 = Label::createWithBMFont("fonts/konqa32.fnt", "TESTING RETINA DISPLAY"); label1->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label1); label1->setPosition(Point(s.width/2, s.height/2)); @@ -582,7 +580,7 @@ LabelFNTGlyphDesigner::LabelFNTGlyphDesigner() addChild(layer, -10); // LabelBMFont - auto label1 = Label::createWithBMFont("Testing Glyph Designer", "fonts/futura-48.fnt"); + auto label1 = Label::createWithBMFont("fonts/futura-48.fnt", "Testing Glyph Designer"); label1->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label1); label1->setPosition(Point(s.width/2, s.height/2)); @@ -603,7 +601,8 @@ LabelTTFUnicodeChinese::LabelTTFUnicodeChinese() auto size = Director::getInstance()->getWinSize(); // Adding "啊" letter at the end of string to make VS2012 happy, otherwise VS will generate errors // like "Error 3 error C2146: syntax error : missing ')' before identifier 'label'"; - auto label = Label::createWithTTF("美好的一天啊", "fonts/wt021.ttf", 55, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, "美好的一天啊"); + TTFConfig ttfConfig("fonts/wt021.ttf",55,GlyphCollection::CUSTOM, "美好的一天啊"); + auto label = Label::createWithTTF(ttfConfig,"美好的一天啊", TextHAlignment::CENTER, size.width); label->setAnchorPoint(Point(0.5f, 0.5f)); label->setPosition(Point(size.width / 2, size.height /2)); this->addChild(label); @@ -622,7 +621,7 @@ std::string LabelTTFUnicodeChinese::subtitle() const LabelFNTUnicodeChinese::LabelFNTUnicodeChinese() { auto size = Director::getInstance()->getWinSize(); - auto label = Label::createWithBMFont("中国", "fonts/bitmapFontChinese.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", "中国"); label->setAnchorPoint(Point(0.5f, 0.5f)); label->setPosition(Point(size.width / 2, size.height /2)); this->addChild(label); @@ -671,8 +670,7 @@ LabelFNTMultiLineAlignment::LabelFNTMultiLineAlignment() auto size = Director::getInstance()->getWinSize(); // create and initialize a Label - this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/markerFelt.fnt", TextHAlignment::CENTER, size.width/1.5); - //this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/bitmapFontTest.fnt", TextHAlignment::CENTER, size.width/1.5); + this->_labelShouldRetain = Label::createWithBMFont("fonts/markerFelt.fnt", LongSentencesExample, TextHAlignment::CENTER, size.width/1.5); this->_labelShouldRetain->setAnchorPoint(Point(0.5f, 0.5f)); this->_labelShouldRetain->retain(); @@ -855,22 +853,22 @@ LabelFNTUNICODELanguages::LabelFNTUNICODELanguages() auto s = Director::getInstance()->getWinSize(); - auto label1 = Label::createWithBMFont(spanish, "fonts/arial-unicode-26.fnt", TextHAlignment::CENTER, 200); + auto label1 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", spanish, TextHAlignment::CENTER, 200); addChild(label1); label1->setAnchorPoint(Point(0.5f, 0.5f)); label1->setPosition(Point(s.width/2, s.height/5*3)); - auto label2 = Label::createWithBMFont(chinese, "fonts/arial-unicode-26.fnt"); + auto label2 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", chinese); addChild(label2); label2->setAnchorPoint(Point(0.5f, 0.5f)); label2->setPosition(Point(s.width/2, s.height/5*2.5)); - auto label3 = Label::createWithBMFont(russian, "fonts/arial-26-en-ru.fnt"); + auto label3 = Label::createWithBMFont("fonts/arial-26-en-ru.fnt", russian); addChild(label3); label3->setAnchorPoint(Point(0.5f, 0.5f)); label3->setPosition(Point(s.width/2, s.height/5*2)); - auto label4 = Label::createWithBMFont(japanese, "fonts/arial-unicode-26.fnt"); + auto label4 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", japanese); addChild(label4); label4->setAnchorPoint(Point(0.5f, 0.5f)); label4->setPosition(Point(s.width/2, s.height/5*1.5)); @@ -894,7 +892,7 @@ LabelFNTBounds::LabelFNTBounds() addChild(layer, -10); // LabelBMFont - label1 = Label::createWithBMFont("Testing Glyph Designer", "fonts/boundsTestFont.fnt", TextHAlignment::CENTER, s.width); + label1 = Label::createWithBMFont("fonts/boundsTestFont.fnt", "Testing Glyph Designer", TextHAlignment::CENTER, s.width); label1->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label1); label1->setPosition(Point(s.width/2, s.height/2)); @@ -946,7 +944,8 @@ LabelTTFLongLineWrapping::LabelTTFLongLineWrapping() auto size = Director::getInstance()->getWinSize(); // Long sentence - auto label1 = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 28, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + TTFConfig ttfConfig("fonts/arial.ttf", 28); + auto label1 = Label::createWithTTF(ttfConfig, LongSentencesExample, TextHAlignment::CENTER,size.width); label1->setPosition( Point(size.width/2, size.height/2) ); label1->setAnchorPoint(Point(0.5, 1.0)); addChild(label1); @@ -966,22 +965,23 @@ LabelTTFColor::LabelTTFColor() { auto size = Director::getInstance()->getWinSize(); + TTFConfig ttfConfig("fonts/arial.ttf", 35); // Green - auto label1 = Label::createWithTTF("Green", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + auto label1 = Label::createWithTTF(ttfConfig,"Green", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height/5 * 1.5) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point(0.5, 0.5)); addChild(label1); // Red - auto label2 = Label::createWithTTF("Red", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + auto label2 = Label::createWithTTF(ttfConfig,"Red", TextHAlignment::CENTER, size.width); label2->setPosition( Point(size.width/2, size.height/5 * 2.0) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point(0.5, 0.5)); addChild(label2); // Blue - auto label3 = Label::createWithTTF("Blue", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + auto label3 = Label::createWithTTF(ttfConfig,"Blue", TextHAlignment::CENTER, size.width); label3->setPosition( Point(size.width/2, size.height/5 * 2.5) ); label3->setColor( Color3B::BLUE ); label3->setAnchorPoint(Point(0.5, 0.5)); @@ -1001,12 +1001,10 @@ std::string LabelTTFColor::subtitle() const LabelTTFDynamicAlignment::LabelTTFDynamicAlignment() { auto size = Director::getInstance()->getWinSize(); - - _label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + TTFConfig ttfConfig("fonts/arial.ttf", 45); + _label = Label::createWithTTF(ttfConfig,LongSentencesExample, TextHAlignment::CENTER, size.width); _label->setPosition( Point(size.width/2, size.height/2) ); - _label->setAnchorPoint(Point(0.5, 0.5)); - - + _label->setAnchorPoint(Point(0.5, 0.5)); auto menu = Menu::create( MenuItemFont::create("Left", CC_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentLeft, this)), @@ -1074,21 +1072,24 @@ LabelTTFUnicodeNew::LabelTTFUnicodeNew() float vStep = size.height/9; float vSize = size.height; - + TTFConfig ttfConfig("fonts/arial.ttf", 45,GlyphCollection::ASCII); // Spanish - auto label1 = Label::createWithTTF("Buen día, ¿cómo te llamas?", "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::ASCII); + auto label1 = Label::createWithTTF(ttfConfig,"Buen día, ¿cómo te llamas?", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, vSize - (vStep * 4.5)) ); label1->setAnchorPoint(Point(0.5, 0.5)); addChild(label1); // German - auto label2 = Label::createWithTTF("In welcher Straße haben Sie gelebt?", "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::ASCII); + auto label2 = Label::createWithTTF(ttfConfig,"In welcher Straße haben Sie gelebt?", TextHAlignment::CENTER,size.width); label2->setPosition( Point(size.width/2, vSize - (vStep * 5.5)) ); label2->setAnchorPoint(Point(0.5, 0.5)); addChild(label2); // chinese - auto label3 = Label::createWithTTF(chinese, "fonts/wt021.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, chinese.c_str()); + ttfConfig.fontFilePath = "fonts/wt021.ttf"; + ttfConfig.glyphs = GlyphCollection::CUSTOM; + ttfConfig.customGlyphs = chinese.c_str(); + auto label3 = Label::createWithTTF(ttfConfig,chinese, TextHAlignment::CENTER,size.width); label3->setPosition( Point(size.width/2, vSize - (vStep * 6.5)) ); label3->setAnchorPoint(Point(0.5, 0.5)); addChild(label3); @@ -1118,9 +1119,10 @@ LabelTTFFontsTestNew::LabelTTFFontsTestNew() #define arraysize(ar) (sizeof(ar) / sizeof(ar[0])) auto size = Director::getInstance()->getWinSize(); - + TTFConfig ttfConfig(ttfpaths[0],40, GlyphCollection::NEHE); for(size_t i=0;i < arraysize(ttfpaths); ++i) { - auto label = Label::createWithTTF( ttfpaths[i], ttfpaths[i], 40, 0, TextHAlignment::CENTER, GlyphCollection::NEHE); + ttfConfig.fontFilePath = ttfpaths[i]; + auto label = Label::createWithTTF(ttfConfig, ttfpaths[i], TextHAlignment::CENTER,0); if( label ) { label->setPosition( Point(size.width/2, ((size.height * 0.6)/arraysize(ttfpaths) * i) + (size.height/5))); @@ -1147,7 +1149,7 @@ LabelBMFontTestNew::LabelBMFontTestNew() { auto size = Director::getInstance()->getWinSize(); - auto label1 = Label::createWithBMFont("Hello World, this is testing the new Label using fnt file", "fonts/bitmapFontTest2.fnt", TextHAlignment::CENTER, size.width); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Hello World, this is testing the new Label using fnt file", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height/2) ); label1->setAnchorPoint(Point(0.5, 0.5)); addChild(label1); @@ -1166,8 +1168,9 @@ std::string LabelBMFontTestNew::subtitle() const LabelTTFDistanceField::LabelTTFDistanceField() { auto size = Director::getInstance()->getWinSize(); + TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); - auto label1 = Label::createWithTTF("Distance Field", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label1 = Label::createWithTTF(ttfConfig,"Distance Field",TextHAlignment::CENTER,size.width); label1->setPosition( Point(size.width/2, size.height/2) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point(0.5, 0.5)); @@ -1180,7 +1183,7 @@ LabelTTFDistanceField::LabelTTFDistanceField() nullptr); label1->runAction(RepeatForever::create(action)); - auto label2 = Label::createWithTTF("Distance Field", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label2 = Label::createWithTTF(ttfConfig,"Distance Field",TextHAlignment::CENTER,size.width); label2->setPosition( Point(size.width/2, size.height/5) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point(0.5, 0.5)); @@ -1205,21 +1208,23 @@ LabelTTFDistanceFieldEffect::LabelTTFDistanceFieldEffect() auto bg = LayerColor::create(Color4B(200,191,231,255)); this->addChild(bg); - auto label1 = Label::createWithTTF("Glow", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); + + auto label1 = Label::createWithTTF(ttfConfig,"Glow", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height*0.5) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point(0.5, 0.5)); label1->setLabelEffect(LabelEffect::GLOW,Color3B::YELLOW); addChild(label1); - auto label2 = Label::createWithTTF("Outline", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label2 = Label::createWithTTF(ttfConfig,"Outline", TextHAlignment::CENTER, size.width); label2->setPosition( Point(size.width/2, size.height*0.375) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point(0.5, 0.5)); label2->setLabelEffect(LabelEffect::OUTLINE,Color3B::BLUE); addChild(label2); - auto label3 = Label::createWithTTF("Shadow", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label3 = Label::createWithTTF(ttfConfig,"Shadow", TextHAlignment::CENTER, size.width); label3->setPosition( Point(size.width/2, size.height*0.25f) ); label3->setColor( Color3B::RED ); label3->setAnchorPoint(Point(0.5, 0.5)); diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index d23091db12..0cee1ffbd1 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -764,20 +764,22 @@ void DirectorEventTest::onEnter() Size s = Director::getInstance()->getWinSize(); - _label1 = Label::createWithTTF("Update: 0", "fonts/arial.ttf", 20); + TTFConfig ttfConfig("fonts/arial.ttf", 20); + + _label1 = Label::createWithTTF(ttfConfig, "Update: 0"); _label1->setPosition(30,s.height/2 + 60); this->addChild(_label1); - _label2 = Label::createWithTTF("Visit: 0", "fonts/arial.ttf", 20); + _label2 = Label::createWithTTF(ttfConfig, "Visit: 0"); _label2->setPosition(30,s.height/2 + 20); this->addChild(_label2); - _label3 = Label::createWithTTF("Draw: 0", "fonts/arial.ttf", 20); + _label3 = Label::createWithTTF(ttfConfig, "Draw: 0"); _label3->setPosition(30,30); _label3->setPosition(30,s.height/2 - 20); this->addChild(_label3); - _label4 = Label::createWithTTF("Projection: 0", "fonts/arial.ttf", 20); + _label4 = Label::createWithTTF(ttfConfig, "Projection: 0"); _label4->setPosition(30,30); _label4->setPosition(30,s.height/2 - 60); this->addChild(_label4); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp index 317bbb8a60..50d60d84fa 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp @@ -86,6 +86,7 @@ void LabelMainScene::initWithSubTest(int nodes) _lastRenderedCount = 0; _quantityNodes = 0; + _accumulativeTime = 0.0f; _labelContainer = Layer::create(); addChild(_labelContainer); @@ -212,15 +213,18 @@ void LabelMainScene::onIncrease(Object* sender) } break; case kCaseLabelUpdate: - for( int i=0;i< kNodesIncrease;i++) { - auto label = Label::createWithTTF("Label", "fonts/arial.ttf", 60, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); - label->setPosition(Point((size.width/2 + rand() % 50), ((int)size.height/2 + rand() % 50))); - _labelContainer->addChild(label, 1, _quantityNodes); + TTFConfig ttfConfig("fonts/arial.ttf", 60, GlyphCollection::DYNAMIC, nullptr, true); + for( int i=0;i< kNodesIncrease;i++) + { + auto label = Label::createWithTTF(ttfConfig, "Label", TextHAlignment::CENTER, size.width); + label->setPosition(Point((size.width/2 + rand() % 50), ((int)size.height/2 + rand() % 50))); + _labelContainer->addChild(label, 1, _quantityNodes); - _quantityNodes++; - } - break; + _quantityNodes++; + } + break; + } case kCaseLabelBMFontBigLabels: for( int i=0;i< kNodesIncrease;i++) { @@ -232,15 +236,18 @@ void LabelMainScene::onIncrease(Object* sender) } break; case kCaseLabelBigLabels: - for( int i=0;i< kNodesIncrease;i++) { - auto label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 60, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr); - label->setPosition(Point((rand() % 50), rand()%((int)size.height/3))); - _labelContainer->addChild(label, 1, _quantityNodes); + TTFConfig ttfConfig("fonts/arial.ttf", 60, GlyphCollection::DYNAMIC); + for( int i=0;i< kNodesIncrease;i++) + { + auto label = Label::createWithTTF(ttfConfig, LongSentencesExample, TextHAlignment::CENTER, size.width); + label->setPosition(Point((rand() % 50), rand()%((int)size.height/3))); + _labelContainer->addChild(label, 1, _quantityNodes); - _quantityNodes++; - } - break; + _quantityNodes++; + } + break; + } default: break; } diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 99f57b9e8e..da69f4695d 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -54,7 +54,7 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat Copying::[*], LabelProtocol::[*], LabelTextFormatProtocol::[*], - Label::[getLettersInfo], + Label::[getLettersInfo createWithTTF setTTFConfig], .*Delegate::[*], PoolManager::[*], Texture2D::[initWithPVRTCData addPVRTCImage releaseData setTexParameters initWithData keepData getPixelFormatInfoMap], From b2038d14d62f36f7ae6a29dc4123a5ce29f1af3a Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Sat, 11 Jan 2014 22:55:23 +0800 Subject: [PATCH 02/24] update lua binding configuration for label. --- tools/tolua/cocos2dx.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index a3fced78fd..e1b5611329 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -48,7 +48,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased], Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns], MenuItem.*::[create setCallback initWithCallback], - Label::[getLettersInfo], + Label::[getLettersInfo createWithTTF setTTFConfig], Copying::[*], LabelProtocol::[*], LabelTextFormatProtocol::[*], From fd481d64a0a5525b7555a032b8b8c050b78b30cb Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 13 Jan 2014 16:32:35 +0800 Subject: [PATCH 03/24] 1.update lua binding configuration for label. 2.recover old method[createWithTTF] --- cocos/2d/CCLabel.cpp | 6 ++++++ cocos/2d/CCLabel.h | 1 + tools/tolua/cocos2dx.ini | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 4775fd2ae8..1802cf43e1 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -66,6 +66,12 @@ Label* Label::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, } } +Label* Label::createWithTTF(const std::string& text, const std::string& fontFilePath, int fontSize, int lineSize /* = 0 */, TextHAlignment alignment /* = TextHAlignment::CENTER */, GlyphCollection glyphs /* = GlyphCollection::NEHE */, const char *customGlyphs /* = 0 */, bool useDistanceField /* = false */) +{ + TTFConfig ttfConfig(fontFilePath.c_str(),fontSize,glyphs,customGlyphs,useDistanceField); + return createWithTTF(ttfConfig,text,alignment,lineSize); +} + Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */) { Label *ret = new Label(); diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 4b8de8163e..f7b92e2021 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -77,6 +77,7 @@ class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public LabelT public: static Label* create(); + CC_DEPRECATED_ATTRIBUTE static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false); static Label* createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment = TextHAlignment::CENTER, int lineWidth = 0); static Label* createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment = TextHAlignment::CENTER, int lineWidth = 0); diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index e1b5611329..622b14aaf4 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -108,7 +108,6 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS ccFontDefinition::[*], Object::[autorelease isEqual acceptVisitor update], UserDefault::[getInstance (s|g)etDataForKey], - Label::[getLettersInfo], EGLViewProtocol::[setTouchDelegate], EGLView::[end swapBuffers], NewTextureAtlas::[*], From 60009a818ed7ba36f8903d6b70e8392c21c325ff Mon Sep 17 00:00:00 2001 From: zhangbin Date: Wed, 15 Jan 2014 12:05:17 +0800 Subject: [PATCH 04/24] closed #3712, Add relative path for CCFileUtils.h in CCConsole.cpp. --- cocos/base/CCConsole.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/base/CCConsole.cpp b/cocos/base/CCConsole.cpp index 9437fc105c..002fb6e071 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -50,7 +50,7 @@ #include "CCScheduler.h" #include "CCScene.h" #include "CCPlatformConfig.h" -#include "CCFileUtils.h" +#include "platform/CCFileUtils.h" #include "CCConfiguration.h" #include "CCTextureCache.h" From 8fac676a82927e608a858744f120f58c9492ffcc Mon Sep 17 00:00:00 2001 From: hbb Date: Wed, 15 Jan 2014 12:39:56 +0800 Subject: [PATCH 05/24] add check data valid in getStringFromFile so far no check would be crashed when getData faild. maybe return an empty string is better. --- cocos/2d/platform/CCFileUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index 3404675922..1434eea8e6 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -547,6 +547,8 @@ static Data getData(const std::string& filename, bool forString) std::string FileUtils::getStringFromFile(const std::string& filename) { Data data = getData(filename, true); + if (! data.getBytes()) + return ""; std::string ret((const char*)data.getBytes()); return ret; } From 04d8c7514cf76151a0f94593b5f8a8c2809c7bbe Mon Sep 17 00:00:00 2001 From: zhangbin Date: Wed, 15 Jan 2014 16:35:08 +0800 Subject: [PATCH 06/24] closed #3688, Solve the bug : LabelAtlas set a shorter string than before, the effect will be wrong. --- cocos/2d/CCAtlasNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 5e88b70832..4fa8442b92 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -158,7 +158,7 @@ void AtlasNode::draw(void) shader, _blendFunc, _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), + _quadsToDraw, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); From 629f111f7d22fd07812c34f9f351ccd0f1138b0b Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 15 Jan 2014 17:21:08 +0800 Subject: [PATCH 07/24] Relieve inherit from LabelProtocol --- cocos/2d/CCLabel.cpp | 100 ++++++------------ cocos/2d/CCLabel.h | 19 ++-- .../PerformanceTest/PerformanceLabelTest.cpp | 2 +- 3 files changed, 40 insertions(+), 81 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 1802cf43e1..a267a41938 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -53,9 +53,9 @@ Label* Label::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, if (ret->setTTFConfig(ttfConfig)) { - if(ttfConfig.distanceFieldEnable) + if(ttfConfig.distanceFieldEnabled) ret->setFontSize(ttfConfig.fontSize); - ret->setText(text,alignment,lineSize); + ret->setString(text,alignment,lineSize); ret->autorelease(); return ret; } @@ -81,7 +81,7 @@ Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::str if (ret->setBMFontFilePath(bmfontFilePath)) { - ret->setText(text,alignment,lineSize); + ret->setString(text,alignment,lineSize); ret->autorelease(); return ret; } @@ -94,7 +94,6 @@ Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::str Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,bool useA8Shader) : _reusedLetter(nullptr) -, _multilineEnable(true) , _commonLineHeight(0.0f) , _lineBreakWithoutSpaces(false) , _width(0.0f) @@ -147,24 +146,15 @@ bool Label::init() return ret; } -bool Label::setTTFConfig(const TTFConfig& ttfConfig) +bool Label::initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false */, bool useA8Shader /* = false */) { - FontAtlas *newAtlas = nullptr; - if(ttfConfig.distanceFieldEnable) - newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, DISTANCEFIELD_ATLAS_FONTSIZE, ttfConfig.glyphs, ttfConfig.customGlyphs,true); - else - newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, ttfConfig.fontSize, ttfConfig.glyphs, ttfConfig.customGlyphs,false); - - if (!newAtlas) - return false; - FontAtlas *oldAtlas = _fontAtlas; bool oldDistanceFieldEnable = _useDistanceField; bool oldA8ShaderEnabel = _useA8Shader; - - _fontAtlas = newAtlas; - _useDistanceField = ttfConfig.distanceFieldEnable; - _useA8Shader = true; + + _fontAtlas = atlas; + _useDistanceField = distanceFieldEnabled; + _useA8Shader = useA8Shader; bool ret = Label::init(); if (oldAtlas) @@ -180,7 +170,7 @@ bool Label::setTTFConfig(const TTFConfig& ttfConfig) _useA8Shader = oldA8ShaderEnabel; Label::init(); - FontAtlasCache::releaseFontAtlas(newAtlas); + FontAtlasCache::releaseFontAtlas(atlas); } } @@ -196,6 +186,20 @@ bool Label::setTTFConfig(const TTFConfig& ttfConfig) return ret; } +bool Label::setTTFConfig(const TTFConfig& ttfConfig) +{ + FontAtlas *newAtlas = nullptr; + if(ttfConfig.distanceFieldEnabled) + newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, DISTANCEFIELD_ATLAS_FONTSIZE, ttfConfig.glyphs, ttfConfig.customGlyphs,true); + else + newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, ttfConfig.fontSize, ttfConfig.glyphs, ttfConfig.customGlyphs,false); + + if (!newAtlas) + return false; + + return initWithFontAtlas(newAtlas,ttfConfig.distanceFieldEnabled,true); +} + bool Label::setBMFontFilePath(const std::string& bmfontFilePath) { FontAtlas *newAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath); @@ -203,57 +207,10 @@ bool Label::setBMFontFilePath(const std::string& bmfontFilePath) if (!newAtlas) return false; - FontAtlas *oldAtlas = _fontAtlas; - bool oldDistanceFieldEnable = _useDistanceField; - bool oldA8ShaderEnabel = _useA8Shader; - - _fontAtlas = newAtlas; - _useDistanceField = false; - _useA8Shader = false; - - bool ret = Label::init(); - if (oldAtlas) - { - if (ret) - { - FontAtlasCache::releaseFontAtlas(oldAtlas); - } - else - { - _fontAtlas = oldAtlas; - _useDistanceField = oldDistanceFieldEnable; - _useA8Shader = oldA8ShaderEnabel; - Label::init(); - - FontAtlasCache::releaseFontAtlas(newAtlas); - } - } - - if (_fontAtlas) - { - _commonLineHeight = _fontAtlas->getCommonLineHeight(); - if (_currentUTF16String) - { - alignText(); - } - } - - return ret; + return initWithFontAtlas(newAtlas); } -void Label::setString(const std::string &text) -{ - _multilineEnable = true; - setText(text, TextHAlignment::CENTER, _width, false); -} - -void Label::setString(const std::string &text,bool multilineEnable) -{ - _multilineEnable = multilineEnable; - setText(text, TextHAlignment::CENTER, _width, false); -} - -bool Label::setText(const std::string& text, const TextHAlignment& alignment /* = TextHAlignment::LEFT */, float lineWidth /* = 0 */, bool lineBreakWithoutSpaces /* = false */) +bool Label::setString(const std::string& text, const TextHAlignment& alignment /* = TextHAlignment::CENTER */, float lineWidth /* = -1 */, bool lineBreakWithoutSpaces /* = false */) { if (!_fontAtlas || _commonLineHeight <= 0) return false; @@ -262,7 +219,10 @@ bool Label::setText(const std::string& text, const TextHAlignment& alignment /* // reset the string resetCurrentString(); - _width = lineWidth; + if(lineWidth >= 0) + { + _width = lineWidth; + } _alignment = alignment; _lineBreakWithoutSpaces = lineBreakWithoutSpaces; @@ -381,7 +341,7 @@ void Label::alignText() _textureAtlas->removeAllQuads(); _fontAtlas->prepareLetterDefinitions(_currentUTF16String); LabelTextFormatter::createStringSprites(this); - if(_multilineEnable && LabelTextFormatter::multilineText(this) ) + if(_width > 0 && LabelTextFormatter::multilineText(this) ) LabelTextFormatter::createStringSprites(this); LabelTextFormatter::alignText(this); diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index f7b92e2021..26dcc89f9a 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -60,7 +60,7 @@ typedef struct _ttfConfig int fontSize; GlyphCollection glyphs; const char *customGlyphs; - bool distanceFieldEnable; + bool distanceFieldEnabled; _ttfConfig(const char* filePath,int fontSize = 36, const GlyphCollection& glyphs = GlyphCollection::NEHE, const char *customGlyphs = nullptr,bool useDistanceField = false) @@ -68,11 +68,11 @@ typedef struct _ttfConfig ,fontSize(fontSize) ,glyphs(glyphs) ,customGlyphs(customGlyphs) - ,distanceFieldEnable(useDistanceField) + ,distanceFieldEnabled(useDistanceField) {} }TTFConfig; -class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public LabelTextFormatProtocol +class CC_DLL Label : public SpriteBatchNode, public LabelTextFormatProtocol { public: static Label* create(); @@ -86,13 +86,11 @@ public: bool setBMFontFilePath(const std::string& bmfontFilePath); - bool setText(const std::string& text, const TextHAlignment& alignment = TextHAlignment::LEFT, float lineWidth = 0, bool lineBreakWithoutSpaces = false); + bool setString(const std::string& text, const TextHAlignment& alignment = TextHAlignment::CENTER, float lineWidth = -1, bool lineBreakWithoutSpaces = false); //only support for TTF void setLabelEffect(LabelEffect effect,const Color3B& effectColor); - virtual void setString(const std::string &text) override; - void setString(const std::string &text,bool multilineEnable); virtual void setAlignment(TextHAlignment alignment); virtual void setWidth(float width); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); @@ -138,7 +136,7 @@ public: virtual void setLabelContentSize(const Size &newSize) override; // carloX - virtual const std::string& getString() const override { static std::string _ret("not implemented"); return _ret; } + virtual const std::string& getString() const { static std::string _ret("not implemented"); return _ret; } void addChild(Node * child, int zOrder=0, int tag=0) override; virtual std::string getDescription() const override; @@ -156,6 +154,8 @@ private: */ ~Label(); + bool initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled = false, bool useA8Shader = false); + void setFontSize(int fontSize); bool init(); @@ -173,9 +173,8 @@ private: //! used for optimization Sprite *_reusedLetter; - std::vector _lettersInfo; - - bool _multilineEnable; + std::vector _lettersInfo; + float _commonLineHeight; bool _lineBreakWithoutSpaces; float _width; diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp index 50d60d84fa..4c9f561b5d 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp @@ -337,7 +337,7 @@ void LabelMainScene::updateText(float dt) case kCaseLabelUpdate: for(const auto &child : children) { Label* label = (Label*)child; - label->setString(text,false); + label->setString(text); } break; default: From 68eddf3cd79faf06d5d211e66d135ce4d5946a15 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Wed, 15 Jan 2014 17:29:07 +0800 Subject: [PATCH 08/24] fix compiling error --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 4c9597201a..e540327313 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -52164446e797e85d5d6d746eb85e915c8eb7df15 \ No newline at end of file +f92acd30f26c52238e94d2ef1f5b11e760980a67 \ No newline at end of file From 4278f024b8b9697ec4b520c6c8c2321d41bd61b7 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 11:17:21 -0800 Subject: [PATCH 09/24] Console::log(format, va_args) is private log(format, va_args) -> static _log(format, va_args) in order to prevent possible resolution errors with overloaded functions. --- CHANGELOG | 1 + cocos/base/CCConsole.cpp | 37 +++++++++++----------- cocos/base/CCConsole.h | 1 - samples/Cpp/TestCpp/Classes/controller.cpp | 1 - 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 68acb827a9..4e7311b166 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ cocos2d-x-3.0final ?.? ? [All] [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. + [FIX] Console: log(format, va_args) is private to prevent possible resolution errors [FIX] Configuration: dumpInfo() -> getInfo() [FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlButton doesn't support to set scale ratio of touchdown state. diff --git a/cocos/base/CCConsole.cpp b/cocos/base/CCConsole.cpp index 002fb6e071..19f7d54048 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -144,24 +144,7 @@ static const char* inet_ntop(int af, const void* src, char* dst, int cnt) // Free functions to log // -// XXX: Deprecated -void CCLog(const char * format, ...) -{ - va_list args; - va_start(args, format); - log(format, args); - va_end(args); -} - -void log(const char * format, ...) -{ - va_list args; - va_start(args, format); - log(format, args); - va_end(args); -} - -void log(const char *format, va_list args) +static void _log(const char *format, va_list args) { char buf[MAX_LOG_LENGTH]; @@ -176,7 +159,7 @@ void log(const char *format, va_list args) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf)); OutputDebugStringW(wszBuf); OutputDebugStringA("\n"); - + WideCharToMultiByte(CP_ACP, 0, wszBuf, sizeof(wszBuf), buf, sizeof(buf), NULL, FALSE); printf("%s\n", buf); @@ -189,6 +172,22 @@ void log(const char *format, va_list args) Director::getInstance()->getConsole()->log(buf); } +// XXX: Deprecated +void CCLog(const char * format, ...) +{ + va_list args; + va_start(args, format); + _log(format, args); + va_end(args); +} + +void log(const char * format, ...) +{ + va_list args; + va_start(args, format); + _log(format, args); + va_end(args); +} // // Console code diff --git a/cocos/base/CCConsole.h b/cocos/base/CCConsole.h index 1218bf8066..7a06d3423f 100644 --- a/cocos/base/CCConsole.h +++ b/cocos/base/CCConsole.h @@ -58,7 +58,6 @@ static const int MAX_LOG_LENGTH = 16*1024; @brief Output Debug message. */ void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2); -void CC_DLL log(const char * format, va_list args); /** Console is helper class that lets the developer control the game from TCP connection. Console will spawn a new thread that will listen to a specified TCP port. diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index 750ba02a9f..b9713167a1 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -151,7 +151,6 @@ TestController::~TestController() void TestController::menuCallback(Object * sender) { - Director::getInstance()->purgeCachedData(); // get the userdata, it's the index of the menu item clicked From f8dc8f0b380175d4e548543e0bbca935c0a79302 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 14:35:26 -0800 Subject: [PATCH 10/24] Renderer performance fixes QuadCommand no longer stores a copy of the quads. Instead it just stores a reference and the MV matrix. Later, the Renderer when it copies the Quads to the queue, it will convert the Quads to world coordinates --- CHANGELOG | 1 + cocos/2d/renderer/CCQuadCommand.cpp | 58 +++-------------------------- cocos/2d/renderer/CCQuadCommand.h | 15 +++++--- cocos/2d/renderer/CCRenderer.cpp | 47 ++++++++++++++++++++++- cocos/2d/renderer/CCRenderer.h | 3 ++ 5 files changed, 64 insertions(+), 60 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4e7311b166..3b3b55d33e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ cocos2d-x-3.0final ?.? ? [FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlButton doesn't support to set scale ratio of touchdown state. [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. + [FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster [FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: Sprites Performance Test has 3 new tests [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index b69fd075d3..f60446871c 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -34,12 +34,11 @@ QuadCommand::QuadCommand() ,_depth(0) ,_textureID(0) ,_blendType(BlendFunc::DISABLE) -,_quadCount(0) -,_capacity(0) +,_quadsCount(0) { _type = RenderCommand::Type::QUAD_COMMAND; _shader = nullptr; - _quad = nullptr; + _quads = nullptr; } void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv) @@ -48,63 +47,16 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* _depth = depth; _textureID = textureID; _blendType = blendType; - _quadCount = quadCount; _shader = shader; - if(quadCount > _capacity ) { - //TODO find a better way to manage quads, current way will result in memory be wasted -// _quad = (V3F_C4B_T2F_Quad*)malloc(sizeof(V3F_C4B_T2F_Quad) * quadCount); - _quad = (V3F_C4B_T2F_Quad*) realloc(_quad, sizeof(*quad) * quadCount ); - _capacity = quadCount; - } + _quadsCount = quadCount; + _quads = quad; - _quadCount = quadCount; - memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount); - - for(int i=0; ibl.vertices.x; - vec1.y = q->bl.vertices.y; - vec1.z = q->bl.vertices.z; - kmVec3Transform(&out1, &vec1, &mv); - q->bl.vertices.x = out1.x; - q->bl.vertices.y = out1.y; - q->bl.vertices.z = out1.z; - - kmVec3 vec2, out2; - vec2.x = q->br.vertices.x; - vec2.y = q->br.vertices.y; - vec2.z = q->br.vertices.z; - kmVec3Transform(&out2, &vec2, &mv); - q->br.vertices.x = out2.x; - q->br.vertices.y = out2.y; - q->br.vertices.z = out2.z; - - kmVec3 vec3, out3; - vec3.x = q->tr.vertices.x; - vec3.y = q->tr.vertices.y; - vec3.z = q->tr.vertices.z; - kmVec3Transform(&out3, &vec3, &mv); - q->tr.vertices.x = out3.x; - q->tr.vertices.y = out3.y; - q->tr.vertices.z = out3.z; - - kmVec3 vec4, out4; - vec4.x = q->tl.vertices.x; - vec4.y = q->tl.vertices.y; - vec4.z = q->tl.vertices.z; - kmVec3Transform(&out4, &vec4, &mv); - q->tl.vertices.x = out4.x; - q->tl.vertices.y = out4.y; - q->tl.vertices.z = out4.z; - } + _mv = mv; } QuadCommand::~QuadCommand() { - free(_quad); } int64_t QuadCommand::generateID() diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index 411dc4913b..b21999ea58 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -41,7 +41,7 @@ public: QuadCommand(); ~QuadCommand(); - void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, + void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount, const kmMat4& mv); // +----------+----------+-----+-----------------------------------+ @@ -60,13 +60,15 @@ public: inline GLuint getTextureID() const { return _textureID; } - inline V3F_C4B_T2F_Quad* getQuad() const { return _quad; } + inline V3F_C4B_T2F_Quad* getQuads() const { return _quads; } - inline ssize_t getQuadCount() const { return _quadCount; } + inline ssize_t getQuadCount() const { return _quadsCount; } inline GLProgram* getShader() const { return _shader; } inline BlendFunc getBlendType() const { return _blendType; } + + inline const kmMat4& getModelView() const { return _mv; } protected: int32_t _materialID; @@ -85,9 +87,10 @@ protected: BlendFunc _blendType; - V3F_C4B_T2F_Quad* _quad; - ssize_t _quadCount; - ssize_t _capacity; + V3F_C4B_T2F_Quad* _quads; + ssize_t _quadsCount; + + kmMat4 _mv; }; NS_CC_END diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 2763f71ef6..5c97dfdae4 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -256,7 +256,9 @@ void Renderer::render() _lastCommand ++; } - memcpy(_quads + _numQuads, cmd->getQuad(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); + memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); + convertToWorldCoordiantes(_quads + _numQuads, cmdQuadCount, cmd->getModelView()); + _numQuads += cmdQuadCount; } else if(commandType == RenderCommand::Type::CUSTOM_COMMAND) @@ -319,6 +321,49 @@ void Renderer::render() _lastMaterialID = 0; } +void Renderer::convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView) +{ + for(ssize_t i=0; ibl.vertices.x; + vec1.y = q->bl.vertices.y; + vec1.z = q->bl.vertices.z; + kmVec3Transform(&out1, &vec1, &modelView); + q->bl.vertices.x = out1.x; + q->bl.vertices.y = out1.y; + q->bl.vertices.z = out1.z; + + kmVec3 vec2, out2; + vec2.x = q->br.vertices.x; + vec2.y = q->br.vertices.y; + vec2.z = q->br.vertices.z; + kmVec3Transform(&out2, &vec2, &modelView); + q->br.vertices.x = out2.x; + q->br.vertices.y = out2.y; + q->br.vertices.z = out2.z; + + kmVec3 vec3, out3; + vec3.x = q->tr.vertices.x; + vec3.y = q->tr.vertices.y; + vec3.z = q->tr.vertices.z; + kmVec3Transform(&out3, &vec3, &modelView); + q->tr.vertices.x = out3.x; + q->tr.vertices.y = out3.y; + q->tr.vertices.z = out3.z; + + kmVec3 vec4, out4; + vec4.x = q->tl.vertices.x; + vec4.y = q->tl.vertices.y; + vec4.z = q->tl.vertices.z; + kmVec3Transform(&out4, &vec4, &modelView); + q->tl.vertices.x = out4.x; + q->tl.vertices.y = out4.y; + q->tl.vertices.z = out4.z; + } +} + void Renderer::drawBatchedQuads() { //TODO we can improve the draw performance by insert material switching command before hand. diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index e732547130..c2dcdccc6f 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -75,9 +75,12 @@ protected: void mapBuffers(); void drawBatchedQuads(); + //Draw the previews queued quads and flush previous context void flush(); + void convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView); + std::stack _commandGroupStack; std::stack _renderStack; From 21c4b2c8935f28eb13e07526089f719025e00afd Mon Sep 17 00:00:00 2001 From: Luis Parravicini Date: Wed, 15 Jan 2014 19:44:57 -0300 Subject: [PATCH 11/24] fixes #3720 --- tools/closure-compiler/obfuscate.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/closure-compiler/obfuscate.py b/tools/closure-compiler/obfuscate.py index 4979edc50e..9572576278 100755 --- a/tools/closure-compiler/obfuscate.py +++ b/tools/closure-compiler/obfuscate.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# create_project.py -# Create cross-platform cocos2d-x project +# obfuscate.py +# Create Ant buildfile to obfuscate game source code # Copyright (c) 2012 cocos2d-x.org # Author: WangZhe @@ -16,9 +16,9 @@ import sys import os, os.path def dumpUsage(): - print "Usage: generate-config.py -input INPUT_PATH -output OUTPUT_PATH -cocos2d COCOS2D_ROOT_PATH" + print "Usage: %s -input INPUT_PATH -output OUTPUT_PATH -cocos2d COCOS2D_ROOT_PATH" % (os.path.basename(__file__)) print "Options:" - print " -intput INPUT_PATH The path to javscript files directory" + print " -input INPUT_PATH The path to javascript files directory" print " -output OUTPUT_PATH The path to the obfuscated javascript file" print " -cocos2d COCOS2D_ROOT_PATH The root path of cocos2d-x, e.g. /workspace/cocos2d-x" print "" @@ -123,7 +123,7 @@ checkParams() generateXmlForCompiler() # print "running ant to generate obfuscated main.js" # os.popen("ant -buildfile obfuscate.xml") -print "Successful! obfuscate.xml is generated." -print "Note: Please reoder the files sequence in obfuscate.xml, keep it the same order as javascript \"requrie\" instruction," -print "then call \"ant -buildfile obfuscate.xml\" to obfuscate your js codes." +print "Successful! obfuscate.xml generated." +print "Note: Please reorder the file's sequence in obfuscate.xml, keep it the same order as javascript \"require\" instruction," +print "then call \"ant -buildfile obfuscate.xml\" to obfuscate your js code." From 65602a4574750b469c093d1dc7f06a36d6627310 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 16:06:47 -0800 Subject: [PATCH 12/24] Updates Xcode, Android and Linux project with new BatchCommand --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos/2d/Android.mk | 1 + cocos/2d/CMakeLists.txt | 1 + cocos/2d/renderer/CCBatchCommand.cpp | 125 ++++++++++++++++++ cocos/2d/renderer/CCBatchCommand.h | 81 ++++++++++++ 5 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 cocos/2d/renderer/CCBatchCommand.cpp create mode 100644 cocos/2d/renderer/CCBatchCommand.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index faa1e4571d..e14906c550 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -3d6ada05d55194dd8e4c10ed8316add7c0d8705c \ No newline at end of file +88c095bbe123ab56df3f7870692c6631f4464c8d \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 303a1da40f..9fca766934 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -122,6 +122,7 @@ renderer/CCFrustum.cpp \ renderer/CCGroupCommand.cpp \ renderer/CCMaterialManager.cpp \ renderer/CCQuadCommand.cpp \ +renderer/CCBatchCommand.cpp \ renderer/CCRenderCommand.cpp \ renderer/CCRenderer.cpp \ renderer/CCRenderMaterial.cpp \ diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 88090ec7c5..8340903c8b 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -144,6 +144,7 @@ set(COCOS2D_SRC renderer/CCGroupCommand.cpp renderer/CCMaterialManager.cpp renderer/CCQuadCommand.cpp + renderer/CCBatchCommand.cpp renderer/CCRenderCommand.cpp renderer/CCRenderer.cpp renderer/CCRenderMaterial.cpp diff --git a/cocos/2d/renderer/CCBatchCommand.cpp b/cocos/2d/renderer/CCBatchCommand.cpp new file mode 100644 index 0000000000..de3fc511cd --- /dev/null +++ b/cocos/2d/renderer/CCBatchCommand.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + + +#include "renderer/CCBatchCommand.h" +#include "ccGLStateCache.h" +#include "CCTextureAtlas.h" + +NS_CC_BEGIN + +BatchCommand::BatchCommand() +: _viewport(0) +, _depth(0) +, _textureID(0) +, _blendType(BlendFunc::DISABLE) +, _textureAtlas(nullptr) +{ + _type = RenderCommand::Type::BATCH_COMMAND; + _shader = nullptr; +} + +void BatchCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform) +{ + _viewport = viewport; + _depth = depth; + _textureID = textureID; + _blendType = blendType; + _shader = shader; + + _textureAtlas = textureAtlas; + + _mv = modelViewTransform; +} + +BatchCommand::~BatchCommand() +{ +} + +int64_t BatchCommand::generateID() +{ + _id = 0; + + //Generate Material ID + //TODO fix shader ID generation + CCASSERT(_shader->getProgram() < pow(2,10), "ShaderID is greater than 2^10"); + //TODO fix texture ID generation + CCASSERT(_textureID < pow(2,18), "TextureID is greater than 2^18"); + + //TODO fix blend id generation + int blendID = 0; + if(_blendType == BlendFunc::DISABLE) + { + blendID = 0; + } + else if(_blendType == BlendFunc::ALPHA_PREMULTIPLIED) + { + blendID = 1; + } + else if(_blendType == BlendFunc::ALPHA_NON_PREMULTIPLIED) + { + blendID = 2; + } + else if(_blendType == BlendFunc::ADDITIVE) + { + blendID = 3; + } + else + { + blendID = 4; + } + + //TODO Material ID should be part of the ID + // + // Temporal hack (later, these 32-bits should be packed in 24-bits + // + // +---------------------+-------------------+----------------------+ + // | Shader ID (10 bits) | Blend ID (4 bits) | Texture ID (18 bits) | + // +---------------------+-------------------+----------------------+ + + _materialID = (int32_t)_shader->getProgram() << 22 + | (int32_t)blendID << 18 + | (int32_t)_textureID << 0; + + //Generate RenderCommandID + _id = (int64_t)_viewport << 61 + | (int64_t)1 << 60 //translucent + | (int64_t)_depth << 36; + + return _id; +} + +void BatchCommand::execute() +{ + // Set material + _shader->use(); + _shader->setUniformsForBuiltins(_mv); + GL::bindTexture2D(_textureID); + GL::blendFunc(_blendType.src, _blendType.dst); + + // Draw + _textureAtlas->drawQuads(); +} + +NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCBatchCommand.h b/cocos/2d/renderer/CCBatchCommand.h new file mode 100644 index 0000000000..d3b2a5245e --- /dev/null +++ b/cocos/2d/renderer/CCBatchCommand.h @@ -0,0 +1,81 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef _CC_BATCHCOMMAND_H_ +#define _CC_BATCHCOMMAND_H_ + +#include "CCRenderCommand.h" +#include "CCGLProgram.h" +#include "CCRenderCommandPool.h" +#include "kazmath/kazmath.h" + +NS_CC_BEGIN + +class TextureAtlas; + +#define CC_NO_TEXTURE 0 + +class BatchCommand : public RenderCommand +{ +public: + + BatchCommand(); + ~BatchCommand(); + + void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform); + + // +----------+----------+-----+-----------------------------------+ + // | | | | | | + // | ViewPort | Transluc | | Depth | Material ID | + // | 3 bits | 1 bit | | 24 bits | 24 bit2 | + // +----------+----------+-----+----------------+------------------+ + virtual int64_t generateID(); + + void execute(); + +protected: + int32_t _materialID; + + //Key Data + int _viewport; /// Which view port it belongs to + + //TODO use material to determine if it's translucent + int32_t _depth; + + //Maternal + GLuint _textureID; + + GLProgram* _shader; +// GLuint _shaderID; + + BlendFunc _blendType; + + TextureAtlas *_textureAtlas; + + // ModelView transform + kmMat4 _mv; +}; +NS_CC_END + +#endif //_CC_BATCHCOMMAND_H_ From 938825360678b8a79c218613ca88f515df4f80e5 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 16:07:38 -0800 Subject: [PATCH 13/24] SpriteBatchCommand and ParticleBatchCommand use the BatchCommand BatchCommand is being used by SpriteBatchCommand and ParticlesBatchCommand This improves performance in batches --- cocos/2d/CCParticleBatchNode.cpp | 28 ++++++++------------------- cocos/2d/CCParticleBatchNode.h | 4 ++-- cocos/2d/CCSpriteBatchNode.cpp | 22 +++++++++------------ cocos/2d/CCSpriteBatchNode.h | 4 ++-- cocos/2d/renderer/CCCustomCommand.cpp | 3 +-- cocos/2d/renderer/CCGroupCommand.cpp | 3 +-- cocos/2d/renderer/CCQuadCommand.cpp | 3 +-- cocos/2d/renderer/CCRenderCommand.h | 1 + cocos/2d/renderer/CCRenderer.cpp | 7 +++++++ 9 files changed, 32 insertions(+), 43 deletions(-) diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 5b78d1256f..773b780997 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -382,26 +382,14 @@ void ParticleBatchNode::draw(void) return; } -// CC_NODE_DRAW_SETUP(); -// -// GL::blendFunc( _blendFunc.src, _blendFunc.dst ); -// -// _textureAtlas->drawQuads(); - - auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - - _quadCommand.init(0, - _vertexZ, - _textureAtlas->getTexture()->getName(), - shader, - _blendFunc, - _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), - mv); - Director::getInstance()->getRenderer()->addCommand(&_quadCommand); + _batchCommand.init(0, + _vertexZ, + _textureAtlas->getTexture()->getName(), + _shaderProgram, + _blendFunc, + _textureAtlas, + _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_batchCommand); CC_PROFILER_STOP("CCParticleBatchNode - draw"); } diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index d4fd276603..bb092e96d2 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -32,7 +32,7 @@ #include "CCNode.h" #include "CCProtocols.h" -#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" NS_CC_BEGIN @@ -146,7 +146,7 @@ private: /** the blend function used for drawing the quads */ BlendFunc _blendFunc; // quad command - QuadCommand _quadCommand; + BatchCommand _batchCommand; }; // end of particle_nodes group diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 3ef2e183e9..502474d00e 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -99,7 +99,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity) _descendants.reserve(capacity); - setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } @@ -356,18 +356,14 @@ void SpriteBatchNode::draw() for(const auto &child: _children) child->updateTransform(); - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - - _quadCommand.init(0, - _vertexZ, - _textureAtlas->getTexture()->getName(), - _shaderProgram, - _blendFunc, - _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), - mv); - Director::getInstance()->getRenderer()->addCommand(&_quadCommand); + _batchCommand.init(0, + _vertexZ, + _textureAtlas->getTexture()->getName(), + _shaderProgram, + _blendFunc, + _textureAtlas, + _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_batchCommand); } void SpriteBatchNode::increaseAtlasCapacity(void) diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index fc140aa391..bbb6294e6d 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -35,7 +35,7 @@ THE SOFTWARE. #include "CCProtocols.h" #include "CCTextureAtlas.h" #include "ccMacros.h" -#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" NS_CC_BEGIN @@ -189,7 +189,7 @@ protected: TextureAtlas *_textureAtlas; BlendFunc _blendFunc; - QuadCommand _quadCommand; // quad command + BatchCommand _batchCommand; // render command // all descendants: children, grand children, etc... // There is not need to retain/release these objects, since they are already retained by _children diff --git a/cocos/2d/renderer/CCCustomCommand.cpp b/cocos/2d/renderer/CCCustomCommand.cpp index 790bd13e69..b0c39f2049 100644 --- a/cocos/2d/renderer/CCCustomCommand.cpp +++ b/cocos/2d/renderer/CCCustomCommand.cpp @@ -27,8 +27,7 @@ NS_CC_BEGIN CustomCommand::CustomCommand() -:RenderCommand() -, func(nullptr) +: func(nullptr) , _viewport(0) , _depth(0) { diff --git a/cocos/2d/renderer/CCGroupCommand.cpp b/cocos/2d/renderer/CCGroupCommand.cpp index 8bd6f85888..4f7707cd76 100644 --- a/cocos/2d/renderer/CCGroupCommand.cpp +++ b/cocos/2d/renderer/CCGroupCommand.cpp @@ -86,8 +86,7 @@ void GroupCommandManager::releaseGroupID(int groupID) } GroupCommand::GroupCommand() -:RenderCommand() -, _viewport(0) +: _viewport(0) , _depth(0) { _type = RenderCommand::Type::GROUP_COMMAND; diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index f60446871c..a19e3f7053 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -29,8 +29,7 @@ NS_CC_BEGIN QuadCommand::QuadCommand() -:RenderCommand() -,_viewport(0) +:_viewport(0) ,_depth(0) ,_textureID(0) ,_blendType(BlendFunc::DISABLE) diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 930ed1ecde..7b6ec54e0c 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -42,6 +42,7 @@ public: { QUAD_COMMAND, CUSTOM_COMMAND, + BATCH_COMMAND, GROUP_COMMAND, UNKNOWN_COMMAND, }; diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 5c97dfdae4..4454f1480f 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -27,6 +27,7 @@ #include "ccGLStateCache.h" #include "CCCustomCommand.h" #include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" #include "CCGroupCommand.h" #include "CCConfiguration.h" #include "CCDirector.h" @@ -267,6 +268,12 @@ void Renderer::render() CustomCommand* cmd = static_cast(command); cmd->execute(); } + else if(commandType == RenderCommand::Type::BATCH_COMMAND) + { + flush(); + BatchCommand* cmd = static_cast(command); + cmd->execute(); + } else if(commandType == RenderCommand::Type::GROUP_COMMAND) { flush(); From ae84650713ea3cbaf8426b45e721d5cef0cd1e98 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 16:09:38 -0800 Subject: [PATCH 14/24] Updates CHANGELOG --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3b3b55d33e..14a94ba772 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,12 +2,14 @@ cocos2d-x-3.0final ?.? ? [All] [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. + [NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% [FIX] Console: log(format, va_args) is private to prevent possible resolution errors [FIX] Configuration: dumpInfo() -> getInfo() [FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlButton doesn't support to set scale ratio of touchdown state. [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. [FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster + [FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20% [FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: Sprites Performance Test has 3 new tests [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected From a410c38e5433097227779443d99abcc20e6a0fce Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 16 Jan 2014 09:55:13 +0800 Subject: [PATCH 15/24] Update VS project file. --- cocos/2d/cocos2d.vcxproj | 2 ++ cocos/2d/cocos2d.vcxproj.filters | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/cocos/2d/cocos2d.vcxproj b/cocos/2d/cocos2d.vcxproj index 90be6eac6d..95f7f385fd 100644 --- a/cocos/2d/cocos2d.vcxproj +++ b/cocos/2d/cocos2d.vcxproj @@ -317,6 +317,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -521,6 +522,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + diff --git a/cocos/2d/cocos2d.vcxproj.filters b/cocos/2d/cocos2d.vcxproj.filters index b57af69e45..6c887936b6 100644 --- a/cocos/2d/cocos2d.vcxproj.filters +++ b/cocos/2d/cocos2d.vcxproj.filters @@ -598,6 +598,9 @@ renderer + + renderer + @@ -1207,5 +1210,8 @@ renderer + + renderer + \ No newline at end of file From 5ef9eef0aee88a747b62f39de676d4d61a12babe Mon Sep 17 00:00:00 2001 From: hbb Date: Thu, 16 Jan 2014 10:09:04 +0800 Subject: [PATCH 16/24] use data.isNull() instead of !data.getBytes() --- cocos/2d/platform/CCFileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index 1434eea8e6..77988ff696 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -547,7 +547,7 @@ static Data getData(const std::string& filename, bool forString) std::string FileUtils::getStringFromFile(const std::string& filename) { Data data = getData(filename, true); - if (! data.getBytes()) + if (data.isNull()) return ""; std::string ret((const char*)data.getBytes()); return ret; From f62c041886df8469706bf793cc132254fa69a455 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 16 Jan 2014 10:27:35 +0800 Subject: [PATCH 17/24] Compilation fix: Updates cocos_files.json and removes unused in template. --- .../multi-platform-cpp/proj.linux/build.sh | 26 ------------------ .../multi-platform-lua/proj.linux/build.sh | 27 ------------------- .../module/cocos_files.json.REMOVED.git-id | 2 +- 3 files changed, 1 insertion(+), 54 deletions(-) delete mode 100755 template/multi-platform-cpp/proj.linux/build.sh delete mode 100755 template/multi-platform-lua/proj.linux/build.sh diff --git a/template/multi-platform-cpp/proj.linux/build.sh b/template/multi-platform-cpp/proj.linux/build.sh deleted file mode 100755 index 99dcf294d3..0000000000 --- a/template/multi-platform-cpp/proj.linux/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# Exit on error -set -e - -rm -rf ../bin -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -#make global libs -cd ../cocos2d -#install depend libs -sudo ./build/install-deps-linux.sh -mkdir -p linux-build -cd linux-build -cmake .. -DBUILD_LIBS_LUA=OFF -DBUILD_HelloCpp=OFF -DBUILD_TestCpp=OFF -DBUILD_HelloLua=OFF -DBUILD_TestLua=OFF -make -j4 - -#make bin -cd $DIR -rm -rf bin -mkdir -p build -cd build -cmake ../.. -make -j4 -cd .. -mv ../bin bin diff --git a/template/multi-platform-lua/proj.linux/build.sh b/template/multi-platform-lua/proj.linux/build.sh deleted file mode 100755 index d1408e62a4..0000000000 --- a/template/multi-platform-lua/proj.linux/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Exit on error -set -e - -rm -rf ../bin -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -#make global libs -cd ../cocos2d -#install depend libs -sudo ./build/install-deps-linux.sh -mkdir -p linux-build -cd linux-build -cmake .. -DBUILD_HelloCpp=OFF -DBUILD_TestCpp=OFF -DBUILD_HelloLua=OFF -DBUILD_TestLua=OFF -make -j4 - -#make bin -cd $DIR -rm -rf bin -mkdir -p build -cd build -cmake ../.. -make -j4 -cd .. -mv ../bin bin -cp ../cocos2d/cocos/scripting/lua/script/* bin/Resources diff --git a/tools/project-creator/module/cocos_files.json.REMOVED.git-id b/tools/project-creator/module/cocos_files.json.REMOVED.git-id index 38b25afe6d..681e527955 100644 --- a/tools/project-creator/module/cocos_files.json.REMOVED.git-id +++ b/tools/project-creator/module/cocos_files.json.REMOVED.git-id @@ -1 +1 @@ -0a2d046187d7848172fadf6ee4a7e80897e6a75c \ No newline at end of file +5ae50c3f2080b46e18ba3f5aee4c5c686d54e13a \ No newline at end of file From 9b490a91240aa27863ebc3629f4b94a6619d036a Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 18:37:07 -0800 Subject: [PATCH 18/24] Sprite: removed _hasChildren _hasChildren has been replaced with !_children.empty() --- CHANGELOG | 3 ++- cocos/2d/CCSprite.cpp | 36 ++++++++++++++---------------------- cocos/2d/CCSprite.h | 1 - 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 14a94ba772..fe83aa6b50 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,7 +9,8 @@ cocos2d-x-3.0final ?.? ? [FIX] ControlButton doesn't support to set scale ratio of touchdown state. [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. [FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster - [FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20% + [FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20% + [FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well [FIX] Tests: TestCpp works with CMake on Windows. [FIX] Tests: Sprites Performance Test has 3 new tests [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 271f1e8db9..8bf5a3d1b1 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -242,9 +242,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) // zwoptex default values _offsetPosition = Point::ZERO; - - _hasChildren = false; - + // clean the Quad memset(&_quad, 0, sizeof(_quad)); @@ -767,7 +765,6 @@ void Sprite::addChild(Node *child, int zOrder, int tag) } //CCNode already sets isReorderChildDirty_ so this needs to be after batchNode check Node::addChild(child, zOrder, tag); - _hasChildren = true; } void Sprite::reorderChild(Node *child, int zOrder) @@ -813,8 +810,6 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup) } Node::removeAllChildrenWithCleanup(cleanup); - - _hasChildren = false; } void Sprite::sortAllChildren() @@ -882,27 +877,24 @@ void Sprite::setDirtyRecursively(bool bValue) { _recursiveDirty = bValue; setDirty(bValue); - // recursively set dirty - if (_hasChildren) - { - for(const auto &child: _children) { - Sprite* sp = dynamic_cast(child); - if (sp) - { - sp->setDirtyRecursively(true); - } + + for(const auto &child: _children) { + Sprite* sp = dynamic_cast(child); + if (sp) + { + sp->setDirtyRecursively(true); } } } // XXX HACK: optimization -#define SET_DIRTY_RECURSIVELY() { \ - if (! _recursiveDirty) { \ - _recursiveDirty = true; \ - setDirty(true); \ - if ( _hasChildren) \ - setDirtyRecursively(true); \ - } \ +#define SET_DIRTY_RECURSIVELY() { \ + if (! _recursiveDirty) { \ + _recursiveDirty = true; \ + setDirty(true); \ + if (!_children.empty()) \ + setDirtyRecursively(true); \ + } \ } void Sprite::setPosition(const Point& pos) diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 0a937a64e1..2081ef8336 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -538,7 +538,6 @@ protected: bool _dirty; /// Whether the sprite needs to be updated bool _recursiveDirty; /// Whether all of the sprite's children needs to be updated - bool _hasChildren; /// Whether the sprite contains children bool _shouldBeHidden; /// should not be drawn because one of the ancestors is not visible kmMat4 _transformToBatch; From c6445b0640d7117cf6eb013f6306bfedf0a5fedf Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 16 Jan 2014 10:41:04 +0800 Subject: [PATCH 19/24] Update CHANGELOG [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index fe83aa6b50..da8bce53e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ cocos2d-x-3.0final ?.? ? [All] + [NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use. [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. [NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% From beb7015d7e0ff62f72273265f320c77d29f87594 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 16 Jan 2014 02:43:13 +0000 Subject: [PATCH 20/24] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index bab1d8a7c5..74cb897b64 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit bab1d8a7c5d8b29f14c8dc19158a8bb994f0e970 +Subproject commit 74cb897b64f7325cf969341e9bc2d87fc7fb1bb7 From 3b20ad5ab7c8f36a96add7bdfed67f5e3d46ab76 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 15 Jan 2014 19:10:40 -0800 Subject: [PATCH 21/24] More renderer optimizations --- cocos/2d/renderer/CCRenderCommand.h | 7 ++--- cocos/2d/renderer/CCRenderer.cpp | 40 ++++++----------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 7b6ec54e0c..887d717d7e 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -50,9 +50,10 @@ public: virtual int64_t generateID() = 0; /** Get Render Command Id */ - virtual inline int64_t getID() { return _id; } - - virtual inline Type getType() { return _type; } + inline int64_t getID() { return _id; } + + /** Returns the Command type */ + inline Type getType() { return _type; } protected: RenderCommand(); diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 4454f1480f..15da8cfbdd 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -333,41 +333,17 @@ void Renderer::convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quanti for(ssize_t i=0; ibl.vertices.x; - vec1.y = q->bl.vertices.y; - vec1.z = q->bl.vertices.z; - kmVec3Transform(&out1, &vec1, &modelView); - q->bl.vertices.x = out1.x; - q->bl.vertices.y = out1.y; - q->bl.vertices.z = out1.z; + kmVec3 *vec1 = (kmVec3*)&q->bl.vertices; + kmVec3Transform(vec1, vec1, &modelView); - kmVec3 vec2, out2; - vec2.x = q->br.vertices.x; - vec2.y = q->br.vertices.y; - vec2.z = q->br.vertices.z; - kmVec3Transform(&out2, &vec2, &modelView); - q->br.vertices.x = out2.x; - q->br.vertices.y = out2.y; - q->br.vertices.z = out2.z; + kmVec3 *vec2 = (kmVec3*)&q->br.vertices; + kmVec3Transform(vec2, vec2, &modelView); - kmVec3 vec3, out3; - vec3.x = q->tr.vertices.x; - vec3.y = q->tr.vertices.y; - vec3.z = q->tr.vertices.z; - kmVec3Transform(&out3, &vec3, &modelView); - q->tr.vertices.x = out3.x; - q->tr.vertices.y = out3.y; - q->tr.vertices.z = out3.z; + kmVec3 *vec3 = (kmVec3*)&q->tr.vertices; + kmVec3Transform(vec3, vec3, &modelView); - kmVec3 vec4, out4; - vec4.x = q->tl.vertices.x; - vec4.y = q->tl.vertices.y; - vec4.z = q->tl.vertices.z; - kmVec3Transform(&out4, &vec4, &modelView); - q->tl.vertices.x = out4.x; - q->tl.vertices.y = out4.y; - q->tl.vertices.z = out4.z; + kmVec3 *vec4 = (kmVec3*)&q->tl.vertices; + kmVec3Transform(vec4, vec4, &modelView); } } From f5c93fc9e6d9b9c285d71408e72a478de6ecd176 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 16 Jan 2014 11:55:42 +0800 Subject: [PATCH 22/24] Update CHANGELOG [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index da8bce53e1..ce30bb23c5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ cocos2d-x-3.0final ?.? ? [All] + [FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong. [NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use. [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. From da32bfd5d7722bc7211d9812dca42d19c844d6dd Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 16 Jan 2014 12:02:37 +0800 Subject: [PATCH 23/24] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index fd5cf6a651..04d52c0ee3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -718,6 +718,9 @@ Developers: Pisces000221 Corrected a few mistakes in the README file of project-creator. + + hbbalfred + Fixed a bug that crash if file doesn't exist when using FileUtils::getStringFromFile. Retired Core Developers: WenSheng Yang From 778292738f09afb2d7c228356c8887e1e9db257a Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 16 Jan 2014 12:03:42 +0800 Subject: [PATCH 24/24] Update CHANGELOG [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index ce30bb23c5..f26d648230 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ cocos2d-x-3.0final ?.? ? [All] + [FIX] Crash if file doesn't exist when using FileUtils::getStringFromFile. [FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong. [NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use. [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands