mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-27 23:41:14 -04:00
extract entry from texcache before doing async resource check. avoids 1-2 seconds of pink textures
This commit is contained in:
parent
7a96cac27e
commit
fb95a6a8b4
@ -118,21 +118,24 @@ namespace ClassicalSharp {
|
||||
DateTime lastModified = TextureCache.GetLastModified(url, game.LastModified);
|
||||
string etag = TextureCache.GetETag(url, game.ETags);
|
||||
|
||||
if (url.Contains(".zip"))
|
||||
if (url.Contains(".zip")) {
|
||||
TexturePack.ExtractCachedTexturePack(game, url);
|
||||
game.AsyncDownloader.DownloadData(url, true, "texturePack",
|
||||
lastModified, etag);
|
||||
else
|
||||
} else {
|
||||
TexturePack.ExtractCachedTerrainPng(game, url);
|
||||
game.AsyncDownloader.DownloadImage(url, true, "terrain",
|
||||
lastModified, etag);
|
||||
}
|
||||
}
|
||||
|
||||
protected void CheckAsyncResources() {
|
||||
DownloadedItem item;
|
||||
if (game.AsyncDownloader.TryGetItem("terrain", out item)) {
|
||||
TexturePack.ExtractTerrainPng(game, item.Url, item);
|
||||
TexturePack.ExtractTerrainPng(game, item);
|
||||
}
|
||||
if (game.AsyncDownloader.TryGetItem("texturePack", out item)) {
|
||||
TexturePack.ExtractTexturePack(game, item.Url, item);
|
||||
TexturePack.ExtractTexturePack(game, item);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -51,8 +51,8 @@ namespace ClassicalSharp.Textures {
|
||||
}
|
||||
|
||||
|
||||
internal static void ExtractTerrainPng(Game game, string url, DownloadedItem item) {
|
||||
if (item != null && item.Data != null) {
|
||||
internal static void ExtractTerrainPng(Game game, DownloadedItem item) {
|
||||
if (item.Data == null) return;
|
||||
Bitmap bmp = (Bitmap)item.Data;
|
||||
game.World.TextureUrl = item.Url;
|
||||
game.Events.RaiseTexturePackChanged();
|
||||
@ -62,10 +62,12 @@ namespace ClassicalSharp.Textures {
|
||||
TextureCache.Add(item.Url, bmp);
|
||||
TextureCache.AddETag(item.Url, item.ETag, game.ETags);
|
||||
TextureCache.AdddLastModified(item.Url, item.LastModified, game.LastModified);
|
||||
} else {
|
||||
}
|
||||
|
||||
internal static void ExtractCachedTerrainPng(Game game, string url) {
|
||||
FileStream data = TextureCache.GetStream(url);
|
||||
if (data == null) { // e.g. 404 errors
|
||||
ExtractDefault(game);
|
||||
if (game.World.TextureUrl != null) ExtractDefault(game);
|
||||
} else if (url != game.World.TextureUrl) {
|
||||
Bitmap bmp = GetBitmap(game.Drawer2D, data);
|
||||
if (bmp == null) { data.Dispose(); return; }
|
||||
@ -80,12 +82,12 @@ namespace ClassicalSharp.Textures {
|
||||
data.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ExtractTexturePack(Game game, string url, DownloadedItem item) {
|
||||
if (item != null && item.Data != null) {
|
||||
internal static void ExtractTexturePack(Game game, DownloadedItem item) {
|
||||
if (item.Data == null) return;
|
||||
game.World.TextureUrl = item.Url;
|
||||
byte[] data = (byte[])item.Data;
|
||||
|
||||
TexturePack extractor = new TexturePack();
|
||||
using (Stream ms = new MemoryStream(data)) {
|
||||
extractor.Extract(ms, game);
|
||||
@ -94,17 +96,19 @@ namespace ClassicalSharp.Textures {
|
||||
TextureCache.Add(item.Url, data);
|
||||
TextureCache.AddETag(item.Url, item.ETag, game.ETags);
|
||||
TextureCache.AdddLastModified(item.Url, item.LastModified, game.LastModified);
|
||||
} else {
|
||||
}
|
||||
|
||||
internal static void ExtractCachedTexturePack(Game game, string url) {
|
||||
FileStream data = TextureCache.GetStream(url);
|
||||
if (data == null) { // e.g. 404 errors
|
||||
ExtractDefault(game);
|
||||
if (game.World.TextureUrl != null) ExtractDefault(game);
|
||||
} else if (url != game.World.TextureUrl) {
|
||||
game.World.TextureUrl = url;
|
||||
TexturePack extractor = new TexturePack();
|
||||
extractor.Extract(data, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Bitmap GetBitmap(IDrawer2D drawer, Stream src) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user