CitiesSkylinesMods / TMPE

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

Reduce `MaxYieldVelocity` #686

Open originalfoo opened 4 years ago

originalfoo commented 4 years ago

In #662 the 'cars stopping at yeild signs' bug was solved so well that now vehicles on Yield roads enter junctions too smoothly with no visible difference to cars on Priority roads (other than that they'll yield if necessary).

We can possibly alter MaxYieldVelocity global config var (and bump config version to make sure it gets pulled in to existing saves) to make vehicles slow down a little before entering junction so there's some visible effect of the Yield sign working.

However, it might be better to have the Yield velocity be a function of road speed (same for Stop velocity too)? For example, Yield could be 60% of segment speed limit, Stop could be 30%? Values would need experimentation to find what looks best. There would likely need to be a min speed so they don't just grind to a crawl.

brunoais commented 2 years ago

I think stop signs should cause complete stop regardless of situation. Yield makes sense to reduce. I'd make it a value between 30-90% based on (and these are all values that can be cached after the road is built):

  1. Number of lanes of opposite traffic to intersect (if 1 lane, then can just go at the 90%. If 2 lanes, then expect more reduction to 80%, 3 lanes (4-way intersection & turn left) almost grind to halt). This part should happen regardless of traffic.
  2. The intersection angle between intersecting traffic (basically, the more visible, based on the angle, the faster to proceed). 2.2 Note: I wouldn't take the buildings in the area into account there. It would be too hard to do such calculations.

E.g. So,

  1. A straight through a 90º angle with 2 way traffic could cause the speed to reduce by 50%
  2. A straight through a 90º angle with 1 way traffic could cause the speed to reduce by 30% (this should be common with roundabouts with 90º angle entrances)
  3. A straight through (or right turn) at 20º angle with 1 way traffic could cause the speed to reduce by 10% (this should be common with roundabouts with angled entrance).
  4. A straight through at 120º angle with 1 way traffic could cause the speed to reduce by 5% (lots of visibility)
  5. A left turn at 30º angle (turning all 150º) with 2 way traffic could cause the speed to reduce by min(turn speed, 30% speed).

Any opinions on this?

originalfoo commented 2 years ago

Yup, that's the key difference between stop sign and yield sign IRL.

Tagging: https://github.com/CitiesSkylinesMods/TMPE/issues/1229 (take a look at the vids in that issue) :)

brunoais commented 2 years ago

Tagging: #1229 (take a look at the vids in that issue) :)

The videos in that issue do show the yielding and stopping but they don't have different speeds for yielding when there's no other traffic to force a speed change or a complete stop.

originalfoo commented 2 years ago

Before I forget, we already have some code for determining speed based on curvature - part of the bulk applicator for roundabouts.

See:

EDIT: Notbly the posts by @scottmcm are the ones we ended up using IIRC: https://github.com/CitiesSkylinesMods/TMPE/issues/793#issuecomment-618121036 (and subsequent comments)

originalfoo commented 2 years ago

Annnnd, additionally... there's some fast math functions that can make the calcs eat less CPU:

https://github.com/Quistar-LAB/EManagersLib/blob/master/EMath.cs

krzychu124 commented 2 years ago

Annnnd, additionally... there's some fast math functions that can make the calcs eat less CPU:

https://github.com/Quistar-LAB/EManagersLib/blob/master/EMath.cs

No need, most of such "vanilla" functions are inlined because of FPS Booster patch introduced in v 0.7 - you won't see any difference or better, there is a chance that patched vanilla will be faster than this custom solution 😅

The videos in that issue do show the yielding and stopping but they don't have different speeds for yielding when there's no other traffic to force a speed change or a complete stop.

Because in code perspective they don't yield when target and incoming vehicles are on priority road. That's a missing bit + that behaviour does not work on junctions with traffic lights yet. It looks like I found a bug in the code that completely ignores MaxYieldVelocity when Simulation Accuracy is >= Medium. It works correctly on Low and Very Low... Time to fix it 😄

Low Simulation Accuracy, at higher setting vehicles on the left side don't care

https://user-images.githubusercontent.com/19638970/153069855-001ce4ed-efaa-4c60-8c8b-ca3b37c00392.mp4

brunoais commented 2 years ago

Nice that there's slowdown but I wouldn't expect a slowdown from 40 to 7. For that kind of junction (angles + traffic), I'd expect a slowdown from 40 to 20~25. But a slowdown is good for realism.

krzychu124 commented 2 years ago

Yeah, I tweaked value because I wasn't sure if it actually works.. I'm not sure if MaxYieldVelocity is that useful, since maybe it would be better to calculate it based on segment speed limit, e.g. 50% speed limit as max 🤔

originalfoo commented 2 years ago

Yup, i think MaxYieldVelocity is more of a hack due to the original implementation, and we should seek to abandon that setting.

Ideally approach speed should be based on factors such as: