fixed #554: upgrade base_nodes to 1.0.0-rc3

This commit is contained in:
minggo 2011-07-01 15:48:05 +08:00
parent de705986f8
commit 16f79cb0be
4 changed files with 136 additions and 55 deletions

View File

@ -1,6 +1,7 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org
@ -33,10 +34,10 @@ namespace cocos2d {
// CCAtlasNode - Creation & Init
CCAtlasNode::CCAtlasNode()
: m_nItemsPerRow(0)
, m_nItemsPerColumn(0)
, m_nItemWidth(0)
, m_nItemHeight(0)
: m_uItemsPerRow(0)
, m_uItemsPerColumn(0)
, m_uItemWidth(0)
, m_uItemHeight(0)
, m_pTextureAtlas(NULL)
, m_bIsOpacityModifyRGB(false)
, m_cOpacity(0)
@ -48,7 +49,8 @@ CCAtlasNode::~CCAtlasNode()
CC_SAFE_RELEASE(m_pTextureAtlas);
}
CCAtlasNode * CCAtlasNode::atlasWithTileFile(const char *tile, int tileWidth, int tileHeight, int itemsToRender)
CCAtlasNode * CCAtlasNode::atlasWithTileFile(const char *tile, unsigned int tileWidth, unsigned int tileHeight,
unsigned int itemsToRender)
{
CCAtlasNode * pRet = new CCAtlasNode();
if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender))
@ -60,11 +62,12 @@ CCAtlasNode * CCAtlasNode::atlasWithTileFile(const char *tile, int tileWidth, in
return NULL;
}
bool CCAtlasNode::initWithTileFile(const char *tile, int tileWidth, int tileHeight, int itemsToRender)
bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, unsigned int tileHeight,
unsigned int itemsToRender)
{
assert(tile != NULL);
m_nItemWidth = (int) (tileWidth * CC_CONTENT_SCALE_FACTOR());
m_nItemHeight = (int) (tileHeight * CC_CONTENT_SCALE_FACTOR());
m_uItemWidth = (int) (tileWidth * CC_CONTENT_SCALE_FACTOR());
m_uItemHeight = (int) (tileHeight * CC_CONTENT_SCALE_FACTOR());
m_cOpacity = 255;
m_tColor = m_tColorUnmodified = ccWHITE;
@ -99,8 +102,8 @@ bool CCAtlasNode::initWithTileFile(const char *tile, int tileWidth, int tileHeig
void CCAtlasNode::calculateMaxItems()
{
CCSize s = m_pTextureAtlas->getTexture()->getContentSizeInPixels();
m_nItemsPerColumn = (int)(s.height / m_nItemHeight);
m_nItemsPerRow = (int)(s.width / m_nItemWidth);
m_uItemsPerColumn = (int)(s.height / m_uItemHeight);
m_uItemsPerRow = (int)(s.width / m_uItemWidth);
}
void CCAtlasNode::updateAtlasValues()

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2009 Valentin Milea
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org
@ -43,7 +44,7 @@ THE SOFTWARE.
namespace cocos2d {
CCNode::CCNode(void)
: m_nZOrder(0)
: m_uZOrder(0)
, m_fVertexZ(0.0f)
, m_fRotation(0.0f)
, m_fScaleX(1.0f)
@ -69,6 +70,8 @@ CCNode::CCNode(void)
, m_pUserData(NULL)
, m_bIsTransformDirty(true)
, m_bIsInverseDirty(true)
, m_fSkewX(0.0)
, m_fSkewY(0.0)
#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
, m_bIsTransformGLDirty(true)
#endif
@ -118,17 +121,46 @@ void CCNode::arrayMakeObjectsPerformSelector(CCArray* pArray, callbackFunc func)
}
}
/// zOrder getter
int CCNode::getZOrder()
float CCNode::getSkewX()
{
return m_nZOrder;
return m_fSkewX;
}
void CCNode::setSkewX(float newSkewX)
{
m_fSkewX = newSkewX;
m_bIsTransformDirty = m_bIsInverseDirty = true;
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
m_bIsTransformGLDirty = true;
#endif
}
float CCNode::getSkewY()
{
return m_fSkewY;
m_bIsTransformDirty = m_bIsInverseDirty = true;
#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX
m_bIsTransformGLDirty = true;
#endif
}
void CCNode::setSkewY(float newSkewY)
{
m_fSkewY = newSkewY;
}
/// zOrder getter
unsigned int CCNode::getZOrder()
{
return m_uZOrder;
}
/// zOrder setter : private method
/// used internally to alter the zOrder variable. DON'T call this method manually
void CCNode::setZOrder(int z)
void CCNode::setZOrder(unsigned int z)
{
m_nZOrder = z;
m_uZOrder = z;
}
/// ertexZ getter
@ -495,7 +527,7 @@ void CCNode::childrenAlloc(void)
m_pChildren->retain();
}
CCNode* CCNode::getChildByTag(int aTag)
CCNode* CCNode::getChildByTag(unsigned int aTag)
{
CCAssert( aTag != kCCNodeTagInvalid, "Invalid tag");
@ -516,7 +548,7 @@ CCNode* CCNode::getChildByTag(int aTag)
* If a class want's to extend the 'addChild' behaviour it only needs
* to override this method
*/
void CCNode::addChild(CCNode *child, int zOrder, int tag)
void CCNode::addChild(CCNode *child, unsigned int zOrder, int tag)
{
CCAssert( child != NULL, "Argument must be non-nil");
CCAssert( child->m_pParent == NULL, "child already added. It can't be added again");
@ -539,7 +571,7 @@ void CCNode::addChild(CCNode *child, int zOrder, int tag)
}
}
void CCNode::addChild(CCNode *child, int zOrder)
void CCNode::addChild(CCNode *child, unsigned int zOrder)
{
CCAssert( child != NULL, "Argument must be non-nil");
this->addChild(child, zOrder, child->m_nTag);
@ -548,7 +580,7 @@ void CCNode::addChild(CCNode *child, int zOrder)
void CCNode::addChild(CCNode *child)
{
CCAssert( child != NULL, "Argument must be non-nil");
this->addChild(child, child->m_nZOrder, child->m_nTag);
this->addChild(child, child->m_uZOrder, child->m_nTag);
}
void CCNode::removeFromParentAndCleanup(bool cleanup)
@ -574,7 +606,7 @@ void CCNode::removeChild(CCNode* child, bool cleanup)
}
}
void CCNode::removeChildByTag(int tag, bool cleanup)
void CCNode::removeChildByTag(unsigned int tag, bool cleanup)
{
CCAssert( tag != kCCNodeTagInvalid, "Invalid tag");
@ -648,7 +680,7 @@ void CCNode::detachChild(CCNode *child, bool doCleanup)
// helper used by reorderChild & add
void CCNode::insertChild(CCNode* child, int z)
void CCNode::insertChild(CCNode* child, unsigned int z)
{
unsigned int index = 0;
CCNode* a = (CCNode*) m_pChildren->lastObject();
@ -662,7 +694,7 @@ void CCNode::insertChild(CCNode* child, int z)
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pNode = (CCNode*) pObject;
if ( pNode && (pNode->m_nZOrder > z ))
if ( pNode && (pNode->m_uZOrder > z ))
{
m_pChildren->insertObject(child, index);
break;
@ -674,7 +706,7 @@ void CCNode::insertChild(CCNode* child, int z)
child->setZOrder(z);
}
void CCNode::reorderChild(CCNode *child, int zOrder)
void CCNode::reorderChild(CCNode *child, unsigned int zOrder)
{
CCAssert( child != NULL, "Child must be non-nil");
@ -721,7 +753,7 @@ void CCNode::visit()
{
pNode = (CCNode*) arrayData->arr[i];
if ( pNode && pNode->m_nZOrder < 0 )
if ( pNode && pNode->m_uZOrder < 0 )
{
pNode->visit();
}
@ -821,6 +853,15 @@ void CCNode::transform()
if (m_fRotation != 0.0f )
glRotatef( -m_fRotation, 0.0f, 0.0f, 1.0f );
// skew
if ( (skewX_ != 0.0f) || (skewY_ != 0.0f) )
{
CCAffineTransform skewMatrix = CCAffineTransformMake( 1.0f, tanf(CC_DEGREES_TO_RADIANS(skewY_)), tanf(CC_DEGREES_TO_RADIANS(skewX_)), 1.0f, 0.0f, 0.0f );
GLfloat glMatrix[16];
CCAffineToGL(&skewMatrix, glMatrix);
glMultMatrixf(glMatrix);
}
// scale
if (m_fScaleX != 1.0f || m_fScaleY != 1.0f)
glScalef( m_fScaleX, m_fScaleY, 1.0f );
@ -878,19 +919,19 @@ void CCNode::stopAction(CCAction* action)
CCActionManager::sharedManager()->removeAction(action);
}
void CCNode::stopActionByTag(int tag)
void CCNode::stopActionByTag(unsigned int tag)
{
CCAssert( tag != kCCActionTagInvalid, "Invalid tag");
CCActionManager::sharedManager()->removeActionByTag(tag, this);
}
CCAction * CCNode::getActionByTag(int tag)
CCAction * CCNode::getActionByTag(unsigned int tag)
{
CCAssert( tag != kCCActionTagInvalid, "Invalid tag");
return CCActionManager::sharedManager()->getActionByTag(tag, this);
}
int CCNode::numberOfRunningActions()
unsigned int CCNode::numberOfRunningActions()
{
return CCActionManager::sharedManager()->numberOfRunningActionsInTarget(this);
}
@ -902,7 +943,7 @@ void CCNode::scheduleUpdate()
scheduleUpdateWithPriority(0);
}
void CCNode::scheduleUpdateWithPriority(int priority)
void CCNode::scheduleUpdateWithPriority(unsigned int priority)
{
CCScheduler::sharedScheduler()->scheduleUpdateForTarget(this, priority, !m_bIsRunning);
}
@ -963,22 +1004,42 @@ void CCNode::selectorProtocolRelease(void)
CCAffineTransform CCNode::nodeToParentTransform(void)
{
if ( m_bIsTransformDirty ) {
if (m_bIsTransformDirty) {
m_tTransform = CCAffineTransformIdentity;
if( ! m_bIsRelativeAnchorPoint && ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero) )
{
m_tTransform = CCAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
}
if( ! CCPoint::CCPointEqualToPoint(m_tPositionInPixels, CCPointZero) )
if(! CCPoint::CCPointEqualToPoint(m_tPositionInPixels, CCPointZero))
{
m_tTransform = CCAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPositionInPixels.y);
if( m_fRotation != 0 )
m_tTransform = CCAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation));
if( ! (m_fScaleX == 1 && m_fScaleY == 1) )
m_tTransform = CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
}
if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero) )
if(m_fRotation != 0)
{
m_tTransform = CCAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation));
}
if(m_fSkewX != 0 || m_fSkewY != 0)
{
// create a skewed coordinate system
CCAffineTransform skew = CCAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)), tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, 0.0f, 0.0f);
// apply the skew to the transform
m_tTransform = CCAffineTransformConcat(skew, m_tTransform);
}
if(! (m_fScaleX == 1 && m_fScaleY == 1))
{
m_tTransform = CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
}
if(! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPixels, CCPointZero))
{
m_tTransform = CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
}
m_bIsTransformDirty = false;
}

View File

@ -1,6 +1,7 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org
@ -47,14 +48,14 @@ class CC_DLL CCAtlasNode : public CCNode, public CCRGBAProtocol, public CCTextur
protected:
//! chars per row
int m_nItemsPerRow;
unsigned int m_uItemsPerRow;
//! chars per column
int m_nItemsPerColumn;
unsigned int m_uItemsPerColumn;
//! width of each char
int m_nItemWidth;
unsigned int m_uItemWidth;
//! height of each char
int m_nItemHeight;
unsigned int m_uItemHeight;
ccColor3B m_tColorUnmodified;
@ -71,10 +72,11 @@ public:
virtual ~CCAtlasNode();
/** creates a CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
static CCAtlasNode * atlasWithTileFile(const char* tile,int tileWidth, int tileHeight, int itemsToRender);
static CCAtlasNode * atlasWithTileFile(const char* tile,unsigned int tileWidth, unsigned int tileHeight,
unsigned int itemsToRender);
/** initializes an CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/
bool initWithTileFile(const char* tile, int tileWidth, int tileHeight, int itemsToRender);
bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);
/** updates the Atlas (indexed vertex array).
* Shall be overriden in subclasses

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2009 Valentin Milea
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org
@ -108,7 +109,7 @@ namespace cocos2d {
// variable property
/** The z order of the node relative to it's "brothers": children of the same parent */
CC_PROPERTY_READONLY(int, m_nZOrder, ZOrder)
CC_PROPERTY_READONLY(unsigned int, m_uZOrder, ZOrder)
/** The real openGL Z vertex.
Differences between openGL Z vertex and cocos2d Z order:
@ -140,6 +141,20 @@ namespace cocos2d {
CC_PROPERTY(CCPoint, m_tPosition, Position)
CC_PROPERTY(CCPoint, m_tPositionInPixels, PositionInPixels)
/** The X skew angle of the node in degrees.
This angle describes the shear distortion in the X direction.
Thus, it is the angle between the Y axis and the left edge of the shape
The default skewX angle is 0. Positive values distort the node in a CW direction.
*/
CC_PROPERTY(float, m_fSkewX, SkewX);
/** The Y skew angle of the node in degrees.
This angle describes the shear distortion in the Y direction.
Thus, it is the angle between the X axis and the bottom edge of the shape
The default skewY angle is 0. Positive values distort the node in a CCW direction.
*/
CC_PROPERTY(float, m_fSkewY, SkewY);
CC_PROPERTY_READONLY(CCArray*, m_pChildren, Children)
/** A CCCamera object that lets you move the node using a gluLookAt
@ -220,10 +235,10 @@ namespace cocos2d {
void childrenAlloc(void);
//! helper that reorder a child
void insertChild(CCNode* child, int z);
void insertChild(CCNode* child, unsigned int z);
//! used internally to alter the zOrder variable. DON'T call this method manually
void setZOrder(int z);
void setZOrder(unsigned int z);
void detachChild(CCNode *child, bool doCleanup);
@ -262,7 +277,7 @@ namespace cocos2d {
/** callback that is called every time the CCNode leaves the 'stage'.
If the CCNode leaves the 'stage' with a transition, this callback is called when the transition finishes.
During onExit you can't a "sister/brother" node.
During onExit you can't access a sibling node.
*/
virtual void onExit();
@ -278,13 +293,13 @@ namespace cocos2d {
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
@since v0.7.1
*/
virtual void addChild(CCNode * child, int zOrder);
virtual void addChild(CCNode * child, unsigned int zOrder);
/** Adds a child to the container with z order and tag
If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
@since v0.7.1
*/
virtual void addChild(CCNode * child, int zOrder, int tag);
virtual void addChild(CCNode * child, unsigned int zOrder, int tag);
// composition: REMOVE
@ -302,7 +317,7 @@ namespace cocos2d {
/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter
@since v0.7.1
*/
void removeChildByTag(int tag, bool cleanup);
void removeChildByTag(unsigned int tag, bool cleanup);
/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
@since v0.7.1
@ -314,12 +329,12 @@ namespace cocos2d {
@return returns a CCNode object
@since v0.7.1
*/
CCNode * getChildByTag(int tag);
CCNode * getChildByTag(unsigned int tag);
/** Reorders a child according to a new z value.
* The child MUST be already added.
*/
virtual void reorderChild(CCNode * child, int zOrder);
virtual void reorderChild(CCNode * child, unsigned int zOrder);
/** Stops all running actions and schedulers
@since v0.8
@ -391,20 +406,20 @@ namespace cocos2d {
/** Removes an action from the running action list given its tag
@since v0.7.1
*/
void stopActionByTag(int tag);
void stopActionByTag(unsigned int tag);
/** Gets an action from the running action list given its tag
@since v0.7.1
@return the Action the with the given tag
*/
CCAction* getActionByTag(int tag);
CCAction* getActionByTag(unsigned int tag);
/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
* Composable actions are counted as 1 action. Example:
* If you are running 1 Sequence of 7 actions, it will return 1.
* If you are running 7 Sequences of 2 actions, it will return 7.
*/
int numberOfRunningActions(void);
unsigned int numberOfRunningActions(void);
// timers
@ -426,7 +441,7 @@ namespace cocos2d {
@since v0.99.3
*/
void scheduleUpdateWithPriority(int priority);
void scheduleUpdateWithPriority(unsigned int priority);
/* unschedules the "update" method.