1.5, added stuff, fixed stuff
- mod icon - fixes for new vanilla clipping issues - GenClosest optimization improving repairing, wardening, tending jobs - caching for new ListerBuildings methods - DynamicDrawManager single threading - Type.GetFields caching - StatParts analyzer category - removed duplicate steam warning and optionally window - added exception handling for debug menu, incidentworker, Graphic_Multi, InitializeComps, making all those now log what mod broke and not cause black screens or whatever
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
#if V1_4
|
||||
using static System.Reflection.Emit.OpCodes;
|
||||
|
||||
namespace PerformanceFish.Hediffs;
|
||||
@@ -48,4 +49,5 @@ public sealed class HediffComp_PsychicHarmonizer_Bugfix : ClassWithFishPatches
|
||||
return codes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -15,6 +15,7 @@ using VisibleHediffCache
|
||||
using NotMissingPartsCache
|
||||
= PerformanceFish.Cache.ByInt<Verse.HediffSet,
|
||||
PerformanceFish.Hediffs.HediffSetCaching.NotMissingPartsCacheValue>;
|
||||
// ReSharper disable WithExpressionModifiesAllMembers
|
||||
|
||||
namespace PerformanceFish.Hediffs;
|
||||
|
||||
@@ -24,26 +25,24 @@ public sealed class HediffSetPrecaching : ClassWithFishPrepatches
|
||||
{
|
||||
public override string Description { get; }
|
||||
= "Caches results of the HediffSet.GetFirstHediffOfDef method. Impact scales with hediff count.";
|
||||
|
||||
|
||||
public override MethodBase TargetMethodBase { get; }
|
||||
= SymbolExtensions.GetMethodInfo(static ()
|
||||
=> default(HediffSet)!.GetFirstHediffOfDef(null, default));
|
||||
= AccessTools.DeclaredMethod(typeof(HediffSet), nameof(HediffSet.GetFirstHediffOfDef));
|
||||
|
||||
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||
=> ilProcessor.ReplaceBodyWith(Replacement);
|
||||
|
||||
public static Hediff? Replacement(HediffSet instance, HediffDef? def, bool mustBeVisible)
|
||||
{
|
||||
var canCache = true;
|
||||
bool canCache;
|
||||
|
||||
if (instance.hediffs.Count >= 5
|
||||
&& def is not null
|
||||
// && def.GetType() == typeof(HediffDef) // different types have different indexing. Can't use those
|
||||
)
|
||||
if ((instance.hediffs.Count >= 5) & def is not null)
|
||||
{
|
||||
ref var cache = ref GetCacheValue(instance, def, mustBeVisible);
|
||||
ref var cache = ref GetCacheValue(instance, def!, mustBeVisible);
|
||||
if (!cache.Dirty)
|
||||
return cache.Hediff;
|
||||
|
||||
canCache = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -75,7 +74,7 @@ public sealed class HediffSetPrecaching : ClassWithFishPrepatches
|
||||
public static unsafe ref HediffSetCaching.HediffCacheValue GetCacheValue(HediffSet instance, HediffDef def,
|
||||
bool mustBeVisible)
|
||||
{
|
||||
var key = new HediffCache { First = instance.pawn.thingIDNumber, Second = def.shortHash };
|
||||
var key = default(HediffCache) with { First = instance.pawn.thingIDNumber, Second = def.shortHash };
|
||||
ref var cache = ref mustBeVisible
|
||||
? ref Unsafe.As<HediffSetCaching.VisibleHediffCacheValue, HediffSetCaching.HediffCacheValue>(
|
||||
ref VisibleHediffCache.GetOrAddReference(Unsafe.As<HediffCache, VisibleHediffCache>(ref key)))
|
||||
@@ -98,10 +97,10 @@ public sealed class HediffSetPrecaching : ClassWithFishPrepatches
|
||||
{
|
||||
public override string Description { get; }
|
||||
= "Caches results of the HediffSet.HasHediff method. Impact scales with hediff count.";
|
||||
|
||||
|
||||
public override MethodBase TargetMethodBase { get; }
|
||||
= SymbolExtensions.GetMethodInfo(static ()
|
||||
=> default(HediffSet)!.HasHediff(null, default));
|
||||
= AccessTools.DeclaredMethod(typeof(HediffSet), nameof(HediffSet.HasHediff),
|
||||
[typeof(HediffDef), typeof(bool)]);
|
||||
|
||||
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||
=> ilProcessor.ReplaceBodyWith(Replacement);
|
||||
@@ -117,7 +116,7 @@ public sealed class HediffSetPrecaching : ClassWithFishPrepatches
|
||||
= "Caches results of the HediffSet.GetNotMissingParts method. Impact scales with hediff count.";
|
||||
|
||||
public override MethodBase TargetMethodBase { get; }
|
||||
= AccessTools.Method(typeof(HediffSet), nameof(HediffSet.GetNotMissingParts));
|
||||
= AccessTools.DeclaredMethod(typeof(HediffSet), nameof(HediffSet.GetNotMissingParts));
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool Prefix(HediffSet __instance, BodyPartHeight height, BodyPartDepth depth, BodyPartTagDef? tag,
|
||||
@@ -160,11 +159,14 @@ public sealed class HediffSetCaching : ClassWithFishPatches
|
||||
{
|
||||
public sealed class DirtyCache : FishPatch
|
||||
{
|
||||
public override List<Type> LinkedPatches { get; }
|
||||
= [typeof(Pawn_PsychicEntropyTrackerOptimization.Psylink_Patch)];
|
||||
|
||||
public override string Description { get; }
|
||||
= "Patched to trigger psylink cache clearing for the psychic entropy optimization.";
|
||||
= "Patched to trigger psylink cache clearing for the psychic entropy optimization";
|
||||
|
||||
public override MethodBase TargetMethodInfo { get; }
|
||||
= AccessTools.Method(typeof(HediffSet), nameof(HediffSet.DirtyCache));
|
||||
= AccessTools.DeclaredMethod(typeof(HediffSet), nameof(HediffSet.DirtyCache));
|
||||
|
||||
public static void Postfix(HediffSet __instance)
|
||||
{
|
||||
@@ -175,9 +177,10 @@ public sealed class HediffSetCaching : ClassWithFishPatches
|
||||
|
||||
public record struct NotMissingPartsCacheValue()
|
||||
{
|
||||
private int _version = -1;
|
||||
private int
|
||||
_version = -1,
|
||||
_nextRefreshTick;
|
||||
private List<Hediff> _hediffsInSet = [];
|
||||
private int _nextRefreshTick;
|
||||
public List<BodyPartRecord> Parts = [];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -204,9 +207,10 @@ public sealed class HediffSetCaching : ClassWithFishPatches
|
||||
|
||||
public record struct HediffCacheValue()
|
||||
{
|
||||
private int _version = -1;
|
||||
private int
|
||||
_version = -1,
|
||||
_nextRefreshTick;
|
||||
private List<Hediff> _hediffsInSet = [];
|
||||
private int _nextRefreshTick;
|
||||
public Hediff? Hediff;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -9,7 +9,11 @@ public sealed class Pawn_PsychicEntropyTrackerOptimization : ClassWithFishPatche
|
||||
{
|
||||
public sealed class Psylink_Patch : FirstPriorityFishPatch
|
||||
{
|
||||
public override string Description { get; } = "Caches/throttles the psylink method to only update every 32 ticks.";
|
||||
public override List<Type> LinkedPatches { get; }
|
||||
= [typeof(HediffSetCaching.DirtyCache)];
|
||||
|
||||
public override string Description { get; }
|
||||
= "Caches/throttles the psylink method to only update on hediff changes or after 128 ticks";
|
||||
|
||||
public override MethodBase TargetMethodInfo { get; }
|
||||
= AccessTools.PropertyGetter(typeof(Pawn_PsychicEntropyTracker),
|
||||
@@ -22,7 +26,7 @@ public sealed class Pawn_PsychicEntropyTrackerOptimization : ClassWithFishPatche
|
||||
if (__instance.psylinkCachedForTick <= TickHelper.TicksGame)
|
||||
{
|
||||
__instance.psylinkCached = __instance.pawn.GetMainPsylinkSource();
|
||||
__instance.psylinkCachedForTick = TickHelper.TicksGame + 32;
|
||||
__instance.psylinkCachedForTick = TickHelper.TicksGame + 128;
|
||||
}
|
||||
|
||||
return __instance.psylinkCached;
|
||||
|
||||
Reference in New Issue
Block a user