From 295ad29b8d60fdbae0c0030e8d887a2adab779a3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 4 May 2022 21:02:41 -0400 Subject: remove aggressive memory optimizations option --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 51 +++++++------------------------ 1 file changed, 11 insertions(+), 40 deletions(-) (limited to 'src/SMAPI/Metadata/CoreAssetPropagator.cs') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 5dee2c4d..12b73515 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI.Framework.ContentManagers; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Internal; using StardewModdingAPI.Toolkit.Utilities; @@ -33,18 +32,12 @@ namespace StardewModdingAPI.Metadata /// The main content manager through which to reload assets. private readonly LocalizedContentManager MainContentManager; - /// An internal content manager used only for asset propagation. See remarks on . - private readonly GameContentManagerForAssetPropagation DisposableContentManager; - /// Writes messages to the console. private readonly IMonitor Monitor; /// Simplifies access to private game code. private readonly Reflector Reflection; - /// Whether to enable more aggressive memory optimizations. - private readonly bool AggressiveMemoryOptimizations; - /// Parse a raw asset name. private readonly Func ParseAssetName; @@ -67,18 +60,14 @@ namespace StardewModdingAPI.Metadata *********/ /// Initialize the core asset data. /// The main content manager through which to reload assets. - /// An internal content manager used only for asset propagation. /// Writes messages to the console. /// Simplifies access to private code. - /// Whether to enable more aggressive memory optimizations. /// Parse a raw asset name. - public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Reflector reflection, bool aggressiveMemoryOptimizations, Func parseAssetName) + public CoreAssetPropagator(LocalizedContentManager mainContent, IMonitor monitor, Reflector reflection, Func parseAssetName) { this.MainContentManager = mainContent; - this.DisposableContentManager = disposableContent; this.Monitor = monitor; this.Reflection = reflection; - this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations; this.ParseAssetName = parseAssetName; } @@ -230,7 +219,7 @@ namespace StardewModdingAPI.Metadata ** Buildings ****/ case "buildings/houses": // Farm - Farm.houseTextures = this.LoadAndDisposeIfNeeded(Farm.houseTextures, key); + Farm.houseTextures = this.LoadTexture(key); return true; case "buildings/houses_paintmask": // Farm @@ -247,7 +236,7 @@ namespace StardewModdingAPI.Metadata ** Content\Characters\Farmer ****/ case "characters/farmer/accessories": // Game1.LoadContent - FarmerRenderer.accessoriesTexture = this.LoadAndDisposeIfNeeded(FarmerRenderer.accessoriesTexture, key); + FarmerRenderer.accessoriesTexture = this.LoadTexture(key); return true; case "characters/farmer/farmer_base": // Farmer @@ -257,19 +246,19 @@ namespace StardewModdingAPI.Metadata return !ignoreWorld && this.ReloadPlayerSprites(assetName); case "characters/farmer/hairstyles": // Game1.LoadContent - FarmerRenderer.hairStylesTexture = this.LoadAndDisposeIfNeeded(FarmerRenderer.hairStylesTexture, key); + FarmerRenderer.hairStylesTexture = this.LoadTexture(key); return true; case "characters/farmer/hats": // Game1.LoadContent - FarmerRenderer.hatsTexture = this.LoadAndDisposeIfNeeded(FarmerRenderer.hatsTexture, key); + FarmerRenderer.hatsTexture = this.LoadTexture(key); return true; case "characters/farmer/pants": // Game1.LoadContent - FarmerRenderer.pantsTexture = this.LoadAndDisposeIfNeeded(FarmerRenderer.pantsTexture, key); + FarmerRenderer.pantsTexture = this.LoadTexture(key); return true; case "characters/farmer/shirts": // Game1.LoadContent - FarmerRenderer.shirtsTexture = this.LoadAndDisposeIfNeeded(FarmerRenderer.shirtsTexture, key); + FarmerRenderer.shirtsTexture = this.LoadTexture(key); return true; /**** @@ -905,9 +894,6 @@ namespace StardewModdingAPI.Metadata GameLocation location = locationInfo.Location; Vector2? playerPos = Game1.player?.Position; - if (this.AggressiveMemoryOptimizations) - location.map.DisposeTileSheets(Game1.mapDisplayDevice); - // reload map location.interiorDoors.Clear(); // prevent errors when doors try to update tiles which no longer exist location.reloadMap(); @@ -973,7 +959,7 @@ namespace StardewModdingAPI.Metadata // update sprite foreach (var target in characters) { - target.Npc.Sprite.spriteTexture = this.LoadAndDisposeIfNeeded(target.Npc.Sprite.spriteTexture, target.AssetName.BaseName); + target.Npc.Sprite.spriteTexture = this.LoadTexture(target.AssetName.BaseName); propagated[target.AssetName] = true; } } @@ -1012,7 +998,7 @@ namespace StardewModdingAPI.Metadata // update portrait foreach (var target in characters) { - target.Npc.Portrait = this.LoadAndDisposeIfNeeded(target.Npc.Portrait, target.AssetName.BaseName); + target.Npc.Portrait = this.LoadTexture(target.AssetName.BaseName); propagated[target.AssetName] = true; } } @@ -1284,25 +1270,10 @@ namespace StardewModdingAPI.Metadata : Array.Empty(); } - /// Load a texture, and dispose the old one if is enabled and it's different from the new instance. - /// The previous texture to dispose. + /// Load a texture from the main content manager. /// The asset key to load. - private Texture2D LoadAndDisposeIfNeeded(Texture2D? oldTexture, string key) + private Texture2D LoadTexture(string key) { - // if aggressive memory optimizations are enabled, load the asset from the disposable - // content manager and dispose the old instance if needed. - if (this.AggressiveMemoryOptimizations) - { - GameContentManagerForAssetPropagation content = this.DisposableContentManager; - - Texture2D newTexture = content.Load(key); - if (oldTexture?.IsDisposed == false && !object.ReferenceEquals(oldTexture, newTexture) && content.IsResponsibleFor(oldTexture)) - oldTexture.Dispose(); - - return newTexture; - } - - // else just (re)load it from the main content manager return this.MainContentManager.Load(key); } -- cgit