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

fixed stay in lane when node.m_segment0 == 0 #619

Merged
merged 3 commits into from
Jan 23, 2020
Merged
Changes from 2 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
19 changes: 16 additions & 3 deletions TLM/TLM/UI/SubTools/LaneConnectorTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TrafficManager.UI.SubTools {
namespace TrafficManager.UI.SubTools {
using System.Collections.Generic;
using System.Linq;
using ColossalFramework;
Expand Down Expand Up @@ -279,6 +279,19 @@ private bool IsLaneMarkerHovered(NodeLaneMarker laneMarker, ref Ray mouseRay) {
return bounds.IntersectRay(mouseRay);
}

/// <summary>
/// Finds the first index for which node.GetSegment(index) != 0 (its possible node.m_segment0 == 0)
/// </summary>
private static int GetFirstSegmentIndex(NetNode node) {
for (int i = 0; i < 8; ++i) {
if (node.GetSegment(i) != 0) {
return i;
}
}
Log.Error("GetFirstSegmentIndex: Node does not have any segments");
return 0;
}

public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) {
// Log._Debug($"LaneConnectorTool: RenderOverlay. SelectedNodeId={SelectedNodeId}
// SelectedSegmentId={SelectedSegmentId} HoveredNodeId={HoveredNodeId}
Expand Down Expand Up @@ -361,15 +374,15 @@ public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) {

if (nodeMarkers != null) {
selectedMarker = null;

int forwardSegmentIndex = GetFirstSegmentIndex(nodesBuffer[SelectedNodeId]);
foreach (NodeLaneMarker sourceLaneMarker in nodeMarkers) {
if (!sourceLaneMarker.IsSource) {
continue;
}

if ((stayInLaneMode == StayInLaneMode.Forward) ||
(stayInLaneMode == StayInLaneMode.Backward)) {
if ((sourceLaneMarker.SegmentIndex == 0)
if ((sourceLaneMarker.SegmentIndex == forwardSegmentIndex)
^ (stayInLaneMode == StayInLaneMode.Backward)) {
continue;
}
Expand Down