Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions TLM/TLM/Manager/Impl/ExtNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ public static bool JunctionHasHighwayRules(ushort nodeId) {
return JunctionHasOnlyHighwayRoads(nodeId) && !LaneConnection.LaneConnectionManager.Instance.Sub.HasNodeConnections(nodeId);
}

public GetNodeSegmentIdsEnumerable GetNodeSegmentIds(ushort nodeId, ClockDirection clockDirection) {
public GetNodeSegmentIdsEnumerable GetNodeSegmentIds(ushort nodeId, ClockDirection clockDirection)
=> GetNodeSegmentIds(nodeId, clockDirection, null);

internal GetNodeSegmentIdsEnumerable GetNodeSegmentIds(ushort nodeId, ClockDirection clockDirection, ushort? initialSegmentId) {
ref NetNode netNode = ref nodeId.ToNode();
var initialSegmentId = GetInitialSegment(ref netNode);
initialSegmentId ??= GetInitialSegment(ref netNode);
var segmentBuffer = Singleton<NetManager>.instance.m_segments.m_buffer;
return new GetNodeSegmentIdsEnumerable(nodeId, initialSegmentId, clockDirection, segmentBuffer);
return new GetNodeSegmentIdsEnumerable(nodeId, initialSegmentId.Value, clockDirection, segmentBuffer);
}

/// <summary>
Expand Down
104 changes: 101 additions & 3 deletions TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace TrafficManager.Manager.Impl {
using TrafficManager.Util;
using TrafficManager.Util.Extensions;
using TrafficManager.Lifecycle;
using TrafficManager.Util.Iterators;

public class JunctionRestrictionsManager
: AbstractGeometryObservingManager,
Expand Down Expand Up @@ -633,7 +634,8 @@ public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) {

public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) {
bool ret = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Bend)) != NetNode.Flags.None
&& node.Info?.m_class?.m_service != ItemClass.Service.Beautification;
&& node.Info?.m_class?.m_service != ItemClass.Service.Beautification
&& IsLikelyPedestrianRoute(segmentId, startNode, true);
#if DEBUG
if (DebugSwitch.JunctionRestrictions.Get()) {
Log._Debug(
Expand Down Expand Up @@ -703,8 +705,8 @@ public bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode

// crossing is allowed at junctions and at untouchable nodes (for example: spiral
// underground parking)
bool ret = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Untouchable)) !=
NetNode.Flags.None;
bool ret = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Untouchable)) != NetNode.Flags.None
&& IsLikelyPedestrianRoute(segmentId, startNode, false);

if (logLogic) {
Log._Debug(
Expand All @@ -715,6 +717,102 @@ public bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode
return ret;
}

private static bool IsLikelyPedestrianRoute(ushort segmentId, bool startNode, bool includeAllPossible) {
#if DEBUG
bool logLogic = DebugSwitch.JunctionRestrictions.Get();
#else
const bool logLogic = false;
#endif

NetSegment segment = segmentId.ToSegment();

if (segment.Info.m_hasPedestrianLanes) {

if (logLogic) {
Log._Debug($"IsLikelyPedestrianRoute(segmentId: {segmentId}, startNode: {startNode}, includeAllPossible: {includeAllPossible})\r\t"
+ $"segment {segmentId} has pedestrian lanes"
+ $"returning true");
}

return true;
}

ushort nodeId = startNode ? segment.m_startNode : segment.m_endNode;

ushort nearestClockwiseSegId = 0;
int clockwiseDistance = 0;
foreach (var otherSegmentId in ExtNodeManager.Instance.GetNodeSegmentIds(nodeId, ClockDirection.Clockwise, segmentId)) {
if (otherSegmentId.ToSegment().Info.m_hasPedestrianLanes) {
nearestClockwiseSegId = otherSegmentId;
break;
}
++clockwiseDistance;
}

if (nearestClockwiseSegId == 0) {

if (logLogic) {
Log._Debug($"IsLikelyPedestrianRoute(segmentId: {segmentId}, startNode: {startNode}, includeAllPossible: {includeAllPossible})\r\t"
+ $"no pedestrian lanes on node {nodeId}"
+ $"returning false");
}

return false;
}

if (includeAllPossible) {

if (logLogic) {
Log._Debug($"IsLikelyPedestrianRoute(segmentId: {segmentId}, startNode: {startNode}, includeAllPossible: {includeAllPossible})\r\t"
+ $"pedestrian lanes found on segment {nearestClockwiseSegId}"
+ $"returning true");
}

return true;
}

ushort nearestCounterClockwiseSegId = 0;
int counterClockwiseDistance = 0;
foreach (var otherSegmentId in ExtNodeManager.Instance.GetNodeSegmentIds(nodeId, ClockDirection.CounterClockwise, segmentId)) {
if (otherSegmentId.ToSegment().Info.m_hasPedestrianLanes) {
nearestCounterClockwiseSegId = otherSegmentId;
break;
}
++counterClockwiseDistance;
}

if (nearestCounterClockwiseSegId == 0 || nearestClockwiseSegId == nearestCounterClockwiseSegId) {

if (logLogic) {
Log._Debug($"IsLikelyPedestrianRoute(segmentId: {segmentId}, startNode: {startNode}, includeAllPossible: {includeAllPossible})\r\t"
+ $"no pedestrian lanes on segment {segmentId}"
+ $"only one segment on node {nodeId} has pedestrian lanes"
+ $"returning false");
}

return false;
}

int distanceThisSide = clockwiseDistance + counterClockwiseDistance - 1;
int distanceOtherSide = 0;
foreach (var otherSegmentId in ExtNodeManager.Instance.GetNodeSegmentIds(nodeId, ClockDirection.Clockwise, nearestClockwiseSegId)) {
++distanceOtherSide;
if (otherSegmentId == nearestCounterClockwiseSegId)
break;
}

bool result = distanceThisSide < distanceOtherSide;

if (logLogic) {
Log._Debug($"HasAnyPedestIsLikelyPedestrianRouterianAccess(segmentId: {segmentId}, startNode: {startNode}, includeAllPossible: {includeAllPossible})\r\t"
+ $"segments with pedestrian lanes - clockwise: {nearestClockwiseSegId}, counter-clockwise: {nearestCounterClockwiseSegId}\r\t"
+ $"distanceThisSide: {distanceThisSide}, distanceOtherSide: {distanceOtherSide}\r\t"
+ $"returning {result}");
}

return result;
}

public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) {
return segmentFlags_[segmentId].IsPedestrianCrossingAllowed(startNode);
}
Expand Down