2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceTouchesTest.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEST_COUNT = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int s_nTouchCurCase = 0;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TouchesMainScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void TouchesMainScene::showCurrentTest()
|
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case 0:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TouchesPerformTest1(true, TEST_COUNT, _curCase);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TouchesPerformTest2(true, TEST_COUNT, _curCase);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
s_nTouchCurCase = _curCase;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
if (layer)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchesMainScene::onEnter()
|
|
|
|
{
|
|
|
|
PerformBasicLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add title
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create(title().c_str(), "Arial", 32);
|
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-50));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
scheduleUpdate();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_plabel = LabelBMFont::create("00.0", "fonts/arial16.fnt");
|
2013-07-12 14:11:55 +08:00
|
|
|
_plabel->setPosition(Point(s.width/2, s.height/2));
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_plabel);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
elapsedTime = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
numberOfTouchesB = numberOfTouchesM = numberOfTouchesE = numberOfTouchesC = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TouchesMainScene::update(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2011-03-25 13:59:08 +08:00
|
|
|
elapsedTime += dt;
|
|
|
|
|
|
|
|
if ( elapsedTime > 1.0f)
|
|
|
|
{
|
|
|
|
float frameRateB = numberOfTouchesB / elapsedTime;
|
|
|
|
float frameRateM = numberOfTouchesM / elapsedTime;
|
|
|
|
float frameRateE = numberOfTouchesE / elapsedTime;
|
|
|
|
float frameRateC = numberOfTouchesC / elapsedTime;
|
|
|
|
elapsedTime = 0;
|
|
|
|
numberOfTouchesB = numberOfTouchesM = numberOfTouchesE = numberOfTouchesC = 0;
|
|
|
|
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "%.1f %.1f %.1f %.1f", frameRateB, frameRateM, frameRateE, frameRateC);
|
2013-06-15 14:03:30 +08:00
|
|
|
_plabel->setString(str);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TouchesMainScene::title()
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TouchesPerformTest1
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void TouchesPerformTest1::onEnter()
|
|
|
|
{
|
|
|
|
TouchesMainScene::onEnter();
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
|
|
|
// Register Touch Event
|
|
|
|
auto listener = TouchEventListener::create(Touch::DispatchMode::ONE_BY_ONE);
|
|
|
|
listener->setSwallowTouches(true);
|
|
|
|
|
|
|
|
listener->onTouchBegan = CC_CALLBACK_2(TouchesPerformTest1::onTouchBegan, this);
|
|
|
|
listener->onTouchMoved = CC_CALLBACK_2(TouchesPerformTest1::onTouchMoved, this);
|
|
|
|
listener->onTouchEnded = CC_CALLBACK_2(TouchesPerformTest1::onTouchEnded, this);
|
|
|
|
listener->onTouchCancelled = CC_CALLBACK_2(TouchesPerformTest1::onTouchCancelled, this);
|
|
|
|
|
2013-09-14 09:02:49 +08:00
|
|
|
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
_touchListener = listener;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TouchesPerformTest1::title()
|
|
|
|
{
|
|
|
|
return "Targeted touches";
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
bool TouchesPerformTest1::onTouchBegan(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesB++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest1::onTouchMoved(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesM++;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest1::onTouchEnded(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesE++;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest1::onTouchCancelled(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesC++;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TouchesPerformTest2
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
void TouchesPerformTest2::onEnter()
|
|
|
|
{
|
|
|
|
TouchesMainScene::onEnter();
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
|
|
|
// Register Touch Event
|
|
|
|
// auto listener = TouchEventListener::create(Touch::DispatchMode::ALL_AT_ONCE);
|
|
|
|
//
|
|
|
|
// listener->onTouchesBegan = CC_CALLBACK_2(TouchesPerformTest2::onTouchesBegan, this);
|
|
|
|
// listener->onTouchesMoved = CC_CALLBACK_2(TouchesPerformTest2::onTouchesMoved, this);
|
|
|
|
// listener->onTouchesEnded = CC_CALLBACK_2(TouchesPerformTest2::onTouchesEnded, this);
|
|
|
|
// listener->onTouchesCancelled = CC_CALLBACK_2(TouchesPerformTest2::onTouchesCancelled, this);
|
|
|
|
//
|
|
|
|
// EventDispatcher::getInstance()->registerEventListenerWithSceneGraphPriority(listener, this);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TouchesPerformTest2::title()
|
|
|
|
{
|
|
|
|
return "Standard touches";
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
//void TouchesPerformTest2::registerWithTouchDispatcher()
|
|
|
|
//{
|
|
|
|
// auto director = Director::getInstance();
|
|
|
|
// director->getTouchDispatcher()->addStandardDelegate(this, 0);
|
|
|
|
//}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest2::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
numberOfTouchesB += touches.size();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest2::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
numberOfTouchesM += touches.size();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest2::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
numberOfTouchesE += touches.size();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TouchesPerformTest2::onTouchesCancelled(const std::vector<Touch*>& touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
numberOfTouchesC += touches.size();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void runTouchesTest()
|
|
|
|
{
|
|
|
|
s_nTouchCurCase = 0;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
|
|
|
auto layer = new TouchesPerformTest1(true, TEST_COUNT, s_nTouchCurCase);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|