diff --git a/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed.cfg b/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed.cfg index aa854d2..75d9d5e 100644 --- a/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed.cfg +++ b/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed.cfg @@ -91,6 +91,7 @@ PART name = ModulePartVariants baseVariant = Ribbed50 baseDisplayName = 2-to-1 + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed_Interstage.cfg b/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed_Interstage.cfg index 9b884c5..523e939 100644 --- a/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed_Interstage.cfg +++ b/GameData/ProceduralFairings/Parts/Adapters/RSBRibbed_Interstage.cfg @@ -94,6 +94,7 @@ PART name = ModulePartVariants baseVariant = Ribbed50 baseDisplayName = 2-to-1 + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Parts/Adapters/RSBTruss.cfg b/GameData/ProceduralFairings/Parts/Adapters/RSBTruss.cfg index d860655..f1f0ea1 100644 --- a/GameData/ProceduralFairings/Parts/Adapters/RSBTruss.cfg +++ b/GameData/ProceduralFairings/Parts/Adapters/RSBTruss.cfg @@ -88,6 +88,7 @@ PART name = ModulePartVariants baseVariant = Truss50 baseDisplayName = 2-to-1 + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Parts/Adapters/RSBTruss_Interstage.cfg b/GameData/ProceduralFairings/Parts/Adapters/RSBTruss_Interstage.cfg index 65bf12f..30a0c39 100644 --- a/GameData/ProceduralFairings/Parts/Adapters/RSBTruss_Interstage.cfg +++ b/GameData/ProceduralFairings/Parts/Adapters/RSBTruss_Interstage.cfg @@ -91,6 +91,7 @@ PART name = ModulePartVariants baseVariant = Truss50 baseDisplayName = 2-to-1 + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Parts/Adapters/SSTUBase.cfg b/GameData/ProceduralFairings/Parts/Adapters/SSTUBase.cfg index 7fb150f..f71ffea 100644 --- a/GameData/ProceduralFairings/Parts/Adapters/SSTUBase.cfg +++ b/GameData/ProceduralFairings/Parts/Adapters/SSTUBase.cfg @@ -88,6 +88,7 @@ PART name = ModulePartVariants baseVariant = SSTU50 baseDisplayName = 2-to-1 + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Parts/Adapters/SSTUBase_Interstage.cfg b/GameData/ProceduralFairings/Parts/Adapters/SSTUBase_Interstage.cfg index ea20b0d..3586640 100644 --- a/GameData/ProceduralFairings/Parts/Adapters/SSTUBase_Interstage.cfg +++ b/GameData/ProceduralFairings/Parts/Adapters/SSTUBase_Interstage.cfg @@ -91,6 +91,7 @@ PART name = ModulePartVariants baseVariant = SSTU50 baseDisplayName = 2-to-1 + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Parts/Payload/base_interstage.cfg b/GameData/ProceduralFairings/Parts/Payload/base_interstage.cfg index fa3081f..dab86a1 100644 --- a/GameData/ProceduralFairings/Parts/Payload/base_interstage.cfg +++ b/GameData/ProceduralFairings/Parts/Payload/base_interstage.cfg @@ -89,6 +89,7 @@ PART MODULE { name = ModulePartVariants baseVariant = Dark + useMultipleDragCubes = false VARIANT { name = Dark diff --git a/GameData/ProceduralFairings/Parts/Payload/base_ring.cfg b/GameData/ProceduralFairings/Parts/Payload/base_ring.cfg index 436328b..68b09ec 100644 --- a/GameData/ProceduralFairings/Parts/Payload/base_ring.cfg +++ b/GameData/ProceduralFairings/Parts/Payload/base_ring.cfg @@ -70,6 +70,7 @@ PART MODULE { name = ModulePartVariants baseVariant = White + useMultipleDragCubes = false VARIANT { name = White diff --git a/GameData/ProceduralFairings/Parts/Payload/fairing_sides.cfg b/GameData/ProceduralFairings/Parts/Payload/fairing_sides.cfg index 5d6909c..58b606d 100644 --- a/GameData/ProceduralFairings/Parts/Payload/fairing_sides.cfg +++ b/GameData/ProceduralFairings/Parts/Payload/fairing_sides.cfg @@ -92,6 +92,7 @@ PART { name = ModulePartVariants baseVariant = White + useMultipleDragCubes = false VARIANT { diff --git a/GameData/ProceduralFairings/Patches/TU_NewSides.cfg b/GameData/ProceduralFairings/Patches/TU_NewSides.cfg index e12187a..4b28607 100644 --- a/GameData/ProceduralFairings/Patches/TU_NewSides.cfg +++ b/GameData/ProceduralFairings/Patches/TU_NewSides.cfg @@ -22,6 +22,7 @@ %MODULE[ModulePartVariants] { baseVariant = TexturesUnlimited + useMultipleDragCubes = false %VARIANT[TexturesUnlimited] { diff --git a/GameData/ProceduralFairings/Patches/TU_TextureSets.cfg b/GameData/ProceduralFairings/Patches/TU_TextureSets.cfg index 0abeecd..98feb17 100644 --- a/GameData/ProceduralFairings/Patches/TU_TextureSets.cfg +++ b/GameData/ProceduralFairings/Patches/TU_TextureSets.cfg @@ -579,6 +579,7 @@ KSP_TEXTURE_SET:NEEDS[TexturesUnlimited] @PART[KzResizableFairingBase]:NEEDS[TexturesUnlimited] { %MODULE[ModulePartVariants] { %baseVariant = Original + %useMultipleDragCubes = false %VARIANT[Original] { %displayName = Original diff --git a/Source/ProceduralFairings/FairingBase.cs b/Source/ProceduralFairings/FairingBase.cs index 0ebbc45..66d17a7 100644 --- a/Source/ProceduralFairings/FairingBase.cs +++ b/Source/ProceduralFairings/FairingBase.cs @@ -12,13 +12,12 @@ using TMPro; using UnityEngine; using UnityEngine.Profiling; +using ROUtils; namespace Keramzit { public class ProceduralFairingBase : PartModule, IPartCostModifier, IPartMassModifier { - protected static System.Random random; - protected int DefaultStall => HighLogic.LoadedSceneIsEditor && random != null ? random.Next(5) : 0; public const float MaxCylinderDimension = 50; protected const float verticalStep = 0.1f; public enum BaseMode { Payload, Adapter, Plate, Other } @@ -151,6 +150,7 @@ public enum BaseMode { Payload, Adapter, Plate, Other } public float CalcSideThickness() => Mode == BaseMode.Adapter ? Mathf.Min(sideThickness * Mathf.Max(baseSize, topSize), 0.25f * Mathf.Min(baseSize, topSize)) : Mode == BaseMode.Payload ? Mathf.Max(baseSize, maxFairingSize) * Mathf.Min(sideThickness, 0.25f) : 0; + public string ShapeKey => $"PF-Base|{Mode}|{baseSize}|{part.name}|{part.variants?.GetCurrentVariantIndex()}"; public ModifierChangeWhen GetModuleCostChangeWhen() => ModifierChangeWhen.FIXED; public ModifierChangeWhen GetModuleMassChangeWhen() => ModifierChangeWhen.FIXED; @@ -173,7 +173,6 @@ public override void OnLoad(ConfigNode node) public override void OnAwake() { base.OnAwake(); - random ??= new System.Random(); if (HighLogic.LoadedSceneIsEditor) { @@ -182,7 +181,7 @@ public override void OnAwake() } } - public override void OnStart (StartState state) + public override void OnStart(StartState state) { Decoupler = part.FindModuleImplementing(); if (Decoupler) @@ -200,7 +199,7 @@ public override void OnStart (StartState state) if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) return; - ProceduralTools.DragCubeTool.UpdateDragCubes(part, stall: DefaultStall); + DragCubeTool.UpdateDragCubes(part, ShapeKey); if (HighLogic.LoadedSceneIsEditor) { ConfigureTechLimits(); @@ -561,7 +560,7 @@ public void UpdateShape(bool pushAttachments) if (!HighLogic.LoadedSceneIsFlight) RecalcShape(scan); Profiler.EndSample(); - ProceduralTools.DragCubeTool.UpdateDragCubes(part, stall: DefaultStall); + DragCubeTool.UpdateDragCubes(part, ShapeKey); UpdateFairingSideDragCubes(); Profiler.EndSample(); @@ -575,7 +574,7 @@ public List GetFairingSides(Part p) => public void UpdateFairingSideDragCubes() { if (GetFairingSides(part).FirstOrDefault() is ProceduralFairingSide p) - ProceduralTools.DragCubeTool.UpdateDragCubes(p.part, symmetry: true); + DragCubeTool.UpdateDragCubes(p.part, p.ShapeKey, updateSymCounterparts: true); } public void UpdateOpen() diff --git a/Source/ProceduralFairings/FairingSide.cs b/Source/ProceduralFairings/FairingSide.cs index e52ca46..a434a34 100644 --- a/Source/ProceduralFairings/FairingSide.cs +++ b/Source/ProceduralFairings/FairingSide.cs @@ -5,6 +5,7 @@ // ================================================== using ProceduralFairings; +using ROUtils; using System; using System.Collections; using System.Collections.Generic; @@ -151,6 +152,7 @@ public class ProceduralFairingSide : PartModule, IPartCostModifier, IPartMassMod private float totalCostBase => (DecouplerEnabled ? decouplerCostBase : 0) + (hingeEnabled ? hingeCostBase : 0); private float totalMassMult => (DecouplerEnabled ? decouplerMassMult : 1) * (hingeEnabled ? hingeMassMult : 1); private float totalMassBase => (DecouplerEnabled ? decouplerMassBase : 0) + (hingeEnabled ? hingeMassBase : 0); + public string ShapeKey => usePreset ? $"PF-Side|{shapePreset}|{numSideParts}|{numSegs}|{baseRad}|{maxRad}|{cylStart}|{cylEnd}|{topRad}|{inlineHeight}|{sideThickness}" : null; [KSPEvent(active = true, guiActiveEditor = true, groupName = PFUtils.PAWGroup, guiName = "Toggle Open/Closed")] public void ToggleOpenClosed() @@ -987,10 +989,11 @@ public void rebuildMesh(bool updateDragCubes = true) } m.triangles = tri; - if (updateDragCubes) - ProceduralTools.DragCubeTool.UpdateDragCubes(part); Profiler.EndSample(); + if (updateDragCubes) + DragCubeTool.UpdateDragCubes(part, ShapeKey); + Profiler.EndSample(); } public void OnHingeEnabledChanged(BaseField f, object obj) diff --git a/Source/ProceduralFairings/ProceduralFairings.csproj b/Source/ProceduralFairings/ProceduralFairings.csproj index ed70bb1..538b9c2 100644 --- a/Source/ProceduralFairings/ProceduralFairings.csproj +++ b/Source/ProceduralFairings/ProceduralFairings.csproj @@ -39,7 +39,6 @@ 8.0 - @@ -64,6 +63,9 @@ + + False + diff --git a/Source/ProceduralFairings/ProceduralTools/DragCubeTool.cs b/Source/ProceduralFairings/ProceduralTools/DragCubeTool.cs deleted file mode 100644 index f58eaff..0000000 --- a/Source/ProceduralFairings/ProceduralTools/DragCubeTool.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System.Linq; -using UnityEngine; -using UnityEngine.Profiling; - -namespace ProceduralTools -{ - public class DragCubeTool : MonoBehaviour - { - public Part part; - private int fxLayer; - private int stall = 0; - private bool symmetry = false; - private static bool? _FARinstalled = null; - public static bool FARinstalled => _FARinstalled ??= AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "FerramAerospaceResearch"); - - public void Awake() - { - fxLayer = LayerMask.NameToLayer("TransparentFX"); - } - - public static DragCubeTool UpdateDragCubes(Part p, bool immediate = false, int stall = 0, bool symmetry = false) - { - var tool = p.GetComponent(); - if (tool == null) - { - tool = p.gameObject.AddComponent(); - tool.part = p; - tool.stall = stall; - tool.symmetry = symmetry; - if (immediate && tool.Ready()) - tool.UpdateCubes(); - } - return tool; - } - - public void FixedUpdate() - { - if (Ready()) - UpdateCubes(); - } - - public bool Ready() - { - if (HighLogic.LoadedSceneIsFlight) - return FlightGlobals.ready; //&& !part.packed && part.vessel.loaded; - if (HighLogic.LoadedSceneIsEditor) - return part.localRoot == EditorLogic.RootPart && part.gameObject.layer != fxLayer && --stall < 0; - return true; - } - - private void UpdateCubes() - { - Profiler.BeginSample("PF.DragCubeTool.UpdateCubes"); - Profiler.BeginSample("PF.DragCubeTool.FAR"); - if (FARinstalled) - part.SendMessage("GeometryPartModuleRebuildMeshData"); - Profiler.EndSample(); - Profiler.BeginSample("PF.DragCubeTool.Render"); - var dragCube = DragCubeSystem.Instance.RenderProceduralDragCube(part); - Profiler.EndSample(); - Profiler.BeginSample("PF.DragCubeTool.Complete"); - part.DragCubes.ClearCubes(); - part.DragCubes.Cubes.Add(dragCube); - part.DragCubes.ResetCubeWeights(); - part.DragCubes.ForceUpdate(true, true, false); - part.DragCubes.SetDragWeights(); - if (symmetry) - { - foreach (Part p in part.symmetryCounterparts) - { - p.DragCubes.ClearCubes(); - p.DragCubes.Cubes.Add(dragCube); - p.DragCubes.ResetCubeWeights(); - p.DragCubes.ForceUpdate(true, true, false); - p.DragCubes.SetDragWeights(); - } - } - Destroy(this); - Profiler.EndSample(); - Profiler.EndSample(); - } - } -}