Skip to content

Commit 522144f

Browse files
authored
Reference DragCubeTool from ROUtils, implement caching (#27)
1 parent 380725e commit 522144f

6 files changed

Lines changed: 37 additions & 72 deletions

File tree

Source/ROLib/Modules/ModuleROSolar.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,19 @@ public void InitializeUI()
322322
prevScale = panelScale;
323323
}
324324
};
325+
325326
Fields[nameof(TechLevel)].uiControlEditor.onFieldChanged =
326327
Fields[nameof(TechLevel)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
327328
{
328329
ModelChangedHandler(true);
329330
};
330331

332+
Fields[nameof(trackingToggle)].uiControlEditor.onFieldChanged =
333+
Fields[nameof(trackingToggle)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
334+
{
335+
ModelChangedHandler(true);
336+
};
337+
331338
SetUIVisibleFields();
332339
}
333340

@@ -445,7 +452,9 @@ private void UpdateAttachNodes(bool userInput)
445452
/// <summary>
446453
/// Calls the generic ROT procedural drag-cube updating routines. Will update the drag cubes for whatever the current model state is.
447454
/// </summary>
448-
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, true);
455+
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, ShapeKey);
456+
457+
private string ShapeKey => lengthWidth ? $"ROS|{currentVariant}|{currentCore}|{panelWidth}|{panelLength}|{trackingToggle}" : $"ROS|{currentVariant}|{currentCore}|{panelScale}|{trackingToggle}";
449458

450459
#endregion Custom Update Methods
451460

Source/ROLib/Modules/ModuleROTank.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ internal void ModelChangedHandler(bool pushNodes)
292292
SetupKorolevCross();
293293
ROLStockInterop.UpdatePartHighlighting(part);
294294
//if (HighLogic.LoadedSceneIsEditor)
295-
//GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
295+
//GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
296296
}
297297

298298
internal void ModelChangedHandlerWithSymmetry(bool pushNodes, bool symmetry)
@@ -794,7 +794,16 @@ public void UpdateAvailableVariants()
794794
/// <summary>
795795
/// Calls the generic ROT procedural drag-cube updating routines. Will update the drag cubes for whatever the current model state is.
796796
/// </summary>
797-
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, true);
797+
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, ShapeKey);
798+
799+
private string ShapeKey
800+
{
801+
get
802+
{
803+
if (lengthWidth) return null;
804+
return $"ROT|{currentDiameter}|{currentCore}|{currentVScale}|{currentNose}|{currentNoseVScale}|{currentNoseRotation}|{currentMount}|{currentMountVScale}|{currentMountRotation}";
805+
}
806+
}
798807

799808
private void SetModelFromDimensions()
800809
{

Source/ROLib/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[assembly: AssemblyConfiguration("")]
1212
[assembly: AssemblyCompany("")]
1313
[assembly: AssemblyProduct("ROLib")]
14-
[assembly: AssemblyCopyright("Copyright © KSP-RO group 2022")]
14+
[assembly: AssemblyCopyright("Copyright © KSP-RO group 2025")]
1515
[assembly: AssemblyTrademark("")]
1616
[assembly: AssemblyCulture("")]
1717

@@ -33,13 +33,14 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.0.0.0")] // Don't change for every release
36+
[assembly: AssemblyVersion("2.0.0.0")] // Don't change for every release
3737
#if CIBUILD
3838
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
3939
[assembly: KSPAssembly("ROLib", @MAJOR@, @MINOR@, @PATCH@)]
4040
#else
41-
[assembly: AssemblyFileVersion("1.9.1.0")]
42-
[assembly: KSPAssembly("ROLib", 1, 9, 1)]
41+
[assembly: AssemblyFileVersion("2.0.0.0")]
42+
[assembly: KSPAssembly("ROLib", 2, 0, 0)]
4343
#endif
4444

45-
//[assembly: KSPAssemblyDependency("TexturesUnlimited", 1, 0)] // We need this to ensure correct load order but unfortunately TU doesn't define the KSPAssembly attribute. https://github.com/shadowmage45/TexturesUnlimited/issues/104
45+
[assembly: KSPAssemblyDependency("TexturesUnlimited", 1, 6)]
46+
[assembly: KSPAssemblyDependency("ROUtils", 1, 1)]

Source/ROLib/ROLib.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<Reference Include="Assembly-CSharp">
4343
<Private>False</Private>
4444
</Reference>
45+
<Reference Include="ROUtils">
46+
<Private>False</Private>
47+
</Reference>
4548
<Reference Include="System">
4649
<Private>False</Private>
4750
</Reference>
@@ -110,7 +113,6 @@
110113
<Compile Include="Properties\AssemblyInfo.cs" />
111114
<Compile Include="UI\ModelSelectionGUI.cs" />
112115
<Compile Include="UI\ModelWindow.cs" />
113-
<Compile Include="Utils\ProceduralTools\DragCubeTool.cs" />
114116
<Compile Include="Utils\ModuleDefinitionVariantSet.cs" />
115117
<Compile Include="Utils\ROLAttachNodeUtils.cs" />
116118
<Compile Include="Utils\ROLConfigNodeUtils.cs" />

Source/ROLib/Utils/ProceduralTools/DragCubeTool.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

Source/ROLib/Utils/ROLModInterop.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
2-
using UnityEngine;
2+
using System.Linq;
33
using System.Reflection;
4+
using UnityEngine;
45
using KSPShaderTools;
5-
using System.Linq;
6-
using ProceduralTools;
6+
using ROUtils;
77

88
namespace ROLib
99
{
@@ -30,21 +30,18 @@ public static void UpdateResourceVolume(Part part)
3030

3131
/// <summary>
3232
/// Updates part highlight renderer list, sends message to ModuleROTFlagDecal to update its renderer,
33-
/// sends message to FAR to update voxels, or if createDefaultCube==true will re-render the 'default' stock drag cube for the part<para/>
33+
/// sends message to FAR to update voxels
3434
/// Should be called anytime the model geometry in a part is changed -- either models added/deleted, procedural meshes updated. Other methods exist for pure drag-cube updating in ROLStockInterop.
3535
/// </summary>
3636
/// <param name="part"></param>
37-
/// <param name="createDefaultCube"></param>
38-
public static void OnPartGeometryUpdate(Part part, bool createDefaultCube)
37+
/// <param name="shapeKey">Key that uniquely idenfies the geometry of the part. Used for drag cube caching.</param>
38+
public static void OnPartGeometryUpdate(Part part, string shapeKey = null)
3939
{
4040
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { return; }//noop on prefabs
4141
ROLStockInterop.UpdatePartHighlighting(part);
4242
part.airlock = LocateAirlock(part);
4343
PartGeometryUpdate(part);
44-
if (createDefaultCube)
45-
DragCubeTool.UpdateDragCubes(part);
46-
else if (IsFARInstalled()) // DragCubeTool calls this.
47-
part.SendMessage("GeometryPartModuleRebuildMeshData");
44+
DragCubeTool.UpdateDragCubes(part, shapeKey);
4845
if (HighLogic.LoadedSceneIsEditor && part.parent == null && part != EditorLogic.RootPart) //likely the part under the cursor; this fixes problems with modular parts not wanting to attach to stuff
4946
{
5047
part.gameObject.SetLayerRecursive(1, 2097152);//1<<21 = Part Triggers get skipped by the relayering (hatches, ladders, ??)

0 commit comments

Comments
 (0)