fix(cheatenabler): plan belt-signal statistics outside the logic tick

Signals can change inside the logic tick when drones finish a blueprint, so a
cache miss now queues the belt and the production planner runs from the next
frame update; the tick only applies cached rates. Document the recipe-based
upstream statistics in the unreleased changelog.
This commit is contained in:
soarqin committed 2026-10-25 22:01:05 +08:00
1 parent f0773ffb9b
commit 79c736d90c
2 files changed
+26 -5

No files matched your search

+2
View File
@@ -4,6 +4,7 @@
## Changlog
* 2.4.8 - Unreleased
* `Belt signal item generation`: Calculate raw-material, intermediate, and proliferator statistics from the game's current recipe data, using each item's standard recipe and counting by-products and consumption separately. If an item's recipe data is incomplete, only its upstream statistics pause, with the reason logged; item generation is unaffected.
* 2.4.7
* `Dev Shortcuts`: Work immediately when enabled after loading a save, and process each key press once per frame at accelerated game speeds.
* Extend `Unlock Tech with Key-Modifiers` with a downgrade mode.
@@ -203,6 +204,7 @@
## 更新日志
* 2.4.8 - Unreleased
* `传送带信号物品生成`:原料、中间产物和增产剂的统计改为按游戏当前配方数据计算,采用各物品的标准配方,并分别计入副产物和消耗。某物品的配方数据不完整时,仅暂停该物品的上游统计并在日志中说明原因,不影响物品生成。
* 2.4.7
* `开发模式快捷键`:修复载入存档后启用时不生效的问题;加速游戏时每次按键仍只执行一次。
* `使用组合键点击解锁科技` 新增降级模式。
@@ -23,6 +23,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
private static readonly Dictionary<(int itemId, bool proliferated, bool sprayed),
IReadOnlyList<BeltSignalSourceRate>> SourceCache = [];
private static readonly HashSet<(int itemId, bool proliferated, bool sprayed)> FailedSources = [];
private static readonly HashSet<BeltSignal> PendingSources = [];
public static void Init()
{
@@ -36,6 +37,13 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
ProductionCatalogService.Changed -= OnProductionCatalogChanged;
}
public static void OnUpdate()
{
if (PendingSources.Count == 0) return;
foreach (var beltSignal in PendingSources) TryApplySources(beltSignal, true);
PendingSources.Clear();
}
private static void ResetState()
{
_initialized = false;
@@ -43,6 +51,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
_portalFrom = null;
_portalTo = null;
_signalBeltsCapacity = 0;
PendingSources.Clear();
ClearSourceCache();
}
@@ -76,6 +85,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
_initialized = false;
_signalBelts = null;
_signalBeltsCapacity = 0;
PendingSources.Clear();
ClearSourceCache();
}
@@ -302,8 +312,15 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
private static void AddSourcesToBeltSignal(BeltSignal beltSignal)
{
beltSignal.SourceStats = null;
// Signals can change inside the logic tick, for example when drones finish a blueprint, so missing rates
// are planned in the next frame update and the tick only applies cached rates.
if (!TryApplySources(beltSignal, false)) PendingSources.Add(beltSignal);
}
private static bool TryApplySources(BeltSignal beltSignal, bool calculate)
{
var itemId = beltSignal.SignalId;
if (itemId < 1000 || beltSignal.Stack == 0) return;
if (itemId < 1000 || beltSignal.Stack == 0) return true;
var catalog = ProductionCatalogService.Current;
if (!ReferenceEquals(_sourceCatalog, catalog))
{
@@ -319,12 +336,13 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
if (catalog == null)
{
LogSourceFailure(key, "Production data is not loaded.");
return;
return true;
}
if (FailedSources.Contains(key)) return;
if (FailedSources.Contains(key)) return true;
if (!SourceCache.TryGetValue(key, out var rates))
{
if (!calculate) return false;
try
{
var request = BeltSignalSourcePreset.Create(catalog, itemId, proliferated, sprayed);
@@ -332,7 +350,7 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
if (!report.MaterialComplete)
{
LogSourceFailure(key, string.Join("; ", report.Diagnostics.Select(diagnostic => diagnostic.Message)));
return;
return true;
}
rates = BeltSignalSourceStats.FromReport(report, itemId);
@@ -340,13 +358,14 @@ internal class BeltSignalGenerator : PatchImpl<BeltSignalGenerator>
catch (Exception exception)
{
LogSourceFailure(key, exception.ToString());
return;
return true;
}
SourceCache[key] = rates;
}
if (rates.Count > 0) beltSignal.SourceStats = new BeltSignalSourceStats(rates);
return true;
}
private static void LogSourceFailure((int itemId, bool proliferated, bool sprayed) key, string reason)