protected void CheckSkin() { DownloadedItem item; game.AsyncDownloader.TryGetItem(SkinIdentifier, out item); if (item != null && item.Data != null) { Bitmap bmp = (Bitmap)item.Data; game.Graphics.DeleteTexture(ref PlayerTextureId); if (!FastBitmap.CheckFormat(bmp.PixelFormat)) { game.Drawer2D.ConvertTo32Bpp(ref bmp); } try { SkinType = Utils.GetSkinType(bmp); if (Model is HumanoidModel || Model is ChibiModel) { ClearHat(bmp, SkinType); } PlayerTextureId = game.Graphics.CreateTexture(bmp); MobTextureId = -1; // Custom mob textures. if (Utils.IsUrlPrefix(SkinName, 0) && item.TimeAdded > lastModelChange) { MobTextureId = PlayerTextureId; } } catch (NotSupportedException) { ResetSkin(bmp); } bmp.Dispose(); } }
/// <summary> Updates the underlying atlas bitmap, fields, and texture. </summary> public void UpdateState(BlockInfo info, Bitmap bmp) { if (!FastBitmap.CheckFormat(bmp.PixelFormat)) { Utils.LogDebug("Converting terrain atlas to 32bpp image"); drawer.ConvertTo32Bpp(ref bmp); } AtlasBitmap = bmp; elementSize = bmp.Width >> 4; using (FastBitmap fastBmp = new FastBitmap(bmp, true, true)) info.RecalculateSpriteBB(fastBmp); }
/// <summary> Reads a bitmap from the stream (converting it to 32 bits per pixel if necessary), /// and updates the native texture for it. </summary> public void UpdateTexture(ref int texId, byte[] data, bool setSkinType) { MemoryStream stream = new MemoryStream(data); Graphics.DeleteTexture(ref texId); using (Bitmap bmp = Platform.ReadBmp(stream)) { if (setSkinType) { DefaultPlayerSkinType = Utils.GetSkinType(bmp); } if (!FastBitmap.CheckFormat(bmp.PixelFormat)) { using (Bitmap bmp32 = Drawer2D.ConvertTo32Bpp(bmp)) texId = Graphics.CreateTexture(bmp32); } else { texId = Graphics.CreateTexture(bmp); } } }
protected void CheckAsyncResources() { DownloadedItem item; if (game.AsyncDownloader.TryGetItem("terrain", out item)) { if (item.Data != null) { Bitmap bmp = (Bitmap)item.Data; game.World.TextureUrl = item.Url; game.Events.RaiseTexturePackChanged(); if (!FastBitmap.CheckFormat(bmp.PixelFormat)) { Utils.LogDebug("Converting terrain atlas to 32bpp image"); game.Drawer2D.ConvertTo32Bpp(ref bmp); } if (!game.ChangeTerrainAtlas(bmp)) { bmp.Dispose(); return; } TextureCache.AddToCache(item.Url, bmp); TextureCache.AddETagToCache(item.Url, item.ETag, game.ETags); } else if (item.ResponseCode == HttpStatusCode.NotModified) { Bitmap bmp = TextureCache.GetBitmapFromCache(item.Url); if (bmp == null) // Should never happen, but handle anyways. { ExtractDefault(); } else if (item.Url != game.World.TextureUrl) { game.Events.RaiseTexturePackChanged(); if (!game.ChangeTerrainAtlas(bmp)) { bmp.Dispose(); return; } } if (bmp != null) { game.World.TextureUrl = item.Url; } } else { ExtractDefault(); } } if (game.AsyncDownloader.TryGetItem("texturePack", out item)) { if (item.Data != null) { game.World.TextureUrl = item.Url; TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract((byte[])item.Data, game); TextureCache.AddToCache(item.Url, (byte[])item.Data); TextureCache.AddETagToCache(item.Url, item.ETag, game.ETags); } else if (item.ResponseCode == HttpStatusCode.NotModified) { byte[] data = TextureCache.GetDataFromCache(item.Url); if (data == null) // Should never happen, but handle anyways. { ExtractDefault(); } else if (item.Url != game.World.TextureUrl) { TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract(data, game); } if (data != null) { game.World.TextureUrl = item.Url; } } else { ExtractDefault(); } } }
protected void CheckAsyncResources() { DownloadedItem item; if (game.AsyncDownloader.TryGetItem("terrain", out item)) { if (item.Data != null) { Bitmap bmp = (Bitmap)item.Data; if (!FastBitmap.CheckFormat(bmp.PixelFormat)) { Utils.LogDebug("Converting terrain atlas to 32bpp image"); game.Drawer2D.ConvertTo32Bpp(ref bmp); } game.ChangeTerrainAtlas(bmp); TextureCache.AddToCache(item.Url, bmp); game.Map.TextureUrl = item.Url; } else if (Is304Status(item.WebEx)) { Bitmap bmp = TextureCache.GetBitmapFromCache(item.Url); if (bmp == null) // Should never happen, but handle anyways. { ExtractDefault(); } else { game.ChangeTerrainAtlas(bmp); } game.Map.TextureUrl = item.Url; } else { ExtractDefault(); game.Map.TextureUrl = null; } } if (game.AsyncDownloader.TryGetItem("texturePack", out item)) { if (item.Data != null) { TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract((byte[])item.Data, game); TextureCache.AddToCache(item.Url, (byte[])item.Data); game.Map.TextureUrl = item.Url; } else if (Is304Status(item.WebEx)) { byte[] data = TextureCache.GetDataFromCache(item.Url); if (data == null) // Should never happen, but handle anyways. { ExtractDefault(); } else { TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract(data, game); } game.Map.TextureUrl = item.Url; } else { ExtractDefault(); game.Map.TextureUrl = null; } } }