From 931c42a621d681828007e806883352c3a576d1e5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 4 Apr 2012 21:58:04 +0800 Subject: [PATCH 1/5] Updated some files. --- cocos2dx/base_nodes/CCAtlasNode.cpp | 43 +- cocos2dx/base_nodes/CCNode.cpp | 300 +-- cocos2dx/kazmath/include/kazmath/aabb.h | 7 +- cocos2dx/kazmath/include/kazmath/mat3.h | 45 +- cocos2dx/kazmath/include/kazmath/mat4.h | 53 +- cocos2dx/kazmath/include/kazmath/plane.h | 19 +- cocos2dx/kazmath/include/kazmath/quaternion.h | 43 +- cocos2dx/kazmath/include/kazmath/ray2.h | 9 +- cocos2dx/kazmath/include/kazmath/utility.h | 13 +- cocos2dx/kazmath/include/kazmath/vec2.h | 24 +- cocos2dx/kazmath/include/kazmath/vec3.h | 35 +- cocos2dx/kazmath/include/kazmath/vec4.h | 27 +- .../particle_nodes/CCParticleBatchNode.cpp | 2 + .../particle_nodes/CCParticleSystemQuad.cpp | 4 + cocos2dx/textures/CCTextureAtlas.cpp | 18 +- tests/test.android/build_native.sh | 4 +- tests/tests/ParticleTest/ParticleTest.cpp | 2272 +++++++++-------- tests/tests/ParticleTest/ParticleTest.h | 110 +- 18 files changed, 1525 insertions(+), 1503 deletions(-) diff --git a/cocos2dx/base_nodes/CCAtlasNode.cpp b/cocos2dx/base_nodes/CCAtlasNode.cpp index 1acb5276b3..48b5676e9b 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.cpp +++ b/cocos2dx/base_nodes/CCAtlasNode.cpp @@ -27,13 +27,13 @@ THE SOFTWARE. #include "CCAtlasNode.h" #include "CCTextureAtlas.h" #include "CCDirector.h" -#include "CCGLProgram.h" -#include "CCShaderCache.h" -#include "ccGLStateCache.h" -#include "CCDirector.h" -#include "support/TransformUtils.h" - -// external +#include "CCGLProgram.h" +#include "CCShaderCache.h" +#include "ccGLStateCache.h" +#include "CCDirector.h" +#include "support/TransformUtils.h" + +// external #include "kazmath/GL/matrix.h" namespace cocos2d { @@ -87,11 +87,11 @@ bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, uns m_tBlendFunc.src = CC_BLEND_SRC; m_tBlendFunc.dst = CC_BLEND_DST; - // double retain to avoid the autorelease pool - // also, using: self.textureAtlas supports re-initialization without leaking - this->m_pTextureAtlas = new CCTextureAtlas(); - m_pTextureAtlas->initWithFile(tile, itemsToRender); - + CCTextureAtlas* pNewAtlas= new CCTextureAtlas(); + pNewAtlas->initWithFile(tile, itemsToRender); + setTextureAtlas(pNewAtlas); + pNewAtlas->release(); + if (! m_pTextureAtlas) { CCLOG("cocos2d: Could not initialize CCAtlasNode. Invalid Texture."); @@ -106,8 +106,8 @@ bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, uns m_uQuadsToDraw = itemsToRender; - // shader stuff - setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor)); + // shader stuff + setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor)); m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color"); return true; @@ -132,13 +132,13 @@ void CCAtlasNode::updateAtlasValues() // CCAtlasNode - draw void CCAtlasNode::draw(void) { - CC_NODE_DRAW_SETUP(); - - 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}; - getShaderProgram()->setUniformLocationWith4fv(m_nUniformColor, colors, 1); - + CC_NODE_DRAW_SETUP(); + + 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}; + getShaderProgram()->setUniformLocationWith4fv(m_nUniformColor, colors, 1); + m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0); } @@ -234,6 +234,7 @@ void CCAtlasNode::setTextureAtlas(CCTextureAtlas* var) CC_SAFE_RELEASE(m_pTextureAtlas); m_pTextureAtlas = var; } + CCTextureAtlas * CCAtlasNode::getTextureAtlas() { return m_pTextureAtlas; diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index 02f7459022..66798d340b 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -36,7 +36,7 @@ THE SOFTWARE. #include "CCActionManager.h" #include "CCScriptSupport.h" #include "CCGLProgram.h" -// externals +// externals #include "kazmath/GL/matrix.h" #if CC_NODE_RENDER_SUBPIXEL @@ -47,7 +47,7 @@ THE SOFTWARE. namespace cocos2d { -// XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered. +// XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered. static int s_globalOrderOfArrival = 1; CCNode::CCNode(void) @@ -84,10 +84,10 @@ CCNode::CCNode(void) , m_glServerState(CC_GL_BLEND) , m_bReorderChildDirty(false) { - // set default scheduler and actionManager - CCDirector *director = CCDirector::sharedDirector(); - m_pActionManager = director->getActionManager(); - m_pActionManager->retain(); + // set default scheduler and actionManager + CCDirector *director = CCDirector::sharedDirector(); + m_pActionManager = director->getActionManager(); + m_pActionManager->retain(); m_pScheduler = director->getScheduler(); m_pScheduler->retain(); } @@ -96,7 +96,7 @@ CCNode::~CCNode(void) { CCLOGINFO( "cocos2d: deallocing" ); - CC_SAFE_RELEASE(m_pActionManager); + CC_SAFE_RELEASE(m_pActionManager); CC_SAFE_RELEASE(m_pScheduler); // attributes CC_SAFE_RELEASE(m_pCamera); @@ -162,8 +162,8 @@ void CCNode::_setZOrder(int z) void CCNode::setZOrder(int z) { _setZOrder(z); - if (m_pParent) - { + if (m_pParent) + { m_pParent->reorderChild(this, z); } } @@ -429,7 +429,7 @@ void CCNode::setUserData(void *var) CCRect CCNode::boundingBox() { - CCRect rect = CCRectMake(0, 0, m_tContentSize.width, m_tContentSize.height); + CCRect rect = CCRectMake(0, 0, m_tContentSize.width, m_tContentSize.height); return CCRectApplyAffineTransform(rect, nodeToParentTransform()); } @@ -637,34 +637,34 @@ void CCNode::reorderChild(CCNode *child, int zOrder) child->_setZOrder(zOrder); } -void CCNode::sortAllChildren() -{ - if (m_bReorderChildDirty) - { - int i,j,length = m_pChildren->data->num; - CCNode ** x = (CCNode**)m_pChildren->data->arr; - CCNode *tempItem; - - // insertion sort - for(i=1; i=0 && ( tempItem->m_nZOrder < x[j]->m_nZOrder || ( tempItem->m_nZOrder== x[j]->m_nZOrder && tempItem->m_nOrderOfArrival < x[j]->m_nOrderOfArrival ) ) ) - { - x[j+1] = x[j]; - j = j-1; - } - x[j+1] = tempItem; - } - - //don't need to check children recursively, that's done in visit of each child - - m_bReorderChildDirty = false; - } -} +void CCNode::sortAllChildren() +{ + if (m_bReorderChildDirty) + { + int i,j,length = m_pChildren->data->num; + CCNode ** x = (CCNode**)m_pChildren->data->arr; + CCNode *tempItem; + + // insertion sort + for(i=1; i=0 && ( tempItem->m_nZOrder < x[j]->m_nZOrder || ( tempItem->m_nZOrder== x[j]->m_nZOrder && tempItem->m_nOrderOfArrival < x[j]->m_nOrderOfArrival ) ) ) + { + x[j+1] = x[j]; + j = j-1; + } + x[j+1] = tempItem; + } + + //don't need to check children recursively, that's done in visit of each child + + m_bReorderChildDirty = false; + } +} void CCNode::draw() @@ -729,7 +729,7 @@ void CCNode::visit() this->draw(); } - // reset for next frame + // reset for next frame m_nOrderOfArrival = 0; if (m_pGrid && m_pGrid->isActive()) @@ -751,30 +751,30 @@ void CCNode::transformAncestors() void CCNode::transform() { - kmMat4 transfrom4x4; - - // Convert 3x3 into 4x4 matrix - CCAffineTransform tmpAffine = this->nodeToParentTransform(); - CGAffineToGL(&tmpAffine, transfrom4x4.mat); - - // Update Z vertex manually - transfrom4x4.mat[14] = m_fVertexZ; - - kmGLMultMatrix( &transfrom4x4 ); - - - // XXX: Expensive calls. Camera should be integrated into the cached affine matrix - if ( m_pCamera != NULL && !(m_pGrid != NULL && m_pGrid->isActive()) ) - { - bool translate = (m_tAnchorPointInPoints.x != 0.0f || m_tAnchorPointInPoints.y != 0.0f); - - if( translate ) - kmGLTranslatef(RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.y), 0 ); - - m_pCamera->locate(); - - if( translate ) - kmGLTranslatef(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPoints.y), 0 ); + kmMat4 transfrom4x4; + + // Convert 3x3 into 4x4 matrix + CCAffineTransform tmpAffine = this->nodeToParentTransform(); + CGAffineToGL(&tmpAffine, transfrom4x4.mat); + + // Update Z vertex manually + transfrom4x4.mat[14] = m_fVertexZ; + + kmGLMultMatrix( &transfrom4x4 ); + + + // XXX: Expensive calls. Camera should be integrated into the cached affine matrix + if ( m_pCamera != NULL && !(m_pGrid != NULL && m_pGrid->isActive()) ) + { + bool translate = (m_tAnchorPointInPoints.x != 0.0f || m_tAnchorPointInPoints.y != 0.0f); + + if( translate ) + kmGLTranslatef(RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.y), 0 ); + + m_pCamera->locate(); + + if( translate ) + kmGLTranslatef(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPoints.y), 0 ); } } @@ -799,9 +799,9 @@ void CCNode::onEnterTransitionDidFinish() arrayMakeObjectsPerformSelector(m_pChildren, onEnterTransitionDidFinish, CCNode*); } -void CCNode::onExitTransitionDidStart() -{ - arrayMakeObjectsPerformSelector(m_pChildren, onExitTransitionDidStart, CCNode*); +void CCNode::onExitTransitionDidStart() +{ + arrayMakeObjectsPerformSelector(m_pChildren, onExitTransitionDidStart, CCNode*); } void CCNode::onExit() @@ -835,19 +835,19 @@ void CCNode::unregisterScriptHandler(void) } } -void CCNode::setActionManager(CCActionManager* actionManager) -{ - if( actionManager != m_pActionManager ) { - this->stopAllActions(); - CC_SAFE_RELEASE(m_pActionManager); - CC_SAFE_RETAIN(actionManager); - m_pActionManager = actionManager; - } -} - -CCActionManager* CCNode::getActionManager() -{ - return m_pActionManager; +void CCNode::setActionManager(CCActionManager* actionManager) +{ + if( actionManager != m_pActionManager ) { + this->stopAllActions(); + CC_SAFE_RETAIN(actionManager); + CC_SAFE_RELEASE(m_pActionManager); + m_pActionManager = actionManager; + } +} + +CCActionManager* CCNode::getActionManager() +{ + return m_pActionManager; } CCAction * CCNode::runAction(CCAction* action) @@ -886,20 +886,20 @@ unsigned int CCNode::numberOfRunningActions() // CCNode - Callbacks -void CCNode::setScheduler(CCScheduler* scheduler) -{ - if( scheduler != m_pScheduler ) { - this->unscheduleAllSelectors(); - CC_SAFE_RELEASE(m_pScheduler); - CC_SAFE_RETAIN(scheduler); - m_pScheduler = scheduler; - } -} - -CCScheduler* CCNode::getScheduler() -{ - return m_pScheduler; -} +void CCNode::setScheduler(CCScheduler* scheduler) +{ + if( scheduler != m_pScheduler ) { + this->unscheduleAllSelectors(); + CC_SAFE_RETAIN(scheduler); + CC_SAFE_RELEASE(m_pScheduler); + m_pScheduler = scheduler; + } +} + +CCScheduler* CCNode::getScheduler() +{ + return m_pScheduler; +} void CCNode::scheduleUpdate() { @@ -921,9 +921,9 @@ void CCNode::schedule(SEL_SCHEDULE selector) this->schedule(selector, 0.0f, kCCRepeatForever, 0.0f); } -void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval) -{ - this->schedule(selector, interval, kCCRepeatForever, 0.0f); +void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval) +{ + this->schedule(selector, interval, kCCRepeatForever, 0.0f); } void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval, unsigned int repeat, ccTime delay) @@ -934,9 +934,9 @@ void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval, unsigned int repea m_pScheduler->scheduleSelector(selector, this, interval, !m_bIsRunning, repeat, delay); } -void CCNode::scheduleOnce(SEL_SCHEDULE selector, ccTime delay) -{ - this->schedule(selector, 0.0f, 0, delay); +void CCNode::scheduleOnce(SEL_SCHEDULE selector, ccTime delay) +{ + this->schedule(selector, 0.0f, 0, delay); } void CCNode::unschedule(SEL_SCHEDULE selector) @@ -967,57 +967,57 @@ void CCNode::pauseSchedulerAndActions() CCAffineTransform CCNode::nodeToParentTransform(void) { - if ( m_bIsTransformDirty ) { - - // Translate values - float x = m_tPosition.x; - float y = m_tPosition.y; - - if ( !m_bIsRelativeAnchorPoint ) { - x += m_tAnchorPointInPoints.x; - y += m_tAnchorPointInPoints.y; - } - - // Rotation values - float c = 1, s = 0; - if( m_fRotation ) { - float radians = -CC_DEGREES_TO_RADIANS(m_fRotation); - c = cosf(radians); - s = sinf(radians); - } - - bool needsSkewMatrix = ( m_fSkewX || m_fSkewY ); - - - // optimization: - // inline anchor point calculation if skew is not needed - if( !needsSkewMatrix && !CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) { - x += c * -m_tAnchorPointInPoints.x * m_fScaleX + -s * -m_tAnchorPointInPoints.y * m_fScaleY; - y += s * -m_tAnchorPointInPoints.x * m_fScaleX + c * -m_tAnchorPointInPoints.y * m_fScaleY; - } - - - // Build Transform Matrix - m_tTransform = CCAffineTransformMake( c * m_fScaleX, s * m_fScaleX, - -s * m_fScaleY, c * m_fScaleY, - x, y ); - - // XXX: Try to inline skew - // If skew is needed, apply skew and then anchor point - if( needsSkewMatrix ) { - CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), - tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, - 0.0f, 0.0f ); - m_tTransform = CCAffineTransformConcat(skewMatrix, m_tTransform); - - // adjust anchor point - if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) - m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPoints.x, -m_tAnchorPointInPoints.y); - } - - m_bIsTransformDirty = false; - } - + if ( m_bIsTransformDirty ) { + + // Translate values + float x = m_tPosition.x; + float y = m_tPosition.y; + + if ( !m_bIsRelativeAnchorPoint ) { + x += m_tAnchorPointInPoints.x; + y += m_tAnchorPointInPoints.y; + } + + // Rotation values + float c = 1, s = 0; + if( m_fRotation ) { + float radians = -CC_DEGREES_TO_RADIANS(m_fRotation); + c = cosf(radians); + s = sinf(radians); + } + + bool needsSkewMatrix = ( m_fSkewX || m_fSkewY ); + + + // optimization: + // inline anchor point calculation if skew is not needed + if( !needsSkewMatrix && !CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) { + x += c * -m_tAnchorPointInPoints.x * m_fScaleX + -s * -m_tAnchorPointInPoints.y * m_fScaleY; + y += s * -m_tAnchorPointInPoints.x * m_fScaleX + c * -m_tAnchorPointInPoints.y * m_fScaleY; + } + + + // Build Transform Matrix + m_tTransform = CCAffineTransformMake( c * m_fScaleX, s * m_fScaleX, + -s * m_fScaleY, c * m_fScaleY, + x, y ); + + // XXX: Try to inline skew + // If skew is needed, apply skew and then anchor point + if( needsSkewMatrix ) { + CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), + tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, + 0.0f, 0.0f ); + m_tTransform = CCAffineTransformConcat(skewMatrix, m_tTransform); + + // adjust anchor point + if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) + m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPoints.x, -m_tAnchorPointInPoints.y); + } + + m_bIsTransformDirty = false; + } + return m_tTransform; } diff --git a/cocos2dx/kazmath/include/kazmath/aabb.h b/cocos2dx/kazmath/include/kazmath/aabb.h index 0e78a0470c..5c2e997bec 100644 --- a/cocos2dx/kazmath/include/kazmath/aabb.h +++ b/cocos2dx/kazmath/include/kazmath/aabb.h @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef KAZMATH_AABB_H_INCLUDED #define KAZMATH_AABB_H_INCLUDED +#include "CCPlatformMacros.h" #include "vec3.h" #include "utility.h" @@ -42,9 +43,9 @@ typedef struct kmAABB { kmVec3 max; /** The min corner of the box */ } kmAABB; -const int kmAABBContainsPoint(const kmVec3* pPoint, const kmAABB* pBox); -kmAABB* const kmAABBAssign(kmAABB* pOut, const kmAABB* pIn); -kmAABB* const kmAABBScale(kmAABB* pOut, const kmAABB* pIn, kmScalar s); +CC_DLL const int kmAABBContainsPoint(const kmVec3* pPoint, const kmAABB* pBox); +CC_DLL kmAABB* const kmAABBAssign(kmAABB* pOut, const kmAABB* pIn); +CC_DLL kmAABB* const kmAABBScale(kmAABB* pOut, const kmAABB* pIn, kmScalar s); #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/mat3.h b/cocos2dx/kazmath/include/kazmath/mat3.h index f0de4234b7..16422ebc54 100644 --- a/cocos2dx/kazmath/include/kazmath/mat3.h +++ b/cocos2dx/kazmath/include/kazmath/mat3.h @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef MAT3_H_INCLUDED #define MAT3_H_INCLUDED +#include "CCPlatformMacros.h" #include "utility.h" struct kmVec3; @@ -40,33 +41,33 @@ typedef struct kmMat3{ extern "C" { #endif -kmMat3* const kmMat3Fill(kmMat3* pOut, const kmScalar* pMat); -kmMat3* const kmMat3Adjugate(kmMat3* pOut, const kmMat3* pIn); -kmMat3* const kmMat3Identity(kmMat3* pOut); -kmMat3* const kmMat3Inverse(kmMat3* pOut, const kmScalar pDeterminate, const kmMat3* pM); -const int kmMat3IsIdentity(const kmMat3* pIn); -kmMat3* const kmMat3Transpose(kmMat3* pOut, const kmMat3* pIn); -const kmScalar kmMat3Determinant(const kmMat3* pIn); -kmMat3* const kmMat3Multiply(kmMat3* pOut, const kmMat3* pM1, const kmMat3* pM2); -kmMat3* const kmMat3ScalarMultiply(kmMat3* pOut, const kmMat3* pM, const kmScalar pFactor); +CC_DLL kmMat3* const kmMat3Fill(kmMat3* pOut, const kmScalar* pMat); +CC_DLL kmMat3* const kmMat3Adjugate(kmMat3* pOut, const kmMat3* pIn); +CC_DLL kmMat3* const kmMat3Identity(kmMat3* pOut); +CC_DLL kmMat3* const kmMat3Inverse(kmMat3* pOut, const kmScalar pDeterminate, const kmMat3* pM); +CC_DLL const int kmMat3IsIdentity(const kmMat3* pIn); +CC_DLL kmMat3* const kmMat3Transpose(kmMat3* pOut, const kmMat3* pIn); +CC_DLL const kmScalar kmMat3Determinant(const kmMat3* pIn); +CC_DLL kmMat3* const kmMat3Multiply(kmMat3* pOut, const kmMat3* pM1, const kmMat3* pM2); +CC_DLL kmMat3* const kmMat3ScalarMultiply(kmMat3* pOut, const kmMat3* pM, const kmScalar pFactor); -kmMat3* const kmMat3RotationAxisAngle(kmMat3* pOut, const struct kmVec3* axis, kmScalar radians); -struct kmVec3* const kmMat3RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat3* pIn); +CC_DLL kmMat3* const kmMat3RotationAxisAngle(kmMat3* pOut, const struct kmVec3* axis, kmScalar radians); +CC_DLL struct kmVec3* const kmMat3RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat3* pIn); -kmMat3* const kmMat3Assign(kmMat3* pOut, const kmMat3* pIn); -const int kmMat3AreEqual(const kmMat3* pM1, const kmMat3* pM2); +CC_DLL kmMat3* const kmMat3Assign(kmMat3* pOut, const kmMat3* pIn); +CC_DLL const int kmMat3AreEqual(const kmMat3* pM1, const kmMat3* pM2); -kmMat3* const kmMat3RotationX(kmMat3* pOut, const kmScalar radians); -kmMat3* const kmMat3RotationY(kmMat3* pOut, const kmScalar radians); -kmMat3* const kmMat3RotationZ(kmMat3* pOut, const kmScalar radians); +CC_DLL kmMat3* const kmMat3RotationX(kmMat3* pOut, const kmScalar radians); +CC_DLL kmMat3* const kmMat3RotationY(kmMat3* pOut, const kmScalar radians); +CC_DLL kmMat3* const kmMat3RotationZ(kmMat3* pOut, const kmScalar radians); -kmMat3* const kmMat3Rotation(kmMat3* pOut, const kmScalar radians); -kmMat3* const kmMat3Scaling(kmMat3* pOut, const kmScalar x, const kmScalar y); -kmMat3* const kmMat3Translation(kmMat3* pOut, const kmScalar x, const kmScalar y); +CC_DLL kmMat3* const kmMat3Rotation(kmMat3* pOut, const kmScalar radians); +CC_DLL kmMat3* const kmMat3Scaling(kmMat3* pOut, const kmScalar x, const kmScalar y); +CC_DLL kmMat3* const kmMat3Translation(kmMat3* pOut, const kmScalar x, const kmScalar y); -kmMat3* const kmMat3RotationQuaternion(kmMat3* pOut, const struct kmQuaternion* pIn); -kmMat3* const kmMat3RotationAxisAngle(kmMat3* pOut, const struct kmVec3* axis, kmScalar radians); -struct kmVec3* const kmMat3RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat3* pIn); +CC_DLL kmMat3* const kmMat3RotationQuaternion(kmMat3* pOut, const struct kmQuaternion* pIn); +CC_DLL kmMat3* const kmMat3RotationAxisAngle(kmMat3* pOut, const struct kmVec3* axis, kmScalar radians); +CC_DLL struct kmVec3* const kmMat3RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat3* pIn); #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/mat4.h b/cocos2dx/kazmath/include/kazmath/mat4.h index 38008ba276..ca5004499b 100644 --- a/cocos2dx/kazmath/include/kazmath/mat4.h +++ b/cocos2dx/kazmath/include/kazmath/mat4.h @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef MAT4_H_INCLUDED #define MAT4_H_INCLUDED +#include "CCPlatformMacros.h" #include "utility.h" struct kmVec3; @@ -50,43 +51,43 @@ typedef struct kmMat4 { kmScalar mat[16]; } kmMat4; -kmMat4* const kmMat4Fill(kmMat4* pOut, const kmScalar* pMat); +CC_DLL kmMat4* const kmMat4Fill(kmMat4* pOut, const kmScalar* pMat); -kmMat4* const kmMat4Identity(kmMat4* pOut); +CC_DLL kmMat4* const kmMat4Identity(kmMat4* pOut); -kmMat4* const kmMat4Inverse(kmMat4* pOut, const kmMat4* pM); +CC_DLL kmMat4* const kmMat4Inverse(kmMat4* pOut, const kmMat4* pM); -const int kmMat4IsIdentity(const kmMat4* pIn); +CC_DLL const int kmMat4IsIdentity(const kmMat4* pIn); -kmMat4* const kmMat4Transpose(kmMat4* pOut, const kmMat4* pIn); -kmMat4* const kmMat4Multiply(kmMat4* pOut, const kmMat4* pM1, const kmMat4* pM2); +CC_DLL kmMat4* const kmMat4Transpose(kmMat4* pOut, const kmMat4* pIn); +CC_DLL kmMat4* const kmMat4Multiply(kmMat4* pOut, const kmMat4* pM1, const kmMat4* pM2); -kmMat4* const kmMat4Assign(kmMat4* pOut, const kmMat4* pIn); -const int kmMat4AreEqual(const kmMat4* pM1, const kmMat4* pM2); +CC_DLL kmMat4* const kmMat4Assign(kmMat4* pOut, const kmMat4* pIn); +CC_DLL const int kmMat4AreEqual(const kmMat4* pM1, const kmMat4* pM2); -kmMat4* const kmMat4RotationX(kmMat4* pOut, const kmScalar radians); -kmMat4* const kmMat4RotationY(kmMat4* pOut, const kmScalar radians); -kmMat4* const kmMat4RotationZ(kmMat4* pOut, const kmScalar radians); -kmMat4* const kmMat4RotationPitchYawRoll(kmMat4* pOut, const kmScalar pitch, const kmScalar yaw, const kmScalar roll); -kmMat4* const kmMat4RotationQuaternion(kmMat4* pOut, const struct kmQuaternion* pQ); -kmMat4* const kmMat4RotationTranslation(kmMat4* pOut, const struct kmMat3* rotation, const struct kmVec3* translation); -kmMat4* const kmMat4Scaling(kmMat4* pOut, const kmScalar x, const kmScalar y, const kmScalar z); -kmMat4* const kmMat4Translation(kmMat4* pOut, const kmScalar x, const kmScalar y, const kmScalar z); +CC_DLL kmMat4* const kmMat4RotationX(kmMat4* pOut, const kmScalar radians); +CC_DLL kmMat4* const kmMat4RotationY(kmMat4* pOut, const kmScalar radians); +CC_DLL kmMat4* const kmMat4RotationZ(kmMat4* pOut, const kmScalar radians); +CC_DLL kmMat4* const kmMat4RotationPitchYawRoll(kmMat4* pOut, const kmScalar pitch, const kmScalar yaw, const kmScalar roll); +CC_DLL kmMat4* const kmMat4RotationQuaternion(kmMat4* pOut, const struct kmQuaternion* pQ); +CC_DLL kmMat4* const kmMat4RotationTranslation(kmMat4* pOut, const struct kmMat3* rotation, const struct kmVec3* translation); +CC_DLL kmMat4* const kmMat4Scaling(kmMat4* pOut, const kmScalar x, const kmScalar y, const kmScalar z); +CC_DLL kmMat4* const kmMat4Translation(kmMat4* pOut, const kmScalar x, const kmScalar y, const kmScalar z); -struct kmVec3* const kmMat4GetUpVec3(struct kmVec3* pOut, const kmMat4* pIn); -struct kmVec3* const kmMat4GetRightVec3(struct kmVec3* pOut, const kmMat4* pIn); -struct kmVec3* const kmMat4GetForwardVec3(struct kmVec3* pOut, const kmMat4* pIn); +CC_DLL struct kmVec3* const kmMat4GetUpVec3(struct kmVec3* pOut, const kmMat4* pIn); +CC_DLL struct kmVec3* const kmMat4GetRightVec3(struct kmVec3* pOut, const kmMat4* pIn); +CC_DLL struct kmVec3* const kmMat4GetForwardVec3(struct kmVec3* pOut, const kmMat4* pIn); -kmMat4* const kmMat4PerspectiveProjection(kmMat4* pOut, kmScalar fovY, kmScalar aspect, kmScalar zNear, kmScalar zFar); -kmMat4* const kmMat4OrthographicProjection(kmMat4* pOut, kmScalar left, kmScalar right, kmScalar bottom, kmScalar top, kmScalar nearVal, kmScalar farVal); -kmMat4* const kmMat4LookAt(kmMat4* pOut, const struct kmVec3* pEye, const struct kmVec3* pCenter, const struct kmVec3* pUp); +CC_DLL kmMat4* const kmMat4PerspectiveProjection(kmMat4* pOut, kmScalar fovY, kmScalar aspect, kmScalar zNear, kmScalar zFar); +CC_DLL kmMat4* const kmMat4OrthographicProjection(kmMat4* pOut, kmScalar left, kmScalar right, kmScalar bottom, kmScalar top, kmScalar nearVal, kmScalar farVal); +CC_DLL kmMat4* const kmMat4LookAt(kmMat4* pOut, const struct kmVec3* pEye, const struct kmVec3* pCenter, const struct kmVec3* pUp); -kmMat4* const kmMat4RotationAxisAngle(kmMat4* pOut, const struct kmVec3* axis, kmScalar radians); -struct kmMat3* const kmMat4ExtractRotation(struct kmMat3* pOut, const kmMat4* pIn); -struct kmPlane* const kmMat4ExtractPlane(struct kmPlane* pOut, const kmMat4* pIn, const kmEnum plane); -struct kmVec3* const kmMat4RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat4* pIn); +CC_DLL kmMat4* const kmMat4RotationAxisAngle(kmMat4* pOut, const struct kmVec3* axis, kmScalar radians); +CC_DLL struct kmMat3* const kmMat4ExtractRotation(struct kmMat3* pOut, const kmMat4* pIn); +CC_DLL struct kmPlane* const kmMat4ExtractPlane(struct kmPlane* pOut, const kmMat4* pIn, const kmEnum plane); +CC_DLL struct kmVec3* const kmMat4RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat4* pIn); #ifdef __cplusplus } #endif diff --git a/cocos2dx/kazmath/include/kazmath/plane.h b/cocos2dx/kazmath/include/kazmath/plane.h index 4270a8adb6..d59e99b4b5 100644 --- a/cocos2dx/kazmath/include/kazmath/plane.h +++ b/cocos2dx/kazmath/include/kazmath/plane.h @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define KM_PLANE_NEAR 4 #define KM_PLANE_FAR 5 +#include "CCPlatformMacros.h" #include "utility.h" struct kmVec3; @@ -53,15 +54,15 @@ typedef enum POINT_CLASSIFICATION { POINT_ON_PLANE, } POINT_CLASSIFICATION; -const kmScalar kmPlaneDot(const kmPlane* pP, const struct kmVec4* pV); -const kmScalar kmPlaneDotCoord(const kmPlane* pP, const struct kmVec3* pV); -const kmScalar kmPlaneDotNormal(const kmPlane* pP, const struct kmVec3* pV); -kmPlane* const kmPlaneFromPointNormal(kmPlane* pOut, const struct kmVec3* pPoint, const struct kmVec3* pNormal); -kmPlane* const kmPlaneFromPoints(kmPlane* pOut, const struct kmVec3* p1, const struct kmVec3* p2, const struct kmVec3* p3); -kmVec3* const kmPlaneIntersectLine(struct kmVec3* pOut, const kmPlane* pP, const struct kmVec3* pV1, const struct kmVec3* pV2); -kmPlane* const kmPlaneNormalize(kmPlane* pOut, const kmPlane* pP); -kmPlane* const kmPlaneScale(kmPlane* pOut, const kmPlane* pP, kmScalar s); -const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifys a point against a plane */ +CC_DLL const kmScalar kmPlaneDot(const kmPlane* pP, const struct kmVec4* pV); +CC_DLL const kmScalar kmPlaneDotCoord(const kmPlane* pP, const struct kmVec3* pV); +CC_DLL const kmScalar kmPlaneDotNormal(const kmPlane* pP, const struct kmVec3* pV); +CC_DLL kmPlane* const kmPlaneFromPointNormal(kmPlane* pOut, const struct kmVec3* pPoint, const struct kmVec3* pNormal); +CC_DLL kmPlane* const kmPlaneFromPoints(kmPlane* pOut, const struct kmVec3* p1, const struct kmVec3* p2, const struct kmVec3* p3); +CC_DLL kmVec3* const kmPlaneIntersectLine(struct kmVec3* pOut, const kmPlane* pP, const struct kmVec3* pV1, const struct kmVec3* pV2); +CC_DLL kmPlane* const kmPlaneNormalize(kmPlane* pOut, const kmPlane* pP); +CC_DLL kmPlane* const kmPlaneScale(kmPlane* pOut, const kmPlane* pP, kmScalar s); +CC_DLL const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifys a point against a plane */ #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/quaternion.h b/cocos2dx/kazmath/include/kazmath/quaternion.h index 81ff547710..7c2407b7bb 100644 --- a/cocos2dx/kazmath/include/kazmath/quaternion.h +++ b/cocos2dx/kazmath/include/kazmath/quaternion.h @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. extern "C" { #endif +#include "CCPlatformMacros.h" #include "utility.h" struct kmMat4; @@ -43,68 +44,68 @@ typedef struct kmQuaternion { kmScalar w; } kmQuaternion; -kmQuaternion* const kmQuaternionConjugate(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Returns pOut, sets pOut to the conjugate of pIn +CC_DLL kmQuaternion* const kmQuaternionConjugate(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Returns pOut, sets pOut to the conjugate of pIn -const kmScalar kmQuaternionDot(const kmQuaternion* q1, const kmQuaternion* q2); ///< Returns the dot product of the 2 quaternions +CC_DLL const kmScalar kmQuaternionDot(const kmQuaternion* q1, const kmQuaternion* q2); ///< Returns the dot product of the 2 quaternions -kmQuaternion* kmQuaternionExp(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Returns the exponential of the quaternion +CC_DLL kmQuaternion* kmQuaternionExp(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Returns the exponential of the quaternion ///< Makes the passed quaternion an identity quaternion -kmQuaternion* kmQuaternionIdentity(kmQuaternion* pOut); +CC_DLL kmQuaternion* kmQuaternionIdentity(kmQuaternion* pOut); ///< Returns the inverse of the passed Quaternion -kmQuaternion* kmQuaternionInverse(kmQuaternion* pOut, +CC_DLL kmQuaternion* kmQuaternionInverse(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Returns true if the quaternion is an identity quaternion -int kmQuaternionIsIdentity(const kmQuaternion* pIn); +CC_DLL int kmQuaternionIsIdentity(const kmQuaternion* pIn); ///< Returns the length of the quaternion -kmScalar kmQuaternionLength(const kmQuaternion* pIn); +CC_DLL kmScalar kmQuaternionLength(const kmQuaternion* pIn); ///< Returns the length of the quaternion squared (prevents a sqrt) -kmScalar kmQuaternionLengthSq(const kmQuaternion* pIn); +CC_DLL kmScalar kmQuaternionLengthSq(const kmQuaternion* pIn); ///< Returns the natural logarithm -kmQuaternion* kmQuaternionLn(kmQuaternion* pOut, const kmQuaternion* pIn); +CC_DLL kmQuaternion* kmQuaternionLn(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Multiplies 2 quaternions together -kmQuaternion* kmQuaternionMultiply(kmQuaternion* pOut, const kmQuaternion* q1, const kmQuaternion* q2); +CC_DLL kmQuaternion* kmQuaternionMultiply(kmQuaternion* pOut, const kmQuaternion* q1, const kmQuaternion* q2); ///< Normalizes a quaternion -kmQuaternion* kmQuaternionNormalize(kmQuaternion* pOut, const kmQuaternion* pIn); +CC_DLL kmQuaternion* kmQuaternionNormalize(kmQuaternion* pOut, const kmQuaternion* pIn); ///< Rotates a quaternion around an axis -kmQuaternion* kmQuaternionRotationAxis(kmQuaternion* pOut, const struct kmVec3* pV, kmScalar angle); +CC_DLL kmQuaternion* kmQuaternionRotationAxis(kmQuaternion* pOut, const struct kmVec3* pV, kmScalar angle); ///< Creates a quaternion from a rotation matrix -kmQuaternion* kmQuaternionRotationMatrix(kmQuaternion* pOut, const struct kmMat3* pIn); +CC_DLL kmQuaternion* kmQuaternionRotationMatrix(kmQuaternion* pOut, const struct kmMat3* pIn); ///< Create a quaternion from yaw, pitch and roll -kmQuaternion* kmQuaternionRotationYawPitchRoll(kmQuaternion* pOut, kmScalar yaw, kmScalar pitch, kmScalar roll); +CC_DLL kmQuaternion* kmQuaternionRotationYawPitchRoll(kmQuaternion* pOut, kmScalar yaw, kmScalar pitch, kmScalar roll); ///< Interpolate between 2 quaternions -kmQuaternion* kmQuaternionSlerp(kmQuaternion* pOut, const kmQuaternion* q1, const kmQuaternion* q2, kmScalar t); +CC_DLL kmQuaternion* kmQuaternionSlerp(kmQuaternion* pOut, const kmQuaternion* q1, const kmQuaternion* q2, kmScalar t); ///< Get the axis and angle of rotation from a quaternion -void kmQuaternionToAxisAngle(const kmQuaternion* pIn, struct kmVec3* pVector, kmScalar* pAngle); +CC_DLL void kmQuaternionToAxisAngle(const kmQuaternion* pIn, struct kmVec3* pVector, kmScalar* pAngle); ///< Scale a quaternion -kmQuaternion* kmQuaternionScale(kmQuaternion* pOut, const kmQuaternion* pIn, kmScalar s); -kmQuaternion* kmQuaternionAssign(kmQuaternion* pOut, const kmQuaternion* pIn); -kmQuaternion* kmQuaternionAdd(kmQuaternion* pOut, const kmQuaternion* pQ1, const kmQuaternion* pQ2); -kmQuaternion* kmQuaternionRotationBetweenVec3(kmQuaternion* pOut, const struct kmVec3* vec1, const struct kmVec3* vec2, const struct kmVec3* fallback); -struct kmVec3* kmQuaternionMultiplyVec3(struct kmVec3* pOut, const kmQuaternion* q, const struct kmVec3* v); +CC_DLL kmQuaternion* kmQuaternionScale(kmQuaternion* pOut, const kmQuaternion* pIn, kmScalar s); +CC_DLL kmQuaternion* kmQuaternionAssign(kmQuaternion* pOut, const kmQuaternion* pIn); +CC_DLL kmQuaternion* kmQuaternionAdd(kmQuaternion* pOut, const kmQuaternion* pQ1, const kmQuaternion* pQ2); +CC_DLL kmQuaternion* kmQuaternionRotationBetweenVec3(kmQuaternion* pOut, const struct kmVec3* vec1, const struct kmVec3* vec2, const struct kmVec3* fallback); +CC_DLL struct kmVec3* kmQuaternionMultiplyVec3(struct kmVec3* pOut, const kmQuaternion* q, const struct kmVec3* v); #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/ray2.h b/cocos2dx/kazmath/include/kazmath/ray2.h index 609e6e5152..c93c3b4a4e 100644 --- a/cocos2dx/kazmath/include/kazmath/ray2.h +++ b/cocos2dx/kazmath/include/kazmath/ray2.h @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef RAY_2_H #define RAY_2_H +#include "CCPlatformMacros.h" #include "utility.h" #include "vec2.h" @@ -38,10 +39,10 @@ typedef struct kmRay2 { kmVec2 dir; } kmRay2; -void kmRay2Fill(kmRay2* ray, kmScalar px, kmScalar py, kmScalar vx, kmScalar vy); -kmBool kmRay2IntersectLineSegment(const kmRay2* ray, const kmVec2* p1, const kmVec2* p2, kmVec2* intersection); -kmBool kmRay2IntersectTriangle(const kmRay2* ray, const kmVec2* p1, const kmVec2* p2, const kmVec2* p3, kmVec2* intersection, kmVec2* normal_out); -kmBool kmRay2IntersectCircle(const kmRay2* ray, const kmVec2 centre, const kmScalar radius, kmVec2* intersection); +CC_DLL void kmRay2Fill(kmRay2* ray, kmScalar px, kmScalar py, kmScalar vx, kmScalar vy); +CC_DLL kmBool kmRay2IntersectLineSegment(const kmRay2* ray, const kmVec2* p1, const kmVec2* p2, kmVec2* intersection); +CC_DLL kmBool kmRay2IntersectTriangle(const kmRay2* ray, const kmVec2* p1, const kmVec2* p2, const kmVec2* p3, kmVec2* intersection, kmVec2* normal_out); +CC_DLL kmBool kmRay2IntersectCircle(const kmRay2* ray, const kmVec2 centre, const kmScalar radius, kmVec2* intersection); #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/utility.h b/cocos2dx/kazmath/include/kazmath/utility.h index 71caf1f151..62b196be1c 100644 --- a/cocos2dx/kazmath/include/kazmath/utility.h +++ b/cocos2dx/kazmath/include/kazmath/utility.h @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef UTILITY_H_INCLUDED #define UTILITY_H_INCLUDED +#include "CCPlatformMacros.h" #include #ifndef kmScalar @@ -59,13 +60,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. extern "C" { #endif -extern kmScalar kmSQR(kmScalar s); -extern kmScalar kmDegreesToRadians(kmScalar degrees); -extern kmScalar kmRadiansToDegrees(kmScalar radians); +CC_DLL kmScalar kmSQR(kmScalar s); +CC_DLL kmScalar kmDegreesToRadians(kmScalar degrees); +CC_DLL kmScalar kmRadiansToDegrees(kmScalar radians); -extern kmScalar kmMin(kmScalar lhs, kmScalar rhs); -extern kmScalar kmMax(kmScalar lhs, kmScalar rhs); -extern kmBool kmAlmostEqual(kmScalar lhs, kmScalar rhs); +CC_DLL kmScalar kmMin(kmScalar lhs, kmScalar rhs); +CC_DLL kmScalar kmMax(kmScalar lhs, kmScalar rhs); +CC_DLL kmBool kmAlmostEqual(kmScalar lhs, kmScalar rhs); #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/vec2.h b/cocos2dx/kazmath/include/kazmath/vec2.h index 3ca56b328d..d8fdf82e41 100644 --- a/cocos2dx/kazmath/include/kazmath/vec2.h +++ b/cocos2dx/kazmath/include/kazmath/vec2.h @@ -26,6 +26,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef VEC2_H_INCLUDED #define VEC2_H_INCLUDED +#include "CCPlatformMacros.h" + struct kmMat3; #ifndef kmScalar @@ -44,17 +46,17 @@ typedef struct kmVec2 { #ifdef __cplusplus extern "C" { #endif -kmVec2* kmVec2Fill(kmVec2* pOut, kmScalar x, kmScalar y); -kmScalar kmVec2Length(const kmVec2* pIn); ///< Returns the length of the vector -kmScalar kmVec2LengthSq(const kmVec2* pIn); ///< Returns the square of the length of the vector -kmVec2* kmVec2Normalize(kmVec2* pOut, const kmVec2* pIn); ///< Returns the vector passed in set to unit length -kmVec2* kmVec2Add(kmVec2* pOut, const kmVec2* pV1, const kmVec2* pV2); ///< Adds 2 vectors and returns the result -kmScalar kmVec2Dot(const kmVec2* pV1, const kmVec2* pV2); /** Returns the Dot product which is the cosine of the angle between the two vectors multiplied by their lengths */ -kmVec2* kmVec2Subtract(kmVec2* pOut, const kmVec2* pV1, const kmVec2* pV2); ///< Subtracts 2 vectors and returns the result -kmVec2* kmVec2Transform(kmVec2* pOut, const kmVec2* pV1, const struct kmMat3* pM); /** Transform the Vector */ -kmVec2* kmVec2TransformCoord(kmVec2* pOut, const kmVec2* pV, const struct kmMat3* pM); /// #ifndef kmScalar @@ -44,23 +45,23 @@ typedef struct kmVec3 { extern "C" { #endif -kmVec3* kmVec3Fill(kmVec3* pOut, kmScalar x, kmScalar y, kmScalar z); -kmScalar kmVec3Length(const kmVec3* pIn); /** Returns the length of the vector */ -kmScalar kmVec3LengthSq(const kmVec3* pIn); /** Returns the square of the length of the vector */ -kmVec3* kmVec3Normalize(kmVec3* pOut, const kmVec3* pIn); /** Returns the vector passed in set to unit length */ -kmVec3* kmVec3Cross(kmVec3* pOut, const kmVec3* pV1, const kmVec3* pV2); /** Returns a vector perpendicular to 2 other vectors */ -kmScalar kmVec3Dot(const kmVec3* pV1, const kmVec3* pV2); /** Returns the cosine of the angle between 2 vectors */ -kmVec3* kmVec3Add(kmVec3* pOut, const kmVec3* pV1, const kmVec3* pV2); /** Adds 2 vectors and returns the result */ -kmVec3* kmVec3Subtract(kmVec3* pOut, const kmVec3* pV1, const kmVec3* pV2); /** Subtracts 2 vectors and returns the result */ -kmVec3* kmVec3Transform(kmVec3* pOut, const kmVec3* pV1, const struct kmMat4* pM); /** Transforms a vector (assuming w=1) by a given matrix */ -kmVec3* kmVec3TransformNormal(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM);/**Transforms a 3D normal by a given matrix */ -kmVec3* kmVec3TransformCoord(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM); /**Transforms a 3D vector by a given matrix, projecting the result back into w = 1. */ -kmVec3* kmVec3Scale(kmVec3* pOut, const kmVec3* pIn, const kmScalar s); /** Scales a vector to length s */ -int kmVec3AreEqual(const kmVec3* p1, const kmVec3* p2); -kmVec3* kmVec3InverseTransform(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM); -kmVec3* kmVec3InverseTransformNormal(kmVec3* pOut, const kmVec3* pVect, const struct kmMat4* pM); -kmVec3* kmVec3Assign(kmVec3* pOut, const kmVec3* pIn); -kmVec3* kmVec3Zero(kmVec3* pOut); +CC_DLL kmVec3* kmVec3Fill(kmVec3* pOut, kmScalar x, kmScalar y, kmScalar z); +CC_DLL kmScalar kmVec3Length(const kmVec3* pIn); /** Returns the length of the vector */ +CC_DLL kmScalar kmVec3LengthSq(const kmVec3* pIn); /** Returns the square of the length of the vector */ +CC_DLL kmVec3* kmVec3Normalize(kmVec3* pOut, const kmVec3* pIn); /** Returns the vector passed in set to unit length */ +CC_DLL kmVec3* kmVec3Cross(kmVec3* pOut, const kmVec3* pV1, const kmVec3* pV2); /** Returns a vector perpendicular to 2 other vectors */ +CC_DLL kmScalar kmVec3Dot(const kmVec3* pV1, const kmVec3* pV2); /** Returns the cosine of the angle between 2 vectors */ +CC_DLL kmVec3* kmVec3Add(kmVec3* pOut, const kmVec3* pV1, const kmVec3* pV2); /** Adds 2 vectors and returns the result */ +CC_DLL kmVec3* kmVec3Subtract(kmVec3* pOut, const kmVec3* pV1, const kmVec3* pV2); /** Subtracts 2 vectors and returns the result */ +CC_DLL kmVec3* kmVec3Transform(kmVec3* pOut, const kmVec3* pV1, const struct kmMat4* pM); /** Transforms a vector (assuming w=1) by a given matrix */ +CC_DLL kmVec3* kmVec3TransformNormal(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM);/**Transforms a 3D normal by a given matrix */ +CC_DLL kmVec3* kmVec3TransformCoord(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM); /**Transforms a 3D vector by a given matrix, projecting the result back into w = 1. */ +CC_DLL kmVec3* kmVec3Scale(kmVec3* pOut, const kmVec3* pIn, const kmScalar s); /** Scales a vector to length s */ +CC_DLL int kmVec3AreEqual(const kmVec3* p1, const kmVec3* p2); +CC_DLL kmVec3* kmVec3InverseTransform(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM); +CC_DLL kmVec3* kmVec3InverseTransformNormal(kmVec3* pOut, const kmVec3* pVect, const struct kmMat4* pM); +CC_DLL kmVec3* kmVec3Assign(kmVec3* pOut, const kmVec3* pIn); +CC_DLL kmVec3* kmVec3Zero(kmVec3* pOut); #ifdef __cplusplus } diff --git a/cocos2dx/kazmath/include/kazmath/vec4.h b/cocos2dx/kazmath/include/kazmath/vec4.h index 7507ea3cbc..651f48aca2 100644 --- a/cocos2dx/kazmath/include/kazmath/vec4.h +++ b/cocos2dx/kazmath/include/kazmath/vec4.h @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef VEC4_H_INCLUDED #define VEC4_H_INCLUDED +#include "CCPlatformMacros.h" #include "utility.h" struct kmMat4; @@ -46,20 +47,20 @@ typedef struct kmVec4 { extern "C" { #endif -kmVec4* kmVec4Fill(kmVec4* pOut, kmScalar x, kmScalar y, kmScalar z, kmScalar w); -kmVec4* kmVec4Add(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2); -kmScalar kmVec4Dot(const kmVec4* pV1, const kmVec4* pV2); -kmScalar kmVec4Length(const kmVec4* pIn); -kmScalar kmVec4LengthSq(const kmVec4* pIn); -kmVec4* kmVec4Lerp(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2, kmScalar t); -kmVec4* kmVec4Normalize(kmVec4* pOut, const kmVec4* pIn); -kmVec4* kmVec4Scale(kmVec4* pOut, const kmVec4* pIn, const kmScalar s); ///< Scales a vector to length s -kmVec4* kmVec4Subtract(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2); -kmVec4* kmVec4Transform(kmVec4* pOut, const kmVec4* pV, const struct kmMat4* pM); -kmVec4* kmVec4TransformArray(kmVec4* pOut, unsigned int outStride, +CC_DLL kmVec4* kmVec4Fill(kmVec4* pOut, kmScalar x, kmScalar y, kmScalar z, kmScalar w); +CC_DLL kmVec4* kmVec4Add(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2); +CC_DLL kmScalar kmVec4Dot(const kmVec4* pV1, const kmVec4* pV2); +CC_DLL kmScalar kmVec4Length(const kmVec4* pIn); +CC_DLL kmScalar kmVec4LengthSq(const kmVec4* pIn); +CC_DLL kmVec4* kmVec4Lerp(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2, kmScalar t); +CC_DLL kmVec4* kmVec4Normalize(kmVec4* pOut, const kmVec4* pIn); +CC_DLL kmVec4* kmVec4Scale(kmVec4* pOut, const kmVec4* pIn, const kmScalar s); ///< Scales a vector to length s +CC_DLL kmVec4* kmVec4Subtract(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2); +CC_DLL kmVec4* kmVec4Transform(kmVec4* pOut, const kmVec4* pV, const struct kmMat4* pM); +CC_DLL kmVec4* kmVec4TransformArray(kmVec4* pOut, unsigned int outStride, const kmVec4* pV, unsigned int vStride, const struct kmMat4* pM, unsigned int count); -int kmVec4AreEqual(const kmVec4* p1, const kmVec4* p2); -kmVec4* kmVec4Assign(kmVec4* pOut, const kmVec4* pIn); +CC_DLL int kmVec4AreEqual(const kmVec4* p1, const kmVec4* p2); +CC_DLL kmVec4* kmVec4Assign(kmVec4* pOut, const kmVec4* pIn); #ifdef __cplusplus } diff --git a/cocos2dx/particle_nodes/CCParticleBatchNode.cpp b/cocos2dx/particle_nodes/CCParticleBatchNode.cpp index e6ca669cf4..fa6e2a3d87 100644 --- a/cocos2dx/particle_nodes/CCParticleBatchNode.cpp +++ b/cocos2dx/particle_nodes/CCParticleBatchNode.cpp @@ -481,7 +481,9 @@ void CCParticleBatchNode::insertChild(CCParticleSystem* pSystem, unsigned int in // make room for quads, not necessary for last child if (pSystem->getAtlasIndex() + pSystem->getTotalParticles() != m_pTextureAtlas->getTotalQuads()) + { m_pTextureAtlas->moveQuadsFromIndex(index, index+pSystem->getTotalParticles()); + } // increase totalParticles here for new particles, update method of particlesystem will fill the quads m_pTextureAtlas->increaseTotalQuadsWith(pSystem->getTotalParticles()); diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index 084a121bf2..1cedd5dc54 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -301,8 +301,12 @@ void CCParticleSystemQuad::draw() glBindVertexArray( m_uVAOname ); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]); + glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray( 0 ); CC_INCREMENT_GL_DRAWS(1); diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 8a97a5e89d..7670499cdb 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -486,8 +486,9 @@ void CCTextureAtlas::moveQuadsFromIndex(unsigned int oldIndex, unsigned int amou CCAssert(oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index"); if( oldIndex == newIndex ) + { return; - + } //create buffer size_t quadSize = sizeof(ccV3F_C4B_T2F_Quad); ccV3F_C4B_T2F_Quad* tempQuads = (ccV3F_C4B_T2F_Quad*)malloc( quadSize * amount); @@ -519,12 +520,13 @@ void CCTextureAtlas::moveQuadsFromIndex(unsigned int index, unsigned int newInde void CCTextureAtlas::fillWithEmptyQuadsFromIndex(unsigned int index, unsigned int amount) { - ccV3F_C4B_T2F_Quad* quad = (ccV3F_C4B_T2F_Quad*)calloc(1,sizeof(ccV3F_C4B_T2F_Quad)); + ccV3F_C4B_T2F_Quad quad; + memset(&quad, 0, sizeof(quad)); unsigned int to = index + amount; for (int i = index ; i < to ; i++) { - m_pQuads[i] = *quad; + m_pQuads[i] = quad; } } @@ -552,25 +554,25 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start) // // XXX: update is done in draw... perhaps it should be done in a timer - if (m_bDirty) { + if (m_bDirty) + { glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]); - glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] ); - glBindBuffer(GL_ARRAY_BUFFER, 0); m_bDirty = false; } glBindVertexArray( m_uVAOname ); - + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]); + CHECK_GL_ERROR_DEBUG(); #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); #else glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); #endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP - + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindVertexArray(0); #else // ! CC_TEXTURE_ATLAS_USE_VAO diff --git a/tests/test.android/build_native.sh b/tests/test.android/build_native.sh index 1bdf8f9c6b..4debccd916 100755 --- a/tests/test.android/build_native.sh +++ b/tests/test.android/build_native.sh @@ -1,7 +1,7 @@ #!/bin/bash # set params -NDK_ROOT_LOCAL=/cygdrive/d/programe/android/ndk/android-ndk-r7b -COCOS2DX_ROOT_LOCAL=/cygdrive/e/cocos2d-x +NDK_ROOT_LOCAL=/cygdrive/e/android/android-ndk-r7b +COCOS2DX_ROOT_LOCAL=/cygdrive/f/Project/dumganhar/cocos2d-x # try to get global variable if [ $NDK_ROOT"aaa" != "aaa" ]; then diff --git a/tests/tests/ParticleTest/ParticleTest.cpp b/tests/tests/ParticleTest/ParticleTest.cpp index d3aa39d917..b3439cbf02 100644 --- a/tests/tests/ParticleTest/ParticleTest.cpp +++ b/tests/tests/ParticleTest/ParticleTest.cpp @@ -1,20 +1,20 @@ -#include "ParticleTest.h" -// #include "CCActionInterval.h" -// #include "CCMenu.h" -// #include "CCLabelTTF.h" -// #include "CCLabelAtlas.h" -// #include "touch_dispatcher/CCTouchDispatcher.h" -#include "../testResource.h" -/*#include "support/CCPointExtension.h"*/ - -enum { - kTagParticleCount = 1, -}; - +#include "ParticleTest.h" +// #include "CCActionInterval.h" +// #include "CCMenu.h" +// #include "CCLabelTTF.h" +// #include "CCLabelAtlas.h" +// #include "touch_dispatcher/CCTouchDispatcher.h" +#include "../testResource.h" +/*#include "support/CCPointExtension.h"*/ + +enum { + kTagParticleCount = 1, +}; + CCLayer* nextParticleAction(); CCLayer* backParticleAction(); -CCLayer* restartParticleAction(); - +CCLayer* restartParticleAction(); + //------------------------------------------------------------------ // // DemoFirework @@ -31,14 +31,14 @@ void DemoFirework::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); setEmitterPosition(); -} - +} + std::string DemoFirework::title() { return "ParticleFireworks"; -} - - +} + + //------------------------------------------------------------------ // // DemoFire @@ -57,13 +57,13 @@ void DemoFire::onEnter() m_emitter->setPosition( CCPointMake(p.x, 100) ); setEmitterPosition(); -} - +} + std::string DemoFire::title() { return "ParticleFire"; -} - +} + //------------------------------------------------------------------ // // DemoSun @@ -79,14 +79,14 @@ void DemoSun::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoSun::title() { return "ParticleSun"; -} - +} + //------------------------------------------------------------------ // // DemoGalaxy @@ -95,21 +95,21 @@ std::string DemoSun::title() void DemoGalaxy::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleGalaxy::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoGalaxy::title() { return "ParticleGalaxy"; -} - +} + //------------------------------------------------------------------ // // DemoFlower @@ -118,20 +118,20 @@ std::string DemoGalaxy::title() void DemoFlower::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleFlower::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoFlower::title() { return "ParticleFlower"; -} - +} + //------------------------------------------------------------------ // // DemoBigFlower @@ -140,7 +140,7 @@ std::string DemoFlower::title() void DemoBigFlower::onEnter() { ParticleDemo::onEnter(); - + m_emitter = new CCParticleSystemQuad(); m_emitter->initWithTotalParticles(50); //m_emitter->autorelease(); @@ -148,7 +148,7 @@ void DemoBigFlower::onEnter() m_background->addChild(m_emitter, 10); ////m_emitter->release(); // win32 : use this line or remove this line and use autorelease() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); - + m_emitter->setDuration(-1); // gravity @@ -209,13 +209,13 @@ void DemoBigFlower::onEnter() m_emitter->setIsBlendAdditive(true); setEmitterPosition(); -} - +} + std::string DemoBigFlower::title() { return "ParticleBigFlower"; -} - +} + //------------------------------------------------------------------ // // DemoRotFlower @@ -294,13 +294,13 @@ void DemoRotFlower::onEnter() m_emitter->setIsBlendAdditive(false); setEmitterPosition(); -} - +} + std::string DemoRotFlower::title() { return "ParticleRotFlower"; -} - +} + //------------------------------------------------------------------ // // DemoMeteor @@ -317,13 +317,13 @@ void DemoMeteor::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); setEmitterPosition(); -} - +} + std::string DemoMeteor::title() { return "ParticleMeteor"; -} - +} + //------------------------------------------------------------------ // // DemoSpiral @@ -332,21 +332,21 @@ std::string DemoMeteor::title() void DemoSpiral::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleSpiral::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoSpiral::title() { return "ParticleSpiral"; -} - +} + //------------------------------------------------------------------ // // DemoExplosion @@ -365,13 +365,13 @@ void DemoExplosion::onEnter() m_emitter->setIsAutoRemoveOnFinish(true); setEmitterPosition(); -} - +} + std::string DemoExplosion::title() { return "ParticleExplosion"; -} - +} + //------------------------------------------------------------------ // // DemoSmoke @@ -390,13 +390,13 @@ void DemoSmoke::onEnter() m_emitter->setPosition( CCPointMake( p.x, 100) ); setEmitterPosition(); -} - +} + std::string DemoSmoke::title() { return "ParticleSmoke"; -} - +} + //------------------------------------------------------------------ // // DemoSnow @@ -412,39 +412,39 @@ void DemoSnow::onEnter() CCPoint p = m_emitter->getPosition(); m_emitter->setPosition( CCPointMake( p.x, p.y-110) ); - m_emitter->setLife(3); - m_emitter->setLifeVar(1); - - // gravity - m_emitter->setGravity(CCPointMake(0,-10)); - - // speed of particles - m_emitter->setSpeed(130); - m_emitter->setSpeedVar(30); - - - ccColor4F startColor = m_emitter->getStartColor(); - startColor.r = 0.9f; - startColor.g = 0.9f; - startColor.b = 0.9f; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = m_emitter->getStartColorVar(); - startColorVar.b = 0.1f; - m_emitter->setStartColorVar(startColorVar); - - m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); + m_emitter->setLife(3); + m_emitter->setLifeVar(1); + + // gravity + m_emitter->setGravity(CCPointMake(0,-10)); + + // speed of particles + m_emitter->setSpeed(130); + m_emitter->setSpeedVar(30); + + + ccColor4F startColor = m_emitter->getStartColor(); + startColor.r = 0.9f; + startColor.g = 0.9f; + startColor.b = 0.9f; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = m_emitter->getStartColorVar(); + startColorVar.b = 0.1f; + m_emitter->setStartColorVar(startColorVar); + + m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_snow) ); setEmitterPosition(); -} - +} + std::string DemoSnow::title() { return "ParticleSnow"; -} - +} + //------------------------------------------------------------------ // // DemoRain @@ -453,7 +453,7 @@ std::string DemoSnow::title() void DemoRain::onEnter() { ParticleDemo::onEnter(); - + m_emitter = CCParticleRain::node(); m_emitter->retain(); m_background->addChild(m_emitter, 10); @@ -464,14 +464,14 @@ void DemoRain::onEnter() m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoRain::title() { return "ParticleRain"; -} - +} + //------------------------------------------------------------------ // // DemoModernArt @@ -480,7 +480,7 @@ std::string DemoRain::title() void DemoModernArt::onEnter() { ParticleDemo::onEnter(); - + //FIXME: If use CCParticleSystemPoint, bada 1.0 device will crash. // Crash place: CCParticleSystemPoint.cpp Line 149, function: glDrawArrays(GL_POINTS, 0, m_uParticleIdx); // m_emitter = new CCParticleSystemPoint(); @@ -492,73 +492,73 @@ void DemoModernArt::onEnter() ////m_emitter->release(); CCSize s = CCDirector::sharedDirector()->getWinSize(); - - // duration - m_emitter->setDuration(-1); - - // gravity - m_emitter->setGravity(CCPointMake(0,0)); - - // angle - m_emitter->setAngle(0); - m_emitter->setAngleVar(360); - - // radial - m_emitter->setRadialAccel(70); - m_emitter->setRadialAccelVar(10); - - // tagential - m_emitter->setTangentialAccel(80); - m_emitter->setTangentialAccelVar(0); - - // speed of particles - m_emitter->setSpeed(50); - m_emitter->setSpeedVar(10); - - // emitter position - m_emitter->setPosition( CCPointMake( s.width/2, s.height/2) ); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(2.0f); - m_emitter->setLifeVar(0.3f); - - // emits per frame - m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(1.0f); - m_emitter->setStartSizeVar(1.0f); - m_emitter->setEndSize(32.0f); - m_emitter->setEndSizeVar(8.0f); - + + // duration + m_emitter->setDuration(-1); + + // gravity + m_emitter->setGravity(CCPointMake(0,0)); + + // angle + m_emitter->setAngle(0); + m_emitter->setAngleVar(360); + + // radial + m_emitter->setRadialAccel(70); + m_emitter->setRadialAccelVar(10); + + // tagential + m_emitter->setTangentialAccel(80); + m_emitter->setTangentialAccelVar(0); + + // speed of particles + m_emitter->setSpeed(50); + m_emitter->setSpeedVar(10); + + // emitter position + m_emitter->setPosition( CCPointMake( s.width/2, s.height/2) ); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(2.0f); + m_emitter->setLifeVar(0.3f); + + // emits per frame + m_emitter->setEmissionRate(m_emitter->getTotalParticles()/m_emitter->getLife()); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(1.0f); + m_emitter->setStartSizeVar(1.0f); + m_emitter->setEndSize(32.0f); + m_emitter->setEndSizeVar(8.0f); + // texture m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); // additive m_emitter->setIsBlendAdditive(false); - setEmitterPosition(); -} - + setEmitterPosition(); +} + std::string DemoModernArt::title() { return "Varying size"; -} - +} + //------------------------------------------------------------------ // // DemoRing @@ -574,20 +574,20 @@ void DemoRing::onEnter() m_background->addChild(m_emitter, 10); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_stars1) ); - m_emitter->setLifeVar(0); - m_emitter->setLife(10); - m_emitter->setSpeed(100); - m_emitter->setSpeedVar(0); - m_emitter->setEmissionRate(10000); + m_emitter->setLifeVar(0); + m_emitter->setLife(10); + m_emitter->setSpeed(100); + m_emitter->setSpeedVar(0); + m_emitter->setEmissionRate(10000); setEmitterPosition(); -} - +} + std::string DemoRing::title() { return "Ring Demo"; -} - +} + //------------------------------------------------------------------ // // ParallaxParticle @@ -596,284 +596,284 @@ std::string DemoRing::title() void ParallaxParticle::onEnter() { ParticleDemo::onEnter(); - - m_background->getParent()->removeChild(m_background, true); - m_background = NULL; - - CCParallaxNode* p = CCParallaxNode::node(); - addChild(p, 5); - - CCSprite *p1 = CCSprite::spriteWithFile(s_back3); - CCSprite *p2 = CCSprite::spriteWithFile(s_back3); - - p->addChild( p1, 1, CCPointMake(0.5f,1), CCPointMake(0,250) ); - p->addChild(p2, 2, CCPointMake(1.5f,1), CCPointMake(0,50) ); - - m_emitter = CCParticleFlower::node(); - m_emitter->retain(); - m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - - p1->addChild(m_emitter, 10); - m_emitter->setPosition( CCPointMake(250,200) ); - - CCParticleSun* par = CCParticleSun::node(); - p2->addChild(par, 10); - par->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); - - CCActionInterval* move = CCMoveBy::actionWithDuration(4, CCPointMake(300,0)); - CCActionInterval* move_back = move->reverse(); - CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL); - p->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq)); -} - + + m_background->getParent()->removeChild(m_background, true); + m_background = NULL; + + CCParallaxNode* p = CCParallaxNode::node(); + addChild(p, 5); + + CCSprite *p1 = CCSprite::spriteWithFile(s_back3); + CCSprite *p2 = CCSprite::spriteWithFile(s_back3); + + p->addChild( p1, 1, CCPointMake(0.5f,1), CCPointMake(0,250) ); + p->addChild(p2, 2, CCPointMake(1.5f,1), CCPointMake(0,50) ); + + m_emitter = CCParticleFlower::node(); + m_emitter->retain(); + m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); + + p1->addChild(m_emitter, 10); + m_emitter->setPosition( CCPointMake(250,200) ); + + CCParticleSun* par = CCParticleSun::node(); + p2->addChild(par, 10); + par->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); + + CCActionInterval* move = CCMoveBy::actionWithDuration(4, CCPointMake(300,0)); + CCActionInterval* move_back = move->reverse(); + CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL); + p->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq)); +} + std::string ParallaxParticle::title() { return "Parallax + Particles"; -} - +} + //------------------------------------------------------------------ // // RadiusMode1 // -//------------------------------------------------------------------ +//------------------------------------------------------------------ void RadiusMode1::onEnter() { ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - m_emitter->initWithTotalParticles(200); - addChild(m_emitter, 10); - m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); - - // duration - m_emitter->setDuration(kCCParticleDurationInfinity); - - // radius mode - m_emitter->setEmitterMode(kCCParticleModeRadius); - - // radius mode: start and end radius in pixels - m_emitter->setStartRadius(0); - m_emitter->setStartRadiusVar(0); - m_emitter->setEndRadius(160); - m_emitter->setEndRadiusVar(0); - - // radius mode: degrees per second - m_emitter->setRotatePerSecond(180); - m_emitter->setRotatePerSecondVar(0); - - - // angle - m_emitter->setAngle(90); - m_emitter->setAngleVar(0); - - // emitter position - CCSize size = CCDirector::sharedDirector()->getWinSize(); - m_emitter->setPosition(ccp(size.width/2, size.height/2)); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(5); - m_emitter->setLifeVar(0); - - // spin of particles - m_emitter->setStartSpin(0); - m_emitter->setStartSpinVar(0); - m_emitter->setEndSpin(0); - m_emitter->setEndSpinVar(0); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(32); - m_emitter->setStartSizeVar(0); - m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); - + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + m_emitter->initWithTotalParticles(200); + addChild(m_emitter, 10); + m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); + + // duration + m_emitter->setDuration(kCCParticleDurationInfinity); + + // radius mode + m_emitter->setEmitterMode(kCCParticleModeRadius); + + // radius mode: start and end radius in pixels + m_emitter->setStartRadius(0); + m_emitter->setStartRadiusVar(0); + m_emitter->setEndRadius(160); + m_emitter->setEndRadiusVar(0); + + // radius mode: degrees per second + m_emitter->setRotatePerSecond(180); + m_emitter->setRotatePerSecondVar(0); + + + // angle + m_emitter->setAngle(90); + m_emitter->setAngleVar(0); + + // emitter position + CCSize size = CCDirector::sharedDirector()->getWinSize(); + m_emitter->setPosition(ccp(size.width/2, size.height/2)); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(5); + m_emitter->setLifeVar(0); + + // spin of particles + m_emitter->setStartSpin(0); + m_emitter->setStartSpinVar(0); + m_emitter->setEndSpin(0); + m_emitter->setEndSpinVar(0); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(32); + m_emitter->setStartSizeVar(0); + m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); + // additive m_emitter->setIsBlendAdditive(false); } -std::string RadiusMode1::title() -{ - return "Radius Mode: Spiral"; -} - +std::string RadiusMode1::title() +{ + return "Radius Mode: Spiral"; +} + //------------------------------------------------------------------ // // RadiusMode2 // -//------------------------------------------------------------------ +//------------------------------------------------------------------ void RadiusMode2::onEnter() { ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - m_emitter->initWithTotalParticles(200); - addChild(m_emitter, 10); - m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); - - // duration - m_emitter->setDuration(kCCParticleDurationInfinity); - - // radius mode - m_emitter->setEmitterMode(kCCParticleModeRadius); - - // radius mode: start and end radius in pixels - m_emitter->setStartRadius(100); - m_emitter->setStartRadiusVar(0); - m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); - m_emitter->setEndRadiusVar(0); - - // radius mode: degrees per second - m_emitter->setRotatePerSecond(45); - m_emitter->setRotatePerSecondVar(0); - - - // angle - m_emitter->setAngle(90); - m_emitter->setAngleVar(0); - - // emitter position - CCSize size = CCDirector::sharedDirector()->getWinSize(); - m_emitter->setPosition(ccp(size.width/2, size.height/2)); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(4); - m_emitter->setLifeVar(0); - - // spin of particles - m_emitter->setStartSpin(0); - m_emitter->setStartSpinVar(0); - m_emitter->setEndSpin(0); - m_emitter->setEndSpinVar(0); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(32); - m_emitter->setStartSizeVar(0); - m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); - + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + m_emitter->initWithTotalParticles(200); + addChild(m_emitter, 10); + m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/stars-grayscale.png")); + + // duration + m_emitter->setDuration(kCCParticleDurationInfinity); + + // radius mode + m_emitter->setEmitterMode(kCCParticleModeRadius); + + // radius mode: start and end radius in pixels + m_emitter->setStartRadius(100); + m_emitter->setStartRadiusVar(0); + m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); + m_emitter->setEndRadiusVar(0); + + // radius mode: degrees per second + m_emitter->setRotatePerSecond(45); + m_emitter->setRotatePerSecondVar(0); + + + // angle + m_emitter->setAngle(90); + m_emitter->setAngleVar(0); + + // emitter position + CCSize size = CCDirector::sharedDirector()->getWinSize(); + m_emitter->setPosition(ccp(size.width/2, size.height/2)); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(4); + m_emitter->setLifeVar(0); + + // spin of particles + m_emitter->setStartSpin(0); + m_emitter->setStartSpinVar(0); + m_emitter->setEndSpin(0); + m_emitter->setEndSpinVar(0); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(32); + m_emitter->setStartSizeVar(0); + m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); + // additive m_emitter->setIsBlendAdditive(false); } -std::string RadiusMode2::title() -{ - return "Radius Mode: Semi Circle"; -} - +std::string RadiusMode2::title() +{ + return "Radius Mode: Semi Circle"; +} + //------------------------------------------------------------------ // // Issue704 // -//------------------------------------------------------------------ +//------------------------------------------------------------------ void Issue704::onEnter() { ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - m_emitter->initWithTotalParticles(100); - addChild(m_emitter, 10); - m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png")); - - // duration - m_emitter->setDuration(kCCParticleDurationInfinity); - - // radius mode - m_emitter->setEmitterMode(kCCParticleModeRadius); - - // radius mode: start and end radius in pixels - m_emitter->setStartRadius(50); - m_emitter->setStartRadiusVar(0); - m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); - m_emitter->setEndRadiusVar(0); - - // radius mode: degrees per second - m_emitter->setRotatePerSecond(0); - m_emitter->setRotatePerSecondVar(0); - - - // angle - m_emitter->setAngle(90); - m_emitter->setAngleVar(0); - - // emitter position - CCSize size = CCDirector::sharedDirector()->getWinSize(); - m_emitter->setPosition(ccp(size.width/2, size.height/2)); - m_emitter->setPosVar(CCPointZero); - - // life of particles - m_emitter->setLife(5); - m_emitter->setLifeVar(0); - - // spin of particles - m_emitter->setStartSpin(0); - m_emitter->setStartSpinVar(0); - m_emitter->setEndSpin(0); - m_emitter->setEndSpinVar(0); - - // color of particles - ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColor(startColor); - - ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; - m_emitter->setStartColorVar(startColorVar); - - ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColor(endColor); - - ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; - m_emitter->setEndColorVar(endColorVar); - - // size, in pixels - m_emitter->setStartSize(16); - m_emitter->setStartSizeVar(0); - m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); - + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + m_emitter->initWithTotalParticles(100); + addChild(m_emitter, 10); + m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png")); + + // duration + m_emitter->setDuration(kCCParticleDurationInfinity); + + // radius mode + m_emitter->setEmitterMode(kCCParticleModeRadius); + + // radius mode: start and end radius in pixels + m_emitter->setStartRadius(50); + m_emitter->setStartRadiusVar(0); + m_emitter->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); + m_emitter->setEndRadiusVar(0); + + // radius mode: degrees per second + m_emitter->setRotatePerSecond(0); + m_emitter->setRotatePerSecondVar(0); + + + // angle + m_emitter->setAngle(90); + m_emitter->setAngleVar(0); + + // emitter position + CCSize size = CCDirector::sharedDirector()->getWinSize(); + m_emitter->setPosition(ccp(size.width/2, size.height/2)); + m_emitter->setPosVar(CCPointZero); + + // life of particles + m_emitter->setLife(5); + m_emitter->setLifeVar(0); + + // spin of particles + m_emitter->setStartSpin(0); + m_emitter->setStartSpinVar(0); + m_emitter->setEndSpin(0); + m_emitter->setEndSpinVar(0); + + // color of particles + ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColor(startColor); + + ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; + m_emitter->setStartColorVar(startColorVar); + + ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColor(endColor); + + ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; + m_emitter->setEndColorVar(endColorVar); + + // size, in pixels + m_emitter->setStartSize(16); + m_emitter->setStartSizeVar(0); + m_emitter->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + m_emitter->setEmissionRate(m_emitter->getTotalParticles() / m_emitter->getLife()); + // additive m_emitter->setIsBlendAdditive(false); @@ -881,84 +881,84 @@ void Issue704::onEnter() m_emitter->runAction(CCRepeatForever::actionWithAction(rot)); } -std::string Issue704::title() -{ - return "Issue 704. Free + Rot"; -} - -std::string Issue704::subtitle() -{ - return "Emitted particles should not rotate"; -} - +std::string Issue704::title() +{ + return "Issue 704. Free + Rot"; +} + +std::string Issue704::subtitle() +{ + return "Emitted particles should not rotate"; +} + //------------------------------------------------------------------ // // Issue870 // -//------------------------------------------------------------------ -void Issue870::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleSystemQuad *system = new CCParticleSystemQuad(); - system->initWithFile("Images/SpinningPeas.plist"); - system->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"), CCRectMake(0,0,32,32)); - addChild(system, 10); - m_emitter = system; - - m_nIndex = 0; - schedule(schedule_selector(Issue870::updateQuads), 2.0f); -} - -void Issue870::updateQuads(ccTime dt) -{ - m_nIndex = (m_nIndex + 1) % 4; - CCRect rect = CCRectMake(m_nIndex * 32, 0, 32, 32); - CCParticleSystemQuad* system = (CCParticleSystemQuad*)m_emitter; - system->setTextureWithRect(m_emitter->getTexture(), rect); -} - -std::string Issue870::title() -{ - return "Issue 870. SubRect"; -} - -std::string Issue870::subtitle() -{ - return "Every 2 seconds the particle should change"; -} - +//------------------------------------------------------------------ +void Issue870::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleSystemQuad *system = new CCParticleSystemQuad(); + system->initWithFile("Images/SpinningPeas.plist"); + system->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"), CCRectMake(0,0,32,32)); + addChild(system, 10); + m_emitter = system; + + m_nIndex = 0; + schedule(schedule_selector(Issue870::updateQuads), 2.0f); +} + +void Issue870::updateQuads(ccTime dt) +{ + m_nIndex = (m_nIndex + 1) % 4; + CCRect rect = CCRectMake(m_nIndex * 32, 0, 32, 32); + CCParticleSystemQuad* system = (CCParticleSystemQuad*)m_emitter; + system->setTextureWithRect(m_emitter->getTexture(), rect); +} + +std::string Issue870::title() +{ + return "Issue 870. SubRect"; +} + +std::string Issue870::subtitle() +{ + return "Every 2 seconds the particle should change"; +} + //------------------------------------------------------------------ // // DemoParticleFromFile // -//------------------------------------------------------------------ -void DemoParticleFromFile::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = new CCParticleSystemQuad(); - std::string filename = "Images/" + m_title + ".plist"; - m_emitter->initWithFile(filename.c_str()); - addChild(m_emitter, 10); - - setEmitterPosition(); -} - +//------------------------------------------------------------------ +void DemoParticleFromFile::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = new CCParticleSystemQuad(); + std::string filename = "Images/" + m_title + ".plist"; + m_emitter->initWithFile(filename.c_str()); + addChild(m_emitter, 10); + + setEmitterPosition(); +} + //------------------------------------------------------------------ // // ParticleDemo // //------------------------------------------------------------------ - + enum { IDC_NEXT = 100, @@ -966,9 +966,9 @@ enum IDC_RESTART, IDC_TOGGLE }; - -static int sceneIdx = -1; - + +static int sceneIdx = -1; + #define MAX_LAYER 41 CCLayer* createParticleLayer(int nIndex) @@ -994,17 +994,17 @@ CCLayer* createParticleLayer(int nIndex) case 16: return new DemoModernArt(); case 17: return new DemoRing(); case 18: return new ParallaxParticle(); - case 19: return new DemoParticleFromFile("BoilingFoam"); - case 20: return new DemoParticleFromFile("BurstPipe"); - case 21: return new DemoParticleFromFile("Comet"); - case 22: return new DemoParticleFromFile("debian"); - case 23: return new DemoParticleFromFile("ExplodingRing"); - case 24: return new DemoParticleFromFile("LavaFlow"); - case 25: return new DemoParticleFromFile("SpinningPeas"); - case 26: return new DemoParticleFromFile("SpookyPeas"); + case 19: return new DemoParticleFromFile("BoilingFoam"); + case 20: return new DemoParticleFromFile("BurstPipe"); + case 21: return new DemoParticleFromFile("Comet"); + case 22: return new DemoParticleFromFile("debian"); + case 23: return new DemoParticleFromFile("ExplodingRing"); + case 24: return new DemoParticleFromFile("LavaFlow"); + case 25: return new DemoParticleFromFile("SpinningPeas"); + case 26: return new DemoParticleFromFile("SpookyPeas"); case 27: return new DemoParticleFromFile("Upsidedown"); - case 28: return new DemoParticleFromFile("Flower"); - case 29: return new DemoParticleFromFile("Spiral"); + case 28: return new DemoParticleFromFile("Flower"); + case 29: return new DemoParticleFromFile("Spiral"); case 30: return new DemoParticleFromFile("Galaxy"); case 31: return new DemoParticleFromFile("Phoenix"); case 32: return new RadiusMode1(); @@ -1055,11 +1055,11 @@ CCLayer* restartParticleAction() pLayer->autorelease(); return pLayer; -} - - -ParticleDemo::ParticleDemo(void) -{ +} + + +ParticleDemo::ParticleDemo(void) +{ initWithColor( ccc4(127,127,127,255) ); m_emitter = NULL; @@ -1095,13 +1095,13 @@ ParticleDemo::ParticleDemo(void) item4->setPosition( CCPointMake( 0, 100) ); item4->setAnchorPoint( CCPointMake(0,0) ); - addChild( menu, 100 ); - + addChild( menu, 100 ); + CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.'); - addChild(labelAtlas, 100, kTagParticleCount); - labelAtlas->setPosition( CCPointMake(s.width-66,50) ); - - // moving background + addChild(labelAtlas, 100, kTagParticleCount); + labelAtlas->setPosition(CCPointMake(s.width-66,50)); + + // moving background m_background = CCSprite::spriteWithFile(s_back3); addChild(m_background, 5); m_background->setPosition( CCPointMake(s.width/2, s.height-180) ); @@ -1113,21 +1113,21 @@ ParticleDemo::ParticleDemo(void) scheduleUpdate(); -} - -ParticleDemo::~ParticleDemo(void) -{ - CC_SAFE_RELEASE(m_emitter); -} - -void ParticleDemo::onEnter(void) -{ - CCLayer::onEnter(); - - CCLabelTTF* pLabel = (CCLabelTTF*)(this->getChildByTag(1000)); - pLabel->setString(title().c_str()); -} - +} + +ParticleDemo::~ParticleDemo(void) +{ + CC_SAFE_RELEASE(m_emitter); +} + +void ParticleDemo::onEnter(void) +{ + CCLayer::onEnter(); + + CCLabelTTF* pLabel = (CCLabelTTF*)(this->getChildByTag(1000)); + pLabel->setString(title().c_str()); +} + std::string ParticleDemo::title() { return "No title"; @@ -1170,11 +1170,11 @@ void ParticleDemo::update(ccTime dt) { if (m_emitter) { - CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount); - char str[5] = {0}; - sprintf(str, "%04d", m_emitter->getParticleCount()); - atlas->setString(str); - } + CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount); + char str[5] = {0}; + sprintf(str, "%04d", m_emitter->getParticleCount()); + atlas->setString(str); + } } void ParticleDemo::toggleCallback(CCObject* pSender) @@ -1213,7 +1213,7 @@ void ParticleDemo::backCallback(CCObject* pSender) CCDirector::sharedDirector()->replaceScene(s); s->release(); } - + void ParticleDemo::setEmitterPosition() { CCSize s = CCDirector::sharedDirector()->getWinSize(); @@ -1221,643 +1221,645 @@ void ParticleDemo::setEmitterPosition() { m_emitter->setPosition( CCPointMake(s.width / 2, s.height / 2) ); } -} - -// ParticleBatchHybrid - -void ParticleBatchHybrid::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - m_emitter = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - m_emitter->retain(); - CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(m_emitter->getTexture()); - - batch->addChild(m_emitter); - - addChild(batch, 10); - - schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f); - - CCNode *node = CCNode::node(); - addChild(node); - - m_pParent1 = batch; - m_pParent2 = node; -} - -void ParticleBatchHybrid::switchRender(ccTime dt) -{ - bool usingBatch = ( m_emitter->getBatchNode() != NULL ); - m_emitter->removeFromParentAndCleanup(false); - - CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 ); - newParent->addChild(m_emitter); - - CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode"); -} - +} + +// ParticleBatchHybrid + +void ParticleBatchHybrid::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + m_emitter = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + m_emitter->retain(); + CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(m_emitter->getTexture()); + + batch->addChild(m_emitter); + + addChild(batch, 10); + + schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f); + + CCNode *node = CCNode::node(); + addChild(node); + + m_pParent1 = batch; + m_pParent2 = node; +} + +void ParticleBatchHybrid::switchRender(ccTime dt) +{ + bool usingBatch = ( m_emitter->getBatchNode() != NULL ); + m_emitter->removeFromParentAndCleanup(false); + + CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 ); + newParent->addChild(m_emitter); + + CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode"); +} + std::string ParticleBatchHybrid::title() { return "Paticle Batch"; } -std::string ParticleBatchHybrid::subtitle() -{ - return "Hybrid: batched and non batched every 2 seconds"; -} - -// ParticleBatchMultipleEmitters - -void ParticleBatchMultipleEmitters::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - emitter1->setStartColor(ccc4f(1,0,0,1)); - CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - emitter2->setStartColor(ccc4f(0,1,0,1)); - CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); - emitter3->setStartColor(ccc4f(0,0,1,1)); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - emitter1->setPosition(ccp( s.width/1.25f, s.height/1.25f)); - emitter2->setPosition(ccp( s.width/2, s.height/2)); - emitter3->setPosition(ccp( s.width/4, s.height/4)); - - CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(emitter1->getTexture()); - - batch->addChild(emitter1, 0); - batch->addChild(emitter2, 0); - batch->addChild(emitter3, 0); - - addChild(batch, 10); -} - +std::string ParticleBatchHybrid::subtitle() +{ + return "Hybrid: batched and non batched every 2 seconds"; +} + +// ParticleBatchMultipleEmitters + +void ParticleBatchMultipleEmitters::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + emitter1->setStartColor(ccc4f(1,0,0,1)); + CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + emitter2->setStartColor(ccc4f(0,1,0,1)); + CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/LavaFlow.plist"); + emitter3->setStartColor(ccc4f(0,0,1,1)); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + emitter1->setPosition(ccp( s.width/1.25f, s.height/1.25f)); + emitter2->setPosition(ccp( s.width/2, s.height/2)); + emitter3->setPosition(ccp( s.width/4, s.height/4)); + + CCParticleBatchNode *batch = CCParticleBatchNode::batchNodeWithTexture(emitter1->getTexture()); + + batch->addChild(emitter1, 0); + batch->addChild(emitter2, 0); + batch->addChild(emitter3, 0); + + addChild(batch, 10); +} + std::string ParticleBatchMultipleEmitters::title() { return "Paticle Batch"; } -std::string ParticleBatchMultipleEmitters::subtitle() -{ - return "Multiple emitters. One Batch"; -} - -// ParticleReorder - -void ParticleReorder::onEnter() -{ - ParticleDemo::onEnter(); - - m_nOrder = 0; - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleSystem *ignore = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - CCNode *parent1 = CCNode::node(); - CCNode *parent2 = CCParticleBatchNode::batchNodeWithTexture(ignore->getTexture()); - - for( unsigned int i=0; i<2;i++) { - CCNode *parent = ( i==0 ? parent1 : parent2 ); - - CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - emitter1->setStartColor(ccc4f(1,0,0,1)); - emitter1->setIsBlendAdditive(false); - CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - emitter2->setStartColor(ccc4f(0,1,0,1)); - emitter2->setIsBlendAdditive(false); - CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); - emitter3->setStartColor(ccc4f(0,0,1,1)); - emitter3->setIsBlendAdditive(false); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - int neg = (i==0 ? 1 : -1 ); - - emitter1->setPosition(ccp( s.width/2-30, s.height/2+60*neg)); - emitter2->setPosition(ccp( s.width/2, s.height/2+60*neg)); - emitter3->setPosition(ccp( s.width/2+30, s.height/2+60*neg)); - - parent->addChild(emitter1, 0, 1); - parent->addChild(emitter2, 0, 2); - parent->addChild(emitter3, 0, 3); - - addChild(parent, 10, 1000+i); - } - - schedule(schedule_selector(ParticleReorder::reorderParticles), 1.0f); -} - -std::string ParticleReorder::title() -{ - return "Reordering particles"; -} - -std::string ParticleReorder::subtitle() -{ - return "Reordering particles with and without batches batches"; -} - -void ParticleReorder::reorderParticles(ccTime dt) -{ - for( int i=0; i<2;i++) { - CCNode *parent = getChildByTag(1000+i); - - CCNode *child1 = parent->getChildByTag(1); - CCNode *child2 = parent->getChildByTag(2); - CCNode *child3 = parent->getChildByTag(3); - - if( m_nOrder % 3 == 0 ) { - parent->reorderChild(child1, 1); - parent->reorderChild(child2, 2); - parent->reorderChild(child3, 3); - - } else if (m_nOrder % 3 == 1 ) { - parent->reorderChild(child1, 3); - parent->reorderChild(child2, 1); - parent->reorderChild(child3, 2); - - } else if (m_nOrder % 3 == 2 ) { - parent->reorderChild(child1, 2); - parent->reorderChild(child2, 3); - parent->reorderChild(child3, 1); - } - } - - m_nOrder++; -} - -class RainbowEffect : public CCParticleSystemQuad -{ -public: - bool init(); - virtual bool initWithTotalParticles(unsigned int numberOfParticles); - virtual void update(ccTime dt); -}; - -bool RainbowEffect::init() -{ - return initWithTotalParticles(150); -} - -bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles) -{ - if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) - { - // additive - setIsBlendAdditive(false); - - // duration - setDuration(kCCParticleDurationInfinity); - - // Gravity Mode - setEmitterMode(kCCParticleModeGravity); - - // Gravity Mode: gravity - setGravity(ccp(0,0)); - - // Gravity mode: radial acceleration - setRadialAccel(0); - setRadialAccelVar(0); - - // Gravity mode: speed of particles - setSpeed(120); - setSpeedVar(0); - - - // angle - setAngle(180); - setAngleVar(0); - - // emitter position - CCSize winSize = CCDirector::sharedDirector()->getWinSize(); - setPosition(ccp(winSize.width/2, winSize.height/2)); - setPosVar(CCPointZero); - - // life of particles - setLife(0.5f); - setLifeVar(0); - - // size, in pixels - setStartSize(25.0f); - setStartSizeVar(0); - setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per seconds - setEmissionRate(getTotalParticles()/getLife()); - - // color of particles - setStartColor(ccc4FFromccc4B(ccc4(50, 50, 50, 50))); - setEndColor(ccc4FFromccc4B(ccc4(0, 0, 0, 0))); - - m_tStartColorVar.r = 0.0f; - m_tStartColorVar.g = 0.0f; - m_tStartColorVar.b = 0.0f; - m_tStartColorVar.a = 0.0f; - m_tEndColorVar.r = 0.0f; - m_tEndColorVar.g = 0.0f; - m_tEndColorVar.b = 0.0f; - m_tEndColorVar.a = 0.0f; - - setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png")); - return true; - } - - return false; -} - -void RainbowEffect::update(ccTime dt) -{ - m_fEmitCounter = 0; - CCParticleSystemQuad::update(dt); -} - - -void Issue1201::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - RainbowEffect *particle = new RainbowEffect(); - particle->initWithTotalParticles(50); - - addChild(particle); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - particle->setPosition(ccp(s.width/2, s.height/2)); - - m_emitter = particle; -} - -std::string Issue1201::title() -{ - return "Issue 1201. Unfinished"; -} - -std::string Issue1201::subtitle() -{ - return "Unfinished test. Ignore it"; -} - -void MultipleParticleSystems::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"); - - for (int i = 0; i<5; i++) { - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); - - particleSystem->setPosition(ccp(i*50 ,i*50)); - - particleSystem->setPositionType(kCCPositionTypeGrouped); - addChild(particleSystem); - } - - m_emitter = NULL; - -} - +std::string ParticleBatchMultipleEmitters::subtitle() +{ + return "Multiple emitters. One Batch"; +} + +// ParticleReorder + +void ParticleReorder::onEnter() +{ + ParticleDemo::onEnter(); + + m_nOrder = 0; + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleSystem* ignore = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + CCNode *parent1 = CCNode::node(); + CCNode *parent2 = CCParticleBatchNode::batchNodeWithTexture(ignore->getTexture()); + ignore->unscheduleUpdate(); + + for( unsigned int i=0; i<2;i++) + { + CCNode *parent = ( i==0 ? parent1 : parent2 ); + + CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + emitter1->setStartColor(ccc4f(1,0,0,1)); + emitter1->setIsBlendAdditive(false); + CCParticleSystemQuad *emitter2 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + emitter2->setStartColor(ccc4f(0,1,0,1)); + emitter2->setIsBlendAdditive(false); + CCParticleSystemQuad *emitter3 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); + emitter3->setStartColor(ccc4f(0,0,1,1)); + emitter3->setIsBlendAdditive(false); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + int neg = (i==0 ? 1 : -1 ); + + emitter1->setPosition(ccp( s.width/2-30, s.height/2+60*neg)); + emitter2->setPosition(ccp( s.width/2, s.height/2+60*neg)); + emitter3->setPosition(ccp( s.width/2+30, s.height/2+60*neg)); + + parent->addChild(emitter1, 0, 1); + parent->addChild(emitter2, 0, 2); + parent->addChild(emitter3, 0, 3); + + addChild(parent, 10, 1000+i); + } + + schedule(schedule_selector(ParticleReorder::reorderParticles), 1.0f); +} + +std::string ParticleReorder::title() +{ + return "Reordering particles"; +} + +std::string ParticleReorder::subtitle() +{ + return "Reordering particles with and without batches batches"; +} + +void ParticleReorder::reorderParticles(ccTime dt) +{ + for( int i=0; i<2;i++) { + CCNode *parent = getChildByTag(1000+i); + + CCNode *child1 = parent->getChildByTag(1); + CCNode *child2 = parent->getChildByTag(2); + CCNode *child3 = parent->getChildByTag(3); + + if( m_nOrder % 3 == 0 ) { + parent->reorderChild(child1, 1); + parent->reorderChild(child2, 2); + parent->reorderChild(child3, 3); + + } else if (m_nOrder % 3 == 1 ) { + parent->reorderChild(child1, 3); + parent->reorderChild(child2, 1); + parent->reorderChild(child3, 2); + + } else if (m_nOrder % 3 == 2 ) { + parent->reorderChild(child1, 2); + parent->reorderChild(child2, 3); + parent->reorderChild(child3, 1); + } + } + + m_nOrder++; +} + +class RainbowEffect : public CCParticleSystemQuad +{ +public: + bool init(); + virtual bool initWithTotalParticles(unsigned int numberOfParticles); + virtual void update(ccTime dt); +}; + +bool RainbowEffect::init() +{ + return initWithTotalParticles(150); +} + +bool RainbowEffect::initWithTotalParticles(unsigned int numberOfParticles) +{ + if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) + { + // additive + setIsBlendAdditive(false); + + // duration + setDuration(kCCParticleDurationInfinity); + + // Gravity Mode + setEmitterMode(kCCParticleModeGravity); + + // Gravity Mode: gravity + setGravity(ccp(0,0)); + + // Gravity mode: radial acceleration + setRadialAccel(0); + setRadialAccelVar(0); + + // Gravity mode: speed of particles + setSpeed(120); + setSpeedVar(0); + + + // angle + setAngle(180); + setAngleVar(0); + + // emitter position + CCSize winSize = CCDirector::sharedDirector()->getWinSize(); + setPosition(ccp(winSize.width/2, winSize.height/2)); + setPosVar(CCPointZero); + + // life of particles + setLife(0.5f); + setLifeVar(0); + + // size, in pixels + setStartSize(25.0f); + setStartSizeVar(0); + setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per seconds + setEmissionRate(getTotalParticles()/getLife()); + + // color of particles + setStartColor(ccc4FFromccc4B(ccc4(50, 50, 50, 50))); + setEndColor(ccc4FFromccc4B(ccc4(0, 0, 0, 0))); + + m_tStartColorVar.r = 0.0f; + m_tStartColorVar.g = 0.0f; + m_tStartColorVar.b = 0.0f; + m_tStartColorVar.a = 0.0f; + m_tEndColorVar.r = 0.0f; + m_tEndColorVar.g = 0.0f; + m_tEndColorVar.b = 0.0f; + m_tEndColorVar.a = 0.0f; + + setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/particles.png")); + return true; + } + + return false; +} + +void RainbowEffect::update(ccTime dt) +{ + m_fEmitCounter = 0; + CCParticleSystemQuad::update(dt); +} + + +void Issue1201::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + RainbowEffect *particle = new RainbowEffect(); + particle->initWithTotalParticles(50); + + addChild(particle); + + CCSize s = CCDirector::sharedDirector()->getWinSize(); + + particle->setPosition(ccp(s.width/2, s.height/2)); + + m_emitter = particle; +} + +std::string Issue1201::title() +{ + return "Issue 1201. Unfinished"; +} + +std::string Issue1201::subtitle() +{ + return "Unfinished test. Ignore it"; +} + +void MultipleParticleSystems::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCTextureCache::sharedTextureCache()->addImage("Images/particles.png"); + + for (int i = 0; i<5; i++) { + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); + + particleSystem->setPosition(ccp(i*50 ,i*50)); + + particleSystem->setPositionType(kCCPositionTypeGrouped); + addChild(particleSystem); + } + + m_emitter = NULL; + +} + std::string MultipleParticleSystems::title() { return "Multiple particle systems"; } -std::string MultipleParticleSystems::subtitle() -{ - return "v1.1 test: FPS should be lower than next test"; -} - -void MultipleParticleSystems::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned int count = 0; - - CCObject* pObj = NULL; - CCARRAY_FOREACH(m_pChildren, pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[100] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - -// MultipleParticleSystemsBatched - -void MultipleParticleSystemsBatched::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - CCParticleBatchNode *batchNode = new CCParticleBatchNode(); - batchNode->initWithTexture(NULL, 3000); - - addChild(batchNode, 1, 2); - - for (int i = 0; i<5; i++) { - - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); - - particleSystem->setPositionType(kCCPositionTypeGrouped); - particleSystem->setPosition(ccp(i*50 ,i*50)); - - batchNode->setTexture(particleSystem->getTexture()); - batchNode->addChild(particleSystem); - } - - batchNode->release(); - - m_emitter = NULL; -} - -void MultipleParticleSystemsBatched::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned count = 0; - - CCNode* batchNode = getChildByTag(2); - CCObject* pObj = NULL; - CCARRAY_FOREACH(batchNode->getChildren(), pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[50] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - +std::string MultipleParticleSystems::subtitle() +{ + return "v1.1 test: FPS should be lower than next test"; +} + +void MultipleParticleSystems::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned int count = 0; + + CCObject* pObj = NULL; + CCARRAY_FOREACH(m_pChildren, pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[100] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + +// MultipleParticleSystemsBatched + +void MultipleParticleSystemsBatched::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + CCParticleBatchNode *batchNode = new CCParticleBatchNode(); + batchNode->initWithTexture(NULL, 3000); + + addChild(batchNode, 1, 2); + + for (int i = 0; i<5; i++) { + + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/SpinningPeas.plist"); + + particleSystem->setPositionType(kCCPositionTypeGrouped); + particleSystem->setPosition(ccp(i*50 ,i*50)); + + batchNode->setTexture(particleSystem->getTexture()); + batchNode->addChild(particleSystem); + } + + batchNode->release(); + + m_emitter = NULL; +} + +void MultipleParticleSystemsBatched::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned count = 0; + + CCNode* batchNode = getChildByTag(2); + CCObject* pObj = NULL; + CCARRAY_FOREACH(batchNode->getChildren(), pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[50] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + std::string MultipleParticleSystemsBatched::title() { return "Multiple particle systems batched"; } -std::string MultipleParticleSystemsBatched::subtitle() -{ - return "v1.1 test: should perform better than previous test"; -} - -// AddAndDeleteParticleSystems - -void AddAndDeleteParticleSystems::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background, true); - m_background = NULL; - - //adds the texture inside the plist to the texture cache - m_pBatchNode = CCParticleBatchNode::batchNodeWithTexture(NULL, 16000); - - addChild(m_pBatchNode, 1, 2); - - for (int i = 0; i<6; i++) { - - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); - m_pBatchNode->setTexture(particleSystem->getTexture()); - - particleSystem->setPositionType(kCCPositionTypeGrouped); - particleSystem->setTotalParticles(200); - - particleSystem->setPosition(ccp(i*15 +100,i*15+100)); - - unsigned int randZ = rand() % 100; - m_pBatchNode->addChild(particleSystem, randZ, -1); - - } - - schedule(schedule_selector(AddAndDeleteParticleSystems::removeSystem), 0.5f); - m_emitter = NULL; - -} - -void AddAndDeleteParticleSystems::removeSystem(ccTime dt) -{ - int nChildrenCount = m_pBatchNode->getChildren()->count(); - if (nChildrenCount > 0) - { - CCLOG("remove random system"); - unsigned int uRand = rand() % (nChildrenCount - 1); - m_pBatchNode->removeChild((CCNode*)m_pBatchNode->getChildren()->objectAtIndex(uRand), true); - - CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); - //add new - - particleSystem->setPositionType(kCCPositionTypeGrouped); - particleSystem->setTotalParticles(200); - - particleSystem->setPosition(ccp(rand() % 300 ,rand() % 400)); - - CCLOG("add a new system"); - unsigned int randZ = rand() % 100; - m_pBatchNode->addChild(particleSystem, randZ, -1); - } -} - -void AddAndDeleteParticleSystems::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned int count = 0; - - CCNode* batchNode = getChildByTag(2); - CCObject* pObj = NULL; - CCARRAY_FOREACH(batchNode->getChildren(), pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[100] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - +std::string MultipleParticleSystemsBatched::subtitle() +{ + return "v1.1 test: should perform better than previous test"; +} + +// AddAndDeleteParticleSystems + +void AddAndDeleteParticleSystems::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background, true); + m_background = NULL; + + //adds the texture inside the plist to the texture cache + m_pBatchNode = CCParticleBatchNode::batchNodeWithTexture(NULL, 16000); + + addChild(m_pBatchNode, 1, 2); + + for (int i = 0; i<6; i++) { + + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); + m_pBatchNode->setTexture(particleSystem->getTexture()); + + particleSystem->setPositionType(kCCPositionTypeGrouped); + particleSystem->setTotalParticles(200); + + particleSystem->setPosition(ccp(i*15 +100,i*15+100)); + + unsigned int randZ = rand() % 100; + m_pBatchNode->addChild(particleSystem, randZ, -1); + + } + + schedule(schedule_selector(AddAndDeleteParticleSystems::removeSystem), 0.5f); + m_emitter = NULL; + +} + +void AddAndDeleteParticleSystems::removeSystem(ccTime dt) +{ + int nChildrenCount = m_pBatchNode->getChildren()->count(); + if (nChildrenCount > 0) + { + CCLOG("remove random system"); + unsigned int uRand = rand() % (nChildrenCount - 1); + m_pBatchNode->removeChild((CCNode*)m_pBatchNode->getChildren()->objectAtIndex(uRand), true); + + CCParticleSystemQuad *particleSystem = CCParticleSystemQuad::particleWithFile("Images/Spiral.plist"); + //add new + + particleSystem->setPositionType(kCCPositionTypeGrouped); + particleSystem->setTotalParticles(200); + + particleSystem->setPosition(ccp(rand() % 300 ,rand() % 400)); + + CCLOG("add a new system"); + unsigned int randZ = rand() % 100; + m_pBatchNode->addChild(particleSystem, randZ, -1); + } +} + +void AddAndDeleteParticleSystems::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned int count = 0; + + CCNode* batchNode = getChildByTag(2); + CCObject* pObj = NULL; + CCARRAY_FOREACH(batchNode->getChildren(), pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[100] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + std::string AddAndDeleteParticleSystems::title() { return "Add and remove Particle System"; } -std::string AddAndDeleteParticleSystems::subtitle() -{ - return "v1.1 test: every 2 sec 1 system disappear, 1 appears"; -} - -// ReorderParticleSystems - -void ReorderParticleSystems::onEnter() -{ - ParticleDemo::onEnter(); - - setColor(ccBLACK); - removeChild(m_background ,true); - m_background = NULL; - - m_pBatchNode = CCParticleBatchNode::batchNodeWithFile("Images/stars-grayscale.png" ,3000); - - addChild(m_pBatchNode, 1, 2); - - - for (int i = 0; i<3; i++) { - - CCParticleSystemQuad* particleSystem = new CCParticleSystemQuad(); - particleSystem->initWithTotalParticles(200); - particleSystem->setTexture(m_pBatchNode->getTexture()); - - // duration - particleSystem->setDuration(kCCParticleDurationInfinity); - - // radius mode - particleSystem->setEmitterMode(kCCParticleModeRadius); - - // radius mode: 100 pixels from center - particleSystem->setStartRadius(100); - particleSystem->setStartRadiusVar(0); - particleSystem->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); - particleSystem->setEndRadiusVar(0); // not used when start == end - - // radius mode: degrees per second - // 45 * 4 seconds of life = 180 degrees - particleSystem->setRotatePerSecond(45); - particleSystem->setRotatePerSecondVar(0); - - - // angle - particleSystem->setAngle(90); - particleSystem->setAngleVar(0); - - // emitter position - particleSystem->setPosVar(CCPointZero); - - // life of particles - particleSystem->setLife(4); - particleSystem->setLifeVar(0); - - // spin of particles - particleSystem->setStartSpin(0); - particleSystem->setStartSpinVar(0); - particleSystem->setEndSpin(0); - particleSystem->setEndSpinVar(0); - - // color of particles - float color[3] = {0,0,0}; - color[i] = 1; - ccColor4F startColor = {color[0], color[1], color[2], 1.0f}; - particleSystem->setStartColor(startColor); - - ccColor4F startColorVar = {0, 0, 0, 0}; - particleSystem->setStartColorVar(startColorVar); - - ccColor4F endColor = startColor; - particleSystem->setEndColor(endColor); - - ccColor4F endColorVar = startColorVar; - particleSystem->setEndColorVar(endColorVar); - - // size, in pixels - particleSystem->setStartSize(32); - particleSystem->setStartSizeVar(0); - particleSystem->setEndSize(kCCParticleStartSizeEqualToEndSize); - - // emits per second - particleSystem->setEmissionRate(particleSystem->getTotalParticles()/particleSystem->getLife()); - - // additive - - particleSystem->setPosition(ccp(i*10+120 ,200)); - - - m_pBatchNode->addChild(particleSystem); - particleSystem->setPositionType(kCCPositionTypeFree); - - particleSystem->release(); - - //[pBNode addChild:particleSystem z:10 tag:0); - - } - - schedule(schedule_selector(ReorderParticleSystems::reorderSystem), 2.0f); - m_emitter = NULL; - -} - -void ReorderParticleSystems::reorderSystem(ccTime time) -{ - CCParticleSystem* system = (CCParticleSystem*)m_pBatchNode->getChildren()->objectAtIndex(1); - m_pBatchNode->reorderChild(system, system->getZOrder() - 1); -} - - -void ReorderParticleSystems::update(ccTime dt) -{ - CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); - - unsigned int count = 0; - - CCNode* batchNode = getChildByTag(2); - CCObject* pObj = NULL; - CCARRAY_FOREACH(batchNode->getChildren(), pObj) - { - CCParticleSystem* item = dynamic_cast(pObj); - if (item != NULL) - { - count += item->getParticleCount(); - } - } - char str[100] = {0}; - sprintf(str, "%4d", count); - atlas->setString(str); -} - +std::string AddAndDeleteParticleSystems::subtitle() +{ + return "v1.1 test: every 2 sec 1 system disappear, 1 appears"; +} + +// ReorderParticleSystems + +void ReorderParticleSystems::onEnter() +{ + ParticleDemo::onEnter(); + + setColor(ccBLACK); + removeChild(m_background ,true); + m_background = NULL; + + m_pBatchNode = CCParticleBatchNode::batchNodeWithFile("Images/stars-grayscale.png" ,3000); + + addChild(m_pBatchNode, 1, 2); + + + for (int i = 0; i<3; i++) { + + CCParticleSystemQuad* particleSystem = new CCParticleSystemQuad(); + particleSystem->initWithTotalParticles(200); + particleSystem->setTexture(m_pBatchNode->getTexture()); + + // duration + particleSystem->setDuration(kCCParticleDurationInfinity); + + // radius mode + particleSystem->setEmitterMode(kCCParticleModeRadius); + + // radius mode: 100 pixels from center + particleSystem->setStartRadius(100); + particleSystem->setStartRadiusVar(0); + particleSystem->setEndRadius(kCCParticleStartRadiusEqualToEndRadius); + particleSystem->setEndRadiusVar(0); // not used when start == end + + // radius mode: degrees per second + // 45 * 4 seconds of life = 180 degrees + particleSystem->setRotatePerSecond(45); + particleSystem->setRotatePerSecondVar(0); + + + // angle + particleSystem->setAngle(90); + particleSystem->setAngleVar(0); + + // emitter position + particleSystem->setPosVar(CCPointZero); + + // life of particles + particleSystem->setLife(4); + particleSystem->setLifeVar(0); + + // spin of particles + particleSystem->setStartSpin(0); + particleSystem->setStartSpinVar(0); + particleSystem->setEndSpin(0); + particleSystem->setEndSpinVar(0); + + // color of particles + float color[3] = {0,0,0}; + color[i] = 1; + ccColor4F startColor = {color[0], color[1], color[2], 1.0f}; + particleSystem->setStartColor(startColor); + + ccColor4F startColorVar = {0, 0, 0, 0}; + particleSystem->setStartColorVar(startColorVar); + + ccColor4F endColor = startColor; + particleSystem->setEndColor(endColor); + + ccColor4F endColorVar = startColorVar; + particleSystem->setEndColorVar(endColorVar); + + // size, in pixels + particleSystem->setStartSize(32); + particleSystem->setStartSizeVar(0); + particleSystem->setEndSize(kCCParticleStartSizeEqualToEndSize); + + // emits per second + particleSystem->setEmissionRate(particleSystem->getTotalParticles()/particleSystem->getLife()); + + // additive + + particleSystem->setPosition(ccp(i*10+120 ,200)); + + + m_pBatchNode->addChild(particleSystem); + particleSystem->setPositionType(kCCPositionTypeFree); + + particleSystem->release(); + + //[pBNode addChild:particleSystem z:10 tag:0); + + } + + schedule(schedule_selector(ReorderParticleSystems::reorderSystem), 2.0f); + m_emitter = NULL; + +} + +void ReorderParticleSystems::reorderSystem(ccTime time) +{ + CCParticleSystem* system = (CCParticleSystem*)m_pBatchNode->getChildren()->objectAtIndex(1); + m_pBatchNode->reorderChild(system, system->getZOrder() - 1); +} + + +void ReorderParticleSystems::update(ccTime dt) +{ + CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagParticleCount); + + unsigned int count = 0; + + CCNode* batchNode = getChildByTag(2); + CCObject* pObj = NULL; + CCARRAY_FOREACH(batchNode->getChildren(), pObj) + { + CCParticleSystem* item = dynamic_cast(pObj); + if (item != NULL) + { + count += item->getParticleCount(); + } + } + char str[100] = {0}; + sprintf(str, "%4d", count); + atlas->setString(str); +} + std::string ReorderParticleSystems::title() { return "reorder systems"; } -std::string ReorderParticleSystems::subtitle() -{ - return "changes every 2 seconds"; -} - - -void ParticleTestScene::runThisTest() -{ - addChild(nextParticleAction()); - - CCDirector::sharedDirector()->replaceScene(this); -} +std::string ReorderParticleSystems::subtitle() +{ + return "changes every 2 seconds"; +} + + +void ParticleTestScene::runThisTest() +{ + addChild(nextParticleAction()); + + CCDirector::sharedDirector()->replaceScene(this); +} diff --git a/tests/tests/ParticleTest/ParticleTest.h b/tests/tests/ParticleTest/ParticleTest.h index 07d1f9a021..dc3e748a81 100644 --- a/tests/tests/ParticleTest/ParticleTest.h +++ b/tests/tests/ParticleTest/ParticleTest.h @@ -1,28 +1,28 @@ #ifndef _PARTICLE_TEST_H_ #define _PARTICLE_TEST_H_ - -#include "../testBasic.h" -////----#include "cocos2d.h" + +#include "../testBasic.h" +////----#include "cocos2d.h" // #include "touch_dispatcher/CCTouch.h" // #include "CCParticleExample.h" - -class ParticleTestScene : public TestScene -{ -public: - virtual void runThisTest(); -}; - + +class ParticleTestScene : public TestScene +{ +public: + virtual void runThisTest(); +}; + class ParticleDemo : public CCLayerColor { -protected: +protected: CCParticleSystem* m_emitter; CCSprite* m_background; - -public: - ParticleDemo(void); - ~ParticleDemo(void); - - virtual void onEnter(void); + +public: + ParticleDemo(void); + ~ParticleDemo(void); + + virtual void onEnter(void); virtual std::string title(); @@ -152,19 +152,19 @@ public: virtual std::string title(); }; -class DemoParticleFromFile : public ParticleDemo -{ -public: - std::string m_title; - DemoParticleFromFile(const char *file) - { - m_title = file; - } - virtual void onEnter(); - virtual std::string title() - { - return m_title; - } +class DemoParticleFromFile : public ParticleDemo +{ +public: + std::string m_title; + DemoParticleFromFile(const char *file) + { + m_title = file; + } + virtual void onEnter(); + virtual std::string title() + { + return m_title; + } }; class RadiusMode1 : public ParticleDemo @@ -173,22 +173,22 @@ public: virtual void onEnter(); virtual std::string title(); }; - + class RadiusMode2 : public ParticleDemo { public: virtual void onEnter(); virtual std::string title(); -}; - +}; + class Issue704 : public ParticleDemo { public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); -}; - +}; + class Issue870 : public ParticleDemo { public: @@ -199,16 +199,16 @@ public: private: int m_nIndex; -}; - +}; + class Issue1201 : public ParticleDemo { public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); -}; - +}; + class ParticleBatchHybrid : public ParticleDemo { public: @@ -217,18 +217,18 @@ public: virtual std::string title(); virtual std::string subtitle(); private: - CCNode* m_pParent1; + CCNode* m_pParent1; CCNode* m_pParent2; -}; - +}; + class ParticleBatchMultipleEmitters : public ParticleDemo { public: virtual void onEnter(); virtual std::string title(); virtual std::string subtitle(); -}; - +}; + class ParticleReorder : public ParticleDemo { public: @@ -238,8 +238,8 @@ public: virtual std::string subtitle(); private: unsigned int m_nOrder; -}; - +}; + class MultipleParticleSystems : public ParticleDemo { public: @@ -247,8 +247,8 @@ public: virtual std::string title(); virtual std::string subtitle(); virtual void update(ccTime dt); -}; - +}; + class MultipleParticleSystemsBatched : public ParticleDemo { public: @@ -258,8 +258,8 @@ public: virtual std::string subtitle(); private: CCParticleBatchNode* m_pBatchNode; -}; - +}; + class AddAndDeleteParticleSystems : public ParticleDemo { public: @@ -270,8 +270,8 @@ public: virtual std::string subtitle(); private: CCParticleBatchNode* m_pBatchNode; -}; - +}; + class ReorderParticleSystems : public ParticleDemo { public: @@ -282,6 +282,6 @@ public: virtual std::string subtitle(); private: CCParticleBatchNode* m_pBatchNode; -}; - -#endif +}; + +#endif From 2b272e281394c2dc468a84de816f3fa2f787856d Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 5 Apr 2012 14:19:22 +0800 Subject: [PATCH 2/5] ParticleTest --- HelloWorld/Classes/HelloWorldScene.cpp | 10 ++++++++++ .../project.pbxproj.REMOVED.git-id | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/HelloWorld/Classes/HelloWorldScene.cpp b/HelloWorld/Classes/HelloWorldScene.cpp index ed64ec4220..2926807222 100644 --- a/HelloWorld/Classes/HelloWorldScene.cpp +++ b/HelloWorld/Classes/HelloWorldScene.cpp @@ -68,6 +68,16 @@ bool HelloWorld::init() // add the sprite as a child to this layer this->addChild(pSprite, 0); + CCParticleSystem* pTmp = CCParticleSystemQuad::particleWithFile("LavaFlow.plist"); + CCParticleBatchNode* pBatch = CCParticleBatchNode::batchNodeWithTexture(pTmp->getTexture()); + addChild(pBatch); + pTmp->unscheduleUpdate(); + + CCParticleSystem* pSys = CCParticleSystemQuad::particleWithFile("LavaFlow.plist"); + pBatch->addChild(pSys); + pSys->setPosition(ccp(size.width/2, size.height/2)); + + return true; } diff --git a/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id b/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id index 8894e9c69d..ecb49f312f 100644 --- a/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/HelloWorld/ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -2d9494d763406ba9945e40f011820005d14b92eb \ No newline at end of file +ce13f14088361cd82d63174ca2c3134f69b1e8bb \ No newline at end of file From df58a0925510e2d388852bb912e6a46c723fe59b Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 5 Apr 2012 18:53:53 +0800 Subject: [PATCH 3/5] Update: 1. init CCSprite::m_pobBatchNode at the beginning of CCSprite::initWithTexture. 2. Add CCAssert in ccArrayRemoveObjectAtIndex. 3. Use new method to allocate CCDirector. --- cocos2dx/CCDirector.cpp | 26 ++++++++++++------- .../platform/win32/CCAccelerometer_win32.cpp | 1 + .../platform/win32/CCAccelerometer_win32.h | 2 +- cocos2dx/sprite_nodes/CCSprite.cpp | 5 ++-- cocos2dx/support/data_support/ccCArray.h | 23 ++++++++-------- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index d5ea09de0e..c8fd3d4af1 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -69,21 +69,20 @@ NS_CC_BEGIN // XXX it shoul be a Director ivar. Move it there once support for multiple directors is added // singleton stuff -static CCDisplayLinkDirector s_sharedDirector; -static bool s_bFirstRun = true; +static CCDisplayLinkDirector* s_pSharedDirector = NULL; #define kDefaultFPS 60 // 60 frames per second extern const char* cocos2dVersion(void); CCDirector* CCDirector::sharedDirector(void) { - if (s_bFirstRun) - { - s_sharedDirector.init(); - s_bFirstRun = false; - } - - return &s_sharedDirector; + if (s_pSharedDirector == NULL) + { + s_pSharedDirector = new CCDisplayLinkDirector(); + s_pSharedDirector->init(); + } + + return s_pSharedDirector; } CCDirector::CCDirector(void) @@ -112,6 +111,9 @@ bool CCDirector::init(void) m_pProjectionDelegate = NULL; // FPS + m_fAccumDt = 0.0f; + m_fFrameRate = 0.0f; + m_pFPSLabel = NULL; m_bDisplayFPS = false; m_uTotalFrames = m_uFrames = 0; m_pszFPS = new char[10]; @@ -157,7 +159,7 @@ bool CCDirector::init(void) CCDirector::~CCDirector(void) { - CCLOGINFO("cocos2d: deallocing %p", this); + CCLOG("cocos2d: deallocing %p", this); #if CC_DIRECTOR_FAST_FPS CC_SAFE_RELEASE(m_pFPSLabel); @@ -171,6 +173,7 @@ CCDirector::~CCDirector(void) CC_SAFE_RELEASE(m_pTouchDispatcher); CC_SAFE_RELEASE(m_pKeypadDispatcher); CC_SAFE_DELETE(m_pAccelerometer); + // pop the autorelease pool CCPoolManager::getInstance()->pop(); @@ -236,10 +239,12 @@ void CCDirector::drawScene(void) m_pNotificationNode->visit(); } +#if CC_DIRECTOR_FAST_FPS == 1 if (m_bDisplayFPS) { showFPS(); } +#endif #if CC_ENABLE_PROFILERS showProfilers(); @@ -667,6 +672,7 @@ void CCDirector::purgeDirector() // OpenGL view m_pobOpenGLView->release(); m_pobOpenGLView = NULL; + CC_SAFE_DELETE(s_pSharedDirector); } void CCDirector::setNextScene(void) diff --git a/cocos2dx/platform/win32/CCAccelerometer_win32.cpp b/cocos2dx/platform/win32/CCAccelerometer_win32.cpp index 06d75c877d..d2d400621d 100644 --- a/cocos2dx/platform/win32/CCAccelerometer_win32.cpp +++ b/cocos2dx/platform/win32/CCAccelerometer_win32.cpp @@ -151,6 +151,7 @@ namespace cocos2d CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL) { + memset(&m_obAccelerationValue, 0, sizeof(m_obAccelerationValue)); } CCAccelerometer::~CCAccelerometer() diff --git a/cocos2dx/platform/win32/CCAccelerometer_win32.h b/cocos2dx/platform/win32/CCAccelerometer_win32.h index ff0b626faf..438bcfe3c0 100644 --- a/cocos2dx/platform/win32/CCAccelerometer_win32.h +++ b/cocos2dx/platform/win32/CCAccelerometer_win32.h @@ -38,8 +38,8 @@ public: void setDelegate(CCAccelerometerDelegate* pDelegate); void update( double x,double y,double z,double timestamp ); private: + CCAcceleration m_obAccelerationValue; CCAccelerometerDelegate* m_pAccelDelegate; - CCAcceleration m_obAccelerationValue; }; }//namespace cocos2d diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index b8477b338e..980875efee 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -159,6 +159,7 @@ bool CCSprite::init(void) // designated initializer bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated) { + m_pobBatchNode = NULL; // shader program setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); @@ -172,7 +173,6 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r m_sBlendFunc.src = CC_BLEND_SRC; m_sBlendFunc.dst = CC_BLEND_DST; - m_bFlipX = m_bFlipY = false; // default transform anchor: center @@ -182,8 +182,7 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r m_obOffsetPosition = CCPointZero; m_bHasChildren = false; - m_pobBatchNode = NULL; - + // clean the Quad memset(&m_sQuad, 0, sizeof(m_sQuad)); diff --git a/cocos2dx/support/data_support/ccCArray.h b/cocos2dx/support/data_support/ccCArray.h index 9469f45c48..fa015562ba 100644 --- a/cocos2dx/support/data_support/ccCArray.h +++ b/cocos2dx/support/data_support/ccCArray.h @@ -225,18 +225,19 @@ static inline void ccArrayRemoveAllObjects(ccArray *arr) Behaviour undefined if index outside [0, num-1]. */ static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj) { - if (bReleaseObj) - { - arr->arr[index]->release(); - } - - arr->num--; + CCAssert(arr && arr->num > 0 && index < arr->num, "Invalid index. Out of bounds"); + if (bReleaseObj) + { + arr->arr[index]->release(); + } - unsigned int remaining = arr->num - index; - if (remaining > 0) - { - memmove(&arr->arr[index], &arr->arr[index+1], remaining * sizeof(void*)); - } + arr->num--; + + unsigned int remaining = arr->num - index; + if (remaining > 0) + { + memmove(&arr->arr[index], &arr->arr[index+1], remaining * sizeof(void*)); + } } /** Removes object at specified index and fills the gap with the last object, From 64665fe7c82e6717b84615c39350b081cf561c81 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Apr 2012 12:02:40 +0800 Subject: [PATCH 4/5] issue #1094: Make ParticleBatchNode works on win32. --- cocos2dx/cocoa/CCDictionary.cpp | 5 +- cocos2dx/cocoa/CCObject.cpp | 4 +- cocos2dx/include/CCCamera.h | 126 ++++++++------- cocos2dx/include/CCObject.h | 8 +- cocos2dx/include/CCString.h | 152 ++++++++++-------- .../particle_nodes/CCParticleSystemQuad.cpp | 13 +- cocos2dx/support/CCArray.cpp | 11 +- cocos2dx/textures/CCTextureAtlas.cpp | 56 +++++-- 8 files changed, 220 insertions(+), 155 deletions(-) diff --git a/cocos2dx/cocoa/CCDictionary.cpp b/cocos2dx/cocoa/CCDictionary.cpp index 12036a27d9..7c68944273 100644 --- a/cocos2dx/cocoa/CCDictionary.cpp +++ b/cocos2dx/cocoa/CCDictionary.cpp @@ -220,6 +220,7 @@ void CCDictionary::removeAllObjects() CCObject* CCDictionary::copyWithZone(CCZone* pZone) { + CCAssert(pZone == NULL, "CCDirctionary should not be inherited."); CCDictionary* pNewDict = new CCDictionary(); CCDictElement* pElement = NULL; @@ -227,14 +228,14 @@ CCObject* CCDictionary::copyWithZone(CCZone* pZone) { CCDICT_FOREACH(this, pElement) { - pNewDict->setObject(pElement->getObject(), pElement->getIntKey()); + pNewDict->setObject(pElement->getObject()->copy(), pElement->getIntKey()); } } else if (m_eDictType == kCCDictStr) { CCDICT_FOREACH(this, pElement) { - pNewDict->setObject(pElement->getObject(), pElement->getStrKey()); + pNewDict->setObject(pElement->getObject()->copy(), pElement->getStrKey()); } } diff --git a/cocos2dx/cocoa/CCObject.cpp b/cocos2dx/cocoa/CCObject.cpp index de36894444..1aade9d140 100644 --- a/cocos2dx/cocoa/CCObject.cpp +++ b/cocos2dx/cocoa/CCObject.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #include "ccMacros.h" #include "CCScriptSupport.h" -namespace cocos2d { +NS_CC_BEGIN CCObject* CCCopying::copyWithZone(CCZone *pZone) { @@ -111,4 +111,4 @@ bool CCObject::isEqual(const CCObject *pObject) return this == pObject; } -}//namespace cocos2d +NS_CC_END diff --git a/cocos2dx/include/CCCamera.h b/cocos2dx/include/CCCamera.h index 599fbc05d3..dbd5d4e961 100755 --- a/cocos2dx/include/CCCamera.h +++ b/cocos2dx/include/CCCamera.h @@ -31,84 +31,86 @@ THE SOFTWARE. #include "ccMacros.h" #include #include "kazmath/mat4.h" -namespace cocos2d { - /** - A CCCamera is used in every CCNode. - Useful to look at the object from different views. - The OpenGL gluLookAt() function is used to locate the - camera. - If the object is transformed by any of the scale, rotation or - position attributes, then they will override the camera. +NS_CC_BEGIN - IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both. - World coordinates won't work if you use the camera. +/** +A CCCamera is used in every CCNode. +Useful to look at the object from different views. +The OpenGL gluLookAt() function is used to locate the +camera. - Limitations: +If the object is transformed by any of the scale, rotation or +position attributes, then they will override the camera. - - Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors) - using the camera. +IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both. +World coordinates won't work if you use the camera. - - It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object. +Limitations: - - It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate. +- Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors) +using the camera. - */ - class CC_DLL CCCamera : public CCObject - { - protected: - float m_fEyeX; - float m_fEyeY; - float m_fEyeZ; +- It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object. - float m_fCenterX; - float m_fCenterY; - float m_fCenterZ; +- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate. - float m_fUpX; - float m_fUpY; - float m_fUpZ; +*/ +class CC_DLL CCCamera : public CCObject +{ +protected: + float m_fEyeX; + float m_fEyeY; + float m_fEyeZ; - bool m_bDirty; - kmMat4 m_lookupMatrix; - public: - CCCamera(void); - ~CCCamera(void); + float m_fCenterX; + float m_fCenterY; + float m_fCenterZ; - void init(void); + float m_fUpX; + float m_fUpY; + float m_fUpZ; - char * description(void); + bool m_bDirty; + kmMat4 m_lookupMatrix; +public: + CCCamera(void); + ~CCCamera(void); - /** sets the dirty value */ - inline void setDirty(bool bValue) { m_bDirty = bValue; } - /** get the dirty value */ - inline bool getDirty(void) { return m_bDirty; } + void init(void); - /** sets the camera in the default position */ - void restore(void); - /** Sets the camera using gluLookAt using its eye, center and up_vector */ - void locate(void); - /** sets the eye values in points */ - void setEyeXYZ(float fEyeX, float fEyeY, float fEyeZ); - /** sets the center values in points */ - void setCenterXYZ(float fCenterX, float fCenterY, float fCenterZ); - /** sets the up values */ - void setUpXYZ(float fUpX, float fUpY, float fUpZ); + char * description(void); - /** get the eye vector values in points */ - void getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ); - /** get the center vector values int points */ - void getCenterXYZ(float *pCenterX, float *pCenterY, float *pCenterZ); - /** get the up vector values */ - void getUpXYZ(float *pUpX, float *pUpY, float *pUpZ); - public: - /** returns the Z eye */ - static float getZEye(); + /** sets the dirty value */ + inline void setDirty(bool bValue) { m_bDirty = bValue; } + /** get the dirty value */ + inline bool getDirty(void) { return m_bDirty; } - private: - DISALLOW_COPY_AND_ASSIGN(CCCamera); - }; + /** sets the camera in the default position */ + void restore(void); + /** Sets the camera using gluLookAt using its eye, center and up_vector */ + void locate(void); + /** sets the eye values in points */ + void setEyeXYZ(float fEyeX, float fEyeY, float fEyeZ); + /** sets the center values in points */ + void setCenterXYZ(float fCenterX, float fCenterY, float fCenterZ); + /** sets the up values */ + void setUpXYZ(float fUpX, float fUpY, float fUpZ); -}//namespace cocos2d + /** get the eye vector values in points */ + void getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ); + /** get the center vector values int points */ + void getCenterXYZ(float *pCenterX, float *pCenterY, float *pCenterZ); + /** get the up vector values */ + void getUpXYZ(float *pUpX, float *pUpY, float *pUpZ); +public: + /** returns the Z eye */ + static float getZEye(); + +private: + DISALLOW_COPY_AND_ASSIGN(CCCamera); +}; + +NS_CC_END #endif // __CCCAMERA_H__ diff --git a/cocos2dx/include/CCObject.h b/cocos2dx/include/CCObject.h index e65b533f2f..9d59d9375c 100755 --- a/cocos2dx/include/CCObject.h +++ b/cocos2dx/include/CCObject.h @@ -28,7 +28,8 @@ THE SOFTWARE. #include "CCCommon.h" #include "ccTypes.h" -namespace cocos2d { +NS_CC_BEGIN + class CCZone; class CCObject; class CCString; @@ -86,8 +87,7 @@ typedef void (CCObject::*SEL_EventHandler)(CCEvent*); #define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR) #define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR) #define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR) - - -}//namespace cocos2d + +NS_CC_END #endif // __COCOA_NSOBJECT_H__ diff --git a/cocos2dx/include/CCString.h b/cocos2dx/include/CCString.h index ee04d17f8e..9ee58daeaa 100755 --- a/cocos2dx/include/CCString.h +++ b/cocos2dx/include/CCString.h @@ -23,87 +23,105 @@ THE SOFTWARE. ****************************************************************************/ #ifndef __CCSTRING_H__ #define __CCSTRING_H__ + #include #include #include "CCObject.h" #include "CCFileUtils.h" -namespace cocos2d { +NS_CC_BEGIN - class CC_DLL CCString : public CCObject +class CC_DLL CCString : public CCObject +{ +public: + std::string m_sString; +public: + CCString() + :m_sString("") + {} + + CCString(const char * str) { - public: - std::string m_sString; - public: - CCString() - :m_sString("") - {} - CCString(const char * str) - { - m_sString = str; - } - virtual ~CCString(){ m_sString.clear(); } - - int toInt() - { - return atoi(m_sString.c_str()); - } - unsigned int toUInt() - { - return (unsigned int)atoi(m_sString.c_str()); - } - float toFloat() - { - return (float)atof(m_sString.c_str()); - } - std::string toStdString() - { - return m_sString; - } + m_sString = str; + } - const char* c_str() - { - return m_sString.c_str(); - } + virtual ~CCString() + { + m_sString.clear(); + } + + int toInt() + { + return atoi(m_sString.c_str()); + } - bool isEmpty() - { - return m_sString.empty(); - } + unsigned int toUInt() + { + return (unsigned int)atoi(m_sString.c_str()); + } - virtual bool isEqual(const CCObject* pObject) + float toFloat() + { + return (float)atof(m_sString.c_str()); + } + + std::string toStdString() + { + return m_sString; + } + + const char* c_str() + { + return m_sString.c_str(); + } + + bool isEmpty() + { + return m_sString.empty(); + } + + virtual CCObject* copyWithZone(CCZone* pZone) + { + CCAssert(pZone == NULL, "CCString should not be inherited."); + CCString* pStr = new CCString(m_sString.c_str()); + return pStr; + } + + virtual bool isEqual(const CCObject* pObject) + { + bool bRet = false; + const CCString* pStr = dynamic_cast(pObject); + if (pStr != NULL) { - bool bRet = false; - const CCString* pStr = dynamic_cast(pObject); - if (pStr != NULL) + if (0 == m_sString.compare(pStr->m_sString)) { - if (0 == m_sString.compare(pStr->m_sString)) - { - bRet = true; - } + bRet = true; } - return bRet; } + return bRet; + } - /** @brief: Get string from a file. - * @return: a pointer which needs to be deleted manually by 'delete[]' . - */ - static char* stringWithContentsOfFile(const char* pszFileName) + /** @brief: Get string from a file. + * @return: a pointer which needs to be deleted manually by 'delete[]' . + */ + static char* stringWithContentsOfFile(const char* pszFileName) + { + unsigned long size = 0; + unsigned char* pData = 0; + char* pszRet = 0; + pData = CCFileUtils::getFileData(pszFileName, "rb", &size); + do { - unsigned long size = 0; - unsigned char* pData = 0; - char* pszRet = 0; - pData = CCFileUtils::getFileData(pszFileName, "rb", &size); - do - { - CC_BREAK_IF(!pData || size <= 0); - pszRet = new char[size+1]; - pszRet[size] = '\0'; - memcpy(pszRet, pData, size); - CC_SAFE_DELETE_ARRAY(pData); - } while (false); - return pszRet; - } - }; -}// namespace cocos2d + CC_BREAK_IF(!pData || size <= 0); + pszRet = new char[size+1]; + pszRet[size] = '\0'; + memcpy(pszRet, pData, size); + CC_SAFE_DELETE_ARRAY(pData); + } while (false); + return pszRet; + } +}; + +NS_CC_END + #endif //__CCSTRING_H__ \ No newline at end of file diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index 1cedd5dc54..e4a472c5e0 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -301,11 +301,18 @@ void CCParticleSystemQuad::draw() glBindVertexArray( m_uVAOname ); + /* Application will crash in glDrawElements function on some win32 computers which use Integrated Graphics. + Indices should be bound again to avoid this bug. + */ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]); +#endif glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, 0); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +#endif glBindVertexArray( 0 ); @@ -414,7 +421,7 @@ bool CCParticleSystemQuad::allocMemory() m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc(m_uTotalParticles * sizeof(ccV3F_C4B_T2F_Quad)); m_pIndices = (GLushort*)malloc(m_uTotalParticles * 6 * sizeof(GLushort)); - + if( !m_pQuads || !m_pIndices) { CCLOG("cocos2d: Particle system: not enough memory"); @@ -423,6 +430,10 @@ bool CCParticleSystemQuad::allocMemory() return false; } + + memset(m_pQuads, 0, m_uTotalParticles * sizeof(ccV3F_C4B_T2F_Quad)); + memset(m_pIndices, 0, m_uTotalParticles * 6 * sizeof(GLushort)); + return true; } diff --git a/cocos2dx/support/CCArray.cpp b/cocos2dx/support/CCArray.cpp index 7b5ef42648..2dcaa76f16 100644 --- a/cocos2dx/support/CCArray.cpp +++ b/cocos2dx/support/CCArray.cpp @@ -336,12 +336,15 @@ void CCArray::replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool CCObject* CCArray::copyWithZone(CCZone* pZone) { + CCAssert(pZone == NULL, "CCArray should not be inherited."); CCArray* pArray = new CCArray(); + pArray->initWithCapacity(this->data->num > 0 ? this->data->num : 1); - if (!(pArray && pArray->initWithArray(this))) - { - CC_SAFE_DELETE(pArray); - } + CCObject* pObj = NULL; + CCARRAY_FOREACH(this, pObj) + { + pArray->addObject(pObj->copy()); + } return pArray; } diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 7670499cdb..3430cfaf2d 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -156,8 +156,9 @@ bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) ); m_pIndices = (GLushort *)malloc( m_uCapacity * 6 * sizeof(GLushort) ); - - if( ! ( m_pQuads && m_pIndices) && m_uCapacity > 0) { + + if( ! ( m_pQuads && m_pIndices) && m_uCapacity > 0) + { //CCLOG("cocos2d: CCTextureAtlas: not enough memory"); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); @@ -168,6 +169,9 @@ bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity return false; } + memset( m_pQuads, 0, m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) ); + memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) ); + this->setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO @@ -426,31 +430,49 @@ bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity) { return true; } + unsigned int uOldCapactiy = m_uCapacity; // update capacity and totolQuads m_uTotalQuads = MIN(m_uTotalQuads, newCapacity); m_uCapacity = newCapacity; - void * tmpQuads = NULL; - void * tmpIndices = NULL; + ccV3F_C4B_T2F_Quad* tmpQuads = NULL; + GLushort* tmpIndices = NULL; // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL, // so here must judge whether m_pQuads and m_pIndices is NULL. if (m_pQuads == NULL) { - tmpQuads = malloc(m_uCapacity * sizeof(m_pQuads[0])); + tmpQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(m_pQuads[0]) ); + if (tmpQuads != NULL) + { + memset(tmpQuads, 0, m_uCapacity * sizeof(m_pQuads[0]) ); + } } else { - tmpQuads = realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity ); + tmpQuads = (ccV3F_C4B_T2F_Quad*)realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity ); + if (tmpQuads != NULL && m_uCapacity > uOldCapactiy) + { + memset(tmpQuads+uOldCapactiy, 0, (m_uCapacity - uOldCapactiy)*sizeof(m_pQuads[0]) ); + } } if (m_pIndices == NULL) { - tmpIndices = malloc( m_uCapacity * 6 * sizeof(m_pIndices[0])); + tmpIndices = (GLushort*)malloc( m_uCapacity * 6 * sizeof(m_pIndices[0]) ); + if (tmpIndices != NULL) + { + memset( tmpIndices, 0, m_uCapacity * 6 * sizeof(m_pIndices[0]) ); + } + } else { - tmpIndices = realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 ); + tmpIndices = (GLushort*)realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 ); + if (tmpIndices != NULL && m_uCapacity > uOldCapactiy) + { + memset( tmpIndices+uOldCapactiy, 0, (m_uCapacity-uOldCapactiy) * 6 * sizeof(m_pIndices[0]) ); + } } if( ! ( tmpQuads && tmpIndices) ) { @@ -463,8 +485,8 @@ bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity) return false; } - m_pQuads = (ccV3F_C4B_T2F_Quad *)tmpQuads; - m_pIndices = (GLushort *)tmpIndices; + m_pQuads = tmpQuads; + m_pIndices = tmpIndices; setupIndices(); @@ -564,15 +586,24 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start) } glBindVertexArray( m_uVAOname ); + + /* Application will crash in glDrawElements function on some win32 computers which use Integrated Graphics. + Indices should be bound again to avoid this bug. + */ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]); - CHECK_GL_ERROR_DEBUG(); +#endif + #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); #else glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); #endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +#endif + glBindVertexArray(0); #else // ! CC_TEXTURE_ATLAS_USE_VAO @@ -601,8 +632,6 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start) // tex coords glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, texCoords)); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]); #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP @@ -611,6 +640,7 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start) glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); #endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); #endif // CC_TEXTURE_ATLAS_USE_VAO From 4baebb8cab664c237caa5456a3709ca90420e41f Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 8 Apr 2012 12:50:15 +0800 Subject: [PATCH 5/5] issue #1094: renamed CCPoolManager::getInstance() to CCPoolManager::sharedPoolManager(), and added CCPoolManager::purgePoolManager() method. Using pointer rather than global variable to make a singleton. fixed a memory leak in CCParticleSystem. --- cocos2dx/CCDirector.cpp | 17 ++++++++---- cocos2dx/cocoa/CCAutoreleasePool.cpp | 27 +++++++++++++------- cocos2dx/cocoa/CCObject.cpp | 4 +-- cocos2dx/include/CCAutoreleasePool.h | 3 ++- cocos2dx/particle_nodes/CCParticleSystem.cpp | 2 -- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index c8fd3d4af1..bb279f7a6c 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -76,6 +76,12 @@ extern const char* cocos2dVersion(void); CCDirector* CCDirector::sharedDirector(void) { +// static bool bFirst = true; +// if (bFirst) +// { +// bFirst = false; +// s_pSharedDirector.init(); +// } if (s_pSharedDirector == NULL) { s_pSharedDirector = new CCDisplayLinkDirector(); @@ -101,8 +107,8 @@ bool CCDirector::init(void) m_pNotificationNode = NULL; m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS; - m_pobScenesStack = CCArray::array(); - m_pobScenesStack->retain(); + m_pobScenesStack = new CCArray(); + m_pobScenesStack->init(); // Set default projection (3D) m_eProjection = kCCDirectorProjectionDefault; @@ -152,7 +158,7 @@ bool CCDirector::init(void) m_pAccelerometer = new CCAccelerometer(); // create autorelease pool - CCPoolManager::getInstance()->push(); + CCPoolManager::sharedPoolManager()->push(); return true; } @@ -175,7 +181,8 @@ CCDirector::~CCDirector(void) CC_SAFE_DELETE(m_pAccelerometer); // pop the autorelease pool - CCPoolManager::getInstance()->pop(); + CCPoolManager::sharedPoolManager()->pop(); + CCPoolManager::purgePoolManager(); // delete m_pLastUpdate CC_SAFE_DELETE(m_pLastUpdate); @@ -1015,7 +1022,7 @@ void CCDisplayLinkDirector::mainLoop(void) drawScene(); // release the objects - CCPoolManager::getInstance()->pop(); + CCPoolManager::sharedPoolManager()->pop(); } } diff --git a/cocos2dx/cocoa/CCAutoreleasePool.cpp b/cocos2dx/cocoa/CCAutoreleasePool.cpp index c4a8501fcd..246ec9d0a0 100644 --- a/cocos2dx/cocoa/CCAutoreleasePool.cpp +++ b/cocos2dx/cocoa/CCAutoreleasePool.cpp @@ -26,7 +26,7 @@ THE SOFTWARE. NS_CC_BEGIN -CCPoolManager g_PoolManager; +static CCPoolManager* s_pPoolManager = NULL; CCAutoreleasePool::CCAutoreleasePool(void) { @@ -87,9 +87,18 @@ void CCAutoreleasePool::clear() // //-------------------------------------------------------------------- -CCPoolManager* CCPoolManager::getInstance() +CCPoolManager* CCPoolManager::sharedPoolManager() { - return &g_PoolManager; + if (s_pPoolManager == NULL) + { + s_pPoolManager = new CCPoolManager(); + } + return s_pPoolManager; +} + +void CCPoolManager::purgePoolManager() +{ + CC_SAFE_DELETE(s_pPoolManager); } CCPoolManager::CCPoolManager() @@ -102,13 +111,13 @@ CCPoolManager::CCPoolManager() CCPoolManager::~CCPoolManager() { - finalize(); - - // we only release the last autorelease pool here + finalize(); + + // we only release the last autorelease pool here m_pCurReleasePool = 0; - m_pReleasePoolStack->removeObjectAtIndex(0); - - CC_SAFE_DELETE(m_pReleasePoolStack); + m_pReleasePoolStack->removeObjectAtIndex(0); + + CC_SAFE_DELETE(m_pReleasePoolStack); } void CCPoolManager::finalize() diff --git a/cocos2dx/cocoa/CCObject.cpp b/cocos2dx/cocoa/CCObject.cpp index 1aade9d140..7dec3b0a61 100644 --- a/cocos2dx/cocoa/CCObject.cpp +++ b/cocos2dx/cocoa/CCObject.cpp @@ -55,7 +55,7 @@ CCObject::~CCObject(void) // from pool manager if (m_bManaged) { - CCPoolManager::getInstance()->removeObject(this); + CCPoolManager::sharedPoolManager()->removeObject(this); } // if the object is referenced by Lua engine, remove it @@ -90,7 +90,7 @@ void CCObject::retain(void) CCObject* CCObject::autorelease(void) { - CCPoolManager::getInstance()->addObject(this); + CCPoolManager::sharedPoolManager()->addObject(this); m_bManaged = true; return this; diff --git a/cocos2dx/include/CCAutoreleasePool.h b/cocos2dx/include/CCAutoreleasePool.h index 69acb33529..4becac5791 100755 --- a/cocos2dx/include/CCAutoreleasePool.h +++ b/cocos2dx/include/CCAutoreleasePool.h @@ -58,7 +58,8 @@ public: void removeObject(CCObject* pObject); void addObject(CCObject* pObject); - static CCPoolManager* getInstance(); + static CCPoolManager* sharedPoolManager(); + static void purgePoolManager(); friend class CCAutoreleasePool; }; diff --git a/cocos2dx/particle_nodes/CCParticleSystem.cpp b/cocos2dx/particle_nodes/CCParticleSystem.cpp index 174ee11e27..8bbe235459 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystem.cpp @@ -325,8 +325,6 @@ bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary) } CCAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture"); - CC_BREAK_IF(!m_pTexture); - this->m_pTexture->retain(); } bRet = true; }