Don't try to load cache for vision reels

This commit is contained in:
Nick 2024-06-17 18:06:25 -04:00
parent 50db88ecbe
commit dd05a79b1c

View File

@ -149,7 +149,7 @@ namespace NewHorizons.Builder.Props
// We can fit 16 slides max into an atlas // We can fit 16 slides max into an atlas
var textures = new Texture2D[slidesCount > 16 ? 16 : slidesCount]; var textures = new Texture2D[slidesCount > 16 ? 16 : slidesCount];
var (invImageLoader, atlasImageLoader, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection); var (invImageLoader, atlasImageLoader, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection, true);
var key = GetUniqueSlideReelID(mod, info.slides); var key = GetUniqueSlideReelID(mod, info.slides);
@ -344,7 +344,7 @@ namespace NewHorizons.Builder.Props
var slideCollection = new SlideCollection(slidesCount); var slideCollection = new SlideCollection(slidesCount);
slideCollection.streamingAssetIdentifier = string.Empty; // NREs if null slideCollection.streamingAssetIdentifier = string.Empty; // NREs if null
var (invImageLoader, _, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection); var (invImageLoader, _, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection, true);
if (invImageLoader != null) if (invImageLoader != null)
{ {
// Loaded directly from cache // Loaded directly from cache
@ -400,7 +400,7 @@ namespace NewHorizons.Builder.Props
var slideCollection = new SlideCollection(slidesCount); // TODO: uh I think that info.slides[i].playTimeDuration is not being read here... note to self for when I implement support for that: 0.7 is what to default to if playTimeDuration turns out to be 0 var slideCollection = new SlideCollection(slidesCount); // TODO: uh I think that info.slides[i].playTimeDuration is not being read here... note to self for when I implement support for that: 0.7 is what to default to if playTimeDuration turns out to be 0
slideCollection.streamingAssetIdentifier = string.Empty; // NREs if null slideCollection.streamingAssetIdentifier = string.Empty; // NREs if null
var (_, _, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection); var (_, _, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection, false);
imageLoader.imageLoadedEvent.AddListener((Texture2D tex, int index, string originalPath) => imageLoader.imageLoadedEvent.AddListener((Texture2D tex, int index, string originalPath) =>
{ {
var time = DateTime.Now; var time = DateTime.Now;
@ -453,7 +453,7 @@ namespace NewHorizons.Builder.Props
var slideCollection = new SlideCollection(slidesCount); var slideCollection = new SlideCollection(slidesCount);
slideCollection.streamingAssetIdentifier = string.Empty; // NREs if null slideCollection.streamingAssetIdentifier = string.Empty; // NREs if null
var (_, _, imageLoader) = StartAsyncLoader(mod, slides, ref slideCollection); var (_, _, imageLoader) = StartAsyncLoader(mod, slides, ref slideCollection, false);
// This variable just lets us track how many of the slides have been loaded. // This variable just lets us track how many of the slides have been loaded.
// This way as soon as the last one is loaded (due to async loading, this may be // This way as soon as the last one is loaded (due to async loading, this may be
@ -497,7 +497,7 @@ namespace NewHorizons.Builder.Props
} }
private static (SlideReelAsyncImageLoader inverted, SlideReelAsyncImageLoader atlas, SlideReelAsyncImageLoader slides) private static (SlideReelAsyncImageLoader inverted, SlideReelAsyncImageLoader atlas, SlideReelAsyncImageLoader slides)
StartAsyncLoader(IModBehaviour mod, SlideInfo[] slides, ref SlideCollection slideCollection) StartAsyncLoader(IModBehaviour mod, SlideInfo[] slides, ref SlideCollection slideCollection, bool useCache)
{ {
var invertedImageLoader = new SlideReelAsyncImageLoader(); var invertedImageLoader = new SlideReelAsyncImageLoader();
var atlasImageLoader = new SlideReelAsyncImageLoader(); var atlasImageLoader = new SlideReelAsyncImageLoader();
@ -509,7 +509,7 @@ namespace NewHorizons.Builder.Props
NHLogger.Log($"Does cache exist for slide reels? {cacheExists}"); NHLogger.Log($"Does cache exist for slide reels? {cacheExists}");
if (cacheExists) if (useCache && cacheExists)
{ {
// 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")));
@ -527,7 +527,7 @@ namespace NewHorizons.Builder.Props
} }
else else
{ {
if (cacheExists) if (useCache && 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)));
@ -540,7 +540,7 @@ namespace NewHorizons.Builder.Props
slideCollection.slides[i] = slide; slideCollection.slides[i] = slide;
} }
if (cacheExists) if (useCache && cacheExists)
{ {
// This code will execute in order to create the cache // This code will execute in order to create the cache
// Loaders go sequentually - Load the inverted textures to the cache so that ImageUtilities will reuse them later // Loaders go sequentually - Load the inverted textures to the cache so that ImageUtilities will reuse them later
@ -553,7 +553,7 @@ namespace NewHorizons.Builder.Props
} }
else else
{ {
// Will be slow and create the cache // Will be slow and create the cache if needed
imageLoader.Start(true); imageLoader.Start(true);
return (null, null, imageLoader); return (null, null, imageLoader);