From 6bf0b7d2fb16d0cdcf0d00a52afa8659d8ac14f1 Mon Sep 17 00:00:00 2001 From: "kian.zarrin" Date: Sun, 26 Jan 2020 16:07:36 +0200 Subject: [PATCH 1/6] Boosted lane connector hovering raycast. removed unnecessary setter for SubTool.Hovered*Id tested and works --- TLM/TLM/UI/SubTool.cs | 12 ++++-------- TLM/TLM/UI/SubTools/LaneArrowTool.cs | 1 - TLM/TLM/UI/SubTools/LaneConnectorTool.cs | 19 ++---------------- TLM/TLM/UI/TrafficManagerTool.cs | 25 ++++++++++++++++++++++-- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/TLM/TLM/UI/SubTool.cs b/TLM/TLM/UI/SubTool.cs index 6d953e3e7..e70f78891 100644 --- a/TLM/TLM/UI/SubTool.cs +++ b/TLM/TLM/UI/SubTool.cs @@ -78,15 +78,11 @@ private Texture2D BorderlessTexture { private GUIStyle borderlessStyle_; - protected virtual ushort HoveredNodeId { - get => TrafficManagerTool.HoveredNodeId; - set => TrafficManagerTool.HoveredNodeId = value; - } + protected virtual ushort HoveredNodeId => TrafficManagerTool.HoveredNodeId; - protected virtual ushort HoveredSegmentId { - get => TrafficManagerTool.HoveredSegmentId; - set => TrafficManagerTool.HoveredSegmentId = value; - } + protected virtual ushort HoveredSegmentId => TrafficManagerTool.HoveredSegmentId; + + protected virtual uint HoveredLaneId => TrafficManagerTool.HoveredLaneId; protected ushort SelectedNodeId { get => TrafficManagerTool.SelectedNodeId; diff --git a/TLM/TLM/UI/SubTools/LaneArrowTool.cs b/TLM/TLM/UI/SubTools/LaneArrowTool.cs index 28884f859..a310b047d 100644 --- a/TLM/TLM/UI/SubTools/LaneArrowTool.cs +++ b/TLM/TLM/UI/SubTools/LaneArrowTool.cs @@ -162,7 +162,6 @@ protected override ushort HoveredNodeId { } return base.HoveredNodeId; } - set => base.HoveredNodeId = value; } /// diff --git a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs index 590a444cd..4121e4b99 100644 --- a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs +++ b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs @@ -11,6 +11,7 @@ namespace TrafficManager.UI.SubTools { using State.Keybinds; using UnityEngine; using Util.Caching; + using static Util.Shortcuts; public class LaneConnectorTool : SubTool { private enum MarkerSelectionMode { @@ -203,8 +204,7 @@ private void ShowOverlay(bool viewOnly, RenderManager.CameraInfo cameraInfo) { // bounds.center = laneMarker.position; // bounds.IntersectRay(mouseRay); - bool markerIsHovered = IsLaneMarkerHovered(laneMarker, ref mouseRay); - + bool markerIsHovered = laneMarker.LaneId == HoveredLaneId; // 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 @@ -264,21 +264,6 @@ bool drawMarker } // end for node in all nodes } - private bool IsLaneMarkerHovered(NodeLaneMarker laneMarker, ref Ray mouseRay) { - Bounds bounds = new Bounds(Vector3.zero, Vector3.one) { - center = laneMarker.Position - }; - - if (bounds.IntersectRay(mouseRay)) { - return true; - } - - bounds = new Bounds(Vector3.zero, Vector3.one) { - center = laneMarker.SecondaryPosition - }; - return bounds.IntersectRay(mouseRay); - } - public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) { // Log._Debug($"LaneConnectorTool: RenderOverlay. SelectedNodeId={SelectedNodeId} // SelectedSegmentId={SelectedSegmentId} HoveredNodeId={HoveredNodeId} diff --git a/TLM/TLM/UI/TrafficManagerTool.cs b/TLM/TLM/UI/TrafficManagerTool.cs index c65314500..82be8674c 100644 --- a/TLM/TLM/UI/TrafficManagerTool.cs +++ b/TLM/TLM/UI/TrafficManagerTool.cs @@ -20,6 +20,7 @@ namespace TrafficManager.UI { using SubTools.SpeedLimits; using Util; using UnityEngine; + using static Util.Shortcuts; [UsedImplicitly] public class TrafficManagerTool @@ -28,9 +29,12 @@ public class TrafficManagerTool { private ToolMode toolMode_; private NetTool _netTool; + private bool _requireHoveredLane => _activeSubTool is LaneConnectorTool; internal static ushort HoveredNodeId; internal static ushort HoveredSegmentId; + internal static uint HoveredLaneId; + private static bool _mouseClickProcessed; @@ -943,8 +947,12 @@ private bool DetermineHoveredElements() { if (HoveredNodeId != 0) { HoveredSegmentId = GetHoveredSegmentFromNode(); } - } + if(HoveredSegmentId != 0 && _requireHoveredLane) { + DetermineHoveredLane(); + } + + } return HoveredNodeId != 0 || HoveredSegmentId != 0; } @@ -988,8 +996,21 @@ private static float GetAngle(Vector3 v1, Vector3 v2) { return ret; } - /// + private void DetermineHoveredLane() { + NetSegment segment = GetSeg(HoveredSegmentId); + segment.GetClosestLanePosition( + m_mousePosition, + LaneArrowManager.LANE_TYPES, + LaneArrowManager.VEHICLE_TYPES, + out Vector3 pos, + out uint laneID, + out int laneIndex, + out float laneOffset); + HoveredLaneId = laneID; + } + + /// /// Displays lane ids over lanes /// private void GuiDisplayLanes(ushort segmentId, From 546941f96a0e05748225e822b5031fca4a57fc8a Mon Sep 17 00:00:00 2001 From: "kian.zarrin" Date: Sun, 26 Jan 2020 16:38:15 +0200 Subject: [PATCH 2/6] minor fix. --- TLM/TLM/UI/TrafficManagerTool.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TLM/TLM/UI/TrafficManagerTool.cs b/TLM/TLM/UI/TrafficManagerTool.cs index 82be8674c..a00c13b3f 100644 --- a/TLM/TLM/UI/TrafficManagerTool.cs +++ b/TLM/TLM/UI/TrafficManagerTool.cs @@ -29,7 +29,6 @@ public class TrafficManagerTool { private ToolMode toolMode_; private NetTool _netTool; - private bool _requireHoveredLane => _activeSubTool is LaneConnectorTool; internal static ushort HoveredNodeId; internal static ushort HoveredSegmentId; @@ -829,6 +828,7 @@ public bool DoRayCast(RaycastInput input, out RaycastOutput output) { private bool DetermineHoveredElements() { HoveredSegmentId = 0; HoveredNodeId = 0; + HoveredLaneId = 0; bool mouseRayValid = !UIView.IsInsideUI() && Cursor.visible && (_activeSubTool == null || !_activeSubTool.IsCursorInPanel()); @@ -948,7 +948,7 @@ private bool DetermineHoveredElements() { HoveredSegmentId = GetHoveredSegmentFromNode(); } - if(HoveredSegmentId != 0 && _requireHoveredLane) { + if(HoveredSegmentId != 0) { DetermineHoveredLane(); } From 8c2793260dfdf6b55f23d64d5c04c422b2ae243d Mon Sep 17 00:00:00 2001 From: "kian.zarrin" Date: Sun, 26 Jan 2020 16:42:19 +0200 Subject: [PATCH 3/6] --- TLM/TLM/UI/TrafficManagerTool.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TLM/TLM/UI/TrafficManagerTool.cs b/TLM/TLM/UI/TrafficManagerTool.cs index a00c13b3f..78d864317 100644 --- a/TLM/TLM/UI/TrafficManagerTool.cs +++ b/TLM/TLM/UI/TrafficManagerTool.cs @@ -34,7 +34,6 @@ public class TrafficManagerTool internal static ushort HoveredSegmentId; internal static uint HoveredLaneId; - private static bool _mouseClickProcessed; private const bool HoverPrefersSmallerSegments = true; @@ -951,7 +950,6 @@ private bool DetermineHoveredElements() { if(HoveredSegmentId != 0) { DetermineHoveredLane(); } - } return HoveredNodeId != 0 || HoveredSegmentId != 0; } From 7fd4eda9494cf7a6f87f63a1903dd3ef585b3030 Mon Sep 17 00:00:00 2001 From: "kian.zarrin" Date: Sun, 26 Jan 2020 16:55:27 +0200 Subject: [PATCH 4/6] fixed merge --- TLM/TLM/UI/SubTools/LaneConnectorTool.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs index 3da66c947..6a0dd95ae 100644 --- a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs +++ b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs @@ -277,6 +277,19 @@ private bool IsLaneMarkerHovered(NodeLaneMarker laneMarker, ref Ray mouseRay) { return bounds.IntersectRay(mouseRay); } + /// + /// Finds the first index for which node.GetSegment(index) != 0 (its possible node.m_segment0 == 0) + /// + 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} From c0e2652405bbff2fb0cbeb02cc9cfd6da2a8be42 Mon Sep 17 00:00:00 2001 From: "kian.zarrin" Date: Wed, 29 Jan 2020 16:54:43 +0200 Subject: [PATCH 5/6] use hit pos instead of mouse pos --- TLM/TLM/UI/SubTools/LaneConnectorTool.cs | 15 --------------- TLM/TLM/UI/TrafficManagerTool.cs | 13 ++++++++----- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs index 6a0dd95ae..532e6fd96 100644 --- a/TLM/TLM/UI/SubTools/LaneConnectorTool.cs +++ b/TLM/TLM/UI/SubTools/LaneConnectorTool.cs @@ -262,21 +262,6 @@ bool drawMarker } // end for node in all nodes } - private bool IsLaneMarkerHovered(NodeLaneMarker laneMarker, ref Ray mouseRay) { - Bounds bounds = new Bounds(Vector3.zero, Vector3.one) { - center = laneMarker.Position - }; - - if (bounds.IntersectRay(mouseRay)) { - return true; - } - - bounds = new Bounds(Vector3.zero, Vector3.one) { - center = laneMarker.SecondaryPosition - }; - return bounds.IntersectRay(mouseRay); - } - /// /// Finds the first index for which node.GetSegment(index) != 0 (its possible node.m_segment0 == 0) /// diff --git a/TLM/TLM/UI/TrafficManagerTool.cs b/TLM/TLM/UI/TrafficManagerTool.cs index f1eee82d2..a98c743dd 100644 --- a/TLM/TLM/UI/TrafficManagerTool.cs +++ b/TLM/TLM/UI/TrafficManagerTool.cs @@ -948,7 +948,7 @@ private bool DetermineHoveredElements() { } if(HoveredSegmentId != 0) { - DetermineHoveredLane(); + DetermineHoveredLane(segmentOutput.m_hitPos); } } return HoveredNodeId != 0 || HoveredSegmentId != 0; @@ -995,12 +995,15 @@ private static float GetAngle(Vector3 v1, Vector3 v2) { } /// - private void DetermineHoveredLane() { + /// Determine the + /// + /// + private void DetermineHoveredLane(Vector3 hitPos) { NetSegment segment = GetSeg(HoveredSegmentId); segment.GetClosestLanePosition( - m_mousePosition, - LaneArrowManager.LANE_TYPES, - LaneArrowManager.VEHICLE_TYPES, + hitPos, + NetInfo.LaneType.All, + VehicleInfo.VehicleType.All, out Vector3 pos, out uint laneID, out int laneIndex, From 3f67fe373b16e69e11d44a17e39bd067c22078f2 Mon Sep 17 00:00:00 2001 From: "kian.zarrin" Date: Wed, 29 Jan 2020 17:04:56 +0200 Subject: [PATCH 6/6] fixed bridge issue --- TLM/TLM/UI/TrafficManagerTool.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TLM/TLM/UI/TrafficManagerTool.cs b/TLM/TLM/UI/TrafficManagerTool.cs index a98c743dd..977b60565 100644 --- a/TLM/TLM/UI/TrafficManagerTool.cs +++ b/TLM/TLM/UI/TrafficManagerTool.cs @@ -944,7 +944,7 @@ private bool DetermineHoveredElements() { } if (HoveredNodeId != 0) { - HoveredSegmentId = GetHoveredSegmentFromNode(); + HoveredSegmentId = GetHoveredSegmentFromNode(segmentOutput.m_hitPos); } if(HoveredSegmentId != 0) { @@ -957,10 +957,10 @@ private bool DetermineHoveredElements() { /// /// returns the node segment that is closest to the mouse pointer based on angle. /// - internal ushort GetHoveredSegmentFromNode() { + internal ushort GetHoveredSegmentFromNode(Vector3 hitPos) { ushort minSegId = 0; NetNode node = NetManager.instance.m_nodes.m_buffer[HoveredNodeId]; - Vector3 dir0 = m_mousePosition - node.m_position; + Vector3 dir0 = hitPos - node.m_position; float min_angle = float.MaxValue; Constants.ServiceFactory.NetService.IterateNodeSegments( HoveredNodeId,