gas grid dispersoin
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
3811986740
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
NOTE: SWAP TO THE rimworld-1.6 BRANCH BEFORE DOWNLOADING OTHERWISE IT WILL NOT WORK FOR 1.6!
|
|
||||||
# Performance Fish
|
# Performance Fish
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,89 @@ public sealed class GasGridOptimization : ClassWithFishPrepatches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if V1_6
|
||||||
|
public abstract class PackedGasPatch : FishPrepatch
|
||||||
|
{
|
||||||
|
public override bool ShowSettings => false;
|
||||||
|
public override bool Enabled
|
||||||
|
{
|
||||||
|
get => base.Enabled && Get<TickPatch>().Enabled;
|
||||||
|
set => base.Enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static uint PackedDensityAt(GasGrid grid, int index)
|
||||||
|
{
|
||||||
|
var grids = grid.ParallelGasGrids();
|
||||||
|
return ((uint)grids[3].DensityAt(index) << 24)
|
||||||
|
| ((uint)grids[2].DensityAt(index) << 16)
|
||||||
|
| ((uint)grids[1].DensityAt(index) << 8)
|
||||||
|
| grids[0].DensityAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class GetDirectIndexPatch : PackedGasPatch
|
||||||
|
{
|
||||||
|
public override MethodBase TargetMethodBase { get; }
|
||||||
|
= AccessTools.DeclaredMethod(typeof(GasGrid), nameof(GasGrid.GetDirect), [typeof(int)]);
|
||||||
|
|
||||||
|
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||||
|
=> ilProcessor.ReplaceBodyWith(ReplacementBody);
|
||||||
|
|
||||||
|
public static uint ReplacementBody(GasGrid __instance, int index)
|
||||||
|
=> PackedDensityAt(__instance, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class GetDirectCellPatch : PackedGasPatch
|
||||||
|
{
|
||||||
|
public override MethodBase TargetMethodBase { get; }
|
||||||
|
= AccessTools.DeclaredMethod(typeof(GasGrid), nameof(GasGrid.GetDirect), [typeof(IntVec3)]);
|
||||||
|
|
||||||
|
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||||
|
=> ilProcessor.ReplaceBodyWith(ReplacementBody);
|
||||||
|
|
||||||
|
public static uint ReplacementBody(GasGrid __instance, IntVec3 c)
|
||||||
|
=> PackedDensityAt(__instance, c.CellToIndex(__instance.map));
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SetPackedDirectPatch : PackedGasPatch
|
||||||
|
{
|
||||||
|
public override MethodBase TargetMethodBase { get; }
|
||||||
|
= AccessTools.DeclaredMethod(typeof(GasGrid), nameof(GasGrid.SetDirect),
|
||||||
|
[typeof(int), typeof(uint)]);
|
||||||
|
|
||||||
|
public static void Postfix(GasGrid __instance, int index)
|
||||||
|
{
|
||||||
|
var density = __instance.gasDensity[index];
|
||||||
|
SetDirectPatch.ReplacementBody(__instance, index, (byte)density, (byte)(density >> 8),
|
||||||
|
(byte)(density >> 16), (byte)(density >> 24));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ClearCellUnsafePatch : PackedGasPatch
|
||||||
|
{
|
||||||
|
public override MethodBase TargetMethodBase { get; }
|
||||||
|
= AccessTools.DeclaredMethod(typeof(GasGrid), nameof(GasGrid.ClearCellUnsafe));
|
||||||
|
|
||||||
|
public static void Postfix(GasGrid __instance, IntVec3 cell)
|
||||||
|
{
|
||||||
|
var index = cell.CellToIndex(__instance.map);
|
||||||
|
var grids = __instance.ParallelGasGrids();
|
||||||
|
for (var i = 0; i < grids.Length; i++)
|
||||||
|
grids[i].SetDirect(index, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public sealed class TickPatch : FishPrepatch
|
public sealed class TickPatch : FishPrepatch
|
||||||
{
|
{
|
||||||
public override List<Type> LinkedPatches { get; } =
|
public override List<Type> LinkedPatches { get; } =
|
||||||
[
|
[
|
||||||
typeof(SetDirectPatch),
|
typeof(SetDirectPatch),
|
||||||
#if V1_4
|
typeof(CalculateGasEffectsPatch),
|
||||||
typeof(ColorAtPatch),
|
typeof(ColorAtPatch),
|
||||||
|
#if V1_6
|
||||||
|
typeof(GetDirectIndexPatch), typeof(GetDirectCellPatch),
|
||||||
|
typeof(SetPackedDirectPatch), typeof(ClearCellUnsafePatch),
|
||||||
#endif
|
#endif
|
||||||
typeof(AddGasPatch), typeof(AnyGasAtPatch),
|
typeof(AddGasPatch), typeof(AnyGasAtPatch),
|
||||||
typeof(DensityAtPatch), typeof(Debug_ClearAllPatch), typeof(Debug_FillAllPatch),
|
typeof(DensityAtPatch), typeof(Debug_ClearAllPatch), typeof(Debug_FillAllPatch),
|
||||||
@@ -174,6 +250,35 @@ public sealed class GasGridOptimization : ClassWithFishPrepatches
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class CalculateGasEffectsPatch : FishPrepatch
|
||||||
|
{
|
||||||
|
public override bool ShowSettings => false;
|
||||||
|
public override bool Enabled
|
||||||
|
{
|
||||||
|
get => base.Enabled && Get<TickPatch>().Enabled;
|
||||||
|
set => base.Enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MethodBase TargetMethodBase { get; }
|
||||||
|
= AccessTools.PropertyGetter(typeof(GasGrid), nameof(GasGrid.CalculateGasEffects));
|
||||||
|
|
||||||
|
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
|
||||||
|
=> ilProcessor.ReplaceBodyWith(ReplacementBody);
|
||||||
|
|
||||||
|
public static bool ReplacementBody(GasGrid __instance)
|
||||||
|
{
|
||||||
|
// Vanilla uses this to decide whether to equalize gas through buildings.
|
||||||
|
var gasGrids = __instance.ParallelGasGrids();
|
||||||
|
for (var i = 0; i < gasGrids.Length; i++)
|
||||||
|
{
|
||||||
|
if (gasGrids[i].CalculateGasEffects)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if !V1_4
|
#if !V1_4
|
||||||
public class ParallelJob : IJobParallelFor
|
public class ParallelJob : IJobParallelFor
|
||||||
{
|
{
|
||||||
@@ -186,6 +291,11 @@ public sealed class GasGridOptimization : ClassWithFishPrepatches
|
|||||||
public sealed class ColorAtPatch : FishPrepatch
|
public sealed class ColorAtPatch : FishPrepatch
|
||||||
{
|
{
|
||||||
public override bool ShowSettings => false;
|
public override bool ShowSettings => false;
|
||||||
|
public override bool Enabled
|
||||||
|
{
|
||||||
|
get => base.Enabled && Get<TickPatch>().Enabled;
|
||||||
|
set => base.Enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
public override MethodBase TargetMethodBase { get; }
|
public override MethodBase TargetMethodBase { get; }
|
||||||
#if V1_4
|
#if V1_4
|
||||||
|
|||||||
Reference in New Issue
Block a user