CCRANDOM_() uses std::rand() because it can be seeded with std::srand()

plus other minor fixes in perf tests
This commit is contained in:
Ricardo Quesada 2014-11-26 20:07:42 -08:00
parent db71d562e9
commit bfb79b6a9e
4 changed files with 44 additions and 26 deletions

View File

@ -67,7 +67,7 @@ THE SOFTWARE.
*/
#ifndef CC_DIRECTOR_STATS_POSITION
#define CC_DIRECTOR_STATS_POSITION Director::getInstance()->getVisibleOrigin()
#endif
#endif // CC_DIRECTOR_STATS_POSITION
using namespace std;
@ -1076,7 +1076,7 @@ void Director::showStats()
static unsigned long prevCalls = 0;
static unsigned long prevVerts = 0;
static float prevDeltaTime = 0.016; // 60FPS
static const float FPS_FILTER = 0.05;
static const float FPS_FILTER = 0.10;
_accumDt += _deltaTime;
@ -1112,7 +1112,6 @@ void Director::showStats()
prevVerts = currentVerts;
}
Mat4 identity = Mat4::IDENTITY;
_drawnVerticesLabel->visit(_renderer, identity, 0);
_drawnBatchesLabel->visit(_renderer, identity, 0);
@ -1123,7 +1122,7 @@ void Director::showStats()
void Director::calculateMPF()
{
static float prevSecondsPerFrame = 0;
static const float MPF_FILTER = 0.05;
static const float MPF_FILTER = 0.10;
struct timeval now;
gettimeofday(&now, nullptr);

View File

@ -26,9 +26,10 @@ THE SOFTWARE.
#ifndef __ccRandom_H_
#define __ccRandom_H_
#include "platform/CCPlatformMacros.h"
#include <random>
#include <cstdlib>
#include "platform/CCPlatformMacros.h"
NS_CC_BEGIN
@ -75,24 +76,38 @@ inline double random(double min, double max) {
}
/**
* returns a random int between 0 and RAND_MAX
*/
* Returns a random int between 0 and RAND_MAX
*/
inline int random() {
return cocos2d::random(0, RAND_MAX);
};
/**
* returns a random float between -1 and 1
*/
* Returns a random float between -1 and 1.
* It can be seeded using std::srand(seed);
*/
inline float rand_minus1_1() {
return cocos2d::random(-1.f, 1.f);
// FIXME: using the new c++11 random engine generator
// without a proper way to set a seed is not useful.
// Resorting to the old random method since it can
// be seeded using std::srand()
return ((std::rand() / (float)RAND_MAX) * 2) -1;
// return cocos2d::random(-1.f, 1.f);
};
/**
* returns a random float between 0 and 1
*/
* Returns a random float between 0 and 1.
* It can be seeded using std::srand(seed);
*/
inline float rand_0_1() {
return cocos2d::random(0.f, 1.f);
// FIXME: using the new c++11 random engine generator
// without a proper way to set a seed is not useful.
// Resorting to the old random method since it can
// be seeded using std::srand()
return std::rand() / (float)RAND_MAX;
// return cocos2d::random(0.f, 1.f);
};
NS_CC_END

View File

@ -27,6 +27,8 @@
#include "PerformanceSpriteTest.h"
#include <cmath>
enum {
kMaxNodes = 50000,
kNodesIncrease = 250,
@ -53,7 +55,7 @@ SubTest::~SubTest()
void SubTest::initWithSubTest(int subtest, Node* p)
{
srand(0);
std::srand(0);
_subtestNumber = subtest;
_parentNode = nullptr;
@ -367,7 +369,10 @@ void SpriteMenuLayer::showCurrentTest()
////////////////////////////////////////////////////////
// FIXME: This should be part of the class, but VC2013 doesn't support constexpr as static members yet
static const float SECONDS_PER_TESTS = 4.0f;
static const float SECONDS_PER_TESTS = 0.2f;
static const int MAX_SPRITE_TEST_CASE = 7;
static const int MAX_SUB_TEST_NUMS = 3;
// 500 sprites, 1500 sprites, etc...
bool SpriteMainScene::_s_autoTest = false;
int SpriteMainScene::_s_nSpriteCurCase = 0;
@ -377,7 +382,7 @@ std::vector<float> SpriteMainScene::_s_saved_fps = {};
void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
{
//srandom(0);
std::srand(0);
_subtestNumber = asubtest;
_subTest = new (std::nothrow) SubTest;
@ -559,7 +564,7 @@ void SpriteMainScene::dumpProfilerFPS()
log("");
int index = 0;
int sprites = 0;
while((sprites = _s_spritesQuanityArray[index++])) {
while((sprites = _s_spritesQuanityArray[index])) {
log("Number of sprites: %d", sprites);
for(int i=0; i < MAX_SPRITE_TEST_CASE; i++)
{
@ -567,13 +572,15 @@ void SpriteMainScene::dumpProfilerFPS()
buffer[0]=0;
for(int j=0; j < MAX_SUB_TEST_NUMS; j++)
{
float fps = _s_saved_fps[j + i*MAX_SUB_TEST_NUMS];
float fps = _s_saved_fps[j + i*MAX_SUB_TEST_NUMS + MAX_SUB_TEST_NUMS * MAX_SPRITE_TEST_CASE * index];
char fps_str[64];
sprintf(fps_str, "\t%.1f", fps);
sprintf(fps_str, "\t%d", (int)roundf(fps));
strcat(buffer, fps_str);
}
log("%c%s", i + 'A', buffer);
}
index++;
};
}
@ -681,17 +688,17 @@ void SpriteMainScene::endAutoTest()
void SpriteMainScene::nextAutoTest()
{
if (SpriteMainScene::_s_nSpriteCurCase < SpriteMainScene::MAX_SPRITE_TEST_CASE)
if (SpriteMainScene::_s_nSpriteCurCase < MAX_SPRITE_TEST_CASE)
{
if (_subtestNumber < SpriteMainScene::MAX_SUB_TEST_NUMS)
if (_subtestNumber < MAX_SUB_TEST_NUMS)
{
// Increase Sub Main Test (1, 2, 3, 4, ...)
_subtestNumber += 1;
autoShowSpriteTests(_s_nSpriteCurCase, _subtestNumber, _quantityNodes);
}
else if (_subtestNumber == SpriteMainScene::MAX_SUB_TEST_NUMS)
else if (_subtestNumber == MAX_SUB_TEST_NUMS)
{
if (SpriteMainScene::_s_nSpriteCurCase + 1 < SpriteMainScene::MAX_SPRITE_TEST_CASE)
if (SpriteMainScene::_s_nSpriteCurCase + 1 < MAX_SPRITE_TEST_CASE)
{
// Increase Main Test (A, B, C, ...)
_subtestNumber = 1;

View File

@ -104,9 +104,6 @@ protected:
int _quantityNodes;
SubTest* _subTest;
int _subtestNumber;
static const int MAX_SPRITE_TEST_CASE = 7;
static const int MAX_SUB_TEST_NUMS = 13;
};
class SpritePerformTestA : public SpriteMainScene