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);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TouchesPerformTest1::title()
|
|
|
|
{
|
|
|
|
return "Targeted touches";
|
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void TouchesPerformTest1::registerWithTouchDispatcher()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
director->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bool TouchesPerformTest1::ccTouchBegan(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesB++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest1::ccTouchMoved(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesM++;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest1::ccTouchEnded(Touch* touch, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesE++;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest1::ccTouchCancelled(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);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TouchesPerformTest2::title()
|
|
|
|
{
|
|
|
|
return "Standard touches";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchesPerformTest2::registerWithTouchDispatcher()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
director->getTouchDispatcher()->addStandardDelegate(this, 0);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest2::ccTouchesBegan(Set* touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesB += touches->count();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest2::ccTouchesMoved(Set* touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesM += touches->count();
|
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest2::ccTouchesEnded(Set* touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesE += touches->count();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TouchesPerformTest2::ccTouchesCancelled(Set* touches, Event* event)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
numberOfTouchesC += touches->count();
|
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
|
|
|
}
|