CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
576 stars 85 forks source link

Junction "turn filters" (partially enter blocked junction if turning) #46

Open originalfoo opened 5 years ago

originalfoo commented 5 years ago

This relates to PR: https://github.com/krzychu124/Cities-Skylines-Traffic-Manager-President-Edition/pull/25

Partially enter junction

But also check out this mod, specifically how the vehicles can part-enter the junction to wait for left/right turn:

EDIT: Mod linked above no longer exists, and there's nothing in web archive. Can't find source code. Mod was by pcfantasy, called "Advanced Junction Rule":

Traffic in UK does same sort of thing, only in opposite (vehicles drive on left in UK). Would be freaking awesome if this functionality could be merged in too :) It's common in Europe too.

See also: https://github.com/VictorPhilipp/Cities-Skylines-Traffic-Manager-President-Edition/issues/62

originalfoo commented 5 years ago

Filter left/right signs

There's a "green filter" or "green arrow" rule that's common in many countries

From: https://github.com/VictorPhilipp/Cities-Skylines-Traffic-Manager-President-Edition/issues/31

Not quite. The green arrow is like a Stop sign for right turns. You habe to stop first, then obey yield rules and only then you are allowed to turn right at a red traffic light.

See also: http://transblawg.eu/2004/02/03/green-arrow-in-german-traffic-gruner-pfeil-als-verkehrsschild/ (Germany and UK)

Depending on country:

originalfoo commented 5 years ago

@FireController1847 mentioned 'yellow flashing left arrow" which does similar:

pcfantasy commented 5 years ago

@FireController1847 @aubergine10

Yes, those functions are very similar as left waiting rules which is widely used in China or Japan. It is very useful if junction is large, left turn traffic can enter juction a lot first to wait for real turn.

You can check my source code to help add this function into TMPE, I detour some methods in CarAI.cs to implement this.

https://github.com/pcfantasy/AdvancedJunctionRule

originalfoo commented 5 years ago

For vehicles part-entering junction, would it not be easier to simply extend the relevant lanes out in to the junction so the cars yield normally to oncoming traffic?

originalfoo commented 5 years ago

Can everyone following this issue please review my notes on unprotected turns vs. turn on red here: https://github.com/krzychu124/Cities-Skylines-Traffic-Manager-President-Edition/issues/63#issuecomment-462480725

originalfoo commented 5 years ago

Found a workshop traffic lights asset pack that includes the yellow arrow thing: https://steamcommunity.com/sharedfiles/filedetails/?id=1535107168

I've asked the author of the asset to take a look at this thread and hopefully provide additional input.

originalfoo commented 5 years ago

I've found some arrow props which could be useful for converting some types of traffic light assets in to more advanced forms (would need definition files for the base traffic light assets to work out where exactly to place these props - an extension to #49).

Take a look at the props to see what I mean (I wonder if he can do yellow versions too?):

https://steamcommunity.com/sharedfiles/filedetails/?id=917459841

Now imagine what we could do to UK traffic lights (specifically those with "no left/right turn" signs) by adding the arrow props:

uk lights

Source of UK traffic lights shown above: https://steamcommunity.com/sharedfiles/filedetails/?id=1406118102

originalfoo commented 5 years ago

Summarising what I know so far:

Green arrow sign

  • Where: Germany, ...?
  • Looks like:
    green arrow

This sign means that, regardless of state of the traffic lights (at least in Germany), you can turn in the direction of the arrow so long as you yield to any other traffic/pedestrians. This would be an "unprotected turn", as their is risk of collision.

LOL! A traffic light that stayed red for 28 years!

Green arrow light

  • Where: Most countries
  • Looks like:
    green arrow

This light means traffic can move in the direction of the arrow, regardless of what the other lights are doing. This would be a "protected turn", with no danger of collision from other traffic/pedestrians.

Yellow flashing arrow

  • Where: USA, Spain, ...?
  • Looks like:
    flashing yellow

This light, while flashing, means traffic can move in the direction of the arrow, but must yield to any other traffic/pedestrians. This would be an "unprotected turn", as there is risk of collision.

Summary of arrow lights

There are sometimes other stages of arrow lights:

pcfantasy commented 5 years ago

@aubergine10

So I think this function is not exactly like "left waiting" rule in East Asia country.

Summary of left waiting rule in China:

(1)Left Red & Straight Red = Left Car stay in that direction (2)Left Red & Straight Green = Left Car partially enter junction(which is left waiting area) (3)Left Green & Straight Red = Left Car turn

You see, even in (2), this will be no risk of collision, because left Car will not real turn, just enter a waiting area, if juction is very large, this will very helpfull.

originalfoo commented 5 years ago

In China cars drive on the right side of road?

I'm not sure how to deal with that situation you describe.

I'm thinking basically there's combination of options that we can work with:

I'm trying to think of ways that we can handle all these situations, ideally, without adding any more UI elements....?

RDTG commented 5 years ago

Found a workshop traffic lights asset pack that includes the yellow arrow thing: https://steamcommunity.com/sharedfiles/filedetails/?id=1535107168

I've asked the author of the asset to take a look at this thread and hopefully provide additional input.

Welp i'm here. OK so, I did some extensive digging into this way back before my first SSD died and my health took a crap. So, it'd be entirely possible to have the traffic light flash a yellow arrow (with whatever parameters wanted like time of day or what not) BUT it would take a better coder than I to do it.. You could play with looping the traffic light shader on yellow, but that'd make all of the lights on the signal yellow (for instance if it has a turn arrow and a non-directional signal that'd look weird). Or you could take a crack at making a new shader and overhaul the traffic signals completely. :\ Both of these would require extensive work, to be honest, it'd be much much easier just to rewrite the traffic rules and leave the animated signal stuff be for now, however if someone does get around to implementing it I would be more than happy to rig up some test assets for it.

originalfoo commented 5 years ago

@RDTG: As there is code that knows what state a traffic light needs to be in (based on TMPE settings for junction, traffic lights, etc) it should be possible to plop a prop in the right location (see this comment for rough idea).

So the base traffic light model would have the bit where the yellow arrow would go, only it wouldn't contain a light or anything. When the traffic light prop is added to the road, the code would add in a "turned off" prop for the flashing yellow bit, aligned and positioned relative to the traffic light. Then, when time comes to flash the yellow arrow, the code places a different prop (one with flashing arrow) and removes the previous prop (the unlit one). So that gets around having to mess with shaders, etc.

The prop swapping could be constrained to what's in camera view to reduce number of props being swapped in and out.

There might be better ways to do it, but I don't know about asset creation. For example, is a traffic light "prop" just a single solid thing, or can it be a collection of props? If it could be a collection of props then we could just toggle some on and off. Maybe submeshes could be used or variation percentages? Like I say, I don't really know what is possible 'within' a prop asset.

FireController1847 commented 5 years ago

This sounds very cool and I look forward to seeing it implemented. However, what is the plan for different regions of the world? Driving can be very, very different all the time, and as we've seen here, this "yellow flashing" or "left yield" or whatever seems to act differently in different parts of the world. How would we know how to implement this if we don't have truly one thing to implement it on? Will we end up implementing every different version of this and make it an option?

originalfoo commented 5 years ago

@FireController1847 : I was thinking of a combination of existing settings could cover most cases.

To elaborate on an earlier comment:

If we knew where conflict points are, we could further refine the 'priority' state (eg. if no conflict points for current traffic signal state, cars would not need to yeild maybe)?

Those are just very rough ideas.

BTW, for China situation, I don't even know if it's possible to get both green and red lights active (for a single traffic light prop) at the same time?

originalfoo commented 5 years ago

Another approach would be, assuming we make a much better UI for timed traffic lights, to be able to add 'flags' (as in tags) to traffic light states, and somehow have those influence things?

pcfantasy commented 5 years ago

@aubergine10

Agree with your setting.

In China, if there is only single traffic light prop, left waiting rule is not allowed in that junction.

And what`s more, Left waiting function is done by me in this mod based on TMPE https://steamcommunity.com/sharedfiles/filedetails/?id=1647686914 https://github.com/pcfantasy/AdvancedJunctionRule

  1. I detour TMPE MayChangeSegment method to get traffic light states
  2. When left is red, straight is green, let left car go and save some data to get (current stop position and the first position after left turn)
  3. Detour CarAI.SimulationStep to make left car stop again inside junction, (about 1/3 bettween current stop position and the first position after left turn)
  4. When left is green, let car go again.

This is for your reference, maybe there is a better way to implement this.

originalfoo commented 5 years ago

Currently Enter blocked junction has only 2 states: on / off

We could add third state: on / partial / off

The partial would define whether vehicles can part-enter junction when doing far-side turns.

EDIT: So it would become:

And the stop/yield/priority signs defines how traffic from different segments gets prioritised in race conditions.

originalfoo commented 5 years ago

If #3 is implemented, which in turn allows #4, we could automatically determine how far in to a junction cars can move to wait to turn.

This wouldn't require the visualisation aspects of #4, just some of the collision detection code:

This would mean that we could work out the in-junction stop/yield point for any FS lane. Also, if we find there is no conflict point (due to user making good traffic light settings), they won't even need to yield/stop. It would work on any road, even small roads (on small roads they only pull in to junction by tiny amount).

originalfoo commented 5 years ago

List of "yellow traps": https://midimagic.sgc-hosting.com/yeltrp.htm

Lots of info on left-turns (from perspective of vehicles driving on right): https://midimagic.sgc-hosting.com/lagdef.htm

Not entirely related to this topic, but a huge list of road design fallacies that will be useful for future reference: https://midimagic.sgc-hosting.com/trafalcy.htm