Stabilize RimWorld 1.6 caches and tick optimizations
This commit is contained in:
@@ -59,27 +59,33 @@ public static class Utility
|
||||
return;
|
||||
|
||||
_gcInProgress = true;
|
||||
|
||||
if (_cachesToProcessForGC is null || _currentGCProgress >= _cachesToProcessForGC.Length)
|
||||
try
|
||||
{
|
||||
_cachesToProcessForGC = All.ToArray();
|
||||
_gcRate = GenDate.TicksPerTwelfth / _cachesToProcessForGC.CountNonEmpty();
|
||||
_currentGCProgress = 0;
|
||||
_destroyedThingCounter = 0;
|
||||
}
|
||||
if (_cachesToProcessForGC is null || _currentGCProgress >= _cachesToProcessForGC.Length)
|
||||
{
|
||||
_cachesToProcessForGC = All.ToArray();
|
||||
var nonEmptyCount = _cachesToProcessForGC.CountNonEmpty();
|
||||
_gcRate = nonEmptyCount > 0 ? GenDate.TicksPerTwelfth / nonEmptyCount : 1000;
|
||||
_currentGCProgress = 0;
|
||||
_destroyedThingCounter = 0;
|
||||
if (nonEmptyCount == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
while (_cachesToProcessForGC[_currentGCProgress].Count == 0
|
||||
&& _cachesToProcessForGC.Length - _currentGCProgress > 1)
|
||||
while (_currentGCProgress < _cachesToProcessForGC.Length
|
||||
&& _cachesToProcessForGC[_currentGCProgress].Count == 0)
|
||||
{
|
||||
_currentGCProgress++;
|
||||
}
|
||||
|
||||
if (_currentGCProgress < _cachesToProcessForGC.Length)
|
||||
_cachesToProcessForGC[_currentGCProgress++].Clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentGCProgress++;
|
||||
_lastGCTick = TickHelper.TicksGame;
|
||||
_gcInProgress = false;
|
||||
}
|
||||
|
||||
if (_currentGCProgress < _cachesToProcessForGC.Length)
|
||||
_cachesToProcessForGC[_currentGCProgress++].Clear();
|
||||
|
||||
_lastGCTick = TickHelper.TicksGame;
|
||||
|
||||
_gcInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,4 +420,4 @@ public sealed class CollectionRef<T>(AccessTools.FieldRef<T> fieldRef) : ICleara
|
||||
}
|
||||
|
||||
private delegate void ClearInvoker(ref T collectionRef);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user