diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index b613a38204..d0a79e6b00 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -623,24 +623,32 @@ void CCDirector::end(void) void CCDirector::setNextScene(void) { - bool runningIsTransition = dynamic_cast(m_pRunningScene) != NULL; - bool newIsTransition = dynamic_cast(m_pNextScene) != NULL; +// bool runningIsTransition = dynamic_cast(m_pRunningScene) != NULL; +// bool newIsTransition = dynamic_cast(m_pNextScene) != NULL; + ccSceneFlag runningSceneType = ccNormalScene; + ccSceneFlag newSceneType = m_pNextScene->getSceneType(); + + if (m_pRunningScene) + { + runningSceneType = m_pRunningScene->getSceneType(); + } // If it is not a transition, call onExit/cleanup - if (! newIsTransition) - { - if (m_pRunningScene) - { - m_pRunningScene->onExit(); - } - - // issue #709. the root node (scene) should receive the cleanup message too - // otherwise it might be leaked. - if (m_bSendCleanupToScene && m_pRunningScene) - { - m_pRunningScene->cleanup(); - } - } + /*if (! newIsTransition)*/ + if (! (newSceneType & ccTransitionScene)) + { + if (m_pRunningScene) + { + m_pRunningScene->onExit(); + } + + // issue #709. the root node (scene) should receive the cleanup message too + // otherwise it might be leaked. + if (m_bSendCleanupToScene && m_pRunningScene) + { + m_pRunningScene->cleanup(); + } + } if (m_pRunningScene) { @@ -650,7 +658,8 @@ void CCDirector::setNextScene(void) m_pNextScene->retain(); m_pNextScene = NULL; - if (! runningIsTransition && m_pRunningScene) + /*if (! runningIsTransition && m_pRunningScene)*/ + if (! (runningSceneType & ccTransitionScene) && m_pRunningScene) { m_pRunningScene->onEnter(); m_pRunningScene->onEnterTransitionDidFinish(); diff --git a/cocos2dx/CCScheduler.cpp b/cocos2dx/CCScheduler.cpp index eb97811219..f5c0001cdd 100644 --- a/cocos2dx/CCScheduler.cpp +++ b/cocos2dx/CCScheduler.cpp @@ -255,7 +255,7 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol { for (unsigned int i = 0; i < pElement->timers->num; ++i) { - CCTimer *pTimer = static_cast(pElement->timers->arr[i]); + CCTimer *pTimer = (CCTimer*)(pElement->timers->arr[i]); if (pfnSelector == pTimer->m_pfnSelector) { @@ -570,7 +570,7 @@ void CCScheduler::tick(ccTime dt) // The 'timers' array may change while inside this loop for (elt->timerIndex = 0; elt->timerIndex < elt->timers->num; ++(elt->timerIndex)) { - elt->currentTimer = static_cast(elt->timers->arr[elt->timerIndex]); + elt->currentTimer = (CCTimer*)(elt->timers->arr[elt->timerIndex]); elt->currentTimerSalvaged = false; elt->currentTimer->update(dt); diff --git a/cocos2dx/actions/CCActionManager.cpp b/cocos2dx/actions/CCActionManager.cpp index 56a3614455..bec9afc2cd 100644 --- a/cocos2dx/actions/CCActionManager.cpp +++ b/cocos2dx/actions/CCActionManager.cpp @@ -400,7 +400,7 @@ void CCActionManager::update(cocos2d::ccTime dt) // elt, at this moment, is still valid // so it is safe to ask this here (issue #490) - elt = static_cast(elt->hh.next); + elt = (tHashElement*)(elt->hh.next); // only delete currentTarget if no actions were scheduled during the cycle (issue #481) if (m_bCurrentTargetSalvaged && m_pCurrentTarget->actions->num == 0) diff --git a/cocos2dx/actions/CCIntervalAction.cpp b/cocos2dx/actions/CCIntervalAction.cpp index 5a682c358d..9d9904c3be 100644 --- a/cocos2dx/actions/CCIntervalAction.cpp +++ b/cocos2dx/actions/CCIntervalAction.cpp @@ -69,7 +69,7 @@ NSObject* CCIntervalAction::copyWithZone(NSZone *pZone) if(pZone && pZone->m_pCopyObject) { //in case of being called at sub class - pCopy = static_cast(pZone->m_pCopyObject); + pCopy = (CCIntervalAction*)(pZone->m_pCopyObject); } else { @@ -215,8 +215,8 @@ NSObject* CCSequence::copyWithZone(NSZone *pZone) __super::copyWithZone(pZone); - pCopy->initOneTwo(static_cast(m_pActions[0]->copy()->autorelease()), - static_cast(m_pActions[1]->copy()->autorelease())); + pCopy->initOneTwo((CCFiniteTimeAction*)(m_pActions[0]->copy()->autorelease()), + (CCFiniteTimeAction*)(m_pActions[1]->copy()->autorelease())); CCX_SAFE_DELETE(pNewZone); return pCopy; @@ -1365,10 +1365,12 @@ NSObject* CCFadeIn::copyWithZone(cocos2d::NSZone *pZone) void CCFadeIn::update(cocos2d::ccTime time) { - // because we can not use dynamic_cast(), so we cast in c style. - // Is it sprite? can it be other node? - /* dynamic_cast(m_pTarget)->setOpacity((GLubyte)(255 * time));*/ - ((CCSprite *)(m_pTarget))->setOpacity((GLubyte)(255 * time)); + CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setOpacity((GLubyte)(255 * time)); + } + /*m_pTarget->setOpacity((GLubyte)(255 * time));*/ } CCIntervalAction* CCFadeIn::reverse(void) @@ -1413,10 +1415,12 @@ NSObject* CCFadeOut::copyWithZone(cocos2d::NSZone *pZone) void CCFadeOut::update(cocos2d::ccTime time) { - // because we can not use dynamic_cast(), so we cast in c style. - // Is it sprite? can it be other node? - // dynamic_cast(m_pTarget)->setOpacity(GLubyte(255 * (1 - time))); - ((CCSprite *)m_pTarget)->setOpacity((GLubyte)(255 * (1 - time))); + CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setOpacity(GLubyte(255 * (1 - time))); + } + /*m_pTarget->setOpacity(GLubyte(255 * (1 - time)));*/ } CCIntervalAction* CCFadeOut::reverse(void) @@ -1474,12 +1478,22 @@ void CCFadeTo::startWithTarget(CCNode *pTarget) { __super::startWithTarget(pTarget); - m_fromOpacity = ((CCRGBAProtocol*)(pTarget))->getOpacity(); + CCRGBAProtocol *pRGBAProtocol = pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + m_fromOpacity = pRGBAProtocol->getOpacity(); + } + /*m_fromOpacity = pTarget->getOpacity();*/ } void CCFadeTo::update(cocos2d::ccTime time) { - ((CCRGBAProtocol*)(m_pTarget))->setOpacity((GLubyte)(m_fromOpacity + (m_toOpacity - m_fromOpacity) * time)); + CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setOpacity((GLubyte)(m_fromOpacity + (m_toOpacity - m_fromOpacity) * time)); + } + /*m_pTarget->setOpacity((GLubyte)(m_fromOpacity + (m_toOpacity - m_fromOpacity) * time));*/ } // @@ -1531,22 +1545,23 @@ NSObject* CCTintTo::copyWithZone(cocos2d::NSZone *pZone) void CCTintTo::startWithTarget(CCNode *pTarget) { __super::startWithTarget(pTarget); - - // because we can not use dynamic_cast(), so we cast in c style. - // Is it sprite? can it be other node? - /*m_from = dynamic_cast(pTarget)->getColor();*/ - m_from = ((CCSprite *)(pTarget))->getColor(); + CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + m_from = pRGBAProtocol->getColor(); + } + /*m_from = pTarget->getColor();*/ } void CCTintTo::update(cocos2d::ccTime time) { - // because we can not use dynamic_cast(), so we cast in c style. - // Is it sprite? can it be other node? - /*CCRGBAProtocol *pTn = dynamic_cast(m_pTarget);*/ - CCSprite *pTn = (CCSprite *)(m_pTarget); - pTn->setColor(ccc3(GLubyte(m_from.r + (m_to.r - m_from.r) * time), - (GLbyte)(m_from.g + (m_to.g - m_from.g) * time), - (GLbyte)(m_from.b + (m_to.b - m_from.b) * time))); + CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setColor(ccc3(GLubyte(m_from.r + (m_to.r - m_from.r) * time), + (GLbyte)(m_from.g + (m_to.g - m_from.g) * time), + (GLbyte)(m_from.b + (m_to.b - m_from.b) * time))); + } } // @@ -1602,17 +1617,25 @@ void CCTintBy::startWithTarget(CCNode *pTarget) { __super::startWithTarget(pTarget); - ccColor3B color = ((CCRGBAProtocol*)(pTarget))->getColor(); - m_fromR = color.r; - m_fromG = color.g; - m_fromB = color.b; + CCRGBAProtocol *pRGBAProtocol = pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + ccColor3B color = pRGBAProtocol->getColor(); + m_fromR = color.r; + m_fromG = color.g; + m_fromB = color.b; + } } void CCTintBy::update(cocos2d::ccTime time) { - ((CCRGBAProtocol*)(m_pTarget))->setColor(ccc3((GLubyte)(m_fromR + m_deltaR * time), - (GLubyte)(m_fromG + m_deltaG * time), - (GLubyte)(m_fromB + m_deltaB * time))); + CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setColor(ccc3((GLubyte)(m_fromR + m_deltaR * time), + (GLubyte)(m_fromG + m_deltaG * time), + (GLubyte)(m_fromB + m_deltaB * time))); + } } CCIntervalAction* CCTintBy::reverse(void) @@ -1739,7 +1762,7 @@ void CCReverseTime::update(cocos2d::ccTime time) CCIntervalAction* CCReverseTime::reverse(void) { - return static_cast(m_pOther->copy()->autorelease()); + return (CCIntervalAction*)(m_pOther->copy()->autorelease()); } // diff --git a/cocos2dx/base_nodes/CCAtlasNode.cpp b/cocos2dx/base_nodes/CCAtlasNode.cpp index 2597f73d43..70e1425e90 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.cpp +++ b/cocos2dx/base_nodes/CCAtlasNode.cpp @@ -82,15 +82,15 @@ CCAtlasNode * CCAtlasNode::initWithTileFile(const char *tile, int tileWidth, int void CCAtlasNode::calculateMaxItems() { CGSize s = m_pTextureAtlas->getTexture()->getContentSize(); - m_nItemsPerColumn = static_cast(s.height / m_nItemHeight); - m_nItemsPerRow = static_cast(s.width / m_nItemWidth); + m_nItemsPerColumn = (int)(s.height / m_nItemHeight); + m_nItemsPerRow = (int)(s.width / m_nItemWidth); } void CCAtlasNode:: calculateTexCoordsSteps() { CCTexture2D *texture = m_pTextureAtlas->getTexture(); - m_fTexStepX = m_nItemWidth / static_cast(texture->getPixelsWide()); - m_fTexStepY = m_nItemHeight / static_cast(texture->getPixelsHigh()); + m_fTexStepX = m_nItemWidth / (float)(texture->getPixelsWide()); + m_fTexStepY = m_nItemHeight / (float)(texture->getPixelsHigh()); } void CCAtlasNode::updateAtlasValues() diff --git a/cocos2dx/include/CCAtlasNode.h b/cocos2dx/include/CCAtlasNode.h index ec4957e0c7..592e7a8ccd 100644 --- a/cocos2dx/include/CCAtlasNode.h +++ b/cocos2dx/include/CCAtlasNode.h @@ -87,6 +87,8 @@ public: virtual void draw(); + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + // CC Texture protocol // returns the used texture diff --git a/cocos2dx/include/CCBitmapFontAtlas.h b/cocos2dx/include/CCBitmapFontAtlas.h index 303921bc75..1c6b8d7f8e 100644 --- a/cocos2dx/include/CCBitmapFontAtlas.h +++ b/cocos2dx/include/CCBitmapFontAtlas.h @@ -162,6 +162,8 @@ namespace cocos2d{ // super method virtual void setString(const char *label); virtual void setAnchorPoint(CGPoint var); + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; } #if CC_BITMAPFONTATLAS_DEBUG_DRAW virtual void draw(); #endif // CC_BITMAPFONTATLAS_DEBUG_DRAW diff --git a/cocos2dx/include/CCLabel.h b/cocos2dx/include/CCLabel.h index 1ae8926923..d7949dc6a2 100644 --- a/cocos2dx/include/CCLabel.h +++ b/cocos2dx/include/CCLabel.h @@ -55,6 +55,8 @@ namespace cocos2d{ * @warning Changing the string is as expensive as creating a new CCLabel. To obtain better performance use CCLabelAtlas */ virtual void setString(const char *label); + + virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; } protected: CGSize m_tDimensions; UITextAlignment m_eAlignment; diff --git a/cocos2dx/include/CCLabelAtlas.h b/cocos2dx/include/CCLabelAtlas.h index 8a1a58a15e..41cc4e0faa 100644 --- a/cocos2dx/include/CCLabelAtlas.h +++ b/cocos2dx/include/CCLabelAtlas.h @@ -53,6 +53,8 @@ namespace cocos2d{ virtual void updateAtlasValues(); virtual void setString(const char *label); virtual void draw(); + + virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; } protected: // string to render std::string m_sString; diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index 48e3cfb08b..6e0218a038 100644 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -130,6 +130,8 @@ public: /** BlendFunction. Conforms to CCBlendProtocol protocol */ CCX_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc) + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + private : void updateColor(); }; diff --git a/cocos2dx/include/CCMenu.h b/cocos2dx/include/CCMenu.h index 36a6e2492e..410621d92c 100644 --- a/cocos2dx/include/CCMenu.h +++ b/cocos2dx/include/CCMenu.h @@ -90,6 +90,8 @@ namespace cocos2d{ virtual ccColor3B getColor(void); virtual void setColor(ccColor3B color); + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + private: CCMenuItem* itemForTouch(CCTouch * touch); diff --git a/cocos2dx/include/CCMenuItem.h b/cocos2dx/include/CCMenuItem.h index ed26ce9bc4..f59641eb56 100644 --- a/cocos2dx/include/CCMenuItem.h +++ b/cocos2dx/include/CCMenuItem.h @@ -107,6 +107,8 @@ namespace cocos2d{ virtual GLubyte getOpacity(); virtual void setColor(ccColor3B color); virtual ccColor3B getColor(); + + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } protected: ccColor3B m_tColorBackup; float m_fOriginalScale; @@ -189,6 +191,8 @@ namespace cocos2d{ virtual ccColor3B getColor(){return ccBLACK;} virtual void setOpacity(GLubyte opacity){} virtual GLubyte getOpacity(){return 0;} + + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } }; /** CCMenuItemImage accepts images as items. @@ -251,6 +255,8 @@ namespace cocos2d{ virtual void selected(); virtual void unselected(); virtual void setIsEnabled(bool var); + + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } }; } diff --git a/cocos2dx/include/CCNode.h b/cocos2dx/include/CCNode.h index f8fdb54333..2ec92f598b 100644 --- a/cocos2dx/include/CCNode.h +++ b/cocos2dx/include/CCNode.h @@ -39,6 +39,8 @@ class CCGridBase; class CGPoint; class CCTouch; class CCAction; +class CCRGBAProtocol; +class CCLabelProtocol; enum { kCCNodeTagInvalid = -1, @@ -446,6 +448,8 @@ public: virtual void selectorProtocolRetain(void); virtual void selectorProtocolRelease(void); + virtual CCRGBAProtocol* convertToRGBAProtocol(void) { return NULL; } + virtual CCLabelProtocol* convertToLabelProtocol(void) { return NULL; } // transformation methods diff --git a/cocos2dx/include/CCScene.h b/cocos2dx/include/CCScene.h index 28e075b6c9..9af6e1937d 100644 --- a/cocos2dx/include/CCScene.h +++ b/cocos2dx/include/CCScene.h @@ -40,6 +40,12 @@ additional logic. It is a good practice to use and CCScene as the parent of all your nodes. */ +typedef enum +{ + ccNormalScene = 1 << 0, + ccTransitionScene = 1 << 1, +} ccSceneFlag; + class CCX_DLL CCScene : public CCNode { public: @@ -47,8 +53,11 @@ public: virtual ~CCScene(); bool init(); static CCScene *node(void); + inline ccSceneFlag getSceneType(void) { return m_eSceneType; } + +protected: + ccSceneFlag m_eSceneType; }; }//namespace cocos2d #endif // __CCSCENE_H__ - diff --git a/cocos2dx/include/CCSprite.h b/cocos2dx/include/CCSprite.h index ea001c9b5a..907174943c 100644 --- a/cocos2dx/include/CCSprite.h +++ b/cocos2dx/include/CCSprite.h @@ -89,7 +89,7 @@ typedef enum { * - But the rendering will be slower: 1 draw per children. * */ -class CCX_DLL CCSprite : public CCNode, public CCTextureProtocol +class CCX_DLL CCSprite : public CCNode, public CCTextureProtocol, public CCRGBAProtocol { public: virtual void draw(void); @@ -232,6 +232,8 @@ public: virtual void setIsOpacityModifyRGB(bool bValue); virtual bool getIsOpacityModifyRGB(void); + virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol *)this; } + // CCTextureProtocol virtual void setTexture(CCTexture2D *texture); virtual CCTexture2D* getTexture(void); diff --git a/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp b/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp index 1d84008117..e3d4c73329 100644 --- a/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp +++ b/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp @@ -416,7 +416,7 @@ namespace cocos2d{ CCSprite *fontChar; - fontChar = dynamic_cast(this->getChildByTag(i)); + fontChar = (CCSprite*)(this->getChildByTag(i)); if( ! fontChar ) { fontChar = new CCSprite(); @@ -488,7 +488,7 @@ namespace cocos2d{ NSMutableArray::NSMutableArrayIterator it; for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it) { - (dynamic_cast(*it))->setColor(m_tColor); + ((CCSprite*)(*it))->setColor(m_tColor); } } } @@ -505,7 +505,11 @@ namespace cocos2d{ NSMutableArray::NSMutableArrayIterator it; for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it) { - (dynamic_cast(*it))->setOpacity(m_cOpacity); + CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setOpacity(m_cOpacity); + } } } } @@ -521,7 +525,11 @@ namespace cocos2d{ NSMutableArray::NSMutableArrayIterator it; for(it = m_pChildren->begin(); it != m_pChildren->end(); ++it) { - (dynamic_cast(*it))->setIsOpacityModifyRGB(m_bIsOpacityModifyRGB); + CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setIsOpacityModifyRGB(m_bIsOpacityModifyRGB); + } } } } diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index 3d1cce0068..d7387810ef 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -107,8 +107,8 @@ void CCLayer::setIsTouchEnabled(bool enabled) else { // have problems? - CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast(this)); - CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast(this)); + CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCTargetedTouchDelegate*)(this)); + CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCStandardTouchDelegate*)(this)); } } } @@ -157,8 +157,8 @@ void CCLayer::onExit() { if( m_bIsTouchEnabled ) { - CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast(this)); - CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast(this)); + CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCTargetedTouchDelegate*)(this)); + CCTouchDispatcher::getSharedDispatcher()->removeDelegate((CCStandardTouchDelegate*)(this)); } /** if( isAccelerometerEnabled ) diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index 889784b7f7..2291f811b3 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -32,6 +32,7 @@ CCScene::CCScene() { m_bIsRelativeAnchorPoint = false; m_tAnchorPoint = ccp(0.5f, 0.5f); + m_eSceneType = ccNormalScene; } CCScene::~CCScene() diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp index f7c6142777..1549c48588 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp @@ -80,6 +80,7 @@ CCTransitionScene * CCTransitionScene::initWithDuration(ccTime t, CCScene *scene m_pInScene->retain(); m_pOutScene = CCDirector::getSharedDirector()->getRunningScene(); m_pOutScene->retain(); + m_eSceneType = ccTransitionScene; NSAssert( m_pInScene != m_pOutScene, "Incoming scene must be different from the outgoing scene" ); @@ -229,7 +230,7 @@ void CCRotoZoomTransition:: onEnter() m_pInScene->setAnchorPoint(ccp(0.5f, 0.5f)); m_pOutScene->setAnchorPoint(ccp(0.5f, 0.5f)); - CCIntervalAction *rotozoom = static_cast(CCSequence::actions + CCIntervalAction *rotozoom = (CCIntervalAction*)(CCSequence::actions ( CCSpawn::actions ( @@ -280,8 +281,8 @@ void CCJumpZoomTransition::onEnter() CCIntervalAction *scaleIn = CCScaleTo::actionWithDuration(m_fDuration/4, 1.0f); CCIntervalAction *scaleOut = CCScaleTo::actionWithDuration(m_fDuration/4, 0.5f); - CCIntervalAction *jumpZoomOut = dynamic_cast(CCSequence::actions(scaleOut, jump, NULL)); - CCIntervalAction *jumpZoomIn = dynamic_cast(CCSequence::actions(jump, scaleIn, NULL)); + CCIntervalAction *jumpZoomOut = (CCIntervalAction*)(CCSequence::actions(scaleOut, jump, NULL)); + CCIntervalAction *jumpZoomIn = (CCIntervalAction*)(CCSequence::actions(jump, scaleIn, NULL)); CCIntervalAction *delay = CCDelayTime::actionWithDuration(m_fDuration/2); diff --git a/cocos2dx/menu_nodes/CCMenu.cpp b/cocos2dx/menu_nodes/CCMenu.cpp index af22486500..56c15ba03e 100644 --- a/cocos2dx/menu_nodes/CCMenu.cpp +++ b/cocos2dx/menu_nodes/CCMenu.cpp @@ -118,7 +118,8 @@ namespace cocos2d{ CCNode * CCMenu::addChild(CCNode * child, int zOrder, int tag) { - NSAssert( dynamic_cast(child) != NULL, L"Menu only supports MenuItem objects as children"); + // we can not use RTTI, so we do not known the type of object + /*NSAssert( dynamic_cast(child) != NULL, L"Menu only supports MenuItem objects as children");*/ return __super::addChild(child, zOrder, tag); } @@ -513,8 +514,12 @@ namespace cocos2d{ { break; } - - dynamic_cast(*it)->setOpacity(m_cOpacity); + + CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setOpacity(m_cOpacity); + } } } } @@ -538,7 +543,11 @@ namespace cocos2d{ break; } - dynamic_cast(*it)->setColor(m_tColor); + CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); + if (pRGBAProtocol) + { + pRGBAProtocol->setColor(m_tColor); + } } } } diff --git a/cocos2dx/menu_nodes/CCMenuItem.cpp b/cocos2dx/menu_nodes/CCMenuItem.cpp index 5ed43edbab..39d7db9165 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.cpp +++ b/cocos2dx/menu_nodes/CCMenuItem.cpp @@ -140,7 +140,7 @@ namespace cocos2d{ } void CCMenuItemLabel::setString(const char * label) { - dynamic_cast(m_pLabel)->setString(label); + m_pLabel->convertToLabelProtocol()->setString(label); this->setContentSize(m_pLabel->getContentSize()); // [label_ setString:string]; // [self setContentSize: [label_ contentSize]]; @@ -185,12 +185,12 @@ namespace cocos2d{ { if(enabled == false) { - m_tColorBackup = dynamic_cast(m_pLabel)->getColor(); - dynamic_cast(m_pLabel)->setColor(m_tDisabledColor); + m_tColorBackup = m_pLabel->convertToRGBAProtocol()->getColor(); + m_pLabel->convertToRGBAProtocol()->setColor(m_tDisabledColor); } else { - dynamic_cast(m_pLabel)->setColor(m_tColorBackup); + m_pLabel->convertToRGBAProtocol()->setColor(m_tColorBackup); } } __super::setIsEnabled(enabled); @@ -201,19 +201,19 @@ namespace cocos2d{ } void CCMenuItemLabel::setOpacity(GLubyte opacity) { - dynamic_cast(m_pLabel)->setOpacity(opacity); + m_pLabel->convertToRGBAProtocol()->setOpacity(opacity); } GLubyte CCMenuItemLabel::getOpacity() { - return dynamic_cast(m_pLabel)->getOpacity(); + return m_pLabel->convertToRGBAProtocol()->getOpacity(); } void CCMenuItemLabel::setColor(ccColor3B color) { - dynamic_cast(m_pLabel)->setColor(color); + m_pLabel->convertToRGBAProtocol()->setColor(color); } ccColor3B CCMenuItemLabel::getColor() { - return dynamic_cast(m_pLabel)->getColor(); + return m_pLabel->convertToRGBAProtocol()->getColor(); } // @@ -379,29 +379,31 @@ namespace cocos2d{ // void CCMenuItemImage::setOpacity(GLubyte opacity) { - dynamic_cast(m_pNormalImage)->setOpacity(opacity); - dynamic_cast(m_pSelectedImage)->setOpacity(opacity); + m_pNormalImage->convertToRGBAProtocol()->setOpacity(opacity); + m_pSelectedImage->convertToRGBAProtocol()->setOpacity(opacity); + if (m_pDisabledImage) - { - dynamic_cast(m_pDisabledImage)->setOpacity(opacity); + { + m_pDisabledImage->convertToRGBAProtocol()->setOpacity(opacity); } } void CCMenuItemImage::setColor(ccColor3B color) { - dynamic_cast(m_pNormalImage)->setColor(color); - dynamic_cast(m_pSelectedImage)->setColor(color); + m_pNormalImage->convertToRGBAProtocol()->setColor(color); + m_pSelectedImage->convertToRGBAProtocol()->setColor(color); + if (m_pDisabledImage) - { - dynamic_cast(m_pDisabledImage)->setColor(color); + { + m_pDisabledImage->convertToRGBAProtocol()->setColor(color); } } GLubyte CCMenuItemImage::getOpacity() { - return dynamic_cast(m_pNormalImage)->getOpacity(); + return m_pNormalImage->convertToRGBAProtocol()->getOpacity(); } ccColor3B CCMenuItemImage::getColor() { - return dynamic_cast(m_pNormalImage)->getColor(); + return m_pNormalImage->convertToRGBAProtocol()->getColor(); } CCMenuItemImage * CCMenuItemImage::itemFromNormalImage(const char *normalImage, const char *selectedImage) { @@ -545,7 +547,7 @@ namespace cocos2d{ NSMutableArray::NSMutableArrayIterator it; for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it) { - dynamic_cast(*it)->setOpacity(opacity); + (*it)->convertToRGBAProtocol()->setOpacity(opacity); } } } @@ -561,7 +563,7 @@ namespace cocos2d{ NSMutableArray::NSMutableArrayIterator it; for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it) { - dynamic_cast(*it)->setColor(color); + (*it)->convertToRGBAProtocol()->setColor(color); } } } diff --git a/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp b/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp index 9c7738b3e0..bae05a842d 100644 --- a/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp +++ b/cocos2dx/platform/uphone/CCXFileUtils_uphone.cpp @@ -113,7 +113,7 @@ public: }; void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts) { - CCDictMaker *pMaker = static_cast(ctx); + CCDictMaker *pMaker = (CCDictMaker*)(ctx); std::string sName((char*)name); if( sName == "dict" ) { @@ -155,21 +155,21 @@ void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts) } void plist_endElement(void *ctx, const xmlChar *name) { - CCDictMaker * pMaker = static_cast(ctx); + CCDictMaker * pMaker = (CCDictMaker*)(ctx); std::string sName((char*)name); if( sName == "dict" ) { pMaker->m_tDictStack.pop(); if ( !pMaker->m_tDictStack.empty() ) { - pMaker->m_pCurDict = static_cast*>(pMaker->m_tDictStack.top()); + pMaker->m_pCurDict = (std::map*)(pMaker->m_tDictStack.top()); } } pMaker->m_tState = SAX_NONE; } void plist_characters(void *ctx, const xmlChar *ch, int len) { - CCDictMaker * pMaker = static_cast(ctx); + CCDictMaker * pMaker = (CCDictMaker*)(ctx); if (pMaker->m_tState == SAX_NONE) { return; diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 4c6218758d..72361ad4b9 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -604,8 +604,8 @@ CCNode* CCSprite::addChild(CCNode *pChild, int zOrder, int tag) if (m_bUsesSpriteSheet) { - unsigned int index = m_pobSpriteSheet->atlasIndexForChild(static_cast(pChild), zOrder); - m_pobSpriteSheet->insertChild(static_cast(pChild), index); + unsigned int index = m_pobSpriteSheet->atlasIndexForChild((CCSprite*)(pChild), zOrder); + m_pobSpriteSheet->insertChild((CCSprite*)(pChild), index); } m_bHasChildren = true; @@ -641,7 +641,7 @@ void CCSprite::removeChild(CCNode *pChild, bool bCleanup) { if (m_bUsesSpriteSheet) { - m_pobSpriteSheet->removeSpriteFromAtlas(static_cast(pChild)); + m_pobSpriteSheet->removeSpriteFromAtlas((CCSprite*)(pChild)); } __super::removeChild(pChild, bCleanup); @@ -656,7 +656,7 @@ void CCSprite::removeAllChildrenWithCleanup(bool bCleanup) NSMutableArray::NSMutableArrayIterator iter; for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter) { - pChild = static_cast(*iter); + pChild = (CCSprite*)(*iter); m_pobSpriteSheet->removeSpriteFromAtlas(pChild); } } @@ -681,7 +681,7 @@ void CCSprite::setDirtyRecursively(bool bValue) NSMutableArray::NSMutableArrayIterator iter; for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter) { - pChild = static_cast(*iter); + pChild = (CCSprite*)(*iter); pChild->setDirtyRecursively(true); } } @@ -973,8 +973,9 @@ void CCSprite::setTexture(CCTexture2D *texture) // CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteSheet assert(! m_bUsesSpriteSheet); - // // accept texture==nil as argument - assert((! texture) || dynamic_cast(texture)); + // we can not use RTTI, so we do not known the type of object + // accept texture==nil as argument + /*assert((! texture) || dynamic_cast(texture));*/ CCX_SAFE_RELEASE(m_pobTexture); diff --git a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp index c8e9f88861..15083f28af 100644 --- a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp @@ -78,14 +78,14 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(map *pobDi map *pMetadataMap = NULL; if (metadataIter != pobDictionary->end()) { - pMetadataMap = static_cast*>(metadataIter->second); + pMetadataMap = (map*)(metadataIter->second); } map::iterator framesIter = pobDictionary->find("frames"); map *pFramesMap = NULL; if (framesIter != pobDictionary->end()) { - pFramesMap = static_cast*>(framesIter->second); + pFramesMap = (map*)(framesIter->second); } int format = 0; @@ -122,7 +122,7 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(map *pobDi } CCSpriteFrame *pSpriteFrame; - pFrame = static_cast*>(frameIter->second); + pFrame = (map*)(frameIter->second); if (format == 0) { /* diff --git a/cocos2dx/sprite_nodes/CCSpriteSheet.cpp b/cocos2dx/sprite_nodes/CCSpriteSheet.cpp index bca4c3ad56..358c860f19 100644 --- a/cocos2dx/sprite_nodes/CCSpriteSheet.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteSheet.cpp @@ -166,7 +166,7 @@ CCNode* CCSpriteSheet::addChild(CCNode *child, int zOrder, int tag) { assert(child != NULL); - CCSprite *pSprite = static_cast(child); + CCSprite *pSprite = (CCSprite*)(child); // check CCSprite is using the same texture id assert(pSprite->getTexture()->getName() == m_pobTextureAtlas->getTexture()->getName()); @@ -199,7 +199,7 @@ void CCSpriteSheet::reorderChild(CCNode *child, int zOrder) // override remove child void CCSpriteSheet::removeChild(CCNode *child, bool cleanup) { - CCSprite *pSprite = static_cast(child); + CCSprite *pSprite = (CCSprite*)(child); // explicit null handling if (pSprite == NULL) @@ -217,7 +217,7 @@ void CCSpriteSheet::removeChild(CCNode *child, bool cleanup) void CCSpriteSheet::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup) { - removeChild(static_cast(m_pChildren->getObjectAtIndex(uIndex)), bDoCleanup); + removeChild((CCSprite*)(m_pChildren->getObjectAtIndex(uIndex)), bDoCleanup); } void CCSpriteSheet::removeAllChildrenWithCleanup(bool bCleanup) @@ -229,7 +229,7 @@ void CCSpriteSheet::removeAllChildrenWithCleanup(bool bCleanup) NSMutableArray::NSMutableArrayIterator iter; for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter) { - pSprite = static_cast(*iter); + pSprite = (CCSprite*)(*iter); if (! pSprite) { @@ -331,7 +331,7 @@ unsigned int CCSpriteSheet::rebuildIndexInOrder(CCSprite *pobParent, unsigned in NSMutableArray::NSMutableArrayIterator iter; for (iter = pChildren->begin(); iter != pChildren->end(); ++iter) { - pSprite = static_cast(*iter); + pSprite = (CCSprite*)(*iter); if (! pSprite) { @@ -358,7 +358,7 @@ unsigned int CCSpriteSheet::rebuildIndexInOrder(CCSprite *pobParent, unsigned in NSMutableArray::NSMutableArrayIterator iter; for (iter = pChildren->begin(); iter != pChildren->end(); ++iter) { - pSprite = static_cast(*iter); + pSprite = (CCSprite*)(*iter); if (! pSprite) { @@ -385,7 +385,7 @@ unsigned int CCSpriteSheet::highestAtlasIndexInChild(CCSprite *pSprite) } else { - return highestAtlasIndexInChild(static_cast(pChildren->getLastObject())); + return highestAtlasIndexInChild((CCSprite*)(pChildren->getLastObject())); } } @@ -399,7 +399,7 @@ unsigned int CCSpriteSheet::lowestAtlasIndexInChild(CCSprite *pSprite) } else { - return lowestAtlasIndexInChild(static_cast(pChildren->getObjectAtIndex(0))); + return lowestAtlasIndexInChild((CCSprite*)(pChildren->getObjectAtIndex(0))); } } @@ -409,11 +409,11 @@ unsigned int CCSpriteSheet::atlasIndexForChild(CCSprite *pobSprite, int nZ) unsigned int uChildIndex = pBrothers->getIndexOfObject(pobSprite); // ignore parent Z if parent is spriteSheet - bool bIgnoreParent = static_cast(pobSprite->getParent()) == this; + bool bIgnoreParent = (CCSpriteSheet*)(pobSprite->getParent()) == this; CCSprite *pPrevious = NULL; if (uChildIndex > 0) { - pPrevious = static_cast(pBrothers->getObjectAtIndex(uChildIndex - 1)); + pPrevious = (CCSprite*)(pBrothers->getObjectAtIndex(uChildIndex - 1)); } // first child of the sprite sheet @@ -432,7 +432,7 @@ unsigned int CCSpriteSheet::atlasIndexForChild(CCSprite *pobSprite, int nZ) // first child of an CCSprite ? if (uChildIndex == 0) { - CCSprite *p = static_cast(pobSprite->getParent()); + CCSprite *p = (CCSprite*)(pobSprite->getParent()); // less than parent and brothers if (nZ < 0) @@ -453,7 +453,7 @@ unsigned int CCSpriteSheet::atlasIndexForChild(CCSprite *pobSprite, int nZ) } // else (previous < 0 and sprite >= 0 ) - CCSprite *p = static_cast(pobSprite->getParent()); + CCSprite *p = (CCSprite*)(pobSprite->getParent()); return p->getAtlasIndex() + 1; } @@ -509,7 +509,7 @@ void CCSpriteSheet::insertChild(CCSprite *pobSprite, unsigned int uIndex) CCSprite *pSprite; for (iterNode = pChildren->begin(); iterNode != pChildren->end(); ++iterNode) { - pSprite = static_cast(*iterNode); + pSprite = (CCSprite*)(*iterNode); if (! pSprite) { @@ -541,7 +541,7 @@ void CCSpriteSheet::removeSpriteFromAtlas(CCSprite *pobSprite) for(; uIndex < count; ++uIndex) { - CCSprite* s = static_cast(m_pobDescendants->getObjectAtIndex(uIndex)); + CCSprite* s = (CCSprite*)(m_pobDescendants->getObjectAtIndex(uIndex)); s->setAtlasIndex( s->getAtlasIndex() - 1 ); } } @@ -555,7 +555,7 @@ void CCSpriteSheet::removeSpriteFromAtlas(CCSprite *pobSprite) NSMutableArray::NSMutableArrayIterator iter; for (iter = pChildren->begin(); iter != pChildren->end(); ++iter) { - pSprite = static_cast(*iter); + pSprite = (CCSprite*)(*iter); if (! pSprite) { diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index c6700b1ad6..7bc0836e37 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -162,8 +162,8 @@ CCTexture2D * CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat m_uPixelsWide = pixelsWide; m_uPixelsHigh = pixelsHigh; m_ePixelFormat = pixelFormat; - m_fMaxS = contentSize.width / static_cast(pixelsWide); - m_fMaxT = contentSize.height / static_cast(pixelsHigh); + m_fMaxS = contentSize.width / (float)(pixelsWide); + m_fMaxT = contentSize.height / (float)(pixelsHigh); m_bHasPremultipliedAlpha = false; @@ -251,7 +251,7 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, un pixelFormat = kCCTexture2DPixelFormat_A8; } - imageSize = CGSizeMake(static_cast(image->width()), static_cast(image->height())); + imageSize = CGSizeMake((float)(image->width()), (float)(image->height())); // Create the bitmap graphics context @@ -277,7 +277,7 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, un // info = kCGImageAlphaOnly; // context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info); - tempData = static_cast(image->getRGBA8888Data()); + tempData = (void*)(image->getRGBA8888Data()); NSAssert(tempData != NULL, "NULL image data."); if(image->width() == POTWide && image->height() == POTHigh) { @@ -465,7 +465,7 @@ CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bp } glCompressedTexImage2D(GL_TEXTURE_2D, level, format, length, length, 0, size, data); - m_tContentSize = CGSizeMake(static_cast(length), static_cast(length)); + m_tContentSize = CGSizeMake((float)(length), (float)(length)); m_uPixelsWide = length; m_uPixelsHigh = length; m_fMaxS = 1.0f; @@ -495,7 +495,7 @@ CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file) m_uPixelsWide = pvr->getWidth(); // width m_uPixelsHigh = pvr->getHeight(); // height /// be careful : unsigned int to float - m_tContentSize = CGSizeMake(static_cast(m_uPixelsWide), static_cast(m_uPixelsHigh)); + m_tContentSize = CGSizeMake((float)(m_uPixelsWide), (float)(m_uPixelsHigh)); pvr->release(); diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index 884db3aa8f..41b160d4d7 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -266,13 +266,13 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u NSSetIterator setIter; for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter) { - pTouch = static_cast(*setIter); + pTouch = (CCTouch *)(*setIter); CCTargetedTouchHandler *pHandler; NSMutableArray::NSMutableArrayIterator arrayIter; for (arrayIter = m_pTargetedHandlers->begin(); arrayIter != m_pTargetedHandlers->end(); ++arrayIter) /*for (unsigned int i = 0; i < m_pTargetedHandlers->num; ++i)*/ { - pHandler = static_cast(*arrayIter); + pHandler = (CCTargetedTouchHandler *)(*arrayIter); if (! pHandler) { @@ -331,7 +331,7 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int u CCStandardTouchHandler *pHandler; for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter) { - pHandler = static_cast(*iter); + pHandler = (CCStandardTouchHandler*)(*iter); if (! pHandler) {