From 72ede55ac79f85f060e3d00cc39aaeaec5bbad09 Mon Sep 17 00:00:00 2001 From: Maks Date: Mon, 3 Feb 2014 22:12:03 +0200 Subject: [PATCH 01/18] fix string size check and assert condition 1. std::string::size() return size_t (is never < 0) 2. "event must be larger than 0" and 'event' has unsigned int type --- cocos/2d/platform/win32/CCImage.cpp | 2 +- cocos/editor-support/cocostudio/TriggerMng.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/2d/platform/win32/CCImage.cpp b/cocos/2d/platform/win32/CCImage.cpp index a753d3e9c7..5f52e5b43c 100644 --- a/cocos/2d/platform/win32/CCImage.cpp +++ b/cocos/2d/platform/win32/CCImage.cpp @@ -84,7 +84,7 @@ public: wchar_t * pwszBuffer = NULL; do { - if (nString.size() < 0) + if (nString.size() == 0) { break; } diff --git a/cocos/editor-support/cocostudio/TriggerMng.cpp b/cocos/editor-support/cocostudio/TriggerMng.cpp index bc0d4580c2..c98fc6ce78 100644 --- a/cocos/editor-support/cocostudio/TriggerMng.cpp +++ b/cocos/editor-support/cocostudio/TriggerMng.cpp @@ -106,7 +106,7 @@ void TriggerMng::parse(const rapidjson::Value &root) cocos2d::Vector* TriggerMng::get(unsigned int event) const { - CCAssert(event >= 0, "Argument must be larger than 0"); + CCAssert(event != 0, "Argument must be larger than 0"); auto iter = _eventTriggers.find(event); if (iter == _eventTriggers.end()) @@ -170,7 +170,7 @@ void TriggerMng::removeAll(void) bool TriggerMng::remove(unsigned int event) { bool bRet = false; - CCAssert(event >= 0, "event must be larger than 0"); + CCAssert(event != 0, "event must be larger than 0"); do { auto iterator = _eventTriggers.find(event); @@ -194,7 +194,7 @@ bool TriggerMng::remove(unsigned int event) bool TriggerMng::remove(unsigned int event, TriggerObj *Obj) { bool bRet = false; - CCAssert(event >= 0, "event must be larger than 0"); + CCAssert(event != 0, "event must be larger than 0"); CCAssert(Obj != 0, "TriggerObj must be not 0"); do { From 3d0fabe08c5931176c4153af8bff44efc981554a Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Wed, 12 Feb 2014 18:19:06 +0800 Subject: [PATCH 02/18] issue #3708:Performance Test: data structure conversion in lua binding --- cocos/scripting/lua/bindings/CCLuaStack.cpp | 3 +- .../lua/bindings/lua_cocos2dx_deprecated.cpp | 12 +- .../lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- .../lua/bindings/lua_cocos2dx_manual.hpp | 2 + .../PerformanceTest/PerformanceTest.lua | 2845 ++++++++++------- 5 files changed, 1668 insertions(+), 1196 deletions(-) diff --git a/cocos/scripting/lua/bindings/CCLuaStack.cpp b/cocos/scripting/lua/bindings/CCLuaStack.cpp index b836f49853..338517f447 100644 --- a/cocos/scripting/lua/bindings/CCLuaStack.cpp +++ b/cocos/scripting/lua/bindings/CCLuaStack.cpp @@ -105,7 +105,7 @@ int lua_print(lua_State * luastate) if (i!=nargs) t += "\t"; } - CCLOG("[LUA-print] %s", t.c_str()); + log("[LUA-print] %s", t.c_str()); return 0; } @@ -157,6 +157,7 @@ bool LuaStack::init(void) register_all_cocos2dx_extension(_state); register_all_cocos2dx_deprecated(_state); register_cocos2dx_extension_CCBProxy(_state); + register_cocos2dx_PerformanceStuctAndTable(_state); tolua_opengl_open(_state); register_all_cocos2dx_gui(_state); register_all_cocos2dx_studio(_state); diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp index e907189be2..c0dcde7df5 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp @@ -106,7 +106,7 @@ bool array_to_valuevector_deprecated(Array& array,ValueVector& valueVec) #define deprecatedFunctionTip(oldFun,newFun) CCLOG("%s was deprecated please use %s instead ",oldFun, newFun) static int tolua_Cocos2d_CCPoint_new00(lua_State* tolua_S) { - deprecatedClassTip("CCPoint"); +// deprecatedClassTip("CCPoint"); #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -132,7 +132,7 @@ tolua_lerror: static int tolua_Cocos2d_CCPoint_new00_local(lua_State* tolua_S) { - deprecatedClassTip("CCPoint"); +// deprecatedClassTip("CCPoint"); #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -183,7 +183,7 @@ tolua_lerror: static int tolua_Cocos2d_CCPoint_new01_local(lua_State* tolua_S) { - deprecatedClassTip("CCPoint"); +// deprecatedClassTip("CCPoint"); tolua_Error tolua_err; if ( @@ -197,8 +197,10 @@ static int tolua_Cocos2d_CCPoint_new01_local(lua_State* tolua_S) { float x = ((float) tolua_tonumber(tolua_S,2,0)); float y = ((float) tolua_tonumber(tolua_S,3,0)); - Point tolua_ret(x,y); - point_to_luaval(tolua_S, tolua_ret); + Point* tolua_ret = (Point*) Mtolua_new((Point)(x,y)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"CCPoint"); + tolua_register_gc(tolua_S,lua_gettop(tolua_S)); + //point_to_luaval(tolua_S, tolua_ret); } return 1; tolua_lerror: 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 ee22cb131d..25c76fc902 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 @@ -c5f8d4a3ea721a2ecb36fe381430b7ac6fad1740 \ No newline at end of file +8102f7376c603c7a65f754d9d1f981c6a5c1ce2f \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp index d8dae90200..5610aaf2fa 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp @@ -55,6 +55,8 @@ TOLUA_API int register_all_cocos2dx_manual(lua_State* tolua_S); TOLUA_API int register_cocos2dx_event_releated(lua_State* tolua_S); +TOLUA_API int register_cocos2dx_PerformanceStuctAndTable(lua_State* tolua_S); + struct LuaEventAccelerationData { void* acc; diff --git a/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua b/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua index 9e2ef7adc9..b5b95f7ef6 100644 --- a/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua +++ b/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua @@ -1,6 +1,6 @@ require "luaScript/PerformanceTest/PerformanceSpriteTest" -local MAX_COUNT = 5 +local MAX_COUNT = 7 local LINE_SPACE = 40 local kItemTagBasic = 1000 @@ -10,26 +10,28 @@ local testsName = "PerformanceParticleTest", "PerformanceSpriteTest", "PerformanceTextureTest", - "PerformanceTouchesTest" + "PerformanceTouchesTest", + "PerformanceStructOrLuaTable", + "PerformanceTableConversionV3", } local s = cc.Director:getInstance():getWinSize() --Create toMainLayr MenuItem function CreatePerfomBasicLayerMenu(pMenu) - if nil == pMenu then - return - end - local function toMainLayer() + if nil == pMenu then + return + end + local function toMainLayer() local pScene = PerformanceTestMain() if pScene ~= nil then cc.Director:getInstance():replaceScene(pScene) end - end + end --Create BackMneu cc.MenuItemFont:setFontName("Arial") cc.MenuItemFont:setFontSize(24) - local pMenuItemFont = cc.MenuItemFont:create("Back") + local pMenuItemFont = cc.MenuItemFont:create("Back") pMenuItemFont:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25)) pMenuItemFont:registerScriptTapHandler(toMainLayer) pMenu:addChild(pMenuItemFont) @@ -40,18 +42,18 @@ end ---------------------------------- local NodeChildrenTestParam = { - kTagInfoLayer = 1, - kTagMainLayer = 2, - kTagLabelAtlas = 3, - kTagBase = 20000, - TEST_COUNT = 4, - kMaxNodes = 15000, - kNodesIncrease = 500, + kTagInfoLayer = 1, + kTagMainLayer = 2, + kTagLabelAtlas = 3, + kTagBase = 20000, + TEST_COUNT = 4, + kMaxNodes = 15000, + kNodesIncrease = 500, } local function runNodeChildrenTest() - --NodeChildrenMainScene - local nLastRenderedCount = 0 + --NodeChildrenMainScene + local nLastRenderedCount = 0 local nQuantityOfNodes = 0 local nCurrentQuantityOfNodes = 0 --IterateSpriteSheet @@ -65,350 +67,350 @@ local function runNodeChildrenTest() local pNewscene = cc.Scene:create() local function GetTitle() - if 0 == nCurCase then - return "B - Iterate SpriteSheet" - elseif 1 == nCurCase then - return "C - Add to spritesheet" - elseif 2 == nCurCase then - return "D - Del from spritesheet" - elseif 3 == nCurCase then - return "E - Reorder from spritesheet" - end + if 0 == nCurCase then + return "B - Iterate SpriteSheet" + elseif 1 == nCurCase then + return "C - Add to spritesheet" + elseif 2 == nCurCase then + return "D - Del from spritesheet" + elseif 3 == nCurCase then + return "E - Reorder from spritesheet" + end end local function GetSubTitle() - if 0 == nCurCase then - return "Iterate children using C Array API. See console" - elseif 1 == nCurCase then - return "Adds %10 of total sprites with random z. See console" - elseif 2 == nCurCase then - return "Remove %10 of total sprites placed randomly. See console" - elseif 3 == nCurCase then - return "Reorder %10 of total sprites placed randomly. See console" - end + if 0 == nCurCase then + return "Iterate children using C Array API. See console" + elseif 1 == nCurCase then + return "Adds %10 of total sprites with random z. See console" + elseif 2 == nCurCase then + return "Remove %10 of total sprites placed randomly. See console" + elseif 3 == nCurCase then + return "Reorder %10 of total sprites placed randomly. See console" + end end local function GetProfilerName() - if 0 == nCurCase then - return "iter c-array" - elseif 1 == nCurCase then - return "add sprites" - elseif 2 == nCurCase then - return "remove sprites" - elseif 3 == nCurCase then - return "reorder sprites" - end + if 0 == nCurCase then + return "iter c-array" + elseif 1 == nCurCase then + return "add sprites" + elseif 2 == nCurCase then + return "remove sprites" + elseif 3 == nCurCase then + return "reorder sprites" + end end local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end + if nil ~= pMenu then + bControlMenuVisible = bMenuVisible + nMaxCases = nMaxCasesNum + nCurCase = nCurCaseIndex + if true == bControlMenuVisible then + local function backCallback() + nCurCase = nCurCase - 1 + if nCurCase < 0 then + nCurCase = nCurCase + nMaxCases + end + ShowCurrentTest() + end - local function restartCallback() - ShowCurrentTest() - end + local function restartCallback() + ShowCurrentTest() + end - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end + local function nextCallback() + nCurCase = nCurCase + 1 + --No check nMaxCases + nCurCase = nCurCase % nMaxCases + ShowCurrentTest() + end + + local size = cc.Director:getInstance():getWinSize() + local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) + item1:registerScriptTapHandler(backCallback) + pMenu:addChild(item1,kItemTagBasic) + local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) + item2:registerScriptTapHandler(restartCallback) + pMenu:addChild(item2,kItemTagBasic) + local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) + pMenu:addChild(item3,kItemTagBasic) + item3:registerScriptTapHandler(nextCallback) + + local size = cc.Director:getInstance():getWinSize() + item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) + item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + end + end end local function updateQuantityLabel() - if nQuantityOfNodes ~= nLastRenderedCount then - -- local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) - local pInfoLabel = tolua.cast(pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") - local strNode = nQuantityOfNodes.." nodes" - pInfoLabel:setString(strNode) - nLastRenderedCount = nQuantityOfNodes - end + if nQuantityOfNodes ~= nLastRenderedCount then + -- local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) + local pInfoLabel = tolua.cast(pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local strNode = nQuantityOfNodes.." nodes" + pInfoLabel:setString(strNode) + nLastRenderedCount = nQuantityOfNodes + end end local function IterateSpriteSheetCArrayUpdate(t) - if nil == pBatchNode then - return - end - local pChildren = pBatchNode:getChildren() - local pObject = nil - if nil == pChildren then - return - end - local i = 0 - local len = table.getn(pChildren) - for i = 0, len - 1, 1 do - local child = tolua.cast(pChildren[i + 1], "cc.Sprite") - child:setVisible(false) - end + if nil == pBatchNode then + return + end + local pChildren = pBatchNode:getChildren() + local pObject = nil + if nil == pChildren then + return + end + local i = 0 + local len = table.getn(pChildren) + for i = 0, len - 1, 1 do + local child = tolua.cast(pChildren[i + 1], "cc.Sprite") + child:setVisible(false) + end end local function AddSpriteSheetUpdate(t) - if nil == pBatchNode then - return - end - - --15 percent - local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 - local zs = {} - if nTotalToAdd > 0 then + if nil == pBatchNode then + return + end + + --15 percent + local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 + local zs = {} + if nTotalToAdd > 0 then local pSprites = {} - local i = 0 - for i = 0 , nTotalToAdd - 1 do - local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) + local i = 0 + for i = 0 , nTotalToAdd - 1 do + local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) pSprites[i + 1] = pSprite - zs[i] = math.random(-1,1) * 50 - end - - for i = 0 , nTotalToAdd - 1 do - local pChild = tolua.cast(pSprites[i + 1],"cc.Node") - pBatchNode:addChild(pChild, zs[i], NodeChildrenTestParam.kTagBase + i) - end - - pBatchNode:sortAllChildren() - - for i = 0 , nTotalToAdd - 1 do - pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true) - end - end + zs[i] = math.random(-1,1) * 50 + end + + for i = 0 , nTotalToAdd - 1 do + local pChild = tolua.cast(pSprites[i + 1],"cc.Node") + pBatchNode:addChild(pChild, zs[i], NodeChildrenTestParam.kTagBase + i) + end + + pBatchNode:sortAllChildren() + + for i = 0 , nTotalToAdd - 1 do + pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true) + end + end end local function RemoveSpriteSheetUpdate(t) - if nil == pBatchNode then - return - end - local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 - if nTotalToAdd > 0 then + if nil == pBatchNode then + return + end + local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 + if nTotalToAdd > 0 then local pSprites = {} - -- Don't include the sprite creation time as part of the profiling - local i = 0 - for i = 0, nTotalToAdd - 1 do - local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) + -- Don't include the sprite creation time as part of the profiling + local i = 0 + for i = 0, nTotalToAdd - 1 do + local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) pSprites[i + 1] = pSprite - end - -- add them with random Z (very important!) - for i=0, nTotalToAdd - 1 do - local pChild = tolua.cast(pSprites[i + 1],"cc.Node") - pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) + end + -- add them with random Z (very important!) + for i=0, nTotalToAdd - 1 do + local pChild = tolua.cast(pSprites[i + 1],"cc.Node") + pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) end - for i = 0, nTotalToAdd - 1 do - pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true) - end + for i = 0, nTotalToAdd - 1 do + pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true) + end end end local function ReorderSpriteSheetUpdate(t) - if nil == pBatchNode then - return - end + if nil == pBatchNode then + return + end -- 15 percent - local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 + local nTotalToAdd = nCurrentQuantityOfNodes * 0.15 - if nTotalToAdd > 0 then + if nTotalToAdd > 0 then local pSprites = {} - -- Don't include the sprite creation time as part of the profiling - local i = 0 - for i = 0,nTotalToAdd - 1 do - local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) - pSprites[i + 1] = pSprite - end + -- Don't include the sprite creation time as part of the profiling + local i = 0 + for i = 0,nTotalToAdd - 1 do + local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32)) + pSprites[i + 1] = pSprite + end - --dd them with random Z (very important!) - for i = 0, nTotalToAdd - 1 do - local pChild = tolua.cast(pSprites[i + 1] ,"cc.Node") - pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) - end + --dd them with random Z (very important!) + for i = 0, nTotalToAdd - 1 do + local pChild = tolua.cast(pSprites[i + 1] ,"cc.Node") + pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) + end - pBatchNode:sortAllChildren() + pBatchNode:sortAllChildren() - -- reorder them - for i = 0, nTotalToAdd - 1 do - local pNode = tolua.cast(pSprites[i + 1],"cc.Node") - pBatchNode:reorderChild(pNode, math.random(-1,1) * 50) - end - pBatchNode:sortAllChildren() - --remove them - for i = 0, nTotalToAdd - 1 do - pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase+i, true) - end + -- reorder them + for i = 0, nTotalToAdd - 1 do + local pNode = tolua.cast(pSprites[i + 1],"cc.Node") + pBatchNode:reorderChild(pNode, math.random(-1,1) * 50) + end + pBatchNode:sortAllChildren() + --remove them + for i = 0, nTotalToAdd - 1 do + pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase+i, true) + end end end local function NodeChildrenScheduleUpdate() - if 0 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(IterateSpriteSheetCArrayUpdate,0) - elseif 1 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(AddSpriteSheetUpdate,0) - elseif 2 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(RemoveSpriteSheetUpdate,0) - elseif 3 == nCurCase then - pNewscene:scheduleUpdateWithPriorityLua(ReorderSpriteSheetUpdate,0) - end + if 0 == nCurCase then + pNewscene:scheduleUpdateWithPriorityLua(IterateSpriteSheetCArrayUpdate,0) + elseif 1 == nCurCase then + pNewscene:scheduleUpdateWithPriorityLua(AddSpriteSheetUpdate,0) + elseif 2 == nCurCase then + pNewscene:scheduleUpdateWithPriorityLua(RemoveSpriteSheetUpdate,0) + elseif 3 == nCurCase then + pNewscene:scheduleUpdateWithPriorityLua(ReorderSpriteSheetUpdate,0) + end end local function updateQuantityOfNodes() - local s = cc.Director:getInstance():getWinSize() - --increase nodes - if( nCurrentQuantityOfNodes < nQuantityOfNodes ) then - local i = 0 - for i = 0,nQuantityOfNodes - nCurrentQuantityOfNodes - 1 do - local sprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 32, 32)) - pBatchNode:addChild(sprite) - sprite:setPosition(cc.p( math.random() * s.width, math.random() * s.height)) - if 0 ~= nCurCase then - sprite:setVisible(false) - end - end - elseif (nCurrentQuantityOfNodes > nQuantityOfNodes ) then - i = 0 - for i = 0, nCurrentQuantityOfNodes - nQuantityOfNodes - 1 do - local index = nCurrentQuantityOfNodes - i - 1 - pBatchNode:removeChildAtIndex(index, true) - end - end - - - nCurrentQuantityOfNodes = nQuantityOfNodes + local s = cc.Director:getInstance():getWinSize() + --increase nodes + if( nCurrentQuantityOfNodes < nQuantityOfNodes ) then + local i = 0 + for i = 0,nQuantityOfNodes - nCurrentQuantityOfNodes - 1 do + local sprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 32, 32)) + pBatchNode:addChild(sprite) + sprite:setPosition(cc.p( math.random() * s.width, math.random() * s.height)) + if 0 ~= nCurCase then + sprite:setVisible(false) + end + end + elseif (nCurrentQuantityOfNodes > nQuantityOfNodes ) then + i = 0 + for i = 0, nCurrentQuantityOfNodes - nQuantityOfNodes - 1 do + local index = nCurrentQuantityOfNodes - i - 1 + pBatchNode:removeChildAtIndex(index, true) + end + end + + + nCurrentQuantityOfNodes = nQuantityOfNodes end local function onDecrease() - nQuantityOfNodes = nQuantityOfNodes - NodeChildrenTestParam.kNodesIncrease - if nQuantityOfNodes < 0 then - nQuantityOfNodes = 0 - end - - updateQuantityLabel() - updateQuantityOfNodes() + nQuantityOfNodes = nQuantityOfNodes - NodeChildrenTestParam.kNodesIncrease + if nQuantityOfNodes < 0 then + nQuantityOfNodes = 0 + end + + updateQuantityLabel() + updateQuantityOfNodes() end local function onIncrease() - nQuantityOfNodes = nQuantityOfNodes + NodeChildrenTestParam.kNodesIncrease - if nQuantityOfNodes > NodeChildrenTestParam.kMaxNodes then - nQuantityOfNodes = NodeChildrenTestParam.kMaxNodes - end - - updateQuantityLabel() - updateQuantityOfNodes() + nQuantityOfNodes = nQuantityOfNodes + NodeChildrenTestParam.kNodesIncrease + if nQuantityOfNodes > NodeChildrenTestParam.kMaxNodes then + nQuantityOfNodes = NodeChildrenTestParam.kMaxNodes + end + + updateQuantityLabel() + updateQuantityOfNodes() end local function SpecialInitWithQuantityOfNodes() - -- if 0 == nCurCase then - pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png") - pNewscene:addChild(pBatchNode) - --[[ - else - pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png") - pNewscene:addChild(pBatchNode) - end - ]]-- + -- if 0 == nCurCase then + pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png") + pNewscene:addChild(pBatchNode) + --[[ + else + pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png") + pNewscene:addChild(pBatchNode) + end + ]]-- end local function MainSceneInitWithQuantityOfNodes(nNodes) - local s = cc.Director:getInstance():getWinSize() - + local s = cc.Director:getInstance():getWinSize() + --Title - local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) - pNewscene:addChild(pLabel, 1) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - if (nil ~= GetSubTitle()) and ("" ~= GetSubTitle()) then - local pSubLabel = cc.LabelTTF:create(GetSubTitle(), "Thonburi", 16) - pNewscene:addChild(pSubLabel, 1) - pSubLabel:setPosition(cc.p(s.width/2, s.height-80)) + local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) + pNewscene:addChild(pLabel, 1) + pLabel:setPosition(cc.p(s.width/2, s.height-32)) + pLabel:setColor(cc.c3b(255,255,40)) + + if (nil ~= GetSubTitle()) and ("" ~= GetSubTitle()) then + local pSubLabel = cc.LabelTTF:create(GetSubTitle(), "Thonburi", 16) + pNewscene:addChild(pSubLabel, 1) + pSubLabel:setPosition(cc.p(s.width/2, s.height-80)) end - nLastRenderedCount = 0 - nCurrentQuantityOfNodes = 0 - nQuantityOfNodes = nNodes - - --"+","-" Menu - cc.MenuItemFont:setFontSize(65) - local pDecrease = cc.MenuItemFont:create(" - ") - pDecrease:registerScriptTapHandler(onDecrease) - pDecrease:setColor(cc.c3b(0,200,20)) - local pIncrease = cc.MenuItemFont:create(" + ") - pIncrease:registerScriptTapHandler(onIncrease) - pIncrease:setColor(cc.c3b(0,200,20)) - - local pMenuAddOrSub = cc.Menu:create() - pMenuAddOrSub:addChild(pDecrease) - pMenuAddOrSub:addChild(pIncrease) - pMenuAddOrSub:alignItemsHorizontally() - pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - pNewscene:addChild(pMenuAddOrSub,1) - - --InfoLayer - local pInfoLabel = cc.LabelTTF:create("0 nodes", "Marker Felt", 30) - pInfoLabel:setColor(cc.c3b(0,200,20)) - pInfoLabel:setPosition(cc.p(s.width/2, s.height/2-15)) - pNewscene:addChild(pInfoLabel, 1, NodeChildrenTestParam.kTagInfoLayer) - - --NodeChildrenMenuLayer - local pNodeChildrenMenuLayer = cc.Layer:create() - local pNodeChildrenMenuMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pNodeChildrenMenuMenu) - CreateBasicLayerMenuItem(pNodeChildrenMenuMenu,true,NodeChildrenTestParam.TEST_COUNT,nCurCase) - pNodeChildrenMenuMenu:setPosition(cc.p(0, 0)) - pNodeChildrenMenuLayer:addChild(pNodeChildrenMenuMenu) - pNewscene:addChild(pNodeChildrenMenuLayer) - - updateQuantityLabel() - updateQuantityOfNodes() - - end - - function ShowCurrentTest() - if nil ~= pNewscene then - pNewscene:unscheduleUpdate() - end - - pNewscene = cc.Scene:create() - if nil ~= pNewscene then - SpecialInitWithQuantityOfNodes() - MainSceneInitWithQuantityOfNodes(nQuantityOfNodes) --- pNewscene:registerScriptHandler(onNodeEvent) - NodeChildrenScheduleUpdate() - cc.Director:getInstance():replaceScene(pNewscene) - end + nLastRenderedCount = 0 + nCurrentQuantityOfNodes = 0 + nQuantityOfNodes = nNodes + + --"+","-" Menu + cc.MenuItemFont:setFontSize(65) + local pDecrease = cc.MenuItemFont:create(" - ") + pDecrease:registerScriptTapHandler(onDecrease) + pDecrease:setColor(cc.c3b(0,200,20)) + local pIncrease = cc.MenuItemFont:create(" + ") + pIncrease:registerScriptTapHandler(onIncrease) + pIncrease:setColor(cc.c3b(0,200,20)) + + local pMenuAddOrSub = cc.Menu:create() + pMenuAddOrSub:addChild(pDecrease) + pMenuAddOrSub:addChild(pIncrease) + pMenuAddOrSub:alignItemsHorizontally() + pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) + pNewscene:addChild(pMenuAddOrSub,1) + + --InfoLayer + local pInfoLabel = cc.LabelTTF:create("0 nodes", "Marker Felt", 30) + pInfoLabel:setColor(cc.c3b(0,200,20)) + pInfoLabel:setPosition(cc.p(s.width/2, s.height/2-15)) + pNewscene:addChild(pInfoLabel, 1, NodeChildrenTestParam.kTagInfoLayer) + + --NodeChildrenMenuLayer + local pNodeChildrenMenuLayer = cc.Layer:create() + local pNodeChildrenMenuMenu = cc.Menu:create() + CreatePerfomBasicLayerMenu(pNodeChildrenMenuMenu) + CreateBasicLayerMenuItem(pNodeChildrenMenuMenu,true,NodeChildrenTestParam.TEST_COUNT,nCurCase) + pNodeChildrenMenuMenu:setPosition(cc.p(0, 0)) + pNodeChildrenMenuLayer:addChild(pNodeChildrenMenuMenu) + pNewscene:addChild(pNodeChildrenMenuLayer) + + updateQuantityLabel() + updateQuantityOfNodes() + end - SpecialInitWithQuantityOfNodes() - MainSceneInitWithQuantityOfNodes(NodeChildrenTestParam.kNodesIncrease) --- pNewscene:registerScriptHandler(onNodeEvent) - NodeChildrenScheduleUpdate() - - return pNewscene + function ShowCurrentTest() + if nil ~= pNewscene then + pNewscene:unscheduleUpdate() + end + + pNewscene = cc.Scene:create() + if nil ~= pNewscene then + SpecialInitWithQuantityOfNodes() + MainSceneInitWithQuantityOfNodes(nQuantityOfNodes) +-- pNewscene:registerScriptHandler(onNodeEvent) + NodeChildrenScheduleUpdate() + cc.Director:getInstance():replaceScene(pNewscene) + end + end + + SpecialInitWithQuantityOfNodes() + MainSceneInitWithQuantityOfNodes(NodeChildrenTestParam.kNodesIncrease) +-- pNewscene:registerScriptHandler(onNodeEvent) + NodeChildrenScheduleUpdate() + + return pNewscene end ---------------------------------- --PerformanceParticleTest @@ -429,7 +431,7 @@ local ParticleTestParam = } local function runParticleTest() - --PerformanceParticle param + --PerformanceParticle param local nLastRenderedCount = 0 local nQuantityParticles = 0 local nSubtestNumber = 0 @@ -443,447 +445,447 @@ local function runParticleTest() local pNewScene = cc.Scene:create() local function GetTitle() - local strTitle = nil - if 0 == nCurCase then - strTitle = string.format("A (%d) size=4",nSubtestNumber) - elseif 1 == nCurCase then - strTitle = string.format("B (%d) size=8",nSubtestNumber) - elseif 2 == nCurCase then - strTitle = string.format("C (%d) size=32",nSubtestNumber) - elseif 3 == nCurCase then - strTitle = string.format("D (%d) size=64",nSubtestNumber) - end - return strTitle + local strTitle = nil + if 0 == nCurCase then + strTitle = string.format("A (%d) size=4",nSubtestNumber) + elseif 1 == nCurCase then + strTitle = string.format("B (%d) size=8",nSubtestNumber) + elseif 2 == nCurCase then + strTitle = string.format("C (%d) size=32",nSubtestNumber) + elseif 3 == nCurCase then + strTitle = string.format("D (%d) size=64",nSubtestNumber) + end + return strTitle end local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end + if nil ~= pMenu then + bControlMenuVisible = bMenuVisible + nMaxCases = nMaxCasesNum + nCurCase = nCurCaseIndex + if true == bControlMenuVisible then + local function backCallback() + nCurCase = nCurCase - 1 + if nCurCase < 0 then + nCurCase = nCurCase + nMaxCases + end + ShowCurrentTest() + end - local function restartCallback() - ShowCurrentTest() - end + local function restartCallback() + ShowCurrentTest() + end - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end + local function nextCallback() + nCurCase = nCurCase + 1 + --No check nMaxCases + nCurCase = nCurCase % nMaxCases + ShowCurrentTest() + end + + local size = cc.Director:getInstance():getWinSize() + local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) + item1:registerScriptTapHandler(backCallback) + pMenu:addChild(item1,kItemTagBasic) + local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) + item2:registerScriptTapHandler(restartCallback) + pMenu:addChild(item2,kItemTagBasic) + local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) + pMenu:addChild(item3,kItemTagBasic) + item3:registerScriptTapHandler(nextCallback) + + local size = cc.Director:getInstance():getWinSize() + item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) + item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + end + end end local function TestNCallback(tag,pMenuItem) - local nIndex = pMenuItem:getLocalZOrder() - ParticleTestParam.kSubMenuBasicZOrder - nSubtestNumber = nIndex - ShowCurrentTest() + local nIndex = pMenuItem:getLocalZOrder() - ParticleTestParam.kSubMenuBasicZOrder + nSubtestNumber = nIndex + ShowCurrentTest() end local function UpdateQuantityLabel() - if nQuantityParticles ~= nLastRenderedCount then - local pInfoLabel = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagInfoLayer), "cc.LabelTTF") - local strInfo = string.format("%u particles", nQuantityParticles) - pInfoLabel:setString(strInfo) - - nLastRenderedCount = nQuantityParticles - end + if nQuantityParticles ~= nLastRenderedCount then + local pInfoLabel = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagInfoLayer), "cc.LabelTTF") + local strInfo = string.format("%u particles", nQuantityParticles) + pInfoLabel:setString(strInfo) + + nLastRenderedCount = nQuantityParticles + end end local function doTest() - local s = cc.Director:getInstance():getWinSize() - local pParticleSystem = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"cc.ParticleSystem") - if nil == pParticleSystem then - return - end - if 0 == nCurCase then - --duration - pParticleSystem:setDuration(-1) + local s = cc.Director:getInstance():getWinSize() + local pParticleSystem = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"cc.ParticleSystem") + if nil == pParticleSystem then + return + end + if 0 == nCurCase then + --duration + pParticleSystem:setDuration(-1) - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) + --gravity + pParticleSystem:setGravity(cc.p(0,-90)) - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) + --angle + pParticleSystem:setAngle(90) + pParticleSystem:setAngleVar(0) - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) + --radial + pParticleSystem:setRadialAccel(0) + pParticleSystem:setRadialAccelVar(0) - -- speed of particles + -- speed of particles pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) + pParticleSystem:setSpeedVar(50) + + -- emitter position + pParticleSystem:setPosition(cc.p(s.width/2, 100)) + pParticleSystem:setPosVar(cc.p(s.width/2,0)) - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) + -- life of particles + pParticleSystem:setLife(2.0) + pParticleSystem:setLifeVar(1) - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) + --emits per frame + pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) + + --color of particles + pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) + pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - -- size, in pixels - pParticleSystem:setEndSize(4.0) - pParticleSystem:setStartSize(4.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) + -- size, in pixels + pParticleSystem:setEndSize(4.0) + pParticleSystem:setStartSize(4.0) + pParticleSystem:setEndSizeVar(0) + pParticleSystem:setStartSizeVar(0) - -- additive - pParticleSystem:setBlendAdditive(false) - - elseif 1 == nCurCase then - --duration - pParticleSystem:setDuration(-1) + -- additive + pParticleSystem:setBlendAdditive(false) + + elseif 1 == nCurCase then + --duration + pParticleSystem:setDuration(-1) - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) + --gravity + pParticleSystem:setGravity(cc.p(0,-90)) - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) + --angle + pParticleSystem:setAngle(90) + pParticleSystem:setAngleVar(0) - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles + --radial + pParticleSystem:setRadialAccel(0) + pParticleSystem:setRadialAccelVar(0) + + -- speed of particles pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) + pParticleSystem:setSpeedVar(50) + + -- emitter position + pParticleSystem:setPosition(cc.p(s.width/2, 100)) + pParticleSystem:setPosVar(cc.p(s.width/2,0)) - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) + -- life of particles + pParticleSystem:setLife(2.0) + pParticleSystem:setLifeVar(1) - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) + --emits per frame + pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) + + --color of particles + pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) + pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - -- size, in pixels - pParticleSystem:setEndSize(8.0) - pParticleSystem:setStartSize(8.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - elseif 2 == nCurCase then - --duration - pParticleSystem:setDuration(-1) + -- size, in pixels + pParticleSystem:setEndSize(8.0) + pParticleSystem:setStartSize(8.0) + pParticleSystem:setEndSizeVar(0) + pParticleSystem:setStartSizeVar(0) + + -- additive + pParticleSystem:setBlendAdditive(false) + elseif 2 == nCurCase then + --duration + pParticleSystem:setDuration(-1) - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) + --gravity + pParticleSystem:setGravity(cc.p(0,-90)) - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) + --angle + pParticleSystem:setAngle(90) + pParticleSystem:setAngleVar(0) - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles + --radial + pParticleSystem:setRadialAccel(0) + pParticleSystem:setRadialAccelVar(0) + + -- speed of particles pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) + pParticleSystem:setSpeedVar(50) + + -- emitter position + pParticleSystem:setPosition(cc.p(s.width/2, 100)) + pParticleSystem:setPosVar(cc.p(s.width/2,0)) - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) + -- life of particles + pParticleSystem:setLife(2.0) + pParticleSystem:setLifeVar(1) - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) + --emits per frame + pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) + + --color of particles + pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) + pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - -- size, in pixels - pParticleSystem:setEndSize(32.0) - pParticleSystem:setStartSize(32.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - elseif 3 == nCurCase then - --duration - pParticleSystem:setDuration(-1) + -- size, in pixels + pParticleSystem:setEndSize(32.0) + pParticleSystem:setStartSize(32.0) + pParticleSystem:setEndSizeVar(0) + pParticleSystem:setStartSizeVar(0) + + -- additive + pParticleSystem:setBlendAdditive(false) + elseif 3 == nCurCase then + --duration + pParticleSystem:setDuration(-1) - --gravity - pParticleSystem:setGravity(cc.p(0,-90)) + --gravity + pParticleSystem:setGravity(cc.p(0,-90)) - --angle - pParticleSystem:setAngle(90) - pParticleSystem:setAngleVar(0) + --angle + pParticleSystem:setAngle(90) + pParticleSystem:setAngleVar(0) - --radial - pParticleSystem:setRadialAccel(0) - pParticleSystem:setRadialAccelVar(0) - - -- speed of particles + --radial + pParticleSystem:setRadialAccel(0) + pParticleSystem:setRadialAccelVar(0) + + -- speed of particles pParticleSystem:setSpeed(180) - pParticleSystem:setSpeedVar(50) - - -- emitter position - pParticleSystem:setPosition(cc.p(s.width/2, 100)) - pParticleSystem:setPosVar(cc.p(s.width/2,0)) + pParticleSystem:setSpeedVar(50) + + -- emitter position + pParticleSystem:setPosition(cc.p(s.width/2, 100)) + pParticleSystem:setPosVar(cc.p(s.width/2,0)) - -- life of particles - pParticleSystem:setLife(2.0) - pParticleSystem:setLifeVar(1) + -- life of particles + pParticleSystem:setLife(2.0) + pParticleSystem:setLifeVar(1) - --emits per frame - pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) - - --color of particles - pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) + --emits per frame + pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife()) + + --color of particles + pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) + pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0)) - pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2)) - pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) + pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2)) - -- size, in pixels - pParticleSystem:setEndSize(64.0) - pParticleSystem:setStartSize(64.0) - pParticleSystem:setEndSizeVar(0) - pParticleSystem:setStartSizeVar(0) - - -- additive - pParticleSystem:setBlendAdditive(false) - end + -- size, in pixels + pParticleSystem:setEndSize(64.0) + pParticleSystem:setStartSize(64.0) + pParticleSystem:setEndSizeVar(0) + pParticleSystem:setStartSizeVar(0) + + -- additive + pParticleSystem:setBlendAdditive(false) + end end local function CreateParticleSystem() - local pParticleSystem = nil - --[[ - * Tests: - * 1: Point Particle System using 32-bit textures (PNG) - * 2: Point Particle System using 16-bit textures (PNG) - * 3: Point Particle System using 8-bit textures (PNG) - * 4: Point Particle System using 4-bit textures (PVRTC) + local pParticleSystem = nil + --[[ + * Tests: + * 1: Point Particle System using 32-bit textures (PNG) + * 2: Point Particle System using 16-bit textures (PNG) + * 3: Point Particle System using 8-bit textures (PNG) + * 4: Point Particle System using 4-bit textures (PVRTC) - * 5: Quad Particle System using 32-bit textures (PNG) - * 6: Quad Particle System using 16-bit textures (PNG) - * 7: Quad Particle System using 8-bit textures (PNG) - * 8: Quad Particle System using 4-bit textures (PVRTC) - ]]-- - pNewScene:removeChildByTag(ParticleTestParam.kTagParticleSystem, true) - - --remove the "fire.png" from the TextureCache cache. - local pTexture = cc.Director:getInstance():getTextureCache():addImage("Images/fire.png") - cc.Director:getInstance():getTextureCache():removeTexture(pTexture) - local pParticleSystem = cc.ParticleSystemQuad:createWithTotalParticles(nQuantityParticles) - if 1 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - elseif 2 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - elseif 3 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8) - elseif 4 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - elseif 5 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - elseif 6 == nSubtestNumber then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8) - else - pParticleSystem = nil - print("Shall not happen!") - end - - if nil ~= pParticleSystem then - pParticleSystem:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png")) - end - - pNewScene:addChild(pParticleSystem, 0, ParticleTestParam.kTagParticleSystem) - - doTest() - --restore the default pixel format - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - end - - local function step(t) - local pAtlas = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagLabelAtlas),"cc.LabelAtlas") - local pEmitter = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"cc.ParticleSystem") - local strInfo = string.format("%4d",pEmitter:getParticleCount()) - pAtlas:setString(strInfo) - end - - local function ScheduleFuncion() - local function OnEnterOrExit(tag) - local scheduler = cc.Director:getInstance():getScheduler() - if tag == "enter" then - ScheduleSelector = scheduler:scheduleScriptFunc(step,0,false) - elseif tag == "exit" then - scheduler:unscheduleScriptEntry(ScheduleSelector) - end - end - pNewScene:registerScriptHandler(OnEnterOrExit) - end + * 5: Quad Particle System using 32-bit textures (PNG) + * 6: Quad Particle System using 16-bit textures (PNG) + * 7: Quad Particle System using 8-bit textures (PNG) + * 8: Quad Particle System using 4-bit textures (PVRTC) + ]]-- + pNewScene:removeChildByTag(ParticleTestParam.kTagParticleSystem, true) + + --remove the "fire.png" from the TextureCache cache. + local pTexture = cc.Director:getInstance():getTextureCache():addImage("Images/fire.png") + cc.Director:getInstance():getTextureCache():removeTexture(pTexture) + local pParticleSystem = cc.ParticleSystemQuad:createWithTotalParticles(nQuantityParticles) + if 1 == nSubtestNumber then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + elseif 2 == nSubtestNumber then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) + elseif 3 == nSubtestNumber then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8) + elseif 4 == nSubtestNumber then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + elseif 5 == nSubtestNumber then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) + elseif 6 == nSubtestNumber then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8) + else + pParticleSystem = nil + print("Shall not happen!") + end + + if nil ~= pParticleSystem then + pParticleSystem:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png")) + end + + pNewScene:addChild(pParticleSystem, 0, ParticleTestParam.kTagParticleSystem) + + doTest() + --restore the default pixel format + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + end + + local function step(t) + local pAtlas = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagLabelAtlas),"cc.LabelAtlas") + local pEmitter = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"cc.ParticleSystem") + local strInfo = string.format("%4d",pEmitter:getParticleCount()) + pAtlas:setString(strInfo) + end + + local function ScheduleFuncion() + local function OnEnterOrExit(tag) + local scheduler = cc.Director:getInstance():getScheduler() + if tag == "enter" then + ScheduleSelector = scheduler:scheduleScriptFunc(step,0,false) + elseif tag == "exit" then + scheduler:unscheduleScriptEntry(ScheduleSelector) + end + end + pNewScene:registerScriptHandler(OnEnterOrExit) + end local function onDecrease() - nQuantityParticles = nQuantityParticles - ParticleTestParam.kNodesIncrease - if nQuantityParticles < 0 then - nQuantityParticles = 0 + nQuantityParticles = nQuantityParticles - ParticleTestParam.kNodesIncrease + if nQuantityParticles < 0 then + nQuantityParticles = 0 end - UpdateQuantityLabel() - CreateParticleSystem() + UpdateQuantityLabel() + CreateParticleSystem() end local function onIncrease() - nQuantityParticles = nQuantityParticles + ParticleTestParam.kNodesIncrease - if nQuantityParticles > ParticleTestParam.kMaxParticles then - nQuantityParticles = ParticleTestParam.kMaxParticles + nQuantityParticles = nQuantityParticles + ParticleTestParam.kNodesIncrease + if nQuantityParticles > ParticleTestParam.kMaxParticles then + nQuantityParticles = ParticleTestParam.kMaxParticles end - UpdateQuantityLabel() - CreateParticleSystem() + UpdateQuantityLabel() + CreateParticleSystem() end local function InitWithSubTest(nSubtest,nParticles) - nSubtestNumber = nSubtest - local s = cc.Director:getInstance():getWinSize() - - nLastRenderedCount = 0 - nQuantityParticles = nParticles - - --"+","-" Menu - cc.MenuItemFont:setFontSize(65) - local pDecrease = cc.MenuItemFont:create(" - ") - pDecrease:registerScriptTapHandler(onDecrease) - pDecrease:setColor(cc.c3b(0,200,20)) - local pIncrease = cc.MenuItemFont:create(" + ") - pIncrease:registerScriptTapHandler(onIncrease) - pIncrease:setColor(cc.c3b(0,200,20)) - - local pMenuAddOrSub = cc.Menu:create() - pMenuAddOrSub:addChild(pDecrease) - pMenuAddOrSub:addChild(pIncrease) - pMenuAddOrSub:alignItemsHorizontally() - pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - pNewScene:addChild(pMenuAddOrSub,1) - - local pInfoLabel = cc.LabelTTF:create("0 nodes", "Marker Felt", 30) + nSubtestNumber = nSubtest + local s = cc.Director:getInstance():getWinSize() + + nLastRenderedCount = 0 + nQuantityParticles = nParticles + + --"+","-" Menu + cc.MenuItemFont:setFontSize(65) + local pDecrease = cc.MenuItemFont:create(" - ") + pDecrease:registerScriptTapHandler(onDecrease) + pDecrease:setColor(cc.c3b(0,200,20)) + local pIncrease = cc.MenuItemFont:create(" + ") + pIncrease:registerScriptTapHandler(onIncrease) + pIncrease:setColor(cc.c3b(0,200,20)) + + local pMenuAddOrSub = cc.Menu:create() + pMenuAddOrSub:addChild(pDecrease) + pMenuAddOrSub:addChild(pIncrease) + pMenuAddOrSub:alignItemsHorizontally() + pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) + pNewScene:addChild(pMenuAddOrSub,1) + + local pInfoLabel = cc.LabelTTF:create("0 nodes", "Marker Felt", 30) pInfoLabel:setColor(cc.c3b(0,200,20)) - pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90)) - pNewScene:addChild(pInfoLabel, 1, ParticleTestParam.kTagInfoLayer) - - --particles on stage - local pLabelAtlas = cc.LabelAtlas:_create("0000", "fps_images.png", 12, 32, string.byte('.')) - pNewScene:addChild(pLabelAtlas, 0, ParticleTestParam.kTagLabelAtlas) - pLabelAtlas:setPosition(cc.p(s.width-66,50)) - - --ParticleTestMenuLayer - local pParticleMenuLayer = cc.Layer:create() - local pParticleMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pParticleMenu) - CreateBasicLayerMenuItem(pParticleMenu,true,ParticleTestParam.TEST_COUNT,nCurCase) - pParticleMenu:setPosition(cc.p(0, 0)) - pParticleMenuLayer:addChild(pParticleMenu) - pNewScene:addChild(pParticleMenuLayer) - - --Sub Tests - cc.MenuItemFont:setFontSize(40) - local pSubMenu = cc.Menu:create() - local i = 1 - for i = 1, 6 do - local strNum = string.format("%d ",i) - local pItemFont = cc.MenuItemFont:create(strNum) - pItemFont:registerScriptTapHandler(TestNCallback) - pSubMenu:addChild(pItemFont, i + ParticleTestParam.kSubMenuBasicZOrder) - if i <= 3 then - pItemFont:setColor(cc.c3b(200,20,20)) - else - pItemFont:setColor(cc.c3b(0,200,20)) - end - end - pSubMenu:alignItemsHorizontally() - pSubMenu:setPosition(cc.p(s.width/2, 80)) - pNewScene:addChild(pSubMenu, 2) - - local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) - pNewScene:addChild(pLabel, 1) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - UpdateQuantityLabel() - CreateParticleSystem() - ScheduleFuncion() + pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90)) + pNewScene:addChild(pInfoLabel, 1, ParticleTestParam.kTagInfoLayer) + + --particles on stage + local pLabelAtlas = cc.LabelAtlas:_create("0000", "fps_images.png", 12, 32, string.byte('.')) + pNewScene:addChild(pLabelAtlas, 0, ParticleTestParam.kTagLabelAtlas) + pLabelAtlas:setPosition(cc.p(s.width-66,50)) + + --ParticleTestMenuLayer + local pParticleMenuLayer = cc.Layer:create() + local pParticleMenu = cc.Menu:create() + CreatePerfomBasicLayerMenu(pParticleMenu) + CreateBasicLayerMenuItem(pParticleMenu,true,ParticleTestParam.TEST_COUNT,nCurCase) + pParticleMenu:setPosition(cc.p(0, 0)) + pParticleMenuLayer:addChild(pParticleMenu) + pNewScene:addChild(pParticleMenuLayer) + + --Sub Tests + cc.MenuItemFont:setFontSize(40) + local pSubMenu = cc.Menu:create() + local i = 1 + for i = 1, 6 do + local strNum = string.format("%d ",i) + local pItemFont = cc.MenuItemFont:create(strNum) + pItemFont:registerScriptTapHandler(TestNCallback) + pSubMenu:addChild(pItemFont, i + ParticleTestParam.kSubMenuBasicZOrder) + if i <= 3 then + pItemFont:setColor(cc.c3b(200,20,20)) + else + pItemFont:setColor(cc.c3b(0,200,20)) + end + end + pSubMenu:alignItemsHorizontally() + pSubMenu:setPosition(cc.p(s.width/2, 80)) + pNewScene:addChild(pSubMenu, 2) + + local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) + pNewScene:addChild(pLabel, 1) + pLabel:setPosition(cc.p(s.width/2, s.height-32)) + pLabel:setColor(cc.c3b(255,255,40)) + + UpdateQuantityLabel() + CreateParticleSystem() + ScheduleFuncion() end function ShowCurrentTest() - if nil ~= pNewScene then - cc.Director:getInstance():getScheduler():unscheduleScriptEntry(ScheduleSelector) - end - pNewScene = cc.Scene:create() - InitWithSubTest(nSubtestNumber,nQuantityParticles) - cc.Director:getInstance():replaceScene(pNewScene) + if nil ~= pNewScene then + cc.Director:getInstance():getScheduler():unscheduleScriptEntry(ScheduleSelector) + end + pNewScene = cc.Scene:create() + InitWithSubTest(nSubtestNumber,nQuantityParticles) + cc.Director:getInstance():replaceScene(pNewScene) end - - InitWithSubTest(1,ParticleTestParam.kNodesIncrease) - return pNewScene + + InitWithSubTest(1,ParticleTestParam.kNodesIncrease) + return pNewScene end ---------------------------------- @@ -891,7 +893,7 @@ end ---------------------------------- local SpriteTestParam = { - kMaxNodes = 50000, + kMaxNodes = 50000, kNodesIncrease = 250, TEST_COUNT = 7, @@ -906,7 +908,7 @@ local SpriteTestParam = } local function runSpriteTest() - --PerformanceParticle param + --PerformanceParticle param local nLastRenderedCount = 0 local nQuantityNodes = 0 local nSubtestNumber = 0 @@ -921,170 +923,170 @@ local function runSpriteTest() local pBatchNode = nil local function GetTitle() - local strTitle = nil - if 0 == nCurCase then - strTitle = string.format("A (%d) position",nSubtestNumber) - elseif 1 == nCurCase then - strTitle = string.format("B (%d) scale",nSubtestNumber) - elseif 2 == nCurCase then - strTitle = string.format("C (%d) scale + rot",nSubtestNumber) - elseif 3 == nCurCase then - strTitle = string.format("D (%d) 100%% out",nSubtestNumber) - elseif 4 == nCurCase then - strTitle = string.format("E (%d) 80%% out",nSubtestNumber) - elseif 5 == nCurCase then - strTitle = string.format("F (%d) actions",nSubtestNumber) - elseif 6 == nCurCase then - strTitle = string.format("G (%d) actions 80%% out",nSubtestNumber) - end - - return strTitle + local strTitle = nil + if 0 == nCurCase then + strTitle = string.format("A (%d) position",nSubtestNumber) + elseif 1 == nCurCase then + strTitle = string.format("B (%d) scale",nSubtestNumber) + elseif 2 == nCurCase then + strTitle = string.format("C (%d) scale + rot",nSubtestNumber) + elseif 3 == nCurCase then + strTitle = string.format("D (%d) 100%% out",nSubtestNumber) + elseif 4 == nCurCase then + strTitle = string.format("E (%d) 80%% out",nSubtestNumber) + elseif 5 == nCurCase then + strTitle = string.format("F (%d) actions",nSubtestNumber) + elseif 6 == nCurCase then + strTitle = string.format("G (%d) actions 80%% out",nSubtestNumber) + end + + return strTitle end local pNewScene = cc.Scene:create() local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end + if nil ~= pMenu then + bControlMenuVisible = bMenuVisible + nMaxCases = nMaxCasesNum + nCurCase = nCurCaseIndex + if true == bControlMenuVisible then + local function backCallback() + nCurCase = nCurCase - 1 + if nCurCase < 0 then + nCurCase = nCurCase + nMaxCases + end + ShowCurrentTest() + end - local function restartCallback() - ShowCurrentTest() - end + local function restartCallback() + ShowCurrentTest() + end - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end + local function nextCallback() + nCurCase = nCurCase + 1 + --No check nMaxCases + nCurCase = nCurCase % nMaxCases + ShowCurrentTest() + end + + local size = cc.Director:getInstance():getWinSize() + local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) + item1:registerScriptTapHandler(backCallback) + pMenu:addChild(item1,kItemTagBasic) + local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) + item2:registerScriptTapHandler(restartCallback) + pMenu:addChild(item2,kItemTagBasic) + local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) + pMenu:addChild(item3,kItemTagBasic) + item3:registerScriptTapHandler(nextCallback) + + local size = cc.Director:getInstance():getWinSize() + item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) + item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + end + end end local function UpdateNodes() - if nQuantityNodes ~= nLastRenderedCount then - local pInfoLabel = tolua.cast(pNewScene:getChildByTag(SpriteTestParam.kTagInfoLayer), "cc.LabelTTF") - local strInfo = string.format("%u nodes", nQuantityNodes) - pInfoLabel:setString(strInfo) - nLastRenderedCount = nQuantityNodes - end + if nQuantityNodes ~= nLastRenderedCount then + local pInfoLabel = tolua.cast(pNewScene:getChildByTag(SpriteTestParam.kTagInfoLayer), "cc.LabelTTF") + local strInfo = string.format("%u nodes", nQuantityNodes) + pInfoLabel:setString(strInfo) + nLastRenderedCount = nQuantityNodes + end end local function PerformancePosition(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) + local size = cc.Director:getInstance():getWinSize() + pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) end local function PerformanceScale(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - pSprite:setScale(math.random() * 100 / 50) - end - - local function PerformanceRotationScale(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - pSprite:setRotation(math.random() * 360) - pSprite:setScale(math.random() * 2) - end - - local function PerformanceOut100(pSprite) - pSprite:setPosition(cc.p( -1000, -1000)) - end - - local function Performanceout20(pSprite) - local size = cc.Director:getInstance():getWinSize() + local size = cc.Director:getInstance():getWinSize() + pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) + pSprite:setScale(math.random() * 100 / 50) + end + + local function PerformanceRotationScale(pSprite) + local size = cc.Director:getInstance():getWinSize() + pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) + pSprite:setRotation(math.random() * 360) + pSprite:setScale(math.random() * 2) + end + + local function PerformanceOut100(pSprite) + pSprite:setPosition(cc.p( -1000, -1000)) + end + + local function Performanceout20(pSprite) + local size = cc.Director:getInstance():getWinSize() + print("come in") + if math.random() < 0.2 then + pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) + else + pSprite:setPosition(cc.p( -1000, -1000)) + end + end + + local function PerformanceActions(pSprite) + local size = cc.Director:getInstance():getWinSize() + pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - if math.random() < 0.2 then - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - else - pSprite:setPosition(cc.p( -1000, -1000)) - end - end - - local function PerformanceActions(pSprite) - local size = cc.Director:getInstance():getWinSize() - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) + local fPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 + local pRot = cc.RotateBy:create(fPeriod, 360.0 * math.random() ) + local pRot_back = pRot:reverse() + local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back)) + pSprite:runAction(pPermanentRotation) - local fPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pRot = cc.RotateBy:create(fPeriod, 360.0 * math.random() ) - local pRot_back = pRot:reverse() - local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back)) - pSprite:runAction(pPermanentRotation) - - local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5) - local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse())) - pSprite:runAction(pPermanentScaleLoop) - end - - local function PerformanceActions20(pSprite) - local size = cc.Director:getInstance():getWinSize() - - if math.random() < 0.2 then - pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) - else - pSprite:setPosition(cc.p( -1000, -1000)) + local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 + local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5) + local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse())) + pSprite:runAction(pPermanentScaleLoop) + end + + local function PerformanceActions20(pSprite) + local size = cc.Director:getInstance():getWinSize() + + if math.random() < 0.2 then + pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height)))) + else + pSprite:setPosition(cc.p( -1000, -1000)) end - local pPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pRot = cc.RotateBy:create(pPeriod, 360.0 * math.random()) - local pRot_back = pRot:reverse() - local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back)) - pSprite:runAction(pPermanentRotation) + local pPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 + local pRot = cc.RotateBy:create(pPeriod, 360.0 * math.random()) + local pRot_back = pRot:reverse() + local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back)) + pSprite:runAction(pPermanentRotation) - local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 - local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5) + local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0 + local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5) local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse())) - pSprite:runAction(pPermanentScaleLoop) - - end - - local function CreateSpriteWithTag(nTag) + pSprite:runAction(pPermanentScaleLoop) + + end + + local function CreateSpriteWithTag(nTag) --create - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - local pSprite = nil - if 1 == nSubtestNumber then - pSprite = cc.Sprite:create("Images/grossinis_sister1.png") + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + local pSprite = nil + if 1 == nSubtestNumber then + pSprite = cc.Sprite:create("Images/grossinis_sister1.png") pNewScene:addChild(pSprite, 0, nTag+100) - elseif 2 == nSubtestNumber or 3 == nSubtestNumber then - pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 52, 139)) + elseif 2 == nSubtestNumber or 3 == nSubtestNumber then + pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 52, 139)) pBatchNode:addChild(pSprite, 0, nTag+100) - elseif 4 == nSubtestNumber then - local nIndex = math.floor((math.random() * 1400 / 100)) + 1 + elseif 4 == nSubtestNumber then + local nIndex = math.floor((math.random() * 1400 / 100)) + 1 local strPath = string.format("Images/grossini_dance_%02d.png", nIndex) pSprite = cc.Sprite:create(strPath) pNewScene:addChild(pSprite, 0, nTag+100) - elseif 5 == nSubtestNumber or 6 == nSubtestNumber then - local nY = 0 - local nX = 0 + elseif 5 == nSubtestNumber or 6 == nSubtestNumber then + local nY = 0 + local nX = 0 local nR = math.floor(math.random() * 1400 / 100) nX = nR % 5 @@ -1094,231 +1096,231 @@ local function runSpriteTest() nY = nY * 121 pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(nX,nY,85,121)) pBatchNode:addChild(pSprite, 0, nTag+100) - elseif 7 == nSubtestNumber then - local nX = 0 - local nY = 0 + elseif 7 == nSubtestNumber then + local nX = 0 + local nY = 0 local nR = math.floor(math.random() * 6400 / 100) - nX = nR % 8 + nX = nR % 8 nY = math.floor(nR / 8) local strPath = string.format("Images/sprites_test/sprite-%d-%d.png", nX, nY) pSprite = cc.Sprite:create(strPath) pNewScene:addChild(pSprite, 0, nTag+100) - elseif 8 == nSubtestNumber or 9 == nSubtestNumber then - local nX = 0 - local nY = 0 + elseif 8 == nSubtestNumber or 9 == nSubtestNumber then + local nX = 0 + local nY = 0 local nR = math.floor(math.random() * 6400 / 100) - nX = nR % 8 + nX = nR % 8 nY = math.floor(nR / 8) nX = nX * 32 nY = nY * 32 pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(nX,nY,32,32)) pBatchNode:addChild(pSprite, 0, nTag+100) - end - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT ) - - return pSprite + end + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT ) + + return pSprite end local function RemoveByTag(nTag) - if 1 == nSubtestNumber or 4 == nSubtestNumber or 7 == nSubtestNumber then - pNewScene:removeChildByTag(nTag + 100, true) - elseif 2 == nSubtestNumber or 3 == nSubtestNumber or 5 == nSubtestNumber or 6 == nSubtestNumber or 8 == nSubtestNumber or 9 == nSubtestNumber then - pBatchNode:removeChildAtIndex(nTag,true) - end - + if 1 == nSubtestNumber or 4 == nSubtestNumber or 7 == nSubtestNumber then + pNewScene:removeChildByTag(nTag + 100, true) + elseif 2 == nSubtestNumber or 3 == nSubtestNumber or 5 == nSubtestNumber or 6 == nSubtestNumber or 8 == nSubtestNumber or 9 == nSubtestNumber then + pBatchNode:removeChildAtIndex(nTag,true) + end + end local function DoTest(pSprite) - if 0 == nCurCase then - PerformancePosition(pSprite) - elseif 1 == nCurCase then - PerformanceScale(pSprite) - elseif 2 == nCurCase then - PerformanceRotationScale(pSprite) - elseif 3 == nCurCase then - PerformanceOut100(pSprite) - elseif 4 == nCurCase then - Performanceout20(pSprite) - elseif 5 == nCurCase then - PerformanceActions(pSprite) - elseif 6 == nCurCase then - PerformanceActions20(pSprite) - end + if 0 == nCurCase then + PerformancePosition(pSprite) + elseif 1 == nCurCase then + PerformanceScale(pSprite) + elseif 2 == nCurCase then + PerformanceRotationScale(pSprite) + elseif 3 == nCurCase then + PerformanceOut100(pSprite) + elseif 4 == nCurCase then + Performanceout20(pSprite) + elseif 5 == nCurCase then + PerformanceActions(pSprite) + elseif 6 == nCurCase then + PerformanceActions20(pSprite) + end end local function onDecrease() - if nQuantityNodes <= 0 then - return - end - - local i = 0 - for i = 0 , SpriteTestParam.kNodesIncrease - 1 do - nQuantityNodes = nQuantityNodes - 1 - RemoveByTag(nQuantityNodes) - end - UpdateNodes() + if nQuantityNodes <= 0 then + return + end + + local i = 0 + for i = 0 , SpriteTestParam.kNodesIncrease - 1 do + nQuantityNodes = nQuantityNodes - 1 + RemoveByTag(nQuantityNodes) + end + UpdateNodes() end local function onIncrease() - if nQuantityNodes >= SpriteTestParam.kMaxNodes then - return - end - - local i = 0 - for i = 0,SpriteTestParam.kNodesIncrease - 1 do - local pSprite = CreateSpriteWithTag(nQuantityNodes) + if nQuantityNodes >= SpriteTestParam.kMaxNodes then + return + end + + local i = 0 + for i = 0,SpriteTestParam.kNodesIncrease - 1 do + local pSprite = CreateSpriteWithTag(nQuantityNodes) DoTest(pSprite) - nQuantityNodes = nQuantityNodes + 1 - end - UpdateNodes() + nQuantityNodes = nQuantityNodes + 1 + end + UpdateNodes() end local function TestNCallback(tag,pMenuItem) - local nIndex = pMenuItem:getLocalZOrder() - SpriteTestParam.kSubMenuBasicZOrder - nSubtestNumber = nIndex - ShowCurrentTest() + local nIndex = pMenuItem:getLocalZOrder() - SpriteTestParam.kSubMenuBasicZOrder + nSubtestNumber = nIndex + ShowCurrentTest() end local function InitWithSubTest(nSubTest) - pBatchNode = nil - --[[ - * 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 + pBatchNode = nil + --[[ + * 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 - * 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 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 - * 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 - ]]-- - --purge textures - local pMgr = cc.Director:getInstance():getTextureCache() - --[mgr removeAllTextures] - pMgr:removeTexture(pMgr:addImage("Images/grossinis_sister1.png")) - pMgr:removeTexture(pMgr:addImage("Images/grossini_dance_atlas.png")) - pMgr:removeTexture(pMgr:addImage("Images/spritesheet1.png")) - - if 1 == nSubTest or 4 == nSubTest or 7 == nSubTest then - elseif 2 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + * 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 + ]]-- + --purge textures + local pMgr = cc.Director:getInstance():getTextureCache() + --[mgr removeAllTextures] + pMgr:removeTexture(pMgr:addImage("Images/grossinis_sister1.png")) + pMgr:removeTexture(pMgr:addImage("Images/grossini_dance_atlas.png")) + pMgr:removeTexture(pMgr:addImage("Images/spritesheet1.png")) + + if 1 == nSubTest or 4 == nSubTest or 7 == nSubTest then + elseif 2 == nSubTest then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) pBatchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100) pNewScene:addChild(pBatchNode, 0) - elseif 3 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) + elseif 3 == nSubTest then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) pBatchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100) pNewScene:addChild(pBatchNode, 0) - elseif 5 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + elseif 5 == nSubTest then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) pBatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100) pNewScene:addChild(pBatchNode, 0) - elseif 6 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) + elseif 6 == nSubTest then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) pBatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100) pNewScene:addChild(pBatchNode, 0) - elseif 8 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + elseif 8 == nSubTest then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100) pNewScene:addChild(pBatchNode, 0) - elseif 9 == nSubTest then - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) + elseif 9 == nSubTest then + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100) pNewScene:addChild(pBatchNode, 0) - end - - if nil ~= pBatchNode then - pBatchNode:retain() - end + end + + if nil ~= pBatchNode then + pBatchNode:retain() + end - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT ) + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT ) end local function InitWithSpriteTest(nSubtest,nNodes) - nSubtestNumber = nSubtest - --about create subset - InitWithSubTest(nSubtest) - local s = cc.Director:getInstance():getWinSize() - - nLastRenderedCount = 0 - nQuantityNodes = 0 - - --"+","-" Menu - cc.MenuItemFont:setFontSize(65) - local pDecrease = cc.MenuItemFont:create(" - ") - pDecrease:registerScriptTapHandler(onDecrease) - pDecrease:setColor(cc.c3b(0,200,20)) - local pIncrease = cc.MenuItemFont:create(" + ") - pIncrease:registerScriptTapHandler(onIncrease) - pIncrease:setColor(cc.c3b(0,200,20)) - - local pMenuAddOrSub = cc.Menu:create() - pMenuAddOrSub:addChild(pDecrease) - pMenuAddOrSub:addChild(pIncrease) - pMenuAddOrSub:alignItemsHorizontally() - pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - pNewScene:addChild(pMenuAddOrSub,1) - - local pInfoLabel = cc.LabelTTF:create("0 nodes", "Marker Felt", 30) + nSubtestNumber = nSubtest + --about create subset + InitWithSubTest(nSubtest) + local s = cc.Director:getInstance():getWinSize() + + nLastRenderedCount = 0 + nQuantityNodes = 0 + + --"+","-" Menu + cc.MenuItemFont:setFontSize(65) + local pDecrease = cc.MenuItemFont:create(" - ") + pDecrease:registerScriptTapHandler(onDecrease) + pDecrease:setColor(cc.c3b(0,200,20)) + local pIncrease = cc.MenuItemFont:create(" + ") + pIncrease:registerScriptTapHandler(onIncrease) + pIncrease:setColor(cc.c3b(0,200,20)) + + local pMenuAddOrSub = cc.Menu:create() + pMenuAddOrSub:addChild(pDecrease) + pMenuAddOrSub:addChild(pIncrease) + pMenuAddOrSub:alignItemsHorizontally() + pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) + pNewScene:addChild(pMenuAddOrSub,1) + + local pInfoLabel = cc.LabelTTF:create("0 nodes", "Marker Felt", 30) pInfoLabel:setColor(cc.c3b(0,200,20)) - pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90)) - pNewScene:addChild(pInfoLabel, 1, SpriteTestParam.kTagInfoLayer) - - --SpriteTestMenuLayer - local pSpriteMenuLayer = cc.Layer:create() - local pSpriteMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pSpriteMenu) - CreateBasicLayerMenuItem(pSpriteMenu,true,SpriteTestParam.TEST_COUNT,nCurCase) - pSpriteMenu:setPosition(cc.p(0, 0)) - pSpriteMenuLayer:addChild(pSpriteMenu) - pNewScene:addChild(pSpriteMenuLayer,1,SpriteTestParam.kTagMenuLayer) - - - --Sub Tests - cc.MenuItemFont:setFontSize(40) - local pSubMenu = cc.Menu:create() - local i = 1 - for i = 1, 9 do - local strNum = string.format("%d ",i) - local pItemFont = cc.MenuItemFont:create(strNum) - pItemFont:registerScriptTapHandler(TestNCallback) - pSubMenu:addChild(pItemFont, i + SpriteTestParam.kSubMenuBasicZOrder) - if i <= 3 then - pItemFont:setColor(cc.c3b(200,20,20)) - elseif i <= 6 then - pItemFont:setColor(cc.c3b(0,200,20)) - else - pItemFont:setColor(cc.c3b(0,20,200)) - end - end - - - pSubMenu:alignItemsHorizontally() - pSubMenu:setPosition(cc.p(s.width/2, 80)) - pNewScene:addChild(pSubMenu, 2) - - local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) - pNewScene:addChild(pLabel, 1) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - while nQuantityNodes < nNodes do - onIncrease() - end + pInfoLabel:setPosition(cc.p(s.width/2, s.height - 90)) + pNewScene:addChild(pInfoLabel, 1, SpriteTestParam.kTagInfoLayer) + + --SpriteTestMenuLayer + local pSpriteMenuLayer = cc.Layer:create() + local pSpriteMenu = cc.Menu:create() + CreatePerfomBasicLayerMenu(pSpriteMenu) + CreateBasicLayerMenuItem(pSpriteMenu,true,SpriteTestParam.TEST_COUNT,nCurCase) + pSpriteMenu:setPosition(cc.p(0, 0)) + pSpriteMenuLayer:addChild(pSpriteMenu) + pNewScene:addChild(pSpriteMenuLayer,1,SpriteTestParam.kTagMenuLayer) + + + --Sub Tests + cc.MenuItemFont:setFontSize(40) + local pSubMenu = cc.Menu:create() + local i = 1 + for i = 1, 9 do + local strNum = string.format("%d ",i) + local pItemFont = cc.MenuItemFont:create(strNum) + pItemFont:registerScriptTapHandler(TestNCallback) + pSubMenu:addChild(pItemFont, i + SpriteTestParam.kSubMenuBasicZOrder) + if i <= 3 then + pItemFont:setColor(cc.c3b(200,20,20)) + elseif i <= 6 then + pItemFont:setColor(cc.c3b(0,200,20)) + else + pItemFont:setColor(cc.c3b(0,20,200)) + end + end + + + pSubMenu:alignItemsHorizontally() + pSubMenu:setPosition(cc.p(s.width/2, 80)) + pNewScene:addChild(pSubMenu, 2) + + local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) + pNewScene:addChild(pLabel, 1) + pLabel:setPosition(cc.p(s.width/2, s.height-32)) + pLabel:setColor(cc.c3b(255,255,40)) + while nQuantityNodes < nNodes do + onIncrease() + end end - function ShowCurrentTest() - pNewScene = cc.Scene:create() - InitWithSpriteTest(nSubtestNumber,nQuantityNodes) - cc.Director:getInstance():replaceScene(pNewScene) + function ShowCurrentTest() + pNewScene = cc.Scene:create() + InitWithSpriteTest(nSubtestNumber,nQuantityNodes) + cc.Director:getInstance():replaceScene(pNewScene) end InitWithSpriteTest(1,SpriteTestParam.kInitNodes) @@ -1331,111 +1333,111 @@ end ---------------------------------- local TextureTestParam = { - TEST_COUNT = 1, + TEST_COUNT = 1, } local function runTextureTest() - - local function GetTitle() - return "Texture Performance Test" - end - - local function GetSubtitle() - return "See console for results" - end - - local nTexCurCase = 0 - local pNewscene = cc.Scene:create() - local pLayer = cc.Layer:create() - local s = cc.Director:getInstance():getWinSize() - - local function PerformTestsPNG(strFileName) - local time - local pTexture = nil - local pCache = cc.Director:getInstance():getTextureCache() + + local function GetTitle() + return "Texture Performance Test" + end + + local function GetSubtitle() + return "See console for results" + end + + local nTexCurCase = 0 + local pNewscene = cc.Scene:create() + local pLayer = cc.Layer:create() + local s = cc.Director:getInstance():getWinSize() + + local function PerformTestsPNG(strFileName) + local time + local pTexture = nil + local pCache = cc.Director:getInstance():getTextureCache() local pDefaultFormat = cc.Texture2D:getDefaultAlphaPixelFormat(); - print("RGBA 8888") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - --os.time()--get secs,not micr sec - print("add sucess") - else - print(" ERROR") - end - pCache:removeTexture(pTexture) - - print("RGBA 4444") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) - --gettimeofday(&now, NULL) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then + print("RGBA 8888") + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888) + pTexture = pCache:addImage(strFileName) + if nil ~= pTexture then + --os.time()--get secs,not micr sec print("add sucess") - else - print(" ERROR") + else + print(" ERROR") end - pCache:removeTexture(pTexture) - - print("RGBA 5551") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB5_A1) - --gettimeofday(&now, NULL) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - print("add sucess") - else - print(" ERROR") + pCache:removeTexture(pTexture) + + print("RGBA 4444") + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444) + --gettimeofday(&now, NULL) + pTexture = pCache:addImage(strFileName) + if nil ~= pTexture then + print("add sucess") + else + print(" ERROR") end - pCache:removeTexture(pTexture) - - print("RGB 565") - cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RG_B565) - -- gettimeofday(&now, NULL) - pTexture = pCache:addImage(strFileName) - if nil ~= pTexture then - --log(" ms:%f", calculateDeltaTime(&now) ) - print("add sucess") - else - print(" ERROR") - end - pCache:removeTexture(pTexture) + pCache:removeTexture(pTexture) + + print("RGBA 5551") + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB5_A1) + --gettimeofday(&now, NULL) + pTexture = pCache:addImage(strFileName) + if nil ~= pTexture then + print("add sucess") + else + print(" ERROR") + end + pCache:removeTexture(pTexture) + + print("RGB 565") + cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RG_B565) + -- gettimeofday(&now, NULL) + pTexture = pCache:addImage(strFileName) + if nil ~= pTexture then + --log(" ms:%f", calculateDeltaTime(&now) ) + print("add sucess") + else + print(" ERROR") + end + pCache:removeTexture(pTexture) cc.Texture2D:setDefaultAlphaPixelFormat(pDefaultFormat) - end - local function PerformTests() - print("--------") - print("--- PNG 128x128 ---") - PerformTestsPNG("Images/test_image.png") - - print("--- PNG 512x512 ---") - PerformTestsPNG("Images/texture512x512.png") - - print("EMPTY IMAGE") - print("--- PNG 1024x1024 ---") - PerformTestsPNG("Images/texture1024x1024.png") - - print("SPRITESHEET IMAGE") - print("--- PNG 1024x1024 ---") - PerformTestsPNG("Images/PlanetCute-1024x1024.png") - - print("LANDSCAPE IMAGE") - print("--- PNG 1024x1024 ---") - PerformTestsPNG("Images/landscape-1024x1024.png") - end - - local function InitTextureMenuLayer() - if nil == pLayer then - return - end - - --Title - local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) - pLayer:addChild(pLabel, 1) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) + end + local function PerformTests() + print("--------") + print("--- PNG 128x128 ---") + PerformTestsPNG("Images/test_image.png") + + print("--- PNG 512x512 ---") + PerformTestsPNG("Images/texture512x512.png") + + print("EMPTY IMAGE") + print("--- PNG 1024x1024 ---") + PerformTestsPNG("Images/texture1024x1024.png") + + print("SPRITESHEET IMAGE") + print("--- PNG 1024x1024 ---") + PerformTestsPNG("Images/PlanetCute-1024x1024.png") + + print("LANDSCAPE IMAGE") + print("--- PNG 1024x1024 ---") + PerformTestsPNG("Images/landscape-1024x1024.png") + end + + local function InitTextureMenuLayer() + if nil == pLayer then + return + end + + --Title + local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) + pLayer:addChild(pLabel, 1) + pLabel:setPosition(cc.p(s.width/2, s.height-32)) + pLabel:setColor(cc.c3b(255,255,40)) - --Subtitle + --Subtitle local pSubLabel = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16) pLayer:addChild(pSubLabel, 1) pSubLabel:setPosition(cc.p(s.width/2, s.height-80)) @@ -1447,23 +1449,23 @@ local function runTextureTest() pLayer:addChild(pMenu) PerformTests() - end - - InitTextureMenuLayer() - pNewscene:addChild(pLayer) - return pNewscene + end + + InitTextureMenuLayer() + pNewscene:addChild(pLayer) + return pNewscene end ---------------------------------- --PerformanceTouchesTest ---------------------------------- local TouchesTestParam = { - TEST_COUNT = 2, + TEST_COUNT = 2, } local function runTouchesTest() - local nTouchCurCase = 0 - --PerformBasicLayer param - local bControlMenuVisible = false + local nTouchCurCase = 0 + --PerformBasicLayer param + local bControlMenuVisible = false local nMaxCases = 0 local nCurCase = 0 --TouchesMainScene param @@ -1475,80 +1477,80 @@ local function runTouchesTest() local fElapsedTime = 0.0 local s = cc.Director:getInstance():getWinSize() - local pNewscene = cc.Scene:create() - local pLayer = cc.Layer:create() - + local pNewscene = cc.Scene:create() + local pLayer = cc.Layer:create() + local function GetTitle() - if 0 == nCurCase then - return "Targeted touches" - elseif 1 == nCurCase then - return "Standard touches" - end + if 0 == nCurCase then + return "Targeted touches" + elseif 1 == nCurCase then + return "Standard touches" + end end - + local function CreateBasicLayerMenuItem(pMenu,bMenuVisible,nMaxCasesNum,nCurCaseIndex) - if nil ~= pMenu then - bControlMenuVisible = bMenuVisible - nMaxCases = nMaxCasesNum - nCurCase = nCurCaseIndex - if true == bControlMenuVisible then - local function backCallback() - nCurCase = nCurCase - 1 - if nCurCase < 0 then - nCurCase = nCurCase + nMaxCases - end - ShowCurrentTest() - end + if nil ~= pMenu then + bControlMenuVisible = bMenuVisible + nMaxCases = nMaxCasesNum + nCurCase = nCurCaseIndex + if true == bControlMenuVisible then + local function backCallback() + nCurCase = nCurCase - 1 + if nCurCase < 0 then + nCurCase = nCurCase + nMaxCases + end + ShowCurrentTest() + end - local function restartCallback() - ShowCurrentTest() - end + local function restartCallback() + ShowCurrentTest() + end - local function nextCallback() - nCurCase = nCurCase + 1 - --No check nMaxCases - nCurCase = nCurCase % nMaxCases - ShowCurrentTest() - end - - local size = cc.Director:getInstance():getWinSize() - local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) - item1:registerScriptTapHandler(backCallback) - pMenu:addChild(item1,kItemTagBasic) - local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) - item2:registerScriptTapHandler(restartCallback) - pMenu:addChild(item2,kItemTagBasic) - local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) - pMenu:addChild(item3,kItemTagBasic) - item3:registerScriptTapHandler(nextCallback) - - local size = cc.Director:getInstance():getWinSize() - item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - end - end + local function nextCallback() + nCurCase = nCurCase + 1 + --No check nMaxCases + nCurCase = nCurCase % nMaxCases + ShowCurrentTest() + end + + local size = cc.Director:getInstance():getWinSize() + local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2) + item1:registerScriptTapHandler(backCallback) + pMenu:addChild(item1,kItemTagBasic) + local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2) + item2:registerScriptTapHandler(restartCallback) + pMenu:addChild(item2,kItemTagBasic) + local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2) + pMenu:addChild(item3,kItemTagBasic) + item3:registerScriptTapHandler(nextCallback) + + local size = cc.Director:getInstance():getWinSize() + item1:setPosition(cc.p(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + item2:setPosition(cc.p(size.width / 2, item2:getContentSize().height / 2)) + item3:setPosition(cc.p(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + end + end end local function update(fTime) - fElapsedTime = fElapsedTime + fTime + fElapsedTime = fElapsedTime + fTime - if fElapsedTime > 1.0 then - local fFrameRateB = nNumberOfTouchesB / fElapsedTime - local fFrameRateM = nNumberOfTouchesM / fElapsedTime - local fFrameRateE = nNumberOfTouchesE / fElapsedTime - local fFrameRateC = nNumberOfTouchesC / fElapsedTime - fElapsedTime = 0 - nNumberOfTouchesB = 0 - nNumberOfTouchesM = 0 - nNumberOfTouchesE = 0 - nNumberOfTouchesC = 0 - - local strInfo = string.format("%.1f %.1f %.1f %.1f",fFrameRateB, fFrameRateM, fFrameRateE, fFrameRateC) - if nil ~= pClassLabel then - pClassLabel:setString(strInfo) - end - end + if fElapsedTime > 1.0 then + local fFrameRateB = nNumberOfTouchesB / fElapsedTime + local fFrameRateM = nNumberOfTouchesM / fElapsedTime + local fFrameRateE = nNumberOfTouchesE / fElapsedTime + local fFrameRateC = nNumberOfTouchesC / fElapsedTime + fElapsedTime = 0 + nNumberOfTouchesB = 0 + nNumberOfTouchesM = 0 + nNumberOfTouchesE = 0 + nNumberOfTouchesC = 0 + + local strInfo = string.format("%.1f %.1f %.1f %.1f",fFrameRateB, fFrameRateM, fFrameRateE, fFrameRateC) + if nil ~= pClassLabel then + pClassLabel:setString(strInfo) + end + end end @@ -1587,30 +1589,30 @@ local function runTouchesTest() end local function InitLayer() - --menu - local pTouchesTestMenu = cc.Menu:create() - CreatePerfomBasicLayerMenu(pTouchesTestMenu) - CreateBasicLayerMenuItem(pTouchesTestMenu,true,TouchesTestParam.TEST_COUNT,nCurCase) - pTouchesTestMenu:setPosition(cc.p(0, 0)) - pLayer:addChild(pTouchesTestMenu) - - --Title - local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) - pLayer:addChild(pLabel, 1) - pLabel:setPosition(cc.p(s.width/2, s.height-32)) - pLabel:setColor(cc.c3b(255,255,40)) - - pLayer:scheduleUpdateWithPriorityLua(update,0) + --menu + local pTouchesTestMenu = cc.Menu:create() + CreatePerfomBasicLayerMenu(pTouchesTestMenu) + CreateBasicLayerMenuItem(pTouchesTestMenu,true,TouchesTestParam.TEST_COUNT,nCurCase) + pTouchesTestMenu:setPosition(cc.p(0, 0)) + pLayer:addChild(pTouchesTestMenu) + + --Title + local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40) + pLayer:addChild(pLabel, 1) + pLabel:setPosition(cc.p(s.width/2, s.height-32)) + pLabel:setColor(cc.c3b(255,255,40)) + + pLayer:scheduleUpdateWithPriorityLua(update,0) - pClassLabel = cc.LabelBMFont:create("00.0", "fonts/arial16.fnt") - pClassLabel:setPosition(cc.p(s.width/2, s.height/2)) - pLayer:addChild(pClassLabel) + pClassLabel = cc.LabelBMFont:create("00.0", "fonts/arial16.fnt") + pClassLabel:setPosition(cc.p(s.width/2, s.height/2)) + pLayer:addChild(pClassLabel) - fElapsedTime = 0.0 - nNumberOfTouchesB = 0 - nNumberOfTouchesM = 0 - nNumberOfTouchesE = 0 - nNumberOfTouchesC = 0 + fElapsedTime = 0.0 + nNumberOfTouchesB = 0 + nNumberOfTouchesM = 0 + nNumberOfTouchesE = 0 + nNumberOfTouchesC = 0 if 0 == nCurCase then local listener = cc.EventListenerTouchOneByOne:create() @@ -1632,23 +1634,486 @@ local function runTouchesTest() end function ShowCurrentTest() - if nil ~= pLayer then - pLayer:unscheduleUpdate() - end - - pNewscene = cc.Scene:create() - - if nil ~= pNewscene then - pLayer = cc.Layer:create() - InitLayer() - pNewscene:addChild(pLayer) - cc.Director:getInstance():replaceScene(pNewscene) - end + if nil ~= pLayer then + pLayer:unscheduleUpdate() + end + + pNewscene = cc.Scene:create() + + if nil ~= pNewscene then + pLayer = cc.Layer:create() + InitLayer() + pNewscene:addChild(pLayer) + cc.Director:getInstance():replaceScene(pNewscene) + end end - InitLayer() - pNewscene:addChild(pLayer) - return pNewscene + InitLayer() + pNewscene:addChild(pLayer) + return pNewscene +end + + +local function runStructOrLuaTableTest() + -- body + local newscene = cc.Scene:create() + local layer = cc.Layer:create() + local s = cc.Director:getInstance():getWinSize() + local scheduler = cc.Director:getInstance():getScheduler() + local scheduleEntryID = 0 + local pushNum = 1500 + local socket = require("socket") + local maxTime = 0.0 + local minTime = 99999 + local averageTime1 = 0.0 + local averageTime2 = 0.0 + local totalTime = 0.0 + local numberOfCalls = 0 + + local function GetTitle() + return "Struct or LuaTable Performance Test" + end + + local function GetSubtitle() + return "See console for results" + end + + local function initVar() + maxTime = 0.0 + minTime = 99999 + averageTime1 = 0.0 + averageTime2 = 0.0 + totalTime = 0.0 + numberOfCalls = 0 + end + + --Title + local title = cc.LabelTTF:create(GetTitle(), "Arial", 28) + layer:addChild(title, 1) + title:setPosition(cc.p(s.width/2, s.height-32)) + title:setColor(cc.c3b(255,255,40)) + --Subtitle + local subTitle = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16) + layer:addChild(subTitle, 1) + subTitle:setPosition(cc.p(s.width/2, s.height-80)) + + --"+","-" Menu + local function onDecrease() + pushNum = pushNum - 100 + if pushNum == 0 then + pushNum = 100 + end + local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local strNum = string.format("%d", pushNum) + numLabel:setString(strNum) + end + + local function onIncrease() + pushNum = pushNum + 100 + local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local strNum = string.format("%d", pushNum) + numLabel:setString(strNum) + end + + cc.MenuItemFont:setFontSize(65) + local decrease = cc.MenuItemFont:create(" - ") + decrease:registerScriptTapHandler(onDecrease) + decrease:setColor(cc.c3b(0,200,20)) + local increase = cc.MenuItemFont:create(" + ") + increase:registerScriptTapHandler(onIncrease) + increase:setColor(cc.c3b(0,200,20)) + + local menuAddOrSub = cc.Menu:create() + menuAddOrSub:addChild(decrease) + menuAddOrSub:addChild(increase) + menuAddOrSub:alignItemsHorizontally() + menuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) + layer:addChild(menuAddOrSub,1) + + --num + local numLabel = cc.LabelTTF:create("10000", "Marker Felt", 30) + numLabel:setColor(cc.c3b(0,200,20)) + numLabel:setPosition(cc.p(s.width/2, s.height/2-15)) + layer:addChild(numLabel, 1, NodeChildrenTestParam.kTagInfoLayer) + + --struct lua_table + local function toggleCallback(tag, sender) + decrease:setEnabled(true) + increase:setEnabled(true) + layer:unscheduleUpdate() + scheduler:unscheduleScriptEntry(scheduleEntryID) + initVar() + end + + cc.MenuItemFont:setFontSize(18) + local structItem = cc.MenuItemFont:create("push struct object") + local tableItem = cc.MenuItemFont:create("push table object") + local toggleItem = cc.MenuItemToggle:create(structItem) + toggleItem:registerScriptTapHandler(toggleCallback) + toggleItem:addSubItem(tableItem) + toggleItem:setAnchorPoint(cc.p(0.0, 0.5)) + toggleItem:setPosition(cc.p(VisibleRect:left())) + local menuStructOrTable = cc.Menu:create(toggleItem) + menuStructOrTable:setPosition(cc.p(0,0)) + layer:addChild(menuStructOrTable) + + --setPosition,getPosition,Point + local setPositionItem = cc.MenuItemFont:create("setPosition") + local getPositionItem = cc.MenuItemFont:create("getPosition") + local pointItem = cc.MenuItemFont:create("object") + local funcToggleItem = cc.MenuItemToggle:create(setPositionItem) + funcToggleItem:addSubItem(getPositionItem) + funcToggleItem:addSubItem(pointItem) + funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5)) + funcToggleItem:setPosition(cc.p(VisibleRect:leftBottom().x, VisibleRect:leftBottom().y + 30)) + local funcMenu = cc.Menu:create(funcToggleItem) + funcMenu:setPosition(cc.p(0, 0)) + layer:addChild(funcMenu) + + local performanceObject = cc.PerformanceStuctAndTable:create() + performanceObject:retain() + + local function step(dt) + print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",pushNum, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls)) + end + + local function profileEnd(startTime) + local duration = socket.gettime() - startTime + totalTime = totalTime + duration + averageTime1 = (averageTime1 + duration) / 2 + averageTime2 = totalTime / numberOfCalls + + if maxTime < duration then + maxTime = duration + end + + if minTime > duration then + minTime = duration + end + end + + local function callSetPositionSturct() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + performanceObject:setPositionStruct(CCPoint(1,2)) + end + profileEnd(startTime) + end + + local function callGetPositionStruct() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + local pt =performanceObject:getPositionStruct() + end + profileEnd(startTime) + end + + local function callPointStruct( ... ) + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + local pt = CCPoint(1,2) + end + profileEnd(startTime) + end + + local function callSetPositionTable() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + performanceObject:setPositionTable(cc.p(1,2)) + end + profileEnd(startTime) + end + + local function callGetPositionTable() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + local pt = performanceObject:getPositionTable() + end + profileEnd(startTime) + end + + local function callTableObject() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + local pt = cc.p(1,2) + end + profileEnd(startTime) + end + + local function update(dt) + local selectedItem = toggleItem:getSelectedIndex() + local funcSelected = funcToggleItem:getSelectedIndex() + if 0 == selectedItem then + if 0 == funcSelected then + callSetPositionSturct() + elseif 1 == funcSelected then + callGetPositionStruct() + elseif 2 == funcSelected then + callPointStruct() + end + elseif 1 == selectedItem then + if 0 == funcSelected then + callSetPositionTable() + elseif 1 == funcSelected then + callGetPositionTable() + elseif 2 == funcSelected then + callTableObject() + end + end + end + + local function onNodeEvent(tag) + if tag == "exit" then + self:unscheduleUpdate() + scheduler:unscheduleScriptEntry(scheduleEntryID) + end + end + + layer:registerScriptHandler(onNodeEvent) + + + local function startCallback() + initVar() + decrease:setEnabled(false) + increase:setEnabled(false) + layer:unscheduleUpdate() + layer:scheduleUpdateWithPriorityLua(update, 0) + scheduler:unscheduleScriptEntry(scheduleEntryID) + scheduleEntryID = scheduler:scheduleScriptFunc(step,2,false) + end + + local function stopCallback() + decrease:setEnabled(true) + increase:setEnabled(true) + layer:unscheduleUpdate() + scheduler:unscheduleScriptEntry(scheduleEntryID) + end + local startItem = cc.MenuItemFont:create("start") + startItem:registerScriptTapHandler(startCallback) + local stopItem = cc.MenuItemFont:create("stop") + stopItem:registerScriptTapHandler(stopCallback) + local startAndStop = cc.Menu:create(startItem,stopItem) + startAndStop:alignItemsVertically() + startAndStop:setPosition(VisibleRect:right().x - 50, VisibleRect:right().y) + layer:addChild(startAndStop) + + --back menu + local menu = cc.Menu:create() + CreatePerfomBasicLayerMenu(menu) + menu:setPosition(cc.p(0, 0)) + layer:addChild(menu) + + newscene:addChild(layer) + return newscene +end + + +local function runTableConversionV3() + -- body + local newscene = cc.Scene:create() + local layer = cc.Layer:create() + local s = cc.Director:getInstance():getWinSize() + local scheduler = cc.Director:getInstance():getScheduler() + local scheduleEntryID = 0 + local pushNum = 1500 + local socket = require("socket") + local maxTime = 0.0 + local minTime = 99999 + local averageTime1 = 0.0 + local averageTime2 = 0.0 + local totalTime = 0.0 + local numberOfCalls = 0 + + local function GetTitle() + return "Table Conversion Performance Test" + end + + local function GetSubtitle() + return "See console for results" + end + + local function initVar() + maxTime = 0.0 + minTime = 99999 + averageTime1 = 0.0 + averageTime2 = 0.0 + totalTime = 0.0 + numberOfCalls = 0 + end + + --Title + local title = cc.LabelTTF:create(GetTitle(), "Arial", 28) + layer:addChild(title, 1) + title:setPosition(cc.p(s.width/2, s.height-32)) + title:setColor(cc.c3b(255,255,40)) + --Subtitle + local subTitle = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16) + layer:addChild(subTitle, 1) + subTitle:setPosition(cc.p(s.width/2, s.height-80)) + + --"+","-" Menu + local function onDecrease() + pushNum = pushNum - 100 + if pushNum == 0 then + pushNum = 100 + end + local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local strNum = string.format("%d", pushNum) + numLabel:setString(strNum) + end + + local function onIncrease() + pushNum = pushNum + 100 + local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local strNum = string.format("%d", pushNum) + numLabel:setString(strNum) + end + + cc.MenuItemFont:setFontSize(65) + local decrease = cc.MenuItemFont:create(" - ") + decrease:registerScriptTapHandler(onDecrease) + decrease:setColor(cc.c3b(0,200,20)) + local increase = cc.MenuItemFont:create(" + ") + increase:registerScriptTapHandler(onIncrease) + increase:setColor(cc.c3b(0,200,20)) + + local menuAddOrSub = cc.Menu:create() + menuAddOrSub:addChild(decrease) + menuAddOrSub:addChild(increase) + menuAddOrSub:alignItemsHorizontally() + menuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) + layer:addChild(menuAddOrSub,1) + + --num + local numLabel = cc.LabelTTF:create("10000", "Marker Felt", 30) + numLabel:setColor(cc.c3b(0,200,20)) + numLabel:setPosition(cc.p(s.width/2, s.height/2-15)) + layer:addChild(numLabel, 1, NodeChildrenTestParam.kTagInfoLayer) + + --setPosition,getPosition,Point + cc.MenuItemFont:setFontSize(18) + local setPositionItem = cc.MenuItemFont:create("setPosition") + local getPositionItem = cc.MenuItemFont:create("getPosition") + local pointItem = cc.MenuItemFont:create("object") + local funcToggleItem = cc.MenuItemToggle:create(setPositionItem) + funcToggleItem:addSubItem(getPositionItem) + funcToggleItem:addSubItem(pointItem) + funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5)) + funcToggleItem:setPosition(cc.p(VisibleRect:left())) + local funcMenu = cc.Menu:create(funcToggleItem) + funcMenu:setPosition(cc.p(0, 0)) + layer:addChild(funcMenu) + + local testNode = cc.Node:create() + layer:addChild(testNode) + + local function step(dt) + print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",pushNum, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls)) + end + + local function profileEnd(startTime) + local duration = socket.gettime() - startTime + totalTime = totalTime + duration + averageTime1 = (averageTime1 + duration) / 2 + averageTime2 = totalTime / numberOfCalls + + if maxTime < duration then + maxTime = duration + end + + if minTime > duration then + minTime = duration + end + end + + local function callSetPosition() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + testNode:setPosition(cc.p(1,2)) + end + profileEnd(startTime) + end + + local function callGetPosition() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + local x,y = testNode:getPosition() + end + profileEnd(startTime) + end + + local function callTableObject() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,pushNum do + local pt = cc.p(1,2) + end + profileEnd(startTime) + end + + local function update(dt) + + local funcSelected = funcToggleItem:getSelectedIndex() + if 0 == funcSelected then + callSetPosition() + elseif 1 == funcSelected then + callGetPosition() + elseif 2 == funcSelected then + callTableObject() + end + end + + local function onNodeEvent(tag) + if tag == "exit" then + self:unscheduleUpdate() + scheduler:unscheduleScriptEntry(scheduleEntryID) + end + end + + layer:registerScriptHandler(onNodeEvent) + + + local function startCallback() + initVar() + decrease:setEnabled(false) + increase:setEnabled(false) + layer:unscheduleUpdate() + layer:scheduleUpdateWithPriorityLua(update, 0) + scheduler:unscheduleScriptEntry(scheduleEntryID) + scheduleEntryID = scheduler:scheduleScriptFunc(step,2,false) + end + + local function stopCallback() + decrease:setEnabled(true) + increase:setEnabled(true) + layer:unscheduleUpdate() + scheduler:unscheduleScriptEntry(scheduleEntryID) + end + local startItem = cc.MenuItemFont:create("start") + startItem:registerScriptTapHandler(startCallback) + local stopItem = cc.MenuItemFont:create("stop") + stopItem:registerScriptTapHandler(stopCallback) + local startAndStop = cc.Menu:create(startItem,stopItem) + startAndStop:alignItemsVertically() + startAndStop:setPosition(VisibleRect:right().x - 50, VisibleRect:right().y) + layer:addChild(startAndStop) + + --back menu + local menu = cc.Menu:create() + CreatePerfomBasicLayerMenu(menu) + menu:setPosition(cc.p(0, 0)) + layer:addChild(menu) + + newscene:addChild(layer) + return newscene end @@ -1657,11 +2122,13 @@ end ------------------------ local CreatePerformancesTestTable = { - runNodeChildrenTest, - runParticleTest, - runSpriteTest, - runTextureTest, - runTouchesTest + runNodeChildrenTest, + runParticleTest, + runSpriteTest, + runTextureTest, + runTouchesTest, + runStructOrLuaTableTest, + runTableConversionV3, } local function CreatePerformancesTestScene(nPerformanceNo) @@ -1669,41 +2136,41 @@ local function CreatePerformancesTestScene(nPerformanceNo) return pNewscene end local function menuCallback(tag, pMenuItem) - local scene = nil + local scene = nil local nIdx = pMenuItem:getLocalZOrder() - kItemTagBasic - local PerformanceTestScene = CreatePerformancesTestScene(nIdx) + local PerformanceTestScene = CreatePerformancesTestScene(nIdx) if nil ~= PerformanceTestScene then cc.Director:getInstance():replaceScene(PerformanceTestScene) end end local function PerformanceMainLayer() - local layer = cc.Layer:create() + local layer = cc.Layer:create() - local menu = cc.Menu:create() + local menu = cc.Menu:create() menu:setPosition(cc.p(0, 0)) cc.MenuItemFont:setFontName("Arial") cc.MenuItemFont:setFontSize(24) for i = 1, MAX_COUNT do - local item = cc.MenuItemFont:create(testsName[i]) + local item = cc.MenuItemFont:create(testsName[i]) item:registerScriptTapHandler(menuCallback) - item:setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE) + item:setPosition(s.width / 2, s.height - i * LINE_SPACE) menu:addChild(item, kItemTagBasic + i) - end + end layer:addChild(menu) - return layer + return layer end ------------------------------------- -- Performance Test ------------------------------------- function PerformanceTestMain() - local scene = cc.Scene:create() + local scene = cc.Scene:create() - scene:addChild(PerformanceMainLayer()) - scene:addChild(CreateBackMenuItem()) + scene:addChild(PerformanceMainLayer()) + scene:addChild(CreateBackMenuItem()) - return scene + return scene end From 4eecc7e56b7ea77a9228eb34bedb6d5cd2ae1c6c Mon Sep 17 00:00:00 2001 From: xingsenma Date: Thu, 13 Feb 2014 13:54:05 +0800 Subject: [PATCH 03/18] #3947 Simulate 'setTimeout' and 'setInterval' in JSB. --- .../javascript/script/jsb_cocos2d.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cocos/scripting/javascript/script/jsb_cocos2d.js b/cocos/scripting/javascript/script/jsb_cocos2d.js index 2ab020b08a..8c1c2cfc09 100644 --- a/cocos/scripting/javascript/script/jsb_cocos2d.js +++ b/cocos/scripting/javascript/script/jsb_cocos2d.js @@ -3,6 +3,7 @@ // var cc = cc || {}; +var window = window || this; cc.TARGET_PLATFORM = { WINDOWS:0, @@ -821,3 +822,62 @@ cc.VisibleRect = { } }; +var _windowTimeIntervalId = 0; +var _windowTimeFunHash = {}; +var WindowTimeFun = cc.Class.extend({ + _code: null, + _intervalId: 0, + ctor: function (code) { + this._intervalId = _windowTimeIntervalId++; + this._code = code; + }, + fun: function () { + if (!this._code) return; + var code = this._code; + if (typeof code == "string") { + Function(code)(); + } + else if (typeof code == "function") { + code(); + } + } +}); + +/** + * overwrite window's setTimeout + @param {String|Function} code + @param {number} delay + @return {number} + */ +var setTimeout = function (code, delay) { + var target = new WindowTimeFun(code); + cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, 0, 0, false); + _windowTimeFunHash[target._intervalId] = target; + return target._intervalId; +}; + +/** + * overwrite window's setInterval + @param {String|Function} code + @param {number} delay + @return {number} + */ +var setInterval = function (code, delay) { + var target = new WindowTimeFun(code); + cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, cc.REPEAT_FOREVER, 0, false); + _windowTimeFunHash[target._intervalId] = target; + return target._intervalId; +}; + +/** + * overwrite window's clearInterval + @param {number} intervalId + */ +var clearInterval = function (intervalId) { + var target = _windowTimeFunHash[intervalId]; + if (target) { + cc.Director.getInstance().getScheduler().unscheduleCallbackForTarget(target, target.fun); + delete _windowTimeFunHash[intervalId]; + } +}; +var clearTimeout = clearInterval; \ No newline at end of file From 8ae5d2a0490f0479328de82288d4f803cfd9d2f8 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 13 Feb 2014 16:22:41 +0800 Subject: [PATCH 04/18] closed #3964, Solve the bug of logic code in method Image::saveImageToPNG(). --- cocos/2d/CCRenderTexture.cpp | 4 +-- cocos/2d/platform/CCImageCommon_cpp.h | 36 +++++++++---------- .../RenderTextureTest/RenderTextureTest.cpp | 10 ++---- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 57b6a00d24..5be23d9baa 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -446,10 +446,10 @@ Image* RenderTexture::newImage(bool fliimage) break; } - this->begin(); + this->onBegin(); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0,0,savedBufferWidth, savedBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, tempData); - this->end(); + this->onEnd(); if ( fliimage ) // -- flip is only required when saving image to file { diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index 40eeca0ae7..8e482188e5 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -948,7 +948,7 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) } png_read_image(png_ptr, row_pointers); - png_read_end(png_ptr, NULL); + png_read_end(png_ptr, nullptr); _preMulti = false; @@ -1094,7 +1094,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) tiffMapProc, tiffUnmapProc); - CC_BREAK_IF(NULL == tif); + CC_BREAK_IF(nullptr == tif); uint32 w = 0, h = 0; uint16 bitsPerSample = 0, samplePerPixel = 0, planarConfig = 0; @@ -1116,7 +1116,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen) _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); - if (raster != NULL) + if (raster != nullptr) { if (TIFFReadRGBAImageOriented(tif, w, h, raster, ORIENTATION_TOPLEFT, 0)) { @@ -1851,7 +1851,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen) if (WebPDecode(static_cast(data), dataLen, &config) != VP8_STATUS_OK) { free(_data); - _data = NULL; + _data = nullptr; break; } @@ -1941,21 +1941,21 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) png_bytep *row_pointers; fp = fopen(filePath.c_str(), "wb"); - CC_BREAK_IF(NULL == fp); + CC_BREAK_IF(nullptr == fp); - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); - if (NULL == png_ptr) + if (nullptr == png_ptr) { fclose(fp); break; } info_ptr = png_create_info_struct(png_ptr); - if (NULL == info_ptr) + if (nullptr == info_ptr) { fclose(fp); - png_destroy_write_struct(&png_ptr, NULL); + png_destroy_write_struct(&png_ptr, nullptr); break; } #if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA && CC_TARGET_PLATFORM != CC_PLATFORM_NACL) @@ -1987,14 +1987,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) png_set_packing(png_ptr); row_pointers = (png_bytep *)malloc(_height * sizeof(png_bytep)); - if(row_pointers == NULL) + if(row_pointers == nullptr) { fclose(fp); png_destroy_write_struct(&png_ptr, &info_ptr); break; } - if (hasAlpha()) + if (!hasAlpha()) { for (int i = 0; i < (int)_height; i++) { @@ -2004,14 +2004,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) png_write_image(png_ptr, row_pointers); free(row_pointers); - row_pointers = NULL; + row_pointers = nullptr; } else { if (isToRGB) { unsigned char *pTempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char*))); - if (NULL == pTempData) + if (nullptr == pTempData) { fclose(fp); png_destroy_write_struct(&png_ptr, &info_ptr); @@ -2036,7 +2036,7 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) png_write_image(png_ptr, row_pointers); free(row_pointers); - row_pointers = NULL; + row_pointers = nullptr; if (pTempData != nullptr) { @@ -2053,14 +2053,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB) png_write_image(png_ptr, row_pointers); free(row_pointers); - row_pointers = NULL; + row_pointers = nullptr; } } png_write_end(png_ptr, info_ptr); png_free(png_ptr, palette); - palette = NULL; + palette = nullptr; png_destroy_write_struct(&png_ptr, &info_ptr); @@ -2085,7 +2085,7 @@ bool Image::saveImageToJPG(const std::string& filePath) /* Now we can initialize the JPEG compression object. */ jpeg_create_compress(&cinfo); - CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == NULL); + CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == nullptr); jpeg_stdio_dest(&cinfo, outfile); @@ -2103,7 +2103,7 @@ bool Image::saveImageToJPG(const std::string& filePath) if (hasAlpha()) { unsigned char *pTempData = static_cast(malloc(_width * _height * 3 * sizeof(unsigned char))); - if (NULL == pTempData) + if (nullptr == pTempData) { jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); diff --git a/tests/test-cpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/test-cpp/Classes/RenderTextureTest/RenderTextureTest.cpp index e893f707f7..4203356b7c 100644 --- a/tests/test-cpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/test-cpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -143,14 +143,8 @@ void RenderTextureSave::saveImage(cocos2d::Object *sender) _target->saveToFile(png, Image::Format::PNG); _target->saveToFile(jpg, Image::Format::JPG); - - auto image = _target->newImage(); - - auto tex = Director::getInstance()->getTextureCache()->addImage(image, png); - - CC_SAFE_DELETE(image); - - auto sprite = Sprite::createWithTexture(tex); + std::string fileName = FileUtils::getInstance()->getWritablePath() + jpg; + auto sprite = Sprite::create(fileName); sprite->setScale(0.3f); addChild(sprite); From 3f8bc8cc43bfa03646a724e4c499829a33f6dbf9 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 17 Feb 2014 10:24:58 +0800 Subject: [PATCH 05/18] issue #3708:Remove the useless test case --- cocos/scripting/lua/bindings/CCLuaStack.cpp | 3 +- .../lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- .../lua/bindings/lua_cocos2dx_manual.hpp | 2 - .../PerformanceTest/PerformanceTest.lua | 312 ++---------------- 4 files changed, 34 insertions(+), 285 deletions(-) diff --git a/cocos/scripting/lua/bindings/CCLuaStack.cpp b/cocos/scripting/lua/bindings/CCLuaStack.cpp index 338517f447..b836f49853 100644 --- a/cocos/scripting/lua/bindings/CCLuaStack.cpp +++ b/cocos/scripting/lua/bindings/CCLuaStack.cpp @@ -105,7 +105,7 @@ int lua_print(lua_State * luastate) if (i!=nargs) t += "\t"; } - log("[LUA-print] %s", t.c_str()); + CCLOG("[LUA-print] %s", t.c_str()); return 0; } @@ -157,7 +157,6 @@ bool LuaStack::init(void) register_all_cocos2dx_extension(_state); register_all_cocos2dx_deprecated(_state); register_cocos2dx_extension_CCBProxy(_state); - register_cocos2dx_PerformanceStuctAndTable(_state); tolua_opengl_open(_state); register_all_cocos2dx_gui(_state); register_all_cocos2dx_studio(_state); 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 25c76fc902..ee22cb131d 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 @@ -8102f7376c603c7a65f754d9d1f981c6a5c1ce2f \ No newline at end of file +c5f8d4a3ea721a2ecb36fe381430b7ac6fad1740 \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp index 5610aaf2fa..d8dae90200 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.hpp @@ -55,8 +55,6 @@ TOLUA_API int register_all_cocos2dx_manual(lua_State* tolua_S); TOLUA_API int register_cocos2dx_event_releated(lua_State* tolua_S); -TOLUA_API int register_cocos2dx_PerformanceStuctAndTable(lua_State* tolua_S); - struct LuaEventAccelerationData { void* acc; diff --git a/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua b/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua index b5b95f7ef6..25fc53ad33 100644 --- a/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua +++ b/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua @@ -1,6 +1,6 @@ require "luaScript/PerformanceTest/PerformanceSpriteTest" -local MAX_COUNT = 7 +local MAX_COUNT = 6 local LINE_SPACE = 40 local kItemTagBasic = 1000 @@ -11,8 +11,7 @@ local testsName = "PerformanceSpriteTest", "PerformanceTextureTest", "PerformanceTouchesTest", - "PerformanceStructOrLuaTable", - "PerformanceTableConversionV3", + "PerformanceFuncRelateWithTable", } local s = cc.Director:getInstance():getWinSize() @@ -1653,15 +1652,14 @@ local function runTouchesTest() return pNewscene end - -local function runStructOrLuaTableTest() +local function runFuncRelateWithTable() -- body local newscene = cc.Scene:create() local layer = cc.Layer:create() local s = cc.Director:getInstance():getWinSize() local scheduler = cc.Director:getInstance():getScheduler() local scheduleEntryID = 0 - local pushNum = 1500 + local quantityOfNodes = 10000 local socket = require("socket") local maxTime = 0.0 local minTime = 99999 @@ -1671,7 +1669,7 @@ local function runStructOrLuaTableTest() local numberOfCalls = 0 local function GetTitle() - return "Struct or LuaTable Performance Test" + return "Func Releated Table Performance Test" end local function GetSubtitle() @@ -1699,279 +1697,19 @@ local function runStructOrLuaTableTest() --"+","-" Menu local function onDecrease() - pushNum = pushNum - 100 - if pushNum == 0 then - pushNum = 100 + quantityOfNodes = quantityOfNodes - 100 + if quantityOfNodes == 0 then + quantityOfNodes = 100 end local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") - local strNum = string.format("%d", pushNum) + local strNum = string.format("%d", quantityOfNodes) numLabel:setString(strNum) end local function onIncrease() - pushNum = pushNum + 100 + quantityOfNodes = quantityOfNodes + 100 local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") - local strNum = string.format("%d", pushNum) - numLabel:setString(strNum) - end - - cc.MenuItemFont:setFontSize(65) - local decrease = cc.MenuItemFont:create(" - ") - decrease:registerScriptTapHandler(onDecrease) - decrease:setColor(cc.c3b(0,200,20)) - local increase = cc.MenuItemFont:create(" + ") - increase:registerScriptTapHandler(onIncrease) - increase:setColor(cc.c3b(0,200,20)) - - local menuAddOrSub = cc.Menu:create() - menuAddOrSub:addChild(decrease) - menuAddOrSub:addChild(increase) - menuAddOrSub:alignItemsHorizontally() - menuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15)) - layer:addChild(menuAddOrSub,1) - - --num - local numLabel = cc.LabelTTF:create("10000", "Marker Felt", 30) - numLabel:setColor(cc.c3b(0,200,20)) - numLabel:setPosition(cc.p(s.width/2, s.height/2-15)) - layer:addChild(numLabel, 1, NodeChildrenTestParam.kTagInfoLayer) - - --struct lua_table - local function toggleCallback(tag, sender) - decrease:setEnabled(true) - increase:setEnabled(true) - layer:unscheduleUpdate() - scheduler:unscheduleScriptEntry(scheduleEntryID) - initVar() - end - - cc.MenuItemFont:setFontSize(18) - local structItem = cc.MenuItemFont:create("push struct object") - local tableItem = cc.MenuItemFont:create("push table object") - local toggleItem = cc.MenuItemToggle:create(structItem) - toggleItem:registerScriptTapHandler(toggleCallback) - toggleItem:addSubItem(tableItem) - toggleItem:setAnchorPoint(cc.p(0.0, 0.5)) - toggleItem:setPosition(cc.p(VisibleRect:left())) - local menuStructOrTable = cc.Menu:create(toggleItem) - menuStructOrTable:setPosition(cc.p(0,0)) - layer:addChild(menuStructOrTable) - - --setPosition,getPosition,Point - local setPositionItem = cc.MenuItemFont:create("setPosition") - local getPositionItem = cc.MenuItemFont:create("getPosition") - local pointItem = cc.MenuItemFont:create("object") - local funcToggleItem = cc.MenuItemToggle:create(setPositionItem) - funcToggleItem:addSubItem(getPositionItem) - funcToggleItem:addSubItem(pointItem) - funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5)) - funcToggleItem:setPosition(cc.p(VisibleRect:leftBottom().x, VisibleRect:leftBottom().y + 30)) - local funcMenu = cc.Menu:create(funcToggleItem) - funcMenu:setPosition(cc.p(0, 0)) - layer:addChild(funcMenu) - - local performanceObject = cc.PerformanceStuctAndTable:create() - performanceObject:retain() - - local function step(dt) - print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",pushNum, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls)) - end - - local function profileEnd(startTime) - local duration = socket.gettime() - startTime - totalTime = totalTime + duration - averageTime1 = (averageTime1 + duration) / 2 - averageTime2 = totalTime / numberOfCalls - - if maxTime < duration then - maxTime = duration - end - - if minTime > duration then - minTime = duration - end - end - - local function callSetPositionSturct() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,pushNum do - performanceObject:setPositionStruct(CCPoint(1,2)) - end - profileEnd(startTime) - end - - local function callGetPositionStruct() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,pushNum do - local pt =performanceObject:getPositionStruct() - end - profileEnd(startTime) - end - - local function callPointStruct( ... ) - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,pushNum do - local pt = CCPoint(1,2) - end - profileEnd(startTime) - end - - local function callSetPositionTable() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,pushNum do - performanceObject:setPositionTable(cc.p(1,2)) - end - profileEnd(startTime) - end - - local function callGetPositionTable() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,pushNum do - local pt = performanceObject:getPositionTable() - end - profileEnd(startTime) - end - - local function callTableObject() - numberOfCalls = numberOfCalls + 1 - local startTime = socket.gettime() - for i=1,pushNum do - local pt = cc.p(1,2) - end - profileEnd(startTime) - end - - local function update(dt) - local selectedItem = toggleItem:getSelectedIndex() - local funcSelected = funcToggleItem:getSelectedIndex() - if 0 == selectedItem then - if 0 == funcSelected then - callSetPositionSturct() - elseif 1 == funcSelected then - callGetPositionStruct() - elseif 2 == funcSelected then - callPointStruct() - end - elseif 1 == selectedItem then - if 0 == funcSelected then - callSetPositionTable() - elseif 1 == funcSelected then - callGetPositionTable() - elseif 2 == funcSelected then - callTableObject() - end - end - end - - local function onNodeEvent(tag) - if tag == "exit" then - self:unscheduleUpdate() - scheduler:unscheduleScriptEntry(scheduleEntryID) - end - end - - layer:registerScriptHandler(onNodeEvent) - - - local function startCallback() - initVar() - decrease:setEnabled(false) - increase:setEnabled(false) - layer:unscheduleUpdate() - layer:scheduleUpdateWithPriorityLua(update, 0) - scheduler:unscheduleScriptEntry(scheduleEntryID) - scheduleEntryID = scheduler:scheduleScriptFunc(step,2,false) - end - - local function stopCallback() - decrease:setEnabled(true) - increase:setEnabled(true) - layer:unscheduleUpdate() - scheduler:unscheduleScriptEntry(scheduleEntryID) - end - local startItem = cc.MenuItemFont:create("start") - startItem:registerScriptTapHandler(startCallback) - local stopItem = cc.MenuItemFont:create("stop") - stopItem:registerScriptTapHandler(stopCallback) - local startAndStop = cc.Menu:create(startItem,stopItem) - startAndStop:alignItemsVertically() - startAndStop:setPosition(VisibleRect:right().x - 50, VisibleRect:right().y) - layer:addChild(startAndStop) - - --back menu - local menu = cc.Menu:create() - CreatePerfomBasicLayerMenu(menu) - menu:setPosition(cc.p(0, 0)) - layer:addChild(menu) - - newscene:addChild(layer) - return newscene -end - - -local function runTableConversionV3() - -- body - local newscene = cc.Scene:create() - local layer = cc.Layer:create() - local s = cc.Director:getInstance():getWinSize() - local scheduler = cc.Director:getInstance():getScheduler() - local scheduleEntryID = 0 - local pushNum = 1500 - local socket = require("socket") - local maxTime = 0.0 - local minTime = 99999 - local averageTime1 = 0.0 - local averageTime2 = 0.0 - local totalTime = 0.0 - local numberOfCalls = 0 - - local function GetTitle() - return "Table Conversion Performance Test" - end - - local function GetSubtitle() - return "See console for results" - end - - local function initVar() - maxTime = 0.0 - minTime = 99999 - averageTime1 = 0.0 - averageTime2 = 0.0 - totalTime = 0.0 - numberOfCalls = 0 - end - - --Title - local title = cc.LabelTTF:create(GetTitle(), "Arial", 28) - layer:addChild(title, 1) - title:setPosition(cc.p(s.width/2, s.height-32)) - title:setColor(cc.c3b(255,255,40)) - --Subtitle - local subTitle = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16) - layer:addChild(subTitle, 1) - subTitle:setPosition(cc.p(s.width/2, s.height-80)) - - --"+","-" Menu - local function onDecrease() - pushNum = pushNum - 100 - if pushNum == 0 then - pushNum = 100 - end - local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") - local strNum = string.format("%d", pushNum) - numLabel:setString(strNum) - end - - local function onIncrease() - pushNum = pushNum + 100 - local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") - local strNum = string.format("%d", pushNum) + local strNum = string.format("%d", quantityOfNodes) numLabel:setString(strNum) end @@ -2000,9 +1738,11 @@ local function runTableConversionV3() cc.MenuItemFont:setFontSize(18) local setPositionItem = cc.MenuItemFont:create("setPosition") local getPositionItem = cc.MenuItemFont:create("getPosition") + local getAnchorPointItem = cc.MenuItemFont:create("getAnchorPoint") local pointItem = cc.MenuItemFont:create("object") local funcToggleItem = cc.MenuItemToggle:create(setPositionItem) funcToggleItem:addSubItem(getPositionItem) + funcToggleItem:addSubItem(getAnchorPointItem) funcToggleItem:addSubItem(pointItem) funcToggleItem:setAnchorPoint(cc.p(0.0, 0.5)) funcToggleItem:setPosition(cc.p(VisibleRect:left())) @@ -2014,7 +1754,7 @@ local function runTableConversionV3() layer:addChild(testNode) local function step(dt) - print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",pushNum, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls)) + print(string.format("push num: %d, avg1:%f, avg2:%f,min:%f, max:%f, total: %f, calls: %d",quantityOfNodes, averageTime1, averageTime2, minTime, maxTime, totalTime, numberOfCalls)) end local function profileEnd(startTime) @@ -2035,7 +1775,7 @@ local function runTableConversionV3() local function callSetPosition() numberOfCalls = numberOfCalls + 1 local startTime = socket.gettime() - for i=1,pushNum do + for i=1,quantityOfNodes do testNode:setPosition(cc.p(1,2)) end profileEnd(startTime) @@ -2044,16 +1784,25 @@ local function runTableConversionV3() local function callGetPosition() numberOfCalls = numberOfCalls + 1 local startTime = socket.gettime() - for i=1,pushNum do + for i=1,quantityOfNodes do local x,y = testNode:getPosition() end profileEnd(startTime) end + local function callGetAnchorPoint() + numberOfCalls = numberOfCalls + 1 + local startTime = socket.gettime() + for i=1,quantityOfNodes do + local anchorPoint = testNode:getAnchorPoint() + end + profileEnd(startTime) + end + local function callTableObject() numberOfCalls = numberOfCalls + 1 local startTime = socket.gettime() - for i=1,pushNum do + for i=1,quantityOfNodes do local pt = cc.p(1,2) end profileEnd(startTime) @@ -2067,13 +1816,15 @@ local function runTableConversionV3() elseif 1 == funcSelected then callGetPosition() elseif 2 == funcSelected then + callGetAnchorPoint() + elseif 3 == funcSelected then callTableObject() end end local function onNodeEvent(tag) if tag == "exit" then - self:unscheduleUpdate() + layer:unscheduleUpdate() scheduler:unscheduleScriptEntry(scheduleEntryID) end end @@ -2085,6 +1836,7 @@ local function runTableConversionV3() initVar() decrease:setEnabled(false) increase:setEnabled(false) + funcToggleItem:setEnabled(false) layer:unscheduleUpdate() layer:scheduleUpdateWithPriorityLua(update, 0) scheduler:unscheduleScriptEntry(scheduleEntryID) @@ -2094,6 +1846,7 @@ local function runTableConversionV3() local function stopCallback() decrease:setEnabled(true) increase:setEnabled(true) + funcToggleItem:setEnabled(true) layer:unscheduleUpdate() scheduler:unscheduleScriptEntry(scheduleEntryID) end @@ -2127,8 +1880,7 @@ local CreatePerformancesTestTable = runSpriteTest, runTextureTest, runTouchesTest, - runStructOrLuaTableTest, - runTableConversionV3, + runFuncRelateWithTable, } local function CreatePerformancesTestScene(nPerformanceNo) From 4d35c8626c7255f97649c33d85e3b55a3b081141 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 17 Feb 2014 10:36:30 +0800 Subject: [PATCH 06/18] issue #3708:Remove some comments --- .../lua/bindings/lua_cocos2dx_deprecated.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp index c0dcde7df5..e907189be2 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp @@ -106,7 +106,7 @@ bool array_to_valuevector_deprecated(Array& array,ValueVector& valueVec) #define deprecatedFunctionTip(oldFun,newFun) CCLOG("%s was deprecated please use %s instead ",oldFun, newFun) static int tolua_Cocos2d_CCPoint_new00(lua_State* tolua_S) { -// deprecatedClassTip("CCPoint"); + deprecatedClassTip("CCPoint"); #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -132,7 +132,7 @@ tolua_lerror: static int tolua_Cocos2d_CCPoint_new00_local(lua_State* tolua_S) { -// deprecatedClassTip("CCPoint"); + deprecatedClassTip("CCPoint"); #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -183,7 +183,7 @@ tolua_lerror: static int tolua_Cocos2d_CCPoint_new01_local(lua_State* tolua_S) { -// deprecatedClassTip("CCPoint"); + deprecatedClassTip("CCPoint"); tolua_Error tolua_err; if ( @@ -197,10 +197,8 @@ static int tolua_Cocos2d_CCPoint_new01_local(lua_State* tolua_S) { float x = ((float) tolua_tonumber(tolua_S,2,0)); float y = ((float) tolua_tonumber(tolua_S,3,0)); - Point* tolua_ret = (Point*) Mtolua_new((Point)(x,y)); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"CCPoint"); - tolua_register_gc(tolua_S,lua_gettop(tolua_S)); - //point_to_luaval(tolua_S, tolua_ret); + Point tolua_ret(x,y); + point_to_luaval(tolua_S, tolua_ret); } return 1; tolua_lerror: From cae938bd4e464e09c35d9905c5f42de1f7ca4516 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Feb 2014 12:56:28 +0800 Subject: [PATCH 07/18] Update CHANGELOG [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 7bea54ed36..84da1d96a4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ cocos2d-x-3.0rc0 Feb.?? 2014 [NEW] Using python to automatically generate script bindings codes. [NEW] Linux javascript bindings support. + [FIX] Supports 'setTimeout' and 'setInterval' in JSB. [FIX] Exposes the missing data structures of Spine to JS. [FIX] Node::setRotation() moves opposite when node has a physics body. [FIX] A string which only contains CJK characters can't make a line-break when it's needed. From 4f94064242e87ce3deeddfa34aef9be5dcfb901f Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 17 Feb 2014 14:35:49 +0800 Subject: [PATCH 08/18] closed #4048:fixed LabelTTFMultiline test case show nothing on mac. --- cocos/2d/platform/mac/CCDevice.mm | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cocos/2d/platform/mac/CCDevice.mm b/cocos/2d/platform/mac/CCDevice.mm index 4a76b742b3..bf7b9099fc 100644 --- a/cocos/2d/platform/mac/CCDevice.mm +++ b/cocos/2d/platform/mac/CCDevice.mm @@ -112,24 +112,37 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch font, NSFontAttributeName, paragraphStyle, NSParagraphStyleAttributeName, nil]; - // linebreak + // linebreak if (info->width > 0) { if ([string sizeWithAttributes:tokenAttributesDict].width > info->width) { NSMutableString *lineBreak = [[[NSMutableString alloc] init] autorelease]; NSUInteger length = [string length]; NSRange range = NSMakeRange(0, 1); - NSUInteger width = 0; + CGSize textSize; NSUInteger lastBreakLocation = 0; + NSUInteger insertCount = 0; for (NSUInteger i = 0; i < length; i++) { range.location = i; NSString *character = [string substringWithRange:range]; [lineBreak appendString:character]; - if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) { lastBreakLocation = i; } - width = [lineBreak sizeWithAttributes:tokenAttributesDict].width; - if (width > info->width) { - [lineBreak insertString:@"\r\n" atIndex:(lastBreakLocation > 0) ? lastBreakLocation : [lineBreak length] - 1]; + if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) { + lastBreakLocation = i + insertCount; + } + textSize = [lineBreak sizeWithAttributes:tokenAttributesDict]; + if(textSize.height > info->height) + break; + if (textSize.width > info->width) { + if(lastBreakLocation > 0) { + [lineBreak insertString:@"\r" atIndex:lastBreakLocation]; + lastBreakLocation = 0; + } + else { + [lineBreak insertString:@"\r" atIndex:[lineBreak length] - 1]; + } + insertCount += 1; } } + string = lineBreak; } } From 19b1945efbe641b0fd9753f1ca9ec0fb5910c241 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Feb 2014 21:15:26 +0800 Subject: [PATCH 09/18] closed #4054: Removing child from TMXLayer may cause crash. --- cocos/2d/CCSpriteBatchNode.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index e93b462d68..fe390dcd6c 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -541,8 +541,9 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite) { auto next = std::next(it); + Sprite *spr = nullptr; for(; next != _descendants.end(); ++next) { - Sprite *spr = *next; + spr = *next; spr->setAtlasIndex( spr->getAtlasIndex() - 1 ); } @@ -649,10 +650,11 @@ SpriteBatchNode * SpriteBatchNode::addSpriteWithoutQuad(Sprite*child, int z, int child->setAtlasIndex(z); // XXX: optimize with a binary search - auto it = std::begin(_descendants); - for(const auto &sprite: _descendants) { - if(sprite->getAtlasIndex() >= z) - std::next(it); + auto it = _descendants.begin(); + for (; it != _descendants.end(); ++it) + { + if((*it)->getAtlasIndex() >= z) + break; } _descendants.insert(it, child); From 2ee133047958c35547cb43c8bfc652a2353b9126 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Feb 2014 21:16:25 +0800 Subject: [PATCH 10/18] closed #4054: Adds test for removing child from TMXLayer. --- tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp b/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp index dfa145c221..3142023399 100644 --- a/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp +++ b/tests/test-cpp/Classes/TileMapTest/TileMapTest.cpp @@ -423,7 +423,11 @@ void TMXOrthoTest4::removeSprite(float dt) auto s = layer->getLayerSize(); auto sprite = layer->getTileAt( Point(s.width-1,0) ); + auto sprite2 = layer->getTileAt(Point(s.width-1, s.height-1)); layer->removeChild(sprite, true); + auto sprite3 = layer->getTileAt(Point(2, s.height-1)); + layer->removeChild(sprite3, true); + layer->removeChild(sprite2, true); } std::string TMXOrthoTest4::title() const From 789ebffb141773728e67a5f105efd680a7999e2f Mon Sep 17 00:00:00 2001 From: JianjunMao Date: Mon, 17 Feb 2014 21:23:29 +0800 Subject: [PATCH 11/18] fix string concatenation set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") which leads to list of strings. The result is "-stdlib=libc++;-std=c++11" if CMAKE_CXX_FLAGS is defined as "-stdlib=libc++" --- template/multi-platform-cpp/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/multi-platform-cpp/CMakeLists.txt b/template/multi-platform-cpp/CMakeLists.txt index ea987c6f53..522d947c27 100644 --- a/template/multi-platform-cpp/CMakeLists.txt +++ b/template/multi-platform-cpp/CMakeLists.txt @@ -18,8 +18,8 @@ endif(DEBUG_MODE) set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1") set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") if(USE_CHIPMUNK) message("Using chipmunk ...") From 332baa2ddced1ed6471a8685bf07080e7e4545f1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Feb 2014 22:00:44 +0800 Subject: [PATCH 12/18] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index b1b24dbc55..5bb455d513 100644 --- a/AUTHORS +++ b/AUTHORS @@ -746,6 +746,9 @@ Developers: ucchen Exposed the missing data structures of Spine to JS. + + justmao945 + Corrected the definition of CMake variables. Retired Core Developers: WenSheng Yang From e9c003663feb99738b451735b2b95f926cda7ef8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Feb 2014 22:15:25 +0800 Subject: [PATCH 13/18] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 5bb455d513..a1dbc7c616 100644 --- a/AUTHORS +++ b/AUTHORS @@ -749,6 +749,9 @@ Developers: justmao945 Corrected the definition of CMake variables. + + maksqwe + Fixed string size check in BitmapDC::utf8ToUtf16 on win32 and assert condition in TriggerMng. Retired Core Developers: WenSheng Yang From 905443d17ce58e4fc1eac39be8c9c19d2476d2f0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 18 Feb 2014 10:11:04 +0800 Subject: [PATCH 14/18] new[] free mismatching after PR #5326. --- cocos/2d/platform/android/CCDevice.cpp | 7 ++----- cocos/2d/platform/ios/CCDevice.mm | 4 ++-- cocos/2d/platform/linux/CCDevice.cpp | 2 +- cocos/2d/platform/mac/CCDevice.mm | 2 +- cocos/2d/platform/win32/CCDevice.cpp | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cocos/2d/platform/android/CCDevice.cpp b/cocos/2d/platform/android/CCDevice.cpp index f30790afb7..d3136a41a3 100644 --- a/cocos/2d/platform/android/CCDevice.cpp +++ b/cocos/2d/platform/android/CCDevice.cpp @@ -78,10 +78,7 @@ public: ~BitmapDC(void) { - if (_data) - { - delete [] _data; - } + CC_SAFE_FREE(_data); } bool getBitmapFromJavaShadowStroke( const char *text, @@ -222,7 +219,7 @@ extern "C" cocos2d::BitmapDC& bitmapDC = cocos2d::sharedBitmapDC(); bitmapDC._width = width; bitmapDC._height = height; - bitmapDC._data = new unsigned char[size]; + bitmapDC._data = (unsigned char*)malloc(sizeof(unsigned char) * size); env->GetByteArrayRegion(pixels, 0, size, (jbyte*)bitmapDC._data); } }; diff --git a/cocos/2d/platform/ios/CCDevice.mm b/cocos/2d/platform/ios/CCDevice.mm index ba6bfd76cf..7d91cb68ce 100644 --- a/cocos/2d/platform/ios/CCDevice.mm +++ b/cocos/2d/platform/ios/CCDevice.mm @@ -326,7 +326,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align, dim.height += shadowStrokePaddingY; - unsigned char* data = new unsigned char[(int)(dim.width * dim.height * 4)]; + unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * (int)(dim.width * dim.height * 4)); memset(data, 0, (int)(dim.width * dim.height * 4)); // draw text @@ -341,7 +341,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align, if (!context) { CGColorSpaceRelease(colorSpace); - delete[] data; + CC_SAFE_FREE(data); break; } diff --git a/cocos/2d/platform/linux/CCDevice.cpp b/cocos/2d/platform/linux/CCDevice.cpp index b062a658a7..a12d2ebc0c 100644 --- a/cocos/2d/platform/linux/CCDevice.cpp +++ b/cocos/2d/platform/linux/CCDevice.cpp @@ -411,7 +411,7 @@ public: int txtHeight = iMaxLineHeight; iMaxLineHeight = MAX(iMaxLineHeight, nHeight); - _data = new unsigned char[iMaxLineWidth * iMaxLineHeight * 4]; + _data = (unsigned char*)malloc(sizeof(unsigned char) * (iMaxLineWidth * iMaxLineHeight * 4)); memset(_data,0, iMaxLineWidth * iMaxLineHeight*4); int iCurYCursor = computeLineStartY(face, eAlignMask, txtHeight, iMaxLineHeight); diff --git a/cocos/2d/platform/mac/CCDevice.mm b/cocos/2d/platform/mac/CCDevice.mm index bf7b9099fc..5b83ee2e38 100644 --- a/cocos/2d/platform/mac/CCDevice.mm +++ b/cocos/2d/platform/mac/CCDevice.mm @@ -207,7 +207,7 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch NSUInteger textureSize = POTWide*POTHigh*4; - unsigned char* dataNew = new unsigned char[textureSize]; + unsigned char* dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize); if (dataNew) { memcpy(dataNew, data, textureSize); // output params diff --git a/cocos/2d/platform/win32/CCDevice.cpp b/cocos/2d/platform/win32/CCDevice.cpp index 1bf50cddef..9d3bf94ce2 100644 --- a/cocos/2d/platform/win32/CCDevice.cpp +++ b/cocos/2d/platform/win32/CCDevice.cpp @@ -412,7 +412,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD CC_BREAK_IF(! dc.drawText(text, size, align)); int dataLen = size.cx * size.cy * 4; - unsigned char* dataBuf = new unsigned char[dataLen]; + unsigned char* dataBuf = (unsigned char*)malloc(sizeof(unsigned char) * dataLen); CC_BREAK_IF(! dataBuf); struct From 650331769ab79760795bdb0c8defb3a2e033d471 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 18 Feb 2014 10:47:14 +0800 Subject: [PATCH 15/18] closed #3964, Use GL methods instead in function RenderTexture::newImage() --- cocos/2d/CCRenderTexture.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 5be23d9baa..fede04c4c3 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -446,10 +446,23 @@ Image* RenderTexture::newImage(bool fliimage) break; } - this->onBegin(); + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); + glBindFramebuffer(GL_FRAMEBUFFER, _FBO); + + //TODO move this to configration, so we don't check it every time + /* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers. + */ + if (Configuration::getInstance()->checkForGLExtension("GL_QCOM")) + { + // -- bind a temporary texture so we can clear the render buffer without losing our texture + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0); + CHECK_GL_ERROR_DEBUG(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0); + } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0,0,savedBufferWidth, savedBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, tempData); - this->onEnd(); + glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); if ( fliimage ) // -- flip is only required when saving image to file { From b4121f47fcef6926c53d90b39594a72a0226ccf9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 18 Feb 2014 11:07:58 +0800 Subject: [PATCH 16/18] [Android] Don't free BitmapDC::_data in BitmapDC's destructor. Remove unused BitmapDC::env. --- cocos/2d/platform/android/CCDevice.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cocos/2d/platform/android/CCDevice.cpp b/cocos/2d/platform/android/CCDevice.cpp index d3136a41a3..b311c8cc8e 100644 --- a/cocos/2d/platform/android/CCDevice.cpp +++ b/cocos/2d/platform/android/CCDevice.cpp @@ -78,7 +78,6 @@ public: ~BitmapDC(void) { - CC_SAFE_FREE(_data); } bool getBitmapFromJavaShadowStroke( const char *text, @@ -112,11 +111,11 @@ public: // Do a full lookup for the font path using FileUtils in case the given font name is a relative path to a font file asset, // or the path has been mapped to a different location in the app package: std::string fullPathOrFontName = FileUtils::getInstance()->fullPathForFilename(pFontName); - - // If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context - // requires this portion of the path to be omitted for assets inside the app package. - if (fullPathOrFontName.find("assets/") == 0) - { + + // If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context + // requires this portion of the path to be omitted for assets inside the app package. + if (fullPathOrFontName.find("assets/") == 0) + { fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/")); // Chop out the 'assets/' portion of the path. } @@ -160,7 +159,6 @@ public: int _width; int _height; unsigned char *_data; - JNIEnv *env; }; static BitmapDC& sharedBitmapDC() From 297fe597e1322448f1fdbbd1e4db04c7b748a5cd Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 18 Feb 2014 11:08:27 +0800 Subject: [PATCH 17/18] Updates mac / iOS project. --- build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 283d017ac8..ab3eb20e53 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -5bde2def1fece71a2464526c90939b9999ed05f3 \ No newline at end of file +a7af0ccd05e86210026f7c72d6f5a7be8e17fe3d \ No newline at end of file From 34f8f0a3081ef844eda03f01878ae57d187e4797 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 18 Feb 2014 11:14:02 +0800 Subject: [PATCH 18/18] Uses `malloc` instead of `new[]`, keep malloc/free matching. --- cocos/2d/CCTexture2D.cpp | 56 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index 3c69c7f614..29f672f94a 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -753,7 +753,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) if (outTempData != nullptr && outTempData != tempData) { - delete [] outTempData; + free(outTempData); } // set the premultiplied tag @@ -781,32 +781,32 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, s { case PixelFormat::RGBA8888: *outDataLen = dataLen*4; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertI8ToRGBA8888(data, dataLen, *outData); break; case PixelFormat::RGB888: *outDataLen = dataLen*3; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertI8ToRGB888(data, dataLen, *outData); break; case PixelFormat::RGB565: *outDataLen = dataLen*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertI8ToRGB565(data, dataLen, *outData); break; case PixelFormat::AI88: *outDataLen = dataLen*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertI8ToAI88(data, dataLen, *outData); break; case PixelFormat::RGBA4444: *outDataLen = dataLen*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertI8ToRGBA4444(data, dataLen, *outData); break; case PixelFormat::RGB5A1: *outDataLen = dataLen*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertI8ToRGB5A1(data, dataLen, *outData); break; default: @@ -830,37 +830,37 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, { case PixelFormat::RGBA8888: *outDataLen = dataLen*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToRGBA8888(data, dataLen, *outData); break; case PixelFormat::RGB888: *outDataLen = dataLen/2*3; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToRGB888(data, dataLen, *outData); break; case PixelFormat::RGB565: *outDataLen = dataLen; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToRGB565(data, dataLen, *outData); break; case PixelFormat::A8: *outDataLen = dataLen/2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToA8(data, dataLen, *outData); break; case PixelFormat::I8: *outDataLen = dataLen/2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToI8(data, dataLen, *outData); break; case PixelFormat::RGBA4444: *outDataLen = dataLen; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToRGBA4444(data, dataLen, *outData); break; case PixelFormat::RGB5A1: *outDataLen = dataLen; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertAI88ToRGB5A1(data, dataLen, *outData); break; default: @@ -885,32 +885,32 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat { case PixelFormat::RGBA8888: *outDataLen = dataLen/3*4; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGB888ToRGBA8888(data, dataLen, *outData); break; case PixelFormat::RGB565: *outDataLen = dataLen/3*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGB888ToRGB565(data, dataLen, *outData); break; case PixelFormat::I8: *outDataLen = dataLen/3; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGB888ToI8(data, dataLen, *outData); break; case PixelFormat::AI88: *outDataLen = dataLen/3*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGB888ToAI88(data, dataLen, *outData); break; case PixelFormat::RGBA4444: *outDataLen = dataLen/3*2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGB888ToRGBA4444(data, dataLen, *outData); break; case PixelFormat::RGB5A1: *outDataLen = dataLen; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGB888ToRGB5A1(data, dataLen, *outData); break; default: @@ -934,37 +934,37 @@ Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* d { case PixelFormat::RGB888: *outDataLen = dataLen/4*3; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToRGB888(data, dataLen, *outData); break; case PixelFormat::RGB565: *outDataLen = dataLen/2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToRGB565(data, dataLen, *outData); break; case PixelFormat::A8: *outDataLen = dataLen/4; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToA8(data, dataLen, *outData); break; case PixelFormat::I8: *outDataLen = dataLen/4; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToI8(data, dataLen, *outData); break; case PixelFormat::AI88: *outDataLen = dataLen/2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToAI88(data, dataLen, *outData); break; case PixelFormat::RGBA4444: *outDataLen = dataLen/2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToRGBA4444(data, dataLen, *outData); break; case PixelFormat::RGB5A1: *outDataLen = dataLen/2; - *outData = new unsigned char[*outDataLen]; + *outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen)); convertRGBA8888ToRGB5A1(data, dataLen, *outData); break; default: @@ -1094,7 +1094,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin if (outTempData != nullptr && outTempData != outData.getBytes()) { - delete [] outTempData; + free(outTempData); } #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) _hasPremultipliedAlpha = true;