Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference DragCubeTool from ROUtils and implement caching #359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Source/ProceduralAbstractShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ protected set
}
private float _length;

/// <summary>
/// Key that will uniquely identify the geometry of the current shape.
/// </summary>
public abstract string ShapeKey { get; }

#endregion

#region Events
Expand Down
9 changes: 2 additions & 7 deletions Source/ProceduralPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using KSPAPIExtensions;
using System.Reflection;
using UnityEngine.Profiling;
using ROUtils;

namespace ProceduralParts
{
Expand Down Expand Up @@ -596,13 +597,7 @@ public void OnPartColliderChanged()
{
if (!HighLogic.LoadedSceneIsEditor || updateDragCubesInEditor)
{
// Drag cubes should get generated immediately during the partcatalog compilation stage;
// in all other cases there may need to be a delay.
if (PartLoader.Instance.IsReady())
ProceduralTools.DragCubeTool.UpdateDragCubes(part);
else
ProceduralTools.DragCubeTool.UpdateDragCubesImmediate(part);

DragCubeTool.UpdateDragCubes(part, CurrentShape.ShapeKey);
}
}

Expand Down
4 changes: 3 additions & 1 deletion Source/ProceduralParts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ROUtils">
<Private>False</Private>
</Reference>
<Reference Include="System">
<Private>False</Private>
</Reference>
Expand Down Expand Up @@ -111,7 +114,6 @@
<Compile Include="ProceduralAbstractShape.cs" />
<Compile Include="ProceduralPart.cs" />
<Compile Include="ProceduralAbstractSoRShape.cs" />
<Compile Include="ProceduralTools\DragCubeTool.cs" />
<Compile Include="ProceduralTools\KSPFieldTool.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TankContentSwitcher.cs" />
Expand Down
9 changes: 9 additions & 0 deletions Source/ProceduralShapeBezierCone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ internal class ShapePreset

#endregion

public override string ShapeKey
{
get
{
string shape = selectedShape != CustomShapeName ? selectedShape : $"{shapePoints.x};{shapePoints.y};{shapePoints.z};{shapePoints.w}";
return $"BCone|{topDiameter}|{bottomDiameter}|{length}|{offset}|{shape}";
}
}

#region Helper Funcs

internal const float MaxCircleError = 0.01f;
Expand Down
2 changes: 2 additions & 0 deletions Source/ProceduralShapeCone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ProceduralShapeCone : ProceduralAbstractSoRShape

#endregion

public override string ShapeKey => $"PP-Cone|{topDiameter}|{bottomDiameter}|{length}";

#region Limit paramters

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Source/ProceduralShapeCylinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ProceduralShapeCylinder : ProceduralAbstractSoRShape

#endregion

public override string ShapeKey => $"PP-Cyl|{diameter}|{length}";

#region Initialization

public override void OnStart(StartState state)
Expand Down
7 changes: 4 additions & 3 deletions Source/ProceduralShapeHollowCone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ProceduralParts
class ProceduralShapeHollowCone : ProceduralAbstractShape
{
private const string ModTag = "[ProceduralShapeHollowCone]";
public override Vector3 CoMOffset => CoMOffset_internal();
private const float maxError = 0.0125f;

#region Config parameters

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

private const float maxError = 0.0125f;

public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt((Math.Max(bottomOuterDiameter, topOuterDiameter)))/(2f * maxError)), 24);

[KSPField]
Expand All @@ -53,6 +51,9 @@ class ProceduralShapeHollowCone : ProceduralAbstractShape

#region Utility Properties

public override Vector3 CoMOffset => CoMOffset_internal();
public override string ShapeKey => $"PP-HCone|{topOuterDiameter}|{topInnerDiameter}|{bottomOuterDiameter}|{bottomInnerDiameter}|{length}";

private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);

Expand Down
5 changes: 3 additions & 2 deletions Source/ProceduralShapeHollowCylinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ProceduralParts
class ProceduralShapeHollowCylinder : ProceduralAbstractShape
{
private const string ModTag = "[ProceduralShapeHollowCylinder]";
private const float maxError = 0.0125f;

#region Config parameters

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

private const float maxError = 0.0125f;

public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt(outerDiameter)/(2f * maxError)), 24);

[KSPField]
Expand All @@ -41,6 +40,8 @@ class ProceduralShapeHollowCylinder : ProceduralAbstractShape

#region Utility Properties

public override string ShapeKey => $"PP-HCyl|{outerDiameter}|{innerDiameter}|{length}";

private float CornerCenterCornerAngle => 2 * Mathf.PI / numSides;
private float NormSideLength => Mathf.Tan(CornerCenterCornerAngle / 2);

Expand Down
5 changes: 3 additions & 2 deletions Source/ProceduralShapeHollowPill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ProceduralParts
class ProceduralShapeHollowPill : ProceduralAbstractShape
{
private const string ModTag = "[ProceduralShapeHollowPill]";
private const float maxError = 0.0125f;

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

private const float maxError = 0.0125f;

public int numSides => (int)Math.Max(Mathf.PI * Mathf.Sqrt(Mathf.Sqrt(outerDiameter)/(2f * maxError)), 24);

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

public override string ShapeKey => $"PP-HPill|{innerDiameter}|{outerDiameter}|{length}|{fillet}";

public override void OnStart(StartState state)
{
base.OnStart(state);
Expand Down
5 changes: 3 additions & 2 deletions Source/ProceduralShapeHollowTruss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ProceduralShapeHollowTruss : ProceduralAbstractShape
{
#region KSPFields
private const string ModTag = "[ProceduralShapeHollowTruss]";
private const float maxMeshBendError = 0.02f;

[KSPField(isPersistant = true, guiActiveEditor = true, guiName = "Top D", guiFormat = "F3", guiUnits = "m", groupName = ProceduralPart.PAWGroupName),
UI_FloatEdit(scene = UI_Scene.Editor, incrementSlide = SliderPrecision, sigFigs = 5, unit = "m", useSI = true)]
Expand Down Expand Up @@ -61,10 +62,10 @@ public float RealLength
return realLength;
}
}

const float maxMeshBendError = 0.02f;
#endregion

public override string ShapeKey => $"PP-HTruss|N{nbRods}{(symmetryRods ? "S" : "")}|{topDiameter}|{bottomDiameter}|{length}|{rodDiameter}|{tiltAngle}|{offsetAngle}";

public override void OnStart(StartState state)
{
base.OnStart(state);
Expand Down
2 changes: 2 additions & 0 deletions Source/ProceduralShapePill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ProceduralShapePill : ProceduralAbstractSoRShape

#endregion

public override string ShapeKey => $"PP-Pill|{diameter}|{length}|{fillet}";

#region Initialization

public override void OnStart(StartState state)
Expand Down
1 change: 1 addition & 0 deletions Source/ProceduralShapePolygon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ internal SimPart() { }
// => (0.25 * innerDIameter * innerDiameter * normSideLength * cornerCount)
}

public override string ShapeKey => $"PP-Poly|N{cornerCount}|{diameter}|{length}";
private new float Length => length;
private int CornerCount => (int)cornerCount;
private float CornerCenterCornerAngle => 2 * Mathf.PI / CornerCount;
Expand Down
81 changes: 0 additions & 81 deletions Source/ProceduralTools/DragCubeTool.cs

This file was deleted.

2 changes: 2 additions & 0 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
#else
[assembly: AssemblyFileVersion("2.99.0.0")]
#endif

[assembly: KSPAssemblyDependency("ROUtils", 1, 1)]
Loading