From f7b2ca21259ad39036e3ce7d5d4b4c87f062a8e5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 25 Mar 2013 11:47:27 +0800 Subject: [PATCH] Fixing compilation errors when enable CC_ENABLE_PROFILERS. --- cocos2dx/include/ccMacros.h | 6 +- .../PerformanceNodeChildrenTest.cpp | 81 ++++++------------- .../PerformanceNodeChildrenTest.h | 18 ++--- 3 files changed, 35 insertions(+), 70 deletions(-) diff --git a/cocos2dx/include/ccMacros.h b/cocos2dx/include/ccMacros.h index a925725f70..dde93334e2 100644 --- a/cocos2dx/include/ccMacros.h +++ b/cocos2dx/include/ccMacros.h @@ -203,9 +203,9 @@ It should work same as apples CFSwapInt32LittleToHost(..) #define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingEndTimingBlock(__name__); } while(0) #define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) CCProfilingResetTimingBlock(__name__); } while(0) -#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ CCProfilingBeginTimingBlock( [NSString stringWithFormat:@"%08X - %@", __id__, __name__] ); } while(0) -#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ CCProfilingEndTimingBlock( [NSString stringWithFormat:@"%08X - %@", __id__, __name__] ); } while(0) -#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ CCProfilingResetTimingBlock( [NSString stringWithFormat:@"%08X - %@", __id__, __name__] ); } while(0) +#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ CCProfilingBeginTimingBlock( CCString::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ CCProfilingEndTimingBlock( CCString::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) +#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ CCProfilingResetTimingBlock( CCString::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0) #else diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp index b8a61b6322..6c3268c4ff 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp @@ -165,10 +165,7 @@ void NodeChildrenMainScene::updateQuantityLabel() //////////////////////////////////////////////////////// IterateSpriteSheet::~IterateSpriteSheet() { -#if CC_ENABLE_PROFILERS - CCProfiler::releaseTimer(_profilingTimer); - _profilingTimer = NULL; -#endif + } void IterateSpriteSheet::updateQuantityOfNodes() @@ -203,17 +200,13 @@ void IterateSpriteSheet::initWithQuantityOfNodes(unsigned int nNodes) { batchNode = CCSpriteBatchNode::create("Images/spritesheet1.png"); addChild(batchNode); - + NodeChildrenMainScene::initWithQuantityOfNodes(nNodes); -#if CC_ENABLE_PROFILERS - _profilingTimer = CCProfiler::timerWithName(profilerName().c_str(), this); -#endif - scheduleUpdate(); } -std::string IterateSpriteSheet::profilerName() +const char* IterateSpriteSheet::profilerName() { return "none"; } @@ -229,9 +222,7 @@ void IterateSpriteSheetFastEnum::update(float dt) CCArray* pChildren = batchNode->getChildren(); CCObject* pObject = NULL; -#if CC_ENABLE_PROFILERS - CCProfilingBeginTimingBlock(_profilingTimer); -#endif + CC_PROFILER_START_INSTANCE(this, this->profilerName()); CCARRAY_FOREACH(pChildren, pObject) { @@ -239,9 +230,7 @@ void IterateSpriteSheetFastEnum::update(float dt) pSprite->setVisible(false); } -#if CC_ENABLE_PROFILERS - CCProfilingEndTimingBlock(_profilingTimer); -#endif + CC_PROFILER_STOP_INSTANCE(this, this->profilerName()); } std::string IterateSpriteSheetFastEnum::title() @@ -254,7 +243,7 @@ std::string IterateSpriteSheetFastEnum::subtitle() return "Iterate children using Fast Enum API. See console"; } -std::string IterateSpriteSheetFastEnum::profilerName() +const char* IterateSpriteSheetFastEnum::profilerName() { return "iter fast enum"; } @@ -270,9 +259,7 @@ void IterateSpriteSheetCArray::update(float dt) CCArray* pChildren = batchNode->getChildren(); CCObject* pObject = NULL; -#if CC_ENABLE_PROFILERS - CCProfilingBeginTimingBlock(_profilingTimer); -#endif + CC_PROFILER_START(this->profilerName()); CCARRAY_FOREACH(pChildren, pObject) { @@ -280,9 +267,7 @@ void IterateSpriteSheetCArray::update(float dt) pSprite->setVisible(false); } -#if CC_ENABLE_PROFILERS - CCProfilingEndTimingBlock(_profilingTimer); -#endif + CC_PROFILER_STOP(this->profilerName()); } @@ -296,7 +281,7 @@ std::string IterateSpriteSheetCArray::subtitle() return "Iterate children using C Array API. See console"; } -std::string IterateSpriteSheetCArray::profilerName() +const char* IterateSpriteSheetCArray::profilerName() { return "iter c-array"; } @@ -308,10 +293,7 @@ std::string IterateSpriteSheetCArray::profilerName() //////////////////////////////////////////////////////// AddRemoveSpriteSheet::~AddRemoveSpriteSheet() { -#if CC_ENABLE_PROFILERS - CCProfiler::releaseTimer(_profilingTimer); _profilingTimer = NULL; -#endif } void AddRemoveSpriteSheet::initWithQuantityOfNodes(unsigned int nNodes) @@ -321,10 +303,6 @@ void AddRemoveSpriteSheet::initWithQuantityOfNodes(unsigned int nNodes) NodeChildrenMainScene::initWithQuantityOfNodes(nNodes); -#if CC_ENABLE_PROFILERS - _profilingTimer = CCProfiler::timerWithName(profilerName().c_str(), this); -#endif - scheduleUpdate(); } @@ -356,7 +334,7 @@ void AddRemoveSpriteSheet::updateQuantityOfNodes() currentQuantityOfNodes = quantityOfNodes; } -std::string AddRemoveSpriteSheet::profilerName() +const char* AddRemoveSpriteSheet::profilerName() { return "none"; } @@ -388,18 +366,16 @@ void AddSpriteSheet::update(float dt) } // add them with random Z (very important!) -#if CC_ENABLE_PROFILERS - CCProfilingBeginTimingBlock(_profilingTimer); -#endif + CC_PROFILER_START( this->profilerName() ); for( int i=0; i < totalToAdd;i++ ) { batchNode->addChild((CCNode*) (sprites->objectAtIndex(i)), zs[i], kTagBase+i); } - -#if CC_ENABLE_PROFILERS - CCProfilingEndTimingBlock(_profilingTimer); -#endif + + batchNode->sortAllChildren(); + + CC_PROFILER_STOP(this->profilerName()); // remove them for( int i=0;i < totalToAdd;i++) @@ -421,7 +397,7 @@ std::string AddSpriteSheet::subtitle() return "Adds %10 of total sprites with random z. See console"; } -std::string AddSpriteSheet::profilerName() +const char* AddSpriteSheet::profilerName() { return "add sprites"; } @@ -456,18 +432,14 @@ void RemoveSpriteSheet::update(float dt) } // remove them -#if CC_ENABLE_PROFILERS - CCProfilingBeginTimingBlock(_profilingTimer); -#endif + CC_PROFILER_START( this->profilerName() ); for( int i=0;i < totalToAdd;i++) { batchNode->removeChildByTag(kTagBase+i, true); } -#if CC_ENABLE_PROFILERS - CCProfilingEndTimingBlock(_profilingTimer); -#endif + CC_PROFILER_STOP( this->profilerName() ); } } @@ -481,7 +453,7 @@ std::string RemoveSpriteSheet::subtitle() return "Remove %10 of total sprites placed randomly. See console"; } -std::string RemoveSpriteSheet::profilerName() +const char* RemoveSpriteSheet::profilerName() { return "remove sprites"; } @@ -515,22 +487,19 @@ void ReorderSpriteSheet::update(float dt) batchNode->addChild((CCNode*) (sprites->objectAtIndex(i)), CCRANDOM_MINUS1_1() * 50, kTagBase+i); } - // [batchNode sortAllChildren]; + batchNode->sortAllChildren(); // reorder them -#if CC_ENABLE_PROFILERS - CCProfilingBeginTimingBlock(_profilingTimer); -#endif + CC_PROFILER_START( this->profilerName() ); for( int i=0;i < totalToAdd;i++) { CCNode* pNode = (CCNode*) (batchNode->getChildren()->objectAtIndex(i)); batchNode->reorderChild(pNode, CCRANDOM_MINUS1_1() * 50); } - -#if CC_ENABLE_PROFILERS - CCProfilingEndTimingBlock(_profilingTimer); -#endif + + batchNode->sortAllChildren(); + CC_PROFILER_STOP( this->profilerName() ); // remove them for( int i=0;i < totalToAdd;i++) @@ -550,7 +519,7 @@ std::string ReorderSpriteSheet::subtitle() return "Reorder %10 of total sprites placed randomly. See console"; } -std::string ReorderSpriteSheet::profilerName() +const char* ReorderSpriteSheet::profilerName() { return "reorder sprites"; } diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h index 448659c7b1..479bde3e26 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h @@ -38,14 +38,10 @@ public: virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt) = 0; - virtual std::string profilerName(); + virtual const char* profilerName(); protected: CCSpriteBatchNode *batchNode; - -#if CC_ENABLE_PROFILERS - CCProfilingTimer *_profilingTimer; -#endif }; class IterateSpriteSheetFastEnum : public IterateSpriteSheet @@ -55,7 +51,7 @@ public: virtual std::string title(); virtual std::string subtitle(); - virtual std::string profilerName(); + virtual const char* profilerName(); }; class IterateSpriteSheetCArray : public IterateSpriteSheet @@ -65,7 +61,7 @@ public: virtual std::string title(); virtual std::string subtitle(); - virtual std::string profilerName(); + virtual const char* profilerName(); }; class AddRemoveSpriteSheet : public NodeChildrenMainScene @@ -75,7 +71,7 @@ public: virtual void updateQuantityOfNodes(); virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void update(float dt) = 0; - virtual std::string profilerName(); + virtual const char* profilerName(); protected: CCSpriteBatchNode *batchNode; @@ -92,7 +88,7 @@ public: virtual std::string title(); virtual std::string subtitle(); - virtual std::string profilerName(); + virtual const char* profilerName(); }; class RemoveSpriteSheet : public AddRemoveSpriteSheet @@ -102,7 +98,7 @@ public: virtual std::string title(); virtual std::string subtitle(); - virtual std::string profilerName(); + virtual const char* profilerName(); }; class ReorderSpriteSheet : public AddRemoveSpriteSheet @@ -112,7 +108,7 @@ public: virtual std::string title(); virtual std::string subtitle(); - virtual std::string profilerName(); + virtual const char* profilerName(); }; void runNodeChildrenTest();