mirror of https://github.com/axmolengine/axmol.git
Update:
1. init CCSprite::m_pobBatchNode at the beginning of CCSprite::initWithTexture. 2. Add CCAssert in ccArrayRemoveObjectAtIndex. 3. Use new method to allocate CCDirector.
This commit is contained in:
parent
2b272e2813
commit
df58a09255
|
@ -69,21 +69,20 @@ NS_CC_BEGIN
|
|||
// XXX it shoul be a Director ivar. Move it there once support for multiple directors is added
|
||||
|
||||
// singleton stuff
|
||||
static CCDisplayLinkDirector s_sharedDirector;
|
||||
static bool s_bFirstRun = true;
|
||||
static CCDisplayLinkDirector* s_pSharedDirector = NULL;
|
||||
|
||||
#define kDefaultFPS 60 // 60 frames per second
|
||||
extern const char* cocos2dVersion(void);
|
||||
|
||||
CCDirector* CCDirector::sharedDirector(void)
|
||||
{
|
||||
if (s_bFirstRun)
|
||||
{
|
||||
s_sharedDirector.init();
|
||||
s_bFirstRun = false;
|
||||
}
|
||||
|
||||
return &s_sharedDirector;
|
||||
if (s_pSharedDirector == NULL)
|
||||
{
|
||||
s_pSharedDirector = new CCDisplayLinkDirector();
|
||||
s_pSharedDirector->init();
|
||||
}
|
||||
|
||||
return s_pSharedDirector;
|
||||
}
|
||||
|
||||
CCDirector::CCDirector(void)
|
||||
|
@ -112,6 +111,9 @@ bool CCDirector::init(void)
|
|||
m_pProjectionDelegate = NULL;
|
||||
|
||||
// FPS
|
||||
m_fAccumDt = 0.0f;
|
||||
m_fFrameRate = 0.0f;
|
||||
m_pFPSLabel = NULL;
|
||||
m_bDisplayFPS = false;
|
||||
m_uTotalFrames = m_uFrames = 0;
|
||||
m_pszFPS = new char[10];
|
||||
|
@ -157,7 +159,7 @@ bool CCDirector::init(void)
|
|||
|
||||
CCDirector::~CCDirector(void)
|
||||
{
|
||||
CCLOGINFO("cocos2d: deallocing %p", this);
|
||||
CCLOG("cocos2d: deallocing %p", this);
|
||||
|
||||
#if CC_DIRECTOR_FAST_FPS
|
||||
CC_SAFE_RELEASE(m_pFPSLabel);
|
||||
|
@ -171,6 +173,7 @@ CCDirector::~CCDirector(void)
|
|||
CC_SAFE_RELEASE(m_pTouchDispatcher);
|
||||
CC_SAFE_RELEASE(m_pKeypadDispatcher);
|
||||
CC_SAFE_DELETE(m_pAccelerometer);
|
||||
|
||||
// pop the autorelease pool
|
||||
CCPoolManager::getInstance()->pop();
|
||||
|
||||
|
@ -236,10 +239,12 @@ void CCDirector::drawScene(void)
|
|||
m_pNotificationNode->visit();
|
||||
}
|
||||
|
||||
#if CC_DIRECTOR_FAST_FPS == 1
|
||||
if (m_bDisplayFPS)
|
||||
{
|
||||
showFPS();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CC_ENABLE_PROFILERS
|
||||
showProfilers();
|
||||
|
@ -667,6 +672,7 @@ void CCDirector::purgeDirector()
|
|||
// OpenGL view
|
||||
m_pobOpenGLView->release();
|
||||
m_pobOpenGLView = NULL;
|
||||
CC_SAFE_DELETE(s_pSharedDirector);
|
||||
}
|
||||
|
||||
void CCDirector::setNextScene(void)
|
||||
|
|
|
@ -151,6 +151,7 @@ namespace cocos2d
|
|||
CCAccelerometer::CCAccelerometer() :
|
||||
m_pAccelDelegate(NULL)
|
||||
{
|
||||
memset(&m_obAccelerationValue, 0, sizeof(m_obAccelerationValue));
|
||||
}
|
||||
|
||||
CCAccelerometer::~CCAccelerometer()
|
||||
|
|
|
@ -38,8 +38,8 @@ public:
|
|||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
||||
void update( double x,double y,double z,double timestamp );
|
||||
private:
|
||||
CCAcceleration m_obAccelerationValue;
|
||||
CCAccelerometerDelegate* m_pAccelDelegate;
|
||||
CCAcceleration m_obAccelerationValue;
|
||||
};
|
||||
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -159,6 +159,7 @@ bool CCSprite::init(void)
|
|||
// designated initializer
|
||||
bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated)
|
||||
{
|
||||
m_pobBatchNode = NULL;
|
||||
// shader program
|
||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
||||
|
||||
|
@ -172,7 +173,6 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r
|
|||
m_sBlendFunc.src = CC_BLEND_SRC;
|
||||
m_sBlendFunc.dst = CC_BLEND_DST;
|
||||
|
||||
|
||||
m_bFlipX = m_bFlipY = false;
|
||||
|
||||
// default transform anchor: center
|
||||
|
@ -182,8 +182,7 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r
|
|||
m_obOffsetPosition = CCPointZero;
|
||||
|
||||
m_bHasChildren = false;
|
||||
m_pobBatchNode = NULL;
|
||||
|
||||
|
||||
// clean the Quad
|
||||
memset(&m_sQuad, 0, sizeof(m_sQuad));
|
||||
|
||||
|
|
|
@ -225,18 +225,19 @@ static inline void ccArrayRemoveAllObjects(ccArray *arr)
|
|||
Behaviour undefined if index outside [0, num-1]. */
|
||||
static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj)
|
||||
{
|
||||
if (bReleaseObj)
|
||||
{
|
||||
arr->arr[index]->release();
|
||||
}
|
||||
|
||||
arr->num--;
|
||||
CCAssert(arr && arr->num > 0 && index < arr->num, "Invalid index. Out of bounds");
|
||||
if (bReleaseObj)
|
||||
{
|
||||
arr->arr[index]->release();
|
||||
}
|
||||
|
||||
unsigned int remaining = arr->num - index;
|
||||
if (remaining > 0)
|
||||
{
|
||||
memmove(&arr->arr[index], &arr->arr[index+1], remaining * sizeof(void*));
|
||||
}
|
||||
arr->num--;
|
||||
|
||||
unsigned int remaining = arr->num - index;
|
||||
if (remaining > 0)
|
||||
{
|
||||
memmove(&arr->arr[index], &arr->arr[index+1], remaining * sizeof(void*));
|
||||
}
|
||||
}
|
||||
|
||||
/** Removes object at specified index and fills the gap with the last object,
|
||||
|
|
Loading…
Reference in New Issue