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
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void SubTest::initWithSubTest(int nSubTest, CCNode* p)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
CCTextureCache *mgr = CCTextureCache::sharedTextureCache();
|
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:
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
|
2012-06-14 15:13:16 +08:00
|
|
|
batchNode = CCSpriteBatchNode::create("Images/grossinis_sister1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
|
2012-06-14 15:13:16 +08:00
|
|
|
batchNode = CCSpriteBatchNode::create("Images/grossinis_sister1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
///
|
|
|
|
case 5:
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
|
2012-06-14 15:13:16 +08:00
|
|
|
batchNode = CCSpriteBatchNode::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:
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
|
2012-06-14 15:13:16 +08:00
|
|
|
batchNode = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
///
|
|
|
|
case 8:
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
|
2012-06-14 15:13:16 +08:00
|
|
|
batchNode = CCSpriteBatchNode::create("Images/spritesheet1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
p->addChild(batchNode, 0);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
|
2012-06-14 15:13:16 +08:00
|
|
|
batchNode = CCSpriteBatchNode::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
|
|
|
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCSprite* SubTest::createSpriteWithTag(int tag)
|
|
|
|
{
|
|
|
|
// create
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
|
|
|
|
|
|
|
|
CCSprite* sprite = NULL;
|
|
|
|
switch (subtestNumber)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
sprite = CCSprite::create("Images/grossinis_sister1.png");
|
2011-03-25 13:59:08 +08:00
|
|
|
parent->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
{
|
2012-07-23 22:49:11 +08:00
|
|
|
sprite = CCSprite::createWithTexture(batchNode->getTexture(), CCRectMake(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);
|
2012-06-14 15:13:16 +08:00
|
|
|
sprite = CCSprite::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;
|
2012-07-23 22:49:11 +08:00
|
|
|
sprite = CCSprite::createWithTexture(batchNode->getTexture(), CCRectMake(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);
|
2012-06-14 15:13:16 +08:00
|
|
|
sprite = CCSprite::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;
|
2012-07-23 22:49:11 +08:00
|
|
|
sprite = CCSprite::createWithTexture(batchNode->getTexture(), CCRectMake(x,y,32,32));
|
2011-03-25 13:59:08 +08:00
|
|
|
batchNode->addChild(sprite, 0, tag+100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
SpriteMainScene* pScene = NULL;
|
|
|
|
SpriteMainScene* pPreScene = (SpriteMainScene*) getParent();
|
|
|
|
int nSubTest = pPreScene->getSubTestNum();
|
|
|
|
int nNodes = pPreScene->getNodesNum();
|
|
|
|
|
|
|
|
switch (m_nCurCase)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
pScene = new SpritePerformTest1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pScene = new SpritePerformTest2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pScene = new SpritePerformTest3;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pScene = new SpritePerformTest4;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pScene = new SpritePerformTest5;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
pScene = new SpritePerformTest6;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
pScene = new SpritePerformTest7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s_nSpriteCurCase = m_nCurCase;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pScene)
|
|
|
|
{
|
|
|
|
pScene->initWithSubTest(nSubTest, nNodes);
|
|
|
|
CCDirector::sharedDirector()->replaceScene(pScene);
|
|
|
|
pScene->release();
|
|
|
|
}
|
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;
|
|
|
|
m_pSubTest = new SubTest;
|
|
|
|
m_pSubTest->initWithSubTest(asubtest, this);
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
lastRenderedCount = 0;
|
|
|
|
quantityNodes = 0;
|
|
|
|
|
|
|
|
CCMenuItemFont::setFontSize(65);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", this, menu_selector(SpriteMainScene::onDecrease));
|
2011-03-25 13:59:08 +08:00
|
|
|
decrease->setColor(ccc3(0,200,20));
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont *increase = CCMenuItemFont::create(" + ", this, menu_selector(SpriteMainScene::onIncrease));
|
2011-03-25 13:59:08 +08:00
|
|
|
increase->setColor(ccc3(0,200,20));
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(decrease, increase, NULL);
|
2011-03-25 13:59:08 +08:00
|
|
|
menu->alignItemsHorizontally();
|
|
|
|
menu->setPosition(ccp(s.width/2, s.height-65));
|
|
|
|
addChild(menu, 1);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF *infoLabel = CCLabelTTF::create("0 nodes", "Marker Felt", 30);
|
2011-03-25 13:59:08 +08:00
|
|
|
infoLabel->setColor(ccc3(0,200,20));
|
|
|
|
infoLabel->setPosition(ccp(s.width/2, s.height-90));
|
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
|
|
|
// add menu
|
|
|
|
SpriteMenuLayer* pMenu = new SpriteMenuLayer(true, TEST_COUNT, s_nSpriteCurCase);
|
|
|
|
addChild(pMenu, 1, kTagMenuLayer);
|
|
|
|
pMenu->release();
|
|
|
|
|
|
|
|
// Sub Tests
|
|
|
|
CCMenuItemFont::setFontSize(32);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* pSubMenu = CCMenu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 1; i <= 9; ++i)
|
|
|
|
{
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%d ", i);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* itemFont = CCMenuItemFont::create(str, this, menu_selector(SpriteMainScene::testNCallback));
|
2012-04-19 14:35:52 +08:00
|
|
|
itemFont->setTag(i);
|
|
|
|
pSubMenu->addChild(itemFont, 10);
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
if( i<= 3)
|
|
|
|
itemFont->setColor(ccc3(200,20,20));
|
|
|
|
else if(i <= 6)
|
|
|
|
itemFont->setColor(ccc3(0,200,20));
|
|
|
|
else
|
2012-04-19 14:35:52 +08:00
|
|
|
itemFont->setColor(ccc3(0,20,200));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pSubMenu->alignItemsHorizontally();
|
|
|
|
pSubMenu->setPosition(ccp(s.width/2, 80));
|
|
|
|
addChild(pSubMenu, 2);
|
|
|
|
|
|
|
|
// add title label
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 40);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
|
|
|
label->setPosition(ccp(s.width/2, s.height-32));
|
|
|
|
label->setColor(ccc3(255,255,40));
|
|
|
|
|
|
|
|
while(quantityNodes < nNodes)
|
|
|
|
onIncrease(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteMainScene::title()
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteMainScene::~SpriteMainScene()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pSubTest)
|
|
|
|
{
|
|
|
|
delete m_pSubTest;
|
|
|
|
m_pSubTest = NULL;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::testNCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
subtestNumber = ((CCMenuItemFont*) pSender)->getTag();
|
|
|
|
SpriteMenuLayer* pMenu = (SpriteMenuLayer*)getChildByTag(kTagMenuLayer);
|
|
|
|
pMenu->restartCallback(pSender);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::updateNodes()
|
|
|
|
{
|
|
|
|
if( quantityNodes != lastRenderedCount )
|
|
|
|
{
|
|
|
|
CCLabelTTF *infoLabel = (CCLabelTTF *) getChildByTag(kTagInfoLayer);
|
|
|
|
char str[16] = {0};
|
|
|
|
sprintf(str, "%u nodes", quantityNodes);
|
|
|
|
infoLabel->setString(str);
|
|
|
|
|
|
|
|
lastRenderedCount = quantityNodes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::onIncrease(CCObject* pSender)
|
|
|
|
{
|
|
|
|
if( quantityNodes >= kMaxNodes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i=0;i< kNodesIncrease;i++)
|
|
|
|
{
|
|
|
|
CCSprite *sprite = m_pSubTest->createSpriteWithTag(quantityNodes);
|
|
|
|
doTest(sprite);
|
|
|
|
quantityNodes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::onDecrease(CCObject* pSender)
|
|
|
|
{
|
|
|
|
if( quantityNodes <= 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i=0;i < kNodesIncrease;i++)
|
|
|
|
{
|
|
|
|
quantityNodes--;
|
|
|
|
m_pSubTest->removeByTag(quantityNodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNodes();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// For test functions
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void performanceActions(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
|
|
|
|
float period = 0.5f + (rand() % 1000) / 500.0f;
|
2012-06-14 15:13:16 +08:00
|
|
|
CCRotateBy* rot = CCRotateBy::create(period, 360.0f * CCRANDOM_0_1());
|
2011-03-25 13:59:08 +08:00
|
|
|
CCActionInterval* rot_back = rot->reverse();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCAction *permanentRotation = CCRepeatForever::create((CCActionInterval *)CCSequence::create(rot, rot_back, NULL));
|
2011-03-25 13:59:08 +08:00
|
|
|
pSprite->runAction(permanentRotation);
|
|
|
|
|
|
|
|
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval *grow = CCScaleBy::create(growDuration, 0.5f, 0.5f);
|
2012-08-27 10:47:32 +08:00
|
|
|
CCAction *permanentScaleLoop = CCRepeatForever::create((CCActionInterval *)CCSequence::create(grow, grow->reverse(), NULL));
|
2011-03-25 13:59:08 +08:00
|
|
|
pSprite->runAction(permanentScaleLoop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void performanceActions20(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
|
|
|
pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
else
|
|
|
|
pSprite->setPosition(ccp( -1000, -1000));
|
|
|
|
|
|
|
|
float period = 0.5f + (rand() % 1000) / 500.0f;
|
2012-06-14 15:13:16 +08:00
|
|
|
CCRotateBy* rot = CCRotateBy::create(period, 360.0f * CCRANDOM_0_1());
|
2011-03-25 13:59:08 +08:00
|
|
|
CCActionInterval* rot_back = rot->reverse();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCAction *permanentRotation = CCRepeatForever::create((CCActionInterval *)CCSequence::create(rot, rot_back, NULL));
|
2011-03-25 13:59:08 +08:00
|
|
|
pSprite->runAction(permanentRotation);
|
|
|
|
|
|
|
|
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval *grow = CCScaleBy::create(growDuration, 0.5f, 0.5f);
|
2012-07-23 22:49:11 +08:00
|
|
|
CCAction *permanentScaleLoop = CCRepeatForever::create(CCSequence::createWithTwoActions(grow, grow->reverse()));
|
2011-03-25 13:59:08 +08:00
|
|
|
pSprite->runAction(permanentScaleLoop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void performanceRotationScale(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
pSprite->setRotation(CCRANDOM_0_1() * 360);
|
|
|
|
pSprite->setScale(CCRANDOM_0_1() * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void performancePosition(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void performanceout20(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
|
|
|
pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
else
|
|
|
|
pSprite->setPosition(ccp( -1000, -1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
void performanceOut100(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
pSprite->setPosition(ccp( -1000, -1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
void performanceScale(CCSprite* pSprite)
|
|
|
|
{
|
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
pSprite->setPosition(ccp((rand() % (int)size.width), (rand() % (int)size.height)));
|
|
|
|
pSprite->setScale(CCRANDOM_0_1() * 100 / 50);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest1::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest2::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest3::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest4::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest5::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest6::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePerformTest7::doTest(CCSprite* sprite)
|
|
|
|
{
|
|
|
|
performanceActions20(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void runSpriteTest()
|
|
|
|
{
|
|
|
|
SpriteMainScene* pScene = new SpritePerformTest1;
|
2012-04-19 14:35:52 +08:00
|
|
|
pScene->initWithSubTest(1, 50);
|
|
|
|
CCDirector::sharedDirector()->replaceScene(pScene);
|
|
|
|
pScene->release();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|