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-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case 0:
|
2013-06-15 14:03:30 +08:00
|
|
|
pLayer = new TouchesPerformTest1(true, TEST_COUNT, _curCase);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-06-15 14:03:30 +08:00
|
|
|
pLayer = 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
|
|
|
|
|
|
|
if (pLayer)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* pScene = Scene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
pScene->addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(pScene);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchesMainScene::onEnter()
|
|
|
|
{
|
|
|
|
PerformBasicLayer::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add title
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label = LabelTTF::create(title().c_str(), "Arial", 32);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
label->setPosition(ccp(s.width/2, s.height-50));
|
|
|
|
|
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-06-15 14:03:30 +08:00
|
|
|
_plabel->setPosition(ccp(s.width/2, s.height/2));
|
|
|
|
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-06-20 14:17:10 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-03-21 17:35:20 +08:00
|
|
|
pDirector->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-06-20 14:17:10 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-03-21 17:35:20 +08:00
|
|
|
pDirector->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-06-20 14:17:10 +08:00
|
|
|
Scene* pScene = Scene::create();
|
|
|
|
Layer* pLayer = new TouchesPerformTest1(true, TEST_COUNT, s_nTouchCurCase);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(pScene);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|