2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "PerformanceNodeChildrenTest.h"
|
|
|
|
#include "PerformanceParticleTest.h"
|
|
|
|
#include "PerformanceSpriteTest.h"
|
|
|
|
#include "PerformanceTextureTest.h"
|
|
|
|
#include "PerformanceTouchesTest.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_COUNT = 5,
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::string testsName[MAX_COUNT] =
|
|
|
|
{
|
|
|
|
"PerformanceNodeChildrenTest",
|
|
|
|
"PerformanceParticleTest",
|
|
|
|
"PerformanceSpriteTest",
|
|
|
|
"PerformanceTextureTest",
|
|
|
|
"PerformanceTouchesTest"
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PerformanceMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void PerformanceMainLayer::onEnter()
|
|
|
|
{
|
|
|
|
CCLayer::onEnter();
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* pMenu = CCMenu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
pMenu->setPosition( CCPointZero );
|
|
|
|
CCMenuItemFont::setFontName("Arial");
|
|
|
|
CCMenuItemFont::setFontSize(24);
|
|
|
|
for (int i = 0; i < MAX_COUNT; ++i)
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(PerformanceMainLayer::menuCallback));
|
|
|
|
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
|
|
|
pMenu->addChild(pItem, kItemTagBasic + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
addChild(pMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceMainLayer::menuCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
CCMenuItemFont* pItem = (CCMenuItemFont*)pSender;
|
|
|
|
int nIndex = pItem->getZOrder() - kItemTagBasic;
|
|
|
|
|
|
|
|
switch (nIndex)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
runNodeChildrenTest();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
runParticleTest();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
runSpriteTest();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
runTextureTest();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
runTouchesTest();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PerformBasicLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
PerformBasicLayer::PerformBasicLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
|
|
|
|
: m_bControlMenuVisible(bControlMenuVisible)
|
|
|
|
, m_nMaxCases(nMaxCases)
|
|
|
|
, m_nCurCase(nCurCase)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformBasicLayer::onEnter()
|
|
|
|
{
|
|
|
|
CCLayer::onEnter();
|
|
|
|
|
|
|
|
CCMenuItemFont::setFontName("Arial");
|
|
|
|
CCMenuItemFont::setFontSize(24);
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(PerformBasicLayer::toMainLayer));
|
2012-10-23 17:48:50 +08:00
|
|
|
pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* pMenu = CCMenu::create(pMainItem, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
pMenu->setPosition( CCPointZero );
|
|
|
|
|
|
|
|
if (m_bControlMenuVisible)
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(PerformBasicLayer::backCallback) );
|
|
|
|
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(PerformBasicLayer::restartCallback) );
|
|
|
|
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(PerformBasicLayer::nextCallback) );
|
2012-10-23 17:48:50 +08:00
|
|
|
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
pMenu->addChild(item1, kItemTagBasic);
|
|
|
|
pMenu->addChild(item2, kItemTagBasic);
|
|
|
|
pMenu->addChild(item3, kItemTagBasic);
|
|
|
|
}
|
|
|
|
addChild(pMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformBasicLayer::toMainLayer(CCObject* pSender)
|
|
|
|
{
|
|
|
|
PerformanceTestScene* pScene = new PerformanceTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void PerformBasicLayer::restartCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformBasicLayer::nextCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
m_nCurCase++;
|
|
|
|
m_nCurCase = m_nCurCase % m_nMaxCases;
|
|
|
|
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void PerformBasicLayer::backCallback(CCObject* pSender)
|
|
|
|
{
|
2011-03-25 13:59:08 +08:00
|
|
|
m_nCurCase--;
|
|
|
|
if( m_nCurCase < 0 )
|
2012-04-19 14:35:52 +08:00
|
|
|
m_nCurCase += m_nMaxCases;
|
|
|
|
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PerformanceTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void PerformanceTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
CCLayer* pLayer = new PerformanceMainLayer();
|
|
|
|
addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
|
|
|
}
|