Adds "Sort all Children" perf test

Adds a new perf tests: "sortAllChildren"

Signed-off-by: Ricardo Quesada <ricardoquesada@gmail.com>
This commit is contained in:
Ricardo Quesada 2013-08-23 13:14:57 -07:00
parent daa0095989
commit 364288cf66
3 changed files with 82 additions and 10 deletions

View File

@ -42,12 +42,6 @@ Array::Array()
init();
}
Array::Array(unsigned int capacity)
: data(NULL)
{
initWithCapacity(capacity);
}
Array* Array::create()
{
Array* array = new Array();
@ -132,7 +126,7 @@ Array* Array::createWithContentsOfFile(const char* fileName)
Array* ret = Array::createWithContentsOfFileThreadSafe(fileName);
if (ret != nullptr)
{
pRet->autorelease();
ret->autorelease();
}
return ret;
}

View File

@ -41,6 +41,7 @@ static std::function<NodeChildrenMainScene*()> createFunctions[] =
CL(AddSpriteSheet),
CL(RemoveSpriteSheet),
CL(ReorderSpriteSheet),
CL(SortAllChildrenSpriteSheet),
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
@ -381,9 +382,15 @@ void CallFuncsSpriteSheetForEach::update(float dt)
CC_PROFILER_START(this->profilerName());
#if CC_USE_ARRAY_VECTOR
std::for_each(std::begin(*children), std::end(*children), [](const RCPtr<Object>& obj) {
static_cast<Node*>( static_cast<Object*>(obj) )->getPosition();
});
#else
std::for_each(std::begin(*children), std::end(*children), [](Object* obj) {
static_cast<Node*>(obj)->getPosition();
});
#endif
CC_PROFILER_STOP(this->profilerName());
}
@ -544,7 +551,7 @@ void AddSpriteSheet::update(float dt)
std::string AddSpriteSheet::title()
{
return "D - Add to spritesheet";
return "F - Add to spritesheet";
}
std::string AddSpriteSheet::subtitle()
@ -600,7 +607,7 @@ void RemoveSpriteSheet::update(float dt)
std::string RemoveSpriteSheet::title()
{
return "E - Del from spritesheet";
return "G - Del from spritesheet";
}
std::string RemoveSpriteSheet::subtitle()
@ -666,7 +673,7 @@ void ReorderSpriteSheet::update(float dt)
std::string ReorderSpriteSheet::title()
{
return "F - Reorder from spritesheet";
return "H - Reorder from spritesheet";
}
std::string ReorderSpriteSheet::subtitle()
@ -679,6 +686,67 @@ const char* ReorderSpriteSheet::profilerName()
return "reorder sprites";
}
////////////////////////////////////////////////////////
//
// SortAllChildrenSpriteSheet
//
////////////////////////////////////////////////////////
void SortAllChildrenSpriteSheet::update(float dt)
{
//srandom(0);
// 15 percent
int totalToAdd = currentQuantityOfNodes * 0.15f;
if( totalToAdd > 0 )
{
auto sprites = Array::createWithCapacity(totalToAdd);
// Don't include the sprite's creation time as part of the profiling
for(int i=0; i<totalToAdd; i++)
{
auto sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32));
sprites->addObject(sprite);
}
// add them with random Z (very important!)
for( int i=0; i < totalToAdd;i++ )
{
batchNode->addChild((Node*) (sprites->getObjectAtIndex(i)), CCRANDOM_MINUS1_1() * 50, kTagBase+i);
}
batchNode->sortAllChildren();
// reorder them
for( int i=0;i < totalToAdd;i++)
{
auto node = (Node*) (batchNode->getChildren()->getObjectAtIndex(i));
batchNode->reorderChild(node, CCRANDOM_MINUS1_1() * 50);
}
CC_PROFILER_START( this->profilerName() );
batchNode->sortAllChildren();
CC_PROFILER_STOP( this->profilerName() );
batchNode->removeAllChildrenWithCleanup(true);
}
}
std::string SortAllChildrenSpriteSheet::title()
{
return "H - Sort All Children from spritesheet";
}
std::string SortAllChildrenSpriteSheet::subtitle()
{
return "Calls sortOfChildren(). See console";
}
const char* SortAllChildrenSpriteSheet::profilerName()
{
return "sort all children";
}
void runNodeChildrenTest()
{
auto scene = createFunctions[g_curCase]();

View File

@ -148,6 +148,16 @@ public:
virtual const char* profilerName();
};
class SortAllChildrenSpriteSheet : public AddRemoveSpriteSheet
{
public:
virtual void update(float dt);
virtual std::string title();
virtual std::string subtitle();
virtual const char* profilerName();
};
void runNodeChildrenTest();
#endif // __PERFORMANCE_NODE_CHILDREN_TEST_H__