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, implement caching #27

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
11 changes: 10 additions & 1 deletion Source/ROLib/Modules/ModuleROSolar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,19 @@ public void InitializeUI()
prevScale = panelScale;
}
};

Fields[nameof(TechLevel)].uiControlEditor.onFieldChanged =
Fields[nameof(TechLevel)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
{
ModelChangedHandler(true);
};

Fields[nameof(trackingToggle)].uiControlEditor.onFieldChanged =
Fields[nameof(trackingToggle)].uiControlEditor.onSymmetryFieldChanged = (a, b) =>
{
ModelChangedHandler(true);
};

SetUIVisibleFields();
}

Expand Down Expand Up @@ -445,7 +452,9 @@ private void UpdateAttachNodes(bool userInput)
/// <summary>
/// Calls the generic ROT procedural drag-cube updating routines. Will update the drag cubes for whatever the current model state is.
/// </summary>
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, true);
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, ShapeKey);

private string ShapeKey => lengthWidth ? $"ROS|{currentVariant}|{currentCore}|{panelWidth}|{panelLength}|{trackingToggle}" : $"ROS|{currentVariant}|{currentCore}|{panelScale}|{trackingToggle}";

#endregion Custom Update Methods

Expand Down
13 changes: 11 additions & 2 deletions Source/ROLib/Modules/ModuleROTank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ internal void ModelChangedHandler(bool pushNodes)
SetupKorolevCross();
ROLStockInterop.UpdatePartHighlighting(part);
//if (HighLogic.LoadedSceneIsEditor)
//GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
//GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
}

internal void ModelChangedHandlerWithSymmetry(bool pushNodes, bool symmetry)
Expand Down Expand Up @@ -794,7 +794,16 @@ public void UpdateAvailableVariants()
/// <summary>
/// Calls the generic ROT procedural drag-cube updating routines. Will update the drag cubes for whatever the current model state is.
/// </summary>
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, true);
private void UpdateDragCubes() => ROLModInterop.OnPartGeometryUpdate(part, ShapeKey);

private string ShapeKey
{
get
{
if (lengthWidth) return null;
return $"ROT|{currentDiameter}|{currentCore}|{currentVScale}|{currentNose}|{currentNoseVScale}|{currentNoseRotation}|{currentMount}|{currentMountVScale}|{currentMountRotation}";
}
}

private void SetModelFromDimensions()
{
Expand Down
3 changes: 2 additions & 1 deletion Source/ROLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
[assembly: KSPAssembly("ROLib", 1, 9, 1)]
#endif

//[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
[assembly: KSPAssemblyDependency("TexturesUnlimited", 1, 6)]
[assembly: KSPAssemblyDependency("ROUtils", 1, 1)]
4 changes: 3 additions & 1 deletion Source/ROLib/ROLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<Reference Include="Assembly-CSharp">
<Private>False</Private>
</Reference>
<Reference Include="ROUtils">
<Private>False</Private>
</Reference>
<Reference Include="System">
<Private>False</Private>
</Reference>
Expand Down Expand Up @@ -111,7 +114,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\ModelSelectionGUI.cs" />
<Compile Include="UI\ModelWindow.cs" />
<Compile Include="Utils\ProceduralTools\DragCubeTool.cs" />
<Compile Include="Utils\ModuleDefinitionVariantSet.cs" />
<Compile Include="Utils\ROLAttachNodeUtils.cs" />
<Compile Include="Utils\ROLConfigNodeUtils.cs" />
Expand Down
53 changes: 0 additions & 53 deletions Source/ROLib/Utils/ProceduralTools/DragCubeTool.cs

This file was deleted.

17 changes: 7 additions & 10 deletions Source/ROLib/Utils/ROLModInterop.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using UnityEngine;
using System.Linq;
using System.Reflection;
using UnityEngine;
using KSPShaderTools;
using System.Linq;
using ProceduralTools;
using ROUtils;

namespace ROLib
{
Expand All @@ -30,21 +30,18 @@ public static void UpdateResourceVolume(Part part)

/// <summary>
/// Updates part highlight renderer list, sends message to ModuleROTFlagDecal to update its renderer,
/// sends message to FAR to update voxels, or if createDefaultCube==true will re-render the 'default' stock drag cube for the part<para/>
/// sends message to FAR to update voxels
/// 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.
/// </summary>
/// <param name="part"></param>
/// <param name="createDefaultCube"></param>
public static void OnPartGeometryUpdate(Part part, bool createDefaultCube)
/// <param name="shapeKey">Key that uniquely idenfies the geometry of the part. Used for drag cube caching.</param>
public static void OnPartGeometryUpdate(Part part, string shapeKey = null)
{
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { return; }//noop on prefabs
ROLStockInterop.UpdatePartHighlighting(part);
part.airlock = LocateAirlock(part);
PartGeometryUpdate(part);
if (createDefaultCube)
DragCubeTool.UpdateDragCubes(part);
else if (IsFARInstalled()) // DragCubeTool calls this.
part.SendMessage("GeometryPartModuleRebuildMeshData");
DragCubeTool.UpdateDragCubes(part, shapeKey);
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
{
part.gameObject.SetLayerRecursive(1, 2097152);//1<<21 = Part Triggers get skipped by the relayering (hatches, ladders, ??)
Expand Down
Loading