Merge pull request #258 from songchengjiang/v3

add particle3D performance Test
This commit is contained in:
XiaoYang 2015-03-19 13:48:04 +08:00
commit 9665557e66
5 changed files with 278 additions and 7 deletions

View File

@ -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<Node*>(sender)->getTag();
auto menu = static_cast<Particle3DMenuLayer*>( 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();
}

View File

@ -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

View File

@ -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();} },

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -189,12 +189,13 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y</Command>
<ClCompile Include="..\Classes\NewEventDispatcherTest\NewEventDispatcherTest.cpp" />
<ClCompile Include="..\Classes\NewRendererTest\NewRendererTest.cpp" />
<ClCompile Include="..\Classes\Particle3DTest\Particle3DTest.cpp" />
<ClCompile Include="..\Classes\CocosStudio3DTest\CocosStudio3DTest.cpp" />
<ClCompile Include="..\Classes\CocosStudio3DTest\CocosStudio3DTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceAllocTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceContainerTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceEventDispatcherTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceLabelTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceMathTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceParticle3DTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceRendererTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceScenarioTest.cpp" />
<ClCompile Include="..\Classes\PhysicsTest\PhysicsTest.cpp" />
@ -388,12 +389,13 @@ xcopy "$(OutDir)..\*.dll" "$(OutDir)" /D /Y</Command>
<ClInclude Include="..\Classes\NewEventDispatcherTest\NewEventDispatcherTest.h" />
<ClInclude Include="..\Classes\NewRendererTest\NewRendererTest.h" />
<ClInclude Include="..\Classes\Particle3DTest\Particle3DTest.h" />
<ClInclude Include="..\Classes\CocosStudio3DTest\CocosStudio3DTest.h" />
<ClInclude Include="..\Classes\CocosStudio3DTest\CocosStudio3DTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceAllocTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceContainerTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceEventDispatcherTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceLabelTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceMathTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceParticle3DTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceRendererTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceScenarioTest.h" />
<ClInclude Include="..\Classes\PhysicsTest\PhysicsTest.h" />

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="win32">
@ -345,7 +345,7 @@
</Filter>
<Filter Include="Classes\CocosStudio3DTest">
<UniqueIdentifier>{e4104916-24d0-49b8-a864-d273ea13a248}</UniqueIdentifier>
</Filter>
</Filter>
<Filter Include="Classes\UITest\CocostudioGUISceneTest\CustomTest\CustomWidgetCallbackBindTest">
<UniqueIdentifier>{65be3b70-58d6-47f4-bc67-fac9ee134c42}</UniqueIdentifier>
</Filter>
@ -905,7 +905,7 @@
</ClCompile>
<ClCompile Include="..\Classes\CocosStudio3DTest\CocosStudio3DTest.cpp">
<Filter>Classes\CocosStudio3DTest</Filter>
</ClCompile>
</ClCompile>
<ClCompile Include="..\Classes\PerformanceTest\PerformanceMathTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
@ -921,6 +921,9 @@
<ClCompile Include="..\Classes\AllocatorTest\AllocatorTest.cpp">
<Filter>Classes\AllocatorTest</Filter>
</ClCompile>
<ClCompile Include="..\Classes\PerformanceTest\PerformanceParticle3DTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
@ -1672,7 +1675,7 @@
</ClInclude>
<ClInclude Include="..\Classes\CocosStudio3DTest\CocosStudio3DTest.h">
<Filter>Classes\CocosStudio3DTest</Filter>
</ClInclude>
</ClInclude>
<ClInclude Include="..\Classes\PerformanceTest\PerformanceMathTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
@ -1688,5 +1691,8 @@
<ClInclude Include="..\Classes\AllocatorTest\AllocatorTest.h">
<Filter>Classes\AllocatorTest</Filter>
</ClInclude>
<ClInclude Include="..\Classes\PerformanceTest\PerformanceParticle3DTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
</ItemGroup>
</Project>