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"
|
|
|
|
}
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2012-08-27 11:43:47 +08:00
|
|
|
|
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
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(pScene)
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
--Create BackMneu
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontName("Arial")
|
|
|
|
cc.MenuItemFont:setFontSize(24)
|
|
|
|
local pMenuItemFont = cc.MenuItemFont:create("Back")
|
|
|
|
pMenuItemFont:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25))
|
2013-05-09 09:57:05 +08:00
|
|
|
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
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pNewscene = cc.Scene:create()
|
2013-05-09 09:57:05 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
2013-05-09 09:57:05 +08:00
|
|
|
item1:registerScriptTapHandler(backCallback)
|
|
|
|
pMenu:addChild(item1,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
2013-05-09 09:57:05 +08:00
|
|
|
item2:registerScriptTapHandler(restartCallback)
|
|
|
|
pMenu:addChild(item2,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
2013-05-09 09:57:05 +08:00
|
|
|
pMenu:addChild(item3,kItemTagBasic)
|
|
|
|
item3:registerScriptTapHandler(nextCallback)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updateQuantityLabel()
|
|
|
|
if nQuantityOfNodes ~= nLastRenderedCount then
|
|
|
|
-- local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local pInfoLabel = tolua.cast(pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "LabelTTF")
|
2013-05-09 09:57:05 +08:00
|
|
|
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
|
2013-08-20 13:44:37 +08:00
|
|
|
local len = table.getn(pChildren)
|
2013-05-09 09:57:05 +08:00
|
|
|
for i = 0, len - 1, 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local child = tolua.cast(pChildren[i + 1], "Sprite")
|
2013-05-09 09:57:05 +08:00
|
|
|
child:setVisible(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-09 11:31:40 +08:00
|
|
|
local function AddSpriteSheetUpdate(t)
|
|
|
|
if nil == pBatchNode then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
--15 percent
|
|
|
|
local nTotalToAdd = nCurrentQuantityOfNodes * 0.15
|
|
|
|
local zs = {}
|
|
|
|
if nTotalToAdd > 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSprites = {}
|
2013-05-09 11:31:40 +08:00
|
|
|
local i = 0
|
|
|
|
for i = 0 , nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32))
|
|
|
|
pSprites[i + 1] = pSprite
|
2013-05-09 11:31:40 +08:00
|
|
|
zs[i] = math.random(-1,1) * 50
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 0 , nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pChild = tolua.cast(pSprites[i + 1],"Node")
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:addChild(pChild, zs[i], NodeChildrenTestParam.kTagBase + i)
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
pBatchNode:sortAllChildren()
|
|
|
|
|
|
|
|
for i = 0 , nTotalToAdd - 1 do
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true)
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function RemoveSpriteSheetUpdate(t)
|
|
|
|
if nil == pBatchNode then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local nTotalToAdd = nCurrentQuantityOfNodes * 0.15
|
|
|
|
if nTotalToAdd > 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSprites = {}
|
2013-05-09 11:31:40 +08:00
|
|
|
-- Don't include the sprite creation time as part of the profiling
|
|
|
|
local i = 0
|
|
|
|
for i = 0, nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32))
|
|
|
|
pSprites[i + 1] = pSprite
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
-- add them with random Z (very important!)
|
|
|
|
for i=0, nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pChild = tolua.cast(pSprites[i + 1],"Node")
|
2013-05-09 11:31:40 +08:00
|
|
|
pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 0, nTotalToAdd - 1 do
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase + i, true)
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ReorderSpriteSheetUpdate(t)
|
|
|
|
if nil == pBatchNode then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- 15 percent
|
2013-05-10 14:59:21 +08:00
|
|
|
local nTotalToAdd = nCurrentQuantityOfNodes * 0.15
|
2013-05-09 11:31:40 +08:00
|
|
|
|
|
|
|
if nTotalToAdd > 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSprites = {}
|
2013-05-09 11:31:40 +08:00
|
|
|
-- Don't include the sprite creation time as part of the profiling
|
|
|
|
local i = 0
|
|
|
|
for i = 0,nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0,0,32,32))
|
|
|
|
pSprites[i + 1] = pSprite
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
--dd them with random Z (very important!)
|
|
|
|
for i = 0, nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pChild = tolua.cast(pSprites[i + 1] ,"Node")
|
2013-05-09 11:31:40 +08:00
|
|
|
pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i)
|
|
|
|
end
|
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:sortAllChildren()
|
2013-05-09 11:31:40 +08:00
|
|
|
|
|
|
|
-- reorder them
|
|
|
|
for i = 0, nTotalToAdd - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local pNode = tolua.cast(pSprites[i + 1],"Node")
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:reorderChild(pNode, math.random(-1,1) * 50)
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:sortAllChildren()
|
2013-05-09 11:31:40 +08:00
|
|
|
--remove them
|
|
|
|
for i = 0, nTotalToAdd - 1 do
|
2013-05-10 14:59:21 +08:00
|
|
|
pBatchNode:removeChildByTag( NodeChildrenTestParam.kTagBase+i, true)
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-09 09:57:05 +08:00
|
|
|
local function NodeChildrenScheduleUpdate()
|
|
|
|
if 0 == nCurCase then
|
|
|
|
pNewscene:scheduleUpdateWithPriorityLua(IterateSpriteSheetCArrayUpdate,0)
|
|
|
|
elseif 1 == nCurCase then
|
2013-05-09 11:31:40 +08:00
|
|
|
pNewscene:scheduleUpdateWithPriorityLua(AddSpriteSheetUpdate,0)
|
2013-05-09 09:57:05 +08:00
|
|
|
elseif 2 == nCurCase then
|
2013-05-09 11:31:40 +08:00
|
|
|
pNewscene:scheduleUpdateWithPriorityLua(RemoveSpriteSheetUpdate,0)
|
2013-05-09 09:57:05 +08:00
|
|
|
elseif 3 == nCurCase then
|
2013-05-09 11:31:40 +08:00
|
|
|
pNewscene:scheduleUpdateWithPriorityLua(ReorderSpriteSheetUpdate,0)
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updateQuantityOfNodes()
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-05-09 09:57:05 +08:00
|
|
|
--increase nodes
|
|
|
|
if( nCurrentQuantityOfNodes < nQuantityOfNodes ) then
|
|
|
|
local i = 0
|
|
|
|
for i = 0,nQuantityOfNodes - nCurrentQuantityOfNodes - 1 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 32, 32))
|
2013-05-09 09:57:05 +08:00
|
|
|
pBatchNode:addChild(sprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setPosition(cc.p( math.random() * s.width, math.random() * s.height))
|
2013-05-09 09:57:05 +08:00
|
|
|
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()
|
2013-05-09 16:59:39 +08:00
|
|
|
-- if 0 == nCurCase then
|
2013-08-20 13:44:37 +08:00
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png")
|
2013-05-09 09:57:05 +08:00
|
|
|
pNewscene:addChild(pBatchNode)
|
2013-05-09 16:59:39 +08:00
|
|
|
--[[
|
2013-05-09 09:57:05 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png")
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewscene:addChild(pBatchNode)
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
2013-05-09 16:59:39 +08:00
|
|
|
]]--
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function MainSceneInitWithQuantityOfNodes(nNodes)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-05-09 09:57:05 +08:00
|
|
|
|
|
|
|
--Title
|
2013-08-20 13:44:37 +08:00
|
|
|
local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40)
|
2013-05-09 09:57:05 +08:00
|
|
|
pNewscene:addChild(pLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pLabel:setPosition(cc.p(s.width/2, s.height-32))
|
|
|
|
pLabel:setColor(cc.c3b(255,255,40))
|
2013-05-09 09:57:05 +08:00
|
|
|
|
|
|
|
if (nil ~= GetSubTitle()) and ("" ~= GetSubTitle()) then
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSubLabel = cc.LabelTTF:create(GetSubTitle(), "Thonburi", 16)
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewscene:addChild(pSubLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pSubLabel:setPosition(cc.p(s.width/2, s.height-80))
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
nLastRenderedCount = 0
|
|
|
|
nCurrentQuantityOfNodes = 0
|
|
|
|
nQuantityOfNodes = nNodes
|
|
|
|
|
2013-05-13 10:07:22 +08:00
|
|
|
--"+","-" Menu
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontSize(65)
|
|
|
|
local pDecrease = cc.MenuItemFont:create(" - ")
|
2013-05-09 09:57:05 +08:00
|
|
|
pDecrease:registerScriptTapHandler(onDecrease)
|
2013-08-20 13:44:37 +08:00
|
|
|
pDecrease:setColor(cc.c3b(0,200,20))
|
|
|
|
local pIncrease = cc.MenuItemFont:create(" + ")
|
2013-05-09 09:57:05 +08:00
|
|
|
pIncrease:registerScriptTapHandler(onIncrease)
|
2013-08-20 13:44:37 +08:00
|
|
|
pIncrease:setColor(cc.c3b(0,200,20))
|
2013-05-09 09:57:05 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pMenuAddOrSub = cc.Menu:create()
|
2013-05-09 09:57:05 +08:00
|
|
|
pMenuAddOrSub:addChild(pDecrease)
|
|
|
|
pMenuAddOrSub:addChild(pIncrease)
|
2013-05-10 14:59:21 +08:00
|
|
|
pMenuAddOrSub:alignItemsHorizontally()
|
2013-08-20 13:44:37 +08:00
|
|
|
pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
|
2013-05-09 09:57:05 +08:00
|
|
|
pNewscene:addChild(pMenuAddOrSub,1)
|
|
|
|
|
|
|
|
--InfoLayer
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewscene:addChild(pInfoLabel, 1, NodeChildrenTestParam.kTagInfoLayer)
|
2013-05-09 09:57:05 +08:00
|
|
|
|
|
|
|
--NodeChildrenMenuLayer
|
2013-08-20 13:44:37 +08:00
|
|
|
local pNodeChildrenMenuLayer = cc.Layer:create()
|
|
|
|
local pNodeChildrenMenuMenu = cc.Menu:create()
|
2013-05-09 09:57:05 +08:00
|
|
|
CreatePerfomBasicLayerMenu(pNodeChildrenMenuMenu)
|
|
|
|
CreateBasicLayerMenuItem(pNodeChildrenMenuMenu,true,NodeChildrenTestParam.TEST_COUNT,nCurCase)
|
2013-08-20 13:44:37 +08:00
|
|
|
pNodeChildrenMenuMenu:setPosition(cc.p(0, 0))
|
2013-05-09 09:57:05 +08:00
|
|
|
pNodeChildrenMenuLayer:addChild(pNodeChildrenMenuMenu)
|
|
|
|
pNewscene:addChild(pNodeChildrenMenuLayer)
|
|
|
|
|
|
|
|
updateQuantityLabel()
|
|
|
|
updateQuantityOfNodes()
|
|
|
|
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function ShowCurrentTest()
|
|
|
|
if nil ~= pNewscene then
|
|
|
|
pNewscene:unscheduleUpdate()
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pNewscene = cc.Scene:create()
|
2013-05-09 11:31:40 +08:00
|
|
|
if nil ~= pNewscene then
|
|
|
|
SpecialInitWithQuantityOfNodes()
|
|
|
|
MainSceneInitWithQuantityOfNodes(nQuantityOfNodes)
|
|
|
|
-- pNewscene:registerScriptHandler(onNodeEvent)
|
|
|
|
NodeChildrenScheduleUpdate()
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(pNewscene)
|
2013-05-09 11:31:40 +08:00
|
|
|
end
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
SpecialInitWithQuantityOfNodes()
|
|
|
|
MainSceneInitWithQuantityOfNodes(NodeChildrenTestParam.kNodesIncrease)
|
2013-05-09 11:31:40 +08:00
|
|
|
-- pNewscene:registerScriptHandler(onNodeEvent)
|
2013-05-09 09:57:05 +08:00
|
|
|
NodeChildrenScheduleUpdate()
|
2013-05-09 11:31:40 +08:00
|
|
|
|
2013-05-09 09:57:05 +08:00
|
|
|
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,
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
kSubMenuBasicZOrder = 10
|
2013-05-09 09:57:05 +08:00
|
|
|
}
|
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
local function runParticleTest()
|
|
|
|
--PerformanceParticle param
|
|
|
|
local nLastRenderedCount = 0
|
|
|
|
local nQuantityParticles = 0
|
|
|
|
local nSubtestNumber = 0
|
|
|
|
--BasiceLayer param
|
|
|
|
local bControlMenuVisible = false
|
|
|
|
local nMaxCases = 0
|
|
|
|
local nCurCase = 0
|
|
|
|
|
|
|
|
local ScheduleSelector = nil
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pNewScene = cc.Scene:create()
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
2013-05-10 14:59:21 +08:00
|
|
|
item1:registerScriptTapHandler(backCallback)
|
|
|
|
pMenu:addChild(item1,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
2013-05-10 14:59:21 +08:00
|
|
|
item2:registerScriptTapHandler(restartCallback)
|
|
|
|
pMenu:addChild(item2,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
2013-05-10 14:59:21 +08:00
|
|
|
pMenu:addChild(item3,kItemTagBasic)
|
|
|
|
item3:registerScriptTapHandler(nextCallback)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-10 14:59:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function TestNCallback(tag,pMenuItem)
|
|
|
|
local nIndex = pMenuItem:getZOrder() - ParticleTestParam.kSubMenuBasicZOrder
|
|
|
|
nSubtestNumber = nIndex
|
|
|
|
ShowCurrentTest()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function UpdateQuantityLabel()
|
|
|
|
if nQuantityParticles ~= nLastRenderedCount then
|
2013-08-20 13:44:37 +08:00
|
|
|
local pInfoLabel = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagInfoLayer), "LabelTTF")
|
2013-05-10 14:59:21 +08:00
|
|
|
local strInfo = string.format("%u particles", nQuantityParticles)
|
|
|
|
pInfoLabel:setString(strInfo)
|
|
|
|
|
|
|
|
nLastRenderedCount = nQuantityParticles
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function doTest()
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
local pParticleSystem = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"ParticleSystem")
|
2013-05-10 14:59:21 +08:00
|
|
|
if nil == pParticleSystem then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if 0 == nCurCase then
|
|
|
|
--duration
|
|
|
|
pParticleSystem:setDuration(-1)
|
|
|
|
|
|
|
|
--gravity
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setGravity(cc.p(0,-90))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
--angle
|
|
|
|
pParticleSystem:setAngle(90)
|
|
|
|
pParticleSystem:setAngleVar(0)
|
|
|
|
|
|
|
|
--radial
|
|
|
|
pParticleSystem:setRadialAccel(0)
|
|
|
|
pParticleSystem:setRadialAccelVar(0)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
pParticleSystem:setSpeed(180)
|
|
|
|
pParticleSystem:setSpeedVar(50)
|
|
|
|
|
|
|
|
-- emitter position
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setPosition(cc.p(s.width/2, 100))
|
|
|
|
pParticleSystem:setPosVar(cc.p(s.width/2,0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
pParticleSystem:setLife(2.0)
|
|
|
|
pParticleSystem:setLifeVar(1)
|
|
|
|
|
|
|
|
--emits per frame
|
|
|
|
pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife())
|
|
|
|
|
|
|
|
--color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- 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)
|
|
|
|
|
|
|
|
--gravity
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setGravity(cc.p(0,-90))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
--angle
|
|
|
|
pParticleSystem:setAngle(90)
|
|
|
|
pParticleSystem:setAngleVar(0)
|
|
|
|
|
|
|
|
--radial
|
|
|
|
pParticleSystem:setRadialAccel(0)
|
|
|
|
pParticleSystem:setRadialAccelVar(0)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
pParticleSystem:setSpeed(180)
|
|
|
|
pParticleSystem:setSpeedVar(50)
|
|
|
|
|
|
|
|
-- emitter position
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setPosition(cc.p(s.width/2, 100))
|
|
|
|
pParticleSystem:setPosVar(cc.p(s.width/2,0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
pParticleSystem:setLife(2.0)
|
|
|
|
pParticleSystem:setLifeVar(1)
|
|
|
|
|
|
|
|
--emits per frame
|
|
|
|
pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife())
|
|
|
|
|
|
|
|
--color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- 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
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setGravity(cc.p(0,-90))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
--angle
|
|
|
|
pParticleSystem:setAngle(90)
|
|
|
|
pParticleSystem:setAngleVar(0)
|
|
|
|
|
|
|
|
--radial
|
|
|
|
pParticleSystem:setRadialAccel(0)
|
|
|
|
pParticleSystem:setRadialAccelVar(0)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
pParticleSystem:setSpeed(180)
|
|
|
|
pParticleSystem:setSpeedVar(50)
|
|
|
|
|
|
|
|
-- emitter position
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setPosition(cc.p(s.width/2, 100))
|
|
|
|
pParticleSystem:setPosVar(cc.p(s.width/2,0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
pParticleSystem:setLife(2.0)
|
|
|
|
pParticleSystem:setLifeVar(1)
|
|
|
|
|
|
|
|
--emits per frame
|
|
|
|
pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife())
|
|
|
|
|
|
|
|
--color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- 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
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setGravity(cc.p(0,-90))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
--angle
|
|
|
|
pParticleSystem:setAngle(90)
|
|
|
|
pParticleSystem:setAngleVar(0)
|
|
|
|
|
|
|
|
--radial
|
|
|
|
pParticleSystem:setRadialAccel(0)
|
|
|
|
pParticleSystem:setRadialAccelVar(0)
|
|
|
|
|
|
|
|
-- speed of particles
|
|
|
|
pParticleSystem:setSpeed(180)
|
|
|
|
pParticleSystem:setSpeedVar(50)
|
|
|
|
|
|
|
|
-- emitter position
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setPosition(cc.p(s.width/2, 100))
|
|
|
|
pParticleSystem:setPosVar(cc.p(s.width/2,0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- life of particles
|
|
|
|
pParticleSystem:setLife(2.0)
|
|
|
|
pParticleSystem:setLifeVar(1)
|
|
|
|
|
|
|
|
--emits per frame
|
|
|
|
pParticleSystem:setEmissionRate(pParticleSystem:getTotalParticles() / pParticleSystem:getLife())
|
|
|
|
|
|
|
|
--color of particles
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColor(cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setStartColorVar( cc.c4f(0.5, 0.5, 0.5, 1.0))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColor(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setEndColorVar(cc.c4f(0.1, 0.1, 0.1, 0.2))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
-- 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)
|
|
|
|
|
|
|
|
* 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.
|
2013-08-20 13:44:37 +08:00
|
|
|
local pTexture = cc.TextureCache:getInstance():addImage("Images/fire.png")
|
|
|
|
cc.TextureCache:getInstance():removeTexture(pTexture)
|
2014-01-04 15:46:04 +08:00
|
|
|
local pParticleSystem = cc.ParticleSystemQuad:createWithTotalParticles(nQuantityParticles)
|
2013-05-10 14:59:21 +08:00
|
|
|
if 1 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
2013-05-10 14:59:21 +08:00
|
|
|
elseif 2 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
|
2013-05-10 14:59:21 +08:00
|
|
|
elseif 3 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8)
|
2013-05-10 14:59:21 +08:00
|
|
|
elseif 4 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
2013-05-10 14:59:21 +08:00
|
|
|
elseif 5 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
|
2013-05-10 14:59:21 +08:00
|
|
|
elseif 6 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8)
|
2013-05-10 14:59:21 +08:00
|
|
|
else
|
|
|
|
pParticleSystem = nil
|
|
|
|
print("Shall not happen!")
|
|
|
|
end
|
|
|
|
|
|
|
|
if nil ~= pParticleSystem then
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleSystem:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
|
2013-05-10 14:59:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
pNewScene:addChild(pParticleSystem, 0, ParticleTestParam.kTagParticleSystem)
|
|
|
|
|
|
|
|
doTest()
|
|
|
|
--restore the default pixel format
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
2013-05-10 14:59:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function step(t)
|
2013-08-20 13:44:37 +08:00
|
|
|
local pAtlas = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagLabelAtlas),"LabelAtlas")
|
|
|
|
local pEmitter = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"ParticleSystem")
|
2013-05-10 14:59:21 +08:00
|
|
|
local strInfo = string.format("%4d",pEmitter:getParticleCount())
|
|
|
|
pAtlas:setString(strInfo)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function ScheduleFuncion()
|
|
|
|
local function OnEnterOrExit(tag)
|
2013-08-20 13:44:37 +08:00
|
|
|
local scheduler = cc.Director:getInstance():getScheduler()
|
2013-05-10 14:59:21 +08:00
|
|
|
if tag == "enter" then
|
|
|
|
ScheduleSelector = scheduler:scheduleScriptFunc(step,0,false)
|
|
|
|
elseif tag == "exit" then
|
|
|
|
scheduler:unscheduleScriptEntry(ScheduleSelector)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pNewScene:registerScriptHandler(OnEnterOrExit)
|
|
|
|
end
|
|
|
|
|
2013-05-11 17:00:19 +08:00
|
|
|
local function onDecrease()
|
2013-05-10 14:59:21 +08:00
|
|
|
nQuantityParticles = nQuantityParticles - ParticleTestParam.kNodesIncrease
|
|
|
|
if nQuantityParticles < 0 then
|
|
|
|
nQuantityParticles = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
UpdateQuantityLabel()
|
|
|
|
CreateParticleSystem()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onIncrease()
|
|
|
|
nQuantityParticles = nQuantityParticles + ParticleTestParam.kNodesIncrease
|
|
|
|
if nQuantityParticles > ParticleTestParam.kMaxParticles then
|
|
|
|
nQuantityParticles = ParticleTestParam.kMaxParticles
|
|
|
|
end
|
|
|
|
|
|
|
|
UpdateQuantityLabel()
|
|
|
|
CreateParticleSystem()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function InitWithSubTest(nSubtest,nParticles)
|
|
|
|
nSubtestNumber = nSubtest
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
nLastRenderedCount = 0
|
|
|
|
nQuantityParticles = nParticles
|
|
|
|
|
2013-05-13 10:07:22 +08:00
|
|
|
--"+","-" Menu
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontSize(65)
|
|
|
|
local pDecrease = cc.MenuItemFont:create(" - ")
|
2013-05-10 14:59:21 +08:00
|
|
|
pDecrease:registerScriptTapHandler(onDecrease)
|
2013-08-20 13:44:37 +08:00
|
|
|
pDecrease:setColor(cc.c3b(0,200,20))
|
|
|
|
local pIncrease = cc.MenuItemFont:create(" + ")
|
2013-05-10 14:59:21 +08:00
|
|
|
pIncrease:registerScriptTapHandler(onIncrease)
|
2013-08-20 13:44:37 +08:00
|
|
|
pIncrease:setColor(cc.c3b(0,200,20))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pMenuAddOrSub = cc.Menu:create()
|
2013-05-10 14:59:21 +08:00
|
|
|
pMenuAddOrSub:addChild(pDecrease)
|
|
|
|
pMenuAddOrSub:addChild(pIncrease)
|
|
|
|
pMenuAddOrSub:alignItemsHorizontally()
|
2013-08-20 13:44:37 +08:00
|
|
|
pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewScene:addChild(pMenuAddOrSub,1)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewScene:addChild(pInfoLabel, 1, ParticleTestParam.kTagInfoLayer)
|
|
|
|
|
|
|
|
--particles on stage
|
2013-08-20 13:44:37 +08:00
|
|
|
local pLabelAtlas = cc.LabelAtlas:_create("0000", "fps_images.png", 12, 32, string.byte('.'))
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewScene:addChild(pLabelAtlas, 0, ParticleTestParam.kTagLabelAtlas)
|
2013-08-20 13:44:37 +08:00
|
|
|
pLabelAtlas:setPosition(cc.p(s.width-66,50))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
--ParticleTestMenuLayer
|
2013-08-20 13:44:37 +08:00
|
|
|
local pParticleMenuLayer = cc.Layer:create()
|
|
|
|
local pParticleMenu = cc.Menu:create()
|
2013-05-10 14:59:21 +08:00
|
|
|
CreatePerfomBasicLayerMenu(pParticleMenu)
|
|
|
|
CreateBasicLayerMenuItem(pParticleMenu,true,ParticleTestParam.TEST_COUNT,nCurCase)
|
2013-08-20 13:44:37 +08:00
|
|
|
pParticleMenu:setPosition(cc.p(0, 0))
|
2013-05-10 14:59:21 +08:00
|
|
|
pParticleMenuLayer:addChild(pParticleMenu)
|
|
|
|
pNewScene:addChild(pParticleMenuLayer)
|
|
|
|
|
|
|
|
--Sub Tests
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontSize(40)
|
|
|
|
local pSubMenu = cc.Menu:create()
|
2013-05-10 14:59:21 +08:00
|
|
|
local i = 1
|
|
|
|
for i = 1, 6 do
|
|
|
|
local strNum = string.format("%d ",i)
|
2013-08-20 13:44:37 +08:00
|
|
|
local pItemFont = cc.MenuItemFont:create(strNum)
|
2013-05-10 14:59:21 +08:00
|
|
|
pItemFont:registerScriptTapHandler(TestNCallback)
|
|
|
|
pSubMenu:addChild(pItemFont, i + ParticleTestParam.kSubMenuBasicZOrder)
|
|
|
|
if i <= 3 then
|
2013-08-20 13:44:37 +08:00
|
|
|
pItemFont:setColor(cc.c3b(200,20,20))
|
2013-05-10 14:59:21 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
pItemFont:setColor(cc.c3b(0,200,20))
|
2013-05-10 14:59:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
pSubMenu:alignItemsHorizontally()
|
2013-08-20 13:44:37 +08:00
|
|
|
pSubMenu:setPosition(cc.p(s.width/2, 80))
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewScene:addChild(pSubMenu, 2)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40)
|
2013-05-10 14:59:21 +08:00
|
|
|
pNewScene:addChild(pLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pLabel:setPosition(cc.p(s.width/2, s.height-32))
|
|
|
|
pLabel:setColor(cc.c3b(255,255,40))
|
2013-05-10 14:59:21 +08:00
|
|
|
|
|
|
|
UpdateQuantityLabel()
|
|
|
|
CreateParticleSystem()
|
|
|
|
ScheduleFuncion()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ShowCurrentTest()
|
|
|
|
if nil ~= pNewScene then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():getScheduler():unscheduleScriptEntry(ScheduleSelector)
|
2013-05-10 14:59:21 +08:00
|
|
|
end
|
2013-08-20 13:44:37 +08:00
|
|
|
pNewScene = cc.Scene:create()
|
2013-05-10 14:59:21 +08:00
|
|
|
InitWithSubTest(nSubtestNumber,nQuantityParticles)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(pNewScene)
|
2013-05-10 14:59:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
InitWithSubTest(1,ParticleTestParam.kNodesIncrease)
|
|
|
|
return pNewScene
|
|
|
|
end
|
|
|
|
|
2013-05-11 17:00:19 +08:00
|
|
|
----------------------------------
|
|
|
|
--PerformanceSpriteTest
|
|
|
|
----------------------------------
|
|
|
|
local SpriteTestParam =
|
|
|
|
{
|
|
|
|
kMaxNodes = 50000,
|
|
|
|
kNodesIncrease = 250,
|
|
|
|
TEST_COUNT = 7,
|
|
|
|
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
kTagMainLayer = 2,
|
|
|
|
-- 50000 -- kMaxNodes
|
|
|
|
kTagMenuLayer = 50000 + 1000,
|
|
|
|
kInitNodes = 50,
|
|
|
|
kSubMenuBasicZOrder = 20,
|
|
|
|
|
|
|
|
kRandMax = 32767
|
|
|
|
}
|
|
|
|
|
|
|
|
local function runSpriteTest()
|
|
|
|
--PerformanceParticle param
|
|
|
|
local nLastRenderedCount = 0
|
|
|
|
local nQuantityNodes = 0
|
|
|
|
local nSubtestNumber = 0
|
|
|
|
--BasiceLayer param
|
|
|
|
local bControlMenuVisible = false
|
|
|
|
local nMaxCases = 0
|
|
|
|
local nCurCase = 0
|
|
|
|
|
|
|
|
local ScheduleSelector = nil
|
|
|
|
|
|
|
|
--SubTest
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pNewScene = cc.Scene:create()
|
2013-05-11 17:00:19 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
2013-05-11 17:00:19 +08:00
|
|
|
item1:registerScriptTapHandler(backCallback)
|
|
|
|
pMenu:addChild(item1,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
2013-05-11 17:00:19 +08:00
|
|
|
item2:registerScriptTapHandler(restartCallback)
|
|
|
|
pMenu:addChild(item2,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
2013-05-11 17:00:19 +08:00
|
|
|
pMenu:addChild(item3,kItemTagBasic)
|
|
|
|
item3:registerScriptTapHandler(nextCallback)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function UpdateNodes()
|
|
|
|
if nQuantityNodes ~= nLastRenderedCount then
|
2013-08-20 13:44:37 +08:00
|
|
|
local pInfoLabel = tolua.cast(pNewScene:getChildByTag(SpriteTestParam.kTagInfoLayer), "LabelTTF")
|
2013-05-11 17:00:19 +08:00
|
|
|
local strInfo = string.format("%u nodes", nQuantityNodes)
|
|
|
|
pInfoLabel:setString(strInfo)
|
|
|
|
nLastRenderedCount = nQuantityNodes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformancePosition(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformanceScale(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSprite:setScale(math.random() * 100 / 50)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformanceRotationScale(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSprite:setRotation(math.random() * 360)
|
|
|
|
pSprite:setScale(math.random() * 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformanceOut100(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite:setPosition(cc.p( -1000, -1000))
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function Performanceout20(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
2013-05-11 17:00:19 +08:00
|
|
|
|
|
|
|
if math.random() < 0.2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
2013-05-11 17:00:19 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite:setPosition(cc.p( -1000, -1000))
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformanceActions(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
2013-05-11 17:00:19 +08:00
|
|
|
|
|
|
|
local fPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0
|
2013-08-20 13:44:37 +08:00
|
|
|
local pRot = cc.RotateBy:create(fPeriod, 360.0 * math.random() )
|
2013-05-11 17:00:19 +08:00
|
|
|
local pRot_back = pRot:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSprite:runAction(pPermanentRotation)
|
|
|
|
|
|
|
|
local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0
|
2013-08-20 13:44:37 +08:00
|
|
|
local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5)
|
|
|
|
local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse()))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSprite:runAction(pPermanentScaleLoop)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformanceActions20(pSprite)
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
2013-05-11 17:00:19 +08:00
|
|
|
|
|
|
|
if math.random() < 0.2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite:setPosition(cc.p((math.random(0,SpriteTestParam.kRandMax) % (size.width) ), (math.random(0,SpriteTestParam.kRandMax) % (size.height))))
|
2013-05-11 17:00:19 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite:setPosition(cc.p( -1000, -1000))
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local pPeriod = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0
|
2013-08-20 13:44:37 +08:00
|
|
|
local pRot = cc.RotateBy:create(pPeriod, 360.0 * math.random())
|
2013-05-11 17:00:19 +08:00
|
|
|
local pRot_back = pRot:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local pPermanentRotation = cc.RepeatForever:create(cc.Sequence:create(pRot, pRot_back))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSprite:runAction(pPermanentRotation)
|
|
|
|
|
|
|
|
|
|
|
|
local fGrowDuration = 0.5 + (math.random(0,SpriteTestParam.kRandMax) % 1000) / 500.0
|
2013-08-20 13:44:37 +08:00
|
|
|
local pGrow = cc.ScaleBy:create(fGrowDuration, 0.5, 0.5)
|
|
|
|
local pPermanentScaleLoop = cc.RepeatForever:create(cc.Sequence:create(pGrow, pGrow:reverse()))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSprite:runAction(pPermanentScaleLoop)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local function CreateSpriteWithTag(nTag)
|
|
|
|
--create
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
2013-05-11 17:00:19 +08:00
|
|
|
local pSprite = nil
|
|
|
|
if 1 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite = cc.Sprite:create("Images/grossinis_sister1.png")
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pSprite, 0, nTag+100)
|
|
|
|
elseif 2 == nSubtestNumber or 3 == nSubtestNumber then
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(0, 0, 52, 139))
|
2013-05-11 17:00:19 +08:00
|
|
|
pBatchNode:addChild(pSprite, 0, nTag+100)
|
|
|
|
elseif 4 == nSubtestNumber then
|
|
|
|
local nIndex = math.floor((math.random() * 1400 / 100)) + 1
|
|
|
|
local strPath = string.format("Images/grossini_dance_%02d.png", nIndex)
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite = cc.Sprite:create(strPath)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pSprite, 0, nTag+100)
|
|
|
|
elseif 5 == nSubtestNumber or 6 == nSubtestNumber then
|
|
|
|
local nY = 0
|
|
|
|
local nX = 0
|
|
|
|
local nR = math.floor(math.random() * 1400 / 100)
|
|
|
|
|
|
|
|
nX = nR % 5
|
|
|
|
nY = math.floor(nR / 5)
|
|
|
|
|
|
|
|
nX = nX * 85
|
|
|
|
nY = nY * 121
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(nX,nY,85,121))
|
2013-05-11 17:00:19 +08:00
|
|
|
pBatchNode:addChild(pSprite, 0, nTag+100)
|
|
|
|
elseif 7 == nSubtestNumber then
|
|
|
|
local nX = 0
|
|
|
|
local nY = 0
|
|
|
|
local nR = math.floor(math.random() * 6400 / 100)
|
|
|
|
|
|
|
|
nX = nR % 8
|
|
|
|
nY = math.floor(nR / 8)
|
|
|
|
|
|
|
|
local strPath = string.format("Images/sprites_test/sprite-%d-%d.png", nX, nY)
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite = cc.Sprite:create(strPath)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pSprite, 0, nTag+100)
|
|
|
|
elseif 8 == nSubtestNumber or 9 == nSubtestNumber then
|
|
|
|
local nX = 0
|
|
|
|
local nY = 0
|
|
|
|
local nR = math.floor(math.random() * 6400 / 100)
|
|
|
|
|
|
|
|
nX = nR % 8
|
|
|
|
nY = math.floor(nR / 8)
|
|
|
|
|
|
|
|
nX = nX * 32
|
|
|
|
nY = nY * 32
|
2013-08-20 13:44:37 +08:00
|
|
|
pSprite = cc.Sprite:createWithTexture(pBatchNode:getTexture(), cc.rect(nX,nY,32,32))
|
2013-05-11 17:00:19 +08:00
|
|
|
pBatchNode:addChild(pSprite, 0, nTag+100)
|
|
|
|
end
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT )
|
2013-05-11 17:00:19 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
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()
|
|
|
|
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)
|
|
|
|
DoTest(pSprite)
|
|
|
|
nQuantityNodes = nQuantityNodes + 1
|
|
|
|
end
|
|
|
|
UpdateNodes()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function TestNCallback(tag,pMenuItem)
|
|
|
|
local nIndex = pMenuItem:getZOrder() - 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
|
|
|
|
|
|
|
|
* 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
|
2013-08-20 13:44:37 +08:00
|
|
|
local pMgr = cc.TextureCache:getInstance()
|
2013-05-11 17:00:19 +08:00
|
|
|
--[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
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pBatchNode, 0)
|
|
|
|
elseif 3 == nSubTest then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
|
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/grossinis_sister1.png", 100)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pBatchNode, 0)
|
|
|
|
elseif 5 == nSubTest then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pBatchNode, 0)
|
|
|
|
elseif 6 == nSubTest then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
|
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 100)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pBatchNode, 0)
|
|
|
|
elseif 8 == nSubTest then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pBatchNode, 0)
|
|
|
|
elseif 9 == nSubTest then
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
|
|
|
|
pBatchNode = cc.SpriteBatchNode:create("Images/spritesheet1.png", 100)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pBatchNode, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
if nil ~= pBatchNode then
|
|
|
|
pBatchNode:retain()
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE_PIXELFORMAT_DEFAULT )
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function InitWithSpriteTest(nSubtest,nNodes)
|
|
|
|
nSubtestNumber = nSubtest
|
|
|
|
--about create subset
|
|
|
|
InitWithSubTest(nSubtest)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-05-11 17:00:19 +08:00
|
|
|
|
|
|
|
nLastRenderedCount = 0
|
|
|
|
nQuantityNodes = 0
|
|
|
|
|
2013-05-13 10:07:22 +08:00
|
|
|
--"+","-" Menu
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontSize(65)
|
|
|
|
local pDecrease = cc.MenuItemFont:create(" - ")
|
2013-05-11 17:00:19 +08:00
|
|
|
pDecrease:registerScriptTapHandler(onDecrease)
|
2013-08-20 13:44:37 +08:00
|
|
|
pDecrease:setColor(cc.c3b(0,200,20))
|
|
|
|
local pIncrease = cc.MenuItemFont:create(" + ")
|
2013-05-11 17:00:19 +08:00
|
|
|
pIncrease:registerScriptTapHandler(onIncrease)
|
2013-08-20 13:44:37 +08:00
|
|
|
pIncrease:setColor(cc.c3b(0,200,20))
|
2013-05-11 17:00:19 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pMenuAddOrSub = cc.Menu:create()
|
2013-05-11 17:00:19 +08:00
|
|
|
pMenuAddOrSub:addChild(pDecrease)
|
|
|
|
pMenuAddOrSub:addChild(pIncrease)
|
|
|
|
pMenuAddOrSub:alignItemsHorizontally()
|
2013-08-20 13:44:37 +08:00
|
|
|
pMenuAddOrSub:setPosition(cc.p(s.width/2, s.height/2+15))
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pMenuAddOrSub,1)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pInfoLabel, 1, SpriteTestParam.kTagInfoLayer)
|
|
|
|
|
|
|
|
--SpriteTestMenuLayer
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSpriteMenuLayer = cc.Layer:create()
|
|
|
|
local pSpriteMenu = cc.Menu:create()
|
2013-05-11 17:00:19 +08:00
|
|
|
CreatePerfomBasicLayerMenu(pSpriteMenu)
|
|
|
|
CreateBasicLayerMenuItem(pSpriteMenu,true,SpriteTestParam.TEST_COUNT,nCurCase)
|
2013-08-20 13:44:37 +08:00
|
|
|
pSpriteMenu:setPosition(cc.p(0, 0))
|
2013-05-11 17:00:19 +08:00
|
|
|
pSpriteMenuLayer:addChild(pSpriteMenu)
|
|
|
|
pNewScene:addChild(pSpriteMenuLayer,1,SpriteTestParam.kTagMenuLayer)
|
|
|
|
|
|
|
|
|
|
|
|
--Sub Tests
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.MenuItemFont:setFontSize(40)
|
|
|
|
local pSubMenu = cc.Menu:create()
|
2013-05-11 17:00:19 +08:00
|
|
|
local i = 1
|
|
|
|
for i = 1, 9 do
|
|
|
|
local strNum = string.format("%d ",i)
|
2013-08-20 13:44:37 +08:00
|
|
|
local pItemFont = cc.MenuItemFont:create(strNum)
|
2013-05-11 17:00:19 +08:00
|
|
|
pItemFont:registerScriptTapHandler(TestNCallback)
|
|
|
|
pSubMenu:addChild(pItemFont, i + SpriteTestParam.kSubMenuBasicZOrder)
|
|
|
|
if i <= 3 then
|
2013-08-20 13:44:37 +08:00
|
|
|
pItemFont:setColor(cc.c3b(200,20,20))
|
2013-05-11 17:00:19 +08:00
|
|
|
elseif i <= 6 then
|
2013-08-20 13:44:37 +08:00
|
|
|
pItemFont:setColor(cc.c3b(0,200,20))
|
2013-05-11 17:00:19 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
pItemFont:setColor(cc.c3b(0,20,200))
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
pSubMenu:alignItemsHorizontally()
|
2013-08-20 13:44:37 +08:00
|
|
|
pSubMenu:setPosition(cc.p(s.width/2, 80))
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pSubMenu, 2)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40)
|
2013-05-11 17:00:19 +08:00
|
|
|
pNewScene:addChild(pLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pLabel:setPosition(cc.p(s.width/2, s.height-32))
|
|
|
|
pLabel:setColor(cc.c3b(255,255,40))
|
2013-05-11 17:00:19 +08:00
|
|
|
while nQuantityNodes < nNodes do
|
|
|
|
onIncrease()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ShowCurrentTest()
|
2013-08-20 13:44:37 +08:00
|
|
|
pNewScene = cc.Scene:create()
|
2013-05-11 17:00:19 +08:00
|
|
|
InitWithSpriteTest(nSubtestNumber,nQuantityNodes)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(pNewScene)
|
2013-05-11 17:00:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
InitWithSpriteTest(1,SpriteTestParam.kInitNodes)
|
|
|
|
|
|
|
|
return pNewScene
|
|
|
|
end
|
|
|
|
|
2013-05-09 14:46:48 +08:00
|
|
|
----------------------------------
|
|
|
|
--PerformanceTextureTest
|
|
|
|
----------------------------------
|
|
|
|
local TextureTestParam =
|
|
|
|
{
|
|
|
|
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
|
2013-08-20 13:44:37 +08:00
|
|
|
local pNewscene = cc.Scene:create()
|
|
|
|
local pLayer = cc.Layer:create()
|
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-05-09 14:46:48 +08:00
|
|
|
|
|
|
|
local function PerformTestsPNG(strFileName)
|
|
|
|
local time
|
|
|
|
local pTexture = nil
|
2013-08-20 13:44:37 +08:00
|
|
|
local pCache = cc.TextureCache:getInstance()
|
2013-05-09 14:46:48 +08:00
|
|
|
print("RGBA 8888")
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
2013-05-09 14:46:48 +08:00
|
|
|
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)
|
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
print("RGBA 4444")
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
|
2013-05-10 14:59:21 +08:00
|
|
|
--gettimeofday(&now, NULL)
|
|
|
|
pTexture = pCache:addImage(strFileName)
|
2013-05-09 14:46:48 +08:00
|
|
|
if nil ~= pTexture then
|
|
|
|
print("add sucess")
|
|
|
|
else
|
|
|
|
print(" ERROR")
|
|
|
|
end
|
|
|
|
pCache:removeTexture(pTexture)
|
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
print("RGBA 5551")
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB5_A1)
|
2013-05-10 14:59:21 +08:00
|
|
|
--gettimeofday(&now, NULL)
|
|
|
|
pTexture = pCache:addImage(strFileName)
|
2013-05-09 14:46:48 +08:00
|
|
|
if nil ~= pTexture then
|
|
|
|
print("add sucess")
|
|
|
|
else
|
|
|
|
print(" ERROR")
|
|
|
|
end
|
2013-05-10 14:59:21 +08:00
|
|
|
pCache:removeTexture(pTexture)
|
2013-05-09 14:46:48 +08:00
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
print("RGB 565")
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RG_B565)
|
2013-05-10 14:59:21 +08:00
|
|
|
-- gettimeofday(&now, NULL)
|
|
|
|
pTexture = pCache:addImage(strFileName)
|
2013-05-09 14:46:48 +08:00
|
|
|
if nil ~= pTexture then
|
2013-07-24 06:20:22 +08:00
|
|
|
--log(" ms:%f", calculateDeltaTime(&now) )
|
2013-05-09 14:46:48 +08:00
|
|
|
print("add sucess")
|
|
|
|
else
|
2013-05-10 14:59:21 +08:00
|
|
|
print(" ERROR")
|
2013-05-09 14:46:48 +08:00
|
|
|
end
|
2013-05-10 14:59:21 +08:00
|
|
|
pCache:removeTexture(pTexture)
|
2013-05-09 14:46:48 +08:00
|
|
|
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")
|
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
print("SPRITESHEET IMAGE")
|
|
|
|
print("--- PNG 1024x1024 ---")
|
|
|
|
PerformTestsPNG("Images/PlanetCute-1024x1024.png")
|
2013-05-09 14:46:48 +08:00
|
|
|
|
2013-05-10 14:59:21 +08:00
|
|
|
print("LANDSCAPE IMAGE")
|
|
|
|
print("--- PNG 1024x1024 ---")
|
|
|
|
PerformTestsPNG("Images/landscape-1024x1024.png")
|
2013-05-09 14:46:48 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function InitTextureMenuLayer()
|
|
|
|
if nil == pLayer then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
--Title
|
2013-08-20 13:44:37 +08:00
|
|
|
local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40)
|
2013-05-09 14:46:48 +08:00
|
|
|
pLayer:addChild(pLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pLabel:setPosition(cc.p(s.width/2, s.height-32))
|
|
|
|
pLabel:setColor(cc.c3b(255,255,40))
|
2013-05-09 14:46:48 +08:00
|
|
|
|
|
|
|
--Subtitle
|
2013-08-20 13:44:37 +08:00
|
|
|
local pSubLabel = cc.LabelTTF:create(GetSubtitle(), "Thonburi", 16)
|
2013-05-09 14:46:48 +08:00
|
|
|
pLayer:addChild(pSubLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pSubLabel:setPosition(cc.p(s.width/2, s.height-80))
|
2013-05-09 14:46:48 +08:00
|
|
|
|
|
|
|
--menu
|
2013-08-20 13:44:37 +08:00
|
|
|
local pMenu = cc.Menu:create()
|
2013-05-09 14:46:48 +08:00
|
|
|
CreatePerfomBasicLayerMenu(pMenu)
|
2013-08-20 13:44:37 +08:00
|
|
|
pMenu:setPosition(cc.p(0, 0))
|
2013-05-09 14:46:48 +08:00
|
|
|
pLayer:addChild(pMenu)
|
|
|
|
|
|
|
|
PerformTests()
|
|
|
|
end
|
|
|
|
|
|
|
|
InitTextureMenuLayer()
|
|
|
|
pNewscene:addChild(pLayer)
|
|
|
|
return pNewscene
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
2013-05-09 16:59:39 +08:00
|
|
|
----------------------------------
|
|
|
|
--PerformanceTouchesTest
|
|
|
|
----------------------------------
|
|
|
|
local TouchesTestParam =
|
|
|
|
{
|
|
|
|
TEST_COUNT = 2,
|
|
|
|
}
|
|
|
|
local function runTouchesTest()
|
|
|
|
local nTouchCurCase = 0
|
|
|
|
--PerformBasicLayer param
|
|
|
|
local bControlMenuVisible = false
|
|
|
|
local nMaxCases = 0
|
|
|
|
local nCurCase = 0
|
|
|
|
--TouchesMainScene param
|
|
|
|
local pClassLabel = nil
|
|
|
|
local nNumberOfTouchesB = 0
|
|
|
|
local nNumberOfTouchesM = 0
|
|
|
|
local nNumberOfTouchesE = 0
|
|
|
|
local nNumberOfTouchesC = 0
|
|
|
|
local fElapsedTime = 0.0
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
local pNewscene = cc.Scene:create()
|
|
|
|
local pLayer = cc.Layer:create()
|
2013-05-09 16:59:39 +08:00
|
|
|
|
|
|
|
local function GetTitle()
|
|
|
|
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
|
|
|
|
|
|
|
|
local function restartCallback()
|
|
|
|
ShowCurrentTest()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function nextCallback()
|
|
|
|
nCurCase = nCurCase + 1
|
|
|
|
--No check nMaxCases
|
|
|
|
nCurCase = nCurCase % nMaxCases
|
|
|
|
ShowCurrentTest()
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
local item1 = cc.MenuItemImage:create(s_pPathB1, s_pPathB2)
|
2013-05-09 16:59:39 +08:00
|
|
|
item1:registerScriptTapHandler(backCallback)
|
|
|
|
pMenu:addChild(item1,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item2 = cc.MenuItemImage:create(s_pPathR1, s_pPathR2)
|
2013-05-09 16:59:39 +08:00
|
|
|
item2:registerScriptTapHandler(restartCallback)
|
|
|
|
pMenu:addChild(item2,kItemTagBasic)
|
2013-08-20 13:44:37 +08:00
|
|
|
local item3 = cc.MenuItemImage:create(s_pPathF1, s_pPathF2)
|
2013-05-09 16:59:39 +08:00
|
|
|
pMenu:addChild(item3,kItemTagBasic)
|
|
|
|
item3:registerScriptTapHandler(nextCallback)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
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))
|
2013-05-09 16:59:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function update(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
|
2013-05-10 14:59:21 +08:00
|
|
|
fElapsedTime = 0
|
2013-05-09 16:59:39 +08:00
|
|
|
nNumberOfTouchesB = 0
|
|
|
|
nNumberOfTouchesM = 0
|
|
|
|
nNumberOfTouchesE = 0
|
|
|
|
nNumberOfTouchesC = 0
|
|
|
|
|
|
|
|
local strInfo = string.format("%.1f %.1f %.1f %.1f",fFrameRateB, fFrameRateM, fFrameRateE, fFrameRateC)
|
|
|
|
if nil ~= pClassLabel then
|
2013-05-10 14:59:21 +08:00
|
|
|
pClassLabel:setString(strInfo)
|
2013-05-09 16:59:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- handling touch events
|
|
|
|
local function onTouchBegan(tableArray)
|
|
|
|
if 0 == nCurCase then
|
|
|
|
nNumberOfTouchesB = nNumberOfTouchesB + 1
|
|
|
|
elseif 1 == nCurCase then
|
|
|
|
nNumberOfTouchesB = nNumberOfTouchesB + table.getn(tableArray)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onTouchMoved(tableArray)
|
|
|
|
if 0 == nCurCase then
|
|
|
|
nNumberOfTouchesM = nNumberOfTouchesM + 1
|
|
|
|
elseif 1 == nCurCase then
|
|
|
|
nNumberOfTouchesM = nNumberOfTouchesM + table.getn(tableArray)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onTouchEnded(tableArray)
|
|
|
|
if 0 == nCurCase then
|
|
|
|
nNumberOfTouchesE = nNumberOfTouchesE + 1
|
|
|
|
elseif 1 == nCurCase then
|
|
|
|
nNumberOfTouchesE = nNumberOfTouchesE + table.getn(tableArray)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onTouchCancelled(tableArray)
|
|
|
|
if 0 == nCurCase then
|
|
|
|
nNumberOfTouchesC = nNumberOfTouchesC + 1
|
|
|
|
elseif 1 == nCurCase then
|
|
|
|
nNumberOfTouchesC = nNumberOfTouchesC + table.getn(tableArray)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function onTouch(eventType,tableArray)
|
|
|
|
if eventType == "began" then
|
|
|
|
return onTouchBegan(tableArray)
|
|
|
|
elseif eventType == "moved" then
|
|
|
|
return onTouchMoved(tableArray)
|
|
|
|
elseif eventType == "ended" then
|
|
|
|
return onTouchEnded(tableArray)
|
|
|
|
elseif eventType == "cancelled" then
|
|
|
|
return onTouchCancelled(tableArray)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function InitLayer()
|
|
|
|
--menu
|
2013-08-20 13:44:37 +08:00
|
|
|
local pTouchesTestMenu = cc.Menu:create()
|
2013-05-09 16:59:39 +08:00
|
|
|
CreatePerfomBasicLayerMenu(pTouchesTestMenu)
|
|
|
|
CreateBasicLayerMenuItem(pTouchesTestMenu,true,TouchesTestParam.TEST_COUNT,nCurCase)
|
2013-08-20 13:44:37 +08:00
|
|
|
pTouchesTestMenu:setPosition(cc.p(0, 0))
|
2013-05-09 16:59:39 +08:00
|
|
|
pLayer:addChild(pTouchesTestMenu)
|
|
|
|
|
|
|
|
--Title
|
2013-08-20 13:44:37 +08:00
|
|
|
local pLabel = cc.LabelTTF:create(GetTitle(), "Arial", 40)
|
2013-05-09 16:59:39 +08:00
|
|
|
pLayer:addChild(pLabel, 1)
|
2013-08-20 13:44:37 +08:00
|
|
|
pLabel:setPosition(cc.p(s.width/2, s.height-32))
|
|
|
|
pLabel:setColor(cc.c3b(255,255,40))
|
2013-05-09 16:59:39 +08:00
|
|
|
|
|
|
|
pLayer:scheduleUpdateWithPriorityLua(update,0)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pClassLabel = cc.LabelBMFont:create("00.0", "fonts/arial16.fnt")
|
|
|
|
pClassLabel:setPosition(cc.p(s.width/2, s.height/2))
|
2013-05-10 14:59:21 +08:00
|
|
|
pLayer:addChild(pClassLabel)
|
2013-05-09 16:59:39 +08:00
|
|
|
|
|
|
|
fElapsedTime = 0.0
|
|
|
|
nNumberOfTouchesB = 0
|
|
|
|
nNumberOfTouchesM = 0
|
|
|
|
nNumberOfTouchesE = 0
|
|
|
|
nNumberOfTouchesC = 0
|
|
|
|
pLayer:setTouchEnabled(true)
|
|
|
|
|
|
|
|
pLayer:registerScriptTouchHandler(onTouch,true)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ShowCurrentTest()
|
|
|
|
if nil ~= pLayer then
|
|
|
|
pLayer:unscheduleUpdate()
|
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
pNewscene = cc.Scene:create()
|
2013-05-09 16:59:39 +08:00
|
|
|
|
|
|
|
if nil ~= pNewscene then
|
2013-08-20 13:44:37 +08:00
|
|
|
pLayer = cc.Layer:create()
|
2013-05-09 16:59:39 +08:00
|
|
|
InitLayer()
|
|
|
|
pNewscene:addChild(pLayer)
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(pNewscene)
|
2013-05-09 16:59:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
InitLayer()
|
|
|
|
pNewscene:addChild(pLayer)
|
|
|
|
return pNewscene
|
|
|
|
end
|
|
|
|
|
2013-05-09 14:46:48 +08:00
|
|
|
|
2013-05-09 16:59:39 +08:00
|
|
|
------------------------
|
|
|
|
--
|
|
|
|
------------------------
|
2013-05-09 09:57:05 +08:00
|
|
|
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
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.Director:getInstance():replaceScene(PerformanceTestScene)
|
2013-05-09 09:57:05 +08:00
|
|
|
end
|
2012-08-27 11:43:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local function PerformanceMainLayer()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2012-08-27 11:43:47 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local menu = cc.Menu:create()
|
|
|
|
menu:setPosition(cc.p(0, 0))
|
|
|
|
cc.MenuItemFont:setFontName("Arial")
|
|
|
|
cc.MenuItemFont:setFontSize(24)
|
2013-05-09 09:57:05 +08:00
|
|
|
for i = 1, MAX_COUNT do
|
2013-08-20 13:44:37 +08:00
|
|
|
local item = cc.MenuItemFont: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()
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2012-08-27 11:43:47 +08:00
|
|
|
|
|
|
|
scene:addChild(PerformanceMainLayer())
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
|
|
|
return scene
|
|
|
|
end
|