From 028cf7874eafb8aab7f09842ddfff8fa9e78d7a3 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 13 Apr 2012 11:22:17 +0800 Subject: [PATCH] issue #1156: remove unneeded macros and functions --- HelloWorld/Classes/AppDelegate.cpp | 2 +- cocos2dx/CCDirector.cpp | 156 +++++++++--------- cocos2dx/include/CCDirector.h | 150 ++++------------- cocos2dx/include/ccConfig.h | 48 ++---- cocos2dx/platform/ios/CCImage_ios.mm | 2 - .../EffectsAdvancedTest.cpp | 2 +- tests/tests/TileMapTest/TileMapTest.cpp | 4 +- 7 files changed, 134 insertions(+), 230 deletions(-) diff --git a/HelloWorld/Classes/AppDelegate.cpp b/HelloWorld/Classes/AppDelegate.cpp index 28c0eb77fc..0de388bec1 100644 --- a/HelloWorld/Classes/AppDelegate.cpp +++ b/HelloWorld/Classes/AppDelegate.cpp @@ -99,7 +99,7 @@ bool AppDelegate::applicationDidFinishLaunching() { // pDirector->enableRetinaDisplay(true); // turn on display FPS - pDirector->setDisplayFPS(true); + //pDirector->setDisplayFPS(true); // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 3d11c35348..401889eb55 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -54,9 +54,7 @@ THE SOFTWARE. #include "CCShaderCache.h" #include "kazmath/kazmath.h" #include "kazmath/GL/matrix.h" -#if CC_ENABLE_PROFILERS #include "support/CCProfiling.h" -#endif // CC_ENABLE_PROFILERS #include @@ -115,7 +113,9 @@ bool CCDirector::init(void) m_fAccumDt = 0.0f; m_fFrameRate = 0.0f; m_pFPSLabel = NULL; - m_bDisplayFPS = false; + m_pSPFLabel = NULL; + m_pDrawsLabel = NULL; + m_bDisplayStats = false; m_uTotalFrames = m_uFrames = 0; m_pszFPS = new char[10]; m_pLastUpdate = new struct cc_timeval(); @@ -162,9 +162,9 @@ CCDirector::~CCDirector(void) { CCLOG("cocos2d: deallocing %p", this); -#if CC_DIRECTOR_FAST_FPS CC_SAFE_RELEASE(m_pFPSLabel); -#endif + CC_SAFE_RELEASE(m_pSPFLabel); + CC_SAFE_RELEASE(m_pDrawsLabel); CC_SAFE_RELEASE(m_pRunningScene); CC_SAFE_RELEASE(m_pNotificationNode); @@ -196,14 +196,6 @@ void CCDirector::setGLDefaultValues(void) // set other opengl default values glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - -#if CC_DIRECTOR_FAST_FPS - if (! m_pFPSLabel) - { - m_pFPSLabel = CCLabelTTF::labelWithString("00.0", "Arial", 24); - m_pFPSLabel->retain(); - } -#endif } // Draw the SCene @@ -240,17 +232,11 @@ void CCDirector::drawScene(void) { m_pNotificationNode->visit(); } - -#if CC_DIRECTOR_FAST_FPS == 1 - if (m_bDisplayFPS) - { - showFPS(); - } -#endif - -#if CC_ENABLE_PROFILERS - showProfilers(); -#endif + + if (m_bDisplayStats) + { + showStats(); + } kmGLPopMatrix(); @@ -262,6 +248,11 @@ void CCDirector::drawScene(void) { m_pobOpenGLView->swapBuffers(); } + + if (m_bDisplayStats) + { + calculateMPF(); + } } void CCDirector::calculateDeltaTime(void) @@ -314,7 +305,15 @@ void CCDirector::setOpenGLView(CC_GLVIEW *pobOpenGLView) // set size m_obWinSizeInPoints = m_pobOpenGLView->getSize(); m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor, m_obWinSizeInPoints.height * m_fContentScaleFactor); - setGLDefaultValues(); + + createStatsLabel(); + + if (m_pobOpenGLView) + { + setGLDefaultValues(); + } + + CHECK_GL_ERROR_DEBUG(); if (m_fContentScaleFactor != 1) { @@ -521,12 +520,6 @@ CCSize CCDirector::getWinSizeInPixels() return s; } -// return the current frame size -CCSize CCDirector::getDisplaySizeInPixels(void) -{ - return m_obWinSizeInPixels; -} - void CCDirector::reshapeProjection(const CCSize& newWindowSize) { CC_UNUSED_PARAM(newWindowSize); @@ -652,9 +645,9 @@ void CCDirector::purgeDirector() stopAnimation(); -#if CC_DIRECTOR_FAST_FPS CC_SAFE_RELEASE_NULL(m_pFPSLabel); -#endif + CC_SAFE_RELEASE_NULL(m_pSPFLabel); + CC_SAFE_RELEASE_NULL(m_pDrawsLabel); CCObject* pProjectionDelegate = (CCObject*)m_pProjectionDelegate; CC_SAFE_RELEASE_NULL(pProjectionDelegate); @@ -744,41 +737,69 @@ void CCDirector::resume(void) m_fDeltaTime = 0; } -#if CC_DIRECTOR_FAST_FPS // display the FPS using a LabelAtlas // updates the FPS every frame -void CCDirector::showFPS(void) +void CCDirector::showStats(void) { m_uFrames++; m_fAccumDt += m_fDeltaTime; - - if (m_fAccumDt > CC_DIRECTOR_FPS_INTERVAL) - { - m_fFrameRate = m_uFrames / m_fAccumDt; - m_uFrames = 0; - m_fAccumDt = 0; - - sprintf(m_pszFPS, "%.1f", m_fFrameRate); - m_pFPSLabel->setString(m_pszFPS); - } - - m_pFPSLabel->draw(); + + if (m_bDisplayStats) + { + if (m_fAccumDt > CC_DIRECTOR_STATS_INTERVAL && m_pFPSLabel && m_pSPFLabel && m_pDrawsLabel) + { + sprintf(m_pszFPS, "%.3f", m_fSecondsPerFrame); + m_pFPSLabel->setString(m_pszFPS); + + m_fFrameRate = m_uFrames / m_fAccumDt; + m_uFrames = 0; + m_fAccumDt = 0; + + sprintf(m_pszFPS, "%.1f", m_fFrameRate); + m_pFPSLabel->setString(m_pszFPS); + + sprintf(m_pszFPS, "%4d", g_uNumberOfDraws); + m_pDrawsLabel->setString(m_pszFPS); + } + + m_pDrawsLabel->draw(); + m_pFPSLabel->draw(); + m_pSPFLabel->draw(); + } + + g_uNumberOfDraws = 0; } -#endif // CC_DIRECTOR_FAST_FPS - -void CCDirector::showProfilers() +void CCDirector::calculateMPF() { -#if CC_ENABLE_PROFILERS - m_fAccumDtForProfiler += m_fDeltaTime; - if (m_fAccumDtForProfiler > 1.0f) - { - m_fAccumDtForProfiler = 0; - CCProfiler::sharedProfiler()->displayTimers(); - } -#endif + struct cc_timeval now; + CCTime::gettimeofdayCocos2d(&now, NULL); + + m_fSecondsPerFrame = (now.tv_sec - m_pLastUpdate->tv_sec) + (now.tv_usec - m_pLastUpdate->tv_usec) / 1000000.0f; } +void CCDirector::createStatsLabel() +{ + if( m_pFPSLabel && m_pSPFLabel ) { + CCTexture2D *texture = m_pFPSLabel->getTexture(); + + m_pFPSLabel->release(); + m_pSPFLabel->release(); + CCTextureCache::sharedTextureCache()->removeTexture(texture); + m_pFPSLabel = NULL; + m_pSPFLabel = NULL; + } + + m_pFPSLabel = CCLabelTTF::labelWithString("00.0", "Arial", 20); + m_pSPFLabel = CCLabelTTF::labelWithString("0.000", "Arial", 20); + m_pDrawsLabel = CCLabelTTF::labelWithString("000", "Arial", 20); + + m_pDrawsLabel->setPosition(ccpAdd(ccp(0, 34), CC_DIRECTOR_STATS_POSITION)); + m_pSPFLabel->setPosition(ccpAdd(ccp(0, 17), CC_DIRECTOR_STATS_POSITION)); + m_pFPSLabel->setPosition(CC_DIRECTOR_STATS_POSITION); +} + + /*************************************************** * mobile platforms specific functions **************************************************/ @@ -797,16 +818,6 @@ void CCDirector::updateContentScaleFactor() } } - -bool CCDirector::setDirectorType(ccDirectorType obDirectorType) -{ - CC_UNUSED_PARAM(obDirectorType); - // we only support CCDisplayLinkDirector - CCDirector::sharedDirector(); - - return true; -} - bool CCDirector::enableRetinaDisplay(bool enabled) { // Already enabled? @@ -839,15 +850,6 @@ bool CCDirector::enableRetinaDisplay(bool enabled) // release cached texture CCTextureCache::purgeSharedTextureCache(); -#if CC_DIRECTOR_FAST_FPS - if (m_pFPSLabel) - { - CC_SAFE_RELEASE_NULL(m_pFPSLabel); - m_pFPSLabel = CCLabelTTF::labelWithString("00.0", "Arial", 24); - m_pFPSLabel->retain(); - } -#endif - if (m_fContentScaleFactor == 2) { m_bRetinaDisplay = true; diff --git a/cocos2dx/include/CCDirector.h b/cocos2dx/include/CCDirector.h index 7f6fb98a01..92958ea7b6 100755 --- a/cocos2dx/include/CCDirector.h +++ b/cocos2dx/include/CCDirector.h @@ -34,7 +34,7 @@ THE SOFTWARE. #include "CCArray.h" #include "CCGeometry.h" #include "CCEGLView.h" -#include "CCGL.h" +#include "CCGL.h" #include "kazmath/mat4.h" namespace cocos2d { @@ -54,66 +54,8 @@ typedef enum { /// Detault projection is 3D projection kCCDirectorProjectionDefault = kCCDirectorProjection3D, - - // backward compatibility stuff - CCDirectorProjection2D = kCCDirectorProjection2D, - CCDirectorProjection3D = kCCDirectorProjection3D, - CCDirectorProjectionCustom = kCCDirectorProjectionCustom, } ccDirectorProjection; -/** @typedef ccDirectorType - Possible Director Types. - @since v0.8.2 - */ -typedef enum { - /** Will use a Director that triggers the main loop from an NSTimer object - * - * Features and Limitations: - * - Integrates OK with UIKit objects - * - It the slowest director - * - The interval update is customizable from 1 to 60 - */ - kCCDirectorTypeNSTimer, - - /** will use a Director that triggers the main loop from a custom main loop. - * - * Features and Limitations: - * - Faster than NSTimer Director - * - It doesn't integrate well with UIKit objects - * - The interval update can't be customizable - */ - kCCDirectorTypeMainLoop, - - /** Will use a Director that triggers the main loop from a thread, but the main loop will be executed on the main thread. - * - * Features and Limitations: - * - Faster than NSTimer Director - * - It doesn't integrate well with UIKit objects - * - The interval update can't be customizable - */ - kCCDirectorTypeThreadMainLoop, - - /** Will use a Director that synchronizes timers with the refresh rate of the display. - * - * Features and Limitations: - * - Faster than NSTimer Director - * - Only available on 3.1+ - * - Scheduled timers & drawing are synchronizes with the refresh rate of the display - * - Integrates OK with UIKit objects - * - The interval update can be 1/60, 1/30, 1/15 - */ - kCCDirectorTypeDisplayLink, - - /** Default director is the NSTimer directory */ - kCCDirectorTypeDefault = kCCDirectorTypeNSTimer, - - // backward compatibility stuff - CCDirectorTypeNSTimer = kCCDirectorTypeNSTimer, - CCDirectorTypeMainLoop = kCCDirectorTypeMainLoop, - CCDirectorTypeThreadMainLoop = kCCDirectorTypeThreadMainLoop, - CCDirectorTypeDisplayLink = kCCDirectorTypeDisplayLink, - CCDirectorTypeDefault =kCCDirectorTypeDefault, -} ccDirectorType; /** @typedef ccDeviceOrientation Possible device orientations @@ -140,7 +82,7 @@ class CCScene; class CCEGLView; class CCDirectorDelegate; class CCNode; -class CCScheduler; +class CCScheduler; class CCActionManager; class CCTouchDispatcher; class CCKeypadDispatcher; @@ -184,9 +126,12 @@ public: virtual void setAnimationInterval(double dValue) = 0; /** Whether or not to display the FPS on the bottom-left corner */ - inline bool isDisplayFPS(void) { return m_bDisplayFPS; } + inline bool isDisplayStats(void) { return m_bDisplayStats; } /** Display the FPS on the bottom-left corner */ - inline void setDisplayFPS(bool bDisplayFPS) { m_bDisplayFPS = bDisplayFPS; } + inline void setDisplayStats(bool bDisplayStats) { m_bDisplayStats = bDisplayStats; } + + /** seconds per frame */ + inline float getSecondsPerFrame() { return m_fSecondsPerFrame; } /** Get the CCEGLView, where everything is rendered */ inline CC_GLVIEW* getOpenGLView(void) { return m_pobOpenGLView; } @@ -228,21 +173,13 @@ public: // window size /** returns the size of the OpenGL view in points. - It takes into account any possible rotation (device orientation) of the window */ CCSize getWinSize(void); /** returns the size of the OpenGL view in pixels. - It takes into account any possible rotation (device orientation) of the window. - On Mac winSize and winSizeInPixels return the same value. */ CCSize getWinSizeInPixels(void); - /** returns the display size of the OpenGL view in pixels. - It doesn't take into account any possible rotation of the window. - */ - CCSize getDisplaySizeInPixels(void); - /** changes the projection size */ void reshapeProjection(const CCSize& newWindowSize); @@ -264,6 +201,8 @@ public: /**Enters the Director's main loop with the given Scene. * Call it to run only your FIRST scene. * Don't call it if there is already a running scene. + * + * It will call pushScene: and then it will call startAnimation */ void runWithScene(CCScene *pScene); @@ -344,9 +283,6 @@ public: virtual void mainLoop(void) = 0; - // Profiler - void showProfilers(void); - /** rotates the screen if an orientation different than Portrait is used */ void applyOrientation(void); @@ -371,44 +307,29 @@ public: bool enableRetinaDisplay(bool enabled); bool isRetinaDisplay() { return m_bRetinaDisplay; } - /** There are 4 types of Director. - - kCCDirectorTypeNSTimer (default) - - kCCDirectorTypeMainLoop - - kCCDirectorTypeThreadMainLoop - - kCCDirectorTypeDisplayLink - - Each Director has it's own benefits, limitations. - Now we only support DisplayLink director, so it has not effect. - - This method should be called before any other call to the director. - - @since v0.8.2 - */ - static bool setDirectorType(ccDirectorType obDirectorType); - public: - /** CCScheduler associated with this director - @since v2.0 - */ - CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler); - - /** CCActionManager associated with this director - @since v2.0 - */ + /** CCScheduler associated with this director + @since v2.0 + */ + CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler); + + /** CCActionManager associated with this director + @since v2.0 + */ CC_PROPERTY(CCActionManager*, m_pActionManager, ActionManager); - /** CCTouchDispatcher associated with this director - @since v2.0 + /** CCTouchDispatcher associated with this director + @since v2.0 */ CC_PROPERTY(CCTouchDispatcher*, m_pTouchDispatcher, TouchDispatcher); - /** CCKeypadDispatcher associated with this director - @since v2.0 + /** CCKeypadDispatcher associated with this director + @since v2.0 */ CC_PROPERTY(CCKeypadDispatcher*, m_pKeypadDispatcher, KeypadDispatcher); - /** CCAccelerometer associated with this director - @since v2.0 + /** CCAccelerometer associated with this director + @since v2.0 */ CC_PROPERTY(CCAccelerometer*, m_pAccelerometer, Accelerometer); @@ -425,14 +346,13 @@ protected: void setNextScene(void); -#if CC_DIRECTOR_FAST_FPS - /** shows the FPS in the screen */ - void showFPS(void); -#else - void showFPS(void) {} -#endif // CC_DIRECTOR_FAST_FPS + void showStats(); + void createStatsLabel(); + void calculateMPF(); -/** calculates delta time since last time it was called */ void calculateDeltaTime();protected: + /** calculates delta time since last time it was called */ + void calculateDeltaTime(); +protected: /* The CCEGLView, where everything is rendered */ CC_GLVIEW *m_pobOpenGLView; @@ -442,12 +362,13 @@ protected: /* landscape mode ? */ bool m_bLandscape; - bool m_bDisplayFPS; + bool m_bDisplayStats; ccTime m_fAccumDt; ccTime m_fFrameRate; -#if CC_DIRECTOR_FAST_FPS + CCLabelTTF *m_pFPSLabel; -#endif + CCLabelTTF *m_pSPFLabel; + CCLabelTTF *m_pDrawsLabel; /* is the running scene paused */ bool m_bPaused; @@ -455,6 +376,7 @@ protected: /* How many frames were called since the director started */ unsigned int m_uTotalFrames; unsigned int m_uFrames; + ccTime m_fSecondsPerFrame; /* The running scene */ CCScene *m_pRunningScene; @@ -505,10 +427,6 @@ protected: bool m_bIsContentScaleSupported; bool m_bRetinaDisplay; - -#if CC_ENABLE_PROFILERS - ccTime m_fAccumDtForProfiler; -#endif }; /** diff --git a/cocos2dx/include/ccConfig.h b/cocos2dx/include/ccConfig.h index 8145c8a7a2..d62a87a945 100755 --- a/cocos2dx/include/ccConfig.h +++ b/cocos2dx/include/ccConfig.h @@ -76,28 +76,14 @@ To enabled set it to 1. Disabled by default. #define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0 #endif -/** @def CC_FONT_LABEL_SUPPORT - If enabled, FontLabel will be used to render .ttf files. - If the .ttf file is not found, then it will use the standard UIFont class - If disabled, the standard UIFont class will be used. - - To disable set it to 0. Enabled by default. - Only valid for cocos2d-ios. Not supported on cocos2d-mac - */ -#ifndef CC_FONT_LABEL_SUPPORT -#define CC_FONT_LABEL_SUPPORT 1 -#endif - -/** @def CC_DIRECTOR_FAST_FPS - If enabled, then the FPS will be drawn using CCLabelAtlas (fast rendering). - You will need to add the fps_images.png to your project. - If disabled, the FPS will be rendered using CCLabel (slow rendering) +/** @def CC_DIRECTOR_STATS_POSITION + Position of the FPS - To enable set it to a value different than 0. Enabled by default. + Default: 0,0 (bottom-left corner) */ -#ifndef CC_DIRECTOR_FAST_FPS -#define CC_DIRECTOR_FAST_FPS 1 +#ifndef CC_DIRECTOR_STATS_POSITION +#define CC_DIRECTOR_STATS_POSITION ccp(0,0) #endif /** @def CC_DIRECTOR_FPS_INTERVAL @@ -107,8 +93,8 @@ To enabled set it to 1. Disabled by default. Default value: 0.1f */ -#ifndef CC_DIRECTOR_FPS_INTERVAL -#define CC_DIRECTOR_FPS_INTERVAL (0.5f) +#ifndef CC_DIRECTOR_STATS_INTERVAL +#define CC_DIRECTOR_STATS_INTERVAL (0.5f) #endif /** @def CC_DIRECTOR_FPS_POSITION @@ -180,16 +166,16 @@ Only valid for cocos2d-mac. Not supported on cocos2d-ios. #define CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP 0 #endif -/** @def CC_TEXTURE_ATLAS_USE_VAO - By default, CCTextureAtlas (used by many cocos2d classes) will use VAO (Vertex Array Objects). - Apple recommends its usage but they might consume a lot of memory, specially if you use many of them. - So for certain cases, where you might need hundreds of VAO objects, it might be a good idea to disable it. - - To disable it set it to 0. Enabled by default. - - */ -#ifndef CC_TEXTURE_ATLAS_USE_VAO -#define CC_TEXTURE_ATLAS_USE_VAO 1 +/** @def CC_TEXTURE_ATLAS_USE_VAO + By default, CCTextureAtlas (used by many cocos2d classes) will use VAO (Vertex Array Objects). + Apple recommends its usage but they might consume a lot of memory, specially if you use many of them. + So for certain cases, where you might need hundreds of VAO objects, it might be a good idea to disable it. + + To disable it set it to 0. Enabled by default. + + */ +#ifndef CC_TEXTURE_ATLAS_USE_VAO +#define CC_TEXTURE_ATLAS_USE_VAO 1 #endif /** @def CC_TEXTURE_NPOT_SUPPORT diff --git a/cocos2dx/platform/ios/CCImage_ios.mm b/cocos2dx/platform/ios/CCImage_ios.mm index 75de90ed33..9a92fd9c70 100644 --- a/cocos2dx/platform/ios/CCImage_ios.mm +++ b/cocos2dx/platform/ios/CCImage_ios.mm @@ -28,11 +28,9 @@ THE SOFTWARE. #import #import -#if CC_FONT_LABEL_SUPPORT // FontLabel support #import "FontLabel/FontManager.h" #import "FontLabel/FontLabelStringDrawing.h" -#endif// CC_FONT_LABEL_SUPPORT typedef struct { diff --git a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp index 37e399dec5..298c98573a 100644 --- a/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/tests/tests/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -180,7 +180,7 @@ void Effect5::onExit() { EffectAdvanceTextLayer::onExit(); - CCDirector::sharedDirector()->setProjection(CCDirectorProjection3D); + CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D); } //------------------------------------------------------------------ diff --git a/tests/tests/TileMapTest/TileMapTest.cpp b/tests/tests/TileMapTest/TileMapTest.cpp index 23b1cc1491..89fec91ff0 100644 --- a/tests/tests/TileMapTest/TileMapTest.cpp +++ b/tests/tests/TileMapTest/TileMapTest.cpp @@ -150,12 +150,12 @@ void TMXOrthoTest::onEnter() { TileDemo::onEnter(); - CCDirector::sharedDirector()->setProjection(CCDirectorProjection3D); + CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D); } void TMXOrthoTest::onExit() { - CCDirector::sharedDirector()->setProjection(CCDirectorProjection2D); + CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D); TileDemo::onExit(); }