fix crashes, temp disable reflection caching, possibly reduce optimization in some areas, likely break 1.5
This commit is contained in:
@@ -3,7 +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/.
|
||||
|
||||
global using LwmCompCache = PerformanceFish.Cache.ByReference<Verse.Thing, PerformanceFish.Hauling.LwmCompCacheValue>;
|
||||
global using LwmCompCache = PerformanceFish.Cache.ByReference<Verse.ThingDef, PerformanceFish.Hauling.LwmCompCacheValue>;
|
||||
|
||||
namespace PerformanceFish.Hauling;
|
||||
|
||||
@@ -11,9 +11,9 @@ public record struct LwmCompCacheValue
|
||||
{
|
||||
public CompProperties? CompProperties;
|
||||
|
||||
public static CompProperties? TryGetLwmProps(Thing slotGroupParent)
|
||||
public static CompProperties? TryGetLwmProps(ThingDef thingDef)
|
||||
=> ModCompatibility.Types.LWM.CompProperties != null
|
||||
? slotGroupParent.def.comps?.Find(static props
|
||||
? thingDef.comps?.Find(static props
|
||||
=> props.GetType() == ModCompatibility.Types.LWM.CompProperties)
|
||||
: null;
|
||||
|
||||
@@ -35,4 +35,4 @@ public record struct LwmCompCacheValue
|
||||
=> ModCompatibility.Types.LWM.CompProperties is { } propsType
|
||||
? AccessTools.FieldRefAccess<CompProperties, int>(AccessTools.Field(propsType, name))
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
global using RimfactoryExtensionCache
|
||||
= PerformanceFish.Cache.ByReference<Verse.Thing, PerformanceFish.Hauling.RimfactoryExtensionCacheValue>;
|
||||
= PerformanceFish.Cache.ByReference<Verse.ThingDef, PerformanceFish.Hauling.RimfactoryExtensionCacheValue>;
|
||||
using RimfactoryTypes = PerformanceFish.ModCompatibility.Types.Rimfactory;
|
||||
|
||||
namespace PerformanceFish.Hauling;
|
||||
@@ -13,17 +13,17 @@ public record struct RimfactoryExtensionCacheValue
|
||||
{
|
||||
public DefModExtension? ModExtension;
|
||||
|
||||
public static DefModExtension? TryGetExtension(Thing slotGroupParent)
|
||||
public static DefModExtension? TryGetExtension(ThingDef thingDef)
|
||||
=> RimfactoryTypes.ModExtension != null
|
||||
? slotGroupParent.def.modExtensions?.Find(_extensionPredicate)
|
||||
? thingDef.modExtensions?.Find(_extensionPredicate)
|
||||
: null;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool HasExtension(Thing slotGroupParent)
|
||||
=> RimfactoryTypes.ModExtension != null && TestExtension(slotGroupParent);
|
||||
public static bool HasExtension(Thing thing)
|
||||
=> RimfactoryTypes.ModExtension != null && TestExtension(thing.def);
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static bool TestExtension(Thing slotGroupParent) => slotGroupParent.TryGetRimfactoryExtension() != null;
|
||||
private static bool TestExtension(ThingDef thingDef) => TryGetExtension(thingDef) != null;
|
||||
|
||||
static RimfactoryExtensionCacheValue() => EnsureInitialized();
|
||||
|
||||
@@ -44,4 +44,4 @@ public record struct RimfactoryExtensionCacheValue
|
||||
=> RimfactoryTypes.ModExtension is { } extensionType
|
||||
? AccessTools.FieldRefAccess<DefModExtension, int>(AccessTools.Field(extensionType, name))
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ public static class StorageExtensions
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static CompProperties? TryGetLwmCompProperties(this Thing thing)
|
||||
=> LwmCompCache.GetOrAdd(thing).CompProperties;
|
||||
=> LwmCompCache.GetOrAdd(thing.def).CompProperties;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static DefModExtension? TryGetRimfactoryExtension(this Thing thing)
|
||||
=> RimfactoryExtensionCache.GetOrAdd(thing).ModExtension;
|
||||
=> RimfactoryExtensionCache.GetOrAdd(thing.def).ModExtension;
|
||||
|
||||
public static int GetTotalSlots(this SlotGroup slotGroup) => slotGroup.GetTotalSlots(slotGroup.CellsList.Count);
|
||||
|
||||
@@ -57,4 +57,4 @@ public static class StorageExtensions
|
||||
LwmCompCacheValue.EnsureInitialized();
|
||||
RimfactoryExtensionCacheValue.EnsureInitialized();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user