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"
|
2013-09-06 11:02:04 +08:00
|
|
|
#include "PerformanceAllocTest.h"
|
2013-12-13 12:42:15 +08:00
|
|
|
#include "PerformanceLabelTest.h"
|
2014-01-15 11:27:57 +08:00
|
|
|
#include "PerformanceRendererTest.h"
|
2014-01-16 10:19:52 +08:00
|
|
|
#include "PerformanceContainerTest.h"
|
2014-01-22 14:12:25 +08:00
|
|
|
#include "PerformanceEventDispatcherTest.h"
|
2014-02-10 11:42:15 +08:00
|
|
|
#include "PerformanceScenarioTest.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
struct {
|
|
|
|
const char *name;
|
2014-02-20 10:53:49 +08:00
|
|
|
std::function<void(Ref*)> callback;
|
2013-06-08 08:21:11 +08:00
|
|
|
} g_testsName[] =
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "Alloc Test", [](Ref*sender){runAllocPerformanceTest(); } },
|
|
|
|
{ "NodeChildren Test", [](Ref*sender){runNodeChildrenTest();} },
|
|
|
|
{ "Particle Test",[](Ref*sender){runParticleTest();} },
|
|
|
|
{ "Sprite Perf Test",[](Ref*sender){runSpriteTest();} },
|
|
|
|
{ "Texture Perf Test",[](Ref*sender){runTextureTest();} },
|
|
|
|
{ "Touches Perf Test",[](Ref*sender){runTouchesTest();} },
|
|
|
|
{ "Label Perf Test",[](Ref*sender){runLabelTest();} },
|
|
|
|
{ "Renderer Perf Test",[](Ref*sender){runRendererTest();} },
|
|
|
|
{ "Container Perf Test", [](Ref* sender ) { runContainerPerformanceTest(); } },
|
|
|
|
{ "EventDispatcher Perf Test", [](Ref* sender ) { runEventDispatcherPerformanceTest(); } },
|
|
|
|
{ "Scenario Perf Test", [](Ref* sender ) { runScenarioTest(); } },
|
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]);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
Vector2 PerformanceMainLayer::_CurrentPos = Vector2::ZERO;
|
2014-02-10 11:42:15 +08:00
|
|
|
|
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-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-01-15 11:27:57 +08:00
|
|
|
_itemMenu = Menu::create();
|
2014-02-10 11:42:15 +08:00
|
|
|
_itemMenu->setPosition(_CurrentPos);
|
2014-03-26 23:33:58 +08:00
|
|
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
2013-06-20 14:17:10 +08:00
|
|
|
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-08-16 16:05:27 +08:00
|
|
|
auto pItem = MenuItemFont::create(g_testsName[i].name, g_testsName[i].callback);
|
2014-04-15 18:23:40 +08:00
|
|
|
pItem->setPosition(Vector2(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
2014-01-15 11:27:57 +08:00
|
|
|
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-01-15 11:27:57 +08:00
|
|
|
addChild(_itemMenu);
|
|
|
|
|
|
|
|
// Register Touch Event
|
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
|
|
|
listener->setSwallowTouches(true);
|
|
|
|
|
|
|
|
listener->onTouchBegan = CC_CALLBACK_2(PerformanceMainLayer::onTouchBegan, this);
|
|
|
|
listener->onTouchMoved = CC_CALLBACK_2(PerformanceMainLayer::onTouchMoved, this);
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
auto mouseListener = EventListenerMouse::create();
|
|
|
|
mouseListener->onMouseScroll = CC_CALLBACK_1(PerformanceMainLayer::onMouseScroll, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PerformanceMainLayer::onTouchBegan(Touch* touches, Event *event)
|
|
|
|
{
|
|
|
|
_beginPos = touches->getLocation();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void PerformanceMainLayer::onTouchMoved(Touch* touches, Event *event)
|
|
|
|
{
|
|
|
|
auto touchLocation = touches->getLocation();
|
|
|
|
float nMoveY = touchLocation.y - _beginPos.y;
|
|
|
|
|
|
|
|
auto curPos = _itemMenu->getPosition();
|
2014-04-15 18:23:40 +08:00
|
|
|
auto nextPos = Vector2(curPos.x, curPos.y + nMoveY);
|
2014-01-15 11:27:57 +08:00
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2::ZERO);
|
2014-01-15 11:27:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
2014-01-15 11:27:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemMenu->setPosition(nextPos);
|
|
|
|
_beginPos = touchLocation;
|
2014-02-10 11:42:15 +08:00
|
|
|
_CurrentPos = nextPos;
|
2014-01-15 11:27:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceMainLayer::onMouseScroll(Event *event)
|
|
|
|
{
|
|
|
|
auto mouseEvent = static_cast<EventMouse*>(event);
|
|
|
|
float nMoveY = mouseEvent->getScrollY() * 6;
|
|
|
|
|
|
|
|
auto curPos = _itemMenu->getPosition();
|
2014-04-15 18:23:40 +08:00
|
|
|
auto nextPos = Vector2(curPos.x, curPos.y + nMoveY);
|
2014-01-15 11:27:57 +08:00
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2::ZERO);
|
2014-01-15 11:27:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
2014-01-15 11:27:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemMenu->setPosition(nextPos);
|
2014-02-10 11:42:15 +08:00
|
|
|
_CurrentPos = nextPos;
|
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
|
|
|
|
2014-03-26 23:33:58 +08:00
|
|
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(24);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto pMainItem = MenuItemFont::create("Back", CC_CALLBACK_1(PerformBasicLayer::toMainLayer, this));
|
2014-04-15 18:23:40 +08:00
|
|
|
pMainItem->setPosition(Vector2(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(pMainItem, NULL);
|
2014-04-15 18:23:40 +08:00
|
|
|
menu->setPosition( Vector2::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-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(PerformBasicLayer::backCallback, this));
|
|
|
|
auto item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(PerformBasicLayer::restartCallback, this));
|
|
|
|
auto item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(PerformBasicLayer::nextCallback, this));
|
2014-04-15 18:23:40 +08:00
|
|
|
item1->setPosition(Vector2(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(Vector2(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(Vector2(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
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void PerformBasicLayer::toMainLayer(Ref* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new PerformanceTestScene();
|
2013-07-23 08:25:44 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void PerformBasicLayer::restartCallback(Ref* sender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
showCurrentTest();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void PerformBasicLayer::nextCallback(Ref* sender)
|
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();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void PerformBasicLayer::backCallback(Ref* sender)
|
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-08-16 16:05:27 +08:00
|
|
|
auto layer = new PerformanceMainLayer();
|
2013-07-23 08:25:44 +08:00
|
|
|
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
|
|
|
}
|