Skip to content

Commit

Permalink
cleanup unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
andyoneal committed Nov 2, 2023
1 parent a93f38c commit 0fcaac1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 53 deletions.
35 changes: 19 additions & 16 deletions InstDysonNodeFrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ public static class InstDysonNodeFrameRenderer
private static readonly int InstIndexBuffer = Shader.PropertyToID("_InstIndexBuffer");
private static readonly int GlobalDSSunPosition = Shader.PropertyToID("_Global_DS_SunPosition");
private static readonly int GlobalDSSunPositionMap = Shader.PropertyToID("_Global_DS_SunPosition_Map");

private static readonly int CamPosition = Shader.PropertyToID("_CamPosition");
private static readonly int Scale = Shader.PropertyToID("_Scale");
private static readonly int UnityMatrixVp = Shader.PropertyToID("_UNITY_MATRIX_VP");
private static readonly int FOV = Shader.PropertyToID("_FOV");
private static readonly int LOD0IDBuffer = Shader.PropertyToID("_LOD0_ID_Buffer");
private static readonly int LOD1IDBuffer = Shader.PropertyToID("_LOD1_ID_Buffer");
private static readonly int LOD2IDBuffer = Shader.PropertyToID("_LOD2_ID_Buffer");


public static void SetupMeshes()
Expand Down Expand Up @@ -96,7 +102,8 @@ public static void SetupBuffers()
}
}
}
if(argBuffer != null) argBuffer.Release();

argBuffer?.Release();
argBuffer = new ComputeBuffer(argArr.Length, 4, ComputeBufferType.IndirectArguments);
argBuffer.SetData(argArr);
}
Expand Down Expand Up @@ -132,11 +139,7 @@ private static void rebuildInstBuffers()
{
for (int i = 0; i < 3; i++)
{
if (lodBatchBuffers[b][i] != null)
{
lodBatchBuffers[b][i].Release();
}

lodBatchBuffers[b][i]?.Release();
lodBatchBuffers[b][i] = new ComputeBuffer(bufferCount, 4, ComputeBufferType.Append);
}
}
Expand Down Expand Up @@ -215,24 +218,24 @@ public static void Render(DysonSphereSegmentRenderer dssr, ERenderPlace place, i

var batches = dssr.batches;
var instMats = dssr.instMats;
frameLODShader.SetVectorArray("_LayerRotations", layerRotations);
frameLODShader.SetVector("_CamPosition", cam.transform.position);
frameLODShader.SetFloat("_Scale", scale.x);
frameLODShader.SetVectorArray(LayerRotations, layerRotations);
frameLODShader.SetVector(CamPosition, cam.transform.position);
frameLODShader.SetFloat(Scale, scale.x);
Matrix4x4 v = cam.worldToCameraMatrix;
Matrix4x4 p = cam.projectionMatrix;
frameLODShader.SetMatrix("_UNITY_MATRIX_VP", p * v);
frameLODShader.SetMatrix(UnityMatrixVp, p * v);
float fov = cam.fieldOfView;
frameLODShader.SetFloat("_FOV", fov);
frameLODShader.SetFloat(FOV, fov);
var mpb = new MaterialPropertyBlock();
mpb.SetVectorArray(LayerRotations, layerRotations);
for (var b = 0; b < DysonSphereSegmentRenderer.totalProtoCount; b++)
{
if (batches[b] == null || batches[b].cursor <= 0) continue;
batches[b].SyncBufferData();
frameLODShader.SetBuffer(csKernelId, "_InstBuffer", batches[b].buffer);
frameLODShader.SetBuffer(csKernelId, "_LOD0_ID_Buffer", lodBatchBuffers[b][0]);
frameLODShader.SetBuffer(csKernelId, "_LOD1_ID_Buffer", lodBatchBuffers[b][1]);
frameLODShader.SetBuffer(csKernelId, "_LOD2_ID_Buffer", lodBatchBuffers[b][2]);
frameLODShader.SetBuffer(csKernelId, InstBuffer, batches[b].buffer);
frameLODShader.SetBuffer(csKernelId, LOD0IDBuffer, lodBatchBuffers[b][0]);
frameLODShader.SetBuffer(csKernelId, LOD1IDBuffer, lodBatchBuffers[b][1]);
frameLODShader.SetBuffer(csKernelId, LOD2IDBuffer, lodBatchBuffers[b][2]);
for (int i = 0; i < 3; i++)
{
lodBatchBuffers[b][i].SetCounterValue(0u);
Expand Down
16 changes: 2 additions & 14 deletions Patch_DysonShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@

namespace SphereOpt;

internal class Patch_DysonShell
internal static class Patch_DysonShell
{
[HarmonyPatch(typeof(DysonShell), "SetProtoId")]
[HarmonyPostfix]
static void DysonShell_SetProtoId(DysonShell __instance)
{
var arraySizeNeeded = __instance.polygon.Count * 3;
if (arraySizeNeeded > 256) CustomShaderManager.ApplyCustomShaderToMaterial(__instance.material, "dysonshell-max");
else if (arraySizeNeeded > 128) CustomShaderManager.ApplyCustomShaderToMaterial(__instance.material, "dysonshell-huge");
else if (arraySizeNeeded > 16) CustomShaderManager.ApplyCustomShaderToMaterial(__instance.material, "dysonshell-large");
else CustomShaderManager.ApplyCustomShaderToMaterial(__instance.material, "dysonshell-small");
}

[HarmonyPatch(typeof(DysonShell), "SetMaterialStaticVars")]
[HarmonyPrefix]
private static bool DysonShell_SetMaterialStaticVars()
{
return false;
}


[HarmonyPatch(typeof(DysonShell), "GenerateModelObjects")]
[HarmonyPostfix]
Expand Down Expand Up @@ -121,7 +109,7 @@ private static void DysonSphereSegmentRenderer_Free(DysonSphereSegmentRenderer _
instDysonShellRenderer?.Free();
SphereOpt.RemoveRenderer(__instance.dysonSphere);
}

[HarmonyPatch(typeof(DysonSphereLayer), "Free")]
[HarmonyPrefix]
private static void DysonSphereLayer_Free(DysonSphereLayer __instance)
Expand Down
4 changes: 2 additions & 2 deletions Patch_DysonSphereSegmentRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SphereOpt;

public class Patch_DysonSphereSegmentRenderer
public static class Patch_DysonSphereSegmentRenderer
{
/*[HarmonyPatch(typeof(GameCamera), "Logic")]
[HarmonyPostfix]
Expand All @@ -18,7 +18,7 @@ private static bool DSPGame_StartDemoGame(ref int index)
index = -2;
return true;
}*/

[HarmonyPatch(typeof(DysonSphereSegmentRenderer.Batch), "SetCapacity")]
[HarmonyPostfix]
public static void Batch_SetCapacity(DysonSphereSegmentRenderer.Batch __instance, int newCap)
Expand Down
2 changes: 1 addition & 1 deletion Patch_VFPreload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace SphereOpt;

internal class Patch_VFPreload
internal static class Patch_VFPreload
{
[HarmonyPatch(typeof(VFPreload), "SaveMaterial")]
[HarmonyPrefix]
Expand Down
20 changes: 0 additions & 20 deletions SphereOpt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,6 @@ private void Awake()

CustomShaderManager.InitWithBundle(Bundle);

CustomShaderManager.AddCustomShaderDesc(
"dysonshell-max",
"VF Shaders/Dyson Sphere/Dyson Shell Unlit REPLACE"
);

CustomShaderManager.AddCustomShaderDesc(
"dysonshell-small",
"VF Shaders/Dyson Sphere/Dyson Shell Unlit REPLACE Small"
);

CustomShaderManager.AddCustomShaderDesc(
"dysonshell-large",
"VF Shaders/Dyson Sphere/Dyson Shell Unlit REPLACE Large"
);

CustomShaderManager.AddCustomShaderDesc(
"dysonshell-huge",
"VF Shaders/Dyson Sphere/Dyson Shell Unlit REPLACE Huge"
);

CustomShaderManager.AddCustomShaderDesc(
"dysonshell-inst",
"VF Shaders/Dyson Sphere/Dyson Shell Unlit Instanced"
Expand Down
7 changes: 7 additions & 0 deletions SphereOpt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,6 +19,11 @@
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="DysonSphereProgram.GameLibs" Version="0.9.27.15466-r.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.7.0" />
<PackageReference Include="Roslynator.Analyzers" Version="4.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
</ItemGroup>
Expand Down

0 comments on commit 0fcaac1

Please sign in to comment.