2014-01-15 09:22:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceSpriteTest.h"
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-11-27 12:07:42 +08:00
|
|
|
#include <cmath>
|
2014-11-28 00:58:07 +08:00
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2014-11-28 00:58:07 +08:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER<1800
|
|
|
|
#define CC_ROUND(__f__) __f__
|
|
|
|
#else
|
|
|
|
#define CC_ROUND(__f__) roundf(__f__)
|
|
|
|
#endif
|
2014-11-27 12:07:42 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
enum {
|
2012-06-12 16:56:34 +08:00
|
|
|
kMaxNodes = 50000,
|
|
|
|
kNodesIncrease = 250,
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
TEST_COUNT = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kTagInfoLayer = 1,
|
|
|
|
kTagMainLayer = 2,
|
2013-09-30 16:22:55 +08:00
|
|
|
kTagAutoTestMenu = 3,
|
2011-04-21 14:46:15 +08:00
|
|
|
kTagMenuLayer = (kMaxNodes + 1000),
|
2011-03-25 13:59:08 +08:00
|
|
|
};
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SubTest
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2011-04-07 14:30:35 +08:00
|
|
|
SubTest::~SubTest()
|
|
|
|
{
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode->release();
|
2011-04-07 14:30:35 +08:00
|
|
|
}
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
void SubTest::initWithSubTest(int subtest, Node* p)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-11-27 12:07:42 +08:00
|
|
|
std::srand(0);
|
2014-01-15 09:22:45 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
_subtestNumber = subtest;
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = nullptr;
|
2011-03-25 13:59:08 +08:00
|
|
|
/*
|
2014-01-15 09:22:45 +08:00
|
|
|
* Tests:
|
|
|
|
* 1: 1 (32-bit) PNG sprite of 52 x 139
|
2014-01-17 05:07:56 +08:00
|
|
|
* 2: 1 (32-bit) PNG sprite of 52 x 139 (same as 1)
|
2014-01-15 09:22:45 +08:00
|
|
|
* 3: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
|
|
|
|
* 4: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
|
|
|
|
|
|
|
|
* 5: 14 (32-bit) PNG sprites of 85 x 121 each
|
|
|
|
* 6: 14 (32-bit) PNG sprites of 85 x 121 each that belong to on texture atlas
|
|
|
|
* 7: 14 (32-bit) PNG Batch Node of 85 x 121 each
|
|
|
|
* 8: 14 (16-bit) PNG Batch Node of 85 x 121 each
|
|
|
|
|
|
|
|
* 9: 64 (32-bit) sprites of 32 x 32 each
|
|
|
|
*10: 64 (32-bit) sprites of 32 x 32 each that belong to on texture atlas
|
|
|
|
*11: 64 (32-bit) PNG Batch Node of 32 x 32 each
|
|
|
|
*12: 64 (16-bit) PNG Batch Node of 32 x 32 each
|
2014-11-27 08:55:39 +08:00
|
|
|
*
|
|
|
|
*13: (16-bit) PNG sprites. 33% from test4, 33% from test8, 33% from test12
|
2011-03-25 13:59:08 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
// purge textures
|
2013-11-07 21:48:39 +08:00
|
|
|
auto mgr = Director::getInstance()->getTextureCache();
|
2014-01-15 09:22:45 +08:00
|
|
|
mgr->removeTextureForKey("Images/grossinis_sister1.png");
|
|
|
|
mgr->removeTextureForKey("Images/grossini_dance_atlas.png");
|
|
|
|
mgr->removeTextureForKey("Images/spritesheet1.png");
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
switch ( _subtestNumber)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-01-15 09:22:45 +08:00
|
|
|
///
|
2011-03-25 13:59:08 +08:00
|
|
|
case 1:
|
|
|
|
case 2:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = Node::create();
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-01-15 09:22:45 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = SpriteBatchNode::create("Images/grossinis_sister1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
///
|
|
|
|
case 5:
|
|
|
|
case 6:
|
2014-01-15 09:22:45 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = Node::create();
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
|
|
|
|
break;
|
2014-01-15 09:22:45 +08:00
|
|
|
case 8:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
///
|
2014-01-15 09:22:45 +08:00
|
|
|
case 9:
|
|
|
|
case 10:
|
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = Node::create();
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
case 12:
|
2013-07-26 04:36:19 +08:00
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode = SpriteBatchNode::create("Images/spritesheet1.png", 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
///
|
2014-01-17 05:07:56 +08:00
|
|
|
case 13:
|
|
|
|
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
|
|
|
|
_parentNode = Node::create();
|
|
|
|
break;
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-17 05:07:56 +08:00
|
|
|
p->addChild(_parentNode);
|
|
|
|
_parentNode->retain();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* SubTest::createSpriteWithTag(int tag)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-01-17 05:07:56 +08:00
|
|
|
TextureCache *cache = Director::getInstance()->getTextureCache();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
Sprite* sprite = nullptr;
|
2014-11-27 08:55:39 +08:00
|
|
|
switch (_subtestNumber)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-01-15 09:22:45 +08:00
|
|
|
///
|
2011-03-25 13:59:08 +08:00
|
|
|
case 1:
|
|
|
|
case 2:
|
2014-01-15 09:22:45 +08:00
|
|
|
{
|
|
|
|
sprite = Sprite::create("Images/grossinis_sister1.png");
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
2011-03-25 13:59:08 +08:00
|
|
|
case 4:
|
2014-01-15 09:22:45 +08:00
|
|
|
{
|
2014-01-17 05:07:56 +08:00
|
|
|
Texture2D *texture = cache->addImage("Images/grossinis_sister1.png");
|
|
|
|
sprite = Sprite::createWithTexture(texture, Rect(0, 0, 52, 139));
|
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2011-03-25 13:59:08 +08:00
|
|
|
case 5:
|
2014-01-15 09:22:45 +08:00
|
|
|
{
|
|
|
|
int idx = (CCRANDOM_0_1() * 1400 / 100) + 1;
|
|
|
|
char str[32] = {0};
|
|
|
|
sprintf(str, "Images/grossini_dance_%02d.png", idx);
|
|
|
|
sprite = Sprite::create(str);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
case 6:
|
|
|
|
case 7:
|
2014-01-15 09:22:45 +08:00
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 1400 / 100);
|
|
|
|
|
|
|
|
y = r / 5;
|
|
|
|
x = r % 5;
|
|
|
|
|
|
|
|
x *= 85;
|
|
|
|
y *= 121;
|
2014-01-17 05:07:56 +08:00
|
|
|
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
|
|
|
|
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
|
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
case 9:
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 6400 / 100);
|
|
|
|
|
|
|
|
y = r / 8;
|
|
|
|
x = r % 8;
|
|
|
|
|
|
|
|
char str[40] = {0};
|
|
|
|
sprintf(str, "Images/sprites_test/sprite-%d-%d.png", x, y);
|
2013-06-20 14:17:10 +08:00
|
|
|
sprite = Sprite::create(str);
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
case 10:
|
2014-01-17 05:07:56 +08:00
|
|
|
case 11:
|
|
|
|
case 12:
|
2014-01-15 09:22:45 +08:00
|
|
|
{
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 6400 / 100);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
y = r / 8;
|
|
|
|
x = r % 8;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
x *= 32;
|
|
|
|
y *= 32;
|
2014-01-17 05:07:56 +08:00
|
|
|
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
|
|
|
|
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
|
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
2014-01-15 09:22:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-01-17 05:07:56 +08:00
|
|
|
///
|
|
|
|
case 13:
|
2014-01-15 09:22:45 +08:00
|
|
|
{
|
2014-01-17 05:07:56 +08:00
|
|
|
int test = (CCRANDOM_0_1() * 3);
|
2014-01-15 09:22:45 +08:00
|
|
|
|
2014-01-17 05:07:56 +08:00
|
|
|
if(test==0) {
|
|
|
|
// Switch case 1
|
|
|
|
sprite = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
|
|
|
}
|
|
|
|
else if(test==1)
|
|
|
|
{
|
|
|
|
// Switch case 6
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 1400 / 100);
|
2014-01-15 09:22:45 +08:00
|
|
|
|
2014-01-17 05:07:56 +08:00
|
|
|
y = r / 5;
|
|
|
|
x = r % 5;
|
|
|
|
|
|
|
|
x *= 85;
|
|
|
|
y *= 121;
|
|
|
|
Texture2D *texture = cache->addImage("Images/grossini_dance_atlas.png");
|
|
|
|
sprite = Sprite::createWithTexture(texture, Rect(x,y,85,121));
|
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(test==2)
|
|
|
|
{
|
|
|
|
int y,x;
|
|
|
|
int r = (CCRANDOM_0_1() * 6400 / 100);
|
|
|
|
|
|
|
|
y = r / 8;
|
|
|
|
x = r % 8;
|
|
|
|
|
|
|
|
x *= 32;
|
|
|
|
y *= 32;
|
|
|
|
Texture2D *texture = cache->addImage("Images/spritesheet1.png");
|
|
|
|
sprite = Sprite::createWithTexture(texture, CC_RECT_PIXELS_TO_POINTS(Rect(x,y,32,32)));
|
|
|
|
_parentNode->addChild(sprite, 0, tag+100);
|
|
|
|
}
|
2014-01-15 09:22:45 +08:00
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubTest::removeByTag(int tag)
|
|
|
|
{
|
2014-01-17 05:07:56 +08:00
|
|
|
_parentNode->removeChildByTag(tag+100, true);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpriteMenuLayer
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMenuLayer::restartCallback(Ref* sender)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
|
|
|
if ( SpriteMainScene::_s_autoTest )
|
|
|
|
{
|
|
|
|
log("It's auto sprite performace testing,so this operation is invalid");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PerformBasicLayer::restartCallback(sender);
|
|
|
|
}
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMenuLayer::nextCallback(Ref* sender)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
|
|
|
if ( SpriteMainScene::_s_autoTest )
|
|
|
|
{
|
|
|
|
log("It's auto sprite performace testing,so this operation is invalid");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PerformBasicLayer::nextCallback(sender);
|
|
|
|
}
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMenuLayer::backCallback(Ref* sender)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
|
|
|
if ( SpriteMainScene::_s_autoTest )
|
|
|
|
{
|
|
|
|
log("It's auto sprite performace testing,so this operation is invalid");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PerformBasicLayer::backCallback(sender);
|
|
|
|
}
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void SpriteMenuLayer::showCurrentTest()
|
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
SpriteMainScene* scene = nullptr;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto pPreScene = (SpriteMainScene*) getParent();
|
2011-03-25 13:59:08 +08:00
|
|
|
int nSubTest = pPreScene->getSubTestNum();
|
|
|
|
int nNodes = pPreScene->getNodesNum();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
case 0:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestA;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestB;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestC;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestD;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestE;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestF;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
case 6:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestG;
|
2011-03-25 13:59:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-09-30 16:22:55 +08:00
|
|
|
|
|
|
|
SpriteMainScene::_s_nSpriteCurCase = _curCase;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
if (scene)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->initWithSubTest(nSubTest, nNodes);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SpriteMainScene
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2013-09-30 16:22:55 +08:00
|
|
|
|
2014-11-27 10:35:14 +08:00
|
|
|
// FIXME: This should be part of the class, but VC2013 doesn't support constexpr as static members yet
|
2014-11-27 12:23:16 +08:00
|
|
|
static const float SECONDS_PER_TESTS = 4.0f;
|
|
|
|
static const int MAX_SPRITE_TEST_CASE = 7; // A...G
|
|
|
|
static const int MAX_SUB_TEST_NUMS = 13; // 1...13
|
2014-11-27 12:07:42 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
// 500 sprites, 1500 sprites, etc...
|
2013-09-30 16:22:55 +08:00
|
|
|
bool SpriteMainScene::_s_autoTest = false;
|
2014-11-27 08:55:39 +08:00
|
|
|
int SpriteMainScene::_s_nSpriteCurCase = 0;
|
|
|
|
int SpriteMainScene::_s_spritesQuatityIndex = 0;
|
2014-11-27 10:11:53 +08:00
|
|
|
int SpriteMainScene::_s_spritesQuanityArray[] = {1000, 3000, 0};
|
2014-11-27 12:23:16 +08:00
|
|
|
// FIXME: to make VS2012 happy. Once VS2012 is deprecated, we can just simply replace it with {}
|
|
|
|
std::vector<float> SpriteMainScene::_s_saved_fps = std::vector<float>();
|
2013-09-30 16:22:55 +08:00
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
|
|
|
|
{
|
2014-11-27 12:07:42 +08:00
|
|
|
std::srand(0);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
_subtestNumber = asubtest;
|
2014-08-28 07:31:57 +08:00
|
|
|
_subTest = new (std::nothrow) SubTest;
|
2013-06-15 14:03:30 +08:00
|
|
|
_subTest->initWithSubTest(asubtest, this);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
_lastRenderedCount = 0;
|
|
|
|
_quantityNodes = 0;
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontSize(65);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteMainScene::onDecrease, this));
|
2013-07-05 16:49:22 +08:00
|
|
|
decrease->setColor(Color3B(0,200,20));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteMainScene::onIncrease, this));
|
2013-07-05 16:49:22 +08:00
|
|
|
increase->setColor(Color3B(0,200,20));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(decrease, increase, nullptr);
|
2011-03-25 13:59:08 +08:00
|
|
|
menu->alignItemsHorizontally();
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(s.width/2, s.height-65));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(menu, 1);
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto infoLabel = Label::createWithTTF("0 nodes", "fonts/Marker Felt.ttf", 30);
|
2013-07-05 16:49:22 +08:00
|
|
|
infoLabel->setColor(Color3B(0,200,20));
|
2014-05-15 01:07:09 +08:00
|
|
|
infoLabel->setPosition(Vec2(s.width/2, s.height-90));
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(infoLabel, 1, kTagInfoLayer);
|
|
|
|
|
|
|
|
// add menu
|
2014-08-28 07:31:57 +08:00
|
|
|
auto menuLayer = new (std::nothrow) SpriteMenuLayer(true, TEST_COUNT, SpriteMainScene::_s_nSpriteCurCase);
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(menuLayer, 1, kTagMenuLayer);
|
|
|
|
menuLayer->release();
|
2013-09-30 16:22:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* auto test menu
|
|
|
|
*/
|
|
|
|
|
|
|
|
auto menuAutoTest = Menu::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
menuAutoTest->setPosition( Vec2::ZERO );
|
2014-03-26 23:33:58 +08:00
|
|
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
2013-09-30 16:22:55 +08:00
|
|
|
MenuItemFont::setFontSize(24);
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
MenuItemFont* autoTestItem = nullptr;
|
2013-09-30 16:22:55 +08:00
|
|
|
if (SpriteMainScene::_s_autoTest)
|
|
|
|
{
|
|
|
|
autoTestItem = MenuItemFont::create("Auto Test On",CC_CALLBACK_1(SpriteMainScene::onAutoTest, this));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
autoTestItem = MenuItemFont::create("Auto Test Off",CC_CALLBACK_1(SpriteMainScene::onAutoTest, this));
|
|
|
|
}
|
|
|
|
autoTestItem->setTag(1);
|
2014-05-15 01:07:09 +08:00
|
|
|
autoTestItem->setPosition(Vec2( s.width - 90, s.height / 2));
|
2013-09-30 16:22:55 +08:00
|
|
|
menuAutoTest->addChild(autoTestItem);
|
|
|
|
addChild( menuAutoTest, 3, kTagAutoTestMenu );
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
// Sub Tests
|
2014-01-17 05:07:56 +08:00
|
|
|
MenuItemFont::setFontSize(28);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto subMenu = Menu::create();
|
2014-01-17 05:07:56 +08:00
|
|
|
for (int i = 1; i <= 13; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
char str[10] = {0};
|
|
|
|
sprintf(str, "%d ", i);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto itemFont = MenuItemFont::create(str, CC_CALLBACK_1(SpriteMainScene::testNCallback, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
itemFont->setTag(i);
|
2013-07-24 06:20:22 +08:00
|
|
|
subMenu->addChild(itemFont, 10);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
if( i<= 4)
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(200,20,20));
|
2014-01-15 09:22:45 +08:00
|
|
|
else if(i <= 8)
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(0,200,20));
|
2014-01-17 05:07:56 +08:00
|
|
|
else if( i<=12)
|
2013-07-05 16:49:22 +08:00
|
|
|
itemFont->setColor(Color3B(0,20,200));
|
2014-01-17 05:07:56 +08:00
|
|
|
else
|
|
|
|
itemFont->setColor(Color3B::GRAY);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
subMenu->alignItemsHorizontally();
|
2014-05-15 01:07:09 +08:00
|
|
|
subMenu->setPosition(Vec2(s.width/2, 80));
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(subMenu, 2);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// add title label
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF(title(), "fonts/arial.ttf", 32);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
2014-05-15 01:07:09 +08:00
|
|
|
label->setPosition(Vec2(s.width/2, s.height-50));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
|
|
|
|
// subtitle
|
|
|
|
std::string strSubtitle = subtitle();
|
|
|
|
if( ! strSubtitle.empty() )
|
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/Thonburi.ttf", 16);
|
2014-01-15 09:22:45 +08:00
|
|
|
addChild(l, 9999);
|
2014-05-15 01:07:09 +08:00
|
|
|
l->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
|
2014-01-15 09:22:45 +08:00
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
while(_quantityNodes < nNodes)
|
2011-03-25 13:59:08 +08:00
|
|
|
onIncrease(this);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SpriteMainScene::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
std::string SpriteMainScene::subtitle() const
|
|
|
|
{
|
|
|
|
return ""; // override me
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
SpriteMainScene::~SpriteMainScene()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_subTest)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
delete _subTest;
|
2014-07-10 00:45:27 +08:00
|
|
|
_subTest = nullptr;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMainScene::testNCallback(Ref* sender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-30 16:22:55 +08:00
|
|
|
if (SpriteMainScene::_s_autoTest)
|
|
|
|
{
|
|
|
|
log("It's auto sprite performace testing,so this operation is invalid");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
_subtestNumber = static_cast<MenuItemFont*>(sender)->getTag();
|
2013-07-26 06:53:24 +08:00
|
|
|
auto menu = static_cast<SpriteMenuLayer*>( getChildByTag(kTagMenuLayer) );
|
|
|
|
menu->restartCallback(sender);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::updateNodes()
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
if( _quantityNodes != _lastRenderedCount )
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-03-26 23:33:58 +08:00
|
|
|
auto infoLabel = (Label *) getChildByTag(kTagInfoLayer);
|
2011-03-25 13:59:08 +08:00
|
|
|
char str[16] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "%u nodes", _quantityNodes);
|
2011-03-25 13:59:08 +08:00
|
|
|
infoLabel->setString(str);
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
_lastRenderedCount = _quantityNodes;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMainScene::onIncrease(Ref* sender)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
if( _quantityNodes >= kMaxNodes)
|
2011-03-25 13:59:08 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i=0;i< kNodesIncrease;i++)
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
auto sprite = _subTest->createSpriteWithTag(_quantityNodes);
|
2011-03-25 13:59:08 +08:00
|
|
|
doTest(sprite);
|
2014-11-27 08:55:39 +08:00
|
|
|
_quantityNodes++;
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
updateNodes();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMainScene::onDecrease(Ref* sender)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-09-30 16:22:55 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
if( _quantityNodes <= 0 )
|
2011-03-25 13:59:08 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
for( int i=0;i < kNodesIncrease;i++)
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
_quantityNodes--;
|
|
|
|
_subTest->removeByTag(_quantityNodes);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
updateNodes();
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:22:55 +08:00
|
|
|
void SpriteMainScene::dumpProfilerFPS()
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
log("COPY & PASTE into Cocos2d-x Performance Test spreadsheet");
|
|
|
|
log("https://docs.google.com/spreadsheets/d/1XolpgYfoWszA2rxnVRCAVS7ILAGiV049o5mpL29cwLs/edit#gid=1561044615");
|
|
|
|
log("");
|
|
|
|
int index = 0;
|
|
|
|
int sprites = 0;
|
2014-11-27 12:07:42 +08:00
|
|
|
while((sprites = _s_spritesQuanityArray[index])) {
|
2014-11-27 08:55:39 +08:00
|
|
|
log("Number of sprites: %d", sprites);
|
|
|
|
for(int i=0; i < MAX_SPRITE_TEST_CASE; i++)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
2014-11-27 10:11:53 +08:00
|
|
|
buffer[0]=0;
|
2014-11-27 08:55:39 +08:00
|
|
|
for(int j=0; j < MAX_SUB_TEST_NUMS; j++)
|
|
|
|
{
|
2014-11-27 12:07:42 +08:00
|
|
|
float fps = _s_saved_fps[j + i*MAX_SUB_TEST_NUMS + MAX_SUB_TEST_NUMS * MAX_SPRITE_TEST_CASE * index];
|
2014-11-27 08:55:39 +08:00
|
|
|
char fps_str[64];
|
2014-11-28 00:58:07 +08:00
|
|
|
sprintf(fps_str, "\t%d", (int)CC_ROUND(fps));
|
2014-11-27 08:55:39 +08:00
|
|
|
strcat(buffer, fps_str);
|
|
|
|
}
|
|
|
|
log("%c%s", i + 'A', buffer);
|
|
|
|
}
|
2014-11-27 12:07:42 +08:00
|
|
|
|
|
|
|
index++;
|
2014-11-27 08:55:39 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::saveFPS()
|
|
|
|
{
|
|
|
|
float fps = Director::getInstance()->getFrameRate();
|
|
|
|
_s_saved_fps.push_back(fps);
|
2014-11-27 10:11:53 +08:00
|
|
|
log("Nodes: %d, Test: %c, SubTest: %d = %.1f", _quantityNodes, 'A'+_s_nSpriteCurCase, _subtestNumber, fps);
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::updateAutoTest(float dt)
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
saveFPS();
|
|
|
|
nextAutoTest();
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::onEnter()
|
|
|
|
{
|
|
|
|
Scene::onEnter();
|
|
|
|
|
|
|
|
if ( SpriteMainScene::_s_autoTest )
|
|
|
|
{
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto sched = director->getScheduler();
|
2014-11-27 08:55:39 +08:00
|
|
|
|
|
|
|
// schedule it only once. Call me after 3 seconds
|
|
|
|
sched->schedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::updateAutoTest), this, SECONDS_PER_TESTS, 0, 0, false);
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::onExit()
|
|
|
|
{
|
|
|
|
if ( SpriteMainScene::_s_autoTest )
|
|
|
|
{
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto sched = director->getScheduler();
|
2014-10-04 00:38:36 +08:00
|
|
|
sched->unschedule(CC_SCHEDULE_SELECTOR(SpriteMainScene::updateAutoTest), this );
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Scene::onExit();
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpriteMainScene::autoShowSpriteTests(int curCase, int subTest, int nodes)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
SpriteMainScene* scene = nullptr;
|
2013-09-30 16:22:55 +08:00
|
|
|
|
|
|
|
switch (curCase)
|
|
|
|
{
|
|
|
|
case 0:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestA;
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestB;
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestC;
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestD;
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestE;
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
case 5:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestF;
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
case 6:
|
2014-11-27 08:55:39 +08:00
|
|
|
scene = new (std::nothrow) SpritePerformTestG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CCASSERT(false, "Invalid scene value");
|
2013-09-30 16:22:55 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-11-27 08:55:39 +08:00
|
|
|
|
2013-09-30 16:22:55 +08:00
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
scene->initWithSubTest(subTest, nodes);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::beginAutoTest()
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
_s_spritesQuatityIndex = 0;
|
|
|
|
_s_nSpriteCurCase = 0;
|
|
|
|
_s_saved_fps.clear();
|
|
|
|
|
|
|
|
_subtestNumber = 0;
|
|
|
|
_quantityNodes = _s_spritesQuanityArray[_s_spritesQuatityIndex];
|
|
|
|
|
|
|
|
nextAutoTest();
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::endAutoTest()
|
|
|
|
{
|
|
|
|
SpriteMainScene::_s_autoTest = false;
|
|
|
|
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto sched = director->getScheduler();
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
sched->unschedule( CC_SCHEDULE_SELECTOR( SpriteMainScene::updateAutoTest ), this );
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::nextAutoTest()
|
|
|
|
{
|
2014-11-27 12:07:42 +08:00
|
|
|
if (SpriteMainScene::_s_nSpriteCurCase < MAX_SPRITE_TEST_CASE)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
2014-11-27 12:07:42 +08:00
|
|
|
if (_subtestNumber < MAX_SUB_TEST_NUMS)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
// Increase Sub Main Test (1, 2, 3, 4, ...)
|
|
|
|
_subtestNumber += 1;
|
|
|
|
autoShowSpriteTests(_s_nSpriteCurCase, _subtestNumber, _quantityNodes);
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
2014-11-27 12:07:42 +08:00
|
|
|
else if (_subtestNumber == MAX_SUB_TEST_NUMS)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
2014-11-27 12:07:42 +08:00
|
|
|
if (SpriteMainScene::_s_nSpriteCurCase + 1 < MAX_SPRITE_TEST_CASE)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
// Increase Main Test (A, B, C, ...)
|
|
|
|
_subtestNumber = 1;
|
|
|
|
_s_nSpriteCurCase++;
|
|
|
|
autoShowSpriteTests(_s_nSpriteCurCase, _subtestNumber, _quantityNodes);
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
// Increase quanity of sprites, or finish
|
|
|
|
int sprites = _s_spritesQuanityArray[++_s_spritesQuatityIndex];
|
|
|
|
if (sprites != 0) {
|
|
|
|
_quantityNodes = sprites;
|
|
|
|
_subtestNumber = 1;
|
|
|
|
_s_nSpriteCurCase = 0;
|
|
|
|
autoShowSpriteTests(_s_nSpriteCurCase, _subtestNumber, _quantityNodes);
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
finishAutoTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteMainScene::finishAutoTest()
|
|
|
|
{
|
|
|
|
SpriteMainScene::_s_autoTest = false;
|
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto sched = director->getScheduler();
|
2014-10-04 00:38:36 +08:00
|
|
|
sched->unschedule( CC_SCHEDULE_SELECTOR( SpriteMainScene::updateAutoTest ), this);
|
2013-09-30 16:22:55 +08:00
|
|
|
|
|
|
|
auto autoTestMenu = dynamic_cast<Menu*>(getChildByTag(kTagAutoTestMenu));
|
|
|
|
if (nullptr != autoTestMenu)
|
|
|
|
{
|
|
|
|
auto menuItemFont = dynamic_cast<MenuItemFont*>(autoTestMenu->getChildByTag(1));
|
|
|
|
if (nullptr != menuItemFont)
|
|
|
|
{
|
|
|
|
menuItemFont->setString("Auto Test finish");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
log("Sprite performance test is finished");
|
|
|
|
|
|
|
|
dumpProfilerFPS();
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SpriteMainScene::onAutoTest(Ref* sender)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
|
|
|
SpriteMainScene::_s_autoTest = !SpriteMainScene::_s_autoTest;
|
|
|
|
MenuItemFont* menuItem = dynamic_cast<MenuItemFont*>(sender);
|
2014-11-27 08:55:39 +08:00
|
|
|
|
|
|
|
if (SpriteMainScene::_s_autoTest)
|
2013-09-30 16:22:55 +08:00
|
|
|
{
|
2014-11-27 08:55:39 +08:00
|
|
|
menuItem->setString("Auto Test On");
|
|
|
|
beginAutoTest();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menuItem->setString("Auto Test Off");
|
|
|
|
endAutoTest();
|
2013-09-30 16:22:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// For test functions
|
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceActions(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float period = 0.5f + (rand() % 1000) / 500.0f;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
|
|
|
|
auto rot_back = rot->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, nullptr));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentRotation);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
|
2014-07-10 00:45:27 +08:00
|
|
|
auto permanentScaleLoop = RepeatForever::create(Sequence::create(grow, grow->reverse(), nullptr));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentScaleLoop);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceActions20(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( -1000, -1000));
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float period = 0.5f + (rand() % 1000) / 500.0f;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rot = RotateBy::create(period, 360.0f * CCRANDOM_0_1());
|
|
|
|
auto rot_back = rot->reverse();
|
2014-07-10 00:45:27 +08:00
|
|
|
auto permanentRotation = RepeatForever::create(Sequence::create(rot, rot_back, nullptr));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentRotation);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
float growDuration = 0.5f + (rand() % 1000) / 500.0f;
|
2013-08-16 16:05:27 +08:00
|
|
|
auto grow = ScaleBy::create(growDuration, 0.5f, 0.5f);
|
|
|
|
auto permanentScaleLoop = RepeatForever::create(Sequence::createWithTwoActions(grow, grow->reverse()));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->runAction(permanentScaleLoop);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceRotationScale(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setRotation(CCRANDOM_0_1() * 360);
|
|
|
|
sprite->setScale(CCRANDOM_0_1() * 2);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performancePosition(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceout20(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
if( CCRANDOM_0_1() < 0.2f )
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( -1000, -1000));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceOut100(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2( -1000, -1000));
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
void performanceScale(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition(Vec2((rand() % (int)size.width), (rand() % (int)size.height)));
|
2013-07-24 06:20:22 +08:00
|
|
|
sprite->setScale(CCRANDOM_0_1() * 100 / 50);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestA
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestA::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "A (%d) position", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestA::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performancePosition(sprite);
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestB
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestB::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "B (%d) scale", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestB::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceScale(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestC
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestC::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "C (%d) scale + rot", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestC::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceRotationScale(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestD
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestD::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "D (%d) 100%% out", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestD::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceOut100(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestE
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestE::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "E (%d) 80%% out", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestE::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceout20(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestF
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestF::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "F (%d) actions", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestF::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceActions(sprite);
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-11-27 08:55:39 +08:00
|
|
|
// SpritePerformTestG
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2011-03-25 13:59:08 +08:00
|
|
|
////////////////////////////////////////////////////////
|
2014-11-27 08:55:39 +08:00
|
|
|
std::string SpritePerformTestG::title() const
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
char str[32] = {0};
|
2014-11-27 08:55:39 +08:00
|
|
|
sprintf(str, "G (%d) actions 80%% out", _subtestNumber);
|
2011-03-25 13:59:08 +08:00
|
|
|
std::string strRet = str;
|
|
|
|
return strRet;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:55:39 +08:00
|
|
|
void SpritePerformTestG::doTest(Sprite* sprite)
|
2011-03-25 13:59:08 +08:00
|
|
|
{
|
|
|
|
performanceActions20(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void runSpriteTest()
|
|
|
|
{
|
2013-09-30 16:22:55 +08:00
|
|
|
SpriteMainScene::_s_autoTest = false;
|
2014-11-27 08:55:39 +08:00
|
|
|
auto scene = new (std::nothrow) SpritePerformTestA;
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->initWithSubTest(1, 50);
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
|
|
|
scene->release();
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|