axmol/tests/cpp-tests/Classes/PerformanceTest/PerformanceEventDispatcherT...

747 lines
26 KiB
C++
Raw Normal View History

//
// PerformanceEventDispatcherTest.cpp
//
#include "PerformanceEventDispatcherTest.h"
#include <algorithm>
2015-04-09 12:23:47 +08:00
USING_NS_CC;
// 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)
PerformceEventDispatcherTests::PerformceEventDispatcherTests()
{
ADD_TEST_CASE(TouchEventDispatchingPerfTest);
ADD_TEST_CASE(KeyboardEventDispatchingPerfTest);
ADD_TEST_CASE(CustomEventDispatchingPerfTest);
}
enum {
kTagInfoLayer = 1,
kTagBase = 20000,
};
enum {
kMaxNodes = 15000,
kNodesIncrease = 500,
};
int PerformanceEventDispatcherScene::quantityOfNodes = kNodesIncrease;
////////////////////////////////////////////////////////
//
// PerformanceEventDispatcherScene
//
////////////////////////////////////////////////////////
bool PerformanceEventDispatcherScene::init()
{
if (TestCase::init())
{
initWithQuantityOfNodes(quantityOfNodes);
return true;
}
return false;
}
void PerformanceEventDispatcherScene::initWithQuantityOfNodes(unsigned int nNodes)
{
_type = 0;
2014-03-20 16:24:55 +08:00
srand((unsigned)time(nullptr));
auto s = Director::getInstance()->getWinSize();
_lastRenderedCount = 0;
_currentQuantityOfNodes = 0;
quantityOfNodes = nNodes;
MenuItemFont::setFontSize(65);
auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) {
quantityOfNodes -= kNodesIncrease;
if( quantityOfNodes < 0 )
quantityOfNodes = 0;
updateQuantityLabel();
updateQuantityOfNodes();
updateProfilerName();
CC_PROFILER_PURGE_ALL();
srand(0);
});
decrease->setColor(Color3B(0,200,20));
_decrease = decrease;
auto increase = MenuItemFont::create(" + ", [&](Ref *sender) {
quantityOfNodes += kNodesIncrease;
if( quantityOfNodes > kMaxNodes )
quantityOfNodes = kMaxNodes;
updateQuantityLabel();
updateQuantityOfNodes();
updateProfilerName();
CC_PROFILER_PURGE_ALL();
srand(0);
});
increase->setColor(Color3B(0,200,20));
_increase = increase;
auto menu = Menu::create(decrease, increase, nullptr);
menu->alignItemsHorizontally();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
menu->setPosition(Vec2(s.width/2, s.height/2+15));
addChild(menu, 1);
auto infoLabel = Label::createWithTTF("0 listeners", "fonts/Marker Felt.ttf", 30);
infoLabel->setColor(Color3B(0,200,20));
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
infoLabel->setPosition(Vec2(s.width/2, s.height/2-15));
addChild(infoLabel, 1, kTagInfoLayer);
int oldFontSize = MenuItemFont::getFontSize();
MenuItemFont::setFontSize(24);
Vector<cocos2d::MenuItem *> toggleItems;
generateTestFunctions();
CCASSERT(!_testFunctions.empty(), "Should not be empty after generate test functions");
for (const auto& f : _testFunctions)
{
toggleItems.pushBack(MenuItemFont::create(f.name));
}
auto reset = [this](){
// Removes all nodes
for (auto& node : _nodes)
{
node->removeFromParent();
}
_nodes.clear();
// Removes all fixed listeners
for (auto& listener : _fixedPriorityListeners)
{
Director::getInstance()->getEventDispatcher()->removeEventListener(listener);
}
this->_lastRenderedCount = 0;
};
auto toggle = MenuItemToggle::createWithCallback([=](Ref* sender){
auto toggle = static_cast<MenuItemToggle*>(sender);
this->_type = toggle->getSelectedIndex();
_subtitleLabel->setString(StringUtils::format("Test '%s', See console", this->_testFunctions[this->_type].name));
this->updateProfilerName();
reset();
}, toggleItems);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
toggle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
toggle->setPosition(VisibleRect::left());
_toggle = toggle;
auto start = MenuItemFont::create("start", [this](Ref* sender){
auto director = Director::getInstance();
auto sched = director->getScheduler();
CC_PROFILER_PURGE_ALL();
sched->schedule(CC_SCHEDULE_SELECTOR(PerformanceEventDispatcherScene::dumpProfilerInfo), this, 2, false);
this->unscheduleUpdate();
this->scheduleUpdate();
this->_startItem->setEnabled(false);
this->_stopItem->setEnabled(true);
this->_toggle->setEnabled(false);
this->_increase->setEnabled(false);
this->_decrease->setEnabled(false);
});
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
start->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
start->setPosition(VisibleRect::right() + Vec2(0, 40));
_startItem = start;
auto stop = MenuItemFont::create("stop", [=](Ref* sender){
auto director = Director::getInstance();
auto sched = director->getScheduler();
sched->unschedule(CC_SCHEDULE_SELECTOR(PerformanceEventDispatcherScene::dumpProfilerInfo), this);
this->unscheduleUpdate();
this->_startItem->setEnabled(true);
this->_stopItem->setEnabled(false);
this->_toggle->setEnabled(true);
this->_increase->setEnabled(true);
this->_decrease->setEnabled(true);
reset();
});
stop->setEnabled(false);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
stop->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
stop->setPosition(VisibleRect::right() + Vec2(0, -40));
_stopItem = stop;
auto menu2 = Menu::create(toggle, start, stop, nullptr);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
menu2->setPosition(Vec2::ZERO);
addChild(menu2);
MenuItemFont::setFontSize(oldFontSize);
updateQuantityLabel();
updateQuantityOfNodes();
updateProfilerName();
}
std::string PerformanceEventDispatcherScene::title() const
{
return "No title";
}
std::string PerformanceEventDispatcherScene::subtitle() const
{
return "";
}
void PerformanceEventDispatcherScene::updateQuantityLabel()
{
if( quantityOfNodes != _lastRenderedCount )
{
auto infoLabel = static_cast<Label*>( getChildByTag(kTagInfoLayer) );
char str[20] = {0};
sprintf(str, "%u listeners", quantityOfNodes);
infoLabel->setString(str);
}
}
const char * PerformanceEventDispatcherScene::profilerName()
{
return _profilerName;
}
void PerformanceEventDispatcherScene::updateProfilerName()
{
snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), quantityOfNodes);
}
void PerformanceEventDispatcherScene::dumpProfilerInfo(float dt)
{
CC_PROFILER_DISPLAY_TIMERS();
}
void PerformanceEventDispatcherScene::update(float dt)
{
_testFunctions[_type].func();
}
void PerformanceEventDispatcherScene::updateQuantityOfNodes()
{
_currentQuantityOfNodes = quantityOfNodes;
}
const char* PerformanceEventDispatcherScene::testName()
{
return _testFunctions[_type].name;
}
////////////////////////////////////////////////////////
//
// TouchEventDispatchingPerfTest
//
////////////////////////////////////////////////////////
void TouchEventDispatchingPerfTest::generateTestFunctions()
{
TestFunction testFunctions[] = {
{ "OneByOne-scenegraph", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event* event){
return false;
};
listener->onTouchMoved = [](Touch* touch, Event* event){};
listener->onTouchEnded = [](Touch* touch, Event* event){};
// Create new touchable nodes
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(1000 + i);
this->addChild(node);
this->_nodes.push_back(node);
dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node);
}
_lastRenderedCount = quantityOfNodes;
}
Size size = Director::getInstance()->getWinSize();
EventTouch touchEvent;
touchEvent.setEventCode(EventTouch::EventCode::BEGAN);
std::vector<Touch*> touches;
for (int i = 0; i < 4; ++i)
{
Touch* touch = new (std::nothrow) Touch();
touch->autorelease();
touch->setTouchInfo(i, rand() % 200, rand() % 200);
touches.push_back(touch);
}
touchEvent.setTouches(touches);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&touchEvent);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "OneByOne-fixed", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event* event){
return false;
};
listener->onTouchMoved = [](Touch* touch, Event* event){};
listener->onTouchEnded = [](Touch* touch, Event* event){};
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto l = listener->clone();
this->_fixedPriorityListeners.push_back(l);
dispatcher->addEventListenerWithFixedPriority(l, i+1);
}
_lastRenderedCount = quantityOfNodes;
}
Size size = Director::getInstance()->getWinSize();
EventTouch touchEvent;
touchEvent.setEventCode(EventTouch::EventCode::BEGAN);
std::vector<Touch*> touches;
for (int i = 0; i < 4; ++i)
{
Touch* touch = new (std::nothrow) Touch();
touch->autorelease();
touch->setTouchInfo(i, rand() % 200, rand() % 200);
touches.push_back(touch);
}
touchEvent.setTouches(touches);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&touchEvent);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "AllAtOnce-scenegraph", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){};
listener->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){};
listener->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){};
// Create new touchable nodes
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(1000 + i);
this->addChild(node);
this->_nodes.push_back(node);
dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node);
}
_lastRenderedCount = quantityOfNodes;
}
Size size = Director::getInstance()->getWinSize();
EventTouch touchEvent;
touchEvent.setEventCode(EventTouch::EventCode::BEGAN);
std::vector<Touch*> touches;
for (int i = 0; i < 4; ++i)
{
Touch* touch = new (std::nothrow) Touch();
touch->autorelease();
touch->setTouchInfo(i, rand() % 200, rand() % 200);
touches.push_back(touch);
}
touchEvent.setTouches(touches);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&touchEvent);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "AllAtOnce-fixed", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){};
listener->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){};
listener->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){};
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto l = listener->clone();
this->_fixedPriorityListeners.push_back(l);
dispatcher->addEventListenerWithFixedPriority(l, i+1);
}
_lastRenderedCount = quantityOfNodes;
}
Size size = Director::getInstance()->getWinSize();
EventTouch touchEvent;
touchEvent.setEventCode(EventTouch::EventCode::BEGAN);
std::vector<Touch*> touches;
for (int i = 0; i < 4; ++i)
{
Touch* touch = new (std::nothrow) Touch();
touch->autorelease();
touch->setTouchInfo(i, rand() % 200, rand() % 200);
touches.push_back(touch);
}
touchEvent.setTouches(touches);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&touchEvent);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "TouchModeMix-scenegraph", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listenerOneByOne = EventListenerTouchOneByOne::create();
listenerOneByOne->onTouchBegan = [](Touch* touch, Event* event){
return false;
};
listenerOneByOne->onTouchMoved = [](Touch* touch, Event* event){};
listenerOneByOne->onTouchEnded = [](Touch* touch, Event* event){};
auto listenerAllAtOnce = EventListenerTouchAllAtOnce::create();
listenerAllAtOnce->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){};
listenerAllAtOnce->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){};
listenerAllAtOnce->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){};
int i = 0;
// Create new touchable nodes
for (; i < this->quantityOfNodes/2; ++i)
{
auto node = Node::create();
node->setTag(1000 + i);
this->addChild(node);
this->_nodes.push_back(node);
dispatcher->addEventListenerWithSceneGraphPriority(listenerOneByOne->clone(), node);
}
for (; i < this->quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(1000 + i);
this->addChild(node);
this->_nodes.push_back(node);
dispatcher->addEventListenerWithSceneGraphPriority(listenerAllAtOnce->clone(), node);
}
_lastRenderedCount = quantityOfNodes;
}
Size size = Director::getInstance()->getWinSize();
EventTouch touchEvent;
touchEvent.setEventCode(EventTouch::EventCode::BEGAN);
std::vector<Touch*> touches;
for (int i = 0; i < 4; ++i)
{
Touch* touch = new (std::nothrow) Touch();
touch->autorelease();
touch->setTouchInfo(i, rand() % 200, rand() % 200);
touches.push_back(touch);
}
touchEvent.setTouches(touches);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&touchEvent);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "TouchModeMix-fixed", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listenerOneByOne = EventListenerTouchOneByOne::create();
listenerOneByOne->onTouchBegan = [](Touch* touch, Event* event){
return false;
};
listenerOneByOne->onTouchMoved = [](Touch* touch, Event* event){};
listenerOneByOne->onTouchEnded = [](Touch* touch, Event* event){};
auto listenerAllAtOnce = EventListenerTouchAllAtOnce::create();
listenerAllAtOnce->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){};
listenerAllAtOnce->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){};
listenerAllAtOnce->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){};
int i = 0;
for (; i < this->quantityOfNodes/2; ++i)
{
auto l = listenerOneByOne->clone();
this->_fixedPriorityListeners.push_back(l);
dispatcher->addEventListenerWithFixedPriority(l, i+1);
}
for (; i < this->quantityOfNodes; ++i)
{
auto l = listenerAllAtOnce->clone();
this->_fixedPriorityListeners.push_back(l);
dispatcher->addEventListenerWithFixedPriority(l, i+1);
}
_lastRenderedCount = quantityOfNodes;
}
Size size = Director::getInstance()->getWinSize();
EventTouch touchEvent;
touchEvent.setEventCode(EventTouch::EventCode::BEGAN);
std::vector<Touch*> touches;
for (int i = 0; i < 4; ++i)
{
Touch* touch = new (std::nothrow) Touch();
touch->autorelease();
touch->setTouchInfo(i, rand() % 200, rand() % 200);
touches.push_back(touch);
}
touchEvent.setTouches(touches);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&touchEvent);
CC_PROFILER_STOP(this->profilerName());
} } ,
};
for (const auto& func : testFunctions)
{
_testFunctions.push_back(func);
}
}
std::string TouchEventDispatchingPerfTest::title() const
{
return "Touch Event Dispatching Perf test";
}
std::string TouchEventDispatchingPerfTest::subtitle() const
{
return "Test 'OneByOne-scenegraph', See console";
}
////////////////////////////////////////////////////////
//
// KeyboardEventDispatchingPerfTest
//
////////////////////////////////////////////////////////
void KeyboardEventDispatchingPerfTest::generateTestFunctions()
{
TestFunction testFunctions[] = {
{ "keyboard-scenegraph", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event){};
listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event){};
// Create new nodes listen to keyboard event
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(1000 + i);
this->addChild(node);
this->_nodes.push_back(node);
dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node);
}
_lastRenderedCount = quantityOfNodes;
}
EventKeyboard event(EventKeyboard::KeyCode::KEY_RETURN, true);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&event);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "keyboard-fixed", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event){};
listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event){};
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto l = listener->clone();
this->_fixedPriorityListeners.push_back(l);
dispatcher->addEventListenerWithFixedPriority(l, i+1);
}
_lastRenderedCount = quantityOfNodes;
}
EventKeyboard event(EventKeyboard::KeyCode::KEY_RETURN, true);
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&event);
CC_PROFILER_STOP(this->profilerName());
} } ,
};
for (const auto& func : testFunctions)
{
_testFunctions.push_back(func);
}
}
std::string KeyboardEventDispatchingPerfTest::title() const
{
return "Keyboard Event Dispatching Perf test";
}
std::string KeyboardEventDispatchingPerfTest::subtitle() const
{
return "Test 'keyboard-scenegraph', See console";
}
////////////////////////////////////////////////////////
//
// CustomEventDispatchingPerfTest
//
////////////////////////////////////////////////////////
void CustomEventDispatchingPerfTest::onEnter()
{
PerformanceEventDispatcherScene::onEnter();
for (int i = 0; i < 2000; i++)
{
auto listener = EventListenerCustom::create(StringUtils::format("custom_event_%d", i), [](EventCustom* event){});
_eventDispatcher->addEventListenerWithFixedPriority(listener, i + 1);
_customListeners.push_back(listener);
}
}
void CustomEventDispatchingPerfTest::onExit()
{
for (auto& l : _customListeners)
{
_eventDispatcher->removeEventListener(l);
}
PerformanceEventDispatcherScene::onExit();
}
void CustomEventDispatchingPerfTest::generateTestFunctions()
{
TestFunction testFunctions[] = {
{ "custom-scenegraph", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerCustom::create("custom_event_test_scenegraph", [](EventCustom* event){});
// Create new nodes listen to custom event
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto node = Node::create();
node->setTag(1000 + i);
this->addChild(node);
this->_nodes.push_back(node);
dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node);
}
_lastRenderedCount = quantityOfNodes;
}
EventCustom event("custom_event_test_scenegraph");
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&event);
CC_PROFILER_STOP(this->profilerName());
} } ,
{ "custom-fixed", [=](){
auto dispatcher = Director::getInstance()->getEventDispatcher();
if (quantityOfNodes != _lastRenderedCount)
{
auto listener = EventListenerCustom::create("custom_event_test_fixed", [](EventCustom* event){});
for (int i = 0; i < this->quantityOfNodes; ++i)
{
auto l = listener->clone();
this->_fixedPriorityListeners.push_back(l);
dispatcher->addEventListenerWithFixedPriority(l, i+1);
}
_lastRenderedCount = quantityOfNodes;
}
EventCustom event("custom_event_test_fixed");
CC_PROFILER_START(this->profilerName());
dispatcher->dispatchEvent(&event);
CC_PROFILER_STOP(this->profilerName());
} } ,
};
for (const auto& func : testFunctions)
{
_testFunctions.push_back(func);
}
}
std::string CustomEventDispatchingPerfTest::title() const
{
return "Custom Event Dispatching Perf test";
}
std::string CustomEventDispatchingPerfTest::subtitle() const
{
return "Test 'custom-scenegraph', See console";
}