static void array_Value(CCArray * aArray, const cocos2d::ValueVector & value)
{
    cocos2d::ValueVector::const_iterator beg = value.begin();
    cocos2d::ValueVector::const_iterator end = value.end();
    for (; beg != end; ++beg)
    {
        const Value & v = *beg;
        if (v.getType() == Value::Type::MAP)
        {
            CCDictionary * dict = new CCDictionary();
            dict->init();
            dictionary_Value(dict, v.asValueMap());
            aArray->addObject(dict);
            dict->release();
        }
        else if (v.getType() == Value::Type::VECTOR)
        {
            CCArray * arr = new CCArray();
            arr->init();
            array_Value(arr, v.asValueVector());
            aArray->addObject(arr);
            arr->release();
        }
        else
        {
            CCString * str = new CCString();
            if (v.getType() == Value::Type::DOUBLE)
                str->initWithFormat("%f", v.asDouble());
            else
                str->initWithFormat("%s", v.asString().c_str());
            aArray->addObject(str);
            str->release();
        }
    }
}
Example #2
0
CCArray* CCArray::create()
{
    CCArray* pArray = new CCArray();

    if (pArray && pArray->init())
    {
        pArray->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(pArray);
    }
    
    return pArray;
}
Example #3
0
//Given a set of points it returns a polygon surrounding those points (a convex hull)
//From here: http://www.algorithmist.com/index.php/Monotone_Chain_Convex_Hull.cpp
CCArray* GameHelper::convexHull(CCArray* P) {
	/*int n = P->count();
	int k = 0;
	CCArray *H = CCArray::create->initWithCapacity(n*2);
	
	//Sort points lexicographically (by X, then secondarily by Y)
	NSSortDescriptor *xDescriptor = NSSortDescriptor::alloc()->initWithKey("self.x" , true);
	NSSortDescriptor *yDescriptor = NSSortDescriptor::alloc()->initWithKey("self.y" , true);
	
	CCArray *descriptors = CCArray::arrayWithObjects(xDescriptor, yDescriptor, NULL);
	CCArray *sortedP = P::sortedArrayUsingDescriptors(descriptors);
	
	//Build lower hull
	for (int i = 0; i < n; i ++) {
		while (k >= 2 && this->clockwiseO([H , k-2) , H->objectAtIndex(k-1) , sortedP->objectAtIndex(i)]){
			k--;
		}
		H->insertObject([sortedP , i) , k++];
	};
 	
	//Build upper hull
	for (int i = n-2, t = k + 1; i >= 0; i --) {		
		while (k >= t && this->clockwiseO([H , k-2) , H->objectAtIndex(k-1) , sortedP->objectAtIndex(i)]){
			k--;
		}
		H->insertObject([sortedP , i) , k++];
	};	
	
	H->removeObjectsInRange(CCRangeMake(k, H.count-k));

	//Remove all duplicate objects
	CCArray *noDupeArray = CCArray::alloc()->init();
	for(int i = 0; i<H.count; i++){
		if(!noDupeArray->containsObject(H::objectAtIndex(i))){
			noDupeArray->addObject(H::objectAtIndex(i));
		}
	}*/

	CCArray *noDupeArray = CCArray::create();
	noDupeArray->init();
	return noDupeArray;
}
Example #4
0
EditorSprite* EditorLayer::findTouchSprite( cocos2d::CCTouch *pTouch )
{
	CCPoint pos = m_containerLayer->convertTouchToNodeSpace(pTouch);
	pos = pTouch->getLocation();
	CCLOG("position x = %.0f, y = %.0f", pos.x, pos.y);


	CCArray* arraySprites = new CCArray();
	arraySprites->init();

	for (unsigned int i=0; i<m_arraySprite->count(); i++)
	{
		EditorSprite* pEditorSprite = (EditorSprite*)m_arraySprite->objectAtIndex(i);
		if (!pEditorSprite->isTransparentInPoint(pos))
		{
			arraySprites->addObject(pEditorSprite);
		}
	}

	EditorSprite* pRet = NULL;
	if (arraySprites->count() > 0)
	{
		pRet = (EditorSprite*)arraySprites->objectAtIndex(0);
	}
	for (unsigned int i=0; i<arraySprites->count(); i++)
	{
		EditorSprite* pEditorSprite = (EditorSprite*)arraySprites->objectAtIndex(i);
		if (pEditorSprite->getOrderForAdd() > pRet->getOrderForAdd())
		{
			pRet = pEditorSprite;
		}
	}

	arraySprites->removeAllObjects();
	delete arraySprites;

	return pRet;
}
static void dictionary_Value(CCDictionary * aDict, const cocos2d::ValueMap & value)
{
    cocos2d::ValueMap::const_iterator beg = value.begin();
    cocos2d::ValueMap::const_iterator end = value.end();
    for (; beg != end; ++beg)
    {
        const std::string & key = (*beg).first;
        const cocos2d::Value & v = (*beg).second;
        if (v.getType() == Value::Type::MAP)
        {
            CCDictionary * d = new CCDictionary();
            d->init();
            dictionary_Value(d, v.asValueMap());
            aDict->setObject(d, key);
            d->release();
        }
        else if (v.getType() == Value::Type::VECTOR)
        {
            CCArray * a = new CCArray();
            a->init();
            array_Value(a, v.asValueVector());
            aDict->setObject(a, key);
            a->release();
        }
        else
        {
            CCString * str = new CCString();
            if (v.getType() == Value::Type::DOUBLE)
                str->initWithFormat("%f", v.asDouble());
            else
                str->initWithFormat("%s", v.asString().c_str());
            aDict->setObject(str, key);
            str->release();
        }
    }
}