1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 06:53:31 +08:00

CheatEnabler: optimization

This commit is contained in:
2025-04-26 00:31:56 +08:00
parent 950bde3464
commit 6877b8e9ac
2 changed files with 167 additions and 107 deletions

View File

@@ -5,7 +5,7 @@
* 2.3.30
+ Fix a warning issue while `No condition build` or `No collision` is enabled.
+ Optimized `Finish build immediately` for better performance.
+ Increase performance for `Finish build immediately` greatly on pasting large blueprints.
* 2.3.29
+ Fix compatibility with game update 0.10.32.25779
* 2.3.28
@@ -155,7 +155,7 @@
* 2.3.30
+ 修复了启用`无条件建造``无碰撞`时的警告问题
+ 优化了`立即完成建造`的性能表现
+ 粘贴大规模蓝图时大幅提升`立即完成建造`的性能表现
* 2.3.29
+ 修复了与游戏更新0.10.32.25779的兼容性
* 2.3.28

View File

@@ -92,6 +92,7 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
GreaterPowerUsageInLogistics.Enable(GreaterPowerUsageInLogisticsEnabled.Value);
ControlPanelRemoteLogistics.Enable(ControlPanelRemoteLogisticsEnabled.Value);
Enable(true);
CargoTrafficPatch.Enable(true);
GameLogic.OnGameBegin += GameMain_Begin_Postfix_For_ImmBuild;
GameLogic.OnDataLoaded += OnDataLoaded;
}
@@ -100,6 +101,7 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
{
GameLogic.OnDataLoaded -= OnDataLoaded;
GameLogic.OnGameBegin -= GameMain_Begin_Postfix_For_ImmBuild;
CargoTrafficPatch.Enable(false);
Enable(false);
ImmediateBuild.Enable(false);
ArchitectMode.Enable(false);
@@ -116,6 +118,10 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
}
private static HashSet<int> _beltIds = [];
private static HashSet<int> _alterBeltRendererIds;
private static HashSet<int> _alterPathRendererIds;
private static HashSet<int> _refreshPathUVIds;
private static void OnDataLoaded()
{
WindTurbinesPowerGlobalCoverage.Enable(WindTurbinesPowerGlobalCoverageEnabled.Value);
@@ -163,6 +169,10 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
{
var anyBelt = false;
var anyBuilt = false;
_alterBeltRendererIds ??= [];
_alterPathRendererIds ??= [];
_refreshPathUVIds ??= [];
CargoTrafficPatch.IsBatchBuilding = true;
factory.BeginFlattenTerrain();
factory.cargoTraffic._batch_buffer_no_refresh = true;
PlanetFactory.batchBuild = true;
@@ -187,6 +197,25 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
}
factory.cargoTraffic._batch_buffer_no_refresh = false;
factory.EndFlattenTerrain();
CargoTrafficPatch.IsBatchBuilding = false;
var cargoTraffic = factory.cargoTraffic;
var entityPool = factory.entityPool;
var colChunks = factory.planet.physics?.colChunks;
foreach (var beltId in _alterBeltRendererIds)
{
cargoTraffic.AlterBeltRenderer(beltId, entityPool, colChunks, false);
}
foreach (var pathId in _alterPathRendererIds)
{
cargoTraffic.AlterPathRenderer(pathId, false);
}
foreach (var pathId in _refreshPathUVIds)
{
cargoTraffic.RefreshPathUV(pathId);
}
_alterBeltRendererIds.Clear();
_alterPathRendererIds.Clear();
_refreshPathUVIds.Clear();
if (anyBuilt)
{
factory.planet.physics?.raycastLogic?.NotifyBatchObjectRemove();
@@ -205,6 +234,37 @@ public class FactoryPatch: PatchImpl<FactoryPatch>
}
}
private class CargoTrafficPatch : PatchImpl<CargoTrafficPatch>
{
public static bool IsBatchBuilding;
[HarmonyPrefix]
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterBeltRenderer))]
private static bool CargoTraffic_AlterBeltRenderer_Prefix(int beltId)
{
if (!IsBatchBuilding) return true;
_alterBeltRendererIds.Add(beltId);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterPathRenderer))]
private static bool CargoTraffic_AlterPathRenderer_Prefix(int pathId)
{
if (!IsBatchBuilding) return true;
_alterPathRendererIds.Add(pathId);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathUV))]
private static bool CargoTraffic_RefreshPathUV_Prefix(int pathId)
{
if (!IsBatchBuilding) return true;
_refreshPathUVIds.Add(pathId);
return false;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlanetData), nameof(PlanetData.NotifyFactoryLoaded))]
private static void PlanetData_NotifyFactoryLoaded_Postfix(PlanetData __instance)