diff --git a/CHANGELOG b/CHANGELOG index fe1e346007..c4a8ea7282 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ cocos2d-x-3.0final ?.? ? [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] GLCache: glActiveTexture() is cached with GL::activeTexture(). All code MUST call the cached version in order to work correctly [NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use. + [NEW] Label: Integrates LabelAtlas into new Label. [NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% [FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work. diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index e14906c550..b052741ae6 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -88c095bbe123ab56df3f7870692c6631f4464c8d \ No newline at end of file +e1e5a1169e92834330092c45165660c6cbd03609 \ No newline at end of file diff --git a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id index 2603132689..bb3a11cb54 100644 --- a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -b6abaf935c97f8f1dc7a7179e54850928015b442 \ No newline at end of file +1fa58d8cba77ef923c83d2860d5511d28dad6c27 \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 9fca766934..2253bcd7d9 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -47,6 +47,7 @@ CCEventListenerTouch.cpp \ CCEventMouse.cpp \ CCEventTouch.cpp \ CCFont.cpp \ +CCFontCharMap.cpp \ CCFontAtlas.cpp \ CCFontAtlasCache.cpp \ CCFontAtlasFactory.cpp \ diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 4fa8442b92..f86c143d78 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -34,7 +34,7 @@ THE SOFTWARE. #include "ccGLStateCache.h" #include "CCDirector.h" #include "TransformUtils.h" -#include "CCRenderer.h" +#include "renderer/CCRenderer.h" #include "renderer/CCQuadCommand.h" // external diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index cdaf6a3df5..f5bc3bf95d 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -31,9 +31,10 @@ #include "CCShaderCache.h" #include "CCDirector.h" #include "CCDrawingPrimitives.h" -#include "CCRenderer.h" -#include "CCGroupCommand.h" -#include "CCCustomCommand.h" + +#include "renderer/CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN diff --git a/cocos/2d/CCConfiguration.cpp b/cocos/2d/CCConfiguration.cpp index ddbc3cfae9..dbdf12ea14 100644 --- a/cocos/2d/CCConfiguration.cpp +++ b/cocos/2d/CCConfiguration.cpp @@ -31,13 +31,13 @@ THE SOFTWARE. #include "CCDictionary.h" #include "CCInteger.h" #include "CCBool.h" -#include "cocos2d.h" #include "platform/CCFileUtils.h" using namespace std; NS_CC_BEGIN +extern const char* cocos2dVersion(); Configuration* Configuration::s_sharedConfiguration = nullptr; diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 3e06a99c75..d66385e295 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -60,9 +60,10 @@ THE SOFTWARE. #include "CCEventDispatcher.h" #include "CCEventCustom.h" #include "CCFontFreeType.h" -#include "CCRenderer.h" -#include "CCConsole.h" +#include "renderer/CCRenderer.h" #include "renderer/CCFrustum.h" +#include "CCConsole.h" + /** Position of the FPS diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index b920a311c2..3432ad024f 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -26,9 +26,9 @@ #include "CCGL.h" #include "CCEventType.h" #include "CCConfiguration.h" -#include "CCCustomCommand.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCRenderer.h" #include "CCDirector.h" -#include "CCRenderer.h" #include "CCEventListenerCustom.h" #include "CCEventDispatcher.h" diff --git a/cocos/2d/CCFont.cpp b/cocos/2d/CCFont.cpp index dc363cfe02..1c2d3bab86 100644 --- a/cocos/2d/CCFont.cpp +++ b/cocos/2d/CCFont.cpp @@ -28,6 +28,7 @@ #include "CCFontFNT.h" #include "CCFontFreeType.h" +#include "CCFontCharMap.h" #include "edtaa3func.h" NS_CC_BEGIN @@ -116,6 +117,21 @@ Font* Font::createWithFNT(const std::string& fntFilePath) return FontFNT::create(fntFilePath); } +Font* Font::createWithCharMap(const std::string& plistFile) +{ + return FontCharMap::create(plistFile); +} + +Font* Font::createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) +{ + return FontCharMap::create(texture,itemWidth,itemHeight,startCharMap); +} + +Font* Font::createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) +{ + return FontCharMap::create(charMapFile,itemWidth,itemHeight,startCharMap); +} + unsigned char * Font::makeDistanceMap( unsigned char *img, unsigned int width, unsigned int height) { unsigned int pixelAmount = (width + 2 * DistanceMapSpread) * (height + 2 * DistanceMapSpread); diff --git a/cocos/2d/CCFont.h b/cocos/2d/CCFont.h index 440da0808b..f8bb2b5201 100644 --- a/cocos/2d/CCFont.h +++ b/cocos/2d/CCFont.h @@ -28,7 +28,6 @@ #include -#include "cocos2d.h" #include "CCLabel.h" NS_CC_BEGIN @@ -45,6 +44,10 @@ public: // create the font static Font* createWithTTF(const std::string& fntName, int fontSize, GlyphCollection glyphs, const char *customGlyphs); static Font* createWithFNT(const std::string& fntFilePath); + + static Font * createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); + static Font * createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); + static Font * createWithCharMap(const std::string& plistFile); static unsigned char * makeDistanceMap(unsigned char *img, unsigned int width, unsigned int height); void setDistanceFieldEnabled(bool distanceFieldEnabled); diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 9282956d03..6327d1cc31 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -22,10 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "cocos2d.h" + #include "CCFontAtlas.h" #include "CCFont.h" #include "CCFontFreeType.h" +#include "ccUTF8.h" +#include "CCDirector.h" #define PAGE_WIDTH 1024 #define PAGE_HEIGHT 1024 @@ -128,8 +130,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) Rect tempRect; - FontLetterDefinition tempDef; - tempDef.offsetX = 0; + FontLetterDefinition tempDef; tempDef.anchorX = 0.0f; tempDef.anchorY = 1.0f; @@ -141,7 +142,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.width = 0; tempDef.height = 0; tempDef.U = 0; - tempDef.V = 0; + tempDef.V = 0; + tempDef.offsetX = 0; tempDef.offsetY = 0; tempDef.textureID = 0; } @@ -150,7 +152,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) tempDef.validDefinition = true; tempDef.letteCharUTF16 = utf16String[i]; tempDef.width = tempRect.size.width + _letterPadding; - tempDef.height = _currentPageLineHeight - 1; + tempDef.height = _currentPageLineHeight - 1; + tempDef.offsetX = tempRect.origin.x; tempDef.offsetY = tempRect.origin.y; tempDef.commonLineHeight = _currentPageLineHeight; diff --git a/cocos/2d/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h index 0a2d6f215b..b4122e1294 100644 --- a/cocos/2d/CCFontAtlas.h +++ b/cocos/2d/CCFontAtlas.h @@ -26,11 +26,14 @@ #define _CCFontAtlas_h_ #include +#include "CCPlatformMacros.h" +#include "CCObject.h" NS_CC_BEGIN //fwd class Font; +class Texture2D; struct FontLetterDefinition { diff --git a/cocos/2d/CCFontAtlasCache.cpp b/cocos/2d/CCFontAtlasCache.cpp index ccea76b254..ce0f18a54e 100644 --- a/cocos/2d/CCFontAtlasCache.cpp +++ b/cocos/2d/CCFontAtlasCache.cpp @@ -23,6 +23,8 @@ THE SOFTWARE. ****************************************************************************/ +#include + #include "CCFontAtlasCache.h" #include "CCFontAtlasFactory.h" @@ -69,6 +71,65 @@ FontAtlas * FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName) return tempAtlas; } +FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile) +{ + std::string atlasName = generateFontName(plistFile, 0, GlyphCollection::CUSTOM,false); + FontAtlas *tempAtlas = _atlasMap[atlasName]; + + if ( !tempAtlas ) + { + tempAtlas = FontAtlasFactory::createAtlasFromCharMap(plistFile); + if (tempAtlas) + _atlasMap[atlasName] = tempAtlas; + } + else + { + tempAtlas->retain(); + } + + return tempAtlas; +} + +FontAtlas * FontAtlasCache::getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) +{ + char tmp[30]; + sprintf(tmp,"name:%u_%d_%d_%d",texture->getName(),itemWidth,itemHeight,startCharMap); + std::string atlasName = generateFontName(tmp, 0, GlyphCollection::CUSTOM,false); + FontAtlas *tempAtlas = _atlasMap[atlasName]; + + if ( !tempAtlas ) + { + tempAtlas = FontAtlasFactory::createAtlasFromCharMap(texture,itemWidth,itemHeight,startCharMap); + if (tempAtlas) + _atlasMap[atlasName] = tempAtlas; + } + else + { + tempAtlas->retain(); + } + + return tempAtlas; +} + +FontAtlas * FontAtlasCache::getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) +{ + std::string atlasName = generateFontName(charMapFile, 0, GlyphCollection::CUSTOM,false); + FontAtlas *tempAtlas = _atlasMap[atlasName]; + + if ( !tempAtlas ) + { + tempAtlas = FontAtlasFactory::createAtlasFromCharMap(charMapFile,itemWidth,itemHeight,startCharMap); + if (tempAtlas) + _atlasMap[atlasName] = tempAtlas; + } + else + { + tempAtlas->retain(); + } + + return tempAtlas; +} + std::string FontAtlasCache::generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField) { std::string tempName(fontFileName); diff --git a/cocos/2d/CCFontAtlasCache.h b/cocos/2d/CCFontAtlasCache.h index bdc7dd24d1..82353e7949 100644 --- a/cocos/2d/CCFontAtlasCache.h +++ b/cocos/2d/CCFontAtlasCache.h @@ -29,23 +29,24 @@ #include #include -#include "cocos2d.h" #include "CCFontAtlas.h" +#include "CCLabel.h" NS_CC_BEGIN class CC_DLL FontAtlasCache -{ - +{ public: - static FontAtlas * getFontAtlasTTF(const std::string& fontFileName, int size, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false); static FontAtlas * getFontAtlasFNT(const std::string& fontFileName); + + static FontAtlas * getFontAtlasCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); + static FontAtlas * getFontAtlasCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); + static FontAtlas * getFontAtlasCharMap(const std::string& plistFile); static bool releaseFontAtlas(FontAtlas *atlas); -private: - +private: static std::string generateFontName(const std::string& fontFileName, int size, GlyphCollection theGlyphs, bool useDistanceField); static std::unordered_map _atlasMap; }; diff --git a/cocos/2d/CCFontAtlasFactory.cpp b/cocos/2d/CCFontAtlasFactory.cpp index c9d3ebbb3b..3b6d536223 100644 --- a/cocos/2d/CCFontAtlasFactory.cpp +++ b/cocos/2d/CCFontAtlasFactory.cpp @@ -60,4 +60,46 @@ FontAtlas * FontAtlasFactory::createAtlasFromFNT(const std::string& fntFilePath) } } +FontAtlas * FontAtlasFactory::createAtlasFromCharMap(const std::string& plistFile) +{ + Font *font = Font::createWithCharMap(plistFile); + + if(font) + { + return font->createFontAtlas(); + } + else + { + return nullptr; + } +} + +FontAtlas * FontAtlasFactory::createAtlasFromCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) +{ + Font *font = Font::createWithCharMap(texture,itemWidth,itemHeight,startCharMap); + + if(font) + { + return font->createFontAtlas(); + } + else + { + return nullptr; + } +} + +FontAtlas * FontAtlasFactory::createAtlasFromCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) +{ + Font *font = Font::createWithCharMap(charMapFile,itemWidth,itemHeight,startCharMap); + + if(font) + { + return font->createFontAtlas(); + } + else + { + return nullptr; + } +} + NS_CC_END diff --git a/cocos/2d/CCFontAtlasFactory.h b/cocos/2d/CCFontAtlasFactory.h index 2a10cc8d63..7c97430fa4 100644 --- a/cocos/2d/CCFontAtlasFactory.h +++ b/cocos/2d/CCFontAtlasFactory.h @@ -26,8 +26,8 @@ #ifndef _CCFontAtlasFactory_h_ #define _CCFontAtlasFactory_h_ -#include "cocos2d.h" #include "CCFontAtlas.h" +#include "CCLabel.h" NS_CC_BEGIN @@ -39,6 +39,10 @@ public: static FontAtlas * createAtlasFromTTF(const std::string& fntFilePath, int fontSize, GlyphCollection glyphs, const char *customGlyphs = 0, bool useDistanceField = false); static FontAtlas * createAtlasFromFNT(const std::string& fntFilePath); + + static FontAtlas * createAtlasFromCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); + static FontAtlas * createAtlasFromCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); + static FontAtlas * createAtlasFromCharMap(const std::string& plistFile); private: }; diff --git a/cocos/2d/CCFontCharMap.cpp b/cocos/2d/CCFontCharMap.cpp new file mode 100644 index 0000000000..217312762b --- /dev/null +++ b/cocos/2d/CCFontCharMap.cpp @@ -0,0 +1,171 @@ +/**************************************************************************** + Copyright (c) 2013 Zynga Inc. + 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 "CCFontCharMap.h" +#include "CCFontAtlas.h" + +NS_CC_BEGIN + +FontCharMap * FontCharMap::create(const std::string& plistFile) +{ + std::string pathStr = FileUtils::getInstance()->fullPathForFilename(plistFile); + std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/"; + + ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(pathStr.c_str()); + + CCASSERT(dict["version"].asInt() == 1, "Unsupported version. Upgrade cocos2d version"); + + std::string textureFilename = relPathStr + dict["textureFilename"].asString(); + + unsigned int width = dict["itemWidth"].asInt() / CC_CONTENT_SCALE_FACTOR(); + unsigned int height = dict["itemHeight"].asInt() / CC_CONTENT_SCALE_FACTOR(); + unsigned int startChar = dict["firstChar"].asInt(); + + Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(textureFilename); + if (!tempTexture) + { + return nullptr; + } + + FontCharMap *tempFont = new FontCharMap(tempTexture,width,height,startChar); + + if (!tempFont) + { + return nullptr; + } + tempFont->autorelease(); + return tempFont; +} + +FontCharMap* FontCharMap::create(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) +{ + Texture2D *tempTexture = Director::getInstance()->getTextureCache()->addImage(charMapFile); + + if (!tempTexture) + { + return nullptr; + } + + FontCharMap *tempFont = new FontCharMap(tempTexture,itemWidth,itemHeight,startCharMap); + + if (!tempFont) + { + return nullptr; + } + tempFont->autorelease(); + return tempFont; +} + +FontCharMap* FontCharMap::create(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) +{ + FontCharMap *tempFont = new FontCharMap(texture,itemWidth,itemHeight,startCharMap); + + if (!tempFont) + { + return nullptr; + } + tempFont->autorelease(); + return tempFont; +} + +FontCharMap::~FontCharMap() +{ + +} + +Size * FontCharMap::getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const +{ + if (!text) + return 0; + + outNumLetters = cc_wcslen(text); + + if (!outNumLetters) + return 0; + + Size *sizes = new Size[outNumLetters]; + if (!sizes) + return 0; + + int advance = _itemWidth * CC_CONTENT_SCALE_FACTOR(); + for (int c = 0; c < outNumLetters; ++c) + { + sizes[c].width = advance; + } + + return sizes; +} + +Rect FontCharMap::getRectForChar(unsigned short theChar) const +{ + return _charRect; +} + +FontAtlas * FontCharMap::createFontAtlas() +{ + FontAtlas *tempAtlas = new FontAtlas(*this); + if (!tempAtlas) + return nullptr; + + Size s = _texture->getContentSize(); + + int itemsPerColumn = (int)(s.height / _itemHeight); + int itemsPerRow = (int)(s.width / _itemWidth); + + tempAtlas->setCommonLineHeight(_itemHeight); + + FontLetterDefinition tempDefinition; + tempDefinition.textureID = 0; + tempDefinition.anchorX = 0.5f; + tempDefinition.anchorY = 0.5f; + tempDefinition.offsetX = 0.0f; + tempDefinition.offsetY = 0.0f; + tempDefinition.validDefinition = true; + tempDefinition.width = _itemWidth; + tempDefinition.height = _itemHeight; + + int charId = _mapStartChar; + float itemWidthInPixels = _itemWidth * CC_CONTENT_SCALE_FACTOR(); + float itemHeightInPixels = _itemHeight * CC_CONTENT_SCALE_FACTOR(); + for (int row = 0; row < itemsPerColumn; ++row) + { + for (int col = 0; col < itemsPerRow; ++col) + { + tempDefinition.letteCharUTF16 = charId; + + tempDefinition.U = _itemWidth * col; + tempDefinition.V = _itemHeight * row; + + tempAtlas->addLetterDefinition(tempDefinition); + charId++; + } + } + + tempAtlas->addTexture(*_texture,0); + + return tempAtlas; +} + +NS_CC_END \ No newline at end of file diff --git a/cocos/2d/CCFontCharMap.h b/cocos/2d/CCFontCharMap.h new file mode 100644 index 0000000000..83352ddb4e --- /dev/null +++ b/cocos/2d/CCFontCharMap.h @@ -0,0 +1,70 @@ +/**************************************************************************** + Copyright (c) 2013 Zynga Inc. + 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 _CCFontCharMap_h_ +#define _CCFontCharMap_h_ + +#include "cocos2d.h" +#include "CCFont.h" + +NS_CC_BEGIN + +class FontCharMap : public Font +{ +public: + static FontCharMap * create(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); + static FontCharMap * create(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); + static FontCharMap * create(const std::string& plistFile); + + virtual Size* getAdvancesForTextUTF16(unsigned short *text, int &outNumLetters) const override; + virtual Rect getRectForChar(unsigned short theChar) const override; + virtual FontAtlas *createFontAtlas() override; + +protected: + FontCharMap(Texture2D* texture,int itemWidth, int itemHeight, int startCharMap) + :_texture(texture) + ,_mapStartChar(startCharMap) + ,_itemWidth(itemWidth) + ,_itemHeight(itemHeight) + ,_charRect(0,0,itemWidth,itemHeight) + {} + /** + * @js NA + * @lua NA + */ + virtual ~FontCharMap(); + +private: + Texture2D* _texture; + int _mapStartChar; + int _itemWidth; + int _itemHeight; + + Rect _charRect; +}; + +NS_CC_END + +#endif /* defined(_CCFontCharMap_h_) */ diff --git a/cocos/2d/CCFontDefinition.cpp b/cocos/2d/CCFontDefinition.cpp index c0d8af5051..ebb79f3172 100644 --- a/cocos/2d/CCFontDefinition.cpp +++ b/cocos/2d/CCFontDefinition.cpp @@ -23,8 +23,9 @@ THE SOFTWARE. ****************************************************************************/ -#include "cocos2d.h" + #include "CCFontDefinition.h" +#include "CCDirector.h" NS_CC_BEGIN @@ -221,7 +222,6 @@ FontAtlas * FontDefinitionTTF::createFontAtlas() if ( item.second.validDefinition ) { FontLetterDefinition tempDefinition = item.second; - tempDefinition.offsetX = 0; tempDefinition.anchorX = 0.0f; tempDefinition.anchorY = 1.0f; retAtlas->addLetterDefinition(tempDefinition); diff --git a/cocos/2d/CCFontFNT.cpp b/cocos/2d/CCFontFNT.cpp index 93fd5c2410..53eade4046 100644 --- a/cocos/2d/CCFontFNT.cpp +++ b/cocos/2d/CCFontFNT.cpp @@ -25,6 +25,10 @@ #include "CCFontFNT.h" #include "CCFontAtlas.h" +#include "CCLabelBMFont.h" +#include "CCDirector.h" +#include "CCTextureCache.h" +#include "ccUTF8.h" NS_CC_BEGIN diff --git a/cocos/2d/CCFontFNT.h b/cocos/2d/CCFontFNT.h index eec0bd761c..85588a662a 100644 --- a/cocos/2d/CCFontFNT.h +++ b/cocos/2d/CCFontFNT.h @@ -26,11 +26,12 @@ #ifndef _CCFontFNT_h_ #define _CCFontFNT_h_ -#include "cocos2d.h" #include "CCFont.h" NS_CC_BEGIN +class CCBMFontConfiguration; + class FontFNT : public Font { diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 60b5a11954..c503611b71 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -31,6 +31,7 @@ THE SOFTWARE. #include "CCTextImage.h" #include "CCFont.h" #include "CCFontDefinition.h" +#include "platform/CCFileUtils.h" NS_CC_BEGIN @@ -175,7 +176,7 @@ bool FontFreeType::getBBOXFotChar(unsigned short theChar, Rect &outRect) const return false; // store result in the passed rectangle - outRect.origin.x = 0; + outRect.origin.x = _fontRef->glyph->metrics.horiBearingX >> 6; outRect.origin.y = - (_fontRef->glyph->metrics.horiBearingY >> 6); outRect.size.width = (_fontRef->glyph->metrics.width >> 6); outRect.size.height = (_fontRef->glyph->metrics.height >> 6); @@ -267,7 +268,7 @@ Size * FontFreeType::getAdvancesForTextUTF16(unsigned short *text, int &outNumLe int advance = 0; int kerning = 0; - advance = getAdvanceForChar(text[c]) - getBearingXForChar(text[c]); + advance = getAdvanceForChar(text[c]); if (c < (outNumLetters-1)) kerning = getHorizontalKerningForChars(text[c], text[c+1]); @@ -294,7 +295,7 @@ int FontFreeType::getAdvanceForChar(unsigned short theChar) const return 0; // get to the advance for this glyph - return (static_cast(_fontRef->glyph->advance.x >> 6)); + return (static_cast(_fontRef->glyph->metrics.horiAdvance >> 6)); } int FontFreeType::getBearingXForChar(unsigned short theChar) const diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index a267a41938..52f817ef7c 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -27,6 +27,12 @@ #include "CCFontDefinition.h" #include "CCFontAtlasCache.h" #include "CCLabelTextFormatter.h" +#include "CCSprite.h" +#include "CCShaderCache.h" +#include "ccUTF8.h" +#include "CCSpriteFrame.h" +#include "CCDirector.h" +#include "renderer/CCRenderer.h" #define DISTANCEFIELD_ATLAS_FONTSIZE 50 @@ -92,6 +98,93 @@ Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::str } } +Label* Label::createWithCharMap(const std::string& plistFile) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setCharMap(plistFile)) + { + ret->autorelease(); + return ret; + } + else + { + delete ret; + return nullptr; + } +} + +Label* Label::createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setCharMap(texture,itemWidth,itemHeight,startCharMap)) + { + ret->autorelease(); + return ret; + } + else + { + delete ret; + return nullptr; + } +} + +Label* Label::createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setCharMap(charMapFile,itemWidth,itemHeight,startCharMap)) + { + ret->autorelease(); + return ret; + } + else + { + delete ret; + return nullptr; + } +} + +bool Label::setCharMap(const std::string& plistFile) +{ + FontAtlas *newAtlas = FontAtlasCache::getFontAtlasCharMap(plistFile); + + if (!newAtlas) + return false; + + return initWithFontAtlas(newAtlas); +} + +bool Label::setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) +{ + FontAtlas *newAtlas = FontAtlasCache::getFontAtlasCharMap(texture,itemWidth,itemHeight,startCharMap); + + if (!newAtlas) + return false; + + return initWithFontAtlas(newAtlas); +} + +bool Label::setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) +{ + FontAtlas *newAtlas = FontAtlasCache::getFontAtlasCharMap(charMapFile,itemWidth,itemHeight,startCharMap); + + if (!newAtlas) + return false; + + return initWithFontAtlas(newAtlas); +} + Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,bool useA8Shader) : _reusedLetter(nullptr) , _commonLineHeight(0.0f) diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 26dcc89f9a..b34507312e 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -62,12 +62,12 @@ typedef struct _ttfConfig const char *customGlyphs; bool distanceFieldEnabled; - _ttfConfig(const char* filePath,int fontSize = 36, const GlyphCollection& glyphs = GlyphCollection::NEHE, - const char *customGlyphs = nullptr,bool useDistanceField = false) + _ttfConfig(const char* filePath,int size = 36, const GlyphCollection& glyphCollection = GlyphCollection::NEHE, + const char *customGlyphCollection = nullptr,bool useDistanceField = false) :fontFilePath(filePath) - ,fontSize(fontSize) - ,glyphs(glyphs) - ,customGlyphs(customGlyphs) + ,fontSize(size) + ,glyphs(glyphCollection) + ,customGlyphs(customGlyphCollection) ,distanceFieldEnabled(useDistanceField) {} }TTFConfig; @@ -82,10 +82,18 @@ public: static Label* createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment = TextHAlignment::CENTER, int lineWidth = 0); + static Label * createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); + static Label * createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); + static Label * createWithCharMap(const std::string& plistFile); + bool setTTFConfig(const TTFConfig& ttfConfig); bool setBMFontFilePath(const std::string& bmfontFilePath); + bool setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); + bool setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); + bool setCharMap(const std::string& plistFile); + bool setString(const std::string& text, const TextHAlignment& alignment = TextHAlignment::CENTER, float lineWidth = -1, bool lineBreakWithoutSpaces = false); //only support for TTF @@ -172,29 +180,29 @@ private: virtual void updateColor() override; //! used for optimization - Sprite *_reusedLetter; - std::vector _lettersInfo; + Sprite *_reusedLetter; + std::vector _lettersInfo; - float _commonLineHeight; - bool _lineBreakWithoutSpaces; - float _width; - TextHAlignment _alignment; - unsigned short int * _currentUTF16String; - unsigned short int * _originalUTF16String; - Size * _advances; - FontAtlas * _fontAtlas; - bool _isOpacityModifyRGB; + float _commonLineHeight; + bool _lineBreakWithoutSpaces; + float _width; + TextHAlignment _alignment; + unsigned short int * _currentUTF16String; + unsigned short int * _originalUTF16String; + Size * _advances; + FontAtlas * _fontAtlas; + bool _isOpacityModifyRGB; - bool _useDistanceField; - bool _useA8Shader; - int _fontSize; + bool _useDistanceField; + bool _useA8Shader; + int _fontSize; - LabelEffect _currLabelEffect; - Color3B _effectColor; + LabelEffect _currLabelEffect; + Color3B _effectColor; - GLuint _uniformEffectColor; + GLuint _uniformEffectColor; - CustomCommand _customCommand; + CustomCommand _customCommand; }; diff --git a/cocos/2d/CCLabelTextFormatProtocol.h b/cocos/2d/CCLabelTextFormatProtocol.h index bf72775a51..e91d7b875a 100644 --- a/cocos/2d/CCLabelTextFormatProtocol.h +++ b/cocos/2d/CCLabelTextFormatProtocol.h @@ -25,11 +25,16 @@ #ifndef _CCLabelTextFormatProtocol_h_ #define _CCLabelTextFormatProtocol_h_ -#include "CCFontAtlas.h" + #include +#include "CCFontAtlas.h" +#include "CCGeometry.h" +#include "ccTypes.h" + NS_CC_BEGIN +class Sprite; struct LetterInfo { @@ -46,13 +51,13 @@ public: virtual ~LabelTextFormatProtocol() {} - virtual bool recordLetterInfo(const cocos2d::Point& point,unsigned short int theChar, int spriteIndex) = 0; + virtual bool recordLetterInfo(const Point& point,unsigned short int theChar, int spriteIndex) = 0; virtual bool recordPlaceholderInfo(int spriteIndex) = 0; virtual std::vector *getLettersInfo() = 0; virtual float getLetterPosXLeft(int index) const = 0; virtual float getLetterPosXRight(int index) const = 0; // sprite related stuff - virtual cocos2d::Sprite *getLetter(int ID) = 0; + virtual Sprite *getLetter(int ID) = 0; // font related stuff virtual int getCommonLineHeight() const = 0; @@ -60,7 +65,7 @@ public: virtual int getXOffsetForChar(unsigned short c) const = 0; virtual int getYOffsetForChar(unsigned short c) const = 0; virtual int getAdvanceForChar(unsigned short c, int hintPositionInString) const = 0; - virtual cocos2d::Rect getRectForChar(unsigned short c) const = 0; + virtual Rect getRectForChar(unsigned short c) const = 0; // string related stuff virtual int getStringNumLines() const = 0; @@ -68,7 +73,7 @@ public: virtual unsigned short getCharAtStringPosition(int position) const = 0; virtual unsigned short * getUTF8String() const = 0; virtual void assignNewUTF8String(unsigned short *newString) = 0; - virtual TextHAlignment getTextAlignment() const = 0; + virtual TextHAlignment getTextAlignment() const = 0; // label related stuff virtual float getMaxLineWidth() const = 0; diff --git a/cocos/2d/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp index 550d017beb..968d196f18 100644 --- a/cocos/2d/CCLabelTextFormatter.cpp +++ b/cocos/2d/CCLabelTextFormatter.cpp @@ -25,9 +25,9 @@ #include -#include "cocos2d.h" #include "ccUTF8.h" #include "CCLabelTextFormatter.h" +#include "CCDirector.h" using namespace std; @@ -353,7 +353,7 @@ bool LabelTextFormatter::createStringSprites(LabelTextFormatProtocol *theLabel) Point fontPos = Point((float)nextFontPositionX + charXOffset + charRect.size.width * 0.5f + kerningAmount, - (float)nextFontPositionY + yOffset - charRect.size.height * 0.5f); + (float)nextFontPositionY + yOffset - charRect.size.height * 0.5f); if( theLabel->recordLetterInfo(CC_POINT_PIXELS_TO_POINTS(fontPos),c,i) == false) { diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index 1bae6e040c..1b24c97f25 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -44,8 +44,8 @@ THE SOFTWARE. #include "CCEventListenerAcceleration.h" #include "platform/CCDevice.h" #include "CCScene.h" -#include "CCCustomCommand.h" -#include "CCRenderer.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCRenderer.h" NS_CC_BEGIN diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index 4e248b7ea1..fdb0b70fb8 100644 --- a/cocos/2d/CCMotionStreak.cpp +++ b/cocos/2d/CCMotionStreak.cpp @@ -31,8 +31,8 @@ THE SOFTWARE. #include "ccMacros.h" #include "CCDirector.h" #include "CCVertex.h" -#include "CCCustomCommand.h" -#include "CCRenderer.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCRenderer.h" NS_CC_BEGIN diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 90d5647a57..9c24500da0 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -25,9 +25,9 @@ #include "CCNodeGrid.h" #include "CCGrid.h" -#include "CCGroupCommand.h" -#include "CCRenderer.h" -#include "CCCustomCommand.h" +#include "renderer/CCGroupCommand.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 773b780997..b291910422 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -44,7 +44,7 @@ #include "kazmath/GL/matrix.h" #include "CCProfiling.h" #include "renderer/CCQuadCommand.h" -#include "CCRenderer.h" +#include "renderer/CCRenderer.h" NS_CC_BEGIN diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index 579db6c024..8495483116 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -38,9 +38,9 @@ THE SOFTWARE. #include "TransformUtils.h" #include "CCEventType.h" #include "CCConfiguration.h" -#include "CCRenderer.h" +#include "renderer/CCRenderer.h" #include "renderer/CCQuadCommand.h" -#include "CCCustomCommand.h" +#include "renderer/CCCustomCommand.h" // extern #include "kazmath/GL/matrix.h" diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index 7d135a9016..37c754a0ee 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -33,8 +33,8 @@ THE SOFTWARE. #include "CCDirector.h" #include "TransformUtils.h" #include "CCDrawingPrimitives.h" -#include "CCRenderer.h" -#include "CCCustomCommand.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCCustomCommand.h" // extern #include "kazmath/GL/matrix.h" diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index efaad582ef..fcf00452ed 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -38,9 +38,9 @@ THE SOFTWARE. #include "CCEventType.h" #include "CCGrid.h" -#include "CCRenderer.h" -#include "CCGroupCommand.h" -#include "CCCustomCommand.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" // extern #include "kazmath/GL/matrix.h" diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 8bf5a3d1b1..c66c811b1b 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -45,9 +45,9 @@ THE SOFTWARE. #include "CCAffineTransform.h" #include "TransformUtils.h" #include "CCProfiling.h" -#include "CCRenderer.h" +#include "renderer/CCRenderer.h" #include "renderer/CCQuadCommand.h" -#include "CCFrustum.h" +#include "renderer/CCFrustum.h" // external #include "kazmath/GL/matrix.h" diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 502474d00e..fde85639aa 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -43,7 +43,7 @@ THE SOFTWARE. #include "CCProfiling.h" #include "CCLayer.h" #include "CCScene.h" -#include "CCRenderer.h" +#include "renderer/CCRenderer.h" #include "renderer/CCQuadCommand.h" // external #include "kazmath/GL/matrix.h" diff --git a/cocos/2d/CCTextImage.cpp b/cocos/2d/CCTextImage.cpp index d47ab768d0..cd972a172e 100644 --- a/cocos/2d/CCTextImage.cpp +++ b/cocos/2d/CCTextImage.cpp @@ -28,10 +28,10 @@ #include #include -#include "cocos2d.h" #include "CCTextImage.h" #include "CCFontFreeType.h" #include "CCFont.h" +#include "ccUTF8.h" NS_CC_BEGIN @@ -295,7 +295,7 @@ bool TextImage::createPageDefinitions(unsigned short int *inText, int imageWidth return true; } -int TextImage::getNumGlyphsFittingInSize(std::map &glyphDefs, unsigned short int *strUTF8, Font *font, Size *constrainSize, int &outNewSize) +int TextImage::getNumGlyphsFittingInSize(std::unordered_map &glyphDefs, unsigned short int *strUTF8, Font *font, Size *constrainSize, int &outNewSize) { if (!strUTF8) return 0; diff --git a/cocos/2d/CCTextImage.h b/cocos/2d/CCTextImage.h index 1c0da97201..b7baddb561 100644 --- a/cocos/2d/CCTextImage.h +++ b/cocos/2d/CCTextImage.h @@ -23,15 +23,19 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef _TextImage_h_ -#define _TextImage_h_ +#ifndef _CCTextImage_h_ +#define _CCTextImage_h_ -//#include "CCFont.h" #include +#include + +#include "CCPlatformMacros.h" +#include "CCGeometry.h" NS_CC_BEGIN class Font; +class Texture2D; /** @brief GlyphDef defines one single glyph (character) in a text image * @@ -43,27 +47,33 @@ class CC_DLL GlyphDef { public: - GlyphDef() : _validGlyph(false) { /*do nothing*/ } - GlyphDef(unsigned short int letterUTF8, const Rect &rect) { _gliphRect = rect; _uTF16Letter = letterUTF8; } + GlyphDef() : _validGlyph(false) {} + GlyphDef(unsigned short int letterUTF8, const Rect &rect) { + _gliphRect = rect; + _uTF16Letter = letterUTF8; + } - void setUTF16Letter(unsigned short int letterUTF8) { _uTF16Letter = letterUTF8; } - void setRect(const Rect & theRect) { _gliphRect = theRect; } - unsigned short int getUTF8Letter() { return _uTF16Letter; } - const Rect & getRect() const { return _gliphRect; } - void setPadding(float padding) { _padding = padding; } - float getPadding() { return _padding; } - void setCommonHeight(float commonHeight) { _commonHeight = commonHeight; } - float getCommonHeight() { return _commonHeight; } - void setValid(bool isValid) { _validGlyph = isValid; } - bool isValid() { return _validGlyph; } + void setUTF16Letter(unsigned short int letterUTF8) { _uTF16Letter = letterUTF8; } + void setRect(const Rect & theRect) { _gliphRect = theRect; } + + unsigned short int getUTF8Letter() const { return _uTF16Letter; } + const Rect& getRect() const { return _gliphRect; } + + void setPadding(float padding) { _padding = padding; } + float getPadding() const { return _padding; } + + void setCommonHeight(float commonHeight) { _commonHeight = commonHeight; } + float getCommonHeight() const { return _commonHeight; } + + void setValid(bool isValid) { _validGlyph = isValid; } + bool isValid() const { return _validGlyph; } -private: - - Rect _gliphRect; - unsigned short int _uTF16Letter; - float _padding; - float _commonHeight; - bool _validGlyph; +protected: + Rect _gliphRect; + unsigned short int _uTF16Letter; + float _padding; + float _commonHeight; + bool _validGlyph; }; @@ -78,23 +88,21 @@ public: TextLineDef(float x, float y, float width, float height); - float getX() const { return _x; } - float getY() const { return _y; } - float getWidth() const { return _width; } - float getHeight() const { return _height; } + float getX() const { return _x; } + float getY() const { return _y; } + float getWidth() const { return _width; } + float getHeight() const { return _height; } - void addGlyph(GlyphDef theGlyph) { _glyphs.push_back(theGlyph); } - int getNumGlyph() const { return static_cast(_glyphs.size()); } - const GlyphDef & getGlyphAt(int index) const { return _glyphs[index]; } - -private: - - float _x; - float _y; - float _width; - float _height; - std::vector _glyphs; + void addGlyph(GlyphDef theGlyph) { _glyphs.push_back(theGlyph); } + int getNumGlyph() const { return static_cast(_glyphs.size()); } + const GlyphDef & getGlyphAt(int index) const { return _glyphs[index]; } +protected: + float _x; + float _y; + float _width; + float _height; + std::vector _glyphs; }; /** @brief TextPageDef defines one text image page (a TextImage can have/use more than one page) @@ -115,28 +123,26 @@ public: */ ~TextPageDef(); - void addLine(TextLineDef *theLine) { _lines.push_back(theLine); } - int getNumLines() const { return static_cast(_lines.size()); } - TextLineDef * getLineAt(int index) const { return _lines[index]; } - int getWidth() const { return _width; } - int getHeight() const { return _height; } - int getPageNumber() const { return _pageNum; } - void setPageData(unsigned char *data) { _pageData = data; } - const unsigned char * getPageData() const { return _pageData; } - Texture2D *getPageTexture(); + void addLine(TextLineDef *theLine) { _lines.push_back(theLine); } + int getNumLines() const { return static_cast(_lines.size()); } + TextLineDef * getLineAt(int index) const { return _lines[index]; } + int getWidth() const { return _width; } + int getHeight() const { return _height; } + int getPageNumber() const { return _pageNum; } + void setPageData(unsigned char *data) { _pageData = data; } + const unsigned char * getPageData() const { return _pageData; } + Texture2D *getPageTexture(); void preparePageTexture(bool releaseRAWData = true); -private: - +protected: bool generatePageTexture(bool releasePageData = false); - int _pageNum; - int _width; - int _height; - unsigned char * _pageData; - Texture2D * _pageTexture; - std::vector _lines; - + int _pageNum; + int _width; + int _height; + unsigned char * _pageData; + Texture2D* _pageTexture; + std::vector _lines; }; /** @brief CCTextFontPages collection of pages (TextPageDef) @@ -156,13 +162,12 @@ public: */ ~TextFontPagesDef(); - void addPage(TextPageDef *newPage) { _pages.push_back(newPage); } - int getNumPages() const { return static_cast(_pages.size()); } - TextPageDef* getPageAt(int index) const { return _pages[index]; } + void addPage(TextPageDef *newPage) { _pages.push_back(newPage); } + int getNumPages() const { return static_cast(_pages.size()); } + TextPageDef* getPageAt(int index) const { return _pages[index]; } -private: - - std::vector _pages; +protected: + std::vector _pages; }; @@ -184,28 +189,27 @@ public: bool initWithString(const char *text, int width, int height, Font* font, bool releaseRAWData = true); - TextFontPagesDef * getPages() const { return _fontPages; } - Font * getFont() const { return _font; } - -private: + TextFontPagesDef* getPages() const { return _fontPages; } + Font* getFont() const { return _font; } +protected: bool createImageDataFromPages(TextFontPagesDef *thePages, bool releaseRAWData = true); bool addGlyphsToLine(TextLineDef *line, const char *lineText, bool textIsUTF16 = false); bool generateTextGlyphs(const char * text); - int getNumGlyphsFittingInSize(std::map &glyphDefs, unsigned short int *strUTF8, Font *font, Size *constrainSize, int &outNewSize); + int getNumGlyphsFittingInSize(std::unordered_map &glyphDefs, unsigned short int *strUTF8, Font *font, Size *constrainSize, int &outNewSize); bool createPageDefinitions(unsigned short int *inText, int imageWidth, int imageHeight, int lineHeight); unsigned char * preparePageGlyphData(TextPageDef *thePage); // glyph rendering unsigned char * renderGlyphData(TextPageDef *thePage); - std::map _textGlyphs; - TextFontPagesDef * _fontPages; - Font * _font; + std::unordered_map _textGlyphs; + TextFontPagesDef* _fontPages; + Font* _font; }; NS_CC_END -#endif +#endif // _CCTextImage_h_ diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index 8a9818d8fc..2d2787a25d 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -624,11 +624,11 @@ void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start) { glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); // option 1: subdata - //glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * n , &_quads[start] ); - +// glBufferSubData(GL_ARRAY_BUFFER, sizeof(_quads[0])*start, sizeof(_quads[0]) * n , &_quads[start] ); + // option 2: data - // glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW); - +// glBufferData(GL_ARRAY_BUFFER, sizeof(quads_[0]) * (n-start), &quads_[start], GL_DYNAMIC_DRAW); + // option 3: orphaning + glMapBuffer glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * (numberOfQuads-start), nullptr, GL_DYNAMIC_DRAW); void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 8340903c8b..886c2ebc21 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -71,6 +71,7 @@ set(COCOS2D_SRC CCFontDefinition.cpp CCFontFNT.cpp CCFontFreeType.cpp + CCFontCharMap.cpp CCLabel.cpp CCLabelAtlas.cpp CCLabelBMFont.cpp diff --git a/cocos/2d/ccCArray.cpp b/cocos/2d/ccCArray.cpp index 9c43756ffd..b0827eed5c 100644 --- a/cocos/2d/ccCArray.cpp +++ b/cocos/2d/ccCArray.cpp @@ -73,7 +73,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra) { while (arr->max < arr->num + extra) { - CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].", + CCLOGINFO("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].", static_cast(arr->max), static_cast(arr->max*2)); diff --git a/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h b/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h index bae95bcfea..f2d39c3c10 100644 --- a/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h +++ b/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h @@ -38,7 +38,7 @@ varying vec2 v_texCoord; \n\ \n\ void main() \n\ { \n\ - gl_Position = CC_PMatrix * a_position; \n\ + gl_Position = CC_PMatrix * a_position; \n\ v_fragmentColor = a_color; \n\ v_texCoord = a_texCoord; \n\ } \n\ diff --git a/cocos/2d/ccUTF8.cpp b/cocos/2d/ccUTF8.cpp index 6e70a313d5..c4b9893a04 100644 --- a/cocos/2d/ccUTF8.cpp +++ b/cocos/2d/ccUTF8.cpp @@ -279,7 +279,7 @@ cc_utf8_get_char (const char * p) unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1 */, int* rUtf16Size/* = nullptr */) { - unsigned short len = cc_utf8_strlen(str_old, length); + long len = cc_utf8_strlen(str_old, length); if (rUtf16Size != nullptr) { *rUtf16Size = len; } diff --git a/cocos/2d/cocos2d.cpp b/cocos/2d/cocos2d.cpp index 99adc6518c..34b10b7f09 100644 --- a/cocos/2d/cocos2d.cpp +++ b/cocos/2d/cocos2d.cpp @@ -25,7 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "cocos2d.h" +#include "CCPlatformMacros.h" NS_CC_BEGIN diff --git a/cocos/2d/cocos2d.vcxproj b/cocos/2d/cocos2d.vcxproj index 95f7f385fd..9c7bd8f40f 100644 --- a/cocos/2d/cocos2d.vcxproj +++ b/cocos/2d/cocos2d.vcxproj @@ -248,6 +248,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -429,6 +430,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 6c887936b6..6a28597e2d 100644 --- a/cocos/2d/cocos2d.vcxproj.filters +++ b/cocos/2d/cocos2d.vcxproj.filters @@ -601,6 +601,9 @@ renderer + + label_nodes + @@ -1213,5 +1216,8 @@ renderer + + label_nodes + \ No newline at end of file diff --git a/cocos/2d/platform/linux/CCImage.cpp b/cocos/2d/platform/linux/CCImage.cpp index 45602638b5..0d53db0c19 100644 --- a/cocos/2d/platform/linux/CCImage.cpp +++ b/cocos/2d/platform/linux/CCImage.cpp @@ -459,7 +459,7 @@ bool Image::initWithString( { bool bRet = false; do - { + { CC_BREAK_IF(! pText); BitmapDC &dc = sharedBitmapDC(); diff --git a/cocos/2d/renderer/CCCustomCommand.cpp b/cocos/2d/renderer/CCCustomCommand.cpp index b0c39f2049..5bbf2032ea 100644 --- a/cocos/2d/renderer/CCCustomCommand.cpp +++ b/cocos/2d/renderer/CCCustomCommand.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCCustomCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN diff --git a/cocos/2d/renderer/CCFrustum.cpp b/cocos/2d/renderer/CCFrustum.cpp index e02236e3b0..4f88e2356f 100644 --- a/cocos/2d/renderer/CCFrustum.cpp +++ b/cocos/2d/renderer/CCFrustum.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCFrustum.h" +#include "renderer/CCFrustum.h" #include "CCConsole.h" #include diff --git a/cocos/2d/renderer/CCGroupCommand.cpp b/cocos/2d/renderer/CCGroupCommand.cpp index 4f7707cd76..9c0e57eb92 100644 --- a/cocos/2d/renderer/CCGroupCommand.cpp +++ b/cocos/2d/renderer/CCGroupCommand.cpp @@ -23,8 +23,8 @@ ****************************************************************************/ -#include "CCGroupCommand.h" -#include "CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "renderer/CCRenderer.h" #include "CCDirector.h" NS_CC_BEGIN diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 887d717d7e..57fa2e75ce 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -40,11 +40,11 @@ public: enum class Type { + UNKNOWN_COMMAND, QUAD_COMMAND, CUSTOM_COMMAND, BATCH_COMMAND, GROUP_COMMAND, - UNKNOWN_COMMAND, }; virtual int64_t generateID() = 0; diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 3ffa5b583a..df7d41473a 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -22,13 +22,13 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCRenderer.h" -#include "CCShaderCache.h" -#include "ccGLStateCache.h" -#include "CCCustomCommand.h" +#include "renderer/CCRenderer.h" #include "renderer/CCQuadCommand.h" #include "renderer/CCBatchCommand.h" -#include "CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCGroupCommand.h" +#include "CCShaderCache.h" +#include "ccGLStateCache.h" #include "CCConfiguration.h" #include "CCDirector.h" #include "CCEventDispatcher.h" @@ -177,12 +177,15 @@ void Renderer::mapBuffers() void Renderer::addCommand(RenderCommand* command) { - command->generateID(); - _renderGroups[_commandGroupStack.top()].push_back(command); + int renderQueue =_commandGroupStack.top(); + addCommand(command, renderQueue); } void Renderer::addCommand(RenderCommand* command, int renderQueue) { + CCASSERT(renderQueue >=0, "Invalid render queue"); + CCASSERT(command->getType() != RenderCommand::Type::UNKNOWN_COMMAND, "Invalid Command Type"); + command->generateID(); _renderGroups[renderQueue].push_back(command); } @@ -290,6 +293,7 @@ void Renderer::render() } else { + CCASSERT(true, "Invalid command"); flush(); } } @@ -330,6 +334,10 @@ void Renderer::render() void Renderer::convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView) { +// kmMat4 matrixP, mvp; +// kmGLGetMatrix(KM_GL_PROJECTION, &matrixP); +// kmMat4Multiply(&mvp, &matrixP, &modelView); + for(ssize_t i=0; i #include +#include "CCDirector.h" +#include "platform/CCFileUtils.h" +#include "CCScene.h" +#include "CCTextureCache.h" +#include "CCSpriteFrameCache.h" + +#include "CCBReader.h" #include "CCNodeLoader.h" #include "CCNodeLoaderLibrary.h" #include "CCNodeLoaderListener.h" @@ -11,7 +17,7 @@ #include "CCBSequenceProperty.h" #include "CCBKeyframe.h" -#include + using namespace std; using namespace cocos2d; diff --git a/cocos/editor-support/cocosbuilder/CCBReader.h b/cocos/editor-support/cocosbuilder/CCBReader.h index 69306227ed..3c2a39c763 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.h +++ b/cocos/editor-support/cocosbuilder/CCBReader.h @@ -1,9 +1,12 @@ #ifndef _CCB_CCBREADER_H_ #define _CCB_CCBREADER_H_ -#include "cocos2d.h" #include #include +#include "CCNode.h" +#include "CCData.h" +#include "CCMap.h" + #include "CCBSequence.h" #include "extensions/GUI/CCControlExtension/CCControl.h" diff --git a/cocos/editor-support/cocosbuilder/CCBSelectorResolver.h b/cocos/editor-support/cocosbuilder/CCBSelectorResolver.h index f054c284c5..110d2ced61 100644 --- a/cocos/editor-support/cocosbuilder/CCBSelectorResolver.h +++ b/cocos/editor-support/cocosbuilder/CCBSelectorResolver.h @@ -1,7 +1,6 @@ #ifndef _CCB_CCBSELECTORRESOLVER_H_ #define _CCB_CCBSELECTORRESOLVER_H_ -#include "cocos2d.h" #include "extensions//GUI/CCControlExtension/CCInvocation.h" diff --git a/cocos/editor-support/cocosbuilder/CCBSequence.h b/cocos/editor-support/cocosbuilder/CCBSequence.h index dd7c1a899f..045fa536b5 100644 --- a/cocos/editor-support/cocosbuilder/CCBSequence.h +++ b/cocos/editor-support/cocosbuilder/CCBSequence.h @@ -2,7 +2,8 @@ #define __CCB_CCSEQUENCE_H__ #include -#include "cocos2d.h" + +#include "CCObject.h" #include "CCBSequenceProperty.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCBSequenceProperty.h b/cocos/editor-support/cocosbuilder/CCBSequenceProperty.h index 03ca04799f..fe19b15596 100644 --- a/cocos/editor-support/cocosbuilder/CCBSequenceProperty.h +++ b/cocos/editor-support/cocosbuilder/CCBSequenceProperty.h @@ -1,7 +1,8 @@ #ifndef __CCB_SEQUENCE_PROPERTY_H__ #define __CCB_SEQUENCE_PROPERTY_H__ -#include "cocos2d.h" +#include "CCObject.h" +#include "CCVector.h" #include "CCBKeyframe.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCLabelBMFontLoader.h b/cocos/editor-support/cocosbuilder/CCLabelBMFontLoader.h index ae5cb20011..c24239c3f2 100644 --- a/cocos/editor-support/cocosbuilder/CCLabelBMFontLoader.h +++ b/cocos/editor-support/cocosbuilder/CCLabelBMFontLoader.h @@ -1,6 +1,9 @@ #ifndef _CCB_CCLABELBMFONTLOADER_H_ #define _CCB_CCLABELBMFONTLOADER_H_ +#include "CCObject.h" +#include "CCLabelBMFont.h" + #include "CCNodeLoader.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCLabelTTFLoader.h b/cocos/editor-support/cocosbuilder/CCLabelTTFLoader.h index de0ca00d42..aa0fc0cdfe 100644 --- a/cocos/editor-support/cocosbuilder/CCLabelTTFLoader.h +++ b/cocos/editor-support/cocosbuilder/CCLabelTTFLoader.h @@ -1,6 +1,9 @@ #ifndef _CCB_CCLABELTTFLOADER_H_ #define _CCB_CCLABELTTFLOADER_H_ +#include "CCObject.h" +#include "CCLabelTTF.h" + #include "CCNodeLoader.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCMenuItemLoader.h b/cocos/editor-support/cocosbuilder/CCMenuItemLoader.h index 5db15eacba..1156a46f13 100644 --- a/cocos/editor-support/cocosbuilder/CCMenuItemLoader.h +++ b/cocos/editor-support/cocosbuilder/CCMenuItemLoader.h @@ -1,6 +1,9 @@ #ifndef _CCB_CCMENUITEMLOADER_H_ #define _CCB_CCMENUITEMLOADER_H_ +#include "CCObject.h" +#include "CCMenuItem.h" + #include "CCLayerLoader.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCMenuLoader.h b/cocos/editor-support/cocosbuilder/CCMenuLoader.h index 851913c74c..75ff815f26 100644 --- a/cocos/editor-support/cocosbuilder/CCMenuLoader.h +++ b/cocos/editor-support/cocosbuilder/CCMenuLoader.h @@ -2,6 +2,8 @@ #define _CCB_CCMENULOADER_H_ #include "CCLayerLoader.h" +#include "CCObject.h" +#include "CCMenu.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCNode+CCBRelativePositioning.h b/cocos/editor-support/cocosbuilder/CCNode+CCBRelativePositioning.h index 7923d3c681..7dd0ed5ea8 100644 --- a/cocos/editor-support/cocosbuilder/CCNode+CCBRelativePositioning.h +++ b/cocos/editor-support/cocosbuilder/CCNode+CCBRelativePositioning.h @@ -1,7 +1,6 @@ #ifndef __CCB_CCNODE_RELATIVEPOSITIONING_H__ #define __CCB_CCNODE_RELATIVEPOSITIONING_H__ -#include "cocos2d.h" #include "CCBReader.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp index adb7b8d095..598f6cad11 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp @@ -1,9 +1,12 @@ +#include "cocos2d.h" + #include "CCNodeLoader.h" #include "CCBSelectorResolver.h" #include "CCBMemberVariableAssigner.h" #include "CCBAnimationManager.h" #include "CCNode+CCBRelativePositioning.h" + using namespace std; using namespace cocos2d; using namespace cocos2d::extension; diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.h b/cocos/editor-support/cocosbuilder/CCNodeLoader.h index bb18d03866..e67fcb047f 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.h +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.h @@ -2,7 +2,6 @@ #define _CCB_CCNODELOADER_H_ #include "extensions/GUI/CCControlExtension/CCInvocation.h" -#include "cocos2d.h" #include "CCBReader.h" #include "extensions/GUI/CCControlExtension/CCControl.h" diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoaderLibrary.h b/cocos/editor-support/cocosbuilder/CCNodeLoaderLibrary.h index c75276d22f..6fe711feda 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoaderLibrary.h +++ b/cocos/editor-support/cocosbuilder/CCNodeLoaderLibrary.h @@ -1,7 +1,6 @@ #ifndef _CCB_CCNODELOADERLIBRARY_H_ #define _CCB_CCNODELOADERLIBRARY_H_ -#include "cocos2d.h" #include "CCBReader.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoaderListener.h b/cocos/editor-support/cocosbuilder/CCNodeLoaderListener.h index cf6c53e543..dedaafa51e 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoaderListener.h +++ b/cocos/editor-support/cocosbuilder/CCNodeLoaderListener.h @@ -1,7 +1,6 @@ #ifndef _CCB_CCNODELOADERLISTENER_H_ #define _CCB_CCNODELOADERLISTENER_H_ -#include "cocos2d.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCParticleSystemQuadLoader.h b/cocos/editor-support/cocosbuilder/CCParticleSystemQuadLoader.h index feced7312e..64efbdecba 100644 --- a/cocos/editor-support/cocosbuilder/CCParticleSystemQuadLoader.h +++ b/cocos/editor-support/cocosbuilder/CCParticleSystemQuadLoader.h @@ -1,6 +1,9 @@ #ifndef _CCB_CCPARTICLESYSTEMQUADLOADER_H_ #define _CCB_CCPARTICLESYSTEMQUADLOADER_H_ +#include "CCObject.h" +#include "CCParticleSystemQuad.h" + #include "CCNodeLoader.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocostudio/CCActionEaseEx.h b/cocos/editor-support/cocostudio/CCActionEaseEx.h index 0350d4d590..0a88c77e69 100644 --- a/cocos/editor-support/cocostudio/CCActionEaseEx.h +++ b/cocos/editor-support/cocostudio/CCActionEaseEx.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __ActionEaseEx_H__ #define __ActionEaseEx_H__ -#include "cocos2d.h" #include "cocostudio/CocoStudio.h" namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCActionFrame.h b/cocos/editor-support/cocostudio/CCActionFrame.h index 5b152f4eb3..9ff01ddf05 100644 --- a/cocos/editor-support/cocostudio/CCActionFrame.h +++ b/cocos/editor-support/cocostudio/CCActionFrame.h @@ -25,7 +25,8 @@ THE SOFTWARE. #ifndef __ActionFRAME_H__ #define __ActionFRAME_H__ -#include "cocos2d.h" +#include "CCGeometry.h" +#include "CCActionInterval.h" namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCActionFrameEasing.h b/cocos/editor-support/cocostudio/CCActionFrameEasing.h index 65c9ad3a05..1ae824e482 100644 --- a/cocos/editor-support/cocostudio/CCActionFrameEasing.h +++ b/cocos/editor-support/cocostudio/CCActionFrameEasing.h @@ -25,7 +25,7 @@ THE SOFTWARE. #ifndef __ActionFrameEasing_H__ #define __ActionFrameEasing_H__ -#include "cocos2d.h" +#include "CCObject.h" namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCActionManagerEx.h b/cocos/editor-support/cocostudio/CCActionManagerEx.h index e24c48d436..ba4e0c7804 100644 --- a/cocos/editor-support/cocostudio/CCActionManagerEx.h +++ b/cocos/editor-support/cocostudio/CCActionManagerEx.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __ActionMANAGER_H__ #define __ActionMANAGER_H__ -#include "cocos2d.h" #include "cocostudio/CCActionObject.h" #include "cocostudio/DictionaryHelper.h" diff --git a/cocos/editor-support/cocostudio/CCActionNode.h b/cocos/editor-support/cocostudio/CCActionNode.h index 42e4d0e4ee..9a2195327d 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.h +++ b/cocos/editor-support/cocostudio/CCActionNode.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __ActionNODE_H__ #define __ActionNODE_H__ -#include "cocos2d.h" #include "cocostudio/CCActionFrame.h" #include "cocostudio/DictionaryHelper.h" diff --git a/cocos/editor-support/cocostudio/CCActionObject.cpp b/cocos/editor-support/cocostudio/CCActionObject.cpp index eeba39d121..57291ae369 100644 --- a/cocos/editor-support/cocostudio/CCActionObject.cpp +++ b/cocos/editor-support/cocostudio/CCActionObject.cpp @@ -25,6 +25,10 @@ THE SOFTWARE. #include "cocostudio/CCActionObject.h" #include "cocostudio/DictionaryHelper.h" +#include "CCDirector.h" +#include "CCScheduler.h" +#include "CCActionInstant.h" + using namespace cocos2d; namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCActionObject.h b/cocos/editor-support/cocostudio/CCActionObject.h index 8d33a2017f..249489b620 100644 --- a/cocos/editor-support/cocostudio/CCActionObject.h +++ b/cocos/editor-support/cocostudio/CCActionObject.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __ActionObject_H__ #define __ActionObject_H__ -#include "cocos2d.h" #include "CCActionNode.h" #include "cocostudio/DictionaryHelper.h" diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index decc3cc0c2..80d6a4dca7 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -28,9 +28,12 @@ THE SOFTWARE. #include "cocostudio/CCDataReaderHelper.h" #include "cocostudio/CCDatas.h" #include "cocostudio/CCSkin.h" + #include "renderer/CCQuadCommand.h" -#include "CCRenderer.h" -#include "CCGroupCommand.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "CCShaderCache.h" +#include "CCDrawingPrimitives.h" #if ENABLE_PHYSICS_BOX2D_DETECT #include "Box2D/Box2D.h" @@ -570,7 +573,7 @@ void CCArmature::drawContour() } DrawPrimitives::drawPoly( points, (unsigned int)length, true ); - delete points; + delete []points; } } } diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index 0848ab6226..de05838940 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#include "CCSpriteFrameCache.h" #include "cocostudio/CCArmatureDataManager.h" #include "cocostudio/CCTransformHelp.h" diff --git a/cocos/editor-support/cocostudio/CCArmatureDefine.h b/cocos/editor-support/cocostudio/CCArmatureDefine.h index 934b7bc43d..8c8eca2608 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDefine.h +++ b/cocos/editor-support/cocostudio/CCArmatureDefine.h @@ -26,8 +26,6 @@ THE SOFTWARE. #define __CCARMATUREDEFINE_H__ -#include "cocos2d.h" - #define VERSION_COMBINED 0.30f #define VERSION_CHANGE_ROTATION_RANGE 1.0f #define VERSION_COLOR_READING 1.1f diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 45dcade7d6..634630ec64 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -26,8 +26,11 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCArmature.h" #include "cocostudio/CCSkin.h" -#include "CCRenderer.h" -#include "CCGroupCommand.h" + +#include "renderer/CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "CCShaderCache.h" +#include "CCDirector.h" using namespace cocos2d; diff --git a/cocos/editor-support/cocostudio/CCBatchNode.h b/cocos/editor-support/cocostudio/CCBatchNode.h index 1de8a963a2..f0ce41df2f 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.h +++ b/cocos/editor-support/cocostudio/CCBatchNode.h @@ -25,6 +25,7 @@ THE SOFTWARE. #ifndef __CCBATCHNODE_H__ #define __CCBATCHNODE_H__ +#include "CCNode.h" #include "cocostudio/CCArmatureDefine.h" namespace cocos2d { diff --git a/cocos/editor-support/cocostudio/CCComBase.h b/cocos/editor-support/cocostudio/CCComBase.h index 59dfccbe7f..2f32d20045 100644 --- a/cocos/editor-support/cocostudio/CCComBase.h +++ b/cocos/editor-support/cocostudio/CCComBase.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __CC_EXTENTIONS_CCCOMBASE_H__ #define __CC_EXTENTIONS_CCCOMBASE_H__ -#include "cocos2d.h" #include "ObjectFactory.h" #include "DictionaryHelper.h" #include diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 452f25d9b8..13ceb9db6d 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -22,7 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#include "platform/CCFileUtils.h" +#include "CCDirector.h" +#include "CCScheduler.h" + #include "tinyxml2.h" + #include "cocostudio/CCDataReaderHelper.h" #include "cocostudio/CCArmatureDataManager.h" #include "cocostudio/CCTransformHelp.h" @@ -288,7 +293,7 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath) std::string str = &filePathStr[startPos]; // Read content from file - std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath); std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath); DataInfo dataInfo; @@ -384,7 +389,7 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const size_t startPos = filePathStr.find_last_of("."); std::string str = &filePathStr[startPos]; - std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath); // XXX fileContent is being leaked data->fileContent = FileUtils::getInstance()->getStringFromFile(fullPath); @@ -461,7 +466,7 @@ void DataReaderHelper::addDataAsyncCallBack(float dt) if (0 == _asyncRefCount) { _asyncRefTotalCount = 0; - CCDirector::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this); + Director::getInstance()->getScheduler()->unscheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this); } } } diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.h b/cocos/editor-support/cocostudio/CCDataReaderHelper.h index 03ed25133b..ac580d6385 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.h +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.h @@ -35,6 +35,7 @@ THE SOFTWARE. #include #include #include +#include namespace tinyxml2 { diff --git a/cocos/editor-support/cocostudio/CCDatas.h b/cocos/editor-support/cocostudio/CCDatas.h index 42ac9ae2f6..6ee2adbcf6 100644 --- a/cocos/editor-support/cocostudio/CCDatas.h +++ b/cocos/editor-support/cocostudio/CCDatas.h @@ -25,6 +25,12 @@ THE SOFTWARE. #ifndef __CCARMATURE_DATAS_H__ #define __CCARMATURE_DATAS_H__ +#include "CCObject.h" +#include "ccTypes.h" +#include "CCVector.h" +#include "CCMap.h" +#include "CCAffineTransform.h" +#include "CCNode.h" #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCTweenFunction.h" diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index 7463ff54ff..72428edfff 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -30,6 +30,8 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDataManager.h" #include "cocostudio/CCTransformHelp.h" +#include "CCParticleSystemQuad.h" + using namespace cocos2d; namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCDisplayManager.cpp b/cocos/editor-support/cocostudio/CCDisplayManager.cpp index c2ce242a47..ca07edaae7 100644 --- a/cocos/editor-support/cocostudio/CCDisplayManager.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayManager.cpp @@ -28,6 +28,8 @@ THE SOFTWARE. #include "cocostudio/CCUtilMath.h" #include "cocostudio/CCSkin.h" +#include "CCParticleSystemQuad.h" + using namespace cocos2d; namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCInputDelegate.cpp b/cocos/editor-support/cocostudio/CCInputDelegate.cpp index 3f3d94745e..1bafbe42f2 100644 --- a/cocos/editor-support/cocostudio/CCInputDelegate.cpp +++ b/cocos/editor-support/cocostudio/CCInputDelegate.cpp @@ -23,6 +23,11 @@ THE SOFTWARE. ****************************************************************************/ #include "cocostudio/CCInputDelegate.h" +#include "CCDirector.h" +#include "platform/CCDevice.h" +#include "CCEventListenerTouch.h" +#include "CCEventListenerAcceleration.h" +#include "CCEventListenerKeyboard.h" using namespace cocos2d; diff --git a/cocos/editor-support/cocostudio/CCInputDelegate.h b/cocos/editor-support/cocostudio/CCInputDelegate.h index 81cd4c9218..9341179bf8 100644 --- a/cocos/editor-support/cocostudio/CCInputDelegate.h +++ b/cocos/editor-support/cocostudio/CCInputDelegate.h @@ -25,7 +25,12 @@ THE SOFTWARE. #ifndef __CC_EXTENTIONS_CCINPUTDELEGATE_H__ #define __CC_EXTENTIONS_CCINPUTDELEGATE_H__ -#include "cocos2d.h" +#include "CCPlatformMacros.h" +#include "CCTouch.h" +#include "CCEvent.h" +#include "ccTypes.h" +#include "CCEventKeyboard.h" +#include "CCEventListener.h" namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.h b/cocos/editor-support/cocostudio/CCSSceneReader.h index 6b72b82574..19ca837c6a 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.h +++ b/cocos/editor-support/cocostudio/CCSSceneReader.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __CCSSCENEREADER_H__ #define __CCSSCENEREADER_H__ -#include "cocos2d.h" #include "cocostudio/DictionaryHelper.h" diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index d26199c205..da98e5a736 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -22,11 +22,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#include "CCSpriteFrame.h" +#include "CCSpriteFrameCache.h" +#include "CCDirector.h" +#include "renderer/CCRenderer.h" + #include "cocostudio/CCSkin.h" #include "cocostudio/CCTransformHelp.h" #include "cocostudio/CCSpriteFrameCacheHelper.h" #include "cocostudio/CCArmature.h" + using namespace cocos2d; namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index e0f255e70d..4798b2345b 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -25,9 +25,11 @@ THE SOFTWARE. #ifndef __CCSKIN_H__ #define __CCSKIN_H__ +#include "CCSprite.h" +#include "renderer/CCQuadCommand.h" + #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCBone.h" -#include "renderer/CCQuadCommand.h" namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp index c5399ba479..1c226668db 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp @@ -24,6 +24,8 @@ THE SOFTWARE. #include "cocostudio/CCSpriteFrameCacheHelper.h" +#include "CCSpriteFrameCache.h" + using namespace cocos2d; @@ -49,7 +51,7 @@ void SpriteFrameCacheHelper::purge() void SpriteFrameCacheHelper::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath) { - CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); + SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); } SpriteFrameCacheHelper::SpriteFrameCacheHelper() diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h index 75797c1aa2..452666a67d 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h @@ -24,8 +24,10 @@ THE SOFTWARE. #ifndef __CCSPRITEFRAMECACHEHELPER_H__ #define __CCSPRITEFRAMECACHEHELPER_H__ +#include "CCPlatformMacros.h" #include "cocostudio/CCArmatureDefine.h" #include +#include namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/CCUtilMath.h b/cocos/editor-support/cocostudio/CCUtilMath.h index b10690d620..cc27ccae86 100644 --- a/cocos/editor-support/cocostudio/CCUtilMath.h +++ b/cocos/editor-support/cocostudio/CCUtilMath.h @@ -25,6 +25,7 @@ THE SOFTWARE. #ifndef __CCUTILMATH_H__ #define __CCUTILMATH_H__ +#include "CCSprite.h" #include "cocostudio/CCArmatureDefine.h" #include diff --git a/cocos/editor-support/cocostudio/DictionaryHelper.cpp b/cocos/editor-support/cocostudio/DictionaryHelper.cpp index 0c46694e7b..436c345d0c 100644 --- a/cocos/editor-support/cocostudio/DictionaryHelper.cpp +++ b/cocos/editor-support/cocostudio/DictionaryHelper.cpp @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#include "CCPlatformMacros.h" #include "cocostudio/DictionaryHelper.h" namespace cocostudio { diff --git a/cocos/editor-support/cocostudio/DictionaryHelper.h b/cocos/editor-support/cocostudio/DictionaryHelper.h index 58f58455f5..cefb9610ff 100644 --- a/cocos/editor-support/cocostudio/DictionaryHelper.h +++ b/cocos/editor-support/cocostudio/DictionaryHelper.h @@ -25,7 +25,6 @@ THE SOFTWARE. #ifndef __DICTIONARYHELPER_H__ #define __DICTIONARYHELPER_H__ -#include "cocos2d.h" #include "json/document.h" #define DICTOOL DictionaryHelper::getInstance() diff --git a/cocos/editor-support/spine/CCSkeleton.h b/cocos/editor-support/spine/CCSkeleton.h index f1cffffea6..a2460ca690 100644 --- a/cocos/editor-support/spine/CCSkeleton.h +++ b/cocos/editor-support/spine/CCSkeleton.h @@ -35,7 +35,11 @@ #define SPINE_CCSKELETON_H_ #include -#include "cocos2d.h" + +#include "CCNode.h" +#include "CCProtocols.h" +#include "CCTextureAtlas.h" +#include "renderer/CCCustomCommand.h" namespace spine { diff --git a/cocos/editor-support/spine/CCSkeletonAnimation.h b/cocos/editor-support/spine/CCSkeletonAnimation.h index 228a07b88e..3c09ee28c3 100644 --- a/cocos/editor-support/spine/CCSkeletonAnimation.h +++ b/cocos/editor-support/spine/CCSkeletonAnimation.h @@ -36,7 +36,6 @@ #include #include -#include "cocos2d.h" namespace spine { diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index e4c9c1f66f..38c73c5a65 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -30,9 +30,9 @@ THE SOFTWARE. #include "CCShaderCache.h" #include "CCDirector.h" #include "CCDrawingPrimitives.h" -#include "CCRenderer.h" -#include "CCGroupCommand.h" -#include "CCCustomCommand.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCGroupCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN diff --git a/cocos/network/HttpClient.cpp b/cocos/network/HttpClient.cpp index cc19b72524..771a23c6f8 100644 --- a/cocos/network/HttpClient.cpp +++ b/cocos/network/HttpClient.cpp @@ -25,10 +25,17 @@ ****************************************************************************/ #include "HttpClient.h" + #include #include +#include + #include +#include "CCVector.h" +#include "CCDirector.h" +#include "CCScheduler.h" + #include "curl/curl.h" #include "platform/CCFileUtils.h" diff --git a/cocos/network/HttpClient.h b/cocos/network/HttpClient.h index 74f498e942..8c57bb2586 100644 --- a/cocos/network/HttpClient.h +++ b/cocos/network/HttpClient.h @@ -27,8 +27,6 @@ #ifndef __CCHTTPREQUEST_H__ #define __CCHTTPREQUEST_H__ -#include "cocos2d.h" - #include "network/HttpRequest.h" #include "network/HttpResponse.h" #include "network/HttpClient.h" diff --git a/cocos/network/HttpRequest.h b/cocos/network/HttpRequest.h index 50d660bca3..8ca5eee84d 100644 --- a/cocos/network/HttpRequest.h +++ b/cocos/network/HttpRequest.h @@ -26,7 +26,8 @@ #ifndef __HTTP_REQUEST_H__ #define __HTTP_REQUEST_H__ -#include "cocos2d.h" +#include "CCPlatformMacros.h" +#include "CCObject.h" NS_CC_BEGIN diff --git a/cocos/network/HttpResponse.h b/cocos/network/HttpResponse.h index 764ddde120..ebad23ec64 100644 --- a/cocos/network/HttpResponse.h +++ b/cocos/network/HttpResponse.h @@ -26,7 +26,6 @@ #ifndef __HTTP_RESPONSE__ #define __HTTP_RESPONSE__ -#include "cocos2d.h" #include "network/HttpRequest.h" NS_CC_BEGIN diff --git a/cocos/physics/CCPhysicsBody.h b/cocos/physics/CCPhysicsBody.h index 52ba0f527d..09574a22cc 100644 --- a/cocos/physics/CCPhysicsBody.h +++ b/cocos/physics/CCPhysicsBody.h @@ -300,29 +300,29 @@ protected: virtual ~PhysicsBody(); protected: - Node* _node; - std::vector _joints; - Vector _shapes; - PhysicsWorld* _world; - PhysicsBodyInfo* _info; - bool _dynamic; - bool _enable; - bool _rotationEnable; - bool _gravityEnable; - bool _massDefault; - bool _momentDefault; - float _mass; - float _area; - float _density; - float _moment; - float _linearDamping; - float _angularDamping; - int _tag; + Node* _node; + std::vector _joints; + Vector _shapes; + PhysicsWorld* _world; + PhysicsBodyInfo* _info; + bool _dynamic; + bool _enable; + bool _rotationEnable; + bool _gravityEnable; + bool _massDefault; + bool _momentDefault; + float _mass; + float _area; + float _density; + float _moment; + float _linearDamping; + float _angularDamping; + int _tag; - int _categoryBitmask; - int _collisionBitmask; - int _contactTestBitmask; - int _group; + int _categoryBitmask; + int _collisionBitmask; + int _contactTestBitmask; + int _group; friend class PhysicsWorld; friend class PhysicsShape; diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 74cb897b64..f03e84b93a 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 74cb897b64f7325cf969341e9bc2d87fc7fb1bb7 +Subproject commit f03e84b93ae69080e369962ba2e95ea9b2fd91c7 diff --git a/cocos/scripting/lua/bindings/lua_xml_http_request.h b/cocos/scripting/lua/bindings/lua_xml_http_request.h index 8d0ae45394..c76f1ba383 100644 --- a/cocos/scripting/lua/bindings/lua_xml_http_request.h +++ b/cocos/scripting/lua/bindings/lua_xml_http_request.h @@ -32,6 +32,8 @@ extern "C" { } #endif +#include +#include #include "network/HttpClient.h" diff --git a/extensions/GUI/CCControlExtension/CCControl.h b/extensions/GUI/CCControlExtension/CCControl.h index 4e36bbe753..5c1815291f 100644 --- a/extensions/GUI/CCControlExtension/CCControl.h +++ b/extensions/GUI/CCControlExtension/CCControl.h @@ -31,12 +31,11 @@ #define __CCCONTROL_H__ #include "CCControlUtils.h" -#include "cocos2d.h" +#include "CCLayer.h" NS_CC_EXT_BEGIN - class Invocation; /** diff --git a/extensions/GUI/CCControlExtension/CCControlButton.h b/extensions/GUI/CCControlExtension/CCControlButton.h index d4208c0566..35202c6cec 100644 --- a/extensions/GUI/CCControlExtension/CCControlButton.h +++ b/extensions/GUI/CCControlExtension/CCControlButton.h @@ -33,6 +33,7 @@ #include "CCControl.h" #include "CCInvocation.h" #include "CCScale9Sprite.h" +#include "CCMap.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp b/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp index ab3fccdb74..b813750887 100644 --- a/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp +++ b/extensions/GUI/CCControlExtension/CCControlPotentiometer.cpp @@ -26,7 +26,6 @@ */ #include "CCControlPotentiometer.h" -#include "cocos2d.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCControlExtension/CCControlPotentiometer.h b/extensions/GUI/CCControlExtension/CCControlPotentiometer.h index bebe39b382..74d0219bc9 100644 --- a/extensions/GUI/CCControlExtension/CCControlPotentiometer.h +++ b/extensions/GUI/CCControlExtension/CCControlPotentiometer.h @@ -28,6 +28,7 @@ #define __CCCONTROLPOTENTIOMETER_H__ #include "CCControl.h" +#include "CCProgressTimer.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCControlExtension/CCControlStepper.h b/extensions/GUI/CCControlExtension/CCControlStepper.h index 1741e8c8a8..2376db9c99 100644 --- a/extensions/GUI/CCControlExtension/CCControlStepper.h +++ b/extensions/GUI/CCControlExtension/CCControlStepper.h @@ -29,6 +29,7 @@ #define __CCCONTROLSTEPPER_H__ #include "CCControl.h" +#include "CCLabelTTF.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCControlExtension/CCControlSwitch.cpp b/extensions/GUI/CCControlExtension/CCControlSwitch.cpp index f583398f06..e37c76735f 100644 --- a/extensions/GUI/CCControlExtension/CCControlSwitch.cpp +++ b/extensions/GUI/CCControlExtension/CCControlSwitch.cpp @@ -26,7 +26,12 @@ */ #include "CCControlSwitch.h" -#include "cocos2d.h" +#include "CCSprite.h" +#include "CCActionTween.h" +#include "CCLabelTTF.h" +#include "CCClippingNode.h" +#include "ccShaders.h" +#include "CCRenderTexture.h" NS_CC_EXT_BEGIN // ControlSwitchSprite diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp index 532c7fcf06..9f1a19e813 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp @@ -26,6 +26,9 @@ THE SOFTWARE. ****************************************************************************/ #include "CCScale9Sprite.h" +#include "CCPlatformMacros.h" +#include "CCSprite.h" +#include "CCSpriteFrameCache.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.h b/extensions/GUI/CCControlExtension/CCScale9Sprite.h index 6b91aac717..fbeca870eb 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.h +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.h @@ -28,7 +28,10 @@ THE SOFTWARE. #ifndef __CCScale9Sprite_H__ #define __CCScale9Sprite_H__ -#include "cocos2d.h" +#include "CCNode.h" +#include "CCSpriteFrame.h" +#include "CCSpriteBatchNode.h" + #include "../../ExtensionMacros.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCEditBox/CCEditBox.h b/extensions/GUI/CCEditBox/CCEditBox.h index a1aac55d6e..ff6a4149b4 100644 --- a/extensions/GUI/CCEditBox/CCEditBox.h +++ b/extensions/GUI/CCEditBox/CCEditBox.h @@ -26,7 +26,7 @@ #ifndef __CCEDITTEXT_H__ #define __CCEDITTEXT_H__ -#include "cocos2d.h" +#include "CCIMEDelegate.h" #include "extensions/ExtensionMacros.h" #include "../CCControlExtension/CCControlExtensions.h" diff --git a/extensions/GUI/CCEditBox/CCEditBoxImpl.h b/extensions/GUI/CCEditBox/CCEditBoxImpl.h index b01362eff0..7cb6c6ed1c 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImpl.h +++ b/extensions/GUI/CCEditBox/CCEditBoxImpl.h @@ -26,7 +26,6 @@ #ifndef __CCEditBoxIMPL_H__ #define __CCEditBoxIMPL_H__ -#include "cocos2d.h" #include "extensions/ExtensionMacros.h" #include "CCEditBox.h" diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 05200d32cb..e1c21ce3a6 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -24,6 +24,13 @@ ****************************************************************************/ #include "CCScrollView.h" +#include "CCEGLView.h" +#include "platform/CCDevice.h" +#include "CCActionInstant.h" +#include "CCActionInterval.h" +#include "CCActionTween.h" +#include "CCDirector.h" +#include "renderer/CCRenderer.h" #include diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index c77d74bc13..88fc9b4523 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -26,7 +26,9 @@ #ifndef __CCSCROLLVIEW_H__ #define __CCSCROLLVIEW_H__ -#include "cocos2d.h" +#include "CCLayer.h" +#include "CCEventListenerTouch.h" + #include "extensions/ExtensionMacros.h" NS_CC_EXT_BEGIN diff --git a/extensions/GUI/CCScrollView/CCTableView.cpp b/extensions/GUI/CCScrollView/CCTableView.cpp index ff143f77d5..ad639e4986 100644 --- a/extensions/GUI/CCScrollView/CCTableView.cpp +++ b/extensions/GUI/CCScrollView/CCTableView.cpp @@ -23,7 +23,6 @@ THE SOFTWARE. ****************************************************************************/ -#include "cocos2d.h" #include "CCTableView.h" #include "CCTableViewCell.h" diff --git a/extensions/GUI/CCScrollView/CCTableViewCell.cpp b/extensions/GUI/CCScrollView/CCTableViewCell.cpp index 7df9c478fd..aa1cf70bca 100644 --- a/extensions/GUI/CCScrollView/CCTableViewCell.cpp +++ b/extensions/GUI/CCScrollView/CCTableViewCell.cpp @@ -33,7 +33,7 @@ void TableViewCell::reset() _idx = CC_INVALID_INDEX; } -ssize_t TableViewCell::getIdx() +ssize_t TableViewCell::getIdx() const { return _idx; } diff --git a/extensions/GUI/CCScrollView/CCTableViewCell.h b/extensions/GUI/CCScrollView/CCTableViewCell.h index 33438a0f96..fb0a509df1 100644 --- a/extensions/GUI/CCScrollView/CCTableViewCell.h +++ b/extensions/GUI/CCScrollView/CCTableViewCell.h @@ -26,8 +26,8 @@ #ifndef __CCTABLEVIEWCELL_H__ #define __CCTABLEVIEWCELL_H__ -#include "cocos2d.h" #include "extensions/ExtensionMacros.h" +#include "CCNode.h" NS_CC_EXT_BEGIN @@ -43,7 +43,7 @@ public: /** * The index used internally by SWTableView and its subclasses */ - ssize_t getIdx(); + ssize_t getIdx() const; void setIdx(ssize_t uIdx); /** * Cleans up any resources linked to this cell and resets idx property. diff --git a/extensions/physics-nodes/CCPhysicsDebugNode.h b/extensions/physics-nodes/CCPhysicsDebugNode.h index fe4d167bff..5d4eb2f2f0 100644 --- a/extensions/physics-nodes/CCPhysicsDebugNode.h +++ b/extensions/physics-nodes/CCPhysicsDebugNode.h @@ -23,11 +23,12 @@ #ifndef __PHYSICSNODES_DEBUGNODE_H__ #define __PHYSICSNODES_DEBUGNODE_H__ -#include "cocos2d.h" #include "extensions/ExtensionMacros.h" #if CC_ENABLE_CHIPMUNK_INTEGRATION +#include "CCDrawNode.h" + #include "chipmunk.h" NS_CC_EXT_BEGIN diff --git a/extensions/physics-nodes/CCPhysicsSprite.h b/extensions/physics-nodes/CCPhysicsSprite.h index fcedfca031..e8f9284a98 100644 --- a/extensions/physics-nodes/CCPhysicsSprite.h +++ b/extensions/physics-nodes/CCPhysicsSprite.h @@ -24,7 +24,7 @@ #ifndef __PHYSICSNODES_CCPHYSICSSPRITE_H__ #define __PHYSICSNODES_CCPHYSICSSPRITE_H__ -#include "cocos2d.h" +#include "CCSprite.h" #include "extensions/ExtensionMacros.h" struct cpBody; diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index 07d231cbf8..1d661d5aa1 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -122,6 +122,7 @@ Classes/PerformanceTest/PerformanceTextureTest.cpp \ Classes/PerformanceTest/PerformanceTouchesTest.cpp \ Classes/PerformanceTest/PerformanceLabelTest.cpp \ Classes/PerformanceTest/PerformanceRendererTest.cpp \ +Classes/PerformanceTest/PerformanceContainerTest.cpp \ Classes/PhysicsTest/PhysicsTest.cpp \ Classes/RenderTextureTest/RenderTextureTest.cpp \ Classes/RotateWorldTest/RotateWorldTest.cpp \ diff --git a/samples/Cpp/TestCpp/CMakeLists.txt b/samples/Cpp/TestCpp/CMakeLists.txt index 6c10336eb2..df0a738a87 100644 --- a/samples/Cpp/TestCpp/CMakeLists.txt +++ b/samples/Cpp/TestCpp/CMakeLists.txt @@ -117,6 +117,7 @@ set(SAMPLE_SRC Classes/PerformanceTest/PerformanceTouchesTest.cpp Classes/PerformanceTest/PerformanceLabelTest.cpp Classes/PerformanceTest/PerformanceRendererTest.cpp + Classes/PerformanceTest/PerformanceContainerTest.cpp Classes/PhysicsTest/PhysicsTest.cpp Classes/RenderTextureTest/RenderTextureTest.cpp Classes/RotateWorldTest/RotateWorldTest.cpp diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index c28585dfbe..604ff0cb8b 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -67,6 +67,7 @@ static std::function createFunctions[] = CL(LabelBMFontTestNew), CL(LabelTTFDistanceField), CL(LabelTTFDistanceFieldEffect), + CL(LabelCharMapTest), CL(LabelCrashTest) }; @@ -1244,6 +1245,52 @@ std::string LabelTTFDistanceFieldEffect::subtitle() const return "Testing effect base on DistanceField"; } +LabelCharMapTest::LabelCharMapTest() +{ + _time = 0.0f; + + auto label1 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist"); + addChild(label1, 0, kTagSprite1); + label1->setPosition( Point(10,100) ); + label1->setOpacity( 200 ); + + auto label2 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist"); + addChild(label2, 0, kTagSprite2); + label2->setPosition( Point(10,160) ); + label2->setOpacity( 32 ); + + auto label3 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.png", 48, 64, ' '); + label3->setString("123 Test"); + addChild(label3, 0, kTagSprite3); + label3->setPosition( Point(10,220) ); + + schedule(schedule_selector(LabelCharMapTest::step)); +} + +void LabelCharMapTest::step(float dt) +{ + _time += dt; + char string[12] = {0}; + sprintf(string, "%2.2f Test", _time); + + auto label1 = (Label*)getChildByTag(kTagSprite1); + label1->setString(string); + + auto label2 = (Label*)getChildByTag(kTagSprite2); + sprintf(string, "%d", (int)_time); + label2->setString(string); +} + +std::string LabelCharMapTest::title() const +{ + return "New Label + char map file"; +} + +std::string LabelCharMapTest::subtitle() const +{ + return "Updating label should be fast."; +} + LabelCrashTest::LabelCrashTest() { auto size = Director::getInstance()->getWinSize(); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h index b0b120b063..45d9374d4c 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h @@ -347,6 +347,22 @@ public: virtual std::string subtitle() const override; }; +class LabelCharMapTest : public AtlasDemoNew +{ +public: + CREATE_FUNC(LabelCharMapTest); + + LabelCharMapTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; + + void step(float dt); + +private: + float _time; +}; + class LabelCrashTest : public AtlasDemoNew { public: diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.cpp new file mode 100644 index 0000000000..75efc640e5 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.cpp @@ -0,0 +1,711 @@ +/* + * + */ +#include "PerformanceContainerTest.h" + +#include + +// Enable profiles for this file +#undef CC_PROFILER_DISPLAY_TIMERS +#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers() +#undef CC_PROFILER_PURGE_ALL +#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers() + +#undef CC_PROFILER_START +#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__) +#undef CC_PROFILER_STOP +#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__) +#undef CC_PROFILER_RESET +#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__) + +#undef CC_PROFILER_START_CATEGORY +#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0) +#undef CC_PROFILER_STOP_CATEGORY +#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0) +#undef CC_PROFILER_RESET_CATEGORY +#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0) + +#undef CC_PROFILER_START_INSTANCE +#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#undef CC_PROFILER_STOP_INSTANCE +#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#undef CC_PROFILER_RESET_INSTANCE +#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) + +static std::function createFunctions[] = +{ + CL(TemplateVectorPerfTest), + CL(ArrayPerfTest) +}; + +#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) + +enum { + kTagInfoLayer = 1, + + kTagBase = 20000, +}; + +enum { + kMaxNodes = 15000, + kNodesIncrease = 500, +}; + +static int g_curCase = 0; + +//////////////////////////////////////////////////////// +// +// ContainerBasicLayer +// +//////////////////////////////////////////////////////// + +ContainerBasicLayer::ContainerBasicLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase) +: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase) +{ +} + +void ContainerBasicLayer::showCurrentTest() +{ + int nodes = ((PerformanceContainerScene*)getParent())->getQuantityOfNodes(); + + auto scene = createFunctions[_curCase](); + + g_curCase = _curCase; + + if (scene) + { + scene->initWithQuantityOfNodes(nodes); + + Director::getInstance()->replaceScene(scene); + } +} + +//////////////////////////////////////////////////////// +// +// PerformanceContainerScene +// +//////////////////////////////////////////////////////// +void PerformanceContainerScene::initWithQuantityOfNodes(unsigned int nNodes) +{ + _type = 0; + //srand(time()); + auto s = Director::getInstance()->getWinSize(); + + // Title + auto label = LabelTTF::create(title().c_str(), "Arial", 40); + addChild(label, 1, TAG_TITLE); + label->setPosition(Point(s.width/2, s.height-32)); + label->setColor(Color3B(255,255,40)); + + // Subtitle + std::string strSubTitle = subtitle(); + if(strSubTitle.length()) + { + auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16); + addChild(l, 1, TAG_SUBTITLE); + l->setPosition(Point(s.width/2, s.height-80)); + } + + lastRenderedCount = 0; + currentQuantityOfNodes = 0; + quantityOfNodes = nNodes; + + MenuItemFont::setFontSize(65); + auto decrease = MenuItemFont::create(" - ", [&](Object *sender) { + quantityOfNodes -= kNodesIncrease; + if( quantityOfNodes < 0 ) + quantityOfNodes = 0; + + updateQuantityLabel(); + updateQuantityOfNodes(); + updateProfilerName(); + CC_PROFILER_PURGE_ALL(); + srand(0); + }); + decrease->setColor(Color3B(0,200,20)); + _decrease = decrease; + + auto increase = MenuItemFont::create(" + ", [&](Object *sender) { + quantityOfNodes += kNodesIncrease; + if( quantityOfNodes > kMaxNodes ) + quantityOfNodes = kMaxNodes; + + updateQuantityLabel(); + updateQuantityOfNodes(); + updateProfilerName(); + CC_PROFILER_PURGE_ALL(); + srand(0); + }); + increase->setColor(Color3B(0,200,20)); + _increase = increase; + + auto menu = Menu::create(decrease, increase, NULL); + menu->alignItemsHorizontally(); + menu->setPosition(Point(s.width/2, s.height/2+15)); + addChild(menu, 1); + + auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); + infoLabel->setColor(Color3B(0,200,20)); + infoLabel->setPosition(Point(s.width/2, s.height/2-15)); + addChild(infoLabel, 1, kTagInfoLayer); + + auto menuLayer = new ContainerBasicLayer(true, MAX_LAYER, g_curCase); + addChild(menuLayer); + menuLayer->release(); + + printf("Size of Node: %lu\n", sizeof(Node)); + + int oldFontSize = MenuItemFont::getFontSize(); + MenuItemFont::setFontSize(24); + + Vector toggleItems; + + generateTestFunctions(); + + CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions"); + + + for (const auto& f : _testFunctions) + { + toggleItems.pushBack(MenuItemFont::create(f.name)); + } + + auto toggle = MenuItemToggle::createWithCallback([this](Object* sender){ + auto toggle = static_cast(sender); + this->_type = toggle->getSelectedIndex(); + auto label = static_cast(this->getChildByTag(TAG_SUBTITLE)); + label->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name)); + this->updateProfilerName(); + }, toggleItems); + + toggle->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); + toggle->setPosition(VisibleRect::left()); + _toggle = toggle; + + auto start = MenuItemFont::create("start", [this](Object* sender){ + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + CC_PROFILER_PURGE_ALL(); + sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false); + + this->unscheduleUpdate(); + this->scheduleUpdate(); + this->_startItem->setEnabled(false); + this->_stopItem->setEnabled(true); + this->_toggle->setEnabled(false); + this->_increase->setEnabled(false); + this->_decrease->setEnabled(false); + }); + start->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); + start->setPosition(VisibleRect::right() + Point(0, 40)); + _startItem = start; + + auto stop = MenuItemFont::create("stop", [this](Object* sender){ + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this); + + this->unscheduleUpdate(); + this->_startItem->setEnabled(true); + this->_stopItem->setEnabled(false); + this->_toggle->setEnabled(true); + this->_increase->setEnabled(true); + this->_decrease->setEnabled(true); + }); + + stop->setEnabled(false); + stop->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); + stop->setPosition(VisibleRect::right() + Point(0, -40)); + _stopItem = stop; + + auto menu2 = Menu::create(toggle, start, stop, NULL); + menu2->setPosition(Point::ZERO); + addChild(menu2); + + MenuItemFont::setFontSize(oldFontSize); + + updateQuantityLabel(); + updateQuantityOfNodes(); + updateProfilerName(); +} + +std::string PerformanceContainerScene::title() const +{ + return "No title"; +} + +std::string PerformanceContainerScene::subtitle() const +{ + return ""; +} + +void PerformanceContainerScene::updateQuantityLabel() +{ + if( quantityOfNodes != lastRenderedCount ) + { + auto infoLabel = static_cast( getChildByTag(kTagInfoLayer) ); + char str[20] = {0}; + sprintf(str, "%u nodes", quantityOfNodes); + infoLabel->setString(str); + + lastRenderedCount = quantityOfNodes; + } +} + +const char * PerformanceContainerScene::profilerName() +{ + return _profilerName; +} + +void PerformanceContainerScene::updateProfilerName() +{ + snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), quantityOfNodes); +} + +void PerformanceContainerScene::onExitTransitionDidStart() +{ + Scene::onExitTransitionDidStart(); + + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this); +} + +void PerformanceContainerScene::onEnterTransitionDidFinish() +{ + Scene::onEnterTransitionDidFinish(); + + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + CC_PROFILER_PURGE_ALL(); + sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false); +} + +void PerformanceContainerScene::dumpProfilerInfo(float dt) +{ + CC_PROFILER_DISPLAY_TIMERS(); +} + +void PerformanceContainerScene::update(float dt) +{ + _testFunctions[_type].func(); +} + +void PerformanceContainerScene::updateQuantityOfNodes() +{ + currentQuantityOfNodes = quantityOfNodes; +} + +const char* PerformanceContainerScene::testName() +{ + return _testFunctions[_type].name; +} + +//////////////////////////////////////////////////////// +// +// TemplateVectorPerfTest +// +//////////////////////////////////////////////////////// + +void TemplateVectorPerfTest::generateTestFunctions() +{ + auto createVector = [this](){ + Vector ret; + + for( int i=0; isetTag(i); + ret.pushBack(node); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "pushBack", [=](){ + Vector nodeVector; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + { "insert", [=](){ + Vector nodeVector; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + { "replace", [=](){ + Vector nodeVector = createVector(); + + srand(time(nullptr)); + ssize_t index = rand() % quantityOfNodes; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + { "getIndex", [=](){ + + Vector nodeVector = createVector(); + Node* objToGet = nodeVector.at(quantityOfNodes/3); + ssize_t index = 0; + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `index` to avoids `getIndex` invoking was optimized in release mode + if (index == quantityOfNodes/3) + { + nodeVector.clear(); + } + } } , + { "find", [=](){ + Vector nodeVector = createVector(); + Node* objToGet = nodeVector.at(quantityOfNodes/3); + Vector::iterator iter; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `iter` to avoids `find` invoking was optimized in release mode + if (*iter == objToGet) + { + nodeVector.clear(); + } + + } } , + { "at", [=](){ + Vector nodeVector = createVector(); + Node* objToGet = nullptr; + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `objToGet` to avoids `at` invoking was optimized in release mode + if (nodeVector.getIndex(objToGet) == quantityOfNodes/3) + { + nodeVector.clear(); + } + } } , + { "contains", [=](){ + Vector nodeVector = createVector(); + Node* objToGet = nodeVector.at(quantityOfNodes/3); + + bool ret = false; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `ret` to avoids `contains` invoking was optimized in release mode + if (ret) + { + nodeVector.clear(); + } + } } , + { "eraseObject", [=](){ + Vector nodeVector = createVector(); + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i] = nodeVector.at(i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CCASSERT(nodeVector.empty(), "nodeVector was not empty."); + + free(nodes); + } } , + { "erase", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CCASSERT(nodeVector.empty(), "nodeVector was not empty."); + + } } , + { "clear", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CCASSERT(nodeVector.empty(), "nodeVector was not empty."); + } } , + { "swap by index", [=](){ + Vector nodeVector = createVector(); + + int swapIndex1 = quantityOfNodes / 3; + int swapIndex2 = quantityOfNodes / 3 * 2; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "swap by object", [=](){ + Vector nodeVector = createVector(); + + Node* swapNode1 = nodeVector.at(quantityOfNodes / 3); + Node* swapNode2 = nodeVector.at(quantityOfNodes / 3 * 2); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "reverse", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "c++11 Range Loop", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for (const auto& e : nodeVector) + { + e->setTag(111); + } + CC_PROFILER_STOP(this->profilerName()); + } } , + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + + + +std::string TemplateVectorPerfTest::title() const +{ + return "Vector Perf test"; +} + +std::string TemplateVectorPerfTest::subtitle() const +{ + return "Test 'pushBack', See console"; +} + + + +//////////////////////////////////////////////////////// +// +// ArrayPerfTest +// +//////////////////////////////////////////////////////// + +std::string ArrayPerfTest::title() const +{ + return "Array Perf test"; +} + +std::string ArrayPerfTest::subtitle() const +{ + return "Test `addObject`, See console"; +} + +void ArrayPerfTest::generateTestFunctions() +{ + auto createArray = [this](){ + Array* ret = Array::create(); + + for( int i=0; isetTag(i); + ret->addObject(node); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "addObject", [=](){ + Array* nodeVector = Array::create(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iaddObject(Node::create()); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "insertObject", [=](){ + Array* nodeVector = Array::create(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iinsertObject(Node::create(), 0); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "setObject", [=](){ + Array* nodeVector = createArray(); + + srand(time(nullptr)); + ssize_t index = rand() % quantityOfNodes; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; isetObject(Node::create(), index); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "getIndexOfObject", [=](){ + Array* nodeVector = createArray(); + Object* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3); + ssize_t index = 0; + CC_PROFILER_START(this->profilerName()); + for( int i=0; igetIndexOfObject(objToGet); + CC_PROFILER_STOP(this->profilerName()); + // Uses `index` to avoids `getIndex` invoking was optimized in release mode + if (index == quantityOfNodes/3) + { + nodeVector->removeAllObjects(); + } + } } , + { "getObjectAtIndex", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; igetObjectAtIndex(quantityOfNodes/3); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "containsObject", [=](){ + Array* nodeVector = createArray(); + Object* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; icontainsObject(objToGet); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "removeObject", [=](){ + Array* nodeVector = createArray(); + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i] = static_cast(nodeVector->getObjectAtIndex(i)); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveObject(nodes[i]); + CC_PROFILER_STOP(this->profilerName()); + + CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); + + free(nodes); + } } , + { "removeObjectAtIndex", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveObjectAtIndex(0); + CC_PROFILER_STOP(this->profilerName()); + + CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); + + } } , + { "removeAllObjects", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveAllObjects(); + CC_PROFILER_STOP(this->profilerName()); + + CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); + } } , + { "swap by index", [=](){ + Array* nodeVector = createArray(); + + int swapIndex1 = quantityOfNodes / 3; + int swapIndex2 = quantityOfNodes / 3 * 2; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iswap(swapIndex1, swapIndex2); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "swap by object", [=](){ + Array* nodeVector = createArray(); + + Object* swapNode1 = nodeVector->getObjectAtIndex(quantityOfNodes / 3); + Object* swapNode2 = nodeVector->getObjectAtIndex(quantityOfNodes / 3 * 2); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iexchangeObject(swapNode1, swapNode2); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "reverseObjects", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; ireverseObjects(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "CCARRAY_FOREACH", [=](){ + Array* nodeVector = createArray(); + Object* obj; + CC_PROFILER_START(this->profilerName()); + + CCARRAY_FOREACH(nodeVector, obj) + { + static_cast(obj)->setTag(111); + } + CC_PROFILER_STOP(this->profilerName()); + } } , + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + +///---------------------------------------- +void runContainerPerformanceTest() +{ + auto scene = createFunctions[g_curCase](); + scene->initWithQuantityOfNodes(kNodesIncrease); + + Director::getInstance()->replaceScene(scene); +} diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h new file mode 100644 index 0000000000..d99cac90ff --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h @@ -0,0 +1,91 @@ +/* + * + */ +#ifndef __PERFORMANCE_CONTAINER_TEST_H__ +#define __PERFORMANCE_CONTAINER_TEST_H__ + +#include "PerformanceTest.h" +#include "CCProfiling.h" + +class ContainerBasicLayer : public PerformBasicLayer +{ +public: + ContainerBasicLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0); + + virtual void showCurrentTest(); +}; + +class PerformanceContainerScene : public Scene +{ +public: + static const int TAG_TITLE = 100; + static const int TAG_SUBTITLE = 101; + + struct TestFunction + { + const char* name; + std::function func; + }; + + virtual void initWithQuantityOfNodes(unsigned int nNodes); + virtual void generateTestFunctions() = 0; + + virtual std::string title() const; + virtual std::string subtitle() const; + virtual void updateQuantityOfNodes(); + + const char* profilerName(); + void updateProfilerName(); + + // for the profiler + virtual const char* testName(); + void updateQuantityLabel(); + int getQuantityOfNodes() { return quantityOfNodes; } + void dumpProfilerInfo(float dt); + + // overrides + virtual void onExitTransitionDidStart() override; + virtual void onEnterTransitionDidFinish() override; + virtual void update(float dt) override; + +protected: + char _profilerName[256]; + int lastRenderedCount; + int quantityOfNodes; + int currentQuantityOfNodes; + unsigned int _type; + std::vector _testFunctions; + + MenuItemFont* _increase; + MenuItemFont* _decrease; + MenuItemFont* _startItem; + MenuItemFont* _stopItem; + MenuItemToggle* _toggle; +}; + +class TemplateVectorPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(TemplateVectorPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class ArrayPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(ArrayPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + + +void runContainerPerformanceTest(); + +#endif // __PERFORMANCE_CONTAINER_TEST_H__ diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp index 9ef97602b6..7884aec8d3 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp @@ -8,6 +8,7 @@ #include "PerformanceAllocTest.h" #include "PerformanceLabelTest.h" #include "PerformanceRendererTest.h" +#include "PerformanceContainerTest.h" enum { @@ -28,6 +29,7 @@ struct { { "Touches Perf Test",[](Object*sender){runTouchesTest();} }, { "Label Perf Test",[](Object*sender){runLabelTest();} }, { "Renderer Perf Test",[](Object*sender){runRendererTest();} }, + { "Container Perf Test", [](Object* sender ) { runContainerPerformanceTest(); } } }; static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]); diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index 1e60324f40..056b3f6cff 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -186,6 +186,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$ + @@ -332,6 +333,8 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\websockets\prebuilt\win32\*.*" "$ + + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index 00e2567c95..5cfe11e6c9 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -718,6 +718,9 @@ Classes\PerformanceTest + + Classes\PerformanceTest + @@ -1324,5 +1327,11 @@ Classes\PerformanceTest + + Classes\PerformanceTest + + + Classes\PerformanceTest + \ No newline at end of file diff --git a/tools/jenkins-scripts/pull-request-builder.py b/tools/jenkins-scripts/pull-request-builder.py index 0b0733639b..91b54c7f69 100755 --- a/tools/jenkins-scripts/pull-request-builder.py +++ b/tools/jenkins-scripts/pull-request-builder.py @@ -27,6 +27,7 @@ def set_description(desc, url): def main(): #get payload from os env payload_str = os.environ['payload'] + payload_str = payload_str.decode('utf-8','ignore') #parse to json obj payload = json.loads(payload_str) 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 681e527955..0b8e553434 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 @@ -5ae50c3f2080b46e18ba3f5aee4c5c686d54e13a \ No newline at end of file +f056b511a4fb5efc921792e46fe57597f669de83 \ No newline at end of file