diff --git a/AUTHORS b/AUTHORS index 27723850a3..c37354a317 100644 --- a/AUTHORS +++ b/AUTHORS @@ -94,6 +94,7 @@ Developers: use tinyxml2 to replace libxml2 Added Mingw-crt Support without breaking VS SDK CMake support for windows. + Added support for x64 target of windows. mchinen fix emulator issue for OpenGL ES 2.0 on Android @@ -717,6 +718,12 @@ Developers: Pisces000221 Corrected a few mistakes in the README file of project-creator. + + hbbalfred + Fixed a bug that crash if file doesn't exist when using FileUtils::getStringFromFile. + + liang8305 + Use multiple processes according the number of cores to build android project Retired Core Developers: WenSheng Yang diff --git a/CHANGELOG b/CHANGELOG index a16751e56c..e77a4728ac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,37 @@ -cocos2d-x-3.0final ?.? ? +cocos2d-x-3.0beta2 ?.? ? [All] - [FIX] Crash was triggered if there is not `textureFileName`section in particle plist file. + [NEW] Adds performance test for Containers(Vector<>, Array, Map, Dictionary). + [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. + [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] Node: Added `setGlobalZOrder()`. Useful to change the Node's render order. Node::setZOrder() -> Node::setLocalZOrder() + [NEW] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% + [NEW] LuaBindings: Bindings-generator supports to bind namespace for lua. + + [FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work. + [FIX] Crash if file doesn't exist when using FileUtils::getStringFromFile. + [FIX] If setting a shorter string than before while using LabelAtlas, the effect will be wrong. + [FIX] Label: Crash when using unknown characters. + [FIX] Console: log(format, va_args) is private to prevent possible resolution errors + [FIX] Configuration: dumpInfo() -> getInfo() [FIX] ControlSlider doesn't support to set selected thumb sprite. [FIX] ControlButton doesn't support to set scale ratio of touchdown state. + [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. + [FIX] Renderer: Uses a float as key with only the depth. Viewport, opaque are not needed now + [FIX] Renderer Performance Fix: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster + [FIX] Renderer Performance Fix: Sprite and SpriteBatchNode (and subclasses) has much better performance + [FIX] Renderer Performance Fix: When note using VAO, call glBufferData() instead of glBufferSubData(). + [FIX] Renderer Performance Fix: Doesn't sort z=0 elements. It also uses sort() instead of stable_sort() for z!=0. + [FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well + [FIX] Tests: TestCpp works with CMake on Windows. + [FIX] Tests: Sprites Performance Test has 4 new tests + [FIX] TextureCache: getTextureForKey and removeTextureForKey work as expected + [FIX] TextureCache: dumpCachedTextureInfo() -> getCachedTextureInfo() [FIX] Websocket doesn't support send/receive data which larger than 4096 bytes. - [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. - [FIX] TestCpp works by using CMake on Windows. + [FIX] Windows: There will be some compilation errors when using x64 target on Windows. + cocos2d-x-3.0beta Jan.7 2014 [All] [NEW] New label: shadow, outline, glow support diff --git a/build/android-build.py b/build/android-build.py index 3285c690e9..0309cf008b 100755 --- a/build/android-build.py +++ b/build/android-build.py @@ -12,6 +12,16 @@ LUA_SAMPLES = ['hellolua', 'testlua'] JSB_SAMPLES = ['cocosdragon', 'crystalcraze', 'moonwarriors', 'testjavascript', 'watermelonwithme'] ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JSB_SAMPLES +def get_num_of_cpu(): + ''' The build process can be accelerated by running multiple concurrent job processes using the -j-option. + ''' + try: + from numpy.distutils import cpuinfo + return cpuinfo.cpu._getNCPUs() + except Exception: + print "Can't know cpuinfo, use default 1 cpu" + return 1 + def check_environment_variables(): ''' Checking the environment NDK_ROOT, which will be used for building ''' @@ -94,10 +104,12 @@ def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,an else: ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root) + num_of_cpu = get_num_of_cpu() if ndk_build_param == None: - command = '%s -C %s %s' % (ndk_path, app_android_root, ndk_module_path) + command = '%s -j%d -C %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_module_path) else: - command = '%s -C %s %s %s' % (ndk_path, app_android_root, ndk_build_param, ndk_module_path) + command = '%s -j%d -C %s %s %s' % (ndk_path, num_of_cpu, app_android_root, ndk_build_param, ndk_module_path) + print command if os.system(command) != 0: raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") elif android_platform is not None: diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index faa1e4571d..a520602c3d 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -3d6ada05d55194dd8e4c10ed8316add7c0d8705c \ No newline at end of file +63e6598ea5798bf42bbd22c2295e65f7c739695a \ 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 0f53b948c7..eac7e38de9 100644 --- a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -2efefc01ff97bda1498d1d4a850ea1881f751f7c \ No newline at end of file +447e7ba37294e6da0df2e02f5a62f30fb15e3272 \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 303a1da40f..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 \ @@ -122,6 +123,7 @@ renderer/CCFrustum.cpp \ renderer/CCGroupCommand.cpp \ renderer/CCMaterialManager.cpp \ renderer/CCQuadCommand.cpp \ +renderer/CCBatchCommand.cpp \ renderer/CCRenderCommand.cpp \ renderer/CCRenderer.cpp \ renderer/CCRenderMaterial.cpp \ diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 5e88b70832..15492a651f 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 @@ -152,13 +152,13 @@ void AtlasNode::draw(void) auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - _quadCommand.init(0, - _vertexZ, + _quadCommand.init( + _globalZOrder, _textureAtlas->getTexture()->getName(), shader, _blendFunc, _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), + _quadsToDraw, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index cdaf6a3df5..f20b4d2778 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 @@ -209,12 +210,12 @@ void ClippingNode::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand.init(0,_vertexZ); + _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - _beforeVisitCmd.init(0,_vertexZ); + _beforeVisitCmd.init(_globalZOrder); _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this); renderer->addCommand(&_beforeVisitCmd); if (_alphaThreshold < 1) @@ -237,7 +238,7 @@ void ClippingNode::visit() } _stencil->visit(); - _afterDrawStencilCmd.init(0,_vertexZ); + _afterDrawStencilCmd.init(_globalZOrder); _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); renderer->addCommand(&_afterDrawStencilCmd); @@ -267,7 +268,7 @@ void ClippingNode::visit() this->draw(); } - _afterVisitCmd.init(0,_vertexZ); + _afterVisitCmd.init(_globalZOrder); _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this); renderer->addCommand(&_afterVisitCmd); diff --git a/cocos/2d/CCConfiguration.cpp b/cocos/2d/CCConfiguration.cpp index 47a079d415..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; @@ -88,24 +88,20 @@ Configuration::~Configuration() { } -void Configuration::dumpInfo() const +std::string Configuration::getInfo() const { - // Dump - Value forDump = Value(_valueDict); - CCLOG("%s", forDump.getDescription().c_str()); - // And Dump some warnings as well #if CC_ENABLE_PROFILERS - CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)"); - printf("\n"); + CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)\n"); #endif #if CC_ENABLE_GL_STATE_CACHE == 0 - CCLOG(""); - CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)"); - printf("\n"); + CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)\n"); #endif + // Dump + Value forDump = Value(_valueDict); + return forDump.getDescription(); } void Configuration::gatherGPUInfo() @@ -150,7 +146,7 @@ void Configuration::gatherGPUInfo() _supportsShareableVAO = checkForGLExtension("vertex_array_object"); _valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO); - + CHECK_GL_ERROR_DEBUG(); } diff --git a/cocos/2d/CCConfiguration.h b/cocos/2d/CCConfiguration.h index f2a7e1052c..4a1ec1568c 100644 --- a/cocos/2d/CCConfiguration.h +++ b/cocos/2d/CCConfiguration.h @@ -122,8 +122,8 @@ public: /** sets a new key/value pair in the configuration dictionary */ void setValue(const std::string& key, const Value& value); - /** dumps the current configuration on the console */ - void dumpInfo() const; + /** returns the Configuration info */ + std::string getInfo() const; /** gathers OpenGL / GPU information */ void gatherGPUInfo(); diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index d3c53b6f3e..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 @@ -377,7 +378,7 @@ void Director::setOpenGLView(EGLView *openGLView) // Configuration. Gather GPU info Configuration *conf = Configuration::getInstance(); conf->gatherGPUInfo(); - conf->dumpInfo(); + CCLOG("%s\n",conf->getInfo().c_str()); // EAGLView is not a Object delete _openGLView; // [openGLView_ release] diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index b920a311c2..003209b6e4 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" @@ -241,7 +241,7 @@ void DrawNode::render() void DrawNode::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } 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 4d35ce980d..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 @@ -100,6 +102,7 @@ bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontL } else { + outDefinition.validDefinition = false; return false; } } @@ -127,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; @@ -140,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; } @@ -149,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 d7125bcd30..0cac300283 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -27,67 +27,85 @@ #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 NS_CC_BEGIN -Label* Label::createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs, bool useDistanceField) +Label* Label::create() { - FontAtlas *tmpAtlas = nullptr; - if(useDistanceField) - tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), DISTANCEFIELD_ATLAS_FONTSIZE, glyphs, customGlyphs,true); - else - tmpAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath.c_str(), fontSize, glyphs, customGlyphs,false); + Label *ret = new Label(); - if (!tmpAtlas) - return nullptr; - - // create the actual label - Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize, useDistanceField,true); - - if (templabel) - { - if(useDistanceField) - templabel->setFontSize(fontSize); - templabel->setText(label, lineSize, alignment, false); - return templabel; - } - - return nullptr; -} - -Label* Label::createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment, int lineSize) -{ - - FontAtlas *tmpAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath.c_str()); - - if (!tmpAtlas) - return 0; - - Label* templabel = Label::createWithAtlas(tmpAtlas, alignment, lineSize); - - if (templabel) - { - templabel->setText(label, lineSize, alignment, false); - return templabel; - } - else - { - return 0; - } - - return 0; -} - -Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int lineSize, bool useDistanceField,bool useA8Shader) -{ - Label *ret = new Label(atlas, alignment, useDistanceField,useA8Shader); - if (!ret) - return 0; - - if( ret->init() ) + return nullptr; + + ret->autorelease(); + + return ret; +} + +Label* Label::createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setTTFConfig(ttfConfig)) + { + if(ttfConfig.distanceFieldEnabled) + ret->setFontSize(ttfConfig.fontSize); + ret->setString(text,alignment,lineSize); + ret->autorelease(); + return ret; + } + else + { + delete ret; + return nullptr; + } +} + +Label* Label::createWithTTF(const std::string& text, const std::string& fontFilePath, int fontSize, int lineSize /* = 0 */, TextHAlignment alignment /* = TextHAlignment::CENTER */, GlyphCollection glyphs /* = GlyphCollection::NEHE */, const char *customGlyphs /* = 0 */, bool useDistanceField /* = false */) +{ + TTFConfig ttfConfig(fontFilePath.c_str(),fontSize,glyphs,customGlyphs,useDistanceField); + return createWithTTF(ttfConfig,text,alignment,lineSize); +} + +Label* Label::createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment /* = TextHAlignment::CENTER */, int lineSize /* = 0 */) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setBMFontFilePath(bmfontFilePath)) + { + ret->setString(text,alignment,lineSize); + ret->autorelease(); + return ret; + } + else + { + delete ret; + return nullptr; + } +} + +Label* Label::createWithCharMap(const std::string& plistFile) +{ + Label *ret = new Label(); + + if (!ret) + return nullptr; + + if (ret->setCharMap(plistFile)) { ret->autorelease(); return ret; @@ -95,21 +113,86 @@ Label* Label::createWithAtlas(FontAtlas *atlas, TextHAlignment alignment, int li else { delete ret; - return 0; + return nullptr; } - - return ret; +} + +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) -, _multilineEnable(true) , _commonLineHeight(0.0f) , _lineBreakWithoutSpaces(false) , _width(0.0f) , _alignment(alignment) -, _currentUTF16String(0) -, _originalUTF16String(0) +, _currentUTF16String(nullptr) +, _originalUTF16String(nullptr) , _advances(nullptr) , _fontAtlas(atlas) , _isOpacityModifyRGB(true) @@ -118,6 +201,7 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b , _fontSize(0) , _uniformEffectColor(0) { + _cascadeColorEnabled = true; } Label::~Label() @@ -137,10 +221,13 @@ bool Label::init() bool ret = true; if(_fontAtlas) { - _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); - _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); - ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); - _reusedLetter->retain(); + if (_reusedLetter == nullptr) + { + _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); + _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); + _reusedLetter->retain(); + } + ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); } if (_useDistanceField) setLabelEffect(LabelEffect::NORMAL,Color3B::BLACK); @@ -148,46 +235,94 @@ bool Label::init() setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR)); else setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + return ret; } -void Label::setString(const std::string &stringToRender) +bool Label::initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false */, bool useA8Shader /* = false */) { - _multilineEnable = true; - setText(stringToRender, _width, TextHAlignment::CENTER, false); + FontAtlas *oldAtlas = _fontAtlas; + bool oldDistanceFieldEnable = _useDistanceField; + bool oldA8ShaderEnabel = _useA8Shader; + + _fontAtlas = atlas; + _useDistanceField = distanceFieldEnabled; + _useA8Shader = useA8Shader; + + bool ret = Label::init(); + if (oldAtlas) + { + if (ret) + { + FontAtlasCache::releaseFontAtlas(oldAtlas); + } + else + { + _fontAtlas = oldAtlas; + _useDistanceField = oldDistanceFieldEnable; + _useA8Shader = oldA8ShaderEnabel; + Label::init(); + + FontAtlasCache::releaseFontAtlas(atlas); + } + } + + if (_fontAtlas) + { + _commonLineHeight = _fontAtlas->getCommonLineHeight(); + if (_currentUTF16String) + { + alignText(); + } + } + + return ret; } -void Label::setString(const std::string &stringToRender,bool multilineEnable) +bool Label::setTTFConfig(const TTFConfig& ttfConfig) { - _multilineEnable = multilineEnable; - setText(stringToRender, _width, TextHAlignment::CENTER, false); + FontAtlas *newAtlas = nullptr; + if(ttfConfig.distanceFieldEnabled) + newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, DISTANCEFIELD_ATLAS_FONTSIZE, ttfConfig.glyphs, ttfConfig.customGlyphs,true); + else + newAtlas = FontAtlasCache::getFontAtlasTTF(ttfConfig.fontFilePath, ttfConfig.fontSize, ttfConfig.glyphs, ttfConfig.customGlyphs,false); + + if (!newAtlas) + return false; + + return initWithFontAtlas(newAtlas,ttfConfig.distanceFieldEnabled,true); } -bool Label::setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment, bool lineBreakWithoutSpaces) +bool Label::setBMFontFilePath(const std::string& bmfontFilePath) { - if (!_fontAtlas) + FontAtlas *newAtlas = FontAtlasCache::getFontAtlasFNT(bmfontFilePath); + + if (!newAtlas) + return false; + + return initWithFontAtlas(newAtlas); +} + +bool Label::setString(const std::string& text, const TextHAlignment& alignment /* = TextHAlignment::CENTER */, float lineWidth /* = -1 */, bool lineBreakWithoutSpaces /* = false */) +{ + if (!_fontAtlas || _commonLineHeight <= 0) return false; // carloX // reset the string resetCurrentString(); - _width = lineWidth; + if(lineWidth >= 0) + { + _width = lineWidth; + } _alignment = alignment; _lineBreakWithoutSpaces = lineBreakWithoutSpaces; - // store locally common line height - _commonLineHeight = _fontAtlas->getCommonLineHeight(); - if (_commonLineHeight <= 0) - return false; - -// int numLetter = 0; - unsigned short* utf16String = cc_utf8_to_utf16(stringToRender.c_str()); + unsigned short* utf16String = cc_utf8_to_utf16(text.c_str()); if(!utf16String) return false; - _cascadeColorEnabled = true; - setCurrentString(utf16String); setOriginalString(utf16String); @@ -299,7 +434,7 @@ void Label::alignText() _textureAtlas->removeAllQuads(); _fontAtlas->prepareLetterDefinitions(_currentUTF16String); LabelTextFormatter::createStringSprites(this); - if(_multilineEnable && LabelTextFormatter::multilineText(this) ) + if(_width > 0 && LabelTextFormatter::multilineText(this) ) LabelTextFormatter::createStringSprites(this); LabelTextFormatter::alignText(this); @@ -531,7 +666,7 @@ void Label::onDraw() void Label::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Label::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index ea7462ab50..b34507312e 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -54,23 +54,51 @@ enum class LabelEffect { struct FontLetterDefinition; class FontAtlas; +typedef struct _ttfConfig +{ + std::string fontFilePath; + int fontSize; + GlyphCollection glyphs; + const char *customGlyphs; + bool distanceFieldEnabled; + _ttfConfig(const char* filePath,int size = 36, const GlyphCollection& glyphCollection = GlyphCollection::NEHE, + const char *customGlyphCollection = nullptr,bool useDistanceField = false) + :fontFilePath(filePath) + ,fontSize(size) + ,glyphs(glyphCollection) + ,customGlyphs(customGlyphCollection) + ,distanceFieldEnabled(useDistanceField) + {} +}TTFConfig; -class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public LabelTextFormatProtocol +class CC_DLL Label : public SpriteBatchNode, public LabelTextFormatProtocol { public: - - // static create - static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false); - - static Label* createWithBMFont(const std::string& label, const std::string& bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0); - - bool setText(const std::string& stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false); + static Label* create(); + CC_DEPRECATED_ATTRIBUTE static Label* createWithTTF(const std::string& label, const std::string& fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0, bool useDistanceField = false); + static Label* createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment alignment = TextHAlignment::CENTER, int lineWidth = 0); + + static Label* createWithBMFont(const std::string& bmfontFilePath, const std::string& text,const TextHAlignment& alignment = TextHAlignment::CENTER, int lineWidth = 0); + + 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 void setLabelEffect(LabelEffect effect,const Color3B& effectColor); - virtual void setString(const std::string &stringToRender) override; - void setString(const std::string &stringToRender,bool multilineEnable); virtual void setAlignment(TextHAlignment alignment); virtual void setWidth(float width); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); @@ -116,7 +144,7 @@ public: virtual void setLabelContentSize(const Size &newSize) override; // carloX - virtual const std::string& getString() const override { static std::string _ret("not implemented"); return _ret; } + virtual const std::string& getString() const { static std::string _ret("not implemented"); return _ret; } void addChild(Node * child, int zOrder=0, int tag=0) override; virtual std::string getDescription() const override; @@ -127,14 +155,14 @@ private: /** * @js NA */ - Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField = false,bool useA8Shader = false); + Label(FontAtlas *atlas = nullptr, TextHAlignment alignment = TextHAlignment::CENTER, bool useDistanceField = false,bool useA8Shader = false); /** * @js NA * @lua NA */ ~Label(); - static Label* createWithAtlas(FontAtlas *atlas, TextHAlignment alignment = TextHAlignment::LEFT, int lineSize = 0, bool useDistanceField = false,bool useA8Shader = false); + bool initWithFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled = false, bool useA8Shader = false); void setFontSize(int fontSize); @@ -151,32 +179,30 @@ private: virtual void updateColor() override; - //! used for optimization - Sprite *_reusedLetter; - std::vector _lettersInfo; - - bool _multilineEnable; - float _commonLineHeight; - bool _lineBreakWithoutSpaces; - float _width; - TextHAlignment _alignment; - unsigned short int * _currentUTF16String; - unsigned short int * _originalUTF16String; - Size * _advances; - FontAtlas * _fontAtlas; - bool _isOpacityModifyRGB; + Sprite *_reusedLetter; + std::vector _lettersInfo; - bool _useDistanceField; - bool _useA8Shader; - int _fontSize; + float _commonLineHeight; + bool _lineBreakWithoutSpaces; + float _width; + TextHAlignment _alignment; + unsigned short int * _currentUTF16String; + unsigned short int * _originalUTF16String; + Size * _advances; + FontAtlas * _fontAtlas; + bool _isOpacityModifyRGB; - LabelEffect _currLabelEffect; - Color3B _effectColor; + bool _useDistanceField; + bool _useA8Shader; + int _fontSize; - GLuint _uniformEffectColor; + LabelEffect _currLabelEffect; + Color3B _effectColor; - CustomCommand _customCommand; + GLuint _uniformEffectColor; + + CustomCommand _customCommand; }; diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index 539c5dab6a..1b856664fd 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -275,8 +275,7 @@ std::set* CCBMFontConfiguration::parseBinaryConfigFile(unsigned ch unsigned long remains = size; - unsigned char version = pData[3]; - CCASSERT(version == 3, "Only version 3 is supported"); + CCASSERT(pData[3] == 3, "Only version 3 is supported"); pData += 4; remains -= 4; @@ -343,8 +342,7 @@ std::set* CCBMFontConfiguration::parseBinaryConfigFile(unsigned ch */ const char *value = (const char *)pData; - size_t len = strlen(value); - CCASSERT(len < blockSize, "Block size should be less then string"); + CCASSERT(strlen(value) < blockSize, "Block size should be less then string"); _atlasName = FileUtils::getInstance()->fullPathFromRelativeFile(value, controlFile); } 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 956c5c3bb1..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; @@ -63,20 +63,24 @@ bool LabelTextFormatter::multilineText(LabelTextFormatProtocol *theLabel) { LetterInfo* info = &leterInfo->at(j+skip); - unsigned int justSkipped = 0; + unsigned int justSkipped = 0; while (info->def.validDefinition == false) { justSkipped++; - info = &leterInfo->at( j+skip+justSkipped ); + tIndex = j+skip+justSkipped; + if(tIndex < strLen) + info = &leterInfo->at( tIndex ); + else + break; } skip += justSkipped; tIndex = j + skip; - if (i >= stringLength) + if (tIndex >= stringLength) break; - unsigned short character = strWhole[i]; + unsigned short character = strWhole[tIndex]; if (!isStartOfWord) { @@ -241,8 +245,6 @@ bool LabelTextFormatter::alignText(LabelTextFormatProtocol *theLabel) continue; } int index = static_cast(i + lineLength - 1 + lineNumber); - if(currentChar == 0) - index -= 1; if (index < 0) continue; LetterInfo* info = &leterInfo->at( index ); @@ -351,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..54b9c48cd9 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 @@ -565,7 +565,7 @@ void LayerColor::updateColor() void LayerColor::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index 4e248b7ea1..735a8edae2 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 @@ -359,7 +359,7 @@ void MotionStreak::draw() if(_nuPoints <= 1) return; kmGLGetMatrix(KM_GL_MODELVIEW,&_cachedMV); - _customCommand.init(0,_vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(MotionStreak::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 3b7ce1c47c..e631d0f02a 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -108,7 +108,8 @@ Node::Node(void) , _inverseDirty(true) // children (lazy allocs) // lazy alloc -, _ZOrder(0) +, _localZOrder(0) +, _globalZOrder(0) , _parent(nullptr) // "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true , _tag(Node::INVALID_TAG) @@ -212,29 +213,22 @@ void Node::setSkewY(float newSkewY) _transformDirty = _inverseDirty = true; } -/// zOrder getter -int Node::getZOrder() const -{ - return _ZOrder; -} /// zOrder setter : private method /// used internally to alter the zOrder variable. DON'T call this method manually -void Node::_setZOrder(int z) +void Node::_setLocalZOrder(int z) { - _ZOrder = z; + _localZOrder = z; } -void Node::setZOrder(int z) +void Node::setLocalZOrder(int z) { + _localZOrder = z; if (_parent) { _parent->reorderChild(this, z); } - // should set "_ZOrder" after reorderChild, because the implementation of reorderChild subclass of Node, such as Sprite, - // will return when _ZOrder value is not changed - _setZOrder(z); - + _eventDispatcher->setDirtyForNode(this); } @@ -246,9 +240,10 @@ float Node::getVertexZ() const /// vertexZ setter -void Node::setVertexZ(float var) +void Node::setVertexZ(float zOrder) { - _vertexZ = var; + _vertexZ = zOrder; + setGlobalZOrder(zOrder); } @@ -650,7 +645,7 @@ void Node::addChild(Node *child, int zOrder) void Node::addChild(Node *child) { CCASSERT( child != nullptr, "Argument must be non-nil"); - this->addChild(child, child->_ZOrder, child->_tag); + this->addChild(child, child->_localZOrder, child->_tag); } void Node::removeFromParent() @@ -767,7 +762,7 @@ void Node::insertChild(Node* child, int z) { _reorderChildDirty = true; _children.pushBack(child); - child->_setZOrder(z); + child->_setLocalZOrder(z); } void Node::reorderChild(Node *child, int zOrder) @@ -775,7 +770,7 @@ void Node::reorderChild(Node *child, int zOrder) CCASSERT( child != nullptr, "Child must be non-nil"); _reorderChildDirty = true; child->setOrderOfArrival(s_globalOrderOfArrival++); - child->_setZOrder(zOrder); + child->_setLocalZOrder(zOrder); } void Node::sortAllChildren() @@ -816,7 +811,7 @@ void Node::visit() { auto node = _children.at(i); - if ( node && node->_ZOrder < 0 ) + if ( node && node->_localZOrder < 0 ) node->visit(); else break; diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 3069fb0a84..0598773a7c 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -161,43 +161,72 @@ public: /// @name Setters & Getters for Graphic Peroperties /** - * Sets the Z order which stands for the drawing order, and reorder this node in its parent's children array. - * - * The Z order of node is relative to its siblings. - * It is not related to the OpenGL's z property. This one only affects the draw order of itself and its siblings. - * Lower Z order number are drawn before higher numbers. - * Please refer to `setVertexZ(float)` for the difference. - * - * @param zOrder Z order of this node. + LocalZOrder is the 'key' used to sort the node relative to its siblings. + + The Node's parent will sort all its children based ont the LocalZOrder value. + If two nodes have the same LocalZOrder, then the node that was added first to the children's array will be in front of the other node in the array. + + Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order ) + And Nodes that have LocalZOder values < 0 are the "left" subtree + While Nodes with LocalZOder >=0 are the "right" subtree. + + @see `setGlobalZOrder` + @see `setVertexZ` */ - virtual void setZOrder(int zOrder); - /* - * Sets the z order which stands for the drawing order - * - * This is an internal method. Don't call it outside the framework. - * The difference between setZOrder(int) and _setOrder(int) is: - * - _setZOrder(int) is a pure setter for _ZOrder memeber variable - * - setZOrder(int) firstly changes _ZOrder, then recorder this node in its parent's chilren array. + virtual void setLocalZOrder(int zOrder); + + CC_DEPRECATED_ATTRIBUTE virtual void setZOrder(int zOrder) { setLocalZOrder(zOrder); } + /* Helper function used by `setLocalZOrder`. Don't use it unless you know what you are doing. */ - virtual void _setZOrder(int z); + virtual void _setLocalZOrder(int z); /** - * Gets the Z order of this node. + * Gets the local Z order of this node. * - * @see `setZOrder(int)` + * @see `setLocalZOrder(int)` * - * @return The Z order. + * @return The local (relative to its siblings) Z order. */ - virtual int getZOrder() const; + virtual int getLocalZOrder() const { return _localZOrder; } + CC_DEPRECATED_ATTRIBUTE virtual int getZOrder() const { return getLocalZOrder(); } /** - * Sets the real OpenGL Z vertex. + Defines the oder in which the nodes are renderer. + Nodes that have a Global Z Order lower, are renderer first. + + In case two or more nodes have the same Global Z Order, the oder is not guaranteed. + The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used. + + By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes. + + Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order. + + Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their acenstors. + And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode. + + @see `setLocalZOrder()` + @see `setVertexZ()` + + @since v3.0 + */ + virtual void setGlobalZOrder(float zOrder) { _globalZOrder = zOrder; } + /** + * Returns the Node's Global Z Order. * - * Differences between openGL Z vertex and cocos2d Z order: - * - OpenGL Z modifies the Z vertex, and not the Z order in the relation between parent-children - * - OpenGL Z might require to set 2D projection - * - cocos2d Z order works OK if all the nodes uses the same openGL Z vertex. eg: `vertexZ = 0` + * @see `setGlobalZOrder(int)` * - * @warning Use it at your own risk since it might break the cocos2d parent-children z order + * @return The node's global Z order + */ + virtual float getGlobalZOrder() const { return _globalZOrder; } + + /** + * Sets the 'z' value in the OpenGL Depth Buffer. + * + * The OpenGL depth buffer and depth testing are disabled by default. You need to turn them on + * in order to use this property correctly. + * + * `setVertexZ()` also sets the `setGlobalZValue()` with the vertexZ value. + * + * @see `setGlobalZValue()` * * @param vertexZ OpenGL Z vertex of this node. */ @@ -1411,7 +1440,6 @@ protected: float _scaleX; ///< scaling factor on x-axis float _scaleY; ///< scaling factor on y-axis - float _vertexZ; ///< OpenGL real Z vertex Point _position; ///< position of the node @@ -1433,8 +1461,12 @@ protected: mutable bool _transformDirty; ///< transform dirty flag mutable bool _inverseDirty; ///< inverse transform dirty flag - int _ZOrder; ///< z-order value that affects the draw order - + + int _localZOrder; ///< Local order (relative to its siblings) used to sort the node + float _globalZOrder; ///< Global order used to sort the node + float _vertexZ; ///< OpenGL real Z vertex + + Vector _children; ///< array of children nodes Node *_parent; ///< weak reference to parent node diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 90d5647a57..f8c5d5accb 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 @@ -92,7 +92,7 @@ void NodeGrid::visit() Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand.init(0,_vertexZ); + _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); @@ -104,7 +104,7 @@ void NodeGrid::visit() _nodeGrid->set2DProjection(); } - _gridBeginCommand.init(0,_vertexZ); + _gridBeginCommand.init(_globalZOrder); _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); renderer->addCommand(&_gridBeginCommand); @@ -152,7 +152,7 @@ void NodeGrid::visit() director->setProjection(beforeProjectionType); } - _gridEndCommand.init(0,_vertexZ); + _gridEndCommand.init(_globalZOrder); _gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); renderer->addCommand(&_gridEndCommand); diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 5b78d1256f..bca1c3eb28 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 @@ -197,7 +197,7 @@ int ParticleBatchNode::addChildHelper(ParticleSystem* child, int z, int aTag) _children.insert(pos, child); child->setTag(aTag); - child->_setZOrder(z); + child->_setLocalZOrder(z); child->setParent(this); @@ -264,7 +264,7 @@ void ParticleBatchNode::reorderChild(Node * aChild, int zOrder) } } - child->_setZOrder(zOrder); + child->_setLocalZOrder(zOrder); } void ParticleBatchNode::getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z) @@ -382,26 +382,14 @@ void ParticleBatchNode::draw(void) return; } -// CC_NODE_DRAW_SETUP(); -// -// GL::blendFunc( _blendFunc.src, _blendFunc.dst ); -// -// _textureAtlas->drawQuads(); - - auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - - _quadCommand.init(0, - _vertexZ, - _textureAtlas->getTexture()->getName(), - shader, - _blendFunc, - _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), - mv); - Director::getInstance()->getRenderer()->addCommand(&_quadCommand); + _batchCommand.init( + _globalZOrder, + _textureAtlas->getTexture()->getName(), + _shaderProgram, + _blendFunc, + _textureAtlas, + _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_batchCommand); CC_PROFILER_STOP("CCParticleBatchNode - draw"); } diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index d4fd276603..bb092e96d2 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -32,7 +32,7 @@ #include "CCNode.h" #include "CCProtocols.h" -#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" NS_CC_BEGIN @@ -146,7 +146,7 @@ private: /** the blend function used for drawing the quads */ BlendFunc _blendFunc; // quad command - QuadCommand _quadCommand; + BatchCommand _batchCommand; }; // end of particle_nodes group diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index 579db6c024..bd4bef3599 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" @@ -439,7 +439,7 @@ void ParticleSystemQuad::draw() auto shader = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - _quadCommand.init(0, _vertexZ, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); + _quadCommand.init(_globalZOrder, _texture->getName(), shader, _blendFunc, _quads, _particleIdx, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index 7d135a9016..112b34d85b 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" @@ -555,7 +555,7 @@ void ProgressTimer::draw() if( ! _vertexData || ! _sprite) return; - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ProgressTimer::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index efaad582ef..57b6a00d24 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" @@ -322,7 +322,7 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep this->begin(); //clear screen - _beginWithClearCommand.init(0, _vertexZ); + _beginWithClearCommand.init(_globalZOrder); _beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand); } @@ -340,7 +340,7 @@ void RenderTexture::clearDepth(float depthValue) this->begin(); - _clearDepthCommand.init(0, _vertexZ); + _clearDepthCommand.init(_globalZOrder); _clearDepthCommand.func = CC_CALLBACK_0(RenderTexture::onClearDepth, this); Director::getInstance()->getRenderer()->addCommand(&_clearDepthCommand); @@ -605,7 +605,7 @@ void RenderTexture::draw() begin(); //clear screen - _clearCommand.init(0, _vertexZ); + _clearCommand.init(_globalZOrder); _clearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_clearCommand); @@ -648,13 +648,13 @@ void RenderTexture::begin() (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 ); kmGLMultMatrix(&orthoMatrix); - _groupCommand.init(0, _vertexZ); + _groupCommand.init(_globalZOrder); Renderer *renderer = Director::getInstance()->getRenderer(); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - _beginCommand.init(0, _vertexZ); + _beginCommand.init(_globalZOrder); _beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this); Director::getInstance()->getRenderer()->addCommand(&_beginCommand); @@ -662,7 +662,7 @@ void RenderTexture::begin() void RenderTexture::end() { - _endCommand.init(0, _vertexZ); + _endCommand.init(_globalZOrder); _endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this); Renderer *renderer = Director::getInstance()->getRenderer(); diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 271f1e8db9..65c7a24b50 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" @@ -242,9 +242,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) // zwoptex default values _offsetPosition = Point::ZERO; - - _hasChildren = false; - + // clean the Quad memset(&_quad, 0, sizeof(_quad)); @@ -672,7 +670,7 @@ void Sprite::updateTransform(void) void Sprite::draw(void) { //TODO implement z order - _quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); + _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); // if(culling()) { @@ -767,18 +765,12 @@ void Sprite::addChild(Node *child, int zOrder, int tag) } //CCNode already sets isReorderChildDirty_ so this needs to be after batchNode check Node::addChild(child, zOrder, tag); - _hasChildren = true; } void Sprite::reorderChild(Node *child, int zOrder) { - CCASSERT(child != nullptr, ""); - CCASSERT(_children.contains(child), ""); - - if (zOrder == child->getZOrder()) - { - return; - } + CCASSERT(child != nullptr, "child must be non null"); + CCASSERT(_children.contains(child), "child does not belong to this"); if( _batchNode && ! _reorderChildDirty) { @@ -813,8 +805,6 @@ void Sprite::removeAllChildrenWithCleanup(bool cleanup) } Node::removeAllChildrenWithCleanup(cleanup); - - _hasChildren = false; } void Sprite::sortAllChildren() @@ -882,27 +872,24 @@ void Sprite::setDirtyRecursively(bool bValue) { _recursiveDirty = bValue; setDirty(bValue); - // recursively set dirty - if (_hasChildren) - { - for(const auto &child: _children) { - Sprite* sp = dynamic_cast(child); - if (sp) - { - sp->setDirtyRecursively(true); - } + + for(const auto &child: _children) { + Sprite* sp = dynamic_cast(child); + if (sp) + { + sp->setDirtyRecursively(true); } } } // XXX HACK: optimization -#define SET_DIRTY_RECURSIVELY() { \ - if (! _recursiveDirty) { \ - _recursiveDirty = true; \ - setDirty(true); \ - if ( _hasChildren) \ - setDirtyRecursively(true); \ - } \ +#define SET_DIRTY_RECURSIVELY() { \ + if (! _recursiveDirty) { \ + _recursiveDirty = true; \ + setDirty(true); \ + if (!_children.empty()) \ + setDirtyRecursively(true); \ + } \ } void Sprite::setPosition(const Point& pos) diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 0a937a64e1..2081ef8336 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -538,7 +538,6 @@ protected: bool _dirty; /// Whether the sprite needs to be updated bool _recursiveDirty; /// Whether all of the sprite's children needs to be updated - bool _hasChildren; /// Whether the sprite contains children bool _shouldBeHidden; /// should not be drawn because one of the ancestors is not visible kmMat4 _transformToBatch; diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 3ef2e183e9..0526b6768d 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" @@ -99,7 +99,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity) _descendants.reserve(capacity); - setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } @@ -356,18 +356,14 @@ void SpriteBatchNode::draw() for(const auto &child: _children) child->updateTransform(); - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - - _quadCommand.init(0, - _vertexZ, - _textureAtlas->getTexture()->getName(), - _shaderProgram, - _blendFunc, - _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), - mv); - Director::getInstance()->getRenderer()->addCommand(&_quadCommand); + _batchCommand.init( + _globalZOrder, + _textureAtlas->getTexture()->getName(), + _shaderProgram, + _blendFunc, + _textureAtlas, + _modelViewTransform); + Director::getInstance()->getRenderer()->addCommand(&_batchCommand); } void SpriteBatchNode::increaseAtlasCapacity(void) diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index fc140aa391..bbb6294e6d 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -35,7 +35,7 @@ THE SOFTWARE. #include "CCProtocols.h" #include "CCTextureAtlas.h" #include "ccMacros.h" -#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" NS_CC_BEGIN @@ -189,7 +189,7 @@ protected: TextureAtlas *_textureAtlas; BlendFunc _blendFunc; - QuadCommand _quadCommand; // quad command + BatchCommand _batchCommand; // render command // all descendants: children, grand children, etc... // There is not need to retain/release these objects, since they are already retained by _children diff --git a/cocos/2d/CCTMXTiledMap.cpp b/cocos/2d/CCTMXTiledMap.cpp index 33a4b77519..54fecd658b 100644 --- a/cocos/2d/CCTMXTiledMap.cpp +++ b/cocos/2d/CCTMXTiledMap.cpp @@ -174,7 +174,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo) if (layerInfo->_visible) { TMXLayer *child = parseLayer(layerInfo, mapInfo); - addChild((Node*)child, idx, idx); + addChild(child, idx, idx); // update content size with the max size const Size& childSize = child->getContentSize(); 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/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index 4af449c8bf..c6527ba07f 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -97,7 +97,7 @@ void TextureCache::addImageAsync(const std::string &path, std::functionfullPathForFilename(path.c_str()); + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path); auto it = _textures.find(fullpath); if( it != _textures.end() ) @@ -290,7 +290,7 @@ Texture2D * TextureCache::addImage(const std::string &path) // MUTEX: // Needed since addImageAsync calls this method from a different thread - std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path.c_str()); + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path); if (fullpath.size() == 0) { return nullptr; @@ -307,7 +307,7 @@ Texture2D * TextureCache::addImage(const std::string &path) image = new Image(); CC_BREAK_IF(nullptr == image); - bool bRet = image->initWithImageFile(fullpath.c_str()); + bool bRet = image->initWithImageFile(fullpath); CC_BREAK_IF(!bRet); texture = new Texture2D(); @@ -417,16 +417,30 @@ void TextureCache::removeTexture(Texture2D* texture) void TextureCache::removeTextureForKey(const std::string &textureKeyName) { - auto it = _textures.find(textureKeyName); + std::string key = textureKeyName; + auto it = _textures.find(key); + + if( it == _textures.end() ) { + key = FileUtils::getInstance()->fullPathForFilename(textureKeyName); + it = _textures.find(key); + } + if( it != _textures.end() ) { (it->second)->release(); _textures.erase(it); } } -Texture2D* TextureCache::getTextureForKey(const std::string &key) const +Texture2D* TextureCache::getTextureForKey(const std::string &textureKeyName) const { + std::string key = textureKeyName; auto it = _textures.find(key); + + if( it == _textures.end() ) { + key = FileUtils::getInstance()->fullPathForFilename(textureKeyName); + it = _textures.find(key); + } + if( it != _textures.end() ) return it->second; return nullptr; @@ -448,20 +462,28 @@ void TextureCache::waitForQuit() if (_loadingThread) _loadingThread->join(); } -void TextureCache::dumpCachedTextureInfo() const +std::string TextureCache::getCachedTextureInfo() const { + char buffer[16386]; + char buftmp[4096]; + + memset(buffer,0,sizeof(buffer)); + unsigned int count = 0; unsigned int totalBytes = 0; for( auto it = _textures.begin(); it != _textures.end(); ++it ) { + memset(buftmp,0,sizeof(buftmp)); + + Texture2D* tex = it->second; unsigned int bpp = tex->getBitsPerPixelForFormat(); // Each texture takes up width * height * bytesPerPixel bytes. auto bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8; totalBytes += bytes; count++; - log("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB", + snprintf(buftmp,sizeof(buftmp)-1,"\"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB\n", it->first.c_str(), (long)tex->retainCount(), (long)tex->getName(), @@ -469,9 +491,13 @@ void TextureCache::dumpCachedTextureInfo() const (long)tex->getPixelsHigh(), (long)bpp, (long)bytes / 1024); + strcat(buffer, buftmp); } - log("cocos2d: TextureCache dumpDebugInfo: %ld textures, for %lu KB (%.2f MB)", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f)); + snprintf(buftmp, sizeof(buftmp)-1, "TextureCache dumpDebugInfo: %ld textures, for %lu KB (%.2f MB)\n", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f)); + strcat(buffer, buftmp); + + return std::string(buffer); } #if CC_ENABLE_CACHE_TEXTURE_DATA diff --git a/cocos/2d/CCTextureCache.h b/cocos/2d/CCTextureCache.h index 8d55c93656..f5b187797f 100644 --- a/cocos/2d/CCTextureCache.h +++ b/cocos/2d/CCTextureCache.h @@ -163,7 +163,7 @@ public: * * @since v1.0 */ - void dumpCachedTextureInfo() const; + std::string getCachedTextureInfo() const; //wait for texture cahe to quit befor destroy instance //called by director, please do not called outside diff --git a/cocos/2d/CCTransitionPageTurn.cpp b/cocos/2d/CCTransitionPageTurn.cpp index 7ade9878a4..7e4102b009 100644 --- a/cocos/2d/CCTransitionPageTurn.cpp +++ b/cocos/2d/CCTransitionPageTurn.cpp @@ -98,23 +98,23 @@ void TransitionPageTurn::draw() if( _isInSceneOnTop ) { _outSceneProxy->visit(); - _enableOffsetCmd.init(0, _vertexZ); + _enableOffsetCmd.init(_globalZOrder); _enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd); _inSceneProxy->visit(); - _disableOffsetCmd.init(0, _vertexZ); + _disableOffsetCmd.init(_globalZOrder); _disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd); } else { _inSceneProxy->visit(); - _enableOffsetCmd.init(0, _vertexZ); + _enableOffsetCmd.init(_globalZOrder); _enableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onEnablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_enableOffsetCmd); _outSceneProxy->visit(); - _disableOffsetCmd.init(0, _vertexZ); + _disableOffsetCmd.init(_globalZOrder); _disableOffsetCmd.func = CC_CALLBACK_0(TransitionPageTurn::onDisablePolygonOffset, this); Director::getInstance()->getRenderer()->addCommand(&_disableOffsetCmd); } diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 88090ec7c5..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 @@ -144,6 +145,7 @@ set(COCOS2D_SRC renderer/CCGroupCommand.cpp renderer/CCMaterialManager.cpp renderer/CCQuadCommand.cpp + renderer/CCBatchCommand.cpp renderer/CCRenderCommand.cpp renderer/CCRenderer.cpp renderer/CCRenderMaterial.cpp diff --git a/cocos/2d/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/ccGLStateCache.cpp b/cocos/2d/ccGLStateCache.cpp index 97599289d1..d8a620f463 100644 --- a/cocos/2d/ccGLStateCache.cpp +++ b/cocos/2d/ccGLStateCache.cpp @@ -44,7 +44,6 @@ namespace static bool s_vertexAttribColor = false; static bool s_vertexAttribTexCoords = false; - #if CC_ENABLE_GL_STATE_CACHE #define kMaxActiveTexture 16 @@ -55,6 +54,8 @@ namespace static GLenum s_blendingDest = -1; static int s_GLServerState = 0; static GLuint s_VAO = 0; + static GLenum s_activeTexture = -1; + #endif // CC_ENABLE_GL_STATE_CACHE } @@ -159,7 +160,7 @@ void bindTexture2DN(GLuint textureUnit, GLuint textureId) if (s_currentBoundTexture[textureUnit] != textureId) { s_currentBoundTexture[textureUnit] = textureId; - glActiveTexture(GL_TEXTURE0 + textureUnit); + activeTexture(GL_TEXTURE0 + textureUnit); glBindTexture(GL_TEXTURE_2D, textureId); } #else @@ -186,6 +187,18 @@ void deleteTextureN(GLuint textureUnit, GLuint textureId) glDeleteTextures(1, &textureId); } +void activeTexture(GLenum texture) +{ +#if CC_ENABLE_GL_STATE_CACHE + if(s_activeTexture != texture) { + s_activeTexture = texture; + glActiveTexture(s_activeTexture); + } +#else + glActiveTexture(texture); +#endif +} + void bindVAO(GLuint vaoId) { if (Configuration::getInstance()->supportsShareableVAO()) diff --git a/cocos/2d/ccGLStateCache.h b/cocos/2d/ccGLStateCache.h index a33f8ba59d..fd94c7006f 100644 --- a/cocos/2d/ccGLStateCache.h +++ b/cocos/2d/ccGLStateCache.h @@ -129,6 +129,12 @@ void CC_DLL deleteTexture(GLuint textureId); */ void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId); +/** Select active texture unit. + If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly. + @since v3.0 + */ +void CC_DLL activeTexture(GLenum texture); + /** If the vertex array is not already bound, it binds it. If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glBindVertexArray() directly. @since v2.0.0 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 90be6eac6d..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 + @@ -317,6 +318,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -428,6 +430,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -521,6 +524,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + diff --git a/cocos/2d/cocos2d.vcxproj.filters b/cocos/2d/cocos2d.vcxproj.filters index b57af69e45..6a28597e2d 100644 --- a/cocos/2d/cocos2d.vcxproj.filters +++ b/cocos/2d/cocos2d.vcxproj.filters @@ -598,6 +598,12 @@ renderer + + renderer + + + label_nodes + @@ -1207,5 +1213,11 @@ renderer + + renderer + + + label_nodes + \ No newline at end of file diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index 3404675922..77988ff696 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -547,6 +547,8 @@ static Data getData(const std::string& filename, bool forString) std::string FileUtils::getStringFromFile(const std::string& filename) { Data data = getData(filename, true); + if (data.isNull()) + return ""; std::string ret((const char*)data.getBytes()); return ret; } diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index 0a29d6efe5..be747149cb 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -326,7 +326,10 @@ public: * @note This method is used internally. */ virtual ValueVector getValueVectorFromFile(const std::string& filename); - + + /** Returns the full path cache */ + const std::unordered_map& getFullPathCache() const { return _fullPathCache; } + protected: /** * The default constructor. diff --git a/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index e1566df16d..f1e7afb0ed 100644 --- a/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -89,38 +89,43 @@ public class Cocos2dxHelper { jobs.add(r); } + private static boolean sInited = false; public static void init(final Activity activity) { - final ApplicationInfo applicationInfo = activity.getApplicationInfo(); - - initListener(); - - try { - // Get the lib_name from AndroidManifest.xml metadata - ActivityInfo ai = - activity.getPackageManager().getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA); - if (null != ai.metaData) { - String lib_name = ai.metaData.getString(META_DATA_LIB_NAME); - if (null != lib_name) { - System.loadLibrary(lib_name); - } else { - System.loadLibrary(DEFAULT_LIB_NAME); + if (!sInited) { + final ApplicationInfo applicationInfo = activity.getApplicationInfo(); + + initListener(); + + try { + // Get the lib_name from AndroidManifest.xml metadata + ActivityInfo ai = + activity.getPackageManager().getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA); + if (null != ai.metaData) { + String lib_name = ai.metaData.getString(META_DATA_LIB_NAME); + if (null != lib_name) { + System.loadLibrary(lib_name); + } else { + System.loadLibrary(DEFAULT_LIB_NAME); + } } + } catch (PackageManager.NameNotFoundException e) { + throw new RuntimeException("Error getting activity info", e); } - } catch (PackageManager.NameNotFoundException e) { - throw new RuntimeException("Error getting activity info", e); - } + + Cocos2dxHelper.sPackageName = applicationInfo.packageName; + Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); + //Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); + + Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity); + Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity); + Cocos2dxHelper.sAssetManager = activity.getAssets(); + + //Cocos2dxHelper.nativeSetAssetManager(sAssetManager); + Cocos2dxBitmap.setContext(activity); + sActivity = activity; - Cocos2dxHelper.sPackageName = applicationInfo.packageName; - Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); - //Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); - - Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity); - Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity); - Cocos2dxHelper.sAssetManager = activity.getAssets(); - - //Cocos2dxHelper.nativeSetAssetManager(sAssetManager); - Cocos2dxBitmap.setContext(activity); - sActivity = activity; + sInited = true; + } } public static void initListener() { 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/CCBatchCommand.cpp b/cocos/2d/renderer/CCBatchCommand.cpp new file mode 100644 index 0000000000..b9b0c7fab9 --- /dev/null +++ b/cocos/2d/renderer/CCBatchCommand.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + + +#include "renderer/CCBatchCommand.h" +#include "ccGLStateCache.h" +#include "CCTextureAtlas.h" + +NS_CC_BEGIN + +BatchCommand::BatchCommand() +: _textureID(0) +, _blendType(BlendFunc::DISABLE) +, _textureAtlas(nullptr) +{ + _type = RenderCommand::Type::BATCH_COMMAND; + _shader = nullptr; +} + +void BatchCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform) +{ + _globalOrder = globalOrder; + _textureID = textureID; + _blendType = blendType; + _shader = shader; + + _textureAtlas = textureAtlas; + + _mv = modelViewTransform; +} + +BatchCommand::~BatchCommand() +{ +} + +void BatchCommand::execute() +{ + // Set material + _shader->use(); + _shader->setUniformsForBuiltins(_mv); + GL::bindTexture2D(_textureID); + GL::blendFunc(_blendType.src, _blendType.dst); + + // Draw + _textureAtlas->drawQuads(); +} + +NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCBatchCommand.h b/cocos/2d/renderer/CCBatchCommand.h new file mode 100644 index 0000000000..9ac5b346ee --- /dev/null +++ b/cocos/2d/renderer/CCBatchCommand.h @@ -0,0 +1,68 @@ +/**************************************************************************** + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef _CC_BATCHCOMMAND_H_ +#define _CC_BATCHCOMMAND_H_ + +#include "CCRenderCommand.h" +#include "CCGLProgram.h" +#include "CCRenderCommandPool.h" +#include "kazmath/kazmath.h" + +NS_CC_BEGIN + +class TextureAtlas; + +#define CC_NO_TEXTURE 0 + +class BatchCommand : public RenderCommand +{ +public: + + BatchCommand(); + ~BatchCommand(); + + void init(float depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, TextureAtlas *textureAtlas, const kmMat4& modelViewTransform); + + void execute(); + +protected: + int32_t _materialID; + + //Maternal + GLuint _textureID; + + GLProgram* _shader; +// GLuint _shaderID; + + BlendFunc _blendType; + + TextureAtlas *_textureAtlas; + + // ModelView transform + kmMat4 _mv; +}; +NS_CC_END + +#endif //_CC_BATCHCOMMAND_H_ diff --git a/cocos/2d/renderer/CCCustomCommand.cpp b/cocos/2d/renderer/CCCustomCommand.cpp index 790bd13e69..c324032116 100644 --- a/cocos/2d/renderer/CCCustomCommand.cpp +++ b/cocos/2d/renderer/CCCustomCommand.cpp @@ -22,23 +22,19 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCCustomCommand.h" +#include "renderer/CCCustomCommand.h" NS_CC_BEGIN CustomCommand::CustomCommand() -:RenderCommand() -, func(nullptr) -, _viewport(0) -, _depth(0) +: func(nullptr) { _type = RenderCommand::Type::CUSTOM_COMMAND; } -void CustomCommand::init(int viewport, int32_t depth) +void CustomCommand::init(float globalOrder) { - _viewport = viewport; - _depth = depth; + _globalOrder = globalOrder; } CustomCommand::~CustomCommand() @@ -46,17 +42,6 @@ CustomCommand::~CustomCommand() } -int64_t CustomCommand::generateID() -{ - _id = 0; - - _id = (int64_t)_viewport << 61 - | (int64_t)1 << 60 // translucent - | (int64_t)_depth << 36; - - return _id; -} - void CustomCommand::execute() { if(func) diff --git a/cocos/2d/renderer/CCCustomCommand.h b/cocos/2d/renderer/CCCustomCommand.h index 7ff4c3e3ca..03fdead69a 100644 --- a/cocos/2d/renderer/CCCustomCommand.h +++ b/cocos/2d/renderer/CCCustomCommand.h @@ -39,14 +39,7 @@ public: public: - void init(int viewport, int32_t depth); - - // +----------+----------+-----+-----------------------------------+ - // | | | | | | - // | ViewPort | Transluc | | Depth | | - // | 3 bits | 1 bit | | 24 bits | | - // +----------+----------+-----+----------------+------------------+ - virtual int64_t generateID(); + void init(float depth); void execute(); @@ -54,8 +47,6 @@ public: std::function func; protected: - int _viewport; - int32_t _depth; }; NS_CC_END 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 8bd6f85888..95b9a5ccb5 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 @@ -86,18 +86,14 @@ void GroupCommandManager::releaseGroupID(int groupID) } GroupCommand::GroupCommand() -:RenderCommand() -, _viewport(0) -, _depth(0) { _type = RenderCommand::Type::GROUP_COMMAND; _renderQueueID = GroupCommandManager::getInstance()->getGroupID(); } -void GroupCommand::init(int viewport, int32_t depth) +void GroupCommand::init(float globalOrder) { - _viewport = viewport; - _depth = depth; + _globalOrder = globalOrder; GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID); _renderQueueID = GroupCommandManager::getInstance()->getGroupID(); } @@ -107,15 +103,4 @@ GroupCommand::~GroupCommand() GroupCommandManager::getInstance()->releaseGroupID(_renderQueueID); } -int64_t GroupCommand::generateID() -{ - _id = 0; - - _id = (int64_t)_viewport << 61 - | (int64_t)1 << 60 // translucent - | (int64_t)_depth << 36; - - return _id; -} - NS_CC_END diff --git a/cocos/2d/renderer/CCGroupCommand.h b/cocos/2d/renderer/CCGroupCommand.h index 7a6b6e511c..42c23d02b9 100644 --- a/cocos/2d/renderer/CCGroupCommand.h +++ b/cocos/2d/renderer/CCGroupCommand.h @@ -56,23 +56,11 @@ public: GroupCommand(); ~GroupCommand(); -public: + void init(float depth); - void init(int viewport, int32_t depth); - - // +----------+----------+-----+-----------------------------------+ - // | | | | | | - // | ViewPort | Transluc | | Depth | | - // | 3 bits | 1 bit | | 24 bits | | - // +----------+----------+-----+----------------+------------------+ - virtual int64_t generateID() override; - - inline bool isTranslucent() {return true;} - inline int getRenderQueueID() {return _renderQueueID;} + inline int getRenderQueueID() const {return _renderQueueID;} protected: - int _viewport; - int32_t _depth; int _renderQueueID; }; diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index b69fd075d3..9cae10d701 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -29,88 +29,36 @@ NS_CC_BEGIN QuadCommand::QuadCommand() -:RenderCommand() -,_viewport(0) -,_depth(0) -,_textureID(0) +:_textureID(0) ,_blendType(BlendFunc::DISABLE) -,_quadCount(0) -,_capacity(0) +,_quadsCount(0) { _type = RenderCommand::Type::QUAD_COMMAND; _shader = nullptr; - _quad = nullptr; + _quads = nullptr; } -void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv) +void QuadCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const kmMat4 &mv) { - _viewport = viewport; - _depth = depth; + _globalOrder = globalOrder; _textureID = textureID; _blendType = blendType; - _quadCount = quadCount; _shader = shader; - if(quadCount > _capacity ) { - //TODO find a better way to manage quads, current way will result in memory be wasted -// _quad = (V3F_C4B_T2F_Quad*)malloc(sizeof(V3F_C4B_T2F_Quad) * quadCount); - _quad = (V3F_C4B_T2F_Quad*) realloc(_quad, sizeof(*quad) * quadCount ); - _capacity = quadCount; - } + _quadsCount = quadCount; + _quads = quad; - _quadCount = quadCount; - memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount); + _mv = mv; - for(int i=0; ibl.vertices.x; - vec1.y = q->bl.vertices.y; - vec1.z = q->bl.vertices.z; - kmVec3Transform(&out1, &vec1, &mv); - q->bl.vertices.x = out1.x; - q->bl.vertices.y = out1.y; - q->bl.vertices.z = out1.z; - - kmVec3 vec2, out2; - vec2.x = q->br.vertices.x; - vec2.y = q->br.vertices.y; - vec2.z = q->br.vertices.z; - kmVec3Transform(&out2, &vec2, &mv); - q->br.vertices.x = out2.x; - q->br.vertices.y = out2.y; - q->br.vertices.z = out2.z; - - kmVec3 vec3, out3; - vec3.x = q->tr.vertices.x; - vec3.y = q->tr.vertices.y; - vec3.z = q->tr.vertices.z; - kmVec3Transform(&out3, &vec3, &mv); - q->tr.vertices.x = out3.x; - q->tr.vertices.y = out3.y; - q->tr.vertices.z = out3.z; - - kmVec3 vec4, out4; - vec4.x = q->tl.vertices.x; - vec4.y = q->tl.vertices.y; - vec4.z = q->tl.vertices.z; - kmVec3Transform(&out4, &vec4, &mv); - q->tl.vertices.x = out4.x; - q->tl.vertices.y = out4.y; - q->tl.vertices.z = out4.z; - } + generateMaterialID(); } QuadCommand::~QuadCommand() { - free(_quad); } -int64_t QuadCommand::generateID() +void QuadCommand::generateMaterialID() { - _id = 0; - //Generate Material ID //TODO fix shader ID generation CCASSERT(_shader->getProgram() < pow(2,10), "ShaderID is greater than 2^10"); @@ -148,19 +96,12 @@ int64_t QuadCommand::generateID() // | Shader ID (10 bits) | Blend ID (4 bits) | Texture ID (18 bits) | // +---------------------+-------------------+----------------------+ - _materialID = (int32_t)_shader->getProgram() << 22 - | (int32_t)blendID << 18 - | (int32_t)_textureID << 0; - - //Generate RenderCommandID - _id = (int64_t)_viewport << 61 - | (int64_t)1 << 60 //translucent - | (int64_t)_depth << 36; - - return _id; + _materialID = (uint32_t)_shader->getProgram() << 22 + | (uint32_t)blendID << 18 + | (uint32_t)_textureID << 0; } -void QuadCommand::useMaterial() +void QuadCommand::useMaterial() const { _shader->use(); diff --git a/cocos/2d/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index 411dc4913b..42411f48e9 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -41,41 +41,31 @@ public: QuadCommand(); ~QuadCommand(); - void init(int viewport, int32_t depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, + void init(float depth, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount, const kmMat4& mv); - // +----------+----------+-----+-----------------------------------+ - // | | | | | | - // | ViewPort | Transluc | | Depth | Material ID | - // | 3 bits | 1 bit | | 24 bits | 24 bit2 | - // +----------+----------+-----+----------------+------------------+ - virtual int64_t generateID(); - - void useMaterial(); + void useMaterial() const; //TODO use material to decide if it is translucent inline bool isTranslucent() const { return true; } - inline int32_t getMaterialID() const { return _materialID; } + void generateMaterialID(); + inline uint32_t getMaterialID() const { return _materialID; } inline GLuint getTextureID() const { return _textureID; } - inline V3F_C4B_T2F_Quad* getQuad() const { return _quad; } + inline V3F_C4B_T2F_Quad* getQuads() const { return _quads; } - inline ssize_t getQuadCount() const { return _quadCount; } + inline ssize_t getQuadCount() const { return _quadsCount; } inline GLProgram* getShader() const { return _shader; } inline BlendFunc getBlendType() const { return _blendType; } + + inline const kmMat4& getModelView() const { return _mv; } protected: - int32_t _materialID; - - //Key Data - int _viewport; /// Which view port it belongs to - - //TODO use material to determine if it's translucent - int32_t _depth; + uint32_t _materialID; //Maternal GLuint _textureID; @@ -85,9 +75,10 @@ protected: BlendFunc _blendType; - V3F_C4B_T2F_Quad* _quad; - ssize_t _quadCount; - ssize_t _capacity; + V3F_C4B_T2F_Quad* _quads; + ssize_t _quadsCount; + + kmMat4 _mv; }; NS_CC_END diff --git a/cocos/2d/renderer/CCRenderCommand.cpp b/cocos/2d/renderer/CCRenderCommand.cpp index 71fee4edb0..578f28d426 100644 --- a/cocos/2d/renderer/CCRenderCommand.cpp +++ b/cocos/2d/renderer/CCRenderCommand.cpp @@ -28,9 +28,9 @@ NS_CC_BEGIN RenderCommand::RenderCommand() +: _type(RenderCommand::Type::UNKNOWN_COMMAND) +, _globalOrder(0) { - _id = 0; - _type = RenderCommand::Type::UNKNOWN_COMMAND; } RenderCommand::~RenderCommand() @@ -57,9 +57,7 @@ void printBits(ssize_t const size, void const * const ptr) void RenderCommand::printID() { - printf("CommandID: "); - printBits(sizeof(_id), &_id); - printf("\n"); + printf("Command Depth: %f\n", _globalOrder); } NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 930ed1ecde..688f65feb7 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -33,25 +33,27 @@ NS_CC_BEGIN -//TODO make RenderCommand inherent from Object +/** Base class of the RenderCommand hierarchy. + The Renderer knows how to render RenderCommands. + */ class RenderCommand { public: enum class Type { + UNKNOWN_COMMAND, QUAD_COMMAND, CUSTOM_COMMAND, + BATCH_COMMAND, GROUP_COMMAND, - UNKNOWN_COMMAND, }; - virtual int64_t generateID() = 0; - /** Get Render Command Id */ - virtual inline int64_t getID() { return _id; } - - virtual inline Type getType() { return _type; } + inline float getGlobalOrder() const { return _globalOrder; } + + /** Returns the Command type */ + inline Type getType() const { return _type; } protected: RenderCommand(); @@ -59,9 +61,11 @@ protected: void printID(); - //Generated IDs - int64_t _id; /// used for sorting render commands + // Type used in order to avoid dynamic cast, faster Type _type; + + // commands are sort by depth + float _globalOrder; }; NS_CC_END diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 1d3b8cd2b4..6642ddfd6c 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -22,23 +22,80 @@ THE SOFTWARE. ****************************************************************************/ -#include "CCRenderer.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCQuadCommand.h" +#include "renderer/CCBatchCommand.h" +#include "renderer/CCCustomCommand.h" +#include "renderer/CCGroupCommand.h" #include "CCShaderCache.h" #include "ccGLStateCache.h" -#include "CCCustomCommand.h" -#include "renderer/CCQuadCommand.h" -#include "CCGroupCommand.h" #include "CCConfiguration.h" #include "CCDirector.h" #include "CCEventDispatcher.h" #include "CCEventListenerCustom.h" #include "CCEventType.h" -#include // for std::stable_sort +#include NS_CC_BEGIN -using namespace std; + +bool compareRenderCommand(RenderCommand* a, RenderCommand* b) +{ + return a->getGlobalOrder() < b->getGlobalOrder(); +} + +void RenderQueue::push_back(RenderCommand* command) +{ + float z = command->getGlobalOrder(); + if(z < 0) + _queueNegZ.push_back(command); + else if(z > 0) + _queuePosZ.push_back(command); + else + _queue0.push_back(command); +} + +ssize_t RenderQueue::size() const +{ + return _queueNegZ.size() + _queue0.size() + _queuePosZ.size(); +} + +void RenderQueue::sort() +{ + // Don't sort _queue0, it already comes sorted + std::sort(std::begin(_queueNegZ), std::end(_queueNegZ), compareRenderCommand); + std::sort(std::begin(_queuePosZ), std::end(_queuePosZ), compareRenderCommand); +} + +RenderCommand* RenderQueue::operator[](ssize_t index) const +{ + if(index < _queueNegZ.size()) + return _queueNegZ[index]; + + index -= _queueNegZ.size(); + + if(index < _queue0.size()) + return _queue0[index]; + + index -= _queue0.size(); + + if(index < _queuePosZ.size()) + return _queuePosZ[index]; + + CCASSERT(false, "invalid index"); + return nullptr; +} + +void RenderQueue::clear() +{ + _queueNegZ.clear(); + _queue0.clear(); + _queuePosZ.clear(); +} +// +// +// #define DEFAULT_RENDER_QUEUE 0 Renderer::Renderer() @@ -176,13 +233,14 @@ 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) { - command->generateID(); + CCASSERT(renderQueue >=0, "Invalid render queue"); + CCASSERT(command->getType() != RenderCommand::Type::UNKNOWN_COMMAND, "Invalid Command Type"); _renderGroups[renderQueue].push_back(command); } @@ -203,11 +261,6 @@ int Renderer::createRenderQueue() return (int)_renderGroups.size() - 1; } -bool compareRenderCommand(RenderCommand* a, RenderCommand* b) -{ - return a->getID() < b->getID(); -} - void Renderer::render() { //Uncomment this once everything is rendered by new renderer @@ -219,9 +272,9 @@ void Renderer::render() { //Process render commands //1. Sort render commands based on ID - for (auto it = _renderGroups.begin(); it != _renderGroups.end(); ++it) + for (auto &renderqueue : _renderGroups) { - std::stable_sort((*it).begin(), (*it).end(), compareRenderCommand); + renderqueue.sort(); } while(!_renderStack.empty()) @@ -242,31 +295,41 @@ void Renderer::render() if(commandType == RenderCommand::Type::QUAD_COMMAND) { - QuadCommand* cmd = static_cast(command); + auto cmd = static_cast(command); ssize_t cmdQuadCount = cmd->getQuadCount(); //Batch quads if(_numQuads + cmdQuadCount > VBO_SIZE) { - CCASSERT(cmdQuadCount < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command"); + CCASSERT(cmdQuadCount>=0 && cmdQuadCountgetQuad(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); + memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmdQuadCount); + convertToWorldCoordiantes(_quads + _numQuads, cmdQuadCount, cmd->getModelView()); + _numQuads += cmdQuadCount; } else if(commandType == RenderCommand::Type::CUSTOM_COMMAND) { flush(); - CustomCommand* cmd = static_cast(command); + auto cmd = static_cast(command); + cmd->execute(); + } + else if(commandType == RenderCommand::Type::BATCH_COMMAND) + { + flush(); + auto cmd = static_cast(command); cmd->execute(); } else if(commandType == RenderCommand::Type::GROUP_COMMAND) { flush(); - GroupCommand* cmd = static_cast(command); + auto cmd = static_cast(command); _renderStack.top().currentIndex = i + 1; @@ -279,6 +342,7 @@ void Renderer::render() } else { + CCASSERT(true, "Invalid command"); flush(); } } @@ -317,6 +381,29 @@ void Renderer::render() _lastMaterialID = 0; } +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; ibl.vertices; + kmVec3Transform(vec1, vec1, &modelView); + + kmVec3 *vec2 = (kmVec3*)&q->br.vertices; + kmVec3Transform(vec2, vec2, &modelView); + + kmVec3 *vec3 = (kmVec3*)&q->tr.vertices; + kmVec3Transform(vec3, vec3, &modelView); + + kmVec3 *vec4 = (kmVec3*)&q->tl.vertices; + kmVec3Transform(vec4, vec4, &modelView); + } +} + void Renderer::drawBatchedQuads() { //TODO we can improve the draw performance by insert material switching command before hand. @@ -336,6 +423,13 @@ void Renderer::drawBatchedQuads() //Set VBO data glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); + // option 1: subdata +// 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); + + // option 3: orphaning + glMapBuffer glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * (_numQuads), nullptr, GL_DYNAMIC_DRAW); void *buf = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); memcpy(buf, _quads, sizeof(_quads[0])* (_numQuads)); @@ -351,7 +445,7 @@ void Renderer::drawBatchedQuads() #define kQuadSize sizeof(_quads[0].bl) glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(_quads[0]) * _numQuads , _quads); + glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _numQuads , _quads, GL_DYNAMIC_DRAW); GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX); @@ -368,12 +462,12 @@ void Renderer::drawBatchedQuads() } //Start drawing verties in batch - for(size_t i = _firstCommand; i <= _lastCommand; i++) + for(ssize_t i = _firstCommand; i <= _lastCommand; i++) { - RenderCommand* command = _renderGroups[_renderStack.top().renderQueueID][i]; + auto command = _renderGroups[_renderStack.top().renderQueueID][i]; if (command->getType() == RenderCommand::Type::QUAD_COMMAND) { - QuadCommand* cmd = static_cast(command); + auto cmd = static_cast(command); if(_lastMaterialID != cmd->getMaterialID()) { //Draw quads @@ -414,7 +508,7 @@ void Renderer::drawBatchedQuads() } - _firstCommand = _lastCommand; + _firstCommand = _lastCommand + 1; _numQuads = 0; } @@ -424,4 +518,4 @@ void Renderer::flush() _lastMaterialID = 0; } -NS_CC_END \ No newline at end of file +NS_CC_END diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index e732547130..39511a04f0 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -37,12 +37,31 @@ NS_CC_BEGIN class EventListenerCustom; -typedef std::vector RenderQueue; +/** Class that knows how to sort the Commands. + Since the commands that have z==0 are "pushed back" in + the correct order, the only Commands that need to be sorted, + are the ones that have z <0 and z >0. + And that is what this class does. +*/ +class RenderQueue { + +public: + void push_back(RenderCommand* command); + ssize_t size() const; + void sort(); + RenderCommand* operator[](ssize_t index) const; + void clear(); + +protected: + std::vector _queueNegZ; + std::vector _queue0; + std::vector _queuePosZ; +}; struct RenderStackElement { int renderQueueID; - size_t currentIndex; + ssize_t currentIndex; }; class Renderer @@ -75,18 +94,21 @@ protected: void mapBuffers(); void drawBatchedQuads(); + //Draw the previews queued quads and flush previous context void flush(); + void convertToWorldCoordiantes(V3F_C4B_T2F_Quad* quads, ssize_t quantity, const kmMat4& modelView); + std::stack _commandGroupStack; std::stack _renderStack; std::vector _renderGroups; - int _lastMaterialID; + uint32_t _lastMaterialID; - size_t _firstCommand; - size_t _lastCommand; + ssize_t _firstCommand; + ssize_t _lastCommand; V3F_C4B_T2F_Quad _quads[VBO_SIZE]; GLushort _indices[6 * VBO_SIZE]; diff --git a/cocos/base/CCConsole.cpp b/cocos/base/CCConsole.cpp index 69c44c4494..eea6c483c8 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -50,6 +50,9 @@ #include "CCScheduler.h" #include "CCScene.h" #include "CCPlatformConfig.h" +#include "platform/CCFileUtils.h" +#include "CCConfiguration.h" +#include "CCTextureCache.h" NS_CC_BEGIN @@ -61,7 +64,7 @@ NS_CC_BEGIN static ssize_t mydprintf(int sock, const char *format, ...) { va_list args; - char buf[1024]; + char buf[16386]; va_start(args, format); vsnprintf(buf, sizeof(buf), format, args); @@ -92,6 +95,33 @@ static void printSceneGraphBoot(int fd) mydprintf(fd, "Total Nodes: %d\n", total); } +static void printFileUtils(int fd) +{ + FileUtils* fu = FileUtils::getInstance(); + + mydprintf(fd, "\nSearch Paths:\n"); + auto list = fu->getSearchPaths(); + for( const auto &item : list) { + mydprintf(fd, "%s\n", item.c_str()); + } + + mydprintf(fd, "\nResolution Order:\n"); + list = fu->getSearchResolutionsOrder(); + for( const auto &item : list) { + mydprintf(fd, "%s\n", item.c_str()); + } + + mydprintf(fd, "\nWriteble Path:\n"); + mydprintf(fd, "%s\n", fu->getWritablePath().c_str()); + + mydprintf(fd, "\nFull Path Cache:\n"); + auto cache = fu->getFullPathCache(); + for( const auto &item : cache) { + mydprintf(fd, "%s -> %s\n", item.first.c_str(), item.second.c_str()); + } +} + + #if defined(__MINGW32__) static const char* inet_ntop(int af, const void* src, char* dst, int cnt) { @@ -114,24 +144,7 @@ static const char* inet_ntop(int af, const void* src, char* dst, int cnt) // Free functions to log // -// XXX: Deprecated -void CCLog(const char * format, ...) -{ - va_list args; - va_start(args, format); - log(format, args); - va_end(args); -} - -void log(const char * format, ...) -{ - va_list args; - va_start(args, format); - log(format, args); - va_end(args); -} - -void log(const char *format, va_list args) +static void _log(const char *format, va_list args) { char buf[MAX_LOG_LENGTH]; @@ -146,7 +159,7 @@ void log(const char *format, va_list args) MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf)); OutputDebugStringW(wszBuf); OutputDebugStringA("\n"); - + WideCharToMultiByte(CP_ACP, 0, wszBuf, sizeof(wszBuf), buf, sizeof(buf), NULL, FALSE); printf("%s\n", buf); @@ -159,6 +172,22 @@ void log(const char *format, va_list args) Director::getInstance()->getConsole()->log(buf); } +// XXX: Deprecated +void CCLog(const char * format, ...) +{ + va_list args; + va_start(args, format); + _log(format, args); + va_end(args); +} + +void log(const char * format, ...) +{ + va_list args; + va_start(args, format); + _log(format, args); + va_end(args); +} // // Console code @@ -174,6 +203,7 @@ Console::Console() { // VS2012 doesn't support initializer list, so we create a new array and assign its elements to '_command'. Command commands[] = { + { "config", std::bind(&Console::commandConfig, this, std::placeholders::_1, std::placeholders::_2) }, { "debug msg on", [&](int fd, const char* command) { _sendDebugStrings = true; } }, @@ -181,6 +211,7 @@ Console::Console() _sendDebugStrings = false; } }, { "exit", std::bind(&Console::commandExit, this, std::placeholders::_1, std::placeholders::_2) }, + { "fileutils dump", std::bind(&Console::commandFileUtilsDump, this, std::placeholders::_1, std::placeholders::_2) }, { "fps on", [](int fd, const char* command) { Director *dir = Director::getInstance(); Scheduler *sched = dir->getScheduler(); @@ -193,6 +224,7 @@ Console::Console() } }, { "help", std::bind(&Console::commandHelp, this, std::placeholders::_1, std::placeholders::_2) }, { "scene graph", std::bind(&Console::commandSceneGraph, this, std::placeholders::_1, std::placeholders::_2) }, + { "textures", std::bind(&Console::commandTextures, this, std::placeholders::_1, std::placeholders::_2) }, }; _maxCommands = sizeof(commands)/sizeof(commands[0]); @@ -340,6 +372,31 @@ void Console::commandSceneGraph(int fd, const char *command) sched->performFunctionInCocosThread( std::bind(&printSceneGraphBoot, fd) ); } +void Console::commandFileUtilsDump(int fd, const char *command) +{ + Scheduler *sched = Director::getInstance()->getScheduler(); + sched->performFunctionInCocosThread( std::bind(&printFileUtils, fd) ); +} + +void Console::commandConfig(int fd, const char *command) +{ + Scheduler *sched = Director::getInstance()->getScheduler(); + sched->performFunctionInCocosThread( [&](){ + mydprintf(fd, "%s", Configuration::getInstance()->getInfo().c_str()); + } + ); +} + +void Console::commandTextures(int fd, const char *command) +{ + Scheduler *sched = Director::getInstance()->getScheduler(); + sched->performFunctionInCocosThread( [&](){ + mydprintf(fd, "%s", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); + } + ); +} + + bool Console::parseCommand(int fd) { auto r = readline(fd); diff --git a/cocos/base/CCConsole.h b/cocos/base/CCConsole.h index eb27bcfb34..7a06d3423f 100644 --- a/cocos/base/CCConsole.h +++ b/cocos/base/CCConsole.h @@ -58,7 +58,6 @@ static const int MAX_LOG_LENGTH = 16*1024; @brief Output Debug message. */ void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2); -void CC_DLL log(const char * format, va_list args); /** Console is helper class that lets the developer control the game from TCP connection. Console will spawn a new thread that will listen to a specified TCP port. @@ -109,6 +108,9 @@ protected: void commandHelp(int fd, const char *command); void commandExit(int fd, const char *command); void commandSceneGraph(int fd, const char *command); + void commandFileUtilsDump(int fd, const char *command); + void commandConfig(int fd, const char *command); + void commandTextures(int fd, const char *command); // file descriptor: socket, console, etc. int _listenfd; diff --git a/cocos/base/CCMap.h b/cocos/base/CCMap.h index 450b39bc2e..9f7b6b17f6 100644 --- a/cocos/base/CCMap.h +++ b/cocos/base/CCMap.h @@ -25,10 +25,17 @@ #ifndef __CCMAP_H__ #define __CCMAP_H__ +#define USE_STD_UNORDERED_MAP 1 + #include "ccMacros.h" #include "CCObject.h" #include + +#if USE_STD_UNORDERED_MAP #include +#else +#include +#endif NS_CC_BEGIN @@ -44,7 +51,11 @@ public: // ------------------------------------------ // Iterators // ------------------------------------------ +#if USE_STD_UNORDERED_MAP typedef std::unordered_map RefMap; +#else + typedef std::map RefMap; +#endif typedef typename RefMap::iterator iterator; typedef typename RefMap::const_iterator const_iterator; @@ -104,25 +115,39 @@ public: /** Sets capacity of the map */ void reserve(ssize_t capacity) { +#if USE_STD_UNORDERED_MAP _data.reserve(capacity); +#endif } /** Returns the number of buckets in the Map container. */ ssize_t bucketCount() const { +#if USE_STD_UNORDERED_MAP return _data.bucket_count(); +#else + return 0; +#endif } /** Returns the number of elements in bucket n. */ ssize_t bucketSize(ssize_t n) const { +#if USE_STD_UNORDERED_MAP return _data.bucket_size(n); +#else + return 0; +#endif } /** Returns the bucket number where the element with key k is located. */ ssize_t bucket(const K& k) const { +#if USE_STD_UNORDERED_MAP return _data.bucket(k); +#else + return 0; +#endif } /** The number of elements in the map. */ @@ -144,9 +169,11 @@ public: std::vector keys() const { std::vector keys; - + if (!_data.empty()) { + keys.reserve(_data.size()); + for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter) { keys.push_back(iter->first); @@ -160,14 +187,21 @@ public: { std::vector keys; - for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter) + if (!_data.empty()) { - if (iter->second == object) + keys.reserve(_data.size() / 10); + + for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter) { - keys.push_back(iter->first); + if (iter->second == object) + { + keys.push_back(iter->first); + } } } + keys.shrink_to_fit(); + return keys; } diff --git a/cocos/editor-support/cocosbuilder/CCBAnimationManager.h b/cocos/editor-support/cocosbuilder/CCBAnimationManager.h index 14328af61d..f1f351a631 100644 --- a/cocos/editor-support/cocosbuilder/CCBAnimationManager.h +++ b/cocos/editor-support/cocosbuilder/CCBAnimationManager.h @@ -1,7 +1,11 @@ #ifndef __CCB_CCBANIMATION_MANAGER_H__ #define __CCB_CCBANIMATION_MANAGER_H__ -#include "cocos2d.h" +#include "CCMap.h" +#include "CCActionInterval.h" +#include "CCActionInstant.h" +#include "CCActionEase.h" + #include "extensions/ExtensionMacros.h" #include "CCBSequence.h" #include "CCBSequenceProperty.h" diff --git a/cocos/editor-support/cocosbuilder/CCBKeyframe.h b/cocos/editor-support/cocosbuilder/CCBKeyframe.h index 49779319cc..e3c009e2df 100644 --- a/cocos/editor-support/cocosbuilder/CCBKeyframe.h +++ b/cocos/editor-support/cocosbuilder/CCBKeyframe.h @@ -1,7 +1,9 @@ #ifndef __CCB_KEYFRAME_H__ #define __CCB_KEYFRAME_H__ -#include "cocos2d.h" +#include "CCObject.h" +#include "CCValue.h" + namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCBMemberVariableAssigner.h b/cocos/editor-support/cocosbuilder/CCBMemberVariableAssigner.h index 7c429ed505..4cafab98d6 100644 --- a/cocos/editor-support/cocosbuilder/CCBMemberVariableAssigner.h +++ b/cocos/editor-support/cocosbuilder/CCBMemberVariableAssigner.h @@ -1,7 +1,6 @@ #ifndef _CCB_CCBMEMBERVARIABLEASSIGNER_H_ #define _CCB_CCBMEMBERVARIABLEASSIGNER_H_ -#include "cocos2d.h" namespace cocosbuilder { diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index f190b72def..056f2553d0 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -1,7 +1,13 @@ -#include "CCBReader.h" - +#include #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..752e4911a9 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; @@ -153,7 +156,7 @@ void BatchNode::draw() void BatchNode::generateGroupCommand() { Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand->init(0,_vertexZ); + _groupCommand->init(_globalZOrder); renderer->addCommand(_groupCommand); renderer->pushGroup(_groupCommand->getRenderQueueID()); 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/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 4bd7883a43..dbaa142020 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -145,7 +145,7 @@ void Bone::setBoneData(BoneData *boneData) } _name = _boneData->name; - _ZOrder = _boneData->zOrder; + _localZOrder = _boneData->zOrder; _displayManager->initDisplayList(boneData); } @@ -283,11 +283,11 @@ void Bone::updateZOrder() if (_dataVersion >= VERSION_COMBINED) { int zorder = _tweenData->zOrder + _boneData->zOrder; - setZOrder(zorder); + setLocalZOrder(zorder); } else { - setZOrder(_tweenData->zOrder); + setLocalZOrder(_tweenData->zOrder); } } @@ -374,10 +374,10 @@ Tween *Bone::getTween() return _tween; } -void Bone::setZOrder(int zOrder) +void Bone::setLocalZOrder(int zOrder) { - if (_ZOrder != zOrder) - Node::setZOrder(zOrder); + if (_localZOrder != zOrder) + Node::setLocalZOrder(zOrder); } kmMat4 Bone::getNodeToArmatureTransform() const diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index db153a1da5..c81583a8c9 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -143,7 +143,7 @@ public: //! Update zorder void updateZOrder(); - virtual void setZOrder(int zOrder) override; + virtual void setLocalZOrder(int zOrder) override; Tween *getTween(); 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 20f826cb2b..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 { @@ -115,7 +117,7 @@ void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty) anchorPoint = PointApplyTransform(anchorPoint, displayTransform); displayTransform.mat[12] = anchorPoint.x; displayTransform.mat[13] = anchorPoint.y; - kmMat4 t = TransformConcat(displayTransform, bone->getArmature()->getNodeToParentTransform()); + kmMat4 t = TransformConcat( bone->getArmature()->getNodeToParentTransform(),displayTransform); detector->updateTransform(t); } while (0); 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/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 349bba5dfe..a8bd016948 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -331,7 +331,7 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget*widg widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); } int z = DICTOOL->getIntValue_json(options, "ZOrder"); - widget->setZOrder(z); + widget->setLocalZOrder(z); } void WidgetPropertiesReader0250::setColorPropsForWidgetFromJsonDictionary(Widget *widget, const rapidjson::Value&options) @@ -1062,7 +1062,7 @@ void WidgetPropertiesReader0300::setPropsForWidgetFromJsonDictionary(Widget*widg widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); } int z = DICTOOL->getIntValue_json(options, "ZOrder"); - widget->setZOrder(z); + widget->setLocalZOrder(z); bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter"); if (layout) diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 12b18604ff..e33c4ad86a 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -203,7 +203,7 @@ void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d: node->setTag(nTag); int nZorder = DICTOOL->getIntValue_json(root, "zorder"); - node->setZOrder(nZorder); + node->setLocalZOrder(nZorder); float fScaleX = DICTOOL->getFloatValue_json(root, "scalex", 1.0); float fScaleY = DICTOOL->getFloatValue_json(root, "scaley", 1.0); 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 94ba291e2b..440ce92159 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 { @@ -197,7 +203,7 @@ void Skin::updateTransform() kmMat4 Skin::getNodeToWorldTransform() const { - return TransformConcat(_transform, _bone->getArmature()->getNodeToWorldTransform()); + return TransformConcat( _bone->getArmature()->getNodeToWorldTransform(), _transform); } kmMat4 Skin::getNodeToWorldTransformAR() const @@ -219,7 +225,7 @@ void Skin::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &mv); //TODO implement z order - _quadCommand.init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); + _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } 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.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index 9051679a98..82c0ed50cd 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -131,7 +131,7 @@ void Skeleton::draw() kmGLMatrixMode(KM_GL_MODELVIEW); kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Skeleton::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } 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..8a64ad7ed4 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 @@ -210,18 +210,18 @@ void Layout::stencilClippingVisit() Renderer* renderer = Director::getInstance()->getRenderer(); - _groupCommand.init(0,_vertexZ); + _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); - _beforeVisitCmdStencil.init(0,_vertexZ); + _beforeVisitCmdStencil.init(_globalZOrder); _beforeVisitCmdStencil.func = CC_CALLBACK_0(Layout::onBeforeVisitStencil, this); renderer->addCommand(&_beforeVisitCmdStencil); _clippingStencil->visit(); - _afterDrawStencilCmd.init(0,_vertexZ); + _afterDrawStencilCmd.init(_globalZOrder); _afterDrawStencilCmd.func = CC_CALLBACK_0(Layout::onAfterDrawStencil, this); renderer->addCommand(&_afterDrawStencilCmd); @@ -251,7 +251,7 @@ void Layout::stencilClippingVisit() this->draw(); } - _afterVisitCmdStencil.init(0,_vertexZ); + _afterVisitCmdStencil.init(_globalZOrder); _afterVisitCmdStencil.func = CC_CALLBACK_0(Layout::onAfterVisitStencil, this); renderer->addCommand(&_afterVisitCmdStencil); @@ -336,13 +336,13 @@ void Layout::scissorClippingVisit() { Renderer* renderer = Director::getInstance()->getRenderer(); - _beforeVisitCmdScissor.init(0, _vertexZ); + _beforeVisitCmdScissor.init(_globalZOrder); _beforeVisitCmdScissor.func = CC_CALLBACK_0(Layout::onBeforeVisitScissor, this); renderer->addCommand(&_beforeVisitCmdScissor); Node::visit(); - _afterVisitCmdScissor.init(0, _vertexZ); + _afterVisitCmdScissor.init(_globalZOrder); _afterVisitCmdScissor.func = CC_CALLBACK_0(Layout::onAfterVisitScissor, this); renderer->addCommand(&_afterVisitCmdScissor); } @@ -651,14 +651,14 @@ void Layout::addBackGroundImage() if (_backGroundScale9Enabled) { _backGroundImage = extension::Scale9Sprite::create(); - _backGroundImage->setZOrder(-1); + _backGroundImage->setLocalZOrder(-1); Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); static_cast(_backGroundImage)->setPreferredSize(_size); } else { _backGroundImage = Sprite::create(); - _backGroundImage->setZOrder(-1); + _backGroundImage->setLocalZOrder(-1); Node::addChild(_backGroundImage, BACKGROUNDIMAGE_Z, -1); } _backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f)); diff --git a/cocos/gui/UILayout.h b/cocos/gui/UILayout.h index fffb6aaad1..327707d7c8 100644 --- a/cocos/gui/UILayout.h +++ b/cocos/gui/UILayout.h @@ -195,7 +195,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) */ virtual void addChild(Node * child, int zOrder) override; /** @@ -204,7 +204,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ virtual void addChild(Node* child, int zOrder, int tag) override; diff --git a/cocos/gui/UIListView.cpp b/cocos/gui/UIListView.cpp index ba6a567aef..8c732f6e70 100644 --- a/cocos/gui/UIListView.cpp +++ b/cocos/gui/UIListView.cpp @@ -378,7 +378,7 @@ void ListView::refreshView() for (int i=0; isetZOrder(i); + item->setLocalZOrder(i); remedyLayoutParameter(item); } updateInnerContainerSize(); diff --git a/cocos/gui/UIScrollView.h b/cocos/gui/UIScrollView.h index ae49fa02ea..0b196cef55 100644 --- a/cocos/gui/UIScrollView.h +++ b/cocos/gui/UIScrollView.h @@ -242,7 +242,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) */ virtual void addChild(Node * child, int zOrder) override; /** @@ -251,7 +251,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ virtual void addChild(Node* child, int zOrder, int tag) override; diff --git a/cocos/gui/UIWidget.cpp b/cocos/gui/UIWidget.cpp index e28f4d8db0..d09a8fde39 100644 --- a/cocos/gui/UIWidget.cpp +++ b/cocos/gui/UIWidget.cpp @@ -1040,7 +1040,7 @@ void Widget::copyProperties(Widget *widget) setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); _touchPassedEnabled = false; - setZOrder(widget->getZOrder()); + setLocalZOrder(widget->getLocalZOrder()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); diff --git a/cocos/gui/UIWidget.h b/cocos/gui/UIWidget.h index d07bc4bee8..3827c60db2 100644 --- a/cocos/gui/UIWidget.h +++ b/cocos/gui/UIWidget.h @@ -212,7 +212,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) */ virtual void addChild(Node * child, int zOrder) override; /** @@ -221,7 +221,7 @@ public: * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node - * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) + * @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ virtual void addChild(Node* child, int zOrder, int tag) override; 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/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index a33c70d7bd..e540327313 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -16af4ad046f4db00af7a229d89c406054d8616c3 \ No newline at end of file +f92acd30f26c52238e94d2ef1f5b11e760980a67 \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/CCBProxy.cpp b/cocos/scripting/lua/bindings/CCBProxy.cpp index cab487b1d8..f0ba9f92f8 100644 --- a/cocos/scripting/lua/bindings/CCBProxy.cpp +++ b/cocos/scripting/lua/bindings/CCBProxy.cpp @@ -58,75 +58,75 @@ const char* CCBProxy::getNodeTypeName(Node* pNode) } if (NULL != dynamic_cast(pNode)) { - return "LabelTTF"; + return "cc.LabelTTF"; } if (NULL != dynamic_cast(pNode)) { - return "LabelBMFont"; + return "cc.LabelBMFont"; } if (NULL != dynamic_cast(pNode)) { - return "Sprite"; + return "cc.Sprite"; } if (NULL != dynamic_cast(pNode)) { - return "ControlButton"; + return "cc.ControlButton"; } if (NULL != dynamic_cast(pNode)) { - return "LayerGradient"; + return "cc.LayerGradient"; } if (NULL != dynamic_cast(pNode)) { - return "LayerColor"; + return "cc.LayerColor"; } if (NULL != dynamic_cast(pNode)) { - return "LayerGradient"; + return "cc.LayerGradient"; } if (NULL != dynamic_cast(pNode)) { - return "Menu"; + return "cc.Menu"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItemAtlasFont"; + return "cc.MenuItemAtlasFont"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItemFont"; + return "cc.MenuItemFont"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItemLabel"; + return "cc.MenuItemLabel"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItemImage"; + return "cc.MenuItemImage"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItemToggle"; + return "cc.MenuItemToggle"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItemSprite"; + return "cc.MenuItemSprite"; } if (NULL != dynamic_cast(pNode)) { - return "MenuItem"; + return "cc.MenuItem"; } if (NULL != dynamic_cast(pNode)) { - return "Layer"; + return "cc.Layer"; } if (NULL != dynamic_cast(pNode)) { - return "String"; + return "cc.String"; } if (NULL != dynamic_cast(pNode)) { - return "ParticleSystemQuad"; + return "cc.ParticleSystemQuad"; } return "No Support"; diff --git a/cocos/scripting/lua/bindings/CCLuaEngine.cpp b/cocos/scripting/lua/bindings/CCLuaEngine.cpp index a05fa8f54d..502909695d 100644 --- a/cocos/scripting/lua/bindings/CCLuaEngine.cpp +++ b/cocos/scripting/lua/bindings/CCLuaEngine.cpp @@ -167,7 +167,7 @@ int LuaEngine::executeEvent(int nHandler, const char* pEventName, Object* pEvent _stack->pushString(pEventName); if (pEventSource) { - _stack->pushObject(pEventSource, pEventSourceClassName ? pEventSourceClassName : "CCObject"); + _stack->pushObject(pEventSource, pEventSourceClassName ? pEventSourceClassName : "cc.Object"); } int ret = _stack->executeFunctionByHandler(nHandler, pEventSource ? 2 : 1); _stack->clean(); @@ -329,7 +329,7 @@ int LuaEngine::handleMenuClickedEvent(void* data) return 0; _stack->pushInt(menuItem->getTag()); - _stack->pushObject(menuItem, "MenuItem"); + _stack->pushObject(menuItem, "cc.MenuItem"); int ret = _stack->executeFunctionByHandler(handler, 2); _stack->clean(); return ret; @@ -352,7 +352,7 @@ int LuaEngine::handleCallFuncActionEvent(void* data) Object* target = static_cast(basicScriptData->value); if (NULL != target) { - _stack->pushObject(target, "Node"); + _stack->pushObject(target, "cc.Node"); } int ret = _stack->executeFunctionByHandler(handler, target ? 1 : 0); _stack->clean(); @@ -447,7 +447,7 @@ int LuaEngine::handleCommonEvent(void* data) } else { - _stack->pushObject(commonInfo->eventSource, "Object"); + _stack->pushObject(commonInfo->eventSource, "cc.Object"); } } int ret = _stack->executeFunctionByHandler(commonInfo->handler, commonInfo->eventSource ? 2 : 1); @@ -585,7 +585,7 @@ int LuaEngine::handlerControlEvent(void* data) if (0 != handler) { - _stack->pushObject((Object*)basicScriptData->nativeObject, "Object"); + _stack->pushObject((Object*)basicScriptData->nativeObject, "cc.Object"); _stack->pushInt(controlEvents); ret = _stack->executeFunctionByHandler(handler, 2); _stack->clean(); @@ -612,7 +612,7 @@ int LuaEngine::handleEventAcc(void* data) lua_State* L = _stack->getLuaState(); LuaEventAccelerationData* eventListennerAcc = static_cast(basicScriptData->value); - toluafix_pushusertype_ccobject(L, eventListennerAcc->event->_ID, &(eventListennerAcc->event->_luaID), (void*)(eventListennerAcc->event),"Event"); + toluafix_pushusertype_ccobject(L, eventListennerAcc->event->_ID, &(eventListennerAcc->event->_luaID), (void*)(eventListennerAcc->event),"cc.Event"); Acceleration* accleration = static_cast(eventListennerAcc->acc); lua_pushnumber(L,accleration->x); lua_pushnumber(L,accleration->y); @@ -640,7 +640,7 @@ int LuaEngine::handleEventKeyboard(ScriptHandlerMgr::HandlerType type, void* dat lua_State* L = _stack->getLuaState(); lua_pushinteger(L, keyboardData->keyCode); - toluafix_pushusertype_ccobject(L, keyboardData->event->_ID, &(keyboardData->event->_luaID), (void*)(keyboardData->event),"Event"); + toluafix_pushusertype_ccobject(L, keyboardData->event->_ID, &(keyboardData->event->_luaID), (void*)(keyboardData->event),"cc.Event"); int ret = _stack->executeFunctionByHandler(handler, 2); _stack->clean(); return ret; @@ -667,8 +667,8 @@ int LuaEngine::handleEventTouch(ScriptHandlerMgr::HandlerType type, void* data) Touch* touch = touchData->touch; if (NULL != touch) { - _stack->pushObject(touchData->touch, "Touch"); - _stack->pushObject(touchData->event, "Event"); + _stack->pushObject(touchData->touch, "cc.Touch"); + _stack->pushObject(touchData->event, "cc.Event"); ret = _stack->executeFunctionByHandler(handler, 2); } _stack->clean(); @@ -702,11 +702,11 @@ int LuaEngine::handleEventTouches(ScriptHandlerMgr::HandlerType type,void* data) for (auto& touch : touchesData->touches) { _stack->pushInt(i); - _stack->pushObject(touch, "Touch"); + _stack->pushObject(touch, "cc.Touch"); lua_rawset(L, -3); ++i; } - _stack->pushObject(touchesData->event, "Event"); + _stack->pushObject(touchesData->event, "cc.Event"); ret = _stack->executeFunctionByHandler(handler, 2); _stack->clean(); @@ -731,7 +731,7 @@ int LuaEngine::handleEventMouse(ScriptHandlerMgr::HandlerType type, void* data) if (0 == handler) return 0; - _stack->pushObject(mouseData->event, "Event"); + _stack->pushObject(mouseData->event, "cc.Event"); int ret = _stack->executeFunctionByHandler(handler, 1); _stack->clean(); @@ -754,7 +754,7 @@ int LuaEngine::handleEvenCustom(void* data) return 0; lua_State* L = _stack->getLuaState(); - toluafix_pushusertype_ccobject(L, eventCustom->_ID, &(eventCustom->_luaID), (void*)(eventCustom),"EventCustom"); + toluafix_pushusertype_ccobject(L, eventCustom->_ID, &(eventCustom->_luaID), (void*)(eventCustom),"cc.EventCustom"); int ret = _stack->executeFunctionByHandler(handler, 1); _stack->clean(); @@ -859,14 +859,102 @@ int LuaEngine::handleEvent(ScriptHandlerMgr::HandlerType type, void* data, int n int LuaEngine::handleTableViewEvent(ScriptHandlerMgr::HandlerType type,void* data) { - CCASSERT(0, "TableView is not bound yet"); - return 0; + if (nullptr == data) + return 0; + + BasicScriptData* eventData = static_cast(data); + if (nullptr == eventData->nativeObject || nullptr == eventData->value) + return 0; + + LuaTableViewEventData* tableViewData = static_cast(eventData->value); + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, type); + + if (0 == handler) + return 0; + + Object* obj = static_cast(eventData->nativeObject); + if (nullptr == obj) + return 0; + + int ret = 0; + switch (type) + { + case ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL: + case ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM: + { + toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); + ret = _stack->executeFunctionByHandler(handler, 1); + } + break; + case ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED: + case ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT: + case ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT: + case ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE: + { + Object* cellObject = static_cast(tableViewData->value); + if (nullptr == cellObject) { + break; + } + toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); + toluafix_pushusertype_ccobject(_stack->getLuaState(), cellObject->_ID, &(cellObject->_luaID), (void*)(cellObject),"cc.TableViewCell"); + ret = _stack->executeFunctionByHandler(handler, 2); + } + break; + default: + break; + } + + return ret; + } int LuaEngine::handleTableViewEvent(ScriptHandlerMgr::HandlerType handlerType,void* data, int numResults, const std::function& func) { - CCASSERT(0, "TableView is not bound yet"); - return 0; + if (nullptr == data || numResults <= 0) + return 0; + + BasicScriptData* eventData = static_cast(data); + if (nullptr == eventData->nativeObject || nullptr == eventData->value) + return 0; + + LuaTableViewEventData* tableViewData = static_cast(eventData->value); + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, handlerType); + + if (0 == handler) + return 0; + + Object* obj = static_cast(eventData->nativeObject); + if (nullptr == obj) + return 0; + + int ret = 0; + switch (handlerType) + { + case ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX: + { + toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); + _stack->pushLong(*((ssize_t*)tableViewData->value)); + ret = _stack->executeFunction(handler, 2, 2, func); + } + break; + case ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX: + { + toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); + _stack->pushLong(*((ssize_t*)tableViewData->value)); + ret = _stack->executeFunction(handler, 2, 1, func); + } + break; + case ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS: + { + toluafix_pushusertype_ccobject(_stack->getLuaState(), obj->_ID, &(obj->_luaID), (void*)(obj),"cc.TableView"); + ret = _stack->executeFunction(handler, 1, 1, func); + } + break; + default: + break; + } + + return ret; } int LuaEngine::handleAssetsManagerEvent(ScriptHandlerMgr::HandlerType type,void* data) @@ -925,7 +1013,7 @@ int LuaEngine::handleStudioEventListener(ScriptHandlerMgr::HandlerType type,void if (0 == handler) return 0; - _stack->pushObject(listenerData->objTarget, "Object"); + _stack->pushObject(listenerData->objTarget, "cc.Object"); _stack->pushInt(listenerData->eventType); _stack->executeFunctionByHandler(handler, 2); @@ -956,7 +1044,7 @@ int LuaEngine::handleArmatureWrapper(ScriptHandlerMgr::HandlerType type,void* da { LuaArmatureMovementEventData* movementData = static_cast(wrapperData->eventData); - _stack->pushObject(movementData->objTarget, "Armature"); + _stack->pushObject(movementData->objTarget, "ccs.Armature"); _stack->pushInt(movementData->movementType); _stack->pushString(movementData->movementID.c_str()); _stack->executeFunctionByHandler(handler, 3); @@ -966,7 +1054,7 @@ int LuaEngine::handleArmatureWrapper(ScriptHandlerMgr::HandlerType type,void* da { LuaArmatureFrameEventData* frameData = static_cast(wrapperData->eventData); - _stack->pushObject(frameData->objTarget, "Bone"); + _stack->pushObject(frameData->objTarget, "ccs.Bone"); _stack->pushString(frameData->frameEventName.c_str()); _stack->pushInt(frameData->originFrameIndex); _stack->pushInt(frameData->currentFrameIndex); diff --git a/cocos/scripting/lua/bindings/CCLuaStack.cpp b/cocos/scripting/lua/bindings/CCLuaStack.cpp index 7215e6afac..9661fb1cd8 100644 --- a/cocos/scripting/lua/bindings/CCLuaStack.cpp +++ b/cocos/scripting/lua/bindings/CCLuaStack.cpp @@ -151,7 +151,6 @@ bool LuaStack::init(void) register_all_cocos2dx_extension(_state); register_all_cocos2dx_deprecated(_state); register_cocos2dx_extension_CCBProxy(_state); - register_cocos2dx_event_releated(_state); tolua_opengl_open(_state); register_all_cocos2dx_gui(_state); register_all_cocos2dx_studio(_state); diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp index c04df69ce3..ed8178972e 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp @@ -33,6 +33,7 @@ extern "C" { #endif std::unordered_map g_luaType; +std::unordered_map g_typeCast; #if COCOS2D_DEBUG >=1 void luaval_to_native_err(lua_State* L,const char* msg,tolua_Error* err) diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.h b/cocos/scripting/lua/bindings/LuaBasicConversions.h index 20e4f79d73..9dcc2fc6e2 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.h +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.h @@ -35,6 +35,7 @@ extern "C" { using namespace cocos2d; extern std::unordered_map g_luaType; +extern std::unordered_map g_typeCast; #if COCOS2D_DEBUG >=1 void luaval_to_native_err(lua_State* L,const char* msg,tolua_Error* err); diff --git a/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id index 42910a1d92..caaa6e32e0 100644 --- a/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id +++ b/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -bcec27eb626dbcf63b810cce7f0f48b2d02c2158 \ No newline at end of file +bc70bac577759c95fbcf25da6937dbd9109da8d5 \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/LuaOpengl.h b/cocos/scripting/lua/bindings/LuaOpengl.h index d4691677ae..9e04ea1322 100644 --- a/cocos/scripting/lua/bindings/LuaOpengl.h +++ b/cocos/scripting/lua/bindings/LuaOpengl.h @@ -36,7 +36,7 @@ extern "C" { class GLNode:public cocos2d::Node { - virtual void draw(); + virtual void draw() override; }; TOLUA_API int tolua_opengl_open(lua_State* tolua_S); diff --git a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp index 81317d65d7..c781d5b1ec 100644 --- a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp +++ b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp @@ -282,7 +282,7 @@ static int tolua_Cocos2d_ScriptHandlerMgr_registerScriptHandler00(lua_State* tol #ifndef TOLUA_RELEASE tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || - !tolua_isusertype(tolua_S, 2, "Object", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 2, "cc.Object", 0, &tolua_err) || !toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err) || !tolua_isnumber(tolua_S, 4, 0, &tolua_err) || !tolua_isnoobj(tolua_S,5,&tolua_err) ) @@ -316,7 +316,7 @@ static int tolua_Cocos2d_ScriptHandlerMgr_unregisterScriptHandler00(lua_State* t #ifndef TOLUA_RELEASE tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || - !tolua_isusertype(tolua_S, 2, "Object", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 2, "cc.Object", 0, &tolua_err) || !tolua_isnumber(tolua_S, 3, 0, &tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; @@ -348,7 +348,7 @@ static int tolua_Cocos2d_ScriptHandlerMgr_removeObjectAllHandlers00(lua_State* t #ifndef TOLUA_RELEASE tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || - !tolua_isusertype(tolua_S, 2, "Object", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 2, "cc.Object", 0, &tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else diff --git a/cocos/scripting/lua/bindings/Lua_web_socket.cpp b/cocos/scripting/lua/bindings/Lua_web_socket.cpp index 4d3b8ae715..f508e720f6 100644 --- a/cocos/scripting/lua/bindings/Lua_web_socket.cpp +++ b/cocos/scripting/lua/bindings/Lua_web_socket.cpp @@ -164,7 +164,7 @@ static int tolua_collect_WebSocket (lua_State* tolua_S) /* function to release collected object via destructor */ static void tolua_reg_Web_Socket_type(lua_State* tolua_S) { - tolua_usertype(tolua_S, "WebSocket"); + tolua_usertype(tolua_S, "cc.WebSocket"); } /* method: create of class WebSocket */ @@ -174,7 +174,7 @@ static int tolua_Cocos2d_WebSocket_create00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertable(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertable(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !tolua_isstring(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -185,7 +185,7 @@ static int tolua_Cocos2d_WebSocket_create00(lua_State* tolua_S) const char* urlName = ((const char*) tolua_tostring(tolua_S,2,0)); LuaWebSocket *wSocket = new LuaWebSocket(); wSocket->init(*wSocket, urlName); - tolua_pushusertype(tolua_S,(void*)wSocket,"WebSocket"); + tolua_pushusertype(tolua_S,(void*)wSocket,"cc.WebSocket"); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); } return 1; @@ -204,7 +204,7 @@ static int tolua_Cocos2d_WebSocket_createByAProtocol00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertable(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertable(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !tolua_isstring(tolua_S,2,0,&tolua_err) || !tolua_isstring(tolua_S,3,0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) @@ -219,7 +219,7 @@ static int tolua_Cocos2d_WebSocket_createByAProtocol00(lua_State* tolua_S) protocols.push_back(protocol); LuaWebSocket *wSocket = new LuaWebSocket(); wSocket->init(*wSocket, urlName,&protocols); - tolua_pushusertype(tolua_S,(void*)wSocket,"WebSocket"); + tolua_pushusertype(tolua_S,(void*)wSocket,"cc.WebSocket"); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); } return 1; @@ -238,7 +238,7 @@ static int tolua_Cocos2d_WebSocket_createByProtocolArray00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertable(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertable(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !tolua_isstring(tolua_S,2,0,&tolua_err) || !tolua_isusertable(tolua_S,3,"CCArray",0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) @@ -262,7 +262,7 @@ static int tolua_Cocos2d_WebSocket_createByProtocolArray00(lua_State* tolua_S) } LuaWebSocket *wSocket = new LuaWebSocket(); wSocket->init(*wSocket, urlName,&protocols); - tolua_pushusertype(tolua_S,(void*)wSocket,"WebSocket"); + tolua_pushusertype(tolua_S,(void*)wSocket,"cc.WebSocket"); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); } return 1; @@ -281,7 +281,7 @@ static int tolua_Cocos2d_WebSocket_getReadyState00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; @@ -312,7 +312,7 @@ static int tolua_Cocos2d_WebSocket_close00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; @@ -340,7 +340,7 @@ static int tolua_Cocos2d_WebSocket_sendString00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S, 1, "WebSocket", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 1, "cc.WebSocket", 0, &tolua_err) || !tolua_isstring(tolua_S, 2, 0, &tolua_err) || !tolua_isnoobj(tolua_S, 3, &tolua_err) ) @@ -376,12 +376,12 @@ tolua_lerror: TOLUA_API int tolua_web_socket_open(lua_State* tolua_S){ tolua_open(tolua_S); tolua_reg_Web_Socket_type(tolua_S); - tolua_module(tolua_S,NULL,0); - tolua_beginmodule(tolua_S,NULL); + tolua_module(tolua_S,"cc",0); + tolua_beginmodule(tolua_S,"cc"); #ifdef __cplusplus - tolua_cclass(tolua_S,"WebSocket","WebSocket","",tolua_collect_WebSocket); + tolua_cclass(tolua_S,"WebSocket","cc.WebSocket","",tolua_collect_WebSocket); #else - tolua_cclass(tolua_S,"WebSocket","WebSocket","",NULL); + tolua_cclass(tolua_S,"WebSocket","cc.WebSocket","",NULL); #endif tolua_beginmodule(tolua_S,"WebSocket"); tolua_function(tolua_S, "create", tolua_Cocos2d_WebSocket_create00); @@ -400,7 +400,7 @@ int tolua_Cocos2d_WebSocket_registerScriptHandler00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) || !tolua_isnumber(tolua_S,3,0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) @@ -429,7 +429,7 @@ int tolua_Cocos2d_WebSocket_unregisterScriptHandler00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"WebSocket",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -457,7 +457,7 @@ TOLUA_API int register_web_socket_manual(lua_State* tolua_S) if (nullptr == tolua_S) return 0 ; - lua_pushstring(tolua_S,"WebSocket"); + lua_pushstring(tolua_S,"cc.WebSocket"); lua_rawget(tolua_S,LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { diff --git a/cocos/scripting/lua/bindings/Lua_web_socket.h b/cocos/scripting/lua/bindings/Lua_web_socket.h index 5431209d12..d2463af3c2 100644 --- a/cocos/scripting/lua/bindings/Lua_web_socket.h +++ b/cocos/scripting/lua/bindings/Lua_web_socket.h @@ -39,10 +39,10 @@ class LuaWebSocket: public cocos2d::network::WebSocket,public cocos2d::network:: { public: virtual ~LuaWebSocket(); - virtual void onOpen(WebSocket* ws); - virtual void onMessage(WebSocket* ws, const WebSocket::Data& data); - virtual void onClose(WebSocket* ws); - virtual void onError(WebSocket* ws, const WebSocket::ErrorCode& error); + virtual void onOpen(WebSocket* ws) override; + virtual void onMessage(WebSocket* ws, const WebSocket::Data& data) override; + virtual void onClose(WebSocket* ws) override; + virtual void onError(WebSocket* ws, const WebSocket::ErrorCode& error) override; enum WebSocketScriptHandlerType { diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp index 5120f1d966..581279907d 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp @@ -83,7 +83,7 @@ static int lua_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ArmatureAnimation",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccs.ArmatureAnimation",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -153,7 +153,7 @@ static int lua_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ArmatureAnimation",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccs.ArmatureAnimation",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -217,7 +217,7 @@ tolua_lerror: static void extendArmatureAnimation(lua_State* L) { - lua_pushstring(L, "ArmatureAnimation"); + lua_pushstring(L, "ccs.ArmatureAnimation"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -237,7 +237,7 @@ static int lua_cocos2dx_ArmatureDataManager_addArmatureFileInfoAsyncCallFunc(lua #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ArmatureDataManager",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccs.ArmatureDataManager",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -309,7 +309,7 @@ tolua_lerror: static void extendArmatureDataManager(lua_State* L) { - lua_pushstring(L, "ArmatureDataManager"); + lua_pushstring(L, "ccs.ArmatureDataManager"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -328,7 +328,7 @@ static int lua_cocos2dx_extension_Bone_setIgnoreMovementBoneData(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Bone",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccs.Bone",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -373,7 +373,7 @@ static int lua_cocos2dx_extension_Bone_getIgnoreMovementBoneData(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Bone",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccs.Bone",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -405,7 +405,7 @@ tolua_lerror: static void extendBone(lua_State* L) { - lua_pushstring(L, "Bone"); + lua_pushstring(L, "ccs.Bone"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp index 0d6d053810..e907189be2 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp @@ -2123,6 +2123,15 @@ static int tolua_bnd_cast_deprecated00(lua_State* tolua_S) } else { + std::string castName = tolua_tostring(tolua_S,2,NULL); + auto iter = g_typeCast.find(castName); + if (iter != g_typeCast.end() ) + { + CCLOG("Cast name %s doesn't include modular name which it belongs to,please add the modular name",iter->first.c_str()); + tolua_pushstring(tolua_S, iter->second.c_str()); + lua_insert(tolua_S, 2); + lua_pop(tolua_S, 1); + } return tolua_bnd_cast(tolua_S); } } diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp index 88b4693c01..739abb548c 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp @@ -42,6 +42,203 @@ USING_NS_CC; USING_NS_CC_EXT; using namespace cocostudio; +class LuaScrollViewDelegate:public Object, public ScrollViewDelegate +{ +public: + virtual ~LuaScrollViewDelegate() + {} + + virtual void scrollViewDidScroll(ScrollView* view) override + { + if (nullptr != view) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL); + if (0 != handler) + { + CommonScriptData data(handler,""); + ScriptEvent event(kCommonEvent,(void*)&data); + LuaEngine::getInstance()->sendEvent(&event); + } + + } + } + + virtual void scrollViewDidZoom(ScrollView* view) override + { + if (nullptr != view) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM); + if (0 != handler) + { + CommonScriptData data(handler,""); + ScriptEvent event(kCommonEvent,(void*)&data); + LuaEngine::getInstance()->sendEvent(&event); + } + } + } +}; + +static int tolua_cocos2dx_ScrollView_setDelegate(lua_State* tolua_S) +{ + if (nullptr == tolua_S) + return 0; + + int argc = 0; + ScrollView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"cc.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = (ScrollView*) tolua_tousertype(tolua_S,1,0); +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) + { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2dx_ScrollView_setDelegate'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (0 == argc) + { + LuaScrollViewDelegate* delegate = new LuaScrollViewDelegate(); + if (nullptr == delegate) + return 0; + + self->setUserObject(delegate); + self->setDelegate(delegate); + + delegate->release(); + + return 0; + } + + CCLOG("'setDelegate' function of ScrollView wrong number of arguments: %d, was expecting %d\n", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'setDelegate'.",&tolua_err); + return 0; +#endif +} + +static int tolua_cocos2d_ScrollView_registerScriptHandler(lua_State* tolua_S) +{ + if (NULL == tolua_S) + return 0; + + int argc = 0; + ScrollView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"cc.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(tolua_S,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_ScrollView_registerScriptHandler'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(tolua_S) - 1; + if (2 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) || + !tolua_isnumber(tolua_S, 3, 0, &tolua_err) ) + { + goto tolua_lerror; + } +#endif + LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,2,0)); + ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(tolua_S,3,0) + (int)ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, handlerType); + return 0; + } + + CCLOG("'registerScriptHandler' function of ScrollView has wrong number of arguments: %d, was expecting %d\n", argc, 2); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +static int tolua_cocos2d_ScrollView_unregisterScriptHandler(lua_State* tolua_S) +{ + if (NULL == tolua_S) + return 0; + + int argc = 0; + ScrollView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(tolua_S,1,"cc.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(tolua_S,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_ScrollView_unregisterScriptHandler'\n", NULL); + return 0; + } +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!tolua_isnumber(tolua_S, 2, 0, &tolua_err)) + goto tolua_lerror; +#endif + ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(tolua_S,2,0) + (int)ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, handlerType); + return 0; + } + + CCLOG("'unregisterScriptHandler' function of ScrollView has wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'unregisterScriptHandler'.",&tolua_err); + return 0; +#endif +} + +static void extendScrollView(lua_State* tolua_S) +{ + lua_pushstring(tolua_S, "cc.ScrollView"); + lua_rawget(tolua_S, LUA_REGISTRYINDEX); + if (lua_istable(tolua_S,-1)) + { + lua_pushstring(tolua_S,"setDelegate"); + lua_pushcfunction(tolua_S,tolua_cocos2dx_ScrollView_setDelegate ); + lua_rawset(tolua_S,-3); + lua_pushstring(tolua_S,"registerScriptHandler"); + lua_pushcfunction(tolua_S,tolua_cocos2d_ScrollView_registerScriptHandler ); + lua_rawset(tolua_S,-3); + lua_pushstring(tolua_S,"unregisterScriptHandler"); + lua_pushcfunction(tolua_S,tolua_cocos2d_ScrollView_unregisterScriptHandler ); + lua_rawset(tolua_S,-3); + } + lua_pop(tolua_S, 1); +} + + static int tolua_cocos2d_Control_registerControlEventHandler(lua_State* tolua_S) { if (NULL == tolua_S) @@ -52,7 +249,7 @@ static int tolua_cocos2d_Control_registerControlEventHandler(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Control",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.Control",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -108,7 +305,7 @@ static int tolua_cocos2d_control_unregisterControlEventHandler(lua_State* tolua_ #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"Control",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.Control",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -153,7 +350,7 @@ tolua_lerror: static void extendControl(lua_State* tolua_S) { - lua_pushstring(tolua_S, "Control"); + lua_pushstring(tolua_S, "cc.Control"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -177,7 +374,7 @@ static int tolua_cocos2d_EditBox_registerScriptEditBoxHandler(lua_State* tolua_S #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"EditBox",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.EditBox",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -226,7 +423,7 @@ static int tolua_cocos2d_EditBox_unregisterScriptEditBoxHandler(lua_State* tolua #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"EditBox",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.EditBox",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -258,7 +455,7 @@ tolua_lerror: static void extendEditBox(lua_State* tolua_S) { - lua_pushstring(tolua_S, "EditBox"); + lua_pushstring(tolua_S, "cc.EditBox"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -281,7 +478,7 @@ static int tolua_cocos2d_CCBProxy_create(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S,1,"CCBProxy",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"cc.CCBProxy",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -291,7 +488,7 @@ static int tolua_cocos2d_CCBProxy_create(lua_State* tolua_S) CCBProxy* tolua_ret = (CCBProxy*)CCBProxy::create(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int *pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CCBProxy"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.CCBProxy"); return 1; } @@ -316,7 +513,7 @@ static int tolua_cocos2d_CCBProxy_createCCBReader(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"CCBProxy",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.CCBProxy",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -335,7 +532,7 @@ static int tolua_cocos2d_CCBProxy_createCCBReader(lua_State* tolua_S) CCBReader* tolua_ret = (CCBReader*) self->createCCBReader(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"CCBReader"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.CCBReader"); return 1; } @@ -366,7 +563,7 @@ static int tolua_cocos2d_CCBProxy_readCCBFromFile(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"CCBProxy",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.CCBProxy",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -384,7 +581,7 @@ static int tolua_cocos2d_CCBProxy_readCCBFromFile(lua_State* tolua_S) { #if COCOS2D_DEBUG >= 1 if (!tolua_isstring(tolua_S, 2, 0, &tolua_err)|| - !tolua_isusertype(tolua_S,3,"CCBReader",0,&tolua_err)|| + !tolua_isusertype(tolua_S,3,"cc.CCBReader",0,&tolua_err)|| !tolua_isboolean(tolua_S,4,1,&tolua_err ) ) goto tolua_lerror; @@ -395,7 +592,7 @@ static int tolua_cocos2d_CCBProxy_readCCBFromFile(lua_State* tolua_S) tolua_ret = (Node*) self->readCCBFromFile(ccbFilePath, ccbReader, setOwner); ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"Node"); + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"cc.Node"); return 1; } @@ -420,7 +617,7 @@ static int tolua_cocos2d_CCBProxy_getNodeTypeName(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"CCBProxy",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.CCBProxy",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -437,7 +634,7 @@ static int tolua_cocos2d_CCBProxy_getNodeTypeName(lua_State* tolua_S) if (1 == argc) { #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"Node",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror; #endif Node* node = static_cast(tolua_tousertype(tolua_S,2,0)); @@ -466,7 +663,7 @@ static int tolua_cocos2d_CCBProxy_setCallback(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"CCBProxy",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.CCBProxy",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -482,7 +679,7 @@ static int tolua_cocos2d_CCBProxy_setCallback(lua_State* tolua_S) if ( argc >= 2 && argc <= 3 ) { #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,2,"Node",0,&tolua_err) || + if (!tolua_isusertype(tolua_S,2,"cc.Node",0,&tolua_err) || !toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err) || !tolua_isnumber(tolua_S, 4, 1, &tolua_err) ) @@ -510,8 +707,8 @@ int register_cocos2dx_extension_CCBProxy(lua_State* tolua_S) { tolua_module(tolua_S,"cc",0); tolua_beginmodule(tolua_S,"cc"); - tolua_usertype(tolua_S,"CCBProxy"); - tolua_cclass(tolua_S,"CCBProxy","CCBProxy","Layer",NULL); + tolua_usertype(tolua_S,"cc.CCBProxy"); + tolua_cclass(tolua_S,"CCBProxy","cc.CCBProxy","cc.Layer",NULL); tolua_beginmodule(tolua_S,"CCBProxy"); tolua_function(tolua_S, "create", tolua_cocos2d_CCBProxy_create); tolua_function(tolua_S, "createCCBReader", tolua_cocos2d_CCBProxy_createCCBReader); @@ -522,7 +719,7 @@ int register_cocos2dx_extension_CCBProxy(lua_State* tolua_S) tolua_endmodule(tolua_S); std::string typeName = typeid(CCBProxy).name(); - g_luaType[typeName] = "CCBProxy"; + g_luaType[typeName] = "cc.CCBProxy"; return 1; } @@ -537,7 +734,7 @@ static int tolua_cocos2d_CCBReader_load(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"CCBReader",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.CCBReader",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -564,12 +761,12 @@ static int tolua_cocos2d_CCBReader_load(lua_State* tolua_S) Node* tolua_ret = (Node*) self->readNodeGraphFromFile(fileName); int ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"Node"); + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"cc.Node"); return 1; } #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S, 3, "Object", 0, &tolua_err)) + if (!tolua_isusertype(tolua_S, 3, "cc.Object", 0, &tolua_err)) goto tolua_lerror; #endif Object* owner = static_cast(tolua_tousertype(tolua_S, 3, 0)); @@ -579,7 +776,7 @@ static int tolua_cocos2d_CCBReader_load(lua_State* tolua_S) Node* tolua_ret = (Node*) self->readNodeGraphFromFile(fileName,owner); int ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"Node"); + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"cc.Node"); return 1; } @@ -591,7 +788,7 @@ static int tolua_cocos2d_CCBReader_load(lua_State* tolua_S) Node* tolua_ret = (Node*) self->readNodeGraphFromFile(fileName,owner,size); int ID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* luaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"Node"); + toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)tolua_ret,"cc.Node"); return 1; } @@ -608,7 +805,7 @@ tolua_lerror: static void extendCCBReader(lua_State* tolua_S) { - lua_pushstring(tolua_S, "CCBReader"); + lua_pushstring(tolua_S, "cc.CCBReader"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -630,7 +827,7 @@ static int tolua_cocos2d_CCBAnimationManager_setCallFuncForLuaCallbackNamed(lua_ #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S,1,"CCBAnimationManager",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.CCBAnimationManager",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(tolua_S,1,0)); @@ -647,7 +844,7 @@ static int tolua_cocos2d_CCBAnimationManager_setCallFuncForLuaCallbackNamed(lua_ { #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,2, "CallFunc", 0, &tolua_err) || + if (!tolua_isusertype(tolua_S,2, "cc.CallFunc", 0, &tolua_err) || !tolua_isstring(tolua_S, 3, 0, &tolua_err) ) goto tolua_lerror; #endif @@ -675,7 +872,7 @@ tolua_lerror: static void extendCCBAnimationManager(lua_State* tolua_S) { - lua_pushstring(tolua_S, "CCBAnimationManager"); + lua_pushstring(tolua_S, "cc.CCBAnimationManager"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -692,7 +889,7 @@ public: virtual ~LuaAssetsManagerDelegateProtocol() {} - virtual void onProgress(int percent) + virtual void onProgress(int percent) override { int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS); if (0 != handler) @@ -703,7 +900,7 @@ public: } } - virtual void onSuccess() + virtual void onSuccess() override { int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS); if (0 != handler) @@ -714,7 +911,7 @@ public: } } - virtual void onError(AssetsManager::ErrorCode errorCode) + virtual void onError(AssetsManager::ErrorCode errorCode) override { int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR); if (0 != handler) @@ -736,7 +933,7 @@ static int lua_cocos2dx_AssetsManager_setDelegate(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"AssetsManager",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.AssetsManager",0,&tolua_err)) goto tolua_lerror; #endif self = (AssetsManager*) tolua_tousertype(L,1,0); @@ -791,7 +988,7 @@ tolua_lerror: static void extendAssetsManager(lua_State* L) { - lua_pushstring(L, "AssetsManager"); + lua_pushstring(L, "cc.AssetsManager"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -800,6 +997,473 @@ static void extendAssetsManager(lua_State* L) lua_pop(L, 1); } +#define KEY_TABLEVIEW_DATA_SOURCE "TableViewDataSource" +#define KEY_TABLEVIEW_DELEGATE "TableViewDelegate" + +class LUA_TableViewDelegate:public Object, public TableViewDelegate +{ +public: + LUA_TableViewDelegate(){} + + virtual ~LUA_TableViewDelegate(){} + + + virtual void scrollViewDidScroll(ScrollView* view) override + { + if (nullptr != view) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL); + if (0 != handler) + { + LuaTableViewEventData eventData; + BasicScriptData data(view,&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL, (void*)&data); + } + } + } + + virtual void scrollViewDidZoom(ScrollView* view) override + { + if (nullptr != view) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)view, ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM); + if (0 != handler) + { + LuaTableViewEventData eventData; + BasicScriptData data(view,&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::SCROLLVIEW_ZOOM, (void*)&data); + } + } + } + + virtual void tableCellTouched(TableView* table, TableViewCell* cell) override + { + if (nullptr != table && nullptr != cell) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED); + if (0 != handler) + { + LuaTableViewEventData eventData(cell); + BasicScriptData data(table,&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_TOUCHED,(void*)&data); + } + } + } + + virtual void tableCellHighlight(TableView* table, TableViewCell* cell) override + { + if (nullptr != table && nullptr != cell) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT); + if (0 != handler) + { + LuaTableViewEventData eventData(cell); + BasicScriptData data(table,&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_HIGHLIGHT,(void*)&data); + } + } + } + + virtual void tableCellUnhighlight(TableView* table, TableViewCell* cell) override + { + if (nullptr != table && nullptr != cell) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT); + if (0 != handler) + { + LuaTableViewEventData eventData(cell); + BasicScriptData data(table,&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_UNHIGHLIGHT,(void*)&data); + } + } + } + + virtual void tableCellWillRecycle(TableView* table, TableViewCell* cell) override + { + if (nullptr != table && nullptr != cell) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE); + if (0 != handler) + { + LuaTableViewEventData eventData(cell); + BasicScriptData data(table,&eventData); + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_WILL_RECYCLE,(void*)&data); + } + } + } +}; + +static int lua_cocos2dx_TableView_setDelegate(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + TableView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = (TableView*) tolua_tousertype(L,1,0); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) + { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TableView_setDelegate'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (0 == argc) + { + LUA_TableViewDelegate* delegate = new LUA_TableViewDelegate(); + if (nullptr == delegate) + return 0; + + Dictionary* userDict = static_cast(self->getUserObject()); + if (nullptr == userDict) + { + userDict = new Dictionary(); + if (NULL == userDict) + return 0; + + self->setUserObject(userDict); + userDict->release(); + } + + userDict->setObject(delegate, KEY_TABLEVIEW_DELEGATE); + self->setDelegate(delegate); + delegate->release(); + + return 0; + } + + CCLOG("'setDelegate' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'setDelegate'.",&tolua_err); + return 0; +#endif +} + +class LUA_TableViewDataSource:public Object,public TableViewDataSource +{ +public: + LUA_TableViewDataSource(){} + virtual ~LUA_TableViewDataSource(){} + + virtual Size tableCellSizeForIndex(TableView *table, ssize_t idx) override + { + if (nullptr != table ) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX); + if (0 != handler) + { + LuaTableViewEventData eventData(&idx); + BasicScriptData data(table,&eventData); + float width = 0.0; + float height = 0.0; + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_SIZE_FOR_INDEX, (void*)&data,2,[&](lua_State* L,int numReturn){ + CCASSERT(numReturn == 2, "tableCellSizeForIndex return count error"); + ValueVector vec; + width = (float)tolua_tonumber(L, -1, 0); + lua_pop(L, 1); + height = (float)tolua_tonumber(L, -1, 0); + lua_pop(L, 1); + }); + + return Size(width, height); + } + } + + return Size::ZERO; + } + + virtual TableViewCell* tableCellAtIndex(TableView *table, ssize_t idx) override + { + if (nullptr != table ) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX); + if (0 != handler) + { + LuaTableViewEventData eventData(&idx); + BasicScriptData data(table,&eventData); + TableViewCell* viewCell = nullptr; + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLECELL_AT_INDEX, (void*)&data, 1, [&](lua_State* L, int numReturn){ + CCASSERT(numReturn == 1, "tableCellAtIndex return count error"); + viewCell = static_cast(tolua_tousertype(L, -1, nullptr)); + lua_pop(L, 1); + }); + + return viewCell; + } + } + + return NULL; + } + + virtual ssize_t numberOfCellsInTableView(TableView *table) override + { + if (nullptr != table ) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)table, ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS); + if (0 != handler) + { + LuaTableViewEventData eventData; + BasicScriptData data(table,&eventData); + ssize_t counts = 0; + LuaEngine::getInstance()->handleEvent(ScriptHandlerMgr::HandlerType::TABLEVIEW_NUMS_OF_CELLS, (void*)&data,1, [&](lua_State* L, int numReturn){ + CCASSERT(numReturn == 1, "numberOfCellsInTableView return count error"); + counts = (ssize_t)tolua_tonumber(L, -1, 0); + lua_pop(L, 1); + }); + return counts; + } + } + return 0; + } +}; + +static int lua_cocos2dx_TableView_setDataSource(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + TableView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = (TableView*) tolua_tousertype(L,1,0); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) + { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_TableView_setDataSource'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (0 == argc) + { + LUA_TableViewDataSource* dataSource = new LUA_TableViewDataSource(); + if (nullptr == dataSource) + return 0; + + Dictionary* userDict = static_cast(self->getUserObject()); + if (nullptr == userDict) + { + userDict = new Dictionary(); + if (NULL == userDict) + return 0; + + self->setUserObject(userDict); + userDict->release(); + } + + userDict->setObject(dataSource, KEY_TABLEVIEW_DATA_SOURCE); + + self->setDataSource(dataSource); + + dataSource->release(); + + return 0; + } + + CCLOG("'setDataSource' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'setDataSource'.",&tolua_err); + return 0; +#endif +} + +static int lua_cocos2dx_TableView_create(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertable(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(L) - 1; + + if (2 == argc || 1 == argc) + { + LUA_TableViewDataSource* dataSource = new LUA_TableViewDataSource(); + Size size; + ok &= luaval_to_size(L, 2, &size); + + TableView* ret = nullptr; + + if (1 == argc) + { + ret = TableView::create(dataSource, size); + } + else + { +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(L,3,"cc.Node",0,&tolua_err)) goto tolua_lerror; +#endif + Node* node = static_cast(tolua_tousertype(L, 3, nullptr)); + ret = TableView::create(dataSource, size, node); + } + + if (nullptr == ret) + return 0; + + ret->reloadData(); + + Dictionary* userDict = new Dictionary(); + userDict->setObject(dataSource, KEY_TABLEVIEW_DATA_SOURCE); + ret->setUserObject(userDict); + userDict->release(); + + dataSource->release(); + + + int nID = (int)ret->_ID; + int* pLuaID = &ret->_luaID; + toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)ret,"cc.TableView"); + + return 1; + } + CCLOG("'create' function of TableView wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'create'.",&tolua_err); + return 0; +#endif +} + +static int lua_cocos2d_TableView_registerScriptHandler(lua_State* L) +{ + if (NULL == L) + return 0; + + int argc = 0; + TableView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'tolua_cocos2d_TableView_registerScriptHandler'\n", NULL); + return 0; + } +#endif + argc = lua_gettop(L) - 1; + if (2 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) || + !tolua_isnumber(L, 3, 0, &tolua_err) ) + { + goto tolua_lerror; + } +#endif + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(L,3,0) + (int)ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, handlerType); + return 0; + } + + CCLOG("'registerScriptHandler' function of TableView has wrong number of arguments: %d, was expecting %d\n", argc, 2); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'registerScriptHandler'.",&tolua_err); + return 0; +#endif +} + +static int lua_cocos2d_TableView_unregisterScriptHandler(lua_State* L) +{ + if (NULL == L) + return 0; + + int argc = 0; + TableView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"cc.TableView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2d_TableView_unregisterScriptHandler'\n", NULL); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!tolua_isnumber(L, 2, 0, &tolua_err)) + goto tolua_lerror; +#endif + ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(L,2,0) + (int)ScriptHandlerMgr::HandlerType::SCROLLVIEW_SCROLL); + ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, handlerType); + return 0; + } + + CCLOG("'unregisterScriptHandler' function of TableView has wrong number of arguments: %d, was expecting %d\n", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'unregisterScriptHandler'.",&tolua_err); + return 0; +#endif +} + +static void extendTableView(lua_State* L) +{ + lua_pushstring(L, "cc.TableView"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "setDelegate", lua_cocos2dx_TableView_setDelegate); + tolua_function(L, "setDataSource", lua_cocos2dx_TableView_setDataSource); + tolua_function(L, "create", lua_cocos2dx_TableView_create); + tolua_function(L, "registerScriptHandler", lua_cocos2d_TableView_registerScriptHandler); + tolua_function(L, "unregisterScriptHandler", lua_cocos2d_TableView_unregisterScriptHandler); + } + lua_pop(L, 1); +} + int register_all_cocos2dx_extension_manual(lua_State* tolua_S) { extendControl(tolua_S); @@ -807,5 +1471,7 @@ int register_all_cocos2dx_extension_manual(lua_State* tolua_S) extendCCBReader(tolua_S); extendCCBAnimationManager(tolua_S); extendAssetsManager(tolua_S); + extendScrollView(tolua_S); + extendTableView(tolua_S); return 0; } diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h index 1a76eaf316..b150bf3cbd 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h @@ -46,5 +46,16 @@ struct LuaAssetsManagerEventData } }; +struct LuaTableViewEventData +{ + void* value; + + // Constructor + LuaTableViewEventData(void* _value = nullptr) + :value(_value) + { + } +}; + #endif // #ifndef COCOS2DX_SCRIPT_LUA_COCOS2DX_SUPPORT_LUA_COCOS2DX_EXTENSION_MANUAL_H diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp index ec8a23ccd8..b51979ff53 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp @@ -94,7 +94,7 @@ static int lua_cocos2dx_Widget_addTouchEventListener(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Widget",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -145,7 +145,7 @@ tolua_lerror: static void extendWidget(lua_State* L) { - lua_pushstring(L, "Widget"); + lua_pushstring(L, "ccui.Widget"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -164,7 +164,7 @@ static int lua_cocos2dx_CheckBox_addEventListenerCheckBox(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"CheckBox",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.CheckBox",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -214,7 +214,7 @@ tolua_lerror: static void extendCheckBox(lua_State* L) { - lua_pushstring(L, "CheckBox"); + lua_pushstring(L, "ccui.CheckBox"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -233,7 +233,7 @@ static int lua_cocos2dx_Slider_addEventListenerSlider(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"Slider",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.Slider",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -283,7 +283,7 @@ tolua_lerror: static void extendSlider(lua_State* L) { - lua_pushstring(L, "Slider"); + lua_pushstring(L, "ccui.Slider"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -302,7 +302,7 @@ static int lua_cocos2dx_TextField_addEventListenerTextField(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.TextField",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -352,7 +352,7 @@ tolua_lerror: static void extendTextField(lua_State* L) { - lua_pushstring(L, "TextField"); + lua_pushstring(L, "ccui.TextField"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -371,7 +371,7 @@ static int lua_cocos2dx_PageView_addEventListenerPageView(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"PageView",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.PageView",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -421,7 +421,7 @@ tolua_lerror: static void extendPageView(lua_State* L) { - lua_pushstring(L, "PageView"); + lua_pushstring(L, "ccui.PageView"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -440,7 +440,7 @@ static int lua_cocos2dx_ListView_addEventListenerListView(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"ListView",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.ListView",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -490,7 +490,7 @@ tolua_lerror: static void extendListView(lua_State* L) { - lua_pushstring(L, "ListView"); + lua_pushstring(L, "ccui.ListView"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { @@ -509,7 +509,7 @@ static int lua_cocos2dx_LayoutParameter_setMargin(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"LayoutParameter",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -577,7 +577,7 @@ static int lua_cocos2dx_LayoutParameter_getMargin(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"LayoutParameter",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror; #endif self = static_cast(tolua_tousertype(L,1,0)); @@ -628,7 +628,7 @@ tolua_lerror: static void extendLayoutParameter(lua_State* L) { - lua_pushstring(L, "LayoutParameter"); + lua_pushstring(L, "ccui.LayoutParameter"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id index e3c65441d6..e296678e5b 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -1 +1 @@ -f916840e52bdfd7e7283cb9c70ebfaf1c23b9301 \ No newline at end of file +9d9d07e19dba691a22e4d184f0ec0e6ae6207a9b \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp index 0d11f0f9b4..7da290e02a 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp @@ -29,7 +29,7 @@ int lua_cocos2dx_physics_PhysicsBody_getJoints(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsBody",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsBody",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsBody*)tolua_tousertype(tolua_S,1,0); @@ -69,7 +69,7 @@ int lua_cocos2dx_physics_PhysicsBody_getJoints(lua_State* tolua_S) if(name != g_luaType.end()){ className = name->second.c_str(); } else { - className = "PhysicsJoint"; + className = "cc.PhysicsJoint"; } lua_pushnumber(tolua_S, (lua_Number)indexTable); @@ -102,7 +102,7 @@ int lua_cocos2dx_physics_PhysicsWorld_getScene(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsWorld",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsWorld",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsWorld*)tolua_tousertype(tolua_S,1,0); @@ -129,7 +129,7 @@ int lua_cocos2dx_physics_PhysicsWorld_getScene(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "Scene"; + className = "cc.Scene"; } int ID = (int)(ret._ID); @@ -162,7 +162,7 @@ int lua_cocos2dx_physics_PhysicsWorld_rayCast(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsWorld",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsWorld",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsWorld*)tolua_tousertype(tolua_S,1,0); @@ -191,7 +191,7 @@ int lua_cocos2dx_physics_PhysicsWorld_rayCast(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsWorld"; + className = "cc.PhysicsWorld"; } tolua_pushusertype(tolua_S, (void*)(&world), className.c_str()); @@ -229,7 +229,7 @@ int lua_cocos2dx_physics_PhysicsWorld_queryRect(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsWorld",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsWorld",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsWorld*)tolua_tousertype(tolua_S,1,0); @@ -257,7 +257,7 @@ int lua_cocos2dx_physics_PhysicsWorld_queryRect(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsWorld"; + className = "cc.PhysicsWorld"; } tolua_pushusertype(tolua_S, (void*)(&world), className.c_str()); @@ -268,7 +268,7 @@ int lua_cocos2dx_physics_PhysicsWorld_queryRect(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsShape"; + className = "cc.PhysicsShape"; } toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), className.c_str()); return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); @@ -305,7 +305,7 @@ int lua_cocos2dx_physics_PhysicsWorld_queryPoint(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsWorld",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsWorld",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsWorld*)tolua_tousertype(tolua_S,1,0); @@ -333,7 +333,7 @@ int lua_cocos2dx_physics_PhysicsWorld_queryPoint(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsWorld"; + className = "cc.PhysicsWorld"; } tolua_pushusertype(tolua_S, (void*)(&world), className.c_str()); @@ -344,7 +344,7 @@ int lua_cocos2dx_physics_PhysicsWorld_queryPoint(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsShape"; + className = "cc.PhysicsShape"; } toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), className.c_str()); return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); @@ -380,7 +380,7 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"PhysicsBody",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"cc.PhysicsBody",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -409,7 +409,7 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -450,7 +450,7 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -493,7 +493,7 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -527,7 +527,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"PhysicsBody",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"cc.PhysicsBody",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -556,7 +556,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -597,7 +597,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -640,7 +640,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -674,7 +674,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"PhysicsBody",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"cc.PhysicsBody",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -703,7 +703,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -744,7 +744,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -787,7 +787,7 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) if(iter != g_luaType.end()){ className = iter->second.c_str(); } else { - className = "PhysicsBody"; + className = "cc.PhysicsBody"; } cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); if (NULL != dynObject) { @@ -821,7 +821,7 @@ int lua_cocos2dx_physics_PhysicsShape_recenterPoints(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"PhysicsShape",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShape",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -886,7 +886,7 @@ int lua_cocos2dx_physics_PhysicsShape_getPolyonCenter(lua_State* tolua_S) #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"PhysicsShape",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShape",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; @@ -924,14 +924,13 @@ int lua_cocos2dx_physics_PhysicsShapeBox_getPoints(lua_State* tolua_S) { int argc = 0; cocos2d::PhysicsShapeBox* cobj = nullptr; - bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsShapeBox*)tolua_tousertype(tolua_S,1,0); @@ -967,14 +966,13 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_getPoints(lua_State* tolua_S) { int argc = 0; cocos2d::PhysicsShapePolygon* cobj = nullptr; - bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsShapePolygon",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapePolygon",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsShapePolygon*)tolua_tousertype(tolua_S,1,0); @@ -1012,14 +1010,13 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPoints(lua_State* tolua_S) { int argc = 0; cocos2d::PhysicsShapeEdgeBox* cobj = nullptr; - bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsShapeEdgeBox",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeEdgeBox",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsShapeEdgeBox*)tolua_tousertype(tolua_S,1,0); @@ -1057,14 +1054,13 @@ int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPoints(lua_State* tolua_S) { int argc = 0; cocos2d::PhysicsShapeEdgePolygon* cobj = nullptr; - bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsShapeEdgePolygon",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeEdgePolygon",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsShapeEdgePolygon*)tolua_tousertype(tolua_S,1,0); @@ -1102,14 +1098,13 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeChain_getPoints(lua_State* tolua_S) { int argc = 0; cocos2d::PhysicsShapeEdgeChain* cobj = nullptr; - bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"PhysicsShapeEdgeChain",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeEdgeChain",0,&tolua_err)) goto tolua_lerror; #endif cobj = (cocos2d::PhysicsShapeEdgeChain*)tolua_tousertype(tolua_S,1,0); @@ -1145,7 +1140,7 @@ tolua_lerror: int register_all_cocos2dx_physics_manual(lua_State* tolua_S) { - lua_pushstring(tolua_S, "PhysicsBody"); + lua_pushstring(tolua_S, "cc.PhysicsBody"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1164,7 +1159,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsShape"); + lua_pushstring(tolua_S, "cc.PhysicsShape"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1177,7 +1172,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsShapeBox"); + lua_pushstring(tolua_S, "cc.PhysicsShapeBox"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1187,7 +1182,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsShapeEdgeBox"); + lua_pushstring(tolua_S, "cc.PhysicsShapeEdgeBox"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1197,7 +1192,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsShapePolygon"); + lua_pushstring(tolua_S, "cc.PhysicsShapePolygon"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1207,7 +1202,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsShapeEdgePolygon"); + lua_pushstring(tolua_S, "cc.PhysicsShapeEdgePolygon"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1217,7 +1212,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsShapeEdgeChain"); + lua_pushstring(tolua_S, "cc.PhysicsShapeEdgeChain"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { @@ -1227,7 +1222,7 @@ int register_all_cocos2dx_physics_manual(lua_State* tolua_S) } lua_pop(tolua_S, 1); - lua_pushstring(tolua_S, "PhysicsWorld"); + lua_pushstring(tolua_S, "cc.PhysicsWorld"); lua_rawget(tolua_S, LUA_REGISTRYINDEX); if (lua_istable(tolua_S,-1)) { diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp index 593dd3f0a3..63ea2a23cd 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp @@ -94,7 +94,7 @@ static int lua_cocos2dx_CCSkeletonAnimation_createWithFile(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertable(L,1,"SkeletonAnimation",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(L,1,"sp.SkeletonAnimation",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(L) - 1; @@ -115,7 +115,7 @@ static int lua_cocos2dx_CCSkeletonAnimation_createWithFile(lua_State* L) int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)tolua_ret,"SkeletonAnimation"); + toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)tolua_ret,"sp.SkeletonAnimation"); return 1; } else if (3 == argc) { @@ -135,7 +135,7 @@ static int lua_cocos2dx_CCSkeletonAnimation_createWithFile(lua_State* L) int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)tolua_ret,"SkeletonAnimation"); + toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)tolua_ret,"sp.SkeletonAnimation"); return 1; } @@ -153,7 +153,7 @@ int tolua_Cocos2d_CCSkeletonAnimation_registerScriptHandler00(lua_State* tolua_S #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"SkeletonAnimation",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"sp.SkeletonAnimation",0,&tolua_err) || !toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -180,7 +180,7 @@ int tolua_Cocos2d_CCSkeletonAnimation_unregisterScriptHandler00(lua_State* tolua #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"SkeletonAnimation",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"sp.SkeletonAnimation",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; @@ -205,7 +205,7 @@ static int tolua_Cocos2d_CCSkeletonAnimation_setTimeScale00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"SkeletonAnimation",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"sp.SkeletonAnimation",0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -232,7 +232,7 @@ static int tolua_Cocos2d_CCSkeletonAnimation_setDebugSlots00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"SkeletonAnimation",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"sp.SkeletonAnimation",0,&tolua_err) || !tolua_isboolean(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -259,7 +259,7 @@ static int tolua_Cocos2d_CCSkeletonAnimation_setDebugBones00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"SkeletonAnimation",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"sp.SkeletonAnimation",0,&tolua_err) || !tolua_isboolean(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -286,7 +286,7 @@ static int tolua_Cocos2d_CCSkeletonAnimation_setPremultipliedAlpha00(lua_State* #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"SkeletonAnimation",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"sp.SkeletonAnimation",0,&tolua_err) || !tolua_isboolean(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -311,13 +311,13 @@ tolua_lerror: static int tolua_spine_SkeletoneAnimation_setBlendFunc(lua_State* tolua_S) { - return tolua_cocos2dx_setBlendFunc(tolua_S,"SkeletonAnimation"); + return tolua_cocos2dx_setBlendFunc(tolua_S,"sp.SkeletonAnimation"); } static void extendCCSkeletonAnimation(lua_State* L) { - lua_pushstring(L, "SkeletonAnimation"); + lua_pushstring(L, "sp.SkeletonAnimation"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L,-1)) { diff --git a/cocos/scripting/lua/bindings/lua_xml_http_request.cpp b/cocos/scripting/lua/bindings/lua_xml_http_request.cpp index 9a7b124ee9..9470afffb1 100644 --- a/cocos/scripting/lua/bindings/lua_xml_http_request.cpp +++ b/cocos/scripting/lua/bindings/lua_xml_http_request.cpp @@ -270,7 +270,7 @@ void LuaMinXmlHttpRequest::getByteData(unsigned char* byteData) /* function to regType */ static void lua_reg_xml_http_request(lua_State* L) { - tolua_usertype(L, "XMLHttpRequest"); + tolua_usertype(L, "cc.XMLHttpRequest"); } static int lua_collect_xml_http_request (lua_State* L) @@ -296,7 +296,7 @@ static int lua_cocos2dx_XMLHttpRequest_constructor(lua_State* L) self->autorelease(); int ID = self? (int)self->_ID : -1; int* luaID = self? &self->_luaID : NULL; - toluafix_pushusertype_ccobject(L, ID, luaID, (void*)self, "XMLHttpRequest"); + toluafix_pushusertype_ccobject(L, ID, luaID, (void*)self, "cc.XMLHttpRequest"); return 1; } @@ -316,7 +316,7 @@ static int lua_get_XMLHttpRequest_responseType(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -345,7 +345,7 @@ static int lua_set_XMLHttpRequest_responseType(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -388,7 +388,7 @@ static int lua_get_XMLHttpRequest_withCredentials(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -417,7 +417,7 @@ static int lua_set_XMLHttpRequest_withCredentials(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -457,7 +457,7 @@ static int lua_get_XMLHttpRequest_timeout(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -486,7 +486,7 @@ static int lua_set_XMLHttpRequest_timeout(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -526,7 +526,7 @@ static int lua_get_XMLHttpRequest_readyState(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -555,7 +555,7 @@ static int lua_get_XMLHttpRequest_status(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -584,7 +584,7 @@ static int lua_get_XMLHttpRequest_statusText(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -613,7 +613,7 @@ static int lua_get_XMLHttpRequest_responseText(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -640,7 +640,7 @@ static int lua_get_XMLHttpRequest_response(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -711,7 +711,7 @@ static int lua_cocos2dx_XMLHttpRequest_open(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -796,7 +796,7 @@ static int lua_cocos2dx_XMLHttpRequest_send(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -855,7 +855,7 @@ static int lua_cocos2dx_XMLHttpRequest_setRequestHeader(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -902,7 +902,7 @@ static int lua_cocos2dx_XMLHttpRequest_getAllResponseHeaders(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -948,7 +948,7 @@ static int lua_cocos2dx_XMLHttpRequest_getResponseHeader(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -1002,7 +1002,7 @@ static int lua_cocos2dx_XMLHttpRequest_registerScriptHandler(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -1046,7 +1046,7 @@ static int lua_cocos2dx_XMLHttpRequest_unregisterScriptHandler(lua_State* L) #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L,1,"XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(L,1,"cc.XMLHttpRequest",0,&tolua_err)) goto tolua_lerror; #endif self = (LuaMinXmlHttpRequest*) tolua_tousertype(L,1,0); @@ -1082,9 +1082,9 @@ TOLUA_API int register_xml_http_request(lua_State* L) { tolua_open(L); lua_reg_xml_http_request(L); - tolua_module(L,NULL,0); - tolua_beginmodule(L,NULL); - tolua_cclass(L,"XMLHttpRequest","XMLHttpRequest","Object",lua_collect_xml_http_request); + tolua_module(L,"cc",0); + tolua_beginmodule(L,"cc"); + tolua_cclass(L,"XMLHttpRequest","cc.XMLHttpRequest","cc.Object",lua_collect_xml_http_request); tolua_beginmodule(L,"XMLHttpRequest"); tolua_variable(L, "responseType", lua_get_XMLHttpRequest_responseType, lua_set_XMLHttpRequest_responseType); tolua_variable(L, "withCredentials", lua_get_XMLHttpRequest_withCredentials, lua_set_XMLHttpRequest_withCredentials); 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/cocos/scripting/lua/script/CCBReaderLoad.lua b/cocos/scripting/lua/script/CCBReaderLoad.lua index 733a432317..141a4e5df5 100644 --- a/cocos/scripting/lua/script/CCBReaderLoad.lua +++ b/cocos/scripting/lua/script/CCBReaderLoad.lua @@ -17,7 +17,7 @@ function CCBReaderLoad(strFilePath,proxy,owner) local i = 1 for i = 1,table.getn(ownerCallbackNames) do local callbackName = ownerCallbackNames[i] - local callbackNode = tolua.cast(ownerCallbackNodes[i],"Node") + local callbackNode = tolua.cast(ownerCallbackNodes[i],"cc.Node") if "function" == type(owner[callbackName]) then proxy:setCallback(callbackNode, owner[callbackName], ownerCallbackControlEvents[i]) @@ -33,7 +33,7 @@ function CCBReaderLoad(strFilePath,proxy,owner) for i = 1, table.getn(ownerOutletNames) do local outletName = ownerOutletNames[i] - local outletNode = tolua.cast(ownerOutletNodes[i],"Node") + local outletNode = tolua.cast(ownerOutletNodes[i],"cc.Node") owner[outletName] = outletNode end end @@ -42,8 +42,8 @@ function CCBReaderLoad(strFilePath,proxy,owner) local animationManagersForNodes = ccbReader:getAnimationManagersForNodes() for i = 1 , table.getn(nodesWithAnimationManagers) do - local innerNode = tolua.cast(nodesWithAnimationManagers[i], "Node") - local animationManager = tolua.cast(animationManagersForNodes[i], "CCBAnimationManager") + local innerNode = tolua.cast(nodesWithAnimationManagers[i], "cc.Node") + local animationManager = tolua.cast(animationManagersForNodes[i], "cc.CCBAnimationManager") local documentControllerName = animationManager:getDocumentControllerName() if "" == documentControllerName then @@ -59,7 +59,7 @@ function CCBReaderLoad(strFilePath,proxy,owner) for i = 1,table.getn(documentCallbackNames) do local callbackName = documentCallbackNames[i] - local callbackNode = tolua.cast(documentCallbackNodes[i],"Node") + local callbackNode = tolua.cast(documentCallbackNodes[i],"cc.Node") if "" ~= documentControllerName and nil ~= ccb[documentControllerName] then if "function" == type(ccb[documentControllerName][callbackName]) then proxy:setCallback(callbackNode, ccb[documentControllerName][callbackName], documentCallbackControlEvents[i]) @@ -75,7 +75,7 @@ function CCBReaderLoad(strFilePath,proxy,owner) for i = 1, table.getn(documentOutletNames) do local outletName = documentOutletNames[i] - local outletNode = tolua.cast(documentOutletNodes[i],"Node") + local outletNode = tolua.cast(documentOutletNodes[i],"cc.Node") if nil ~= ccb[documentControllerName] then ccb[documentControllerName][outletName] = tolua.cast(outletNode, proxy:getNodeTypeName(outletNode)) diff --git a/cocos/scripting/lua/script/Deprecated.lua b/cocos/scripting/lua/script/Deprecated.lua index e48ba122e9..38ae6ff614 100644 --- a/cocos/scripting/lua/script/Deprecated.lua +++ b/cocos/scripting/lua/script/Deprecated.lua @@ -706,6 +706,21 @@ end rawset(CCEGLView,"sharedOpenGLView",CCEGLViewDeprecated.sharedOpenGLView) --functions of CCFileUtils will be deprecated end +--Enums of CCTableView will be deprecated begin +rawset(CCTableView, "kTableViewScroll",cc.SCROLLVIEW_SCRIPT_SCROLL) +rawset(CCTableView,"kTableViewZoom",cc.SCROLLVIEW_SCRIPT_ZOOM) +rawset(CCTableView,"kTableCellTouched",cc.TABLECELL_TOUCHED) +rawset(CCTableView,"kTableCellSizeForIndex",cc.TABLECELL_SIZE_FOR_INDEX) +rawset(CCTableView,"kTableCellSizeAtIndex",cc.TABLECELL_SIZE_AT_INDEX) +rawset(CCTableView,"kNumberOfCellsInTableView",cc.NUMBER_OF_CELLS_IN_TABLEVIEW) +--Enums of CCTableView will be deprecated end + +--Enums of CCScrollView will be deprecated begin +rawset(CCScrollView, "kScrollViewScroll",cc.SCROLLVIEW_SCRIPT_SCROLL) +rawset(CCScrollView,"kScrollViewZoom",cc.SCROLLVIEW_SCRIPT_ZOOM) +--Enums of CCScrollView will be deprecated end + + --functions of CCApplication will be deprecated end local CCApplicationDeprecated = { } diff --git a/cocos/scripting/lua/script/DeprecatedClass.lua b/cocos/scripting/lua/script/DeprecatedClass.lua index c899d0a0dc..05e476a6fe 100644 --- a/cocos/scripting/lua/script/DeprecatedClass.lua +++ b/cocos/scripting/lua/script/DeprecatedClass.lua @@ -175,6 +175,15 @@ end _G["CCEaseElasticOut"] = DeprecatedClass.CCEaseElasticOut() --CCEaseElasticOut class will be Deprecated,end +--CCTableViewCell class will be Deprecated,begin +function DeprecatedClass.CCTableViewCell() + deprecatedTip("CCTableViewCell","cc.TableViewCell") + return cc.TableViewCell +end +_G["CCTableViewCell"] = DeprecatedClass.CCTableViewCell() +--CCTableViewCell class will be Deprecated,end + + --CCEaseBackOut class will be Deprecated,begin function DeprecatedClass.CCEaseBackOut() deprecatedTip("CCEaseBackOut","cc.EaseBackOut") @@ -719,6 +728,15 @@ end _G["CCPlace"] = DeprecatedClass.CCPlace() --CCPlace class will be Deprecated,end +--CCScrollView class will be Deprecated,begin +function DeprecatedClass.CCScrollView() + deprecatedTip("CCScrollView","cc.ScrollView") + return cc.ScrollView +end +_G["CCScrollView"] = DeprecatedClass.CCScrollView() +--CCScrollView class will be Deprecated,end + + --CCGLProgram class will be Deprecated,begin function DeprecatedClass.CCGLProgram() deprecatedTip("CCGLProgram","cc.GLProgram") @@ -799,6 +817,15 @@ end _G["CCParticleFlower"] = DeprecatedClass.CCParticleFlower() --CCParticleFlower class will be Deprecated,end +--CCTableView class will be Deprecated,begin +function DeprecatedClass.CCTableView() + deprecatedTip("CCTableView","cc.TableView") + return cc.TableView +end +_G["CCTableView"] = DeprecatedClass.CCTableView() +--CCTableView class will be Deprecated,end + + --CCParticleSmoke class will be Deprecated,begin function DeprecatedClass.CCParticleSmoke() deprecatedTip("CCParticleSmoke","cc.ParticleSmoke") @@ -2127,4 +2154,20 @@ end _G["CCBProxy"] = DeprecatedClass.CCBProxy() --CCBProxy class will be Deprecated,end +--WebSocket class will be Deprecated,begin +function DeprecatedClass.WebSocket() + deprecatedTip("WebSocket","cc.WebSocket") + return cc.WebSocket +end +_G["WebSocket"] = DeprecatedClass.WebSocket() +--WebSocket class will be Deprecated,end + +--XMLHttpRequest class will be Deprecated,begin +function DeprecatedClass.XMLHttpRequest() + deprecatedTip("XMLHttpRequest","cc.XMLHttpRequest") + return cc.XMLHttpRequest +end +_G["XMLHttpRequest"] = DeprecatedClass.XMLHttpRequest() +--XMLHttpRequest class will be Deprecated,end + 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..0c4fbe72a3 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 @@ -487,7 +494,7 @@ void ScrollView::addChild(Node * child, int zOrder, int tag) void ScrollView::beforeDraw() { - _beforeDrawCommand.init(0, _vertexZ); + _beforeDrawCommand.init(_globalZOrder); _beforeDrawCommand.func = CC_CALLBACK_0(ScrollView::onBeforeDraw, this); Director::getInstance()->getRenderer()->addCommand(&_beforeDrawCommand); } @@ -522,7 +529,7 @@ void ScrollView::onBeforeDraw() void ScrollView::afterDraw() { - _afterDrawCommand.init(0, _vertexZ); + _afterDrawCommand.init(_globalZOrder); _afterDrawCommand.func = CC_CALLBACK_0(ScrollView::onAfterDraw, this); Director::getInstance()->getRenderer()->addCommand(&_afterDrawCommand); } 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/extensions/proj.win32/Win32InputBox.cpp b/extensions/proj.win32/Win32InputBox.cpp index 220a932072..1412e1a198 100644 --- a/extensions/proj.win32/Win32InputBox.cpp +++ b/extensions/proj.win32/Win32InputBox.cpp @@ -280,14 +280,14 @@ void CWin32InputBox::InitDialog() // Message handler for about box. LRESULT CALLBACK CWin32InputBox::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLong(hDlg, GWL_USERDATA); + CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLongPtr(hDlg, GWLP_USERDATA); WIN32INPUTBOX_PARAM *param = _this ? _this->GetParam() : 0; switch (message) { case WM_INITDIALOG: { - ::SetWindowLong(hDlg, GWL_USERDATA, (LONG) lParam); + SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR) lParam); _this = (CWin32InputBox *) lParam; _this->_param->hDlg = hDlg; diff --git a/samples/Cpp/AssetsManagerTest/proj.android/AndroidManifest.xml b/samples/Cpp/AssetsManagerTest/proj.android/AndroidManifest.xml index b6b69e4442..b236420d07 100644 --- a/samples/Cpp/AssetsManagerTest/proj.android/AndroidManifest.xml +++ b/samples/Cpp/AssetsManagerTest/proj.android/AndroidManifest.xml @@ -14,7 +14,7 @@ android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" - android:configChanges="orientation|screenSize|smallestScreenSize"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> getRenderer()->addCommand(&_customCommand); @@ -1630,7 +1630,7 @@ void ActionCatmullRomStacked::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -1745,7 +1745,7 @@ void ActionCardinalSplineStacked::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -2107,7 +2107,7 @@ void ActionCatmullRom::draw() kmGLPopMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -2207,7 +2207,7 @@ void ActionCardinalSpline::draw() kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); kmGLPopMatrix(); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/BaseTest.cpp b/samples/Cpp/TestCpp/Classes/BaseTest.cpp index f0cd18c58a..529a1337ec 100644 --- a/samples/Cpp/TestCpp/Classes/BaseTest.cpp +++ b/samples/Cpp/TestCpp/Classes/BaseTest.cpp @@ -1,10 +1,26 @@ -// -// BaseTest.cpp -// TestCpp -// -// Created by Ricardo Quesada on 6/6/13. -// -// +/**************************************************************************** + 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 "BaseTest.h" #include "VisibleRect.h" diff --git a/samples/Cpp/TestCpp/Classes/BaseTest.h b/samples/Cpp/TestCpp/Classes/BaseTest.h index e6e3ababfa..1c509e1716 100644 --- a/samples/Cpp/TestCpp/Classes/BaseTest.h +++ b/samples/Cpp/TestCpp/Classes/BaseTest.h @@ -1,10 +1,26 @@ -// -// BaseTest.h -// TestCpp -// -// Created by Ricardo Quesada on 6/6/13. -// -// +/**************************************************************************** + 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 __TestCpp__BaseTest__ #define __TestCpp__BaseTest__ diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp index 70e55dae5d..2dabe08a75 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -149,7 +149,7 @@ void Box2DTestLayer::draw() kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp index dd8d3f8693..2b05f4a60b 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp @@ -211,7 +211,7 @@ void Box2DView::draw() { Layer::draw(); - _customCmd.init(0, _vertexZ); + _customCmd.init(_globalZOrder); _customCmd.func = CC_CALLBACK_0(Box2DView::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCmd); } diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index 68a584d577..829c8766dc 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -611,7 +611,7 @@ void RawStencilBufferTest::draw() auto iter = _renderCmds.begin(); - iter->init(0, _vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onEnableStencil, this); renderer->addCommand(&(*iter)); ++iter; @@ -628,7 +628,7 @@ void RawStencilBufferTest::draw() spritePoint.y = 0; _sprites.at(i)->setPosition( spritePoint ); - iter->init(0, _vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawClip, this, i, stencilPoint); renderer->addCommand(&(*iter)); ++iter; @@ -638,7 +638,7 @@ void RawStencilBufferTest::draw() _sprites.at(i)->visit(); kmGLPopMatrix(); - iter->init(0, _vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawSprite, this, i, winPoint); renderer->addCommand(&(*iter)); ++iter; @@ -649,7 +649,7 @@ void RawStencilBufferTest::draw() kmGLPopMatrix(); } - iter->init(0, _vertexZ); + iter->init(_globalZOrder); iter->func = CC_CALLBACK_0(RawStencilBufferTest::onDisableStencil, this); renderer->addCommand(&(*iter)); diff --git a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp index 2cfb569796..de6f94c98c 100644 --- a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp @@ -103,7 +103,8 @@ void ConfigurationLoadConfig::onEnter() ConfigurationBase::onEnter(); Configuration::getInstance()->loadConfigFile("configs/config-test-ok.plist"); - Configuration::getInstance()->dumpInfo(); + std::string config = Configuration::getInstance()->getInfo(); + log("%s\n", config.c_str()); } @@ -196,7 +197,8 @@ void ConfigurationSet::onEnter() conf->setValue("this.is.a.bool.value", Value(true) ); conf->setValue("this.is.a.string.value", Value("hello world") ); - conf->dumpInfo(); + auto str = conf->getInfo(); + log("%s\n", str.c_str()); } std::string ConfigurationSet::subtitle() const diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index 61aa2aa0b2..622220f09d 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -116,7 +116,7 @@ DrawPrimitivesTest::DrawPrimitivesTest() void DrawPrimitivesTest::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 1349970d67..88a63ce1f9 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -503,7 +503,7 @@ void TestChangeZorder::changeZorder(float dt) Node *node = getChildByTag(currentTag); - node->setZOrder(CCRANDOM_0_1() * 3); + node->setLocalZOrder(CCRANDOM_0_1() * 3); currentTag ++; currentTag = currentTag % 3; @@ -637,7 +637,7 @@ void TestParticleDisplay::onEnter() bone->addDisplay(p1, 0); bone->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); + bone->setLocalZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a3"); @@ -645,7 +645,7 @@ void TestParticleDisplay::onEnter() bone->addDisplay(p2, 0); bone->changeDisplayWithIndex(0, true); bone->setIgnoreMovementBoneData(true); - bone->setZOrder(100); + bone->setLocalZOrder(100); bone->setScale(1.2f); armature->addBone(bone, "bady-a30"); } @@ -1067,8 +1067,22 @@ void TestColliderDetector::update(float delta) } void TestColliderDetector::draw() { - armature2->drawContour(); + _customCommand.init(_globalZOrder); + _customCommand.func = CC_CALLBACK_0(TestColliderDetector::onDraw, this); + Director::getInstance()->getRenderer()->addCommand(&_customCommand); } + +void TestColliderDetector::onDraw() +{ + kmMat4 oldMat; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); + kmGLLoadMatrix(&_modelViewTransform); + + armature2->drawContour(); + + kmGLLoadMatrix(&oldMat); +} + #endif @@ -1094,7 +1108,7 @@ std::string TestBoundingBox::title() const } void TestBoundingBox::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(TestBoundingBox::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index c3b64debb9..9a07cc0d5d 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -271,6 +271,7 @@ public: virtual std::string title() const override; virtual void update(float delta); virtual void draw(); + void onDraw(); void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex); @@ -278,6 +279,7 @@ public: cocostudio::Armature *armature; cocostudio::Armature *armature2; + CustomCommand _customCommand; //new render needed this for drawing primitives cocos2d::Sprite *bullet; }; #endif diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index a06f00d592..5253040a66 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -56,7 +56,7 @@ bool UIImageViewTest::init() _uiLayer->addChild(sprite); */ -// imageView->setZOrder(20); +// imageView->setLocalZOrder(20); return true; } diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index d85049bc94..e09dc7f4fc 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -210,7 +210,7 @@ void Atlas1::draw() // GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // GL_TEXTURE_2D - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Atlas1::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); @@ -526,7 +526,7 @@ Atlas4::Atlas4() void Atlas4::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Atlas4::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -1612,7 +1612,7 @@ std::string LabelBMFontBounds::subtitle() const void LabelBMFontBounds::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp index 9d3d063102..a3dff56208 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.cpp @@ -66,7 +66,9 @@ static std::function createFunctions[] = CL(LabelTTFUnicodeNew), CL(LabelBMFontTestNew), CL(LabelTTFDistanceField), - CL(LabelTTFDistanceFieldEffect) + CL(LabelTTFDistanceFieldEffect), + CL(LabelCharMapTest), + CL(LabelCrashTest) }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -158,20 +160,19 @@ LabelTTFAlignmentNew::LabelTTFAlignmentNew() { auto s = Director::getInstance()->getWinSize(); - auto ttf0 = Label::createWithTTF("Alignment 0\nnew line", "fonts/tahoma.ttf", 32); - ttf0->setAlignment(TextHAlignment::LEFT); + TTFConfig config("fonts/tahoma.ttf",32); + + auto ttf0 = Label::createWithTTF(config,"Alignment 0\nnew line",TextHAlignment::LEFT); ttf0->setPosition(Point(s.width/2,(s.height/6)*2 - 30)); ttf0->setAnchorPoint(Point(0.5f,0.5f)); this->addChild(ttf0); - auto ttf1 = Label::createWithTTF("Alignment 1\nnew line", "fonts/tahoma.ttf", 32); - ttf1->setAlignment(TextHAlignment::CENTER); + auto ttf1 = Label::createWithTTF(config,"Alignment 1\nnew line",TextHAlignment::CENTER); ttf1->setPosition(Point(s.width/2,(s.height/6)*3 - 30)); ttf1->setAnchorPoint(Point(0.5f,0.5f)); this->addChild(ttf1); - auto ttf2 = Label::createWithTTF("Alignment 2\nnew line", "fonts/tahoma.ttf", 32); - ttf1->setAlignment(TextHAlignment::RIGHT); + auto ttf2 = Label::createWithTTF(config,"Alignment 2\nnew line",TextHAlignment::RIGHT); ttf2->setPosition(Point(s.width/2,(s.height/6)*4 - 30)); ttf2->setAnchorPoint(Point(0.5f,0.5f)); this->addChild(ttf2); @@ -194,7 +195,7 @@ LabelFNTColorAndOpacity::LabelFNTColorAndOpacity() auto col = LayerColor::create( Color4B(128,128,128,255) ); addChild(col, -10); - auto label1 = Label::createWithBMFont("Test", "fonts/bitmapFontTest2.fnt"); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test"); label1->setAnchorPoint( Point(0,0) ); addChild(label1, 0, kTagBitmapAtlas1); @@ -204,13 +205,13 @@ LabelFNTColorAndOpacity::LabelFNTColorAndOpacity() auto repeat = RepeatForever::create(seq); label1->runAction(repeat); - auto label2 = Label::createWithBMFont("Test", "fonts/bitmapFontTest2.fnt"); + auto label2 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test"); label2->setAnchorPoint( Point(0.5f, 0.5f) ); label2->setColor( Color3B::RED ); addChild(label2, 0, kTagBitmapAtlas2); label2->runAction( repeat->clone() ); - auto label3 = Label::createWithBMFont("Test", "fonts/bitmapFontTest2.fnt"); + auto label3 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test"); label3->setAnchorPoint( Point(1,1) ); addChild(label3, 0, kTagBitmapAtlas3); @@ -252,7 +253,7 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() _time = 0; // Upper Label - auto label = Label::createWithBMFont("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas"); addChild(label); auto s = Director::getInstance()->getWinSize(); @@ -289,7 +290,7 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() // Bottom Label - auto label2 = Label::createWithBMFont("00.0", "fonts/bitmapFontTest.fnt"); + auto label2 = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "00.0"); addChild(label2, 0, kTagBitmapAtlas2); label2->setPosition( Point(s.width/2.0f, 80) ); @@ -301,7 +302,7 @@ LabelFNTSpriteActions::LabelFNTSpriteActions() void LabelFNTSpriteActions::draw() { - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(LabelFNTSpriteActions::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); @@ -341,7 +342,7 @@ std::string LabelFNTSpriteActions::subtitle() const LabelFNTPadding::LabelFNTPadding() { - auto label = Label::createWithBMFont("abcdefg", "fonts/bitmapFontTest4.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "abcdefg"); addChild(label); auto s = Director::getInstance()->getWinSize(); @@ -365,17 +366,17 @@ LabelFNTOffset::LabelFNTOffset() auto s = Director::getInstance()->getWinSize(); Label* label = NULL; - label = Label::createWithBMFont("FaFeFiFoFu", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "FaFeFiFoFu"); addChild(label); label->setPosition( Point(s.width/2, s.height/2+50) ); label->setAnchorPoint( Point(0.5f, 0.5f) ) ; - label = Label::createWithBMFont("fafefifofu", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "fafefifofu"); addChild(label); label->setPosition( Point(s.width/2, s.height/2) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); - label = Label::createWithBMFont("aeiou", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "aeiou"); addChild(label); label->setPosition( Point(s.width/2, s.height/2-50) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); @@ -396,19 +397,19 @@ LabelFNTColor::LabelFNTColor() auto s = Director::getInstance()->getWinSize(); Label* label = NULL; - label = Label::createWithBMFont("Blue", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Blue"); label->setColor( Color3B::BLUE ); addChild(label); label->setPosition( Point(s.width/2, s.height/4) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); - label = Label::createWithBMFont("Red", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Red"); addChild(label); label->setPosition( Point(s.width/2, 2*s.height/4) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); label->setColor( Color3B::RED ); - label = Label::createWithBMFont("G", "fonts/bitmapFontTest5.fnt"); + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Green"); addChild(label); label->setPosition( Point(s.width/2, 3*s.height/4) ); label->setAnchorPoint( Point(0.5f, 0.5f) ); @@ -433,7 +434,7 @@ LabelFNTHundredLabels::LabelFNTHundredLabels() { char str[6] = {0}; sprintf(str, "-%d-", i); - auto label = Label::createWithBMFont(str, "fonts/bitmapFontTest.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", str); addChild(label); auto s = Director::getInstance()->getWinSize(); @@ -459,7 +460,7 @@ LabelFNTMultiLine::LabelFNTMultiLine() Size s; // Left - auto label1 = Label::createWithBMFont(" Multi line\nLeft", "fonts/bitmapFontTest3.fnt"); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", " Multi line\nLeft"); label1->setAnchorPoint(Point(0,0)); addChild(label1, 0, kTagBitmapAtlas1); @@ -468,7 +469,7 @@ LabelFNTMultiLine::LabelFNTMultiLine() // Center - auto label2 = Label::createWithBMFont("Multi line\nCenter", "fonts/bitmapFontTest3.fnt"); + auto label2 = Label::createWithBMFont( "fonts/bitmapFontTest3.fnt", "Multi line\nCenter"); label2->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label2, 0, kTagBitmapAtlas2); @@ -476,7 +477,7 @@ LabelFNTMultiLine::LabelFNTMultiLine() CCLOG("content size: %.2fx%.2f", s.width, s.height); // right - auto label3 = Label::createWithBMFont("Multi line\nRight\nThree lines Three", "fonts/bitmapFontTest3.fnt"); + auto label3 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "Multi line\nRight\nThree lines Three"); label3->setAnchorPoint(Point(1, 1)); addChild(label3, 0, kTagBitmapAtlas3); @@ -504,19 +505,18 @@ LabelFNTandTTFEmpty::LabelFNTandTTFEmpty() float delta = s.height/4; // LabelBMFont - auto label1 = Label::createWithBMFont("", "fonts/bitmapFontTest3.fnt", TextHAlignment::CENTER, s.width); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "", TextHAlignment::CENTER, s.width); addChild(label1, 0, kTagBitmapAtlas1); label1->setAnchorPoint(Point(0.5f, 0.5f)); label1->setPosition(Point(s.width/2, delta)); // LabelTTF - auto label2 = Label::createWithTTF("", "fonts/arial.ttf", 48, s.width, TextHAlignment::CENTER,GlyphCollection::NEHE); + TTFConfig ttfConfig("fonts/arial.ttf",48); + auto label2 = Label::createWithTTF(ttfConfig,"", TextHAlignment::CENTER,s.width); addChild(label2, 0, kTagBitmapAtlas2); label2->setAnchorPoint(Point(0.5f, 0.5f)); label2->setPosition(Point(s.width/2, delta * 2)); - - schedule(schedule_selector(LabelFNTandTTFEmpty::updateStrings), 1.0f); setEmpty = false; @@ -558,7 +558,7 @@ LabelFNTRetina::LabelFNTRetina() auto s = Director::getInstance()->getWinSize(); // LabelBMFont - auto label1 = Label::createWithBMFont("TESTING RETINA DISPLAY", "fonts/konqa32.fnt"); + auto label1 = Label::createWithBMFont("fonts/konqa32.fnt", "TESTING RETINA DISPLAY"); label1->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label1); label1->setPosition(Point(s.width/2, s.height/2)); @@ -582,7 +582,7 @@ LabelFNTGlyphDesigner::LabelFNTGlyphDesigner() addChild(layer, -10); // LabelBMFont - auto label1 = Label::createWithBMFont("Testing Glyph Designer", "fonts/futura-48.fnt"); + auto label1 = Label::createWithBMFont("fonts/futura-48.fnt", "Testing Glyph Designer"); label1->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label1); label1->setPosition(Point(s.width/2, s.height/2)); @@ -603,7 +603,8 @@ LabelTTFUnicodeChinese::LabelTTFUnicodeChinese() auto size = Director::getInstance()->getWinSize(); // Adding "啊" letter at the end of string to make VS2012 happy, otherwise VS will generate errors // like "Error 3 error C2146: syntax error : missing ')' before identifier 'label'"; - auto label = Label::createWithTTF("美好的一天啊", "fonts/wt021.ttf", 55, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, "美好的一天啊"); + TTFConfig ttfConfig("fonts/wt021.ttf",55,GlyphCollection::CUSTOM, "美好的一天啊"); + auto label = Label::createWithTTF(ttfConfig,"美好的一天啊", TextHAlignment::CENTER, size.width); label->setAnchorPoint(Point(0.5f, 0.5f)); label->setPosition(Point(size.width / 2, size.height /2)); this->addChild(label); @@ -622,7 +623,7 @@ std::string LabelTTFUnicodeChinese::subtitle() const LabelFNTUnicodeChinese::LabelFNTUnicodeChinese() { auto size = Director::getInstance()->getWinSize(); - auto label = Label::createWithBMFont("中国", "fonts/bitmapFontChinese.fnt"); + auto label = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", "中国"); label->setAnchorPoint(Point(0.5f, 0.5f)); label->setPosition(Point(size.width / 2, size.height /2)); this->addChild(label); @@ -671,8 +672,7 @@ LabelFNTMultiLineAlignment::LabelFNTMultiLineAlignment() auto size = Director::getInstance()->getWinSize(); // create and initialize a Label - this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/markerFelt.fnt", TextHAlignment::CENTER, size.width/1.5); - //this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/bitmapFontTest.fnt", TextHAlignment::CENTER, size.width/1.5); + this->_labelShouldRetain = Label::createWithBMFont("fonts/markerFelt.fnt", LongSentencesExample, TextHAlignment::CENTER, size.width/1.5); this->_labelShouldRetain->setAnchorPoint(Point(0.5f, 0.5f)); this->_labelShouldRetain->retain(); @@ -855,22 +855,22 @@ LabelFNTUNICODELanguages::LabelFNTUNICODELanguages() auto s = Director::getInstance()->getWinSize(); - auto label1 = Label::createWithBMFont(spanish, "fonts/arial-unicode-26.fnt", TextHAlignment::CENTER, 200); + auto label1 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", spanish, TextHAlignment::CENTER, 200); addChild(label1); label1->setAnchorPoint(Point(0.5f, 0.5f)); label1->setPosition(Point(s.width/2, s.height/5*3)); - auto label2 = Label::createWithBMFont(chinese, "fonts/arial-unicode-26.fnt"); + auto label2 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", chinese); addChild(label2); label2->setAnchorPoint(Point(0.5f, 0.5f)); label2->setPosition(Point(s.width/2, s.height/5*2.5)); - auto label3 = Label::createWithBMFont(russian, "fonts/arial-26-en-ru.fnt"); + auto label3 = Label::createWithBMFont("fonts/arial-26-en-ru.fnt", russian); addChild(label3); label3->setAnchorPoint(Point(0.5f, 0.5f)); label3->setPosition(Point(s.width/2, s.height/5*2)); - auto label4 = Label::createWithBMFont(japanese, "fonts/arial-unicode-26.fnt"); + auto label4 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", japanese); addChild(label4); label4->setAnchorPoint(Point(0.5f, 0.5f)); label4->setPosition(Point(s.width/2, s.height/5*1.5)); @@ -894,7 +894,7 @@ LabelFNTBounds::LabelFNTBounds() addChild(layer, -10); // LabelBMFont - label1 = Label::createWithBMFont("Testing Glyph Designer", "fonts/boundsTestFont.fnt", TextHAlignment::CENTER, s.width); + label1 = Label::createWithBMFont("fonts/boundsTestFont.fnt", "Testing Glyph Designer", TextHAlignment::CENTER, s.width); label1->setAnchorPoint(Point(0.5f, 0.5f)); addChild(label1); label1->setPosition(Point(s.width/2, s.height/2)); @@ -912,7 +912,7 @@ std::string LabelFNTBounds::subtitle() const void LabelFNTBounds::draw() { - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(LabelFNTBounds::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -946,7 +946,8 @@ LabelTTFLongLineWrapping::LabelTTFLongLineWrapping() auto size = Director::getInstance()->getWinSize(); // Long sentence - auto label1 = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 28, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + TTFConfig ttfConfig("fonts/arial.ttf", 28); + auto label1 = Label::createWithTTF(ttfConfig, LongSentencesExample, TextHAlignment::CENTER,size.width); label1->setPosition( Point(size.width/2, size.height/2) ); label1->setAnchorPoint(Point(0.5, 1.0)); addChild(label1); @@ -966,22 +967,23 @@ LabelTTFColor::LabelTTFColor() { auto size = Director::getInstance()->getWinSize(); + TTFConfig ttfConfig("fonts/arial.ttf", 35); // Green - auto label1 = Label::createWithTTF("Green", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + auto label1 = Label::createWithTTF(ttfConfig,"Green", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height/5 * 1.5) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point(0.5, 0.5)); addChild(label1); // Red - auto label2 = Label::createWithTTF("Red", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + auto label2 = Label::createWithTTF(ttfConfig,"Red", TextHAlignment::CENTER, size.width); label2->setPosition( Point(size.width/2, size.height/5 * 2.0) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point(0.5, 0.5)); addChild(label2); // Blue - auto label3 = Label::createWithTTF("Blue", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + auto label3 = Label::createWithTTF(ttfConfig,"Blue", TextHAlignment::CENTER, size.width); label3->setPosition( Point(size.width/2, size.height/5 * 2.5) ); label3->setColor( Color3B::BLUE ); label3->setAnchorPoint(Point(0.5, 0.5)); @@ -1001,12 +1003,10 @@ std::string LabelTTFColor::subtitle() const LabelTTFDynamicAlignment::LabelTTFDynamicAlignment() { auto size = Director::getInstance()->getWinSize(); - - _label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE); + TTFConfig ttfConfig("fonts/arial.ttf", 45); + _label = Label::createWithTTF(ttfConfig,LongSentencesExample, TextHAlignment::CENTER, size.width); _label->setPosition( Point(size.width/2, size.height/2) ); - _label->setAnchorPoint(Point(0.5, 0.5)); - - + _label->setAnchorPoint(Point(0.5, 0.5)); auto menu = Menu::create( MenuItemFont::create("Left", CC_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentLeft, this)), @@ -1074,21 +1074,24 @@ LabelTTFUnicodeNew::LabelTTFUnicodeNew() float vStep = size.height/9; float vSize = size.height; - + TTFConfig ttfConfig("fonts/arial.ttf", 45,GlyphCollection::ASCII); // Spanish - auto label1 = Label::createWithTTF("Buen día, ¿cómo te llamas?", "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::ASCII); + auto label1 = Label::createWithTTF(ttfConfig,"Buen día, ¿cómo te llamas?", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, vSize - (vStep * 4.5)) ); label1->setAnchorPoint(Point(0.5, 0.5)); addChild(label1); // German - auto label2 = Label::createWithTTF("In welcher Straße haben Sie gelebt?", "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::ASCII); + auto label2 = Label::createWithTTF(ttfConfig,"In welcher Straße haben Sie gelebt?", TextHAlignment::CENTER,size.width); label2->setPosition( Point(size.width/2, vSize - (vStep * 5.5)) ); label2->setAnchorPoint(Point(0.5, 0.5)); addChild(label2); // chinese - auto label3 = Label::createWithTTF(chinese, "fonts/wt021.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, chinese.c_str()); + ttfConfig.fontFilePath = "fonts/wt021.ttf"; + ttfConfig.glyphs = GlyphCollection::CUSTOM; + ttfConfig.customGlyphs = chinese.c_str(); + auto label3 = Label::createWithTTF(ttfConfig,chinese, TextHAlignment::CENTER,size.width); label3->setPosition( Point(size.width/2, vSize - (vStep * 6.5)) ); label3->setAnchorPoint(Point(0.5, 0.5)); addChild(label3); @@ -1118,9 +1121,10 @@ LabelTTFFontsTestNew::LabelTTFFontsTestNew() #define arraysize(ar) (sizeof(ar) / sizeof(ar[0])) auto size = Director::getInstance()->getWinSize(); - + TTFConfig ttfConfig(ttfpaths[0],40, GlyphCollection::NEHE); for(size_t i=0;i < arraysize(ttfpaths); ++i) { - auto label = Label::createWithTTF( ttfpaths[i], ttfpaths[i], 40, 0, TextHAlignment::CENTER, GlyphCollection::NEHE); + ttfConfig.fontFilePath = ttfpaths[i]; + auto label = Label::createWithTTF(ttfConfig, ttfpaths[i], TextHAlignment::CENTER,0); if( label ) { label->setPosition( Point(size.width/2, ((size.height * 0.6)/arraysize(ttfpaths) * i) + (size.height/5))); @@ -1147,7 +1151,7 @@ LabelBMFontTestNew::LabelBMFontTestNew() { auto size = Director::getInstance()->getWinSize(); - auto label1 = Label::createWithBMFont("Hello World, this is testing the new Label using fnt file", "fonts/bitmapFontTest2.fnt", TextHAlignment::CENTER, size.width); + auto label1 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Hello World, this is testing the new Label using fnt file", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height/2) ); label1->setAnchorPoint(Point(0.5, 0.5)); addChild(label1); @@ -1166,8 +1170,9 @@ std::string LabelBMFontTestNew::subtitle() const LabelTTFDistanceField::LabelTTFDistanceField() { auto size = Director::getInstance()->getWinSize(); + TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); - auto label1 = Label::createWithTTF("Distance Field", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label1 = Label::createWithTTF(ttfConfig,"Distance Field",TextHAlignment::CENTER,size.width); label1->setPosition( Point(size.width/2, size.height/2) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point(0.5, 0.5)); @@ -1180,7 +1185,7 @@ LabelTTFDistanceField::LabelTTFDistanceField() nullptr); label1->runAction(RepeatForever::create(action)); - auto label2 = Label::createWithTTF("Distance Field", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label2 = Label::createWithTTF(ttfConfig,"Distance Field",TextHAlignment::CENTER,size.width); label2->setPosition( Point(size.width/2, size.height/5) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point(0.5, 0.5)); @@ -1205,21 +1210,23 @@ LabelTTFDistanceFieldEffect::LabelTTFDistanceFieldEffect() auto bg = LayerColor::create(Color4B(200,191,231,255)); this->addChild(bg); - auto label1 = Label::createWithTTF("Glow", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); + + auto label1 = Label::createWithTTF(ttfConfig,"Glow", TextHAlignment::CENTER, size.width); label1->setPosition( Point(size.width/2, size.height*0.5) ); label1->setColor( Color3B::GREEN ); label1->setAnchorPoint(Point(0.5, 0.5)); label1->setLabelEffect(LabelEffect::GLOW,Color3B::YELLOW); addChild(label1); - auto label2 = Label::createWithTTF("Outline", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label2 = Label::createWithTTF(ttfConfig,"Outline", TextHAlignment::CENTER, size.width); label2->setPosition( Point(size.width/2, size.height*0.375) ); label2->setColor( Color3B::RED ); label2->setAnchorPoint(Point(0.5, 0.5)); label2->setLabelEffect(LabelEffect::OUTLINE,Color3B::BLUE); addChild(label2); - auto label3 = Label::createWithTTF("Shadow", "fonts/arial.ttf", 80, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); + auto label3 = Label::createWithTTF(ttfConfig,"Shadow", TextHAlignment::CENTER, size.width); label3->setPosition( Point(size.width/2, size.height*0.25f) ); label3->setColor( Color3B::RED ); label3->setAnchorPoint(Point(0.5, 0.5)); @@ -1237,3 +1244,71 @@ 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(); + + TTFConfig ttfConfig("fonts/arial.ttf", 80, GlyphCollection::DYNAMIC,nullptr,true); + + auto label1 = Label::createWithTTF(ttfConfig,"Test崩溃123", TextHAlignment::CENTER, size.width); + label1->setPosition( Point(size.width/2, size.height/2) ); + label1->setAnchorPoint(Point(0.5, 0.5)); + addChild(label1); +} + +std::string LabelCrashTest::title() const +{ + return "New Label Crash Test"; +} + +std::string LabelCrashTest::subtitle() const +{ + return "Not crash and show [Test123] when using unknown character."; +} diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h index ad6b53211c..45d9374d4c 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTestNew.h @@ -347,6 +347,32 @@ 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: + CREATE_FUNC(LabelCrashTest); + + LabelCrashTest(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; // we don't support linebreak mode diff --git a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index d23091db12..194a7bc74c 100644 --- a/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -166,11 +166,11 @@ void TouchableSpriteTest::onEnter() target->setOpacity(255); if (target == sprite2) { - sprite1->setZOrder(100); + sprite1->setLocalZOrder(100); } else if(target == sprite1) { - sprite1->setZOrder(0); + sprite1->setLocalZOrder(0); } }; @@ -764,20 +764,22 @@ void DirectorEventTest::onEnter() Size s = Director::getInstance()->getWinSize(); - _label1 = Label::createWithTTF("Update: 0", "fonts/arial.ttf", 20); + TTFConfig ttfConfig("fonts/arial.ttf", 20); + + _label1 = Label::createWithTTF(ttfConfig, "Update: 0"); _label1->setPosition(30,s.height/2 + 60); this->addChild(_label1); - _label2 = Label::createWithTTF("Visit: 0", "fonts/arial.ttf", 20); + _label2 = Label::createWithTTF(ttfConfig, "Visit: 0"); _label2->setPosition(30,s.height/2 + 20); this->addChild(_label2); - _label3 = Label::createWithTTF("Draw: 0", "fonts/arial.ttf", 20); + _label3 = Label::createWithTTF(ttfConfig, "Draw: 0"); _label3->setPosition(30,30); _label3->setPosition(30,s.height/2 - 20); this->addChild(_label3); - _label4 = Label::createWithTTF("Projection: 0", "fonts/arial.ttf", 20); + _label4 = Label::createWithTTF(ttfConfig, "Projection: 0"); _label4->setPosition(30,30); _label4->setPosition(30,s.height/2 - 60); this->addChild(_label4); diff --git a/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp b/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp index 7044ade0ed..c88c2a28e1 100644 --- a/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp @@ -38,6 +38,7 @@ static std::function createFunctions[] = CL(NewClippingNodeTest), CL(NewDrawNodeTest), CL(NewCullingTest), + CL(VBOFullTest), }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -485,3 +486,32 @@ std::string NewCullingTest::subtitle() const return "Culling"; } +VBOFullTest::VBOFullTest() +{ + Size s = Director::getInstance()->getWinSize(); + Node* parent = Node::create(); + parent->setPosition(s.width/2, s.height/2); + addChild(parent); + + for (int i=0; isetPosition(Point(0,0)); + parent->addChild(sprite); + } +} + +VBOFullTest::~VBOFullTest() +{ + +} + +std::string VBOFullTest::title() const +{ + return "New Renderer"; +} + +std::string VBOFullTest::subtitle() const +{ + return "VBO full Test, everthing should render normally"; +} diff --git a/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.h b/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.h index 16604b55d1..caf133f7ff 100644 --- a/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.h +++ b/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.h @@ -118,4 +118,16 @@ protected: virtual ~NewCullingTest(); }; +class VBOFullTest : public MultiSceneTest +{ +public: + CREATE_FUNC(VBOFullTest); + virtual std::string title() const override; + virtual std::string subtitle() const override; + +protected: + VBOFullTest(); + virtual ~VBOFullTest(); +}; + #endif //__NewRendererTest_H_ diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp index 4d69c14542..290366c94c 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp @@ -67,6 +67,7 @@ static std::function createFunctions[] = CL(ConvertToNode), CL(NodeOpaqueTest), CL(NodeNonOpaqueTest), + CL(NodeGlobalZValueTest), }; #define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) @@ -905,6 +906,55 @@ std::string NodeNonOpaqueTest::subtitle() const return "Node rendered with GL_BLEND enabled"; } +/// NodeGlobalZValueTest + +NodeGlobalZValueTest::NodeGlobalZValueTest() +{ + Size s = Director::getInstance()->getWinSize(); + for (int i = 0; i < 9; i++) + { + Sprite *sprite; + auto parent = Node::create(); + if(i==4) { + sprite = Sprite::create("Images/grossinis_sister2.png"); + _sprite = sprite; + _sprite->setGlobalZOrder(-1); + } + else + sprite = Sprite::create("Images/grossinis_sister1.png"); + + parent->addChild(sprite); + this->addChild(parent); + + float w = sprite->getContentSize().width; + sprite->setPosition(s.width/2 - w*0.7*(i-5), s.height/2); + } + + this->scheduleUpdate(); +} + +void NodeGlobalZValueTest::update(float dt) +{ + static float accum = 0; + + accum += dt; + if( accum > 1) { + float z = _sprite->getGlobalZOrder(); + _sprite->setGlobalZOrder(-z); + accum = 0; + } +} + +std::string NodeGlobalZValueTest::title() const +{ + return "Global Z Value"; +} + +std::string NodeGlobalZValueTest::subtitle() const +{ + return "Center Sprite should change go from foreground to background"; +} + // // MySprite: Used by CameraTest1 and CameraTest2 @@ -932,7 +982,7 @@ protected: void MySprite::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(MySprite::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h index 2207c65f7c..334e2df08a 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h @@ -249,6 +249,20 @@ protected: NodeNonOpaqueTest(); }; +class NodeGlobalZValueTest : public TestCocosNodeDemo +{ +public: + CREATE_FUNC(NodeGlobalZValueTest); + virtual std::string title() const override; + virtual std::string subtitle() const override; + + virtual void update(float dt) override; + +protected: + NodeGlobalZValueTest(); + Sprite *_sprite; +}; + class CocosNodeTestScene : public TestScene { 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..7754582947 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.cpp @@ -0,0 +1,1369 @@ +/* + * + */ +#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), + CL(TemplateMapStringKeyPerfTest), + CL(DictionaryStringKeyPerfTest), + CL(TemplateMapIntKeyPerfTest), + CL(DictionaryIntKeyPerfTest) +}; + +#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::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); + } +} + +//////////////////////////////////////////////////////// +// +// TemplateMapStringKeyPerfTest +// +//////////////////////////////////////////////////////// + +void TemplateMapStringKeyPerfTest::generateTestFunctions() +{ + auto createMap = [this](){ + Map ret; + + for( int i=0; isetTag(i); + ret.insert(StringUtils::format("key_%d", i), node); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "insert", [=](){ + Map map; + + std::string* keys = new std::string[quantityOfNodes]; + + for (int i = 0; i < quantityOfNodes; ++i) + { + keys[i] = StringUtils::format("key_%d", i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CC_SAFE_DELETE_ARRAY(keys); + } } , + + { "at", [=](){ + Map map = createMap(); + + std::string* keys = new std::string[quantityOfNodes]; + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + for (int i = 0; i < quantityOfNodes; ++i) + { + keys[i] = StringUtils::format("key_%d", i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CC_SAFE_DELETE_ARRAY(keys); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i]->setTag(100); + } + + CC_SAFE_FREE(nodes); + } } , + + { "erase", [=](){ + auto map = createMap(); + + std::string* keys = new std::string[quantityOfNodes]; + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + for (int i = 0; i < quantityOfNodes; ++i) + { + keys[i] = StringUtils::format("key_%d", i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CC_SAFE_DELETE_ARRAY(keys); + + CC_SAFE_FREE(nodes); + } } , + + { "clear", [=](){ + auto map = createMap(); + + CC_PROFILER_START(this->profilerName()); + map.clear(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "size", [=](){ + auto map = createMap(); + + ssize_t size = 0; + CC_PROFILER_START(this->profilerName()); + size = map.size(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "keys(all)", [=](){ + auto map = createMap(); + + CC_PROFILER_START(this->profilerName()); + auto keys = map.keys(); + CC_PROFILER_STOP(this->profilerName()); + + std::string allKeysString; + for (const auto& key : keys) + { + allKeysString += "_" + key; + } + } } , + + { "keys(object)", [=](){ + Map map; + + Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes); + Node* sameNode = Node::create(); + + for( int i=0; isetTag(i); + map.insert(StringUtils::format("key_%d", i), node); + } + } + + CC_PROFILER_START(this->profilerName()); + auto keys = map.keys(sameNode); + CC_PROFILER_STOP(this->profilerName()); + + std::string allKeysString; + for (const auto& key : keys) + { + allKeysString += "_" + key; + } + + CC_SAFE_FREE(nodes); + } } , + + { "c++11 range loop", [=](){ + auto map = createMap(); + + CC_PROFILER_START(this->profilerName()); + + for (const auto& e : map) + { + e.second->setTag(100); + } + + CC_PROFILER_STOP(this->profilerName()); + } } , + + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + +std::string TemplateMapStringKeyPerfTest::title() const +{ + return "Map String Key Perf test"; +} + +std::string TemplateMapStringKeyPerfTest::subtitle() const +{ + return "Test 'insert', See console"; +} + +//////////////////////////////////////////////////////// +// +// DictionaryStringKeyPerfTest +// +//////////////////////////////////////////////////////// + +void DictionaryStringKeyPerfTest::generateTestFunctions() +{ + auto createDict = [this](){ + Dictionary* ret = Dictionary::create(); + + for( int i=0; isetTag(i); + ret->setObject(node, StringUtils::format("key_%d", i)); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "setObject", [=](){ + Dictionary* dict = Dictionary::create(); + + std::string* keys = new std::string[quantityOfNodes]; + + for (int i = 0; i < quantityOfNodes; ++i) + { + keys[i] = StringUtils::format("key_%d", i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; isetObject(Node::create(), keys[i]); + CC_PROFILER_STOP(this->profilerName()); + + CC_SAFE_DELETE_ARRAY(keys); + } } , + + { "objectForKey", [=](){ + auto dict = createDict(); + + std::string* keys = new std::string[quantityOfNodes]; + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + for (int i = 0; i < quantityOfNodes; ++i) + { + keys[i] = StringUtils::format("key_%d", i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; i(dict->objectForKey(keys[i])); + CC_PROFILER_STOP(this->profilerName()); + + CC_SAFE_DELETE_ARRAY(keys); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i]->setTag(100); + } + + CC_SAFE_FREE(nodes); + } } , + + { "removeObjectForKey", [=](){ + auto dict = createDict(); + + std::string* keys = new std::string[quantityOfNodes]; + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + for (int i = 0; i < quantityOfNodes; ++i) + { + keys[i] = StringUtils::format("key_%d", i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveObjectForKey(keys[i]); + CC_PROFILER_STOP(this->profilerName()); + + CC_SAFE_DELETE_ARRAY(keys); + + CC_SAFE_FREE(nodes); + } } , + + { "removeAllObjects", [=](){ + auto dict = createDict(); + + CC_PROFILER_START(this->profilerName()); + dict->removeAllObjects(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "count", [=](){ + auto dict = createDict(); + + ssize_t size = 0; + CC_PROFILER_START(this->profilerName()); + size = dict->count(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "allKeys", [=](){ + auto dict = createDict(); + + CC_PROFILER_START(this->profilerName()); + auto keys = dict->allKeys(); + CC_PROFILER_STOP(this->profilerName()); + + std::string allKeysString; + Object* obj; + CCARRAY_FOREACH(keys, obj) + { + auto key = static_cast(obj); + allKeysString += (std::string("_") + key->getCString()); + } + } } , + + { "allKeysForObject", [=](){ + Dictionary* dict = Dictionary::create(); + + Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes); + Node* sameNode = Node::create(); + + for( int i=0; isetObject(sameNode, StringUtils::format("key_%d", i)); + } + else + { + auto node = Node::create(); + node->setTag(i); + dict->setObject(node, StringUtils::format("key_%d", i)); + } + } + + CC_PROFILER_START(this->profilerName()); + auto keys = dict->allKeysForObject(sameNode); + CC_PROFILER_STOP(this->profilerName()); + + std::string allKeysString; + Object* obj; + CCARRAY_FOREACH(keys, obj) + { + auto key = static_cast(obj); + allKeysString += (std::string("_") + key->getCString()); + } + + CC_SAFE_FREE(nodes); + } } , + + { "CCDICT_FOREACH", [=](){ + auto dict = createDict(); + + CC_PROFILER_START(this->profilerName()); + + DictElement* e = nullptr; + CCDICT_FOREACH(dict, e) + { + static_cast(e->getObject())->setTag(100); + } + + CC_PROFILER_STOP(this->profilerName()); + } } , + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + +std::string DictionaryStringKeyPerfTest::title() const +{ + return "Dictionary String Key Perf test"; +} + +std::string DictionaryStringKeyPerfTest::subtitle() const +{ + return "Test `setObject`, See console"; +} + + +//////////////////////////////////////////////////////// +// +// TemplateMapIntKeyPerfTest +// +//////////////////////////////////////////////////////// + +void TemplateMapIntKeyPerfTest::generateTestFunctions() +{ + auto createMap = [this](){ + Map ret; + + for( int i=0; isetTag(i); + ret.insert(100+i, node); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "insert", [=](){ + Map map; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "at", [=](){ + auto map = createMap(); + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i]->setTag(100); + } + + CC_SAFE_FREE(nodes); + } } , + + { "erase", [=](){ + auto map = createMap(); + + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CC_SAFE_FREE(nodes); + } } , + + { "clear", [=](){ + auto map = createMap(); + + CC_PROFILER_START(this->profilerName()); + map.clear(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "size", [=](){ + auto map = createMap(); + + ssize_t size = 0; + CC_PROFILER_START(this->profilerName()); + size = map.size(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "keys(all)", [=](){ + auto map = createMap(); + + CC_PROFILER_START(this->profilerName()); + auto keys = map.keys(); + CC_PROFILER_STOP(this->profilerName()); + + int allKeysInt = 0; + for (const auto& key : keys) + { + allKeysInt += key; + } + } } , + + { "keys(object)", [=](){ + Map map; + + Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes); + Node* sameNode = Node::create(); + + for( int i=0; isetTag(i); + map.insert(100 + i, node); + } + } + + CC_PROFILER_START(this->profilerName()); + auto keys = map.keys(sameNode); + CC_PROFILER_STOP(this->profilerName()); + + int allKeysInt = 0; + for (const auto& key : keys) + { + allKeysInt += key; + } + + CC_SAFE_FREE(nodes); + } } , + + { "c++11 range loop", [=](){ + auto map = createMap(); + + CC_PROFILER_START(this->profilerName()); + + for (const auto& e : map) + { + e.second->setTag(100); + } + + CC_PROFILER_STOP(this->profilerName()); + } } , + + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + +std::string TemplateMapIntKeyPerfTest::title() const +{ + return "Map Integer Key Perf test"; +} + +std::string TemplateMapIntKeyPerfTest::subtitle() const +{ + return "Test 'insert', See console"; +} + +//////////////////////////////////////////////////////// +// +// DictionaryIntKeyPerfTest +// +//////////////////////////////////////////////////////// + +void DictionaryIntKeyPerfTest::generateTestFunctions() +{ + auto createDict = [this](){ + Dictionary* ret = Dictionary::create(); + + for( int i=0; isetTag(i); + ret->setObject(node, 100 + i); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "setObject", [=](){ + Dictionary* dict = Dictionary::create(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; isetObject(Node::create(), 100 + i); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "objectForKey", [=](){ + auto dict = createDict(); + + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; i(dict->objectForKey(100 + i)); + CC_PROFILER_STOP(this->profilerName()); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i]->setTag(100); + } + + CC_SAFE_FREE(nodes); + } } , + + { "removeObjectForKey", [=](){ + auto dict = createDict(); + + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveObjectForKey(100 + i); + CC_PROFILER_STOP(this->profilerName()); + + CC_SAFE_FREE(nodes); + } } , + + { "removeAllObjects", [=](){ + auto dict = createDict(); + + CC_PROFILER_START(this->profilerName()); + dict->removeAllObjects(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "count", [=](){ + auto dict = createDict(); + + unsigned int size = 0; + CC_PROFILER_START(this->profilerName()); + size = dict->count(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "allKeys", [=](){ + auto dict = createDict(); + + CC_PROFILER_START(this->profilerName()); + auto keys = dict->allKeys(); + CC_PROFILER_STOP(this->profilerName()); + + int allKeysInt = 0; + Object* obj; + CCARRAY_FOREACH(keys, obj) + { + auto key = static_cast(obj); + allKeysInt += key->getValue(); + } + } } , + + { "allKeysForObject", [=](){ + Dictionary* dict = Dictionary::create(); + + Node** nodes = (Node**) malloc(sizeof(Node*) * quantityOfNodes); + Node* sameNode = Node::create(); + + for( int i=0; isetObject(sameNode, 100 + i); + } + else + { + auto node = Node::create(); + node->setTag(i); + dict->setObject(node, 100 + i); + } + } + + CC_PROFILER_START(this->profilerName()); + auto keys = dict->allKeysForObject(sameNode); + CC_PROFILER_STOP(this->profilerName()); + + int allKeysInt = 0; + Object* obj; + CCARRAY_FOREACH(keys, obj) + { + auto key = static_cast(obj); + allKeysInt += key->getValue(); + } + + CC_SAFE_FREE(nodes); + } } , + + { "CCDICT_FOREACH", [=](){ + auto dict = createDict(); + + CC_PROFILER_START(this->profilerName()); + + DictElement* e = nullptr; + CCDICT_FOREACH(dict, e) + { + static_cast(e->getObject())->setTag(100); + } + + CC_PROFILER_STOP(this->profilerName()); + } } , + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + +std::string DictionaryIntKeyPerfTest::title() const +{ + return "Dictionary Integer Key Perf test"; +} + +std::string DictionaryIntKeyPerfTest::subtitle() const +{ + return "Test `setObject`, See console"; +} + + +///---------------------------------------- +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..603c759f76 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h @@ -0,0 +1,132 @@ +/* + * + */ +#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 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; +}; + +class TemplateMapStringKeyPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(TemplateMapStringKeyPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class DictionaryStringKeyPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(DictionaryStringKeyPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class TemplateMapIntKeyPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(TemplateMapIntKeyPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class DictionaryIntKeyPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(DictionaryIntKeyPerfTest); + + 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/PerformanceLabelTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp index 317bbb8a60..4c9f561b5d 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceLabelTest.cpp @@ -86,6 +86,7 @@ void LabelMainScene::initWithSubTest(int nodes) _lastRenderedCount = 0; _quantityNodes = 0; + _accumulativeTime = 0.0f; _labelContainer = Layer::create(); addChild(_labelContainer); @@ -212,15 +213,18 @@ void LabelMainScene::onIncrease(Object* sender) } break; case kCaseLabelUpdate: - for( int i=0;i< kNodesIncrease;i++) { - auto label = Label::createWithTTF("Label", "fonts/arial.ttf", 60, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr,true); - label->setPosition(Point((size.width/2 + rand() % 50), ((int)size.height/2 + rand() % 50))); - _labelContainer->addChild(label, 1, _quantityNodes); + TTFConfig ttfConfig("fonts/arial.ttf", 60, GlyphCollection::DYNAMIC, nullptr, true); + for( int i=0;i< kNodesIncrease;i++) + { + auto label = Label::createWithTTF(ttfConfig, "Label", TextHAlignment::CENTER, size.width); + label->setPosition(Point((size.width/2 + rand() % 50), ((int)size.height/2 + rand() % 50))); + _labelContainer->addChild(label, 1, _quantityNodes); - _quantityNodes++; - } - break; + _quantityNodes++; + } + break; + } case kCaseLabelBMFontBigLabels: for( int i=0;i< kNodesIncrease;i++) { @@ -232,15 +236,18 @@ void LabelMainScene::onIncrease(Object* sender) } break; case kCaseLabelBigLabels: - for( int i=0;i< kNodesIncrease;i++) { - auto label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 60, size.width, TextHAlignment::CENTER, GlyphCollection::DYNAMIC,nullptr); - label->setPosition(Point((rand() % 50), rand()%((int)size.height/3))); - _labelContainer->addChild(label, 1, _quantityNodes); + TTFConfig ttfConfig("fonts/arial.ttf", 60, GlyphCollection::DYNAMIC); + for( int i=0;i< kNodesIncrease;i++) + { + auto label = Label::createWithTTF(ttfConfig, LongSentencesExample, TextHAlignment::CENTER, size.width); + label->setPosition(Point((rand() % 50), rand()%((int)size.height/3))); + _labelContainer->addChild(label, 1, _quantityNodes); - _quantityNodes++; - } - break; + _quantityNodes++; + } + break; + } default: break; } @@ -330,7 +337,7 @@ void LabelMainScene::updateText(float dt) case kCaseLabelUpdate: for(const auto &child : children) { Label* label = (Label*)child; - label->setString(text,false); + label->setString(text); } break; default: diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceRendererTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceRendererTest.cpp new file mode 100644 index 0000000000..60031018c6 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceRendererTest.cpp @@ -0,0 +1,55 @@ +// +// PerformanceRendererTest.cpp +// cocos2d_samples +// +// Created by Huabing on 1/10/14. +// +// + +#include "PerformanceRendererTest.h" +#include "PerformanceTextureTest.h" +#include "../testResource.h" + +RenderTestLayer::RenderTestLayer() +: PerformBasicLayer(true, 1, 1) +{ +} + +RenderTestLayer::~RenderTestLayer() +{ +} + +Scene* RenderTestLayer::scene() +{ + auto scene = Scene::create(); + RenderTestLayer *layer = new RenderTestLayer(); + scene->addChild(layer); + layer->release(); + + return scene; +} + +void RenderTestLayer::onEnter() +{ + PerformBasicLayer::onEnter(); + auto map = TMXTiledMap::create("TileMaps/map/sl.tmx"); + + Size CC_UNUSED s = map->getContentSize(); + CCLOG("ContentSize: %f, %f", s.width,s.height); + + addChild(map,-1); + + //map->setAnchorPoint( Point(0, 0) ); + //map->setPosition( Point(-20,-200) ); +} + +void RenderTestLayer::showCurrentTest() +{ + +} + +void runRendererTest() +{ + auto scene = RenderTestLayer::scene(); + Director::getInstance()->replaceScene(scene); +} \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceRendererTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceRendererTest.h new file mode 100644 index 0000000000..07aeb4bc01 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceRendererTest.h @@ -0,0 +1,28 @@ +// +// PerformanceRendererTest.h +// cocos2d_samples +// +// Created by Huabing on 1/10/14. +// +// + +#ifndef __PERFORMANCE_RENDERER_TEST_H__ +#define __PERFORMANCE_RENDERER_TEST_H__ + +#include "PerformanceTest.h" + +class RenderTestLayer : public PerformBasicLayer +{ + +public: + RenderTestLayer(); + virtual ~RenderTestLayer(); + + virtual void onEnter() override; + virtual void showCurrentTest() override; +public: + static Scene* scene(); +}; + +void runRendererTest(); +#endif diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp index a9e6f78c94..0acc702e08 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp @@ -1,3 +1,30 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2011 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 "PerformanceSpriteTest.h" enum { @@ -21,144 +48,154 @@ enum { //////////////////////////////////////////////////////// SubTest::~SubTest() { - if (batchNode) - { - batchNode->release(); - batchNode = NULL; - } + _parentNode->release(); } -void SubTest::initWithSubTest(int nSubTest, Node* p) +void SubTest::initWithSubTest(int subtest, Node* p) { - subtestNumber = nSubTest; - parent = p; - batchNode = NULL; + srand(0); + + subtestNumber = subtest; + _parentNode = nullptr; /* - * Tests: - * 1: 1 (32-bit) PNG sprite of 52 x 139 - * 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139 + * Tests: + * 1: 1 (32-bit) PNG sprite of 52 x 139 + * 2: 1 (32-bit) PNG sprite of 52 x 139 (same as 1) + * 3: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139 + * 4: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139 - * 5: 14 (32-bit) PNG sprites of 85 x 121 each - * 6: 14 (32-bit) PNG Batch Node of 85 x 121 each - * 7: 14 (16-bit) PNG Batch Node of 85 x 121 each - * 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each + * 5: 14 (32-bit) PNG sprites of 85 x 121 each + * 6: 14 (32-bit) PNG sprites of 85 x 121 each that belong to on texture atlas + * 7: 14 (32-bit) PNG Batch Node of 85 x 121 each + * 8: 14 (16-bit) PNG Batch Node of 85 x 121 each - * 9: 64 (32-bit) sprites of 32 x 32 each - *10: 64 (32-bit) PNG Batch Node of 32 x 32 each - *11: 64 (16-bit) PNG Batch Node of 32 x 32 each - *12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each + * 9: 64 (32-bit) sprites of 32 x 32 each + *10: 64 (32-bit) sprites of 32 x 32 each that belong to on texture atlas + *11: 64 (32-bit) PNG Batch Node of 32 x 32 each + *12: 64 (16-bit) PNG Batch Node of 32 x 32 each */ // purge textures auto mgr = Director::getInstance()->getTextureCache(); - // [mgr removeAllTextures]; - mgr->removeTexture(mgr->addImage("Images/grossinis_sister1.png")); - mgr->removeTexture(mgr->addImage("Images/grossini_dance_atlas.png")); - mgr->removeTexture(mgr->addImage("Images/spritesheet1.png")); + mgr->removeTextureForKey("Images/grossinis_sister1.png"); + mgr->removeTextureForKey("Images/grossini_dance_atlas.png"); + mgr->removeTextureForKey("Images/spritesheet1.png"); switch ( subtestNumber) { - case 1: - case 4: - case 7: - break; /// + case 1: case 2: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100); - p->addChild(batchNode, 0); + _parentNode = Node::create(); break; case 3: + Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + _parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100); + break; + case 4: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); - batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100); - p->addChild(batchNode, 0); + _parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100); break; /// case 5: - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); - p->addChild(batchNode, 0); - break; case 6: + Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + _parentNode = Node::create(); + break; + case 7: + Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + _parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); + break; + case 8: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); - batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); - p->addChild(batchNode, 0); + _parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); break; /// - case 8: - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100); - p->addChild(batchNode, 0); - break; case 9: + case 10: + Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + _parentNode = Node::create(); + break; + case 11: + Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + _parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100); + break; + case 12: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); - batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100); - p->addChild(batchNode, 0); + _parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100); + break; + + /// + case 13: + Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); + _parentNode = Node::create(); break; default: break; } - if (batchNode) - { - batchNode->retain(); - } - - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); + p->addChild(_parentNode); + _parentNode->retain(); } Sprite* SubTest::createSpriteWithTag(int tag) { - // create - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + TextureCache *cache = Director::getInstance()->getTextureCache(); Sprite* sprite = NULL; switch (subtestNumber) { + /// case 1: - { - sprite = Sprite::create("Images/grossinis_sister1.png"); - parent->addChild(sprite, 0, tag+100); - break; - } case 2: - case 3: - { - sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0, 0, 52, 139)); - batchNode->addChild(sprite, 0, tag+100); - break; - } + { + sprite = Sprite::create("Images/grossinis_sister1.png"); + _parentNode->addChild(sprite, 0, tag+100); + break; + } + case 3: case 4: - { - int idx = (CCRANDOM_0_1() * 1400 / 100) + 1; - char str[32] = {0}; - sprintf(str, "Images/grossini_dance_%02d.png", idx); - sprite = Sprite::create(str); - parent->addChild(sprite, 0, tag+100); - break; - } + { + Texture2D *texture = cache->addImage("Images/grossinis_sister1.png"); + sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139)); + _parentNode->addChild(sprite, 0, tag+100); + break; + } + + /// case 5: + { + int idx = (CCRANDOM_0_1() * 1400 / 100) + 1; + char str[32] = {0}; + sprintf(str, "Images/grossini_dance_%02d.png", idx); + sprite = Sprite::create(str); + _parentNode->addChild(sprite, 0, tag+100); + break; + } case 6: - { - int y,x; - int r = (CCRANDOM_0_1() * 1400 / 100); - - y = r / 5; - x = r % 5; - - x *= 85; - y *= 121; - sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(x,y,85,121)); - batchNode->addChild(sprite, 0, tag+100); - break; - } - case 7: + case 8: + { + int y,x; + int r = (CCRANDOM_0_1() * 1400 / 100); + + y = r / 5; + x = r % 5; + + x *= 85; + y *= 121; + Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png"); + sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121)); + _parentNode->addChild(sprite, 0, tag+100); + break; + } + + /// + case 9: { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); @@ -169,12 +206,54 @@ Sprite* SubTest::createSpriteWithTag(int tag) char str[40] = {0}; sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y); sprite = Sprite::create(str); - parent->addChild(sprite, 0, tag+100); + _parentNode->addChild(sprite, 0, tag+100); break; } - case 8: - case 9: + case 10: + case 11: + case 12: + { + int y,x; + int r = (CCRANDOM_0_1() * 6400 / 100); + + y = r / 8; + x = r % 8; + + x *= 32; + y *= 32; + Texture2D *texture = cache->addImage("Images/spritesheet1.png"); + sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32))); + _parentNode->addChild(sprite, 0, tag+100); + break; + } + /// + case 13: + { + int test = (CCRANDOM_0_1() * 3); + + if(test==0) { + // Switch case 1 + sprite = Sprite::create("Images/grossinis_sister1.png"); + _parentNode->addChild(sprite, 0, tag+100); + } + else if(test==1) + { + // Switch case 6 + int y,x; + int r = (CCRANDOM_0_1() * 1400 / 100); + + y = r / 5; + x = r % 5; + + x *= 85; + y *= 121; + Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png"); + sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121)); + _parentNode->addChild(sprite, 0, tag+100); + + } + else if(test==2) { int y,x; int r = (CCRANDOM_0_1() * 6400 / 100); @@ -184,41 +263,22 @@ Sprite* SubTest::createSpriteWithTag(int tag) x *= 32; y *= 32; - sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(x,y,32,32)); - batchNode->addChild(sprite, 0, tag+100); - break; + Texture2D *texture = cache->addImage("Images/spritesheet1.png"); + sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32))); + _parentNode->addChild(sprite, 0, tag+100); } + } default: break; } - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); - return sprite; } void SubTest::removeByTag(int tag) { - switch (subtestNumber) - { - case 1: - case 4: - case 7: - parent->removeChildByTag(tag+100, true); - break; - case 2: - case 3: - case 5: - case 6: - case 8: - case 9: - batchNode->removeChildAtIndex(tag, true); - // [batchNode removeChildByTag:tag+100 cleanup:YES]; - break; - default: - break; - } + _parentNode->removeChildByTag(tag+100, true); } //////////////////////////////////////////////////////// @@ -365,9 +425,9 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) addChild( menuAutoTest, 3, kTagAutoTestMenu ); // Sub Tests - MenuItemFont::setFontSize(32); + MenuItemFont::setFontSize(28); auto subMenu = Menu::create(); - for (int i = 1; i <= 9; ++i) + for (int i = 1; i <= 13; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); @@ -375,12 +435,14 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) itemFont->setTag(i); subMenu->addChild(itemFont, 10); - if( i<= 3) + if( i<= 4) itemFont->setColor(Color3B(200,20,20)); - else if(i <= 6) + else if(i <= 8) itemFont->setColor(Color3B(0,200,20)); - else + else if( i<=12) itemFont->setColor(Color3B(0,20,200)); + else + itemFont->setColor(Color3B::GRAY); } subMenu->alignItemsHorizontally(); @@ -388,11 +450,21 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) addChild(subMenu, 2); // add title label - auto label = LabelTTF::create(title().c_str(), "Arial", 40); + auto label = LabelTTF::create(title(), "Arial", 40); addChild(label, 1); label->setPosition(Point(s.width/2, s.height-32)); label->setColor(Color3B(255,255,40)); + + // subtitle + std::string strSubtitle = subtitle(); + if( ! strSubtitle.empty() ) + { + auto l = LabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); + addChild(l, 9999); + l->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) ); + } + while(quantityNodes < nNodes) onIncrease(this); } @@ -402,6 +474,12 @@ std::string SpriteMainScene::title() const return "No title"; } +std::string SpriteMainScene::subtitle() const +{ + return ""; // override me +} + + SpriteMainScene::~SpriteMainScene() { if (_subTest) @@ -761,6 +839,12 @@ std::string SpritePerformTest1::title() const return strRet; } +std::string SpritePerformTest1::subtitle() const +{ + return "test 1"; +} + + void SpritePerformTest1::doTest(Sprite* sprite) { performancePosition(sprite); @@ -778,6 +862,11 @@ std::string SpritePerformTest2::title() const return strRet; } +std::string SpritePerformTest2::subtitle() const +{ + return "test 2"; +} + void SpritePerformTest2::doTest(Sprite* sprite) { performanceScale(sprite); @@ -796,6 +885,11 @@ std::string SpritePerformTest3::title() const return strRet; } +std::string SpritePerformTest3::subtitle() const +{ + return "test 3"; +} + void SpritePerformTest3::doTest(Sprite* sprite) { performanceRotationScale(sprite); @@ -814,6 +908,11 @@ std::string SpritePerformTest4::title() const return strRet; } +std::string SpritePerformTest4::subtitle() const +{ + return "test 4"; +} + void SpritePerformTest4::doTest(Sprite* sprite) { performanceOut100(sprite); @@ -832,6 +931,11 @@ std::string SpritePerformTest5::title() const return strRet; } +std::string SpritePerformTest5::subtitle() const +{ + return "test 5"; +} + void SpritePerformTest5::doTest(Sprite* sprite) { performanceout20(sprite); @@ -850,6 +954,11 @@ std::string SpritePerformTest6::title() const return strRet; } +std::string SpritePerformTest6::subtitle() const +{ + return "test 6"; +} + void SpritePerformTest6::doTest(Sprite* sprite) { performanceActions(sprite); @@ -868,6 +977,11 @@ std::string SpritePerformTest7::title() const return strRet; } +std::string SpritePerformTest7::subtitle() const +{ + return "test 7"; +} + void SpritePerformTest7::doTest(Sprite* sprite) { performanceActions20(sprite); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h index 9fb0993441..0aa21356c7 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h @@ -1,3 +1,30 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2011 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 __PERFORMANCE_SPRITE_TEST_H__ #define __PERFORMANCE_SPRITE_TEST_H__ @@ -12,9 +39,8 @@ public: void initWithSubTest(int nSubTest, Node* parent); protected: - int subtestNumber; - SpriteBatchNode *batchNode; - Node* parent; + int subtestNumber; + Node *_parentNode; }; class SpriteMenuLayer : public PerformBasicLayer @@ -36,6 +62,7 @@ class SpriteMainScene : public Scene public: virtual ~SpriteMainScene(); virtual std::string title() const; + virtual std::string subtitle() const; void initWithSubTest(int nSubTest, int nNodes); void updateNodes(); @@ -53,23 +80,25 @@ public: virtual void onExit(); void updateAutoTest(float dt); void onAutoTest(Object* sender); -private: + + static bool _s_autoTest; + static int _s_nSpriteCurCase; + +protected: void dumpProfilerFPS(); void beginAutoTest(); void endAutoTest(); void nextAutoTest(); void finishAutoTest(); void autoShowSpriteTests(int curCase, int subTest,int nodes); -public: - static bool _s_autoTest; - static int _s_nSpriteCurCase; -protected: + int lastRenderedCount; int quantityNodes; SubTest *_subTest; int subtestNumber; std::vector _vecFPS; int _executeTimes; + static const int MAX_AUTO_TEST_TIMES = 25; static const int MAX_SPRITE_TEST_CASE = 7; static const int MAX_SUB_TEST_NUMS = 9; @@ -80,50 +109,57 @@ protected: class SpritePerformTest1 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; class SpritePerformTest2 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; class SpritePerformTest3 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; class SpritePerformTest4 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; class SpritePerformTest5 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; class SpritePerformTest6 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; class SpritePerformTest7 : public SpriteMainScene { public: - virtual void doTest(Sprite* sprite); + virtual void doTest(Sprite* sprite) override; virtual std::string title() const override; + virtual std::string subtitle() const override; }; void runSpriteTest(); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp index e48ef17f28..7884aec8d3 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp @@ -7,6 +7,8 @@ #include "PerformanceTouchesTest.h" #include "PerformanceAllocTest.h" #include "PerformanceLabelTest.h" +#include "PerformanceRendererTest.h" +#include "PerformanceContainerTest.h" enum { @@ -26,6 +28,8 @@ struct { { "Texture Perf Test",[](Object*sender){runTextureTest();} }, { "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]); @@ -41,18 +45,83 @@ void PerformanceMainLayer::onEnter() auto s = Director::getInstance()->getWinSize(); - auto menu = Menu::create(); - menu->setPosition( Point::ZERO ); + _itemMenu = Menu::create(); + _itemMenu->setPosition( Point::ZERO ); MenuItemFont::setFontName("Arial"); MenuItemFont::setFontSize(24); for (int i = 0; i < g_testMax; ++i) { auto pItem = MenuItemFont::create(g_testsName[i].name, g_testsName[i].callback); pItem->setPosition(Point(s.width / 2, s.height - (i + 1) * LINE_SPACE)); - menu->addChild(pItem, kItemTagBasic + i); + _itemMenu->addChild(pItem, kItemTagBasic + i); } - addChild(menu); + addChild(_itemMenu); + + // Register Touch Event + auto listener = EventListenerTouchOneByOne::create(); + listener->setSwallowTouches(true); + + listener->onTouchBegan = CC_CALLBACK_2(PerformanceMainLayer::onTouchBegan, this); + listener->onTouchMoved = CC_CALLBACK_2(PerformanceMainLayer::onTouchMoved, this); + + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + + auto mouseListener = EventListenerMouse::create(); + mouseListener->onMouseScroll = CC_CALLBACK_1(PerformanceMainLayer::onMouseScroll, this); + _eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this); +} + +bool PerformanceMainLayer::onTouchBegan(Touch* touches, Event *event) +{ + _beginPos = touches->getLocation(); + return true; +} +void PerformanceMainLayer::onTouchMoved(Touch* touches, Event *event) +{ + auto touchLocation = touches->getLocation(); + float nMoveY = touchLocation.y - _beginPos.y; + + auto curPos = _itemMenu->getPosition(); + auto nextPos = Point(curPos.x, curPos.y + nMoveY); + + if (nextPos.y < 0.0f) + { + _itemMenu->setPosition(Point::ZERO); + return; + } + + if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) + { + _itemMenu->setPosition(Point(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))); + return; + } + + _itemMenu->setPosition(nextPos); + _beginPos = touchLocation; +} + +void PerformanceMainLayer::onMouseScroll(Event *event) +{ + auto mouseEvent = static_cast(event); + float nMoveY = mouseEvent->getScrollY() * 6; + + auto curPos = _itemMenu->getPosition(); + auto nextPos = Point(curPos.x, curPos.y + nMoveY); + + if (nextPos.y < 0.0f) + { + _itemMenu->setPosition(Point::ZERO); + return; + } + + if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)) + { + _itemMenu->setPosition(Point(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))); + return; + } + + _itemMenu->setPosition(nextPos); } //////////////////////////////////////////////////////// diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h index 7d4766de30..f06a3c9bbd 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h @@ -7,6 +7,14 @@ class PerformanceMainLayer : public Layer { public: virtual void onEnter(); + + bool onTouchBegan(Touch* touches, Event *event); + void onTouchMoved(Touch* touches, Event *event); + + void onMouseScroll(Event *event); +protected: + Point _beginPos; + Menu* _itemMenu; }; class PerformBasicLayer : public Layer diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index 9a18f256be..e893f707f7 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -470,19 +470,19 @@ RenderTextureTestDepthStencil::~RenderTextureTestDepthStencil() void RenderTextureTestDepthStencil::draw() { - _renderCmds[0].init(0, _vertexZ); + _renderCmds[0].init(_globalZOrder); _renderCmds[0].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforeClear, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[0]); _rend->beginWithClear(0, 0, 0, 0, 0, 0); - _renderCmds[1].init(0, _vertexZ); + _renderCmds[1].init(_globalZOrder); _renderCmds[1].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforeStencil, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[1]); _spriteDS->visit(); - _renderCmds[2].init(0, _vertexZ); + _renderCmds[2].init(_globalZOrder); _renderCmds[2].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onBeforDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[2]); @@ -490,7 +490,7 @@ void RenderTextureTestDepthStencil::draw() _rend->end(); - _renderCmds[3].init(0, _vertexZ); + _renderCmds[3].init(_globalZOrder); _renderCmds[3].func = CC_CALLBACK_0(RenderTextureTestDepthStencil::onAfterDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmds[3]); @@ -638,7 +638,7 @@ SpriteRenderTextureBug::SimpleSprite* SpriteRenderTextureBug::SimpleSprite::crea void SpriteRenderTextureBug::SimpleSprite::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(SpriteRenderTextureBug::SimpleSprite::onBeforeDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index ba6c1f01c1..443a24d681 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -193,7 +193,7 @@ void ShaderNode::setPosition(const Point &newPosition) void ShaderNode::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ShaderNode::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } @@ -526,7 +526,7 @@ void SpriteBlur::initProgram() void SpriteBlur::draw() { - _customCommand.init(0, _vertexZ); + _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(SpriteBlur::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_customCommand); } diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index 569bef3915..e8207b4cb4 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -178,7 +178,7 @@ void ShaderSprite::initShader() void ShaderSprite::draw() { - _renderCommand.init(0, _vertexZ); + _renderCommand.init(_globalZOrder); _renderCommand.func = CC_CALLBACK_0(ShaderSprite::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCommand); diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp index 95bcb47323..a4121f8825 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp @@ -150,18 +150,20 @@ void TextureDemo::onEnter() { BaseTest::onEnter(); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + auto textureCache = Director::getInstance()->getTextureCache(); + log("%s\n", textureCache->getCachedTextureInfo().c_str()); auto col = LayerColor::create(Color4B(128,128,128,255)); addChild(col, -10); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", textureCache->getCachedTextureInfo().c_str()); } TextureDemo::~TextureDemo() { - Director::getInstance()->getTextureCache()->removeUnusedTextures(); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + auto textureCache = Director::getInstance()->getTextureCache(); + textureCache->removeUnusedTextures(); + log("%s\n", textureCache->getCachedTextureInfo().c_str()); } void TextureDemo::restartCallback(Object* sender) @@ -209,7 +211,8 @@ void TextureTIFF::onEnter() auto img = Sprite::create("Images/test_image.tiff"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); this->addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureTIFF::title() const @@ -232,7 +235,7 @@ void TextureTGA::onEnter() auto img = Sprite::create("TileMaps/levelmap.tga"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); this->addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureTGA::title() const @@ -254,7 +257,7 @@ void TexturePNG::onEnter() auto img = Sprite::create("Images/test_image.png"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePNG::title() const @@ -275,7 +278,7 @@ void TextureJPEG::onEnter() auto img = Sprite::create("Images/test_image.jpeg"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureJPEG::title() const @@ -296,7 +299,7 @@ void TextureWEBP::onEnter() auto img = Sprite::create("Images/test_image.webp"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureWEBP::title() const @@ -340,7 +343,7 @@ void TextureMipMap::onEnter() img0->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL))); img1->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL))); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureMipMap::title() const @@ -391,7 +394,7 @@ void TexturePVRMipMap::onEnter() imgMipMap->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL))); img->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL))); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRMipMap::title() const @@ -433,7 +436,7 @@ void TexturePVRMipMap2::onEnter() imgMipMap->runAction(RepeatForever::create(Sequence::create(scale1, sc_back, NULL))); img->runAction(RepeatForever::create(Sequence::create(scale2, sc_back2, NULL))); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRMipMap2::title() const @@ -465,7 +468,7 @@ void TexturePVR2BPP::onEnter() img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVR2BPP::title() const @@ -496,8 +499,8 @@ void TexturePVRTest::onEnter() { log("This test is not supported."); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); - + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); + } std::string TexturePVRTest::title() const @@ -528,7 +531,7 @@ void TexturePVR4BPP::onEnter() { log("This test is not supported in cocos2d-mac"); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVR4BPP::title() const @@ -551,7 +554,7 @@ void TexturePVRRGBA8888::onEnter() auto img = Sprite::create("Images/test_image_rgba8888.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA8888::title() const @@ -581,7 +584,7 @@ void TexturePVRBGRA8888::onEnter() { log("BGRA8888 images are not supported"); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRBGRA8888::title() const @@ -604,7 +607,7 @@ void TexturePVRRGBA5551::onEnter() auto img = Sprite::create("Images/test_image_rgba5551.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA5551::title() const @@ -627,7 +630,7 @@ void TexturePVRRGBA4444::onEnter() auto img = Sprite::create("Images/test_image_rgba4444.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA4444::title() const @@ -655,7 +658,7 @@ void TexturePVRRGBA4444GZ::onEnter() #endif img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA4444GZ::title() const @@ -683,7 +686,7 @@ void TexturePVRRGBA4444CCZ::onEnter() auto img = Sprite::create("Images/test_image_rgba4444.pvr.ccz"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA4444CCZ::title() const @@ -711,7 +714,7 @@ void TexturePVRRGB565::onEnter() auto img = Sprite::create("Images/test_image_rgb565.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGB565::title() const @@ -734,7 +737,7 @@ void TexturePVRRGB888::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGB888::title() const @@ -757,7 +760,7 @@ void TexturePVRA8::onEnter() auto img = Sprite::create("Images/test_image_a8.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } @@ -781,7 +784,7 @@ void TexturePVRI8::onEnter() auto img = Sprite::create("Images/test_image_i8.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRI8::title() const @@ -804,7 +807,7 @@ void TexturePVRAI88::onEnter() auto img = Sprite::create("Images/test_image_ai88.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRAI88::title() const @@ -826,7 +829,7 @@ void TexturePVR2BPPv3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVR2BPPv3::title() const @@ -853,7 +856,7 @@ void TexturePVRII2BPPv3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRII2BPPv3::title() const @@ -884,7 +887,7 @@ void TexturePVR4BPPv3::onEnter() log("This test is not supported"); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVR4BPPv3::title() const @@ -919,7 +922,7 @@ void TexturePVRII4BPPv3::onEnter() log("This test is not supported"); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRII4BPPv3::title() const @@ -946,7 +949,7 @@ void TexturePVRRGBA8888v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA8888v3::title() const @@ -977,7 +980,7 @@ void TexturePVRBGRA8888v3::onEnter() log("BGRA images are not supported"); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRBGRA8888v3::title() const @@ -1004,7 +1007,7 @@ void TexturePVRRGBA5551v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA5551v3::title() const @@ -1031,7 +1034,7 @@ void TexturePVRRGBA4444v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGBA4444v3::title() const @@ -1058,7 +1061,7 @@ void TexturePVRRGB565v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGB565v3::title() const @@ -1085,7 +1088,7 @@ void TexturePVRRGB888v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRRGB888v3::title() const @@ -1112,7 +1115,7 @@ void TexturePVRA8v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRA8v3::title() const @@ -1139,7 +1142,7 @@ void TexturePVRI8v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRI8v3::title() const @@ -1166,7 +1169,7 @@ void TexturePVRAI88v3::onEnter() addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRAI88v3::title() const @@ -1222,7 +1225,7 @@ void TexturePVRNonSquare::onEnter() auto img = Sprite::create("Images/grossini_128x256_mipmap.pvr"); img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRNonSquare::title() const @@ -1251,7 +1254,7 @@ void TexturePVRNPOT4444::onEnter() img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRNPOT4444::title() const @@ -1280,7 +1283,7 @@ void TexturePVRNPOT8888::onEnter() img->setPosition(Point( s.width/2.0f, s.height/2.0f)); addChild(img); } - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePVRNPOT8888::title() const @@ -1334,7 +1337,7 @@ void TextureAlias::onEnter() sprite2->runAction(scaleforever); sprite->runAction(scaleToo); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureAlias::title() const @@ -1439,7 +1442,7 @@ void TexturePixelFormat::onEnter() // restore default Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TexturePixelFormat::title() const @@ -1791,7 +1794,7 @@ void TextureDrawAtPoint::draw() { TextureDemo::draw(); - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TextureDrawAtPoint::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); @@ -1832,7 +1835,7 @@ void TextureDrawInRect::draw() { TextureDemo::draw(); - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TextureDrawInRect::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); @@ -2222,7 +2225,7 @@ void TextureConvertRGB888::onEnter() // restore default Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureConvertRGB888::title() const @@ -2256,7 +2259,7 @@ void TextureConvertRGBA8888::onEnter() // restore default Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureConvertRGBA8888::title() const @@ -2290,7 +2293,7 @@ void TextureConvertI8::onEnter() // restore default Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureConvertI8::title() const @@ -2324,7 +2327,7 @@ void TextureConvertAI88::onEnter() // restore default Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT); - Director::getInstance()->getTextureCache()->dumpCachedTextureInfo(); + log("%s\n", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } std::string TextureConvertAI88::title() const diff --git a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp index 75f0fd6eee..1b45442fd5 100644 --- a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp +++ b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp @@ -599,7 +599,7 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest() void TMXOrthoObjectsTest::draw() { - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TMXOrthoObjectsTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -672,7 +672,7 @@ TMXIsoObjectsTest::TMXIsoObjectsTest() void TMXIsoObjectsTest::draw() { - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TMXIsoObjectsTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } @@ -1504,7 +1504,7 @@ TMXGIDObjectsTest::TMXGIDObjectsTest() void TMXGIDObjectsTest::draw() { - _renderCmd.init(0, _vertexZ); + _renderCmd.init(_globalZOrder); _renderCmd.func = CC_CALLBACK_0(TMXGIDObjectsTest::onDraw, this); Director::getInstance()->getRenderer()->addCommand(&_renderCmd); } diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index 750ba02a9f..b9713167a1 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -151,7 +151,6 @@ TestController::~TestController() void TestController::menuCallback(Object * sender) { - Director::getInstance()->purgeCachedData(); // get the userdata, it's the index of the menu item clicked diff --git a/samples/Cpp/TestCpp/Resources/TileMaps/map/slcj.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/TileMaps/map/slcj.png.REMOVED.git-id new file mode 100644 index 0000000000..c7ca23a772 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/TileMaps/map/slcj.png.REMOVED.git-id @@ -0,0 +1 @@ +64ce8a88d0dee73cf5d9fbb8f3c80673c82b9575 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/proj.android/AndroidManifest.xml b/samples/Cpp/TestCpp/proj.android/AndroidManifest.xml index 48c245c963..2d00af9411 100644 --- a/samples/Cpp/TestCpp/proj.android/AndroidManifest.xml +++ b/samples/Cpp/TestCpp/proj.android/AndroidManifest.xml @@ -14,7 +14,7 @@ android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" - android:configChanges="orientation|screenSize|smallestScreenSize"> + android:configChanges="orientation"> + + @@ -331,7 +333,10 @@ 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 a6990872b6..5cfe11e6c9 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -715,6 +715,12 @@ Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode + + Classes\PerformanceTest + + + Classes\PerformanceTest + @@ -1318,5 +1324,14 @@ Classes\ExtensionsTest\CocoStudioSceneTest\TriggerCode + + Classes\PerformanceTest + + + Classes\PerformanceTest + + + Classes\PerformanceTest + \ No newline at end of file diff --git a/samples/Javascript/CocosDragonJS/proj.android/AndroidManifest.xml b/samples/Javascript/CocosDragonJS/proj.android/AndroidManifest.xml index fb10a9db77..a215673a7c 100644 --- a/samples/Javascript/CocosDragonJS/proj.android/AndroidManifest.xml +++ b/samples/Javascript/CocosDragonJS/proj.android/AndroidManifest.xml @@ -14,7 +14,7 @@ android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" - android:configChanges="orientation|screenSize|smallestScreenSize"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> (dict:objectForKey("x")):getNumber() + local x = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("x")):getNumber() key = "y" - local y = (tolua.cast(dict:objectForKey(key), "String")):intValue()--dynamic_cast(dict:objectForKey("y")):getNumber() + local y = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("y")):getNumber() key = "width" - local width = (tolua.cast(dict:objectForKey(key), "String")):intValue()--dynamic_cast(dict:objectForKey("width")):getNumber() + local width = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("width")):getNumber() key = "height" - local height = (tolua.cast(dict:objectForKey(key), "String")):intValue()--dynamic_cast(dict:objectForKey("height")):getNumber() + local height = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("height")):getNumber() glLineWidth(3) @@ -1081,7 +1081,7 @@ local function TMXOrthoFlipTest() local i = 0 for i = 0, table.getn(map:getChildren())-1, 1 do - local child = tolua.cast(map:getChildren()[i + 1], "SpriteBatchNode") + local child = tolua.cast(map:getChildren()[i + 1], "cc.SpriteBatchNode") child:getTexture():setAntiAliasTexParameters() end @@ -1106,7 +1106,7 @@ local function TMXOrthoFlipRunTimeTest() local i = 0 for i = 0, table.getn(map:getChildren())-1, 1 do - local child = tolua.cast(map:getChildren()[i + 1], "SpriteBatchNode") + local child = tolua.cast(map:getChildren()[i + 1], "cc.SpriteBatchNode") child:getTexture():setAntiAliasTexParameters() end @@ -1186,7 +1186,7 @@ local function TMXOrthoFromXMLTest() local i = 0 local len = table.getn(map:getChildren()) for i = 0, len-1, 1 do - local child = tolua.cast(map:getChildren()[i + 1], "SpriteBatchNode") + local child = tolua.cast(map:getChildren()[i + 1], "cc.SpriteBatchNode") child:getTexture():setAntiAliasTexParameters() end @@ -1214,7 +1214,7 @@ local function TMXBug987() local len = table.getn(childs) local pNode = nil for i = 0, len-1, 1 do - pNode = tolua.cast(childs[i + 1], "TMXLayer") + pNode = tolua.cast(childs[i + 1], "cc.TMXLayer") if pNode == nil then break end diff --git a/samples/Lua/TestLua/Resources/luaScript/XMLHttpRequestTest/XMLHttpRequestTest.lua b/samples/Lua/TestLua/Resources/luaScript/XMLHttpRequestTest/XMLHttpRequestTest.lua index 1cdffa035a..4bec50a734 100644 --- a/samples/Lua/TestLua/Resources/luaScript/XMLHttpRequestTest/XMLHttpRequestTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/XMLHttpRequestTest/XMLHttpRequestTest.lua @@ -22,7 +22,7 @@ local function XMLHttpRequestLayer() --Get local function onMenuGetClicked() - local xhr = XMLHttpRequest:new() + local xhr = cc.XMLHttpRequest:new() xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_STRING xhr:open("GET", "http://httpbin.org/get") @@ -46,7 +46,7 @@ local function XMLHttpRequestLayer() --Post local function onMenuPostClicked() - local xhr = XMLHttpRequest:new() + local xhr = cc.XMLHttpRequest:new() xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_STRING xhr:open("POST", "http://httpbin.org/post") local function onReadyStateChange() @@ -67,7 +67,7 @@ local function XMLHttpRequestLayer() --Post Binary local function onMenuPostBinaryClicked() - local xhr = XMLHttpRequest:new() + local xhr = cc.XMLHttpRequest:new() xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_ARRAY_BUFFER xhr:open("POST", "http://httpbin.org/post") @@ -102,7 +102,7 @@ local function XMLHttpRequestLayer() --Post Json local function onMenuPostJsonClicked() - local xhr = XMLHttpRequest:new() + local xhr = cc.XMLHttpRequest:new() xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_JSON xhr:open("POST", "http://httpbin.org/post") diff --git a/samples/Lua/TestLua/proj.android/AndroidManifest.xml b/samples/Lua/TestLua/proj.android/AndroidManifest.xml index 5eb27de989..430e935659 100644 --- a/samples/Lua/TestLua/proj.android/AndroidManifest.xml +++ b/samples/Lua/TestLua/proj.android/AndroidManifest.xml @@ -14,7 +14,7 @@ android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" - android:configChanges="orientation|screenSize|smallestScreenSize"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation">