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 #58

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
1 change: 1 addition & 0 deletions GameData/ProceduralFairings/Parts/Adapters/RSBRibbed.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ PART
name = ModulePartVariants
baseVariant = Ribbed50
baseDisplayName = 2-to-1
useMultipleDragCubes = false

VARIANT
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ PART
name = ModulePartVariants
baseVariant = Ribbed50
baseDisplayName = 2-to-1
useMultipleDragCubes = false

VARIANT
{
Expand Down
1 change: 1 addition & 0 deletions GameData/ProceduralFairings/Parts/Adapters/RSBTruss.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ PART
name = ModulePartVariants
baseVariant = Truss50
baseDisplayName = 2-to-1
useMultipleDragCubes = false

VARIANT
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ PART
name = ModulePartVariants
baseVariant = Truss50
baseDisplayName = 2-to-1
useMultipleDragCubes = false

VARIANT
{
Expand Down
1 change: 1 addition & 0 deletions GameData/ProceduralFairings/Parts/Adapters/SSTUBase.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ PART
name = ModulePartVariants
baseVariant = SSTU50
baseDisplayName = 2-to-1
useMultipleDragCubes = false

VARIANT
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ PART
name = ModulePartVariants
baseVariant = SSTU50
baseDisplayName = 2-to-1
useMultipleDragCubes = false

VARIANT
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ PART
MODULE {
name = ModulePartVariants
baseVariant = Dark
useMultipleDragCubes = false

VARIANT {
name = Dark
Expand Down
1 change: 1 addition & 0 deletions GameData/ProceduralFairings/Parts/Payload/base_ring.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ PART
MODULE {
name = ModulePartVariants
baseVariant = White
useMultipleDragCubes = false

VARIANT {
name = White
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ PART
{
name = ModulePartVariants
baseVariant = White
useMultipleDragCubes = false

VARIANT
{
Expand Down
1 change: 1 addition & 0 deletions GameData/ProceduralFairings/Patches/TU_NewSides.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
%MODULE[ModulePartVariants]
{
baseVariant = TexturesUnlimited
useMultipleDragCubes = false

%VARIANT[TexturesUnlimited]
{
Expand Down
1 change: 1 addition & 0 deletions GameData/ProceduralFairings/Patches/TU_TextureSets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ KSP_TEXTURE_SET:NEEDS[TexturesUnlimited]
@PART[KzResizableFairingBase]:NEEDS[TexturesUnlimited] {
%MODULE[ModulePartVariants] {
%baseVariant = Original
%useMultipleDragCubes = false

%VARIANT[Original] {
%displayName = Original
Expand Down
13 changes: 6 additions & 7 deletions Source/ProceduralFairings/FairingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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;
Expand All @@ -173,7 +173,6 @@ public override void OnLoad(ConfigNode node)
public override void OnAwake()
{
base.OnAwake();
random ??= new System.Random();

if (HighLogic.LoadedSceneIsEditor)
{
Expand All @@ -182,7 +181,7 @@ public override void OnAwake()
}
}

public override void OnStart (StartState state)
public override void OnStart(StartState state)
{
Decoupler = part.FindModuleImplementing<ModuleDecouple>();
if (Decoupler)
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -575,7 +574,7 @@ public List<ProceduralFairingSide> 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()
Expand Down
7 changes: 5 additions & 2 deletions Source/ProceduralFairings/FairingSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ==================================================

using ProceduralFairings;
using ROUtils;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Source/ProceduralFairings/ProceduralFairings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="ProceduralTools\DragCubeTool.cs" />
<Compile Include="FairingSideShapePreset.cs" />
<Compile Include="ProceduralTools\KSPFieldTool.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -64,6 +63,9 @@
</ItemDefinitionGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp" />
<Reference Include="ROUtils">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="mscorlib" />
<Reference Include="UnityEngine" />
Expand Down
83 changes: 0 additions & 83 deletions Source/ProceduralFairings/ProceduralTools/DragCubeTool.cs

This file was deleted.

Loading