From 32ab31526bc26e268e6700e0105a1658fac4f733 Mon Sep 17 00:00:00 2001 From: egi Date: Wed, 4 Nov 2020 04:18:38 +0100 Subject: [PATCH] Added ushort.ToBuilding() extension method. Redirected call of ProcessBuilding to new ushort.ToBuilding() method. Removed ProcessBuilding method since it used a closure. --- TLM/TLM/Manager/Impl/RoutingManager.cs | 12 +++--------- TLM/TLM/Util/Shortcuts.cs | 4 ++++ TLM/TMPE.CitiesGameBridge/Service/BuildingService.cs | 6 ------ .../Service/IBuildingService.cs | 4 ---- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/TLM/TLM/Manager/Impl/RoutingManager.cs b/TLM/TLM/Manager/Impl/RoutingManager.cs index 7f449cf8e..df2ed30a7 100644 --- a/TLM/TLM/Manager/Impl/RoutingManager.cs +++ b/TLM/TLM/Manager/Impl/RoutingManager.cs @@ -11,6 +11,7 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.API.Traffic.Enums; using TrafficManager.State.ConfigData; using TrafficManager.State; + using TrafficManager.Util; public class RoutingManager : AbstractGeometryObservingManager, @@ -470,15 +471,8 @@ protected void RecalculateLaneEndRoutingData(ushort segmentId, return true; }); - bool isTollBooth = false; - if (buildingId != 0) { - Constants.ServiceFactory.BuildingService.ProcessBuilding( - buildingId, - (ushort bId, ref Building building) => { - isTollBooth = building.Info.m_buildingAI is TollBoothAI; - return true; - }); - } + bool isTollBooth = buildingId != 0 + && buildingId.ToBuilding().Info.m_buildingAI is TollBoothAI; bool nextIsSimpleJunction = false; bool nextIsSplitJunction = false; diff --git a/TLM/TLM/Util/Shortcuts.cs b/TLM/TLM/Util/Shortcuts.cs index a644996e4..b173e7f51 100644 --- a/TLM/TLM/Util/Shortcuts.cs +++ b/TLM/TLM/Util/Shortcuts.cs @@ -48,6 +48,8 @@ internal static void Swap(this List list, int index1, int index2) { private static NetLane[] _laneBuffer = Singleton.instance.m_lanes.m_buffer; + private static Building[] _buildingBuffer = Singleton.instance.m_buildings.m_buffer; + private static ExtSegmentEnd[] _segEndBuff => segEndMan.ExtSegmentEnds; internal static IExtSegmentEndManager segEndMan => Constants.ManagerFactory.ExtSegmentEndManager; @@ -66,6 +68,8 @@ internal static void Swap(this List list, int index1, int index2) { internal static ref NetSegment ToSegment(this ushort segmentId) => ref _segBuffer[segmentId]; + internal static ref Building ToBuilding(this ushort buildingId) => ref _buildingBuffer[buildingId]; + internal static NetInfo.Lane GetLaneInfo(ushort segmentId, int laneIndex) => segmentId.ToSegment().Info.m_lanes[laneIndex]; diff --git a/TLM/TMPE.CitiesGameBridge/Service/BuildingService.cs b/TLM/TMPE.CitiesGameBridge/Service/BuildingService.cs index c3ddd55ac..85d76aec9 100644 --- a/TLM/TMPE.CitiesGameBridge/Service/BuildingService.cs +++ b/TLM/TMPE.CitiesGameBridge/Service/BuildingService.cs @@ -39,11 +39,5 @@ public bool CheckBuildingFlags(ushort buildingId, return expectedResult == null ? result != 0 : result == expectedResult; } - - public void ProcessBuilding(ushort buildingId, BuildingHandler handler) { - handler( - buildingId, - ref Singleton.instance.m_buildings.m_buffer[buildingId]); - } } } \ No newline at end of file diff --git a/TLM/TMPE.GenericGameBridge/Service/IBuildingService.cs b/TLM/TMPE.GenericGameBridge/Service/IBuildingService.cs index 4c3f3671e..b0773c3de 100644 --- a/TLM/TMPE.GenericGameBridge/Service/IBuildingService.cs +++ b/TLM/TMPE.GenericGameBridge/Service/IBuildingService.cs @@ -1,13 +1,9 @@ namespace GenericGameBridge.Service { - public delegate bool BuildingHandler(ushort buildingId, ref Building building); - public interface IBuildingService { bool CheckBuildingFlags(ushort buildingId, Building.Flags flagMask, Building.Flags? expectedResult = default); bool IsBuildingValid(ushort buildingId); - - void ProcessBuilding(ushort buildingId, BuildingHandler handler); } } \ No newline at end of file