Add Sprite tests.

This commit is contained in:
zhangbin 2015-09-06 16:35:13 +08:00
parent cc2dd7b225
commit bd47385bbd
86 changed files with 986 additions and 1 deletions

View File

@ -1032,6 +1032,8 @@
FADE78871B96C4780061590D /* PerformanceParticle3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE78841B96C4780061590D /* PerformanceParticle3DTest.cpp */; };
FADE78891B96C51C0061590D /* Particle3D in Resources */ = {isa = PBXBuildFile; fileRef = FADE78881B96C51C0061590D /* Particle3D */; };
FADE788A1B96C51C0061590D /* Particle3D in Resources */ = {isa = PBXBuildFile; fileRef = FADE78881B96C51C0061590D /* Particle3D */; };
FADE788D1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */; };
FADE788E1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -2164,6 +2166,8 @@
FADE78841B96C4780061590D /* PerformanceParticle3DTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceParticle3DTest.cpp; sourceTree = "<group>"; };
FADE78851B96C4780061590D /* PerformanceParticle3DTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceParticle3DTest.h; sourceTree = "<group>"; };
FADE78881B96C51C0061590D /* Particle3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Particle3D; path = "../tests/performance-tests/Resources/Particle3D"; sourceTree = "<group>"; };
FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceSpriteTest.cpp; sourceTree = "<group>"; };
FADE788C1B96D0710061590D /* PerformanceSpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceSpriteTest.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -4779,6 +4783,8 @@
FADE78721B9572990061590D /* PerformanceParticleTest.h */,
FADE78841B96C4780061590D /* PerformanceParticle3DTest.cpp */,
FADE78851B96C4780061590D /* PerformanceParticle3DTest.h */,
FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */,
FADE788C1B96D0710061590D /* PerformanceSpriteTest.h */,
);
path = tests;
sourceTree = "<group>";
@ -6255,6 +6261,7 @@
buildActionMask = 2147483647;
files = (
FA94B2451B90497E0074B261 /* controller.cpp in Sources */,
FADE788E1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */,
FA94B2431B90497E0074B261 /* BaseTest.cpp in Sources */,
FA94B23B1B9045160074B261 /* PerformanceAllocTest.cpp in Sources */,
FADE78741B9572990061590D /* PerformanceParticleTest.cpp in Sources */,
@ -6277,6 +6284,7 @@
FADE78861B96C4780061590D /* PerformanceParticle3DTest.cpp in Sources */,
FADE786F1B9451540061590D /* PerformanceNodeChildrenTest.cpp in Sources */,
FA94B2351B8F02880074B261 /* Profile.cpp in Sources */,
FADE788D1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */,
FA94B1CE1B8EF7BB0074B261 /* AppDelegate.cpp in Sources */,
FA94B24B1B9059540074B261 /* VisibleRect.cpp in Sources */,
FA94B20A1B8EF8430074B261 /* main.cpp in Sources */,

View File

@ -101,7 +101,7 @@ void Particle3DMainScene::onEnterTransitionDidFinish()
Scene::onEnterTransitionDidFinish();
if (this->isAutoTesting()) {
Profile::getInstance()->testCaseBegin("ParticleTest",
Profile::getInstance()->testCaseBegin("Particle3DTest",
genStrVector("ParticleSystemCount", nullptr),
genStrVector("Avg", "Min", "Max", nullptr));
autoTestIndex = 0;

View File

@ -0,0 +1,811 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "PerformanceSpriteTest.h"
#include "Profile.h"
#include <cmath>
USING_NS_CC;
#if defined(_MSC_VER) && _MSC_VER<1800
#define CC_ROUND(__f__) __f__
#else
#define CC_ROUND(__f__) roundf(__f__)
#endif
#define MAX_SUB_TEST_NUM 13
#define DELAY_TIME 2
#define STAT_TIME 3
enum {
kMaxNodes = 50000,
kNodesIncrease = 250,
};
enum {
kTagInfoLayer = 1,
kTagMainLayer = 2,
kTagTitle = 3,
kTagMenuLayer = (kMaxNodes + 1000),
};
PerformceSpriteTests::PerformceSpriteTests()
{
ADD_TEST_CASE(SpritePerformTestA);
ADD_TEST_CASE(SpritePerformTestB);
ADD_TEST_CASE(SpritePerformTestC);
ADD_TEST_CASE(SpritePerformTestD);
ADD_TEST_CASE(SpritePerformTestE);
ADD_TEST_CASE(SpritePerformTestF);
ADD_TEST_CASE(SpritePerformTestG);
}
int SpriteMainScene::_quantityNodes = 50;
int SpriteMainScene::_subtestNumber = 1;
static int autoTestSpriteCounts[] = {
1000, 2000, 3000
};
////////////////////////////////////////////////////////
//
// SubTest
//
////////////////////////////////////////////////////////
SubTest::~SubTest()
{
_parentNode->release();
}
void SubTest::initWithSubTest(int subtest, Node* p)
{
std::srand(0);
_subtestNumber = subtest;
_parentNode = nullptr;
/*
* Tests:
* 1: 1 (32-bit) PNG sprite of 52 x 139
* 2: 1 (32-bit) PNG sprite of 52 x 139 (same as 1)
* 3: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
* 4: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
* 5: 14 (32-bit) PNG sprites of 85 x 121 each
* 6: 14 (32-bit) PNG sprites of 85 x 121 each that belong to on texture atlas
* 7: 14 (32-bit) PNG Batch Node of 85 x 121 each
* 8: 14 (16-bit) PNG Batch Node of 85 x 121 each
* 9: 64 (32-bit) sprites of 32 x 32 each
*10: 64 (32-bit) sprites of 32 x 32 each that belong to on texture atlas
*11: 64 (32-bit) PNG Batch Node of 32 x 32 each
*12: 64 (16-bit) PNG Batch Node of 32 x 32 each
*
*13: (16-bit) PNG sprites. 33% from test4, 33% from test8, 33% from test12
*/
// purge textures
auto mgr = Director::getInstance()->getTextureCache();
mgr->removeTextureForKey("Images/grossinis_sister1.png");
mgr->removeTextureForKey("Images/grossini_dance_atlas.png");
mgr->removeTextureForKey("Images/spritesheet1.png");
switch ( _subtestNumber)
{
///
case 1:
case 2:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = Node::create();
break;
case 3:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
break;
case 4:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
break;
///
case 5:
case 6:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = Node::create();
break;
case 7:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
break;
case 8:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
break;
///
case 9:
case 10:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = Node::create();
break;
case 11:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
_parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
break;
case 12:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
break;
///
case 13:
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
_parentNode = Node::create();
break;
default:
break;
}
p->addChild(_parentNode);
_parentNode->retain();
}
Sprite* SubTest::createSpriteWithTag(int tag)
{
TextureCache *cache = Director::getInstance()->getTextureCache();
Sprite* sprite = nullptr;
switch (_subtestNumber)
{
///
case 1:
case 2:
{
sprite = Sprite::create("Images/grossinis_sister1.png");
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 3:
case 4:
{
Texture2D *texture = cache->addImage("Images/grossinis_sister1.png");
sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 5:
{
int idx = (CCRANDOM_0_1() * 1400 / 100) + 1;
char str[32] = {0};
sprintf(str, "Images/grossini_dance_%02d.png", idx);
sprite = Sprite::create(str);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 6:
case 7:
case 8:
{
int y,x;
int r = (CCRANDOM_0_1() * 1400 / 100);
y = r / 5;
x = r % 5;
x *= 85;
y *= 121;
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 9:
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
char str[40] = {0};
sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y);
sprite = Sprite::create(str);
_parentNode->addChild(sprite, 0, tag+100);
break;
}
case 10:
case 11:
case 12:
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
x *= 32;
y *= 32;
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_parentNode->addChild(sprite, 0, tag+100);
break;
}
///
case 13:
{
int test = (CCRANDOM_0_1() * 3);
if(test==0) {
// Switch case 1
sprite = Sprite::create("Images/grossinis_sister1.png");
_parentNode->addChild(sprite, 0, tag+100);
}
else if(test==1)
{
// Switch case 6
int y,x;
int r = (CCRANDOM_0_1() * 1400 / 100);
y = r / 5;
x = r % 5;
x *= 85;
y *= 121;
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
_parentNode->addChild(sprite, 0, tag+100);
}
else if(test==2)
{
int y,x;
int r = (CCRANDOM_0_1() * 6400 / 100);
y = r / 8;
x = r % 8;
x *= 32;
y *= 32;
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
_parentNode->addChild(sprite, 0, tag+100);
}
}
default:
break;
}
return sprite;
}
void SubTest::removeByTag(int tag)
{
_parentNode->removeChildByTag(tag+100, true);
}
////////////////////////////////////////////////////////
//
// SpriteMainScene
//
////////////////////////////////////////////////////////
bool SpriteMainScene::init()
{
if (TestCase::init())
{
initWithSubTest(_subtestNumber, _quantityNodes);
return true;
}
return false;
}
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
{
std::srand(0);
_subtestNumber = asubtest;
_subTest = new (std::nothrow) SubTest;
_subTest->initWithSubTest(asubtest, this);
auto s = Director::getInstance()->getWinSize();
_lastRenderedCount = 0;
_quantityNodes = 0;
MenuItemFont::setFontSize(65);
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteMainScene::onDecrease, this));
decrease->setColor(Color3B(0,200,20));
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteMainScene::onIncrease, this));
increase->setColor(Color3B(0,200,20));
auto menu = Menu::create(decrease, increase, nullptr);
menu->alignItemsHorizontally();
menu->setPosition(Vec2(s.width/2, s.height-65));
addChild(menu, 1);
auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30);
infoLabel->setColor(Color3B(0,200,20));
infoLabel->setPosition(Vec2(s.width/2, s.height-90));
addChild(infoLabel, 1, kTagInfoLayer);
/**
* auto test menu
*/
auto menuAutoTest = Menu::create();
menuAutoTest->setPosition( Vec2::ZERO );
MenuItemFont::setFontName("fonts/arial.ttf");
MenuItemFont::setFontSize(24);
// Sub Tests
MenuItemFont::setFontSize(28);
auto subMenu = Menu::create();
for (int i = 1; i <= 13; ++i)
{
char str[10] = {0};
sprintf(str, "%d ", i);
auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(SpriteMainScene::testNCallback, this));
itemFont->setTag(i);
subMenu->addChild(itemFont, 10);
if( i<= 4)
itemFont->setColor(Color3B(200,20,20));
else if(i <= 8)
itemFont->setColor(Color3B(0,200,20));
else if( i<=12)
itemFont->setColor(Color3B(0,20,200));
else
itemFont->setColor(Color3B::GRAY);
}
subMenu->alignItemsHorizontally();
subMenu->setPosition(Vec2(s.width/2, 80));
addChild(subMenu, 2);
// add title label
auto label = Label::createWithTTF(title(), "fonts/arial.ttf", 32);
addChild(label, 1, kTagTitle);
label->setPosition(Vec2(s.width/2, s.height-50));
// subtitle
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/Thonburi.ttf", 16);
addChild(l, 9999);
l->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
while(_quantityNodes < nNodes)
onIncrease(this);
}
std::string SpriteMainScene::title() const
{
return "No title";
}
std::string SpriteMainScene::subtitle() const
{
return ""; // override me
}
SpriteMainScene::~SpriteMainScene()
{
if (_subTest)
{
delete _subTest;
_subTest = nullptr;
}
}
void SpriteMainScene::testNCallback(Ref* sender)
{
if (isAutoTesting())
{
log("It's auto sprite performance testing,so this operation is invalid");
return;
}
_subtestNumber = static_cast<MenuItemFont*>(sender)->getTag();
this->restartTestCallback(sender);
}
void SpriteMainScene::updateNodes()
{
if( _quantityNodes != _lastRenderedCount )
{
auto infoLabel = (Label *) getChildByTag(kTagInfoLayer);
char str[16] = {0};
sprintf(str, "%u nodes", _quantityNodes);
infoLabel->setString(str);
_lastRenderedCount = _quantityNodes;
}
}
void SpriteMainScene::updateTitle()
{
auto titleLabel = (Label *) getChildByTag(kTagTitle);
titleLabel->setString(this->title());
}
void SpriteMainScene::onIncrease(Ref* sender)
{
if( _quantityNodes >= kMaxNodes)
return;
for( int i=0;i< kNodesIncrease;i++)
{
auto sprite = _subTest->createSpriteWithTag(_quantityNodes);
doTest(sprite);
_quantityNodes++;
}
updateNodes();
}
void SpriteMainScene::onDecrease(Ref* sender)
{
if( _quantityNodes <= 0 )
return;
for( int i=0;i < kNodesIncrease;i++)
{
_quantityNodes--;
_subTest->removeByTag(_quantityNodes);
}
updateNodes();
}
void SpriteMainScene::onEnter()
{
Scene::onEnter();
if (isAutoTesting())
{
scheduleUpdate();
Profile::getInstance()->testCaseBegin("SpriteTest",
genStrVector("SpriteCount", "Type", "SubTest", nullptr),
genStrVector("Avg", "Min", "Max", nullptr));
autoTestIndex = 0;
_subtestNumber = 1;
doAutoTest();
}
}
void SpriteMainScene::onExit()
{
auto director = Director::getInstance();
auto sched = director->getScheduler();
sched->unscheduleAllForTarget(this);
Scene::onExit();
}
void SpriteMainScene::update(float dt)
{
if (isStating)
{
totalStatTime += dt;
statCount++;
auto curFrameRate = Director::getInstance()->getFrameRate();
if (maxFrameRate < 0 || curFrameRate > maxFrameRate)
maxFrameRate = curFrameRate;
if (minFrameRate < 0 || curFrameRate < minFrameRate)
minFrameRate = curFrameRate;
}
}
void SpriteMainScene::beginStat(float dt)
{
unschedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::beginStat));
isStating = true;
}
void SpriteMainScene::endStat(float dt)
{
unschedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::endStat));
isStating = false;
// record test data
auto typeStr = getTestCaseName();
auto avgStr = genStr("%.2f", (float) statCount / totalStatTime);
Profile::getInstance()->addTestResult(genStrVector(genStr("%d", _quantityNodes).c_str(), typeStr.c_str(),
genStr("%d", _subtestNumber).c_str(), nullptr),
genStrVector(avgStr.c_str(), genStr("%.2f", minFrameRate).c_str(),
genStr("%.2f", maxFrameRate).c_str(), nullptr));
// check the auto test is end or not
int autoTestCount = sizeof(autoTestSpriteCounts) / sizeof(int);
if (autoTestIndex >= (autoTestCount - 1) &&
_subtestNumber >= MAX_SUB_TEST_NUM)
{
// auto test end
Profile::getInstance()->testCaseEnd();
setAutoTesting(false);
return;
}
if (autoTestIndex >= (autoTestCount - 1))
{
autoTestIndex = 0;
_subtestNumber++;
}
else
{
autoTestIndex++;
}
doAutoTest();
}
void SpriteMainScene::doAutoTest()
{
isStating = false;
statCount = 0;
totalStatTime = 0.0f;
minFrameRate = -1.0f;
maxFrameRate = -1.0f;
// recreate a SubTest object
this->removeChild(_subTest->getTheParentNode());
CC_SAFE_DELETE(_subTest);
_subTest = new (std::nothrow) SubTest;
_subTest->initWithSubTest(_subtestNumber, this);
// create sprites & update the label
_quantityNodes = autoTestSpriteCounts[autoTestIndex];
for( int i = 0; i < _quantityNodes; i++)
{
auto sprite = _subTest->createSpriteWithTag(i);
doTest(sprite);
}
updateNodes();
updateTitle();
schedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::beginStat), DELAY_TIME);
schedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::endStat), DELAY_TIME + STAT_TIME);
}
////////////////////////////////////////////////////////
//
// For test functions
//
////////////////////////////////////////////////////////
void performanceActions(Sprite* sprite)
{
auto size = Director::getInstance()->getWinSize();
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
float period = 0.5f + (rand() % 1000) / 500.0f;
auto rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
auto rot_back = rot->reverse();
auto permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, nullptr));
sprite->runAction(permanentRotation);
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
auto grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
auto permanentScaleLoop = RepeatForever::create(Sequence::create(grow, grow->reverse(), nullptr));
sprite->runAction(permanentScaleLoop);
}
void performanceActions20(Sprite* sprite)
{
auto size = Director::getInstance()->getWinSize();
if( CCRANDOM_0_1() < 0.2f )
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
else
sprite->setPosition(Vec2( -1000, -1000));
float period = 0.5f + (rand() % 1000) / 500.0f;
auto rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
auto rot_back = rot->reverse();
auto permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, nullptr));
sprite->runAction(permanentRotation);
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
auto grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
auto permanentScaleLoop = RepeatForever::create(Sequence::createWithTwoActions(grow, grow->reverse()));
sprite->runAction(permanentScaleLoop);
}
void performanceRotationScale(Sprite* sprite)
{
auto size = Director::getInstance()->getWinSize();
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
sprite->setRotation(CCRANDOM_0_1() * 360);
sprite->setScale(CCRANDOM_0_1() * 2);
}
void performancePosition(Sprite* sprite)
{
auto size = Director::getInstance()->getWinSize();
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
}
void performanceout20(Sprite* sprite)
{
auto size = Director::getInstance()->getWinSize();
if( CCRANDOM_0_1() < 0.2f )
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
else
sprite->setPosition(Vec2( -1000, -1000));
}
void performanceOut100(Sprite* sprite)
{
sprite->setPosition(Vec2( -1000, -1000));
}
void performanceScale(Sprite* sprite)
{
auto size = Director::getInstance()->getWinSize();
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
sprite->setScale(CCRANDOM_0_1() * 100 / 50);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestA
//
////////////////////////////////////////////////////////
std::string SpritePerformTestA::title() const
{
char str[32] = {0};
sprintf(str, "A (%d) position", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestA::doTest(Sprite* sprite)
{
performancePosition(sprite);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestB
//
////////////////////////////////////////////////////////
std::string SpritePerformTestB::title() const
{
char str[32] = {0};
sprintf(str, "B (%d) scale", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestB::doTest(Sprite* sprite)
{
performanceScale(sprite);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestC
//
////////////////////////////////////////////////////////
std::string SpritePerformTestC::title() const
{
char str[32] = {0};
sprintf(str, "C (%d) scale + rot", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestC::doTest(Sprite* sprite)
{
performanceRotationScale(sprite);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestD
//
////////////////////////////////////////////////////////
std::string SpritePerformTestD::title() const
{
char str[32] = {0};
sprintf(str, "D (%d) 100%% out", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestD::doTest(Sprite* sprite)
{
performanceOut100(sprite);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestE
//
////////////////////////////////////////////////////////
std::string SpritePerformTestE::title() const
{
char str[32] = {0};
sprintf(str, "E (%d) 80%% out", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestE::doTest(Sprite* sprite)
{
performanceout20(sprite);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestF
//
////////////////////////////////////////////////////////
std::string SpritePerformTestF::title() const
{
char str[32] = {0};
sprintf(str, "F (%d) actions", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestF::doTest(Sprite* sprite)
{
performanceActions(sprite);
}
////////////////////////////////////////////////////////
//
// SpritePerformTestG
//
////////////////////////////////////////////////////////
std::string SpritePerformTestG::title() const
{
char str[32] = {0};
sprintf(str, "G (%d) actions 80%% out", _subtestNumber);
std::string strRet = str;
return strRet;
}
void SpritePerformTestG::doTest(Sprite* sprite)
{
performanceActions20(sprite);
}

View File

@ -0,0 +1,163 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PERFORMANCE_SPRITE_TEST_H__
#define __PERFORMANCE_SPRITE_TEST_H__
#include <vector>
#include "BaseTest.h"
DEFINE_TEST_SUITE(PerformceSpriteTests);
class SubTest
{
public:
~SubTest();
void removeByTag(int tag);
cocos2d::Sprite* createSpriteWithTag(int tag);
void initWithSubTest(int nSubTest, cocos2d::Node* parent);
cocos2d::Node* getTheParentNode() { return _parentNode; }
protected:
int _subtestNumber;
cocos2d::Node* _parentNode;
};
class SpriteMainScene : public TestCase
{
public:
virtual ~SpriteMainScene();
virtual bool init() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void initWithSubTest(int nSubTest, int nNodes);
void updateNodes();
void updateTitle();
void testNCallback(cocos2d::Ref* sender);
void onIncrease(cocos2d::Ref* sender);
void onDecrease(cocos2d::Ref* sender);
virtual void doTest(cocos2d::Sprite* sprite) = 0;
virtual void onEnter() override;
virtual void onExit() override;
virtual void update(float dt) override;
virtual std::string getTestCaseName() = 0;
void beginStat(float dt);
void endStat(float dt);
void doAutoTest();
protected:
static int _quantityNodes;
static int _subtestNumber;
int _lastRenderedCount;
SubTest* _subTest;
bool isStating;
int autoTestIndex;
int statCount;
float totalStatTime;
float minFrameRate;
float maxFrameRate;
};
class SpritePerformTestA : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestA);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "A"; }
};
class SpritePerformTestB : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestB);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "B"; }
};
class SpritePerformTestC : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestC);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "C"; }
};
class SpritePerformTestD : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestD);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "D"; }
};
class SpritePerformTestE : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestE);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "E"; }
};
class SpritePerformTestF : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestF);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "F"; }
};
class SpritePerformTestG : public SpriteMainScene
{
public:
CREATE_FUNC(SpritePerformTestG);
virtual void doTest(cocos2d::Sprite* sprite) override;
virtual std::string title() const override;
virtual std::string getTestCaseName() override { return "G"; }
};
#endif

View File

@ -24,6 +24,8 @@ public:
addTest("Node Children Tests", []() { return new PerformceNodeChildrenTests(); });
addTest("Particle Tests", []() { return new PerformceParticleTests(); });
addTest("Particle3D Tests", []() { return new PerformceParticle3DTests(); });
addTest("Sprite Tests", []() { return new PerformceParticle3DTests(); });
addTest("Sprite Tests", []() { return new PerformceSpriteTests(); });
}
};

View File

@ -6,5 +6,6 @@
#include "PerformanceNodeChildrenTest.h"
#include "PerformanceParticleTest.h"
#include "PerformanceParticle3DTest.h"
#include "PerformanceSpriteTest.h"
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB