The International Simutrans Forum

Simutrans Extended => Simutrans-Extended development => Simutrans-Extended future development discussion => Topic started by: Vladki on February 01, 2021, 09:16:19 PM

Title: Overtaking improvements
Post by: Vladki on February 01, 2021, 09:16:19 PM
First - if the overtaking algorithm is the same as in standard - please move to standard devel section.

The overtaking as is, is very bad for trucks (player vehicles) that are slower than (private) cars. The problem demonstrates more prominently on one-way roads, where overtaking is more frequent. The problem is that the overtaking vehicle will return to its lane immediately when it enters the next tile (while the overtaken vehicle is still on previous tile). If the vehicle that is overtaken is almost at the end of the tile at the moment, it will stop immediately, because it cannot enter the next tile - it is occupied by overtaking vehicle. If the overtaken vehicle is at the beginning of the tile, the overtaking vehicle may have enough time to clear the next tile and the flow is smooth. Ironically, if the slow truck gets somehow into the overtaking lane, it may continue smoothly for quite a long distance, and be overtaken by cars in the "default" lane.

So how to solve this problem? I  have two ideas, and I'd like to hear opinions from those who know the overtaking (and other vehicle movement code) better.

1. postpone the return to the default lane one more tile - so that there is at least one free tile between the overtaking and overtaken vehicle. This is no problem on one-way road, but could cause "collisions" on two-way road.

2. allow road vehicles to enter the occupied tile, but force them to slow down to the same speed as the vehicle ahead - that will make vehicles move smoother on congested road where overtaking is not possible (lot of cars in opposite direction).

IMHO #1 might be easier to implement, but #2 looks more realistic. Spreading vehicles 1 per tile - i.e. 1 per 125 m (or 1 km in standard) is too far. It should be more in the graphics scale - 1 car per 20-30 m, i.e. 4-6 times more.

What I see as a problem in #2 is what would happen if the car ahead would have to stop (on rail crossing or crossroads), and the other who is already on the same tile would bump into it. For simplicity we could ignore that end let the cars overlap, just like it already happens at high level attractions - dozens of private cars can spawn on the same tile.

Also there may be parts of code that assume there is only (at most) 1 car in each lane (direction) on each tile.

Title: Re: Overtaking improvements
Post by: freddyhayward on February 02, 2021, 01:08:11 AM
I have been looking at overtaking code a lot recently to try and improve it. It is currently extremely complicated. I think it would be well worth simplifying the code so that changes can be more easily made.
Title: Re: Overtaking improvements
Post by: THLeaderH on February 02, 2021, 07:21:17 AM
The overtaking routine is different between for one-way roads and two-way roads. For two-way roads, a vehicle calculates the distance needed for the overtaking. If the road is clear for the calculated distance, the vehicle starts overtaking. Thus, imposing one tile clearance between the overtaken vehicle does not cause collision if the clearance is taking into account for the calculation of the needed distance.

I think that postponing the return to the default lane for one tile is a simple and effective solution, except for the situation that the overtaken vehicle is stopping for some reasons, such as loading cargos.
Title: Re: Overtaking improvements
Post by: Mariculous on February 02, 2021, 01:12:50 PM
Yes, the current overtaking mechanism causes very much stop-and-go.
Instead of the suggested "one fixed tile" rule, vehicles should already be able to switch the lane when the distance to the car behind will be as much as a full tile.
This means, for example, when the overtaken vehicle is at the middle of a tile, and at the same time the the overtaking vehicle is at the middle of the next tile, it can safely switch the lane.
That's because we assume the overtaking vehicle is faster, so it will have left that tile already when the car behind attempts to enter.
Title: Re: Overtaking improvements
Post by: Vladki on February 02, 2021, 03:29:57 PM
Quote from: Freahk on February 02, 2021, 01:12:50 PMThis means, for example, when the overtaken vehicle is at the middle of a tile, and at the same time the the overtaking vehicle is at the middle of the next tile, it can safely switch the lane.
That would be nice indeed. But from the observed behavior I assume that the logic involving overtaking and return do default lane is triggered only when crossing the tile borders. Doing that more frequently will probably use quite a lot of CPU time.
Title: Re: Overtaking improvements
Post by: jamespetts on February 13, 2021, 11:11:28 AM
I also tried to look into the overtaking code at one point, but found it difficult to parse. Given that this was not a priority issue and would consume a huge amount of time, I did not look into it further. If anyone would like to improve the overtaking algorithm, especially to implement the first (and much simpler) of Vladki's suggestions, that would be helpful.

The second of the suggestions is an order of magnitude more complex. What is really needed is a system in which multiple road vehicles (be they private cars or player vehicles) can be on the same tile going in the same direction at the same time, but limited in number, based on the proportion of their length to the tile length, and graphically line up properly on the tile. This would not only improve the appearance of the game, but (realistically) increase the capacity of roads and thus reduce the impact of congestion. Doing this would, however, be a major undertaking.