diff --git a/AUTHORS b/AUTHORS index fd5cf6a651..04d52c0ee3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -718,6 +718,9 @@ Developers: Pisces000221 Corrected a few mistakes in the README file of project-creator. + + hbbalfred + Fixed a bug that crash if file doesn't exist when using FileUtils::getStringFromFile. Retired Core Developers: WenSheng Yang diff --git a/CHANGELOG b/CHANGELOG index da8bce53e1..fe1e346007 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,15 @@ cocos2d-x-3.0final ?.? ? [All] - [NEW] Label: Uses a struct of TTF configuration for Label::createWithTTF to reduce parameters and make this interface more easily to use. - [NEW] Console: added the 'textures', 'fileutils dump' and 'config' commands [NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier. + [NEW] 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] Renderer: Added BatchCommand. This command is not "batchable" with other commands, but improves performance in about 10% + + [FIX] CocoStudio: TestColliderDetector in ArmatureTest can't work. + [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. @@ -11,9 +17,10 @@ cocos2d-x-3.0final ?.? ? [FIX] Particles: Crash was triggered if there is not `textureFileName`section in particle plist file. [FIX] Renderer: QuadCommand::init() does not copy the Quads, it only store a reference making the code faster [FIX] Renderer: Performance improved in Sprite and SpriteBatchNode (and subclasses) sprites in about 20% + [FIX] Renderer: When note using VAO, call glBufferData() instead of glBufferSubData(). [FIX] Sprite: removed _hasChildren optimization. It uses !_children.empty() now which is super fast as well [FIX] Tests: TestCpp works with CMake on Windows. - [FIX] Tests: Sprites Performance Test has 3 new tests + [FIX] 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. diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index e14906c550..b052741ae6 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -88c095bbe123ab56df3f7870692c6631f4464c8d \ No newline at end of file +e1e5a1169e92834330092c45165660c6cbd03609 \ No newline at end of file diff --git a/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_samples.xcodeproj/project.pbxproj.REMOVED.git-id index 0f53b948c7..bb3a11cb54 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 +1fa58d8cba77ef923c83d2860d5511d28dad6c27 \ No newline at end of file diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index 5e88b70832..4fa8442b92 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -158,7 +158,7 @@ void AtlasNode::draw(void) shader, _blendFunc, _textureAtlas->getQuads(), - _textureAtlas->getTotalQuads(), + _quadsToDraw, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); diff --git a/cocos/2d/CCConfiguration.cpp b/cocos/2d/CCConfiguration.cpp index a576532ade..ddbc3cfae9 100644 --- a/cocos/2d/CCConfiguration.cpp +++ b/cocos/2d/CCConfiguration.cpp @@ -146,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/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/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/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/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/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/renderer/CCQuadCommand.h b/cocos/2d/renderer/CCQuadCommand.h index b21999ea58..1837919c8d 100644 --- a/cocos/2d/renderer/CCQuadCommand.h +++ b/cocos/2d/renderer/CCQuadCommand.h @@ -56,7 +56,7 @@ public: //TODO use material to decide if it is translucent inline bool isTranslucent() const { return true; } - inline int32_t getMaterialID() const { return _materialID; } + inline uint32_t getMaterialID() const { return _materialID; } inline GLuint getTextureID() const { return _textureID; } @@ -71,7 +71,7 @@ public: inline const kmMat4& getModelView() const { return _mv; } protected: - int32_t _materialID; + uint32_t _materialID; //Key Data int _viewport; /// Which view port it belongs to diff --git a/cocos/2d/renderer/CCRenderCommand.h b/cocos/2d/renderer/CCRenderCommand.h index 7b6ec54e0c..887d717d7e 100644 --- a/cocos/2d/renderer/CCRenderCommand.h +++ b/cocos/2d/renderer/CCRenderCommand.h @@ -50,9 +50,10 @@ public: virtual int64_t generateID() = 0; /** Get Render Command Id */ - virtual inline int64_t getID() { return _id; } - - virtual inline Type getType() { return _type; } + inline int64_t getID() { return _id; } + + /** Returns the Command type */ + inline Type getType() { return _type; } protected: RenderCommand(); diff --git a/cocos/2d/renderer/CCRenderer.cpp b/cocos/2d/renderer/CCRenderer.cpp index 4454f1480f..3ffa5b583a 100644 --- a/cocos/2d/renderer/CCRenderer.cpp +++ b/cocos/2d/renderer/CCRenderer.cpp @@ -249,7 +249,7 @@ void Renderer::render() //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 && cmdQuadCountbl.vertices.x; - vec1.y = q->bl.vertices.y; - vec1.z = q->bl.vertices.z; - kmVec3Transform(&out1, &vec1, &modelView); - q->bl.vertices.x = out1.x; - q->bl.vertices.y = out1.y; - q->bl.vertices.z = out1.z; + kmVec3 *vec1 = (kmVec3*)&q->bl.vertices; + kmVec3Transform(vec1, vec1, &modelView); - kmVec3 vec2, out2; - vec2.x = q->br.vertices.x; - vec2.y = q->br.vertices.y; - vec2.z = q->br.vertices.z; - kmVec3Transform(&out2, &vec2, &modelView); - q->br.vertices.x = out2.x; - q->br.vertices.y = out2.y; - q->br.vertices.z = out2.z; + kmVec3 *vec2 = (kmVec3*)&q->br.vertices; + kmVec3Transform(vec2, vec2, &modelView); - kmVec3 vec3, out3; - vec3.x = q->tr.vertices.x; - vec3.y = q->tr.vertices.y; - vec3.z = q->tr.vertices.z; - kmVec3Transform(&out3, &vec3, &modelView); - q->tr.vertices.x = out3.x; - q->tr.vertices.y = out3.y; - q->tr.vertices.z = out3.z; + kmVec3 *vec3 = (kmVec3*)&q->tr.vertices; + kmVec3Transform(vec3, vec3, &modelView); - kmVec3 vec4, out4; - vec4.x = q->tl.vertices.x; - vec4.y = q->tl.vertices.y; - vec4.z = q->tl.vertices.z; - kmVec3Transform(&out4, &vec4, &modelView); - q->tl.vertices.x = out4.x; - q->tl.vertices.y = out4.y; - q->tl.vertices.z = out4.z; + kmVec3 *vec4 = (kmVec3*)&q->tl.vertices; + kmVec3Transform(vec4, vec4, &modelView); } } @@ -405,7 +381,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); @@ -422,7 +398,7 @@ 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]; if (command->getType() == RenderCommand::Type::QUAD_COMMAND) diff --git a/cocos/2d/renderer/CCRenderer.h b/cocos/2d/renderer/CCRenderer.h index c2dcdccc6f..a856d201c3 100644 --- a/cocos/2d/renderer/CCRenderer.h +++ b/cocos/2d/renderer/CCRenderer.h @@ -42,7 +42,7 @@ typedef std::vector RenderQueue; struct RenderStackElement { int renderQueueID; - size_t currentIndex; + ssize_t currentIndex; }; class Renderer @@ -86,10 +86,10 @@ protected: 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 19f7d54048..eea6c483c8 100644 --- a/cocos/base/CCConsole.cpp +++ b/cocos/base/CCConsole.cpp @@ -391,7 +391,7 @@ void Console::commandTextures(int fd, const char *command) { Scheduler *sched = Director::getInstance()->getScheduler(); sched->performFunctionInCocosThread( [&](){ - mydprintf(fd, "%s", TextureCache::getInstance()->getCachedTextureInfo().c_str()); + mydprintf(fd, "%s", Director::getInstance()->getTextureCache()->getCachedTextureInfo().c_str()); } ); } diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index 20f826cb2b..7463ff54ff 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -115,7 +115,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/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 94ba291e2b..d26199c205 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -197,7 +197,7 @@ void Skin::updateTransform() kmMat4 Skin::getNodeToWorldTransform() const { - return TransformConcat(_transform, _bone->getArmature()->getNodeToWorldTransform()); + return TransformConcat( _bone->getArmature()->getNodeToWorldTransform(), _transform); } kmMat4 Skin::getNodeToWorldTransformAR() const diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index bab1d8a7c5..74cb897b64 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit bab1d8a7c5d8b29f14c8dc19158a8bb994f0e970 +Subproject commit 74cb897b64f7325cf969341e9bc2d87fc7fb1bb7 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"> drawContour(); + _customCommand.init(0, _vertexZ); + _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 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/PerformanceTest/PerformanceContainerTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.cpp new file mode 100644 index 0000000000..75efc640e5 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.cpp @@ -0,0 +1,711 @@ +/* + * + */ +#include "PerformanceContainerTest.h" + +#include + +// Enable profiles for this file +#undef CC_PROFILER_DISPLAY_TIMERS +#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers() +#undef CC_PROFILER_PURGE_ALL +#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers() + +#undef CC_PROFILER_START +#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__) +#undef CC_PROFILER_STOP +#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__) +#undef CC_PROFILER_RESET +#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__) + +#undef CC_PROFILER_START_CATEGORY +#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0) +#undef CC_PROFILER_STOP_CATEGORY +#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0) +#undef CC_PROFILER_RESET_CATEGORY +#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0) + +#undef CC_PROFILER_START_INSTANCE +#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#undef CC_PROFILER_STOP_INSTANCE +#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#undef CC_PROFILER_RESET_INSTANCE +#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) + +static std::function createFunctions[] = +{ + CL(TemplateVectorPerfTest), + CL(ArrayPerfTest) +}; + +#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) + +enum { + kTagInfoLayer = 1, + + kTagBase = 20000, +}; + +enum { + kMaxNodes = 15000, + kNodesIncrease = 500, +}; + +static int g_curCase = 0; + +//////////////////////////////////////////////////////// +// +// ContainerBasicLayer +// +//////////////////////////////////////////////////////// + +ContainerBasicLayer::ContainerBasicLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase) +: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase) +{ +} + +void ContainerBasicLayer::showCurrentTest() +{ + int nodes = ((PerformanceContainerScene*)getParent())->getQuantityOfNodes(); + + auto scene = createFunctions[_curCase](); + + g_curCase = _curCase; + + if (scene) + { + scene->initWithQuantityOfNodes(nodes); + + Director::getInstance()->replaceScene(scene); + } +} + +//////////////////////////////////////////////////////// +// +// PerformanceContainerScene +// +//////////////////////////////////////////////////////// +void PerformanceContainerScene::initWithQuantityOfNodes(unsigned int nNodes) +{ + _type = 0; + //srand(time()); + auto s = Director::getInstance()->getWinSize(); + + // Title + auto label = LabelTTF::create(title().c_str(), "Arial", 40); + addChild(label, 1, TAG_TITLE); + label->setPosition(Point(s.width/2, s.height-32)); + label->setColor(Color3B(255,255,40)); + + // Subtitle + std::string strSubTitle = subtitle(); + if(strSubTitle.length()) + { + auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16); + addChild(l, 1, TAG_SUBTITLE); + l->setPosition(Point(s.width/2, s.height-80)); + } + + lastRenderedCount = 0; + currentQuantityOfNodes = 0; + quantityOfNodes = nNodes; + + MenuItemFont::setFontSize(65); + auto decrease = MenuItemFont::create(" - ", [&](Object *sender) { + quantityOfNodes -= kNodesIncrease; + if( quantityOfNodes < 0 ) + quantityOfNodes = 0; + + updateQuantityLabel(); + updateQuantityOfNodes(); + updateProfilerName(); + CC_PROFILER_PURGE_ALL(); + srand(0); + }); + decrease->setColor(Color3B(0,200,20)); + _decrease = decrease; + + auto increase = MenuItemFont::create(" + ", [&](Object *sender) { + quantityOfNodes += kNodesIncrease; + if( quantityOfNodes > kMaxNodes ) + quantityOfNodes = kMaxNodes; + + updateQuantityLabel(); + updateQuantityOfNodes(); + updateProfilerName(); + CC_PROFILER_PURGE_ALL(); + srand(0); + }); + increase->setColor(Color3B(0,200,20)); + _increase = increase; + + auto menu = Menu::create(decrease, increase, NULL); + menu->alignItemsHorizontally(); + menu->setPosition(Point(s.width/2, s.height/2+15)); + addChild(menu, 1); + + auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); + infoLabel->setColor(Color3B(0,200,20)); + infoLabel->setPosition(Point(s.width/2, s.height/2-15)); + addChild(infoLabel, 1, kTagInfoLayer); + + auto menuLayer = new ContainerBasicLayer(true, MAX_LAYER, g_curCase); + addChild(menuLayer); + menuLayer->release(); + + printf("Size of Node: %lu\n", sizeof(Node)); + + int oldFontSize = MenuItemFont::getFontSize(); + MenuItemFont::setFontSize(24); + + Vector toggleItems; + + generateTestFunctions(); + + CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions"); + + + for (const auto& f : _testFunctions) + { + toggleItems.pushBack(MenuItemFont::create(f.name)); + } + + auto toggle = MenuItemToggle::createWithCallback([this](Object* sender){ + auto toggle = static_cast(sender); + this->_type = toggle->getSelectedIndex(); + auto label = static_cast(this->getChildByTag(TAG_SUBTITLE)); + label->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name)); + this->updateProfilerName(); + }, toggleItems); + + toggle->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); + toggle->setPosition(VisibleRect::left()); + _toggle = toggle; + + auto start = MenuItemFont::create("start", [this](Object* sender){ + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + CC_PROFILER_PURGE_ALL(); + sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false); + + this->unscheduleUpdate(); + this->scheduleUpdate(); + this->_startItem->setEnabled(false); + this->_stopItem->setEnabled(true); + this->_toggle->setEnabled(false); + this->_increase->setEnabled(false); + this->_decrease->setEnabled(false); + }); + start->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); + start->setPosition(VisibleRect::right() + Point(0, 40)); + _startItem = start; + + auto stop = MenuItemFont::create("stop", [this](Object* sender){ + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this); + + this->unscheduleUpdate(); + this->_startItem->setEnabled(true); + this->_stopItem->setEnabled(false); + this->_toggle->setEnabled(true); + this->_increase->setEnabled(true); + this->_decrease->setEnabled(true); + }); + + stop->setEnabled(false); + stop->setAnchorPoint(Point::ANCHOR_MIDDLE_RIGHT); + stop->setPosition(VisibleRect::right() + Point(0, -40)); + _stopItem = stop; + + auto menu2 = Menu::create(toggle, start, stop, NULL); + menu2->setPosition(Point::ZERO); + addChild(menu2); + + MenuItemFont::setFontSize(oldFontSize); + + updateQuantityLabel(); + updateQuantityOfNodes(); + updateProfilerName(); +} + +std::string PerformanceContainerScene::title() const +{ + return "No title"; +} + +std::string PerformanceContainerScene::subtitle() const +{ + return ""; +} + +void PerformanceContainerScene::updateQuantityLabel() +{ + if( quantityOfNodes != lastRenderedCount ) + { + auto infoLabel = static_cast( getChildByTag(kTagInfoLayer) ); + char str[20] = {0}; + sprintf(str, "%u nodes", quantityOfNodes); + infoLabel->setString(str); + + lastRenderedCount = quantityOfNodes; + } +} + +const char * PerformanceContainerScene::profilerName() +{ + return _profilerName; +} + +void PerformanceContainerScene::updateProfilerName() +{ + snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), quantityOfNodes); +} + +void PerformanceContainerScene::onExitTransitionDidStart() +{ + Scene::onExitTransitionDidStart(); + + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + sched->unscheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this); +} + +void PerformanceContainerScene::onEnterTransitionDidFinish() +{ + Scene::onEnterTransitionDidFinish(); + + auto director = Director::getInstance(); + auto sched = director->getScheduler(); + + CC_PROFILER_PURGE_ALL(); + sched->scheduleSelector(schedule_selector(PerformanceContainerScene::dumpProfilerInfo), this, 2, false); +} + +void PerformanceContainerScene::dumpProfilerInfo(float dt) +{ + CC_PROFILER_DISPLAY_TIMERS(); +} + +void PerformanceContainerScene::update(float dt) +{ + _testFunctions[_type].func(); +} + +void PerformanceContainerScene::updateQuantityOfNodes() +{ + currentQuantityOfNodes = quantityOfNodes; +} + +const char* PerformanceContainerScene::testName() +{ + return _testFunctions[_type].name; +} + +//////////////////////////////////////////////////////// +// +// TemplateVectorPerfTest +// +//////////////////////////////////////////////////////// + +void TemplateVectorPerfTest::generateTestFunctions() +{ + auto createVector = [this](){ + Vector ret; + + for( int i=0; isetTag(i); + ret.pushBack(node); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "pushBack", [=](){ + Vector nodeVector; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + { "insert", [=](){ + Vector nodeVector; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + { "replace", [=](){ + Vector nodeVector = createVector(); + + srand(time(nullptr)); + ssize_t index = rand() % quantityOfNodes; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + { "getIndex", [=](){ + + Vector nodeVector = createVector(); + Node* objToGet = nodeVector.at(quantityOfNodes/3); + ssize_t index = 0; + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `index` to avoids `getIndex` invoking was optimized in release mode + if (index == quantityOfNodes/3) + { + nodeVector.clear(); + } + } } , + { "find", [=](){ + Vector nodeVector = createVector(); + Node* objToGet = nodeVector.at(quantityOfNodes/3); + Vector::iterator iter; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `iter` to avoids `find` invoking was optimized in release mode + if (*iter == objToGet) + { + nodeVector.clear(); + } + + } } , + { "at", [=](){ + Vector nodeVector = createVector(); + Node* objToGet = nullptr; + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `objToGet` to avoids `at` invoking was optimized in release mode + if (nodeVector.getIndex(objToGet) == quantityOfNodes/3) + { + nodeVector.clear(); + } + } } , + { "contains", [=](){ + Vector nodeVector = createVector(); + Node* objToGet = nodeVector.at(quantityOfNodes/3); + + bool ret = false; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + // Uses `ret` to avoids `contains` invoking was optimized in release mode + if (ret) + { + nodeVector.clear(); + } + } } , + { "eraseObject", [=](){ + Vector nodeVector = createVector(); + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i] = nodeVector.at(i); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CCASSERT(nodeVector.empty(), "nodeVector was not empty."); + + free(nodes); + } } , + { "erase", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CCASSERT(nodeVector.empty(), "nodeVector was not empty."); + + } } , + { "clear", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + + CCASSERT(nodeVector.empty(), "nodeVector was not empty."); + } } , + { "swap by index", [=](){ + Vector nodeVector = createVector(); + + int swapIndex1 = quantityOfNodes / 3; + int swapIndex2 = quantityOfNodes / 3 * 2; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "swap by object", [=](){ + Vector nodeVector = createVector(); + + Node* swapNode1 = nodeVector.at(quantityOfNodes / 3); + Node* swapNode2 = nodeVector.at(quantityOfNodes / 3 * 2); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "reverse", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iprofilerName()); + } } , + + { "c++11 Range Loop", [=](){ + Vector nodeVector = createVector(); + + CC_PROFILER_START(this->profilerName()); + for (const auto& e : nodeVector) + { + e->setTag(111); + } + CC_PROFILER_STOP(this->profilerName()); + } } , + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + + + +std::string TemplateVectorPerfTest::title() const +{ + return "Vector Perf test"; +} + +std::string TemplateVectorPerfTest::subtitle() const +{ + return "Test 'pushBack', See console"; +} + + + +//////////////////////////////////////////////////////// +// +// ArrayPerfTest +// +//////////////////////////////////////////////////////// + +std::string ArrayPerfTest::title() const +{ + return "Array Perf test"; +} + +std::string ArrayPerfTest::subtitle() const +{ + return "Test `addObject`, See console"; +} + +void ArrayPerfTest::generateTestFunctions() +{ + auto createArray = [this](){ + Array* ret = Array::create(); + + for( int i=0; isetTag(i); + ret->addObject(node); + } + return ret; + }; + + TestFunction testFunctions[] = { + { "addObject", [=](){ + Array* nodeVector = Array::create(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iaddObject(Node::create()); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "insertObject", [=](){ + Array* nodeVector = Array::create(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iinsertObject(Node::create(), 0); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "setObject", [=](){ + Array* nodeVector = createArray(); + + srand(time(nullptr)); + ssize_t index = rand() % quantityOfNodes; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; isetObject(Node::create(), index); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "getIndexOfObject", [=](){ + Array* nodeVector = createArray(); + Object* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3); + ssize_t index = 0; + CC_PROFILER_START(this->profilerName()); + for( int i=0; igetIndexOfObject(objToGet); + CC_PROFILER_STOP(this->profilerName()); + // Uses `index` to avoids `getIndex` invoking was optimized in release mode + if (index == quantityOfNodes/3) + { + nodeVector->removeAllObjects(); + } + } } , + { "getObjectAtIndex", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; igetObjectAtIndex(quantityOfNodes/3); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "containsObject", [=](){ + Array* nodeVector = createArray(); + Object* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; icontainsObject(objToGet); + CC_PROFILER_STOP(this->profilerName()); + } } , + { "removeObject", [=](){ + Array* nodeVector = createArray(); + Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); + + for (int i = 0; i < quantityOfNodes; ++i) + { + nodes[i] = static_cast(nodeVector->getObjectAtIndex(i)); + } + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveObject(nodes[i]); + CC_PROFILER_STOP(this->profilerName()); + + CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); + + free(nodes); + } } , + { "removeObjectAtIndex", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveObjectAtIndex(0); + CC_PROFILER_STOP(this->profilerName()); + + CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); + + } } , + { "removeAllObjects", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iremoveAllObjects(); + CC_PROFILER_STOP(this->profilerName()); + + CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); + } } , + { "swap by index", [=](){ + Array* nodeVector = createArray(); + + int swapIndex1 = quantityOfNodes / 3; + int swapIndex2 = quantityOfNodes / 3 * 2; + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iswap(swapIndex1, swapIndex2); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "swap by object", [=](){ + Array* nodeVector = createArray(); + + Object* swapNode1 = nodeVector->getObjectAtIndex(quantityOfNodes / 3); + Object* swapNode2 = nodeVector->getObjectAtIndex(quantityOfNodes / 3 * 2); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; iexchangeObject(swapNode1, swapNode2); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "reverseObjects", [=](){ + Array* nodeVector = createArray(); + + CC_PROFILER_START(this->profilerName()); + for( int i=0; ireverseObjects(); + CC_PROFILER_STOP(this->profilerName()); + } } , + + { "CCARRAY_FOREACH", [=](){ + Array* nodeVector = createArray(); + Object* obj; + CC_PROFILER_START(this->profilerName()); + + CCARRAY_FOREACH(nodeVector, obj) + { + static_cast(obj)->setTag(111); + } + CC_PROFILER_STOP(this->profilerName()); + } } , + }; + + for (const auto& func : testFunctions) + { + _testFunctions.push_back(func); + } +} + +///---------------------------------------- +void runContainerPerformanceTest() +{ + auto scene = createFunctions[g_curCase](); + scene->initWithQuantityOfNodes(kNodesIncrease); + + Director::getInstance()->replaceScene(scene); +} diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h new file mode 100644 index 0000000000..d99cac90ff --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceContainerTest.h @@ -0,0 +1,91 @@ +/* + * + */ +#ifndef __PERFORMANCE_CONTAINER_TEST_H__ +#define __PERFORMANCE_CONTAINER_TEST_H__ + +#include "PerformanceTest.h" +#include "CCProfiling.h" + +class ContainerBasicLayer : public PerformBasicLayer +{ +public: + ContainerBasicLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0); + + virtual void showCurrentTest(); +}; + +class PerformanceContainerScene : public Scene +{ +public: + static const int TAG_TITLE = 100; + static const int TAG_SUBTITLE = 101; + + struct TestFunction + { + const char* name; + std::function func; + }; + + virtual void initWithQuantityOfNodes(unsigned int nNodes); + virtual void generateTestFunctions() = 0; + + virtual std::string title() const; + virtual std::string subtitle() const; + virtual void updateQuantityOfNodes(); + + const char* profilerName(); + void updateProfilerName(); + + // for the profiler + virtual const char* testName(); + void updateQuantityLabel(); + int getQuantityOfNodes() { return quantityOfNodes; } + void dumpProfilerInfo(float dt); + + // overrides + virtual void onExitTransitionDidStart() override; + virtual void onEnterTransitionDidFinish() override; + virtual void update(float dt) override; + +protected: + char _profilerName[256]; + int lastRenderedCount; + int quantityOfNodes; + int currentQuantityOfNodes; + unsigned int _type; + std::vector _testFunctions; + + MenuItemFont* _increase; + MenuItemFont* _decrease; + MenuItemFont* _startItem; + MenuItemFont* _stopItem; + MenuItemToggle* _toggle; +}; + +class TemplateVectorPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(TemplateVectorPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class ArrayPerfTest : public PerformanceContainerScene +{ +public: + CREATE_FUNC(ArrayPerfTest); + + virtual void generateTestFunctions() override; + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + + +void runContainerPerformanceTest(); + +#endif // __PERFORMANCE_CONTAINER_TEST_H__ diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/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 431acb25ed..0acc702e08 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp @@ -48,11 +48,7 @@ enum { //////////////////////////////////////////////////////// SubTest::~SubTest() { - if (_batchNode) - { - _batchNode->release(); - _batchNode = NULL; - } + _parentNode->release(); } void SubTest::initWithSubTest(int subtest, Node* p) @@ -60,12 +56,11 @@ void SubTest::initWithSubTest(int subtest, Node* p) srand(0); subtestNumber = subtest; - _parent = p; - _batchNode = nullptr; + _parentNode = nullptr; /* * Tests: * 1: 1 (32-bit) PNG sprite of 52 x 139 - * 2: 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 @@ -90,73 +85,67 @@ void SubTest::initWithSubTest(int subtest, Node* p) { /// case 1: - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - break; case 2: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); + _parentNode = Node::create(); break; case 3: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - _batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100); - p->addChild(_batchNode, 0); + _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); - break; case 6: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - _batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); + _parentNode = Node::create(); break; case 7: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - _batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); - p->addChild(_batchNode, 0); - break; + _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 9: - Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - break; case 10: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - _batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100); + _parentNode = Node::create(); break; case 11: Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888); - _batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100); - p->addChild(_batchNode, 0); + _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(); - } + p->addChild(_parentNode); + _parentNode->retain(); } Sprite* SubTest::createSpriteWithTag(int tag) { + TextureCache *cache = Director::getInstance()->getTextureCache(); + Sprite* sprite = NULL; switch (subtestNumber) { @@ -165,14 +154,15 @@ Sprite* SubTest::createSpriteWithTag(int tag) case 2: { sprite = Sprite::create("Images/grossinis_sister1.png"); - _parent->addChild(sprite, 0, tag+100); + _parentNode->addChild(sprite, 0, tag+100); break; } case 3: case 4: { - sprite = Sprite::createWithTexture(_batchNode->getTexture(), Rect(0, 0, 52, 139)); - _batchNode->addChild(sprite, 0, tag+100); + Texture2D *texture = cache->addImage("Images/grossinis_sister1.png"); + sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139)); + _parentNode->addChild(sprite, 0, tag+100); break; } @@ -183,24 +173,10 @@ Sprite* SubTest::createSpriteWithTag(int tag) char str[32] = {0}; sprintf(str, "Images/grossini_dance_%02d.png", idx); sprite = Sprite::create(str); - _parent->addChild(sprite, 0, tag+100); + _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)); - _parent->addChild(sprite, 0, tag+100); - break; - } - case 7: case 8: { @@ -212,8 +188,9 @@ Sprite* SubTest::createSpriteWithTag(int tag) x *= 85; y *= 121; - sprite = Sprite::createWithTexture(_batchNode->getTexture(), Rect(x,y,85,121)); - _batchNode->addChild(sprite, 0, tag+100); + 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; } @@ -229,25 +206,11 @@ 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 10: - { - int y,x; - int r = (CCRANDOM_0_1() * 6400 / 100); - - y = r / 8; - x = r % 8; - - x *= 32; - y *= 32; - sprite = Sprite::createWithTexture(_batchNode->getTexture(), CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32))); - _parent->addChild(sprite, 0, tag+100); - break; - } - case 11: case 12: { @@ -259,10 +222,52 @@ Sprite* SubTest::createSpriteWithTag(int tag) x *= 32; y *= 32; - sprite = Sprite::createWithTexture(_batchNode->getTexture(), CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32))); - _batchNode->addChild(sprite, 0, tag+100); + 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); + + 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); + } + } default: break; @@ -273,30 +278,7 @@ Sprite* SubTest::createSpriteWithTag(int tag) void SubTest::removeByTag(int tag) { - switch (subtestNumber) - { - case 1: - case 5: - case 9: - _parent->removeChildByTag(tag+100, true); - break; - - case 2: - case 3: - case 4: - - case 6: - case 7: - case 8: - - case 10: - case 11: - case 12: - _batchNode->removeChildByTag(tag+100, true); - break; - default: - break; - } + _parentNode->removeChildByTag(tag+100, true); } //////////////////////////////////////////////////////// @@ -443,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 <= 12; ++i) + for (int i = 1; i <= 13; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); @@ -457,8 +439,10 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) itemFont->setColor(Color3B(200,20,20)); 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(); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h index b6a4910259..0aa21356c7 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.h @@ -40,8 +40,7 @@ public: protected: int subtestNumber; - SpriteBatchNode *_batchNode; - Node* _parent; + Node *_parentNode; }; class SpriteMenuLayer : public PerformBasicLayer 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/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"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation"> + android:configChanges="orientation">