mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 04:53:30 +08:00
Try to optimize ImmBuild
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using CommonAPI.Systems;
|
using CommonAPI.Systems;
|
||||||
@@ -114,7 +115,12 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
|
|||||||
ControlPanelRemoteLogistics.Enable(false);
|
ControlPanelRemoteLogistics.Enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnDataLoaded() => WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
|
private static HashSet<int> _beltIds = [];
|
||||||
|
private static void OnDataLoaded()
|
||||||
|
{
|
||||||
|
WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
|
||||||
|
_beltIds ??= [..LDB.items.dataArray.Where(i => i.prefabDesc.isBelt).Select(i => i.ID)];
|
||||||
|
}
|
||||||
|
|
||||||
public static void OnUpdate()
|
public static void OnUpdate()
|
||||||
{
|
{
|
||||||
@@ -152,7 +158,12 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
|
|||||||
var architect = ArchitectModeEnabled.Value;
|
var architect = ArchitectModeEnabled.Value;
|
||||||
if ((!imm && !architect) || GameMain.gameScenario == null) return;
|
if ((!imm && !architect) || GameMain.gameScenario == null) return;
|
||||||
var prebuilds = factory.prebuildPool;
|
var prebuilds = factory.prebuildPool;
|
||||||
if (imm) factory.BeginFlattenTerrain();
|
var anyBelt = false;
|
||||||
|
if (imm)
|
||||||
|
{
|
||||||
|
factory.BeginFlattenTerrain();
|
||||||
|
factory.cargoTraffic._batch_buffer_no_refresh = true;
|
||||||
|
}
|
||||||
for (var i = factory.prebuildCursor - 1; i > 0; i--)
|
for (var i = factory.prebuildCursor - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
if (prebuilds[i].id != i) continue;
|
if (prebuilds[i].id != i) continue;
|
||||||
@@ -161,18 +172,33 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
|
|||||||
if (!architect) continue;
|
if (!architect) continue;
|
||||||
prebuilds[i].itemRequired = 0;
|
prebuilds[i].itemRequired = 0;
|
||||||
if (imm)
|
if (imm)
|
||||||
|
{
|
||||||
|
anyBelt = anyBelt || _beltIds.Contains(prebuilds[i].protoId);
|
||||||
factory.BuildFinally(GameMain.mainPlayer, i, false);
|
factory.BuildFinally(GameMain.mainPlayer, i, false);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
factory.AlterPrebuildModelState(i);
|
factory.AlterPrebuildModelState(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (imm)
|
if (imm)
|
||||||
|
{
|
||||||
|
anyBelt = anyBelt || _beltIds.Contains(prebuilds[i].protoId);
|
||||||
factory.BuildFinally(GameMain.mainPlayer, i, false);
|
factory.BuildFinally(GameMain.mainPlayer, i, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imm) factory.EndFlattenTerrain();
|
if (imm)
|
||||||
|
{
|
||||||
|
if (anyBelt)
|
||||||
|
{
|
||||||
|
factory.cargoTraffic.RefreshBeltBatchesBuffers();
|
||||||
|
factory.cargoTraffic.RefreshPathBatchesBuffers();
|
||||||
|
}
|
||||||
|
factory.cargoTraffic._batch_buffer_no_refresh = false;
|
||||||
|
factory.EndFlattenTerrain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
|
|||||||
Reference in New Issue
Block a user