void SpriteMonsterMgr::CreateCacheMonster(int typeId)
{
	//CCLOG("create monster cache typeId: %d", typeId);
	SpriteMonster * monster = NULL;

	MonsterInitInfo info;
	info.typeId = typeId;

	monster = new SpriteMonster(info);
	if (monster)
	{
		monster->createTexture(typeId);
		if (cacheMonsters.find(typeId) == cacheMonsters.end())
		{
			set<SpriteMonster*> monsterSet;
			monsterSet.insert(monster);
			cacheMonsters[typeId] = monsterSet;
		}
		else
		{
			cacheMonsters[typeId].insert(monster);
		}
	}
	else
	{
		CC_SAFE_DELETE(monster);
	}
}
SpriteMonster* SpriteMonsterMgr::CreateMonster(MonsterInitInfo info)
{
	SpriteMonster * monster = NULL;

	
	do
	{
		//try to use cache , if failed create a new one
		if (info.useCache)
		{
			if (cacheMonsters.find(info.typeId) == cacheMonsters.end())
			{
				CCLOG("can't find cache monster type : %d", info.typeId);
				break;
			}

			set<SpriteMonster*> monsterSet = cacheMonsters[info.typeId];
			if (monsterSet.size() == 0)
			{
				CCLOG("cache monster count none : type : %d", info.typeId);
				break;
			}

			set<SpriteMonster*>::iterator iter = monsterSet.begin();
			monster = *iter;
			if (monster->initWithInfoAndShow(info))
			{
				if (Add(monster) == false)
				{
					CCLOG("create monster id:%d failed, it's already existed" , info.uid);
					break;
				}
				cacheMonsters[info.typeId].erase(*iter);
				//CCLOG("use cache monster type : %d", info.typeId);
				return monster;
			}
		}
	} while (0);



	monster = new SpriteMonster(info);

	do
	{
		if (!monster)
		{
			break;
		}
		monster->autorelease();

		if (monster->createTexture(info.typeId) && monster->initWithInfoAndShow(info))
		{
			if (Add(monster) == false)
			{
				CCLOG("create monster id:%d failed, it's already existed" , info.uid);
				CC_SAFE_DELETE(monster);
				monster = NULL;
			}
			return  monster;
		}
		else
		{
			break;
		}
	} while (0);

	CC_SAFE_DELETE(monster);
	return NULL;
}