#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);
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);
kmGLMatrixMode(KM_GL_MODELVIEW);
@ -367,7 +369,7 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
break;
default:
CCLOG("cocos2d: Director: unrecognized projecgtion");
CCLOG("cocos2d: Director: unrecognized projection");
break;
}
@ -397,8 +399,8 @@ void CCDirector::setAlphaBlending(bool bOn)
{
glDisable(GL_BLEND);
}
// TODO:
//CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
void CCDirector::setDepthTest(bool bOn)

View File

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

View File

@ -108,7 +108,7 @@ bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, uns
// shader stuff
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
m_nUniformColor = glGetUniformLocation( m_pShaderProgram->getProgram(), "u_color");
m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");
return true;
}
@ -137,7 +137,7 @@ void CCAtlasNode::draw()
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};
m_pShaderProgram->setUniformLocationWith4fv(m_nUniformColor, colors, 1);
getShaderProgram()->setUniformLocationWith4fv(m_nUniformColor, colors, 1);
m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0);
}

View File

@ -642,7 +642,7 @@ void CCNode::insertChild(CCNode* child, int z)
{
m_bReorderChildDirty = true;
ccArrayAppendObjectWithResize(m_pChildren->data, child);
child->setZOrder(z);
child->_setZOrder(z);
}
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");
m_bReorderChildDirty = true;
child->setOrderOfArrival(s_globalOrderOfArrival++);
child->setZOrder(zOrder);
child->_setZOrder(zOrder);
}
void CCNode::sortAllChildren()
@ -900,21 +900,6 @@ unsigned int CCNode::numberOfRunningActions()
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
void CCNode::setScheduler(CCScheduler* scheduler)

View File

@ -273,7 +273,9 @@ void CCGLProgram::setUniformLocationWith1i(unsigned int location, GLint i1)
bool updated = updateUniformLocation(location, &i1, sizeof(i1)*1);
if( updated )
{
glUniform1i( (GLint)location, i1);
}
}
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);
if( updated )
{
glUniform1f( (GLint)location, f1);
}
}
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));
if( updated )
{
glUniform2f( (GLint)location, f1, f2);
}
}
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));
if( updated )
{
glUniform3f( (GLint)location, f1, f2, f3);
}
}
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));
if( updated )
{
glUniform4f( (GLint)location, f1, f2, f3,f4);
}
}
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);
if( updated )
{
glUniform2fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
}
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);
if( updated )
{
glUniform3fv( (GLint)location, (GLsizei)numberOfArrays, floats );
}
}
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);
if( updated )
{
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);
if( updated )
{
glUniformMatrix4fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray);
}
}
void CCGLProgram::setUniformForModelViewProjectionMatrix()

View File

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

View File

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

View File

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

View File

@ -33,6 +33,7 @@
#include "CCArray.h"
#include "CCGL.h"
#include "ccGLStateCache.h"
#include "CCGLProgram.h"
#include "kazmath/kazmath.h"
namespace cocos2d {
@ -43,7 +44,6 @@ namespace cocos2d {
class CCAction;
class CCRGBAProtocol;
class CCLabelProtocol;
class CCGLProgram;
class CCScheduler;
class CCActionManager;
@ -259,7 +259,7 @@ while(false)
/** Shader Program
@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 */
CC_SYNTHESIZE(int, m_nOrderOfArrival, OrderOfArrival);

View File

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

View File

@ -117,11 +117,17 @@ namespace cocos2d {
virtual ~CCTMXTiledMap();
/** 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 */
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 */
CCTMXLayer* layerNamed(const char *layerName);
@ -137,11 +143,10 @@ namespace cocos2d {
private:
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
CCTMXTilesetInfo * tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
void buildWithMapInfo(CCTMXMapInfo* mapInfo);
protected:
//! tile properties
CCDictionary<int, CCStringToStringDictionary*> *m_pTileProperties;
CCDictionary<std::string, CCTMXLayer*> *m_pTMXLayers;
};

View File

@ -94,8 +94,11 @@ default gl blend src function. Compatible with premultiplied alpha images.
#define CC_NODE_DRAW_SETUP() \
do { \
ccGLEnable( m_glServerState ); \
m_pShaderProgram->use(); \
m_pShaderProgram->setUniformForModelViewProjectionMatrix(); \
if (getShaderProgram() != NULL) \
{ \
getShaderProgram()->use(); \
getShaderProgram()->setUniformForModelViewProjectionMatrix(); \
} \
} while(0)
@ -246,7 +249,13 @@ It should work same as apples CFSwapInt32LittleToHost(..)
#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0
#define CHECK_GL_ERROR_DEBUG()
#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
/** @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)
{
//TODO: arrayMakeObjectsPerformSelector(m_pChildren, &CCParticleBatchNode::useSelfRender);
//TODO: useSelfRender is undefined.
//arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCParticleBatchNode::useSelfRender, CCParticleSystem);
CCNode::removeAllChildrenWithCleanup(doCleanup);

View File

@ -535,7 +535,7 @@ bool CCParticleSystem::isFull()
// ParticleSystem - MainLoop
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 )
{
@ -695,7 +695,7 @@ void CCParticleSystem::update(ccTime dt)
if (!m_pBatchNode)
postStep();
//TODO: CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update");
CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update");
}
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);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
// overriding draw method
@ -400,7 +400,7 @@ void CCParticleSystemQuad::initVAO()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//TODO:CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
bool CCParticleSystemQuad::allocMemory()

View File

@ -38,14 +38,14 @@ int CCTime::gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp)
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;

View File

@ -40,7 +40,7 @@ class CC_DLL CCTime
{
public:
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;

View File

@ -43,7 +43,7 @@
Name="VCCLCompilerTool"
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"
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"
BasicRuntimeChecks="3"
RuntimeLibrary="3"

View File

@ -521,7 +521,7 @@ void CCSprite::updateTransform(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");
@ -562,7 +562,7 @@ void CCSprite::draw(void)
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
#if CC_SPRITE_DEBUG_DRAW == 1
@ -587,7 +587,7 @@ void CCSprite::draw(void)
CC_INCREMENT_GL_DRAWS(1);
// TODO: CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
}
// CCNode overrides

View File

@ -125,7 +125,7 @@ CCSpriteBatchNode::~CCSpriteBatchNode()
// don't call visit on it's children
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");
@ -162,7 +162,7 @@ void CCSpriteBatchNode::visit(void)
kmGLPopMatrix();
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
void CCSpriteBatchNode::draw(void)
{
// TODO: CC_PROFILER_START("CCSpriteBatchNode - draw");
CC_PROFILER_START("CCSpriteBatchNode - draw");
// Optimization: Fast Dispatch
if( m_pobTextureAtlas->getTotalQuads() == 0 )
@ -409,7 +409,7 @@ void CCSpriteBatchNode::draw(void)
m_pobTextureAtlas->drawQuads();
// TODO: CC_PROFILER_STOP("CCSpriteBatchNode - draw");
CC_PROFILER_STOP("CCSpriteBatchNode - draw");
}
void CCSpriteBatchNode::increaseAtlasCapacity(void)

View File

@ -24,15 +24,21 @@ THE SOFTWARE.
****************************************************************************/
#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;
static CCProfiler *g_sSharedProfiler;
CCProfiler* CCProfiler::sharedProfiler(void)
{
if (! g_sSharedProfiler)
{
g_sSharedProfiler = new CCProfiler();
@ -40,96 +46,130 @@ namespace cocos2d
}
return g_sSharedProfiler;
}
}
CCProfilingTimer* CCProfiler::timerWithName(const char *pszTimerName, CCObject *pInstance)
{
CCProfilingTimer* CCProfiler::createAndAddTimerWithName(const char* timerName)
{
CCProfiler *p = CCProfiler::sharedProfiler();
CCProfilingTimer *t = new CCProfilingTimer();
t->initWithName(pszTimerName, pInstance);
p->m_pActiveTimers->addObject(t);
t->initWithName(timerName);
m_pActiveTimers->setObject(t, timerName);
t->release();
return t;
}
}
void CCProfiler::releaseTimer(CCProfilingTimer *pTimer)
{
CCProfiler *p = CCProfiler::sharedProfiler();
p->m_pActiveTimers->removeObject(pTimer);
void CCProfiler::releaseTimer(const char* timerName)
{
m_pActiveTimers->removeObjectForKey(timerName);
}
if (0 == (p->m_pActiveTimers->count()))
{
CC_SAFE_DELETE(g_sSharedProfiler);
}
}
bool CCProfiler::init()
{
m_pActiveTimers = CCArray::array();
m_pActiveTimers->retain();
void CCProfiler::releaseAllTimers()
{
m_pActiveTimers->removeAllObjects();
}
bool CCProfiler::init()
{
m_pActiveTimers = new CCMutableDictionary<std::string, CCProfilingTimer*>();
return true;
}
}
CCProfiler::~CCProfiler(void)
{
CCProfiler::~CCProfiler(void)
{
CC_SAFE_RELEASE(m_pActiveTimers);
}
}
void CCProfiler::displayTimers()
void CCProfiler::displayTimers()
{
vector<string> allKeys = m_pActiveTimers->allKeys();
for (vector<string>::iterator it = allKeys.begin(); it != allKeys.end(); ++it)
{
CCObject* pObject = NULL;
CCProfilingTimer* pTimer = NULL;
CCARRAY_FOREACH(m_pActiveTimers, pObject)
{
pTimer = (CCProfilingTimer*) pObject;
char *pszDescription = pTimer->description();
CCLog(pszDescription);
delete pszDescription;
}
CCProfilingTimer* timer = m_pActiveTimers->objectForKey(*it);
CCLog(timer->description());
}
}
// implementation of CCProfilingTimer
// implementation of CCProfilingTimer
bool CCProfilingTimer::initWithName(const char* pszTimerName, CCObject *pInstance)
{
char tmp[160];
sprintf(tmp, "%s (0x%.8x)", pszTimerName, (unsigned int)pInstance);
m_NameStr = string(tmp);
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)
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);
}
char* CCProfilingTimer::description()
{
char *pszDes = new char[m_NameStr.length() + sizeof(double) + 32];
sprintf(pszDes, "%s: avg time, %fms", m_NameStr.c_str(), m_dAverageTime);
return pszDes;
}
gettimeofday((struct timeval *)&timer->m_sStartTime, NULL);
void CCProfilingBeginTimingBlock(CCProfilingTimer *pTimer)
{
CCTime::gettimeofdayCocos2d(pTimer->getStartTime(), NULL);
}
timer->numberOfCalls++;
}
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;
void CCProfilingEndTimingBlock(const char *timerName)
{
CCProfiler* p = CCProfiler::sharedProfiler();
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
// return in milliseconds
pTimer->setAverageTime((pTimer->getAverageTime() + duration) / 2.0f);
}
CCAssert(timer, "CCProfilingTimer not found");
} // end of namespace cocos2d
struct timeval currentTime;
gettimeofday(&currentTime, NULL);
double duration = CCTime::timersubCocos2d((struct cc_timeval *)&timer->m_sStartTime, (struct cc_timeval *)&currentTime);
// 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);
}
void CCProfilingResetTimingBlock(const char *timerName)
{
CCProfiler* p = CCProfiler::sharedProfiler();
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
CCAssert(timer, "CCProfilingTimer not found");
timer->reset();
}
NS_CC_END
#endif // CC_ENABLE_PROFILERS

View File

@ -26,55 +26,75 @@ THE SOFTWARE.
#define __SUPPORT_CCPROFILING_H__
#include "ccConfig.h"
#if CC_ENABLE_PROFILERS
#include <string>
#include "CCObject.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;
class CC_DLL CCProfiler : public CCObject
{
public:
public:
~CCProfiler(void);
/** display the timers */
void displayTimers(void);
bool init(void);
public:
public:
static CCProfiler* sharedProfiler(void);
static CCProfilingTimer* timerWithName(const char *pszTimerName, CCObject *pInstance);
static void releaseTimer(CCProfilingTimer *pTimer);
/** Creates and adds a new timer */
CCProfilingTimer* createAndAddTimerWithName(const char* timerName);
/** releases a timer */
void releaseTimer(const char* timerName);
/** releases all timers */
void releaseAllTimers();
protected:
CCArray *m_pActiveTimers;
};
CCMutableDictionary<std::string, CCProfilingTimer*>* m_pActiveTimers;
};
class CCProfilingTimer : public CCObject
{
public:
bool initWithName(const char* pszTimerName, CCObject *pInstance);
class CCProfilingTimer : public CCObject
{
public:
bool initWithName(const char* timerName);
~CCProfilingTimer(void);
char* description(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();
protected:
std::string m_NameStr;
struct cc_timeval m_sStartTime;
double m_dAverageTime;
};
double minTime;
double maxTime;
double totalTime;
unsigned int numberOfCalls;
};
void CC_DLL CCProfilingBeginTimingBlock(CCProfilingTimer *pTimer);
void CC_DLL CCProfilingEndTimingBlock(CCProfilingTimer *pTimer);
extern void CCProfilingBeginTimingBlock(const char *timerName);
extern void CCProfilingEndTimingBlock(const char *timerName);
extern void CCProfilingResetTimingBlock(const char *timerName);
} // end of namespace cocos2d
/*
* cocos2d profiling categories
* used to enable / disable profilers with granularity
*/
extern bool kCCProfilerCategorySprite;
extern bool kCCProfilerCategoryBatchSprite;
extern bool kCCProfilerCategoryParticles;
NS_CC_END
#endif // CC_ENABLE_PROFILERS
#endif // __SUPPORT_CCPROFILING_H__

View File

@ -243,7 +243,7 @@ void CCTextureAtlas::initVAO()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
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);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
// TextureAtlas - Update, Insert, Move & Remove
@ -547,7 +547,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
glBindVertexArray(0);
// TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}

View File

@ -210,8 +210,11 @@ void CCTMXLayer::parseInternalProperties()
{
m_bUseAutomaticVertexZ = true;
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));
GLint alphaValueLocation = glGetUniformLocation(getShaderProgram()->getProgram(), kCCUniformAlphaTestValue);

View File

@ -29,11 +29,11 @@ THE SOFTWARE.
#include "CCSprite.h"
#include "CCPointExtension.h"
namespace cocos2d{
NS_CC_BEGIN
// implementation CCTMXTiledMap
CCTMXTiledMap * CCTMXTiledMap::tiledMapWithTMXFile(const char *tmxFile)
{
// implementation CCTMXTiledMap
CCTMXTiledMap * CCTMXTiledMap::tiledMapWithTMXFile(const char *tmxFile)
{
CCTMXTiledMap *pRet = new CCTMXTiledMap();
if (pRet->initWithTMXFile(tmxFile))
{
@ -42,10 +42,23 @@ namespace cocos2d{
}
CC_SAFE_DELETE(pRet);
return NULL;
}
bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
}
CCTMXTiledMap* CCTMXTiledMap::tiledMapWithXML(const char* tmxString, const char* resourcePath)
{
CCTMXTiledMap *pRet = new CCTMXTiledMap();
if (pRet->initWithXML(tmxString, resourcePath))
{
CCAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi nil");
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 NULL");
setContentSize(CCSizeZero);
@ -56,93 +69,65 @@ namespace cocos2d{
return false;
}
CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
buildWithMapInfo(mapInfo);
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()
}
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)
,m_pTMXLayers(NULL)
{
}
CCTMXTiledMap::~CCTMXTiledMap()
{
{
}
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()
{
}
CCMutableArray<CCTMXObjectGroup*> * CCTMXTiledMap::getObjectGroups()
{
return m_pObjectGroups;
}
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
{
}
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
{
CC_SAFE_RETAIN(var);
CC_SAFE_RELEASE(m_pObjectGroups);
m_pObjectGroups = var;
}
CCStringToStringDictionary * CCTMXTiledMap::getProperties()
{
}
CCStringToStringDictionary * CCTMXTiledMap::getProperties()
{
return m_pProperties;
}
void CCTMXTiledMap::setProperties(CCStringToStringDictionary* var)
{
}
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)
{
}
// private
CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
CCTMXLayer *layer = CCTMXLayer::layerWithTilesetInfo(tileset, layerInfo, mapInfo);
@ -151,10 +136,10 @@ namespace cocos2d{
layer->setupTiles();
return layer;
}
}
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{
CCSize size = layerInfo->m_tLayerSize;
CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets();
if (tilesets && tilesets->count()>0)
@ -184,7 +169,7 @@ namespace cocos2d{
{
// 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 )
if( (gid & kCCFlippedMask) >= tileset->m_uFirstGid )
return tileset;
}
}
@ -196,18 +181,79 @@ namespace cocos2d{
// 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)
{
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++;
}
}
}
}
// public
CCTMXLayer * CCTMXTiledMap::layerNamed(const char *layerName)
{
CCAssert(layerName != NULL && strlen(layerName) > 0, "Invalid layer name!");
CCObject* pObj = NULL;
CCARRAY_FOREACH(m_pChildren, pObj)
{
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!");
// public
CCTMXLayer * CCTMXTiledMap::layerNamed(const char *layerName)
{
std::string sLayerName = layerName;
CCTMXLayer * pRet = m_pTMXLayers->objectForKey(sLayerName);
return pRet;
}
CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName)
{
std::string sGroupName = groupName;
if (m_pObjectGroups && m_pObjectGroups->count()>0)
{
@ -225,17 +271,17 @@ namespace cocos2d{
// objectGroup not found
return NULL;
}
}
CCString * CCTMXTiledMap::propertyNamed(const char *propertyName)
{
CCString * CCTMXTiledMap::propertyNamed(const char *propertyName)
{
return m_pProperties->objectForKey(std::string(propertyName));
}
CCDictionary<std::string, CCString*> * CCTMXTiledMap::propertiesForGID(int GID)
{
}
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();
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// draw a simple line
// The default state is:
@ -18,7 +18,7 @@ void DrawPrimitivesTest::draw()
// glEnable(GL_LINE_SMOOTH);
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// line: color, width, aliased
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
@ -28,7 +28,7 @@ void DrawPrimitivesTest::draw()
ccDrawColor4B(255,0,0,255);
ccDrawLine( ccp(0, s.height), ccp(s.width, 0) );
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// TIP:
// 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);
ccDrawPoint( ccp(s.width / 2, s.height / 2) );
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// draw 4 small points
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);
ccDrawPoints( points, 4);
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// draw a green circle with 10 segments
glLineWidth(16);
ccDrawColor4B(0, 255, 0, 255);
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
glLineWidth(2);
ccDrawColor4B(0, 255, 255, 255);
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
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) };
ccDrawPoly( vertices, 5, false);
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// closed purble poly
ccDrawColor4B(255, 0, 255, 255);
@ -79,24 +79,24 @@ void DrawPrimitivesTest::draw()
CCPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };
ccDrawPoly( vertices2, 3, true);
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
// draw quad bezier path
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
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
glLineWidth(1);
ccDrawColor4B(255,255,255,255);
ccPointSize(1);
//TODO: CHECK_GL_ERROR_DEBUG();
CHECK_GL_ERROR_DEBUG();
}
void DrawPrimitivesTestScene::runThisTest()

View File

@ -940,7 +940,7 @@ TMXIsoVertexZ::TMXIsoVertexZ()
CCSize s = map->getContentSize();
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
// can use any CCSprite and it will work OK.