Lots of new optimizations utilizing prepatcher
To start, this mod now requires Prepatcher and Fishery. New optimizations include: gene ticking improvements, world object improvements, hediff optimizations, world pawn gc optimizations, better mothballing, dds support, ContentFinder caching, additions and changes to reflection caching, as well as various other additions. Multiplayer support has been improved too, but should be considered highly experimental. The WorkGiver_DoBill bug is fixed in this build. Multiple patches aiming to improve RimWorld's load time have been added too.
This commit is contained in:
@@ -1,22 +1,26 @@
|
||||
// Copyright (c) 2022 bradson
|
||||
// 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.Cache;
|
||||
using StyleDominanceCache = PerformanceFish.Cache.ByIntRefreshable<Verse.Thing, RimWorld.Ideo, PerformanceFish.IdeoUtilityCaching.StyleDominanceCacheValue>;
|
||||
using PerformanceFish.Prepatching;
|
||||
using StyleDominanceCache
|
||||
= PerformanceFish.Cache.ByInt<Verse.Thing, RimWorld.Ideo,
|
||||
PerformanceFish.IdeoUtilityCaching.StyleDominanceCacheValue>;
|
||||
|
||||
namespace PerformanceFish;
|
||||
public class IdeoUtilityCaching : ClassWithFishPatches
|
||||
|
||||
public class IdeoUtilityCaching : ClassWithFishPrepatches
|
||||
{
|
||||
public class GetStyleDominance_Patch : FishPatch
|
||||
public class GetStyleDominance_Patch : FishPrepatch
|
||||
{
|
||||
public override string? Description => "Caches IdeoUtility.GetStyleDominance to only update about once every 600 ticks or so. Only active when not using Performance Optimizer, as that mod includes a similar version too.";
|
||||
public override bool Enabled => base.Enabled && !ModsConfig.IsActive("Taranchuk.PerformanceOptimizer");
|
||||
public override Delegate? TargetMethodGroup => IdeoUtility.GetStyleDominance;
|
||||
public override string Description { get; }
|
||||
= "Caches IdeoUtility.GetStyleDominance to only update about once every 900 ticks or so.";
|
||||
|
||||
public override MethodBase TargetMethodBase { get; } = methodof(IdeoUtility.GetStyleDominance);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool Prefix(Thing t, Ideo ideo, ref float __result, out bool __state)
|
||||
public static bool Prefix(Thing? t, Ideo? ideo, ref float __result, out bool __state)
|
||||
{
|
||||
if (t is null || ideo is null || t.thingIDNumber < 0)
|
||||
{
|
||||
@@ -24,10 +28,9 @@ public class IdeoUtilityCaching : ClassWithFishPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
var key = new StyleDominanceCache(t.thingIDNumber, ideo.id);
|
||||
ref var cache = ref StyleDominanceCache.Get.TryGetReferenceUnsafe(ref key);
|
||||
ref var cache = ref StyleDominanceCache.GetOrAddReference(new(t.thingIDNumber, ideo.id));
|
||||
|
||||
if (Unsafe.IsNullRef(ref cache) || cache.ShouldRefreshNow)
|
||||
if (cache.Dirty)
|
||||
return __state = true;
|
||||
|
||||
__result = cache.Value;
|
||||
@@ -40,28 +43,30 @@ public class IdeoUtilityCaching : ClassWithFishPatches
|
||||
if (!__state)
|
||||
return;
|
||||
|
||||
StyleDominanceCache.Get[new(t, ideo)] = new(__result);
|
||||
UpdateCache(t, ideo, __result);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static void UpdateCache(Thing t, Ideo ideo, float __result)
|
||||
=> StyleDominanceCache.GetExistingReference(t, ideo).Update(__result, t);
|
||||
}
|
||||
|
||||
public struct StyleDominanceCacheValue : IIsRefreshable<StyleDominanceCache, StyleDominanceCacheValue>
|
||||
public record struct StyleDominanceCacheValue
|
||||
{
|
||||
public float Value;
|
||||
private int _nextRefreshTick;
|
||||
|
||||
public StyleDominanceCacheValue(float value)
|
||||
public void Update(float value, Thing thing)
|
||||
{
|
||||
Value = value;
|
||||
_nextRefreshTick = Current.Game.tickManager.TicksGame + 512 + Math.Abs(Rand.Int % 256); // Pawn_StyleObserverTracker.StyleObservableTick runs every 900 ticks
|
||||
_nextRefreshTick = TickHelper.Add(900 - 128, thing.thingIDNumber, 256);
|
||||
// Pawn_StyleObserverTracker.StyleObservableTick runs every 900 ticks
|
||||
}
|
||||
|
||||
public bool ShouldRefreshNow
|
||||
public bool Dirty
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _nextRefreshTick < Current.Game.tickManager.TicksGame;
|
||||
set => _nextRefreshTick = value ? 0 : Current.Game.tickManager.TicksGame + 512 + Math.Abs(Rand.Int % 256);
|
||||
get => TickHelper.Past(_nextRefreshTick);
|
||||
}
|
||||
|
||||
StyleDominanceCacheValue IIsRefreshable<StyleDominanceCache, StyleDominanceCacheValue>.SetNewValue(StyleDominanceCache key) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user