Files
Performance-Fish/Source/PerformanceFish/JobSystem/WorkGiver_HaulOptimization.cs
T
bbradson 949bde76ce Mainly more hauling optimizations, utilizing linked storage groups
This also adds an experimental, usually slower, threaded gas grid mode and implements a workaround for the whole mod and game failing to start when opening prepatcher's mod manager with unfortunate timing
2024-02-01 19:57:50 +01:00

38 lines
1.3 KiB
C#

// 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 sealed class WorkGiver_HaulOptimization : ClassWithFishPatches
{
public sealed class PotentialWorkThingsGlobal_Patch : FishPatch
{
public override List<string> IncompatibleModIDs { get; } = [PackageIDs.MULTIPLAYER];
public override string Description { get; }
= "Sorts haulables by distance before running expensive hauling calculations on them to avoid checks on "
+ "far away items";
public override MethodBase TargetMethodInfo { get; }
= AccessTools.Method(typeof(WorkGiver_Haul), nameof(WorkGiver_Haul.PotentialWorkThingsGlobal));
public static IEnumerable<Thing> Postfix(IEnumerable<Thing> __result, Pawn? pawn)
{
if (pawn != null && __result is List<Thing> list)
Sort(list, pawn);
return __result;
}
private static void Sort(List<Thing> list, Pawn pawn)
{
((ThingPositionComparer)_comparer.Target).rootCell = pawn.Position;
list.Sort(_comparer);
}
private static Comparison<Thing> _comparer = new ThingPositionComparer().Compare;
}
}