mirror of https://github.com/axmolengine/axmol.git
issue #1310: Used CCLabelAtlas instead of CCLabelBMFont to display FPS,SPF status.
Updated CCFileUtils, added some method, such as sharedFileUtils/purgeFileUtils/purgeCachedEntries. Fixed a bug in CCDirector, made retina mode work correctly.
This commit is contained in:
parent
c9dc60b0f7
commit
c95cbb1774
|
@ -120,7 +120,7 @@ bool CCDirector::init(void)
|
|||
|
||||
// paused ?
|
||||
m_bPaused = false;
|
||||
|
||||
|
||||
// purge ?
|
||||
m_bPurgeDirecotorInNextLoop = false;
|
||||
|
||||
|
@ -267,7 +267,7 @@ void CCDirector::calculateDeltaTime(void)
|
|||
return;
|
||||
}
|
||||
|
||||
// new delta time
|
||||
// new delta time. Re-fixed issue #1277
|
||||
if (m_bNextDeltaTimeZero)
|
||||
{
|
||||
m_fDeltaTime = 0;
|
||||
|
@ -417,11 +417,12 @@ void CCDirector::purgeCachedData(void)
|
|||
{
|
||||
CCLabelBMFont::purgeCachedData();
|
||||
CCTextureCache::sharedTextureCache()->removeUnusedTextures();
|
||||
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
|
||||
}
|
||||
|
||||
float CCDirector::getZEye(void)
|
||||
{
|
||||
return (m_obWinSizeInPixels.height / 1.1566f);
|
||||
return (m_obWinSizeInPixels.height / 1.1566f / CC_CONTENT_SCALE_FACTOR());
|
||||
}
|
||||
|
||||
void CCDirector::setAlphaBlending(bool bOn)
|
||||
|
@ -546,6 +547,35 @@ void CCDirector::popScene(void)
|
|||
}
|
||||
}
|
||||
|
||||
void CCDirector::popToRootScene(void)
|
||||
{
|
||||
CCAssert(m_pRunningScene != NULL, "A running Scene is needed");
|
||||
unsigned int c = m_pobScenesStack->count();
|
||||
|
||||
if (c == 1)
|
||||
{
|
||||
m_pobScenesStack->removeLastObject();
|
||||
this->end();
|
||||
}
|
||||
else
|
||||
{
|
||||
while (c > 1)
|
||||
{
|
||||
CCScene *current = (CCScene*)m_pobScenesStack->lastObject();
|
||||
if( current->getIsRunning() )
|
||||
{
|
||||
current->onExit();
|
||||
}
|
||||
current->cleanup();
|
||||
|
||||
m_pobScenesStack->removeLastObject();
|
||||
c--;
|
||||
}
|
||||
m_pNextScene = (CCScene*)m_pobScenesStack->lastObject();
|
||||
m_bSendCleanupToScene = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CCDirector::end()
|
||||
{
|
||||
m_bPurgeDirecotorInNextLoop = true;
|
||||
|
@ -588,6 +618,7 @@ void CCDirector::purgeDirector()
|
|||
CCSpriteFrameCache::purgeSharedSpriteFrameCache();
|
||||
CCTextureCache::purgeSharedTextureCache();
|
||||
CCShaderCache::purgeSharedShaderCache();
|
||||
CCFileUtils::purgeFileUtils();
|
||||
CCConfiguration::purgeConfiguration();
|
||||
|
||||
// cocos2d-x specific data structures
|
||||
|
@ -719,21 +750,32 @@ void CCDirector::calculateMPF()
|
|||
|
||||
void CCDirector::createStatsLabel()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(m_pFPSLabel);
|
||||
CC_SAFE_RELEASE_NULL(m_pSPFLabel);
|
||||
CC_SAFE_RELEASE_NULL(m_pDrawsLabel);
|
||||
|
||||
m_pFPSLabel = CCLabelBMFont::labelWithString("00.0", "fps_images.fnt");
|
||||
m_pSPFLabel = CCLabelBMFont::labelWithString("0.000", "fps_images.fnt");
|
||||
m_pDrawsLabel = CCLabelBMFont::labelWithString("000", "fps_images.fnt");
|
||||
|
||||
m_pFPSLabel->retain();
|
||||
m_pSPFLabel->retain();
|
||||
m_pDrawsLabel->retain();
|
||||
|
||||
m_pDrawsLabel->setPosition(ccp(20, 50));
|
||||
m_pSPFLabel->setPosition(ccp(25, 30));
|
||||
m_pFPSLabel->setPosition(ccp(20, 10));
|
||||
if( m_pFPSLabel && m_pSPFLabel )
|
||||
{
|
||||
CCTexture2D *texture = m_pFPSLabel->getTexture();
|
||||
|
||||
CC_SAFE_RELEASE_NULL(m_pFPSLabel);
|
||||
CC_SAFE_RELEASE_NULL(m_pSPFLabel);
|
||||
CC_SAFE_RELEASE_NULL(m_pDrawsLabel);
|
||||
CCTextureCache::sharedTextureCache()->removeTexture(texture);
|
||||
|
||||
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
|
||||
}
|
||||
|
||||
CCTexture2DPixelFormat currentFormat = CCTexture2D::defaultAlphaPixelFormat();
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
|
||||
m_pFPSLabel = new CCLabelAtlas();
|
||||
m_pFPSLabel->initWithString("00.0", "fps_images.png", 12, 32, '.');
|
||||
m_pSPFLabel = new CCLabelAtlas();
|
||||
m_pSPFLabel->initWithString("0.000", "fps_images.png", 12, 32, '.');
|
||||
m_pDrawsLabel = new CCLabelAtlas();
|
||||
m_pDrawsLabel->initWithString("000", "fps_images.png", 12, 32, '.');
|
||||
|
||||
CCTexture2D::setDefaultAlphaPixelFormat(currentFormat);
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef enum {
|
|||
} ccDirectorProjection;
|
||||
|
||||
/* Forward declarations. */
|
||||
class CCLabelBMFont;
|
||||
class CCLabelAtlas;
|
||||
class CCScene;
|
||||
class CCEGLView;
|
||||
class CCDirectorDelegate;
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
|
||||
/** Whether or not the Director is paused */
|
||||
inline bool isPaused(void) { return m_bPaused; }
|
||||
|
||||
|
||||
/** How many frames were called since the director started */
|
||||
inline unsigned int getFrames(void) { return m_uFrames; }
|
||||
|
||||
|
@ -200,6 +200,13 @@ public:
|
|||
*/
|
||||
void popScene(void);
|
||||
|
||||
/**Pops out all scenes from the queue until the root scene in the queue.
|
||||
* This scene will replace the running one.
|
||||
* The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.
|
||||
* ONLY call it if there is a running scene.
|
||||
*/
|
||||
void popToRootScene(void);
|
||||
|
||||
/** Replaces the running scene with a new one. The running scene is terminated.
|
||||
* ONLY call it if there is a running scene.
|
||||
*/
|
||||
|
@ -332,13 +339,13 @@ protected:
|
|||
float m_fAccumDt;
|
||||
float m_fFrameRate;
|
||||
|
||||
CCLabelBMFont *m_pFPSLabel;
|
||||
CCLabelBMFont *m_pSPFLabel;
|
||||
CCLabelBMFont *m_pDrawsLabel;
|
||||
CCLabelAtlas *m_pFPSLabel;
|
||||
CCLabelAtlas *m_pSPFLabel;
|
||||
CCLabelAtlas *m_pDrawsLabel;
|
||||
|
||||
/* is the running scene paused */
|
||||
/** Whether or not the Director is paused */
|
||||
bool m_bPaused;
|
||||
|
||||
|
||||
/* How many frames were called since the director started */
|
||||
unsigned int m_uTotalFrames;
|
||||
unsigned int m_uFrames;
|
||||
|
|
|
@ -36,6 +36,8 @@ class CC_DLL CCFileUtils
|
|||
public:
|
||||
static CCFileUtils* sharedFileUtils();
|
||||
static void purgeFileUtils();
|
||||
|
||||
void purgeCachedEntries();
|
||||
/**
|
||||
@brief Get resource file data
|
||||
@param[in] pszFileName The resource file name which contain the path
|
||||
|
|
|
@ -25,16 +25,42 @@ THE SOFTWARE.
|
|||
#define __CC_PLATFORM_FILEUTILS_CPP__
|
||||
#include "CCFileUtilsCommon_cpp.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
#include "CCCommon.h"
|
||||
#include "jni/SystemInfoJni.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// record the resource path
|
||||
static string s_strResourcePath = "";
|
||||
|
||||
static CCFileUtils* s_pFileUtils = NULL;
|
||||
|
||||
CCFileUtils* CCFileUtils::sharedFileUtils()
|
||||
{
|
||||
if (s_pFileUtils == NULL)
|
||||
{
|
||||
s_pFileUtils = new CCFileUtils();
|
||||
}
|
||||
return s_pFileUtils;
|
||||
}
|
||||
|
||||
void CCFileUtils::purgeFileUtils()
|
||||
{
|
||||
if (s_pFileUtils != NULL)
|
||||
{
|
||||
s_pFileUtils->purgeCachedEntries();
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(s_pFileUtils);
|
||||
}
|
||||
|
||||
void CCFileUtils::purgeCachedEntries()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is implemented for jni to set apk path.
|
||||
*/
|
||||
|
|
|
@ -212,6 +212,32 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict)
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static CCFileUtils* s_pFileUtils = NULL;
|
||||
|
||||
CCFileUtils* CCFileUtils::sharedFileUtils()
|
||||
{
|
||||
if (s_pFileUtils == NULL)
|
||||
{
|
||||
s_pFileUtils = new CCFileUtils();
|
||||
}
|
||||
return s_pFileUtils;
|
||||
}
|
||||
|
||||
void CCFileUtils::purgeFileUtils()
|
||||
{
|
||||
if (s_pFileUtils != NULL)
|
||||
{
|
||||
s_pFileUtils->purgeCachedEntries();
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(s_pFileUtils);
|
||||
}
|
||||
|
||||
void CCFileUtils::purgeCachedEntries()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||
{
|
||||
assert(0);
|
||||
|
|
|
@ -62,9 +62,19 @@ CCFileUtils* CCFileUtils::sharedFileUtils()
|
|||
|
||||
void CCFileUtils::purgeFileUtils()
|
||||
{
|
||||
if (s_pFileUtils != NULL)
|
||||
{
|
||||
s_pFileUtils->purgeCachedEntries();
|
||||
}
|
||||
|
||||
CC_SAFE_DELETE(s_pFileUtils);
|
||||
}
|
||||
|
||||
void CCFileUtils::purgeCachedEntries()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCFileUtils::setResourcePath(const char *pszResourcePath)
|
||||
{
|
||||
CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
|
||||
|
|
|
@ -90,6 +90,9 @@ void DrawPrimitivesTest::draw()
|
|||
ccDrawCubicBezier(ccp(s.width/2, s.height/2), ccp(s.width/2+30,s.height/2+50), ccp(s.width/2+60,s.height/2-50),ccp(s.width, s.height/2),100);
|
||||
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
//draw a solid polygon
|
||||
CCPoint vertices3[] = {ccp(60,160), ccp(70,190), ccp(100,190), ccp(90,160)};
|
||||
ccDrawSolidPoly( vertices3, 4, ccc4f(1,1,0,1) );
|
||||
|
||||
// restore original values
|
||||
glLineWidth(1);
|
||||
|
|
|
@ -1104,7 +1104,7 @@ void ParticleDemo::onEnter(void)
|
|||
|
||||
addChild( menu, 100 );
|
||||
|
||||
CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.');
|
||||
CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fps_images.png", 12, 32, '.');
|
||||
addChild(labelAtlas, 100, kTagParticleCount);
|
||||
labelAtlas->setPosition(CCPointMake(s.width-66,50));
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ void ParticleMainScene::initWithSubTest(int asubtest, int particles)
|
|||
addChild(infoLabel, 1, kTagInfoLayer);
|
||||
|
||||
// particles on stage
|
||||
CCLabelAtlas *labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.');
|
||||
CCLabelAtlas *labelAtlas = CCLabelAtlas::labelWithString("0000", "fps_images.png", 12, 32, '.');
|
||||
addChild(labelAtlas, 0, kTagLabelAtlas);
|
||||
labelAtlas->setPosition(ccp(s.width-66,50));
|
||||
|
||||
|
|
Loading…
Reference in New Issue