From b52d4724e936390b85d3107176ce7b5c025a9be8 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Wed, 28 Feb 2024 20:15:31 +0900 Subject: [PATCH] cleanup --- .../FileSystemSharedImmediateTexture.cs | 21 ++------------ .../GamePathSharedImmediateTexture.cs | 21 ++------------ .../SharedImmediateTexture.cs | 29 +++++-------------- Dalamud/Interface/Internal/TextureManager.cs | 4 +-- 4 files changed, 15 insertions(+), 60 deletions(-) diff --git a/Dalamud/Interface/Internal/SharedImmediateTextures/FileSystemSharedImmediateTexture.cs b/Dalamud/Interface/Internal/SharedImmediateTextures/FileSystemSharedImmediateTexture.cs index f74379c28..6504c72c0 100644 --- a/Dalamud/Interface/Internal/SharedImmediateTextures/FileSystemSharedImmediateTexture.cs +++ b/Dalamud/Interface/Internal/SharedImmediateTextures/FileSystemSharedImmediateTexture.cs @@ -13,30 +13,15 @@ internal sealed class FileSystemSharedImmediateTexture : SharedImmediateTexture /// Initializes a new instance of the class. /// The path. - /// If set to true, this class will hold a reference to self. - /// Otherwise, it is expected that the caller to hold the reference. - private FileSystemSharedImmediateTexture(string path, bool holdSelfReference) - : base(holdSelfReference) - { - this.path = path; - if (holdSelfReference) - this.ReviveResources(); - } + private FileSystemSharedImmediateTexture(string path) => this.path = path; /// public override string SourcePathForDebug => this.path; - /// Creates a new instance of . - /// The new instance will hold a reference to itself. + /// Creates a new placeholder instance of . /// The path. /// The new instance. - public static SharedImmediateTexture CreateImmediate(string path) => new FileSystemSharedImmediateTexture(path, true); - - /// Creates a new instance of . - /// The caller is expected to manage ownership of the new instance. - /// The path. - /// The new instance. - public static SharedImmediateTexture CreateAsync(string path) => new FileSystemSharedImmediateTexture(path, false); + public static SharedImmediateTexture CreatePlaceholder(string path) => new FileSystemSharedImmediateTexture(path); /// public override string ToString() => diff --git a/Dalamud/Interface/Internal/SharedImmediateTextures/GamePathSharedImmediateTexture.cs b/Dalamud/Interface/Internal/SharedImmediateTextures/GamePathSharedImmediateTexture.cs index c06669372..f1f35677e 100644 --- a/Dalamud/Interface/Internal/SharedImmediateTextures/GamePathSharedImmediateTexture.cs +++ b/Dalamud/Interface/Internal/SharedImmediateTextures/GamePathSharedImmediateTexture.cs @@ -16,30 +16,15 @@ internal sealed class GamePathSharedImmediateTexture : SharedImmediateTexture /// Initializes a new instance of the class. /// The path. - /// If set to true, this class will hold a reference to self. - /// Otherwise, it is expected that the caller to hold the reference. - private GamePathSharedImmediateTexture(string path, bool holdSelfReference) - : base(holdSelfReference) - { - this.path = path; - if (holdSelfReference) - this.ReviveResources(); - } + private GamePathSharedImmediateTexture(string path) => this.path = path; /// public override string SourcePathForDebug => this.path; - /// Creates a new instance of . - /// The new instance will hold a reference to itself. + /// Creates a new placeholder instance of . /// The path. /// The new instance. - public static SharedImmediateTexture CreateImmediate(string path) => new GamePathSharedImmediateTexture(path, true); - - /// Creates a new instance of . - /// The caller is expected to manage ownership of the new instance. - /// The path. - /// The new instance. - public static SharedImmediateTexture CreateAsync(string path) => new GamePathSharedImmediateTexture(path, false); + public static SharedImmediateTexture CreatePlaceholder(string path) => new GamePathSharedImmediateTexture(path); /// public override string ToString() => $"{nameof(GamePathSharedImmediateTexture)}#{this.InstanceIdForDebug}({this.path})"; diff --git a/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs b/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs index b929a6faf..d4df6a85b 100644 --- a/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs +++ b/Dalamud/Interface/Internal/SharedImmediateTextures/SharedImmediateTexture.cs @@ -27,30 +27,15 @@ internal abstract class SharedImmediateTexture private NotOwnedTextureWrap? nonOwningWrap; /// Initializes a new instance of the class. - /// If set to true, this class will hold a reference to self. - /// Otherwise, it is expected that the caller to hold the reference. - protected SharedImmediateTexture(bool holdSelfReference) + /// The new instance is a placeholder instance. + protected SharedImmediateTexture() { this.InstanceIdForDebug = Interlocked.Increment(ref instanceCounter); - - if (holdSelfReference) - { - this.refCount = 1; - this.selfReferenceExpiry = Environment.TickCount64 + SelfReferenceDurationTicks; - this.ContentQueried = true; - this.IsOpportunistic = true; - this.resourceReleased = false; - this.cancellationTokenSource = new(); - } - else - { - this.refCount = 0; - this.selfReferenceExpiry = SelfReferenceExpiryExpired; - this.ContentQueried = false; - this.IsOpportunistic = false; - this.resourceReleased = true; - } - + this.refCount = 0; + this.selfReferenceExpiry = SelfReferenceExpiryExpired; + this.ContentQueried = false; + this.IsOpportunistic = true; + this.resourceReleased = true; this.FirstRequestedTick = this.LatestRequestedTick = Environment.TickCount64; } diff --git a/Dalamud/Interface/Internal/TextureManager.cs b/Dalamud/Interface/Internal/TextureManager.cs index bd35ab97b..3f44bcf20 100644 --- a/Dalamud/Interface/Internal/TextureManager.cs +++ b/Dalamud/Interface/Internal/TextureManager.cs @@ -158,12 +158,12 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public SharedImmediateTexture GetFromGame(string path) => - this.gamePathTextures.GetOrAdd(path, GamePathSharedImmediateTexture.CreateImmediate); + this.gamePathTextures.GetOrAdd(path, GamePathSharedImmediateTexture.CreatePlaceholder); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public SharedImmediateTexture GetFromFile(string path) => - this.fileSystemTextures.GetOrAdd(path, FileSystemSharedImmediateTexture.CreateImmediate); + this.fileSystemTextures.GetOrAdd(path, FileSystemSharedImmediateTexture.CreatePlaceholder); /// [MethodImpl(MethodImplOptions.AggressiveInlining)]