-
Notifications
You must be signed in to change notification settings - Fork 85
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
uni-directional lane connections #1211
Conversation
…inesMods/TMPE into bidirectional-fix-784
The code is complete. this is draft just because I want to perform a few more tests. |
OK I done my tests. deleting other segments and bidirectional lanes work well. |
For some reason the value of `Options.disableDespawning` was historically inverted during de/serialization. This PR fixes that. It's based in part on new `Version` field that Kian put in PR #1211.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another round of questions :)
return (int)(LaneId * 2); | ||
else | ||
return (int)(LaneId * 2 + 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is generated version:
public override int GetHashCode() {
unchecked {
return ((int)LaneId * 397) ^ StartNode.GetHashCode();
}
}
Add also equals and Comparer to speed it up even more (autogenerated):
public bool Equals(LaneEnd other) {
return LaneId == other.LaneId && StartNode == other.StartNode;
}
public override bool Equals(object obj) {
return obj is LaneEnd other && Equals(other);
}
public static bool operator ==(LaneEnd left, LaneEnd right) {
return left.Equals(right);
}
public static bool operator !=(LaneEnd left, LaneEnd right) {
return !left.Equals(right);
}
private sealed class LaneIdStartNodeEqualityComparer : IEqualityComparer<LaneEnd> {
public bool Equals(LaneEnd x, LaneEnd y) {
return x.LaneId == y.LaneId && x.StartNode == y.StartNode;
}
public int GetHashCode(LaneEnd obj) {
unchecked {
return ((int)obj.LaneId * 397) ^ obj.StartNode.GetHashCode();
}
}
}
public static IEqualityComparer<LaneEnd> LaneIdStartNodeComparer { get; } = new LaneIdStartNodeEqualityComparer();
Plus make struct : IEquatable<LaneEnd>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would manually implementing them would speed up code? the auto-generated code seems fine.
using TrafficManager.Util; | ||
using TrafficManager.Util.Extensions; | ||
|
||
internal class ConnectionDataBase : Dictionary<LaneEnd, LaneConnectionData[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add constructor to use correct Comparer since the whole thing is a Dictionary:
public ConnectionDataBase(): base(LaneEnd.LaneIdStartNodeComparer) { }
int nodeArrayIndex = startNode ? 0 : 1; | ||
return Flags.laneConnections[laneId][nodeArrayIndex]; | ||
var key = new LaneEnd(laneId, startNode); | ||
if (connectionDataBase_.TryGetValue(key, out var targets)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace var
with the concrete type here :)
TLM/TLM/State/Configuration.cs
Outdated
@@ -257,6 +287,13 @@ public class ExtCitizenData { | |||
} | |||
} | |||
|
|||
public const int CURRENT_VERSION = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to 2
due to me robbing v1 in PR #1463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I suppose previous intention was to manage version using this:
private const string DATA_ID = "TrafficManager_v1.0";
private const string VERSION_INFO_DATA_ID = "TrafficManager_VersionInfo_v1.0";
Now we have inconsistent code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that older string-based way of doing it was grim; your int Version
approach is far easier to work with... beause it's actually usable lol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if we moved to XML we need to also change the data ID.
|
||
return Flags.laneConnections[sourceLaneId] != null && | ||
Flags.laneConnections[sourceLaneId][nodeArrayIndex] != null; | ||
return HasOutgoingConnections(sourceLaneId, IsHeadingTowardsStartNode(sourceLaneId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although not touched by this PR yet, there might be some issues with IsHeadingTowardsStartNode()
to consider as it checks specifically for NetInfo.Direction.Forward
(taking in to account inverted etc).
- What happens if direction is
Both
- Or any of the new
Avoid
things? - as detailed in Issues with station tracks #1337 (comment)
Also, that method uses foreach
which is about 2x slower than for
loop IIRC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its only used by lane arrow manager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not performance critical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave it like it is. Issue with Avoid flags was before and normal roads where user can manager lane connections are not available so I'm not sure if it's worth to improve that in this PR. IMO a bit out of scope
@krzychu124 if the code is acceptable can you please approve it before more merge conflicts appear? |
There will be merge conflict after #1465 which fixes issue with the new |
And also @aubergine10 planned to do a bit more stuff in 11.6.5.2 (probably some of them will be pushed for later anyways) before releasing TEST as stable and moving to next "major version". |
IMO we should be looking to push 11.6.5.1 to STABLE as soon as we're happy it's got no major issues. I can change 11.6.5.2 milestone to 11.6.6.0 for this PR and continuation of options refactor. Does this PR facilitate what @Elesbaan70 is planning for the displaced traffic lights stuff? |
It does not. But based on further discussions on Discord, that may be moot, so I'd say it's up to @krzychu124 to decide if that matters. |
@krzychu124 Can I merge now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
fixes #784. please see issue for more details.
Edit: as a happy coincident this change also fixes the issue with lane connector tool that got confused with bidirectional lanes.
every connection made by lane connector used to be bidirectional. Now its uni-directional unless user creates connection both ways.
highlights:
Flags
class and intoLaneConnectionManager
class.HasConnections()
andHasOutGoingConnections()
.code design: There are 3 layers:
UI layer (Lane Connector Tool) : no modification was needed.
Middle layer (Lane Connection Manager) : performs all the validations and checks before passing calls to base layer
Base Layer (used to be
Flags
but now isConnectionData
): handles getting/setting lane connection data onlybuild: https://ci.appveyor.com/api/projects/krzychu124/tmpe/artifacts/TMPE.zip?branch=bidirectional-fix-784
the commits are a mess and I was unable to fix them. just review all the commits together.
TODO:
HasConnections