Esempio n. 1
0
        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);
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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));
Esempio n. 7
0
        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));
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        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}.");
            }
        }
Esempio n. 13
0
        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);
        }