From 84c3655a32b1edf9f7f0bc3e58389b8cde108d04 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 11 Sep 2023 22:42:08 -0400 Subject: [PATCH 1/7] Maybe fix ghost bird --- NewHorizons/Builder/Props/DetailBuilder.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 66c16a95..55f77152 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -339,10 +339,12 @@ namespace NewHorizons.Builder.Props component.gameObject.layer = Layer.IgnoreSun; } } - // I forget why this is here + // Else it spams a ton of NRE, happens when you try to put a non-hostile Ghostbird else if (component is GhostIK or GhostEffects) { - UnityEngine.Object.DestroyImmediate(component); + // For when somebody (pikmin) makes a Unity ghost bird + if (component.transform.parent.GetComponent() == null) + UnityEngine.Object.DestroyImmediate(component); return; } else if (component is DarkMatterVolume) From 900c7333a8fb468dfb20baf46089f5010a0a9878 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 11 Sep 2023 20:20:14 -0700 Subject: [PATCH 2/7] move around code, more comment --- NewHorizons/Builder/Props/DetailBuilder.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 55f77152..245ba6c1 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -339,14 +339,6 @@ namespace NewHorizons.Builder.Props component.gameObject.layer = Layer.IgnoreSun; } } - // Else it spams a ton of NRE, happens when you try to put a non-hostile Ghostbird - else if (component is GhostIK or GhostEffects) - { - // For when somebody (pikmin) makes a Unity ghost bird - if (component.transform.parent.GetComponent() == null) - UnityEngine.Object.DestroyImmediate(component); - return; - } else if (component is DarkMatterVolume) { var probeVisuals = component.gameObject.transform.Find("ProbeVisuals"); @@ -402,8 +394,15 @@ namespace NewHorizons.Builder.Props else if (component is Renderer renderer && component.gameObject.GetComponent() == null) renderer.enabled = true; else if(component is Shape shape) shape.enabled = true; - // If it's not a moving anglerfish make sure the anim controller is regular - else if(component is AnglerfishAnimController && component.transform.parent.GetComponent() == null) //Manual parent chain so we can find inactive + // If it's not a moving ghostbird (ie Prefab_IP_GhostBird/Ghostbird_IP_ANIM) make sure it doesnt spam NREs + // Manual parent chain so we can find inactive + else if (component is GhostIK or GhostEffects && component.transform.parent.GetComponent() == null) + { + UnityEngine.Object.DestroyImmediate(component); + } + // If it's not a moving anglerfish (ie Anglerfish_Body/Beast_Anglerfish) make sure the anim controller is regular + // Manual parent chain so we can find inactive + else if(component is AnglerfishAnimController && component.transform.parent.GetComponent() == null) { component.gameObject.AddComponent(); } From 588306f936eaf4d84b05dc0f312f15c22cf7940f Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 11 Sep 2023 23:49:03 -0400 Subject: [PATCH 3/7] Change default particle height to not NRE probably --- .../Builder/Atmosphere/EffectsBuilder.cs | 70 ++++++++++++++----- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs index e06c1800..2896619c 100644 --- a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs @@ -2,6 +2,7 @@ using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; + namespace NewHorizons.Builder.Atmosphere { public static class EffectsBuilder @@ -55,29 +56,19 @@ namespace NewHorizons.Builder.Atmosphere { InitPrefabs(); - GameObject effectsGO = new GameObject("Effects"); + var effectsGO = new GameObject("Effects"); effectsGO.SetActive(false); effectsGO.transform.parent = sector?.transform ?? planetGO.transform; effectsGO.transform.position = planetGO.transform.position; - SectorCullGroup SCG = effectsGO.AddComponent(); - SCG._sector = sector; - SCG._particleSystemSuspendMode = CullGroup.ParticleSystemSuspendMode.Stop; - SCG._occlusionCulling = false; - SCG._dynamicCullingBounds = false; - SCG._waitForStreaming = false; + var sectorCullGroup = effectsGO.AddComponent(); + sectorCullGroup._sector = sector; + sectorCullGroup._particleSystemSuspendMode = CullGroup.ParticleSystemSuspendMode.Stop; + sectorCullGroup._occlusionCulling = false; + sectorCullGroup._dynamicCullingBounds = false; + sectorCullGroup._waitForStreaming = false; - var minHeight = config.Base.surfaceSize; - if (config.HeightMap?.minHeight != null) - { - if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher - else minHeight = config.HeightMap.minHeight; - } - else if (config.Water?.size != null) minHeight = config.Water.size; - else if (config.Lava?.size != null) minHeight = config.Lava.size; - - var maxHeight = config.Atmosphere.size; - if (config.Atmosphere.clouds?.outerCloudRadius != null) maxHeight = config.Atmosphere.clouds.outerCloudRadius; + var (minHeight, maxHeight) = GetDefaultHeightRange(config); foreach (var particleField in config.ParticleFields) { @@ -130,5 +121,48 @@ namespace NewHorizons.Builder.Atmosphere _ => null, }; } + + private static (float, float) GetDefaultHeightRange(PlanetConfig config) + { + // Determining default values for min/max height + var minHeight = 0f; + + if (config.HeightMap?.minHeight != null) + { + if (config.Water?.size >= config.HeightMap.minHeight) minHeight = config.Water.size; // use sea level if its higher + else minHeight = config.HeightMap.minHeight; + } + else if (config.Water?.size != null) + { + minHeight = config.Water.size; + } + else if (config.Lava?.size != null) + { + minHeight = config.Lava.size; + } + else if (config.Base != null) + { + minHeight = config.Base.surfaceSize; + } + + var maxHeight = 100f; + if (config.Atmosphere != null) + { + if (config.Atmosphere.clouds?.outerCloudRadius != null) + { + maxHeight = config.Atmosphere.clouds.outerCloudRadius; + } + else + { + maxHeight = config.Atmosphere.size; + } + } + else if (config.Base != null) + { + maxHeight = config.Base.surfaceSize * 2f; + } + + return (minHeight, maxHeight); + } } } From d3eff8ce2a8079427c674b3ef4f8a044844b72b3 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 11 Sep 2023 23:50:09 -0400 Subject: [PATCH 4/7] Double min height instead --- NewHorizons/Builder/Atmosphere/EffectsBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs index 2896619c..b4c74b78 100644 --- a/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/EffectsBuilder.cs @@ -124,7 +124,6 @@ namespace NewHorizons.Builder.Atmosphere private static (float, float) GetDefaultHeightRange(PlanetConfig config) { - // Determining default values for min/max height var minHeight = 0f; if (config.HeightMap?.minHeight != null) @@ -146,6 +145,7 @@ namespace NewHorizons.Builder.Atmosphere } var maxHeight = 100f; + if (config.Atmosphere != null) { if (config.Atmosphere.clouds?.outerCloudRadius != null) @@ -157,9 +157,9 @@ namespace NewHorizons.Builder.Atmosphere maxHeight = config.Atmosphere.size; } } - else if (config.Base != null) + else if (minHeight != 0f) { - maxHeight = config.Base.surfaceSize * 2f; + maxHeight = minHeight * 2f; } return (minHeight, maxHeight); From ba38800450aa0d91f8c08d9ce69077079fe187e3 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 14 Sep 2023 19:33:24 -0700 Subject: [PATCH 5/7] manully clear system specific caches in reload configs --- NewHorizons/Main.cs | 1 + NewHorizons/Utility/DebugTools/DebugReload.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index facd1493..9bfef433 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -196,6 +196,7 @@ namespace NewHorizons } }; + // why is this false when called in Start if (resetTranslation) { TranslationHandler.ClearTables(); diff --git a/NewHorizons/Utility/DebugTools/DebugReload.cs b/NewHorizons/Utility/DebugTools/DebugReload.cs index af3bd938..74a6ef39 100644 --- a/NewHorizons/Utility/DebugTools/DebugReload.cs +++ b/NewHorizons/Utility/DebugTools/DebugReload.cs @@ -1,4 +1,5 @@ using NewHorizons.Handlers; +using NewHorizons.Utility.Files; using NewHorizons.Utility.OWML; using OWML.Common; using OWML.Common.Menus; @@ -48,6 +49,11 @@ namespace NewHorizons.Utility.DebugTools SearchUtilities.Find("/PauseMenu/PauseMenuManagers").GetComponent().OnSkipToNextTimeLoop(); Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem); + + NHLogger.Log($"Reloading star system {Main.Instance.CurrentStarSystem} - Clearing system-specific caches!"); + ImageUtilities.ClearCache(); + AudioUtilities.ClearCache(); + AssetBundleUtilities.ClearCache(); Main.SecondsElapsedInLoop = -1f; } From d184a28ceb547285b3d93ec9d43fb1ae7ab7e4dc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 14 Sep 2023 20:40:46 -0700 Subject: [PATCH 6/7] better log --- NewHorizons/Utility/DebugTools/DebugReload.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Utility/DebugTools/DebugReload.cs b/NewHorizons/Utility/DebugTools/DebugReload.cs index 74a6ef39..0f581ac8 100644 --- a/NewHorizons/Utility/DebugTools/DebugReload.cs +++ b/NewHorizons/Utility/DebugTools/DebugReload.cs @@ -50,7 +50,7 @@ namespace NewHorizons.Utility.DebugTools Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem); - NHLogger.Log($"Reloading star system {Main.Instance.CurrentStarSystem} - Clearing system-specific caches!"); + NHLogger.Log($"Reloading configs for star system {Main.Instance.CurrentStarSystem} - Clearing system-specific caches!"); ImageUtilities.ClearCache(); AudioUtilities.ClearCache(); AssetBundleUtilities.ClearCache(); From 7beb66606ca88d831f4829edc4422ff97419af9e Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 14 Sep 2023 20:45:25 -0700 Subject: [PATCH 7/7] force clear cache flag for less duplication --- NewHorizons/Main.cs | 6 ++++-- NewHorizons/Utility/DebugTools/DebugReload.cs | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 9bfef433..50b4e146 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -97,6 +97,7 @@ namespace NewHorizons private bool _playerAwake; public bool PlayerSpawned { get; set; } + public bool ForceClearCaches { get; set; } // for reloading configs public ShipWarpController ShipWarpController { get; private set; } @@ -196,7 +197,6 @@ namespace NewHorizons } }; - // why is this false when called in Start if (resetTranslation) { TranslationHandler.ClearTables(); @@ -289,8 +289,10 @@ namespace NewHorizons EnumUtilities.ClearCache(); // Caches of other assets only have to be cleared if we changed star systems - if (CurrentStarSystem != _previousStarSystem) + if (ForceClearCaches || CurrentStarSystem != _previousStarSystem) { + ForceClearCaches = false; + NHLogger.Log($"Changing star system from {_previousStarSystem} to {CurrentStarSystem} - Clearing system-specific caches!"); ImageUtilities.ClearCache(); AudioUtilities.ClearCache(); diff --git a/NewHorizons/Utility/DebugTools/DebugReload.cs b/NewHorizons/Utility/DebugTools/DebugReload.cs index 0f581ac8..87dc99cf 100644 --- a/NewHorizons/Utility/DebugTools/DebugReload.cs +++ b/NewHorizons/Utility/DebugTools/DebugReload.cs @@ -48,12 +48,8 @@ namespace NewHorizons.Utility.DebugTools SearchUtilities.Find("/PauseMenu/PauseMenuManagers").GetComponent().OnSkipToNextTimeLoop(); + Main.Instance.ForceClearCaches = true; Main.Instance.ChangeCurrentStarSystem(Main.Instance.CurrentStarSystem); - - NHLogger.Log($"Reloading configs for star system {Main.Instance.CurrentStarSystem} - Clearing system-specific caches!"); - ImageUtilities.ClearCache(); - AudioUtilities.ClearCache(); - AssetBundleUtilities.ClearCache(); Main.SecondsElapsedInLoop = -1f; }