mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into android_gles20
This commit is contained in:
commit
7ccb38556e
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#include "cocoa/CCNS.h"
|
#include "cocoa/CCNS.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCScene.h"
|
#include "CCScene.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCScheduler.h"
|
#include "CCScheduler.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCTouchDispatcher.h"
|
#include "CCTouchDispatcher.h"
|
||||||
|
@ -96,7 +96,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 = new CCMutableArray<CCScene*>();
|
m_pobScenesStack = CCArray::array();
|
||||||
|
m_pobScenesStack->retain();
|
||||||
|
|
||||||
// Set default projection (3D)
|
// Set default projection (3D)
|
||||||
m_eProjection = kCCDirectorProjectionDefault;
|
m_eProjection = kCCDirectorProjectionDefault;
|
||||||
|
@ -336,8 +337,9 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
|
||||||
{
|
{
|
||||||
// reset the viewport if 3d proj & retina display
|
// reset the viewport if 3d proj & retina display
|
||||||
if( CC_CONTENT_SCALE_FACTOR() != 1 )
|
if( CC_CONTENT_SCALE_FACTOR() != 1 )
|
||||||
|
{
|
||||||
glViewport(-size.width/2, -size.height/2, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
|
glViewport(-size.width/2, -size.height/2, size.width * CC_CONTENT_SCALE_FACTOR(), size.height * CC_CONTENT_SCALE_FACTOR() );
|
||||||
|
}
|
||||||
float zeye = this->getZEye();
|
float zeye = this->getZEye();
|
||||||
|
|
||||||
kmMat4 matrixPerspective, matrixLookup;
|
kmMat4 matrixPerspective, matrixLookup;
|
||||||
|
@ -563,7 +565,7 @@ void CCDirector::popScene(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_bSendCleanupToScene = true;
|
m_bSendCleanupToScene = true;
|
||||||
m_pNextScene = m_pobScenesStack->getObjectAtIndex(c - 1);
|
m_pNextScene = (CCScene*)m_pobScenesStack->objectAtIndex(c - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,7 +326,7 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, CCObject *pTarget
|
||||||
pElement->currentTimerSalvaged = true;
|
pElement->currentTimerSalvaged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccArrayRemoveObjectAtIndex(pElement->timers, i );
|
ccArrayRemoveObjectAtIndex(pElement->timers, i, true);
|
||||||
|
|
||||||
// update timerIndex in case we are in tick:, looping over the actions
|
// update timerIndex in case we are in tick:, looping over the actions
|
||||||
if (pElement->timerIndex >= i)
|
if (pElement->timerIndex >= i)
|
||||||
|
|
|
@ -2055,10 +2055,13 @@ bool CCAnimate::initWithAnimation(CCAnimation *pAnimation)
|
||||||
float accumUnitsOfTime = 0;
|
float accumUnitsOfTime = 0;
|
||||||
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
||||||
|
|
||||||
CCMutableArray<CCAnimationFrame*>* pFrames = pAnimation->getFrames();
|
CCArray* pFrames = pAnimation->getFrames();
|
||||||
for (CCMutableArray<CCAnimationFrame*>::CCMutableArrayIterator iterFrame = pFrames->begin(); iterFrame != pFrames->end(); ++iterFrame)
|
CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame*);
|
||||||
|
|
||||||
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pFrames, pObj)
|
||||||
{
|
{
|
||||||
CCAnimationFrame *frame = *iterFrame;
|
CCAnimationFrame* frame = (CCAnimationFrame*)pObj;
|
||||||
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
||||||
accumUnitsOfTime += frame->getDelayUnits();
|
accumUnitsOfTime += frame->getDelayUnits();
|
||||||
m_pSplitTimes->push_back(value);
|
m_pSplitTimes->push_back(value);
|
||||||
|
@ -2151,7 +2154,7 @@ void CCAnimate::update(ccTime t)
|
||||||
t = fmodf(t, 1.0f);
|
t = fmodf(t, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCAnimationFrame*>* frames = m_pAnimation->getFrames();
|
CCArray* frames = m_pAnimation->getFrames();
|
||||||
unsigned int numberOfFrames = frames->count();
|
unsigned int numberOfFrames = frames->count();
|
||||||
CCSpriteFrame *frameToDisplay = NULL;
|
CCSpriteFrame *frameToDisplay = NULL;
|
||||||
|
|
||||||
|
@ -2159,11 +2162,11 @@ void CCAnimate::update(ccTime t)
|
||||||
float splitTime = m_pSplitTimes->at(i);
|
float splitTime = m_pSplitTimes->at(i);
|
||||||
|
|
||||||
if( splitTime <= t ) {
|
if( splitTime <= t ) {
|
||||||
CCAnimationFrame *frame = frames->getObjectAtIndex(i);
|
CCAnimationFrame* frame = (CCAnimationFrame*)frames->objectAtIndex(i);
|
||||||
frameToDisplay = frame->getSpriteFrame();
|
frameToDisplay = frame->getSpriteFrame();
|
||||||
((CCSprite*)m_pTarget)->setDisplayFrame(frameToDisplay);
|
((CCSprite*)m_pTarget)->setDisplayFrame(frameToDisplay);
|
||||||
|
|
||||||
CCObjectDictionary* dict = frame->getUserInfo();
|
CCDictionary* dict = frame->getUserInfo();
|
||||||
if( dict )
|
if( dict )
|
||||||
{
|
{
|
||||||
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
||||||
|
@ -2177,16 +2180,17 @@ void CCAnimate::update(ccTime t)
|
||||||
|
|
||||||
CCActionInterval* CCAnimate::reverse(void)
|
CCActionInterval* CCAnimate::reverse(void)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCAnimationFrame*>* pOldArray = m_pAnimation->getFrames();
|
CCArray* pOldArray = m_pAnimation->getFrames();
|
||||||
CCMutableArray<CCAnimationFrame*>* pNewArray = new CCMutableArray<CCAnimationFrame*>(pOldArray->count());
|
CCArray* pNewArray = CCArray::arrayWithCapacity(pOldArray->count());
|
||||||
|
|
||||||
|
CCARRAY_VERIFY_TYPE(pOldArray, CCAnimationFrame*);
|
||||||
|
|
||||||
if (pOldArray->count() > 0)
|
if (pOldArray->count() > 0)
|
||||||
{
|
{
|
||||||
CCAnimationFrame *pElement;
|
CCObject* pObj = NULL;
|
||||||
CCMutableArray<CCAnimationFrame*>::CCMutableArrayRevIterator iter;
|
CCARRAY_FOREACH_REVERSE(pOldArray, pObj)
|
||||||
for (iter = pOldArray->rbegin(); iter != pOldArray->rend(); iter++)
|
|
||||||
{
|
{
|
||||||
pElement = *iter;
|
CCAnimationFrame* pElement = (CCAnimationFrame*)pObj;
|
||||||
if (! pElement)
|
if (! pElement)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -95,7 +95,7 @@ void CCActionManager::removeActionAtIndex(unsigned int uIndex, tHashElement *pEl
|
||||||
pElement->currentActionSalvaged = true;
|
pElement->currentActionSalvaged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccArrayRemoveObjectAtIndex(pElement->actions, uIndex);
|
ccArrayRemoveObjectAtIndex(pElement->actions, uIndex, true);
|
||||||
|
|
||||||
// update actionIndex in case we are in tick. looping over the actions
|
// update actionIndex in case we are in tick. looping over the actions
|
||||||
if (pElement->actionIndex >= uIndex)
|
if (pElement->actionIndex >= uIndex)
|
||||||
|
|
|
@ -24,14 +24,14 @@ THE SOFTWARE.
|
||||||
#include "CCAutoreleasePool.h"
|
#include "CCAutoreleasePool.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
|
||||||
namespace cocos2d
|
NS_CC_BEGIN
|
||||||
{
|
|
||||||
|
|
||||||
CCPoolManager g_PoolManager;
|
CCPoolManager g_PoolManager;
|
||||||
|
|
||||||
CCAutoreleasePool::CCAutoreleasePool(void)
|
CCAutoreleasePool::CCAutoreleasePool(void)
|
||||||
{
|
{
|
||||||
m_pManagedObjectArray = new CCMutableArray<CCObject*>();
|
m_pManagedObjectArray = new CCArray();
|
||||||
|
m_pManagedObjectArray->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAutoreleasePool::~CCAutoreleasePool(void)
|
CCAutoreleasePool::~CCAutoreleasePool(void)
|
||||||
|
@ -61,13 +61,14 @@ void CCAutoreleasePool::clear()
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
int nIndex = m_pManagedObjectArray->count() - 1;
|
int nIndex = m_pManagedObjectArray->count() - 1;
|
||||||
#endif
|
#endif
|
||||||
CCMutableArray<CCObject*>::CCMutableArrayRevIterator it;
|
|
||||||
for(it = m_pManagedObjectArray->rbegin(); it != m_pManagedObjectArray->rend(); ++it)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH_REVERSE(m_pManagedObjectArray, pObj)
|
||||||
{
|
{
|
||||||
if(!*it)
|
if(!pObj)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
(*it)->m_bManaged = false;
|
pObj->m_bManaged = false;
|
||||||
//(*it)->release();
|
//(*it)->release();
|
||||||
//delete (*it);
|
//delete (*it);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -93,7 +94,8 @@ CCPoolManager* CCPoolManager::getInstance()
|
||||||
|
|
||||||
CCPoolManager::CCPoolManager()
|
CCPoolManager::CCPoolManager()
|
||||||
{
|
{
|
||||||
m_pReleasePoolStack = new CCMutableArray<CCAutoreleasePool*>();
|
m_pReleasePoolStack = new CCArray();
|
||||||
|
m_pReleasePoolStack->init();
|
||||||
m_pCurReleasePool = 0;
|
m_pCurReleasePool = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,13 +116,13 @@ void CCPoolManager::finalize()
|
||||||
if(m_pReleasePoolStack->count() > 0)
|
if(m_pReleasePoolStack->count() > 0)
|
||||||
{
|
{
|
||||||
//CCAutoreleasePool* pReleasePool;
|
//CCAutoreleasePool* pReleasePool;
|
||||||
CCMutableArray<CCAutoreleasePool*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for(it = m_pReleasePoolStack->begin(); it != m_pReleasePoolStack->end(); ++it)
|
CCARRAY_FOREACH(m_pReleasePoolStack, pObj)
|
||||||
{
|
{
|
||||||
if(!*it)
|
if(!pObj)
|
||||||
break;
|
break;
|
||||||
|
CCAutoreleasePool* pPool = (CCAutoreleasePool*)pObj;
|
||||||
(*it)->clear();
|
pPool->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,10 +154,10 @@ void CCPoolManager::pop()
|
||||||
|
|
||||||
// if(nCount > 1)
|
// if(nCount > 1)
|
||||||
// {
|
// {
|
||||||
// m_pCurReleasePool = m_pReleasePoolStack->getObjectAtIndex(nCount - 2);
|
// m_pCurReleasePool = m_pReleasePoolStack->objectAtIndex(nCount - 2);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
m_pCurReleasePool = m_pReleasePoolStack->getObjectAtIndex(nCount - 2);
|
m_pCurReleasePool = (CCAutoreleasePool*)m_pReleasePoolStack->objectAtIndex(nCount - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*m_pCurReleasePool = NULL;*/
|
/*m_pCurReleasePool = NULL;*/
|
||||||
|
@ -186,4 +188,4 @@ CCAutoreleasePool* CCPoolManager::getCurReleasePool()
|
||||||
return m_pCurReleasePool;
|
return m_pCurReleasePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
|
@ -0,0 +1,253 @@
|
||||||
|
#include "CCDictionary.h"
|
||||||
|
#include "CCString.h"
|
||||||
|
#include "CCInteger.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
CCDictionary::CCDictionary()
|
||||||
|
: m_pElements(NULL)
|
||||||
|
, m_eDictType(kCCDictUnknown)
|
||||||
|
, m_eOldDictType(kCCDictUnknown)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CCDictionary::~CCDictionary()
|
||||||
|
{
|
||||||
|
removeAllObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CCDictionary::count()
|
||||||
|
{
|
||||||
|
return HASH_COUNT(m_pElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCArray* CCDictionary::allKeys()
|
||||||
|
{
|
||||||
|
int iKeyCount = this->count();
|
||||||
|
if (iKeyCount <= 0) return NULL;
|
||||||
|
CCArray* pArray = CCArray::arrayWithCapacity(iKeyCount);
|
||||||
|
|
||||||
|
CCDictElement *pElement, *tmp;
|
||||||
|
if (m_eDictType == kCCDictStr)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
CCString* pOneKey = new CCString(pElement->m_szKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_eDictType == kCCDictInt)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
CCInteger* pOneKey = new CCInteger(pElement->m_iKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCArray* CCDictionary::allKeysForObject(CCObject* object)
|
||||||
|
{
|
||||||
|
int iKeyCount = this->count();
|
||||||
|
if (iKeyCount <= 0) return NULL;
|
||||||
|
CCArray* pArray = CCArray::array();
|
||||||
|
|
||||||
|
CCDictElement *pElement, *tmp;
|
||||||
|
|
||||||
|
if (m_eDictType == kCCDictStr)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
if (object == pElement->m_pObject)
|
||||||
|
{
|
||||||
|
CCString* pOneKey = new CCString(pElement->m_szKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_eDictType == kCCDictInt)
|
||||||
|
{
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
if (object == pElement->m_pObject)
|
||||||
|
{
|
||||||
|
CCInteger* pOneKey = new CCInteger(pElement->m_iKey);
|
||||||
|
pOneKey->autorelease();
|
||||||
|
pArray->addObject(pOneKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCObject* CCDictionary::objectForKey(const char* key)
|
||||||
|
{
|
||||||
|
if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL;
|
||||||
|
CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as key.");
|
||||||
|
|
||||||
|
CCObject* pRetObject = NULL;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_STR(m_pElements,key, pElement);
|
||||||
|
if (pElement != NULL)
|
||||||
|
{
|
||||||
|
pRetObject = pElement->m_pObject;
|
||||||
|
}
|
||||||
|
return pRetObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCObject* CCDictionary::objectForKey(int key)
|
||||||
|
{
|
||||||
|
if (m_eDictType == kCCDictUnknown && m_eDictType == kCCDictUnknown) return NULL;
|
||||||
|
CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as key.");
|
||||||
|
|
||||||
|
CCObject* pRetObject = NULL;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||||
|
if (pElement != NULL)
|
||||||
|
{
|
||||||
|
pRetObject = pElement->m_pObject;
|
||||||
|
}
|
||||||
|
return pRetObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCDictionary::setObject(CCObject* pObject, const char* key)
|
||||||
|
{
|
||||||
|
CCAssert(key != NULL && strlen(key) > 0 && pObject != NULL, "Invalid Argument!");
|
||||||
|
if (m_eOldDictType == kCCDictUnknown)
|
||||||
|
{
|
||||||
|
m_eOldDictType = kCCDictStr;
|
||||||
|
}
|
||||||
|
m_eDictType = kCCDictStr;
|
||||||
|
CCAssert(m_eDictType == m_eOldDictType, "this dictionary does not use string as key.");
|
||||||
|
|
||||||
|
bool bRet = false;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_STR(m_pElements, key, pElement);
|
||||||
|
if (pElement == NULL)
|
||||||
|
{
|
||||||
|
pObject->retain();
|
||||||
|
pElement = new CCDictElement(key, pObject);
|
||||||
|
HASH_ADD_STR(m_pElements, m_szKey, pElement);
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCObject* pTmpObj = pElement->m_pObject;
|
||||||
|
pTmpObj->retain();
|
||||||
|
removeObjectForKey(key);
|
||||||
|
setObject(pObject, key);
|
||||||
|
pTmpObj->release();
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCDictionary::setObject(CCObject* pObject, int key)
|
||||||
|
{
|
||||||
|
CCAssert(pObject != NULL, "Invalid Argument!");
|
||||||
|
if (m_eOldDictType == kCCDictUnknown)
|
||||||
|
{
|
||||||
|
m_eOldDictType = kCCDictInt;
|
||||||
|
}
|
||||||
|
m_eDictType = kCCDictInt;
|
||||||
|
CCAssert(m_eDictType == m_eOldDictType, "this dictionary does not use integer as key.");
|
||||||
|
|
||||||
|
bool bRet = false;
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||||
|
if (pElement == NULL)
|
||||||
|
{
|
||||||
|
pObject->retain();
|
||||||
|
pElement = new CCDictElement(key, pObject);
|
||||||
|
HASH_ADD_INT(m_pElements, m_iKey, pElement);
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCObject* pTmpObj = pElement->m_pObject;
|
||||||
|
pTmpObj->retain();
|
||||||
|
removeObjectForKey(key);
|
||||||
|
setObject(pObject, key);
|
||||||
|
pTmpObj->release();
|
||||||
|
bRet = true;
|
||||||
|
}
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCDictionary::removeObjectForKey(const char* key)
|
||||||
|
{
|
||||||
|
CCAssert(m_eDictType == kCCDictStr, "this dictionary does not use string as its key");
|
||||||
|
CCAssert(key != NULL && strlen(key) > 0, "Invalid Argument!");
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_STR(m_pElements, key, pElement);
|
||||||
|
if (pElement)
|
||||||
|
{
|
||||||
|
HASH_DEL(m_pElements, pElement);
|
||||||
|
pElement->m_pObject->release();
|
||||||
|
CC_SAFE_DELETE(pElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCDictionary::removeObjectForKey(int key)
|
||||||
|
{
|
||||||
|
CCAssert(m_eDictType == kCCDictInt, "this dictionary does not use integer as its key");
|
||||||
|
CCDictElement *pElement = NULL;
|
||||||
|
HASH_FIND_INT(m_pElements, &key, pElement);
|
||||||
|
if (pElement != NULL)
|
||||||
|
{
|
||||||
|
HASH_DEL(m_pElements, pElement);
|
||||||
|
pElement->m_pObject->release();
|
||||||
|
CC_SAFE_DELETE(pElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCDictionary::removeAllObjects()
|
||||||
|
{
|
||||||
|
CCDictElement *pElement, *tmp;
|
||||||
|
HASH_ITER(hh, m_pElements, pElement, tmp)
|
||||||
|
{
|
||||||
|
HASH_DEL(m_pElements, pElement);
|
||||||
|
pElement->m_pObject->release();
|
||||||
|
CC_SAFE_DELETE(pElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCObject* CCDictionary::copyWithZone(CCZone* pZone)
|
||||||
|
{
|
||||||
|
CCDictionary* pNewDict = new CCDictionary();
|
||||||
|
|
||||||
|
CCDictElement* pElement = NULL;
|
||||||
|
if (m_eDictType == kCCDictInt)
|
||||||
|
{
|
||||||
|
CCDICT_FOREACH(this, pElement)
|
||||||
|
{
|
||||||
|
pNewDict->setObject(pElement->getObject(), pElement->getIntKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m_eDictType == kCCDictStr)
|
||||||
|
{
|
||||||
|
CCDICT_FOREACH(this, pElement)
|
||||||
|
{
|
||||||
|
pNewDict->setObject(pElement->getObject(), pElement->getStrKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pNewDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* need deep copy ?*/
|
||||||
|
|
||||||
|
CCDictionary* CCDictionary::dictionaryWithDictionary(CCDictionary* srcDict)
|
||||||
|
{
|
||||||
|
CCDictionary* pNewDict = (CCDictionary*)srcDict->copyWithZone(NULL);
|
||||||
|
pNewDict->autorelease();
|
||||||
|
return pNewDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
|
@ -23,6 +23,8 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCNotificationCenter.h"
|
#include "CCNotificationCenter.h"
|
||||||
|
#include <string>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCAnimation.h"
|
#include "CCAnimation.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief An interval action is an action that takes place within a certain period of time.
|
@brief An interval action is an action that takes place within a certain period of time.
|
||||||
|
@ -717,8 +718,6 @@ private:
|
||||||
CCFiniteTimeAction* m_pAction;
|
CCFiniteTimeAction* m_pAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //__ACTION_CCINTERVAL_ACTION_H__
|
#endif //__ACTION_CCINTERVAL_ACTION_H__
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
#define __ACTION_CCACTION_MANAGER_H__
|
#define __ACTION_CCACTION_MANAGER_H__
|
||||||
|
|
||||||
#include "CCAction.h"
|
#include "CCAction.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
|
@ -28,8 +28,8 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCPlatformConfig.h"
|
#include "CCPlatformConfig.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -54,7 +54,7 @@ public:
|
||||||
virtual ~CCAnimationFrame();
|
virtual ~CCAnimationFrame();
|
||||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
|
/** initializes the animation frame with a spriteframe, number of delay units and a notification user info */
|
||||||
bool initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCObjectDictionary* userInfo);
|
bool initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCDictionary* userInfo);
|
||||||
|
|
||||||
/** CCSpriteFrameName to be used */
|
/** CCSpriteFrameName to be used */
|
||||||
CC_SYNTHESIZE_RETAIN(CCSpriteFrame*, m_pSpriteFrame, SpriteFrame)
|
CC_SYNTHESIZE_RETAIN(CCSpriteFrame*, m_pSpriteFrame, SpriteFrame)
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
CC_SYNTHESIZE(float, m_fDelayUnits, DelayUnits)
|
CC_SYNTHESIZE(float, m_fDelayUnits, DelayUnits)
|
||||||
|
|
||||||
/** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */
|
/** A CCAnimationFrameDisplayedNotification notification will be broadcasted when the frame is displayed with this dictionary as UserInfo. If UserInfo is nil, then no notification will be broadcasted. */
|
||||||
CC_SYNTHESIZE_RETAIN(CCObjectDictionary*, m_pUserInfo, UserInfo)
|
CC_SYNTHESIZE_RETAIN(CCDictionary*, m_pUserInfo, UserInfo)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,18 +92,18 @@ public:
|
||||||
The frames will be created with one "delay unit".
|
The frames will be created with one "delay unit".
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *arrayOfSpriteFrameNames);
|
static CCAnimation* animationWithSpriteFrames(CCArray* arrayOfSpriteFrameNames);
|
||||||
|
|
||||||
/* Creates an animation with an array of CCSpriteFrame and a delay between frames in seconds.
|
/* Creates an animation with an array of CCSpriteFrame and a delay between frames in seconds.
|
||||||
The frames will be added with one "delay unit".
|
The frames will be added with one "delay unit".
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *arrayOfSpriteFrameNames, float delay);
|
static CCAnimation* animationWithSpriteFrames(CCArray* arrayOfSpriteFrameNames, float delay);
|
||||||
|
|
||||||
/* Creates an animation with an array of CCAnimationFrame, the delay per units in seconds and and how many times it should be executed.
|
/* Creates an animation with an array of CCAnimationFrame, the delay per units in seconds and and how many times it should be executed.
|
||||||
@since v2.0
|
@since v2.0
|
||||||
*/
|
*/
|
||||||
static CCAnimation* animationWithAnimationFrames(CCMutableArray<CCAnimationFrame*> *arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops);
|
static CCAnimation* animationWithAnimationFrames(CCArray *arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops);
|
||||||
|
|
||||||
/** Adds a CCSpriteFrame to a CCAnimation.
|
/** Adds a CCSpriteFrame to a CCAnimation.
|
||||||
The frame will be added with one "delay unit".
|
The frame will be added with one "delay unit".
|
||||||
|
@ -126,17 +126,17 @@ public:
|
||||||
/** Initializes a CCAnimation with frames.
|
/** Initializes a CCAnimation with frames.
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
bool initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames);
|
bool initWithSpriteFrames(CCArray *pFrames);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with frames and a delay between frames
|
/** Initializes a CCAnimation with frames and a delay between frames
|
||||||
@since v0.99.5
|
@since v0.99.5
|
||||||
*/
|
*/
|
||||||
bool initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames, float delay);
|
bool initWithSpriteFrames(CCArray *pFrames, float delay);
|
||||||
|
|
||||||
/** Initializes a CCAnimation with CCAnimationFrame
|
/** Initializes a CCAnimation with CCAnimationFrame
|
||||||
@since v2.0
|
@since v2.0
|
||||||
*/
|
*/
|
||||||
bool initWithAnimationFrames(CCMutableArray<CCAnimationFrame*>* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops);
|
bool initWithAnimationFrames(CCArray* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops);
|
||||||
|
|
||||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
CC_PROPERTY_READONLY(float, m_fDuration, Duration)
|
CC_PROPERTY_READONLY(float, m_fDuration, Duration)
|
||||||
|
|
||||||
/** array of CCAnimationFrames */
|
/** array of CCAnimationFrames */
|
||||||
CC_SYNTHESIZE_RETAIN(CCMutableArray<CCAnimationFrame*>*, m_pFrames, Frames)
|
CC_SYNTHESIZE_RETAIN(CCArray*, m_pFrames, Frames)
|
||||||
|
|
||||||
/** whether or not it shall restore the original frame when the animation finishes */
|
/** whether or not it shall restore the original frame when the animation finishes */
|
||||||
CC_SYNTHESIZE(bool, m_bRestoreOriginalFrame, RestoreOriginalFrame)
|
CC_SYNTHESIZE(bool, m_bRestoreOriginalFrame, RestoreOriginalFrame)
|
||||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#define __CC_ANIMATION_CACHE_H__
|
#define __CC_ANIMATION_CACHE_H__
|
||||||
|
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public:
|
||||||
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
||||||
@since v1.1
|
@since v1.1
|
||||||
*/
|
*/
|
||||||
void addAnimationsWithDictionary(CCObjectDictionary* dictionary);
|
void addAnimationsWithDictionary(CCDictionary* dictionary);
|
||||||
|
|
||||||
/** Adds an animation from a plist file.
|
/** Adds an animation from a plist file.
|
||||||
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
Make sure that the frames were previously loaded in the CCSpriteFrameCache.
|
||||||
|
@ -83,11 +83,11 @@ public:
|
||||||
bool init(void);
|
bool init(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseVersion1(CCObjectDictionary* animations);
|
void parseVersion1(CCDictionary* animations);
|
||||||
void parseVersion2(CCObjectDictionary* animations);
|
void parseVersion2(CCDictionary* animations);
|
||||||
const char * valueForKey(const char *key, CCObjectDictionary* dict);
|
const char * valueForKey(const char *key, CCDictionary* dict);
|
||||||
private:
|
private:
|
||||||
CCMutableDictionary<std::string, CCAnimation*>* m_pAnimations;
|
CCDictionary* m_pAnimations;
|
||||||
static CCAnimationCache* s_pSharedAnimationCache;
|
static CCAnimationCache* s_pSharedAnimationCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,25 @@ I found that it's not work in C++. So it keep what it's look like in version 1.0
|
||||||
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
|
arr <= end && ((__object__ = *arr) != NULL/* || true*/); \
|
||||||
arr++)
|
arr++)
|
||||||
|
|
||||||
namespace cocos2d
|
#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*/); \
|
||||||
|
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++) \
|
||||||
|
CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \
|
||||||
|
} while(false)
|
||||||
|
#else
|
||||||
|
#define CCARRAY_VERIFY_TYPE(__array__, __type__) void(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CC_DLL CCArray : public CCObject
|
class CC_DLL CCArray : public CCObject
|
||||||
{
|
{
|
||||||
|
@ -99,11 +116,11 @@ public:
|
||||||
// Removing Objects
|
// Removing Objects
|
||||||
|
|
||||||
/** Remove last object */
|
/** Remove last object */
|
||||||
void removeLastObject();
|
void removeLastObject(bool bReleaseObj = true);
|
||||||
/** Remove a certain object */
|
/** Remove a certain object */
|
||||||
void removeObject(CCObject* object);
|
void removeObject(CCObject* object, bool bReleaseObj = true);
|
||||||
/** Remove an element with a certain index */
|
/** Remove an element with a certain index */
|
||||||
void removeObjectAtIndex(unsigned int index);
|
void removeObjectAtIndex(unsigned int index, bool bReleaseObj = true);
|
||||||
/** Remove all elements */
|
/** Remove all elements */
|
||||||
void removeObjectsInArray(CCArray* otherArray);
|
void removeObjectsInArray(CCArray* otherArray);
|
||||||
/** Remove all objects */
|
/** Remove all objects */
|
||||||
|
@ -124,13 +141,15 @@ public:
|
||||||
/* Shrinks the array so the memory footprint corresponds with the number of items */
|
/* Shrinks the array so the memory footprint corresponds with the number of items */
|
||||||
void reduceMemoryFootprint();
|
void reduceMemoryFootprint();
|
||||||
|
|
||||||
|
void replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject = true);
|
||||||
|
|
||||||
|
/** TODO: deep copy array. */
|
||||||
|
virtual CCObject* copyWithZone(CCZone* pZone) {CCAssert(false, "");return NULL;}
|
||||||
public:
|
public:
|
||||||
ccArray* data;
|
ccArray* data;
|
||||||
|
|
||||||
private:
|
|
||||||
CCArray() : data(NULL) {};
|
CCArray() : data(NULL) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
||||||
#endif // __CCARRAY_H__
|
#endif // __CCARRAY_H__
|
||||||
|
|
|
@ -25,12 +25,13 @@ THE SOFTWARE.
|
||||||
#define __AUTORELEASEPOOL_H__
|
#define __AUTORELEASEPOOL_H__
|
||||||
|
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
class CC_DLL CCAutoreleasePool : public CCObject
|
class CC_DLL CCAutoreleasePool : public CCObject
|
||||||
{
|
{
|
||||||
CCMutableArray<CCObject*>* m_pManagedObjectArray;
|
CCArray* m_pManagedObjectArray;
|
||||||
public:
|
public:
|
||||||
CCAutoreleasePool(void);
|
CCAutoreleasePool(void);
|
||||||
~CCAutoreleasePool(void);
|
~CCAutoreleasePool(void);
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
|
|
||||||
class CC_DLL CCPoolManager
|
class CC_DLL CCPoolManager
|
||||||
{
|
{
|
||||||
CCMutableArray<CCAutoreleasePool*>* m_pReleasePoolStack;
|
CCArray* m_pReleasePoolStack;
|
||||||
CCAutoreleasePool* m_pCurReleasePool;
|
CCAutoreleasePool* m_pCurReleasePool;
|
||||||
|
|
||||||
CCAutoreleasePool* getCurReleasePool();
|
CCAutoreleasePool* getCurReleasePool();
|
||||||
|
@ -62,6 +63,6 @@ public:
|
||||||
friend class CCAutoreleasePool;
|
friend class CCAutoreleasePool;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__AUTORELEASEPOOL_H__
|
#endif //__AUTORELEASEPOOL_H__
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __CCDICTIONARY_H__
|
||||||
|
#define __CCDICTIONARY_H__
|
||||||
|
|
||||||
|
#include "support/data_support/uthash.h"
|
||||||
|
#include "CCObject.h"
|
||||||
|
#include "CCArray.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class CCDictionary;
|
||||||
|
|
||||||
|
class CC_DLL CCDictElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCDictElement(const char* pszKey, CCObject* pObject)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
strncpy(m_szKey, pszKey, sizeof(m_szKey));
|
||||||
|
m_pObject = pObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCDictElement(int iKey, CCObject* pObject)
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
m_iKey = iKey;
|
||||||
|
m_pObject = pObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char* getStrKey() const
|
||||||
|
{
|
||||||
|
return m_szKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int getIntKey() const
|
||||||
|
{
|
||||||
|
return m_iKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CCObject* getObject() const
|
||||||
|
{
|
||||||
|
return m_pObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline void init()
|
||||||
|
{
|
||||||
|
m_iKey = 0;
|
||||||
|
m_pObject = NULL;
|
||||||
|
memset(m_szKey, 0, sizeof(m_szKey));
|
||||||
|
memset(&hh, 0, sizeof(hh));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
char m_szKey[256]; /* hash key of string type*/
|
||||||
|
int m_iKey; /* hash key of integer type */
|
||||||
|
CCObject* m_pObject;/* hash value */
|
||||||
|
public:
|
||||||
|
UT_hash_handle hh; /* makes this class hashable */
|
||||||
|
friend class CCDictionary;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// #define CCDICT_FOREACH(__dict__, pElement) \
|
||||||
|
// for (pElement = __dict__->m_pElements; pElement != NULL; \
|
||||||
|
// pElement = (CCDictElement*)pElement->hh.next)
|
||||||
|
|
||||||
|
#define CCDICT_FOREACH(__dict__, __el__) \
|
||||||
|
CCDictElement* ##__dict__##__el__##tmp = NULL; \
|
||||||
|
HASH_ITER(hh, (__dict__)->m_pElements, __el__, ##__dict__##__el__##tmp)
|
||||||
|
|
||||||
|
|
||||||
|
class CC_DLL CCDictionary : public CCObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCDictionary();
|
||||||
|
~CCDictionary();
|
||||||
|
|
||||||
|
/// return the number of items
|
||||||
|
unsigned int count();
|
||||||
|
|
||||||
|
/// return all the keys
|
||||||
|
CCArray* allKeys();
|
||||||
|
|
||||||
|
/** @warning : We use '==' to compare two objects*/
|
||||||
|
CCArray* allKeysForObject(CCObject* object);
|
||||||
|
|
||||||
|
CCObject* objectForKey(const char* key);
|
||||||
|
CCObject* objectForKey(int key);
|
||||||
|
|
||||||
|
bool setObject(CCObject* pObject, const char* key);
|
||||||
|
bool setObject(CCObject* pObject, int key);
|
||||||
|
|
||||||
|
void removeObjectForKey(const char* key);
|
||||||
|
void removeObjectForKey(int key);
|
||||||
|
|
||||||
|
void removeAllObjects();
|
||||||
|
|
||||||
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
|
static CCDictionary* dictionaryWithDictionary(CCDictionary* srcDict);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CCDictElement* m_pElements;
|
||||||
|
private:
|
||||||
|
enum CCDictType
|
||||||
|
{
|
||||||
|
kCCDictUnknown = 0,
|
||||||
|
kCCDictStr,
|
||||||
|
kCCDictInt
|
||||||
|
};
|
||||||
|
CCDictType m_eDictType;
|
||||||
|
CCDictType m_eOldDictType;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* __CCDICTIONARY_H__ */
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCEGLView.h"
|
#include "CCEGLView.h"
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
|
@ -448,7 +448,7 @@ protected:
|
||||||
bool m_bSendCleanupToScene;
|
bool m_bSendCleanupToScene;
|
||||||
|
|
||||||
/* scheduled scenes */
|
/* scheduled scenes */
|
||||||
CCMutableArray<CCScene*> *m_pobScenesStack;
|
CCArray* m_pobScenesStack;
|
||||||
|
|
||||||
/* last time the main loop was updated */
|
/* last time the main loop was updated */
|
||||||
struct cc_timeval *m_pLastUpdate;
|
struct cc_timeval *m_pLastUpdate;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef __CCINTEGER_H__
|
||||||
|
#define __CCINTEGER_H__
|
||||||
|
|
||||||
|
#include "CCObject.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class CC_DLL CCInteger : public CCObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCInteger(int v)
|
||||||
|
: value(v) {}
|
||||||
|
int value;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
#endif /* __CCINTEGER_H__ */
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||||
#define __CCKEYPAD_DISPATCHER_H__
|
#define __CCKEYPAD_DISPATCHER_H__
|
||||||
|
|
||||||
#include "CCKeypadDelegate.h"
|
#include "CCKeypadDelegate.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -84,9 +84,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typedef CCMutableArray<CCKeypadHandler*> KeypadDelegateArray;
|
CCArray* m_pDelegates;
|
||||||
|
|
||||||
KeypadDelegateArray* m_pDelegates;
|
|
||||||
bool m_bLocked;
|
bool m_bLocked;
|
||||||
bool m_bToAdd;
|
bool m_bToAdd;
|
||||||
bool m_bToRemove;
|
bool m_bToRemove;
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
#include "CCTouchDelegateProtocol.h"
|
#include "CCTouchDelegateProtocol.h"
|
||||||
#include "CCAccelerometerDelegate.h"
|
#include "CCAccelerometerDelegate.h"
|
||||||
#include "CCKeypadDelegate.h"
|
#include "CCKeypadDelegate.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ class CC_DLL CCLayerMultiplex : public CCLayer
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
unsigned int m_nEnabledLayer;
|
unsigned int m_nEnabledLayer;
|
||||||
CCMutableArray<CCLayer *> * m_pLayers;
|
CCArray* m_pLayers;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CCLayerMultiplex();
|
CCLayerMultiplex();
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d{
|
namespace cocos2d{
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ namespace cocos2d{
|
||||||
/** CCMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
/** CCMutableArray that contains the subitems. You can add/remove items in runtime, and you can replace the array with a new one.
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
CC_PROPERTY(CCMutableArray<CCMenuItem*>*, m_pSubItems, SubItems);
|
CC_PROPERTY(CCArray*, m_pSubItems, SubItems);
|
||||||
public:
|
public:
|
||||||
CCMenuItemToggle()
|
CCMenuItemToggle()
|
||||||
: m_cOpacity(0)
|
: m_cOpacity(0)
|
||||||
|
|
|
@ -1,363 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __COCOA_CC_MUTABLE_ARRAY_H__
|
|
||||||
#define __COCOA_CC_MUTABLE_ARRAY_H__
|
|
||||||
|
|
||||||
#include "CCObject.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
#include <vector>
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
|
|
||||||
// the element should be pointer of CCObject or it's sub class
|
|
||||||
template<class T = CCObject*>
|
|
||||||
class CCMutableArray : public CCObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef std::vector<T> CCObjectArray;
|
|
||||||
typedef typename CCObjectArray::iterator CCMutableArrayIterator;
|
|
||||||
typedef typename CCObjectArray::reverse_iterator CCMutableArrayRevIterator;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CCMutableArray(unsigned int uSize = 0)
|
|
||||||
{
|
|
||||||
if (uSize != 0)
|
|
||||||
m_array.reserve(uSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~CCMutableArray(void)
|
|
||||||
{
|
|
||||||
removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline unsigned int count(void)
|
|
||||||
{
|
|
||||||
return (unsigned int)m_array.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool containsObject(T pObject)
|
|
||||||
{
|
|
||||||
if (m_array.empty() || (! pObject))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bRet = false;
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
for (iter = m_array.begin(); iter != m_array.end(); ++iter)
|
|
||||||
{
|
|
||||||
if (*iter == pObject)
|
|
||||||
{
|
|
||||||
bRet = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
T getLastObject(void)
|
|
||||||
{
|
|
||||||
CCMutableArrayRevIterator iter = rbegin();
|
|
||||||
|
|
||||||
if (iter != m_array.rend())
|
|
||||||
return *iter;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
T getObjectAtIndex(unsigned int uIndex)
|
|
||||||
{
|
|
||||||
CCAssert(uIndex < count(), "");
|
|
||||||
|
|
||||||
if (uIndex >= count())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_array[uIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adding objects
|
|
||||||
void addObject(T pObject)
|
|
||||||
{
|
|
||||||
// make sure the pointer is not null
|
|
||||||
if (pObject == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the refrence
|
|
||||||
pObject->retain();
|
|
||||||
|
|
||||||
m_array.push_back(pObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addObjectsFromArray(CCMutableArray<T> *pArray)
|
|
||||||
{
|
|
||||||
if (pArray && pArray->count() > 0)
|
|
||||||
{
|
|
||||||
m_array.reserve(count() + pArray->count());
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
|
||||||
{
|
|
||||||
if (*iter)
|
|
||||||
(*iter)->retain();
|
|
||||||
m_array.push_back(*iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void insertObjectAtIndex(T pObject, unsigned int uIndex)
|
|
||||||
{
|
|
||||||
CCAssert(uIndex <= count(), "");
|
|
||||||
// make sure the object is not null
|
|
||||||
if (pObject == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add the reference of the object
|
|
||||||
pObject->retain();
|
|
||||||
|
|
||||||
// resize the capacity if the index out of it
|
|
||||||
if (uIndex >= m_array.capacity())
|
|
||||||
{
|
|
||||||
m_array.reserve(uIndex + 1);
|
|
||||||
m_array.push_back(pObject);
|
|
||||||
}
|
|
||||||
else // insert the object
|
|
||||||
m_array.insert(m_array.begin() + uIndex, pObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removing objects
|
|
||||||
void removeLastObject(bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
CCMutableArrayRevIterator it = m_array.rbegin();
|
|
||||||
if (it != m_array.rend())
|
|
||||||
{
|
|
||||||
if (bDeleteObject)
|
|
||||||
(*it)->release();
|
|
||||||
m_array.pop_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObject(T pObject, bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (m_array.empty() || (! pObject))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
int i;
|
|
||||||
for (iter = m_array.begin(), i = 0; iter != m_array.end(); ++iter, ++i)
|
|
||||||
{
|
|
||||||
if (*iter == pObject)
|
|
||||||
{
|
|
||||||
m_array.erase(iter);
|
|
||||||
|
|
||||||
if (bDeleteObject)
|
|
||||||
{
|
|
||||||
pObject->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectsInArray(CCMutableArray<T>* pDeleteArray)
|
|
||||||
{
|
|
||||||
if(pDeleteArray && pDeleteArray->count())
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator it;
|
|
||||||
for( it = pDeleteArray->m_array.begin(); it != pDeleteArray->m_array.end(); ++it)
|
|
||||||
{
|
|
||||||
removeObject(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectAtIndex(unsigned int uIndex, bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (m_array.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bDeleteObject)
|
|
||||||
{
|
|
||||||
T pObject = m_array.at(uIndex);
|
|
||||||
if (pObject)
|
|
||||||
{
|
|
||||||
pObject->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_array.erase(m_array.begin() + uIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeAllObjects(bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (bDeleteObject)
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
for (iter = m_array.begin(); iter != m_array.end(); ++iter)
|
|
||||||
(*iter)->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_array.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void replaceObjectAtIndex(unsigned int uIndex, T pObject, bool bDeleteObject = true)
|
|
||||||
{
|
|
||||||
if (bDeleteObject && m_array[uIndex])
|
|
||||||
{
|
|
||||||
m_array[uIndex]->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_array[uIndex] = pObject;
|
|
||||||
|
|
||||||
// add the ref
|
|
||||||
if (pObject)
|
|
||||||
{
|
|
||||||
pObject->retain();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayIterator begin(void)
|
|
||||||
{
|
|
||||||
return m_array.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayRevIterator rbegin(void)
|
|
||||||
{
|
|
||||||
return m_array.rbegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
CCMutableArrayIterator getLastValidIterator(void)
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator iter;
|
|
||||||
CCMutableArrayIterator ret;
|
|
||||||
for (iter = m_array.begin(); iter != m_array.end(); ++iter)
|
|
||||||
{
|
|
||||||
ret = iter;
|
|
||||||
if (! (*iter))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* end is a keyword of lua, so should use other name
|
|
||||||
* to export to lua
|
|
||||||
*/
|
|
||||||
inline CCMutableArrayIterator endToLua(void)
|
|
||||||
{
|
|
||||||
return m_array.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayIterator end(void)
|
|
||||||
{
|
|
||||||
return m_array.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline CCMutableArrayRevIterator rend(void)
|
|
||||||
{
|
|
||||||
return m_array.rend();
|
|
||||||
}
|
|
||||||
|
|
||||||
CCMutableArray<T>* copy(void)
|
|
||||||
{
|
|
||||||
CCMutableArray* pArray = new CCMutableArray();
|
|
||||||
|
|
||||||
pArray->m_array.assign(m_array.begin(), m_array.end());
|
|
||||||
|
|
||||||
if(pArray->count() > 0)
|
|
||||||
{
|
|
||||||
CCMutableArrayIterator it;
|
|
||||||
for(it = pArray->begin(); it != pArray->end(); ++it)
|
|
||||||
{
|
|
||||||
if(*it)
|
|
||||||
{
|
|
||||||
(*it)->retain();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
static CCMutableArray<T>* arrayWithObjects(T pObject1, ...)
|
|
||||||
{
|
|
||||||
CCMutableArray<T> *pArray = new CCMutableArray<T>();
|
|
||||||
pArray->autorelease();
|
|
||||||
|
|
||||||
va_list params;
|
|
||||||
va_start(params, pObject1);
|
|
||||||
|
|
||||||
T pFirst = pObject1;
|
|
||||||
while (pFirst)
|
|
||||||
{
|
|
||||||
pArray->addObject(pFirst);
|
|
||||||
pFirst = va_arg(params, T);
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(params);
|
|
||||||
|
|
||||||
return pArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
static CCMutableArray<T>* arrayWithArray(CCMutableArray<T> *pSrcArray)
|
|
||||||
{
|
|
||||||
CCMutableArray<T> *pDestArray = 0;
|
|
||||||
|
|
||||||
if (pSrcArray == 0)
|
|
||||||
{
|
|
||||||
pDestArray = new CCMutableArray<T>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pDestArray = pSrcArray->copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
pDestArray->autorelease();
|
|
||||||
|
|
||||||
return pDestArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<T> m_array;
|
|
||||||
};
|
|
||||||
|
|
||||||
}//namespace cocos2d
|
|
||||||
|
|
||||||
#endif // __COCOA_CC_MUTABLE_ARRAY_H__
|
|
|
@ -1,241 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
#ifndef __CCMUTABLE_DICTIONARY_H__
|
|
||||||
#define __CCMUTABLE_DICTIONARY_H__
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include "CCObject.h"
|
|
||||||
#include "CCMutableArray.h"
|
|
||||||
#include "ccMacros.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
namespace cocos2d {
|
|
||||||
class CCString;
|
|
||||||
|
|
||||||
template<class _KeyT, class _ValueT = CCObject*>
|
|
||||||
class CCMutableDictionary : public CCObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef std::map<_KeyT, _ValueT> CCObjectMap;
|
|
||||||
typedef typename CCObjectMap::iterator CCObjectMapIter;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
typedef pair<_KeyT, _ValueT> Int_Pair;
|
|
||||||
CCObjectMap m_Map;
|
|
||||||
bool m_bBegin;
|
|
||||||
CCObjectMapIter m_MapIter;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CCMutableDictionary(void)
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
~CCMutableDictionary(void)
|
|
||||||
{
|
|
||||||
removeAllObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// return the number of items
|
|
||||||
unsigned int count()
|
|
||||||
{
|
|
||||||
return m_Map.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// return all the keys
|
|
||||||
std::vector<_KeyT> allKeys()
|
|
||||||
{
|
|
||||||
std::vector<_KeyT> tRet;
|
|
||||||
if (m_Map.size() > 0)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
for( it = m_Map.begin(); it != m_Map.end(); ++it)
|
|
||||||
{
|
|
||||||
tRet.push_back(it->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @warning : We use '==' to compare two objects*/
|
|
||||||
std::vector<_KeyT> allKeysForObject(_ValueT object)
|
|
||||||
{
|
|
||||||
std::vector<_KeyT> tRet;
|
|
||||||
if (m_Map.size() > 0)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
for( it= m_Map.begin(); it != m_Map.end(); ++it)
|
|
||||||
{
|
|
||||||
if (it->second == object)
|
|
||||||
{
|
|
||||||
tRet.push_back(it->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ValueT objectForKey(const _KeyT& key) ///<
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
|
|
||||||
it = m_Map.find(key);
|
|
||||||
|
|
||||||
if(it == m_Map.end()) //no match case
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setObject(_ValueT pObject, const _KeyT& key)
|
|
||||||
{
|
|
||||||
pair<CCObjectMapIter, bool > pr;
|
|
||||||
|
|
||||||
pr = m_Map.insert( Int_Pair(key, pObject) );
|
|
||||||
|
|
||||||
if(pr.second == true)
|
|
||||||
{
|
|
||||||
pObject->retain();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeObjectForKey(const _KeyT& key)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
|
|
||||||
it = m_Map.find(key);
|
|
||||||
|
|
||||||
if(it == m_Map.end()) //no match case
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(it->second )
|
|
||||||
{
|
|
||||||
it->second->release() ;
|
|
||||||
m_Map.erase(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool begin()
|
|
||||||
{
|
|
||||||
if(m_Map.size() == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_MapIter = m_Map.begin();
|
|
||||||
m_bBegin = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ValueT next(_KeyT* key = NULL)
|
|
||||||
{
|
|
||||||
if(!m_bBegin)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
_ValueT pObject = m_MapIter->second;
|
|
||||||
|
|
||||||
if(m_MapIter == m_Map.end())
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(key)
|
|
||||||
{
|
|
||||||
*key = m_MapIter->first;
|
|
||||||
}
|
|
||||||
|
|
||||||
++m_MapIter;
|
|
||||||
|
|
||||||
if(m_MapIter == m_Map.end())
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* end is a keyword of lua, so should use other name
|
|
||||||
* to export to lua
|
|
||||||
*/
|
|
||||||
void endToLua()
|
|
||||||
{
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void end()
|
|
||||||
{
|
|
||||||
m_bBegin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeAllObjects()
|
|
||||||
{
|
|
||||||
if (m_Map.size() > 0)
|
|
||||||
{
|
|
||||||
CCObjectMapIter it;
|
|
||||||
for( it = m_Map.begin(); it != m_Map.end(); ++it)
|
|
||||||
{
|
|
||||||
if (it->second)
|
|
||||||
{
|
|
||||||
it->second->release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_Map.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
static CCMutableDictionary<_KeyT, _ValueT>* dictionaryWithDictionary(CCMutableDictionary<_KeyT, _ValueT>* srcDict)
|
|
||||||
{
|
|
||||||
CCMutableDictionary<_KeyT, _ValueT>* pNewDict = new CCMutableDictionary<_KeyT, _ValueT>();
|
|
||||||
|
|
||||||
srcDict->begin();
|
|
||||||
|
|
||||||
_KeyT key;
|
|
||||||
_ValueT value;
|
|
||||||
|
|
||||||
while( (value = srcDict->next(&key)) )
|
|
||||||
{
|
|
||||||
pNewDict->setObject(value, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
srcDict->end();
|
|
||||||
|
|
||||||
return pNewDict;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#define CCDictionary CCMutableDictionary
|
|
||||||
typedef CCDictionary<std::string, CCString*> CCStringToStringDictionary;
|
|
||||||
typedef CCDictionary<std::string, CCObject*> CCObjectDictionary;
|
|
||||||
|
|
||||||
}//namespace cocos2d
|
|
||||||
|
|
||||||
|
|
||||||
#endif //__CCMUTABLE_DICTIONARY_H__
|
|
|
@ -28,10 +28,10 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CCParticleBatchNode;
|
class CCParticleBatchNode;
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ public:
|
||||||
/** initializes a CCQuadParticleSystem from a CCDictionary.
|
/** initializes a CCQuadParticleSystem from a CCDictionary.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
bool initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary);
|
bool initWithDictionary(CCDictionary *dictionary);
|
||||||
|
|
||||||
//! Initializes a system with a fixed number of particles
|
//! Initializes a system with a fixed number of particles
|
||||||
virtual bool initWithTotalParticles(unsigned int numberOfParticles);
|
virtual bool initWithTotalParticles(unsigned int numberOfParticles);
|
||||||
|
@ -396,17 +396,17 @@ private:
|
||||||
/** Private method, return the string found by key in dict.
|
/** Private method, return the string found by key in dict.
|
||||||
@return "" if not found; return the string if found.
|
@return "" if not found; return the string if found.
|
||||||
*/
|
*/
|
||||||
inline const char * valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict)
|
inline const char * valueForKey(const char *key, CCDictionary *dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
CCString *pString = (CCString*)dict->objectForKey(key);
|
||||||
return pString ? pString->m_sString.c_str() : "";
|
return pString ? pString->m_sString.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__CCPARTICLE_SYSTEM_H__
|
#endif //__CCPARTICLE_SYSTEM_H__
|
||||||
|
|
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||||
#ifndef __CCSHADERCACHE_H__
|
#ifndef __CCSHADERCACHE_H__
|
||||||
#define __CCSHADERCACHE_H__
|
#define __CCSHADERCACHE_H__
|
||||||
|
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool init();
|
bool init();
|
||||||
|
|
||||||
CCMutableDictionary<std::string, CCGLProgram*>* m_pPrograms;
|
CCDictionary* m_pPrograms;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCTextureAtlas.h"
|
#include "CCTextureAtlas.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
#include "CCProtocols.h"
|
#include "CCProtocols.h"
|
||||||
#include "CCTextureAtlas.h"
|
#include "CCTextureAtlas.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d
|
namespace cocos2d
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,7 +38,7 @@ THE SOFTWARE.
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
class CCSprite;
|
class CCSprite;
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
/*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames.
|
||||||
*/
|
*/
|
||||||
void addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *pobDictionary, CCTexture2D *pobTexture);
|
void addSpriteFramesWithDictionary(CCDictionary* pobDictionary, CCTexture2D *pobTexture);
|
||||||
|
|
||||||
/** Adds multiple Sprite Frames from a plist file.
|
/** Adds multiple Sprite Frames from a plist file.
|
||||||
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
|
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
|
||||||
|
@ -103,7 +103,7 @@ public:
|
||||||
/** Removes multiple Sprite Frames from CCDictionary.
|
/** Removes multiple Sprite Frames from CCDictionary.
|
||||||
* @since v0.99.5
|
* @since v0.99.5
|
||||||
*/
|
*/
|
||||||
void removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary);
|
void removeSpriteFramesFromDictionary(CCDictionary* dictionary);
|
||||||
|
|
||||||
/** Removes all Sprite Frames associated with the specified textures.
|
/** Removes all Sprite Frames associated with the specified textures.
|
||||||
* It is convinient to call this method when a specific texture needs to be removed.
|
* It is convinient to call this method when a specific texture needs to be removed.
|
||||||
|
@ -126,11 +126,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCSpriteFrameCache(void) : m_pSpriteFrames(NULL), m_pSpriteFramesAliases(NULL){}
|
CCSpriteFrameCache(void) : m_pSpriteFrames(NULL), m_pSpriteFramesAliases(NULL){}
|
||||||
const char * valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict);
|
const char * valueForKey(const char* key, CCDictionary* dict);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCDictionary<std::string, CCSpriteFrame*> *m_pSpriteFrames;
|
CCDictionary* m_pSpriteFrames;
|
||||||
CCDictionary<std::string, CCString*> *m_pSpriteFramesAliases;
|
CCDictionary* m_pSpriteFramesAliases;
|
||||||
};
|
};
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,11 @@ namespace cocos2d {
|
||||||
return m_sString;
|
return m_sString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* c_str()
|
||||||
|
{
|
||||||
|
return m_sString.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
bool isEmpty()
|
bool isEmpty()
|
||||||
{
|
{
|
||||||
return m_sString.empty();
|
return m_sString.empty();
|
||||||
|
|
|
@ -79,7 +79,7 @@ class CC_DLL CCTMXLayer : public CCSpriteBatchNode
|
||||||
/** Layer orientation, which is the same as the map orientation */
|
/** Layer orientation, which is the same as the map orientation */
|
||||||
CC_SYNTHESIZE(unsigned int, m_uLayerOrientation, LayerOrientation);
|
CC_SYNTHESIZE(unsigned int, m_uLayerOrientation, LayerOrientation);
|
||||||
/** properties from the layer. They can be added using Tiled */
|
/** properties from the layer. They can be added using Tiled */
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
CCTMXLayer();
|
CCTMXLayer();
|
||||||
virtual ~CCTMXLayer();
|
virtual ~CCTMXLayer();
|
||||||
|
|
|
@ -29,8 +29,8 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ namespace cocos2d {
|
||||||
/** offset position of child objects */
|
/** offset position of child objects */
|
||||||
CC_SYNTHESIZE_PASS_BY_REF(CCPoint, m_tPositionOffset, PositionOffset);
|
CC_SYNTHESIZE_PASS_BY_REF(CCPoint, m_tPositionOffset, PositionOffset);
|
||||||
/** list of properties stored in a dictionary */
|
/** list of properties stored in a dictionary */
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
/** array of the objects */
|
/** array of the objects */
|
||||||
CC_PROPERTY(CCMutableArray<CCStringToStringDictionary*>*, m_pObjects, Objects);
|
CC_PROPERTY(CCArray*, m_pObjects, Objects);
|
||||||
public:
|
public:
|
||||||
CCTMXObjectGroup();
|
CCTMXObjectGroup();
|
||||||
virtual ~CCTMXObjectGroup();
|
virtual ~CCTMXObjectGroup();
|
||||||
|
@ -58,7 +58,7 @@ namespace cocos2d {
|
||||||
/** return the dictionary for the specific object name.
|
/** return the dictionary for the specific object name.
|
||||||
It will return the 1st object found on the array for the given name.
|
It will return the 1st object found on the array for the given name.
|
||||||
*/
|
*/
|
||||||
CCStringToStringDictionary *objectNamed(const char *objectName);
|
CCDictionary* objectNamed(const char *objectName);
|
||||||
protected:
|
protected:
|
||||||
/** name of the group */
|
/** name of the group */
|
||||||
std::string m_sGroupName;
|
std::string m_sGroupName;
|
||||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
||||||
#include "CCNode.h"
|
#include "CCNode.h"
|
||||||
#include "CCTMXObjectGroup.h"
|
#include "CCTMXObjectGroup.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CCTMXObjectGroup;
|
class CCTMXObjectGroup;
|
||||||
class CCTMXLayer;
|
class CCTMXLayer;
|
||||||
|
@ -109,9 +109,9 @@ namespace cocos2d {
|
||||||
/** map orientation */
|
/** map orientation */
|
||||||
CC_SYNTHESIZE(int, m_nMapOrientation, MapOrientation);
|
CC_SYNTHESIZE(int, m_nMapOrientation, MapOrientation);
|
||||||
/** object groups */
|
/** object groups */
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXObjectGroup*>*, m_pObjectGroups, ObjectGroups);
|
CC_PROPERTY(CCArray*, m_pObjectGroups, ObjectGroups);
|
||||||
/** properties */
|
/** properties */
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
CCTMXTiledMap();
|
CCTMXTiledMap();
|
||||||
virtual ~CCTMXTiledMap();
|
virtual ~CCTMXTiledMap();
|
||||||
|
@ -138,7 +138,7 @@ namespace cocos2d {
|
||||||
CCString *propertyNamed(const char *propertyName);
|
CCString *propertyNamed(const char *propertyName);
|
||||||
|
|
||||||
/** return properties dictionary for tile GID */
|
/** return properties dictionary for tile GID */
|
||||||
CCDictionary<std::string, CCString*> *propertiesForGID(int GID);
|
CCDictionary* propertiesForGID(int GID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
CCTMXLayer * parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo);
|
||||||
|
@ -146,11 +146,12 @@ namespace cocos2d {
|
||||||
void buildWithMapInfo(CCTMXMapInfo* mapInfo);
|
void buildWithMapInfo(CCTMXMapInfo* mapInfo);
|
||||||
protected:
|
protected:
|
||||||
//! tile properties
|
//! tile properties
|
||||||
CCDictionary<int, CCStringToStringDictionary*> *m_pTileProperties;
|
CCDictionary* m_pTileProperties;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__CCTMX_TILE_MAP_H__
|
#endif //__CCTMX_TILE_MAP_H__
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#ifndef __CC_TM_XML_PARSER__
|
#ifndef __CC_TM_XML_PARSER__
|
||||||
#define __CC_TM_XML_PARSER__
|
#define __CC_TM_XML_PARSER__
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
|
|
||||||
#include "../platform/CCSAXParser.h"
|
#include "../platform/CCSAXParser.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CCTMXObjectGroup;
|
class CCTMXObjectGroup;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ namespace cocos2d {
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCTMXLayerInfo : public CCObject
|
class CC_DLL CCTMXLayerInfo : public CCObject
|
||||||
{
|
{
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
std::string m_sName;
|
std::string m_sName;
|
||||||
CCSize m_tLayerSize;
|
CCSize m_tLayerSize;
|
||||||
|
@ -148,11 +148,11 @@ namespace cocos2d {
|
||||||
/// tiles width & height
|
/// tiles width & height
|
||||||
CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tTileSize, TileSize);
|
CC_SYNTHESIZE_PASS_BY_REF(CCSize, m_tTileSize, TileSize);
|
||||||
/// Layers
|
/// Layers
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXLayerInfo*>*, m_pLayers, Layers);
|
CC_PROPERTY(CCArray*, m_pLayers, Layers);
|
||||||
/// tilesets
|
/// tilesets
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXTilesetInfo*>*, m_pTilesets, Tilesets);
|
CC_PROPERTY(CCArray*, m_pTilesets, Tilesets);
|
||||||
/// ObjectGroups
|
/// ObjectGroups
|
||||||
CC_PROPERTY(CCMutableArray<CCTMXObjectGroup*>*, m_pObjectGroups, ObjectGroups);
|
CC_PROPERTY(CCArray*, m_pObjectGroups, ObjectGroups);
|
||||||
/// parent element
|
/// parent element
|
||||||
CC_SYNTHESIZE(int, m_nParentElement, ParentElement);
|
CC_SYNTHESIZE(int, m_nParentElement, ParentElement);
|
||||||
/// parent GID
|
/// parent GID
|
||||||
|
@ -162,7 +162,7 @@ namespace cocos2d {
|
||||||
/// is stroing characters?
|
/// is stroing characters?
|
||||||
CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);
|
CC_SYNTHESIZE(bool, m_bStoringCharacters, StoringCharacters);
|
||||||
/// properties
|
/// properties
|
||||||
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
|
CC_PROPERTY(CCDictionary*, m_pProperties, Properties);
|
||||||
public:
|
public:
|
||||||
CCTMXMapInfo();
|
CCTMXMapInfo();
|
||||||
virtual ~CCTMXMapInfo();
|
virtual ~CCTMXMapInfo();
|
||||||
|
@ -181,8 +181,8 @@ namespace cocos2d {
|
||||||
/* handles the work of parsing for parseXMLFile: and parseXMLString: */
|
/* handles the work of parsing for parseXMLFile: and parseXMLString: */
|
||||||
bool parseXMLData(const char* data);
|
bool parseXMLData(const char* data);
|
||||||
|
|
||||||
CCDictionary<int, CCStringToStringDictionary*> * getTileProperties();
|
CCDictionary* getTileProperties();
|
||||||
void setTileProperties(CCDictionary<int, CCStringToStringDictionary*> * tileProperties);
|
void setTileProperties(CCDictionary* tileProperties);
|
||||||
|
|
||||||
// implement pure virtual methods of CCSAXDelegator
|
// implement pure virtual methods of CCSAXDelegator
|
||||||
void startElement(void *ctx, const char *name, const char **atts);
|
void startElement(void *ctx, const char *name, const char **atts);
|
||||||
|
@ -203,10 +203,10 @@ namespace cocos2d {
|
||||||
//! current string
|
//! current string
|
||||||
std::string m_sCurrentString;
|
std::string m_sCurrentString;
|
||||||
//! tile properties
|
//! tile properties
|
||||||
CCDictionary<int, CCStringToStringDictionary*>* m_pTileProperties;
|
CCDictionary* m_pTileProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class CCImage;
|
||||||
class CC_DLL CCTextureCache : public CCObject
|
class CC_DLL CCTextureCache : public CCObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CCMutableDictionary<std::string, CCTexture2D*> * m_pTextures;
|
CCDictionary* m_pTextures;
|
||||||
//pthread_mutex_t *m_pDictLock;
|
//pthread_mutex_t *m_pDictLock;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCGL.h"
|
#include "CCGL.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCTouchDelegateProtocol.h"
|
#include "CCTouchDelegateProtocol.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -146,19 +146,19 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void forceRemoveDelegate(CCTouchDelegate *pDelegate);
|
void forceRemoveDelegate(CCTouchDelegate *pDelegate);
|
||||||
void forceAddHandler(CCTouchHandler *pHandler, CCMutableArray<CCTouchHandler*> *pArray);
|
void forceAddHandler(CCTouchHandler *pHandler, CCArray* pArray);
|
||||||
void forceRemoveAllDelegates(void);
|
void forceRemoveAllDelegates(void);
|
||||||
void rearrangeHandlers(CCMutableArray<CCTouchHandler*> *pArray);
|
void rearrangeHandlers(CCArray* pArray);
|
||||||
CCTouchHandler* findHandler(CCMutableArray<CCTouchHandler*> *pArray, CCTouchDelegate *pDelegate);
|
CCTouchHandler* findHandler(CCArray* pArray, CCTouchDelegate *pDelegate);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCMutableArray<CCTouchHandler*> *m_pTargetedHandlers;
|
CCArray* m_pTargetedHandlers;
|
||||||
CCMutableArray<CCTouchHandler*> *m_pStandardHandlers;
|
CCArray* m_pStandardHandlers;
|
||||||
|
|
||||||
bool m_bLocked;
|
bool m_bLocked;
|
||||||
bool m_bToAdd;
|
bool m_bToAdd;
|
||||||
bool m_bToRemove;
|
bool m_bToRemove;
|
||||||
CCMutableArray<CCTouchHandler*> *m_pHandlersToAdd;
|
CCArray* m_pHandlersToAdd;
|
||||||
struct _ccCArray *m_pHandlersToRemove;
|
struct _ccCArray *m_pHandlersToRemove;
|
||||||
bool m_bToQuit;
|
bool m_bToQuit;
|
||||||
bool m_bDispatchEvents;
|
bool m_bDispatchEvents;
|
||||||
|
|
|
@ -97,8 +97,8 @@ THE SOFTWARE.
|
||||||
// cocoa includes
|
// cocoa includes
|
||||||
//
|
//
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "CCZone.h"
|
#include "CCZone.h"
|
||||||
#include "CCGeometry.h"
|
#include "CCGeometry.h"
|
||||||
|
|
|
@ -38,7 +38,8 @@ CCKeypadDispatcher::CCKeypadDispatcher()
|
||||||
, m_bToAdd(false)
|
, m_bToAdd(false)
|
||||||
, m_bToRemove(false)
|
, m_bToRemove(false)
|
||||||
{
|
{
|
||||||
m_pDelegates = new KeypadDelegateArray;
|
m_pDelegates = CCArray::array();
|
||||||
|
m_pDelegates->retain();
|
||||||
|
|
||||||
m_pHandlersToAdd = ccCArrayNew(8);
|
m_pHandlersToAdd = ccCArrayNew(8);
|
||||||
m_pHandlersToRemove = ccCArrayNew(8);
|
m_pHandlersToRemove = ccCArrayNew(8);
|
||||||
|
@ -124,12 +125,11 @@ void CCKeypadDispatcher::forceAddDelegate(CCKeypadDelegate* pDelegate)
|
||||||
|
|
||||||
void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
|
void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
|
||||||
{
|
{
|
||||||
CCKeypadHandler *pHandler;
|
CCKeypadHandler* pHandler = NULL;
|
||||||
CCMutableArray<CCKeypadHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pDelegates, pObj)
|
||||||
for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCKeypadHandler*)pObj;
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
m_pDelegates->removeObject(pHandler);
|
m_pDelegates->removeObject(pHandler);
|
||||||
|
@ -140,19 +140,19 @@ void CCKeypadDispatcher::forceRemoveDelegate(CCKeypadDelegate* pDelegate)
|
||||||
|
|
||||||
bool CCKeypadDispatcher::dispatchKeypadMSG(ccKeypadMSGType nMsgType)
|
bool CCKeypadDispatcher::dispatchKeypadMSG(ccKeypadMSGType nMsgType)
|
||||||
{
|
{
|
||||||
CCKeypadHandler *pHandler;
|
CCKeypadHandler* pHandler = NULL;
|
||||||
CCKeypadDelegate *pDelegate;
|
CCKeypadDelegate* pDelegate = NULL;
|
||||||
CCMutableArray<CCKeypadHandler*>::CCMutableArrayIterator iter;
|
|
||||||
|
|
||||||
m_bLocked = true;
|
m_bLocked = true;
|
||||||
|
|
||||||
if (m_pDelegates->count() > 0)
|
if (m_pDelegates->count() > 0)
|
||||||
{
|
{
|
||||||
for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pDelegates, pObj)
|
||||||
{
|
{
|
||||||
CC_BREAK_IF(!(*iter));
|
CC_BREAK_IF(!pObj);
|
||||||
|
|
||||||
pHandler = *iter;
|
pHandler = (CCKeypadHandler*)pObj;
|
||||||
pDelegate = pHandler->getDelegate();
|
pDelegate = pHandler->getDelegate();
|
||||||
|
|
||||||
switch (nMsgType)
|
switch (nMsgType)
|
||||||
|
|
|
@ -33,7 +33,7 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
||||||
#include "CCLabelBMFont.h"
|
#include "CCLabelBMFont.h"
|
||||||
|
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include "CCConfiguration.h"
|
#include "CCConfiguration.h"
|
||||||
#include "CCDrawingPrimitives.h"
|
#include "CCDrawingPrimitives.h"
|
||||||
#include "CCSprite.h"
|
#include "CCSprite.h"
|
||||||
|
@ -42,26 +42,26 @@ http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "support/data_support/uthash.h"
|
#include "support/data_support/uthash.h"
|
||||||
|
|
||||||
namespace cocos2d{
|
NS_CC_BEGIN
|
||||||
|
|
||||||
//
|
//
|
||||||
//FNTConfig Cache - free functions
|
//FNTConfig Cache - free functions
|
||||||
//
|
//
|
||||||
CCMutableDictionary<std::string, CCBMFontConfiguration*> *configurations = NULL;
|
CCDictionary* configurations = NULL;
|
||||||
CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile)
|
CCBMFontConfiguration* FNTConfigLoadFile( const char *fntFile)
|
||||||
{
|
{
|
||||||
CCBMFontConfiguration* pRet = NULL;
|
CCBMFontConfiguration* pRet = NULL;
|
||||||
|
|
||||||
if( configurations == NULL )
|
if( configurations == NULL )
|
||||||
{
|
{
|
||||||
configurations = new CCMutableDictionary<std::string, CCBMFontConfiguration*>();
|
configurations = new CCDictionary();
|
||||||
}
|
}
|
||||||
std::string key(fntFile);
|
|
||||||
pRet = configurations->objectForKey(key);
|
pRet = (CCBMFontConfiguration*)configurations->objectForKey(fntFile);
|
||||||
if( pRet == NULL )
|
if( pRet == NULL )
|
||||||
{
|
{
|
||||||
pRet = CCBMFontConfiguration::configurationWithFNTFile(fntFile);
|
pRet = CCBMFontConfiguration::configurationWithFNTFile(fntFile);
|
||||||
configurations->setObject(pRet, key);
|
configurations->setObject(pRet, fntFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pRet;
|
return pRet;
|
||||||
|
@ -100,6 +100,7 @@ namespace cocos2d{
|
||||||
CC_SAFE_DELETE(pRet);
|
CC_SAFE_DELETE(pRet);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCBMFontConfiguration::initWithFNTfile(const char *FNTfile)
|
bool CCBMFontConfiguration::initWithFNTfile(const char *FNTfile)
|
||||||
{
|
{
|
||||||
CCAssert(FNTfile != NULL && strlen(FNTfile)!=0, "");
|
CCAssert(FNTfile != NULL && strlen(FNTfile)!=0, "");
|
||||||
|
@ -872,4 +873,4 @@ namespace cocos2d{
|
||||||
}
|
}
|
||||||
#endif // CC_LABELBMFONT_DEBUG_DRAW
|
#endif // CC_LABELBMFONT_DEBUG_DRAW
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
|
@ -745,7 +745,8 @@ void CCLayerMultiplex::addLayer(CCLayer* layer)
|
||||||
|
|
||||||
bool CCLayerMultiplex::initWithLayer(CCLayer* layer)
|
bool CCLayerMultiplex::initWithLayer(CCLayer* layer)
|
||||||
{
|
{
|
||||||
m_pLayers = new CCMutableArray<CCLayer*>(1);
|
m_pLayers = CCArray::array();
|
||||||
|
m_pLayers->retain();
|
||||||
m_pLayers->addObject(layer);
|
m_pLayers->addObject(layer);
|
||||||
m_nEnabledLayer = 0;
|
m_nEnabledLayer = 0;
|
||||||
this->addChild(layer);
|
this->addChild(layer);
|
||||||
|
@ -754,8 +755,8 @@ bool CCLayerMultiplex::initWithLayer(CCLayer* layer)
|
||||||
|
|
||||||
bool CCLayerMultiplex::initWithLayers(CCLayer *layer, va_list params)
|
bool CCLayerMultiplex::initWithLayers(CCLayer *layer, va_list params)
|
||||||
{
|
{
|
||||||
m_pLayers = new CCMutableArray<CCLayer*>(5);
|
m_pLayers = CCArray::arrayWithCapacity(5);
|
||||||
//m_pLayers->retain();
|
m_pLayers->retain();
|
||||||
|
|
||||||
m_pLayers->addObject(layer);
|
m_pLayers->addObject(layer);
|
||||||
|
|
||||||
|
@ -766,7 +767,7 @@ bool CCLayerMultiplex::initWithLayers(CCLayer *layer, va_list params)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nEnabledLayer = 0;
|
m_nEnabledLayer = 0;
|
||||||
this->addChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer));
|
this->addChild((CCNode*)m_pLayers->objectAtIndex(m_nEnabledLayer));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -776,24 +777,24 @@ void CCLayerMultiplex::switchTo(unsigned int n)
|
||||||
{
|
{
|
||||||
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
||||||
|
|
||||||
this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true);
|
this->removeChild((CCNode*)m_pLayers->objectAtIndex(m_nEnabledLayer), true);
|
||||||
|
|
||||||
m_nEnabledLayer = n;
|
m_nEnabledLayer = n;
|
||||||
|
|
||||||
this->addChild(m_pLayers->getObjectAtIndex(n));
|
this->addChild((CCNode*)m_pLayers->objectAtIndex(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCLayerMultiplex::switchToAndReleaseMe(unsigned int n)
|
void CCLayerMultiplex::switchToAndReleaseMe(unsigned int n)
|
||||||
{
|
{
|
||||||
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
CCAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
||||||
|
|
||||||
this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true);
|
this->removeChild((CCNode*)m_pLayers->objectAtIndex(m_nEnabledLayer), true);
|
||||||
|
|
||||||
//[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
//[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
||||||
m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL);
|
m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL);
|
||||||
|
|
||||||
m_nEnabledLayer = n;
|
m_nEnabledLayer = n;
|
||||||
|
|
||||||
this->addChild(m_pLayers->getObjectAtIndex(n));
|
this->addChild((CCNode*)m_pLayers->objectAtIndex(n));
|
||||||
}
|
}
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
|
@ -33,7 +33,7 @@ THE SOFTWARE.
|
||||||
#include "CCScriptSupport.h"
|
#include "CCScriptSupport.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
namespace cocos2d{
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static unsigned int _fontSize = kCCItemSize;
|
static unsigned int _fontSize = kCCItemSize;
|
||||||
static std::string _fontName = "Marker Felt";
|
static std::string _fontName = "Marker Felt";
|
||||||
|
@ -658,13 +658,14 @@ namespace cocos2d{
|
||||||
//
|
//
|
||||||
// MenuItemToggle
|
// MenuItemToggle
|
||||||
//
|
//
|
||||||
void CCMenuItemToggle::setSubItems(CCMutableArray<CCMenuItem*>* var)
|
void CCMenuItemToggle::setSubItems(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pSubItems);
|
CC_SAFE_RELEASE(m_pSubItems);
|
||||||
m_pSubItems = var;
|
m_pSubItems = var;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCMenuItem*> *CCMenuItemToggle::getSubItems()
|
|
||||||
|
CCArray* CCMenuItemToggle::getSubItems()
|
||||||
{
|
{
|
||||||
return m_pSubItems;
|
return m_pSubItems;
|
||||||
}
|
}
|
||||||
|
@ -678,10 +679,12 @@ namespace cocos2d{
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCMenuItemToggle::initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args)
|
bool CCMenuItemToggle::initWithTarget(CCObject* target, SEL_MenuHandler selector, CCMenuItem* item, va_list args)
|
||||||
{
|
{
|
||||||
CCMenuItem::initWithTarget(target, selector);
|
CCMenuItem::initWithTarget(target, selector);
|
||||||
this->m_pSubItems = new CCMutableArray<CCMenuItem*>();
|
this->m_pSubItems = CCArray::array();
|
||||||
|
this->m_pSubItems->retain();
|
||||||
int z = 0;
|
int z = 0;
|
||||||
CCMenuItem *i = item;
|
CCMenuItem *i = item;
|
||||||
while(i)
|
while(i)
|
||||||
|
@ -706,7 +709,8 @@ namespace cocos2d{
|
||||||
bool CCMenuItemToggle::initWithItem(CCMenuItem *item)
|
bool CCMenuItemToggle::initWithItem(CCMenuItem *item)
|
||||||
{
|
{
|
||||||
CCMenuItem::initWithTarget(NULL, NULL);
|
CCMenuItem::initWithTarget(NULL, NULL);
|
||||||
this->m_pSubItems = new CCMutableArray<CCMenuItem*>();
|
this->m_pSubItems = CCArray::array();
|
||||||
|
this->m_pSubItems->retain();
|
||||||
m_pSubItems->addObject(item);
|
m_pSubItems->addObject(item);
|
||||||
m_uSelectedIndex = UINT_MAX;
|
m_uSelectedIndex = UINT_MAX;
|
||||||
this->setSelectedIndex(0);
|
this->setSelectedIndex(0);
|
||||||
|
@ -733,7 +737,7 @@ namespace cocos2d{
|
||||||
currentItem->removeFromParentAndCleanup(false);
|
currentItem->removeFromParentAndCleanup(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItem *item = m_pSubItems->getObjectAtIndex(m_uSelectedIndex);
|
CCMenuItem* item = (CCMenuItem*)m_pSubItems->objectAtIndex(m_uSelectedIndex);
|
||||||
this->addChild(item, 0, kCurrentItem);
|
this->addChild(item, 0, kCurrentItem);
|
||||||
const CCSize& s = item->getContentSize();
|
const CCSize& s = item->getContentSize();
|
||||||
this->setContentSize(s);
|
this->setContentSize(s);
|
||||||
|
@ -747,12 +751,12 @@ namespace cocos2d{
|
||||||
void CCMenuItemToggle::selected()
|
void CCMenuItemToggle::selected()
|
||||||
{
|
{
|
||||||
CCMenuItem::selected();
|
CCMenuItem::selected();
|
||||||
m_pSubItems->getObjectAtIndex(m_uSelectedIndex)->selected();
|
((CCMenuItem*)(m_pSubItems->objectAtIndex(m_uSelectedIndex)))->selected();
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::unselected()
|
void CCMenuItemToggle::unselected()
|
||||||
{
|
{
|
||||||
CCMenuItem::unselected();
|
CCMenuItem::unselected();
|
||||||
m_pSubItems->getObjectAtIndex(m_uSelectedIndex)->unselected();
|
((CCMenuItem*)(m_pSubItems->objectAtIndex(m_uSelectedIndex)))->unselected();
|
||||||
}
|
}
|
||||||
void CCMenuItemToggle::activate()
|
void CCMenuItemToggle::activate()
|
||||||
{
|
{
|
||||||
|
@ -770,16 +774,18 @@ namespace cocos2d{
|
||||||
|
|
||||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it)
|
CCARRAY_FOREACH(m_pSubItems, pObj)
|
||||||
{
|
{
|
||||||
(*it)->setIsEnabled(enabled);
|
CCMenuItem* pItem = (CCMenuItem*)pObj;
|
||||||
|
pItem->setIsEnabled(enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMenuItem* CCMenuItemToggle::selectedItem()
|
CCMenuItem* CCMenuItemToggle::selectedItem()
|
||||||
{
|
{
|
||||||
return m_pSubItems->getObjectAtIndex(m_uSelectedIndex);
|
return (CCMenuItem*)m_pSubItems->objectAtIndex(m_uSelectedIndex);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//CCMenuItemToggle - CCRGBAProtocol protocol
|
//CCMenuItemToggle - CCRGBAProtocol protocol
|
||||||
|
@ -793,10 +799,11 @@ namespace cocos2d{
|
||||||
m_cOpacity = opacity;
|
m_cOpacity = opacity;
|
||||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it)
|
CCARRAY_FOREACH(m_pSubItems, pObj)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(*it)->setOpacity(opacity);
|
CCMenuItem* pItem = (CCMenuItem*)pObj;
|
||||||
|
dynamic_cast<CCRGBAProtocol*>(pItem)->setOpacity(opacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -809,12 +816,13 @@ namespace cocos2d{
|
||||||
m_tColor = color;
|
m_tColor = color;
|
||||||
if(m_pSubItems && m_pSubItems->count() > 0)
|
if(m_pSubItems && m_pSubItems->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCMenuItem*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = m_pSubItems->begin(); it != m_pSubItems->end(); ++it)
|
CCARRAY_FOREACH(m_pSubItems, pObj)
|
||||||
{
|
{
|
||||||
dynamic_cast<CCRGBAProtocol*>(*it)->setColor(color);
|
CCMenuItem* pItem = (CCMenuItem*)pObj;
|
||||||
|
dynamic_cast<CCRGBAProtocol*>(pItem)->setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cocos2d
|
NS_CC_END
|
||||||
|
|
|
@ -150,7 +150,7 @@ bool CCParticleSystem::initWithFile(const char *plistFile)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
m_sPlistFile = CCFileUtils::fullPathFromRelativePath(plistFile);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
|
CCDictionary *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(m_sPlistFile.c_str());
|
||||||
|
|
||||||
CCAssert( dict != NULL, "Particles: file not found");
|
CCAssert( dict != NULL, "Particles: file not found");
|
||||||
bRet = this->initWithDictionary(dict);
|
bRet = this->initWithDictionary(dict);
|
||||||
|
@ -159,7 +159,7 @@ bool CCParticleSystem::initWithFile(const char *plistFile)
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary)
|
bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
|
|
|
@ -52,14 +52,14 @@ typedef enum
|
||||||
class CCDictMaker : public CCSAXDelegator
|
class CCDictMaker : public CCSAXDelegator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCDictionary<std::string, CCObject*> *m_pRootDict;
|
CCDictionary *m_pRootDict;
|
||||||
CCDictionary<std::string, CCObject*> *m_pCurDict;
|
CCDictionary *m_pCurDict;
|
||||||
std::stack<CCDictionary<std::string, CCObject*>*> m_tDictStack;
|
std::stack<CCDictionary*> m_tDictStack;
|
||||||
std::string m_sCurKey;///< parsed key
|
std::string m_sCurKey;///< parsed key
|
||||||
CCSAXState m_tState;
|
CCSAXState m_tState;
|
||||||
CCMutableArray<CCObject*> *m_pArray;
|
CCArray* m_pArray;
|
||||||
|
|
||||||
std::stack<CCMutableArray<CCObject*>*> m_tArrayStack;
|
std::stack<CCArray*> m_tArrayStack;
|
||||||
std::stack<CCSAXState> m_tStateStack;
|
std::stack<CCSAXState> m_tStateStack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary* dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCSAXParser parser;
|
CCSAXParser parser;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public:
|
||||||
std::string sName((char*)name);
|
std::string sName((char*)name);
|
||||||
if( sName == "dict" )
|
if( sName == "dict" )
|
||||||
{
|
{
|
||||||
m_pCurDict = new CCDictionary<std::string, CCObject*>();
|
m_pCurDict = new CCDictionary();
|
||||||
if(! m_pRootDict)
|
if(! m_pRootDict)
|
||||||
{
|
{
|
||||||
// Because it will call m_pCurDict->release() later, so retain here.
|
// Because it will call m_pCurDict->release() later, so retain here.
|
||||||
|
@ -120,8 +120,8 @@ public:
|
||||||
{
|
{
|
||||||
// add the dictionary into the pre dictionary
|
// add the dictionary into the pre dictionary
|
||||||
CCAssert(! m_tDictStack.empty(), "The state is wrong!");
|
CCAssert(! m_tDictStack.empty(), "The state is wrong!");
|
||||||
CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
|
CCDictionary* pPreDict = m_tDictStack.top();
|
||||||
pPreDict->setObject(m_pCurDict, m_sCurKey);
|
pPreDict->setObject(m_pCurDict, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pCurDict->release();
|
m_pCurDict->release();
|
||||||
|
@ -149,17 +149,18 @@ public:
|
||||||
else if (sName == "array")
|
else if (sName == "array")
|
||||||
{
|
{
|
||||||
m_tState = SAX_ARRAY;
|
m_tState = SAX_ARRAY;
|
||||||
m_pArray = new CCMutableArray<CCObject*>();
|
m_pArray = CCArray::array();
|
||||||
|
m_pArray->retain();
|
||||||
|
|
||||||
CCSAXState preState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
|
CCSAXState preState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
|
||||||
if (preState == SAX_DICT)
|
if (preState == SAX_DICT)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(m_pArray, m_sCurKey);
|
m_pCurDict->setObject(m_pArray, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
else if (preState == SAX_ARRAY)
|
else if (preState == SAX_ARRAY)
|
||||||
{
|
{
|
||||||
CCAssert(! m_tArrayStack.empty(), "The state is worng!");
|
CCAssert(! m_tArrayStack.empty(), "The state is worng!");
|
||||||
CCMutableArray<CCObject*>* pPreArray = m_tArrayStack.top();
|
CCArray* pPreArray = m_tArrayStack.top();
|
||||||
pPreArray->addObject(m_pArray);
|
pPreArray->addObject(m_pArray);
|
||||||
}
|
}
|
||||||
m_pArray->release();
|
m_pArray->release();
|
||||||
|
@ -205,7 +206,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(str, m_sCurKey);
|
m_pCurDict->setObject(str, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
str->release();
|
str->release();
|
||||||
}
|
}
|
||||||
|
@ -218,7 +219,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(str, m_sCurKey);
|
m_pCurDict->setObject(str, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
str->release();
|
str->release();
|
||||||
}
|
}
|
||||||
|
@ -254,7 +255,7 @@ public:
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == curState)
|
else if (SAX_DICT == curState)
|
||||||
{
|
{
|
||||||
m_pCurDict->setObject(pText, m_sCurKey);
|
m_pCurDict->setObject(pText, m_sCurKey.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -287,15 +288,15 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary* CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCDictionary<std::string, CCObject*> *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
CCDictionary* ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||||
ret->autorelease();
|
ret->autorelease();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
CCDictionary* CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCDictMaker tMaker;
|
CCDictMaker tMaker;
|
||||||
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
return tMaker.dictionaryWithContentsOfFile(pFileName);
|
||||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
||||||
#define __CC_FILEUTILS_PLATFORM_H__
|
#define __CC_FILEUTILS_PLATFORM_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
NS_CC_BEGIN;
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
@ -87,13 +87,13 @@ public:
|
||||||
@param pFileName The file name of *.plist file
|
@param pFileName The file name of *.plist file
|
||||||
@return The CCDictionary pointer generated from the file
|
@return The CCDictionary pointer generated from the file
|
||||||
*/
|
*/
|
||||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
|
static CCDictionary* dictionaryWithContentsOfFile(const char *pFileName);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@brief The same meaning as dictionaryWithContentsOfFile(), but it doesn't call autorelease, so the
|
@brief The same meaning as dictionaryWithContentsOfFile(), but it doesn't call autorelease, so the
|
||||||
invoker should call release().
|
invoker should call release().
|
||||||
*/
|
*/
|
||||||
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFileThreadSafe(const char *pFileName);
|
static CCDictionary* dictionaryWithContentsOfFileThreadSafe(const char *pFileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get the writeable path
|
@brief Get the writeable path
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCSAXParser.h"
|
#include "CCSAXParser.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/xmlmemory.h>
|
#include <libxml/xmlmemory.h>
|
||||||
|
|
|
@ -211,6 +211,10 @@
|
||||||
RelativePath="..\cocoa\CCData.cpp"
|
RelativePath="..\cocoa\CCData.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\cocoa\CCDictionary.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\cocoa\CCGeometry.cpp"
|
RelativePath="..\cocoa\CCGeometry.cpp"
|
||||||
>
|
>
|
||||||
|
@ -399,6 +403,10 @@
|
||||||
RelativePath="..\include\CCData.h"
|
RelativePath="..\include\CCData.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\include\CCDictionary.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\include\CCDirector.h"
|
RelativePath="..\include\CCDirector.h"
|
||||||
>
|
>
|
||||||
|
@ -435,6 +443,10 @@
|
||||||
RelativePath="..\include\CCIMEDispatcher.h"
|
RelativePath="..\include\CCIMEDispatcher.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\include\CCInteger.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\include\CCKeypadDelegate.h"
|
RelativePath="..\include\CCKeypadDelegate.h"
|
||||||
>
|
>
|
||||||
|
@ -1100,22 +1112,6 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
|
||||||
Name="gles2"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath="..\gles2\CCGLProgram.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\gles2\ccGLStateCache.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\gles2\CCShaderCache.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="kazmath"
|
Name="kazmath"
|
||||||
>
|
>
|
||||||
|
@ -1251,6 +1247,18 @@
|
||||||
<Filter
|
<Filter
|
||||||
Name="shaders"
|
Name="shaders"
|
||||||
>
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\shaders\CCGLProgram.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\shaders\ccGLStateCache.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\shaders\CCShaderCache.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\shaders\ccShaders.cpp"
|
RelativePath="..\shaders\ccShaders.cpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -64,7 +64,7 @@ CCShaderCache::~CCShaderCache()
|
||||||
|
|
||||||
bool CCShaderCache::init()
|
bool CCShaderCache::init()
|
||||||
{
|
{
|
||||||
m_pPrograms = new CCMutableDictionary<std::string, CCGLProgram*>();
|
m_pPrograms = new CCDictionary();
|
||||||
loadDefaultShaders();
|
loadDefaultShaders();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ void CCShaderCache::loadDefaultShaders()
|
||||||
|
|
||||||
CCGLProgram* CCShaderCache::programForKey(const char* key)
|
CCGLProgram* CCShaderCache::programForKey(const char* key)
|
||||||
{
|
{
|
||||||
return m_pPrograms->objectForKey(key);
|
return (CCGLProgram*)m_pPrograms->objectForKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCShaderCache::addProgram(CCGLProgram* program, const char* key)
|
void CCShaderCache::addProgram(CCGLProgram* program, const char* key)
|
|
@ -40,7 +40,7 @@ CCAnimationFrame::CCAnimationFrame()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimationFrame::initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCObjectDictionary* userInfo)
|
bool CCAnimationFrame::initWithSpriteFrame(CCSpriteFrame* spriteFrame, float delayUnits, CCDictionary* userInfo)
|
||||||
{
|
{
|
||||||
setSpriteFrame(spriteFrame);
|
setSpriteFrame(spriteFrame);
|
||||||
setDelayUnits(delayUnits);
|
setDelayUnits(delayUnits);
|
||||||
|
@ -73,7 +73,7 @@ CCObject* CCAnimationFrame::copyWithZone(CCZone* pZone)
|
||||||
}
|
}
|
||||||
|
|
||||||
pCopy->initWithSpriteFrame((CCSpriteFrame*)m_pSpriteFrame->copy()->autorelease(),
|
pCopy->initWithSpriteFrame((CCSpriteFrame*)m_pSpriteFrame->copy()->autorelease(),
|
||||||
m_fDelayUnits, (CCObjectDictionary*)m_pUserInfo->copy()->autorelease());
|
m_fDelayUnits, m_pUserInfo != NULL ? (CCDictionary*)m_pUserInfo->copy()->autorelease() : NULL);
|
||||||
|
|
||||||
CC_SAFE_DELETE(pNewZone);
|
CC_SAFE_DELETE(pNewZone);
|
||||||
return pCopy;
|
return pCopy;
|
||||||
|
@ -90,7 +90,7 @@ CCAnimation* CCAnimation::animation(void)
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *frames)
|
CCAnimation* CCAnimation::animationWithSpriteFrames(CCArray *frames)
|
||||||
{
|
{
|
||||||
CCAnimation *pAnimation = new CCAnimation();
|
CCAnimation *pAnimation = new CCAnimation();
|
||||||
pAnimation->initWithSpriteFrames(frames);
|
pAnimation->initWithSpriteFrames(frames);
|
||||||
|
@ -99,7 +99,7 @@ CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *frames, float delay)
|
CCAnimation* CCAnimation::animationWithSpriteFrames(CCArray *frames, float delay)
|
||||||
{
|
{
|
||||||
CCAnimation *pAnimation = new CCAnimation();
|
CCAnimation *pAnimation = new CCAnimation();
|
||||||
pAnimation->initWithSpriteFrames(frames, delay);
|
pAnimation->initWithSpriteFrames(frames, delay);
|
||||||
|
@ -108,7 +108,7 @@ CCAnimation* CCAnimation::animationWithSpriteFrames(CCMutableArray<CCSpriteFrame
|
||||||
return pAnimation;
|
return pAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimation::animationWithAnimationFrames(CCMutableArray<CCAnimationFrame*>* arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops)
|
CCAnimation* CCAnimation::animationWithAnimationFrames(CCArray* arrayOfSpriteFrameNames, float delayPerUnit, unsigned int loops)
|
||||||
{
|
{
|
||||||
CCAnimation *pAnimation = new CCAnimation();
|
CCAnimation *pAnimation = new CCAnimation();
|
||||||
pAnimation->initWithAnimationFrames(arrayOfSpriteFrameNames, delayPerUnit, loops);
|
pAnimation->initWithAnimationFrames(arrayOfSpriteFrameNames, delayPerUnit, loops);
|
||||||
|
@ -121,24 +121,26 @@ bool CCAnimation::init()
|
||||||
return initWithSpriteFrames(NULL, 0.0f);
|
return initWithSpriteFrames(NULL, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimation::initWithSpriteFrames(CCMutableArray<CCSpriteFrame*>* pFrames)
|
bool CCAnimation::initWithSpriteFrames(CCArray* pFrames)
|
||||||
{
|
{
|
||||||
return initWithSpriteFrames(pFrames, 0.0f);
|
return initWithSpriteFrames(pFrames, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimation::initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames, float delay)
|
bool CCAnimation::initWithSpriteFrames(CCArray *pFrames, float delay)
|
||||||
{
|
{
|
||||||
|
CCARRAY_VERIFY_TYPE(pFrames, CCSpriteFrame*);
|
||||||
|
|
||||||
m_uLoops = 1;
|
m_uLoops = 1;
|
||||||
m_fDelayPerUnit = delay;
|
m_fDelayPerUnit = delay;
|
||||||
CCMutableArray<CCAnimationFrame*>* pTmpFrames = new CCMutableArray<CCAnimationFrame*>();
|
CCArray* pTmpFrames = CCArray::array();
|
||||||
pTmpFrames->autorelease();
|
|
||||||
setFrames(pTmpFrames);
|
setFrames(pTmpFrames);
|
||||||
|
|
||||||
if (pFrames != NULL)
|
if (pFrames != NULL)
|
||||||
{
|
{
|
||||||
for(CCMutableArray<CCSpriteFrame*>::CCMutableArrayIterator it = pFrames->begin(); it != pFrames->end(); ++it)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pFrames, pObj)
|
||||||
{
|
{
|
||||||
CCSpriteFrame* frame = *it;
|
CCSpriteFrame* frame = (CCSpriteFrame*)pObj;
|
||||||
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
||||||
animFrame->initWithSpriteFrame(frame, 1, NULL);
|
animFrame->initWithSpriteFrame(frame, 1, NULL);
|
||||||
m_pFrames->addObject(animFrame);
|
m_pFrames->addObject(animFrame);
|
||||||
|
@ -151,16 +153,19 @@ bool CCAnimation::initWithSpriteFrames(CCMutableArray<CCSpriteFrame*> *pFrames,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCAnimation::initWithAnimationFrames(CCMutableArray<CCAnimationFrame*>* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops)
|
bool CCAnimation::initWithAnimationFrames(CCArray* arrayOfAnimationFrames, float delayPerUnit, unsigned int loops)
|
||||||
{
|
{
|
||||||
|
CCARRAY_VERIFY_TYPE(arrayOfAnimationFrames, CCAnimationFrame*);
|
||||||
|
|
||||||
m_fDelayPerUnit = delayPerUnit;
|
m_fDelayPerUnit = delayPerUnit;
|
||||||
m_uLoops = loops;
|
m_uLoops = loops;
|
||||||
|
|
||||||
setFrames(CCMutableArray<CCAnimationFrame*>::arrayWithArray(arrayOfAnimationFrames));
|
setFrames(CCArray::arrayWithArray(arrayOfAnimationFrames));
|
||||||
|
|
||||||
for( CCMutableArray<CCAnimationFrame*>::CCMutableArrayIterator it = m_pFrames->begin(); it != m_pFrames->end(); ++it )
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pFrames, pObj)
|
||||||
{
|
{
|
||||||
CCAnimationFrame *animFrame = *it;
|
CCAnimationFrame* animFrame = (CCAnimationFrame*)pObj;
|
||||||
m_fTotalDelayUnits += animFrame->getDelayUnits();
|
m_fTotalDelayUnits += animFrame->getDelayUnits();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -54,7 +54,7 @@ void CCAnimationCache::purgeSharedAnimationCache(void)
|
||||||
|
|
||||||
bool CCAnimationCache::init()
|
bool CCAnimationCache::init()
|
||||||
{
|
{
|
||||||
m_pAnimations = new CCMutableDictionary<std::string, CCAnimation*>();
|
m_pAnimations = new CCDictionary();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ CCAnimationCache::~CCAnimationCache()
|
||||||
|
|
||||||
void CCAnimationCache::addAnimation(CCAnimation *animation, const char * name)
|
void CCAnimationCache::addAnimation(CCAnimation *animation, const char * name)
|
||||||
{
|
{
|
||||||
m_pAnimations->setObject(animation, std::string(name));
|
m_pAnimations->setObject(animation, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::removeAnimationByName(const char* name)
|
void CCAnimationCache::removeAnimationByName(const char* name)
|
||||||
|
@ -81,41 +81,43 @@ void CCAnimationCache::removeAnimationByName(const char* name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pAnimations->removeObjectForKey(std::string(name));
|
m_pAnimations->removeObjectForKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCAnimation* CCAnimationCache::animationByName(const char* name)
|
CCAnimation* CCAnimationCache::animationByName(const char* name)
|
||||||
{
|
{
|
||||||
return m_pAnimations->objectForKey(std::string(name));
|
return (CCAnimation*)m_pAnimations->objectForKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::parseVersion1(CCObjectDictionary* animations)
|
void CCAnimationCache::parseVersion1(CCDictionary* animations)
|
||||||
{
|
{
|
||||||
vector<std::string> animationNames = animations->allKeys();
|
|
||||||
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||||
|
|
||||||
for (vector<std::string>::iterator iterName = animationNames.begin(); iterName != animationNames.end(); ++iterName)
|
CCDictElement* pElement = NULL;
|
||||||
|
CCDICT_FOREACH(animations, pElement)
|
||||||
{
|
{
|
||||||
string name = *iterName;
|
CCDictionary* animationDict = (CCDictionary*)pElement->getObject();
|
||||||
CCObjectDictionary* animationDict = (CCObjectDictionary*)animations->objectForKey(name);
|
CCArray* frameNames = (CCArray*)animationDict->objectForKey("frames");
|
||||||
CCMutableArray<CCObject*>* frameNames = (CCMutableArray<CCObject*>*)animationDict->objectForKey("frames");
|
|
||||||
float delay = (float)atof(valueForKey("delay", animationDict));
|
float delay = (float)atof(valueForKey("delay", animationDict));
|
||||||
CCAnimation* animation = NULL;
|
CCAnimation* animation = NULL;
|
||||||
|
|
||||||
if ( frameNames == NULL ) {
|
if ( frameNames == NULL )
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name.c_str());
|
{
|
||||||
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCAnimationFrame*>* frames = new CCMutableArray<CCAnimationFrame*>(frameNames->count());
|
CCArray* frames = CCArray::arrayWithCapacity(frameNames->count());
|
||||||
|
frames->retain();
|
||||||
|
|
||||||
for (CCMutableArray<CCObject*>::CCMutableArrayIterator iterFrameName = frameNames->begin(); iterFrameName != frameNames->end(); ++iterFrameName)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(frameNames, pObj)
|
||||||
{
|
{
|
||||||
const char* frameName = ((CCString*)(*iterFrameName))->toStdString().c_str();
|
const char* frameName = ((CCString*)pObj)->c_str();
|
||||||
CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName);
|
CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName);
|
||||||
|
|
||||||
if ( ! spriteFrame ) {
|
if ( ! spriteFrame ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name.c_str(), frameName);
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -127,57 +129,59 @@ void CCAnimationCache::parseVersion1(CCObjectDictionary* animations)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( frames->count() == 0 ) {
|
if ( frames->count() == 0 ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", name.c_str());
|
CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey());
|
||||||
continue;
|
continue;
|
||||||
} else if ( frames->count() != frameNames->count() ) {
|
} else if ( frames->count() != frameNames->count() ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", name.c_str());
|
CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
animation = CCAnimation::animationWithAnimationFrames(frames, delay, 1);
|
animation = CCAnimation::animationWithAnimationFrames(frames, delay, 1);
|
||||||
|
|
||||||
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, name.c_str());
|
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, pElement->getStrKey());
|
||||||
frames->release();
|
frames->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::parseVersion2(CCObjectDictionary* animations)
|
void CCAnimationCache::parseVersion2(CCDictionary* animations)
|
||||||
{
|
{
|
||||||
vector<std::string> animationNames = animations->allKeys();
|
|
||||||
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||||
|
|
||||||
for (vector<std::string>::iterator iterName = animationNames.begin(); iterName != animationNames.end(); ++iterName)
|
CCDictElement* pElement = NULL;
|
||||||
|
CCDICT_FOREACH(animations, pElement)
|
||||||
{
|
{
|
||||||
string name = *iterName;
|
const char* name = pElement->getStrKey();
|
||||||
CCObjectDictionary* animationDict = (CCObjectDictionary*)animations->objectForKey(name);
|
CCDictionary* animationDict = (CCDictionary*)pElement->getObject();
|
||||||
|
|
||||||
int loops = atoi(valueForKey("loops", animationDict));
|
int loops = atoi(valueForKey("loops", animationDict));
|
||||||
bool restoreOriginalFrame = atoi(valueForKey("restoreOriginalFrame", animationDict)) == 0 ? false : true;
|
bool restoreOriginalFrame = atoi(valueForKey("restoreOriginalFrame", animationDict)) == 0 ? false : true;
|
||||||
|
|
||||||
CCMutableArray<CCObject*>* frameArray = (CCMutableArray<CCObject*>*)animationDict->objectForKey("frames");
|
CCArray* frameArray = (CCArray*)animationDict->objectForKey("frames");
|
||||||
|
|
||||||
if ( frameArray == NULL ) {
|
if ( frameArray == NULL ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name.c_str());
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array of AnimationFrames
|
// Array of AnimationFrames
|
||||||
CCMutableArray<CCAnimationFrame*>* array = new CCMutableArray<CCAnimationFrame*>(frameArray->count());
|
CCArray* array = CCArray::arrayWithCapacity(frameArray->count());
|
||||||
|
array->retain();
|
||||||
|
|
||||||
for (CCMutableArray<CCObject*>::CCMutableArrayIterator iterFrameName = frameArray->begin(); iterFrameName != frameArray->end(); ++iterFrameName)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(frameArray, pObj)
|
||||||
{
|
{
|
||||||
CCObjectDictionary* entry = (CCObjectDictionary*)(*iterFrameName);
|
CCDictionary* entry = (CCDictionary*)(pObj);
|
||||||
|
|
||||||
const char* spriteFrameName = valueForKey("spriteframe", entry);
|
const char* spriteFrameName = valueForKey("spriteframe", entry);
|
||||||
CCSpriteFrame *spriteFrame = frameCache->spriteFrameByName(spriteFrameName);
|
CCSpriteFrame *spriteFrame = frameCache->spriteFrameByName(spriteFrameName);
|
||||||
|
|
||||||
if( ! spriteFrame ) {
|
if( ! spriteFrame ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name.c_str(), spriteFrameName);
|
CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name, spriteFrameName);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float delayUnits = (float)atof(valueForKey("delayUnits", entry));
|
float delayUnits = (float)atof(valueForKey("delayUnits", entry));
|
||||||
CCObjectDictionary* userInfo = (CCObjectDictionary*)entry->objectForKey("notification");
|
CCDictionary* userInfo = (CCDictionary*)entry->objectForKey("notification");
|
||||||
|
|
||||||
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
CCAnimationFrame *animFrame = new CCAnimationFrame();
|
||||||
animFrame->initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
|
animFrame->initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
|
||||||
|
@ -193,14 +197,14 @@ void CCAnimationCache::parseVersion2(CCObjectDictionary* animations)
|
||||||
|
|
||||||
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
animation->setRestoreOriginalFrame(restoreOriginalFrame);
|
||||||
|
|
||||||
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, name.c_str());
|
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, name);
|
||||||
animation->release();
|
animation->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAnimationCache::addAnimationsWithDictionary(CCObjectDictionary* dictionary)
|
void CCAnimationCache::addAnimationsWithDictionary(CCDictionary* dictionary)
|
||||||
{
|
{
|
||||||
CCObjectDictionary* animations = (CCObjectDictionary*)dictionary->objectForKey("animations");
|
CCDictionary* animations = (CCDictionary*)dictionary->objectForKey("animations");
|
||||||
|
|
||||||
if ( animations == NULL ) {
|
if ( animations == NULL ) {
|
||||||
CCLOG("cocos2d: CCAnimationCache: No animations were found in provided dictionary.");
|
CCLOG("cocos2d: CCAnimationCache: No animations were found in provided dictionary.");
|
||||||
|
@ -208,18 +212,19 @@ void CCAnimationCache::addAnimationsWithDictionary(CCObjectDictionary* dictionar
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int version = 1;
|
unsigned int version = 1;
|
||||||
CCObjectDictionary* properties = (CCObjectDictionary*)dictionary->objectForKey("properties");
|
CCDictionary* properties = (CCDictionary*)dictionary->objectForKey("properties");
|
||||||
if( properties )
|
if( properties )
|
||||||
{
|
{
|
||||||
version = atoi(valueForKey("format", properties));
|
version = atoi(valueForKey("format", properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCObject*>* spritesheets = (CCMutableArray<CCObject*>*)properties->objectForKey("spritesheets");
|
CCArray* spritesheets = (CCArray*)properties->objectForKey("spritesheets");
|
||||||
|
|
||||||
for( CCMutableArray<CCObject*>::CCMutableArrayIterator iterName = spritesheets->begin(); iterName != spritesheets->end(); ++iterName)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(spritesheets, pObj)
|
||||||
{
|
{
|
||||||
CCString* name = (CCString*)(*iterName);
|
CCString* name = (CCString*)(pObj);
|
||||||
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->toStdString().c_str());
|
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
@ -234,11 +239,11 @@ void CCAnimationCache::addAnimationsWithDictionary(CCObjectDictionary* dictionar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * CCAnimationCache::valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict)
|
const char * CCAnimationCache::valueForKey(const char *key, CCDictionary *dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
CCString *pString = (CCString*)dict->objectForKey(key);
|
||||||
return pString ? pString->m_sString.c_str() : "";
|
return pString ? pString->m_sString.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -250,7 +255,7 @@ void CCAnimationCache::addAnimationsWithFile(const char* plist)
|
||||||
CCAssert( plist, "Invalid texture file name");
|
CCAssert( plist, "Invalid texture file name");
|
||||||
|
|
||||||
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
||||||
CCObjectDictionary* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
CCDictionary* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
||||||
|
|
||||||
CCAssert( dict, "CCAnimationCache: File could not be found");
|
CCAssert( dict, "CCAnimationCache: File could not be found");
|
||||||
|
|
||||||
|
|
|
@ -960,7 +960,7 @@ void CCSprite::setDisplayFrameWithAnimationName(const char *animationName, int f
|
||||||
|
|
||||||
CCAssert(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");
|
CCAssert(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found");
|
||||||
|
|
||||||
CCAnimationFrame *frame = a->getFrames()->getObjectAtIndex(frameIndex);
|
CCAnimationFrame* frame = (CCAnimationFrame*)a->getFrames()->objectAtIndex(frameIndex);
|
||||||
|
|
||||||
CCAssert(frame, "CCSprite#setDisplayFrame. Invalid frame");
|
CCAssert(frame, "CCSprite#setDisplayFrame. Invalid frame");
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,12 @@ THE SOFTWARE.
|
||||||
#include "support/TransformUtils.h"
|
#include "support/TransformUtils.h"
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
|
#include "CCArray.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace cocos2d {
|
using namespace std;
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
|
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
|
||||||
|
|
||||||
|
@ -58,8 +62,8 @@ void CCSpriteFrameCache::purgeSharedSpriteFrameCache(void)
|
||||||
|
|
||||||
bool CCSpriteFrameCache::init(void)
|
bool CCSpriteFrameCache::init(void)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames= new CCDictionary<std::string, CCSpriteFrame*>();
|
m_pSpriteFrames= new CCDictionary();
|
||||||
m_pSpriteFramesAliases = new CCDictionary<std::string, CCString*>();
|
m_pSpriteFramesAliases = new CCDictionary();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +73,7 @@ CCSpriteFrameCache::~CCSpriteFrameCache(void)
|
||||||
CC_SAFE_RELEASE(m_pSpriteFramesAliases);
|
CC_SAFE_RELEASE(m_pSpriteFramesAliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
|
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary* dictionary, CCTexture2D *pobTexture)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Supported Zwoptex Formats:
|
Supported Zwoptex Formats:
|
||||||
|
@ -80,8 +84,8 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
|
CCDictionary *metadataDict = (CCDictionary*)dictionary->objectForKey("metadata");
|
||||||
CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
|
CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames");
|
||||||
int format = 0;
|
int format = 0;
|
||||||
|
|
||||||
// get the format
|
// get the format
|
||||||
|
@ -93,12 +97,11 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
// check the format
|
// check the format
|
||||||
CCAssert(format >=0 && format <= 3, "");
|
CCAssert(format >=0 && format <= 3, "");
|
||||||
|
|
||||||
framesDict->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(framesDict, pElement)
|
||||||
CCDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
||||||
while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
|
|
||||||
{
|
{
|
||||||
CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
|
CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
|
||||||
|
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(pElement->getStrKey());
|
||||||
if (spriteFrame)
|
if (spriteFrame)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -164,19 +167,19 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
|
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
|
||||||
|
|
||||||
// get aliases
|
// get aliases
|
||||||
CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
|
CCArray* aliases = (CCArray*) (frameDict->objectForKey("aliases"));
|
||||||
CCMutableArray<CCString*>::CCMutableArrayIterator iter;
|
CCString * frameKey = new CCString(pElement->getStrKey());
|
||||||
|
|
||||||
CCString * frameKey = new CCString(key.c_str());
|
CCObject* pObj = NULL;
|
||||||
for (iter = aliases->begin(); iter != aliases->end(); ++iter)
|
CCARRAY_FOREACH(aliases, pObj)
|
||||||
{
|
{
|
||||||
std::string oneAlias = ((CCString*) (*iter))->m_sString;
|
std::string oneAlias = ((CCString*)pObj)->m_sString;
|
||||||
if (m_pSpriteFramesAliases->objectForKey(oneAlias))
|
if (m_pSpriteFramesAliases->objectForKey(oneAlias.c_str()))
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pSpriteFramesAliases->setObject(frameKey, oneAlias);
|
m_pSpriteFramesAliases->setObject(frameKey, oneAlias.c_str());
|
||||||
}
|
}
|
||||||
frameKey->release();
|
frameKey->release();
|
||||||
// create frame
|
// create frame
|
||||||
|
@ -189,7 +192,7 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// add sprite frame
|
// add sprite frame
|
||||||
m_pSpriteFrames->setObject(spriteFrame, key);
|
m_pSpriteFrames->setObject(spriteFrame, pElement->getStrKey());
|
||||||
spriteFrame->release();
|
spriteFrame->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +200,7 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
||||||
{
|
{
|
||||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
CCDictionary *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||||
|
|
||||||
addSpriteFramesWithDictionary(dict, pobTexture);
|
addSpriteFramesWithDictionary(dict, pobTexture);
|
||||||
|
|
||||||
|
@ -222,11 +225,11 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char*
|
||||||
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||||
{
|
{
|
||||||
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
||||||
CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
CCDictionary *dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(pszPath);
|
||||||
|
|
||||||
string texturePath("");
|
string texturePath("");
|
||||||
|
|
||||||
CCDictionary<std::string, CCObject*>* metadataDict = (CCDictionary<std::string, CCObject*>*)dict->objectForKey(string("metadata"));
|
CCDictionary* metadataDict = (CCDictionary*)dict->objectForKey("metadata");
|
||||||
if (metadataDict)
|
if (metadataDict)
|
||||||
{
|
{
|
||||||
// try to read texture file name from meta data
|
// try to read texture file name from meta data
|
||||||
|
@ -269,7 +272,7 @@ void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
||||||
|
|
||||||
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->setObject(pobFrame, std::string(pszFrameName));
|
m_pSpriteFrames->setObject(pobFrame, pszFrameName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFrames(void)
|
void CCSpriteFrameCache::removeSpriteFrames(void)
|
||||||
|
@ -280,18 +283,16 @@ void CCSpriteFrameCache::removeSpriteFrames(void)
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeUnusedSpriteFrames(void)
|
void CCSpriteFrameCache::removeUnusedSpriteFrames(void)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(m_pSpriteFrames, pElement)
|
||||||
CCSpriteFrame *spriteFrame = NULL;
|
|
||||||
while( (spriteFrame = m_pSpriteFrames->next(&key)) )
|
|
||||||
{
|
{
|
||||||
|
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)pElement->getObject();
|
||||||
if( spriteFrame->retainCount() == 1 )
|
if( spriteFrame->retainCount() == 1 )
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCSpriteFrameCache: removing unused frame: %s", key.c_str());
|
CCLOG("cocos2d: CCSpriteFrameCache: removing unused frame: %s", pElement->getStrKey());
|
||||||
m_pSpriteFrames->removeObjectForKey(key);
|
m_pSpriteFrames->removeObjectForKey(pElement->getStrKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_pSpriteFrames->end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,50 +305,47 @@ void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this an alias ?
|
// Is this an alias ?
|
||||||
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(string(pszName));
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(pszName);
|
||||||
|
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(key->m_sString);
|
m_pSpriteFrames->removeObjectForKey(key->c_str());
|
||||||
m_pSpriteFramesAliases->removeObjectForKey(key->m_sString);
|
m_pSpriteFramesAliases->removeObjectForKey(key->c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(std::string(pszName));
|
m_pSpriteFrames->removeObjectForKey(pszName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
||||||
{
|
{
|
||||||
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
||||||
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(path);
|
CCDictionary* dict = CCFileUtils::dictionaryWithContentsOfFileThreadSafe(path);
|
||||||
|
|
||||||
removeSpriteFramesFromDictionary((CCDictionary<std::string, CCSpriteFrame*>*)dict);
|
removeSpriteFramesFromDictionary((CCDictionary*)dict);
|
||||||
|
|
||||||
dict->release();
|
dict->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary<std::string, CCSpriteFrame*> *dictionary)
|
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary* dictionary)
|
||||||
{
|
{
|
||||||
CCDictionary<std::string, CCObject*>* framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(string("frames"));
|
CCDictionary* framesDict = (CCDictionary*)dictionary->objectForKey("frames");
|
||||||
vector<string> keysToRemove;
|
vector<string> keysToRemove;
|
||||||
|
|
||||||
framesDict->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(framesDict, pElement)
|
||||||
CCDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
||||||
while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
|
|
||||||
{
|
{
|
||||||
if (m_pSpriteFrames->objectForKey(key))
|
if (m_pSpriteFrames->objectForKey(pElement->getStrKey()))
|
||||||
{
|
{
|
||||||
keysToRemove.push_back(key);
|
keysToRemove.push_back(pElement->getStrKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
framesDict->end();
|
|
||||||
|
|
||||||
vector<string>::iterator iter;
|
vector<string>::iterator iter;
|
||||||
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(*iter);
|
m_pSpriteFrames->removeObjectForKey((*iter).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,36 +353,34 @@ void CCSpriteFrameCache::removeSpriteFramesFromTexture(CCTexture2D* texture)
|
||||||
{
|
{
|
||||||
vector<string> keysToRemove;
|
vector<string> keysToRemove;
|
||||||
|
|
||||||
m_pSpriteFrames->begin();
|
CCDictElement* pElement = NULL;
|
||||||
std::string key = "";
|
CCDICT_FOREACH(m_pSpriteFrames, pElement)
|
||||||
CCDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
||||||
while( (frameDict = (CCDictionary<std::string, CCObject*>*)m_pSpriteFrames->next(&key)) )
|
|
||||||
{
|
{
|
||||||
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(key);
|
string key = pElement->getStrKey();
|
||||||
|
CCSpriteFrame* frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key.c_str());
|
||||||
if (frame && (frame->getTexture() == texture))
|
if (frame && (frame->getTexture() == texture))
|
||||||
{
|
{
|
||||||
keysToRemove.push_back(key);
|
keysToRemove.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_pSpriteFrames->end();
|
|
||||||
|
|
||||||
vector<string>::iterator iter;
|
vector<string>::iterator iter;
|
||||||
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); ++iter)
|
||||||
{
|
{
|
||||||
m_pSpriteFrames->removeObjectForKey(*iter);
|
m_pSpriteFrames->removeObjectForKey((*iter).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
||||||
{
|
{
|
||||||
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(std::string(pszName));
|
CCSpriteFrame* frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(pszName);
|
||||||
if (!frame)
|
if (!frame)
|
||||||
{
|
{
|
||||||
// try alias dictionary
|
// try alias dictionary
|
||||||
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(string(pszName));
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(pszName);
|
||||||
if (key)
|
if (key)
|
||||||
{
|
{
|
||||||
frame = m_pSpriteFrames->objectForKey(key->m_sString);
|
frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key->c_str());
|
||||||
if (! frame)
|
if (! frame)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName);
|
CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName);
|
||||||
|
@ -394,13 +390,14 @@ CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * CCSpriteFrameCache::valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict)
|
const char * CCSpriteFrameCache::valueForKey(const char *key, CCDictionary *dict)
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
CCString *pString = (CCString*)dict->objectForKey(key);
|
||||||
return pString ? pString->m_sString.c_str() : "";
|
return pString ? pString->m_sString.c_str() : "";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}//namespace cocos2d
|
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -25,8 +25,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCArray.h"
|
#include "CCArray.h"
|
||||||
|
|
||||||
namespace cocos2d
|
NS_CC_BEGIN
|
||||||
{
|
|
||||||
|
|
||||||
CCArray* CCArray::array()
|
CCArray* CCArray::array()
|
||||||
{
|
{
|
||||||
|
@ -158,20 +157,20 @@ void CCArray::insertObject(CCObject* object, unsigned int index)
|
||||||
ccArrayInsertObjectAtIndex(data, object, index);
|
ccArrayInsertObjectAtIndex(data, object, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeLastObject()
|
void CCArray::removeLastObject(bool bReleaseObj)
|
||||||
{
|
{
|
||||||
CCAssert(data->num, "no objects added");
|
CCAssert(data->num, "no objects added");
|
||||||
ccArrayRemoveObjectAtIndex(data, data->num-1);
|
ccArrayRemoveObjectAtIndex(data, data->num-1, bReleaseObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeObject(CCObject* object)
|
void CCArray::removeObject(CCObject* object, bool bReleaseObj/* = true*/)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObject(data, object);
|
ccArrayRemoveObject(data, object, bReleaseObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeObjectAtIndex(unsigned int index)
|
void CCArray::removeObjectAtIndex(unsigned int index, bool bReleaseObj)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(data, index);
|
ccArrayRemoveObjectAtIndex(data, index, bReleaseObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCArray::removeObjectsInArray(CCArray* otherArray)
|
void CCArray::removeObjectsInArray(CCArray* otherArray)
|
||||||
|
@ -242,4 +241,20 @@ CCArray::~CCArray()
|
||||||
ccArrayFree(data);
|
ccArrayFree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCArray::replaceObjectAtIndex(unsigned int uIndex, CCObject* pObject, bool bReleaseObject/* = true*/)
|
||||||
|
{
|
||||||
|
if (bReleaseObject && uIndex < data->num && data->arr[uIndex] != NULL)
|
||||||
|
{
|
||||||
|
data->arr[uIndex]->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data->arr[uIndex] = pObject;
|
||||||
|
|
||||||
|
// add the ref
|
||||||
|
if (pObject)
|
||||||
|
{
|
||||||
|
pObject->retain();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -71,7 +71,7 @@ void CCProfiler::releaseAllTimers()
|
||||||
|
|
||||||
bool CCProfiler::init()
|
bool CCProfiler::init()
|
||||||
{
|
{
|
||||||
m_pActiveTimers = new CCMutableDictionary<std::string, CCProfilingTimer*>();
|
m_pActiveTimers = new CCDictionary();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,10 +82,10 @@ CCProfiler::~CCProfiler(void)
|
||||||
|
|
||||||
void CCProfiler::displayTimers()
|
void CCProfiler::displayTimers()
|
||||||
{
|
{
|
||||||
vector<string> allKeys = m_pActiveTimers->allKeys();
|
CCDictElement* pElement = NULL;
|
||||||
for (vector<string>::iterator it = allKeys.begin(); it != allKeys.end(); ++it)
|
CCDICT_FOREACH(m_pActiveTimers, pElement)
|
||||||
{
|
{
|
||||||
CCProfilingTimer* timer = m_pActiveTimers->objectForKey(*it);
|
CCProfilingTimer* timer = (CCProfilingTimer*)pElement->getObject();
|
||||||
CCLog(timer->description());
|
CCLog(timer->description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ void CCProfilingTimer::reset()
|
||||||
void CCProfilingBeginTimingBlock(const char *timerName)
|
void CCProfilingBeginTimingBlock(const char *timerName)
|
||||||
{
|
{
|
||||||
CCProfiler* p = CCProfiler::sharedProfiler();
|
CCProfiler* p = CCProfiler::sharedProfiler();
|
||||||
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
|
CCProfilingTimer* timer = (CCProfilingTimer*)p->m_pActiveTimers->objectForKey(timerName);
|
||||||
if( ! timer )
|
if( ! timer )
|
||||||
{
|
{
|
||||||
timer = p->createAndAddTimerWithName(timerName);
|
timer = p->createAndAddTimerWithName(timerName);
|
||||||
|
@ -144,7 +144,7 @@ void CCProfilingBeginTimingBlock(const char *timerName)
|
||||||
void CCProfilingEndTimingBlock(const char *timerName)
|
void CCProfilingEndTimingBlock(const char *timerName)
|
||||||
{
|
{
|
||||||
CCProfiler* p = CCProfiler::sharedProfiler();
|
CCProfiler* p = CCProfiler::sharedProfiler();
|
||||||
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
|
CCProfilingTimer* timer = (CCProfilingTimer*)p->m_pActiveTimers->objectForKey(timerName);
|
||||||
|
|
||||||
CCAssert(timer, "CCProfilingTimer not found");
|
CCAssert(timer, "CCProfilingTimer not found");
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ void CCProfilingEndTimingBlock(const char *timerName)
|
||||||
void CCProfilingResetTimingBlock(const char *timerName)
|
void CCProfilingResetTimingBlock(const char *timerName)
|
||||||
{
|
{
|
||||||
CCProfiler* p = CCProfiler::sharedProfiler();
|
CCProfiler* p = CCProfiler::sharedProfiler();
|
||||||
CCProfilingTimer *timer = p->m_pActiveTimers->objectForKey(timerName);
|
CCProfilingTimer *timer = (CCProfilingTimer*)p->m_pActiveTimers->objectForKey(timerName);
|
||||||
|
|
||||||
CCAssert(timer, "CCProfilingTimer not found");
|
CCAssert(timer, "CCProfilingTimer not found");
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCDictionary.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
/** releases all timers */
|
/** releases all timers */
|
||||||
void releaseAllTimers();
|
void releaseAllTimers();
|
||||||
|
|
||||||
CCMutableDictionary<std::string, CCProfilingTimer*>* m_pActiveTimers;
|
CCDictionary* m_pActiveTimers;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CCProfilingTimer : public CCObject
|
class CCProfilingTimer : public CCObject
|
||||||
|
|
|
@ -45,7 +45,7 @@ THE SOFTWARE.
|
||||||
#include "CCObject.h"
|
#include "CCObject.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
// Easy integration
|
// Easy integration
|
||||||
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
#define CCARRAYDATA_FOREACH(__array__, __object__) \
|
||||||
|
@ -86,9 +86,7 @@ static inline void ccArrayFree(ccArray *arr)
|
||||||
|
|
||||||
ccArrayRemoveAllObjects(arr);
|
ccArrayRemoveAllObjects(arr);
|
||||||
|
|
||||||
//delete arr->m_pObjectArray;
|
|
||||||
free(arr->arr);
|
free(arr->arr);
|
||||||
|
|
||||||
free(arr);
|
free(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,9 +223,13 @@ static inline void ccArrayRemoveAllObjects(ccArray *arr)
|
||||||
|
|
||||||
/** Removes object at specified index and pushes back all subsequent objects.
|
/** Removes object at specified index and pushes back all subsequent objects.
|
||||||
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)
|
static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, unsigned int index, bool bReleaseObj)
|
||||||
|
{
|
||||||
|
if (bReleaseObj)
|
||||||
{
|
{
|
||||||
arr->arr[index]->release();
|
arr->arr[index]->release();
|
||||||
|
}
|
||||||
|
|
||||||
arr->num--;
|
arr->num--;
|
||||||
|
|
||||||
unsigned int remaining = arr->num - index;
|
unsigned int remaining = arr->num - index;
|
||||||
|
@ -252,18 +254,20 @@ static inline void ccArrayFastRemoveObject(ccArray *arr, CCObject* object)
|
||||||
{
|
{
|
||||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||||
if (index != UINT_MAX)
|
if (index != UINT_MAX)
|
||||||
|
{
|
||||||
ccArrayFastRemoveObjectAtIndex(arr, index);
|
ccArrayFastRemoveObjectAtIndex(arr, index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Searches for the first occurance of object and removes it. If object is not
|
/** Searches for the first occurance of object and removes it. If object is not
|
||||||
found the function has no effect. */
|
found the function has no effect. */
|
||||||
static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object)
|
static inline void ccArrayRemoveObject(ccArray *arr, CCObject* object, bool bReleaseObj)
|
||||||
{
|
{
|
||||||
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
unsigned int index = ccArrayGetIndexOfObject(arr, object);
|
||||||
|
|
||||||
if (index != UINT_MAX)
|
if (index != UINT_MAX)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(arr, index);
|
ccArrayRemoveObjectAtIndex(arr, index, bReleaseObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +277,7 @@ static inline void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
for( unsigned int i = 0; i < minusArr->num; i++)
|
for( unsigned int i = 0; i < minusArr->num; i++)
|
||||||
{
|
{
|
||||||
ccArrayRemoveObject(arr, minusArr->arr[i]);
|
ccArrayRemoveObject(arr, minusArr->arr[i], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +291,7 @@ static inline void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
|
||||||
{
|
{
|
||||||
if( ccArrayContainsObject(minusArr, arr->arr[i]) )
|
if( ccArrayContainsObject(minusArr, arr->arr[i]) )
|
||||||
{
|
{
|
||||||
delete arr->arr[i];
|
arr->arr[i]->release();
|
||||||
back++;
|
back++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -496,6 +500,6 @@ static inline void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
|
||||||
arr->num -= back;
|
arr->num -= back;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
NS_CC_END
|
||||||
|
|
||||||
#endif // CC_ARRAY_H
|
#endif // CC_ARRAY_H
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
/****************************************************************************
|
/*
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2003-2010, Troy D. Hanson http://uthash.sourceforge.net
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Redistributions of source code must retain the above copyright
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
notice, this list of conditions and the following disclaimer.
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
all copies or substantial portions of the Software.
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
THE SOFTWARE.
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
****************************************************************************/
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
#ifndef __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
||||||
#define __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
#define __SUPPORT_DATA_SUPPORT_UTHASH_H__
|
||||||
|
|
|
@ -41,8 +41,11 @@ THE SOFTWARE.
|
||||||
#include "pthread.h"
|
#include "pthread.h"
|
||||||
#include "CCThread.h"
|
#include "CCThread.h"
|
||||||
#include "semaphore.h"
|
#include "semaphore.h"
|
||||||
|
#include "CCString.h"
|
||||||
|
|
||||||
namespace cocos2d {
|
using namespace std;
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
typedef struct _AsyncStruct
|
typedef struct _AsyncStruct
|
||||||
{
|
{
|
||||||
|
@ -169,7 +172,7 @@ CCTextureCache::CCTextureCache()
|
||||||
{
|
{
|
||||||
CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
||||||
|
|
||||||
m_pTextures = new CCMutableDictionary<std::string, CCTexture2D*>();
|
m_pTextures = new CCDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTextureCache::~CCTextureCache()
|
CCTextureCache::~CCTextureCache()
|
||||||
|
@ -205,7 +208,7 @@ void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallF
|
||||||
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||||
|
|
||||||
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||||
texture = m_pTextures->objectForKey(pathKey);
|
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
|
||||||
|
|
||||||
std::string fullpath = pathKey;
|
std::string fullpath = pathKey;
|
||||||
if (texture != NULL)
|
if (texture != NULL)
|
||||||
|
@ -326,7 +329,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
CCFileUtils::ccRemoveHDSuffixFromFile(pathKey);
|
||||||
|
|
||||||
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
pathKey = CCFileUtils::fullPathFromRelativePath(pathKey.c_str());
|
||||||
texture = m_pTextures->objectForKey(pathKey);
|
texture = (CCTexture2D*)m_pTextures->objectForKey(pathKey.c_str());
|
||||||
|
|
||||||
std::string fullpath = pathKey; // (CCFileUtils::fullPathFromRelativePath(path));
|
std::string fullpath = pathKey; // (CCFileUtils::fullPathFromRelativePath(path));
|
||||||
if( ! texture )
|
if( ! texture )
|
||||||
|
@ -362,7 +365,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtJpg);
|
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtJpg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_pTextures->setObject(texture, pathKey);
|
m_pTextures->setObject(texture, pathKey.c_str());
|
||||||
// autorelease prevents possible crash in multithreaded environments
|
// autorelease prevents possible crash in multithreaded environments
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
|
@ -390,7 +393,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtPng);
|
VolatileTexture::addImageTexture(texture, fullpath.c_str(), CCImage::kFmtPng);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_pTextures->setObject(texture, pathKey);
|
m_pTextures->setObject(texture, pathKey.c_str());
|
||||||
// autorelease prevents possible crash in multithreaded environments
|
// autorelease prevents possible crash in multithreaded environments
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
|
@ -454,7 +457,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
||||||
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
// remove possible -HD suffix to prevent caching the same image twice (issue #1040)
|
||||||
CCFileUtils::ccRemoveHDSuffixFromFile(key);
|
CCFileUtils::ccRemoveHDSuffixFromFile(key);
|
||||||
|
|
||||||
if( (tex = m_pTextures->objectForKey(key)) )
|
if( (tex = (CCTexture2D*)m_pTextures->objectForKey(key.c_str())) )
|
||||||
{
|
{
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +471,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
|
||||||
// cache the texture file name
|
// cache the texture file name
|
||||||
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
|
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
|
||||||
#endif
|
#endif
|
||||||
m_pTextures->setObject(tex, key);
|
m_pTextures->setObject(tex, key.c_str());
|
||||||
tex->autorelease();
|
tex->autorelease();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -497,7 +500,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// If key is nil, then create a new texture each time
|
// If key is nil, then create a new texture each time
|
||||||
if(key && (texture = m_pTextures->objectForKey(forKey)))
|
if(key && (texture = (CCTexture2D *)m_pTextures->objectForKey(forKey.c_str())))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -508,7 +511,7 @@ CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
|
||||||
|
|
||||||
if(key && texture)
|
if(key && texture)
|
||||||
{
|
{
|
||||||
m_pTextures->setObject(texture, forKey);
|
m_pTextures->setObject(texture, forKey.c_str());
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -530,15 +533,15 @@ void CCTextureCache::removeAllTextures()
|
||||||
|
|
||||||
void CCTextureCache::removeUnusedTextures()
|
void CCTextureCache::removeUnusedTextures()
|
||||||
{
|
{
|
||||||
std::vector<std::string> keys = m_pTextures->allKeys();
|
CCDictElement* pElement = NULL;
|
||||||
std::vector<std::string>::iterator it;
|
CCDICT_FOREACH(m_pTextures, pElement)
|
||||||
for (it = keys.begin(); it != keys.end(); ++it)
|
|
||||||
{
|
{
|
||||||
CCTexture2D *value = m_pTextures->objectForKey(*it);
|
CCLOG("cocos2d: CCTextureCache: texture: %s", pElement->getStrKey());
|
||||||
|
CCTexture2D *value = (CCTexture2D*)pElement->getObject();
|
||||||
if (value->retainCount() == 1)
|
if (value->retainCount() == 1)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", (*it).c_str());
|
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", pElement->getStrKey());
|
||||||
m_pTextures->removeObjectForKey(*it);
|
m_pTextures->removeObjectForKey(pElement->getStrKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,11 +551,12 @@ void CCTextureCache::removeTexture(CCTexture2D* texture)
|
||||||
if( ! texture )
|
if( ! texture )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<std::string> keys = m_pTextures->allKeysForObject(texture);
|
CCArray* keys = m_pTextures->allKeysForObject(texture);
|
||||||
|
CCObject* pObj;
|
||||||
for (unsigned int i = 0; i < keys.size(); i++)
|
CCARRAY_FOREACH(keys, pObj)
|
||||||
{
|
{
|
||||||
m_pTextures->removeObjectForKey(keys[i]);
|
CCString* pKey = (CCString*)pObj;
|
||||||
|
m_pTextures->removeObjectForKey(pKey->c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,13 +568,12 @@ void CCTextureCache::removeTextureForKey(const char *textureKeyName)
|
||||||
}
|
}
|
||||||
|
|
||||||
string fullPath = CCFileUtils::fullPathFromRelativePath(textureKeyName);
|
string fullPath = CCFileUtils::fullPathFromRelativePath(textureKeyName);
|
||||||
m_pTextures->removeObjectForKey(fullPath);
|
m_pTextures->removeObjectForKey(fullPath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTexture2D* CCTextureCache::textureForKey(const char* key)
|
CCTexture2D* CCTextureCache::textureForKey(const char* key)
|
||||||
{
|
{
|
||||||
std::string strKey = CCFileUtils::fullPathFromRelativePath(key);
|
return (CCTexture2D*)m_pTextures->objectForKey(CCFileUtils::fullPathFromRelativePath(key));
|
||||||
return m_pTextures->objectForKey(strKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureCache::reloadAllTextures()
|
void CCTextureCache::reloadAllTextures()
|
||||||
|
@ -585,18 +588,17 @@ void CCTextureCache::dumpCachedTextureInfo()
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
unsigned int totalBytes = 0;
|
unsigned int totalBytes = 0;
|
||||||
|
|
||||||
vector<string> keys = m_pTextures->allKeys();
|
CCDictElement* pElement = NULL;
|
||||||
vector<string>::iterator iter;
|
CCDICT_FOREACH(m_pTextures, pElement)
|
||||||
for (iter = keys.begin(); iter != keys.end(); iter++)
|
|
||||||
{
|
{
|
||||||
CCTexture2D *tex = m_pTextures->objectForKey(*iter);
|
CCTexture2D* tex = (CCTexture2D*)pElement->getObject();
|
||||||
unsigned int bpp = tex->bitsPerPixelForFormat();
|
unsigned int bpp = tex->bitsPerPixelForFormat();
|
||||||
// Each texture takes up width * height * bytesPerPixel bytes.
|
// Each texture takes up width * height * bytesPerPixel bytes.
|
||||||
unsigned int bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
unsigned int bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8;
|
||||||
totalBytes += bytes;
|
totalBytes += bytes;
|
||||||
count++;
|
count++;
|
||||||
CCLOG("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
CCLOG("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB",
|
||||||
(*iter).c_str(),
|
pElement->getStrKey(),
|
||||||
(long)tex->retainCount(),
|
(long)tex->retainCount(),
|
||||||
(long)tex->getName(),
|
(long)tex->getName(),
|
||||||
(long)tex->getPixelsWide(),
|
(long)tex->getPixelsWide(),
|
||||||
|
@ -797,5 +799,5 @@ void VolatileTexture::reloadAllTextures()
|
||||||
|
|
||||||
#endif // CC_ENABLE_CACHE_TEXTTURE_DATA
|
#endif // CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||||
|
|
||||||
}//namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ namespace cocos2d {
|
||||||
CCPointObject *point = (CCPointObject*)m_pParallaxArray->arr[i];
|
CCPointObject *point = (CCPointObject*)m_pParallaxArray->arr[i];
|
||||||
if( point->getChild()->isEqual(child))
|
if( point->getChild()->isEqual(child))
|
||||||
{
|
{
|
||||||
ccArrayRemoveObjectAtIndex(m_pParallaxArray, i);
|
ccArrayRemoveObjectAtIndex(m_pParallaxArray, i, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ bool CCTMXLayer::initWithTilesetInfo(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerIn
|
||||||
m_uMinGID = layerInfo->m_uMinGID;
|
m_uMinGID = layerInfo->m_uMinGID;
|
||||||
m_uMaxGID = layerInfo->m_uMaxGID;
|
m_uMaxGID = layerInfo->m_uMaxGID;
|
||||||
m_cOpacity = layerInfo->m_cOpacity;
|
m_cOpacity = layerInfo->m_cOpacity;
|
||||||
m_pProperties = CCStringToStringDictionary::dictionaryWithDictionary(layerInfo->getProperties());
|
setProperties(CCDictionary::dictionaryWithDictionary(layerInfo->getProperties()));
|
||||||
m_fContentScaleFactor = CCDirector::sharedDirector()->getContentScaleFactor();
|
m_fContentScaleFactor = CCDirector::sharedDirector()->getContentScaleFactor();
|
||||||
|
|
||||||
// tilesetInfo
|
// tilesetInfo
|
||||||
|
@ -196,8 +196,9 @@ void CCTMXLayer::setupTiles()
|
||||||
// CCTMXLayer - Properties
|
// CCTMXLayer - Properties
|
||||||
CCString* CCTMXLayer::propertyNamed(const char *propertyName)
|
CCString* CCTMXLayer::propertyNamed(const char *propertyName)
|
||||||
{
|
{
|
||||||
return m_pProperties->objectForKey(std::string(propertyName));
|
return (CCString*)m_pProperties->objectForKey(propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXLayer::parseInternalProperties()
|
void CCTMXLayer::parseInternalProperties()
|
||||||
{
|
{
|
||||||
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
// if cc_vertex=automatic, then tiles will be rendered using vertexz
|
||||||
|
@ -674,11 +675,11 @@ int CCTMXLayer::vertexZForPos(const CCPoint& pos)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStringToStringDictionary * CCTMXLayer::getProperties()
|
CCDictionary * CCTMXLayer::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXLayer::setProperties(CCStringToStringDictionary* var)
|
void CCTMXLayer::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
|
|
|
@ -26,7 +26,8 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "CCTMXObjectGroup.h"
|
#include "CCTMXObjectGroup.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
namespace cocos2d {
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
//implementation CCTMXObjectGroup
|
//implementation CCTMXObjectGroup
|
||||||
|
|
||||||
|
@ -34,8 +35,9 @@ namespace cocos2d {
|
||||||
:m_tPositionOffset(CCPointZero)
|
:m_tPositionOffset(CCPointZero)
|
||||||
,m_sGroupName("")
|
,m_sGroupName("")
|
||||||
{
|
{
|
||||||
m_pObjects = new CCMutableArray<CCStringToStringDictionary*>();
|
m_pObjects = CCArray::array();
|
||||||
m_pProperties = new CCStringToStringDictionary();
|
m_pObjects->retain();
|
||||||
|
m_pProperties = new CCDictionary();
|
||||||
}
|
}
|
||||||
CCTMXObjectGroup::~CCTMXObjectGroup()
|
CCTMXObjectGroup::~CCTMXObjectGroup()
|
||||||
{
|
{
|
||||||
|
@ -43,17 +45,18 @@ namespace cocos2d {
|
||||||
CC_SAFE_RELEASE(m_pObjects);
|
CC_SAFE_RELEASE(m_pObjects);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
}
|
}
|
||||||
CCStringToStringDictionary * CCTMXObjectGroup::objectNamed(const char *objectName)
|
CCDictionary* CCTMXObjectGroup::objectNamed(const char *objectName)
|
||||||
{
|
{
|
||||||
if (m_pObjects && m_pObjects->count() > 0)
|
if (m_pObjects && m_pObjects->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for (it = m_pObjects->begin(); it != m_pObjects->end(); ++it)
|
CCARRAY_FOREACH(m_pObjects, pObj)
|
||||||
{
|
{
|
||||||
CCString *name = (*it)->objectForKey(std::string("name"));
|
CCDictionary* pDict = (CCDictionary*)pObj;
|
||||||
|
CCString *name = (CCString*)pDict->objectForKey("name");
|
||||||
if (name && name->m_sString == objectName)
|
if (name && name->m_sString == objectName)
|
||||||
{
|
{
|
||||||
return *it;
|
return pDict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,28 +65,28 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
CCString* CCTMXObjectGroup::propertyNamed(const char* propertyName)
|
CCString* CCTMXObjectGroup::propertyNamed(const char* propertyName)
|
||||||
{
|
{
|
||||||
return m_pProperties->objectForKey(std::string(propertyName));
|
return (CCString*)m_pProperties->objectForKey(propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStringToStringDictionary * CCTMXObjectGroup::getProperties()
|
CCDictionary* CCTMXObjectGroup::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXObjectGroup::setProperties(CCStringToStringDictionary * properties)
|
void CCTMXObjectGroup::setProperties(CCDictionary * properties)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(properties);
|
CC_SAFE_RETAIN(properties);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
m_pProperties = properties;
|
m_pProperties = properties;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCStringToStringDictionary*> *CCTMXObjectGroup::getObjects()
|
CCArray* CCTMXObjectGroup::getObjects()
|
||||||
{
|
{
|
||||||
return m_pObjects;
|
return m_pObjects;
|
||||||
}
|
}
|
||||||
void CCTMXObjectGroup::setObjects(CCMutableArray<CCStringToStringDictionary*> * objects)
|
void CCTMXObjectGroup::setObjects(CCArray* objects)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(objects);
|
CC_SAFE_RETAIN(objects);
|
||||||
CC_SAFE_RELEASE(m_pObjects);
|
CC_SAFE_RELEASE(m_pObjects);
|
||||||
m_pObjects = objects;
|
m_pObjects = objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace cocos2d
|
NS_CC_END
|
||||||
|
|
|
@ -101,24 +101,24 @@ CCTMXTiledMap::~CCTMXTiledMap()
|
||||||
CC_SAFE_RELEASE(m_pTileProperties);
|
CC_SAFE_RELEASE(m_pTileProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMutableArray<CCTMXObjectGroup*> * CCTMXTiledMap::getObjectGroups()
|
CCArray* CCTMXTiledMap::getObjectGroups()
|
||||||
{
|
{
|
||||||
return m_pObjectGroups;
|
return m_pObjectGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
|
void CCTMXTiledMap::setObjectGroups(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pObjectGroups);
|
CC_SAFE_RELEASE(m_pObjectGroups);
|
||||||
m_pObjectGroups = var;
|
m_pObjectGroups = var;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStringToStringDictionary * CCTMXTiledMap::getProperties()
|
CCDictionary * CCTMXTiledMap::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTMXTiledMap::setProperties(CCStringToStringDictionary* var)
|
void CCTMXTiledMap::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
|
@ -141,14 +141,14 @@ CCTMXLayer * CCTMXTiledMap::parseLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *
|
||||||
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
|
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
|
||||||
{
|
{
|
||||||
CCSize size = layerInfo->m_tLayerSize;
|
CCSize size = layerInfo->m_tLayerSize;
|
||||||
CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets();
|
CCArray* tilesets = mapInfo->getTilesets();
|
||||||
if (tilesets && tilesets->count()>0)
|
if (tilesets && tilesets->count()>0)
|
||||||
{
|
{
|
||||||
CCTMXTilesetInfo* tileset = NULL;
|
CCTMXTilesetInfo* tileset = NULL;
|
||||||
CCMutableArray<CCTMXTilesetInfo*>::CCMutableArrayRevIterator rit;
|
CCObject* pObj = NULL;
|
||||||
for (rit = tilesets->rbegin(); rit != tilesets->rend(); ++rit)
|
CCARRAY_FOREACH_REVERSE(tilesets, pObj);
|
||||||
{
|
{
|
||||||
tileset = *rit;
|
tileset = (CCTMXTilesetInfo*)pObj;
|
||||||
if (tileset)
|
if (tileset)
|
||||||
{
|
{
|
||||||
for( unsigned int y=0; y < size.height; y++ )
|
for( unsigned int y=0; y < size.height; y++ )
|
||||||
|
@ -179,7 +179,7 @@ CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCT
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all the tiles are 0, return empty tileset
|
// If all the tiles are 0, return empty tileset
|
||||||
CCLOG("cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo->m_sName.c_str());
|
CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->m_sName.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,14 +203,14 @@ void CCTMXTiledMap::buildWithMapInfo(CCTMXMapInfo* mapInfo)
|
||||||
|
|
||||||
int idx=0;
|
int idx=0;
|
||||||
|
|
||||||
CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
|
CCArray* layers = mapInfo->getLayers();
|
||||||
if (layers && layers->count()>0)
|
if (layers && layers->count()>0)
|
||||||
{
|
{
|
||||||
CCTMXLayerInfo* layerInfo = NULL;
|
CCTMXLayerInfo* layerInfo = NULL;
|
||||||
CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for (it = layers->begin(); it != layers->end(); ++it)
|
CCARRAY_FOREACH(layers, pObj)
|
||||||
{
|
{
|
||||||
layerInfo = *it;
|
layerInfo = (CCTMXLayerInfo*)pObj;
|
||||||
if (layerInfo && layerInfo->m_bVisible)
|
if (layerInfo && layerInfo->m_bVisible)
|
||||||
{
|
{
|
||||||
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
|
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
|
||||||
|
@ -257,11 +257,11 @@ CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName)
|
||||||
std::string sGroupName = groupName;
|
std::string sGroupName = groupName;
|
||||||
if (m_pObjectGroups && m_pObjectGroups->count()>0)
|
if (m_pObjectGroups && m_pObjectGroups->count()>0)
|
||||||
{
|
{
|
||||||
CCTMXObjectGroup *objectGroup;
|
CCTMXObjectGroup* objectGroup = NULL;
|
||||||
CCMutableArray<CCTMXObjectGroup*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for (it = m_pObjectGroups->begin(); it != m_pObjectGroups->end(); ++it)
|
CCARRAY_FOREACH(m_pObjectGroups, pObj)
|
||||||
{
|
{
|
||||||
objectGroup = (CCTMXObjectGroup*)(*it);
|
objectGroup = (CCTMXObjectGroup*)(pObj);
|
||||||
if (objectGroup && objectGroup->getGroupName() == sGroupName)
|
if (objectGroup && objectGroup->getGroupName() == sGroupName)
|
||||||
{
|
{
|
||||||
return objectGroup;
|
return objectGroup;
|
||||||
|
@ -275,11 +275,12 @@ CCTMXObjectGroup * CCTMXTiledMap::objectGroupNamed(const char *groupName)
|
||||||
|
|
||||||
CCString* CCTMXTiledMap::propertyNamed(const char *propertyName)
|
CCString* CCTMXTiledMap::propertyNamed(const char *propertyName)
|
||||||
{
|
{
|
||||||
return m_pProperties->objectForKey(std::string(propertyName));
|
return (CCString*)m_pProperties->objectForKey(propertyName);
|
||||||
}
|
}
|
||||||
CCDictionary<std::string, CCString*> * CCTMXTiledMap::propertiesForGID(int GID)
|
|
||||||
|
CCDictionary* CCTMXTiledMap::propertiesForGID(int GID)
|
||||||
{
|
{
|
||||||
return m_pTileProperties->objectForKey(GID);
|
return (CCDictionary*)m_pTileProperties->objectForKey(GID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ THE SOFTWARE.
|
||||||
#include "support/base64.h"
|
#include "support/base64.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
/*
|
/*
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
||||||
#include "expat.h"
|
#include "expat.h"
|
||||||
|
@ -46,7 +47,7 @@ THE SOFTWARE.
|
||||||
#endf
|
#endf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace cocos2d {
|
NS_CC_BEGIN
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void tmx_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
void tmx_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
|
||||||
|
@ -72,7 +73,7 @@ namespace cocos2d {
|
||||||
, m_uMaxGID(0)
|
, m_uMaxGID(0)
|
||||||
, m_tOffset(CCPointZero)
|
, m_tOffset(CCPointZero)
|
||||||
{
|
{
|
||||||
m_pProperties= new CCStringToStringDictionary();;
|
m_pProperties= new CCDictionary();;
|
||||||
}
|
}
|
||||||
CCTMXLayerInfo::~CCTMXLayerInfo()
|
CCTMXLayerInfo::~CCTMXLayerInfo()
|
||||||
{
|
{
|
||||||
|
@ -84,11 +85,11 @@ namespace cocos2d {
|
||||||
m_pTiles = NULL;
|
m_pTiles = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CCStringToStringDictionary * CCTMXLayerInfo::getProperties()
|
CCDictionary * CCTMXLayerInfo::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXLayerInfo::setProperties(CCStringToStringDictionary* var)
|
void CCTMXLayerInfo::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
|
@ -149,13 +150,19 @@ namespace cocos2d {
|
||||||
|
|
||||||
void CCTMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
void CCTMXMapInfo::internalInit(const char* tmxFileName, const char* resourcePath)
|
||||||
{
|
{
|
||||||
m_pTilesets = new CCMutableArray<CCTMXTilesetInfo*>();
|
m_pTilesets = CCArray::array();
|
||||||
m_pLayers = new CCMutableArray<CCTMXLayerInfo*>();
|
m_pTilesets->retain();
|
||||||
|
|
||||||
|
m_pLayers = CCArray::array();
|
||||||
|
m_pLayers->retain();
|
||||||
|
|
||||||
m_sTMXFileName = CCFileUtils::fullPathFromRelativePath(tmxFileName);
|
m_sTMXFileName = CCFileUtils::fullPathFromRelativePath(tmxFileName);
|
||||||
m_sResources = resourcePath;
|
m_sResources = resourcePath;
|
||||||
m_pObjectGroups = new CCMutableArray<CCTMXObjectGroup*>();
|
m_pObjectGroups = CCArray::array();
|
||||||
m_pProperties = new CCStringToStringDictionary();
|
m_pObjectGroups->retain();
|
||||||
m_pTileProperties = new CCDictionary<int, CCStringToStringDictionary*>();
|
|
||||||
|
m_pProperties = new CCDictionary();
|
||||||
|
m_pTileProperties = new CCDictionary();
|
||||||
|
|
||||||
// tmp vars
|
// tmp vars
|
||||||
m_sCurrentString = "";
|
m_sCurrentString = "";
|
||||||
|
@ -196,51 +203,53 @@ namespace cocos2d {
|
||||||
CC_SAFE_RELEASE(m_pTileProperties);
|
CC_SAFE_RELEASE(m_pTileProperties);
|
||||||
CC_SAFE_RELEASE(m_pObjectGroups);
|
CC_SAFE_RELEASE(m_pObjectGroups);
|
||||||
}
|
}
|
||||||
CCMutableArray<CCTMXLayerInfo*> * CCTMXMapInfo::getLayers()
|
CCArray* CCTMXMapInfo::getLayers()
|
||||||
{
|
{
|
||||||
return m_pLayers;
|
return m_pLayers;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setLayers(CCMutableArray<CCTMXLayerInfo*>* var)
|
void CCTMXMapInfo::setLayers(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pLayers);
|
CC_SAFE_RELEASE(m_pLayers);
|
||||||
m_pLayers = var;
|
m_pLayers = var;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCTMXTilesetInfo*> * CCTMXMapInfo::getTilesets()
|
CCArray* CCTMXMapInfo::getTilesets()
|
||||||
{
|
{
|
||||||
return m_pTilesets;
|
return m_pTilesets;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setTilesets(CCMutableArray<CCTMXTilesetInfo*>* var)
|
void CCTMXMapInfo::setTilesets(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pTilesets);
|
CC_SAFE_RELEASE(m_pTilesets);
|
||||||
m_pTilesets = var;
|
m_pTilesets = var;
|
||||||
}
|
}
|
||||||
CCMutableArray<CCTMXObjectGroup*> * CCTMXMapInfo::getObjectGroups()
|
CCArray* CCTMXMapInfo::getObjectGroups()
|
||||||
{
|
{
|
||||||
return m_pObjectGroups;
|
return m_pObjectGroups;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var)
|
void CCTMXMapInfo::setObjectGroups(CCArray* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pObjectGroups);
|
CC_SAFE_RELEASE(m_pObjectGroups);
|
||||||
m_pObjectGroups = var;
|
m_pObjectGroups = var;
|
||||||
}
|
}
|
||||||
CCStringToStringDictionary * CCTMXMapInfo::getProperties()
|
CCDictionary * CCTMXMapInfo::getProperties()
|
||||||
{
|
{
|
||||||
return m_pProperties;
|
return m_pProperties;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setProperties(CCStringToStringDictionary* var)
|
void CCTMXMapInfo::setProperties(CCDictionary* var)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(var);
|
CC_SAFE_RETAIN(var);
|
||||||
CC_SAFE_RELEASE(m_pProperties);
|
CC_SAFE_RELEASE(m_pProperties);
|
||||||
m_pProperties = var;
|
m_pProperties = var;
|
||||||
}
|
}
|
||||||
CCDictionary<int, CCStringToStringDictionary*> * CCTMXMapInfo::getTileProperties()
|
|
||||||
|
CCDictionary* CCTMXMapInfo::getTileProperties()
|
||||||
{
|
{
|
||||||
return m_pTileProperties;
|
return m_pTileProperties;
|
||||||
}
|
}
|
||||||
void CCTMXMapInfo::setTileProperties(CCDictionary<int, CCStringToStringDictionary*> * tileProperties)
|
|
||||||
|
void CCTMXMapInfo::setTileProperties(CCDictionary* tileProperties)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(tileProperties);
|
CC_SAFE_RETAIN(tileProperties);
|
||||||
CC_SAFE_RELEASE(m_pTileProperties);
|
CC_SAFE_RELEASE(m_pTileProperties);
|
||||||
|
@ -346,8 +355,8 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
else if(elementName == "tile")
|
else if(elementName == "tile")
|
||||||
{
|
{
|
||||||
CCTMXTilesetInfo* info = pTMXMapInfo->getTilesets()->getLastObject();
|
CCTMXTilesetInfo* info = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
|
||||||
CCStringToStringDictionary *dict = new CCStringToStringDictionary();
|
CCDictionary *dict = new CCDictionary();
|
||||||
pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
|
pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
|
||||||
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
|
||||||
CC_SAFE_RELEASE(dict);
|
CC_SAFE_RELEASE(dict);
|
||||||
|
@ -407,7 +416,7 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
else if(elementName == "image")
|
else if(elementName == "image")
|
||||||
{
|
{
|
||||||
CCTMXTilesetInfo *tileset = pTMXMapInfo->getTilesets()->getLastObject();
|
CCTMXTilesetInfo* tileset = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
|
||||||
|
|
||||||
// build full path
|
// build full path
|
||||||
std::string imagename = valueForKey("source", attributeDict);
|
std::string imagename = valueForKey("source", attributeDict);
|
||||||
|
@ -442,30 +451,30 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
else if(elementName == "object")
|
else if(elementName == "object")
|
||||||
{
|
{
|
||||||
char buffer[32];
|
char buffer[32] = {0};
|
||||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
|
||||||
|
|
||||||
// The value for "type" was blank or not a valid class name
|
// The value for "type" was blank or not a valid class name
|
||||||
// Create an instance of TMXObjectInfo to store the object and its properties
|
// Create an instance of TMXObjectInfo to store the object and its properties
|
||||||
CCStringToStringDictionary *dict = new CCStringToStringDictionary();
|
CCDictionary *dict = new CCDictionary();
|
||||||
|
|
||||||
// Set the name of the object to the value for "name"
|
// Set the name of the object to the value for "name"
|
||||||
std::string key = "name";
|
std::string key = "name";
|
||||||
CCString *value = new CCString(valueForKey("name", attributeDict));
|
CCString *value = new CCString(valueForKey("name", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
// Assign all the attributes as key/name pairs in the properties dictionary
|
// Assign all the attributes as key/name pairs in the properties dictionary
|
||||||
key = "type";
|
key = "type";
|
||||||
value = new CCString(valueForKey("type", attributeDict));
|
value = new CCString(valueForKey("type", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
int x = atoi(valueForKey("x", attributeDict)) + (int)objectGroup->getPositionOffset().x;
|
int x = atoi(valueForKey("x", attributeDict)) + (int)objectGroup->getPositionOffset().x;
|
||||||
key = "x";
|
key = "x";
|
||||||
sprintf(buffer, "%d", x);
|
sprintf(buffer, "%d", x);
|
||||||
value = new CCString(buffer);
|
value = new CCString(buffer);
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
int y = atoi(valueForKey("y", attributeDict)) + (int)objectGroup->getPositionOffset().y;
|
int y = atoi(valueForKey("y", attributeDict)) + (int)objectGroup->getPositionOffset().y;
|
||||||
|
@ -474,17 +483,17 @@ namespace cocos2d {
|
||||||
key = "y";
|
key = "y";
|
||||||
sprintf(buffer, "%d", y);
|
sprintf(buffer, "%d", y);
|
||||||
value = new CCString(buffer);
|
value = new CCString(buffer);
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
key = "width";
|
key = "width";
|
||||||
value = new CCString(valueForKey("width", attributeDict));
|
value = new CCString(valueForKey("width", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
key = "height";
|
key = "height";
|
||||||
value = new CCString(valueForKey("height", attributeDict));
|
value = new CCString(valueForKey("height", attributeDict));
|
||||||
dict->setObject(value, key);
|
dict->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
// Add the object to the objectGroup
|
// Add the object to the objectGroup
|
||||||
|
@ -507,27 +516,27 @@ namespace cocos2d {
|
||||||
// The parent element is the map
|
// The parent element is the map
|
||||||
CCString *value = new CCString(valueForKey("value", attributeDict));
|
CCString *value = new CCString(valueForKey("value", attributeDict));
|
||||||
std::string key = valueForKey("name", attributeDict);
|
std::string key = valueForKey("name", attributeDict);
|
||||||
pTMXMapInfo->getProperties()->setObject(value, key);
|
pTMXMapInfo->getProperties()->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
|
||||||
{
|
{
|
||||||
// The parent element is the last layer
|
// The parent element is the last layer
|
||||||
CCTMXLayerInfo *layer = pTMXMapInfo->getLayers()->getLastObject();
|
CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject();
|
||||||
CCString *value = new CCString(valueForKey("value", attributeDict));
|
CCString *value = new CCString(valueForKey("value", attributeDict));
|
||||||
std::string key = valueForKey("name", attributeDict);
|
std::string key = valueForKey("name", attributeDict);
|
||||||
// Add the property to the layer
|
// Add the property to the layer
|
||||||
layer->getProperties()->setObject(value, key);
|
layer->getProperties()->setObject(value, key.c_str());
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup )
|
||||||
{
|
{
|
||||||
// The parent element is the last object group
|
// The parent element is the last object group
|
||||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
|
||||||
CCString *value = new CCString(valueForKey("value", attributeDict));
|
CCString *value = new CCString(valueForKey("value", attributeDict));
|
||||||
std::string key = valueForKey("name", attributeDict);
|
const char* key = valueForKey("name", attributeDict);
|
||||||
objectGroup->getProperties()->setObject(value, key);
|
objectGroup->getProperties()->setObject(value, key);
|
||||||
value->release();
|
value->release();
|
||||||
|
|
||||||
|
@ -535,20 +544,19 @@ namespace cocos2d {
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
|
||||||
{
|
{
|
||||||
// The parent element is the last object
|
// The parent element is the last object
|
||||||
CCTMXObjectGroup *objectGroup = pTMXMapInfo->getObjectGroups()->getLastObject();
|
CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
|
||||||
CCStringToStringDictionary *dict = objectGroup->getObjects()->getLastObject();
|
CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
|
||||||
|
|
||||||
std::string propertyName = valueForKey("name", attributeDict);
|
const char* propertyName = valueForKey("name", attributeDict);
|
||||||
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
||||||
dict->setObject(propertyValue, propertyName);
|
dict->setObject(propertyValue, propertyName);
|
||||||
propertyValue->release();
|
propertyValue->release();
|
||||||
}
|
}
|
||||||
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile )
|
||||||
{
|
{
|
||||||
CCStringToStringDictionary *dict;
|
CCDictionary* dict = (CCDictionary*)pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());
|
||||||
dict = pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());
|
|
||||||
|
|
||||||
std::string propertyName = valueForKey("name", attributeDict);
|
const char* propertyName = valueForKey("name", attributeDict);
|
||||||
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
|
||||||
dict->setObject(propertyValue, propertyName);
|
dict->setObject(propertyValue, propertyName);
|
||||||
propertyValue->release();
|
propertyValue->release();
|
||||||
|
@ -573,7 +581,7 @@ namespace cocos2d {
|
||||||
{
|
{
|
||||||
pTMXMapInfo->setStoringCharacters(false);
|
pTMXMapInfo->setStoringCharacters(false);
|
||||||
|
|
||||||
CCTMXLayerInfo *layer = pTMXMapInfo->getLayers()->getLastObject();
|
CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject();
|
||||||
|
|
||||||
std::string currentString = pTMXMapInfo->getCurrentString();
|
std::string currentString = pTMXMapInfo->getCurrentString();
|
||||||
unsigned char *buffer;
|
unsigned char *buffer;
|
||||||
|
@ -651,4 +659,5 @@ namespace cocos2d {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}//namespace cocos2d
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCTouchDispatcher.h"
|
#include "CCTouchDispatcher.h"
|
||||||
#include "CCTouchHandler.h"
|
#include "CCTouchHandler.h"
|
||||||
#include "CCMutableArray.h"
|
#include "CCArray.h"
|
||||||
#include "CCSet.h"
|
#include "CCSet.h"
|
||||||
#include "CCTouch.h"
|
#include "CCTouch.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
@ -36,9 +36,9 @@ THE SOFTWARE.
|
||||||
/**
|
/**
|
||||||
* Used for sort
|
* Used for sort
|
||||||
*/
|
*/
|
||||||
static bool less(const cocos2d::CCTouchHandler *p1, const cocos2d::CCTouchHandler *p2)
|
static int less(const void* p1, const void* p2)
|
||||||
{
|
{
|
||||||
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority();
|
return ((cocos2d::CCTouchHandler*)p1)->getPriority() < ((cocos2d::CCTouchHandler*)p2)->getPriority() ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
@ -81,10 +81,12 @@ CCTouchDispatcher* CCTouchDispatcher::sharedDispatcher(void)
|
||||||
bool CCTouchDispatcher::init(void)
|
bool CCTouchDispatcher::init(void)
|
||||||
{
|
{
|
||||||
m_bDispatchEvents = true;
|
m_bDispatchEvents = true;
|
||||||
m_pTargetedHandlers = new CCMutableArray<CCTouchHandler*>(8);
|
m_pTargetedHandlers = CCArray::arrayWithCapacity(8);
|
||||||
m_pStandardHandlers = new CCMutableArray<CCTouchHandler*>(4);
|
m_pTargetedHandlers->retain();
|
||||||
|
m_pStandardHandlers = CCArray::arrayWithCapacity(4);
|
||||||
|
m_pStandardHandlers->retain();
|
||||||
|
|
||||||
m_pHandlersToAdd = new CCMutableArray<CCTouchHandler*>(8);
|
m_pHandlersToAdd = CCArray::arrayWithCapacity(8);
|
||||||
m_pHandlersToRemove = ccCArrayNew(8);
|
m_pHandlersToRemove = ccCArrayNew(8);
|
||||||
|
|
||||||
m_bToRemove = false;
|
m_bToRemove = false;
|
||||||
|
@ -113,14 +115,14 @@ CCTouchDispatcher::~CCTouchDispatcher(void)
|
||||||
//
|
//
|
||||||
// handlers management
|
// handlers management
|
||||||
//
|
//
|
||||||
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCMutableArray<CCTouchHandler*> *pArray)
|
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCArray *pArray)
|
||||||
{
|
{
|
||||||
unsigned int u = 0;
|
unsigned int u = 0;
|
||||||
|
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
CCARRAY_FOREACH(pArray, pObj)
|
||||||
{
|
{
|
||||||
CCTouchHandler *h = *iter;
|
CCTouchHandler *h = (CCTouchHandler *)pObj;
|
||||||
if (h)
|
if (h)
|
||||||
{
|
{
|
||||||
if (h->getPriority() < pHandler->getPriority())
|
if (h->getPriority() < pHandler->getPriority())
|
||||||
|
@ -136,7 +138,7 @@ void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, CCMutableArray
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pArray->insertObjectAtIndex(pHandler, u);
|
pArray->insertObject(pHandler, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||||
|
@ -188,14 +190,14 @@ void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPri
|
||||||
void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
||||||
{
|
{
|
||||||
CCTouchHandler *pHandler;
|
CCTouchHandler *pHandler;
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
|
||||||
|
|
||||||
// XXX: remove it from both handlers ???
|
// XXX: remove it from both handlers ???
|
||||||
|
|
||||||
// remove handler from m_pStandardHandlers
|
// remove handler from m_pStandardHandlers
|
||||||
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pStandardHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCTouchHandler*)pObj;
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
m_pStandardHandlers->removeObject(pHandler);
|
m_pStandardHandlers->removeObject(pHandler);
|
||||||
|
@ -204,9 +206,9 @@ void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove handler from m_pTargetedHandlers
|
// remove handler from m_pTargetedHandlers
|
||||||
for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter)
|
CCARRAY_FOREACH(m_pTargetedHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCTouchHandler*)pObj;
|
||||||
if (pHandler && pHandler->getDelegate() == pDelegate)
|
if (pHandler && pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
m_pTargetedHandlers->removeObject(pHandler);
|
m_pTargetedHandlers->removeObject(pHandler);
|
||||||
|
@ -263,47 +265,49 @@ void CCTouchDispatcher::removeAllDelegates(void)
|
||||||
|
|
||||||
CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate)
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(m_pTargetedHandlers, pObj)
|
||||||
for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if ((*iter)->getDelegate() == pDelegate)
|
CCTouchHandler* pHandler = (CCTouchHandler*)pObj;
|
||||||
|
if (pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
return *iter;
|
return pHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
CCARRAY_FOREACH(m_pStandardHandlers, pObj)
|
||||||
{
|
{
|
||||||
if ((*iter)->getDelegate() == pDelegate)
|
CCTouchHandler* pHandler = (CCTouchHandler*)pObj;
|
||||||
|
if (pHandler->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
return *iter;
|
return pHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTouchHandler* CCTouchDispatcher::findHandler(CCMutableArray<CCTouchHandler*> *pArray, CCTouchDelegate *pDelegate)
|
CCTouchHandler* CCTouchDispatcher::findHandler(CCArray* pArray, CCTouchDelegate *pDelegate)
|
||||||
{
|
{
|
||||||
CCAssert(pArray != NULL && pDelegate != NULL, "");
|
CCAssert(pArray != NULL && pDelegate != NULL, "");
|
||||||
|
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(pArray, pObj)
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if ((*iter)->getDelegate() == pDelegate)
|
CCTouchHandler* pHandle = (CCTouchHandler*)pObj;
|
||||||
|
if (pHandle->getDelegate() == pDelegate)
|
||||||
{
|
{
|
||||||
return *iter;
|
return pHandle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchDispatcher::rearrangeHandlers(CCMutableArray<CCTouchHandler*> *pArray)
|
void CCTouchDispatcher::rearrangeHandlers(CCArray *pArray)
|
||||||
{
|
{
|
||||||
std::sort(pArray->begin(), pArray->end(), less);
|
// FIXME: qsort is not supported in bada1.0, so we must implement it ourselves.
|
||||||
|
qsort(pArray->data->arr, pArray->data->num, sizeof(pArray->data->arr[0]), less);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
||||||
|
@ -350,12 +354,12 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u
|
||||||
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
for (setIter = pTouches->begin(); setIter != pTouches->end(); ++setIter)
|
||||||
{
|
{
|
||||||
pTouch = (CCTouch *)(*setIter);
|
pTouch = (CCTouch *)(*setIter);
|
||||||
CCTargetedTouchHandler *pHandler;
|
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator arrayIter;
|
CCTargetedTouchHandler *pHandler = NULL;
|
||||||
for (arrayIter = m_pTargetedHandlers->begin(); arrayIter != m_pTargetedHandlers->end(); ++arrayIter)
|
CCObject* pObj = NULL;
|
||||||
/*for (unsigned int i = 0; i < m_pTargetedHandlers->num; ++i)*/
|
CCARRAY_FOREACH(m_pTargetedHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = (CCTargetedTouchHandler *)(*arrayIter);
|
pHandler = (CCTargetedTouchHandler *)(pObj);
|
||||||
|
|
||||||
if (! pHandler)
|
if (! pHandler)
|
||||||
{
|
{
|
||||||
|
@ -411,11 +415,11 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u
|
||||||
//
|
//
|
||||||
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
||||||
{
|
{
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCStandardTouchHandler *pHandler = NULL;
|
||||||
CCStandardTouchHandler *pHandler;
|
CCObject* pObj = NULL;
|
||||||
for (iter = m_pStandardHandlers->begin(); iter != m_pStandardHandlers->end(); ++iter)
|
CCARRAY_FOREACH(m_pStandardHandlers, pObj)
|
||||||
{
|
{
|
||||||
pHandler = (CCStandardTouchHandler*)(*iter);
|
pHandler = (CCStandardTouchHandler*)(pObj);
|
||||||
|
|
||||||
if (! pHandler)
|
if (! pHandler)
|
||||||
{
|
{
|
||||||
|
@ -463,11 +467,11 @@ void CCTouchDispatcher::touches(CCSet *pTouches, CCEvent *pEvent, unsigned int u
|
||||||
if (m_bToAdd)
|
if (m_bToAdd)
|
||||||
{
|
{
|
||||||
m_bToAdd = false;
|
m_bToAdd = false;
|
||||||
CCMutableArray<CCTouchHandler*>::CCMutableArrayIterator iter;
|
CCTouchHandler* pHandler = NULL;
|
||||||
CCTouchHandler *pHandler;
|
CCObject* pObj = NULL;
|
||||||
for (iter = m_pHandlersToAdd->begin(); iter != m_pHandlersToAdd->end(); ++iter)
|
CCARRAY_FOREACH(m_pHandlersToAdd, pObj)
|
||||||
{
|
{
|
||||||
pHandler = *iter;
|
pHandler = (CCTouchHandler*)pObj;
|
||||||
if (! pHandler)
|
if (! pHandler)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ACTION_MANUAL_LAYER = 0,
|
ACTION_MANUAL_LAYER = 0,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
7593bccdf37e94e6af9b7bfec82d6931c746f428
|
6b30e04685cc62b5daa0628f9bb038bc42bae923
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
#include "../testBasic.h"
|
#include "../testBasic.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class SpriteTestDemo : public CCLayer
|
class SpriteTestDemo : public CCLayer
|
||||||
{
|
{
|
||||||
|
|
|
@ -615,13 +615,13 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest()
|
||||||
|
|
||||||
////----UXLOG("----> Iterating over all the group objets");
|
////----UXLOG("----> Iterating over all the group objets");
|
||||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
|
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict = NULL;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
{
|
{
|
||||||
dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
|
@ -639,24 +639,23 @@ void TMXOrthoObjectsTest::draw()
|
||||||
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||||
|
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict = NULL;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
|
||||||
{
|
{
|
||||||
dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
std::string key = "x";
|
const char* key = "x";
|
||||||
int x = dict->objectForKey(key)->toInt();
|
int x = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "y";
|
key = "y";
|
||||||
int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
int y = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||||
key = "width";
|
key = "width";
|
||||||
int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
int width = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||||
key = "height";
|
key = "height";
|
||||||
int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
int height = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||||
|
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
@ -697,15 +696,13 @@ TMXIsoObjectsTest::TMXIsoObjectsTest()
|
||||||
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1");
|
||||||
|
|
||||||
//UxMutableArray* objects = group->objects();
|
//UxMutableArray* objects = group->objects();
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
//UxMutableDictionary<std::string>* dict;
|
//UxMutableDictionary<std::string>* dict;
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict;
|
||||||
//CCMutableArray<CCObject*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
|
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
|
||||||
{
|
{
|
||||||
dict = (*it);
|
dict = (CCDictionary*)pObj;
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
|
@ -719,24 +716,23 @@ void TMXIsoObjectsTest::draw()
|
||||||
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
CCTMXTiledMap *map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
|
||||||
CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
|
CCTMXObjectGroup *group = map->objectGroupNamed("Object Group 1");
|
||||||
|
|
||||||
CCMutableArray<CCStringToStringDictionary*> * objects = group->getObjects();
|
CCArray* objects = group->getObjects();
|
||||||
CCStringToStringDictionary* dict;
|
CCDictionary* dict;
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(objects, pObj)
|
||||||
for( it = objects->begin(); it != objects->end(); it++)
|
|
||||||
{
|
{
|
||||||
dict = (*it);//dynamic_cast<CCStringToStringDictionary*>(*it);
|
dict = (CCDictionary*)pObj;//dynamic_cast<CCStringToStringDictionary*>(*it);
|
||||||
|
|
||||||
if(!dict)
|
if(!dict)
|
||||||
break;
|
break;
|
||||||
std::string key = "x";
|
const char* key = "x";
|
||||||
int x = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
int x = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("x"))->getNumber();
|
||||||
key = "y";
|
key = "y";
|
||||||
int y = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
int y = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("y"))->getNumber();
|
||||||
key = "width";
|
key = "width";
|
||||||
int width = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
int width = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("width"))->getNumber();
|
||||||
key = "height";
|
key = "height";
|
||||||
int height = dict->objectForKey(key)->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
int height = ((CCString*)dict->objectForKey(key))->toInt();//dynamic_cast<NSNumber*>(dict->objectForKey("height"))->getNumber();
|
||||||
|
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
@ -1412,26 +1408,25 @@ void TMXGIDObjectsTest::draw()
|
||||||
CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
CCTMXTiledMap *map = (CCTMXTiledMap*)getChildByTag(kTagTileMap);
|
||||||
CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
|
CCTMXObjectGroup *group = map->objectGroupNamed("Object Layer 1");
|
||||||
|
|
||||||
CCMutableArray<CCStringToStringDictionary*> *array = group->getObjects();
|
CCArray *array = group->getObjects();
|
||||||
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator iter;
|
CCDictionary* dict;
|
||||||
CCStringToStringDictionary *dict;
|
CCObject* pObj = NULL;
|
||||||
|
CCARRAY_FOREACH(array, pObj)
|
||||||
for (iter = array->begin(); iter != array->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
dict = *iter;
|
dict = (CCDictionary*)pObj;
|
||||||
if(!dict)
|
if(!dict)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string key = "x";
|
const char* key = "x";
|
||||||
int x = dict->objectForKey(key)->toInt();
|
int x = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "y";
|
key = "y";
|
||||||
int y = dict->objectForKey(key)->toInt();
|
int y = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "width";
|
key = "width";
|
||||||
int width = dict->objectForKey(key)->toInt();
|
int width = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
key = "height";
|
key = "height";
|
||||||
int height = dict->objectForKey(key)->toInt();
|
int height = ((CCString*)dict->objectForKey(key))->toInt();
|
||||||
|
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ PongLayer::PongLayer()
|
||||||
|
|
||||||
CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle);
|
CCTexture2D* paddleTexture = CCTextureCache::sharedTextureCache()->addImage(s_Paddle);
|
||||||
|
|
||||||
CCMutableArray<CCObject *> *paddlesM = new CCMutableArray<CCObject *>(4);
|
CCArray *paddlesM = CCArray::arrayWithCapacity(4);
|
||||||
|
|
||||||
Paddle* paddle = Paddle::paddleWithTexture(paddleTexture);
|
Paddle* paddle = Paddle::paddleWithTexture(paddleTexture);
|
||||||
paddle->setPosition( CCPointMake(160, 15) );
|
paddle->setPosition( CCPointMake(160, 15) );
|
||||||
|
@ -72,12 +72,12 @@ PongLayer::PongLayer()
|
||||||
paddle->setPosition( CCPointMake(160, 480 - kStatusBarHeight - 100) );
|
paddle->setPosition( CCPointMake(160, 480 - kStatusBarHeight - 100) );
|
||||||
paddlesM->addObject( paddle );
|
paddlesM->addObject( paddle );
|
||||||
|
|
||||||
m_paddles = paddlesM->copy();
|
m_paddles = (CCArray*)paddlesM->copy();
|
||||||
|
|
||||||
CCMutableArray<CCObject *>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for(it = m_paddles->begin(); it != m_paddles->end(); it++)
|
CCARRAY_FOREACH(m_paddles, pObj)
|
||||||
{
|
{
|
||||||
paddle = (Paddle*)(*it);
|
paddle = (Paddle*)(pObj);
|
||||||
|
|
||||||
if(!paddle)
|
if(!paddle)
|
||||||
break;
|
break;
|
||||||
|
@ -85,8 +85,6 @@ PongLayer::PongLayer()
|
||||||
addChild(paddle);
|
addChild(paddle);
|
||||||
}
|
}
|
||||||
|
|
||||||
paddlesM->release();
|
|
||||||
|
|
||||||
schedule( schedule_selector(PongLayer::doStep) );
|
schedule( schedule_selector(PongLayer::doStep) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,11 +107,11 @@ void PongLayer::doStep(ccTime delta)
|
||||||
{
|
{
|
||||||
m_ball->move(delta);
|
m_ball->move(delta);
|
||||||
|
|
||||||
Paddle* paddle;
|
Paddle* paddle = NULL;
|
||||||
CCMutableArray<CCObject *>::CCMutableArrayIterator it;
|
CCObject* pObj = NULL;
|
||||||
for(it = m_paddles->begin(); it != m_paddles->end(); it++)
|
CCARRAY_FOREACH(m_paddles, pObj)
|
||||||
{
|
{
|
||||||
paddle = (Paddle*)(*it);
|
paddle = (Paddle*)(pObj);
|
||||||
|
|
||||||
if(!paddle)
|
if(!paddle)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Ball;
|
||||||
class PongLayer : public CCLayer
|
class PongLayer : public CCLayer
|
||||||
{
|
{
|
||||||
Ball* m_ball;
|
Ball* m_ball;
|
||||||
CCMutableArray<CCObject *> *m_paddles;
|
CCArray* m_paddles;
|
||||||
CCPoint m_ballStartingVelocity;
|
CCPoint m_ballStartingVelocity;
|
||||||
public:
|
public:
|
||||||
PongLayer();
|
PongLayer();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class TestScene : public CCScene
|
class TestScene : public CCScene
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue