From 5f2c20477b2cba4bc4ca54979033e8b5bdea19ba Mon Sep 17 00:00:00 2001 From: Aubergine Date: Mon, 24 Feb 2020 13:04:03 +0000 Subject: [PATCH 1/4] Update SpeedLimitManager.cs --- TLM/TLM/Manager/Impl/SpeedLimitManager.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs index c65f4cef5..ac258114f 100644 --- a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs +++ b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs @@ -874,16 +874,13 @@ public bool LoadData(List data) { if (IsValidRange(customSpeedLimit)) { // lane speed limit differs from default speed limit -#if DEBUGLOAD - Log._Debug($"SpeedLimitManager.LoadData: Loading lane speed limit: lane "+ - $"{laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit}"); -#endif - Flags.SetLaneSpeedLimit(laneSpeedLimit.laneId, laneSpeedLimit.speedLimit); - Log._Debug( - $"SpeedLimitManager.LoadData: Loading lane speed limit: " + + Log._DebugIf(DebugSwitch.SpeedLimits.Get(), () => + "SpeedLimitManager.LoadData: Loading lane speed limit: " + $"lane {laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit} km/h"); + float kmph = laneSpeedLimit.speedLimit / Constants.SPEED_TO_KMPH; // convert to game units + Flags.SetLaneSpeedLimit(laneSpeedLimit.laneId, kmph); } else { #if DEBUGLOAD From e5f1a56c42b088f12bf5e77956acb86c5dd70b0e Mon Sep 17 00:00:00 2001 From: Aubergine Date: Mon, 24 Feb 2020 13:12:21 +0000 Subject: [PATCH 2/4] Wrap in #if DEBUG --- TLM/TLM/Manager/Impl/SpeedLimitManager.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs index ac258114f..5331caf21 100644 --- a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs +++ b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs @@ -8,12 +8,12 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.API.Manager; using TrafficManager.API.Traffic.Data; using TrafficManager.State; +#if DEBUG + using TrafficManager.State.ConfigData; +#endif using TrafficManager.UI.SubTools.SpeedLimits; using TrafficManager.Util; using UnityEngine; -#if DEBUG - using State.ConfigData; -#endif public class SpeedLimitManager : AbstractGeometryObservingManager, @@ -874,10 +874,11 @@ public bool LoadData(List data) { if (IsValidRange(customSpeedLimit)) { // lane speed limit differs from default speed limit +#if DEBUG Log._DebugIf(DebugSwitch.SpeedLimits.Get(), () => "SpeedLimitManager.LoadData: Loading lane speed limit: " + $"lane {laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit} km/h"); - +#endif float kmph = laneSpeedLimit.speedLimit / Constants.SPEED_TO_KMPH; // convert to game units From 25551d43ab19dcfa99cba212653c8c27317d555e Mon Sep 17 00:00:00 2001 From: Aubergine Date: Mon, 24 Feb 2020 13:32:48 +0000 Subject: [PATCH 3/4] Updated all the logging calls in LoadData() --- TLM/TLM/Manager/Impl/SpeedLimitManager.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs index 5331caf21..ded4b56ed 100644 --- a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs +++ b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs @@ -850,11 +850,15 @@ protected override void HandleValidSegment(ref ExtSegment seg) { } public bool LoadData(List data) { bool success = true; Log.Info($"Loading lane speed limit data. {data.Count} elements"); +#if DEBUG + bool debugLogging = DebugSwitch.SpeedLimits.Get(); +#endif foreach (Configuration.LaneSpeedLimit laneSpeedLimit in data) { try { if (!Services.NetService.IsLaneValid(laneSpeedLimit.laneId)) { -#if DEBUGLOAD - Log._Debug($"SpeedLimitManager.LoadData: Skipping lane {laneSpeedLimit.laneId}: Lane is invalid"); +#if DEBUG + Log._DebugIf(debugLogging, () => + $"SpeedLimitManager.LoadData: Skipping lane {laneSpeedLimit.laneId}: Lane is invalid"); #endif continue; } @@ -866,8 +870,9 @@ public bool LoadData(List data) { NetInfo info = Singleton .instance.m_segments.m_buffer[segmentId].Info; float customSpeedLimit = GetCustomNetInfoSpeedLimit(info); -#if DEBUGLOAD - Log._Debug($"SpeedLimitManager.LoadData: Handling lane {laneSpeedLimit.laneId}: " + +#if DEBUG + Log._DebugIf(debugLogging, () => + $"SpeedLimitManager.LoadData: Handling lane {laneSpeedLimit.laneId}: " + $"Custom speed limit of segment {segmentId} info ({info}, name={info?.name}, " + $"lanes={info?.m_lanes} is {customSpeedLimit}"); #endif @@ -875,7 +880,7 @@ public bool LoadData(List data) { if (IsValidRange(customSpeedLimit)) { // lane speed limit differs from default speed limit #if DEBUG - Log._DebugIf(DebugSwitch.SpeedLimits.Get(), () => + Log._DebugIf(debugLogging, () => "SpeedLimitManager.LoadData: Loading lane speed limit: " + $"lane {laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit} km/h"); #endif @@ -884,8 +889,9 @@ public bool LoadData(List data) { Flags.SetLaneSpeedLimit(laneSpeedLimit.laneId, kmph); } else { -#if DEBUGLOAD - Log._Debug($"SpeedLimitManager.LoadData: " + +#if DEBUG + Log._DebugIf(debugLogging, () => + "SpeedLimitManager.LoadData: " + $"Skipping lane speed limit of lane {laneSpeedLimit.laneId} " + $"({laneSpeedLimit.speedLimit} km/h)"); #endif From de6a822f7c479aa48d9a400b0565ab00fe961cd1 Mon Sep 17 00:00:00 2001 From: Aubergine Date: Mon, 24 Feb 2020 14:23:09 +0000 Subject: [PATCH 4/4] Rename logging bool --- TLM/TLM/Manager/Impl/SpeedLimitManager.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs index ded4b56ed..65ea5e846 100644 --- a/TLM/TLM/Manager/Impl/SpeedLimitManager.cs +++ b/TLM/TLM/Manager/Impl/SpeedLimitManager.cs @@ -851,13 +851,13 @@ public bool LoadData(List data) { bool success = true; Log.Info($"Loading lane speed limit data. {data.Count} elements"); #if DEBUG - bool debugLogging = DebugSwitch.SpeedLimits.Get(); + bool debugSpeedLimits = DebugSwitch.SpeedLimits.Get(); #endif foreach (Configuration.LaneSpeedLimit laneSpeedLimit in data) { try { if (!Services.NetService.IsLaneValid(laneSpeedLimit.laneId)) { #if DEBUG - Log._DebugIf(debugLogging, () => + Log._DebugIf(debugSpeedLimits, () => $"SpeedLimitManager.LoadData: Skipping lane {laneSpeedLimit.laneId}: Lane is invalid"); #endif continue; @@ -871,7 +871,7 @@ public bool LoadData(List data) { .instance.m_segments.m_buffer[segmentId].Info; float customSpeedLimit = GetCustomNetInfoSpeedLimit(info); #if DEBUG - Log._DebugIf(debugLogging, () => + Log._DebugIf(debugSpeedLimits, () => $"SpeedLimitManager.LoadData: Handling lane {laneSpeedLimit.laneId}: " + $"Custom speed limit of segment {segmentId} info ({info}, name={info?.name}, " + $"lanes={info?.m_lanes} is {customSpeedLimit}"); @@ -880,7 +880,7 @@ public bool LoadData(List data) { if (IsValidRange(customSpeedLimit)) { // lane speed limit differs from default speed limit #if DEBUG - Log._DebugIf(debugLogging, () => + Log._DebugIf(debugSpeedLimits, () => "SpeedLimitManager.LoadData: Loading lane speed limit: " + $"lane {laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit} km/h"); #endif @@ -890,7 +890,7 @@ public bool LoadData(List data) { Flags.SetLaneSpeedLimit(laneSpeedLimit.laneId, kmph); } else { #if DEBUG - Log._DebugIf(debugLogging, () => + Log._DebugIf(debugSpeedLimits, () => "SpeedLimitManager.LoadData: " + $"Skipping lane speed limit of lane {laneSpeedLimit.laneId} " + $"({laneSpeedLimit.speedLimit} km/h)");