Skip to content

Commit

Permalink
Use conditionalweaktable
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Dec 21, 2023
1 parent ca4b2cf commit b6edd30
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/SpaceWarp.Core/Patching/PartOwnerComponentOnFixedUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System.Runtime.CompilerServices;
using HarmonyLib;
using KSP.Sim.impl;
using SpaceWarp.API.Parts;

Expand All @@ -7,7 +8,15 @@ namespace SpaceWarp.Patching;
[HarmonyPatch]
internal class PartOwnerComponentOnFixedUpdate
{
private static Dictionary<PartOwnerComponent, bool> AlreadyCachedOwners = new();
private class ReferenceBoolean
{
internal static ReferenceBoolean TRUE = new();
internal static ReferenceBoolean FALSE = new();
public static implicit operator ReferenceBoolean(bool b) => b ? TRUE : FALSE;
public static implicit operator bool(ReferenceBoolean b) => b == TRUE;
}

private static ConditionalWeakTable<PartOwnerComponent, ReferenceBoolean> AlreadyCachedOwners = new();
[HarmonyPatch(typeof(PartOwnerComponent), "OnFixedUpdate"), HarmonyPrefix]
private static bool PerformBackgroundCalculationsForRegisteredModules(double universalTime,
double deltaUniversalTime,
Expand Down

0 comments on commit b6edd30

Please sign in to comment.