Skip to content

Commit 1ceee56

Browse files
authored
Reference DragCubeTool from ROUtils and implement caching (#359)
1 parent be9ea40 commit 1ceee56

14 files changed

Lines changed: 41 additions & 98 deletions

Source/ProceduralAbstractShape.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ protected set
151151
}
152152
private float _length;
153153

154+
/// <summary>
155+
/// Key that will uniquely identify the geometry of the current shape.
156+
/// </summary>
157+
public abstract string ShapeKey { get; }
158+
154159
#endregion
155160

156161
#region Events

Source/ProceduralPart.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using KSPAPIExtensions;
66
using System.Reflection;
77
using UnityEngine.Profiling;
8+
using ROUtils;
89

910
namespace ProceduralParts
1011
{
@@ -596,13 +597,7 @@ public void OnPartColliderChanged()
596597
{
597598
if (!HighLogic.LoadedSceneIsEditor || updateDragCubesInEditor)
598599
{
599-
// Drag cubes should get generated immediately during the partcatalog compilation stage;
600-
// in all other cases there may need to be a delay.
601-
if (PartLoader.Instance.IsReady())
602-
ProceduralTools.DragCubeTool.UpdateDragCubes(part);
603-
else
604-
ProceduralTools.DragCubeTool.UpdateDragCubesImmediate(part);
605-
600+
DragCubeTool.UpdateDragCubes(part, CurrentShape.ShapeKey);
606601
}
607602
}
608603

Source/ProceduralParts.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
<Prefer32Bit>false</Prefer32Bit>
6666
</PropertyGroup>
6767
<ItemGroup>
68+
<Reference Include="ROUtils">
69+
<Private>False</Private>
70+
</Reference>
6871
<Reference Include="System">
6972
<Private>False</Private>
7073
</Reference>
@@ -111,7 +114,6 @@
111114
<Compile Include="ProceduralAbstractShape.cs" />
112115
<Compile Include="ProceduralPart.cs" />
113116
<Compile Include="ProceduralAbstractSoRShape.cs" />
114-
<Compile Include="ProceduralTools\DragCubeTool.cs" />
115117
<Compile Include="ProceduralTools\KSPFieldTool.cs" />
116118
<Compile Include="Properties\AssemblyInfo.cs" />
117119
<Compile Include="TankContentSwitcher.cs" />

Source/ProceduralShapeBezierCone.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ internal class ShapePreset
6666

6767
#endregion
6868

69+
public override string ShapeKey
70+
{
71+
get
72+
{
73+
string shape = selectedShape != CustomShapeName ? selectedShape : $"{shapePoints.x};{shapePoints.y};{shapePoints.z};{shapePoints.w}";
74+
return $"BCone|{topDiameter}|{bottomDiameter}|{length}|{offset}|{shape}";
75+
}
76+
}
77+
6978
#region Helper Funcs
7079

7180
internal const float MaxCircleError = 0.01f;

Source/ProceduralShapeCone.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class ProceduralShapeCone : ProceduralAbstractSoRShape
2525

2626
#endregion
2727

28+
public override string ShapeKey => $"PP-Cone|{topDiameter}|{bottomDiameter}|{length}";
29+
2830
#region Limit paramters
2931

3032
/// <summary>

Source/ProceduralShapeCylinder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class ProceduralShapeCylinder : ProceduralAbstractSoRShape
1818

1919
#endregion
2020

21+
public override string ShapeKey => $"PP-Cyl|{diameter}|{length}";
22+
2123
#region Initialization
2224

2325
public override void OnStart(StartState state)

Source/ProceduralShapeHollowCone.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ProceduralParts
99
class ProceduralShapeHollowCone : ProceduralAbstractShape
1010
{
1111
private const string ModTag = "[ProceduralShapeHollowCone]";
12-
public override Vector3 CoMOffset => CoMOffset_internal();
12+
private const float maxError = 0.0125f;
1313

1414
#region Config parameters
1515

@@ -39,8 +39,6 @@ class ProceduralShapeHollowCone : ProceduralAbstractShape
3939
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
4040
public float length = 1f;
4141

42-
private const float maxError = 0.0125f;
43-
4442
public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt((Math.Max(bottomOuterDiameter, topOuterDiameter)))/(2f * maxError)), 24);
4543

4644
[KSPField]
@@ -53,6 +51,9 @@ class ProceduralShapeHollowCone : ProceduralAbstractShape
5351

5452
#region Utility Properties
5553

54+
public override Vector3 CoMOffset => CoMOffset_internal();
55+
public override string ShapeKey => $"PP-HCone|{topOuterDiameter}|{topInnerDiameter}|{bottomOuterDiameter}|{bottomInnerDiameter}|{length}";
56+
5657
private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
5758
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);
5859

Source/ProceduralShapeHollowCylinder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ProceduralParts
99
class ProceduralShapeHollowCylinder : ProceduralAbstractShape
1010
{
1111
private const string ModTag = "[ProceduralShapeHollowCylinder]";
12+
private const float maxError = 0.0125f;
1213

1314
#region Config parameters
1415

@@ -27,8 +28,6 @@ class ProceduralShapeHollowCylinder : ProceduralAbstractShape
2728
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
2829
public float length = 1f;
2930

30-
private const float maxError = 0.0125f;
31-
3231
public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt(outerDiameter)/(2f * maxError)), 24);
3332

3433
[KSPField]
@@ -41,6 +40,8 @@ class ProceduralShapeHollowCylinder : ProceduralAbstractShape
4140

4241
#region Utility Properties
4342

43+
public override string ShapeKey => $"PP-HCyl|{outerDiameter}|{innerDiameter}|{length}";
44+
4445
private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
4546
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);
4647

Source/ProceduralShapeHollowPill.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace ProceduralParts
1212
class ProceduralShapeHollowPill : ProceduralAbstractShape
1313
{
1414
private const string ModTag = "[ProceduralShapeHollowPill]";
15+
private const float maxError = 0.0125f;
1516

1617
[KSPField(guiActiveEditor = true, guiName = "Diameters", groupName = ProceduralPart.PAWGroupName)]
1718
private string diamTitleString = "";
@@ -32,8 +33,6 @@ class ProceduralShapeHollowPill : ProceduralAbstractShape
3233
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit="m", useSI = true)]
3334
public float fillet = 0f;
3435

35-
private const float maxError = 0.0125f;
36-
3736
public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt(outerDiameter)/(2f * maxError)), 24);
3837

3938
public float MajorRadius => (outerDiameter + innerDiameter) / 4;
@@ -48,6 +47,8 @@ class ProceduralShapeHollowPill : ProceduralAbstractShape
4847
private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
4948
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);
5049

50+
public override string ShapeKey => $"PP-HPill|{innerDiameter}|{outerDiameter}|{length}|{fillet}";
51+
5152
public override void OnStart(StartState state)
5253
{
5354
base.OnStart(state);

Source/ProceduralShapeHollowTruss.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ProceduralShapeHollowTruss : ProceduralAbstractShape
99
{
1010
#region KSPFields
1111
private const string ModTag = "[ProceduralShapeHollowTruss]";
12+
private const float maxMeshBendError = 0.02f;
1213

1314
[KSPField(isPersistant = true, guiActiveEditor = true, guiName = "Top D", guiFormat = "F3", guiUnits = "m", groupName = ProceduralPart.PAWGroupName),
1415
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
@@ -61,10 +62,10 @@ public float RealLength
6162
return realLength;
6263
}
6364
}
64-
65-
const float maxMeshBendError = 0.02f;
6665
#endregion
6766

67+
public override string ShapeKey => $"PP-HTruss|N{nbRods}{(symmetryRods ? "S" : "")}|{topDiameter}|{bottomDiameter}|{length}|{rodDiameter}|{tiltAngle}|{offsetAngle}";
68+
6869
public override void OnStart(StartState state)
6970
{
7071
base.OnStart(state);

0 commit comments

Comments
 (0)