From 9329ba1b379e347899d1d9b31a97aa906efa0e42 Mon Sep 17 00:00:00 2001 From: songchengjiang Date: Thu, 19 Mar 2015 12:32:53 +0800 Subject: [PATCH 1/7] add particle3D performance Test --- .../PerformanceParticle3DTest.cpp | 219 ++++++++++++++++++ .../PerformanceParticle3DTest.h | 42 ++++ .../PerformanceTest/PerformanceTest.cpp | 2 + tests/cpp-tests/proj.win32/cpp-tests.vcxproj | 8 +- .../proj.win32/cpp-tests.vcxproj.filters | 14 +- 5 files changed, 278 insertions(+), 7 deletions(-) create mode 100644 tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp create mode 100644 tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp new file mode 100644 index 0000000000..8783d4fcbb --- /dev/null +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp @@ -0,0 +1,219 @@ +#include "PerformanceParticle3DTest.h" +#include "Particle3D/PU/CCPUParticleSystem3D.h" + + +enum { + kTagInfoLayer = 1, + kTagMainLayer = 2, + kTagLabelAtlas = 3, + kTagMenuLayer = 1000, + kTagParticleSystem = 1001, + TEST_COUNT = 2, +}; + +enum { + kMaxParticles = 14000, + kNodesIncrease = 1, +}; + +static int s_nParCurIdx = 0; + +//////////////////////////////////////////////////////// +// +// ParticleMenuLayer +// +//////////////////////////////////////////////////////// +Particle3DMenuLayer::Particle3DMenuLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase) +: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase) +{ + +} + +void Particle3DMenuLayer::showCurrentTest() +{ + auto scene = (Particle3DMainScene*)getParent(); + int subTest = scene->getSubTestNum(); + int parNum = scene->getParticlesNum(); + + Particle3DMainScene* pNewScene = nullptr; + + switch (_curCase) + { + case 0: + pNewScene = new (std::nothrow) Particle3DPerformTest; + break; + } + + s_nParCurIdx = _curCase; + if (pNewScene) + { + pNewScene->initWithSubTest(subTest, parNum); + + Director::getInstance()->replaceScene(pNewScene); + pNewScene->release(); + } +} + +//////////////////////////////////////////////////////// +// +// ParticleMainScene +// +//////////////////////////////////////////////////////// +void Particle3DMainScene::initWithSubTest(int asubtest, int particles) +{ + //srandom(0); + + subtestNumber = asubtest; + auto s = Director::getInstance()->getWinSize(); + + lastRenderedCount = 0; + quantityParticles = 0; + + MenuItemFont::setFontSize(65); + auto decrease = MenuItemFont::create(" - ", [=](Ref *sender) { + quantityParticles -= kNodesIncrease; + if( quantityParticles < 0 ) + quantityParticles = 0; + + updateQuantityLabel(); + removeChildByTag(kTagParticleSystem + quantityParticles, true); + }); + decrease->setColor(Color3B(0,200,20)); + auto increase = MenuItemFont::create(" + ", [=](Ref *sender) { + quantityParticles += kNodesIncrease; + if( quantityParticles > kMaxParticles ) + quantityParticles = kMaxParticles; + + updateQuantityLabel(); + createParticleSystem(quantityParticles - 1); + }); + increase->setColor(Color3B(0,200,20)); + + auto menu = Menu::create(decrease, increase, nullptr); + menu->alignItemsHorizontally(); + menu->setPosition(Vec2(s.width/2, s.height/2+15)); + addChild(menu, 1); + + auto infoLabel = Label::createWithTTF("0 Particle Systems", "fonts/Marker Felt.ttf", 30); + infoLabel->setColor(Color3B(0,200,20)); + infoLabel->setPosition(Vec2(s.width/2, s.height - 90)); + addChild(infoLabel, 1, kTagInfoLayer); + + //// particles on stage + //auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.'); + //addChild(labelAtlas, 0, kTagLabelAtlas); + //labelAtlas->setPosition(Vec2(s.width-66,50)); + + // Next Prev Test + auto menuLayer = new (std::nothrow) Particle3DMenuLayer(true, TEST_COUNT, s_nParCurIdx); + addChild(menuLayer, 1, kTagMenuLayer); + menuLayer->release(); + + //// Sub Tests + //MenuItemFont::setFontSize(40); + //auto pSubMenu = Menu::create(); + //for (int i = 1; i <= 6; ++i) + //{ + // char str[10] = {0}; + // sprintf(str, "%d ", i); + // auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(Particle3DMainScene::testNCallback, this)); + // itemFont->setTag(i); + // pSubMenu->addChild(itemFont, 10); + + // if (i <= 3) + // { + // itemFont->setColor(Color3B(200,20,20)); + // } + // else + // { + // itemFont->setColor(Color3B(0,200,20)); + // } + //} + //pSubMenu->alignItemsHorizontally(); + //pSubMenu->setPosition(Vec2(s.width/2, 80)); + //addChild(pSubMenu, 2); + + auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); + addChild(label, 1); + label->setPosition(Vec2(s.width/2, s.height-50)); + + auto camera = Camera::createPerspective(30.0f, s.width / s.height, 1.0f, 1000.0f); + camera->setPosition3D(Vec3(0.0f, 0.0f, 150.0f)); + camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f)); + camera->setCameraFlag(CameraFlag::USER1); + this->addChild(camera); + + schedule(CC_SCHEDULE_SELECTOR(Particle3DMainScene::step)); +} + +std::string Particle3DMainScene::title() const +{ + return "No title"; +} + +void Particle3DMainScene::step(float dt) +{ + auto atlas = (LabelAtlas*) getChildByTag(kTagLabelAtlas); +} + +void Particle3DMainScene::createParticleSystem(int idx) +{ + // removeChildByTag(kTagParticleSystem, true); + + auto ps = PUParticleSystem3D::create("Particle3D/scripts/lineStreak.pu", "Particle3D/materials/pu_mediapack_01.material"); + ps->setCameraMask((unsigned short)CameraFlag::USER1); + ps->setPosition(CCRANDOM_MINUS1_1() * 50.0f, CCRANDOM_MINUS1_1() * 20.0f); + ps->startParticleSystem(); + addChild(ps, 0, kTagParticleSystem + idx); + + + //doTest(); +} + +void Particle3DMainScene::testNCallback(Ref* sender) +{ + subtestNumber = static_cast(sender)->getTag(); + + auto menu = static_cast( getChildByTag(kTagMenuLayer) ); + menu->restartCallback(sender); +} + +void Particle3DMainScene::updateQuantityLabel() +{ + if( quantityParticles != lastRenderedCount ) + { + auto infoLabel = (Label *) getChildByTag(kTagInfoLayer); + char str[20] = {0}; + sprintf(str, "%u Particle Systems", quantityParticles); + infoLabel->setString(str); + + lastRenderedCount = quantityParticles; + } +} + +//////////////////////////////////////////////////////// +// +// ParticlePerformTest1 +// +//////////////////////////////////////////////////////// +std::string Particle3DPerformTest::title() const +{ + char str[20] = {0}; + sprintf(str, "Particle3D Test"/*, subtestNumber*/); + std::string strRet = str; + return strRet; +} + +void Particle3DPerformTest::doTest() +{ + auto s = Director::getInstance()->getWinSize(); +} + +void runParticle3DTest() +{ + auto scene = new (std::nothrow) Particle3DPerformTest; + scene->initWithSubTest(1, kNodesIncrease); + + Director::getInstance()->replaceScene(scene); + scene->release(); +} diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h new file mode 100644 index 0000000000..059709f3a3 --- /dev/null +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h @@ -0,0 +1,42 @@ +#ifndef __PERFORMANCE_PARTICLE_3D_TEST_H__ +#define __PERFORMANCE_PARTICLE_3D_TEST_H__ + +#include "PerformanceTest.h" + +class Particle3DMenuLayer : public PerformBasicLayer +{ +public: + Particle3DMenuLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0); + virtual void showCurrentTest(); +}; + +class Particle3DMainScene : public Scene +{ +public: + virtual void initWithSubTest(int subtest, int particles); + virtual std::string title() const; + + void step(float dt); + void createParticleSystem(int idx); + void testNCallback(Ref* sender); + void updateQuantityLabel(); + int getSubTestNum() { return subtestNumber; } + int getParticlesNum() { return quantityParticles; } + virtual void doTest() = 0; + +protected: + int lastRenderedCount; + int quantityParticles; + int subtestNumber; +}; + +class Particle3DPerformTest : public Particle3DMainScene +{ +public: + virtual std::string title() const override; + virtual void doTest(); +}; + +void runParticle3DTest(); + +#endif diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp index 879ae302a5..aad3bb63f1 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceTest.cpp @@ -2,6 +2,7 @@ #include "../testResource.h" #include "PerformanceNodeChildrenTest.h" #include "PerformanceParticleTest.h" +#include "PerformanceParticle3DTest.h" #include "PerformanceSpriteTest.h" #include "PerformanceTextureTest.h" #include "PerformanceTouchesTest.h" @@ -28,6 +29,7 @@ struct { { "Alloc Test", [](Ref*sender){runAllocPerformanceTest(); } }, { "NodeChildren Test", [](Ref*sender){runNodeChildrenTest();} }, { "Particle Test",[](Ref*sender){runParticleTest();} }, + { "Particle3D Perf Test",[](Ref*sender){runParticle3DTest();} }, { "Sprite Perf Test",[](Ref*sender){runSpriteTest();} }, { "Texture Perf Test",[](Ref*sender){runTextureTest();} }, { "Touches Perf Test",[](Ref*sender){runTouchesTest();} }, diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj index a682d1bfc3..fa6a0837f5 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj @@ -1,4 +1,4 @@ - + @@ -189,12 +189,13 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y - + + @@ -388,12 +389,13 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y - + + diff --git a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters index e2eb2095b9..96321e51f7 100644 --- a/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters +++ b/tests/cpp-tests/proj.win32/cpp-tests.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -345,7 +345,7 @@ {e4104916-24d0-49b8-a864-d273ea13a248} - + {65be3b70-58d6-47f4-bc67-fac9ee134c42} @@ -905,7 +905,7 @@ Classes\CocosStudio3DTest - + Classes\PerformanceTest @@ -921,6 +921,9 @@ Classes\AllocatorTest + + Classes\PerformanceTest + @@ -1672,7 +1675,7 @@ Classes\CocosStudio3DTest - + Classes\PerformanceTest @@ -1688,5 +1691,8 @@ Classes\AllocatorTest + + Classes\PerformanceTest + \ No newline at end of file From b6a29d80ded32dd99c16bc604bf276b2f9f9c41b Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 19 Mar 2015 14:43:29 +0800 Subject: [PATCH 2/7] 3d particle performance test --- build/cocos2d_tests.xcodeproj/project.pbxproj | 8 ++ tests/cpp-tests/CMakeLists.txt | 1 + .../PerformanceParticle3DTest.cpp | 104 ++++++++---------- .../PerformanceParticle3DTest.h | 13 ++- tests/cpp-tests/proj.android/jni/Android.mk | 1 + 5 files changed, 65 insertions(+), 62 deletions(-) diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 2ee8484e39..19cd2ecf4e 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -816,6 +816,8 @@ B2507B6C192589AF00FA4972 /* Shaders3D in Resources */ = {isa = PBXBuildFile; fileRef = B2507B6A192589AF00FA4972 /* Shaders3D */; }; B609E67319C18DAD003D0074 /* BillBoardTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B609E67119C18DAD003D0074 /* BillBoardTest.cpp */; }; B609E67419C18DAD003D0074 /* BillBoardTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B609E67119C18DAD003D0074 /* BillBoardTest.cpp */; }; + B6337DF71ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6337DF51ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp */; }; + B6337DF81ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B6337DF51ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp */; }; B639932E1A490EC700B07923 /* Particle3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B639932C1A490EC700B07923 /* Particle3DTest.cpp */; }; B639932F1A490EC700B07923 /* Particle3DTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B639932C1A490EC700B07923 /* Particle3DTest.cpp */; }; B63993311A49359F00B07923 /* Particle3D in Resources */ = {isa = PBXBuildFile; fileRef = B63993301A49359F00B07923 /* Particle3D */; }; @@ -1752,6 +1754,8 @@ B2507B6A192589AF00FA4972 /* Shaders3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Shaders3D; path = "../tests/cpp-tests/Resources/Shaders3D"; sourceTree = ""; }; B609E67119C18DAD003D0074 /* BillBoardTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BillBoardTest.cpp; path = BillBoardTest/BillBoardTest.cpp; sourceTree = ""; }; B609E67219C18DAD003D0074 /* BillBoardTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BillBoardTest.h; path = BillBoardTest/BillBoardTest.h; sourceTree = ""; }; + B6337DF51ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceParticle3DTest.cpp; sourceTree = ""; }; + B6337DF61ABA9B44005AEF24 /* PerformanceParticle3DTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceParticle3DTest.h; sourceTree = ""; }; B639932C1A490EC700B07923 /* Particle3DTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Particle3DTest.cpp; path = Particle3DTest/Particle3DTest.cpp; sourceTree = ""; }; B639932D1A490EC700B07923 /* Particle3DTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Particle3DTest.h; path = Particle3DTest/Particle3DTest.h; sourceTree = ""; }; B63993301A49359F00B07923 /* Particle3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Particle3D; path = "../tests/cpp-tests/Resources/Particle3D"; sourceTree = ""; }; @@ -2939,6 +2943,8 @@ 1AC35AC118CECF0C00F37B72 /* PerformanceTest */ = { isa = PBXGroup; children = ( + B6337DF51ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp */, + B6337DF61ABA9B44005AEF24 /* PerformanceParticle3DTest.h */, 1AC35AC218CECF0C00F37B72 /* PerformanceAllocTest.cpp */, 1AC35AC318CECF0C00F37B72 /* PerformanceAllocTest.h */, 1AF152D718FD252A00A52F3D /* PerformanceCallbackTest.cpp */, @@ -4866,6 +4872,7 @@ 182C5CBA1A95B2FD00C30D34 /* CocosStudio3DTest.cpp in Sources */, 1AC35C5D18CECF0C00F37B72 /* Ball.cpp in Sources */, 1AC35B7B18CECF0C00F37B72 /* GameOverScene.cpp in Sources */, + B6337DF71ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp in Sources */, 1AC35BF318CECF0C00F37B72 /* ExtensionsTest.cpp in Sources */, 1AC35B3518CECF0C00F37B72 /* TestEntries.cpp in Sources */, 1AC35B2D18CECF0C00F37B72 /* Box2dTest.cpp in Sources */, @@ -5118,6 +5125,7 @@ 1AC35C3E18CECF0C00F37B72 /* PhysicsTest.cpp in Sources */, 3825CC4A1A2C982A00C92EA8 /* CustomRootNode.cpp in Sources */, 29080DC6191B595E0066F8DF /* UIScene_Editor.cpp in Sources */, + B6337DF81ABA9B44005AEF24 /* PerformanceParticle3DTest.cpp in Sources */, 29080DB2191B595E0066F8DF /* UILayoutTest.cpp in Sources */, 1AC35B6A18CECF0C00F37B72 /* ButtonTestLayer.cpp in Sources */, 29080DB6191B595E0066F8DF /* UIListViewTest.cpp in Sources */, diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 03eddd91e7..7e5297f19e 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -155,6 +155,7 @@ set(TESTS_SRC Classes/PerformanceTest/PerformanceAllocTest.cpp Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp Classes/PerformanceTest/PerformanceParticleTest.cpp + Classes/PerformanceTest/PerformanceParticle3DTest.cpp Classes/PerformanceTest/PerformanceSpriteTest.cpp Classes/PerformanceTest/PerformanceTest.cpp Classes/PerformanceTest/PerformanceTextureTest.cpp diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp index 8783d4fcbb..eb8da5f321 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp @@ -16,15 +16,15 @@ enum { kNodesIncrease = 1, }; -static int s_nParCurIdx = 0; +static int s_parCurIdx = 0; //////////////////////////////////////////////////////// // // ParticleMenuLayer // //////////////////////////////////////////////////////// -Particle3DMenuLayer::Particle3DMenuLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase) -: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase) +Particle3DMenuLayer::Particle3DMenuLayer(bool isControlMenuVisible, int maxCases, int curCase) +: PerformBasicLayer(isControlMenuVisible, maxCases, curCase) { } @@ -44,7 +44,7 @@ void Particle3DMenuLayer::showCurrentTest() break; } - s_nParCurIdx = _curCase; + s_parCurIdx = _curCase; if (pNewScene) { pNewScene->initWithSubTest(subTest, parNum); @@ -63,29 +63,29 @@ void Particle3DMainScene::initWithSubTest(int asubtest, int particles) { //srandom(0); - subtestNumber = asubtest; + _subtestNumber = asubtest; auto s = Director::getInstance()->getWinSize(); - lastRenderedCount = 0; - quantityParticles = 0; + _lastRenderedCount = 0; + _quantityParticles = 0; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [=](Ref *sender) { - quantityParticles -= kNodesIncrease; - if( quantityParticles < 0 ) - quantityParticles = 0; + _quantityParticles -= kNodesIncrease; + if( _quantityParticles < 0 ) + _quantityParticles = 0; updateQuantityLabel(); - removeChildByTag(kTagParticleSystem + quantityParticles, true); + removeChildByTag(kTagParticleSystem + _quantityParticles, true); }); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [=](Ref *sender) { - quantityParticles += kNodesIncrease; - if( quantityParticles > kMaxParticles ) - quantityParticles = kMaxParticles; + _quantityParticles += kNodesIncrease; + if( _quantityParticles > kMaxParticles ) + _quantityParticles = kMaxParticles; updateQuantityLabel(); - createParticleSystem(quantityParticles - 1); + createParticleSystem(_quantityParticles - 1); }); increase->setColor(Color3B(0,200,20)); @@ -99,40 +99,11 @@ void Particle3DMainScene::initWithSubTest(int asubtest, int particles) infoLabel->setPosition(Vec2(s.width/2, s.height - 90)); addChild(infoLabel, 1, kTagInfoLayer); - //// particles on stage - //auto labelAtlas = LabelAtlas::create("0000", "fps_images.png", 12, 32, '.'); - //addChild(labelAtlas, 0, kTagLabelAtlas); - //labelAtlas->setPosition(Vec2(s.width-66,50)); - // Next Prev Test - auto menuLayer = new (std::nothrow) Particle3DMenuLayer(true, TEST_COUNT, s_nParCurIdx); + auto menuLayer = new (std::nothrow) Particle3DMenuLayer(true, TEST_COUNT, s_parCurIdx); addChild(menuLayer, 1, kTagMenuLayer); menuLayer->release(); - //// Sub Tests - //MenuItemFont::setFontSize(40); - //auto pSubMenu = Menu::create(); - //for (int i = 1; i <= 6; ++i) - //{ - // char str[10] = {0}; - // sprintf(str, "%d ", i); - // auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(Particle3DMainScene::testNCallback, this)); - // itemFont->setTag(i); - // pSubMenu->addChild(itemFont, 10); - - // if (i <= 3) - // { - // itemFont->setColor(Color3B(200,20,20)); - // } - // else - // { - // itemFont->setColor(Color3B(0,200,20)); - // } - //} - //pSubMenu->alignItemsHorizontally(); - //pSubMenu->setPosition(Vec2(s.width/2, 80)); - //addChild(pSubMenu, 2); - auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); addChild(label, 1); label->setPosition(Vec2(s.width/2, s.height-50)); @@ -143,6 +114,15 @@ void Particle3DMainScene::initWithSubTest(int asubtest, int particles) camera->setCameraFlag(CameraFlag::USER1); this->addChild(camera); + TTFConfig config("fonts/tahoma.ttf",10); + _particleLab = Label::createWithTTF(config,"Particle Count: 0",TextHAlignment::LEFT); + _particleLab->setPosition(Vec2(0.0f, s.height / 6.0f)); + _particleLab->setAnchorPoint(Vec2(0.0f, 0.0f)); + this->addChild(_particleLab); + _quantityParticles = 1; + updateQuantityLabel(); + createParticleSystem(_quantityParticles - 1); + schedule(CC_SCHEDULE_SELECTOR(Particle3DMainScene::step)); } @@ -153,26 +133,38 @@ std::string Particle3DMainScene::title() const void Particle3DMainScene::step(float dt) { - auto atlas = (LabelAtlas*) getChildByTag(kTagLabelAtlas); + unsigned int count = 0; + for (int i = 0; i < _quantityParticles; i++) + { + ParticleSystem3D *ps = static_cast(this->getChildByTag(kTagParticleSystem + i)); + if (ps){ + auto children = ps->getChildren(); + for (auto iter : children){ + ParticleSystem3D *child = dynamic_cast(iter); + if (child){ + count += child->getAliveParticleCount(); + } + } + + char str[128]; + sprintf(str, "Particle Count: %d", count); + _particleLab->setString(str); + } + } } void Particle3DMainScene::createParticleSystem(int idx) { - // removeChildByTag(kTagParticleSystem, true); - - auto ps = PUParticleSystem3D::create("Particle3D/scripts/lineStreak.pu", "Particle3D/materials/pu_mediapack_01.material"); + auto ps = PUParticleSystem3D::create("Particle3D/scripts/example_004.pu", "Particle3D/materials/pu_example.material"); ps->setCameraMask((unsigned short)CameraFlag::USER1); ps->setPosition(CCRANDOM_MINUS1_1() * 50.0f, CCRANDOM_MINUS1_1() * 20.0f); ps->startParticleSystem(); addChild(ps, 0, kTagParticleSystem + idx); - - - //doTest(); } void Particle3DMainScene::testNCallback(Ref* sender) { - subtestNumber = static_cast(sender)->getTag(); + _subtestNumber = static_cast(sender)->getTag(); auto menu = static_cast( getChildByTag(kTagMenuLayer) ); menu->restartCallback(sender); @@ -180,14 +172,14 @@ void Particle3DMainScene::testNCallback(Ref* sender) void Particle3DMainScene::updateQuantityLabel() { - if( quantityParticles != lastRenderedCount ) + if( _quantityParticles != _lastRenderedCount ) { auto infoLabel = (Label *) getChildByTag(kTagInfoLayer); char str[20] = {0}; - sprintf(str, "%u Particle Systems", quantityParticles); + sprintf(str, "%u Particle Systems", _quantityParticles); infoLabel->setString(str); - lastRenderedCount = quantityParticles; + _lastRenderedCount = _quantityParticles; } } diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h index 059709f3a3..fc8f4395f3 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.h @@ -6,7 +6,7 @@ class Particle3DMenuLayer : public PerformBasicLayer { public: - Particle3DMenuLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0); + Particle3DMenuLayer(bool isControlMenuVisible, int maxCases = 0, int curCase = 0); virtual void showCurrentTest(); }; @@ -20,14 +20,15 @@ public: void createParticleSystem(int idx); void testNCallback(Ref* sender); void updateQuantityLabel(); - int getSubTestNum() { return subtestNumber; } - int getParticlesNum() { return quantityParticles; } + int getSubTestNum() { return _subtestNumber; } + int getParticlesNum() { return _quantityParticles; } virtual void doTest() = 0; protected: - int lastRenderedCount; - int quantityParticles; - int subtestNumber; + int _lastRenderedCount; + int _quantityParticles; + int _subtestNumber; + cocos2d::Label *_particleLab; }; class Particle3DPerformTest : public Particle3DMainScene diff --git a/tests/cpp-tests/proj.android/jni/Android.mk b/tests/cpp-tests/proj.android/jni/Android.mk index bc30532323..d84f740630 100644 --- a/tests/cpp-tests/proj.android/jni/Android.mk +++ b/tests/cpp-tests/proj.android/jni/Android.mk @@ -158,6 +158,7 @@ LOCAL_SRC_FILES := main.cpp \ ../../Classes/PerformanceTest/PerformanceAllocTest.cpp \ ../../Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp \ ../../Classes/PerformanceTest/PerformanceParticleTest.cpp \ +../../Classes/PerformanceTest/PerformanceParticle3DTest.cpp \ ../../Classes/PerformanceTest/PerformanceSpriteTest.cpp \ ../../Classes/PerformanceTest/PerformanceTest.cpp \ ../../Classes/PerformanceTest/PerformanceTextureTest.cpp \ From 0106c1184ec5c0025ef202bd6a0dbbe956f8422c Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 19 Mar 2015 15:00:07 +0800 Subject: [PATCH 3/7] add pu for performance test --- .../Particle3D/scripts/example_004.pu | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/cpp-tests/Resources/Particle3D/scripts/example_004.pu diff --git a/tests/cpp-tests/Resources/Particle3D/scripts/example_004.pu b/tests/cpp-tests/Resources/Particle3D/scripts/example_004.pu new file mode 100644 index 0000000000..8004bafa0d --- /dev/null +++ b/tests/cpp-tests/Resources/Particle3D/scripts/example_004.pu @@ -0,0 +1,32 @@ +system example_004 +{ + category Examples_1_10 + technique + { + visual_particle_quota 100 + material ParticleUniverse/Star + default_particle_width 0.6 + default_particle_height 0.6 + renderer Billboard + { + } + emitter SphereSurface + { + emission_rate 60 + time_to_live 1.8 + velocity 0 + direction 0 0 0 + radius 3 + } + affector Colour + { + time_colour 0 1 1 0 1 + time_colour 1 1 0 0 0 + } + affector Gravity + { + mass_affector 0.03 + gravity 150 + } + } +} From 7f18c9809c687c2522d2d069867be8dca2d16077 Mon Sep 17 00:00:00 2001 From: lvlong Date: Thu, 19 Mar 2015 15:02:38 +0800 Subject: [PATCH 4/7] fix :camera-culling MoveTo --- tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 1cb25da673..bb2505003c 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -881,9 +881,11 @@ void CameraCullingDemo::update(float dt) void CameraCullingDemo::reachEndCallBack() { + auto s = Director::getInstance()->getWinSize(); _cameraFirst->stopActionByTag(100); - auto inverse = (MoveTo*)_moveAction->reverse(); + auto inverse = MoveTo::create(4.f, Vec2(-_cameraFirst->getPositionX(), 0)); inverse->retain(); + _moveAction->release(); _moveAction = inverse; auto rot = RotateBy::create(1.f, Vec3(0.f, 180.f, 0.f)); @@ -902,7 +904,7 @@ void CameraCullingDemo::switchViewCallback(Ref* sender) _cameraFirst->setCameraFlag(CameraFlag::USER8); _cameraFirst->setPosition3D(Vec3(-100,0,0)); _cameraFirst->lookAt(Vec3(1000,0,0)); - _moveAction = MoveTo::create(4.f, Vec2(100, 0)); + _moveAction = MoveTo::create(4.f, Vec2(-_cameraFirst->getPositionX(), 0)); _moveAction->retain(); auto seq = Sequence::create(_moveAction, CallFunc::create(CC_CALLBACK_0(CameraCullingDemo::reachEndCallBack, this)), nullptr); seq->setTag(100); From 9e3ae9bfb51028c28bfec3c21a80d619ba114e11 Mon Sep 17 00:00:00 2001 From: lvlong Date: Thu, 19 Mar 2015 15:24:58 +0800 Subject: [PATCH 5/7] remove get window size. --- tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index bb2505003c..2ebaa31641 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -881,11 +881,10 @@ void CameraCullingDemo::update(float dt) void CameraCullingDemo::reachEndCallBack() { - auto s = Director::getInstance()->getWinSize(); _cameraFirst->stopActionByTag(100); auto inverse = MoveTo::create(4.f, Vec2(-_cameraFirst->getPositionX(), 0)); inverse->retain(); - + _moveAction->release(); _moveAction = inverse; auto rot = RotateBy::create(1.f, Vec3(0.f, 180.f, 0.f)); From f60649b39f9daca78259427e3a84b9fb740ede55 Mon Sep 17 00:00:00 2001 From: tangziwen Date: Thu, 19 Mar 2015 16:09:16 +0800 Subject: [PATCH 6/7] add particle-perf for win rt --- .../cpp-tests.Shared/cpp-tests.Shared.vcxitems | 6 ++++-- .../cpp-tests.Shared.vcxitems.filters | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems index 5209f637f5..84eb9ac57a 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems @@ -115,7 +115,7 @@ - + @@ -124,6 +124,7 @@ + @@ -375,7 +376,7 @@ - + @@ -384,6 +385,7 @@ + diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters index 748129c0e0..d44bae8c7e 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Shared/cpp-tests.Shared.vcxitems.filters @@ -771,7 +771,10 @@ Classes\CocosStudio3DTest - + + + Classes\PerformanceTest + @@ -1673,7 +1676,7 @@ {65d0104d-321a-41f7-99af-de609183f206} - + @@ -1700,6 +1703,9 @@ Classes\CocosStudio3DTest - + + + Classes\PerformanceTest + \ No newline at end of file From 6c6fffc8472ce6e3cd8d136d07b6ef2206ee5abe Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 19 Mar 2015 18:10:16 +0800 Subject: [PATCH 7/7] modify enum to static int --- .../PerformanceParticle3DTest.cpp | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp index eb8da5f321..9f3522b962 100644 --- a/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp +++ b/tests/cpp-tests/Classes/PerformanceTest/PerformanceParticle3DTest.cpp @@ -1,20 +1,13 @@ #include "PerformanceParticle3DTest.h" #include "Particle3D/PU/CCPUParticleSystem3D.h" +static int kTagInfoLayer = 1; +static int kTagMenuLayer = 1000; +static int kTagParticleSystem = 1001; +static int test_Count = 2; -enum { - kTagInfoLayer = 1, - kTagMainLayer = 2, - kTagLabelAtlas = 3, - kTagMenuLayer = 1000, - kTagParticleSystem = 1001, - TEST_COUNT = 2, -}; - -enum { - kMaxParticles = 14000, - kNodesIncrease = 1, -}; +static int kMaxParticles = 14000; +static int kNodesIncrease = 1; static int s_parCurIdx = 0; @@ -100,7 +93,7 @@ void Particle3DMainScene::initWithSubTest(int asubtest, int particles) addChild(infoLabel, 1, kTagInfoLayer); // Next Prev Test - auto menuLayer = new (std::nothrow) Particle3DMenuLayer(true, TEST_COUNT, s_parCurIdx); + auto menuLayer = new (std::nothrow) Particle3DMenuLayer(true, test_Count, s_parCurIdx); addChild(menuLayer, 1, kTagMenuLayer); menuLayer->release();