DalamudAssetManager: avoid locks and lookups (#2015)

* Made DalamudAsset-to-something tables into arrays from dictionaries.
  Number of items in the DalamudAsset enum aren't many, and the numbers
  are small enough that implementing lookup tables as arrays aren't
  wasting much memory space.
* Removed locking from asset accessors, while still guaranteeing that
  the load operation happens only once per asset.
* ISharedImmediateTexture: made it not even access assets if textures
  are available.
This commit is contained in:
srkizer 2024-08-25 22:06:21 +09:00 committed by GitHub
parent 981387504b
commit 8822810229
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 168 additions and 145 deletions

View file

@ -5,7 +5,7 @@ using Dalamud.Game.Text.SeStringHandling;
namespace Dalamud.Interface.ImGuiSeStringRenderer;
/// <summary>Represents the result of n rendered interactable SeString.</summary>
/// <summary>Represents the result of a rendered interactable SeString.</summary>
public ref struct SeStringDrawResult
{
private Payload? lazyPayload;

View file

@ -171,17 +171,14 @@ internal abstract class SharedImmediateTexture
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IDalamudTextureWrap GetWrapOrEmpty() => this.GetWrapOrDefault(Service<DalamudAssetManager>.Get().Empty4X4);
public IDalamudTextureWrap GetWrapOrEmpty() =>
this.TryGetWrap(out var texture, out _) ? texture : Service<DalamudAssetManager>.Get().Empty4X4;
/// <inheritdoc/>
[return: NotNullIfNotNull(nameof(defaultWrap))]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IDalamudTextureWrap? GetWrapOrDefault(IDalamudTextureWrap? defaultWrap)
{
if (!this.TryGetWrap(out var texture, out _))
texture = null;
return texture ?? defaultWrap;
}
public IDalamudTextureWrap? GetWrapOrDefault(IDalamudTextureWrap? defaultWrap) =>
this.TryGetWrap(out var texture, out _) ? texture : defaultWrap;
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -37,7 +37,11 @@ public abstract class ForwardingTextureWrap : IDalamudTextureWrap
public Vector2 Size
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(this.Width, this.Height);
get
{
var wrap = this.GetWrap();
return new(wrap.Width, wrap.Height);
}
}
/// <inheritdoc/>

View file

@ -1,20 +1,13 @@
using Dalamud.Interface.Internal;
namespace Dalamud.Interface.Textures.TextureWraps.Internal;
/// <summary>A texture wrap that ignores <see cref="IDisposable.Dispose"/> calls.</summary>
internal class DisposeSuppressingTextureWrap : ForwardingTextureWrap
/// <param name="innerWrap">The inner wrap.</param>
internal class DisposeSuppressingTextureWrap(IDalamudTextureWrap innerWrap) : ForwardingTextureWrap
{
private readonly IDalamudTextureWrap innerWrap;
/// <summary>Initializes a new instance of the <see cref="DisposeSuppressingTextureWrap"/> class.</summary>
/// <param name="wrap">The inner wrap.</param>
public DisposeSuppressingTextureWrap(IDalamudTextureWrap wrap) => this.innerWrap = wrap;
/// <inheritdoc/>
protected override bool TryGetWrap(out IDalamudTextureWrap? wrap)
{
wrap = this.innerWrap;
wrap = innerWrap;
return true;
}
}