Merge pull request #807 from dumganhar/gles20

issue #1056: Updated SpriteTest.
This commit is contained in:
James Chen 2012-03-23 02:33:26 -07:00
commit 98ba5ef203
10 changed files with 592 additions and 585 deletions

View File

@ -39,7 +39,7 @@ THE SOFTWARE.
// externals
#include "kazmath/GL/matrix.h"
#if CC_COCOSNODE_RENDER_SUBPIXEL
#if CC_NODE_RENDER_SUBPIXEL
#define RENDER_IN_SUBPIXEL
#else
#define RENDER_IN_SUBPIXEL (int)

View File

@ -44,22 +44,23 @@ __arr__++)
I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin
*/
#define CCARRAY_FOREACH(__array__, __object__) \
if (__array__ && __array__->data->num > 0) \
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; \
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
if ((__array__) && (__array__)->data->num > 0) \
for(CCObject** arr = (__array__)->data->arr, **end = (__array__)->data->arr + (__array__)->data->num-1; \
arr <= end && (((__object__) = *arr) != NULL/* || true*/); \
arr++)
#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \
if (__array__ && __array__->data->num > 0) \
for(CCObject** arr = __array__->data->arr + __array__->data->num-1, **end = __array__->data->arr; \
arr >= end && ((__object__ = *arr) != NULL/* || true*/); \
if ((__array__) && (__array__)->data->num > 0) \
for(CCObject** arr = (__array__)->data->arr + (__array__)->data->num-1, **end = (__array__)->data->arr; \
arr >= end && (((__object__) = *arr) != NULL/* || true*/); \
arr--)
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
#define CCARRAY_VERIFY_TYPE(__array__, __type__) \
do { \
if (__array__ && __array__->data->num > 0) \
for(CCObject** arr = __array__->data->arr, **end = __array__->data->arr + __array__->data->num-1; arr <= end; arr++) \
if ((__array__) && (__array__)->data->num > 0) \
for(CCObject** arr = (__array__)->data->arr, \
**end = (__array__)->data->arr + (__array__)->data->num-1; arr <= end; arr++) \
CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \
} while(false)
#else

View File

@ -36,34 +36,35 @@
#include "CCGLProgram.h"
#include "kazmath/kazmath.h"
namespace cocos2d {
class CCCamera;
class CCGridBase;
class CCPoint;
class CCTouch;
class CCAction;
class CCRGBAProtocol;
class CCLabelProtocol;
class CCScheduler;
class CCActionManager;
NS_CC_BEGIN
enum {
class CCCamera;
class CCGridBase;
class CCPoint;
class CCTouch;
class CCAction;
class CCRGBAProtocol;
class CCLabelProtocol;
class CCScheduler;
class CCActionManager;
enum {
kCCNodeTagInvalid = -1,
};
};
enum {
enum {
kCCNodeOnEnter,
kCCNodeOnExit
};
};
#define arrayMakeObjectsPerformSelectorWithType(pArray, func, type) \
#define arrayMakeObjectsPerformSelectorWithType(pArray, func, elementType) \
do { \
if(pArray && pArray->count() > 0) \
{ \
CCObject* child; \
CCARRAY_FOREACH(pArray, child) \
{ \
type* pNode = (type*) child; \
elementType pNode = (elementType) child; \
if(pNode && (0 != func)) \
{ \
(pNode->*func)(); \
@ -73,8 +74,24 @@ do { \
} \
while(false)
#define arrayMakeObjectsPerformSelectorWithObject(pArray, func, pObject, elementType) \
do { \
if(pArray && pArray->count() > 0) \
{ \
CCObject* child = NULL; \
CCARRAY_FOREACH(pArray, child) \
{ \
elementType pNode = (elementType) child; \
if(pNode && (0 != func)) \
{ \
(pNode->*func)(pObject); \
} \
} \
} \
} \
while(false)
/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
/** @brief CCNode is the main element. Anything thats gets drawn or contains things that get drawn is a CCNode.
The most popular CCNodes are: CCScene, CCLayer, CCSprite, CCMenu.
The main features of a CCNode are:
@ -129,8 +146,8 @@ while(false)
- Each node has a camera. By default it points to the center of the CCNode.
*/
class CC_DLL CCNode : public CCObject
{
class CC_DLL CCNode : public CCObject
{
// variable property
@ -281,7 +298,7 @@ while(false)
*/
CC_PROPERTY(CCScheduler*, m_pScheduler, Scheduler);
protected:
protected:
// transform
CCAffineTransform m_tTransform, m_tInverse;
@ -295,8 +312,7 @@ while(false)
bool m_bReorderChildDirty;
int m_nScriptHandler;
private:
private:
//! lazy allocs
void childrenAlloc(void);
@ -315,7 +331,7 @@ while(false)
CCPoint convertToWindowSpace(const CCPoint& nodePoint);
public:
public:
CCNode(void);
@ -618,8 +634,9 @@ while(false)
@since v0.7.1
*/
CCPoint convertTouchToNodeSpaceAR(CCTouch * touch);
};
}//namespace cocos2d
};
NS_CC_END
#endif // __PLATFOMR_CCNODE_H__

View File

@ -155,6 +155,9 @@ public:
*/
static CCSprite* spriteWithFile(const char *pszFileName, const CCRect& rect);
/** Creates an sprite.
*/
static CCSprite* node();
public:
CCSprite(void);
virtual ~CCSprite(void);
@ -213,74 +216,74 @@ public:
The rect used will be the size of the texture.
The offset will be (0,0).
*/
bool initWithTexture(CCTexture2D *pTexture);
virtual bool initWithTexture(CCTexture2D *pTexture);
/** Initializes an sprite with a texture and a rect.
The offset will be (0,0).
*/
bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect);
virtual bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect);
/** Initializes an sprite with a texture and a rect in points, optionally rotated.
The offset will be (0,0).
IMPORTANT: This is the designated initializer.
*/
bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated);
virtual bool initWithTexture(CCTexture2D *pTexture, const CCRect& rect, bool rotated);
// Initializes an sprite with an sprite frame.
bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
virtual bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
/** Initializes an sprite with an sprite frame name.
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
If the CCSpriteFrame doesn't exist it will raise an exception.
@since v0.9
*/
bool initWithSpriteFrameName(const char *pszSpriteFrameName);
virtual bool initWithSpriteFrameName(const char *pszSpriteFrameName);
/** Initializes an sprite with an image filename.
The rect used will be the size of the image.
The offset will be (0,0).
*/
bool initWithFile(const char *pszFilename);
virtual bool initWithFile(const char *pszFilename);
/** Initializes an sprite with an image filename, and a rect.
The offset will be (0,0).
*/
bool initWithFile(const char *pszFilename, const CCRect& rect);
virtual bool initWithFile(const char *pszFilename, const CCRect& rect);
// BatchNode methods
/** updates the quad according the the rotation, position, scale values. */
void updateTransform(void);
virtual void updateTransform(void);
/** updates the texture rect of the CCSprite in points.
It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size.
*/
void setTextureRect(const CCRect& rect);
virtual void setTextureRect(const CCRect& rect);
/** set the texture rect, rectRotated and untrimmed size of the CCSprite in points.
It will update the texture coordinates and the vertex rectangle.
*/
void setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize);
virtual void setTextureRect(const CCRect& rect, bool rotated, const CCSize& untrimmedSize);
/** set the vertex rect.
It will be called internally by setTextureRect. Useful if you want to create 2x images from SD images in Retina Display.
Do not call it manually. Use setTextureRect instead.
*/
void setVertexRect(const CCRect& rect);
virtual void setVertexRect(const CCRect& rect);
// Frames
/** sets a new display frame to the CCSprite. */
void setDisplayFrame(CCSpriteFrame *pNewFrame);
virtual void setDisplayFrame(CCSpriteFrame *pNewFrame);
/** returns whether or not a CCSpriteFrame is being displayed */
bool isFrameDisplayed(CCSpriteFrame *pFrame);
virtual bool isFrameDisplayed(CCSpriteFrame *pFrame);
/** returns the current displayed frame. */
CCSpriteFrame* displayFrame(void);
virtual CCSpriteFrame* displayFrame(void);
CCSpriteBatchNode* getBatchNode(void);
void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
virtual CCSpriteBatchNode* getBatchNode(void);
virtual void setBatchNode(CCSpriteBatchNode *pobSpriteBatchNode);
// Animation
@ -288,7 +291,7 @@ public:
The animation name will be get from the CCAnimationCache
@since v0.99.5
*/
void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
virtual void setDisplayFrameWithAnimationName(const char *animationName, int frameIndex);
protected:
virtual void setTextureCoords(CCRect rect);

View File

@ -216,8 +216,6 @@ void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
if( properties )
{
version = atoi(valueForKey("format", properties));
}
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
CCObject* pObj = NULL;
@ -226,6 +224,7 @@ void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
CCString* name = (CCString*)(pObj);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
}
}
switch (version) {
case 1:

View File

@ -137,6 +137,20 @@ CCSprite* CCSprite::spriteWithSpriteFrameName(const char *pszSpriteFrameName)
return spriteWithSpriteFrame(pFrame);
}
CCSprite* CCSprite::node()
{
CCSprite *pSprite = new CCSprite();
if (pSprite && pSprite->init())
{
pSprite->autorelease();
}
else
{
CC_SAFE_DELETE(pSprite);
}
return pSprite;
}
bool CCSprite::init(void)
{
return initWithTexture(NULL, CCRectZero);
@ -505,7 +519,7 @@ void CCSprite::updateTransform(void)
// recursively iterate over children
if( m_bHasChildren ) {
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite);
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite*);
}
#if CC_SPRITE_DEBUG_DRAW
// draw bounding box
@ -701,7 +715,7 @@ void CCSprite::sortAllChildren()
if ( m_pobBatchNode)
{
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite);
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite*);
}
m_bReorderChildDirty = false;

View File

@ -98,10 +98,12 @@ bool CCSpriteBatchNode::initWithTexture(CCTexture2D *tex, unsigned int capacity)
updateBlendFunc();
// no lazy alloc in this node
m_pChildren = CCArray::array();
m_pobDescendants = CCArray::array();
m_pChildren->retain();
m_pobDescendants->retain();
m_pChildren = new CCArray();
m_pChildren->initWithCapacity(capacity);
m_pobDescendants = new CCArray();
m_pobDescendants->initWithCapacity(capacity);
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
return true;
}
@ -169,10 +171,10 @@ void CCSpriteBatchNode::visit(void)
void CCSpriteBatchNode::addChild(CCNode *child, int zOrder, int tag)
{
CCAssert(child != NULL, "child should not be null");
CCAssert(dynamic_cast<CCSprite*>(child) != NULL, "CCSpriteBatchNode only supports CCSprites as children");
CCSprite *pSprite = (CCSprite*)(child);
// check CCSprite is using the same texture id
CCAssert(pSprite->getTexture()->getName() == m_pobTextureAtlas->getTexture()->getName(), "");
CCAssert(pSprite->getTexture()->getName() == m_pobTextureAtlas->getTexture()->getName(), "CCSprite is not using the same texture id");
CCNode::addChild(child, zOrder, tag);
@ -231,18 +233,7 @@ void CCSpriteBatchNode::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup)
void CCSpriteBatchNode::removeAllChildrenWithCleanup(bool bCleanup)
{
// Invalidate atlas index. issue #569
if (m_pChildren && m_pChildren->count() > 0)
{
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
removeSpriteFromAtlas(pChild);
}
}
}
arrayMakeObjectsPerformSelectorWithObject(m_pobDescendants, &CCSprite::setBatchNode, NULL, CCSprite*);
CCNode::removeAllChildrenWithCleanup(bCleanup);
@ -280,7 +271,7 @@ void CCSpriteBatchNode::sortAllChildren()
if (m_pChildren->count() > 0)
{
//first sort all children recursively based on zOrder
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite);
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::sortAllChildren, CCSprite*);
int index=0;
@ -403,7 +394,7 @@ void CCSpriteBatchNode::draw(void)
CC_NODE_DRAW_SETUP();
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite);
arrayMakeObjectsPerformSelectorWithType(m_pChildren, &CCSprite::updateTransform, CCSprite*);
ccGLBlendFunc( m_blendFunc.src, m_blendFunc.dst );
@ -561,56 +552,40 @@ unsigned int CCSpriteBatchNode::atlasIndexForChild(CCSprite *pobSprite, int nZ)
// add child helper
void CCSpriteBatchNode::insertChild(CCSprite *pobSprite, unsigned int uIndex)
void CCSpriteBatchNode::insertChild(CCSprite *pSprite, unsigned int uIndex)
{
pobSprite->setBatchNode(this);
pobSprite->setAtlasIndex(uIndex);
pobSprite->setDirty(true);
pSprite->setBatchNode(this);
pSprite->setAtlasIndex(uIndex);
pSprite->setDirty(true);
if (m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
if(m_pobTextureAtlas->getTotalQuads() == m_pobTextureAtlas->getCapacity())
{
increaseAtlasCapacity();
}
ccV3F_C4B_T2F_Quad quad = pobSprite->getQuad();
ccV3F_C4B_T2F_Quad quad = pSprite->getQuad();
m_pobTextureAtlas->insertQuad(&quad, uIndex);
m_pobDescendants->insertObject(pobSprite, uIndex);
ccArray *descendantsData = m_pobDescendants->data;
ccArrayInsertObjectAtIndex(descendantsData, pSprite, uIndex);
// update indices
unsigned int i = 0;
if (m_pobDescendants && m_pobDescendants->count() > 0)
{
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pobDescendants, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
if (i > uIndex)
{
unsigned int i = uIndex+1;
CCSprite* pChild = NULL;
for(; i<descendantsData->num; i++){
pChild = (CCSprite*)descendantsData->arr[i];
pChild->setAtlasIndex(pChild->getAtlasIndex() + 1);
}
++i;
}
}
}
// add children recursively
CCArray *pChildren = pobSprite->getChildren();
if (pChildren && pChildren->count() > 0)
CCObject* pObj = NULL;
CCARRAY_FOREACH(pSprite->getChildren(), pObj)
{
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildren, pObject)
{
CCSprite* pChild = (CCSprite*) pObject;
if (pChild)
{
unsigned int uIndex = atlasIndexForChild(pChild, pChild->getZOrder());
insertChild(pChild, uIndex);
}
}
pChild = (CCSprite*)pObj;
unsigned int idx = atlasIndexForChild(pChild, pChild->getZOrder());
insertChild(pChild, idx);
}
}
@ -754,8 +729,7 @@ CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsi
// XXX: optimize with a binary search
int i=0;
if (m_pobDescendants && m_pobDescendants->count() > 0)
{
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pobDescendants, pObject)
{
@ -765,7 +739,7 @@ CCSpriteBatchNode * CCSpriteBatchNode::addSpriteWithoutQuad(CCSprite*child, unsi
++i;
}
}
}
m_pobDescendants->insertObject(child, i);
// IMPORTANT: Call super, and not self. Avoid adding it to the texture atlas array

View File

@ -1 +1 @@
20e32b9a1ad61e6bf3e179cc5e1cd7d7bdec57fa
45fa60a7892453b6d2be3554738d829d7743303e

View File

@ -483,7 +483,6 @@ public:
SpriteBatchNodeReorderOneChild();
void reorderSprite(ccTime dt);
virtual std::string title();
virtual std::string subtitle();
private:
CCSpriteBatchNode *m_pBatchNode;
CCSprite *m_pReorderSprite;

View File

@ -805,7 +805,7 @@ TMXIsoZorder::TMXIsoZorder()
addChild(map, 0, kTagTileMap);
CCSize s = map->getContentSize();
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
CCLOG("ContentSize: %f, %f", s.width,s.height);
map->setPosition(ccp(-s.width/2,0));
m_tamara = CCSprite::spriteWithFile(s_pPathSister1);
@ -1011,7 +1011,7 @@ TMXOrthoVertexZ::TMXOrthoVertexZ()
// can use any CCSprite and it will work OK.
CCTMXLayer* layer = map->layerNamed("trees");
m_tamara = layer->tileAt(ccp(0,11));
CCLOG("%@ vertexZ: %f", m_tamara, m_tamara->getVertexZ());
CCLOG("%p vertexZ: %f", m_tamara, m_tamara->getVertexZ());
m_tamara->retain();
CCActionInterval* move = CCMoveBy::actionWithDuration(10, ccpMult( ccp(400,450), 1/CC_CONTENT_SCALE_FACTOR()));