2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceNodeChildrenTest.h"
|
|
|
|
|
2013-08-23 10:30:20 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
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(IterateSpriteSheetIterator),
|
2013-12-19 11:28:09 +08:00
|
|
|
CL(IterateSpriteSheetForEach),
|
2013-08-21 05:18:32 +08:00
|
|
|
|
2013-08-23 09:21:52 +08:00
|
|
|
CL(CallFuncsSpriteSheetForEach),
|
|
|
|
|
2013-09-01 08:08:51 +08:00
|
|
|
CL(AddSprite),
|
2013-08-21 05:18:32 +08:00
|
|
|
CL(AddSpriteSheet),
|
2013-08-25 01:56:07 +08:00
|
|
|
CL(GetSpriteSheet),
|
2013-09-01 08:08:51 +08:00
|
|
|
CL(RemoveSprite),
|
2013-08-21 05:18:32 +08:00
|
|
|
CL(RemoveSpriteSheet),
|
|
|
|
CL(ReorderSpriteSheet),
|
2013-08-24 04:14:57 +08:00
|
|
|
CL(SortAllChildrenSpriteSheet),
|
2013-08-29 03:39:57 +08:00
|
|
|
|
|
|
|
CL(VisitSceneGraph),
|
2013-08-21 05:18:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#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);
|
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
|
2014-02-10 11:42:15 +08:00
|
|
|
auto label = LabelTTF::create(title().c_str(), "Arial", 32);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
2014-02-10 11:42:15 +08:00
|
|
|
label->setPosition(Point(s.width/2, s.height-50));
|
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);
|
2014-02-20 10:53:49 +08:00
|
|
|
auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityOfNodes -= kNodesIncrease;
|
|
|
|
if( quantityOfNodes < 0 )
|
|
|
|
quantityOfNodes = 0;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
updateQuantityOfNodes();
|
2013-08-29 09:32:45 +08:00
|
|
|
updateProfilerName();
|
2013-08-22 11:02:50 +08:00
|
|
|
CC_PROFILER_PURGE_ALL();
|
2013-09-06 12:51:37 +08:00
|
|
|
srand(0);
|
2013-06-08 08:21:11 +08:00
|
|
|
});
|
2013-07-05 16:49:22 +08:00
|
|
|
decrease->setColor(Color3B(0,200,20));
|
2014-02-20 10:53:49 +08:00
|
|
|
auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
|
2013-06-08 08:21:11 +08:00
|
|
|
quantityOfNodes += kNodesIncrease;
|
|
|
|
if( quantityOfNodes > kMaxNodes )
|
|
|
|
quantityOfNodes = kMaxNodes;
|
|
|
|
|
|
|
|
updateQuantityLabel();
|
|
|
|
updateQuantityOfNodes();
|
2013-08-29 09:32:45 +08:00
|
|
|
updateProfilerName();
|
2013-08-22 11:02:50 +08:00
|
|
|
CC_PROFILER_PURGE_ALL();
|
2013-09-06 12:51:37 +08:00
|
|
|
srand(0);
|
2013-06-08 08:21:11 +08:00
|
|
|
});
|
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();
|
2013-08-29 09:32:45 +08:00
|
|
|
updateProfilerName();
|
2013-09-06 12:51:37 +08:00
|
|
|
srand(0);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NodeChildrenMainScene::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NodeChildrenMainScene::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char * NodeChildrenMainScene::profilerName()
|
|
|
|
{
|
|
|
|
return _profilerName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeChildrenMainScene::updateProfilerName()
|
|
|
|
{
|
|
|
|
snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), 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()
|
|
|
|
{
|
|
|
|
// 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-08-29 09:32:45 +08:00
|
|
|
const char* IterateSpriteSheet::testName()
|
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-12-18 16:03:07 +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-11-29 10:37:40 +08:00
|
|
|
for( const auto &object : children )
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
auto o = static_cast<Ref*>(object);
|
2013-08-21 07:06:51 +08:00
|
|
|
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-12-19 05:52:10 +08:00
|
|
|
std::string IterateSpriteSheetForLoop::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Iterate SpriteSheet";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string IterateSpriteSheetForLoop::subtitle() const
|
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-29 09:32:45 +08:00
|
|
|
const char* IterateSpriteSheetForLoop::testName()
|
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
|
|
|
}
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-12-19 11:28:09 +08:00
|
|
|
// IterateSpriteSheetIterator
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-12-19 11:28:09 +08:00
|
|
|
void IterateSpriteSheetIterator::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-12-18 16:03:07 +08:00
|
|
|
auto& children = batchNode->getChildren();
|
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-12-19 11:28:09 +08:00
|
|
|
for( auto it=std::begin(children); it != std::end(children); ++it)
|
|
|
|
{
|
|
|
|
auto sprite = static_cast<Sprite*>(*it);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
std::string IterateSpriteSheetIterator::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Iterate SpriteSheet";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
std::string IterateSpriteSheetIterator::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 11:28:09 +08:00
|
|
|
return "Iterate children using begin() / end(). See console";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
const char* IterateSpriteSheetIterator::testName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-19 11:28:09 +08:00
|
|
|
return "Iterator: begin(), end()";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 05:18:32 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-12-19 11:28:09 +08:00
|
|
|
// IterateSpriteSheetForEach
|
2013-08-21 05:18:32 +08:00
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-12-19 11:28:09 +08:00
|
|
|
void IterateSpriteSheetForEach::update(float dt)
|
2013-08-21 05:18:32 +08:00
|
|
|
{
|
|
|
|
// iterate using fast enumeration protocol
|
2013-12-18 16:03:07 +08:00
|
|
|
auto& children = batchNode->getChildren();
|
2013-08-21 05:18:32 +08:00
|
|
|
|
|
|
|
CC_PROFILER_START(this->profilerName());
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
std::for_each(std::begin(children), std::end(children), [](Node *child) {
|
|
|
|
auto sprite = static_cast<Sprite*>(child);
|
2013-08-21 05:18:32 +08:00
|
|
|
sprite->setVisible(false);
|
2013-12-19 11:28:09 +08:00
|
|
|
});
|
2013-08-21 05:18:32 +08:00
|
|
|
|
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
std::string IterateSpriteSheetForEach::title() const
|
2013-08-21 05:18:32 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Iterate SpriteSheet";
|
2013-08-21 05:18:32 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
std::string IterateSpriteSheetForEach::subtitle() const
|
2013-08-21 05:18:32 +08:00
|
|
|
{
|
2013-12-19 11:28:09 +08:00
|
|
|
return "Iterate children using std::for_each(). See console";
|
2013-08-21 05:18:32 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
const char* IterateSpriteSheetForEach::testName()
|
2013-08-21 05:18:32 +08:00
|
|
|
{
|
2013-12-19 11:28:09 +08:00
|
|
|
return "Iterator: std::for_each()";
|
2013-08-21 05:18:32 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 11:28:09 +08:00
|
|
|
|
2013-08-23 09:21:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CallFuncsSpriteSheetForEach
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void CallFuncsSpriteSheetForEach::update(float dt)
|
|
|
|
{
|
|
|
|
// iterate using fast enumeration protocol
|
2013-11-29 10:37:40 +08:00
|
|
|
auto& children = batchNode->getChildren();
|
2013-08-23 09:21:52 +08:00
|
|
|
|
|
|
|
CC_PROFILER_START(this->profilerName());
|
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
std::for_each(std::begin(children), std::end(children), [](Node* obj) {
|
|
|
|
obj->getPosition();
|
2013-08-23 09:21:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string CallFuncsSpriteSheetForEach::title() const
|
2013-08-23 09:21:52 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "'map' functional call";
|
2013-08-23 09:21:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string CallFuncsSpriteSheetForEach::subtitle() const
|
2013-08-23 09:21:52 +08:00
|
|
|
{
|
|
|
|
return "Using 'std::for_each()'. See console";
|
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* CallFuncsSpriteSheetForEach::testName()
|
2013-08-23 09:21:52 +08:00
|
|
|
{
|
2013-08-29 09:32:45 +08:00
|
|
|
return "Map: std::for_each";
|
2013-08-23 09:21:52 +08:00
|
|
|
}
|
|
|
|
|
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-08-29 09:32:45 +08:00
|
|
|
const char* AddRemoveSpriteSheet::testName()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
|
2013-09-01 08:08:51 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// AddSprite
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void AddSprite::update(float dt)
|
|
|
|
{
|
|
|
|
// reset seed
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
// 100 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
|
|
|
Sprite **sprites = new Sprite*[totalToAdd];
|
|
|
|
int *zs = new int[totalToAdd];
|
|
|
|
|
|
|
|
// Don't include the sprite creation time and random as part of the profiling
|
|
|
|
for(int i=0; i<totalToAdd; i++)
|
|
|
|
{
|
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
|
|
|
zs[i] = CCRANDOM_MINUS1_1() * 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
CC_PROFILER_START( this->profilerName() );
|
|
|
|
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
|
|
|
this->addChild( sprites[i], zs[i], kTagBase+i);
|
|
|
|
}
|
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
|
|
|
|
|
|
|
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
|
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
this->removeChild( sprites[i], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] sprites;
|
|
|
|
delete [] zs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string AddSprite::title() const
|
2013-09-01 08:08:51 +08:00
|
|
|
{
|
|
|
|
return "Node::addChild()";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string AddSprite::subtitle() const
|
2013-09-01 08:08:51 +08:00
|
|
|
{
|
|
|
|
return "Adds sprites with random z. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* AddSprite::testName()
|
|
|
|
{
|
|
|
|
return "Node::addChild()";
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
2013-08-31 22:27:56 +08:00
|
|
|
// 100 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
Sprite **sprites = new Sprite*[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-25 01:56:07 +08:00
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2013-08-31 22:27:56 +08:00
|
|
|
zs[i] = CCRANDOM_MINUS1_1() * 50;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08-25 01:56:07 +08:00
|
|
|
batchNode->addChild( sprites[i], zs[i], kTagBase+i);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-08-31 21:59:44 +08:00
|
|
|
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->removeChild( sprites[i], true);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-08-25 01:56:07 +08:00
|
|
|
delete [] sprites;
|
2011-03-25 13:59:08 +08:00
|
|
|
delete [] zs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string AddSpriteSheet::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::addChild()";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string AddSpriteSheet::subtitle() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Adds sprites with random z. See console";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* AddSpriteSheet::testName()
|
2011-04-25 14:30:30 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::addChild()";
|
2011-04-25 14:30:30 +08:00
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-08-25 01:56:07 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GetSpriteSheet
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void GetSpriteSheet::update(float dt)
|
|
|
|
{
|
|
|
|
// reset seed
|
|
|
|
//srandom(0);
|
|
|
|
|
2013-08-31 22:27:56 +08:00
|
|
|
// 100% percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
2013-08-25 01:56:07 +08:00
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
|
|
|
Sprite **sprites = new Sprite*[totalToAdd];
|
|
|
|
int *zs = new int[totalToAdd];
|
|
|
|
|
|
|
|
// Don't include the sprite creation time and random as part of the profiling
|
|
|
|
for(int i=0; i<totalToAdd; i++)
|
|
|
|
{
|
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
|
|
|
zs[i] = CCRANDOM_MINUS1_1() * 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
|
|
|
batchNode->addChild( sprites[i], zs[i], kTagBase+i);
|
|
|
|
}
|
|
|
|
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
|
|
|
|
CC_PROFILER_START( this->profilerName() );
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
|
|
|
batchNode->getChildByTag(kTagBase+1);
|
|
|
|
}
|
|
|
|
CC_PROFILER_STOP(this->profilerName());
|
|
|
|
|
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
batchNode->removeChild( sprites[i], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] sprites;
|
|
|
|
delete [] zs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string GetSpriteSheet::title() const
|
2013-08-25 01:56:07 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "getChildByTag from spritesheet";
|
2013-08-25 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string GetSpriteSheet::subtitle() const
|
2013-08-25 01:56:07 +08:00
|
|
|
{
|
|
|
|
return "Get sprites using getChildByTag(). See console";
|
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* GetSpriteSheet::testName()
|
2013-08-25 01:56:07 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::getChildByTag()";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// RemoveSprite
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void RemoveSprite::update(float dt)
|
|
|
|
{
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
// 100 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
|
|
|
Sprite **sprites = new Sprite*[totalToAdd];
|
|
|
|
|
|
|
|
// Don't include the sprite creation time as part of the profiling
|
|
|
|
for(int i=0;i<totalToAdd;i++)
|
|
|
|
{
|
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
|
|
|
this->addChild( sprites[i], CCRANDOM_MINUS1_1() * 50, kTagBase+i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove them
|
|
|
|
CC_PROFILER_START( this->profilerName() );
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
this->removeChild( sprites[i], true);
|
|
|
|
}
|
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
|
|
|
|
|
|
|
delete [] sprites;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RemoveSprite::title() const
|
2013-09-01 08:08:51 +08:00
|
|
|
{
|
|
|
|
return "Node::removeChild()";
|
2013-08-25 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RemoveSprite::subtitle() const
|
2013-09-01 08:08:51 +08:00
|
|
|
{
|
|
|
|
return "Remove sprites. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* RemoveSprite::testName()
|
|
|
|
{
|
|
|
|
return "Node::removeChild()";
|
|
|
|
}
|
2013-08-25 01:56:07 +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);
|
|
|
|
|
2013-08-31 22:27:56 +08:00
|
|
|
// 100 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
Sprite **sprites = new Sprite*[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-25 01:56:07 +08:00
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->addChild( sprites[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-03-25 13:59:08 +08:00
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->removeChild( sprites[i], true);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
2013-08-25 01:56:07 +08:00
|
|
|
|
|
|
|
delete [] sprites;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RemoveSpriteSheet::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::removeChild()";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RemoveSpriteSheet::subtitle() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Remove sprites. See console";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* RemoveSpriteSheet::testName()
|
2011-04-25 14:30:30 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::removeChild()";
|
2011-04-25 14:30:30 +08:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2013-08-31 22:27:56 +08:00
|
|
|
// 100 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
Sprite **sprites = new Sprite*[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-25 01:56:07 +08:00
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->addChild( sprites[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-03-25 13:59:08 +08:00
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->reorderChild(sprites[i], CCRANDOM_MINUS1_1() * 50);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-03-25 11:47:27 +08:00
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->removeChild( sprites[i], true);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-08-25 01:56:07 +08:00
|
|
|
|
|
|
|
delete [] sprites;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ReorderSpriteSheet::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::reorderChild()";
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ReorderSpriteSheet::subtitle() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Reorder sprites. See console";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* ReorderSpriteSheet::testName()
|
2011-04-25 14:30:30 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::reorderChild()";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-24 04:14:57 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SortAllChildrenSpriteSheet
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void SortAllChildrenSpriteSheet::update(float dt)
|
|
|
|
{
|
|
|
|
//srandom(0);
|
|
|
|
|
2013-08-31 22:27:56 +08:00
|
|
|
// 100 percent
|
|
|
|
int totalToAdd = currentQuantityOfNodes * 1;
|
2013-08-24 04:14:57 +08:00
|
|
|
|
|
|
|
if( totalToAdd > 0 )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
Sprite **sprites = new Sprite*[totalToAdd];
|
2013-08-24 04:14:57 +08:00
|
|
|
|
|
|
|
// Don't include the sprite's creation time as part of the profiling
|
|
|
|
for(int i=0; i<totalToAdd; i++)
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
|
2013-08-24 04:14:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add them with random Z (very important!)
|
|
|
|
for( int i=0; i < totalToAdd;i++ )
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->addChild( sprites[i], CCRANDOM_MINUS1_1() * 50, kTagBase+i);
|
2013-08-24 04:14:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
|
|
|
|
// reorder them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
2013-08-25 01:56:07 +08:00
|
|
|
batchNode->reorderChild(sprites[i], CCRANDOM_MINUS1_1() * 50);
|
2013-08-24 04:14:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CC_PROFILER_START( this->profilerName() );
|
|
|
|
batchNode->sortAllChildren();
|
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
|
|
|
|
2013-08-25 01:56:07 +08:00
|
|
|
// remove them
|
|
|
|
for( int i=0;i < totalToAdd;i++)
|
|
|
|
{
|
|
|
|
batchNode->removeChild( sprites[i], true);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] sprites;
|
2013-08-24 04:14:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SortAllChildrenSpriteSheet::title() const
|
2013-08-24 04:14:57 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::sortAllChildren()";
|
2013-08-24 04:14:57 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SortAllChildrenSpriteSheet::subtitle() const
|
2013-08-24 04:14:57 +08:00
|
|
|
{
|
|
|
|
return "Calls sortOfChildren(). See console";
|
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* SortAllChildrenSpriteSheet::testName()
|
2013-08-24 04:14:57 +08:00
|
|
|
{
|
2013-09-01 08:08:51 +08:00
|
|
|
return "SpriteBatchNode::sortAllChildren()";
|
2013-08-24 04:14:57 +08:00
|
|
|
}
|
|
|
|
|
2013-08-29 03:39:57 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// VisitSceneGraph
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void VisitSceneGraph::initWithQuantityOfNodes(unsigned int nodes)
|
|
|
|
{
|
|
|
|
NodeChildrenMainScene::initWithQuantityOfNodes(nodes);
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisitSceneGraph::updateQuantityOfNodes()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
// increase nodes
|
|
|
|
if( currentQuantityOfNodes < quantityOfNodes )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (quantityOfNodes-currentQuantityOfNodes); i++)
|
|
|
|
{
|
2013-08-29 09:32:45 +08:00
|
|
|
auto node = Node::create();
|
|
|
|
this->addChild(node);
|
|
|
|
node->setVisible(true);
|
|
|
|
node->setPosition(Point(-1000,-1000));
|
|
|
|
node->setTag(1000 + currentQuantityOfNodes + i );
|
2013-08-29 03:39:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// decrease nodes
|
|
|
|
else if ( currentQuantityOfNodes > quantityOfNodes )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (currentQuantityOfNodes-quantityOfNodes); i++)
|
|
|
|
{
|
|
|
|
this->removeChildByTag(1000 + currentQuantityOfNodes - i -1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentQuantityOfNodes = quantityOfNodes;
|
|
|
|
}
|
|
|
|
void VisitSceneGraph::update(float dt)
|
|
|
|
{
|
|
|
|
CC_PROFILER_START( this->profilerName() );
|
|
|
|
this->visit();
|
|
|
|
CC_PROFILER_STOP( this->profilerName() );
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string VisitSceneGraph::title() const
|
2013-08-29 03:39:57 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "Performance of visiting the scene graph";
|
2013-08-29 03:39:57 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string VisitSceneGraph::subtitle() const
|
2013-08-29 03:39:57 +08:00
|
|
|
{
|
|
|
|
return "calls visit() on scene graph. See console";
|
|
|
|
}
|
|
|
|
|
2013-08-29 09:32:45 +08:00
|
|
|
const char* VisitSceneGraph::testName()
|
2013-08-29 03:39:57 +08:00
|
|
|
{
|
2013-08-31 22:27:56 +08:00
|
|
|
return "visit()";
|
2013-08-29 03:39:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///----------------------------------------
|
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);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|