Merge pull request #829 from dumganhar/iss1094_gles20_particlebat

issue #1094: Make ParticleBatchNode works on win32 and fixed some issues as follows:
1. renamed CCPoolManager::getInstance() to CCPoolManager::sharedPoolManager(), and added CCPoolManager::purgePoolManager() method. Using pointer rather than global variable to make a singleton.
2.fixed a memory leak in CCParticleSystem.
3.init CCSprite::m_pobBatchNode at the beginning of CCSprite::initWithTexture.
4.Add CCAssert in ccArrayRemoveObjectAtIndex.
5.Use new method to allocate CCDirector.
This commit is contained in:
James Chen 2012-04-08 19:45:38 -07:00
commit 6cd69523c8
31 changed files with 688 additions and 585 deletions

View File

@ -69,21 +69,20 @@ NS_CC_BEGIN
// XXX it shoul be a Director ivar. Move it there once support for multiple directors is added // XXX it shoul be a Director ivar. Move it there once support for multiple directors is added
// singleton stuff // singleton stuff
static CCDisplayLinkDirector s_sharedDirector; static CCDisplayLinkDirector* s_pSharedDirector = NULL;
static bool s_bFirstRun = true;
#define kDefaultFPS 60 // 60 frames per second #define kDefaultFPS 60 // 60 frames per second
extern const char* cocos2dVersion(void); extern const char* cocos2dVersion(void);
CCDirector* CCDirector::sharedDirector(void) CCDirector* CCDirector::sharedDirector(void)
{ {
if (s_bFirstRun) if (s_pSharedDirector == NULL)
{ {
s_sharedDirector.init(); s_pSharedDirector = new CCDisplayLinkDirector();
s_bFirstRun = false; s_pSharedDirector->init();
} }
return &s_sharedDirector; return s_pSharedDirector;
} }
CCDirector::CCDirector(void) CCDirector::CCDirector(void)
@ -102,8 +101,8 @@ bool CCDirector::init(void)
m_pNotificationNode = NULL; m_pNotificationNode = NULL;
m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS; m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS;
m_pobScenesStack = CCArray::array(); m_pobScenesStack = new CCArray();
m_pobScenesStack->retain(); m_pobScenesStack->init();
// Set default projection (3D) // Set default projection (3D)
m_eProjection = kCCDirectorProjectionDefault; m_eProjection = kCCDirectorProjectionDefault;
@ -112,6 +111,9 @@ bool CCDirector::init(void)
m_pProjectionDelegate = NULL; m_pProjectionDelegate = NULL;
// FPS // FPS
m_fAccumDt = 0.0f;
m_fFrameRate = 0.0f;
m_pFPSLabel = NULL;
m_bDisplayFPS = false; m_bDisplayFPS = false;
m_uTotalFrames = m_uFrames = 0; m_uTotalFrames = m_uFrames = 0;
m_pszFPS = new char[10]; m_pszFPS = new char[10];
@ -150,14 +152,14 @@ bool CCDirector::init(void)
m_pAccelerometer = new CCAccelerometer(); m_pAccelerometer = new CCAccelerometer();
// create autorelease pool // create autorelease pool
CCPoolManager::getInstance()->push(); CCPoolManager::sharedPoolManager()->push();
return true; return true;
} }
CCDirector::~CCDirector(void) CCDirector::~CCDirector(void)
{ {
CCLOGINFO("cocos2d: deallocing %p", this); CCLOG("cocos2d: deallocing %p", this);
#if CC_DIRECTOR_FAST_FPS #if CC_DIRECTOR_FAST_FPS
CC_SAFE_RELEASE(m_pFPSLabel); CC_SAFE_RELEASE(m_pFPSLabel);
@ -171,8 +173,10 @@ CCDirector::~CCDirector(void)
CC_SAFE_RELEASE(m_pTouchDispatcher); CC_SAFE_RELEASE(m_pTouchDispatcher);
CC_SAFE_RELEASE(m_pKeypadDispatcher); CC_SAFE_RELEASE(m_pKeypadDispatcher);
CC_SAFE_DELETE(m_pAccelerometer); CC_SAFE_DELETE(m_pAccelerometer);
// pop the autorelease pool // pop the autorelease pool
CCPoolManager::getInstance()->pop(); CCPoolManager::sharedPoolManager()->pop();
CCPoolManager::purgePoolManager();
// delete m_pLastUpdate // delete m_pLastUpdate
CC_SAFE_DELETE(m_pLastUpdate); CC_SAFE_DELETE(m_pLastUpdate);
@ -236,10 +240,12 @@ void CCDirector::drawScene(void)
m_pNotificationNode->visit(); m_pNotificationNode->visit();
} }
#if CC_DIRECTOR_FAST_FPS == 1
if (m_bDisplayFPS) if (m_bDisplayFPS)
{ {
showFPS(); showFPS();
} }
#endif
#if CC_ENABLE_PROFILERS #if CC_ENABLE_PROFILERS
showProfilers(); showProfilers();
@ -667,6 +673,7 @@ void CCDirector::purgeDirector()
// OpenGL view // OpenGL view
m_pobOpenGLView->release(); m_pobOpenGLView->release();
m_pobOpenGLView = NULL; m_pobOpenGLView = NULL;
CC_SAFE_DELETE(s_pSharedDirector);
} }
void CCDirector::setNextScene(void) void CCDirector::setNextScene(void)
@ -1009,7 +1016,7 @@ void CCDisplayLinkDirector::mainLoop(void)
drawScene(); drawScene();
// release the objects // release the objects
CCPoolManager::getInstance()->pop(); CCPoolManager::sharedPoolManager()->pop();
} }
} }

View File

@ -27,13 +27,13 @@ THE SOFTWARE.
#include "CCAtlasNode.h" #include "CCAtlasNode.h"
#include "CCTextureAtlas.h" #include "CCTextureAtlas.h"
#include "CCDirector.h" #include "CCDirector.h"
#include "CCGLProgram.h" #include "CCGLProgram.h"
#include "CCShaderCache.h" #include "CCShaderCache.h"
#include "ccGLStateCache.h" #include "ccGLStateCache.h"
#include "CCDirector.h" #include "CCDirector.h"
#include "support/TransformUtils.h" #include "support/TransformUtils.h"
// external // external
#include "kazmath/GL/matrix.h" #include "kazmath/GL/matrix.h"
namespace cocos2d { namespace cocos2d {
@ -87,11 +87,11 @@ bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, uns
m_tBlendFunc.src = CC_BLEND_SRC; m_tBlendFunc.src = CC_BLEND_SRC;
m_tBlendFunc.dst = CC_BLEND_DST; m_tBlendFunc.dst = CC_BLEND_DST;
// double retain to avoid the autorelease pool CCTextureAtlas* pNewAtlas= new CCTextureAtlas();
// also, using: self.textureAtlas supports re-initialization without leaking pNewAtlas->initWithFile(tile, itemsToRender);
this->m_pTextureAtlas = new CCTextureAtlas(); setTextureAtlas(pNewAtlas);
m_pTextureAtlas->initWithFile(tile, itemsToRender); pNewAtlas->release();
if (! m_pTextureAtlas) if (! m_pTextureAtlas)
{ {
CCLOG("cocos2d: Could not initialize CCAtlasNode. Invalid Texture."); 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; m_uQuadsToDraw = itemsToRender;
// shader stuff // shader stuff
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor)); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color"); m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");
return true; return true;
@ -132,13 +132,13 @@ void CCAtlasNode::updateAtlasValues()
// CCAtlasNode - draw // CCAtlasNode - draw
void CCAtlasNode::draw(void) void CCAtlasNode::draw(void)
{ {
CC_NODE_DRAW_SETUP(); CC_NODE_DRAW_SETUP();
ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst ); ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
GLfloat colors[4] = {m_tColor.r / 255.0f, m_tColor.g / 255.0f, m_tColor.b / 255.0f, m_cOpacity / 255.0f}; GLfloat colors[4] = {m_tColor.r / 255.0f, m_tColor.g / 255.0f, m_tColor.b / 255.0f, m_cOpacity / 255.0f};
getShaderProgram()->setUniformLocationWith4fv(m_nUniformColor, colors, 1); getShaderProgram()->setUniformLocationWith4fv(m_nUniformColor, colors, 1);
m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0); m_pTextureAtlas->drawNumberOfQuads(m_uQuadsToDraw, 0);
} }
@ -234,6 +234,7 @@ void CCAtlasNode::setTextureAtlas(CCTextureAtlas* var)
CC_SAFE_RELEASE(m_pTextureAtlas); CC_SAFE_RELEASE(m_pTextureAtlas);
m_pTextureAtlas = var; m_pTextureAtlas = var;
} }
CCTextureAtlas * CCAtlasNode::getTextureAtlas() CCTextureAtlas * CCAtlasNode::getTextureAtlas()
{ {
return m_pTextureAtlas; return m_pTextureAtlas;

View File

@ -36,7 +36,7 @@ THE SOFTWARE.
#include "CCActionManager.h" #include "CCActionManager.h"
#include "CCScriptSupport.h" #include "CCScriptSupport.h"
#include "CCGLProgram.h" #include "CCGLProgram.h"
// externals // externals
#include "kazmath/GL/matrix.h" #include "kazmath/GL/matrix.h"
#if CC_NODE_RENDER_SUBPIXEL #if CC_NODE_RENDER_SUBPIXEL
@ -47,7 +47,7 @@ THE SOFTWARE.
namespace cocos2d { 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; static int s_globalOrderOfArrival = 1;
CCNode::CCNode(void) CCNode::CCNode(void)
@ -84,10 +84,10 @@ CCNode::CCNode(void)
, m_glServerState(CC_GL_BLEND) , m_glServerState(CC_GL_BLEND)
, m_bReorderChildDirty(false) , m_bReorderChildDirty(false)
{ {
// set default scheduler and actionManager // set default scheduler and actionManager
CCDirector *director = CCDirector::sharedDirector(); CCDirector *director = CCDirector::sharedDirector();
m_pActionManager = director->getActionManager(); m_pActionManager = director->getActionManager();
m_pActionManager->retain(); m_pActionManager->retain();
m_pScheduler = director->getScheduler(); m_pScheduler = director->getScheduler();
m_pScheduler->retain(); m_pScheduler->retain();
} }
@ -96,7 +96,7 @@ CCNode::~CCNode(void)
{ {
CCLOGINFO( "cocos2d: deallocing" ); CCLOGINFO( "cocos2d: deallocing" );
CC_SAFE_RELEASE(m_pActionManager); CC_SAFE_RELEASE(m_pActionManager);
CC_SAFE_RELEASE(m_pScheduler); CC_SAFE_RELEASE(m_pScheduler);
// attributes // attributes
CC_SAFE_RELEASE(m_pCamera); CC_SAFE_RELEASE(m_pCamera);
@ -162,8 +162,8 @@ void CCNode::_setZOrder(int z)
void CCNode::setZOrder(int z) void CCNode::setZOrder(int z)
{ {
_setZOrder(z); _setZOrder(z);
if (m_pParent) if (m_pParent)
{ {
m_pParent->reorderChild(this, z); m_pParent->reorderChild(this, z);
} }
} }
@ -429,7 +429,7 @@ void CCNode::setUserData(void *var)
CCRect CCNode::boundingBox() 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()); return CCRectApplyAffineTransform(rect, nodeToParentTransform());
} }
@ -637,34 +637,34 @@ void CCNode::reorderChild(CCNode *child, int zOrder)
child->_setZOrder(zOrder); child->_setZOrder(zOrder);
} }
void CCNode::sortAllChildren() void CCNode::sortAllChildren()
{ {
if (m_bReorderChildDirty) if (m_bReorderChildDirty)
{ {
int i,j,length = m_pChildren->data->num; int i,j,length = m_pChildren->data->num;
CCNode ** x = (CCNode**)m_pChildren->data->arr; CCNode ** x = (CCNode**)m_pChildren->data->arr;
CCNode *tempItem; CCNode *tempItem;
// insertion sort // insertion sort
for(i=1; i<length; i++) for(i=1; i<length; i++)
{ {
tempItem = x[i]; tempItem = x[i];
j = i-1; j = i-1;
//continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller //continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
while(j>=0 && ( tempItem->m_nZOrder < x[j]->m_nZOrder || ( tempItem->m_nZOrder== x[j]->m_nZOrder && tempItem->m_nOrderOfArrival < x[j]->m_nOrderOfArrival ) ) ) while(j>=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]; x[j+1] = x[j];
j = j-1; j = j-1;
} }
x[j+1] = tempItem; x[j+1] = tempItem;
} }
//don't need to check children recursively, that's done in visit of each child //don't need to check children recursively, that's done in visit of each child
m_bReorderChildDirty = false; m_bReorderChildDirty = false;
} }
} }
void CCNode::draw() void CCNode::draw()
@ -729,7 +729,7 @@ void CCNode::visit()
this->draw(); this->draw();
} }
// reset for next frame // reset for next frame
m_nOrderOfArrival = 0; m_nOrderOfArrival = 0;
if (m_pGrid && m_pGrid->isActive()) if (m_pGrid && m_pGrid->isActive())
@ -751,30 +751,30 @@ void CCNode::transformAncestors()
void CCNode::transform() void CCNode::transform()
{ {
kmMat4 transfrom4x4; kmMat4 transfrom4x4;
// Convert 3x3 into 4x4 matrix // Convert 3x3 into 4x4 matrix
CCAffineTransform tmpAffine = this->nodeToParentTransform(); CCAffineTransform tmpAffine = this->nodeToParentTransform();
CGAffineToGL(&tmpAffine, transfrom4x4.mat); CGAffineToGL(&tmpAffine, transfrom4x4.mat);
// Update Z vertex manually // Update Z vertex manually
transfrom4x4.mat[14] = m_fVertexZ; transfrom4x4.mat[14] = m_fVertexZ;
kmGLMultMatrix( &transfrom4x4 ); kmGLMultMatrix( &transfrom4x4 );
// XXX: Expensive calls. Camera should be integrated into the cached affine matrix // XXX: Expensive calls. Camera should be integrated into the cached affine matrix
if ( m_pCamera != NULL && !(m_pGrid != NULL && m_pGrid->isActive()) ) if ( m_pCamera != NULL && !(m_pGrid != NULL && m_pGrid->isActive()) )
{ {
bool translate = (m_tAnchorPointInPoints.x != 0.0f || m_tAnchorPointInPoints.y != 0.0f); bool translate = (m_tAnchorPointInPoints.x != 0.0f || m_tAnchorPointInPoints.y != 0.0f);
if( translate ) if( translate )
kmGLTranslatef(RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.y), 0 ); kmGLTranslatef(RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPoints.y), 0 );
m_pCamera->locate(); m_pCamera->locate();
if( translate ) if( translate )
kmGLTranslatef(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPoints.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPoints.y), 0 ); 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*); arrayMakeObjectsPerformSelector(m_pChildren, onEnterTransitionDidFinish, CCNode*);
} }
void CCNode::onExitTransitionDidStart() void CCNode::onExitTransitionDidStart()
{ {
arrayMakeObjectsPerformSelector(m_pChildren, onExitTransitionDidStart, CCNode*); arrayMakeObjectsPerformSelector(m_pChildren, onExitTransitionDidStart, CCNode*);
} }
void CCNode::onExit() void CCNode::onExit()
@ -835,19 +835,19 @@ void CCNode::unregisterScriptHandler(void)
} }
} }
void CCNode::setActionManager(CCActionManager* actionManager) void CCNode::setActionManager(CCActionManager* actionManager)
{ {
if( actionManager != m_pActionManager ) { if( actionManager != m_pActionManager ) {
this->stopAllActions(); this->stopAllActions();
CC_SAFE_RELEASE(m_pActionManager); CC_SAFE_RETAIN(actionManager);
CC_SAFE_RETAIN(actionManager); CC_SAFE_RELEASE(m_pActionManager);
m_pActionManager = actionManager; m_pActionManager = actionManager;
} }
} }
CCActionManager* CCNode::getActionManager() CCActionManager* CCNode::getActionManager()
{ {
return m_pActionManager; return m_pActionManager;
} }
CCAction * CCNode::runAction(CCAction* action) CCAction * CCNode::runAction(CCAction* action)
@ -886,20 +886,20 @@ unsigned int CCNode::numberOfRunningActions()
// CCNode - Callbacks // CCNode - Callbacks
void CCNode::setScheduler(CCScheduler* scheduler) void CCNode::setScheduler(CCScheduler* scheduler)
{ {
if( scheduler != m_pScheduler ) { if( scheduler != m_pScheduler ) {
this->unscheduleAllSelectors(); this->unscheduleAllSelectors();
CC_SAFE_RELEASE(m_pScheduler); CC_SAFE_RETAIN(scheduler);
CC_SAFE_RETAIN(scheduler); CC_SAFE_RELEASE(m_pScheduler);
m_pScheduler = scheduler; m_pScheduler = scheduler;
} }
} }
CCScheduler* CCNode::getScheduler() CCScheduler* CCNode::getScheduler()
{ {
return m_pScheduler; return m_pScheduler;
} }
void CCNode::scheduleUpdate() void CCNode::scheduleUpdate()
{ {
@ -921,9 +921,9 @@ void CCNode::schedule(SEL_SCHEDULE selector)
this->schedule(selector, 0.0f, kCCRepeatForever, 0.0f); this->schedule(selector, 0.0f, kCCRepeatForever, 0.0f);
} }
void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval) void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval)
{ {
this->schedule(selector, interval, kCCRepeatForever, 0.0f); this->schedule(selector, interval, kCCRepeatForever, 0.0f);
} }
void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval, unsigned int repeat, ccTime delay) 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); m_pScheduler->scheduleSelector(selector, this, interval, !m_bIsRunning, repeat, delay);
} }
void CCNode::scheduleOnce(SEL_SCHEDULE selector, ccTime delay) void CCNode::scheduleOnce(SEL_SCHEDULE selector, ccTime delay)
{ {
this->schedule(selector, 0.0f, 0, delay); this->schedule(selector, 0.0f, 0, delay);
} }
void CCNode::unschedule(SEL_SCHEDULE selector) void CCNode::unschedule(SEL_SCHEDULE selector)
@ -967,57 +967,57 @@ void CCNode::pauseSchedulerAndActions()
CCAffineTransform CCNode::nodeToParentTransform(void) CCAffineTransform CCNode::nodeToParentTransform(void)
{ {
if ( m_bIsTransformDirty ) { if ( m_bIsTransformDirty ) {
// Translate values // Translate values
float x = m_tPosition.x; float x = m_tPosition.x;
float y = m_tPosition.y; float y = m_tPosition.y;
if ( !m_bIsRelativeAnchorPoint ) { if ( !m_bIsRelativeAnchorPoint ) {
x += m_tAnchorPointInPoints.x; x += m_tAnchorPointInPoints.x;
y += m_tAnchorPointInPoints.y; y += m_tAnchorPointInPoints.y;
} }
// Rotation values // Rotation values
float c = 1, s = 0; float c = 1, s = 0;
if( m_fRotation ) { if( m_fRotation ) {
float radians = -CC_DEGREES_TO_RADIANS(m_fRotation); float radians = -CC_DEGREES_TO_RADIANS(m_fRotation);
c = cosf(radians); c = cosf(radians);
s = sinf(radians); s = sinf(radians);
} }
bool needsSkewMatrix = ( m_fSkewX || m_fSkewY ); bool needsSkewMatrix = ( m_fSkewX || m_fSkewY );
// optimization: // optimization:
// inline anchor point calculation if skew is not needed // inline anchor point calculation if skew is not needed
if( !needsSkewMatrix && !CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) { if( !needsSkewMatrix && !CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) {
x += c * -m_tAnchorPointInPoints.x * m_fScaleX + -s * -m_tAnchorPointInPoints.y * m_fScaleY; 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; y += s * -m_tAnchorPointInPoints.x * m_fScaleX + c * -m_tAnchorPointInPoints.y * m_fScaleY;
} }
// Build Transform Matrix // Build Transform Matrix
m_tTransform = CCAffineTransformMake( c * m_fScaleX, s * m_fScaleX, m_tTransform = CCAffineTransformMake( c * m_fScaleX, s * m_fScaleX,
-s * m_fScaleY, c * m_fScaleY, -s * m_fScaleY, c * m_fScaleY,
x, y ); x, y );
// XXX: Try to inline skew // XXX: Try to inline skew
// If skew is needed, apply skew and then anchor point // If skew is needed, apply skew and then anchor point
if( needsSkewMatrix ) { if( needsSkewMatrix ) {
CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), CCAffineTransform skewMatrix = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)),
tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f,
0.0f, 0.0f ); 0.0f, 0.0f );
m_tTransform = CCAffineTransformConcat(skewMatrix, m_tTransform); m_tTransform = CCAffineTransformConcat(skewMatrix, m_tTransform);
// adjust anchor point // adjust anchor point
if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ) if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) )
m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPoints.x, -m_tAnchorPointInPoints.y); m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPoints.x, -m_tAnchorPointInPoints.y);
} }
m_bIsTransformDirty = false; m_bIsTransformDirty = false;
} }
return m_tTransform; return m_tTransform;
} }

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
NS_CC_BEGIN NS_CC_BEGIN
CCPoolManager g_PoolManager; static CCPoolManager* s_pPoolManager = NULL;
CCAutoreleasePool::CCAutoreleasePool(void) 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() CCPoolManager::CCPoolManager()
@ -102,13 +111,13 @@ CCPoolManager::CCPoolManager()
CCPoolManager::~CCPoolManager() CCPoolManager::~CCPoolManager()
{ {
finalize(); finalize();
// we only release the last autorelease pool here // we only release the last autorelease pool here
m_pCurReleasePool = 0; m_pCurReleasePool = 0;
m_pReleasePoolStack->removeObjectAtIndex(0); m_pReleasePoolStack->removeObjectAtIndex(0);
CC_SAFE_DELETE(m_pReleasePoolStack); CC_SAFE_DELETE(m_pReleasePoolStack);
} }
void CCPoolManager::finalize() void CCPoolManager::finalize()

View File

@ -220,6 +220,7 @@ void CCDictionary::removeAllObjects()
CCObject* CCDictionary::copyWithZone(CCZone* pZone) CCObject* CCDictionary::copyWithZone(CCZone* pZone)
{ {
CCAssert(pZone == NULL, "CCDirctionary should not be inherited.");
CCDictionary* pNewDict = new CCDictionary(); CCDictionary* pNewDict = new CCDictionary();
CCDictElement* pElement = NULL; CCDictElement* pElement = NULL;
@ -227,14 +228,14 @@ CCObject* CCDictionary::copyWithZone(CCZone* pZone)
{ {
CCDICT_FOREACH(this, pElement) CCDICT_FOREACH(this, pElement)
{ {
pNewDict->setObject(pElement->getObject(), pElement->getIntKey()); pNewDict->setObject(pElement->getObject()->copy(), pElement->getIntKey());
} }
} }
else if (m_eDictType == kCCDictStr) else if (m_eDictType == kCCDictStr)
{ {
CCDICT_FOREACH(this, pElement) CCDICT_FOREACH(this, pElement)
{ {
pNewDict->setObject(pElement->getObject(), pElement->getStrKey()); pNewDict->setObject(pElement->getObject()->copy(), pElement->getStrKey());
} }
} }

View File

@ -28,7 +28,7 @@ THE SOFTWARE.
#include "ccMacros.h" #include "ccMacros.h"
#include "CCScriptSupport.h" #include "CCScriptSupport.h"
namespace cocos2d { NS_CC_BEGIN
CCObject* CCCopying::copyWithZone(CCZone *pZone) CCObject* CCCopying::copyWithZone(CCZone *pZone)
{ {
@ -55,7 +55,7 @@ CCObject::~CCObject(void)
// from pool manager // from pool manager
if (m_bManaged) if (m_bManaged)
{ {
CCPoolManager::getInstance()->removeObject(this); CCPoolManager::sharedPoolManager()->removeObject(this);
} }
// if the object is referenced by Lua engine, remove it // if the object is referenced by Lua engine, remove it
@ -90,7 +90,7 @@ void CCObject::retain(void)
CCObject* CCObject::autorelease(void) CCObject* CCObject::autorelease(void)
{ {
CCPoolManager::getInstance()->addObject(this); CCPoolManager::sharedPoolManager()->addObject(this);
m_bManaged = true; m_bManaged = true;
return this; return this;
@ -111,4 +111,4 @@ bool CCObject::isEqual(const CCObject *pObject)
return this == pObject; return this == pObject;
} }
}//namespace cocos2d NS_CC_END

View File

@ -58,7 +58,8 @@ public:
void removeObject(CCObject* pObject); void removeObject(CCObject* pObject);
void addObject(CCObject* pObject); void addObject(CCObject* pObject);
static CCPoolManager* getInstance(); static CCPoolManager* sharedPoolManager();
static void purgePoolManager();
friend class CCAutoreleasePool; friend class CCAutoreleasePool;
}; };

View File

@ -31,84 +31,86 @@ THE SOFTWARE.
#include "ccMacros.h" #include "ccMacros.h"
#include <string> #include <string>
#include "kazmath/mat4.h" #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 NS_CC_BEGIN
position attributes, then they will override 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. 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) IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both.
using the camera. 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.
*/ - It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object.
class CC_DLL CCCamera : public CCObject
{
protected:
float m_fEyeX;
float m_fEyeY;
float m_fEyeZ;
float m_fCenterX; - 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_fCenterY;
float m_fCenterZ;
float m_fUpX; */
float m_fUpY; class CC_DLL CCCamera : public CCObject
float m_fUpZ; {
protected:
float m_fEyeX;
float m_fEyeY;
float m_fEyeZ;
bool m_bDirty; float m_fCenterX;
kmMat4 m_lookupMatrix; float m_fCenterY;
public: float m_fCenterZ;
CCCamera(void);
~CCCamera(void);
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 */ void init(void);
inline void setDirty(bool bValue) { m_bDirty = bValue; }
/** get the dirty value */
inline bool getDirty(void) { return m_bDirty; }
/** sets the camera in the default position */ char * description(void);
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);
/** get the eye vector values in points */ /** sets the dirty value */
void getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ); inline void setDirty(bool bValue) { m_bDirty = bValue; }
/** get the center vector values int points */ /** get the dirty value */
void getCenterXYZ(float *pCenterX, float *pCenterY, float *pCenterZ); inline bool getDirty(void) { return m_bDirty; }
/** get the up vector values */
void getUpXYZ(float *pUpX, float *pUpY, float *pUpZ);
public:
/** returns the Z eye */
static float getZEye();
private: /** sets the camera in the default position */
DISALLOW_COPY_AND_ASSIGN(CCCamera); 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__ #endif // __CCCAMERA_H__

View File

@ -28,7 +28,8 @@ THE SOFTWARE.
#include "CCCommon.h" #include "CCCommon.h"
#include "ccTypes.h" #include "ccTypes.h"
namespace cocos2d { NS_CC_BEGIN
class CCZone; class CCZone;
class CCObject; class CCObject;
class CCString; class CCString;
@ -86,8 +87,7 @@ typedef void (CCObject::*SEL_EventHandler)(CCEvent*);
#define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR) #define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR)
#define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR) #define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR)
#define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR) #define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR)
NS_CC_END
}//namespace cocos2d
#endif // __COCOA_NSOBJECT_H__ #endif // __COCOA_NSOBJECT_H__

View File

@ -23,87 +23,105 @@ THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#ifndef __CCSTRING_H__ #ifndef __CCSTRING_H__
#define __CCSTRING_H__ #define __CCSTRING_H__
#include <string> #include <string>
#include <stdlib.h> #include <stdlib.h>
#include "CCObject.h" #include "CCObject.h"
#include "CCFileUtils.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: m_sString = str;
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;
}
const char* c_str() virtual ~CCString()
{ {
return m_sString.c_str(); m_sString.clear();
} }
int toInt()
{
return atoi(m_sString.c_str());
}
bool isEmpty() unsigned int toUInt()
{ {
return m_sString.empty(); 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<const CCString*>(pObject);
if (pStr != NULL)
{ {
bool bRet = false; if (0 == m_sString.compare(pStr->m_sString))
const CCString* pStr = dynamic_cast<const CCString*>(pObject);
if (pStr != NULL)
{ {
if (0 == m_sString.compare(pStr->m_sString)) bRet = true;
{
bRet = true;
}
} }
return bRet;
} }
return bRet;
}
/** @brief: Get string from a file. /** @brief: Get string from a file.
* @return: a pointer which needs to be deleted manually by 'delete[]' . * @return: a pointer which needs to be deleted manually by 'delete[]' .
*/ */
static char* stringWithContentsOfFile(const char* pszFileName) 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; CC_BREAK_IF(!pData || size <= 0);
unsigned char* pData = 0; pszRet = new char[size+1];
char* pszRet = 0; pszRet[size] = '\0';
pData = CCFileUtils::getFileData(pszFileName, "rb", &size); memcpy(pszRet, pData, size);
do CC_SAFE_DELETE_ARRAY(pData);
{ } while (false);
CC_BREAK_IF(!pData || size <= 0); return pszRet;
pszRet = new char[size+1]; }
pszRet[size] = '\0'; };
memcpy(pszRet, pData, size);
CC_SAFE_DELETE_ARRAY(pData); NS_CC_END
} while (false);
return pszRet;
}
};
}// namespace cocos2d
#endif //__CCSTRING_H__ #endif //__CCSTRING_H__

View File

@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef KAZMATH_AABB_H_INCLUDED #ifndef KAZMATH_AABB_H_INCLUDED
#define KAZMATH_AABB_H_INCLUDED #define KAZMATH_AABB_H_INCLUDED
#include "CCPlatformMacros.h"
#include "vec3.h" #include "vec3.h"
#include "utility.h" #include "utility.h"
@ -42,9 +43,9 @@ typedef struct kmAABB {
kmVec3 max; /** The min corner of the box */ kmVec3 max; /** The min corner of the box */
} kmAABB; } kmAABB;
const int kmAABBContainsPoint(const kmVec3* pPoint, const kmAABB* pBox); CC_DLL const int kmAABBContainsPoint(const kmVec3* pPoint, const kmAABB* pBox);
kmAABB* const kmAABBAssign(kmAABB* pOut, const kmAABB* pIn); CC_DLL kmAABB* const kmAABBAssign(kmAABB* pOut, const kmAABB* pIn);
kmAABB* const kmAABBScale(kmAABB* pOut, const kmAABB* pIn, kmScalar s); CC_DLL kmAABB* const kmAABBScale(kmAABB* pOut, const kmAABB* pIn, kmScalar s);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef MAT3_H_INCLUDED #ifndef MAT3_H_INCLUDED
#define MAT3_H_INCLUDED #define MAT3_H_INCLUDED
#include "CCPlatformMacros.h"
#include "utility.h" #include "utility.h"
struct kmVec3; struct kmVec3;
@ -40,33 +41,33 @@ typedef struct kmMat3{
extern "C" { extern "C" {
#endif #endif
kmMat3* const kmMat3Fill(kmMat3* pOut, const kmScalar* pMat); CC_DLL kmMat3* const kmMat3Fill(kmMat3* pOut, const kmScalar* pMat);
kmMat3* const kmMat3Adjugate(kmMat3* pOut, const kmMat3* pIn); CC_DLL kmMat3* const kmMat3Adjugate(kmMat3* pOut, const kmMat3* pIn);
kmMat3* const kmMat3Identity(kmMat3* pOut); CC_DLL kmMat3* const kmMat3Identity(kmMat3* pOut);
kmMat3* const kmMat3Inverse(kmMat3* pOut, const kmScalar pDeterminate, const kmMat3* pM); CC_DLL kmMat3* const kmMat3Inverse(kmMat3* pOut, const kmScalar pDeterminate, const kmMat3* pM);
const int kmMat3IsIdentity(const kmMat3* pIn); CC_DLL const int kmMat3IsIdentity(const kmMat3* pIn);
kmMat3* const kmMat3Transpose(kmMat3* pOut, const kmMat3* pIn); CC_DLL kmMat3* const kmMat3Transpose(kmMat3* pOut, const kmMat3* pIn);
const kmScalar kmMat3Determinant(const kmMat3* pIn); CC_DLL const kmScalar kmMat3Determinant(const kmMat3* pIn);
kmMat3* const kmMat3Multiply(kmMat3* pOut, const kmMat3* pM1, const kmMat3* pM2); CC_DLL 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 kmMat3ScalarMultiply(kmMat3* pOut, const kmMat3* pM, const kmScalar pFactor);
kmMat3* const kmMat3RotationAxisAngle(kmMat3* pOut, const struct kmVec3* axis, kmScalar radians); CC_DLL 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 struct kmVec3* const kmMat3RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat3* pIn);
kmMat3* const kmMat3Assign(kmMat3* pOut, const kmMat3* pIn); CC_DLL kmMat3* const kmMat3Assign(kmMat3* pOut, const kmMat3* pIn);
const int kmMat3AreEqual(const kmMat3* pM1, const kmMat3* pM2); CC_DLL const int kmMat3AreEqual(const kmMat3* pM1, const kmMat3* pM2);
kmMat3* const kmMat3RotationX(kmMat3* pOut, const kmScalar radians); CC_DLL kmMat3* const kmMat3RotationX(kmMat3* pOut, const kmScalar radians);
kmMat3* const kmMat3RotationY(kmMat3* pOut, const kmScalar radians); CC_DLL kmMat3* const kmMat3RotationY(kmMat3* pOut, const kmScalar radians);
kmMat3* const kmMat3RotationZ(kmMat3* pOut, const kmScalar radians); CC_DLL kmMat3* const kmMat3RotationZ(kmMat3* pOut, const kmScalar radians);
kmMat3* const kmMat3Rotation(kmMat3* pOut, const kmScalar radians); CC_DLL kmMat3* const kmMat3Rotation(kmMat3* pOut, const kmScalar radians);
kmMat3* const kmMat3Scaling(kmMat3* pOut, const kmScalar x, const kmScalar y); CC_DLL 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 kmMat3Translation(kmMat3* pOut, const kmScalar x, const kmScalar y);
kmMat3* const kmMat3RotationQuaternion(kmMat3* pOut, const struct kmQuaternion* pIn); CC_DLL kmMat3* const kmMat3RotationQuaternion(kmMat3* pOut, const struct kmQuaternion* pIn);
kmMat3* const kmMat3RotationAxisAngle(kmMat3* pOut, const struct kmVec3* axis, kmScalar radians); CC_DLL 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 struct kmVec3* const kmMat3RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat3* pIn);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef MAT4_H_INCLUDED #ifndef MAT4_H_INCLUDED
#define MAT4_H_INCLUDED #define MAT4_H_INCLUDED
#include "CCPlatformMacros.h"
#include "utility.h" #include "utility.h"
struct kmVec3; struct kmVec3;
@ -50,43 +51,43 @@ typedef struct kmMat4 {
kmScalar mat[16]; kmScalar mat[16];
} kmMat4; } 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); CC_DLL kmMat4* const kmMat4Transpose(kmMat4* pOut, const kmMat4* pIn);
kmMat4* const kmMat4Multiply(kmMat4* pOut, const kmMat4* pM1, const kmMat4* pM2); CC_DLL kmMat4* const kmMat4Multiply(kmMat4* pOut, const kmMat4* pM1, const kmMat4* pM2);
kmMat4* const kmMat4Assign(kmMat4* pOut, const kmMat4* pIn); CC_DLL kmMat4* const kmMat4Assign(kmMat4* pOut, const kmMat4* pIn);
const int kmMat4AreEqual(const kmMat4* pM1, const kmMat4* pM2); CC_DLL const int kmMat4AreEqual(const kmMat4* pM1, const kmMat4* pM2);
kmMat4* const kmMat4RotationX(kmMat4* pOut, const kmScalar radians); CC_DLL kmMat4* const kmMat4RotationX(kmMat4* pOut, const kmScalar radians);
kmMat4* const kmMat4RotationY(kmMat4* pOut, const kmScalar radians); CC_DLL kmMat4* const kmMat4RotationY(kmMat4* pOut, const kmScalar radians);
kmMat4* const kmMat4RotationZ(kmMat4* pOut, const kmScalar radians); CC_DLL kmMat4* const kmMat4RotationZ(kmMat4* pOut, const kmScalar radians);
kmMat4* const kmMat4RotationPitchYawRoll(kmMat4* pOut, const kmScalar pitch, const kmScalar yaw, const kmScalar roll); CC_DLL kmMat4* const kmMat4RotationPitchYawRoll(kmMat4* pOut, const kmScalar pitch, const kmScalar yaw, const kmScalar roll);
kmMat4* const kmMat4RotationQuaternion(kmMat4* pOut, const struct kmQuaternion* pQ); CC_DLL kmMat4* const kmMat4RotationQuaternion(kmMat4* pOut, const struct kmQuaternion* pQ);
kmMat4* const kmMat4RotationTranslation(kmMat4* pOut, const struct kmMat3* rotation, const struct kmVec3* translation); CC_DLL 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); CC_DLL 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 kmMat4Translation(kmMat4* pOut, const kmScalar x, const kmScalar y, const kmScalar z);
struct kmVec3* const kmMat4GetUpVec3(struct kmVec3* pOut, const kmMat4* pIn); CC_DLL struct kmVec3* const kmMat4GetUpVec3(struct kmVec3* pOut, const kmMat4* pIn);
struct kmVec3* const kmMat4GetRightVec3(struct kmVec3* pOut, const kmMat4* pIn); CC_DLL 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 kmMat4GetForwardVec3(struct kmVec3* pOut, const kmMat4* pIn);
kmMat4* const kmMat4PerspectiveProjection(kmMat4* pOut, kmScalar fovY, kmScalar aspect, kmScalar zNear, kmScalar zFar); CC_DLL 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); CC_DLL 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 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); CC_DLL kmMat4* const kmMat4RotationAxisAngle(kmMat4* pOut, const struct kmVec3* axis, kmScalar radians);
struct kmMat3* const kmMat4ExtractRotation(struct kmMat3* pOut, const kmMat4* pIn); CC_DLL struct kmMat3* const kmMat4ExtractRotation(struct kmMat3* pOut, const kmMat4* pIn);
struct kmPlane* const kmMat4ExtractPlane(struct kmPlane* pOut, const kmMat4* pIn, const kmEnum plane); CC_DLL 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 struct kmVec3* const kmMat4RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat4* pIn);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define KM_PLANE_NEAR 4 #define KM_PLANE_NEAR 4
#define KM_PLANE_FAR 5 #define KM_PLANE_FAR 5
#include "CCPlatformMacros.h"
#include "utility.h" #include "utility.h"
struct kmVec3; struct kmVec3;
@ -53,15 +54,15 @@ typedef enum POINT_CLASSIFICATION {
POINT_ON_PLANE, POINT_ON_PLANE,
} POINT_CLASSIFICATION; } POINT_CLASSIFICATION;
const kmScalar kmPlaneDot(const kmPlane* pP, const struct kmVec4* pV); CC_DLL const kmScalar kmPlaneDot(const kmPlane* pP, const struct kmVec4* pV);
const kmScalar kmPlaneDotCoord(const kmPlane* pP, const struct kmVec3* pV); CC_DLL const kmScalar kmPlaneDotCoord(const kmPlane* pP, const struct kmVec3* pV);
const kmScalar kmPlaneDotNormal(const kmPlane* pP, const struct kmVec3* pV); CC_DLL const kmScalar kmPlaneDotNormal(const kmPlane* pP, const struct kmVec3* pV);
kmPlane* const kmPlaneFromPointNormal(kmPlane* pOut, const struct kmVec3* pPoint, const struct kmVec3* pNormal); CC_DLL 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); CC_DLL 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); CC_DLL 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); CC_DLL kmPlane* const kmPlaneNormalize(kmPlane* pOut, const kmPlane* pP);
kmPlane* const kmPlaneScale(kmPlane* pOut, const kmPlane* pP, kmScalar s); CC_DLL 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 POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3* pP); /** Classifys a point against a plane */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern "C" { extern "C" {
#endif #endif
#include "CCPlatformMacros.h"
#include "utility.h" #include "utility.h"
struct kmMat4; struct kmMat4;
@ -43,68 +44,68 @@ typedef struct kmQuaternion {
kmScalar w; kmScalar w;
} kmQuaternion; } 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 ///< Makes the passed quaternion an identity quaternion
kmQuaternion* kmQuaternionIdentity(kmQuaternion* pOut); CC_DLL kmQuaternion* kmQuaternionIdentity(kmQuaternion* pOut);
///< Returns the inverse of the passed Quaternion ///< Returns the inverse of the passed Quaternion
kmQuaternion* kmQuaternionInverse(kmQuaternion* pOut, CC_DLL kmQuaternion* kmQuaternionInverse(kmQuaternion* pOut,
const kmQuaternion* pIn); const kmQuaternion* pIn);
///< Returns true if the quaternion is an identity quaternion ///< 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 ///< 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) ///< 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 ///< Returns the natural logarithm
kmQuaternion* kmQuaternionLn(kmQuaternion* pOut, const kmQuaternion* pIn); CC_DLL kmQuaternion* kmQuaternionLn(kmQuaternion* pOut, const kmQuaternion* pIn);
///< Multiplies 2 quaternions together ///< 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 ///< 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 ///< 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 ///< 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 ///< 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 ///< 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 ///< 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 ///< Scale a quaternion
kmQuaternion* kmQuaternionScale(kmQuaternion* pOut, const kmQuaternion* pIn, kmScalar s); CC_DLL kmQuaternion* kmQuaternionScale(kmQuaternion* pOut, const kmQuaternion* pIn, kmScalar s);
kmQuaternion* kmQuaternionAssign(kmQuaternion* pOut, const kmQuaternion* pIn); CC_DLL kmQuaternion* kmQuaternionAssign(kmQuaternion* pOut, const kmQuaternion* pIn);
kmQuaternion* kmQuaternionAdd(kmQuaternion* pOut, const kmQuaternion* pQ1, const kmQuaternion* pQ2); CC_DLL 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); CC_DLL 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 struct kmVec3* kmQuaternionMultiplyVec3(struct kmVec3* pOut, const kmQuaternion* q, const struct kmVec3* v);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef RAY_2_H #ifndef RAY_2_H
#define RAY_2_H #define RAY_2_H
#include "CCPlatformMacros.h"
#include "utility.h" #include "utility.h"
#include "vec2.h" #include "vec2.h"
@ -38,10 +39,10 @@ typedef struct kmRay2 {
kmVec2 dir; kmVec2 dir;
} kmRay2; } kmRay2;
void kmRay2Fill(kmRay2* ray, kmScalar px, kmScalar py, kmScalar vx, kmScalar vy); CC_DLL 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); CC_DLL 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); CC_DLL 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 kmBool kmRay2IntersectCircle(const kmRay2* ray, const kmVec2 centre, const kmScalar radius, kmVec2* intersection);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UTILITY_H_INCLUDED #ifndef UTILITY_H_INCLUDED
#define UTILITY_H_INCLUDED #define UTILITY_H_INCLUDED
#include "CCPlatformMacros.h"
#include <math.h> #include <math.h>
#ifndef kmScalar #ifndef kmScalar
@ -59,13 +60,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern "C" { extern "C" {
#endif #endif
extern kmScalar kmSQR(kmScalar s); CC_DLL kmScalar kmSQR(kmScalar s);
extern kmScalar kmDegreesToRadians(kmScalar degrees); CC_DLL kmScalar kmDegreesToRadians(kmScalar degrees);
extern kmScalar kmRadiansToDegrees(kmScalar radians); CC_DLL kmScalar kmRadiansToDegrees(kmScalar radians);
extern kmScalar kmMin(kmScalar lhs, kmScalar rhs); CC_DLL kmScalar kmMin(kmScalar lhs, kmScalar rhs);
extern kmScalar kmMax(kmScalar lhs, kmScalar rhs); CC_DLL kmScalar kmMax(kmScalar lhs, kmScalar rhs);
extern kmBool kmAlmostEqual(kmScalar lhs, kmScalar rhs); CC_DLL kmBool kmAlmostEqual(kmScalar lhs, kmScalar rhs);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VEC2_H_INCLUDED #ifndef VEC2_H_INCLUDED
#define VEC2_H_INCLUDED #define VEC2_H_INCLUDED
#include "CCPlatformMacros.h"
struct kmMat3; struct kmMat3;
#ifndef kmScalar #ifndef kmScalar
@ -44,17 +46,17 @@ typedef struct kmVec2 {
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
kmVec2* kmVec2Fill(kmVec2* pOut, kmScalar x, kmScalar y); CC_DLL kmVec2* kmVec2Fill(kmVec2* pOut, kmScalar x, kmScalar y);
kmScalar kmVec2Length(const kmVec2* pIn); ///< Returns the length of the vector CC_DLL 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 CC_DLL 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 CC_DLL 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 CC_DLL 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 */ CC_DLL 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 CC_DLL 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 */ CC_DLL 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); ///<Transforms a 2D vector by a given matrix, projecting the result back into w = 1. CC_DLL kmVec2* kmVec2TransformCoord(kmVec2* pOut, const kmVec2* pV, const struct kmMat3* pM); ///<Transforms a 2D vector by a given matrix, projecting the result back into w = 1.
kmVec2* kmVec2Scale(kmVec2* pOut, const kmVec2* pIn, const kmScalar s); ///< Scales a vector to length s CC_DLL kmVec2* kmVec2Scale(kmVec2* pOut, const kmVec2* pIn, const kmScalar s); ///< Scales a vector to length s
int kmVec2AreEqual(const kmVec2* p1, const kmVec2* p2); ///< Returns 1 if both vectors are equal CC_DLL int kmVec2AreEqual(const kmVec2* p1, const kmVec2* p2); ///< Returns 1 if both vectors are equal
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VEC3_H_INCLUDED #ifndef VEC3_H_INCLUDED
#define VEC3_H_INCLUDED #define VEC3_H_INCLUDED
#include "CCPlatformMacros.h"
#include <assert.h> #include <assert.h>
#ifndef kmScalar #ifndef kmScalar
@ -44,23 +45,23 @@ typedef struct kmVec3 {
extern "C" { extern "C" {
#endif #endif
kmVec3* kmVec3Fill(kmVec3* pOut, kmScalar x, kmScalar y, kmScalar z); CC_DLL kmVec3* kmVec3Fill(kmVec3* pOut, kmScalar x, kmScalar y, kmScalar z);
kmScalar kmVec3Length(const kmVec3* pIn); /** Returns the length of the vector */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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 */ CC_DLL 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. */ 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. */
kmVec3* kmVec3Scale(kmVec3* pOut, const kmVec3* pIn, const kmScalar s); /** Scales a vector to length s */ CC_DLL kmVec3* kmVec3Scale(kmVec3* pOut, const kmVec3* pIn, const kmScalar s); /** Scales a vector to length s */
int kmVec3AreEqual(const kmVec3* p1, const kmVec3* p2); CC_DLL int kmVec3AreEqual(const kmVec3* p1, const kmVec3* p2);
kmVec3* kmVec3InverseTransform(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM); CC_DLL kmVec3* kmVec3InverseTransform(kmVec3* pOut, const kmVec3* pV, const struct kmMat4* pM);
kmVec3* kmVec3InverseTransformNormal(kmVec3* pOut, const kmVec3* pVect, const struct kmMat4* pM); CC_DLL kmVec3* kmVec3InverseTransformNormal(kmVec3* pOut, const kmVec3* pVect, const struct kmMat4* pM);
kmVec3* kmVec3Assign(kmVec3* pOut, const kmVec3* pIn); CC_DLL kmVec3* kmVec3Assign(kmVec3* pOut, const kmVec3* pIn);
kmVec3* kmVec3Zero(kmVec3* pOut); CC_DLL kmVec3* kmVec3Zero(kmVec3* pOut);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef VEC4_H_INCLUDED #ifndef VEC4_H_INCLUDED
#define VEC4_H_INCLUDED #define VEC4_H_INCLUDED
#include "CCPlatformMacros.h"
#include "utility.h" #include "utility.h"
struct kmMat4; struct kmMat4;
@ -46,20 +47,20 @@ typedef struct kmVec4 {
extern "C" { extern "C" {
#endif #endif
kmVec4* kmVec4Fill(kmVec4* pOut, kmScalar x, kmScalar y, kmScalar z, kmScalar w); CC_DLL kmVec4* kmVec4Fill(kmVec4* pOut, kmScalar x, kmScalar y, kmScalar z, kmScalar w);
kmVec4* kmVec4Add(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2); CC_DLL kmVec4* kmVec4Add(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2);
kmScalar kmVec4Dot(const kmVec4* pV1, const kmVec4* pV2); CC_DLL kmScalar kmVec4Dot(const kmVec4* pV1, const kmVec4* pV2);
kmScalar kmVec4Length(const kmVec4* pIn); CC_DLL kmScalar kmVec4Length(const kmVec4* pIn);
kmScalar kmVec4LengthSq(const kmVec4* pIn); CC_DLL kmScalar kmVec4LengthSq(const kmVec4* pIn);
kmVec4* kmVec4Lerp(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2, kmScalar t); CC_DLL kmVec4* kmVec4Lerp(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2, kmScalar t);
kmVec4* kmVec4Normalize(kmVec4* pOut, const kmVec4* pIn); CC_DLL kmVec4* kmVec4Normalize(kmVec4* pOut, const kmVec4* pIn);
kmVec4* kmVec4Scale(kmVec4* pOut, const kmVec4* pIn, const kmScalar s); ///< Scales a vector to length s CC_DLL 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); CC_DLL kmVec4* kmVec4Subtract(kmVec4* pOut, const kmVec4* pV1, const kmVec4* pV2);
kmVec4* kmVec4Transform(kmVec4* pOut, const kmVec4* pV, const struct kmMat4* pM); CC_DLL kmVec4* kmVec4Transform(kmVec4* pOut, const kmVec4* pV, const struct kmMat4* pM);
kmVec4* kmVec4TransformArray(kmVec4* pOut, unsigned int outStride, CC_DLL kmVec4* kmVec4TransformArray(kmVec4* pOut, unsigned int outStride,
const kmVec4* pV, unsigned int vStride, const struct kmMat4* pM, unsigned int count); const kmVec4* pV, unsigned int vStride, const struct kmMat4* pM, unsigned int count);
int kmVec4AreEqual(const kmVec4* p1, const kmVec4* p2); CC_DLL int kmVec4AreEqual(const kmVec4* p1, const kmVec4* p2);
kmVec4* kmVec4Assign(kmVec4* pOut, const kmVec4* pIn); CC_DLL kmVec4* kmVec4Assign(kmVec4* pOut, const kmVec4* pIn);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -481,7 +481,9 @@ void CCParticleBatchNode::insertChild(CCParticleSystem* pSystem, unsigned int in
// make room for quads, not necessary for last child // make room for quads, not necessary for last child
if (pSystem->getAtlasIndex() + pSystem->getTotalParticles() != m_pTextureAtlas->getTotalQuads()) if (pSystem->getAtlasIndex() + pSystem->getTotalParticles() != m_pTextureAtlas->getTotalQuads())
{
m_pTextureAtlas->moveQuadsFromIndex(index, index+pSystem->getTotalParticles()); m_pTextureAtlas->moveQuadsFromIndex(index, index+pSystem->getTotalParticles());
}
// increase totalParticles here for new particles, update method of particlesystem will fill the quads // increase totalParticles here for new particles, update method of particlesystem will fill the quads
m_pTextureAtlas->increaseTotalQuadsWith(pSystem->getTotalParticles()); m_pTextureAtlas->increaseTotalQuadsWith(pSystem->getTotalParticles());

View File

@ -325,8 +325,6 @@ bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary)
} }
CCAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture"); CCAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture");
CC_BREAK_IF(!m_pTexture);
this->m_pTexture->retain();
} }
bRet = true; bRet = true;
} }

View File

@ -301,8 +301,19 @@ void CCParticleSystemQuad::draw()
glBindVertexArray( m_uVAOname ); 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); 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 ); glBindVertexArray( 0 );
CC_INCREMENT_GL_DRAWS(1); CC_INCREMENT_GL_DRAWS(1);
@ -410,7 +421,7 @@ bool CCParticleSystemQuad::allocMemory()
m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc(m_uTotalParticles * sizeof(ccV3F_C4B_T2F_Quad)); m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc(m_uTotalParticles * sizeof(ccV3F_C4B_T2F_Quad));
m_pIndices = (GLushort*)malloc(m_uTotalParticles * 6 * sizeof(GLushort)); m_pIndices = (GLushort*)malloc(m_uTotalParticles * 6 * sizeof(GLushort));
if( !m_pQuads || !m_pIndices) if( !m_pQuads || !m_pIndices)
{ {
CCLOG("cocos2d: Particle system: not enough memory"); CCLOG("cocos2d: Particle system: not enough memory");
@ -419,6 +430,10 @@ bool CCParticleSystemQuad::allocMemory()
return false; return false;
} }
memset(m_pQuads, 0, m_uTotalParticles * sizeof(ccV3F_C4B_T2F_Quad));
memset(m_pIndices, 0, m_uTotalParticles * 6 * sizeof(GLushort));
return true; return true;
} }

View File

@ -151,6 +151,7 @@ namespace cocos2d
CCAccelerometer::CCAccelerometer() : CCAccelerometer::CCAccelerometer() :
m_pAccelDelegate(NULL) m_pAccelDelegate(NULL)
{ {
memset(&m_obAccelerationValue, 0, sizeof(m_obAccelerationValue));
} }
CCAccelerometer::~CCAccelerometer() CCAccelerometer::~CCAccelerometer()

View File

@ -38,8 +38,8 @@ public:
void setDelegate(CCAccelerometerDelegate* pDelegate); void setDelegate(CCAccelerometerDelegate* pDelegate);
void update( double x,double y,double z,double timestamp ); void update( double x,double y,double z,double timestamp );
private: private:
CCAcceleration m_obAccelerationValue;
CCAccelerometerDelegate* m_pAccelDelegate; CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_obAccelerationValue;
}; };
}//namespace cocos2d }//namespace cocos2d

View File

@ -159,6 +159,7 @@ bool CCSprite::init(void)
// designated initializer // designated initializer
bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated) bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated)
{ {
m_pobBatchNode = NULL;
// shader program // shader program
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); 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.src = CC_BLEND_SRC;
m_sBlendFunc.dst = CC_BLEND_DST; m_sBlendFunc.dst = CC_BLEND_DST;
m_bFlipX = m_bFlipY = false; m_bFlipX = m_bFlipY = false;
// default transform anchor: center // default transform anchor: center
@ -182,8 +182,7 @@ bool CCSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool r
m_obOffsetPosition = CCPointZero; m_obOffsetPosition = CCPointZero;
m_bHasChildren = false; m_bHasChildren = false;
m_pobBatchNode = NULL;
// clean the Quad // clean the Quad
memset(&m_sQuad, 0, sizeof(m_sQuad)); memset(&m_sQuad, 0, sizeof(m_sQuad));

View File

@ -336,12 +336,15 @@ void CCArray::replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool
CCObject* CCArray::copyWithZone(CCZone* pZone) CCObject* CCArray::copyWithZone(CCZone* pZone)
{ {
CCAssert(pZone == NULL, "CCArray should not be inherited.");
CCArray* pArray = new CCArray(); CCArray* pArray = new CCArray();
pArray->initWithCapacity(this->data->num > 0 ? this->data->num : 1);
if (!(pArray && pArray->initWithArray(this))) CCObject* pObj = NULL;
{ CCARRAY_FOREACH(this, pObj)
CC_SAFE_DELETE(pArray); {
} pArray->addObject(pObj->copy());
}
return pArray; return pArray;
} }

View File

@ -225,18 +225,19 @@ static inline void ccArrayRemoveAllObjects(ccArray *arr)
Behaviour undefined if index outside [0, num-1]. */ Behaviour undefined if index outside [0, num-1]. */
static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj) static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj)
{ {
if (bReleaseObj) CCAssert(arr && arr->num > 0 && index < arr->num, "Invalid index. Out of bounds");
{ if (bReleaseObj)
arr->arr[index]->release(); {
} arr->arr[index]->release();
}
arr->num--;
unsigned int remaining = arr->num - index; arr->num--;
if (remaining > 0)
{ unsigned int remaining = arr->num - index;
memmove(&arr->arr[index], &arr->arr[index+1], remaining * sizeof(void*)); 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, /** Removes object at specified index and fills the gap with the last object,

View File

@ -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_pQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) );
m_pIndices = (GLushort *)malloc( m_uCapacity * 6 * sizeof(GLushort) ); 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"); //CCLOG("cocos2d: CCTextureAtlas: not enough memory");
CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pQuads);
CC_SAFE_FREE(m_pIndices); CC_SAFE_FREE(m_pIndices);
@ -168,6 +169,9 @@ bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity
return false; return false;
} }
memset( m_pQuads, 0, m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) );
memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) );
this->setupIndices(); this->setupIndices();
#if CC_TEXTURE_ATLAS_USE_VAO #if CC_TEXTURE_ATLAS_USE_VAO
@ -426,31 +430,49 @@ bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity)
{ {
return true; return true;
} }
unsigned int uOldCapactiy = m_uCapacity;
// update capacity and totolQuads // update capacity and totolQuads
m_uTotalQuads = MIN(m_uTotalQuads, newCapacity); m_uTotalQuads = MIN(m_uTotalQuads, newCapacity);
m_uCapacity = newCapacity; m_uCapacity = newCapacity;
void * tmpQuads = NULL; ccV3F_C4B_T2F_Quad* tmpQuads = NULL;
void * tmpIndices = NULL; GLushort* tmpIndices = NULL;
// when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return 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. // so here must judge whether m_pQuads and m_pIndices is NULL.
if (m_pQuads == 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 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) 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 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) ) { if( ! ( tmpQuads && tmpIndices) ) {
@ -463,8 +485,8 @@ bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity)
return false; return false;
} }
m_pQuads = (ccV3F_C4B_T2F_Quad *)tmpQuads; m_pQuads = tmpQuads;
m_pIndices = (GLushort *)tmpIndices; m_pIndices = tmpIndices;
setupIndices(); setupIndices();
@ -486,8 +508,9 @@ void CCTextureAtlas::moveQuadsFromIndex(unsigned int oldIndex, unsigned int amou
CCAssert(oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index"); CCAssert(oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
if( oldIndex == newIndex ) if( oldIndex == newIndex )
{
return; return;
}
//create buffer //create buffer
size_t quadSize = sizeof(ccV3F_C4B_T2F_Quad); size_t quadSize = sizeof(ccV3F_C4B_T2F_Quad);
ccV3F_C4B_T2F_Quad* tempQuads = (ccV3F_C4B_T2F_Quad*)malloc( quadSize * amount); ccV3F_C4B_T2F_Quad* tempQuads = (ccV3F_C4B_T2F_Quad*)malloc( quadSize * amount);
@ -519,12 +542,13 @@ void CCTextureAtlas::moveQuadsFromIndex(unsigned int index, unsigned int newInde
void CCTextureAtlas::fillWithEmptyQuadsFromIndex(unsigned int index, unsigned int amount) 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; unsigned int to = index + amount;
for (int i = index ; i < to ; i++) for (int i = index ; i < to ; i++)
{ {
m_pQuads[i] = *quad; m_pQuads[i] = quad;
} }
} }
@ -552,11 +576,10 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
// //
// XXX: update is done in draw... perhaps it should be done in a timer // 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]); glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] ); glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*start, sizeof(m_pQuads[0]) * n , &m_pQuads[start] );
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
m_bDirty = false; m_bDirty = false;
@ -564,12 +587,22 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
glBindVertexArray( m_uVAOname ); 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
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
#else #else
glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) ); glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP #endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif
glBindVertexArray(0); glBindVertexArray(0);
@ -599,8 +632,6 @@ void CCTextureAtlas::drawNumberOfQuads(unsigned int n, unsigned int start)
// tex coords // tex coords
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, texCoords)); 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]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
@ -609,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])) ); glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(m_pIndices[0])) );
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP #endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif // CC_TEXTURE_ATLAS_USE_VAO #endif // CC_TEXTURE_ATLAS_USE_VAO

View File

@ -1095,13 +1095,13 @@ ParticleDemo::ParticleDemo(void)
item4->setPosition( CCPointMake( 0, 100) ); item4->setPosition( CCPointMake( 0, 100) );
item4->setAnchorPoint( CCPointMake(0,0) ); item4->setAnchorPoint( CCPointMake(0,0) );
addChild( menu, 100 ); addChild( menu, 100 );
CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.'); CCLabelAtlas* labelAtlas = CCLabelAtlas::labelWithString("0000", "fonts/fps_images.png", 16, 24, '.');
addChild(labelAtlas, 100, kTagParticleCount); addChild(labelAtlas, 100, kTagParticleCount);
labelAtlas->setPosition( CCPointMake(s.width-66,50) ); labelAtlas->setPosition(CCPointMake(s.width-66,50));
// moving background // moving background
m_background = CCSprite::spriteWithFile(s_back3); m_background = CCSprite::spriteWithFile(s_back3);
addChild(m_background, 5); addChild(m_background, 5);
m_background->setPosition( CCPointMake(s.width/2, s.height-180) ); m_background->setPosition( CCPointMake(s.width/2, s.height-180) );
@ -1170,10 +1170,10 @@ void ParticleDemo::update(ccTime dt)
{ {
if (m_emitter) if (m_emitter)
{ {
CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount); CCLabelAtlas* atlas = (CCLabelAtlas*)getChildByTag(kTagParticleCount);
char str[5] = {0}; char str[5] = {0};
sprintf(str, "%04d", m_emitter->getParticleCount()); sprintf(str, "%04d", m_emitter->getParticleCount());
atlas->setString(str); atlas->setString(str);
} }
} }
@ -1241,24 +1241,24 @@ void ParticleBatchHybrid::onEnter()
addChild(batch, 10); addChild(batch, 10);
schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f); schedule(schedule_selector(ParticleBatchHybrid::switchRender), 2.0f);
CCNode *node = CCNode::node(); CCNode *node = CCNode::node();
addChild(node); addChild(node);
m_pParent1 = batch; m_pParent1 = batch;
m_pParent2 = node; m_pParent2 = node;
} }
void ParticleBatchHybrid::switchRender(ccTime dt) void ParticleBatchHybrid::switchRender(ccTime dt)
{ {
bool usingBatch = ( m_emitter->getBatchNode() != NULL ); bool usingBatch = ( m_emitter->getBatchNode() != NULL );
m_emitter->removeFromParentAndCleanup(false); m_emitter->removeFromParentAndCleanup(false);
CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 ); CCNode *newParent = (usingBatch ? m_pParent2 : m_pParent1 );
newParent->addChild(m_emitter); newParent->addChild(m_emitter);
CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode"); CCLog("Particle: Using new parent: %s", usingBatch ? "CCNode" : "CCParticleBatchNode");
} }
std::string ParticleBatchHybrid::title() std::string ParticleBatchHybrid::title()
@ -1324,11 +1324,13 @@ void ParticleReorder::onEnter()
removeChild(m_background, true); removeChild(m_background, true);
m_background = NULL; m_background = NULL;
CCParticleSystem *ignore = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); CCParticleSystem* ignore = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist");
CCNode *parent1 = CCNode::node(); CCNode *parent1 = CCNode::node();
CCNode *parent2 = CCParticleBatchNode::batchNodeWithTexture(ignore->getTexture()); CCNode *parent2 = CCParticleBatchNode::batchNodeWithTexture(ignore->getTexture());
ignore->unscheduleUpdate();
for( unsigned int i=0; i<2;i++) { for( unsigned int i=0; i<2;i++)
{
CCNode *parent = ( i==0 ? parent1 : parent2 ); CCNode *parent = ( i==0 ? parent1 : parent2 );
CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist"); CCParticleSystemQuad *emitter1 = CCParticleSystemQuad::particleWithFile("Images/SmallSun.plist");

View File

@ -1,28 +1,28 @@
#ifndef _PARTICLE_TEST_H_ #ifndef _PARTICLE_TEST_H_
#define _PARTICLE_TEST_H_ #define _PARTICLE_TEST_H_
#include "../testBasic.h" #include "../testBasic.h"
////----#include "cocos2d.h" ////----#include "cocos2d.h"
// #include "touch_dispatcher/CCTouch.h" // #include "touch_dispatcher/CCTouch.h"
// #include "CCParticleExample.h" // #include "CCParticleExample.h"
class ParticleTestScene : public TestScene class ParticleTestScene : public TestScene
{ {
public: public:
virtual void runThisTest(); virtual void runThisTest();
}; };
class ParticleDemo : public CCLayerColor class ParticleDemo : public CCLayerColor
{ {
protected: protected:
CCParticleSystem* m_emitter; CCParticleSystem* m_emitter;
CCSprite* m_background; CCSprite* m_background;
public: public:
ParticleDemo(void); ParticleDemo(void);
~ParticleDemo(void); ~ParticleDemo(void);
virtual void onEnter(void); virtual void onEnter(void);
virtual std::string title(); virtual std::string title();
@ -152,19 +152,19 @@ public:
virtual std::string title(); virtual std::string title();
}; };
class DemoParticleFromFile : public ParticleDemo class DemoParticleFromFile : public ParticleDemo
{ {
public: public:
std::string m_title; std::string m_title;
DemoParticleFromFile(const char *file) DemoParticleFromFile(const char *file)
{ {
m_title = file; m_title = file;
} }
virtual void onEnter(); virtual void onEnter();
virtual std::string title() virtual std::string title()
{ {
return m_title; return m_title;
} }
}; };
class RadiusMode1 : public ParticleDemo class RadiusMode1 : public ParticleDemo
@ -173,22 +173,22 @@ public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title(); virtual std::string title();
}; };
class RadiusMode2 : public ParticleDemo class RadiusMode2 : public ParticleDemo
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title(); virtual std::string title();
}; };
class Issue704 : public ParticleDemo class Issue704 : public ParticleDemo
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
}; };
class Issue870 : public ParticleDemo class Issue870 : public ParticleDemo
{ {
public: public:
@ -199,16 +199,16 @@ public:
private: private:
int m_nIndex; int m_nIndex;
}; };
class Issue1201 : public ParticleDemo class Issue1201 : public ParticleDemo
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
}; };
class ParticleBatchHybrid : public ParticleDemo class ParticleBatchHybrid : public ParticleDemo
{ {
public: public:
@ -217,18 +217,18 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
private: private:
CCNode* m_pParent1; CCNode* m_pParent1;
CCNode* m_pParent2; CCNode* m_pParent2;
}; };
class ParticleBatchMultipleEmitters : public ParticleDemo class ParticleBatchMultipleEmitters : public ParticleDemo
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
}; };
class ParticleReorder : public ParticleDemo class ParticleReorder : public ParticleDemo
{ {
public: public:
@ -238,8 +238,8 @@ public:
virtual std::string subtitle(); virtual std::string subtitle();
private: private:
unsigned int m_nOrder; unsigned int m_nOrder;
}; };
class MultipleParticleSystems : public ParticleDemo class MultipleParticleSystems : public ParticleDemo
{ {
public: public:
@ -247,8 +247,8 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual void update(ccTime dt); virtual void update(ccTime dt);
}; };
class MultipleParticleSystemsBatched : public ParticleDemo class MultipleParticleSystemsBatched : public ParticleDemo
{ {
public: public:
@ -258,8 +258,8 @@ public:
virtual std::string subtitle(); virtual std::string subtitle();
private: private:
CCParticleBatchNode* m_pBatchNode; CCParticleBatchNode* m_pBatchNode;
}; };
class AddAndDeleteParticleSystems : public ParticleDemo class AddAndDeleteParticleSystems : public ParticleDemo
{ {
public: public:
@ -270,8 +270,8 @@ public:
virtual std::string subtitle(); virtual std::string subtitle();
private: private:
CCParticleBatchNode* m_pBatchNode; CCParticleBatchNode* m_pBatchNode;
}; };
class ReorderParticleSystems : public ParticleDemo class ReorderParticleSystems : public ParticleDemo
{ {
public: public:
@ -282,6 +282,6 @@ public:
virtual std::string subtitle(); virtual std::string subtitle();
private: private:
CCParticleBatchNode* m_pBatchNode; CCParticleBatchNode* m_pBatchNode;
}; };
#endif #endif