standardize code

This commit is contained in:
2youyou2 2013-09-16 12:21:18 +08:00
parent b7b079c1c6
commit d8b64b8645
3 changed files with 59 additions and 58 deletions

View File

@ -454,7 +454,7 @@ void Armature::update(float dt)
Object *object = NULL; Object *object = NULL;
CCARRAY_FOREACH(_topBoneList, object) CCARRAY_FOREACH(_topBoneList, object)
{ {
((Bone *)object)->update(dt); static_cast<Bone*>(object)->update(dt);
} }
_armatureTransformDirty = false; _armatureTransformDirty = false;
@ -483,7 +483,7 @@ void Armature::draw()
{ {
case CS_DISPLAY_SPRITE: case CS_DISPLAY_SPRITE:
{ {
Skin *skin = (Skin *)node; Skin *skin = static_cast<Skin *>(node);
TextureAtlas *textureAtlas = skin->getTextureAtlas(); TextureAtlas *textureAtlas = skin->getTextureAtlas();
BlendType blendType = bone->getBlendType(); BlendType blendType = bone->getBlendType();
@ -513,7 +513,7 @@ void Armature::draw()
break; break;
case CS_DISPLAY_ARMATURE: case CS_DISPLAY_ARMATURE:
{ {
Armature *armature = (Armature *)(node); Armature *armature = static_cast<Armature *>(node);
TextureAtlas *textureAtlas = armature->getTextureAtlas(); TextureAtlas *textureAtlas = armature->getTextureAtlas();
if(_atlas != textureAtlas) if(_atlas != textureAtlas)
@ -675,14 +675,15 @@ Rect Armature::getBoundingBox() const
Bone *Armature::getBoneAtPoint(float x, float y) Bone *Armature::getBoneAtPoint(float x, float y)
{ {
int length = _children->data->num; int length = _children->count();
Bone **bs = (Bone **)_children->data->arr; Bone *bs;
for(int i = length - 1; i >= 0; i--) for(int i = length - 1; i >= 0; i--)
{ {
if(bs[i]->getDisplayManager()->containPoint(x, y)) bs = static_cast<Bone*>( _children->getObjectAtIndex(i) );
if(bs->getDisplayManager()->containPoint(x, y))
{ {
return bs[i]; return bs;
} }
} }
return NULL; return NULL;

View File

@ -63,16 +63,16 @@ Bone::Bone()
_tweenData = NULL; _tweenData = NULL;
_parentBone = NULL; _parentBone = NULL;
_armature = NULL; _armature = NULL;
m_pChildArmature = NULL; _childArmature = NULL;
m_pBoneData = NULL; _boneData = NULL;
m_pTween = NULL; m_pTween = NULL;
m_pTween = NULL; m_pTween = NULL;
_children = NULL; _children = NULL;
m_pDisplayManager = NULL; _displayManager = NULL;
m_bIgnoreMovementBoneData = false; _ignoreMovementBoneData = false;
m_tWorldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0);
m_bBoneTransformDirty = true; _boneTransformDirty = true;
m_eBlendType = BLEND_NORMAL; _blendType = BLEND_NORMAL;
} }
@ -81,14 +81,14 @@ Bone::~Bone(void)
CC_SAFE_DELETE(_tweenData); CC_SAFE_DELETE(_tweenData);
CC_SAFE_DELETE(_children); CC_SAFE_DELETE(_children);
CC_SAFE_DELETE(m_pTween); CC_SAFE_DELETE(m_pTween);
CC_SAFE_DELETE(m_pDisplayManager); CC_SAFE_DELETE(_displayManager);
if(m_pBoneData) if(_boneData)
{ {
m_pBoneData->release(); _boneData->release();
} }
CC_SAFE_RELEASE(m_pChildArmature); CC_SAFE_RELEASE(_childArmature);
} }
bool Bone::init() bool Bone::init()
@ -115,9 +115,9 @@ bool Bone::init(const char *name)
m_pTween = new Tween(); m_pTween = new Tween();
m_pTween->init(this); m_pTween->init(this);
CC_SAFE_DELETE(m_pDisplayManager); CC_SAFE_DELETE(_displayManager);
m_pDisplayManager = new DisplayManager(); _displayManager = new DisplayManager();
m_pDisplayManager->init(this); _displayManager->init(this);
bRet = true; bRet = true;
@ -131,18 +131,18 @@ void Bone::setBoneData(BoneData *boneData)
{ {
CCASSERT(NULL != boneData, "_boneData must not be NULL"); CCASSERT(NULL != boneData, "_boneData must not be NULL");
m_pBoneData = boneData; _boneData = boneData;
m_pBoneData->retain(); _boneData->retain();
_name = m_pBoneData->name; _name = _boneData->name;
_ZOrder = m_pBoneData->zOrder; _ZOrder = _boneData->zOrder;
m_pDisplayManager->initDisplayList(boneData); _displayManager->initDisplayList(boneData);
} }
BoneData *Bone::getBoneData() BoneData *Bone::getBoneData()
{ {
return m_pBoneData; return _boneData;
} }
void Bone::setArmature(Armature *armature) void Bone::setArmature(Armature *armature)
@ -163,28 +163,28 @@ Armature *Bone::getArmature()
void Bone::update(float delta) void Bone::update(float delta)
{ {
if (_parentBone) if (_parentBone)
m_bBoneTransformDirty = m_bBoneTransformDirty || _parentBone->isTransformDirty(); _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty();
if (m_bBoneTransformDirty) if (_boneTransformDirty)
{ {
if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED)
{ {
TransformHelp::nodeConcat(*_tweenData, *m_pBoneData); TransformHelp::nodeConcat(*_tweenData, *_boneData);
_tweenData->scaleX -= 1; _tweenData->scaleX -= 1;
_tweenData->scaleY -= 1; _tweenData->scaleY -= 1;
} }
TransformHelp::nodeToMatrix(*_tweenData, m_tWorldTransform); TransformHelp::nodeToMatrix(*_tweenData, _worldTransform);
m_tWorldTransform = AffineTransformConcat(getNodeToParentTransform(), m_tWorldTransform); _worldTransform = AffineTransformConcat(getNodeToParentTransform(), _worldTransform);
if(_parentBone) if(_parentBone)
{ {
m_tWorldTransform = AffineTransformConcat(m_tWorldTransform, _parentBone->m_tWorldTransform); _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform);
} }
} }
DisplayFactory::updateDisplay(this, m_pDisplayManager->getCurrentDecorativeDisplay(), delta, m_bBoneTransformDirty || _armature->getArmatureTransformDirty()); DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
Object *object = NULL; Object *object = NULL;
CCARRAY_FOREACH(_children, object) CCARRAY_FOREACH(_children, object)
@ -193,7 +193,7 @@ void Bone::update(float delta)
childBone->update(delta); childBone->update(delta);
} }
m_bBoneTransformDirty = false; _boneTransformDirty = false;
} }
@ -213,7 +213,7 @@ void Bone::updateDisplayedOpacity(GLubyte parentOpacity)
void Bone::updateColor() void Bone::updateColor()
{ {
Node *display = m_pDisplayManager->getDisplayRenderNode(); Node *display = _displayManager->getDisplayRenderNode();
RGBAProtocol *protocol = dynamic_cast<RGBAProtocol *>(display); RGBAProtocol *protocol = dynamic_cast<RGBAProtocol *>(display);
if(protocol != NULL) if(protocol != NULL)
{ {
@ -226,7 +226,7 @@ void Bone::updateZOrder()
{ {
if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED)
{ {
int zorder = _tweenData->zOrder + m_pBoneData->zOrder; int zorder = _tweenData->zOrder + _boneData->zOrder;
setZOrder(zorder); setZOrder(zorder);
} }
else else
@ -296,17 +296,17 @@ Bone *Bone::getParentBone()
void Bone::setChildArmature(Armature *armature) void Bone::setChildArmature(Armature *armature)
{ {
if (m_pChildArmature != armature) if (_childArmature != armature)
{ {
CC_SAFE_RETAIN(armature); CC_SAFE_RETAIN(armature);
CC_SAFE_RELEASE(m_pChildArmature); CC_SAFE_RELEASE(_childArmature);
m_pChildArmature = armature; _childArmature = armature;
} }
} }
Armature *Bone::getChildArmature() Armature *Bone::getChildArmature()
{ {
return m_pChildArmature; return _childArmature;
} }
Tween *Bone::getTween() Tween *Bone::getTween()
@ -322,47 +322,47 @@ void Bone::setZOrder(int zOrder)
void Bone::setTransformDirty(bool dirty) void Bone::setTransformDirty(bool dirty)
{ {
m_bBoneTransformDirty = dirty; _boneTransformDirty = dirty;
} }
bool Bone::isTransformDirty() bool Bone::isTransformDirty()
{ {
return m_bBoneTransformDirty; return _boneTransformDirty;
} }
AffineTransform Bone::getNodeToArmatureTransform() const AffineTransform Bone::getNodeToArmatureTransform() const
{ {
return m_tWorldTransform; return _worldTransform;
} }
AffineTransform Bone::getNodeToWorldTransform() const AffineTransform Bone::getNodeToWorldTransform() const
{ {
return AffineTransformConcat(m_tWorldTransform, _armature->getNodeToWorldTransform()); return AffineTransformConcat(_worldTransform, _armature->getNodeToWorldTransform());
} }
Node *Bone::getDisplayRenderNode() Node *Bone::getDisplayRenderNode()
{ {
return m_pDisplayManager->getDisplayRenderNode(); return _displayManager->getDisplayRenderNode();
} }
void Bone::addDisplay(DisplayData *displayData, int index) void Bone::addDisplay(DisplayData *displayData, int index)
{ {
m_pDisplayManager->addDisplay(displayData, index); _displayManager->addDisplay(displayData, index);
} }
void Bone::addDisplay(Node *display, int index) void Bone::addDisplay(Node *display, int index)
{ {
m_pDisplayManager->addDisplay(display, index); _displayManager->addDisplay(display, index);
} }
void Bone::changeDisplayByIndex(int index, bool force) void Bone::changeDisplayByIndex(int index, bool force)
{ {
m_pDisplayManager->changeDisplayByIndex(index, force); _displayManager->changeDisplayByIndex(index, force);
} }
Array *Bone::getColliderBodyList() Array *Bone::getColliderBodyList()
{ {
if (DecorativeDisplay *decoDisplay = m_pDisplayManager->getCurrentDecorativeDisplay()) if (DecorativeDisplay *decoDisplay = _displayManager->getCurrentDecorativeDisplay())
{ {
if (ColliderDetector *detector = decoDisplay->getColliderDetector()) if (ColliderDetector *detector = decoDisplay->getColliderDetector())
{ {

View File

@ -152,26 +152,26 @@ public:
public: public:
/* /*
* The origin state of the Bone. Display's state is effected by m_pBoneData, m_pNode, _tweenData * The origin state of the Bone. Display's state is effected by _boneData, m_pNode, _tweenData
* when call setData function, it will copy from the BoneData. * when call setData function, it will copy from the BoneData.
*/ */
CC_PROPERTY(BoneData *, m_pBoneData, BoneData); CC_PROPERTY(BoneData *, _boneData, BoneData);
//! A weak reference to the Armature //! A weak reference to the Armature
CC_PROPERTY(Armature *, _armature, Armature); CC_PROPERTY(Armature *, _armature, Armature);
//! A weak reference to the child Armature //! A weak reference to the child Armature
CC_PROPERTY(Armature *, m_pChildArmature, ChildArmature); CC_PROPERTY(Armature *, _childArmature, ChildArmature);
CC_SYNTHESIZE(DisplayManager *, m_pDisplayManager, DisplayManager) CC_SYNTHESIZE(DisplayManager *, _displayManager, DisplayManager)
/* /*
* When Armature play an animation, if there is not a MovementBoneData of this bone in this MovementData, this bone will be hidden. * When Armature play an animation, if there is not a MovementBoneData of this bone in this MovementData, this bone will be hidden.
* Set IgnoreMovementBoneData to true, then this bone will also be shown. * Set IgnoreMovementBoneData to true, then this bone will also be shown.
*/ */
CC_SYNTHESIZE(bool, m_bIgnoreMovementBoneData, IgnoreMovementBoneData) CC_SYNTHESIZE(bool, _ignoreMovementBoneData, IgnoreMovementBoneData)
CC_SYNTHESIZE(BlendType, m_eBlendType, BlendType) CC_SYNTHESIZE(BlendType, _blendType, BlendType)
protected: protected:
Tween *m_pTween; //! Calculate tween effect Tween *m_pTween; //! Calculate tween effect
@ -181,10 +181,10 @@ protected:
CC_SYNTHESIZE(std::string, _name, Name); CC_SYNTHESIZE(std::string, _name, Name);
Bone *_parentBone; //! A weak reference to its parent Bone *_parentBone; //! A weak reference to its parent
bool m_bBoneTransformDirty; //! Whether or not transform dirty bool _boneTransformDirty; //! Whether or not transform dirty
//! self Transform, use this to change display's state //! self Transform, use this to change display's state
AffineTransform m_tWorldTransform; AffineTransform _worldTransform;
}; };
NS_CC_EXT_ARMATURE_END NS_CC_EXT_ARMATURE_END