From a6c20cb23108701c88ea4f44c6fa9a68318d491e Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 13 Feb 2025 14:20:39 -0800 Subject: [PATCH] document --- NewHorizons/Components/EOTE/NHSlideCollection.cs | 11 ++++++++++- .../Components/EOTE/NHSlideCollectionContainer.cs | 1 + .../Utility/Files/SlideReelAsyncImageLoader.cs | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Components/EOTE/NHSlideCollection.cs b/NewHorizons/Components/EOTE/NHSlideCollection.cs index 0eed0393..6ab5ef8b 100644 --- a/NewHorizons/Components/EOTE/NHSlideCollection.cs +++ b/NewHorizons/Components/EOTE/NHSlideCollection.cs @@ -18,9 +18,12 @@ public class NHSlideCollection : SlideCollection public string[] slidePaths; public IModBehaviour mod; private HashSet _pathsBeingLoaded = new(); + /// + /// map of slide path to collections that have this path loaded. used to only unload slide when nothing else is using it + /// public static Dictionary> _slidesRequiringPath = new(); - private ShipLogSlideProjector _shipLogSlideProjector; + private static ShipLogSlideProjector _shipLogSlideProjector; static NHSlideCollection() { @@ -113,6 +116,7 @@ public class NHSlideCollection : SlideCollection // Something else has loaded this image i.e., AutoProjector or Vision torch. We want to ensure we do not delete it if (ImageUtilities.IsTextureLoaded(mod, path)) { + // null is dummy value to ensure its never empty (so its not deleted) _slidesRequiringPath[key] = new() { null }; } else @@ -124,17 +128,21 @@ public class NHSlideCollection : SlideCollection if (ImageUtilities.IsTextureLoaded(mod, path)) { + // already loaded var texture = ImageUtilities.GetTexture(mod, path); slides[wrappedIndex]._image = texture; return texture; } else if (!_pathsBeingLoaded.Contains(path)) { + // not loaded yet, we need to load it var loader = new SlideReelAsyncImageLoader(); loader.PathsToLoad.Add((wrappedIndex, path)); loader.Start(true, false); loader.imageLoadedEvent.AddListener((Texture2D tex, int index, string originalPath) => { + // weird: sometimes we set image, sometimes we return from GetStreamingTexture. oh well + // also somehow setting this later works and updates the cookie without having to manually tell it to do that??? idk how slides[wrappedIndex]._image = tex; _pathsBeingLoaded.Remove(path); if (_shipLogSlideProjector == null) @@ -143,6 +151,7 @@ public class NHSlideCollection : SlideCollection } if (_shipLogSlideProjector != null) { + // gotta tell ship log we updated the image _shipLogSlideProjector._slideDirty = true; } else diff --git a/NewHorizons/Components/EOTE/NHSlideCollectionContainer.cs b/NewHorizons/Components/EOTE/NHSlideCollectionContainer.cs index 444d22da..030139e4 100644 --- a/NewHorizons/Components/EOTE/NHSlideCollectionContainer.cs +++ b/NewHorizons/Components/EOTE/NHSlideCollectionContainer.cs @@ -10,6 +10,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer { public string[] conditionsToSet; public string[] persistentConditionsToSet; + // at some point we'll do streaming on all slides. until then just have an off switch public bool doAsyncLoading = true; [HarmonyPrefix] diff --git a/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs b/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs index e81d8298..e088e9d9 100644 --- a/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs +++ b/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs @@ -42,6 +42,11 @@ public class SlideReelAsyncImageLoader private bool _started; private bool _clamp; + /// + /// start loading the images a frame later + /// + /// sets wrapMode + /// load all slides one at a time vs at the same time public void Start(bool clamp, bool sequential) { if (_started) return;