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

Issues with station tracks #1337

Closed
originalfoo opened this issue Jan 29, 2022 · 20 comments · Fixed by #1467
Closed

Issues with station tracks #1337

originalfoo opened this issue Jan 29, 2022 · 20 comments · Fixed by #1467
Labels
BUG Defect detected confirmed Represents confirmed issue or bug SPEED LIMITS Feature: Speed limits
Milestone

Comments

@originalfoo
Copy link
Member

originalfoo commented Jan 29, 2022

Fixed in TM:PE 11.6.5.2

Describe the problem

Had a few people on TMPE workshop page mention that speed limit overlay isn't appearing on station tracks.

Not sure if this is just related to underground stations, will need some testing.

image

image

@originalfoo originalfoo added BUG Defect detected triage Awaiting issue categorisation SPEED LIMITS Feature: Speed limits confirmed Represents confirmed issue or bug and removed triage Awaiting issue categorisation labels Jan 29, 2022
@originalfoo
Copy link
Member Author

Confirmed bug with train station tracks - the speed icon appears, and interacts (eg. changes color on hover, and lanes highlight), but clicking has no effect:

image

There are no errors in the logs.

I suspect whatever handles the "click" is doing some extra checks on the segment and for some reason deciding it's not applicable for speed limits - I'll dig through the code shortly.

image

image

image

@originalfoo
Copy link
Member Author

What are these new directions AvoidForward and AvoidBackward??

@originalfoo
Copy link
Member Author

originalfoo commented Jan 29, 2022

Ok, I'm sure I've not seen these before, but looks like we have bunch of new directions to deal with:

[Flags]
public enum Direction : byte
{
	None = 0,
	Forward = 1,
	Backward = 2,
	Both = 3,
+	Avoid = 0xC,
+	AvoidBackward = 7,
+	AvoidForward = 0xB,
+	AvoidBoth = 0xF
}

EDIT: This will obviously affect stuff like GetSortedLanes()

@originalfoo
Copy link
Member Author

originalfoo commented Jan 29, 2022

Note: Still push out 11.6.4.3 to workshop today if poss.

I think this update to directions flags is going to take a bit of time to deal with.

For example, AvoidBackward = 7, which in binary is: 0000000000000111

If my understanding of how flags work in C# is correct, that means TM:PE will be seeing that track as Forward, and Backward (ie. Both) and Avoid.

ffs, what did CO do here lol

In any case, station tracks are going to need to deal with what is effectively Both in oldspeak. As far as I know TM:PE speed limits isn't built to deal with Both direction lanes...

@originalfoo
Copy link
Member Author

originalfoo commented Jan 29, 2022

Avoid = 0xC ...in binary is 1100 = "something unknown" | Avoid

@originalfoo
Copy link
Member Author

originalfoo commented Jan 29, 2022

Updated comments above; Both = 11 so it does seem like Avoid is 4 (100) but also with an additional bit (1000) set for some weird reason?

And AvoidBackward seems completely fubar if I'm not mistaken?

@krzychu124
Copy link
Member

Avoid should surely have been value 4 and then it would be a case of just mixing the existing flags with Avoid to get the other variants of avoid directions.

No, no... I think the case here is that Avoid something should be something completely different that Forward, Backward or Both (Forward | Backward), If Avoid is 12 then AvoidBoth is also "ok" (Both | Avoid) but the other two does not make sense

@originalfoo
Copy link
Member Author

originalfoo commented Jan 29, 2022

Yeh, it's set like this:

Direction Prefer Backward Prefer Forward Backward Forward
None 0 0 0 0 0
Forward 0 0 0 0 1
Backward 0 0 0 1 0
Both 0 0 0 1 1
Avoid 0 1 1 0 0
AvoidForward 0 1 0 1 1
AvoidBackward 0 0 1 1 1
AvoidBoth 0 1 1 1 1

@krzychu124
Copy link
Member

oh.. I see that now:
AvoidBackward 7 -> 0111 and AvoidForward 11 -> 1011 so it looks like they see it not as flags in group of 4 bits 0000 but two groups of 2bits 00 00 so flags contains Both use 4 bits 0011 or 1111 but Avoids must contain both so either 01 11(7) or 1011(11)

@originalfoo
Copy link
Member Author

Even if that is the case, AvoidForward and AvoidBackward are reversed?

@krzychu124
Copy link
Member

krzychu124 commented Jan 29, 2022

If you divide that table on two groups it will make a bit more sense (normal - 4 flags, avoids - 4 flags)

Even if that is the case, AvoidForward and AvoidBackward are reversed?

Yes because you are avoiding
image

edit:
...and Avoid avoids Both

@krzychu124
Copy link
Member

I think it is related to the situation you can enter and exit segment in both ways but spawning on the segment allows moving only one direction

@originalfoo
Copy link
Member Author

Table above updated headings.

@originalfoo
Copy link
Member Author

That would be useful on central turning lanes to control "preferred" direction of traffic at segment ends

Might also possibly have some use for tidal lanes (#122) and virtual bus lanes (#123).

@krzychu124
Copy link
Member

Yes but code must check Avoids because flag & Forward != 0 will be true for Forward, Both, and other Avoids excluding Avoid

@originalfoo
Copy link
Member Author

originalfoo commented Jan 30, 2022

This is a freaking nightmare for any mod that interacts with NetInfo.Direction lol

Even Direction.None just became nightmarish to test for

@originalfoo
Copy link
Member Author

heycsl

@originalfoo originalfoo changed the title Possible issue with station tracks Issues with station tracks Jan 30, 2022
@originalfoo originalfoo pinned this issue Jan 30, 2022
@originalfoo
Copy link
Member Author

originalfoo commented Jan 30, 2022

public static NetInfo.Direction Simplify(this NetInfo.Direction dir) =>
    (byte)dir < 4
        ? dir
        : dir == Direction.Avoid
            ? Direction.None
            : (Direction)((byte)dir >> 2);

var normalDirection = someDirection.Simplify();

public const NetInfo.Direction ForwardishMask = (NetInfo.Direction)(9);
public const NetInfo.Direction BackwardishMask = (NetInfo.Direction)(6);

@originalfoo
Copy link
Member Author

algernon provided some additional detail:

It's allocated as part of the base prefab deserialization (including post-deserialization where it's allocated to lane.m_finalDirection) and isn't otherwise touched during gameplay.

@kianzarrin
Copy link
Collaborator

Oh damn I missed all the fun. I have been using avoid flags for a while and am quite familiar with them.
in this PR I have copied code from my mods into TMPE extensions regarding directions: #1487

CS has code to deal with avoid flags so I got my code from there :)

At train station:
Forward/Backward : for trains stopping at station
AvoidBackward = 4 + Forward+Backward where 4 means bypass forward (or avoid bypassing backward)
AvoidForward = 8 + Forward+Backward where 8 means bypass backward (or avoid bypassing forward)

@krzychu124 krzychu124 unpinned this issue Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Defect detected confirmed Represents confirmed issue or bug SPEED LIMITS Feature: Speed limits
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants