ProgSigs - Programmable Signals patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch for OpenTTD

Post by Owen »

Kogut wrote:Is it possible to make conditional train orders based on state of signal?
For example:
- wait for full load but leave if X signal is red (potential use: no more than n trains loading on one station)
- stop loading only if X signal is green (potential use: leave station only if mainline is empty)
etc
It require a lot of work but results may be great!
Thats something which should theoretically be possible with conditional orders, but I'm not the person to ask - I haven't touched the order code (Other than snarfing bits of it's GUI)
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch for OpenTTD

Post by Owen »

New revision. This is the first revision in which you can program, though the ways you can program it at the moment are limited.

Testing is highly appreciated.

For full details, see the first post.
Attachments
ProgSig-e26b81b-r19500.diff
Latest revision
(112.23 KiB) Downloaded 174 times
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Re: ProgSigs - Programmable Signals patch - Now with editor!

Post by XeryusTC »

Will the signals be able to check train information so you can deny certain trains to take a certain route for example?
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch for OpenTTD

Post by Owen »

To quote myself earlier ;-)
Owen wrote:Restrictive/guiding signals are quite a different kettle of fish. Thats not to say they couldn't be implemented (Or even share code), just that they're not currently.
OpenTTD only evaluates signals when (A) A train has entered the block behind them (In which case they go straight to red, don't pass go, don't collect £200), or (B) A train has left them, or (C) a presignal behind them has changed [OK, theres also (D), you've reprogrammed a signal...]. None of these times gives you access to a useful train (And you only get access sometimes anyway).

That feature certainly could be implemented on top of the ProgSigs framework - but it would take a slightly different kind of program (One which could look at the arriving train and allow/deny a route), and it would do it doing pathfinder penalties. In other words, such a feature would probably be implemented by selecting a "Pathfinding" or "Train Restrictions" option from a dropdown in the signal programming window.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch - Now with editor!

Post by Owen »

Revision 545263f, generated against r19504.

This version adds no new features. It just cleans up the code. It also fixes a bug in the save file validation code. Otherwise, it should be functionally identical.

Testing is, as always, appreciated.
Attachments
ProgSig-545263f-r19504.diff
(118.54 KiB) Downloaded 173 times
User avatar
Benny
Tycoon
Tycoon
Posts: 2185
Joined: 25 Aug 2007 17:03
Location: ~/

Re: ProgSigs - Programmable Signals patch - Now with editor!

Post by Benny »

Would anyone be interested in a 24/7 server running this patch?

Just asking. >_>
Image
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch - Now with editor!

Post by Owen »

Were gonna run the next revision (That is, when I get the ability to look at arbitrary signals - and perhaps signal local variables - in) on #openttdcoop.dev.

Those changes are likely to change the save format, though, so starting now wouldn't be wise (I think I'm gonna version the SPRG chunk)
User avatar
Benny
Tycoon
Tycoon
Posts: 2185
Joined: 25 Aug 2007 17:03
Location: ~/

Re: ProgSigs - Programmable Signals patch - Now with editor!

Post by Benny »

Ah, fine. :)

Also: not that I understand these signals yet, but this patch looks good. Adds a lot of flexibility to the game.
Image
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch - Now with editor!

Post by Owen »

New revision. This implements the major feature I'd wanted to get in: Arbitrary signal lookups. You can now look at any other exit signal you own on the map from within your programs.

Diff attached. Main other change is signal removal consolidation and some more cleanups to match the official style.

This version breaks backwards compatibility with previous savegames - that is, games from previous versions will not load (or if they do will behave weirdly).
Attachments
ProgSig-d79c64c-r19518.diff
(134.5 KiB) Downloaded 153 times
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: ProgSigs - Programmable Signals patch

Post by ChillCore »

Hi Owen,
while compiling I had a few warnings.

Code: Select all

[SRC] Compiling programmable_signals.cpp
~/src/programmable_signals.cpp: In member function â void SignalProgram::DebugPrintProgram()â :
~/src/programmable_signals.cpp:405: let op: format â %ldâ  expects type â long intâ , but argument 3 has type â intâ
~/src/programmable_signals.cpp: In member function â virtual bool SignalVariableCondition::Evaluate(SignalVM&)â :
~/src/programmable_signals.cpp:114: let op: control reaches end of non-void function
~/src/programmable_signals.cpp: In function â CommandCost CmdModifySignalInstruction(TileIndex, DoCommandFlag, uint32, uint32, const char*)â :
~/src/programmable_signals.cpp:533: let op: â condâ may be used uninitialized in this function
The game runs but I Did not get to playtesting yet.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch

Post by Owen »

ChillCore wrote:Hi Owen,
while compiling I had a few warnings.

Code: Select all

[SRC] Compiling programmable_signals.cpp
~/src/programmable_signals.cpp: In member function â void SignalProgram::DebugPrintProgram()â :
~/src/programmable_signals.cpp:405: let op: format â %ldâ  expects type â long intâ , but argument 3 has type â intâ
~/src/programmable_signals.cpp: In member function â virtual bool SignalVariableCondition::Evaluate(SignalVM&)â :
~/src/programmable_signals.cpp:114: let op: control reaches end of non-void function
~/src/programmable_signals.cpp: In function â CommandCost CmdModifySignalInstruction(TileIndex, DoCommandFlag, uint32, uint32, const char*)â :
~/src/programmable_signals.cpp:533: let op: â condâ may be used uninitialized in this function
The game runs but I Did not get to playtesting yet.
Thsoe warnings are all minor and I've fixed them & comitted them to the repo (No point spinning out a new patch just yet). A couple of them just required annotating branches as not used; the first has required adding some more casting to the DEBUG call.

What compiler version are you using as it seems a little more picky than my GCC?
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: ProgSigs - Programmable Signals patch

Post by ChillCore »

Terminal
A terminal emulator
Release 0.9.4
Author: Alexander Malmberg

I am on ubuntu 9.04

If you are on Windows you may want to give MinGW-MSYS a go. It seemed rather picky too when I was using that last year.
And according to some compiler bugfix I had to do, with some help, visual studio/express is even pickier.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch

Post by Owen »

ChillCore wrote:Terminal
A terminal emulator
Release 0.9.4
Author: Alexander Malmberg

I am on ubuntu 9.04

If you are on Windows you may want to give MinGW-MSYS a go. It seemed rather picky too when I was using that last year.
And according to some compiler bugfix I had to do, with some help, visual studio/express is even pickier.
The terminal emulator you use is pretty irrelevant, but the Ubuntu 9.04 is enough to tell me that mine is newer (I develop on 9.10, x86_64). Which makes me surprised it would be less picky.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch

Post by Owen »

Bugfix!
Removing an If didn't remove the Else and Endif pseudo instructions properly. Saving would then crash as soon as the If's memory got reclaimed and used for something else. The game would then crash.

This bug was a really, really stupid error on my part :oops:
Attachments
ProgSig-ec0e201-r19518.diff
(134.6 KiB) Downloaded 163 times
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: ProgSigs - Programmable Signals patch

Post by ChillCore »

Owen wrote: The terminal emulator you use is pretty irrelevant, but the Ubuntu 9.04 is enough to tell me that mine is newer (I develop on 9.10, x86_64). Which makes me surprised it would be less picky.
Maybe it is a difference in the configuration file. I have attached mine (copied from the terminal output) if you want to compare.
I am new to ubuntu and its internals is still a still a big puzzle to me.

Compiling the new diff now ...

Edit: Cool ,no more compiler warnings.
Attachments
config.txt
(2.69 KiB) Downloaded 178 times
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch

Post by Owen »

Bugfix release. This corrects a crash bug when deleting an If with a populated Else block, which was introduced by the previous fix for the Save crash regarding If blocks.

As you might have gathered, Ifs are somewhat complex.
Attachments
ProgSig-2612770-r19519.diff
(134.64 KiB) Downloaded 160 times
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: ProgSigs - Programmable Signals patch

Post by ChillCore »

Hi Owen,

While having a better look at your patch I noticed you declare "STR_CONFIG_SETTING_SAMEINDCLOSE" in englich text.
However you do not seem to be using it anywhere ... I am testing and reading to see if the code is solid enough and what I may have to change for inclusion in my patchpack :mrgreen:.

Is this something you have may have forgotten to remove or are you going to be using it in the future?
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch

Post by Owen »

Ill have a look, but it may take a while - a hdd has just died (my seccond in under a month! OMG!) so my dev environment is out of comission until i can replace it and get backups restored.

It sounds like a string removed in trunk recently which has gotten orphaned in my patch. Again, i'll look into it soon.
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: ProgSigs - Programmable Signals patch

Post by ChillCore »

Owen wrote: Ill have a look, but it may take a while - a hdd has just died (my seccond in under a month! OMG!) so my dev environment is out of comission until i can replace it and get backups restored.
Sad to hear that. I hope you get your system back running again.
It sounds like a string removed in trunk recently which has gotten orphaned in my patch. Again, i'll look into it soon.
Most likely that is what happened.


Also, when using block signals after the programmable signal the logic seems to inversed. (or I am doing something wrong :) )
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Re: ProgSigs - Programmable Signals patch

Post by Owen »

It sounds like a string removed in trunk recently which has gotten orphaned in my patch. Again, i'll look into it soon.
Most likely that is what happened.
OK, according to #openttd (Thanks andythenorth) frosch removed the close industries check recently. Git has obviously got a little confused with my somewhat complex history. I'll pull the string out soon
Also, when using block signals after the programmable signal the logic seems to inversed. (or I am doing something wrong :) )
It would be interesting to see what you're doing. I should probably create a wiki page documenting them...
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Bing [Bot] and 14 guests