diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-06 18:26:35 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-06 18:26:35 -0400 |
commit | a969828e9357306aaac5163c430e108ab57f578b (patch) | |
tree | 7d2c8d321b0a000ad2625ffe0c6b35a830d09cc5 /src/SMAPI/Framework/ContentCoordinator.cs | |
parent | b834ed7ef5095203529f8b77aee3f25f5387fbcc (diff) | |
download | SMAPI-a969828e9357306aaac5163c430e108ab57f578b.tar.gz SMAPI-a969828e9357306aaac5163c430e108ab57f578b.tar.bz2 SMAPI-a969828e9357306aaac5163c430e108ab57f578b.zip |
cache asset operation instances created legacy interceptors
Diffstat (limited to 'src/SMAPI/Framework/ContentCoordinator.cs')
-rw-r--r-- | src/SMAPI/Framework/ContentCoordinator.cs | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index ef442fbe..8ce0dba1 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -81,6 +81,14 @@ namespace StardewModdingAPI.Framework /// <summary>The cached asset load/edit operations to apply, indexed by asset name.</summary> private readonly TickCacheDictionary<IAssetName, AssetOperationGroup[]> AssetOperationsByKey = new(); + /// <summary>A cache of asset operation groups created for legacy <see cref="IAssetLoader"/> implementations.</summary> + [Obsolete] + private readonly Dictionary<IAssetLoader, AssetOperationGroup> LegacyLoaderCache = new(ReferenceEqualityComparer.Instance); + + /// <summary>A cache of asset operation groups created for legacy <see cref="IAssetEditor"/> implementations.</summary> + [Obsolete] + private readonly Dictionary<IAssetEditor, AssetOperationGroup> LegacyEditorCache = new(ReferenceEqualityComparer.Instance); + /********* ** Accessors @@ -598,21 +606,26 @@ namespace StardewModdingAPI.Framework } // add operation - yield return new AssetOperationGroup( - mod: loader.Mod, - loadOperations: new[] - { - new AssetLoadOperation( - mod: loader.Mod, - priority: AssetLoadPriority.Exclusive, - onBehalfOf: null, - getData: assetInfo => loader.Data.Load<T>( - this.GetLegacyAssetInfo(assetInfo) + if (!this.LegacyLoaderCache.TryGetValue(loader.Data, out AssetOperationGroup? group)) + { + this.LegacyLoaderCache[loader.Data] = group = new AssetOperationGroup( + mod: loader.Mod, + loadOperations: new[] + { + new AssetLoadOperation( + mod: loader.Mod, + priority: AssetLoadPriority.Exclusive, + onBehalfOf: null, + getData: assetInfo => loader.Data.Load<T>( + this.GetLegacyAssetInfo(assetInfo) + ) ) - ) - }, - editOperations: Array.Empty<AssetEditOperation>() - ); + }, + editOperations: Array.Empty<AssetEditOperation>() + ); + } + + yield return group; } // legacy edit operations @@ -652,21 +665,26 @@ namespace StardewModdingAPI.Framework }; // add operation - yield return new AssetOperationGroup( - mod: editor.Mod, - loadOperations: Array.Empty<AssetLoadOperation>(), - editOperations: new[] - { - new AssetEditOperation( - mod: editor.Mod, - priority: priority, - onBehalfOf: null, - applyEdit: assetData => editor.Data.Edit<T>( - this.GetLegacyAssetData(assetData) + if (!this.LegacyEditorCache.TryGetValue(editor.Data, out AssetOperationGroup? group)) + { + this.LegacyEditorCache[editor.Data] = group = new AssetOperationGroup( + mod: editor.Mod, + loadOperations: Array.Empty<AssetLoadOperation>(), + editOperations: new[] + { + new AssetEditOperation( + mod: editor.Mod, + priority: priority, + onBehalfOf: null, + applyEdit: assetData => editor.Data.Edit<T>( + this.GetLegacyAssetData(assetData) + ) ) - ) - } - ); + } + ); + } + + yield return group; } #pragma warning restore CS0612, CS0618 } |