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
This commit is contained in:
bbradson
2024-02-01 19:57:50 +01:00
parent 20aebe4e83
commit 949bde76ce
27 changed files with 451 additions and 280 deletions
+20
View File
@@ -0,0 +1,20 @@
// https://stackoverflow.com/a/18363848
using System.Diagnostics.CodeAnalysis;
namespace PerformanceFish.Utility;
public static class Is
{
public static bool Null<T>(T? value) where T : class => value == null;
public static bool NotNull<T>([NotNullWhen(true)] T? value) where T : class => value != null;
public static bool Null<T>(T? nullableValue) where T : struct => !nullableValue.HasValue;
public static bool NotNull<T>([NotNullWhen(true)] T? nullableValue) where T : struct => nullableValue.HasValue;
public static bool HasValue<T>([NotNullWhen(true)] T? nullableValue) where T : struct => nullableValue.HasValue;
public static bool HasNoValue<T>(T? nullableValue) where T : struct => !nullableValue.HasValue;
}
@@ -29,9 +29,29 @@ public static class MiscExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsItem(this Thing thing) => thing.def.category == ThingCategory.Item;
public static StorageSettings? TryGetGroupStoreSettings(this ISlotGroupParent slotGroupParent)
=> slotGroupParent.TryGetStorageGroup()?.GetStoreSettings();
public static StorageGroup? TryGetStorageGroup(this SlotGroup slotGroup) => slotGroup.parent.TryGetStorageGroup();
public static StorageGroup? TryGetStorageGroup(this ISlotGroupParent slotGroupParent)
=> slotGroupParent is IStorageGroupMember groupMember ? groupMember.Group : null;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Accepts(this StorageGroup storageGroup, Thing t)
=> storageGroup.GetStoreSettings().AllowedToAccept(t);
public static ISlotGroupParent? GetSlotGroupParent(this in IntVec3 position, Map map)
=> map.haulDestinationManager.SlotGroupAt(position)?.parent;
public static StorageSettings? GetThingStoreSettings(this SlotGroup slotGroup)
=> slotGroup.parent.GetThingStoreSettings();
public static StorageSettings? GetThingStoreSettings(this ISlotGroupParent slotGroupParent)
=> slotGroupParent is IStorageGroupMember groupMember
? groupMember.ThingStoreSettings
: slotGroupParent.GetStoreSettings();
public static ISlotGroupParent? StoringSlotGroupParent(this Thing thing)
=> thing.Position.GetSlotGroupParent(thing.GetMap());
@@ -0,0 +1,16 @@
// 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/.
namespace PerformanceFish.Utility;
public sealed class ThingPositionComparer : IComparer<Thing>
{
public IntVec3 rootCell;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Compare(Thing x, Thing y)
=> (x.Position - rootCell).LengthHorizontalSquared.CompareTo(
(y.Position - rootCell).LengthHorizontalSquared);
}