Пример #1
0
void MapBackground::LoadMapTileImage(MapTile* pTile)
{
	char szImage[200], szPath[200];
	strcpy(szImage, pTile->szImageUrl);

	char* szName = strrchr(szImage, '/')+1;
	strchr(szName, '.')[0] = 0;
	strcat(szName, ".jpg");

	strcpy(szPath, "tiles/");
	strcat(szPath, szName);

	bool isJpg = true;
	if (!s3eFileCheckExists(szPath))
	{
		isJpg = false;
		strchr(szPath, '.')[0] = 0;
		strcat(szPath, ".png");

		char* szTiles = strchr(szPath, '/');
		szTiles[1] = 'r';
	}

	if (s3eFileCheckExists(szPath))
	{
		if ((!pTile->pTexture || pTile->pTexture == g_pLoadingTexture))
		{
			CreateMapTileImage2(pTile, szPath, isJpg);
		}
		g_bInProgress = false;
	}
	else
	{
		pTile->bInProgress = true;
		((ThisAndTile*)g_pThisAndTile)->pTile = pTile;

		IwGetHTTPQueue()->Get(pTile->szImageUrl, g_pThisAndTile, &MapBackground::GotImage, &MapBackground::GotImageError);
	}
}
        bool STDFileSystem::_isExists(const char* file)
        {
            char buff[512];
            _getFullPath(file, buff);
#if __S3E__
            s3eBool res = s3eFileCheckExists(buff);
            return res == S3E_TRUE;
#else
            //todo optimize
            oxHandle* h = oxFileOpen(buff, "rb");
            if (h)
                oxFileClose(h);
            return h != 0;
#endif
        }
bool	CIwGamePlatformFileMarm::Exists(const char* filename)
{
	return s3eFileCheckExists(filename) == S3E_TRUE;
}
Пример #4
0
bool GAFAsset::initWithImageData(const std::string& jsonPath)
{
	if (!s3eFileCheckExists(jsonPath.c_str()))
	{
		GAFLOGERROR("CAN NOT create GAFAsset : %s does not exists", jsonPath.c_str());
		return false;
	}
	GAFData aConfigData;
	//std::string fp = CCFileUtils::sharedFileUtils()->fullPathForFilename(jsonPath.c_str());
	std::string fp = jsonPath;
	s3eFile * file = s3eFileOpen (fp.c_str(), "rb");
	if (!file)
	{
		GAFLOGERROR("CAN NOT create GAFAsset : can not open %s.", fp.c_str());
		return false;
	}
	
	aConfigData.setSize(s3eFileGetSize(file));
	aConfigData.setBytes(new unsigned char[aConfigData.size()]);
	s3eFileRead(aConfigData.bytes(), aConfigData.size(), 1, file);
	s3eFileClose(file);
	aConfigData.setDeleteData(true);

	if (!aConfigData.bytes())
	{
		GAFLOGERROR("Can not get data from json file : %s", jsonPath.c_str());
		return NULL;
	}

	if (!aConfigData.bytes())
	{
		GAFLOGWARN("can not init GAFAsset - invalid anImageData");
		return false;
	}
	
	CCDictionary* configDictionary = CCJSONConverter::sharedConverter()->dictionaryFrom( (const char *)aConfigData.bytes());
	
	CCString *versionNode               = (CCString*)configDictionary->objectForKey(kVersionKey);
	
	if (!isAssetVersionPlayable(versionNode->getCString()))
	{
		return false;
	}
	CCArray *animationConfigFrames      = (CCArray *)configDictionary->objectForKey(kAnimationConfigFramesKey);
	CCArray *interactionObjectNodes     = (CCArray *)configDictionary->objectForKey(kInteractionObjectsKey);
	CCArray *standObjectsNodes          = (CCArray *)configDictionary->objectForKey(kStandObjectsKey);
	CCArray *textureAtlasNode           = (CCArray *)configDictionary->objectForKey(kTextureAtlasKey);
	CCArray *animationSequences         = (CCArray *)configDictionary->objectForKey(kAnimationSequencesKey);
	
	CCDictionary *objectNodes           = (CCDictionary *)configDictionary->objectForKey(kAnimationObjectsKey);
	CCDictionary *masksNodes            = (CCDictionary *)configDictionary->objectForKey(kAnimationMasksKey);
	CCDictionary *namedPartsNodes       = (CCDictionary *)configDictionary->objectForKey(kAnimationNamedPartsKey);

	
	if (!animationConfigFrames || !textureAtlasNode|| !objectNodes)
	{
		GAFLOGERROR("Error while creating GAFAsset. Required subnodes in dictionary are missing.");
		return false;
	}
	
	CC_SAFE_RELEASE(_textureAtlas);
	
	if (!textureAtlasNode->count())
	{
		return false;
	}

	CCDictionary * atlasDictionary = (CCDictionary *)textureAtlasNode->objectAtIndex(0);
	float atlasScale = atlasScaleFromAtlasConfig(atlasDictionary);
	for (int i = 1; i < textureAtlasNode->count(); ++i)
	{
		CCDictionary * a = (CCDictionary *)textureAtlasNode->objectAtIndex(i);
		float as = atlasScaleFromAtlasConfig(a);
		if ( fabs(atlasScale - _currentDeviceScale) > fabs(as - _currentDeviceScale))
		{
			atlasDictionary = a;
			atlasScale = as;
		}
	}
	
	_usedAtlasContentScaleFactor = atlasScale;
	CCArray * atlasesInfo = (CCArray *)atlasDictionary->objectForKey(kAtlasInfoKey);
	if (!atlasesInfo)
	{
		GAFLOGERROR("Error while creating GAFAsset.atlasesInfo subnode is missing in atlasDictionary.");
		return false;
	}
	
	_textureAtlas = GAFTextureAtlas::create(fp.c_str(), atlasDictionary);
	if (!_textureAtlas)
	{
		GAFLOGERROR("Failed to initialize GAFAsset. GAFTextureAtlas could not be created.");
		return false;
	}
	CC_SAFE_RETAIN(_textureAtlas);
	
	if (_objects != objectNodes)
	{
		CC_SAFE_RELEASE(_objects);
		_objects = objectNodes;
		CC_SAFE_RETAIN(_objects);
	}
	
	if (_masks != masksNodes)
	{
		CC_SAFE_RELEASE(_masks);
		_masks	  = masksNodes;
		CC_SAFE_RETAIN(_masks);
	}
	
	if (_namedParts != namedPartsNodes)
	{
		CC_SAFE_RELEASE(_namedParts);
		_namedParts	  = namedPartsNodes;
		CC_SAFE_RETAIN(_namedParts);
	}
	
	if (interactionObjectNodes)
	{
		CC_SAFE_RELEASE(_interactionObjects);
		_interactionObjects = CCArray::create();
		CC_SAFE_RETAIN(_interactionObjects);
		
		for (unsigned int i = 0; i < interactionObjectNodes->count(); ++i)
		{
			CCDictionary * dict = (CCDictionary*)interactionObjectNodes->objectAtIndex(i);
			
			GAFInteractionObject * interObject = GAFInteractionObject::create(dict);
			if (interObject)
			{
				_interactionObjects->addObject(interObject);
			}
		}
	}
	
	if (standObjectsNodes)
	{
		CC_SAFE_RELEASE(_standObjects);
		_standObjects = CCArray::create();
		CC_SAFE_RETAIN(_standObjects);
		
		for (unsigned int i = 0; i < standObjectsNodes->count(); ++i)
		{
			CCDictionary * dict = (CCDictionary*)standObjectsNodes->objectAtIndex(i);
			
			GAFActionObject * interObject = GAFActionObject::create(dict);
			if (interObject)
			{
				_standObjects->addObject(interObject);
			}
		}
	}
	
	loadFramesFromConfigDictionary(configDictionary);
	
	if (animationSequences)
	{
		loadAnimationSequences(animationSequences);
	}
	configDictionary->removeAllObjects();
	return true;
}