cache asset operation instances created legacy interceptors
This commit is contained in:
parent
b834ed7ef5
commit
a969828e93
|
@ -3,8 +3,9 @@
|
||||||
# Release notes
|
# Release notes
|
||||||
## Upcoming release
|
## Upcoming release
|
||||||
* For players:
|
* For players:
|
||||||
|
* Improved performance for many mods still using the older content API.
|
||||||
* Disabled case-insensitive file paths (introduced in 3.14.0) by default.
|
* Disabled case-insensitive file paths (introduced in 3.14.0) by default.
|
||||||
_You can enable them by editing `smapi-internal/config.json` if needed. They'll be re-enabled in a later version after they're reworked to reduce performance impact._
|
_You can enable them by editing `smapi-internal/config.json` if needed. They'll be re-enabled in an upcoming version after they're reworked a bit._
|
||||||
* Removed experimental 'aggressive memory optimizations' option.
|
* Removed experimental 'aggressive memory optimizations' option.
|
||||||
_This was disabled by default and is no longer needed in most cases. Memory usage will be better reduced by reworked asset propagation in the upcoming SMAPI 4.0.0._
|
_This was disabled by default and is no longer needed in most cases. Memory usage will be better reduced by reworked asset propagation in the upcoming SMAPI 4.0.0._
|
||||||
* Fixed 'content file was not found' error when the game tries to load unlocalized text from a localizable mod data asset.
|
* Fixed 'content file was not found' error when the game tries to load unlocalized text from a localizable mod data asset.
|
||||||
|
|
|
@ -81,6 +81,14 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <summary>The cached asset load/edit operations to apply, indexed by asset name.</summary>
|
/// <summary>The cached asset load/edit operations to apply, indexed by asset name.</summary>
|
||||||
private readonly TickCacheDictionary<IAssetName, AssetOperationGroup[]> AssetOperationsByKey = new();
|
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
|
** Accessors
|
||||||
|
@ -598,21 +606,26 @@ namespace StardewModdingAPI.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
// add operation
|
// add operation
|
||||||
yield return new AssetOperationGroup(
|
if (!this.LegacyLoaderCache.TryGetValue(loader.Data, out AssetOperationGroup? group))
|
||||||
mod: loader.Mod,
|
{
|
||||||
loadOperations: new[]
|
this.LegacyLoaderCache[loader.Data] = group = new AssetOperationGroup(
|
||||||
{
|
mod: loader.Mod,
|
||||||
new AssetLoadOperation(
|
loadOperations: new[]
|
||||||
mod: loader.Mod,
|
{
|
||||||
priority: AssetLoadPriority.Exclusive,
|
new AssetLoadOperation(
|
||||||
onBehalfOf: null,
|
mod: loader.Mod,
|
||||||
getData: assetInfo => loader.Data.Load<T>(
|
priority: AssetLoadPriority.Exclusive,
|
||||||
this.GetLegacyAssetInfo(assetInfo)
|
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
|
// legacy edit operations
|
||||||
|
@ -652,21 +665,26 @@ namespace StardewModdingAPI.Framework
|
||||||
};
|
};
|
||||||
|
|
||||||
// add operation
|
// add operation
|
||||||
yield return new AssetOperationGroup(
|
if (!this.LegacyEditorCache.TryGetValue(editor.Data, out AssetOperationGroup? group))
|
||||||
mod: editor.Mod,
|
{
|
||||||
loadOperations: Array.Empty<AssetLoadOperation>(),
|
this.LegacyEditorCache[editor.Data] = group = new AssetOperationGroup(
|
||||||
editOperations: new[]
|
mod: editor.Mod,
|
||||||
{
|
loadOperations: Array.Empty<AssetLoadOperation>(),
|
||||||
new AssetEditOperation(
|
editOperations: new[]
|
||||||
mod: editor.Mod,
|
{
|
||||||
priority: priority,
|
new AssetEditOperation(
|
||||||
onBehalfOf: null,
|
mod: editor.Mod,
|
||||||
applyEdit: assetData => editor.Data.Edit<T>(
|
priority: priority,
|
||||||
this.GetLegacyAssetData(assetData)
|
onBehalfOf: null,
|
||||||
|
applyEdit: assetData => editor.Data.Edit<T>(
|
||||||
|
this.GetLegacyAssetData(assetData)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
yield return group;
|
||||||
}
|
}
|
||||||
#pragma warning restore CS0612, CS0618
|
#pragma warning restore CS0612, CS0618
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue