From 3e6740c7239032a2ccb7efc28ba006cf892265a5 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 23 Aug 2023 13:46:54 -0400 Subject: [PATCH 1/7] Can move them but their streaming is messed up --- NewHorizons/Handlers/PlanetCreationHandler.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index d15c97a9..fb702f54 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -707,6 +707,62 @@ namespace NewHorizons.Handlers var aoName = ao.GetAstroObjectName(); var aoType = ao.GetAstroObjectType(); + // When updating orbits of the twins be sure the FocalBody is gone + if (aoName == AstroObject.Name.TowerTwin || aoName == AstroObject.Name.CaveTwin) + { + var hourglassTwinsFocal = SearchUtilities.Find("FocalBody"); + + // Have to copy the HGT sector bc it has some ruleset stuff on it we want + var clonedSectorHGT = hourglassTwinsFocal.FindChild("Sector_HGT").Instantiate().Rename("Sector_HGT"); + clonedSectorHGT.transform.parent = go.transform; + clonedSectorHGT.transform.localPosition = Vector3.zero; + clonedSectorHGT.transform.localRotation = Quaternion.identity; + var rootSector = clonedSectorHGT.GetComponent(); + + var streamingGroupGO = hourglassTwinsFocal.GetComponentInChildren().gameObject.Instantiate().Rename("StreamingGroup"); + streamingGroupGO.transform.parent = go.transform; + streamingGroupGO.transform.localPosition = Vector3.zero; + streamingGroupGO.transform.localRotation = Quaternion.identity; + + // HGT streaming group is shared between the two so we have to move it onto the individual ones + // Inefficient because being on ember twin will have ash twin assets load regardless of distance but whatever + var sectorStreaming = clonedSectorHGT.GetComponentInChildren(); + sectorStreaming._streamingGroup = streamingGroupGO.GetComponent(); + sectorStreaming.SetSector(rootSector); + + hourglassTwinsFocal.SetActive(false); + + // Remove the drift tracker since its unneeded now + Component.Destroy(go.GetComponent()); + + // Fix anything pointing to the original HGT sector + foreach (var component in ao.GetComponentsInChildren(true)) + { + if (component is ISectorGroup sectorGroup) + { + if (sectorGroup.GetSector()?._name == Sector.Name.HourglassTwins) + { + sectorGroup.SetSector(rootSector); + } + } + + if (component is SectoredMonoBehaviour behaviour) + { + if (behaviour.GetSector()?._name == Sector.Name.HourglassTwins) + { + behaviour.SetSector(rootSector); + } + } + } + + // Update the parent sector + ao.GetRootSector().SetParentSector(rootSector); + + // Take the hourglass twins shader effect controller off the focal body so it can stay active + var shaderController = hourglassTwinsFocal.GetComponentInChildren(); + if (shaderController != null) shaderController.transform.parent = null; + } + var owrb = go.GetComponent(); var im = go.GetComponent(); From eb161544555b1dcce3de29368e449544c76a1a07 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 13:08:00 -0400 Subject: [PATCH 2/7] Fix CaveTwin streaming --- NewHorizons/Handlers/PlanetCreationHandler.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index fb702f54..86962829 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -717,7 +717,7 @@ namespace NewHorizons.Handlers clonedSectorHGT.transform.parent = go.transform; clonedSectorHGT.transform.localPosition = Vector3.zero; clonedSectorHGT.transform.localRotation = Quaternion.identity; - var rootSector = clonedSectorHGT.GetComponent(); + var hgtSector = clonedSectorHGT.GetComponent(); var streamingGroupGO = hourglassTwinsFocal.GetComponentInChildren().gameObject.Instantiate().Rename("StreamingGroup"); streamingGroupGO.transform.parent = go.transform; @@ -728,7 +728,7 @@ namespace NewHorizons.Handlers // Inefficient because being on ember twin will have ash twin assets load regardless of distance but whatever var sectorStreaming = clonedSectorHGT.GetComponentInChildren(); sectorStreaming._streamingGroup = streamingGroupGO.GetComponent(); - sectorStreaming.SetSector(rootSector); + sectorStreaming.SetSector(hgtSector); hourglassTwinsFocal.SetActive(false); @@ -742,7 +742,7 @@ namespace NewHorizons.Handlers { if (sectorGroup.GetSector()?._name == Sector.Name.HourglassTwins) { - sectorGroup.SetSector(rootSector); + sectorGroup.SetSector(hgtSector); } } @@ -750,13 +750,21 @@ namespace NewHorizons.Handlers { if (behaviour.GetSector()?._name == Sector.Name.HourglassTwins) { - behaviour.SetSector(rootSector); + behaviour.SetSector(hgtSector); } } } + // Sector tweaks + if (aoName == AstroObject.Name.CaveTwin) + { + // Ember Twin hemisphere geometry only fully appears at 300 so we shrink the HGT sector to this size since it controls the proxy geometry + hgtSector.GetComponent().radius = 300; + } + + // Update the parent sector - ao.GetRootSector().SetParentSector(rootSector); + ao.GetRootSector().SetParentSector(hgtSector); // Take the hourglass twins shader effect controller off the focal body so it can stay active var shaderController = hourglassTwinsFocal.GetComponentInChildren(); From a620158907ae0d021d5438cff87b8301d1312e74 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 13:17:54 -0400 Subject: [PATCH 3/7] Get HGT streaming group more reliably --- NewHorizons/Handlers/StreamingHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index aeeb7794..c037594d 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -1,3 +1,4 @@ +using NewHorizons.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -143,7 +144,7 @@ namespace NewHorizons.Handlers { if (name is AstroObject.Name.CaveTwin or AstroObject.Name.TowerTwin) { - return GameObject.Find("FocalBody/StreamingGroup_HGT").GetComponent(); + return SearchUtilities.Find("FocalBody/StreamingGroup_HGT").GetComponent(); } else { From 0030b24750ca6b9159a93097e8ce48596349bcfb Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 16:08:03 -0400 Subject: [PATCH 4/7] Don't repeat vanilla sector fixing for moons --- NewHorizons/Main.cs | 44 ++------------------ NewHorizons/Streaming/VanillaStreamingFix.cs | 35 ++++++++++++++++ 2 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 NewHorizons/Streaming/VanillaStreamingFix.cs diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index d839410a..f5014c8e 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -15,6 +15,7 @@ using NewHorizons.OtherMods.AchievementsPlus; using NewHorizons.OtherMods.MenuFramework; using NewHorizons.OtherMods.OWRichPresence; using NewHorizons.OtherMods.VoiceActing; +using NewHorizons.Streaming; using NewHorizons.Utility; using NewHorizons.Utility.DebugTools; using NewHorizons.Utility.DebugTools.Menu; @@ -456,46 +457,9 @@ namespace NewHorizons // Sector changes (so that projection pools actually turn off proxies and cull groups on these moons) - //Fix attlerock vanilla sector components (they were set to timber hearth's sector) - var thm = SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(); - foreach (var component in thm.GetComponentsInChildren(true)) - { - if (component is ISectorGroup sectorGroup) - { - sectorGroup.SetSector(thm); - } - - if (component is SectoredMonoBehaviour behaviour) - { - behaviour.SetSector(thm); - } - } - var thm_ss_obj = new GameObject("Sector_Streaming"); - thm_ss_obj.transform.SetParent(thm.transform, false); - var thm_ss = thm_ss_obj.AddComponent(); - thm_ss._streamingGroup = SearchUtilities.Find("TimberHearth_Body/StreamingGroup_TH").GetComponent(); - thm_ss.SetSector(thm); - - - //Fix hollow's lantern vanilla sector components (they were set to brittle hollow's sector) - var vm = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(); - foreach (var component in vm.GetComponentsInChildren(true)) - { - if (component is ISectorGroup sectorGroup) - { - sectorGroup.SetSector(vm); - } - - if (component is SectoredMonoBehaviour behaviour) - { - behaviour.SetSector(vm); - } - } - var vm_ss_obj = new GameObject("Sector_Streaming"); - vm_ss_obj.transform.SetParent(vm.transform, false); - var vm_ss = vm_ss_obj.AddComponent(); - vm_ss._streamingGroup = SearchUtilities.Find("BrittleHollow_Body/StreamingGroup_BH").GetComponent(); - vm_ss.SetSector(vm); + // Fix moon vanilla sector components (they were set to their primaries' sectors) + VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(), AstroObject.Name.TimberHearth); + VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(), AstroObject.Name.TimberHearth); //Fix brittle hollow north pole projection platform var northPoleSurface = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_NorthPoleSurface").GetComponent(); diff --git a/NewHorizons/Streaming/VanillaStreamingFix.cs b/NewHorizons/Streaming/VanillaStreamingFix.cs new file mode 100644 index 00000000..b6ba2a77 --- /dev/null +++ b/NewHorizons/Streaming/VanillaStreamingFix.cs @@ -0,0 +1,35 @@ +using NewHorizons.Handlers; +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Streaming; + +internal static class VanillaStreamingFix +{ + internal static void UnparentSectorStreaming(Sector rootSector, AstroObject.Name streamingGroupName) + { + foreach (var component in rootSector.GetComponentsInChildren(true)) + { + if (component is ISectorGroup sectorGroup) + { + sectorGroup.SetSector(rootSector); + } + + if (component is SectoredMonoBehaviour behaviour) + { + behaviour.SetSector(rootSector); + } + } + var sectorStreamingObj = new GameObject("Sector_Streaming"); + sectorStreamingObj.transform.SetParent(rootSector.transform, false); + + var sectorStreaming = sectorStreamingObj.AddComponent(); + sectorStreaming._streamingGroup = StreamingHandler.GetStreamingGroup(streamingGroupName); + sectorStreaming.SetSector(rootSector); + } +} From 233bc506250a2010261a149a34ba244965fc8327 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 16:26:27 -0400 Subject: [PATCH 5/7] Fix moving the twins --- NewHorizons/Handlers/PlanetCreationHandler.cs | 54 ++++--------------- NewHorizons/Streaming/VanillaStreamingFix.cs | 24 +++++---- 2 files changed, 23 insertions(+), 55 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 86962829..e0e7fe93 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; - +using NewHorizons.Streaming; namespace NewHorizons.Handlers { @@ -717,58 +717,22 @@ namespace NewHorizons.Handlers clonedSectorHGT.transform.parent = go.transform; clonedSectorHGT.transform.localPosition = Vector3.zero; clonedSectorHGT.transform.localRotation = Quaternion.identity; - var hgtSector = clonedSectorHGT.GetComponent(); - var streamingGroupGO = hourglassTwinsFocal.GetComponentInChildren().gameObject.Instantiate().Rename("StreamingGroup"); - streamingGroupGO.transform.parent = go.transform; - streamingGroupGO.transform.localPosition = Vector3.zero; - streamingGroupGO.transform.localRotation = Quaternion.identity; + // Don't need this part + GameObject.Destroy(clonedSectorHGT.GetComponentInChildren().gameObject); - // HGT streaming group is shared between the two so we have to move it onto the individual ones - // Inefficient because being on ember twin will have ash twin assets load regardless of distance but whatever - var sectorStreaming = clonedSectorHGT.GetComponentInChildren(); - sectorStreaming._streamingGroup = streamingGroupGO.GetComponent(); - sectorStreaming.SetSector(hgtSector); + // Take the hourglass twins shader effect controller off the focal body so it can stay active + var shaderController = hourglassTwinsFocal.GetComponentInChildren(); + if (shaderController != null) shaderController.transform.parent = null; hourglassTwinsFocal.SetActive(false); // Remove the drift tracker since its unneeded now Component.Destroy(go.GetComponent()); - // Fix anything pointing to the original HGT sector - foreach (var component in ao.GetComponentsInChildren(true)) - { - if (component is ISectorGroup sectorGroup) - { - if (sectorGroup.GetSector()?._name == Sector.Name.HourglassTwins) - { - sectorGroup.SetSector(hgtSector); - } - } - - if (component is SectoredMonoBehaviour behaviour) - { - if (behaviour.GetSector()?._name == Sector.Name.HourglassTwins) - { - behaviour.SetSector(hgtSector); - } - } - } - - // Sector tweaks - if (aoName == AstroObject.Name.CaveTwin) - { - // Ember Twin hemisphere geometry only fully appears at 300 so we shrink the HGT sector to this size since it controls the proxy geometry - hgtSector.GetComponent().radius = 300; - } - - - // Update the parent sector - ao.GetRootSector().SetParentSector(hgtSector); - - // Take the hourglass twins shader effect controller off the focal body so it can stay active - var shaderController = hourglassTwinsFocal.GetComponentInChildren(); - if (shaderController != null) shaderController.transform.parent = null; + // Fix sectors + VanillaStreamingFix.UnparentSectorStreaming(ao.GetRootSector(), ao.gameObject, AstroObject.Name.HourglassTwins, Sector.Name.HourglassTwins); + ao.GetRootSector().SetParentSector(null); } var owrb = go.GetComponent(); diff --git a/NewHorizons/Streaming/VanillaStreamingFix.cs b/NewHorizons/Streaming/VanillaStreamingFix.cs index b6ba2a77..2b5b0c36 100644 --- a/NewHorizons/Streaming/VanillaStreamingFix.cs +++ b/NewHorizons/Streaming/VanillaStreamingFix.cs @@ -1,10 +1,4 @@ using NewHorizons.Handlers; -using NewHorizons.Utility; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace NewHorizons.Streaming; @@ -12,21 +6,31 @@ namespace NewHorizons.Streaming; internal static class VanillaStreamingFix { internal static void UnparentSectorStreaming(Sector rootSector, AstroObject.Name streamingGroupName) + => UnparentSectorStreaming(rootSector, rootSector.gameObject, streamingGroupName, Sector.Name.Unnamed); + + internal static void UnparentSectorStreaming(Sector rootSector, GameObject startingObject, AstroObject.Name streamingGroupName, Sector.Name originalParentSectorName) { - foreach (var component in rootSector.GetComponentsInChildren(true)) + // Set originalParentSectorName to unnamed to alter all sectors + foreach (var component in startingObject.GetComponentsInChildren(true)) { if (component is ISectorGroup sectorGroup) { - sectorGroup.SetSector(rootSector); + if (sectorGroup.GetSector()?.GetName() == originalParentSectorName || originalParentSectorName == Sector.Name.Unnamed) + { + sectorGroup.SetSector(rootSector); + } } if (component is SectoredMonoBehaviour behaviour) { - behaviour.SetSector(rootSector); + if (behaviour.GetSector()?.GetName() == originalParentSectorName || originalParentSectorName == Sector.Name.Unnamed) + { + behaviour.SetSector(rootSector); + } } } var sectorStreamingObj = new GameObject("Sector_Streaming"); - sectorStreamingObj.transform.SetParent(rootSector.transform, false); + sectorStreamingObj.transform.SetParent(startingObject.transform, false); var sectorStreaming = sectorStreamingObj.AddComponent(); sectorStreaming._streamingGroup = StreamingHandler.GetStreamingGroup(streamingGroupName); From 2816391966cd91daeac21d18815059fabf65fb58 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 16:29:28 -0400 Subject: [PATCH 6/7] cant help being a gemini --- NewHorizons/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 3d65513d..f9600c0a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -481,7 +481,7 @@ namespace NewHorizons // Fix moon vanilla sector components (they were set to their primaries' sectors) VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(), AstroObject.Name.TimberHearth); - VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(), AstroObject.Name.TimberHearth); + VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(), AstroObject.Name.BrittleHollow); //Fix brittle hollow north pole projection platform var northPoleSurface = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_NorthPoleSurface").GetComponent(); From c46caf40e85eaed7e33f968afb4cfc1c7da0ecb6 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 16:33:48 -0400 Subject: [PATCH 7/7] Don't update if its already updated --- NewHorizons/Handlers/PlanetCreationHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 31556ca6..2ff9a98b 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -747,7 +747,8 @@ namespace NewHorizons.Handlers var aoType = ao.GetAstroObjectType(); // When updating orbits of the twins be sure the FocalBody is gone - if (aoName == AstroObject.Name.TowerTwin || aoName == AstroObject.Name.CaveTwin) + // Don't do it if it's already an NHAstroObject since that means this was already done + if (ao is not NHAstroObject && (aoName == AstroObject.Name.TowerTwin || aoName == AstroObject.Name.CaveTwin)) { var hourglassTwinsFocal = SearchUtilities.Find("FocalBody");