Skip to content

Junction restrictions hook #1579

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d6699b2
Hook API definition
Elesbaan70 May 5, 2022
918ea2d
Fill in missing pieces
Elesbaan70 May 6, 2022
7eaf0e4
No FlagsChanged event until all the redundant mess has been eliminated
Elesbaan70 May 26, 2022
23a1294
Merge branch 'master' into junction-restrictions-hook
Elesbaan70 May 26, 2022
5461b9d
rename "invalid" restrictions to "orphaned"
Elesbaan70 May 27, 2022
1f91a91
Rename antipatterned SegmentEndId class
Elesbaan70 May 27, 2022
5fad9ae
SegmentEndId
Elesbaan70 May 27, 2022
47fd73d
Implement to-be-deprecated APIs privately, eliminate TernaryBool
Elesbaan70 May 27, 2022
438bab0
Remove a lot of redundant code
Elesbaan70 May 27, 2022
a9cfa05
FlagsAttribute missing from JunctionRestrictionFlags
Elesbaan70 May 27, 2022
3c139af
Lazy update of default values
Elesbaan70 May 27, 2022
fca9d25
Cache configurable calculations
Elesbaan70 May 28, 2022
a230ca7
Updates to IJunctionRestrictionsManager
Elesbaan70 May 28, 2022
ed2dd2a
Clean up all the redudant setters
Elesbaan70 May 28, 2022
ef6aa5b
separate and condense deprecated methods
Elesbaan70 May 28, 2022
b00d0e7
clean up some notifications
Elesbaan70 May 28, 2022
2fac55b
Make as many deprecated methods as possible public/obsolete, to help …
Elesbaan70 May 28, 2022
46eb439
several things broken
Elesbaan70 May 28, 2022
211182b
IJunctionRestrictionsHook implementation
Elesbaan70 May 28, 2022
f0a6ba1
If I don't rename this, every future developer will curse me
Elesbaan70 May 29, 2022
4280116
A couple of nasty bugs
Elesbaan70 May 29, 2022
5570ad4
Merge branch 'master' in to junction-restrictions-hook
Elesbaan70 Jun 15, 2022
636d1e2
Reconcile dulicate enum
Elesbaan70 Jun 18, 2022
485305a
Merge branch 'CitiesSkylinesMods:master' into junction-restrictions-hook
Elesbaan70 Jun 18, 2022
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
3 changes: 3 additions & 0 deletions TLM/TLM/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace TrafficManager {
using TrafficManager.API.Hook;
using TrafficManager.API.Manager;
using TrafficManager.API.Notifier;
using TrafficManager.API.UI;
Expand Down Expand Up @@ -37,6 +38,8 @@ public static float ByteToFloat(byte b) {

public static IManagerFactory ManagerFactory => Manager.Impl.ManagerFactory.Instance;

public static IHookFactory HookFactory => Hook.Impl.HookFactory.Instance;

public static IUIFactory UIFactory => UI.UIFactory.Instance;

public static INotifier Notifier => TrafficManager.Notifier.Instance;
Expand Down
19 changes: 11 additions & 8 deletions TLM/TLM/Custom/PathFinding/CustomPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,11 @@ ref nextSegmentId.ToSegment(),
#if JUNCTIONRESTRICTIONS
// next segment does not have pedestrian lanes but cims need to
// cross it to reach the next segment
if (!junctionManager.IsPedestrianCrossingAllowed(
if (!junctionManager.GetValueOrDefault(
leftSegmentId,
leftSegment.m_startNode ==
nextNodeId)) {
nextNodeId,
JunctionRestrictionFlags.AllowPedestrianCrossing)) {
break;
}
#endif
Expand Down Expand Up @@ -1122,10 +1123,11 @@ ref nextSegmentId.ToSegment(),
#if JUNCTIONRESTRICTIONS
// next segment does not have pedestrian lanes but cims need to
// cross it to reach the next segment
if (!junctionManager.IsPedestrianCrossingAllowed(
if (!junctionManager.GetValueOrDefault(
rightSegmentId,
rightSegment.m_startNode ==
nextNodeId)) {
nextNodeId,
JunctionRestrictionFlags.AllowPedestrianCrossing)) {
break;
}
#endif
Expand Down Expand Up @@ -3167,9 +3169,10 @@ private void ProcessItemPedBicycle(
if (Options.junctionRestrictionsEnabled &&
item.Position.m_segment == nextSegmentId) {
// check if pedestrians are not allowed to cross here
if (!junctionManager.IsPedestrianCrossingAllowed(
if (!junctionManager.GetValueOrDefault(
nextSegmentId,
nextIsStartNode)) {
nextIsStartNode,
JunctionRestrictionFlags.AllowPedestrianCrossing)) {
if (isLogEnabled) {
DebugLog(
unitId,
Expand Down Expand Up @@ -3587,7 +3590,7 @@ private bool ProcessItemRouted(
prevIsCarLane && // u-turns for road vehicles only
(!isHeavyVehicle_ || isStockUturnPoint) && // only small vehicles may perform u-turns OR everyone at stock u-turn points
!prevIsOutgoingOneWay && // do not u-turn on one-ways
junctionManager.IsUturnAllowed(prevSegmentId, nextIsStartNode);
junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn);

if (isLogEnabled) {
DebugLog(
Expand All @@ -3600,7 +3603,7 @@ private bool ProcessItemRouted(
$"\tisStockUturnPoint={isStockUturnPoint}\n" +
$"\tprevIsOutgoingOneWay={prevIsOutgoingOneWay}\n" +
$"\tjManager.IsUturnAllowed(prevSegmentId, " +
$"nextIsStartNode)={junctionManager.IsUturnAllowed(prevSegmentId, nextIsStartNode)}\n" +
$"nextIsStartNode)={junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn)}\n" +
$"\tm_queueItem.vehicleId={queueItem_.vehicleId}\n" +
$"\tm_queueItem.spawned={queueItem_.spawned}\n" +
$"\tprevSegmentId={prevSegmentId}\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace TrafficManager.Geometry.Impl {
using System;
using TrafficManager.API.Traffic;
using TrafficManager.Util.Extensions;

public class SegmentEndId : ISegmentEndId {
public SegmentEndId(ushort segmentId, ushort nodeId) {
[Obsolete("New code should use TrafficManager.Network.Data.SegmentId unless it needs to implement ISegmentEndId. ISegmentEndId should be deprecated in the future, and should be avoided in new APIs.")]
public class SegmentEndIdApi : ISegmentEndId {
public SegmentEndIdApi(ushort segmentId, ushort nodeId) {
SegmentId = segmentId;
StartNode = segmentId.ToSegment().IsStartNode(nodeId);
}

public SegmentEndId(ushort segmentId, bool startNode) {
public SegmentEndIdApi(ushort segmentId, bool startNode) {
SegmentId = segmentId;
StartNode = startNode;
}
Expand Down
14 changes: 14 additions & 0 deletions TLM/TLM/Hook/Impl/HookFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrafficManager.API.Hook;

namespace TrafficManager.Hook.Impl {
public class HookFactory : IHookFactory {

public static IHookFactory Instance = new HookFactory();

public IJunctionRestrictionsHook JunctionRestrictionsHook => Manager.Impl.JunctionRestrictionsManager.Instance;
}
}
4 changes: 2 additions & 2 deletions TLM/TLM/Manager/Impl/ExtNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void AddSegment(ushort nodeId, ushort segmentId) {
{
var replacement = new SegmentEndReplacement {
oldSegmentEndId = ExtNodes[nodeId].removedSegmentEndId,
newSegmentEndId = new SegmentEndId(segmentId, nodeId),
newSegmentEndId = new SegmentEndIdApi(segmentId, nodeId),
};

ExtNodes[nodeId].removedSegmentEndId = null;
Expand All @@ -100,7 +100,7 @@ public void AddSegment(ushort nodeId, ushort segmentId) {

public void RemoveSegment(ushort nodeId, ushort segmentId) {
if (ExtNodes[nodeId].segmentIds.Remove(segmentId)) {
ExtNodes[nodeId].removedSegmentEndId = new SegmentEndId(segmentId, nodeId);
ExtNodes[nodeId].removedSegmentEndId = new SegmentEndIdApi(segmentId, nodeId);
}
}

Expand Down
Loading