2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceNodeChildrenTest.h"
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
enum {
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
kTagMainLayer = 2,
|
|
|
|
kTagLabelAtlas = 3,
|
|
|
|
|
|
|
|
kTagBase = 20000,
|
|
|
|
|
2011-04-21 14:46:15 +08:00
|
|
|
TEST_COUNT = 4,
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
enum {
|
|
|
|
kMaxNodes = 15000,
|
|
|
|
kNodesIncrease = 500,
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int s_nCurCase = 0;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// NodeChildrenMenuLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
NodeChildrenMenuLayer::NodeChildrenMenuLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
|
|
|
|
: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeChildrenMenuLayer::showCurrentTest()
|
|
|
|
{
|
|
|
|
int nNodes = ((NodeChildrenMainScene*)getParent())->getQuantityOfNodes();
|
|
|
|
NodeChildrenMainScene* pScene = NULL;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// case 0:
|
|
|
|
// pScene = new IterateSpriteSheetFastEnum();
|
|
|
|
// break;
|
|
|
|
case 0:
|
|
|
|
pScene = new IterateSpriteSheetCArray();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pScene = new AddSpriteSheet();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pScene = new RemoveSpriteSheet();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pScene = new ReorderSpriteSheet();
|
|
|
|
break;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
s_nCurCase = _curCase;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (pScene)
|
|
|
|
{
|
|
|
|
pScene->initWithQuantityOfNodes(nNodes);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(pScene);
|
2012-04-19 14:35:52 +08:00
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// NodeChildrenMainScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
|
|
|
|
{
|
|
|
|
//srand(time());
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Title
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label = LabelTTF::create(title().c_str(), "Arial", 40);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
|
|
|
label->setPosition(ccp(s.width/2, s.height-32));
|
|
|
|
label->setColor(ccc3(255,255,40));
|
|
|
|
|
|
|
|
// Subtitle
|
|
|
|
std::string strSubTitle = subtitle();
|
|
|
|
if(strSubTitle.length())
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(l, 1);
|
|
|
|
l->setPosition(ccp(s.width/2, s.height-80));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
lastRenderedCount = 0;
|
|
|
|
currentQuantityOfNodes = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
quantityOfNodes = nNodes;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(65);
|
|
|
|
MenuItemFont *decrease = MenuItemFont::create(" - ", [&](Object *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityOfNodes -= kNodesIncrease;
|
|
|
|
if( quantityOfNodes < 0 )
|
|
|
|
quantityOfNodes = 0;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
updateQuantityOfNodes();
|
|
|
|
});
|
2011-03-25 13:59:08 +08:00
|
|
|
decrease->setColor(ccc3(0,200,20));
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *increase = MenuItemFont::create(" + ", [&](Object *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityOfNodes += kNodesIncrease;
|
|
|
|
if( quantityOfNodes > kMaxNodes )
|
|
|
|
quantityOfNodes = kMaxNodes;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
updateQuantityOfNodes();
|
|
|
|
});
|
2011-03-25 13:59:08 +08:00
|
|
|
increase->setColor(ccc3(0,200,20));
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(decrease, increase, NULL);
|
2011-03-25 13:59:08 +08:00
|
|
|
menu->alignItemsHorizontally();
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height/2+15));
|
|
|
|
addChild(menu, 1);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30);
|
2011-03-25 13:59:08 +08:00
|
|
|
infoLabel->setColor(ccc3(0,200,20));
|
|
|
|
infoLabel->setPosition(ccp(s.width/2, s.height/2-15));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
|
|
|
NodeChildrenMenuLayer* pMenu = new NodeChildrenMenuLayer(true, TEST_COUNT, s_nCurCase);
|
|
|
|
addChild(pMenu);
|
|
|
|
pMenu->release();
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
updateQuantityLabel();
|
2012-04-19 14:35:52 +08:00
|
|
|
updateQuantityOfNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string NodeChildrenMainScene::title()
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string NodeChildrenMainScene::subtitle()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void NodeChildrenMainScene::updateQuantityLabel()
|
|
|
|
{
|
|
|
|
if( quantityOfNodes != lastRenderedCount )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *infoLabel = (LabelTTF *) getChildByTag(kTagInfoLayer);
|
2011-03-25 13:59:08 +08:00
|
|
|
char str[20] = {0};
|
|
|
|
sprintf(str, "%u nodes", quantityOfNodes);
|
|
|
|
infoLabel->setString(str);
|
|
|
|
|
|
|
|
lastRenderedCount = quantityOfNodes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IterateSpriteSheet
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2011-04-25 14:30:30 +08:00
|
|
|
IterateSpriteSheet::~IterateSpriteSheet()
|
|
|
|
{
|
2013-03-25 11:47:27 +08:00
|
|
|
|
2011-04-25 14:30:30 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void IterateSpriteSheet::updateQuantityOfNodes()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// increase nodes
|
|
|
|
if( currentQuantityOfNodes < quantityOfNodes )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (quantityOfNodes-currentQuantityOfNodes); i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sprite = Sprite::createWithTexture(batchNode->getTexture(), CCRectMake(0, 0, 32, 32));
|
2012-04-19 14:35:52 +08:00
|
|
|
batchNode->addChild(sprite);
|
|
|
|
sprite->setPosition(ccp( CCRANDOM_0_1()*s.width, CCRANDOM_0_1()*s.height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// decrease nodes
|
|
|
|
else if ( currentQuantityOfNodes > quantityOfNodes )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (currentQuantityOfNodes-quantityOfNodes); i++)
|
|
|
|
{
|
|
|
|
int index = currentQuantityOfNodes-i-1;
|
|
|
|
batchNode->removeChildAtIndex(index, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentQuantityOfNodes = quantityOfNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IterateSpriteSheet::initWithQuantityOfNodes(unsigned int nNodes)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/spritesheet1.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batchNode);
|
2013-03-25 11:47:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NodeChildrenMainScene::initWithQuantityOfNodes(nNodes);
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* IterateSpriteSheet::profilerName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IterateSpriteSheetFastEnum
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2012-06-08 13:55:28 +08:00
|
|
|
void IterateSpriteSheetFastEnum::update(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2011-03-25 13:59:08 +08:00
|
|
|
// iterate using fast enumeration protocol
|
2013-06-20 14:17:10 +08:00
|
|
|
Array* pChildren = batchNode->getChildren();
|
|
|
|
Object* pObject = NULL;
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_START_INSTANCE(this, this->profilerName());
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2011-04-21 14:46:15 +08:00
|
|
|
CCARRAY_FOREACH(pChildren, pObject)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pSprite = (Sprite*) pObject;
|
2012-06-15 16:47:30 +08:00
|
|
|
pSprite->setVisible(false);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_STOP_INSTANCE(this, this->profilerName());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string IterateSpriteSheetFastEnum::title()
|
|
|
|
{
|
|
|
|
return "A - Iterate SpriteSheet";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string IterateSpriteSheetFastEnum::subtitle()
|
|
|
|
{
|
|
|
|
return "Iterate children using Fast Enum API. See console";
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* IterateSpriteSheetFastEnum::profilerName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "iter fast enum";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IterateSpriteSheetCArray
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2012-06-08 13:55:28 +08:00
|
|
|
void IterateSpriteSheetCArray::update(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2011-03-25 13:59:08 +08:00
|
|
|
// iterate using fast enumeration protocol
|
2013-06-20 14:17:10 +08:00
|
|
|
Array* pChildren = batchNode->getChildren();
|
|
|
|
Object* pObject = NULL;
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_START(this->profilerName());
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCARRAY_FOREACH(pChildren, pObject)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pSprite = (Sprite*)pObject;
|
2012-06-15 16:47:30 +08:00
|
|
|
pSprite->setVisible(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string IterateSpriteSheetCArray::title()
|
|
|
|
{
|
|
|
|
return "B - Iterate SpriteSheet";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string IterateSpriteSheetCArray::subtitle()
|
|
|
|
{
|
|
|
|
return "Iterate children using C Array API. See console";
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* IterateSpriteSheetCArray::profilerName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "iter c-array";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// AddRemoveSpriteSheet
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
AddRemoveSpriteSheet::~AddRemoveSpriteSheet()
|
|
|
|
{
|
2013-03-25 14:30:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddRemoveSpriteSheet::initWithQuantityOfNodes(unsigned int nNodes)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/spritesheet1.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(batchNode);
|
|
|
|
|
|
|
|
NodeChildrenMainScene::initWithQuantityOfNodes(nNodes);
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void AddRemoveSpriteSheet::updateQuantityOfNodes()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// increase nodes
|
|
|
|
if( currentQuantityOfNodes < quantityOfNodes )
|
|
|
|
{
|
|
|
|
for (int i=0; i < (quantityOfNodes-currentQuantityOfNodes); i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sprite = Sprite::createWithTexture(batchNode->getTexture(), CCRectMake(0, 0, 32, 32));
|
2011-03-25 13:59:08 +08:00
|
|
|
batchNode->addChild(sprite);
|
|
|
|
sprite->setPosition(ccp( CCRANDOM_0_1()*s.width, CCRANDOM_0_1()*s.height));
|
2012-06-15 16:47:30 +08:00
|
|
|
sprite->setVisible(false);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// decrease nodes
|
|
|
|
else if ( currentQuantityOfNodes > quantityOfNodes )
|
|
|
|
{
|
|
|
|
for(int i=0;i < (currentQuantityOfNodes-quantityOfNodes);i++)
|
|
|
|
{
|
|
|
|
int index = currentQuantityOfNodes-i-1;
|
|
|
|
batchNode->removeChildAtIndex(index, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentQuantityOfNodes = quantityOfNodes;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* AddRemoveSpriteSheet::profilerName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// AddSpriteSheet
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2012-06-08 13:55:28 +08:00
|
|
|
void AddSpriteSheet::update(float dt)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
// reset seed
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
// 15 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 0.15f;
|
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Array* sprites = Array::createWithCapacity(totalToAdd);
|
2012-04-19 14:35:52 +08:00
|
|
|
int *zs = new int[totalToAdd];
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Don't include the sprite creation time and random as part of the profiling
|
|
|
|
for(int i=0; i<totalToAdd; i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pSprite = Sprite::createWithTexture(batchNode->getTexture(), CCRectMake(0,0,32,32));
|
2011-04-21 14:46:15 +08:00
|
|
|
sprites->addObject(pSprite);
|
2011-03-25 13:59:08 +08:00
|
|
|
zs[i] = CCRANDOM_MINUS1_1() * 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_START( this->profilerName() );
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode->addChild((Node*) (sprites->objectAtIndex(i)), zs[i], kTagBase+i);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-03-25 11:47:27 +08:00
|
|
|
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
|
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
batchNode->removeChildByTag(kTagBase+i, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] zs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AddSpriteSheet::title()
|
|
|
|
{
|
|
|
|
return "C - Add to spritesheet";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AddSpriteSheet::subtitle()
|
|
|
|
{
|
|
|
|
return "Adds %10 of total sprites with random z. See console";
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* AddSpriteSheet::profilerName()
|
2011-04-25 14:30:30 +08:00
|
|
|
{
|
|
|
|
return "add sprites";
|
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// RemoveSpriteSheet
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2012-06-08 13:55:28 +08:00
|
|
|
void RemoveSpriteSheet::update(float dt)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
// 15 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 0.15f;
|
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Array* sprites = Array::createWithCapacity(totalToAdd);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Don't include the sprite creation time as part of the profiling
|
|
|
|
for(int i=0;i<totalToAdd;i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pSprite = Sprite::createWithTexture(batchNode->getTexture(), CCRectMake(0,0,32,32));
|
2011-04-21 14:46:15 +08:00
|
|
|
sprites->addObject(pSprite);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode->addChild((Node*) (sprites->objectAtIndex(i)), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove them
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_START( this->profilerName() );
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
batchNode->removeChildByTag(kTagBase+i, true);
|
|
|
|
}
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RemoveSpriteSheet::title()
|
|
|
|
{
|
|
|
|
return "D - Del from spritesheet";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RemoveSpriteSheet::subtitle()
|
|
|
|
{
|
|
|
|
return "Remove %10 of total sprites placed randomly. See console";
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* RemoveSpriteSheet::profilerName()
|
2011-04-25 14:30:30 +08:00
|
|
|
{
|
|
|
|
return "remove sprites";
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ReorderSpriteSheet
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2012-06-08 13:55:28 +08:00
|
|
|
void ReorderSpriteSheet::update(float dt)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
// 15 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 0.15f;
|
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Array* sprites = Array::createWithCapacity(totalToAdd);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Don't include the sprite creation time as part of the profiling
|
|
|
|
for(int i=0;i<totalToAdd;i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pSprite = Sprite::createWithTexture(batchNode->getTexture(), CCRectMake(0,0,32,32));
|
2011-04-21 14:46:15 +08:00
|
|
|
sprites->addObject(pSprite);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode->addChild((Node*) (sprites->objectAtIndex(i)), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
batchNode->sortAllChildren();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// reorder them
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_START( this->profilerName() );
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node* pNode = (Node*) (batchNode->getChildren()->objectAtIndex(i));
|
2011-04-21 14:46:15 +08:00
|
|
|
batchNode->reorderChild(pNode, CCRANDOM_MINUS1_1() * 50);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-03-25 11:47:27 +08:00
|
|
|
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
batchNode->removeChildByTag(kTagBase+i, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ReorderSpriteSheet::title()
|
|
|
|
{
|
|
|
|
return "E - Reorder from spritesheet";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ReorderSpriteSheet::subtitle()
|
|
|
|
{
|
|
|
|
return "Reorder %10 of total sprites placed randomly. See console";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-25 11:47:27 +08:00
|
|
|
const char* ReorderSpriteSheet::profilerName()
|
2011-04-25 14:30:30 +08:00
|
|
|
{
|
|
|
|
return "reorder sprites";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void runNodeChildrenTest()
|
|
|
|
{
|
|
|
|
IterateSpriteSheet* pScene = new IterateSpriteSheetCArray();
|
|
|
|
pScene->initWithQuantityOfNodes(kNodesIncrease);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(pScene);
|
2012-04-19 14:35:52 +08:00
|
|
|
pScene->release();
|
|
|
|
}
|