Stabilize RimWorld 1.6 caches and tick optimizations

This commit is contained in:
2026-10-02 04:00:27 -04:00
parent 3199c1a85e
commit 227dcd173f
14 changed files with 209 additions and 76 deletions
@@ -16,6 +16,8 @@ public sealed class NeedsTrackerCaching : ClassWithFishPrepatches
{
public sealed class TryGetNeedPatch : FishPrepatch
{
public override bool DefaultState => true;
public override string? Description { get; }
= "Caches generic need lookups behind the needs list version.";
@@ -30,6 +32,8 @@ public sealed class NeedsTrackerCaching : ClassWithFishPrepatches
public sealed class TryGetNeedOutPatch : FishPrepatch
{
public override bool DefaultState => true;
public override string? Description { get; }
= "Caches generic need lookups behind the needs list version.";
@@ -55,18 +59,18 @@ public sealed class NeedsTrackerCaching : ClassWithFishPrepatches
return cache.Found;
}
return UpdateCache(instance, typeof(T), out need, ref cache);
return UpdateCache(instance, out need, ref cache);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool UpdateCache<T>(Pawn_NeedsTracker instance, Type needType, out T? need, ref CacheValue cache)
private static bool UpdateCache<T>(Pawn_NeedsTracker instance, out T? need, ref CacheValue cache)
where T : Need
{
var needs = instance.needs;
for (var i = 0; i < needs.Count; i++)
{
var candidate = needs[i];
if (candidate.GetType() != needType)
if (candidate.GetType() != typeof(T))
continue;
need = (T)candidate;