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
@@ -3,8 +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/.
// crashes to desktop somehow
/*using Mono.Cecil;
using Mono.Cecil;
using Mono.Cecil.Cil;
using PerformanceFish.Prepatching;
@@ -14,37 +13,46 @@ public sealed class DefDatabasePatches : ClassWithFishPrepatches
{
public sealed class GetNamedPatch : FishPrepatch
{
public override string? Description { get; }
= "Optimizes the method with fewer instructions and faster dictionary lookup function";
public override MethodBase TargetMethodBase { get; } = methodof(DefDatabase<Def>.GetNamed);
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
=> ilProcessor.ReplaceBodyWith(GetNamed<Def>);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T? GetNamed<T>(string defName, bool errorOnFail = true) where T : Def
{
var value = DefDatabase<T>.defsByName.TryGetValue(defName);
if (errorOnFail && value is null)
LogMissingDef<T>(defName);
return value;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void LogMissingDef<T>(string defName) where T : Def
=> Log.Error($"Failed to find {typeof(T)} named {defName}. There are {
DefDatabase<T>.defsList.Count} defs of this type loaded.");
=> ilProcessor.ReplaceBodyWith(Replacement<Def>.GetNamed);
}
public sealed class GetByShortHashPatch : FishPrepatch
{
public override string? Description { get; }
= "Optimizes the method with fewer instructions and faster dictionary lookup function";
public override MethodBase TargetMethodBase { get; } = methodof(DefDatabase<Def>.GetByShortHash);
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
=> ilProcessor.ReplaceBodyWith(GetByShortHash<Def>);
=> ilProcessor.ReplaceBodyWith(Replacement<Def>.GetByShortHash);
}
public static class Replacement<T> where T : Def
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T? GetByShortHash<T>(ushort shortHash) where T : Def
public static T? GetNamed(string defName, bool errorOnFail = true)
{
var value = DefDatabase<T>.defsByName.TryGetValue(defName);
if (errorOnFail && value is null)
LogMissingDef(defName);
return value;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void LogMissingDef(string defName)
=> Log.Error($"Failed to find {typeof(T)} named '{defName}'. DefDatabase<{
typeof(T)}> contains a total of {DefDatabase<T>.defsList.Count} loaded defs.");
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T? GetByShortHash(ushort shortHash)
=> DefDatabase<T>.defsByShortHash.TryGetValue(shortHash);
}
}*/
}