Page 1 of 2

Signal auto complete fix

Posted: 23 Dec 2007 15:37
by Buhmann
Please note that this is my very first patch and that I've never done anything like this before, so expect bad coding etc.

Nevertheless I think this is a small but usefull patch.

When you use the function to automatically build signals on a track with a choosen density, you end up having really large blocks around tunnels or bridges, because signals are simply left out.

With my patch, the code checks wether a signal would be placed in a tunnel or on a bridge. If that's the case, the code forces a signal to appear before the bridge/tunnel. The code also checks if a signal behind a tunnel/bridge would be useful and builds it if needed.

In other words, the code now uses signal blocks that are shorter than the choosen density to keep other signal blocks from becoming larger than they have to be.

Screenshot here

Re: Signal auto complete fix

Posted: 23 Dec 2007 15:51
by Draakon
theres already a feature like this in the trunk.

Re: Signal auto complete fix

Posted: 23 Dec 2007 16:30
by Wolf01
not so true
the trunk feature places signals every XX tiles, if it encounters a tunnel, that tile is skipped, so you end up with a larger gap between two signals with the tunnel in the middle (as Buhmann said)
his patch instead sees the tunnel, if the tunnel is smaller than the prefixed gap it does nothing but it places a signal at the tunnel entrances if needed, mainly because the tunnel is just in the tile where the signal should be
like

Code: Select all

the . are the signals, - the track and )( the tunnel

TRUNK
--.---)   (---.-----------.-----------
--.---------)   (---------.-----------
              ^
signal should be here

his PATCH
--.---)   (---.-----------.-----------
--.--------.)   (.-----------.-----------
and i think is a great feature, very useful also for bridges

Re: Signal auto complete fix

Posted: 23 Dec 2007 16:37
by Bilbo
So basically a bigfix to the code already in trunk ... I hope this bugfix make it there too. Is it reported in bugtracker at bugs.openttd.org?

Re: Signal auto complete fix

Posted: 23 Dec 2007 16:45
by Buhmann
@Wolf01 not exactly ;)
In your example, the signal right after the last tunnel is unnecessary, because the tunnel is shorter than the preferred distance between two signals.

Code: Select all

1. Placing signals before tunnels

TRUNK
--.---)   (---.-----------.-----------
--.---------)   (---------.-----------
   \_____________________/
       block too long


MY PATCH
--.---)   (---.-----------.-----------
--.--------.)   (------.-----------.--


2. Placing signals after tunnels

TRUNK
--.-----------.)   (------.-----------.--
--.-----------.)       (--.-----------.--
--.-----------.)           (----------.--
               \_____________________/
                    block too long
MY PATCH
--.-----------.)   (------.-----------.--
--.-----------.)       (--.-----------.--
--.-----------.)           (.-----------.

Re: Signal auto complete fix

Posted: 23 Dec 2007 16:48
by Wolf01
ah ok, it checks also the length of the tunnel, less signal entropy ;)

Re: Signal auto complete fix

Posted: 23 Dec 2007 16:51
by Psistorm
thats a great patch, I hope it makes it into trunk :) - thats pretty much the optimum behaviour for signal placement, so it sure has my vote, for what it is worth ;)

Re: Signal auto complete fix

Posted: 24 Dec 2007 00:14
by RMJ
very nice :) while you are at it, if you could also fix the signal placement behavior on / & \ kind of tracks, because the gaps on diagonal always becomes to big compared to straight tracks xD

Re: Signal auto complete fix

Posted: 24 Dec 2007 00:25
by Bilbo
I am not sure with that, but aren't trains placed diagonally also proportinally longer and move proportionally faster? Then the same spacing would be fine ...

Re: Signal auto complete fix

Posted: 24 Dec 2007 02:24
by athanasios
Small but clever patch. Thanks.

Re: Signal auto complete fix

Posted: 24 Dec 2007 08:21
by Shrekko
Good Job!!! I always had to place them by myself and that costs a lot of time...

Re: Signal auto complete fix

Posted: 24 Dec 2007 09:32
by pavel1269

Code: Select all

TRUNK
--.-----------.)   (------.-----------.--
--.-----------.)       (--.-----------.--
--.-----------.)           (----------.--
               \_____________________/
                    block too long
PATCH
--.-----------.)   (------.-----------.--
--.-----------.)       (--.-----------.--
--.-----------.)           (.-----------.
i must say, i like the trunk version, since after tunnel

Code: Select all

--.--
--.--
--.--
and as i understand with your patch it will be

Code: Select all

--.--
--.--
---.-
this will be just another thing which will make building tracks for me harder :(

Re: Signal auto complete fix

Posted: 24 Dec 2007 10:18
by Bilbo
So make this fix optional (toggleble in constructuion settings)? Since it seems there are people who like the old behaviour.

Re: Signal auto complete fix

Posted: 24 Dec 2007 11:53
by Buhmann
@pavel

I've thought about that problem, but, if you want your track good looking, you would build tunnels for all tracks anyway, wouldn't you?

If I build tunnels on a two-way track, both tracks get their own tunnel.

And, furthermore, I have no idea how to add a toggle as Bilbo described :D. That way my first patch, and I'm far from understanding the ottd source code...
I'll try it, but I don't promise anything.

Re: Signal auto complete fix

Posted: 24 Dec 2007 12:32
by Bilbo
Buhmann wrote:And, furthermore, I have no idea how to add a toggle as Bilbo described :D.
Add the variable to src/variables.h in the "struct Patches" - perhaps under the "bool enable_signal_gui" add line like "bool signal_autocomplete_mode" or alike with explanation of what the variable does

Look in src/settings.cpp and look for line "const SettingDesc _patch_settings[] = {" and the lines onward. These contain definition of patch settings, so add line there too for the patch settings, like:
SDT_BOOL(Patches, signal_autocomplete_mode, S, 0, false, STR_CONFIG_SIGNAL_AUTOCOMPLETE_MODE, NULL),

Next, open src/lang/english.txt and add english translation of the string used:

STR_CONFIG_SIGNAL_AUTOCOMPLETE_MODE :Use new mode of signal autocomplete

Now just add some checking like "if (_patches.signal_autocomplete_mode) new_behavior; else old_behavior;

and you're done :)

Re: Signal auto complete fix

Posted: 24 Dec 2007 14:30
by Buhmann
You forgot the settings_gui.cpp ;)

Ok, here is the new version of the patch.

Re: Signal auto complete fix

Posted: 24 Dec 2007 19:23
by Born Acorn
Please don't inline images when they're so large, thanks.

Re: Signal auto complete fix

Posted: 26 Dec 2007 01:50
by Bilbo
Buhmann wrote:You forgot the settings_gui.cpp ;)
Now I see .. you have to add line in one of the patch dialog tabs there too so it will appear in the dialog. I forgot that :)

Re: Signal auto complete fix

Posted: 10 Feb 2008 15:51
by Buhmann
So - is there any chance that this patch will make it into trunk?

Re: Signal auto complete fix

Posted: 10 Feb 2008 17:01
by PhilSophus
Buhmann wrote:So - is there any chance that this patch will make it into trunk?
Did you post it to http://bugs.openttd.org? If not, do that and await the comments of the developers.