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();
|
2013-07-23 08:25:44 +08:00
|
|
|
NodeChildrenMainScene* scene = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// case 0:
|
2013-07-23 08:25:44 +08:00
|
|
|
// scene = new IterateSpriteSheetFastEnum();
|
2012-04-19 14:35:52 +08:00
|
|
|
// break;
|
|
|
|
case 0:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new IterateSpriteSheetCArray();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new AddSpriteSheet();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new RemoveSpriteSheet();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new ReorderSpriteSheet();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
s_nCurCase = _curCase;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
if (scene)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->initWithQuantityOfNodes(nNodes);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// NodeChildrenMainScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
|
|
|
|
{
|
|
|
|
//srand(time());
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Title
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create(title().c_str(), "Arial", 40);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition(Point(s.width/2, s.height-32));
|
2013-07-05 16:49:22 +08:00
|
|
|
label->setColor(Color3B(255,255,40));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Subtitle
|
|
|
|
std::string strSubTitle = subtitle();
|
|
|
|
if(strSubTitle.length())
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(l, 1);
|
2013-07-12 14:11:55 +08:00
|
|
|
l->setPosition(Point(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);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto decrease = MenuItemFont::create(" - ", [&](Object *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityOfNodes -= kNodesIncrease;
|
|
|
|
if( quantityOfNodes < 0 )
|
|
|
|
quantityOfNodes = 0;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
updateQuantityOfNodes();
|
|
|
|
});
|
2013-07-05 16:49:22 +08:00
|
|
|
decrease->setColor(Color3B(0,200,20));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto increase = MenuItemFont::create(" + ", [&](Object *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityOfNodes += kNodesIncrease;
|
|
|
|
if( quantityOfNodes > kMaxNodes )
|
|
|
|
quantityOfNodes = kMaxNodes;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
updateQuantityOfNodes();
|
|
|
|
});
|
2013-07-05 16:49:22 +08:00
|
|
|
increase->setColor(Color3B(0,200,20));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(decrease, increase, NULL);
|
2011-03-25 13:59:08 +08:00
|
|
|
menu->alignItemsHorizontally();
|
2013-07-12 14:11:55 +08:00
|
|
|
menu->setPosition(Point(s.width/2, s.height/2+15));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(menu, 1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30);
|
2013-07-05 16:49:22 +08:00
|
|
|
infoLabel->setColor(Color3B(0,200,20));
|
2013-07-12 14:11:55 +08:00
|
|
|
infoLabel->setPosition(Point(s.width/2, s.height/2-15));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menuLayer = new NodeChildrenMenuLayer(true, TEST_COUNT, s_nCurCase);
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(menuLayer);
|
|
|
|
menuLayer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
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-08-16 16:05:27 +08:00
|
|
|
auto 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-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// increase nodes
|
|
|
|
if( currentQuantityOfNodes < quantityOfNodes )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (quantityOfNodes-currentQuantityOfNodes); i++)
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0, 0, 32, 32));
|
2012-04-19 14:35:52 +08:00
|
|
|
batchNode->addChild(sprite);
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point( CCRANDOM_0_1()*s.width, CCRANDOM_0_1()*s.height));
|
2012-04-19 14:35:52 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-16 16:05:27 +08:00
|
|
|
auto pChildren = batchNode->getChildren();
|
2013-06-20 14:17:10 +08:00
|
|
|
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-08-16 16:05:27 +08:00
|
|
|
auto sprite = static_cast<Sprite*>(pObject);
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->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-08-16 16:05:27 +08:00
|
|
|
auto pChildren = batchNode->getChildren();
|
2013-06-20 14:17:10 +08:00
|
|
|
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-08-16 16:05:27 +08:00
|
|
|
auto sprite = static_cast<Sprite*>(pObject);
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->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-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// increase nodes
|
|
|
|
if( currentQuantityOfNodes < quantityOfNodes )
|
|
|
|
{
|
|
|
|
for (int i=0; i < (quantityOfNodes-currentQuantityOfNodes); i++)
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0, 0, 32, 32));
|
2011-03-25 13:59:08 +08:00
|
|
|
batchNode->addChild(sprite);
|
2013-07-12 14:11:55 +08:00
|
|
|
sprite->setPosition(Point( 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-08-16 16:05:27 +08:00
|
|
|
auto sprites = Array::createWithCapacity(totalToAdd);
|
2013-07-24 06:20:22 +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-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprites->addObject(sprite);
|
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-08-16 16:05:27 +08:00
|
|
|
auto 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-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprites->addObject(sprite);
|
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-08-16 16:05:27 +08:00
|
|
|
auto sprites = Array::createWithCapacity(totalToAdd);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Don't include the sprite creation time as part of the profiling
|
2013-07-24 06:20:22 +08:00
|
|
|
for(int i=0; i<totalToAdd; i++)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprites->addObject(sprite);
|
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-08-16 16:05:27 +08:00
|
|
|
auto node = (Node*) (batchNode->getChildren()->objectAtIndex(i));
|
2013-07-23 08:25:44 +08:00
|
|
|
batchNode->reorderChild(node, 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()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
IterateSpriteSheet* scene = new IterateSpriteSheetCArray();
|
|
|
|
scene->initWithQuantityOfNodes(kNodesIncrease);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|