diff --git a/TLM/TLM/Lifecycle/ThreadingExtension.cs b/TLM/TLM/Lifecycle/ThreadingExtension.cs index 67afbc015..5d2841a60 100644 --- a/TLM/TLM/Lifecycle/ThreadingExtension.cs +++ b/TLM/TLM/Lifecycle/ThreadingExtension.cs @@ -20,5 +20,11 @@ public override void OnBeforeSimulationFrame() { TrafficLightSimulationManager.Instance.SimulationStep(); } } + + public override void OnAfterSimulationTick() { + base.OnAfterSimulationTick(); + + UtilityManager.Instance.ProcessTransferRecordableQueue(); + } } // end class } \ No newline at end of file diff --git a/TLM/TLM/Manager/Impl/UtilityManager.cs b/TLM/TLM/Manager/Impl/UtilityManager.cs index 52693290a..38e6ad74c 100644 --- a/TLM/TLM/Manager/Impl/UtilityManager.cs +++ b/TLM/TLM/Manager/Impl/UtilityManager.cs @@ -3,11 +3,14 @@ namespace TrafficManager.Manager.Impl { using CSUtil.Commons; using System.Threading; using System; + using System.Collections.Generic; using JetBrains.Annotations; using TrafficManager.API.Manager; using TrafficManager.State; using UnityEngine; using TrafficManager.Lifecycle; + using Util.Record; + public class UtilityManager : AbstractCustomManager, IUtilityManager { static UtilityManager() { Instance = new UtilityManager(); @@ -15,6 +18,8 @@ static UtilityManager() { public static UtilityManager Instance { get; } + private readonly Queue>> _transferRecordables = new (); + public void ClearTraffic() { lock (Singleton.instance) { try { @@ -179,5 +184,29 @@ public void ResetStuckEntities() { Singleton.instance.ForcedSimulationPaused = false; } } + + /// + /// Queues Transfer recordables to be processed at the end of simulation step + /// + /// Settings record to by applied + /// links between source and newly created clones + public void QueueTransferRecordable(IRecordable recordable, + Dictionary map) { + _transferRecordables.Enqueue( + new KeyValuePair>( + recordable, + new Dictionary(map))); + } + + + /// + /// Processes queued transfer recordables + /// + public void ProcessTransferRecordableQueue() { + while (_transferRecordables.Count > 0) { + KeyValuePair> recordablePair = _transferRecordables.Dequeue(); + recordablePair.Key.Transfer(recordablePair.Value); + } + } } } \ No newline at end of file diff --git a/TLM/TLM/State/TMPEMoveITIntegration.cs b/TLM/TLM/State/TMPEMoveITIntegration.cs index ab01dbd5e..e7fb80d7d 100644 --- a/TLM/TLM/State/TMPEMoveITIntegration.cs +++ b/TLM/TLM/State/TMPEMoveITIntegration.cs @@ -4,6 +4,7 @@ namespace TrafficManager.State { using System.Collections.Generic; using TrafficManager.Util.Record; using CSUtil.Commons; + using Manager.Impl; using TrafficManager.Util; public class TMPEMoveItIntegrationFactory : IMoveItIntegrationFactory { @@ -36,8 +37,8 @@ public override object Copy(InstanceID sourceInstanceID) { } public override void Paste(InstanceID targetInstanceID, object record, Dictionary map) { - if(record is IRecordable r) { - r.Transfer(map); + if(record is IRecordable recordable) { + UtilityManager.Instance.QueueTransferRecordable(recordable, map); } } diff --git a/TLM/TLM/Util/Record/SpeedLimitLaneRecord.cs b/TLM/TLM/Util/Record/SpeedLimitLaneRecord.cs index fc004173c..61ccfffe8 100644 --- a/TLM/TLM/Util/Record/SpeedLimitLaneRecord.cs +++ b/TLM/TLM/Util/Record/SpeedLimitLaneRecord.cs @@ -39,7 +39,7 @@ public void Transfer(uint laneId) { segmentId: segmentId, laneIndex: this.LaneIndex, laneInfo: laneInfo, - laneId: this.LaneId, + laneId: laneId, action: SetSpeedLimitAction.FromNullableFloat(this.speedLimit_)); }