Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Mon Aug 20, 2018 12:45 pm

All times are UTC




Post new topic  Reply to topic  [ 44 posts ]  Go to page 1 2 3 Next
Author Message
 Post subject: Logic Signals patch
PostPosted: Wed Aug 21, 2013 6:03 pm 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
Hi guys, this is my first OpenTTD patch. It is similar to the Programmable Signals patch.

  • Uses the one-way PBS signal sprite for now.
  • You can link signals together, and evaluate them using boolean AND, OR, XOR and NOT operators.
  • Each logic signal can have multiple inputs, but each signal can only have one outgoing link.
  • For now, they are one-way signals, but I think they would work as two-way also.
  • For now, they do not interact with pre-, combo- or exit-signals. I think I will add that also.
  • The plan is to add visual representation for the signal links.

Attachment:
logic_signals.png
logic_signals.png [ 10.27 KiB | Viewed 9565 times ]


The first setting determines which color this signal is by default, e.g. when it is not triggered by the inputs. The second setting determines which color acts as logical 1 in the input signals. The third is the self-explanatory operator to use when evaluating the signal value. The NOT-operator just reverses the state of the first linked signal (so don't bother linking more than 1 to it).

The button to program a signal is on the main rail toolbar for now. It is not ideal, but worked out better for me than having it in the signals GUI directly.

Attachment:
LogicSignals_r25739.diff [82.03 KiB]
Downloaded 873 times


Binary download for windows (sorry no music): http://www.crmreservations.com/LogicSignals_r25745_win32.zip

Please provide feedback, bug reports, and the like.

Edit: Fixed download link for binary version.


Last edited by maddy_ on Thu Nov 14, 2013 11:27 am, edited 8 times in total.

Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Wed Aug 21, 2013 6:13 pm 
Offline
Tycoon
Tycoon

Joined: Wed Apr 27, 2005 7:09 am
Posts: 5237
In case you don´t know, you might take a look into TTDPatch´s programmable and restricted signals, to get an idea what features had already been implemented there.

regards
Michael

_________________
Image


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Wed Aug 21, 2013 7:39 pm 
Online
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 7091
maddy_ wrote:
  • Uses the one-way PBS signal sprite for now.

remind me again why you didn't use one of the 2 currently unused signal graphics?


anyway, perspecively, i'd like to see these features:

  1. Signal Templates:
    • remove all the built-in hardcoded signals, and replace them by customizable signal types
    • you can also add as many signal templates as you like
    • for each signal template you can choose one of the (8) builtin sprites. on the map, only the visual representation is stored (for drawing), the behaviour of the signal is stored off-map (for train movement, pathfinder, etc)
    • the behaviour of the template can be programmed like any individual signal
    • the input cannot be a specific signal, only "all signals of template <Y>" (possibly multiple of these)
    • the default templates will represent the current signal types, but you can add/remove/change their behaviour as you like
    • default template properties:
      1. block signal: acts as block signal, does not depend on any input signals, defaults to green
      2. entry signal: acts as block signal, depends on all signals of <exit signal> and <combo signal>, operator: and, inputs red, output red. defaults to greeen
      3. exit signal: acts as block signal, does not depend on any input signals, defaults to green
      4. combo signal: acts as block signal, depends on all signals of <exit signal> and <combo signal>, operator: and, inputs red, output red. defaults to greeen
      5. two-way path signal: acts as path signal, defaults to green (note: see below for behaviour details), can be passed from behind
      6. one-way path signal: acts as path signal, defaults to green, cannot be passed from behind
  2. Programmable Path Signals:
    this is typically a very neglected feature of this kind of patches, but it's the only feature that will even begin to make me try out the patch.
    • programmable signals get a switch "acts as block signal" and "acts as path signal"
    • block signals show red when a train is in the block, or the programmable signal state (red or green) when no train is in the block. (that means, you cannot program the signal to crash trains, safety always overrides the programmed output
    • path signals show red when no train is near, and green when a train reserved the path. the programmable signal state (red or green) is not shown, but used to determine whether a train can reserve a path through the signal. the reservation may still fail later on because of the track not being free.
    • input for a path signal is not a signal state, but the reservation state of a trackbit (or tile for simplicity)
  3. Restricted Signals:
    the "output" of this is not a signal state, but a pathfinder penalty (either a number or "dead end"). possible input values to be determined (signal states, train properties). the restriction is not checked globally, but only for the first <n> signals and the last signal, that are currently already checked for pathfinding (default: n=10)
  4. Timed Signals:
    signals get a "timetable", and a "start date" (for synchronisation). for every given duration, one method of operation is chosen for the signal output

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Thu Aug 22, 2013 2:38 pm 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
I did not know there was any unused signal graphics, or I might have used them.

As for the other comments, my goal is not to include all possible features and choices here. I was rather trying to do a sort of minimalistic approach, with somewhat clean and simple code, which handles the most common cases such as priority signals. If you want something else, go ahead and create a fork of my patch and add features, but that is not my interest right now.

The idea here is that a single logic signal is somewhat simple to understand and use, but then you can create fairly complex stuff by linking them together if you wish to.


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Thu Aug 22, 2013 5:59 pm 
Offline
Chief Executive
Chief Executive
User avatar

Joined: Mon Jan 14, 2008 3:51 pm
Posts: 644
Location: PL
maddy_ wrote:
but each signal can only have one outgoing link
This could be improved easily. Just forbid creating cycles.

Don't modify MSVC project files manually. List all new files in ./source.list and then use ./projects/generate.vbs to generate project files.

saveload/logic_signals_sl.cpp wrote:
struct TempStorage ...
Try harder when naming things.

command.cpp wrote:
DEF_CMD(CmdProgramLogicSignal, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_PROGRAM_LOGIC_SIGNAL
Perhaps this command should be of type CMDT_OTHER_MANAGEMENT to allow reprogramming signals while paused.

logic_signals_program.cpp wrote:
for (SignalReference *sref = this->linked_signals.Begin(); sref != this->linked_signals.End(); sref++)
{
...
Coding style - remove newline before opening brace.

logic_signals.cpp wrote:
try { return _signal_program_list.at(GetSignalReference(tile, track)); } catch (...) { return NULL; }
...
try { return _signal_link_list.at(GetSignalReference(tile, track)); } catch (...) { return NULL; }
Don't use exceptions to implement logic. It's not an exceptional situation when an item is not in the container. Use std::map::find instead.

logic_signals.h wrote:
#define OPPOSITE_SIGNAL_STATE(state) ((state) == SIGNAL_STATE_RED ? SIGNAL_STATE_GREEN : SIGNAL_STATE_RED)
...
#define MAX_LOGIC_SIGNAL_RECURSIONS 5
Avoid macros. Use a static inline function and a static const variable instead.

logic_signals_cmd.cpp wrote:
if (CheckTileOwnership(tile).Failed()) return_cmd_error(STR_ERROR_OWNED_BY);
It should be
Code:
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret

logic_signals_gui.cpp wrote:
if (IsWidgetLowered(WID_PROGSIG_ADD_LINK))
SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT, this);
else
ResetObjectToPlace();
Coding style - surround if/else sections with braces.

Quote:
logic_signal_program.cpp
logic_signals_cmd.cpp
logic_signals.cpp
logic_signals_gui.cpp
logic_signals.h
Perhaps you should use existing files to put the code in: signal_type.h, signal_func.h, signal.cpp, signal_gui.cpp, rail_cmd.cpp - they seem to be a good place for your code.

_________________
:] don't worry, be happy and checkout my patches


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Fri Aug 23, 2013 2:09 pm 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
Thank you adf88 for reviewing my code and providing feedback. I have released a new version which fixes all your points with regard to coding style.


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Fri Aug 23, 2013 2:51 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
I think adf88 spoke more about the general coding style rules to add braces after an if, not only for the example he gave.
Code:
+         if (trigger_states > 0) { return OppositeSignalState(this->own_default_state); }
+         break;

Code:
+   if (old_type == SIGTYPE_LOGIC) { DeleteSignalProgram(tile, track); }
+   if (new_type == SIGTYPE_LOGIC) { CreateSignalProgram(tile, track); }

...


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Fri Aug 23, 2013 4:35 pm 
Offline
Chief Executive
Chief Executive
User avatar

Joined: Mon Jan 14, 2008 3:51 pm
Posts: 644
Location: PL
I was talking about if-else statement. Single line if statement can be left without braces. See http://wiki.openttd.org/Coding_style#Control_flow for more details.

_________________
:] don't worry, be happy and checkout my patches


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Sun Aug 25, 2013 5:46 am 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
So has any of you actually tried the patch in a game yet? Did the signals work as expected?


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Sun Aug 25, 2013 11:25 pm 
Offline
Engineer
Engineer

Joined: Sun Dec 06, 2009 9:57 pm
Posts: 126
is there any chanse of not only linking the diff file, but rather a compiled version ?
I'd bet there are more than many people whom would be intrested, but lack skills to compile .diff from surce.

BTW, i absolutely love this idea. prehaps my prayers where not for nothing?
programmable signals to create prioritys and sutch, is what i'm personaly missing from the game,
so i'm absolutely excited to try Your patch!

_________________
The Prophet -thx Pikka-


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Mon Aug 26, 2013 12:52 am 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Dec 21, 2004 5:35 am
Posts: 185
Skype: andrey-zaharov
Location: St. Petersburg, Russia
2457 wrote:
is there any chanse of not only linking the diff file, but rather a compiled version ?
I'd bet there are more than many people whom would be intrested, but lack skills to compile .diff from surce.

BTW, i absolutely love this idea. prehaps my prayers where not for nothing?
programmable signals to create prioritys and sutch, is what i'm personaly missing from the game,
so i'm absolutely excited to try Your patch!

there is programmable waypoints built in HardPack patchpack. See links for win32 x64 bundles in my signature

_________________
OpenTTD Hard Game Pack


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Mon Aug 26, 2013 6:20 am 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
2457 wrote:
is there any chanse of not only linking the diff file, but rather a compiled version ?
I'd bet there are more than many people whom would be intrested, but lack skills to compile .diff from surce.


Good point. I will provide a compiled version today.


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Mon Aug 26, 2013 10:57 am 
Offline
Engineer
Engineer

Joined: Sun Dec 06, 2009 9:57 pm
Posts: 126
YEEY, thank You!

Can't wait to FINALY get rid of the utterly silly and needless logic trains FOR EVER :)
and prehaps others can enjoy then complex signalling without building -otherwise- not needed and useless tracks all around the map.

_________________
The Prophet -thx Pikka-


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Mon Aug 26, 2013 5:53 pm 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
Binary for windows is now available for download.


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Mon Aug 26, 2013 8:39 pm 
Offline
Engineer
Engineer

Joined: Sun Dec 06, 2009 9:57 pm
Posts: 126
hmm...
bad news.

http://oi41.tinypic.com/npfk2t.jpg

on this image You can see what i set up allready, a simple priority.
it did work, but only 1 time. secund time the train passed the signals the programmable signal did not turn red.
If i edit the signal, and choose any other logical operator (AND or XOR, or NOT) and then switch back to OR, the thing works again for a nother loop.

other than that i found no problems yet.
if You need a savegame, just say.

_________________
The Prophet -thx Pikka-


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Tue Aug 27, 2013 5:49 am 
Offline
Engineer
Engineer

Joined: Mon Jan 24, 2011 7:08 pm
Posts: 18
Yes, a savegame could be helpful. Did you use any newGRFs? What is the question mark icon at the top right corner of the signal programming window?


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Tue Aug 27, 2013 9:44 am 
Offline
Engineer
Engineer

Joined: Sun Dec 06, 2009 9:57 pm
Posts: 126
hmm i disabled all newGRF-s and it is working proeprly now.
the only grf that was loaded was Lithuanian transportation set.

_________________
The Prophet -thx Pikka-


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Wed Aug 28, 2013 1:55 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4537
Location: /home/sweden
maddy_ wrote:
What is the question mark icon at the top right corner of the signal programming window?


That question mark is because the 2457 has an OpenGFX version without a sprite for the somewhat new window size button.

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Wed Aug 28, 2013 6:14 pm 
Offline
Engineer
Engineer

Joined: Sun Dec 06, 2009 9:57 pm
Posts: 126
this is a marwell!!

I just managed to build a flip-flop type trafic splitter with no logic trains or what so ever, and without unused tracks,
that is -i must say- is sutch a relaxing thing!


oh, btw, it would be nice if the logic signal had a switch to toggle between <default behaviour> of <block>,<one way path> signal. It would allow to make very nice and "evil X" behaviour-less paralell tracks for games with brakedowns enabled.

_________________
The Prophet -thx Pikka-


Top
   
 Post subject: Re: Logic Signals patch
PostPosted: Wed Aug 28, 2013 8:47 pm 
Offline
Engineer
Engineer

Joined: Sun Dec 06, 2009 9:57 pm
Posts: 126
Look!

I made a video too.
Probably -but not sure- i will build other things with You phenomenal patch, and upload them to Youtube.





Thank You for making this patch, again.

_________________
The Prophet -thx Pikka-


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 44 posts ]  Go to page 1 2 3 Next

All times are UTC


Who is online

Users browsing this forum: Gliptal and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.