From 4722df83860d21e92476a84d2b44a98845b73224 Mon Sep 17 00:00:00 2001 From: kianzzarrin Date: Thu, 15 Dec 2022 20:36:42 +0200 Subject: [PATCH] pillar fix queue --- .../BuilidingManger_SimulationStep_Patch.cs | 19 +++++++++++++++++++ .../Patches/NetNodePatches/UpdateBuilding.cs | 2 +- .../NetSegmentPatches/UpdateSegments.cs | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 NodeController/Patches/BuilidingManger_SimulationStep_Patch.cs diff --git a/NodeController/Patches/BuilidingManger_SimulationStep_Patch.cs b/NodeController/Patches/BuilidingManger_SimulationStep_Patch.cs new file mode 100644 index 0000000..b7ce386 --- /dev/null +++ b/NodeController/Patches/BuilidingManger_SimulationStep_Patch.cs @@ -0,0 +1,19 @@ +namespace NodeController.Patches { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using HarmonyLib; + + [HarmonyPatch(typeof(BuildingManager),"SimulationStepImpl")] + internal static class BuilidingManger_SimulationStep_Patch { + // must be read/write from simulation thread. + internal static HashSet FixPillarNodeIDs = new(); + static void Prefix() { + foreach(var nodeID in FixPillarNodeIDs) { + NodeData.FixPillar(nodeID); + } + FixPillarNodeIDs.Clear(); + } + } +} diff --git a/NodeController/Patches/NetNodePatches/UpdateBuilding.cs b/NodeController/Patches/NetNodePatches/UpdateBuilding.cs index c7364ca..69a9c4f 100644 --- a/NodeController/Patches/NetNodePatches/UpdateBuilding.cs +++ b/NodeController/Patches/NetNodePatches/UpdateBuilding.cs @@ -9,7 +9,7 @@ namespace NodeController.Patches; class UpdateBuilding { /// in case another mod updated node building without performing a full update static void Postfix(ushort nodeID) { - SimulationManager.instance.AddAction(() => NodeData.FixPillar(nodeID)); + BuilidingManger_SimulationStep_Patch.FixPillarNodeIDs.Add(nodeID); } } #endif \ No newline at end of file diff --git a/NodeController/Patches/NetSegmentPatches/UpdateSegments.cs b/NodeController/Patches/NetSegmentPatches/UpdateSegments.cs index 00edb78..274242e 100644 --- a/NodeController/Patches/NetSegmentPatches/UpdateSegments.cs +++ b/NodeController/Patches/NetSegmentPatches/UpdateSegments.cs @@ -13,7 +13,7 @@ internal static void Postfix(ushort segmentID, bool startNode) { ref NetSegment segment = ref segmentID.ToSegment(); ushort nodeID = segment.GetNode(startNode); - SimulationManager.instance.AddAction(() => NodeData.FixPillar(nodeID)); + BuilidingManger_SimulationStep_Patch.FixPillarNodeIDs.Add(nodeID); } catch (Exception ex) { ex.Log($"segment:{segmentID}"); } } }