From dae7188dc9784753174bcdc8fd2a3c071b017739 Mon Sep 17 00:00:00 2001 From: JonnyOThan Date: Wed, 18 Jan 2023 12:20:54 -0500 Subject: [PATCH] optimize current part updating --- FreeIva/FreeIva.cs | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/FreeIva/FreeIva.cs b/FreeIva/FreeIva.cs index 8d328a87..d5cc3027 100644 --- a/FreeIva/FreeIva.cs +++ b/FreeIva/FreeIva.cs @@ -231,7 +231,7 @@ public void FixedUpdate() } public static int DepthMaskQueue = 999; - private static HashSet visibleParts = new HashSet(); + /// /// /// @@ -242,9 +242,12 @@ public static void SetRenderQueues(Part activePart) return; } + List possibleParts = new List(); Vector3 _previousCameraPosition = Vector3.zero; public void UpdateCurrentPart() { + if (KerbalIvaAddon.Instance.buckled) return; + if (InternalCamera.Instance == null) { Debug.LogError("InternalCamera was null"); @@ -261,7 +264,7 @@ public void UpdateCurrentPart() // Part colliders are larger than the parts themselves and overlap. // Find which of the containing parts we're nearest to. - List possibleParts = new List(); + possibleParts.Clear(); if (CurrentPart != null) // e.g. on part destroyed. { @@ -364,41 +367,23 @@ public void UpdateCurrentPart() public static bool PartBoundsCamera(Part p) { Profiler.BeginSample("PartBoundsCamera"); - var part = GameObjectBoundsCamera(p.gameObject); - Profiler.EndSample(); - return part; - } + bool result = false; - private static bool GameObjectBoundsCamera(GameObject go) - { - // The transform containing the mesh can be buried several levels deep. - int childCount = go.transform.childCount; - for (int i = 0; i < childCount; i++) + if (p.internalModel != null) { - Transform child = go.transform.GetChild(i); - if (child.name != "main camera pivot" && child.GetComponent() == null) + for (var ivaModule = InternalModuleFreeIva.GetForModel(p.internalModel); ivaModule != null; ivaModule = InternalModuleFreeIva.GetForModel(ivaModule.SecondaryInternalModel)) { - GameObject goc = child.gameObject; - MeshFilter[] meshc = goc.GetComponents(); - for (int m = 0; m < meshc.Length; m++) + Vector3 localPosition = ivaModule.internalModel.transform.InverseTransformPoint(InternalCamera.Instance.transform.position); + if (ivaModule.ShellColliderBounds.Contains(localPosition)) { - Bounds meshBounds = meshc[m].mesh.bounds; - if (meshBounds != null) - { - Vector3 camPos = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.position); - // Bounds are relative to the transform position, not the world. - camPos -= goc.transform.position; - - if (meshBounds.Contains(camPos)) - return true; - } + result = true; + break; } - bool foundGrandChild = GameObjectBoundsCamera(goc); - if (foundGrandChild) - return true; } } - return false; + + Profiler.EndSample(); + return result; } public static void UpdateCurrentPart(Part newCurrentPart)