mirror of https://github.com/axmolengine/axmol.git
[dispatcher] Adding TouchEvent dispatch test.
This commit is contained in:
parent
23e80857fa
commit
62a0dc41c3
|
@ -14,7 +14,7 @@ class PerformBasicLayer : public Layer
|
|||
public:
|
||||
PerformBasicLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0);
|
||||
|
||||
virtual void onEnter();
|
||||
virtual void onEnter() override;
|
||||
|
||||
virtual void restartCallback(Object* sender);
|
||||
virtual void nextCallback(Object* sender);
|
||||
|
|
|
@ -1,8 +1,35 @@
|
|||
#include "PerformanceTouchesTest.h"
|
||||
|
||||
// Enable profiles for this file
|
||||
#undef CC_PROFILER_DISPLAY_TIMERS
|
||||
#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()
|
||||
#undef CC_PROFILER_PURGE_ALL
|
||||
#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()
|
||||
|
||||
#undef CC_PROFILER_START
|
||||
#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)
|
||||
#undef CC_PROFILER_STOP
|
||||
#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)
|
||||
#undef CC_PROFILER_RESET
|
||||
#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)
|
||||
|
||||
#undef CC_PROFILER_START_CATEGORY
|
||||
#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0)
|
||||
#undef CC_PROFILER_STOP_CATEGORY
|
||||
#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0)
|
||||
#undef CC_PROFILER_RESET_CATEGORY
|
||||
#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0)
|
||||
|
||||
#undef CC_PROFILER_START_INSTANCE
|
||||
#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
|
||||
#undef CC_PROFILER_STOP_INSTANCE
|
||||
#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
|
||||
#undef CC_PROFILER_RESET_INSTANCE
|
||||
#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
|
||||
|
||||
enum
|
||||
{
|
||||
TEST_COUNT = 2,
|
||||
TEST_COUNT = 3,
|
||||
};
|
||||
|
||||
static int s_nTouchCurCase = 0;
|
||||
|
@ -23,6 +50,9 @@ void TouchesMainScene::showCurrentTest()
|
|||
case 1:
|
||||
layer = new TouchesPerformTest2(true, TEST_COUNT, _curCase);
|
||||
break;
|
||||
case 2:
|
||||
layer = new TouchesPerformTest3(true, TEST_COUNT, _curCase);
|
||||
break;
|
||||
}
|
||||
s_nTouchCurCase = _curCase;
|
||||
|
||||
|
@ -90,18 +120,8 @@ void TouchesPerformTest1::onEnter()
|
|||
{
|
||||
TouchesMainScene::onEnter();
|
||||
setTouchEnabled(true);
|
||||
|
||||
// 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);
|
||||
|
||||
EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
_touchListener = listener;
|
||||
setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
|
||||
setSwallowsTouches(true);
|
||||
}
|
||||
|
||||
std::string TouchesPerformTest1::title()
|
||||
|
@ -139,16 +159,6 @@ void TouchesPerformTest2::onEnter()
|
|||
{
|
||||
TouchesMainScene::onEnter();
|
||||
setTouchEnabled(true);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
std::string TouchesPerformTest2::title()
|
||||
|
@ -156,12 +166,6 @@ std::string TouchesPerformTest2::title()
|
|||
return "Standard touches";
|
||||
}
|
||||
|
||||
//void TouchesPerformTest2::registerWithTouchDispatcher()
|
||||
//{
|
||||
// auto director = Director::getInstance();
|
||||
// director->getTouchDispatcher()->addStandardDelegate(this, 0);
|
||||
//}
|
||||
|
||||
void TouchesPerformTest2::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
|
||||
{
|
||||
numberOfTouchesB += touches.size();
|
||||
|
@ -181,6 +185,116 @@ void TouchesPerformTest2::onTouchesCancelled(const std::vector<Touch*>& touches,
|
|||
numberOfTouchesC += touches.size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
//
|
||||
// TouchesPerformTest3
|
||||
//
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
class TouchableLayer : public Layer
|
||||
{
|
||||
public:
|
||||
virtual bool onTouchBegan(Touch *touch, Event *event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void onTouchMoved(Touch *touch, Event *event) {}
|
||||
virtual void onTouchEnded(Touch *touch, Event *event) {}
|
||||
virtual void onTouchCancelled(Touch *touch, Event *event) {}
|
||||
|
||||
virtual void onTouchesBegan(const std::vector<Touch*>& touches, Event *event) {}
|
||||
virtual void onTouchesMoved(const std::vector<Touch*>& touches, Event *event) {}
|
||||
virtual void onTouchesEnded(const std::vector<Touch*>& touches, Event *event) {}
|
||||
virtual void onTouchesCancelled(const std::vector<Touch*>&touches, Event *event) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void TouchesPerformTest3::onEnter()
|
||||
{
|
||||
PerformBasicLayer::onEnter();
|
||||
CC_PROFILER_PURGE_ALL();
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
// add title
|
||||
auto label = LabelTTF::create(title().c_str(), "Arial", 32);
|
||||
addChild(label, 1);
|
||||
label->setPosition(Point(s.width/2, s.height-50));
|
||||
|
||||
#define TOUCH_PROFILER_NAME "TouchProfileName"
|
||||
#define TOUCHABLE_NODE_NUM 1000
|
||||
|
||||
for (int i = 0; i < TOUCHABLE_NODE_NUM; ++i)
|
||||
{
|
||||
int zorder = rand() % TOUCHABLE_NODE_NUM;
|
||||
auto layer = new TouchableLayer();
|
||||
layer->setTouchEnabled(true);
|
||||
layer->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);
|
||||
addChild(layer, zorder);
|
||||
layer->release();
|
||||
}
|
||||
|
||||
std::vector<Touch*> touches;
|
||||
for (int i = 0; i < TouchEvent::MAX_TOUCHES; ++i)
|
||||
{
|
||||
Touch* touch = new Touch();
|
||||
touch->setTouchInfo(i, (i+1) * 10, (i+1) * 20);
|
||||
touches.push_back(touch);
|
||||
}
|
||||
|
||||
TouchEvent event;
|
||||
event.setEventCode(TouchEvent::EventCode::BEGAN);
|
||||
event.setTouches(touches);
|
||||
|
||||
auto dispatcher = EventDispatcher::getInstance();
|
||||
|
||||
CC_PROFILER_START(TOUCH_PROFILER_NAME);
|
||||
|
||||
dispatcher->dispatchEvent(&event);
|
||||
|
||||
CC_PROFILER_STOP(TOUCH_PROFILER_NAME);
|
||||
|
||||
CC_PROFILER_DISPLAY_TIMERS();
|
||||
|
||||
for (auto& touch : touches)
|
||||
{
|
||||
touch->release();
|
||||
}
|
||||
}
|
||||
|
||||
std::string TouchesPerformTest3::title()
|
||||
{
|
||||
return "Touch Event Perf Test";
|
||||
}
|
||||
|
||||
void TouchesPerformTest3::showCurrentTest()
|
||||
{
|
||||
Layer* layer = NULL;
|
||||
switch (_curCase)
|
||||
{
|
||||
case 0:
|
||||
layer = new TouchesPerformTest1(true, TEST_COUNT, _curCase);
|
||||
break;
|
||||
case 1:
|
||||
layer = new TouchesPerformTest2(true, TEST_COUNT, _curCase);
|
||||
break;
|
||||
case 2:
|
||||
layer = new TouchesPerformTest3(true, TEST_COUNT, _curCase);
|
||||
break;
|
||||
}
|
||||
s_nTouchCurCase = _curCase;
|
||||
|
||||
if (layer)
|
||||
{
|
||||
auto scene = Scene::create();
|
||||
scene->addChild(layer);
|
||||
layer->release();
|
||||
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
}
|
||||
|
||||
void runTouchesTest()
|
||||
{
|
||||
s_nTouchCurCase = 0;
|
||||
|
|
|
@ -11,10 +11,10 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void showCurrentTest();
|
||||
virtual void onEnter();
|
||||
virtual void showCurrentTest() override;
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title();
|
||||
virtual void update(float dt);
|
||||
virtual void update(float dt) override;
|
||||
|
||||
protected:
|
||||
LabelBMFont * _plabel;
|
||||
|
@ -33,14 +33,13 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void onEnter();
|
||||
virtual std::string title();
|
||||
// virtual void registerWithTouchDispatcher();
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() override;
|
||||
|
||||
virtual bool onTouchBegan(Touch* touch, Event* event);
|
||||
virtual void onTouchMoved(Touch* touch, Event* event);
|
||||
virtual void onTouchEnded(Touch* touch, Event* event);
|
||||
virtual void onTouchCancelled(Touch* touch, Event* event);
|
||||
virtual bool onTouchBegan(Touch* touch, Event* event) override;
|
||||
virtual void onTouchMoved(Touch* touch, Event* event) override;
|
||||
virtual void onTouchEnded(Touch* touch, Event* event) override;
|
||||
virtual void onTouchCancelled(Touch* touch, Event* event) override;
|
||||
};
|
||||
|
||||
class TouchesPerformTest2 : public TouchesMainScene
|
||||
|
@ -51,14 +50,26 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void onEnter();
|
||||
virtual std::string title();
|
||||
// virtual void registerWithTouchDispatcher();
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title() override;
|
||||
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event* event);
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event* event);
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
void onTouchesCancelled(const std::vector<Touch*>& touches, Event* event);
|
||||
void onTouchesBegan(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesMoved(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
||||
void onTouchesCancelled(const std::vector<Touch*>& touches, Event* event) override;
|
||||
};
|
||||
|
||||
class TouchesPerformTest3 : public PerformBasicLayer
|
||||
{
|
||||
public:
|
||||
TouchesPerformTest3(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0)
|
||||
: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string title();
|
||||
virtual void showCurrentTest() override;
|
||||
};
|
||||
|
||||
void runTouchesTest();
|
||||
|
|
Loading…
Reference in New Issue