From aaae566b7b320f301c257fa478d1a53cc2b6ce94 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Thu, 2 Apr 2015 23:35:56 +0800 Subject: [PATCH] Performance: Fixed lag if Director::setContentScaleFactor is called frequently --- cocos/base/CCDirector.cpp | 13 ++++++++++--- cocos/base/CCDirector.h | 4 +++- cocos/platform/CCGLView.cpp | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 6a08b27ae8..fdb9ccffe8 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -2,7 +2,7 @@ Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) 2011 Zynga Inc. -Copyright (c) 2013-2014 Chukong Technologies Inc. +Copyright (c) 2013-2015 Chukong Technologies Inc. http://www.cocos2d-x.org @@ -107,6 +107,7 @@ Director* Director::getInstance() } Director::Director() +: _isStatusLabelUpdated(true) { } @@ -386,7 +387,7 @@ void Director::setOpenGLView(GLView *openGLView) // set size _winSizeInPoints = _openGLView->getDesignResolutionSize(); - createStatsLabel(); + _isStatusLabelUpdated = true; if (_openGLView) { @@ -1110,6 +1111,12 @@ void Director::resume() // updates the FPS every frame void Director::showStats() { + if (_isStatusLabelUpdated) + { + createStatsLabel(); + _isStatusLabelUpdated = false; + } + static unsigned long prevCalls = 0; static unsigned long prevVerts = 0; static float prevDeltaTime = 0.016f; // 60FPS @@ -1255,7 +1262,7 @@ void Director::setContentScaleFactor(float scaleFactor) if (scaleFactor != _contentScaleFactor) { _contentScaleFactor = scaleFactor; - createStatsLabel(); + _isStatusLabelUpdated = true; } } diff --git a/cocos/base/CCDirector.h b/cocos/base/CCDirector.h index c54ad53b58..ec05d21950 100644 --- a/cocos/base/CCDirector.h +++ b/cocos/base/CCDirector.h @@ -2,7 +2,7 @@ Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2010-2013 cocos2d-x.org Copyright (c) 2011 Zynga Inc. - Copyright (c) 2013-2014 Chukong Technologies Inc. + Copyright (c) 2013-2015 Chukong Technologies Inc. http://www.cocos2d-x.org @@ -597,6 +597,8 @@ protected: /* Console for the director */ Console *_console; + bool _isStatusLabelUpdated; + // GLView will recreate stats labels to fit visible rect friend class GLView; }; diff --git a/cocos/platform/CCGLView.cpp b/cocos/platform/CCGLView.cpp index 83709f06b8..0e7897a625 100644 --- a/cocos/platform/CCGLView.cpp +++ b/cocos/platform/CCGLView.cpp @@ -1,6 +1,6 @@ /**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2014 Chukong Technologies Inc. +Copyright (c) 2013-2015 Chukong Technologies Inc. http://www.cocos2d-x.org @@ -156,7 +156,7 @@ void GLView::updateDesignResolutionSize() // reset director's member variables to fit visible rect auto director = Director::getInstance(); director->_winSizeInPoints = getDesignResolutionSize(); - director->createStatsLabel(); + director->_isStatusLabelUpdated = true; director->setGLDefaultValues(); } }