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
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
struct {
|
|
|
|
const char *name;
|
2013-06-20 14:17:10 +08:00
|
|
|
std::function<void(Object*)> callback;
|
2013-06-08 08:21:11 +08:00
|
|
|
} g_testsName[] =
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
{ "PerformanceNodeChildrenTest", [](Object*sender){runNodeChildrenTest();} },
|
|
|
|
{ "PerformanceParticleTest",[](Object*sender){runParticleTest();} },
|
|
|
|
{ "PerformanceSpriteTest",[](Object*sender){runSpriteTest();} },
|
|
|
|
{ "PerformanceTextureTest",[](Object*sender){runTextureTest();} },
|
|
|
|
{ "PerformanceTouchesTest",[](Object*sender){runTouchesTest();} },
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PerformanceMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void PerformanceMainLayer::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
Menu* menu = Menu::create();
|
|
|
|
menu->setPosition( Point::ZERO );
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Arial");
|
|
|
|
MenuItemFont::setFontSize(24);
|
2013-06-08 08:21:11 +08:00
|
|
|
for (int i = 0; i < g_testMax; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* pItem = MenuItemFont::create(g_testsName[i].name, g_testsName[i].callback);
|
2013-07-12 14:11:55 +08:00
|
|
|
pItem->setPosition(Point(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
2013-07-24 06:20:22 +08:00
|
|
|
menu->addChild(pItem, kItemTagBasic + i);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(menu);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PerformBasicLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
PerformBasicLayer::PerformBasicLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
|
2013-06-15 14:03:30 +08:00
|
|
|
: _controlMenuVisible(bControlMenuVisible)
|
|
|
|
, _maxCases(nMaxCases)
|
|
|
|
, _curCase(nCurCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformBasicLayer::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Arial");
|
|
|
|
MenuItemFont::setFontSize(24);
|
|
|
|
MenuItemFont* pMainItem = MenuItemFont::create("Back", CC_CALLBACK_1(PerformBasicLayer::toMainLayer, this));
|
2013-07-12 14:11:55 +08:00
|
|
|
pMainItem->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
2013-07-24 06:20:22 +08:00
|
|
|
Menu* menu = Menu::create(pMainItem, NULL);
|
|
|
|
menu->setPosition( Point::ZERO );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_controlMenuVisible)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
MenuItemImage *item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(PerformBasicLayer::backCallback, this));
|
|
|
|
MenuItemImage *item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(PerformBasicLayer::restartCallback, this));
|
|
|
|
MenuItemImage *item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(PerformBasicLayer::nextCallback, this));
|
2013-07-12 14:11:55 +08:00
|
|
|
item1->setPosition(Point(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
menu->addChild(item1, kItemTagBasic);
|
|
|
|
menu->addChild(item2, kItemTagBasic);
|
|
|
|
menu->addChild(item3, kItemTagBasic);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(menu);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void PerformBasicLayer::toMainLayer(Object* pSender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
PerformanceTestScene* scene = new PerformanceTestScene();
|
|
|
|
scene->runThisTest();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void PerformBasicLayer::restartCallback(Object* pSender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void PerformBasicLayer::nextCallback(Object* pSender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_curCase++;
|
|
|
|
_curCase = _curCase % _maxCases;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void PerformBasicLayer::backCallback(Object* pSender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_curCase--;
|
|
|
|
if( _curCase < 0 )
|
|
|
|
_curCase += _maxCases;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PerformanceTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void PerformanceTestScene::runThisTest()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = new PerformanceMainLayer();
|
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|