From 24097aa01233a44cd22bd5e94688b500b5cf47e7 Mon Sep 17 00:00:00 2001 From: seiggy Date: Mon, 3 Aug 2015 23:39:37 -0400 Subject: [PATCH] Changes to try and fix loading system and compatibility issues. --- TLM/TLM/CustomAI/CustomCargoTruckAI.cs | 2 +- TLM/TLM/Log.cs | 8 ++++ TLM/TLM/SerializableDataExtension.cs | 55 ++++++++++++++++++++------ TLM/TLM/TLM.csproj | 4 +- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/TLM/TLM/CustomAI/CustomCargoTruckAI.cs b/TLM/TLM/CustomAI/CustomCargoTruckAI.cs index 64402086..2ec8f698 100644 --- a/TLM/TLM/CustomAI/CustomCargoTruckAI.cs +++ b/TLM/TLM/CustomAI/CustomCargoTruckAI.cs @@ -48,7 +48,7 @@ private static void RemoveOffers(ushort vehicleId, ref Vehicle data) } } - protected void BaseSimulationStep(ushort vehicleId, ref Vehicle data, Vector3 physicsLodRefPos) + private void BaseSimulationStep(ushort vehicleId, ref Vehicle data, Vector3 physicsLodRefPos) { if ((data.m_flags & Vehicle.Flags.WaitingPath) != Vehicle.Flags.None) { diff --git a/TLM/TLM/Log.cs b/TLM/TLM/Log.cs index 6acbb445..e6f3a25a 100644 --- a/TLM/TLM/Log.cs +++ b/TLM/TLM/Log.cs @@ -11,6 +11,7 @@ public static class Log public static void Message(object s) { +#if DEBUG try { if (InGameDebug) @@ -21,10 +22,12 @@ public static void Message(object s) // cross thread issue? } Debug.Log(Prefix + s.ToString()); +#endif } public static void Error(object s) { +#if DEBUG try { if (InGameDebug) @@ -35,10 +38,12 @@ public static void Error(object s) // cross thread issue? } Debug.LogError(Prefix + s.ToString()); +#endif } public static void Warning(object s) { +#if DEBUG try { if (InGameDebug) @@ -49,14 +54,17 @@ public static void Warning(object s) // cross thread issue? } Debug.LogWarning(Prefix + s.ToString()); +#endif } internal static void Warning(InstanceType instanceType) { +#if DEBUG if (InGameDebug) DebugOutputPanel.AddMessage(ColossalFramework.Plugins.PluginManager.MessageType.Warning, Prefix); Debug.LogWarning(Prefix); +#endif } } diff --git a/TLM/TLM/SerializableDataExtension.cs b/TLM/TLM/SerializableDataExtension.cs index 74c18b89..2cfd81f9 100644 --- a/TLM/TLM/SerializableDataExtension.cs +++ b/TLM/TLM/SerializableDataExtension.cs @@ -111,8 +111,11 @@ private void DeserializeData(byte[] data) } ConfigLoaded = true; + //LoadDataState(); + //StateLoaded = true; + Log.Message("Setting timer to load data."); - var timer = new Timer(5000); + var timer = new Timer(1500); timer.Elapsed += (sender, args) => { if (!ConfigLoaded || StateLoaded) return; @@ -279,10 +282,14 @@ var segmentData in catch (Exception e) { // ignore as it's probably bad save data. - //Log.Warning("Error setting the NodeTrafficLights: " + e.Message); + Log.Warning("Error setting the NodeTrafficLights: " + e.Message); } } - + + // For Traffic++ compatibility + if (!LoadingExtension.IsPathManagerCompatibile) + return; + Log.Message($"LaneFlags: {_configuration.LaneFlags}"); var lanes = _configuration.LaneFlags.Split(','); @@ -290,9 +297,26 @@ var segmentData in return; foreach (var split in lanes.Select(lane => lane.Split(':')).Where(split => split.Length > 1)) { - Log.Message($"Split Data: {split[0]} , {split[1]}"); - Singleton.instance.m_lanes.m_buffer[Convert.ToInt32(split[0])].m_flags = - Convert.ToUInt16(split[1]); + try + { + Log.Message($"Split Data: {split[0]} , {split[1]}"); + var laneIndex = Convert.ToInt32(split[0]); + + //make sure we don't cause any overflows because of bad save data. + if (Singleton.instance.m_lanes.m_buffer.Length <= laneIndex) + continue; + + if (Convert.ToInt32(split[1]) > ushort.MaxValue) + continue; + + Singleton.instance.m_lanes.m_buffer[Convert.ToInt32(split[0])].m_flags = + Convert.ToUInt16(split[1]); + } + catch (Exception e) + { + Log.Error( + $"Error loading Lane Split data. Length: {split.Length} value: {split}\nError: {e.Message}"); + } } } @@ -414,15 +438,24 @@ public override void OnSaveData() Convert.ToInt16((nodeFlags & NetNode.Flags.Junction) != NetNode.Flags.None); } - for (var i = 0; i < Singleton.instance.m_lanes.m_buffer.Length; i++) + // Traffic++ compatibility + if (LoadingExtension.IsPathManagerCompatibile) { - var laneSegment = Singleton.instance.m_lanes.m_buffer[i].m_segment; - - if (TrafficPriority.PrioritySegments.ContainsKey(laneSegment)) + for (var i = 0; i < Singleton.instance.m_lanes.m_buffer.Length; i++) { - configuration.LaneFlags += i + ":" + Singleton.instance.m_lanes.m_buffer[i].m_flags + ","; + var laneSegment = Singleton.instance.m_lanes.m_buffer[i].m_segment; + + if (TrafficPriority.PrioritySegments.ContainsKey(laneSegment)) + { + configuration.LaneFlags += i + ":" + Singleton.instance.m_lanes.m_buffer[i].m_flags + + ","; + } } } + else + { + configuration.LaneFlags = ""; + } var binaryFormatter = new BinaryFormatter(); var memoryStream = new MemoryStream(); diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index beff3afb..6c377be0 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -27,9 +27,11 @@ pdbonly true bin\Release\ - TRACE + + prompt 4 + true