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(); } } }