public Task LoadFontAsync() => fontLoadTask ??= Task.Factory.StartNew(() => { try { BitmapFont font; using (var s = Store.GetStream($@"{AssetName}")) { string hash = s.ComputeMD5Hash(); if (font_cache.TryGetValue(hash, out font)) { Logger.Log($"Cached font load for {AssetName}"); } else { font_cache.TryAdd(hash, font = BitmapFont.FromStream(s, FormatHint.Binary, false)); } } completionSource.SetResult(font); } catch (Exception ex) { Logger.Error(ex, $"Couldn't load font asset from {AssetName}."); completionSource.SetResult(null); throw; } }, TaskCreationOptions.PreferFairness);
private async Task readFontMetadataAsync(bool precache) { await Task.Run(() => { try { font = new BitmapFont(); using (var s = store.GetStream($@"{assetName}.fnt")) font.LoadText(s); if (precache) { for (int i = 0; i < font.Pages.Length; i++) { getTexturePage(i); } } } catch { Logger.Log($"Couldn't load font asset from {assetName}."); throw; } }); fontLoadTask = null; }
private async Task readFontMetadataAsync(bool precache) { await Task.Factory.StartNew(() => { try { font = new BitmapFont(); using (var s = store.GetStream($@"{assetName}.fnt")) font.LoadText(s); if (precache) { for (int i = 0; i < font.Pages.Length; i++) { getTexturePage(i); } } } catch (Exception ex) { Logger.Error(ex, $"Couldn't load font asset from {assetName}."); throw; } }, TaskCreationOptions.LongRunning); fontLoadTask = null; }
private async Task readFontMetadataAsync(bool precache) { await Task.Run(() => { try { font = new BitmapFont(); using (var s = store.GetStream($@"{assetName}.fnt")) font.LoadText(s); if (precache) { for (int i = 0; i < font.Pages.Length; i++) { getTexturePage(i); } } } catch { throw new FontLoadException(assetName); } }); fontLoadTask = null; }
public GlyphStore(ResourceStore <byte[]> store, string assetName = null, bool precache = false) { this.store = store; this.assetName = assetName; fontName = assetName.Split('/').Last(); try { font = new BitmapFont(); font.LoadText(store.GetStream($@"{assetName}.fnt")); if (precache) { for (int i = 0; i < font.Pages.Length; i++) { getTexturePage(i); } } } catch { throw new FontLoadException(assetName); } }
public Task LoadFontAsync() => fontLoadTask ?? (fontLoadTask = Task.Factory.StartNew(() => { try { var font = new BitmapFont(); using (var s = store.GetStream($@"{assetName}.fnt")) font.LoadText(s); completionSource.SetResult(font); } catch (Exception ex) { Logger.Error(ex, $"Couldn't load font asset from {assetName}."); throw; } }, TaskCreationOptions.PreferFairness));
public Task LoadFontAsync() => fontLoadTask ?? (fontLoadTask = Task.Factory.StartNew(() => { try { BitmapFont font; using (var s = store.GetStream($@"{assetName}.bin")) font = BitmapFont.FromStream(s, FormatHint.Binary, false); completionSource.SetResult(font); } catch (Exception ex) { Logger.Error(ex, $"Couldn't load font asset from {assetName}."); throw; } }, TaskCreationOptions.PreferFairness));
private MagickImage getTexturePage(int texturePage) { MagickImage t; if (!texturePages.TryGetValue(texturePage, out t)) { texturePages[texturePage] = t = new MagickImage(store.GetStream($@"{assetName}_{texturePage}.png")); } return(t); }
private RawTexture getTexturePage(int texturePage) { RawTexture t; if (!texturePages.TryGetValue(texturePage, out t)) { using (var stream = store.GetStream($@"{assetName}_{texturePage}.png")) texturePages[texturePage] = t = RawTexture.FromStream(stream); } return(t); }
private RawTexture getTexturePage(int texturePage) { RawTexture t; if (!texturePages.TryGetValue(texturePage, out t)) { using (var stream = store.GetStream($@"{assetName}_{texturePage.ToString().PadLeft((font.Pages.Length - 1).ToString().Length, '0')}.png")) texturePages[texturePage] = t = RawTexture.FromStream(stream); } return(t); }
public GlyphStore(ResourceStore <byte[]> store, string assetName = null) { this.store = store; this.assetName = assetName; try { font = new BitmapFont(); font.LoadText(store.GetStream($@"{assetName}.fnt")); } catch { throw new FontLoadException(assetName); } }
public GlyphStore(ResourceStore <byte[]> store, string assetName = null) { this.store = store; this.assetName = assetName; try { font = new BitmapFont(); font.LoadText(store.GetStream($@"{assetName}.fnt")); //ScaleAdjust = font.StretchedHeight; } catch { throw new Exception($@"Couldn't load font asset from {assetName}."); } }
private RawTexture getTexturePage(int texturePage) { RawTexture t; if (!texturePages.TryGetValue(texturePage, out t)) { t = new RawTexture(); using (var stream = store.GetStream($@"{assetName}_{texturePage}.png")) { var reader = new PngReader(); t.Pixels = reader.Read(stream); t.PixelFormat = OpenTK.Graphics.ES20.PixelFormat.Rgba; t.Width = reader.Width; t.Height = reader.Height; } texturePages[texturePage] = t; } return(t); }