コード例 #1
0
        void CheckForNewTerrainAtlas()
        {
            DownloadedItem item;

            if (game.AsyncDownloader.TryGetItem("terrain", out item))
            {
                if (item.Data != null)
                {
                    game.ChangeTerrainAtlas((Bitmap)item.Data);
                    TextureCache.AddToCache(item.Url, (Bitmap)item.Data);
                }
                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);
                    }
                }
                else
                {
                    ExtractDefault();
                }
            }

            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);
                }
                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);
                    }
                }
                else
                {
                    ExtractDefault();
                }
            }
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
        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;
                }
            }
        }