add a macro to stip fps related data and functions (#17934)

This commit is contained in:
minggo 2017-06-20 09:02:13 +08:00 committed by GitHub
parent 78d5a809c8
commit 3e912ffee3
5 changed files with 28 additions and 4 deletions

View File

@ -337,7 +337,9 @@ void Director::drawScene()
if (_displayStats) if (_displayStats)
{ {
#if !CC_STRIP_FPS
showStats(); showStats();
#endif
} }
_renderer->render(); _renderer->render();
@ -356,7 +358,9 @@ void Director::drawScene()
if (_displayStats) if (_displayStats)
{ {
#if !CC_STRIP_FPS
calculateMPF(); calculateMPF();
#endif
} }
} }
@ -1257,6 +1261,8 @@ void Director::updateFrameRate()
_frameRate = 1.0f / _deltaTime; _frameRate = 1.0f / _deltaTime;
} }
#if !CC_STRIP_FPS
// display the FPS using a LabelAtlas // display the FPS using a LabelAtlas
// updates the FPS every frame // updates the FPS every frame
void Director::showStats() void Director::showStats()
@ -1402,6 +1408,8 @@ void Director::createStatsLabel()
_FPSLabel->setPosition(Vec2(0, height_spacing*0)+CC_DIRECTOR_STATS_POSITION); _FPSLabel->setPosition(Vec2(0, height_spacing*0)+CC_DIRECTOR_STATS_POSITION);
} }
#endif // #if !CC_STRIP_FPS
void Director::setContentScaleFactor(float scaleFactor) void Director::setContentScaleFactor(float scaleFactor)
{ {
if (scaleFactor != _contentScaleFactor) if (scaleFactor != _contentScaleFactor)

View File

@ -593,10 +593,12 @@ protected:
void setNextScene(); void setNextScene();
void updateFrameRate(); void updateFrameRate();
#if !CC_STRIP_FPS
void showStats(); void showStats();
void createStatsLabel(); void createStatsLabel();
void calculateMPF(); void calculateMPF();
void getFPSImageData(unsigned char** datapointer, ssize_t* length); void getFPSImageData(unsigned char** datapointer, ssize_t* length);
#endif
/** calculates delta time since last time it was called */ /** calculates delta time since last time it was called */
void calculateDeltaTime(); void calculateDeltaTime();

View File

@ -398,4 +398,11 @@ THE SOFTWARE.
# define CC_ENABLE_PREMULTIPLIED_ALPHA 1 # define CC_ENABLE_PREMULTIPLIED_ALPHA 1
#endif #endif
/** @def CC_STRIP_FPS
* Whether to strip FPS related data and functions, such as cc_fps_images_png
*/
#ifndef CC_STRIP_FPS
#define CC_STRIP_FPS 0
#endif
#endif // __CCCONFIG_H__ #endif // __CCCONFIG_H__

View File

@ -25,6 +25,8 @@
#include "base/ccFPSImages.h" #include "base/ccFPSImages.h"
#if !CC_STRIP_FPS
unsigned char cc_fps_images_png[] = { unsigned char cc_fps_images_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x03, 0xe7, 0x00, 0x00, 0x00, 0x36, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x03, 0xe7, 0x00, 0x00, 0x00, 0x36,
@ -2376,3 +2378,5 @@ unsigned int cc_fps_images_len(void)
{ {
return sizeof(cc_fps_images_png); return sizeof(cc_fps_images_png);
} }
#endif // #if !CC_STRIP_FPS

View File

@ -23,20 +23,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#ifndef __BASE_CCFPSIMAGES__H #pragma once
#define __BASE_CCFPSIMAGES__H
#include "base/ccConfig.h"
/// @cond DO_NOT_SHOW /// @cond DO_NOT_SHOW
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if !CC_STRIP_FPS
extern unsigned char cc_fps_images_png[]; extern unsigned char cc_fps_images_png[];
unsigned int cc_fps_images_len(void); unsigned int cc_fps_images_len();
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/// @endcond /// @endcond
#endif // __BASE_CCFPSIMAGES__H