Merge pull request #991 from dumganhar/gles20

issue #1310: Synchronize to RC2, updated something as follows.
* 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:
James Chen 2012-06-10 20:05:32 -07:00
commit ed09baeeb0
9 changed files with 139 additions and 34 deletions

View File

@ -120,7 +120,7 @@ bool CCDirector::init(void)
// paused ? // paused ?
m_bPaused = false; m_bPaused = false;
// purge ? // purge ?
m_bPurgeDirecotorInNextLoop = false; m_bPurgeDirecotorInNextLoop = false;
@ -267,7 +267,7 @@ void CCDirector::calculateDeltaTime(void)
return; return;
} }
// new delta time // new delta time. Re-fixed issue #1277
if (m_bNextDeltaTimeZero) if (m_bNextDeltaTimeZero)
{ {
m_fDeltaTime = 0; m_fDeltaTime = 0;
@ -417,11 +417,12 @@ void CCDirector::purgeCachedData(void)
{ {
CCLabelBMFont::purgeCachedData(); CCLabelBMFont::purgeCachedData();
CCTextureCache::sharedTextureCache()->removeUnusedTextures(); CCTextureCache::sharedTextureCache()->removeUnusedTextures();
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
} }
float CCDirector::getZEye(void) 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) 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() void CCDirector::end()
{ {
m_bPurgeDirecotorInNextLoop = true; m_bPurgeDirecotorInNextLoop = true;
@ -588,6 +618,7 @@ void CCDirector::purgeDirector()
CCSpriteFrameCache::purgeSharedSpriteFrameCache(); CCSpriteFrameCache::purgeSharedSpriteFrameCache();
CCTextureCache::purgeSharedTextureCache(); CCTextureCache::purgeSharedTextureCache();
CCShaderCache::purgeSharedShaderCache(); CCShaderCache::purgeSharedShaderCache();
CCFileUtils::purgeFileUtils();
CCConfiguration::purgeConfiguration(); CCConfiguration::purgeConfiguration();
// cocos2d-x specific data structures // cocos2d-x specific data structures
@ -719,21 +750,32 @@ void CCDirector::calculateMPF()
void CCDirector::createStatsLabel() void CCDirector::createStatsLabel()
{ {
CC_SAFE_RELEASE_NULL(m_pFPSLabel); if( m_pFPSLabel && m_pSPFLabel )
CC_SAFE_RELEASE_NULL(m_pSPFLabel); {
CC_SAFE_RELEASE_NULL(m_pDrawsLabel); CCTexture2D *texture = m_pFPSLabel->getTexture();
m_pFPSLabel = CCLabelBMFont::labelWithString("00.0", "fps_images.fnt"); CC_SAFE_RELEASE_NULL(m_pFPSLabel);
m_pSPFLabel = CCLabelBMFont::labelWithString("0.000", "fps_images.fnt"); CC_SAFE_RELEASE_NULL(m_pSPFLabel);
m_pDrawsLabel = CCLabelBMFont::labelWithString("000", "fps_images.fnt"); CC_SAFE_RELEASE_NULL(m_pDrawsLabel);
CCTextureCache::sharedTextureCache()->removeTexture(texture);
m_pFPSLabel->retain();
m_pSPFLabel->retain(); CCFileUtils::sharedFileUtils()->purgeCachedEntries();
m_pDrawsLabel->retain(); }
m_pDrawsLabel->setPosition(ccp(20, 50)); CCTexture2DPixelFormat currentFormat = CCTexture2D::defaultAlphaPixelFormat();
m_pSPFLabel->setPosition(ccp(25, 30)); CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
m_pFPSLabel->setPosition(ccp(20, 10)); 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 );
} }

View File

@ -55,7 +55,7 @@ typedef enum {
} ccDirectorProjection; } ccDirectorProjection;
/* Forward declarations. */ /* Forward declarations. */
class CCLabelBMFont; class CCLabelAtlas;
class CCScene; class CCScene;
class CCEGLView; class CCEGLView;
class CCDirectorDelegate; class CCDirectorDelegate;
@ -120,7 +120,7 @@ public:
/** Whether or not the Director is paused */ /** Whether or not the Director is paused */
inline bool isPaused(void) { return m_bPaused; } inline bool isPaused(void) { return m_bPaused; }
/** How many frames were called since the director started */ /** How many frames were called since the director started */
inline unsigned int getFrames(void) { return m_uFrames; } inline unsigned int getFrames(void) { return m_uFrames; }
@ -200,6 +200,13 @@ public:
*/ */
void popScene(void); 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. /** Replaces the running scene with a new one. The running scene is terminated.
* ONLY call it if there is a running scene. * ONLY call it if there is a running scene.
*/ */
@ -332,13 +339,13 @@ protected:
float m_fAccumDt; float m_fAccumDt;
float m_fFrameRate; float m_fFrameRate;
CCLabelBMFont *m_pFPSLabel; CCLabelAtlas *m_pFPSLabel;
CCLabelBMFont *m_pSPFLabel; CCLabelAtlas *m_pSPFLabel;
CCLabelBMFont *m_pDrawsLabel; CCLabelAtlas *m_pDrawsLabel;
/* is the running scene paused */ /** Whether or not the Director is paused */
bool m_bPaused; bool m_bPaused;
/* How many frames were called since the director started */ /* How many frames were called since the director started */
unsigned int m_uTotalFrames; unsigned int m_uTotalFrames;
unsigned int m_uFrames; unsigned int m_uFrames;

View File

@ -36,6 +36,8 @@ class CC_DLL CCFileUtils
public: public:
static CCFileUtils* sharedFileUtils(); static CCFileUtils* sharedFileUtils();
static void purgeFileUtils(); static void purgeFileUtils();
void purgeCachedEntries();
/** /**
@brief Get resource file data @brief Get resource file data
@param[in] pszFileName The resource file name which contain the path @param[in] pszFileName The resource file name which contain the path

View File

@ -25,16 +25,42 @@ THE SOFTWARE.
#define __CC_PLATFORM_FILEUTILS_CPP__ #define __CC_PLATFORM_FILEUTILS_CPP__
#include "CCFileUtilsCommon_cpp.h" #include "CCFileUtilsCommon_cpp.h"
using namespace std;
NS_CC_BEGIN NS_CC_BEGIN
#include "CCCommon.h" #include "CCCommon.h"
#include "jni/SystemInfoJni.h" #include "jni/SystemInfoJni.h"
using namespace std;
// record the resource path // record the resource path
static string s_strResourcePath = ""; 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. * This function is implemented for jni to set apk path.
*/ */

View File

@ -212,15 +212,30 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict)
NS_CC_BEGIN NS_CC_BEGIN
static CCFileUtils* s_pFileUtils = NULL;
CCFileUtils* CCFileUtils::sharedFileUtils() CCFileUtils* CCFileUtils::sharedFileUtils()
{ {
static CCFileUtils *fileUtils = NULL; if (s_pFileUtils == NULL)
if (fileUtils == NULL)
{ {
fileUtils = new CCFileUtils(); s_pFileUtils = new CCFileUtils();
} }
return s_pFileUtils;
return fileUtils; }
void CCFileUtils::purgeFileUtils()
{
if (s_pFileUtils != NULL)
{
s_pFileUtils->purgeCachedEntries();
}
CC_SAFE_DELETE(s_pFileUtils);
}
void CCFileUtils::purgeCachedEntries()
{
} }
void CCFileUtils::setResourcePath(const char *pszResourcePath) void CCFileUtils::setResourcePath(const char *pszResourcePath)

View File

@ -62,9 +62,19 @@ CCFileUtils* CCFileUtils::sharedFileUtils()
void CCFileUtils::purgeFileUtils() void CCFileUtils::purgeFileUtils()
{ {
if (s_pFileUtils != NULL)
{
s_pFileUtils->purgeCachedEntries();
}
CC_SAFE_DELETE(s_pFileUtils); CC_SAFE_DELETE(s_pFileUtils);
} }
void CCFileUtils::purgeCachedEntries()
{
}
void CCFileUtils::setResourcePath(const char *pszResourcePath) void CCFileUtils::setResourcePath(const char *pszResourcePath)
{ {
CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path"); CCAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");

View File

@ -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); 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(); 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 // restore original values
glLineWidth(1); glLineWidth(1);

View File

@ -1104,7 +1104,7 @@ void ParticleDemo::onEnter(void)
addChild( menu, 100 ); 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); addChild(labelAtlas, 100, kTagParticleCount);
labelAtlas->setPosition(CCPointMake(s.width-66,50)); labelAtlas->setPosition(CCPointMake(s.width-66,50));

View File

@ -95,7 +95,7 @@ void ParticleMainScene::initWithSubTest(int asubtest, int particles)
addChild(infoLabel, 1, kTagInfoLayer); addChild(infoLabel, 1, kTagInfoLayer);
// particles on stage // 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); addChild(labelAtlas, 0, kTagLabelAtlas);
labelAtlas->setPosition(ccp(s.width-66,50)); labelAtlas->setPosition(ccp(s.width-66,50));