mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix some checks, unload all when shiplogslideprojector says to, maybe fix vision torches
This commit is contained in:
parent
a3f2f9fd8c
commit
691cd8b096
@ -156,11 +156,11 @@ 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];
|
||||||
|
|
||||||
// Don't load inverted images if the cache exists, in this case we only load when actively displaying stuff
|
// Slide reels dynamically load the inverted cached images when needed. We only need to load raw images to generate the cache or atlases
|
||||||
var (invImageLoader, atlasImageLoader, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection, !CacheExists(mod), true, false);
|
var (_, atlasImageLoader, imageLoader) = StartAsyncLoader(mod, info.slides, ref slideCollection, false, true, false);
|
||||||
|
|
||||||
// If the cache doesn't exist it will be created here, slide reels only use the base image loader for cache creation so delete the images after to free memory
|
// If the cache doesn't exist it will be created here, slide reels only use the base image loader for cache creation so delete the images after to free memory
|
||||||
imageLoader.deleteTexturesWhenDone = !CacheExists(mod);
|
imageLoader.deleteTexturesWhenDone = true;
|
||||||
|
|
||||||
var key = GetUniqueSlideReelID(mod, info.slides);
|
var key = GetUniqueSlideReelID(mod, info.slides);
|
||||||
|
|
||||||
@ -397,9 +397,9 @@ namespace NewHorizons.Builder.Props
|
|||||||
if (_visionTorchDetectorPrefab == null) return null;
|
if (_visionTorchDetectorPrefab == null) return null;
|
||||||
|
|
||||||
// spawn a trigger for the vision torch
|
// spawn a trigger for the vision torch
|
||||||
var g = DetailBuilder.Make(planetGO, sector, mod, _visionTorchDetectorPrefab, new DetailInfo(info) { scale = 2, rename = !string.IsNullOrEmpty(info.rename) ? info.rename : "VisionStaffDetector" });
|
var visionTorchTargetGO = DetailBuilder.Make(planetGO, sector, mod, _visionTorchDetectorPrefab, new DetailInfo(info) { scale = 2, rename = !string.IsNullOrEmpty(info.rename) ? info.rename : "VisionStaffDetector" });
|
||||||
|
|
||||||
if (g == null)
|
if (visionTorchTargetGO == null)
|
||||||
{
|
{
|
||||||
NHLogger.LogWarning($"Tried to make a vision torch target but couldn't. Do you have the DLC installed?");
|
NHLogger.LogWarning($"Tried to make a vision torch target but couldn't. Do you have the DLC installed?");
|
||||||
return null;
|
return null;
|
||||||
@ -420,17 +420,18 @@ namespace NewHorizons.Builder.Props
|
|||||||
});
|
});
|
||||||
|
|
||||||
// attach a component to store all the data for the slides that play when a vision torch scans this target
|
// attach a component to store all the data for the slides that play when a vision torch scans this target
|
||||||
var target = g.AddComponent<VisionTorchTarget>();
|
var target = visionTorchTargetGO.AddComponent<VisionTorchTarget>();
|
||||||
var slideCollectionContainer = g.AddComponent<NHSlideCollectionContainer>();
|
var slideCollectionContainer = visionTorchTargetGO.AddComponent<NHSlideCollectionContainer>();
|
||||||
|
slideCollectionContainer.doAsyncLoading = false;
|
||||||
slideCollectionContainer.slideCollection = slideCollection;
|
slideCollectionContainer.slideCollection = slideCollection;
|
||||||
target.slideCollection = g.AddComponent<MindSlideCollection>();
|
target.slideCollection = visionTorchTargetGO.AddComponent<MindSlideCollection>();
|
||||||
target.slideCollection._slideCollectionContainer = slideCollectionContainer;
|
target.slideCollection._slideCollectionContainer = slideCollectionContainer;
|
||||||
|
|
||||||
LinkShipLogFacts(info, slideCollectionContainer);
|
LinkShipLogFacts(info, slideCollectionContainer);
|
||||||
|
|
||||||
g.SetActive(true);
|
visionTorchTargetGO.SetActive(true);
|
||||||
|
|
||||||
return g;
|
return visionTorchTargetGO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameObject MakeStandingVisionTorch(GameObject planetGO, Sector sector, ProjectionInfo info, IModBehaviour mod)
|
public static GameObject MakeStandingVisionTorch(GameObject planetGO, Sector sector, ProjectionInfo info, IModBehaviour mod)
|
||||||
@ -489,6 +490,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
// Set up the containers for the slides
|
// Set up the containers for the slides
|
||||||
var slideCollectionContainer = standingTorch.AddComponent<NHSlideCollectionContainer>();
|
var slideCollectionContainer = standingTorch.AddComponent<NHSlideCollectionContainer>();
|
||||||
|
slideCollectionContainer.doAsyncLoading = false;
|
||||||
slideCollectionContainer.slideCollection = slideCollection;
|
slideCollectionContainer.slideCollection = slideCollection;
|
||||||
|
|
||||||
var mindSlideCollection = standingTorch.AddComponent<MindSlideCollection>();
|
var mindSlideCollection = standingTorch.AddComponent<MindSlideCollection>();
|
||||||
@ -550,7 +552,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
// 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(Main.Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/inverted_blank_slide_reel.png")));
|
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/inverted_blank_slide_reel.png")));
|
||||||
}
|
}
|
||||||
else
|
else if (!cacheExists || loadRawImages)
|
||||||
{
|
{
|
||||||
// Used to then make cached stuff
|
// Used to then make cached stuff
|
||||||
imageLoader.PathsToLoad.Add((i, Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/blank_slide_reel.png")));
|
imageLoader.PathsToLoad.Add((i, Path.Combine(Main.Instance.ModHelper.Manifest.ModFolderPath, "Assets/textures/blank_slide_reel.png")));
|
||||||
@ -587,7 +589,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
invertedImageLoader.Start(true, false);
|
invertedImageLoader.Start(true, false);
|
||||||
}
|
}
|
||||||
else
|
if (loadRawImages)
|
||||||
{
|
{
|
||||||
imageLoader.Start(true, false);
|
imageLoader.Start(true, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
{
|
{
|
||||||
public string[] conditionsToSet;
|
public string[] conditionsToSet;
|
||||||
public string[] persistentConditionsToSet;
|
public string[] persistentConditionsToSet;
|
||||||
|
public bool doAsyncLoading = true;
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.Initialize))]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.Initialize))]
|
||||||
@ -68,7 +69,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.NextSlideAvailable))]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.NextSlideAvailable))]
|
||||||
public static bool SlideCollectionContainer_NextSlideAvailable(SlideCollectionContainer __instance, ref bool __result)
|
public static bool SlideCollectionContainer_NextSlideAvailable(SlideCollectionContainer __instance, ref bool __result)
|
||||||
{
|
{
|
||||||
if (__instance is NHSlideCollectionContainer container)
|
if (__instance is NHSlideCollectionContainer container && container.doAsyncLoading)
|
||||||
{
|
{
|
||||||
__result = (container.slideCollection as NHSlideCollection).IsSlideLoaded(container.slideIndex + 1);
|
__result = (container.slideCollection as NHSlideCollection).IsSlideLoaded(container.slideIndex + 1);
|
||||||
return false;
|
return false;
|
||||||
@ -84,7 +85,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.PrevSlideAvailable))]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.PrevSlideAvailable))]
|
||||||
public static bool SlideCollectionContainer_PrevSlideAvailable(SlideCollectionContainer __instance, ref bool __result)
|
public static bool SlideCollectionContainer_PrevSlideAvailable(SlideCollectionContainer __instance, ref bool __result)
|
||||||
{
|
{
|
||||||
if (__instance is NHSlideCollectionContainer container)
|
if (__instance is NHSlideCollectionContainer container && container.doAsyncLoading)
|
||||||
{
|
{
|
||||||
__result = (container.slideCollection as NHSlideCollection).IsSlideLoaded(container.slideIndex - 1);
|
__result = (container.slideCollection as NHSlideCollection).IsSlideLoaded(container.slideIndex - 1);
|
||||||
return false;
|
return false;
|
||||||
@ -99,7 +100,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.UnloadStreamingTextures))]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.UnloadStreamingTextures))]
|
||||||
public static bool SlideCollectionContainer_UnloadStreamingTextures(SlideCollectionContainer __instance)
|
public static bool SlideCollectionContainer_UnloadStreamingTextures(SlideCollectionContainer __instance)
|
||||||
{
|
{
|
||||||
if (__instance is NHSlideCollectionContainer container)
|
if (__instance is NHSlideCollectionContainer container && container.doAsyncLoading)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (container.slideCollection as NHSlideCollection).slidePaths.Length; i++)
|
for (int i = 0; i < (container.slideCollection as NHSlideCollection).slidePaths.Length; i++)
|
||||||
{
|
{
|
||||||
@ -117,7 +118,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.GetStreamingTexture))]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.GetStreamingTexture))]
|
||||||
public static bool SlideCollectionContainer_GetStreamingTexture(SlideCollectionContainer __instance, int id, ref Texture __result)
|
public static bool SlideCollectionContainer_GetStreamingTexture(SlideCollectionContainer __instance, int id, ref Texture __result)
|
||||||
{
|
{
|
||||||
if (__instance is NHSlideCollectionContainer container)
|
if (__instance is NHSlideCollectionContainer container && container.doAsyncLoading)
|
||||||
{
|
{
|
||||||
__result = (container.slideCollection as NHSlideCollection).LoadSlide(id);
|
__result = (container.slideCollection as NHSlideCollection).LoadSlide(id);
|
||||||
return false;
|
return false;
|
||||||
@ -132,7 +133,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.RequestManualStreamSlides))]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.RequestManualStreamSlides))]
|
||||||
public static bool SlideCollectionContainer_RequestManualStreamSlides(SlideCollectionContainer __instance)
|
public static bool SlideCollectionContainer_RequestManualStreamSlides(SlideCollectionContainer __instance)
|
||||||
{
|
{
|
||||||
if (__instance is NHSlideCollectionContainer container)
|
if (__instance is NHSlideCollectionContainer container && container.doAsyncLoading)
|
||||||
{
|
{
|
||||||
(container.slideCollection as NHSlideCollection).LoadSlide(__instance._currentSlideIndex);
|
(container.slideCollection as NHSlideCollection).LoadSlide(__instance._currentSlideIndex);
|
||||||
return false;
|
return false;
|
||||||
@ -147,7 +148,7 @@ public class NHSlideCollectionContainer : SlideCollectionContainer
|
|||||||
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.streamingTexturesAvailable), MethodType.Getter)]
|
[HarmonyPatch(typeof(SlideCollectionContainer), nameof(SlideCollectionContainer.streamingTexturesAvailable), MethodType.Getter)]
|
||||||
public static bool SlideCollectionContainer_streamingTexturesAvailable(SlideCollectionContainer __instance, ref bool __result)
|
public static bool SlideCollectionContainer_streamingTexturesAvailable(SlideCollectionContainer __instance, ref bool __result)
|
||||||
{
|
{
|
||||||
if (__instance is NHSlideCollectionContainer container)
|
if (__instance is NHSlideCollectionContainer container && container.doAsyncLoading)
|
||||||
{
|
{
|
||||||
__result = (container.slideCollection as NHSlideCollection).slidePaths != null && (container.slideCollection as NHSlideCollection).slidePaths.Any();
|
__result = (container.slideCollection as NHSlideCollection).slidePaths != null && (container.slideCollection as NHSlideCollection).slidePaths.Any();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -18,4 +18,20 @@ public static class ShipLogSlideReelPatches
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(ShipLogSlideProjector), nameof(ShipLogSlideProjector.UnloadCurrentStreamingTextures))]
|
||||||
|
public static bool ShipLogSlideProjector_UnloadCurrentStreamingTextures(ShipLogSlideProjector __instance)
|
||||||
|
{
|
||||||
|
if (__instance._collectionIndex >= 0 && __instance._collectionIndex < __instance._slideCollections.Count &&
|
||||||
|
__instance._slideCollections[__instance._collectionIndex] is NHSlideCollection collection)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < collection.slides.Length; i++)
|
||||||
|
{
|
||||||
|
collection.UnloadSlide(i);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ namespace NewHorizons.Utility.Files
|
|||||||
var key = GetKey(path);
|
var key = GetKey(path);
|
||||||
if (_textureCache.TryGetValue(key, out var existingTexture))
|
if (_textureCache.TryGetValue(key, out var existingTexture))
|
||||||
{
|
{
|
||||||
NHLogger.LogVerbose($"Already loaded image at path: {path}");
|
//NHLogger.LogVerbose($"Already loaded image at path: {path}");
|
||||||
return (Texture2D)existingTexture;
|
return (Texture2D)existingTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user