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
@@ -1,43 +1,54 @@
// 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 PerformanceFish.ModCompatibility;
namespace PerformanceFish.JobSystem;
public class JobGiver_HaulOptimization : ClassWithFishPatches
{
public class PotentialWorkThingsGlobal_Patch : FishPatch
{
public override string Description => "Sorts haulables by distance before running expensive hauling calculations on them to avoid checks on far away items";
public override MethodBase TargetMethodInfo => AccessTools.Method(typeof(JobGiver_Haul), nameof(JobGiver_Haul.TryGiveJob));
public static CodeInstructions? Transpiler(CodeInstructions codes, MethodBase method)
{
var pawn_Map_listerHaulables_ThingsPotentiallyNeedingHauling = FishTranspiler.Call(() => default(ListerHaulables)!.ThingsPotentiallyNeedingHauling());
public class PotentialWorkThingsGlobal_Patch : FishPatch
{
public override string Description { get; }
= "Sorts haulables by distance before running expensive hauling calculations on them to avoid checks on "
+ "far away items";
try
{
return codes.InsertAfter(
c => c == pawn_Map_listerHaulables_ThingsPotentiallyNeedingHauling,
new CodeInstruction[]
{
FishTranspiler.Argument(method, "pawn"),
FishTranspiler.Call(SortedThingsPotentiallyNeedingHauling)
});
}
catch (Exception ex)
{
Log.Error($"{ex}");
//Log.Error("Performance Fish failed to apply its JobGiver_Haul transpiler. This particular optimization will be doing nothing now");
return null;
}
}
public static List<Thing> SortedThingsPotentiallyNeedingHauling(List<Thing> things, Pawn pawn)
{
_comparer.rootCell = pawn.Position;
things.Sort(_comparer);
return things;
}
private static WorkGiver_DoBillOptimization.ThingPositionComparer _comparer = new();
}
public override MethodBase TargetMethodInfo { get; }
= AccessTools.Method(typeof(JobGiver_Haul), nameof(JobGiver_Haul.TryGiveJob));
public static CodeInstructions? Transpiler(CodeInstructions codes, MethodBase method)
{
if (ActiveMods.Multiplayer) // PUAH has known issues with sorting and multiplayer
return codes;
var pawn_Map_listerHaulables_ThingsPotentiallyNeedingHauling
= FishTranspiler.Call(static () => default(ListerHaulables)!.ThingsPotentiallyNeedingHauling());
try
{
return codes.InsertAfter(c => c == pawn_Map_listerHaulables_ThingsPotentiallyNeedingHauling,
new CodeInstruction[]
{
FishTranspiler.Argument(method, "pawn"),
FishTranspiler.Call(SortedThingsPotentiallyNeedingHauling)
});
}
catch (Exception ex)
{
Log.Error($"{ex}");
return null;
}
}
public static List<Thing> SortedThingsPotentiallyNeedingHauling(List<Thing> things, Pawn pawn)
{
_comparer.rootCell = pawn.Position;
things.Sort(_comparer);
return things;
}
private static WorkGiver_DoBillOptimization.ThingPositionComparer _comparer = new();
}
}