Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TM:PE settings not copy pasted in-game #1303

Merged
merged 3 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TLM/TLM/Lifecycle/ThreadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ public override void OnBeforeSimulationFrame() {
TrafficLightSimulationManager.Instance.SimulationStep();
}
}

public override void OnAfterSimulationTick() {
base.OnAfterSimulationTick();

UtilityManager.Instance.ProcessTransferRecordableQueue();
}
} // end class
}
29 changes: 29 additions & 0 deletions TLM/TLM/Manager/Impl/UtilityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ 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();
}

public static UtilityManager Instance { get; }

private readonly Queue<KeyValuePair<IRecordable, Dictionary<InstanceID, InstanceID>>> _transferRecordables = new ();

public void ClearTraffic() {
lock (Singleton<VehicleManager>.instance) {
try {
Expand Down Expand Up @@ -179,5 +184,29 @@ public void ResetStuckEntities() {
Singleton<SimulationManager>.instance.ForcedSimulationPaused = false;
}
}

/// <summary>
/// Queues Transfer recordables to be processed at the end of simulation step
/// </summary>
/// <param name="recordable">Settings record to by applied</param>
/// <param name="map">links between source and newly created clones</param>
public void QueueTransferRecordable(IRecordable recordable,
Dictionary<InstanceID, InstanceID> map) {
_transferRecordables.Enqueue(
new KeyValuePair<IRecordable, Dictionary<InstanceID, InstanceID>>(
recordable,
new Dictionary<InstanceID, InstanceID>(map)));
}


/// <summary>
/// Processes queued transfer recordables
/// </summary>
public void ProcessTransferRecordableQueue() {
while (_transferRecordables.Count > 0) {
KeyValuePair<IRecordable, Dictionary<InstanceID, InstanceID>> recordablePair = _transferRecordables.Dequeue();
recordablePair.Key.Transfer(recordablePair.Value);
}
}
}
}
5 changes: 3 additions & 2 deletions TLM/TLM/State/TMPEMoveITIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -36,8 +37,8 @@ public override object Copy(InstanceID sourceInstanceID) {
}

public override void Paste(InstanceID targetInstanceID, object record, Dictionary<InstanceID, InstanceID> map) {
if(record is IRecordable r) {
r.Transfer(map);
if(record is IRecordable recordable) {
UtilityManager.Instance.QueueTransferRecordable(recordable, map);
}
}

Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Util/Record/SpeedLimitLaneRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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_));
}

Expand Down