Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add async loading texture wrap for acceleration.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 18, 2023
1 parent 6dc943f commit fbd8d66
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,29 @@ public enum IconType : byte
public static class IconSet
{
private static readonly Dictionary<uint, TextureWrap> _textures = new Dictionary<uint, TextureWrap>();

private static readonly HashSet<uint> _loadingTexture = new HashSet<uint>();
public static TextureWrap GetTexture(this ITexture text) => GetTexture(text?.IconID ?? 0);

public static TextureWrap GetTexture(uint id)
{
if (!_textures.TryGetValue(id, out var texture))
{
texture = Service.GetTextureIcon(id);
_textures.Add(id, texture);
if (!_loadingTexture.Contains(id))
{
_loadingTexture.Add(id);
Task.Run(() =>
{
texture = Service.GetTextureIcon(id);
_textures.Add(id, texture);
});
}

if (!_textures.TryGetValue(0, out texture))
{
texture = Service.GetTextureIcon(0);
_textures.Add(0, texture);
}
return texture;
}

return texture;
Expand Down

0 comments on commit fbd8d66

Please sign in to comment.