Lots of new optimizations utilizing prepatcher

To start, this mod now requires Prepatcher and Fishery.
New optimizations include: gene ticking improvements, world object improvements, hediff optimizations, world pawn gc optimizations, better mothballing, dds support, ContentFinder caching, additions and changes to reflection caching, as well as various other additions. Multiplayer support has been improved too, but should be considered highly experimental. The WorkGiver_DoBill bug is fixed in this build. Multiple patches aiming to improve RimWorld's load time have been added too.
This commit is contained in:
bbradson
2023-06-03 20:24:38 +02:00
parent cb0a407425
commit ca9321add8
125 changed files with 11272 additions and 3681 deletions
+29 -23
View File
@@ -1,9 +1,11 @@
// Copyright (c) 2022 bradson
// Copyright (c) 2023 bradson
// This Source Code Form is subject to the terms of the Mozilla Public
// 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/.
using IdeoForbidsCache = PerformanceFish.Cache.ByIntRefreshable<RimWorld.CompAssignableToPawn_Bed, Verse.Pawn, PerformanceFish.ThingCompCaching.IdeoForbidsCacheValue>;
using IdeoForbidsCache
= PerformanceFish.Cache.ByInt<RimWorld.CompAssignableToPawn_Bed, Verse.Pawn,
PerformanceFish.ThingCompCaching.IdeoForbidsCacheValue>;
namespace PerformanceFish;
@@ -11,11 +13,13 @@ public class ThingCompCaching : ClassWithFishPatches
{
public class CompAssignableToPawn_Bed_Patch : FishPatch
{
public override string Description => "Caches results of CompAssignableToPawn_Bed.IdeoligionForbids";
public override MethodBase TargetMethodInfo => AccessTools.Method(typeof(CompAssignableToPawn_Bed), nameof(CompAssignableToPawn_Bed.IdeoligionForbids));
public override string Description { get; } = "Caches results of CompAssignableToPawn_Bed.IdeoligionForbids";
public override MethodBase TargetMethodInfo { get; }
= AccessTools.Method(typeof(CompAssignableToPawn_Bed), nameof(CompAssignableToPawn_Bed.IdeoligionForbids));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Prefix(CompAssignableToPawn_Bed __instance, Pawn pawn, ref bool __result, out bool __state)
public static bool Prefix(CompAssignableToPawn_Bed __instance, Pawn? pawn, ref bool __result, out bool __state)
{
if (pawn is null)
{
@@ -23,10 +27,10 @@ public class ThingCompCaching : ClassWithFishPatches
return true;
}
var key = new IdeoForbidsCache(__instance.parent.thingIDNumber, pawn.thingIDNumber);
ref var cache = ref IdeoForbidsCache.Get.TryGetReferenceUnsafe(ref key);
ref var cache
= ref IdeoForbidsCache.GetOrAddReference(new(__instance.parent.thingIDNumber, pawn.thingIDNumber));
if (Unsafe.IsNullRef(ref cache) || cache.ShouldRefreshNow)
if (cache.Dirty)
return __state = true;
__result = cache.Result;
@@ -39,11 +43,15 @@ public class ThingCompCaching : ClassWithFishPatches
if (!__state)
return;
IdeoForbidsCache.Get[new(__instance, pawn)] = new(__instance, __result, pawn);
UpdateCache(__instance, pawn, __result);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void UpdateCache(CompAssignableToPawn_Bed __instance, Pawn pawn, bool __result)
=> IdeoForbidsCache.GetExistingReference(__instance, pawn).Update(__instance, pawn, __result);
}
public struct IdeoForbidsCacheValue : Cache.IIsRefreshable<IdeoForbidsCache, IdeoForbidsCacheValue>
public record struct IdeoForbidsCacheValue
{
public bool Result;
private int _nextRefreshTick;
@@ -51,26 +59,24 @@ public class ThingCompCaching : ClassWithFishPatches
private int _directRelationsVersion;
private List<Pawn> _assignedPawns;
private List<DirectPawnRelation> _directRelations;
public IdeoForbidsCacheValue(CompAssignableToPawn_Bed comp, bool result, Pawn pawn)
public void Update(CompAssignableToPawn_Bed comp, Pawn pawn, bool result)
{
_directRelations = pawn.relations.DirectRelations;
_assignedPawns = comp.assignedPawns;
_directRelationsVersion = _directRelations.Version();
_directRelationsVersion = _directRelations._version;
Result = result;
_assignedPawnsVersion = _assignedPawns.Version();
_nextRefreshTick = Current.Game.tickManager.TicksGame + 1024 + Math.Abs(Rand.Int % 512);
_assignedPawnsVersion = _assignedPawns._version;
_nextRefreshTick = TickHelper.Add(1024, pawn.thingIDNumber);
}
public bool ShouldRefreshNow
public bool Dirty
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
=> _nextRefreshTick < Current.Game.tickManager.TicksGame
|| _assignedPawnsVersion != _assignedPawns.Version()
|| _directRelationsVersion != _directRelations.Version();
set => _nextRefreshTick = value ? 0 : Current.Game.tickManager.TicksGame + 2048 + Math.Abs(Rand.Int % 1024);
=> TickHelper.Past(_nextRefreshTick)
|| _assignedPawnsVersion != _assignedPawns._version
|| _directRelationsVersion != _directRelations._version;
}
public IdeoForbidsCacheValue SetNewValue(IdeoForbidsCache key) => throw new NotImplementedException();
}
}