2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceSpriteTest.h"
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
enum {
|
2012-06-12 16:56:34 +08:00
|
|
|
kMaxNodes = 50000,
|
|
|
|
kNodesIncrease = 250,
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
TEST_COUNT = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
kTagMainLayer = 2,
|
2011-04-21 14:46:15 +08:00
|
|
|
kTagMenuLayer = (kMaxNodes + 1000),
|
2011-03-25 13:59:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int s_nSpriteCurCase = 0;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SubTest
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2011-04-07 14:30:35 +08:00
|
|
|
SubTest::~SubTest()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (batchNode)
|
|
|
|
{
|
|
|
|
batchNode->release();
|
|
|
|
batchNode = NULL;
|
|
|
|
}
|
2011-04-07 14:30:35 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SubTest::initWithSubTest(int nSubTest, Node* p)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
subtestNumber = nSubTest;
|
|
|
|
parent = p;
|
|
|
|
batchNode = NULL;
|
|
|
|
/*
|
|
|
|
* Tests:
|
|
|
|
* 1: 1 (32-bit) PNG sprite of 52 x 139
|
|
|
|
* 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
|
|
|
|
* 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
|
|
|
|
* 4: 1 (4-bit) PVRTC 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 Batch Node of 85 x 121 each
|
|
|
|
* 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
|
|
|
|
* 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each
|
|
|
|
|
|
|
|
* 9: 64 (32-bit) sprites of 32 x 32 each
|
|
|
|
*10: 64 (32-bit) PNG Batch Node of 32 x 32 each
|
|
|
|
*11: 64 (16-bit) PNG Batch Node of 32 x 32 each
|
|
|
|
*12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
|
|
|
|
*/
|
|
|
|
|
|
|
|
// purge textures
|
2013-07-12 06:24:23 +08:00
|
|
|
TextureCache *mgr = TextureCache::getInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
// [mgr removeAllTextures];
|
2011-03-25 13:59:08 +08:00
|
|
|
mgr->removeTexture(mgr->addImage("Images/grossinis_sister1.png"));
|
|
|
|
mgr->removeTexture(mgr->addImage("Images/grossini_dance_atlas.png"));
|
|
|
|
mgr->removeTexture(mgr->addImage("Images/spritesheet1.png"));
|
|
|
|
|
|
|
|
switch ( subtestNumber)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
case 7:
|
|
|
|
break;
|
|
|
|
///
|
|
|
|
case 2:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
case 3:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
///
|
|
|
|
case 5:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2011-03-25 13:59:08 +08:00
|
|
|
case 6:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
///
|
|
|
|
case 8:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
case 9:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2013-06-20 14:17:10 +08:00
|
|
|
batchNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (batchNode)
|
|
|
|
{
|
|
|
|
batchNode->retain();
|
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* SubTest::createSpriteWithTag(int tag)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
// create
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* sprite = NULL;
|
2011-03-25 13:59:08 +08:00
|
|
|
switch (subtestNumber)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite = Sprite::create("Images/grossinis_sister1.png");
|
2011-03-25 13:59:08 +08:00
|
|
|
parent->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
{
|
2013-07-12 14:30:26 +08:00
|
|
|
sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(0, 0, 52, 139));
|
2011-03-25 13:59:08 +08:00
|
|
|
batchNode->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
int idx = (CCRANDOM_0_1() * 1400 / 100) + 1;
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "Images/grossini_dance_%02d.png", idx);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite = Sprite::create(str);
|
2011-03-25 13:59:08 +08:00
|
|
|
parent->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 1400 / 100);
|
|
|
|
|
|
|
|
y = r / 5;
|
|
|
|
x = r % 5;
|
|
|
|
|
|
|
|
x *= 85;
|
|
|
|
y *= 121;
|
2013-07-12 14:30:26 +08:00
|
|
|
sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(x,y,85,121));
|
2011-03-25 13:59:08 +08:00
|
|
|
batchNode->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
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);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite = Sprite::create(str);
|
2011-03-25 13:59:08 +08:00
|
|
|
parent->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 6400 / 100);
|
|
|
|
|
|
|
|
y = r / 8;
|
|
|
|
x = r % 8;
|
|
|
|
|
|
|
|
x *= 32;
|
|
|
|
y *= 32;
|
2013-07-12 14:30:26 +08:00
|
|
|
sprite = Sprite::createWithTexture(batchNode->getTexture(), Rect(x,y,32,32));
|
2011-03-25 13:59:08 +08:00
|
|
|
batchNode->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::DEFAULT);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubTest::removeByTag(int tag)
|
|
|
|
{
|
|
|
|
switch (subtestNumber)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
case 7:
|
|
|
|
parent->removeChildByTag(tag+100, true);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 8:
|
|
|
|
case 9:
|
|
|
|
batchNode->removeChildAtIndex(tag, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
// [batchNode removeChildByTag:tag+100 cleanup:YES];
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpriteMenuLayer
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void SpriteMenuLayer::showCurrentTest()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
SpriteMainScene* scene = NULL;
|
2011-03-25 13:59:08 +08:00
|
|
|
SpriteMainScene* pPreScene = (SpriteMainScene*) getParent();
|
|
|
|
int nSubTest = pPreScene->getSubTestNum();
|
|
|
|
int nNodes = pPreScene->getNodesNum();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
case 0:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest1;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest2;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest3;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest4;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest5;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest6;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 6:
|
2013-07-23 08:25:44 +08:00
|
|
|
scene = new SpritePerformTest7;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
s_nSpriteCurCase = _curCase;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
if (scene)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->initWithSubTest(nSubTest, nNodes);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpriteMainScene
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
|
|
|
|
{
|
|
|
|
//srandom(0);
|
|
|
|
|
|
|
|
subtestNumber = asubtest;
|
2013-06-15 14:03:30 +08:00
|
|
|
_subTest = new SubTest;
|
|
|
|
_subTest->initWithSubTest(asubtest, this);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
lastRenderedCount = 0;
|
|
|
|
quantityNodes = 0;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(65);
|
|
|
|
MenuItemFont *decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteMainScene::onDecrease, this));
|
2013-07-05 16:49:22 +08:00
|
|
|
decrease->setColor(Color3B(0,200,20));
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteMainScene::onIncrease, this));
|
2013-07-05 16:49:22 +08:00
|
|
|
increase->setColor(Color3B(0,200,20));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *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-65));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(menu, 1);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *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-90));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
|
|
|
// add menu
|
2013-07-24 06:20:22 +08:00
|
|
|
SpriteMenuLayer* menuLayer = new SpriteMenuLayer(true, TEST_COUNT, s_nSpriteCurCase);
|
|
|
|
addChild(menuLayer, 1, kTagMenuLayer);
|
|
|
|
menuLayer->release();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Sub Tests
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(32);
|
2013-07-24 06:20:22 +08:00
|
|
|
Menu* subMenu = Menu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 1; i <= 9; ++i)
|
|
|
|
{
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%d ", i);
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* itemFont = MenuItemFont::create(str, CC_CALLBACK_1(SpriteMainScene::testNCallback, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
itemFont->setTag(i);
|
2013-07-24 06:20:22 +08:00
|
|
|
subMenu->addChild(itemFont, 10);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
if( i<= 3)
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(200,20,20));
|
2011-03-25 13:59:08 +08:00
|
|
|
else if(i <= 6)
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(0,200,20));
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(0,20,200));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
subMenu->alignItemsHorizontally();
|
|
|
|
subMenu->setPosition(Point(s.width/2, 80));
|
|
|
|
addChild(subMenu, 2);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// add title label
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *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
|
|
|
|
|
|
|
while(quantityNodes < nNodes)
|
|
|
|
onIncrease(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteMainScene::title()
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteMainScene::~SpriteMainScene()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_subTest)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
delete _subTest;
|
|
|
|
_subTest = NULL;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpriteMainScene::testNCallback(Object* pSender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
subtestNumber = ((MenuItemFont*) pSender)->getTag();
|
2013-07-24 06:20:22 +08:00
|
|
|
SpriteMenuLayer* menu = (SpriteMenuLayer*)getChildByTag(kTagMenuLayer);
|
|
|
|
menu->restartCallback(pSender);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::updateNodes()
|
|
|
|
{
|
|
|
|
if( quantityNodes != lastRenderedCount )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *infoLabel = (LabelTTF *) getChildByTag(kTagInfoLayer);
|
2011-03-25 13:59:08 +08:00
|
|
|
char str[16] = {0};
|
|
|
|
sprintf(str, "%u nodes", quantityNodes);
|
|
|
|
infoLabel->setString(str);
|
|
|
|
|
|
|
|
lastRenderedCount = quantityNodes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpriteMainScene::onIncrease(Object* pSender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
if( quantityNodes >= kMaxNodes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i=0;i< kNodesIncrease;i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *sprite = _subTest->createSpriteWithTag(quantityNodes);
|
2011-03-25 13:59:08 +08:00
|
|
|
doTest(sprite);
|
|
|
|
quantityNodes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNodes();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpriteMainScene::onDecrease(Object* pSender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
if( quantityNodes <= 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i=0;i < kNodesIncrease;i++)
|
|
|
|
{
|
|
|
|
quantityNodes--;
|
2013-06-15 14:03:30 +08:00
|
|
|
_subTest->removeByTag(quantityNodes);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
updateNodes();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// For test functions
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceActions(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float period = 0.5f + (rand() % 1000) / 500.0f;
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateBy* rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
|
|
|
|
ActionInterval* rot_back = rot->reverse();
|
|
|
|
Action *permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, NULL));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentRotation);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
|
2013-06-20 14:17:10 +08:00
|
|
|
ActionInterval *grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
|
|
|
|
Action *permanentScaleLoop = RepeatForever::create(Sequence::create(grow, grow->reverse(), NULL));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentScaleLoop);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceActions20(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point( -1000, -1000));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float period = 0.5f + (rand() % 1000) / 500.0f;
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateBy* rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
|
|
|
|
ActionInterval* rot_back = rot->reverse();
|
|
|
|
Action *permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, NULL));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentRotation);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
|
2013-06-20 14:17:10 +08:00
|
|
|
ActionInterval *grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
|
|
|
|
Action *permanentScaleLoop = RepeatForever::create(Sequence::createWithTwoActions(grow, grow->reverse()));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentScaleLoop);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceRotationScale(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
sprite->setRotation(CCRANDOM_0_1() * 360);
|
|
|
|
sprite->setScale(CCRANDOM_0_1() * 2);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performancePosition(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceout20(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point( -1000, -1000));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceOut100(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point( -1000, -1000));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceScale(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setPosition(Point((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
sprite->setScale(CCRANDOM_0_1() * 100 / 50);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest1
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest1::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "A (%d) position", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest1::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performancePosition(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest2
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest2::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "B (%d) scale", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest2::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceScale(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest3
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest3::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "C (%d) scale + rot", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest3::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceRotationScale(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest4
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest4::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "D (%d) 100%% out", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest4::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceOut100(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest5
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest5::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "E (%d) 80%% out", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest5::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceout20(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest6
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest6::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "F (%d) actions", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest6::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceActions(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpritePerformTest7
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
std::string SpritePerformTest7::title()
|
|
|
|
{
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "G (%d) actions 80%% out", subtestNumber);
|
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void SpritePerformTest7::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceActions20(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void runSpriteTest()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
SpriteMainScene* scene = new SpritePerformTest1;
|
|
|
|
scene->initWithSubTest(1, 50);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|