Bugfixes for world object caches not clearing when reloading without restart and retextures of a small number of things like fire not working

This commit is contained in:
bbradson
2023-06-08 18:57:10 +02:00
parent d7ff5b96cd
commit 76c0f7a371
7 changed files with 14 additions and 5 deletions
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -2,7 +2,7 @@
![](About/Preview.png?raw=true) ![](About/Preview.png?raw=true)
Performance Mod for Rimworld. Performance Mod for Rimworld.
Requires Prepatcher and Fishery. Requires [Prepatcher](https://github.com/Zetrith/Prepatcher) and [Fishery](https://github.com/bbradson/Fishery).
Performance Fish attempts to improve overall framerates and tick times by patching various methods for improved efficiency, while keeping functionality identical. Designed to be used alongside other performance mods, like RocketMan, and intended to be compatible with very large modlists. Most patches become more impactful as the game progresses further into the lategame. Performance Fish attempts to improve overall framerates and tick times by patching various methods for improved efficiency, while keeping functionality identical. Designed to be used alongside other performance mods, like RocketMan, and intended to be compatible with very large modlists. Most patches become more impactful as the game progresses further into the lategame.
+4
View File
@@ -15,6 +15,8 @@ public static class Utility
{ {
public static event Action<Thing>? ThingDestroyed; // TODO public static event Action<Thing>? ThingDestroyed; // TODO
public static event Action? Cleared;
private static volatile int _destroyedThingCounter, _lastGCTick, _gcRate = 1000; private static volatile int _destroyedThingCounter, _lastGCTick, _gcRate = 1000;
private static int _currentGCProgress; private static int _currentGCProgress;
private static volatile bool _gcInProgress; private static volatile bool _gcInProgress;
@@ -88,6 +90,8 @@ public static class Utility
{ {
foreach (var cache in All) foreach (var cache in All)
cache.Clear(); cache.Clear();
Cleared?.Invoke();
} }
public static void LogCurrentCacheUtilization() public static void LogCurrentCacheUtilization()
@@ -22,7 +22,7 @@ public class ContentFinderCaching : ClassWithFishPrepatches
{ {
ref var cache = ref Cache.ByReference<string, CacheValue<T>>.GetOrAddReference(itemPath); ref var cache = ref Cache.ByReference<string, CacheValue<T>>.GetOrAddReference(itemPath);
if (!cache.Cached) if (!cache.Cached || !OnStartup.State.Initialized)
return __state = true; return __state = true;
__result = cache.Value; __result = cache.Value;
@@ -84,8 +84,8 @@ public class WorldObjectsOptimization : ClassWithFishPrepatches
} }
public static int public static int
CachedWorldObjectsVersion, CachedWorldObjectsVersion = -2,
CachedMapsVersion; CachedMapsVersion = -2;
private static Type[] private static Type[]
_whitelistedTickingCompTypes _whitelistedTickingCompTypes
@@ -110,5 +110,9 @@ public class WorldObjectsOptimization : ClassWithFishPrepatches
public static bool CacheDirty(WorldObjectsHolder instance) public static bool CacheDirty(WorldObjectsHolder instance)
=> CachedWorldObjectsVersion != instance.worldObjects._version => CachedWorldObjectsVersion != instance.worldObjects._version
|| CachedMapsVersion != Current.gameInt.maps._version; || CachedMapsVersion != Current.gameInt.maps._version;
public static void SetDirty() => CachedWorldObjectsVersion = CachedMapsVersion = -2;
static WorldObjectsHolderTickPatch() => Cache.Utility.Cleared += SetDirty;
} }
} }
+2 -1
View File
@@ -290,7 +290,8 @@ public class ThingFilterPatches : ClassWithFishPatches
if (recipe?.ingredients is { } ingredients) if (recipe?.ingredients is { } ingredients)
ingredients.RemoveAll(static ingredientCount => ingredientCount is null); ingredients.RemoveAll(static ingredientCount => ingredientCount is null);
else if (def.CostList is { } costList)
if (def.CostList is { } costList)
costList.RemoveAll(static thingDefCountClass => thingDefCountClass?.thingDef is null); costList.RemoveAll(static thingDefCountClass => thingDefCountClass?.thingDef is null);
try try