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

Train tracks segment speed limits #1467

Merged
merged 18 commits into from
Mar 27, 2022

Conversation

krzychu124
Copy link
Member

Closes #1337

  • changed calculation of average speed limit from the per direction to the lane vehicle type,
  • added three additional directions to the method which applies segment speed limits,
  • eliminated SpeedValue equality check boxing

@krzychu124 krzychu124 added BUG Defect detected SPEED LIMITS Feature: Speed limits regression old bug comes back or a new bug introduced in code that used to work. labels Mar 15, 2022
@krzychu124 krzychu124 self-assigned this Mar 15, 2022
TLM/TMPE.API/Traffic/Data/SpeedValue.cs Show resolved Hide resolved
TLM/TMPE.API/Traffic/Data/SpeedValue.cs Outdated Show resolved Hide resolved
Copy link
Member

@originalfoo originalfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to test in-game, but just some comment on the code for now...

When `null`, the speed will be applied to all lanes
_except_ those with `None` direction.
Removes loop of directions.
This is simplified to take advantage of the updates to
`SpeedLimitManager.Instance.SetSegmentSpeedLimit()`
in which lane direction specification is no longer mandatory.

It wipes out several loops, particularly over segment lanes.
@originalfoo originalfoo added this to the 11.6.5.2 milestone Mar 17, 2022
@originalfoo originalfoo self-requested a review March 17, 2022 05:30
@kianzarrin
Copy link
Collaborator

image
might be out of scope of this PR but do these warning need action? if not maybe we should hide them.

@krzychu124
Copy link
Member Author

image might be out of scope of this PR but do these warning need action? if not maybe we should hide them.

It's harmless in this case. We've talked about that on Discord. Warning makes sense to all custom structs but not primitive types. So for ushort is not problem but for idk. Vector3, TimeSpan it will be a problem.

@kvakvs
Copy link
Collaborator

kvakvs commented Mar 23, 2022

I think that field never changes, don't worry.

@krzychu124
Copy link
Member Author

I think that field never changes, don't worry.

warning does not warn about field but behaviour when field type is a non-readonly struct (compiler will create defensive copy on each access (create variable and set it with field value before use) to ensure original value won't ever change)

@kianzarrin
Copy link
Collaborator

if it is harmless then I think it would be wise to hide that warning. if there is too many warnings around then ppl will not pay attention and then important warnings can be ignored. but that is outside the scope of this PR.

@originalfoo
Copy link
Member

I'll send a commit to suppress that warning inline, handle a few other warnings, and also add lane type & vehicle type checks back in to the segment iteration function (in ClickMultiSegment - just to ensure we don't go iterating down non-applicable routes).

Completely useless warning for:
"A closing brace within a C# element, statement, or expression is preceded by a blank line."
Useful for checking if a segment has at least one matching lane
for `LANE_TYPES` and `VEHICLE_TYPES`.

return true;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the fact that you have not used goto nextiter :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vowed never to use goto again in 1986 :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think goto has some uses like breaking out of nested loops.

@@ -72,6 +72,41 @@ public static class NetSegmentExtensions {
return new GetSegmentLaneIdsEnumerable(initialLaneId, netInfo.m_lanes.Length, laneBuffer);
}

/// <summary>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note]
Based this code laneType or VehicleType should never be 0. Maybe we can Assert this condition even if it is only in DEBUG build?
Is there a [NotNull] or [NotZero] annotation we can use here?

in some places in CS they check forlaneType == 0 || (laneInfo.m_laneType & laneType) != 0) but I I think in speed limit manager that does not make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a DEBUG-only AssertNotNone shortcut to test both params.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind. I deleted message.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low priority]
is this critical code path. do the assertion need to be debug only?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low priority]
is this critical code path. do the assertion need to be debug only?

heh, it was your suggesstion in #1467 (comment) :

Maybe we can Assert this condition even if it is only in DEBUG build?

It's a relic from older incarnation of speed limit tool.
`AnyApplicableLane()` will never return `true` if
either of the relevant params are `None`.
@kianzarrin
Copy link
Collaborator

why the speed limit sprites are not on lanes? is it out of scope of this PR?
image

@kianzarrin
Copy link
Collaborator

another visual problem. when I hold shift on roundabout:

  • lane-wise overlay works on roundabout
  • segment-wise overlay does not (does not highlight roundabout)
  • if i shift click though it does change the speed of roundabout.

Copy link
Collaborator

@kianzarrin kianzarrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments above.

@originalfoo
Copy link
Member

  • segment-wise overlay does not (does not highlight roundabout)

Sounds like issue with the overlay (not in scope of this PR). Please create issue to track that.

why the speed limit sprites are not on lanes? is it out of scope of this PR?

That's just the way the render overlay works; for per-lane it uses icon grid with icon-sized gap in the middle. It could be improved, perhaps, but I wouldn't bother until we create a centralised overlay manager.

@kianzarrin
Copy link
Collaborator

You are right. the problem can be reproduced in master. Ill add it to the same ticket you created.

@originalfoo
Copy link
Member

@krzychu124 looks like CI server borked - can you prod it to rerun tests?

@kianzarrin
Copy link
Collaborator

👍

@krzychu124 krzychu124 merged commit 2519838 into master Mar 27, 2022
@krzychu124 krzychu124 deleted the bugfix/1337-train_tracks_speed_limits_tool branch March 27, 2022 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Defect detected regression old bug comes back or a new bug introduced in code that used to work. SPEED LIMITS Feature: Speed limits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with station tracks
4 participants