mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
it doesnt work
This commit is contained in:
parent
d4a50374e9
commit
784b1adb60
@ -513,7 +513,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
NHLogger.LogVerbose($"The atlas cache for slide reel containing [{slides.FirstOrDefault(x => !string.IsNullOrEmpty(x.imagePath))?.imagePath}] is {atlasKey}");
|
NHLogger.LogVerbose($"The atlas cache for slide reel containing [{slides.FirstOrDefault(x => !string.IsNullOrEmpty(x.imagePath))?.imagePath}] is {atlasKey}");
|
||||||
// Load the atlas texture used to draw onto the physical slide reel object
|
// Load the atlas texture used to draw onto the physical slide reel object
|
||||||
atlasImageLoader.PathsToLoad.Add((0, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ATLAS_SLIDE_CACHE_FOLDER, $"{atlasKey}.png")));
|
atlasImageLoader.PathsToLoad.Add((0, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ATLAS_SLIDE_CACHE_FOLDER, $"{atlasKey}.png"), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < slides.Length; i++)
|
for (int i = 0; i < slides.Length; i++)
|
||||||
@ -527,11 +527,12 @@ namespace NewHorizons.Builder.Props
|
|||||||
if (useInvertedCache && cacheExists)
|
if (useInvertedCache && cacheExists)
|
||||||
{
|
{
|
||||||
// Load the inverted images used when displaying slide reels to a screen
|
// Load the inverted images used when displaying slide reels to a screen
|
||||||
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/inverted_blank_slide_reel.png")));
|
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/inverted_blank_slide_reel.png"), false));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imageLoader.PathsToLoad.Add((i, Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/blank_slide_reel.png")));
|
// Used to then make cached stuff
|
||||||
|
imageLoader.PathsToLoad.Add((i, Path.Combine(Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/blank_slide_reel.png"), useInvertedCache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -539,11 +540,11 @@ namespace NewHorizons.Builder.Props
|
|||||||
if (useInvertedCache && cacheExists)
|
if (useInvertedCache && cacheExists)
|
||||||
{
|
{
|
||||||
// Load the inverted images used when displaying slide reels to a screen
|
// Load the inverted images used when displaying slide reels to a screen
|
||||||
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, INVERTED_SLIDE_CACHE_FOLDER, slideInfo.imagePath)));
|
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, INVERTED_SLIDE_CACHE_FOLDER, slideInfo.imagePath), false));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, slideInfo.imagePath)));
|
imageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, slideInfo.imagePath), useInvertedCache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,16 +557,16 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
if (useAtlasCache)
|
if (useAtlasCache)
|
||||||
{
|
{
|
||||||
atlasImageLoader.Start(false);
|
atlasImageLoader.Start(false, false);
|
||||||
}
|
}
|
||||||
// When using the inverted cache we never need the regular images
|
// When using the inverted cache we never need the regular images
|
||||||
if (useInvertedCache)
|
if (useInvertedCache)
|
||||||
{
|
{
|
||||||
invertedImageLoader.Start(true);
|
invertedImageLoader.Start(true, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imageLoader.Start(true);
|
imageLoader.Start(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (invertedImageLoader, atlasImageLoader, imageLoader);
|
return (invertedImageLoader, atlasImageLoader, imageLoader);
|
||||||
@ -573,7 +574,8 @@ namespace NewHorizons.Builder.Props
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Will be slow and create the cache if needed
|
// Will be slow and create the cache if needed
|
||||||
imageLoader.Start(true);
|
// Will run sequentially to ensure we don't run out of memory
|
||||||
|
imageLoader.Start(true, true);
|
||||||
|
|
||||||
return (null, null, imageLoader);
|
return (null, null, imageLoader);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,6 +72,11 @@ namespace NewHorizons.Utility.Files
|
|||||||
{
|
{
|
||||||
var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
|
var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
|
||||||
var key = GetKey(path);
|
var key = GetKey(path);
|
||||||
|
DeleteTexture(key, texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteTexture(string key, Texture2D texture)
|
||||||
|
{
|
||||||
if (_textureCache.ContainsKey(key))
|
if (_textureCache.ContainsKey(key))
|
||||||
{
|
{
|
||||||
if (_textureCache[key] == texture)
|
if (_textureCache[key] == texture)
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace NewHorizons.Utility.Files;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SlideReelAsyncImageLoader
|
public class SlideReelAsyncImageLoader
|
||||||
{
|
{
|
||||||
public List<(int index, string path)> PathsToLoad { get; private set; } = new();
|
public List<(int index, string path, bool deleteImmediately)> PathsToLoad { get; private set; } = new();
|
||||||
|
|
||||||
public class ImageLoadedEvent : UnityEvent<Texture2D, int, string> { }
|
public class ImageLoadedEvent : UnityEvent<Texture2D, int, string> { }
|
||||||
public ImageLoadedEvent imageLoadedEvent = new();
|
public ImageLoadedEvent imageLoadedEvent = new();
|
||||||
@ -31,7 +31,7 @@ public class SlideReelAsyncImageLoader
|
|||||||
private bool _started;
|
private bool _started;
|
||||||
private bool _clamp;
|
private bool _clamp;
|
||||||
|
|
||||||
public void Start(bool clamp)
|
public void Start(bool clamp, bool sequential)
|
||||||
{
|
{
|
||||||
if (_started) return;
|
if (_started) return;
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ public class SlideReelAsyncImageLoader
|
|||||||
|
|
||||||
NHLogger.LogVerbose("Loading new slide reel");
|
NHLogger.LogVerbose("Loading new slide reel");
|
||||||
imageLoadedEvent.AddListener(OnImageLoaded);
|
imageLoadedEvent.AddListener(OnImageLoaded);
|
||||||
SingletonSlideReelAsyncImageLoader.Instance.Load(this);
|
SingletonSlideReelAsyncImageLoader.Instance.Load(this, sequential);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnImageLoaded(Texture texture, int index, string originalPath)
|
private void OnImageLoaded(Texture texture, int index, string originalPath)
|
||||||
@ -60,7 +60,17 @@ public class SlideReelAsyncImageLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator DownloadTexture(string url, int index)
|
private IEnumerator DownloadTextures()
|
||||||
|
{
|
||||||
|
foreach (var (index, path, deleteImmediately) in PathsToLoad)
|
||||||
|
{
|
||||||
|
NHLogger.LogVerbose($"Loaded slide reel {index} of {PathsToLoad.Count}");
|
||||||
|
|
||||||
|
yield return DownloadTexture(path, index, deleteImmediately);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator DownloadTexture(string url, int index, bool deleteImmediately)
|
||||||
{
|
{
|
||||||
var key = ImageUtilities.GetKey(url);
|
var key = ImageUtilities.GetKey(url);
|
||||||
if (ImageUtilities.CheckCachedTexture(key, out var existingTexture))
|
if (ImageUtilities.CheckCachedTexture(key, out var existingTexture))
|
||||||
@ -107,6 +117,12 @@ public class SlideReelAsyncImageLoader
|
|||||||
|
|
||||||
var time = DateTime.Now;
|
var time = DateTime.Now;
|
||||||
imageLoadedEvent?.Invoke(texture, index, url);
|
imageLoadedEvent?.Invoke(texture, index, url);
|
||||||
|
|
||||||
|
// For when its an image loaded only to create a new cacheable image
|
||||||
|
if (deleteImmediately)
|
||||||
|
{
|
||||||
|
ImageUtilities.DeleteTexture(key, texture);
|
||||||
|
}
|
||||||
NHLogger.LogVerbose($"Slide reel event took: {(DateTime.Now - time).TotalMilliseconds}ms");
|
NHLogger.LogVerbose($"Slide reel event took: {(DateTime.Now - time).TotalMilliseconds}ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,6 +131,10 @@ public class SlideReelAsyncImageLoader
|
|||||||
{
|
{
|
||||||
public static SingletonSlideReelAsyncImageLoader Instance { get; private set; }
|
public static SingletonSlideReelAsyncImageLoader Instance { get; private set; }
|
||||||
|
|
||||||
|
private Queue<SlideReelAsyncImageLoader> _loaders = new();
|
||||||
|
|
||||||
|
private bool _isLoading;
|
||||||
|
|
||||||
public void Awake()
|
public void Awake()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
@ -124,20 +144,48 @@ public class SlideReelAsyncImageLoader
|
|||||||
private void OnSceneUnloaded(Scene _)
|
private void OnSceneUnloaded(Scene _)
|
||||||
{
|
{
|
||||||
StopAllCoroutines();
|
StopAllCoroutines();
|
||||||
|
_loaders.Clear();
|
||||||
|
_isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load(SlideReelAsyncImageLoader loader)
|
public void Load(SlideReelAsyncImageLoader loader, bool sequential)
|
||||||
{
|
{
|
||||||
// Delay at least one frame to let things subscribe to the event before it fires
|
// Delay at least one frame to let things subscribe to the event before it fires
|
||||||
Delay.FireOnNextUpdate(() =>
|
Delay.FireOnNextUpdate(() =>
|
||||||
{
|
{
|
||||||
foreach (var (index, path) in loader.PathsToLoad)
|
if (sequential)
|
||||||
|
{
|
||||||
|
// Sequential
|
||||||
|
_loaders.Enqueue(loader);
|
||||||
|
if (!_isLoading)
|
||||||
|
{
|
||||||
|
StartCoroutine(LoadAllSequential());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var (index, path, deleteImmediately) in loader.PathsToLoad)
|
||||||
{
|
{
|
||||||
NHLogger.LogVerbose($"Loaded slide reel {index} of {loader.PathsToLoad.Count}");
|
NHLogger.LogVerbose($"Loaded slide reel {index} of {loader.PathsToLoad.Count}");
|
||||||
|
|
||||||
StartCoroutine(loader.DownloadTexture(path, index));
|
StartCoroutine(loader.DownloadTexture(path, index, deleteImmediately));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerator LoadAllSequential()
|
||||||
|
{
|
||||||
|
NHLogger.Log("Loading slide reels");
|
||||||
|
_isLoading = true;
|
||||||
|
while (_loaders.Count > 0)
|
||||||
|
{
|
||||||
|
var loader = _loaders.Dequeue();
|
||||||
|
yield return loader.DownloadTextures();
|
||||||
|
NHLogger.Log($"Finished a slide reel, {_loaders.Count} left");
|
||||||
|
}
|
||||||
|
_isLoading = false;
|
||||||
|
NHLogger.Log("Done loading slide reels");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user