issue #3640: add performance test->renderer LargeTileMap test

This commit is contained in:
Huabing.Xu 2014-01-15 11:27:57 +08:00
parent 226054e810
commit 19705fcf37
8 changed files with 166 additions and 5 deletions

View File

@ -1 +1 @@
2efefc01ff97bda1498d1d4a850ea1881f751f7c
b6abaf935c97f8f1dc7a7179e54850928015b442

View File

@ -121,6 +121,7 @@ Classes/PerformanceTest/PerformanceTest.cpp \
Classes/PerformanceTest/PerformanceTextureTest.cpp \
Classes/PerformanceTest/PerformanceTouchesTest.cpp \
Classes/PerformanceTest/PerformanceLabelTest.cpp \
Classes/PerformanceTest/PerformanceRendererTest.cpp \
Classes/PhysicsTest/PhysicsTest.cpp \
Classes/RenderTextureTest/RenderTextureTest.cpp \
Classes/RotateWorldTest/RotateWorldTest.cpp \

View File

@ -116,6 +116,7 @@ set(SAMPLE_SRC
Classes/PerformanceTest/PerformanceTextureTest.cpp
Classes/PerformanceTest/PerformanceTouchesTest.cpp
Classes/PerformanceTest/PerformanceLabelTest.cpp
Classes/PerformanceTest/PerformanceRendererTest.cpp
Classes/PhysicsTest/PhysicsTest.cpp
Classes/RenderTextureTest/RenderTextureTest.cpp
Classes/RotateWorldTest/RotateWorldTest.cpp

View File

@ -0,0 +1,55 @@
//
// PerformanceRendererTest.cpp
// cocos2d_samples
//
// Created by Huabing on 1/10/14.
//
//
#include "PerformanceRendererTest.h"
#include "PerformanceTextureTest.h"
#include "../testResource.h"
RenderTestLayer::RenderTestLayer()
: PerformBasicLayer(true, 1, 1)
{
}
RenderTestLayer::~RenderTestLayer()
{
}
Scene* RenderTestLayer::scene()
{
auto scene = Scene::create();
RenderTestLayer *layer = new RenderTestLayer();
scene->addChild(layer);
layer->release();
return scene;
}
void RenderTestLayer::onEnter()
{
PerformBasicLayer::onEnter();
auto map = TMXTiledMap::create("TileMaps/map/sl.tmx");
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
addChild(map,-1);
//map->setAnchorPoint( Point(0, 0) );
//map->setPosition( Point(-20,-200) );
}
void RenderTestLayer::showCurrentTest()
{
}
void runRendererTest()
{
auto scene = RenderTestLayer::scene();
Director::getInstance()->replaceScene(scene);
}

View File

@ -0,0 +1,28 @@
//
// PerformanceRendererTest.h
// cocos2d_samples
//
// Created by Huabing on 1/10/14.
//
//
#ifndef __PERFORMANCE_RENDERER_TEST_H__
#define __PERFORMANCE_RENDERER_TEST_H__
#include "PerformanceTest.h"
class RenderTestLayer : public PerformBasicLayer
{
public:
RenderTestLayer();
virtual ~RenderTestLayer();
virtual void onEnter() override;
virtual void showCurrentTest() override;
public:
static Scene* scene();
};
void runRendererTest();
#endif

View File

@ -7,6 +7,7 @@
#include "PerformanceTouchesTest.h"
#include "PerformanceAllocTest.h"
#include "PerformanceLabelTest.h"
#include "PerformanceRendererTest.h"
enum
{
@ -26,6 +27,7 @@ struct {
{ "Texture Perf Test",[](Object*sender){runTextureTest();} },
{ "Touches Perf Test",[](Object*sender){runTouchesTest();} },
{ "Label Perf Test",[](Object*sender){runLabelTest();} },
{ "Renderer Perf Test",[](Object*sender){runRendererTest();} },
};
static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]);
@ -41,18 +43,83 @@ void PerformanceMainLayer::onEnter()
auto s = Director::getInstance()->getWinSize();
auto menu = Menu::create();
menu->setPosition( Point::ZERO );
_itemMenu = Menu::create();
_itemMenu->setPosition( Point::ZERO );
MenuItemFont::setFontName("Arial");
MenuItemFont::setFontSize(24);
for (int i = 0; i < g_testMax; ++i)
{
auto pItem = MenuItemFont::create(g_testsName[i].name, g_testsName[i].callback);
pItem->setPosition(Point(s.width / 2, s.height - (i + 1) * LINE_SPACE));
menu->addChild(pItem, kItemTagBasic + i);
_itemMenu->addChild(pItem, kItemTagBasic + i);
}
addChild(menu);
addChild(_itemMenu);
// Register Touch Event
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(PerformanceMainLayer::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(PerformanceMainLayer::onTouchMoved, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
auto mouseListener = EventListenerMouse::create();
mouseListener->onMouseScroll = CC_CALLBACK_1(PerformanceMainLayer::onMouseScroll, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
}
bool PerformanceMainLayer::onTouchBegan(Touch* touches, Event *event)
{
_beginPos = touches->getLocation();
return true;
}
void PerformanceMainLayer::onTouchMoved(Touch* touches, Event *event)
{
auto touchLocation = touches->getLocation();
float nMoveY = touchLocation.y - _beginPos.y;
auto curPos = _itemMenu->getPosition();
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
if (nextPos.y < 0.0f)
{
_itemMenu->setPosition(Point::ZERO);
return;
}
if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
{
_itemMenu->setPosition(Point(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
return;
}
_itemMenu->setPosition(nextPos);
_beginPos = touchLocation;
}
void PerformanceMainLayer::onMouseScroll(Event *event)
{
auto mouseEvent = static_cast<EventMouse*>(event);
float nMoveY = mouseEvent->getScrollY() * 6;
auto curPos = _itemMenu->getPosition();
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
if (nextPos.y < 0.0f)
{
_itemMenu->setPosition(Point::ZERO);
return;
}
if (nextPos.y > ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
{
_itemMenu->setPosition(Point(0, ((g_testMax + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
return;
}
_itemMenu->setPosition(nextPos);
}
////////////////////////////////////////////////////////

View File

@ -7,6 +7,14 @@ class PerformanceMainLayer : public Layer
{
public:
virtual void onEnter();
bool onTouchBegan(Touch* touches, Event *event);
void onTouchMoved(Touch* touches, Event *event);
void onMouseScroll(Event *event);
protected:
Point _beginPos;
Menu* _itemMenu;
};
class PerformBasicLayer : public Layer

View File

@ -0,0 +1 @@
64ce8a88d0dee73cf5d9fbb8f3c80673c82b9575