void ParseDataEndElement() { byte[] encoded = null; if ((tileDataCompressionType & CCTileDataCompressionType.Base64) != 0) { storingCharacters = false; int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; if ((tileDataCompressionType & (CCTileDataCompressionType.Gzip | CCTileDataCompressionType.Zlib)) != 0) { if ((tileDataCompressionType & CCTileDataCompressionType.Gzip) != 0) { try { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Gzip); } catch (Exception ex) { CCLog.Log("failed to decompress embedded data object in TMX file."); CCLog.Log(ex.ToString()); } } if ((tileDataCompressionType & CCTileDataCompressionType.Zlib) != 0) { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Zlib); } } else { encoded = currentString; } for (int i = 0; i < layer.TileGIDAndFlags.Length; i++) { int i4 = i * 4; uint gidAndFlags = (uint)( encoded[i4] | encoded[i4 + 1] << 8 | encoded[i4 + 2] << 16 | encoded[i4 + 3] << 24); layer.TileGIDAndFlags[i] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } currentString = null; } else if ((tileDataCompressionType & CCTileDataCompressionType.None) != 0) { currentXmlTileIndex = 0; } }
void OnConfigLoad(CCParticleSystemConfig config, Action <CCParticleSystemConfig> action) { // Right now Mac can not load images with data defined asyncly so we want to short circuit this and // just load the data from disk. If not then we will perform an async load on the image #if MACOS config.LoadParticleTexture(); if (action != null) { action(config); } #else string textureData = config.TextureData; // We will try loading the texture data first if it exists. Hopefully we get lucky if (!string.IsNullOrEmpty(textureData)) { //Debug.Assert(!string.IsNullOrEmpty(textureData), // string.Format("CCParticleSystem: textureData does not exist : {0}", textureName)); int dataLen = textureData.Length; if (dataLen != 0) { var dataBytes = Convert.FromBase64String(textureData); Debug.Assert(dataBytes != null, string.Format("CCParticleSystem: error decoding textureImageData : {0}", config.TextureName)); var imageBytes = ZipUtils.Inflate(dataBytes); Debug.Assert(imageBytes != null, string.Format("CCParticleSystem: error init image with Data for texture : {0}", config.TextureName)); try { CCTextureCache.SharedTextureCache.AddImageAsync(imageBytes, config.TextureName, CCSurfaceFormat.Color, (loadedTexture) => { if (loadedTexture != null) { config.Texture = loadedTexture; if (action != null) { action(config); } } else { if (!string.IsNullOrEmpty(config.TextureName)) { bool bNotify = CCFileUtils.IsPopupNotify; CCFileUtils.IsPopupNotify = false; try { CCTextureCache.SharedTextureCache.AddImageAsync(config.TextureName, (tex2) => { config.Texture = tex2; if (config.Texture == null) { config.Texture = CCParticleExample.DefaultTexture; } if (action != null) { action(config); } }); } catch (Exception) { config.Texture = CCParticleExample.DefaultTexture; } CCFileUtils.IsPopupNotify = bNotify; if (config.Texture == null) { config.Texture = CCParticleExample.DefaultTexture; } } } } ); } catch (Exception ex) { CCLog.Log(ex.ToString()); config.Texture = CCParticleExample.DefaultTexture; } } } else { if (!string.IsNullOrEmpty(config.TextureName)) { bool bNotify = CCFileUtils.IsPopupNotify; CCFileUtils.IsPopupNotify = false; try { CCTextureCache.SharedTextureCache.AddImageAsync(config.TextureName, (tex2) => { config.Texture = tex2; if (config.Texture == null) { config.Texture = CCParticleExample.DefaultTexture; } if (action != null) { action(config); } }); } catch (Exception) { config.Texture = CCParticleExample.DefaultTexture; } CCFileUtils.IsPopupNotify = bNotify; } } #endif }
internal void LoadParticleTexture() { string textureName = TextureName; CCTexture2D tex = null; string textureData = TextureData; // We will try loading the texture data first if it exists. if (!string.IsNullOrEmpty(textureData)) { //Debug.Assert(!string.IsNullOrEmpty(textureData), // string.Format("CCParticleSystem: textureData does not exist : {0}", textureName)); int dataLen = textureData.Length; if (dataLen != 0) { var dataBytes = Convert.FromBase64String(textureData); Debug.Assert(dataBytes != null, string.Format("CCParticleSystem: error decoding textureImageData : {0}", textureName)); var imageBytes = ZipUtils.Inflate(dataBytes); Debug.Assert(imageBytes != null, string.Format("CCParticleSystem: error init image with Data for texture : {0}", textureName)); try { tex = CCTextureCache.SharedTextureCache.AddImage(imageBytes, textureName, CCSurfaceFormat.Color); } catch (Exception ex) { CCLog.Log(ex.ToString()); //Texture = CCParticleExample.DefaultTexture; } if (tex == null) { if (!string.IsNullOrEmpty(textureName)) { bool bNotify = CCFileUtils.IsPopupNotify; CCFileUtils.IsPopupNotify = false; try { tex = CCTextureCache.SharedTextureCache.AddImage(textureName); } catch (Exception) { tex = null; Texture = CCParticleExample.DefaultTexture; } CCFileUtils.IsPopupNotify = bNotify; if (tex == null) { Texture = CCParticleExample.DefaultTexture; } } } } } else { if (!string.IsNullOrEmpty(textureName)) { bool bNotify = CCFileUtils.IsPopupNotify; CCFileUtils.IsPopupNotify = false; try { tex = CCTextureCache.SharedTextureCache.AddImage(textureName); } catch (Exception) { tex = null; } CCFileUtils.IsPopupNotify = bNotify; } } if (tex != null) { Texture = tex; } Debug.Assert(Texture != null, string.Format("CCParticleSystem: error loading the texture : {0}", textureName)); }
void ParseDataEndElement() { byte[] encoded = null; if ((tileDataCompressionType & CCTileDataCompressionType.Base64) != 0) { storingCharacters = false; int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; if ((tileDataCompressionType & (CCTileDataCompressionType.Gzip | CCTileDataCompressionType.Zlib)) != 0) { if ((tileDataCompressionType & CCTileDataCompressionType.Gzip) != 0) { try { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Gzip); } catch (Exception ex) { CCLog.Log("failed to decompress embedded data object in TMX file."); CCLog.Log(ex.ToString()); } } if ((tileDataCompressionType & CCTileDataCompressionType.Zlib) != 0) { encoded = ZipUtils.Inflate(new MemoryStream(currentString), ZipUtils.CompressionFormat.Zlib); } } else { encoded = currentString; } // encoded could be null because the compressed data could not be decompressed if (encoded != null) { for (int i = 0; i < layer.TileGIDAndFlags.Length; i++) { int i4 = i * 4; uint gidAndFlags = (uint)( (uint)encoded[i4] | (uint)encoded[(int)(i4 + 1)] << 8 | (uint)encoded[(int)(i4 + 2)] << 16 | (uint)encoded[(int)(i4 + 3)] << 24); layer.TileGIDAndFlags[i] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } } currentString = null; } else if (tileDataCompressionType == CCTileDataCompressionType.Csv) { storingCharacters = false; int layersCount = Layers != null ? Layers.Count : 0; CCTileLayerInfo layer = layersCount > 0 ? Layers[layersCount - 1] : null; var str = System.Text.Encoding.UTF8.GetString(currentString, 0, currentString.Length).Split(','); for (int i = 0; i < layer.TileGIDAndFlags.Length; i++) { uint gidAndFlags = uint.Parse(str[i]); layer.TileGIDAndFlags[i] = CCTileMapFileEncodedTileFlags.DecodeGidAndFlags(gidAndFlags); } currentString = null; } else if ((tileDataCompressionType & CCTileDataCompressionType.None) != 0) { currentXmlTileIndex = 0; } }
public void EndElement(object ctx, string elementName) { CCTMXMapInfo pTMXMapInfo = this; byte[] encoded = null; if (elementName == "data" && (pTMXMapInfo.LayerAttribs & (int)CCTMXLayerAttrib.Base64) != 0) { pTMXMapInfo.StoringCharacters = false; List <CCTMXLayerInfo> layers = pTMXMapInfo.Layers; int layersCount = layers != null ? layers.Count : 0; CCTMXLayerInfo layer = layersCount > 0 ? layers[layersCount - 1] : null; if ((pTMXMapInfo.LayerAttribs & ((int)(CCTMXLayerAttrib.Gzip) | (int)CCTMXLayerAttrib.Zlib)) != 0) { //gzip compress if ((pTMXMapInfo.LayerAttribs & (int)CCTMXLayerAttrib.Gzip) != 0) { try { encoded = ZipUtils.Inflate(new MemoryStream(pTMXMapInfo.CurrentString), ZipUtils.CompressionFormat.Gzip); } catch (Exception ex) { CCLog.Log("failed to decompress embedded data object in TMX file."); CCLog.Log(ex.ToString()); } } //zlib if ((pTMXMapInfo.LayerAttribs & (int)CCTMXLayerAttrib.Zlib) != 0) { encoded = ZipUtils.Inflate(new MemoryStream(pTMXMapInfo.CurrentString), ZipUtils.CompressionFormat.Zlib); } } else { encoded = pTMXMapInfo.CurrentString; } for (int i = 0; i < layer.Tiles.Length; i++) { int i4 = i * 4; var gid = (uint)( encoded[i4] | encoded[i4 + 1] << 8 | encoded[i4 + 2] << 16 | encoded[i4 + 3] << 24); layer.Tiles[i] = gid; } pTMXMapInfo.CurrentString = null; } else if (elementName == "map") { // The map element has ended pTMXMapInfo.ParentElement = (int)CCTMXProperty.None; } else if (elementName == "layer") { // The layer element has ended pTMXMapInfo.ParentElement = (int)CCTMXProperty.None; } else if (elementName == "objectgroup") { // The objectgroup element has ended pTMXMapInfo.ParentElement = (int)CCTMXProperty.None; } else if (elementName == "object") { // The object element has ended pTMXMapInfo.ParentElement = (int)CCTMXProperty.None; } }