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

Don't allow lane connections between tracks disconnected due to MaxTurnAngle #684

Merged
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
2 changes: 1 addition & 1 deletion TLM/CSUtil.CameraControl
2 changes: 1 addition & 1 deletion TLM/OptionsFramework
2 changes: 1 addition & 1 deletion TLM/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
// Minor Version
// Build Number
// Revision
[assembly: AssemblyVersion("11.1.0.*")]
[assembly: AssemblyVersion("11.1.1.*")]
3 changes: 2 additions & 1 deletion TLM/TLM/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
[assembly: AssemblyConfiguration("")]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("70591292-D092-4DC5-AFB9-3AA950E240BE")]

[assembly: Guid("70591292-D092-4DC5-AFB9-3AA950E240BE")]
2 changes: 1 addition & 1 deletion TLM/TLM/RedirectionFramework
61 changes: 43 additions & 18 deletions TLM/TLM/UI/SubTools/LaneConnectorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace TrafficManager.UI.SubTools {
using TrafficManager.State;
using TrafficManager.Util.Caching;
using UnityEngine;
using System.Text.RegularExpressions;
using static TrafficManager.Util.Shortcuts;

public class LaneConnectorTool : SubTool {
private enum MarkerSelectionMode {
Expand Down Expand Up @@ -361,24 +363,24 @@ private void ShowOverlay(bool viewOnly, RenderManager.CameraInfo cameraInfo) {
continue;
}

// draw source marker in source selection mode,
// draw target marker (if segment turning angles are within bounds) and
// selected source marker in target selection mode
bool drawMarker
= ((GetMarkerSelectionMode() == MarkerSelectionMode.SelectSource)
&& laneMarker.IsSource)
|| ((GetMarkerSelectionMode() == MarkerSelectionMode.SelectTarget)
&& ((laneMarker.IsTarget
&& ((laneMarker.VehicleType & selectedMarker.VehicleType)
!= VehicleInfo.VehicleType.None)
&& CheckSegmentsTurningAngle(
selectedMarker.SegmentId,
ref netManager.m_segments.m_buffer[selectedMarker.SegmentId],
selectedMarker.StartNode,
laneMarker.SegmentId,
ref netManager.m_segments.m_buffer[laneMarker.SegmentId],
laneMarker.StartNode))
|| (laneMarker == selectedMarker)));
bool drawMarker = false;
bool SourceMode = GetMarkerSelectionMode() == MarkerSelectionMode.SelectSource;
bool TargetMode = GetMarkerSelectionMode() == MarkerSelectionMode.SelectTarget;
if ( SourceMode & laneMarker.IsSource) {
// draw source marker in source selection mode,
// make exception for markers that have no target:
foreach(var targetMarker in nodeMarkers) {
if (CanConnect(laneMarker, targetMarker)){
drawMarker = true;
break;
}
}
} else if (TargetMode) {
// selected source marker in target selection mode
drawMarker =
selectedMarker == laneMarker ||
CanConnect(selectedMarker, laneMarker);
}

// highlight hovered marker and selected marker
if (drawMarker) {
Expand Down Expand Up @@ -951,6 +953,29 @@ Color32 nodeMarkerColor
return nodeMarkers;
}

private bool CanConnect(NodeLaneMarker source, NodeLaneMarker target) {
bool ret = source != target && source.IsSource && target.IsTarget;
ret &= (target.VehicleType & source.VehicleType) != 0;

bool IsRoad(NodeLaneMarker marker) =>
(marker.LaneType & LaneArrowManager.LANE_TYPES) != 0 &&
(marker.VehicleType & LaneArrowManager.VEHICLE_TYPES) != 0;

// turning angle does not apply to roads.
bool isRoad = IsRoad(source) && IsRoad(target);

// checktrack turning angles are within bounds
ret &= isRoad || CheckSegmentsTurningAngle(
source.SegmentId,
ref GetSeg(source.SegmentId),
source.StartNode,
target.SegmentId,
ref GetSeg(target.SegmentId),
target.StartNode);

return ret;
}

/// <summary>
/// Checks if the turning angle between two segments at the given node is within bounds.
/// </summary>
Expand Down