#1056: issue #1056: synchronise cocos2d-iphone-2.0-rc0a, update some files.

This commit is contained in:
James Chen 2012-03-16 17:56:19 +08:00
parent 275891dfb0
commit e021ae9821
30 changed files with 608 additions and 472 deletions

View File

@ -345,7 +345,9 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
kmGLMatrixMode(KM_GL_PROJECTION); kmGLMatrixMode(KM_GL_PROJECTION);
kmGLLoadIdentity(); kmGLLoadIdentity();
kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)sizePoint.width/sizePoint.height, 0.5f, 1500.0f ); // issue #1334
kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, zeye*2);
// kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, 1500);
kmGLMultMatrix(&matrixPerspective); kmGLMultMatrix(&matrixPerspective);
kmGLMatrixMode(KM_GL_MODELVIEW); kmGLMatrixMode(KM_GL_MODELVIEW);
@ -367,7 +369,7 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
break; break;
default: default:
CCLOG("cocos2d: Director: unrecognized projecgtion"); CCLOG("cocos2d: Director: unrecognized projection");
break; break;
} }
@ -397,8 +399,8 @@ void CCDirector::setAlphaBlending(bool bOn)
{ {
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
// TODO:
//CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
void CCDirector::setDepthTest(bool bOn) void CCDirector::setDepthTest(bool bOn)

View File

@ -2045,12 +2045,12 @@ bool CCAnimate::initWithAnimation(CCAnimation *pAnimation)
if ( CCActionInterval::initWithDuration(singleDuration * pAnimation->getLoops() ) ) if ( CCActionInterval::initWithDuration(singleDuration * pAnimation->getLoops() ) )
{ {
nextFrame_ = 0; m_nNextFrame = 0;
m_pAnimation = pAnimation; setAnimation(pAnimation);
m_pOrigFrame = NULL; m_pOrigFrame = NULL;
executedLoops_ = 0; m_uExecutedLoops = 0;
splitTimes_->reserve(pAnimation->getFrames()->count()); m_pSplitTimes->reserve(pAnimation->getFrames()->count());
float accumUnitsOfTime = 0; float accumUnitsOfTime = 0;
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits(); float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
@ -2061,7 +2061,7 @@ bool CCAnimate::initWithAnimation(CCAnimation *pAnimation)
CCAnimationFrame *frame = *iterFrame; CCAnimationFrame *frame = *iterFrame;
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
accumUnitsOfTime += frame->getDelayUnits(); accumUnitsOfTime += frame->getDelayUnits();
splitTimes_->push_back(value); m_pSplitTimes->push_back(value);
} }
return true; return true;
} }
@ -2093,10 +2093,10 @@ CCObject* CCAnimate::copyWithZone(CCZone *pZone)
CCAnimate::CCAnimate() CCAnimate::CCAnimate()
: m_pAnimation(NULL) : m_pAnimation(NULL)
, splitTimes_(new std::vector<float>) , m_pSplitTimes(new std::vector<float>)
, nextFrame_(0) , m_nNextFrame(0)
, m_pOrigFrame(NULL) , m_pOrigFrame(NULL)
, executedLoops_(0) , m_uExecutedLoops(0)
{ {
} }
@ -2105,7 +2105,7 @@ CCAnimate::~CCAnimate()
{ {
CC_SAFE_RELEASE(m_pAnimation); CC_SAFE_RELEASE(m_pAnimation);
CC_SAFE_RELEASE(m_pOrigFrame); CC_SAFE_RELEASE(m_pOrigFrame);
CC_SAFE_DELETE(splitTimes_); CC_SAFE_DELETE(m_pSplitTimes);
} }
void CCAnimate::startWithTarget(CCNode *pTarget) void CCAnimate::startWithTarget(CCNode *pTarget)
@ -2120,8 +2120,8 @@ void CCAnimate::startWithTarget(CCNode *pTarget)
m_pOrigFrame = pSprite->displayFrame(); m_pOrigFrame = pSprite->displayFrame();
m_pOrigFrame->retain(); m_pOrigFrame->retain();
} }
nextFrame_ = 0; m_nNextFrame = 0;
executedLoops_ = 0; m_uExecutedLoops = 0;
} }
void CCAnimate::stop(void) void CCAnimate::stop(void)
@ -2142,9 +2142,9 @@ void CCAnimate::update(ccTime t)
// new loop? If so, reset frame counter // new loop? If so, reset frame counter
unsigned int loopNumber = (unsigned int)t; unsigned int loopNumber = (unsigned int)t;
if( loopNumber > executedLoops_ ) { if( loopNumber > m_uExecutedLoops ) {
nextFrame_ = 0; m_nNextFrame = 0;
executedLoops_++; m_uExecutedLoops++;
} }
// new t for animations // new t for animations
@ -2155,8 +2155,8 @@ void CCAnimate::update(ccTime t)
unsigned int numberOfFrames = frames->count(); unsigned int numberOfFrames = frames->count();
CCSpriteFrame *frameToDisplay = NULL; CCSpriteFrame *frameToDisplay = NULL;
for( unsigned int i=nextFrame_; i < numberOfFrames; i++ ) { for( unsigned int i=m_nNextFrame; i < numberOfFrames; i++ ) {
float splitTime = splitTimes_->at(i); float splitTime = m_pSplitTimes->at(i);
if( splitTime <= t ) { if( splitTime <= t ) {
CCAnimationFrame *frame = frames->getObjectAtIndex(i); CCAnimationFrame *frame = frames->getObjectAtIndex(i);
@ -2168,7 +2168,7 @@ void CCAnimate::update(ccTime t)
{ {
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict]; //TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
} }
nextFrame_ = i+1; m_nNextFrame = i+1;
break; break;
} }

View File

@ -108,7 +108,7 @@ bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, uns
// shader stuff // shader stuff
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor)); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
m_nUniformColor = glGetUniformLocation( m_pShaderProgram->getProgram(), "u_color"); m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");
return true; return true;
} }
@ -137,7 +137,7 @@ void CCAtlasNode::draw()
ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst ); ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
GLfloat colors[4] = {m_tColor.r / 255.0f, m_tColor.g / 255.0f, m_tColor.b / 255.0f, m_cOpacity / 255.0f}; GLfloat colors[4] = {m_tColor.r / 255.0f, m_tColor.g / 255.0f, m_tColor.b / 255.0f, m_cOpacity / 255.0f};
m_pShaderProgram->setUniformLocationWith4fv(m_nUniformColor, colors, 1); getShaderProgram()->setUniformLocationWith4fv(m_nUniformColor, colors, 1);
m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0); m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0);
} }

View File

@ -642,7 +642,7 @@ void CCNode::insertChild(CCNode* child, int z)
{ {
m_bReorderChildDirty = true; m_bReorderChildDirty = true;
ccArrayAppendObjectWithResize(m_pChildren->data, child); ccArrayAppendObjectWithResize(m_pChildren->data, child);
child->setZOrder(z); child->_setZOrder(z);
} }
void CCNode::reorderChild(CCNode *child, int zOrder) void CCNode::reorderChild(CCNode *child, int zOrder)
@ -650,7 +650,7 @@ void CCNode::reorderChild(CCNode *child, int zOrder)
CCAssert( child != NULL, "Child must be non-nil"); CCAssert( child != NULL, "Child must be non-nil");
m_bReorderChildDirty = true; m_bReorderChildDirty = true;
child->setOrderOfArrival(s_globalOrderOfArrival++); child->setOrderOfArrival(s_globalOrderOfArrival++);
child->setZOrder(zOrder); child->_setZOrder(zOrder);
} }
void CCNode::sortAllChildren() void CCNode::sortAllChildren()
@ -900,21 +900,6 @@ unsigned int CCNode::numberOfRunningActions()
return m_pActionManager->numberOfRunningActionsInTarget(this); return m_pActionManager->numberOfRunningActionsInTarget(this);
} }
void CCNode::setShaderProgram(CCGLProgram* pShaderProgram)
{
if (m_pShaderProgram != pShaderProgram)
{
CC_SAFE_RETAIN(pShaderProgram);
CC_SAFE_RELEASE(m_pShaderProgram);
m_pShaderProgram = pShaderProgram;
}
}
CCGLProgram* CCNode::getShaderProgram(void)
{
return m_pShaderProgram;
}
// CCNode - Callbacks // CCNode - Callbacks
void CCNode::setScheduler(CCScheduler* scheduler) void CCNode::setScheduler(CCScheduler* scheduler)

View File

@ -272,8 +272,10 @@ void CCGLProgram::setUniformLocationWith1i(unsigned int location, GLint i1)
{ {
bool updated = updateUniformLocation(location, &i1, sizeof(i1)*1); bool updated = updateUniformLocation(location, &i1, sizeof(i1)*1);
if( updated ) if( updated )
{
glUniform1i( (GLint)location, i1); glUniform1i( (GLint)location, i1);
}
} }
void CCGLProgram::setUniformLocationWith1f(unsigned int location, GLfloat f1) void CCGLProgram::setUniformLocationWith1f(unsigned int location, GLfloat f1)
@ -281,7 +283,9 @@ void CCGLProgram::setUniformLocationWith1f(unsigned int location, GLfloat f1)
bool updated = updateUniformLocation(location, &f1, sizeof(f1)*1); bool updated = updateUniformLocation(location, &f1, sizeof(f1)*1);
if( updated ) if( updated )
{
glUniform1f( (GLint)location, f1); glUniform1f( (GLint)location, f1);
}
} }
void CCGLProgram::setUniformLocationWith2f(unsigned int location, GLfloat f1, GLfloat f2) void CCGLProgram::setUniformLocationWith2f(unsigned int location, GLfloat f1, GLfloat f2)
@ -290,7 +294,9 @@ void CCGLProgram::setUniformLocationWith2f(unsigned int location, GLfloat f1, GL
bool updated = updateUniformLocation(location, floats, sizeof(floats)); bool updated = updateUniformLocation(location, floats, sizeof(floats));
if( updated ) if( updated )
{
glUniform2f( (GLint)location, f1, f2); glUniform2f( (GLint)location, f1, f2);
}
} }
void CCGLProgram::setUniformLocationWith3f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3) void CCGLProgram::setUniformLocationWith3f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3)
@ -299,7 +305,9 @@ void CCGLProgram::setUniformLocationWith3f(unsigned int location, GLfloat f1, GL
bool updated = updateUniformLocation(location, floats, sizeof(floats)); bool updated = updateUniformLocation(location, floats, sizeof(floats));
if( updated ) if( updated )
{
glUniform3f( (GLint)location, f1, f2, f3); glUniform3f( (GLint)location, f1, f2, f3);
}
} }
void CCGLProgram::setUniformLocationWith4f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4) void CCGLProgram::setUniformLocationWith4f(unsigned int location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4)
@ -308,7 +316,9 @@ void CCGLProgram::setUniformLocationWith4f(unsigned int location, GLfloat f1, GL
bool updated = updateUniformLocation(location, floats, sizeof(floats)); bool updated = updateUniformLocation(location, floats, sizeof(floats));
if( updated ) if( updated )
{
glUniform4f( (GLint)location, f1, f2, f3,f4); glUniform4f( (GLint)location, f1, f2, f3,f4);
}
} }
void CCGLProgram::setUniformLocationWith2fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays) void CCGLProgram::setUniformLocationWith2fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays)
@ -316,7 +326,9 @@ void CCGLProgram::setUniformLocationWith2fv(unsigned int location, GLfloat* floa
bool updated = updateUniformLocation(location, floats, sizeof(float)*2*numberOfArrays); bool updated = updateUniformLocation(location, floats, sizeof(float)*2*numberOfArrays);
if( updated ) if( updated )
{
glUniform2fv( (GLint)location, (GLsizei)numberOfArrays, floats ); glUniform2fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
} }
void CCGLProgram::setUniformLocationWith3fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays) void CCGLProgram::setUniformLocationWith3fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays)
@ -324,7 +336,9 @@ void CCGLProgram::setUniformLocationWith3fv(unsigned int location, GLfloat* floa
bool updated = updateUniformLocation(location, floats, sizeof(float)*3*numberOfArrays); bool updated = updateUniformLocation(location, floats, sizeof(float)*3*numberOfArrays);
if( updated ) if( updated )
{
glUniform3fv( (GLint)location, (GLsizei)numberOfArrays, floats ); glUniform3fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
} }
void CCGLProgram::setUniformLocationWith4fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays) void CCGLProgram::setUniformLocationWith4fv(unsigned int location, GLfloat* floats, unsigned int numberOfArrays)
@ -332,7 +346,9 @@ void CCGLProgram::setUniformLocationWith4fv(unsigned int location, GLfloat* floa
bool updated = updateUniformLocation(location, floats, sizeof(float)*4*numberOfArrays); bool updated = updateUniformLocation(location, floats, sizeof(float)*4*numberOfArrays);
if( updated ) if( updated )
{
glUniform4fv( (GLint)location, (GLsizei)numberOfArrays, floats ); glUniform4fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
} }
@ -341,7 +357,9 @@ void CCGLProgram::setUniformLocationwithMatrix4fv(unsigned int location, GLfloat
bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*16*numberOfMatrices); bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*16*numberOfMatrices);
if( updated ) if( updated )
{
glUniformMatrix4fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray); glUniformMatrix4fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray);
}
} }
void CCGLProgram::setUniformForModelViewProjectionMatrix() void CCGLProgram::setUniformForModelViewProjectionMatrix()

View File

@ -51,7 +51,7 @@ void CCShaderCache::purgeSharedShaderCache()
} }
CCShaderCache::CCShaderCache() CCShaderCache::CCShaderCache()
: programs_(0) : m_pPrograms(0)
{ {
} }
@ -59,12 +59,12 @@ CCShaderCache::CCShaderCache()
CCShaderCache::~CCShaderCache() CCShaderCache::~CCShaderCache()
{ {
CCLOGINFO("cocos2d deallocing 0x%X", this); CCLOGINFO("cocos2d deallocing 0x%X", this);
programs_->release(); m_pPrograms->release();
} }
bool CCShaderCache::init() bool CCShaderCache::init()
{ {
programs_ = new CCMutableDictionary<std::string, CCGLProgram*>(); m_pPrograms = new CCMutableDictionary<std::string, CCGLProgram*>();
loadDefaultShaders(); loadDefaultShaders();
return true; return true;
} }
@ -82,7 +82,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p, kCCShader_PositionTextureColor); m_pPrograms->setObject(p, kCCShader_PositionTextureColor);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -98,7 +98,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p, kCCShader_PositionTextureColorAlphaTest); m_pPrograms->setObject(p, kCCShader_PositionTextureColorAlphaTest);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -115,7 +115,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p, kCCShader_PositionColor); m_pPrograms->setObject(p, kCCShader_PositionColor);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -131,7 +131,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p, kCCShader_PositionTexture); m_pPrograms->setObject(p, kCCShader_PositionTexture);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -148,7 +148,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p ,kCCShader_PositionTexture_uColor); m_pPrograms->setObject(p ,kCCShader_PositionTexture_uColor);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -166,7 +166,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p, kCCShader_PositionTextureA8Color); m_pPrograms->setObject(p, kCCShader_PositionTextureA8Color);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -182,7 +182,7 @@ void CCShaderCache::loadDefaultShaders()
p->link(); p->link();
p->updateUniforms(); p->updateUniforms();
programs_->setObject(p, kCCShader_Position_uColor); m_pPrograms->setObject(p, kCCShader_Position_uColor);
p->release(); p->release();
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
@ -190,12 +190,12 @@ void CCShaderCache::loadDefaultShaders()
CCGLProgram* CCShaderCache::programForKey(const char* key) CCGLProgram* CCShaderCache::programForKey(const char* key)
{ {
return programs_->objectForKey(key); return m_pPrograms->objectForKey(key);
} }
void CCShaderCache::addProgram(CCGLProgram* program, const char* key) void CCShaderCache::addProgram(CCGLProgram* program, const char* key)
{ {
programs_->setObject(program, key); m_pPrograms->setObject(program, key);
} }
NS_CC_END NS_CC_END

View File

@ -35,46 +35,52 @@ THE SOFTWARE.
NS_CC_BEGIN NS_CC_BEGIN
static GLuint _ccCurrentProjectionMatrix = -1; static GLuint s_uCurrentProjectionMatrix = -1;
static bool _vertexAttribPosition = false; static bool s_bVertexAttribPosition = false;
static bool _vertexAttribColor = false; static bool s_bVertexAttribColor = false;
static bool _vertexAttribTexCoords = false; static bool s_bVertexAttribTexCoords = false;
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
#define kCCMaxActiveTexture 16 #define kCCMaxActiveTexture 16
static GLuint _ccCurrentShaderProgram = -1;
static GLuint _ccCurrentBoundTexture[kCCMaxActiveTexture] = {-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, }; static GLuint s_uCurrentShaderProgram = -1;
static GLenum _ccCurrentActiveTexture = (GL_TEXTURE0 - GL_TEXTURE0); static GLuint s_uCurrentBoundTexture[kCCMaxActiveTexture] = {-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, };
static GLenum _ccBlendingSource = -1; static GLenum s_eCurrentActiveTexture = (GL_TEXTURE0 - GL_TEXTURE0);
static GLenum _ccBlendingDest = -1; static GLenum s_eBlendingSource = -1;
static int _ccGLServerState = 0; static GLenum s_eBlendingDest = -1;
static int s_eGLServerState = 0;
#endif // CC_ENABLE_GL_STATE_CACHE #endif // CC_ENABLE_GL_STATE_CACHE
//#pragma mark - GL State Cache functions // GL State Cache functions
void ccGLInvalidateStateCache( void ) void ccGLInvalidateStateCache( void )
{ {
kmGLFreeAll(); kmGLFreeAll();
_ccCurrentProjectionMatrix = -1; s_uCurrentProjectionMatrix = -1;
_vertexAttribPosition = false; s_bVertexAttribPosition = false;
_vertexAttribColor = false; s_bVertexAttribColor = false;
_vertexAttribTexCoords = false; s_bVertexAttribTexCoords = false;
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
_ccCurrentShaderProgram = -1; s_uCurrentShaderProgram = -1;
for( int i=0; i < kCCMaxActiveTexture; i++ ) for( int i=0; i < kCCMaxActiveTexture; i++ )
_ccCurrentBoundTexture[i] = -1; {
_ccCurrentActiveTexture = (GL_TEXTURE0 - GL_TEXTURE0); s_uCurrentBoundTexture[i] = -1;
_ccBlendingSource = -1; }
_ccBlendingDest = -1; s_eCurrentActiveTexture = (GL_TEXTURE0 - GL_TEXTURE0);
_ccGLServerState = 0; s_eBlendingSource = -1;
s_eBlendingDest = -1;
s_eGLServerState = 0;
#endif #endif
} }
void ccGLDeleteProgram( GLuint program ) void ccGLDeleteProgram( GLuint program )
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
if( program == _ccCurrentShaderProgram ) if( program == s_uCurrentShaderProgram )
_ccCurrentShaderProgram = -1; s_uCurrentShaderProgram = -1;
#endif // CC_ENABLE_GL_STATE_CACHE #endif // CC_ENABLE_GL_STATE_CACHE
glDeleteProgram( program ); glDeleteProgram( program );
@ -83,8 +89,8 @@ void ccGLDeleteProgram( GLuint program )
void ccGLUseProgram( GLuint program ) void ccGLUseProgram( GLuint program )
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
if( program != _ccCurrentShaderProgram ) { if( program != s_uCurrentShaderProgram ) {
_ccCurrentShaderProgram = program; s_uCurrentShaderProgram = program;
glUseProgram(program); glUseProgram(program);
} }
#else #else
@ -96,9 +102,9 @@ void ccGLUseProgram( GLuint program )
void ccGLBlendFunc(GLenum sfactor, GLenum dfactor) void ccGLBlendFunc(GLenum sfactor, GLenum dfactor)
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
if( sfactor != _ccBlendingSource || dfactor != _ccBlendingDest ) { if( sfactor != s_eBlendingSource || dfactor != s_eBlendingDest ) {
_ccBlendingSource = sfactor; s_eBlendingSource = sfactor;
_ccBlendingDest = dfactor; s_eBlendingDest = dfactor;
glBlendFunc( sfactor, dfactor ); glBlendFunc( sfactor, dfactor );
} }
#else #else
@ -109,7 +115,7 @@ void ccGLBlendFunc(GLenum sfactor, GLenum dfactor)
GLenum ccGLGetActiveTexture( void ) GLenum ccGLGetActiveTexture( void )
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
return _ccCurrentActiveTexture + GL_TEXTURE0; return s_eCurrentActiveTexture + GL_TEXTURE0;
#else #else
GLenum activeTexture; GLenum activeTexture;
glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&activeTexture); glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&activeTexture);
@ -120,9 +126,9 @@ GLenum ccGLGetActiveTexture( void )
void ccGLActiveTexture( GLenum textureEnum ) void ccGLActiveTexture( GLenum textureEnum )
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
CCAssert( (textureEnum - GL_TEXTURE0) < kCCMaxActiveTexture, "cocos2d ERROR: Increase kCCMaxActiveTexture to %d!", (textureEnum-GL_TEXTURE0) ); CCAssert( (textureEnum - GL_TEXTURE0) < kCCMaxActiveTexture, "cocos2d ERROR: Increase kCCMaxActiveTexture to kCCMaxActiveTexture!");
if( (textureEnum - GL_TEXTURE0) != _ccCurrentActiveTexture ) { if( (textureEnum - GL_TEXTURE0) != s_eCurrentActiveTexture ) {
_ccCurrentActiveTexture = (textureEnum - GL_TEXTURE0); s_eCurrentActiveTexture = (textureEnum - GL_TEXTURE0);
glActiveTexture( textureEnum ); glActiveTexture( textureEnum );
} }
#else #else
@ -133,9 +139,9 @@ void ccGLActiveTexture( GLenum textureEnum )
void ccGLBindTexture2D( GLuint textureId ) void ccGLBindTexture2D( GLuint textureId )
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
if( _ccCurrentBoundTexture[ _ccCurrentActiveTexture ] != textureId ) if( s_uCurrentBoundTexture[ s_eCurrentActiveTexture ] != textureId )
{ {
_ccCurrentBoundTexture[ _ccCurrentActiveTexture ] = textureId; s_uCurrentBoundTexture[ s_eCurrentActiveTexture ] = textureId;
glBindTexture(GL_TEXTURE_2D, textureId ); glBindTexture(GL_TEXTURE_2D, textureId );
} }
#else #else
@ -147,8 +153,8 @@ void ccGLBindTexture2D( GLuint textureId )
void ccGLDeleteTexture( GLuint textureId ) void ccGLDeleteTexture( GLuint textureId )
{ {
#if CC_ENABLE_GL_STATE_CACHE #if CC_ENABLE_GL_STATE_CACHE
if( textureId == _ccCurrentBoundTexture[ _ccCurrentActiveTexture ] ) if( textureId == s_uCurrentBoundTexture[ s_eCurrentActiveTexture ] )
_ccCurrentBoundTexture[ _ccCurrentActiveTexture ] = -1; s_uCurrentBoundTexture[ s_eCurrentActiveTexture ] = -1;
#endif #endif
glDeleteTextures(1, &textureId ); glDeleteTextures(1, &textureId );
} }
@ -160,13 +166,13 @@ void ccGLEnable( ccGLServerState flags )
bool enabled = false; bool enabled = false;
/* GL_BLEND */ /* GL_BLEND */
if( (enabled=(flags & CC_GL_BLEND)) != (_ccGLServerState & CC_GL_BLEND) ) { if( (enabled=(flags & CC_GL_BLEND)) != (s_eGLServerState & CC_GL_BLEND) ) {
if( enabled ) { if( enabled ) {
glEnable( GL_BLEND ); glEnable( GL_BLEND );
_ccGLServerState |= CC_GL_BLEND; s_eGLServerState |= CC_GL_BLEND;
} else { } else {
glDisable( GL_BLEND ); glDisable( GL_BLEND );
_ccGLServerState &= ~CC_GL_BLEND; s_eGLServerState &= ~CC_GL_BLEND;
} }
} }
@ -185,37 +191,37 @@ void ccGLEnableVertexAttribs( unsigned int flags )
/* Position */ /* Position */
bool enablePosition = flags & kCCVertexAttribFlag_Position; bool enablePosition = flags & kCCVertexAttribFlag_Position;
if( enablePosition != _vertexAttribPosition ) { if( enablePosition != s_bVertexAttribPosition ) {
if( enablePosition ) if( enablePosition )
glEnableVertexAttribArray( kCCVertexAttrib_Position ); glEnableVertexAttribArray( kCCVertexAttrib_Position );
else else
glDisableVertexAttribArray( kCCVertexAttrib_Position ); glDisableVertexAttribArray( kCCVertexAttrib_Position );
_vertexAttribPosition = enablePosition; s_bVertexAttribPosition = enablePosition;
} }
/* Color */ /* Color */
bool enableColor = (flags & kCCVertexAttribFlag_Color) != 0 ? true : false; bool enableColor = (flags & kCCVertexAttribFlag_Color) != 0 ? true : false;
if( enableColor != _vertexAttribColor ) { if( enableColor != s_bVertexAttribColor ) {
if( enableColor ) if( enableColor )
glEnableVertexAttribArray( kCCVertexAttrib_Color ); glEnableVertexAttribArray( kCCVertexAttrib_Color );
else else
glDisableVertexAttribArray( kCCVertexAttrib_Color ); glDisableVertexAttribArray( kCCVertexAttrib_Color );
_vertexAttribColor = enableColor; s_bVertexAttribColor = enableColor;
} }
/* Tex Coords */ /* Tex Coords */
bool enableTexCoords = (flags & kCCVertexAttribFlag_TexCoords) != 0 ? true : false; bool enableTexCoords = (flags & kCCVertexAttribFlag_TexCoords) != 0 ? true : false;
if( enableTexCoords != _vertexAttribTexCoords ) { if( enableTexCoords != s_bVertexAttribTexCoords ) {
if( enableTexCoords ) if( enableTexCoords )
glEnableVertexAttribArray( kCCVertexAttrib_TexCoords ); glEnableVertexAttribArray( kCCVertexAttrib_TexCoords );
else else
glDisableVertexAttribArray( kCCVertexAttrib_TexCoords ); glDisableVertexAttribArray( kCCVertexAttrib_TexCoords );
_vertexAttribTexCoords = enableTexCoords; s_bVertexAttribTexCoords = enableTexCoords;
} }
} }
@ -223,7 +229,7 @@ void ccGLEnableVertexAttribs( unsigned int flags )
void ccSetProjectionMatrixDirty( void ) void ccSetProjectionMatrixDirty( void )
{ {
_ccCurrentProjectionMatrix = -1; s_uCurrentProjectionMatrix = -1;
} }
NS_CC_END NS_CC_END

View File

@ -686,10 +686,10 @@ public:
CC_SYNTHESIZE_RETAIN(CCAnimation*, m_pAnimation, Animation) CC_SYNTHESIZE_RETAIN(CCAnimation*, m_pAnimation, Animation)
protected: protected:
std::vector<float>* splitTimes_; std::vector<float>* m_pSplitTimes;
int nextFrame_; int m_nNextFrame;
CCSpriteFrame* m_pOrigFrame; CCSpriteFrame* m_pOrigFrame;
unsigned int executedLoops_; unsigned int m_uExecutedLoops;
}; };
/** Overrides the target of an action so that it always runs on the target /** Overrides the target of an action so that it always runs on the target

View File

@ -33,6 +33,7 @@
#include "CCArray.h" #include "CCArray.h"
#include "CCGL.h" #include "CCGL.h"
#include "ccGLStateCache.h" #include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "kazmath/kazmath.h" #include "kazmath/kazmath.h"
namespace cocos2d { namespace cocos2d {
@ -42,8 +43,7 @@ namespace cocos2d {
class CCTouch; class CCTouch;
class CCAction; class CCAction;
class CCRGBAProtocol; class CCRGBAProtocol;
class CCLabelProtocol; class CCLabelProtocol;
class CCGLProgram;
class CCScheduler; class CCScheduler;
class CCActionManager; class CCActionManager;
@ -259,7 +259,7 @@ while(false)
/** Shader Program /** Shader Program
@since v2.0 @since v2.0
*/ */
CC_PROPERTY(CCGLProgram*, m_pShaderProgram, ShaderProgram); CC_SYNTHESIZE_RETAIN(CCGLProgram*, m_pShaderProgram, ShaderProgram);
/** used internally for zOrder sorting, don't change this manually */ /** used internally for zOrder sorting, don't change this manually */
CC_SYNTHESIZE(int, m_nOrderOfArrival, OrderOfArrival); CC_SYNTHESIZE(int, m_nOrderOfArrival, OrderOfArrival);

View File

@ -61,7 +61,7 @@ public:
private: private:
bool init(); bool init();
CCMutableDictionary<std::string, CCGLProgram*>* programs_; CCMutableDictionary<std::string, CCGLProgram*>* m_pPrograms;
}; };

View File

@ -117,11 +117,17 @@ namespace cocos2d {
virtual ~CCTMXTiledMap(); virtual ~CCTMXTiledMap();
/** creates a TMX Tiled Map with a TMX file.*/ /** creates a TMX Tiled Map with a TMX file.*/
static CCTMXTiledMap * tiledMapWithTMXFile(const char *tmxFile); static CCTMXTiledMap* tiledMapWithTMXFile(const char *tmxFile);
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
static CCTMXTiledMap* tiledMapWithXML(const char* tmxString, const char* resourcePath);
/** initializes a TMX Tiled Map with a TMX file */ /** initializes a TMX Tiled Map with a TMX file */
bool initWithTMXFile(const char *tmxFile); bool initWithTMXFile(const char *tmxFile);
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
bool initWithXML(const char* tmxString, const char* resourcePath);
/** return the TMXLayer for the specific layer */ /** return the TMXLayer for the specific layer */
CCTMXLayer* layerNamed(const char *layerName); CCTMXLayer* layerNamed(const char *layerName);
@ -137,11 +143,10 @@ namespace cocos2d {
private: private:
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo); CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
CCTMXTilesetInfo * tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo); CCTMXTilesetInfo * tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
void buildWithMapInfo(CCTMXMapInfo* mapInfo);
protected: protected:
//! tile properties //! tile properties
CCDictionary<int, CCStringToStringDictionary*> *m_pTileProperties; CCDictionary<int, CCStringToStringDictionary*> *m_pTileProperties;
CCDictionary<std::string, CCTMXLayer*> *m_pTMXLayers;
}; };

View File

@ -91,11 +91,14 @@ default gl blend src function. Compatible with premultiplied alpha images.
Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
@since v2.0 @since v2.0
*/ */
#define CC_NODE_DRAW_SETUP() \ #define CC_NODE_DRAW_SETUP() \
do { \ do { \
ccGLEnable( m_glServerState ); \ ccGLEnable( m_glServerState ); \
m_pShaderProgram->use(); \ if (getShaderProgram() != NULL) \
m_pShaderProgram->setUniformForModelViewProjectionMatrix(); \ { \
getShaderProgram()->use(); \
getShaderProgram()->setUniformForModelViewProjectionMatrix(); \
} \
} while(0) } while(0)
@ -246,7 +249,13 @@ It should work same as apples CFSwapInt32LittleToHost(..)
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 #if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
#define CHECK_GL_ERROR_DEBUG() #define CHECK_GL_ERROR_DEBUG()
#else #else
#define CHECK_GL_ERROR_DEBUG() ({ GLenum __error = glGetError(); if(__error) CCLog("OpenGL error 0x%04X in %s %d\n", __error, __FUNCTION__, __LINE__); }) #define CHECK_GL_ERROR_DEBUG() \
do { \
GLenum __error = glGetError(); \
if(__error) { \
CCLog("OpenGL error 0x%04X in %s %d\n", __error, __FUNCTION__, __LINE__); \
} \
} while (false)
#endif #endif
/** @def CC_INCREMENT_GL_DRAWS_BY_ONE /** @def CC_INCREMENT_GL_DRAWS_BY_ONE

View File

@ -379,7 +379,8 @@ void CCParticleBatchNode::removeChildAtIndex(unsigned int index, bool doCleanup)
void CCParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup) void CCParticleBatchNode::removeAllChildrenWithCleanup(bool doCleanup)
{ {
//TODO: arrayMakeObjectsPerformSelector(m_pChildren, &CCParticleBatchNode::useSelfRender); //TODO: useSelfRender is undefined.
//arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCParticleBatchNode::useSelfRender, CCParticleSystem);
CCNode::removeAllChildrenWithCleanup(doCleanup); CCNode::removeAllChildrenWithCleanup(doCleanup);

View File

@ -535,7 +535,7 @@ bool CCParticleSystem::isFull()
// ParticleSystem - MainLoop // ParticleSystem - MainLoop
void CCParticleSystem::update(ccTime dt) void CCParticleSystem::update(ccTime dt)
{ {
// TODO: CC_PROFILER_START_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update"); CC_PROFILER_START_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update");
if( m_bIsActive && m_fEmissionRate ) if( m_bIsActive && m_fEmissionRate )
{ {
@ -695,7 +695,7 @@ void CCParticleSystem::update(ccTime dt)
if (!m_pBatchNode) if (!m_pBatchNode)
postStep(); postStep();
//TODO: CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update"); CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update");
} }
void CCParticleSystem::updateWithNoTime(void) void CCParticleSystem::updateWithNoTime(void)

View File

@ -284,7 +284,7 @@ void CCParticleSystemQuad::postStep()
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_pQuads[0])*m_uParticleCount, m_pQuads); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_pQuads[0])*m_uParticleCount, m_pQuads);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
// TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
// overriding draw method // overriding draw method
@ -400,7 +400,7 @@ void CCParticleSystemQuad::initVAO()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
//TODO:CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
bool CCParticleSystemQuad::allocMemory() bool CCParticleSystemQuad::allocMemory()

View File

@ -38,14 +38,14 @@ int CCTime::gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp)
return 0; return 0;
} }
void CCTime::timersubCocos2d(struct cc_timeval *out, struct cc_timeval *start, struct cc_timeval *end) double CCTime::timersubCocos2d(struct cc_timeval *start, struct cc_timeval *end)
{ {
if (! out || ! start || ! end) if (! start || ! end)
{ {
return; return 0;
} }
out->tv_sec = end->tv_sec - start->tv_sec;
out->tv_usec = end->tv_usec - start->tv_usec; return ((end->tv_sec*1000.0+end->tv_usec/1000.0) - (start->tv_sec*1000.0+start->tv_usec/1000.0));
} }
NS_CC_END; NS_CC_END;

View File

@ -40,7 +40,7 @@ class CC_DLL CCTime
{ {
public: public:
static int gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp); static int gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp);
static void timersubCocos2d(struct cc_timeval *out, struct cc_timeval *start, struct cc_timeval *end); static double timersubCocos2d(struct cc_timeval *start, struct cc_timeval *end);
}; };
NS_CC_END; NS_CC_END;

View File

@ -43,7 +43,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\shaders;..\include;..;..\kazmath\include" AdditionalIncludeDirectories="..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\shaders;..\include;..;..\kazmath\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"

View File

@ -521,7 +521,7 @@ void CCSprite::updateTransform(void)
void CCSprite::draw(void) void CCSprite::draw(void)
{ {
// TODO: CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw"); CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
CCAssert(!m_pobBatchNode, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called"); CCAssert(!m_pobBatchNode, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called");
@ -562,7 +562,7 @@ void CCSprite::draw(void)
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
#if CC_SPRITE_DEBUG_DRAW == 1 #if CC_SPRITE_DEBUG_DRAW == 1
@ -587,7 +587,7 @@ void CCSprite::draw(void)
CC_INCREMENT_GL_DRAWS(1); CC_INCREMENT_GL_DRAWS(1);
// TODO: CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw"); CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
} }
// CCNode overrides // CCNode overrides

View File

@ -125,7 +125,7 @@ CCSpriteBatchNode::~CCSpriteBatchNode()
// don't call visit on it's children // don't call visit on it's children
void CCSpriteBatchNode::visit(void) void CCSpriteBatchNode::visit(void)
{ {
// TODO: CC_PROFILER_START_CATEGORY(kCCProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit"); CC_PROFILER_START_CATEGORY(kCCProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit");
CCAssert(m_pParent != NULL, "CCSpriteBatchNode should NOT be root node"); CCAssert(m_pParent != NULL, "CCSpriteBatchNode should NOT be root node");
@ -162,7 +162,7 @@ void CCSpriteBatchNode::visit(void)
kmGLPopMatrix(); kmGLPopMatrix();
m_nOrderOfArrival = 0; m_nOrderOfArrival = 0;
// TODO: CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryBatchSprite, @"CCSpriteBatchNode - visit"); CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit");
} }
@ -395,7 +395,7 @@ void CCSpriteBatchNode::reorderBatch(bool reorder)
// draw // draw
void CCSpriteBatchNode::draw(void) void CCSpriteBatchNode::draw(void)
{ {
// TODO: CC_PROFILER_START("CCSpriteBatchNode - draw"); CC_PROFILER_START("CCSpriteBatchNode - draw");
// Optimization: Fast Dispatch // Optimization: Fast Dispatch
if( m_pobTextureAtlas->getTotalQuads() == 0 ) if( m_pobTextureAtlas->getTotalQuads() == 0 )
@ -409,7 +409,7 @@ void CCSpriteBatchNode::draw(void)
m_pobTextureAtlas->drawQuads(); m_pobTextureAtlas->drawQuads();
// TODO: CC_PROFILER_STOP("CCSpriteBatchNode - draw"); CC_PROFILER_STOP("CCSpriteBatchNode - draw");
} }
void CCSpriteBatchNode::increaseAtlasCapacity(void) void CCSpriteBatchNode::increaseAtlasCapacity(void)

View File

@ -24,112 +24,152 @@ THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "CCProfiling.h" #include "CCProfiling.h"
#if CC_ENABLE_PROFILERS using namespace std;
namespace cocos2d NS_CC_BEGIN
//#pragma mark - Profiling Categories
/* set to NO the categories that you don't want to profile */
bool kCCProfilerCategorySprite = false;
bool kCCProfilerCategoryBatchSprite = false;
bool kCCProfilerCategoryParticles = false;
static CCProfiler* g_sSharedProfiler = NULL;
CCProfiler* CCProfiler::sharedProfiler(void)
{ {
using namespace std; if (! g_sSharedProfiler)
static CCProfiler *g_sSharedProfiler;
CCProfiler* CCProfiler::sharedProfiler(void)
{ {
if (! g_sSharedProfiler) g_sSharedProfiler = new CCProfiler();
{ g_sSharedProfiler->init();
g_sSharedProfiler = new CCProfiler();
g_sSharedProfiler->init();
}
return g_sSharedProfiler;
} }
CCProfilingTimer* CCProfiler::timerWithName(const char *pszTimerName, CCObject *pInstance) return g_sSharedProfiler;
{ }
CCProfiler *p = CCProfiler::sharedProfiler();
CCProfilingTimer *t = new CCProfilingTimer();
t->initWithName(pszTimerName, pInstance);
p->m_pActiveTimers->addObject(t);
t->release();
return t; CCProfilingTimer* CCProfiler::createAndAddTimerWithName(const char* timerName)
{
CCProfiler *p = CCProfiler::sharedProfiler();
CCProfilingTimer *t = new CCProfilingTimer();
t->initWithName(timerName);
m_pActiveTimers->setObject(t, timerName);
t->release();
return t;
}
void CCProfiler::releaseTimer(const char* timerName)
{
m_pActiveTimers->removeObjectForKey(timerName);
}
void CCProfiler::releaseAllTimers()
{
m_pActiveTimers->removeAllObjects();
}
bool CCProfiler::init()
{
m_pActiveTimers = new CCMutableDictionary<std::string, CCProfilingTimer*>();
return true;
}
CCProfiler::~CCProfiler(void)
{
CC_SAFE_RELEASE(m_pActiveTimers);
}
void CCProfiler::displayTimers()
{
vector<string> allKeys = m_pActiveTimers->allKeys();
for (vector<string>::iterator it = allKeys.begin(); it != allKeys.end(); ++it)
{
CCProfilingTimer* timer = m_pActiveTimers->objectForKey(*it);
CCLog(timer->description());
}
}
// implementation of CCProfilingTimer
bool CCProfilingTimer::initWithName(const char* timerName)
{
m_NameStr = timerName;
numberOfCalls = 0;
m_dAverageTime = 0.0;
totalTime = 0.0;
minTime = 10000.0;
maxTime = 0.0;
gettimeofday((struct timeval *)&m_sStartTime, NULL);
return true;
}
CCProfilingTimer::~CCProfilingTimer(void)
{
}
const char* CCProfilingTimer::description()
{
static char s_szDesciption[256] = {0};
sprintf(s_szDesciption, "%s: avg time, %fms", m_NameStr.c_str(), m_dAverageTime);
return s_szDesciption;
}
void CCProfilingTimer::reset()
{
numberOfCalls = 0;
m_dAverageTime = 0;
totalTime = 0;
minTime = 10000;
maxTime = 0;
gettimeofday((struct timeval *)&m_sStartTime, NULL);
}
void CCProfilingBeginTimingBlock(const char *timerName)
{
CCProfiler* p = CCProfiler::sharedProfiler();
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
if( ! timer )
{
timer = p->createAndAddTimerWithName(timerName);
} }
void CCProfiler::releaseTimer(CCProfilingTimer *pTimer) gettimeofday((struct timeval *)&timer->m_sStartTime, NULL);
{
CCProfiler *p = CCProfiler::sharedProfiler();
p->m_pActiveTimers->removeObject(pTimer);
if (0 == (p->m_pActiveTimers->count())) timer->numberOfCalls++;
{ }
CC_SAFE_DELETE(g_sSharedProfiler);
}
}
bool CCProfiler::init() void CCProfilingEndTimingBlock(const char *timerName)
{ {
m_pActiveTimers = CCArray::array(); CCProfiler* p = CCProfiler::sharedProfiler();
m_pActiveTimers->retain(); CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
return true; CCAssert(timer, "CCProfilingTimer not found");
}
CCProfiler::~CCProfiler(void) struct timeval currentTime;
{ gettimeofday(&currentTime, NULL);
CC_SAFE_RELEASE(m_pActiveTimers);
}
void CCProfiler::displayTimers() double duration = CCTime::timersubCocos2d((struct cc_timeval *)&timer->m_sStartTime, (struct cc_timeval *)&currentTime);
{
CCObject* pObject = NULL;
CCProfilingTimer* pTimer = NULL;
CCARRAY_FOREACH(m_pActiveTimers, pObject)
{
pTimer = (CCProfilingTimer*) pObject;
char *pszDescription = pTimer->description();
CCLog(pszDescription);
delete pszDescription;
}
}
// implementation of CCProfilingTimer // milliseconds
timer->m_dAverageTime = (timer->m_dAverageTime + duration) / 2.0f;
timer->totalTime += duration;
timer->maxTime = MAX( timer->maxTime, duration);
timer->minTime = MIN( timer->minTime, duration);
bool CCProfilingTimer::initWithName(const char* pszTimerName, CCObject *pInstance) }
{
char tmp[160];
sprintf(tmp, "%s (0x%.8x)", pszTimerName, (unsigned int)pInstance);
m_NameStr = string(tmp);
m_dAverageTime = 0.0;
return true; void CCProfilingResetTimingBlock(const char *timerName)
} {
CCProfiler* p = CCProfiler::sharedProfiler();
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
CCProfilingTimer::~CCProfilingTimer(void) CCAssert(timer, "CCProfilingTimer not found");
{
}
char* CCProfilingTimer::description() timer->reset();
{ }
char *pszDes = new char[m_NameStr.length() + sizeof(double) + 32];
sprintf(pszDes, "%s: avg time, %fms", m_NameStr.c_str(), m_dAverageTime);
return pszDes;
}
void CCProfilingBeginTimingBlock(CCProfilingTimer *pTimer) NS_CC_END
{
CCTime::gettimeofdayCocos2d(pTimer->getStartTime(), NULL);
}
void CCProfilingEndTimingBlock(CCProfilingTimer *pTimer)
{
struct cc_timeval currentTime;
CCTime::gettimeofdayCocos2d(&currentTime, NULL);
CCTime::timersubCocos2d(&currentTime, pTimer->getStartTime(), &currentTime);
double duration = currentTime.tv_sec * 1000.0 + currentTime.tv_usec / 1000.0;
// return in milliseconds
pTimer->setAverageTime((pTimer->getAverageTime() + duration) / 2.0f);
}
} // end of namespace cocos2d
#endif // CC_ENABLE_PROFILERS

View File

@ -26,55 +26,75 @@ THE SOFTWARE.
#define __SUPPORT_CCPROFILING_H__ #define __SUPPORT_CCPROFILING_H__
#include "ccConfig.h" #include "ccConfig.h"
#if CC_ENABLE_PROFILERS
#include <string> #include <string>
#include "CCObject.h" #include "CCObject.h"
#include "platform/platform.h" #include "platform/platform.h"
#include "CCArray.h" #include "CCMutableDictionary.h"
namespace cocos2d NS_CC_BEGIN
class CCProfilingTimer;
/** CCProfiler
cocos2d builtin profiler.
To use it, enable set the CC_ENABLE_PROFILERS=1 in the ccConfig.h file
*/
class CC_DLL CCProfiler : public CCObject
{ {
class CCProfilingTimer; public:
~CCProfiler(void);
/** display the timers */
void displayTimers(void);
bool init(void);
class CC_DLL CCProfiler : public CCObject public:
{ static CCProfiler* sharedProfiler(void);
public: /** Creates and adds a new timer */
~CCProfiler(void); CCProfilingTimer* createAndAddTimerWithName(const char* timerName);
void displayTimers(void); /** releases a timer */
bool init(void); void releaseTimer(const char* timerName);
/** releases all timers */
void releaseAllTimers();
public: CCMutableDictionary<std::string, CCProfilingTimer*>* m_pActiveTimers;
static CCProfiler* sharedProfiler(void); };
static CCProfilingTimer* timerWithName(const char *pszTimerName, CCObject *pInstance);
static void releaseTimer(CCProfilingTimer *pTimer);
protected: class CCProfilingTimer : public CCObject
CCArray *m_pActiveTimers; {
}; public:
bool initWithName(const char* timerName);
~CCProfilingTimer(void);
const char* description(void);
inline struct cc_timeval * getStartTime(void) { return &m_sStartTime; };
inline void setAverageTime(double value) { m_dAverageTime = value; }
inline double getAverageTime(void) { return m_dAverageTime; }
/** resets the timer properties */
void reset();
class CCProfilingTimer : public CCObject std::string m_NameStr;
{ struct cc_timeval m_sStartTime;
public: double m_dAverageTime;
bool initWithName(const char* pszTimerName, CCObject *pInstance); double minTime;
~CCProfilingTimer(void); double maxTime;
char* description(void); double totalTime;
inline struct cc_timeval * getStartTime(void) { return &m_sStartTime; }; unsigned int numberOfCalls;
inline void setAverageTime(double value) { m_dAverageTime = value; } };
inline double getAverageTime(void) { return m_dAverageTime; }
protected: extern void CCProfilingBeginTimingBlock(const char *timerName);
std::string m_NameStr; extern void CCProfilingEndTimingBlock(const char *timerName);
struct cc_timeval m_sStartTime; extern void CCProfilingResetTimingBlock(const char *timerName);
double m_dAverageTime;
};
void CC_DLL CCProfilingBeginTimingBlock(CCProfilingTimer *pTimer); /*
void CC_DLL CCProfilingEndTimingBlock(CCProfilingTimer *pTimer); * cocos2d profiling categories
* used to enable / disable profilers with granularity
*/
} // end of namespace cocos2d extern bool kCCProfilerCategorySprite;
extern bool kCCProfilerCategoryBatchSprite;
extern bool kCCProfilerCategoryParticles;
NS_CC_END
#endif // CC_ENABLE_PROFILERS
#endif // __SUPPORT_CCPROFILING_H__ #endif // __SUPPORT_CCPROFILING_H__

View File

@ -243,7 +243,7 @@ void CCTextureAtlas::initVAO()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
void CCTextureAtlas::mapBuffers() void CCTextureAtlas::mapBuffers()
@ -259,7 +259,7 @@ void CCTextureAtlas::mapBuffers()
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
// TextureAtlas - Update, Insert, Move & Remove // TextureAtlas - Update, Insert, Move & Remove
@ -547,7 +547,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
glBindVertexArray(0); glBindVertexArray(0);
// TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }

View File

@ -210,8 +210,11 @@ void CCTMXLayer::parseInternalProperties()
{ {
m_bUseAutomaticVertexZ = true; m_bUseAutomaticVertexZ = true;
CCString *alphaFuncVal = propertyNamed("cc_alpha_func"); CCString *alphaFuncVal = propertyNamed("cc_alpha_func");
float alphaFuncValue = alphaFuncVal->toFloat(); float alphaFuncValue = 0.0f;
if (alphaFuncVal != NULL)
{
alphaFuncValue = alphaFuncVal->toFloat();
}
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColorAlphaTest)); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColorAlphaTest));
GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), kCCUniformAlphaTestValue); GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), kCCUniformAlphaTestValue);

View File

@ -29,213 +29,259 @@ THE SOFTWARE.
#include "CCSprite.h" #include "CCSprite.h"
#include "CCPointExtension.h" #include "CCPointExtension.h"
namespace cocos2d{ NS_CC_BEGIN
// implementation CCTMXTiledMap // implementation CCTMXTiledMap
CCTMXTiledMap * CCTMXTiledMap::tiledMapWithTMXFile(const char *tmxFile) CCTMXTiledMap * CCTMXTiledMap::tiledMapWithTMXFile(const char *tmxFile)
{
CCTMXTiledMap *pRet = new CCTMXTiledMap();
if (pRet->initWithTMXFile(tmxFile))
{ {
CCTMXTiledMap *pRet = new CCTMXTiledMap(); pRet->autorelease();
if (pRet->initWithTMXFile(tmxFile))
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
}
bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
{
CCAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi nil");
setContentSize(CCSizeZero);
CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithTMXFile(tmxFile);
if (! mapInfo)
{
return false;
}
CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
m_tMapSize = mapInfo->getMapSize();
m_tTileSize = mapInfo->getTileSize();
m_nMapOrientation = mapInfo->getOrientation();
setObjectGroups(mapInfo->getObjectGroups());
setProperties(mapInfo->getProperties());
CC_SAFE_RELEASE(m_pTileProperties);
m_pTileProperties = mapInfo->getTileProperties();
CC_SAFE_RETAIN(m_pTileProperties);
int idx = 0;
CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
if (layers && layers->count()>0)
{
if (NULL == m_pTMXLayers)
{
m_pTMXLayers = new CCDictionary<std::string, CCTMXLayer*>();
CCAssert(m_pTMXLayers, "Allocate memory failed!");
}
CCTMXLayerInfo *layerInfo = NULL;
CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
for (it = layers->begin(); it != layers->end(); ++it)
{
layerInfo = *it;
if (layerInfo && layerInfo->m_bVisible)
{
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
addChild((CCNode*)child, idx, idx);
// record the CCTMXLayer object by it's name
std::string layerName = child->getLayerName();
m_pTMXLayers->setObject(child, layerName);
// update content size with the max size
const CCSize& childSize = child->getContentSize();
CCSize currentSize = this->getContentSize();
currentSize.width = MAX( currentSize.width, childSize.width );
currentSize.height = MAX( currentSize.height, childSize.height );
this->setContentSize(currentSize);
idx++;
}
}
}
return true;
}
CCTMXTiledMap::CCTMXTiledMap()
:m_tMapSize(CCSizeZero)
,m_tTileSize(CCSizeZero)
,m_pObjectGroups(NULL)
,m_pProperties(NULL)
,m_pTileProperties(NULL)
,m_pTMXLayers(NULL)
{
}
CCTMXTiledMap::~CCTMXTiledMap()
{
CC_SAFE_RELEASE(m_pProperties);
CC_SAFE_RELEASE(m_pObjectGroups);
CC_SAFE_RELEASE(m_pTileProperties);
CC_SAFE_RELEASE(m_pTMXLayers);
}
CCMutableArray<CCTMXObjectGroup*> * CCTMXTiledMap::getObjectGroups()
{
return m_pObjectGroups;
}
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
{
CC_SAFE_RETAIN(var);
CC_SAFE_RELEASE(m_pObjectGroups);
m_pObjectGroups = var;
}
CCStringToStringDictionary * CCTMXTiledMap::getProperties()
{
return m_pProperties;
}
void CCTMXTiledMap::setProperties(CCStringToStringDictionary* var)
{
CC_SAFE_RETAIN(var);
CC_SAFE_RELEASE(m_pProperties);
m_pProperties = var;
}
// private
CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
CCTMXLayer *layer = CCTMXLayer::layerWithTilesetInfo(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->m_bOwnTiles = false;
layer->setupTiles();
return layer;
}
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCSize size = layerInfo->m_tLayerSize;
CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets();
if (tilesets && tilesets->count()>0)
{
CCTMXTilesetInfo *tileset = NULL;
CCMutableArray<CCTMXTilesetInfo*>::CCMutableArrayRevIterator rit;
for (rit = tilesets->rbegin(); rit != tilesets->rend(); ++rit)
{
tileset = *rit;
if (tileset)
{
for( unsigned int y=0; y < size.height; y++ )
{
for( unsigned int x=0; x < size.width; x++ )
{
unsigned int pos = (unsigned int)(x + size.width * y);
unsigned int gid = layerInfo->m_pTiles[ pos ];
// gid are stored in little endian.
// if host is big endian, then swap
//if( o == CFByteOrderBigEndian )
// gid = CFSwapInt32( gid );
/* We support little endian.*/
// XXX: gid == 0 --> empty tile
if( gid != 0 )
{
// Optimization: quick return
// if the layer is invalid (more than 1 tileset per layer) an CCAssert will be thrown later
if( gid >= tileset->m_uFirstGid )
return tileset;
}
}
}
}
}
}
// If all the tiles are 0, return empty tileset
CCLOG("cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo->m_sName.c_str());
return NULL;
}
// public
CCTMXLayer * CCTMXTiledMap::layerNamed(const char *layerName)
{
std::string sLayerName = layerName;
CCTMXLayer * pRet = m_pTMXLayers->objectForKey(sLayerName);
return pRet; return pRet;
} }
CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName) CC_SAFE_DELETE(pRet);
return NULL;
}
CCTMXTiledMap* CCTMXTiledMap::tiledMapWithXML(const char* tmxString, const char* resourcePath)
{
CCTMXTiledMap *pRet = new CCTMXTiledMap();
if (pRet->initWithXML(tmxString, resourcePath))
{ {
std::string sGroupName = groupName; pRet->autorelease();
if (m_pObjectGroups && m_pObjectGroups->count()>0) return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
}
bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
{
CCAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi NULL");
setContentSize(CCSizeZero);
CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithTMXFile(tmxFile);
if (! mapInfo)
{
return false;
}
CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
buildWithMapInfo(mapInfo);
return true;
}
bool CCTMXTiledMap::initWithXML(const char* tmxString, const char* resourcePath)
{
setContentSize(CCSizeZero);
CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithXML(tmxString, resourcePath);
CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
buildWithMapInfo(mapInfo);
return true;
}
CCTMXTiledMap::CCTMXTiledMap()
:m_tMapSize(CCSizeZero)
,m_tTileSize(CCSizeZero)
,m_pObjectGroups(NULL)
,m_pProperties(NULL)
,m_pTileProperties(NULL)
{
}
CCTMXTiledMap::~CCTMXTiledMap()
{
CC_SAFE_RELEASE(m_pProperties);
CC_SAFE_RELEASE(m_pObjectGroups);
CC_SAFE_RELEASE(m_pTileProperties);
}
CCMutableArray<CCTMXObjectGroup*> * CCTMXTiledMap::getObjectGroups()
{
return m_pObjectGroups;
}
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
{
CC_SAFE_RETAIN(var);
CC_SAFE_RELEASE(m_pObjectGroups);
m_pObjectGroups = var;
}
CCStringToStringDictionary * CCTMXTiledMap::getProperties()
{
return m_pProperties;
}
void CCTMXTiledMap::setProperties(CCStringToStringDictionary* var)
{
CC_SAFE_RETAIN(var);
CC_SAFE_RELEASE(m_pProperties);
m_pProperties = var;
}
// private
CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
CCTMXLayer *layer = CCTMXLayer::layerWithTilesetInfo(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->m_bOwnTiles = false;
layer->setupTiles();
return layer;
}
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCSize size = layerInfo->m_tLayerSize;
CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets();
if (tilesets && tilesets->count()>0)
{
CCTMXTilesetInfo *tileset = NULL;
CCMutableArray<CCTMXTilesetInfo*>::CCMutableArrayRevIterator rit;
for (rit = tilesets->rbegin(); rit != tilesets->rend(); ++rit)
{ {
CCTMXObjectGroup *objectGroup; tileset = *rit;
CCMutableArray<CCTMXObjectGroup*>::CCMutableArrayIterator it; if (tileset)
for (it = m_pObjectGroups->begin(); it != m_pObjectGroups->end(); ++it)
{ {
objectGroup = (CCTMXObjectGroup*)(*it); for( unsigned int y=0; y < size.height; y++ )
if (objectGroup && objectGroup->getGroupName() == sGroupName)
{ {
return objectGroup; for( unsigned int x=0; x < size.width; x++ )
} {
unsigned int pos = (unsigned int)(x + size.width * y);
unsigned int gid = layerInfo->m_pTiles[ pos ];
// gid are stored in little endian.
// if host is big endian, then swap
//if( o == CFByteOrderBigEndian )
// gid = CFSwapInt32( gid );
/* We support little endian.*/
// XXX: gid == 0 --> empty tile
if( gid != 0 )
{
// Optimization: quick return
// if the layer is invalid (more than 1 tileset per layer) an CCAssert will be thrown later
if( (gid & kCCFlippedMask) >= tileset->m_uFirstGid )
return tileset;
}
}
}
} }
} }
// objectGroup not found
return NULL;
} }
CCString * CCTMXTiledMap::propertyNamed(const char *propertyName) // If all the tiles are 0, return empty tileset
CCLOG("cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo->m_sName.c_str());
return NULL;
}
void CCTMXTiledMap::buildWithMapInfo(CCTMXMapInfo* mapInfo)
{
m_tMapSize = mapInfo->getMapSize();
m_tTileSize = mapInfo->getTileSize();
m_nMapOrientation = mapInfo->getOrientation();
CC_SAFE_RELEASE(m_pObjectGroups);
m_pObjectGroups = mapInfo->getObjectGroups();
CC_SAFE_RETAIN(m_pObjectGroups);
CC_SAFE_RELEASE(m_pProperties);
m_pProperties = mapInfo->getProperties();
CC_SAFE_RETAIN(m_pProperties);
CC_SAFE_RELEASE(m_pTileProperties);
m_pTileProperties = mapInfo->getTileProperties();
CC_SAFE_RETAIN(m_pTileProperties);
int idx=0;
CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
if (layers && layers->count()>0)
{ {
return m_pProperties->objectForKey(std::string(propertyName)); CCTMXLayerInfo *layerInfo = NULL;
CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
for (it = layers->begin(); it != layers->end(); ++it)
{
layerInfo = *it;
if (layerInfo && layerInfo->m_bVisible)
{
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
addChild((CCNode*)child, idx, idx);
// update content size with the max size
const CCSize& childSize = child->getContentSize();
CCSize currentSize = this->getContentSize();
currentSize.width = MAX( currentSize.width, childSize.width );
currentSize.height = MAX( currentSize.height, childSize.height );
this->setContentSize(currentSize);
idx++;
}
}
} }
CCDictionary<std::string, CCString*> * CCTMXTiledMap::propertiesForGID(int GID) }
// public
CCTMXLayer * CCTMXTiledMap::layerNamed(const char *layerName)
{
CCAssert(layerName != NULL && strlen(layerName) > 0, "Invalid layer name!");
CCObject* pObj = NULL;
CCARRAY_FOREACH(m_pChildren, pObj)
{ {
return m_pTileProperties->objectForKey(GID); CCTMXLayer* layer = dynamic_cast<CCTMXLayer*>(pObj);
if(layer)
{
if(0 == strcmp(layer->getLayerName(), layerName))
{
return layer;
}
}
} }
// layer not found
return NULL;
}
CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName)
{
CCAssert(groupName != NULL && strlen(groupName) > 0, "Invalid group name!");
std::string sGroupName = groupName;
if (m_pObjectGroups && m_pObjectGroups->count()>0)
{
CCTMXObjectGroup *objectGroup;
CCMutableArray<CCTMXObjectGroup*>::CCMutableArrayIterator it;
for (it = m_pObjectGroups->begin(); it != m_pObjectGroups->end(); ++it)
{
objectGroup = (CCTMXObjectGroup*)(*it);
if (objectGroup && objectGroup->getGroupName() == sGroupName)
{
return objectGroup;
}
}
}
// objectGroup not found
return NULL;
}
CCString * CCTMXTiledMap::propertyNamed(const char *propertyName)
{
return m_pProperties->objectForKey(std::string(propertyName));
}
CCDictionary<std::string, CCString*> * CCTMXTiledMap::propertiesForGID(int GID)
{
return m_pTileProperties->objectForKey(GID);
}
}// namespace cocos2d NS_CC_END

View File

@ -1 +1 @@
6869c5352bc6510dba54803f5f4459b0a6a3fcf2 67b1f4a471f50a0df9c0bcd97d27b474d91f28e2

View File

@ -1 +1 @@
d13ddb0931c1772127b38010990140adce837bc8 cc8dd1d0d875569db4112955e0305486374285ae

View File

@ -0,0 +1 @@
a648cdbe1a0668d60bcee196aea024055767496c

View File

@ -8,7 +8,7 @@ void DrawPrimitivesTest::draw()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// draw a simple line // draw a simple line
// The default state is: // The default state is:
@ -18,7 +18,7 @@ void DrawPrimitivesTest::draw()
// glEnable(GL_LINE_SMOOTH); // glEnable(GL_LINE_SMOOTH);
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) ); ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// line: color, width, aliased // line: color, width, aliased
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible // glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
@ -28,7 +28,7 @@ void DrawPrimitivesTest::draw()
ccDrawColor4B(255,0,0,255); ccDrawColor4B(255,0,0,255);
ccDrawLine( ccp(0, s.height), ccp(s.width, 0) ); ccDrawLine( ccp(0, s.height), ccp(s.width, 0) );
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// TIP: // TIP:
// If you are going to use always the same color or width, you don't // If you are going to use always the same color or width, you don't
@ -41,7 +41,7 @@ void DrawPrimitivesTest::draw()
ccDrawColor4B(0,0,255,128); ccDrawColor4B(0,0,255,128);
ccDrawPoint( ccp(s.width / 2, s.height / 2) ); ccDrawPoint( ccp(s.width / 2, s.height / 2) );
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// draw 4 small points // draw 4 small points
CCPoint points[] = { ccp(60,60), ccp(70,70), ccp(60,70), ccp(70,60) }; CCPoint points[] = { ccp(60,60), ccp(70,70), ccp(60,70), ccp(70,60) };
@ -49,21 +49,21 @@ void DrawPrimitivesTest::draw()
ccDrawColor4B(0,255,255,255); ccDrawColor4B(0,255,255,255);
ccDrawPoints( points, 4); ccDrawPoints( points, 4);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// draw a green circle with 10 segments // draw a green circle with 10 segments
glLineWidth(16); glLineWidth(16);
ccDrawColor4B(0, 255, 0, 255); ccDrawColor4B(0, 255, 0, 255);
ccDrawCircle( ccp(s.width/2, s.height/2), 100, 0, 10, false); ccDrawCircle( ccp(s.width/2, s.height/2), 100, 0, 10, false);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// draw a green circle with 50 segments with line to center // draw a green circle with 50 segments with line to center
glLineWidth(2); glLineWidth(2);
ccDrawColor4B(0, 255, 255, 255); ccDrawColor4B(0, 255, 255, 255);
ccDrawCircle( ccp(s.width/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, true); ccDrawCircle( ccp(s.width/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, true);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// open yellow poly // open yellow poly
ccDrawColor4B(255, 255, 0, 255); ccDrawColor4B(255, 255, 0, 255);
@ -71,7 +71,7 @@ void DrawPrimitivesTest::draw()
CCPoint vertices[] = { ccp(0,0), ccp(50,50), ccp(100,50), ccp(100,100), ccp(50,100) }; CCPoint vertices[] = { ccp(0,0), ccp(50,50), ccp(100,50), ccp(100,100), ccp(50,100) };
ccDrawPoly( vertices, 5, false); ccDrawPoly( vertices, 5, false);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// closed purble poly // closed purble poly
ccDrawColor4B(255, 0, 255, 255); ccDrawColor4B(255, 0, 255, 255);
@ -79,24 +79,24 @@ void DrawPrimitivesTest::draw()
CCPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) }; CCPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };
ccDrawPoly( vertices2, 3, true); ccDrawPoly( vertices2, 3, true);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// draw quad bezier path // draw quad bezier path
ccDrawQuadBezier(ccp(0,s.height), ccp(s.width/2,s.height/2), ccp(s.width,s.height), 50); ccDrawQuadBezier(ccp(0,s.height), ccp(s.width/2,s.height/2), ccp(s.width,s.height), 50);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// draw cubic bezier path // draw cubic bezier path
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);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
// restore original values // restore original values
glLineWidth(1); glLineWidth(1);
ccDrawColor4B(255,255,255,255); ccDrawColor4B(255,255,255,255);
ccPointSize(1); ccPointSize(1);
//TODO: CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR_DEBUG();
} }
void DrawPrimitivesTestScene::runThisTest() void DrawPrimitivesTestScene::runThisTest()

View File

@ -940,7 +940,7 @@ TMXIsoVertexZ::TMXIsoVertexZ()
CCSize s = map->getContentSize(); CCSize s = map->getContentSize();
map->setPosition( ccp(-s.width/2,0) ); map->setPosition( ccp(-s.width/2,0) );
////----UXLOG("ContentSize: %f, %f", s.width,s.height); CCLOG("ContentSize: %f, %f", s.width,s.height);
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you // because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
// can use any CCSprite and it will work OK. // can use any CCSprite and it will work OK.