Page 1 of 1

New rail geometry

Posted: Sat May 30, 2015 4:46 pm
by tobsimon
The current rail geometry isn't all that bad, but there are some (considerable) annoyances:
- One diagonal straight track segment required between two curve segments bending in the same direction.
  See simple fix for the ugly rail circles (viewtopic.php?f=6&t=10340).
- No narrow s-bends, but narrow parallel track possible coming from diagonal direction.
- Distance between parallel tracks not uniform in diagonal versus horizontal/vertical direction (also too narrow or too far)
- The train is not centerd on the rail, and does not fit the grid along it's length.
- Track pieces are only buildable on every second tile, not everywhere.
- Unrealistic sharp curve radius for high speeds.

The new rail geometry is designed to have these properties:
- No placement restrictions for the most basic piece, the horizontal/vertical straight track.
- Diagonal track nearly as good and versatile as horizontal/vertical track.
- S-bends to connect even 1-tile off situations, also for diagonal track.
- Preferably done by adding a 22.5° diagonal.
- More realistic train and track proportions.


Railtrack
Currently, there is 48 px wide rolling stock on a 35 px track gauge (both meassured in normal zoom, 32 px per tile) and distance between tracks is 2 tiles. Real track normal gauge is 1435 mm meassured from the inside of the rails, so about 1.5 m. Rolling stock is more or less 3 m wide – twice the track gauge. (Broad gauges also tend to have wider rolling stock.) Track distance is about 4.5 meters, less on old/slow tracks, more near stations – triple the track gauge. So to make it good looking (read: somewhat proportional) in the game, the track gauge should be narrower, or the train should be bigger as should be the distance between tracks. At the very least, the train should be centered on the track...
Factorio train compared to abaout proportional normal gauge train models from another project. They are 65 px wide.
Factorio train compared to abaout proportional normal gauge train models from another project. They are 65 px wide.
Train2.png (67.26 KiB) Viewed 7802 times
I think the train should be 60 px wide (just short of 2 tiles), and the distance between tracks should be 3 tiles. Diagonal track can be build in a very similar distance (2,8), that's a plus. But two tracks 3 tiles apart, 2 tiles wide, that's 5 tiles with one inbetween - no possibility to cross with underground belts. That would require wider track distances. The one tile between tracks is useful for signals, though.


Curve Radius
Current curve radius is 10 tiles, which translates to 200 m at train proportion (48 px is 3 m, so 1 tile is 2 x 2 m) and 140 m at track proportion (35 px is 1.5 m, so 1 tile is 1.4 x 1.4 m). In the real world it's at least 300 m on mayor, 180 m on minor and 100 m on industry connecting track. All with strict speed restrictions. At 160 km/h / 100 mph, the needed radius is well above 600 m. So for slow speed, the current radius isn't unrealistic, but very much so for high speed.

When fitting rail geometry to a grid, you have to deform the curves in such a way, that both their ends fit the grid, but multiple curves together still look round. No work for 90° curves, more complicated for smaller angles. It works better for some radii than for others.
NewRailGeometry.png
NewRailGeometry.png (108.26 KiB) Viewed 7802 times
To facilitate the s-bends, the curve needs to be split at half the prallel track distance you want to bridge (red lines). These split points themselves match the grid well for the two chosen radii, and they both match more or less the 3:-1 gradient (light grey lines) that is just plain lucky. The 1 tile off s-bend now can only be done with the small radius, but I think that's acceptable. The actual split point for the two curve pieces is moved towards the 22.5° angle. This adds a whole bunch of complexity for the implementation, since there are now two variations for the end of the curve (to diagonal or continue curve), but simplifies building complexity and it simply looks better, when the two curve pieces are nearly the same length.


Without further ado, I present the very versatile and maybe much too complex
NewRailGeometry3.png
NewRailGeometry3.png (114.33 KiB) Viewed 7802 times
The straight segments all have about the same length and apart from the two special cases, everything fits the grid. The 1:3 gradient is the linchpin in the whole construction. One piece of it moves one tile further up or down in horizontal/vertical direction, thus allowing full placement freedom, and a whole tile diagonally in diagonal direction. Therefore there is just no sensible way to bridge diagonal parallel track which is a half or 1.5 tiles off (measured diagonally). But that is much to close anyway and since the horizontal/vertical direction should be the most versatile, I restricted the placement of the diagonals to every second tile. One caveat though, this restriction transfers to the curves. On the other hand, in combination with the 3 tile parallel track distance, this forces for attractive (same radius) parallel curve building. The inner curve needs to be started one tile earlier and after 45° it also ends 1 tile later, the track distance is more or less preserved.

I should stop the talk. What do you think about it? Questions and comments please.

Re: New rail geometry

Posted: Sat May 30, 2015 9:50 pm
by ssilk
Wow. I'm impressed. :)

ssilkbot says there are some more suggestions, which are somehow related:

https://forums.factorio.com/forum/vie ... =33&t=5726 [Request] New rails
https://forums.factorio.com/forum/vie ... f=6&t=9619 S-shaped rails!
https://forums.factorio.com/forum/vie ... f=6&t=3309 Additions to the train system.
https://forums.factorio.com/forum/vie ... f=6&t=8621 New tracks/rails
https://forums.factorio.com/forum/vie ... =6&t=13829 Improved rail curves

And far related:
https://forums.factorio.com/forum/vie ... f=6&t=7950 Electric trains
https://forums.factorio.com/forum/vie ... f=6&t=3463 New Locomotives and Wagons, More Trains.
https://forums.factorio.com/forum/vie ... f=6&t=1671 Some notes about trains and tracks (old but some things are still valid)
https://forums.factorio.com/forum/vie ... f=6&t=7685 Rail yard speed limits
https://forums.factorio.com/forum/vie ... =10#p61763 Automatic mining bases expansion (or eliminating the need) (and Kovarex' comment)
https://forums.factorio.com/forum/vie ... f=6&t=9606 Conveyor Belt Auto-Direction
https://forums.factorio.com/forum/vie ... f=6&t=2165 Some suggestions regarding the rail system

Edit: added https://forums.factorio.com/forum/vie ... =6&t=13829

Re: New rail geometry

Posted: Sat May 30, 2015 10:57 pm
by sillyfly
One thing I don't understand - the common lore is that 1 factorio tile = 1 square meter, so if the entire rail segment is 2 by 2 tiles, how can the gauge be more than 2 meters?

Edit: Re-reading that part, I think I may have misunderstood what you wrote. I'll read it again when I'm less tired! :shock:

Re: New rail geometry

Posted: Sun May 31, 2015 7:39 pm
by theRustyKnife
Oh yes please! I need this in the game so bad... Though I can't quite imagine a good way of building tracks when there's so many positions they can be in. I'd still prefer more freedom over inconvenient placing :D

Re: New rail geometry

Posted: Mon Jun 01, 2015 12:46 pm
by tobsimon
I'm glad this is received well. I'm especially happy to have impressed you ssilk :).
sillyfly wrote:the common lore is that 1 factorio tile = 1 square meter
Didn't know that, good to know. I simply took the track gauge and train width as reference lengths.

In some of the older topics there was the issue raised, that track building should be more convenient. Somwhere even a developer hinted, he may have a concept, and http://www.factorio.com/blog/post/fff-85 revealed, that it is on the roadmap for 0.13. Big but, now there are two radii. How would the game decide to build the narrow or the wide one, when drag-building the railtrack?

I'd hate to force players to now run around with three different rail pieces and double the number of rotations.

Lets say, there is only one rail piece - the straight - and the other stuff can only be built connecting to an existing piece. When you are near an existing rail, the hovering rail piece snaps to it. Now, when you press R, it changes (clockwise) from straight to right curve - backwards left curve - backwards right curve - left curve - and again for the wide circle. Building the curve costs 2 or 3 track pieces from your inventory. Not exactly the fastest way to build a wide left curve, kind of like it is now, since you must cycle through all 8 different curves. Also pretty far hidden away for the beginning players. Love to read your ideas on that.

Re: New rail geometry

Posted: Mon Jun 01, 2015 2:30 pm
by ssilk
tobsimon wrote:Lets say, there is only one rail piece - the straight - and the other stuff can only be built connecting to an existing piece.
Reflects exactly my thoughts from an year ago: I think that we have now two kinds of rails is just because it was easier to implement, than with one. There is also this disbalance for needed items between curves and straight rails, which is quite untypical, because most stuff is quite well balanced.

Re: New rail geometry

Posted: Mon Jun 01, 2015 5:38 pm
by DerivePi
tobsimon wrote:I'd hate to force players to now run around with three different rail pieces and double the number of rotations.

Lets say, there is only one rail piece - the straight - and the other stuff can only be built connecting to an existing piece. When you are near an existing rail, the hovering rail piece snaps to it. Now, when you press R, it changes (clockwise) from straight to right curve - backwards left curve - backwards right curve - left curve - and again for the wide circle. Building the curve costs 2 or 3 track pieces from your inventory. Not exactly the fastest way to build a wide left curve, kind of like it is now, since you must cycle through all 8 different curves. Also pretty far hidden away for the beginning players. Love to read your ideas on that.
Yes, one type of RR track that is placed dynamically as the player clicks and holds along a pathway. With that said, I forward the idea that having a very flexible RR placement may not be the best. Under the current grid system, you could click and hold a path right down the middle of two tiles and the game would know which tile the RR track is to be placed on and a curve would not be registered until the player is at least 2 tiles from the current path. With a modified flexible system, I am afraid that there will be a lot of removing and replacing of track every time the player is bumped by a tree. Further, I'd like to promote the automatic removal of trees while the player dynamically lays track/transport belt.

Re: New rail geometry

Posted: Tue Jun 02, 2015 2:19 pm
by ssilk
When I look to cities: skylines - about like placing roads there, but of course much more simplified (just drag the end of a track and after release it is built), cause - as you said - not every combination of rr-track-curve is useful.

To the laying: The raillayer-mod should also be integrated somehow, cause for laying out long distances. In the narrow area the raillyer enables the player to lay tracks in a much larger area and in combination with the personal roboport (that is promised for 0.11 or 0.12) it will also not be needed to place tracks "by hand".

I fear an explosion of graphical possibilities, cause - from aesthetical standpoint - for every type of track and combination of track you need one graphics.

Re: New rail geometry

Posted: Mon Jun 08, 2015 3:54 pm
by tobsimon
The explosion of needed sprites shoudn't be that bad. There are two variants to the curve and the 3:1 diagonal depending on the connecting rail piece, and the special cases mentioned. The variants are very similar and maybe dont even visibly differ (try to spot how the translucent pieces have a slightly different curvature while overlapping compared to the solid pieces), so they are not needed. The crossings are probably already done as any sane programmer would do, combined on the fly out of three layers (rubble, sleepers, rail) so that no combinations have to be saved beforehand.

Re: New rail geometry

Posted: Mon Jun 08, 2015 4:03 pm
by ratchetfreak
tobsimon wrote:[...] The crossings are probably already done as any sane programmer would do, combined on the flay out of three layers (rubble, sleepers, rail) so that no combinations have to be saved beforehand.
you assume the devs are sane...

In my experience such assumptions are rarely correct. Often things like legacy and just not knowing better at the time and fixes being low priority are the culprit of non-optimal code.

Re: New rail geometry

Posted: Mon Jun 08, 2015 4:21 pm
by tobsimon
If that were the case, factorio would probably be laggy as hell. Na I'm fairly certain that it's done this way, cause even with the current curve pieces, the amount of possible cross combinations is astronomical.