2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceNodeChildrenTest.h"
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
// Enable profiles for this file
|
|
|
|
#undef CC_PROFILER_DISPLAY_TIMERS
|
|
|
|
#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()
|
|
|
|
#undef CC_PROFILER_PURGE_ALL
|
|
|
|
#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()
|
|
|
|
|
|
|
|
#undef CC_PROFILER_START
|
|
|
|
#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)
|
|
|
|
#undef CC_PROFILER_STOP
|
|
|
|
#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)
|
|
|
|
#undef CC_PROFILER_RESET
|
|
|
|
#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)
|
|
|
|
|
|
|
|
#undef CC_PROFILER_START_CATEGORY
|
|
|
|
#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0)
|
|
|
|
#undef CC_PROFILER_STOP_CATEGORY
|
|
|
|
#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0)
|
|
|
|
#undef CC_PROFILER_RESET_CATEGORY
|
|
|
|
#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0)
|
|
|
|
|
|
|
|
#undef CC_PROFILER_START_INSTANCE
|
|
|
|
#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
|
|
|
|
#undef CC_PROFILER_STOP_INSTANCE
|
|
|
|
#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
|
|
|
|
#undef CC_PROFILER_RESET_INSTANCE
|
|
|
|
#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
|
|
|
|
|
|
|
|
static std::function<NodeChildrenMainScene*()> createFunctions[] =
|
|
|
|
{
|
|
|
|
CL(IterateSpriteSheetForLoop),
|
|
|
|
CL(IterateSpriteSheetCArray),
|
|
|
|
CL(IterateSpriteSheetIterator),
|
|
|
|
|
|
|
|
CL(AddSpriteSheet),
|
|
|
|
CL(RemoveSpriteSheet),
|
|
|
|
CL(ReorderSpriteSheet),
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
enum {
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
|
|
|
|
kTagBase = 20000,
|
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
|
|
|
};
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
static int g_curCase = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// NodeChildrenMenuLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
NodeChildrenMenuLayer::NodeChildrenMenuLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
|
|
|
|
: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
|
|
|
|
{
|
2013-08-21 05:18:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeChildrenMenuLayer::onExitTransitionDidStart()
|
|
|
|
{
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto sched = director->getScheduler();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
sched->unscheduleSelector(SEL_SCHEDULE(&NodeChildrenMenuLayer::dumpProfilerInfo), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeChildrenMenuLayer::onEnterTransitionDidFinish()
|
|
|
|
{
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto sched = director->getScheduler();
|
|
|
|
|
|
|
|
CC_PROFILER_PURGE_ALL();
|
|
|
|
sched->scheduleSelector(SEL_SCHEDULE(&NodeChildrenMenuLayer::dumpProfilerInfo), this, 2, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NodeChildrenMenuLayer::dumpProfilerInfo(float dt)
|
|
|
|
{
|
|
|
|
CC_PROFILER_DISPLAY_TIMERS();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeChildrenMenuLayer::showCurrentTest()
|
|
|
|
{
|
2013-08-21 05:18:32 +08:00
|
|
|
int nodes = ((NodeChildrenMainScene*)getParent())->getQuantityOfNodes();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
auto scene = createFunctions[_curCase]();
|
|
|
|
|
|
|
|
g_curCase = _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-08-21 05:18:32 +08:00
|
|
|
scene->initWithQuantityOfNodes(nodes);
|
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-21 05:18:32 +08:00
|
|
|
auto menuLayer = new NodeChildrenMenuLayer(true, MAX_LAYER, g_curCase);
|
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-21 05:18:32 +08:00
|
|
|
auto infoLabel = static_cast<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-08-21 05:18:32 +08:00
|
|
|
sprite->setVisible(false);
|
|
|
|
sprite->setPosition(Point(-1000,-1000));
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-08-21 05:18:32 +08:00
|
|
|
// IterateSpriteSheetForLoop
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-08-21 05:18:32 +08:00
|
|
|
void IterateSpriteSheetForLoop::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-21 05:18:32 +08:00
|
|
|
auto children = batchNode->getChildren();
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
CC_PROFILER_START(this->profilerName());
|
2011-04-25 14:30:30 +08:00
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
for( const auto &object : *children )
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-21 07:06:51 +08:00
|
|
|
auto o = static_cast<Object*>(object);
|
|
|
|
auto sprite = static_cast<Sprite*>(o);
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setVisible(false);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
std::string IterateSpriteSheetForLoop::title()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "A - Iterate SpriteSheet";
|
|
|
|
}
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
std::string IterateSpriteSheetForLoop::subtitle()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-21 05:18:32 +08:00
|
|
|
return "Iterate children using C++11 range-based for loop. See console";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
const char* IterateSpriteSheetForLoop::profilerName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-21 05:18:32 +08:00
|
|
|
return "Iterator: C++11 for loop";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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-21 05:18:32 +08:00
|
|
|
auto children = batchNode->getChildren();
|
|
|
|
Object* object = 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
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
CCARRAY_FOREACH(children, object)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-21 05:18:32 +08:00
|
|
|
auto sprite = static_cast<Sprite*>(object);
|
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
|
|
|
{
|
2013-08-21 05:18:32 +08:00
|
|
|
return "Iterator: CC_ARRAY_FOREACH";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IterateSpriteSheetIterator
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void IterateSpriteSheetIterator::update(float dt)
|
|
|
|
{
|
|
|
|
// iterate using fast enumeration protocol
|
|
|
|
auto children = batchNode->getChildren();
|
|
|
|
|
|
|
|
CC_PROFILER_START(this->profilerName());
|
|
|
|
|
|
|
|
for( auto it=std::begin(*children); it != std::end(*children); ++it)
|
|
|
|
{
|
2013-08-21 07:06:51 +08:00
|
|
|
auto obj = static_cast<Object*>(*it);
|
|
|
|
auto sprite = static_cast<Sprite*>(obj);
|
2013-08-21 05:18:32 +08:00
|
|
|
sprite->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string IterateSpriteSheetIterator::title()
|
|
|
|
{
|
|
|
|
return "C - Iterate SpriteSheet";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string IterateSpriteSheetIterator::subtitle()
|
|
|
|
{
|
|
|
|
return "Iterate children using begin() / end(). See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* IterateSpriteSheetIterator::profilerName()
|
|
|
|
{
|
|
|
|
return "Iterator: begin(), end()";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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()
|
|
|
|
{
|
2013-08-21 09:05:35 +08:00
|
|
|
return "D - Add to spritesheet";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2013-08-21 09:05:35 +08:00
|
|
|
return "E - Del from spritesheet";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2013-08-21 09:05:35 +08:00
|
|
|
return "F - Reorder from spritesheet";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-21 05:18:32 +08:00
|
|
|
auto scene = createFunctions[g_curCase]();
|
2013-07-23 08:25:44 +08:00
|
|
|
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
|
|
|
}
|