2012-08-27 11:43:47 +08:00
|
|
|
|
require "luaScript/PerformanceTest/PerformanceSpriteTest"
|
|
|
|
|
|
2013-05-09 09:57:05 +08:00
|
|
|
|
local MAX_COUNT = 5
|
2012-08-27 11:43:47 +08:00
|
|
|
|
local LINE_SPACE = 40
|
|
|
|
|
local kItemTagBasic = 1000
|
|
|
|
|
|
|
|
|
|
local testsName =
|
|
|
|
|
{
|
|
|
|
|
"PerformanceNodeChildrenTest",
|
2013-05-09 09:57:05 +08:00
|
|
|
|
"PerformanceParticleTest",
|
|
|
|
|
"PerformanceSpriteTest",
|
2012-08-27 11:43:47 +08:00
|
|
|
|
"PerformanceTextureTest",
|
|
|
|
|
"PerformanceTouchesTest"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local s = CCDirector:sharedDirector():getWinSize()
|
|
|
|
|
|
2013-05-09 09:57:05 +08:00
|
|
|
|
--Create toMainLayr MenuItem
|
|
|
|
|
function CreatePerfomBasicLayerMenu(pMenu)
|
|
|
|
|
if nil == pMenu then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local function toMainLayer()
|
|
|
|
|
local pScene = PerformanceTestMain()
|
|
|
|
|
if pScene ~= nil then
|
|
|
|
|
CCDirector:sharedDirector():replaceScene(pScene)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
--Create BackMneu
|
|
|
|
|
CCMenuItemFont:setFontName("Arial")
|
|
|
|
|
CCMenuItemFont:setFontSize(24);
|
|
|
|
|
local pMenuItemFont = CCMenuItemFont:create("Back");
|
|
|
|
|
pMenuItemFont:setPosition(ccp(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25))
|
|
|
|
|
pMenuItemFont:registerScriptTapHandler(toMainLayer)
|
|
|
|
|
pMenu:addChild(pMenuItemFont)
|
|
|
|
|
end
|
|
|
|
|
|
2012-08-27 11:43:47 +08:00
|
|
|
|
----------------------------------
|
2013-05-09 09:57:05 +08:00
|
|
|
|
--PerformanceNodeChildrenTest
|
2012-08-27 11:43:47 +08:00
|
|
|
|
----------------------------------
|
2013-05-09 09:57:05 +08:00
|
|
|
|
local NodeChildrenTestParam =
|
|
|
|
|
{
|
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
|
kTagMainLayer = 2,
|
|
|
|
|
kTagLabelAtlas = 3,
|
|
|
|
|
kTagBase = 20000,
|
|
|
|
|
TEST_COUNT = 4,
|
|
|
|
|
kMaxNodes = 15000,
|
|
|
|
|
kNodesIncrease = 500,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local function runNodeChildrenTest()
|
|
|
|
|
--NodeChildrenMainScene
|
|
|
|
|
local nLastRenderedCount = 0
|
|
|
|
|
local nQuantityOfNodes = 0
|
|
|
|
|
local nCurrentQuantityOfNodes = 0
|
|
|
|
|
--IterateSpriteSheet
|
|
|
|
|
local pBatchNode = nil
|
|
|
|
|
|
|
|
|
|
--BasiceLayer param
|
|
|
|
|
local bControlMenuVisible = false
|
|
|
|
|
local nMaxCases = 0
|
|
|
|
|
local nCurCase = 0
|
|
|
|
|
|
|
|
|
|
local pNewscene = CCScene:create()
|
|
|
|
|
|
|
|
|
|
local function ShowCurrentTest()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
local function restartCallback()
|
|
|
|
|
ShowCurrentTest()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function nextCallback()
|
|
|
|
|
nCurCase = nCurCase + 1
|
|
|
|
|
--No check nMaxCases
|
|
|
|
|
nCurCase = nCurCase % nMaxCases
|
|
|
|
|
ShowCurrentTest()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local size = CCDirector:sharedDirector():getWinSize()
|
|
|
|
|
local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2)
|
|
|
|
|
item1:registerScriptTapHandler(backCallback)
|
|
|
|
|
pMenu:addChild(item1,kItemTagBasic)
|
|
|
|
|
local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2)
|
|
|
|
|
item2:registerScriptTapHandler(restartCallback)
|
|
|
|
|
pMenu:addChild(item2,kItemTagBasic)
|
|
|
|
|
local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2)
|
|
|
|
|
pMenu:addChild(item3,kItemTagBasic)
|
|
|
|
|
item3:registerScriptTapHandler(nextCallback)
|
|
|
|
|
|
|
|
|
|
local size = CCDirector:sharedDirector():getWinSize()
|
|
|
|
|
item1:setPosition(CCPointMake(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2))
|
|
|
|
|
item2:setPosition(CCPointMake(size.width / 2, item2:getContentSize().height / 2))
|
|
|
|
|
item3:setPosition(CCPointMake(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), "CCLabelTTF")
|
|
|
|
|
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 = pChildren:count()
|
|
|
|
|
for i = 0, len - 1, 1 do
|
|
|
|
|
local child = tolua.cast(pChildren:objectAtIndex(i), "CCSprite")
|
|
|
|
|
child:setVisible(false)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function NodeChildrenScheduleUpdate()
|
|
|
|
|
if 0 == nCurCase then
|
|
|
|
|
pNewscene:scheduleUpdateWithPriorityLua(IterateSpriteSheetCArrayUpdate,0)
|
|
|
|
|
elseif 1 == nCurCase then
|
|
|
|
|
|
|
|
|
|
elseif 2 == nCurCase then
|
|
|
|
|
|
|
|
|
|
elseif 3 == nCurCase then
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function updateQuantityOfNodes()
|
|
|
|
|
local s = CCDirector:sharedDirector():getWinSize()
|
|
|
|
|
--increase nodes
|
|
|
|
|
if( nCurrentQuantityOfNodes < nQuantityOfNodes ) then
|
|
|
|
|
local i = 0
|
|
|
|
|
for i = 0,nQuantityOfNodes - nCurrentQuantityOfNodes - 1 do
|
|
|
|
|
local sprite = CCSprite:createWithTexture(pBatchNode:getTexture(), CCRectMake(0, 0, 32, 32))
|
|
|
|
|
pBatchNode:addChild(sprite)
|
|
|
|
|
sprite:setPosition(ccp( 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()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function onIncrease()
|
|
|
|
|
nQuantityOfNodes = nQuantityOfNodes + NodeChildrenTestParam.kNodesIncrease
|
|
|
|
|
if nQuantityOfNodes > NodeChildrenTestParam.kMaxNodes then
|
|
|
|
|
nQuantityOfNodes = NodeChildrenTestParam.kMaxNodes
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
updateQuantityLabel()
|
|
|
|
|
updateQuantityOfNodes()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function SpecialInitWithQuantityOfNodes()
|
|
|
|
|
if 0 == nCurCase then
|
|
|
|
|
pBatchNode = CCSpriteBatchNode:create("Images/spritesheet1.png")
|
|
|
|
|
pNewscene:addChild(pBatchNode)
|
|
|
|
|
else
|
|
|
|
|
pBatchNode = CCSpriteBatchNode:create("Images/spritesheet1.png");
|
|
|
|
|
pNewscene:addChild(pBatchNode);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function MainSceneInitWithQuantityOfNodes(nNodes)
|
|
|
|
|
local s = CCDirector:sharedDirector():getWinSize()
|
|
|
|
|
|
|
|
|
|
--Title
|
|
|
|
|
local pLabel = CCLabelTTF:create(GetTitle(), "Arial", 40)
|
|
|
|
|
pNewscene:addChild(pLabel, 1)
|
|
|
|
|
pLabel:setPosition(ccp(s.width/2, s.height-32))
|
|
|
|
|
pLabel:setColor(ccc3(255,255,40))
|
|
|
|
|
|
|
|
|
|
if (nil ~= GetSubTitle()) and ("" ~= GetSubTitle()) then
|
|
|
|
|
local pSubLabel = CCLabelTTF:create(GetSubTitle(), "Thonburi", 16);
|
|
|
|
|
pNewscene:addChild(pSubLabel, 1);
|
|
|
|
|
pSubLabel:setPosition(ccp(s.width/2, s.height-80))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
nLastRenderedCount = 0
|
|
|
|
|
nCurrentQuantityOfNodes = 0
|
|
|
|
|
nQuantityOfNodes = nNodes
|
|
|
|
|
|
|
|
|
|
--"+"<22><>"-" Menu
|
|
|
|
|
CCMenuItemFont:setFontSize(65);
|
|
|
|
|
local pDecrease = CCMenuItemFont:create(" - ")
|
|
|
|
|
pDecrease:registerScriptTapHandler(onDecrease)
|
|
|
|
|
pDecrease:setColor(ccc3(0,200,20));
|
|
|
|
|
local pIncrease = CCMenuItemFont:create(" + ")
|
|
|
|
|
pIncrease:registerScriptTapHandler(onIncrease)
|
|
|
|
|
pIncrease:setColor(ccc3(0,200,20));
|
|
|
|
|
|
|
|
|
|
local pMenuAddOrSub = CCMenu:create()
|
|
|
|
|
pMenuAddOrSub:addChild(pDecrease)
|
|
|
|
|
pMenuAddOrSub:addChild(pIncrease)
|
|
|
|
|
pMenuAddOrSub:alignItemsHorizontally();
|
|
|
|
|
pMenuAddOrSub:setPosition(ccp(s.width/2, s.height/2+15));
|
|
|
|
|
pNewscene:addChild(pMenuAddOrSub,1)
|
|
|
|
|
|
|
|
|
|
--InfoLayer
|
|
|
|
|
local pInfoLabel = CCLabelTTF:create("0 nodes", "Marker Felt", 30);
|
|
|
|
|
pInfoLabel:setColor(ccc3(0,200,20));
|
|
|
|
|
pInfoLabel:setPosition(ccp(s.width/2, s.height/2-15));
|
|
|
|
|
pNewscene:addChild(pInfoLabel, 1, NodeChildrenTestParam.kTagInfoLayer);
|
|
|
|
|
|
|
|
|
|
--NodeChildrenMenuLayer
|
|
|
|
|
local pNodeChildrenMenuLayer = CCLayer:create()
|
|
|
|
|
local pNodeChildrenMenuMenu = CCMenu:create()
|
|
|
|
|
CreatePerfomBasicLayerMenu(pNodeChildrenMenuMenu)
|
|
|
|
|
CreateBasicLayerMenuItem(pNodeChildrenMenuMenu,true,NodeChildrenTestParam.TEST_COUNT,nCurCase)
|
|
|
|
|
pNodeChildrenMenuMenu:setPosition(ccp(0, 0))
|
|
|
|
|
pNodeChildrenMenuLayer:addChild(pNodeChildrenMenuMenu)
|
|
|
|
|
pNewscene:addChild(pNodeChildrenMenuLayer)
|
|
|
|
|
|
|
|
|
|
updateQuantityLabel()
|
|
|
|
|
updateQuantityOfNodes()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
SpecialInitWithQuantityOfNodes()
|
|
|
|
|
MainSceneInitWithQuantityOfNodes(NodeChildrenTestParam.kNodesIncrease)
|
|
|
|
|
NodeChildrenScheduleUpdate()
|
|
|
|
|
return pNewscene
|
|
|
|
|
end
|
|
|
|
|
----------------------------------
|
|
|
|
|
--PerformanceParticleTest
|
|
|
|
|
----------------------------------
|
|
|
|
|
local ParticleTestParam =
|
|
|
|
|
{
|
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
|
kTagMainLayer = 2,
|
|
|
|
|
kTagParticleSystem = 3,
|
|
|
|
|
kTagLabelAtlas = 4,
|
|
|
|
|
kTagMenuLayer = 1000,
|
2012-08-27 11:43:47 +08:00
|
|
|
|
|
2013-05-09 09:57:05 +08:00
|
|
|
|
TEST_COUNT = 4,
|
|
|
|
|
kMaxParticles = 14000,
|
|
|
|
|
kNodesIncrease = 500,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local function runParticleTest()
|
|
|
|
|
local lastRenderedCount
|
|
|
|
|
local quantityParticles
|
|
|
|
|
local subtestNumber
|
|
|
|
|
end
|
|
|
|
|
local CreatePerformancesTestTable =
|
|
|
|
|
{
|
|
|
|
|
runNodeChildrenTest,
|
|
|
|
|
runParticleTest,
|
|
|
|
|
runSpriteTest,
|
|
|
|
|
runTextureTest,
|
|
|
|
|
runTouchesTest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local function CreatePerformancesTestScene(nPerformanceNo)
|
|
|
|
|
local pNewscene = CreatePerformancesTestTable[nPerformanceNo]()
|
|
|
|
|
return pNewscene
|
|
|
|
|
end
|
|
|
|
|
local function menuCallback(tag, pMenuItem)
|
|
|
|
|
local scene = nil
|
|
|
|
|
local nIdx = pMenuItem:getZOrder() - kItemTagBasic
|
|
|
|
|
local PerformanceTestScene = CreatePerformancesTestScene(nIdx)
|
|
|
|
|
if nil ~= PerformanceTestScene then
|
|
|
|
|
CCDirector:sharedDirector():replaceScene(PerformanceTestScene)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--[[
|
2013-03-05 14:46:18 +08:00
|
|
|
|
if tag == "enter" then
|
2012-08-27 11:43:47 +08:00
|
|
|
|
scene = PerformanceSpriteTest()
|
|
|
|
|
elseif tag == 1 then
|
|
|
|
|
|
|
|
|
|
elseif tag == 2 then
|
|
|
|
|
|
|
|
|
|
elseif tag == 3 then
|
|
|
|
|
|
|
|
|
|
elseif tag == 4 then
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
if scene ~= nil then
|
|
|
|
|
CCDirector:sharedDirector():replaceScene(scene)
|
|
|
|
|
end
|
2013-05-09 09:57:05 +08:00
|
|
|
|
]]--
|
2012-08-27 11:43:47 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function PerformanceMainLayer()
|
|
|
|
|
local layer = CCLayer:create()
|
|
|
|
|
|
|
|
|
|
local menu = CCMenu:create()
|
|
|
|
|
menu:setPosition(CCPointMake(0, 0))
|
|
|
|
|
CCMenuItemFont:setFontName("Arial")
|
|
|
|
|
CCMenuItemFont:setFontSize(24)
|
2013-05-09 09:57:05 +08:00
|
|
|
|
for i = 1, MAX_COUNT do
|
2012-08-27 11:43:47 +08:00
|
|
|
|
local item = CCMenuItemFont:create(testsName[i])
|
2012-09-11 17:13:20 +08:00
|
|
|
|
item:registerScriptTapHandler(menuCallback)
|
2012-08-27 11:43:47 +08:00
|
|
|
|
item:setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE)
|
2013-05-09 09:57:05 +08:00
|
|
|
|
menu:addChild(item, kItemTagBasic + i)
|
2012-08-27 11:43:47 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
layer:addChild(menu)
|
|
|
|
|
|
|
|
|
|
return layer
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-------------------------------------
|
|
|
|
|
-- Performance Test
|
|
|
|
|
-------------------------------------
|
2013-05-09 09:57:05 +08:00
|
|
|
|
function PerformanceTestMain()
|
2012-08-27 11:43:47 +08:00
|
|
|
|
local scene = CCScene:create()
|
|
|
|
|
|
|
|
|
|
scene:addChild(PerformanceMainLayer())
|
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
|
|
|
|
|
return scene
|
|
|
|
|
end
|