Exemple #1
0
 void endElement(void *ctx, const char *name)
 {
     CC_UNUSED_PARAM(ctx);
     CCSAXState curState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
     std::string sName((char*)name);
     if( sName == "dict" )
     {
         m_tStateStack.pop();
         m_tDictStack.pop();
         if ( !m_tDictStack.empty())
         {
             m_pCurDict = m_tDictStack.top();
         }
     }
     else if (sName == "array")
     {
         m_tStateStack.pop();
         m_tArrayStack.pop();
         if (! m_tArrayStack.empty())
         {
             m_pArray = m_tArrayStack.top();
         }
     }
     else if (sName == "true")
     {
         CCString *str = new CCString("1");
         if (SAX_ARRAY == curState)
         {
             m_pArray->addObject(str);
         }
         else if (SAX_DICT == curState)
         {
             m_pCurDict->setObject(str, m_sCurKey);
         }
         str->release();
     }
     else if (sName == "false")
     {
         CCString *str = new CCString("0");
         if (SAX_ARRAY == curState)
         {
             m_pArray->addObject(str);
         }
         else if (SAX_DICT == curState)
         {
             m_pCurDict->setObject(str, m_sCurKey);
         }
         str->release();
     }
     m_tState = SAX_NONE;
 }
Exemple #2
0
    void textHandler(void *ctx, const char *ch, int len)
    {
        if (m_tState == SAX_NONE)
        {
            return;
        }
        CCString *pText = new CCString();
        pText->m_sString = std::string((char*)ch,0,len);

        switch(m_tState)
        {
        case SAX_KEY:
            m_sCurKey = pText->m_sString;
            break;
        case SAX_INT:
        case SAX_REAL:
        case SAX_STRING:
            {
                CCAssert(!m_sCurKey.empty(), "not found key : <integet/real>");

                if (m_bInArray)
                {
                    m_pArray->addObject(pText);
                }
                else
                {
                    m_pCurDict->setObject(pText, m_sCurKey);
                }
                break;
            }
        }
        pText->release();
    }
void plist_characters(void *ctx, const xmlChar *ch, int len)
{
 	CCDictMaker * pMaker = (CCDictMaker*)(ctx);
	if (pMaker->m_tState == SAX_NONE)
	{
		return;
	}
 	CCString *pText = new CCString();
	pText->m_sString = std::string((char*)ch,0,len);

 	switch(pMaker->m_tState)
 	{
 	case SAX_KEY:
 		pMaker->m_sCurKey = pText->m_sString;
 		break;
 	case SAX_INT:
 	case SAX_REAL:
 	case SAX_STRING:
 		{
 			CCAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
 			pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
 			break;
 		}
 	}
	pText->release();
}
Exemple #4
0
    void textHandler(void *ctx, const char *ch, int len)
    {
        CC_UNUSED_PARAM(ctx);
        if (m_tState == SAX_NONE)
        {
            return;
        }

        CCSAXState curState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
        CCString *pText = new CCString(std::string((char*)ch,0,len));

        switch(m_tState)
        {
        case SAX_KEY:
            m_sCurKey = pText->getCString();
            break;
        case SAX_INT:
        case SAX_REAL:
        case SAX_STRING:
            {
                if (curState == SAX_DICT)
                {
                    CCAssert(!m_sCurKey.empty(), "key not found : <integer/real>");
                }
                
                m_sCurValue.append(pText->getCString());
            }
            break;
        default:
            break;
        }
        pText->release();
    }
Exemple #5
0
void HSLog::SendDeviceInfo()
{
	LogRequest_TerminalLog* deviceInfo = m_pLog->mutable_terminallogs();
	std::string platform = "";
#if HSWin32
	platform = "Windows";
#elif HSAndroid
	platform = "Android";
#elif HSios
	platform = "IOS";
#endif
	CCString* dpiSize = CCString::createWithFormat("%dx%d",(int)HSBase::GetScreenWidth(),(int)HSBase::GetScreenHeight());


	deviceInfo->set_osname(platform);
	deviceInfo->set_dpisize(dpiSize->getCString());
	deviceInfo->set_clitype(platform);
	deviceInfo->set_verinfo(HSTool::ShareHSTool()->GetSystemVersions());
	deviceInfo->set_nettype(HSTool::ShareHSTool()->GetNetType());
	deviceInfo->set_netproinfo(HSTool::ShareHSTool()->GetOperator());
	deviceInfo->set_countryinfo(HSTool::ShareHSTool()->GetCountryInfo());
	deviceInfo->set_cityinfo(HSTool::ShareHSTool()->GetCityInfo());

	dpiSize->release();
}
Exemple #6
0
void NovelScene::changeBackground(CCNode *pSender, void* node)
{
    CCString* imgFilePath = (CCString*) node;
    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(imgFilePath->getCString());
    ((CCSprite*)pSender)->setTexture(texture);
    imgFilePath->release();
}
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();
        }
    }
}
void textHandler(void *ctx, const XML_Char *ch, int len)
{
 	CCDictMaker * pMaker = this;
	if (pMaker->m_tState == SAX_NONE)
	{
		return;
	}
 	CCString *pText = new CCString();
	pText->m_sString = std::string((char*)ch,0,len);

 	switch(pMaker->m_tState)
 	{
 	case SAX_KEY:
		{
			pMaker->m_sCurKey = pText->m_sString;
		}
 		break;
 	case SAX_INT:
 	case SAX_REAL:
 		{
 			CCAssert(!pMaker->m_sCurKey.empty(), "not found real : <integet/real>");
 			pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
 			break;
 		}
 	case SAX_STRING:
 		{
 			CCAssert(!pMaker->m_sCurKey.empty(), "not found string");
 			pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
 			break;
 		}
 	}
	pText->release();
}
void endElement(void *ctx, const XML_Char *name)
{
	std::string sName((char*)name);
	if( sName == "dict" )
	{
		m_tDictStack.pop();
		if ( !m_tDictStack.empty() )
		{
			m_pCurDict = (CCDictionary<std::string, CCObject*>*)(m_tDictStack.top());
		}
	}
    else if (sName == "array")
    {
        CCAssert(m_bInArray, "The plist file is wrong!");
        m_pCurDict->setObject(m_pArray, m_sCurKey);
        m_pArray->release();
        m_pArray = NULL;
        m_bInArray = false;
    }
    else if (sName == "true")
    {
        CCString *str = new CCString("1");
        if (m_bInArray)
        {
            m_pArray->addObject(str);
        }
        else
        {
            m_pCurDict->setObject(str, m_sCurKey);
        }
        str->release();
    }
    else if (sName == "false")
    {
        CCString *str = new CCString("0");
        if (m_bInArray)
        {
            m_pArray->addObject(str);
        }
        else
        {
            m_pCurDict->setObject(str, m_sCurKey);
        }
        str->release();
    }
	m_tState = SAX_NONE;
}
void ParseFile::downloadFileFinished(CCNode* sender, void* param)
{
	CCString* savePathName = 0;
	ParseError* error = new ParseError();

	CCHttpResponse* response = (CCHttpResponse*)param;
	
	if (response->getResponseCode() == 200)
	{
		FILE* file = 0;
		const char* errorMsg = 0;
		savePathName = (CCString*)response->getHttpRequest()->getUserData();
		std::vector<char>* responseData = response->getResponseData();
		do
		{
			file = fopen(savePathName->getCString(), "wb");
			if (file == 0)
			{
				errorMsg = "error open file!";
				break;
			}
			size_t writeLen = fwrite(&responseData->front(), 1, responseData->size(), file);
			if (writeLen != responseData->size())
			{
				errorMsg = "error write file!";
				break;
			}
		}while(0);

		if (file)
		{
			fclose(file);
		}
		if (errorMsg)
		{
			error->SetError(errorMsg);
		}
	}
	else
	{
		if (strlen(response->getErrorBuffer()) > 0)
		{
			error->SetError(response->getErrorBuffer());
		}
		else
		{
			std::vector<char>* responseData = response->getResponseData();
			responseData->push_back('\0');
			error->SetError(&responseData->front());
		}
	}

	this->downloadFileCompleted(savePathName?savePathName->getCString():0, error);

	savePathName = (CCString*)response->getHttpRequest()->getUserData();
	savePathName->release();

	delete error;
}
	void ProcessApplication::log(ELogType type, const char* format, ...)	{
		CCString* tempString = new CCString();
		va_list ap;
		va_start(ap, format);
		bool initialized(tempString->initWithFormatAndValist(format, ap));
		va_end(ap);
		if(initialized)	{
			log(type, EConsoleBackColor_Black, tempString->getCString());
		}
		tempString->release();
	}
Exemple #12
0
bool HSLanFilter::CreaterMessage(google::protobuf::Message* msg)
{    
	if (!msg)
	{
		return false;
	}
	std::string msgName = msg->GetTypeName();
    
	CCLog(msgName.c_str());
    
    if(!msg->IsInitialized())
    {
        CCString* pErrorInfo = CCString::createWithFormat("Init Error [ %s ]",msgName.c_str());
        HSMessageBox(pErrorInfo->getCString());
        
        pErrorInfo->release();
        return false;
    }
    
	std::string strbody = msg->SerializeAsString();
	std::map<std::string,int>::iterator it = m_lanProtocol.find(msgName);
	if (it == this->m_lanProtocol.end())
	{
		msgName.append(" LAN Not registered ");
		CC_SAFE_DELETE(msg);
		return false;
	}
	long long checksum = (long long)(this->Adler32((unsigned char*)strbody.c_str(),strbody.length()));
    
    
    MessageInfo hsMsg = message::MessageInfo::default_instance();
    hsMsg.Clear();
    message::Head* head = hsMsg.mutable_head();
    head->set_checksum(checksum);
	head->set_sign(0);
	head->set_uid(HS_GAME_CACHE_DATA_LAN().uuid());
	head->set_imei("Ambition:IMEI");
    Body* body = hsMsg.mutable_body();
    body->add_commandid(it->second);
	body->add_data(strbody);
    
    
	std::string data = hsMsg.SerializeAsString();

    
    CCLog("Send_Lan %d: %s",data.length(),data.c_str());
    HSJava::ShaderJava()->distributeDataToOthers(data.c_str(), data.length());    
    
    delete msg;
    msg = NULL;
    
	return true;
}
	void ProcessApplication::log( ELogType type, EConsoleBackColor backColor, const char* format, ... )
	{
		CCString* tempString = new CCString();
		va_list ap;
		va_start(ap, format);
		bool initialized(tempString->initWithFormatAndValist(format, ap));
		va_end(ap);
		if(initialized)	{
			ConsoleBackColorScope colorScope(type, backColor);
			const char* logString(tempString->getCString());
			switch(type)	{
			case( ELogType_Info ):
				{
					logger().information(logString);
				}
				break;
			case( ELogType_Status ):
				{
					logger().information(logString);
				}
				break;
			case( ELogType_Message ):
				{
					logger().information(logString);
				}
				break;
			case( ELogType_Warning ):
				{
					logger().information(logString);
				}
				break;
			case( ELogType_Error ):
				{
					logger().information(logString);
				}
				break;
			default:
				logger().information(logString);
				break;
			}

			// TODO: is debugger present ...
			WCHAR wszBuf[cocos2d::kMaxLogLen + 1] = {0};
			MultiByteToWideChar(CP_UTF8, 0, logString, -1, wszBuf, sizeof(wszBuf));
			OutputDebugStringW(wszBuf);
			OutputDebugStringA("\n");
		}
		tempString->release();
	}
Exemple #14
0
bool ImageResourceCache::AddImage(const char *pKey, const char * pFileName) {
	if (!pKey && !pFileName) {
		return false;
	}
	std::string key = std::string(pKey);
	CCString *pFile = pImages->objectForKey(key);
	if (!pFile) {
		CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(
				pFileName);
		if (pTexture) {
			CCString *pFileString = new CCString(pFileName);
			pImages->setObject(pFileString, key);
			pFileString->release();
			return true;
		}
	}
	return false;
}
Exemple #15
0
CCDictionary* Scriptor::dump_attribs_to_nodes(TiXmlElement* pElement, unsigned int indent, ScriptType st)
{
	if ( !pElement ) return NULL;
	if ( st == sUnknown) return NULL;		//关闭调试输出

	CCDictionary* dt = new CCDictionary(); 

	TiXmlAttribute* pAttrib=pElement->FirstAttribute();
	int i=0;
	int ival;
	double dval;

	while (pAttrib)
	{
		//CCLOG( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value());
		if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS)   
		{
			CCInteger* ci = new CCInteger(ival);
			dt->setObject(ci,pAttrib->Name());
			ci->release();
		}
		else if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) 
		{
			NFloat* fl = new NFloat(dval);
			dt->setObject(fl,pAttrib->Name());
			fl->release();
		}
		else 
		{
			CCString* sl = new CCString(pAttrib->Value());
			dt->setObject(sl,pAttrib->Name());
			pAttrib->Value();
			CCLOG("value pair:%s||%s||%s",pAttrib->Value(),pAttrib->Name(),sl->getCString());
			sl->release();
		}
		i++;
		pAttrib=pAttrib->Next();
	}
	if(i>0)	return dt;
	else CC_SAFE_RELEASE_NULL(dt);
		
	return NULL;
}
Exemple #16
0
int CCPreLoad::addSingle(const char* pic, int type, int size)
{
	int ret = -1;
	CCDictionary* dic = new CCDictionary();
	CCString* str = new CCString();
	CCString* str1 = new CCString();
	do{
		str->initWithFormat("%d", type);
		str1->initWithFormat("%d", size);

		dic->setObject(str1, "size");
		dic->setObject(str, "type");
		m_dict->setObject(dic, pic);
		ret = 0;
	}while(0);
	dic->release();
	str->release();
	str1->release();
	return ret;
}
Exemple #17
0
//------------------------------------------------------------------
//
// SchedulerUpdate
//
//------------------------------------------------------------------
void SchedulerUpdate::onEnter()
{
    SchedulerTestLayer::onEnter();

    TestNode* d = new TestNode();
    CCString* pStr = new CCString("---");
    d->initWithString(pStr, 50);
    pStr->release();
    addChild(d);
    d->release();

    TestNode* b = new TestNode();
    pStr = new CCString("3rd");
    b->initWithString(pStr, 0);
    pStr->release();
    addChild(b);
    b->release();

    TestNode* a = new TestNode();
    pStr = new CCString("1st");
    a->initWithString(pStr, -10);
    pStr->release();
    addChild(a);
    a->release();

    TestNode* c = new TestNode();
    pStr = new CCString("4th");
    c->initWithString(pStr, 10);
    pStr->release();
    addChild(c);
    c->release();

    TestNode* e = new TestNode();
    pStr = new CCString("5th");
    e->initWithString(pStr, 20);
    pStr->release();
    addChild(e);
    e->release();

    TestNode* f = new TestNode();
    pStr = new CCString("2nd");
    f->initWithString(pStr, -5);
    pStr->release();
    addChild(f);
    f->release();

    schedule(schedule_selector(SchedulerUpdate::removeUpdates), 4.0f);
}
    void textHandler(void *ctx, const char *ch, int len)
    {
        CC_UNUSED_PARAM(ctx);
        if (m_tState == SAX_NONE)
        {
            return;
        }

        CCSAXState curState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
        CCString *pText = new CCString();
        pText->m_sString = std::string((char*)ch,0,len);

        switch(m_tState)
        {
        case SAX_KEY:
            m_sCurKey = pText->m_sString;
            break;
        case SAX_INT:
        case SAX_REAL:
        case SAX_STRING:
            {
                CCAssert(!m_sCurKey.empty(), "not found key : <integet/real>");

                if (SAX_ARRAY == curState)
                {
                    m_pArray->addObject(pText);
                }
                else if (SAX_DICT == curState)
                {
                    m_pCurDict->setObject(pText, m_sCurKey);
                }
                break;
            }
        default:
            break;
        }
        pText->release();
    }
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();
        }
    }
}
Exemple #20
0
void CJMultimedia::_playNarrationWithDelayCallfunc(CCNode* sender, void* filePath)
{
    CCString *fileName = (CCString *)filePath;
    playNarration(fileName->getCString());
    fileName->release();
}
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
{
	/*
	Supported Zwoptex Formats:

	ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
	ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
	ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
	ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
	*/

	CCDictionary<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
	CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
	int format = 0;

	// get the format
	if(metadataDict != NULL) 
	{
		format = atoi(valueForKey("format", metadataDict));
	}

	// check the format
	CCAssert(format >=0 && format <= 3, "");

	framesDict->begin();
	std::string key = "";
	CCDictionary<std::string, CCObject*> *frameDict = NULL;
	while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
	{
		CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
		if (spriteFrame)
		{
			continue;
		}
		
		if(format == 0) 
		{
			float x = (float)atof(valueForKey("x", frameDict));
			float y = (float)atof(valueForKey("y", frameDict));
			float w = (float)atof(valueForKey("width", frameDict));
			float h = (float)atof(valueForKey("height", frameDict));
			float ox = (float)atof(valueForKey("offsetX", frameDict));
			float oy = (float)atof(valueForKey("offsetY", frameDict));
			int ow = atoi(valueForKey("originalWidth", frameDict));
			int oh = atoi(valueForKey("originalHeight", frameDict));
			// check ow/oh
			if(!ow || !oh)
			{
				CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
			}
			// abs ow/oh
			ow = abs(ow);
			oh = abs(oh);
			// create frame
			spriteFrame = new CCSpriteFrame();
			spriteFrame->initWithTexture(pobTexture, 
				                        CCRectMake(x, y, w, h), 
										false,
                                        CCPointMake(ox, oy),
                                        CCSizeMake((float)ow, (float)oh)
										);
		} 
		else if(format == 1 || format == 2) 
		{
			CCRect frame = CCRectFromString(valueForKey("frame", frameDict));
			bool rotated = false;

			// rotation
			if (format == 2)
			{
				rotated = atoi(valueForKey("rotated", frameDict)) == 0 ? false : true;
			}

			CCPoint offset = CCPointFromString(valueForKey("offset", frameDict));
			CCSize sourceSize = CCSizeFromString(valueForKey("sourceSize", frameDict));

			// create frame
			spriteFrame = new CCSpriteFrame();
			spriteFrame->initWithTexture(pobTexture, 
				frame,
				rotated,
				offset,
				sourceSize
				);
		} else
		if (format == 3)
		{
			// get values
			CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
			CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
			CCSize spriteSourceSize = CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
			CCRect textureRect = CCRectFromString(valueForKey("textureRect", frameDict));
            bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;

			// get aliases
			CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
            CCMutableArray<CCString*>::CCMutableArrayIterator iter;

            CCString * frameKey = new CCString(key.c_str());
            for (iter = aliases->begin(); iter != aliases->end(); ++iter)
            {
                std::string oneAlias = ((CCString*) (*iter))->m_sString;
                if (m_pSpriteFramesAliases->objectForKey(oneAlias))
                {
                    CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
                }

                m_pSpriteFramesAliases->setObject(frameKey, oneAlias);
            }
            frameKey->release();
            // create frame
            spriteFrame = new CCSpriteFrame();
            spriteFrame->initWithTexture(pobTexture,
                            CCRectMake(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
                            textureRotated,
                            spriteOffset,
                            spriteSourceSize);
		}

		// add sprite frame
		m_pSpriteFrames->setObject(spriteFrame, key);
		spriteFrame->release();
	}
}
// the XML parser calls here with all the elements
void CCTMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
{    
    CC_UNUSED_PARAM(ctx);
    CCTMXMapInfo *pTMXMapInfo = this;
    std::string elementName = (char*)name;
    std::map<std::string, std::string> *attributeDict = new std::map<std::string, std::string>();
    if (atts && atts[0])
    {
        for(int i = 0; atts[i]; i += 2) 
        {
            std::string key = (char*)atts[i];
            std::string value = (char*)atts[i+1];
            attributeDict->insert(pair<std::string, std::string>(key, value));
        }
    }
    if (elementName == "map")
    {
        std::string version = valueForKey("version", attributeDict);
        if ( version != "1.0")
        {
            CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str());
        }
        std::string orientationStr = valueForKey("orientation", attributeDict);
        if (orientationStr == "orthogonal")
            pTMXMapInfo->setOrientation(CCTMXOrientationOrtho);
        else if (orientationStr  == "isometric")
            pTMXMapInfo->setOrientation(CCTMXOrientationIso);
        else if(orientationStr == "hexagonal")
            pTMXMapInfo->setOrientation(CCTMXOrientationHex);
        else
            CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", pTMXMapInfo->getOrientation());

        CCSize s;
        s.width = (float)atof(valueForKey("width", attributeDict));
        s.height = (float)atof(valueForKey("height", attributeDict));
        pTMXMapInfo->setMapSize(s);

        s.width = (float)atof(valueForKey("tilewidth", attributeDict));
        s.height = (float)atof(valueForKey("tileheight", attributeDict));
        pTMXMapInfo->setTileSize(s);

        // The parent element is now "map"
        pTMXMapInfo->setParentElement(TMXPropertyMap);
    } 
    else if (elementName == "tileset") 
    {
        // If this is an external tileset then start parsing that
        std::string externalTilesetFilename = valueForKey("source", attributeDict);
        if (externalTilesetFilename != "")
        {
            // Tileset file will be relative to the map file. So we need to convert it to an absolute path
            if (m_sTMXFileName.find_last_of("/") != string::npos)
            {
                string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1);
                externalTilesetFilename = dir + externalTilesetFilename;
            }
            else 
            {
                externalTilesetFilename = m_sResources + "/" + externalTilesetFilename;
            }
            externalTilesetFilename = CCFileUtils::sharedFileUtils()->fullPathForFilename(externalTilesetFilename.c_str());
            
            m_uCurrentFirstGID = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
            
            pTMXMapInfo->parseXMLFile(externalTilesetFilename.c_str());
        }
        else
        {
            CCTMXTilesetInfo *tileset = new CCTMXTilesetInfo();
            tileset->m_sName = valueForKey("name", attributeDict);
            if (m_uCurrentFirstGID == 0)
            {
                tileset->m_uFirstGid = (unsigned int)atoi(valueForKey("firstgid", attributeDict));
            }
            else
            {
                tileset->m_uFirstGid = m_uCurrentFirstGID;
                m_uCurrentFirstGID = 0;
            }
            tileset->m_uSpacing = (unsigned int)atoi(valueForKey("spacing", attributeDict));
            tileset->m_uMargin = (unsigned int)atoi(valueForKey("margin", attributeDict));
            CCSize s;
            s.width = (float)atof(valueForKey("tilewidth", attributeDict));
            s.height = (float)atof(valueForKey("tileheight", attributeDict));
            tileset->m_tTileSize = s;

            pTMXMapInfo->getTilesets()->addObject(tileset);
            tileset->release();
        }
    }
    else if (elementName == "tile")
    {
        CCTMXTilesetInfo* info = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();
        CCDictionary *dict = new CCDictionary();
        pTMXMapInfo->setParentGID(info->m_uFirstGid + atoi(valueForKey("id", attributeDict)));
        pTMXMapInfo->getTileProperties()->setObject(dict, pTMXMapInfo->getParentGID());
        CC_SAFE_RELEASE(dict);
        
        pTMXMapInfo->setParentElement(TMXPropertyTile);

    }
    else if (elementName == "layer")
    {
        CCTMXLayerInfo *layer = new CCTMXLayerInfo();
        layer->m_sName = valueForKey("name", attributeDict);

        CCSize s;
        s.width = (float)atof(valueForKey("width", attributeDict));
        s.height = (float)atof(valueForKey("height", attributeDict));
        layer->m_tLayerSize = s;

        std::string visible = valueForKey("visible", attributeDict);
        layer->m_bVisible = !(visible == "0");

        std::string opacity = valueForKey("opacity", attributeDict);
        if( opacity != "" )
        {
            layer->m_cOpacity = (unsigned char)(255 * atof(opacity.c_str()));
        }
        else
        {
            layer->m_cOpacity = 255;
        }

        float x = (float)atof(valueForKey("x", attributeDict));
        float y = (float)atof(valueForKey("y", attributeDict));
        layer->m_tOffset = ccp(x,y);

        pTMXMapInfo->getLayers()->addObject(layer);
        layer->release();

        // The parent element is now "layer"
        pTMXMapInfo->setParentElement(TMXPropertyLayer);

    } 
    else if (elementName == "objectgroup")
    {
        CCTMXObjectGroup *objectGroup = new CCTMXObjectGroup();
        objectGroup->setGroupName(valueForKey("name", attributeDict));
        CCPoint positionOffset;
        positionOffset.x = (float)atof(valueForKey("x", attributeDict)) * pTMXMapInfo->getTileSize().width;
        positionOffset.y = (float)atof(valueForKey("y", attributeDict)) * pTMXMapInfo->getTileSize().height;
        objectGroup->setPositionOffset(positionOffset);

        pTMXMapInfo->getObjectGroups()->addObject(objectGroup);
        objectGroup->release();

        // The parent element is now "objectgroup"
        pTMXMapInfo->setParentElement(TMXPropertyObjectGroup);

    }
    else if (elementName == "image")
    {
        CCTMXTilesetInfo* tileset = (CCTMXTilesetInfo*)pTMXMapInfo->getTilesets()->lastObject();

        // build full path
        std::string imagename = valueForKey("source", attributeDict);

        if (m_sTMXFileName.find_last_of("/") != string::npos)
        {
            string dir = m_sTMXFileName.substr(0, m_sTMXFileName.find_last_of("/") + 1);
            tileset->m_sSourceImage = dir + imagename;
        }
        else 
        {
            tileset->m_sSourceImage = m_sResources + (m_sResources.size() ? "/" : "") + imagename;
        }
    } 
    else if (elementName == "data")
    {
        std::string encoding = valueForKey("encoding", attributeDict);
        std::string compression = valueForKey("compression", attributeDict);

        if( encoding == "base64" )
        {
            int layerAttribs = pTMXMapInfo->getLayerAttribs();
            pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
            pTMXMapInfo->setStoringCharacters(true);

            if( compression == "gzip" )
            {
                layerAttribs = pTMXMapInfo->getLayerAttribs();
                pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
            } else
            if (compression == "zlib")
            {
                layerAttribs = pTMXMapInfo->getLayerAttribs();
                pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
            }
            CCAssert( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
        }
        CCAssert( pTMXMapInfo->getLayerAttribs() != TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip/zlib maps are supported" );

    } 
    else if (elementName == "object")
    {
        char buffer[32] = {0};
        CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();

        // The value for "type" was blank or not a valid class name
        // Create an instance of TMXObjectInfo to store the object and its properties
        CCDictionary *dict = new CCDictionary();
        // Parse everything automatically
        const char* pArray[] = {"name", "type", "width", "height", "gid"};
        
        for(size_t i = 0; i < sizeof(pArray)/sizeof(pArray[0]); ++i )
        {
            const char* key = pArray[i];
            CCString* obj = new CCString(valueForKey(key, attributeDict));
            if( obj )
            {
                obj->autorelease();
                dict->setObject(obj, key);
            }
        }

        // But X and Y since they need special treatment
        // X

        const char* value = valueForKey("x", attributeDict);
        if (value) 
        {
            int x = atoi(value) + (int)objectGroup->getPositionOffset().x;
            sprintf(buffer, "%d", x);
            CCString* pStr = new CCString(buffer);
            pStr->autorelease();
            dict->setObject(pStr, "x");
        }

        // Y
        value = valueForKey("y", attributeDict);
        if (value)  {
            int y = atoi(value) + (int)objectGroup->getPositionOffset().y;

            // Correct y position. (Tiled uses Flipped, cocos2d uses Standard)
            y = (int)(m_tMapSize.height * m_tTileSize.height) - y - atoi(valueForKey("height", attributeDict));
            sprintf(buffer, "%d", y);
            CCString* pStr = new CCString(buffer);
            pStr->autorelease();
            dict->setObject(pStr, "y");
        }

        // Add the object to the objectGroup
        objectGroup->getObjects()->addObject(dict);
        dict->release();

         // The parent element is now "object"
         pTMXMapInfo->setParentElement(TMXPropertyObject);

    }
    else if (elementName == "property")
    {
        if ( pTMXMapInfo->getParentElement() == TMXPropertyNone ) 
        {
            CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'",
                valueForKey("name", attributeDict), valueForKey("value",attributeDict) );
        } 
        else if ( pTMXMapInfo->getParentElement() == TMXPropertyMap )
        {
            // The parent element is the map
            CCString *value = new CCString(valueForKey("value", attributeDict));
            std::string key = valueForKey("name", attributeDict);
            pTMXMapInfo->getProperties()->setObject(value, key.c_str());
            value->release();

        } 
        else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer )
        {
            // The parent element is the last layer
            CCTMXLayerInfo* layer = (CCTMXLayerInfo*)pTMXMapInfo->getLayers()->lastObject();
            CCString *value = new CCString(valueForKey("value", attributeDict));
            std::string key = valueForKey("name", attributeDict);
            // Add the property to the layer
            layer->getProperties()->setObject(value, key.c_str());
            value->release();

        } 
        else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup ) 
        {
            // The parent element is the last object group
            CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
            CCString *value = new CCString(valueForKey("value", attributeDict));
            const char* key = valueForKey("name", attributeDict);
            objectGroup->getProperties()->setObject(value, key);
            value->release();

        } 
        else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject )
        {
            // The parent element is the last object
            CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)pTMXMapInfo->getObjectGroups()->lastObject();
            CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();

            const char* propertyName = valueForKey("name", attributeDict);
            CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
            dict->setObject(propertyValue, propertyName);
            propertyValue->release();
        } 
        else if ( pTMXMapInfo->getParentElement() == TMXPropertyTile ) 
        {
            CCDictionary* dict = (CCDictionary*)pTMXMapInfo->getTileProperties()->objectForKey(pTMXMapInfo->getParentGID());

            const char* propertyName = valueForKey("name", attributeDict);
            CCString *propertyValue = new CCString(valueForKey("value", attributeDict));
            dict->setObject(propertyValue, propertyName);
            propertyValue->release();
        }
    }
    else if (elementName == "polygon") 
    {
        // find parent object's dict and add polygon-points to it
        CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
        CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();

        // get points value string
        const char* value = valueForKey("points", attributeDict);
        if(value)
        {
            CCArray* pPointsArray = new CCArray;

            // parse points string into a space-separated set of points
            stringstream pointsStream(value);
            string pointPair;
            while(std::getline(pointsStream, pointPair, ' '))
            {
                // parse each point combo into a comma-separated x,y point
                stringstream pointStream(pointPair);
                string xStr,yStr;
                char buffer[32] = {0};
                
                CCDictionary* pPointDict = new CCDictionary;

                // set x
                if(std::getline(pointStream, xStr, ','))
                {
                    int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
                    sprintf(buffer, "%d", x);
                    CCString* pStr = new CCString(buffer);
                    pStr->autorelease();
                    pPointDict->setObject(pStr, "x");
                }

                // set y
                if(std::getline(pointStream, yStr, ','))
                {
                    int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
                    sprintf(buffer, "%d", y);
                    CCString* pStr = new CCString(buffer);
                    pStr->autorelease();
                    pPointDict->setObject(pStr, "y");
                }
                
                // add to points array
                pPointsArray->addObject(pPointDict);
                pPointDict->release();
            }
            
            dict->setObject(pPointsArray, "points");
            pPointsArray->release();
        }
    }
    else if (elementName == "polyline")
    {
        // find parent object's dict and add polyline-points to it
        // CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
        // CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();
        // TODO: dict->setObject:[attributeDict objectForKey:@"points"] forKey:@"polylinePoints"];
		CCTMXObjectGroup* objectGroup = (CCTMXObjectGroup*)m_pObjectGroups->lastObject();
		CCDictionary* dict = (CCDictionary*)objectGroup->getObjects()->lastObject();

		// get points value string
		const char* value = valueForKey("points", attributeDict);
		if(value)
		{
			CCArray* pPointsArray = new CCArray;

			// parse points string into a space-separated set of points
			stringstream pointsStream(value);
			string pointPair;
			while(std::getline(pointsStream, pointPair, ' '))
			{
				// parse each point combo into a comma-separated x,y point
				stringstream pointStream(pointPair);
				string xStr,yStr;
				char buffer[32] = {0};

				CCDictionary* pPointDict = new CCDictionary;

				// set x
				if(std::getline(pointStream, xStr, ','))
				{
					int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
					sprintf(buffer, "%d", x);
					CCString* pStr = new CCString(buffer);
					pStr->autorelease();
					pPointDict->setObject(pStr, "x");
				}

				// set y
				if(std::getline(pointStream, yStr, ','))
				{
					int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
					sprintf(buffer, "%d", y);
					CCString* pStr = new CCString(buffer);
					pStr->autorelease();
					pPointDict->setObject(pStr, "y");
				}

				// add to points array
				pPointsArray->addObject(pPointDict);
				pPointDict->release();
			}

			dict->setObject(pPointsArray, "points");
			pPointsArray->release();
		}
    }

    if (attributeDict)
    {
        attributeDict->clear();
        delete attributeDict;
    }
}
 /// Callback function used by libcurl for collect header data
 static size_t writeHeaderData(void* ptr, size_t size, size_t nmemb, void* userdata) {
     CURLHandler* handler = (CURLHandler*)userdata;
     size_t sizes = size * nmemb;
     
     // lock
     pthread_mutex_lock(&handler->m_mutex);
     
     // parse pair
     string header((const char*)ptr, sizes);
     CCArray* pair = new CCArray();
     if(!header.empty()) {
         // remove head and tailing brace, bracket, parentheses
         size_t start = 0;
         size_t end = header.length() - 1;
         char c = header[start];
         while(c == '{' || c == '[' || c == '(') {
             start++;
             c = header[start];
         }
         c = header[end];
         while(c == '}' || c == ']' || c == ')') {
             end--;
             c = header[end];
         }
         
         // iterate string
         size_t compStart = start;
         for(size_t i = start; i <= end; i++) {
             c = header[i];
             if(c == ':') {
                 CCString* s = new CCString(header.substr(compStart, i - compStart));
                 pair->addObject(s);
                 s->release();
                 compStart = i + 1;
             } else if(c == ' ' || c == '\t' || c == '\r' || c == '\n') {
                 if(compStart == i) {
                     compStart++;
                 }
             }
         }
         
         // last comp
         // or, if last char is separator, append an empty string
         if(compStart <= end) {
             CCString* s = new CCString(header.substr(compStart, end - compStart + 1));
             pair->addObject(s);
             s->release();
         } else if(header[end] == ':') {
             CCString* s = new CCString("");
             pair->addObject(s);
             s->release();
         }
     }
     
     // if pair count is two, means ok
     if(pair->count() == 2) {
         handler->m_ctx->response->addHeader(((CCString*)pair->objectAtIndex(0))->getCString(),
                                             ((CCString*)pair->objectAtIndex(1))->getCString());
     }
     
     // release array
     pair->release();
     
     // unlock
     pthread_mutex_unlock(&handler->m_mutex);
     
     // return a value which is different with sizes will abort it
     if(handler->m_ctx->request->isCancel())
         return sizes + 1;
     else
         return sizes;
 }