NAND 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

NAND Patch

Post by Owen »

This patch adds signal type 5, the NAND pre signal.

A NAND pre signal has the exact ooposite properties of a normal combo signal. In other words, it is red when a normal signal would be green.

Currently, the signal uses the PBS graphics. I do not have enough NewGRF knowledge to chnage this.

I am not sure if I am smashing the semaphore bitflags in rail_map.h. Could a developer check that for me, so I can fix it if I am.

When building a NAND signal, care should be taken to make sure the signals do not form a loop, else OpenTTD will hang changing signal state constantly. You have been warned. I was wondering if the devs have any information on how to avoid this?

Notes:
* Someone check rail_map's bitflags please
* Fix the hang issue (Delay before changing?)
* Custom graphics :)

Enjoy!

EDIT: Oh yeah, can someone check the code I nicked from PBS applys? Thanks
Attachments
nandv2.diff
Nand gates, version 2 (Fixes YAPF)
(6.47 KiB) Downloaded 553 times
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

You've posted a lot of info about that NAND signal, but you seem to have missed one that interests me: why? What do you gain from being able to build these signals? I wouldn't mind seeing a practical application of them in a screenshot.
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

They are the basic building blocks of all other gates. From a NAND, you can build an AND, NOR, NOT, OR, etc.

I have a practical application also:
http://res1.humgun.com/ttdnand/statpref.png

This somewhat models a really busy station in the OpenTTD Coop Sandbox, where we want a futher away station to be prefered. With a NAND gate setup as shown, it would be possible.

The trains prefer the extension, which we don't want them to. In the example, the station on the right is the overflow station. While in this example, trains prefer the overflow station, the signaling dictates which way they go anyway.

NANDs can be extremely useful.

EDIT: Made image a link
Last edited by Owen on 22 Jul 2006 21:16, edited 1 time in total.
User avatar
Graphite
Engineer
Engineer
Posts: 84
Joined: 17 Nov 2005 20:56
Location: Netherlands
Contact:

Post by Graphite »

Hmmm... to be honest, you completely lost me on that image. I've built my fair share of complicated stuff, but that one surpasses my current ability to figure it out (though it's about bedtime, so that may have something to do with it).

I guess it does have its uses, though I doubt I'll ever use it myself. I am a bit worried that the signal builder is getting a bit overloaded though. If PBS is added back to the mix, you'd be cycling through five signals. If these are added to the game, then the signal gui could do with a make-over as well to resolve that issue.

P.S. That image is rather wide to be placed inline in the post. You might want to either crop it or put it in an attachment.

P.P.S. Transistor Tycoon anyone? :D
A computer scientist is someone who, when told to "Go to Hell," sees the "go to," rather than the destination, as harmful.
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

some pics, by popular demand

EIDT: updated the diff to avoid game hangs on NAND loops
Attachments
the_flip_flop_RS.PNG
the wonderful flip-flop R/S
(333.25 KiB) Downloaded 1195 times
some_gates.PNG
some logic gates
(292.73 KiB) Downloaded 1445 times
nand_miniIN.diff
the diff for the latest miniIN
(6.47 KiB) Downloaded 703 times
Last edited by Wolf01 on 22 Jul 2006 22:24, edited 1 time in total.
User avatar
Nickman
Engineer
Engineer
Posts: 66
Joined: 27 Jun 2006 23:07

Post by Nickman »

I'll be messing around with this one if I get the code to compile :D
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

Update, to remove the hang issue. A presignal change can no longer affect more than 10 blocks however. I hope that this becomes configurable :)
Attachments
nandv3.diff
Version 3
(7.36 KiB) Downloaded 428 times
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

I created a minaturzied (Well, as possible :roll:) version of the RS Flip-Flop:
Attachments
miniff.png
miniff.png (35.89 KiB) Viewed 16302 times
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

now i can reset my memory cell :D
Attachments
memory_cell_with_reset.PNG
memory_cell_with_reset.PNG (43.13 KiB) Viewed 16281 times
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

Ensuring all tracks are free:

EDIT: 99% Perfect balancer (Trains will go to A, B, A, B 99% of the time. The 1% being when a train sits on a flipper)
Attachments
alltracks.png
alltracks.png (47.41 KiB) Viewed 16261 times
NAND Balancer
NAND Balancer
nandbalancer.png (42.84 KiB) Viewed 16258 times
Last edited by Owen on 22 Jul 2006 23:56, edited 1 time in total.
User avatar
sidew
Engineer
Engineer
Posts: 115
Joined: 31 Aug 2005 06:46
Location: Milan, Italy
Contact:

Post by sidew »

If I find my old book of microelectronics, maybe 'll try an small binary adder with carry bit :D

Good old times when I attend the campus...
Sidewinder

Italian Town names patch for OTTD (R5266) now in trunk since 0.4.8
For typo, errors or bug on OTTD italian translation, please PM me.
unofficial italian TTD/OpenTTD forum: http://wolf01.game-host.org/forum/index.php
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

Hehe. Might need to increase the cascade value, I doubt it will work on 10 hops...
Frostregen
Transport Coordinator
Transport Coordinator
Posts: 340
Joined: 06 Feb 2006 23:58

Post by Frostregen »

I don't know if you fixed it already, but you need to change the Set/GetSignalVariant functions to make Semaphores work again.

Code: Select all

static inline SignalVariant GetSignalVariant(TileIndex t)
{
	return (SignalVariant)GB(_m[t].m4, 3, 1);
}

static inline void SetSignalVariant(TileIndex t, SignalVariant v)
{
	SB(_m[t].m4, 3, 1, v);
}
They can be found in rail_cmd.c.
Just modify them to get/set bit 3 instead of 2.

This gave me some serious headache while trying to use them with my copy&paste patch ;)
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

Version 4, incorporating Frostregen's fixes although they were developed independently. I also bumped the cascade limit to 20 since 10 seemed limiting.
Attachments
nandv4.diff
Version 4, for the current trunk revision r5596
(7.48 KiB) Downloaded 446 times
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

NAND Path version 5

Changes:
* Only counts NAND signals now
* When an overflow occurs, displays an error message. While it doesn't tell you the location, chances are this will only occur while building anyway[/b]

To apply, gunzip the diff and apply. Under Linux, do the following:

Code: Select all

cat nandv5.diff.gz | gunzip | patch
Edit: Added MiniIN patch
Attachments
nandv5.diff.gz
NandV5
(2.78 KiB) Downloaded 448 times
nandv5-min.diff
MiniIN patch
(8.51 KiB) Downloaded 444 times
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

miniIN diff with configurable nand cascading in configure patches
Attachments
nand_miniIN_configurable.diff
(10.61 KiB) Downloaded 448 times
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

A relay, much like it's mechanical counterpart, takes an input at one half and produces an output at the other.
Attachments
relay.png
relay.png (64.84 KiB) Viewed 16096 times
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Post by TrueBrain »

Some code-wise tips/trucks you might want to alter:

- Follow the OpenTTD Coding Guidelines
-> if() is wrong, it should have a space between if and ()
-> Don't printf stuff, use DEBUG()
- The define in variables.h might not be the best place. Also, capitals for defines are more common

I am sure there are some more things (nobody is perfect ;)), but that is what I noticed after a quick look ;) I have to say I like it very much, it is nice to have a full logic-set of signals :)

Ps: post it at http://bugs.openttd.org, so devs will notice it :)
Owen
Engineer
Engineer
Posts: 70
Joined: 23 Aug 2004 15:22

Post by Owen »

-> if: Thats my normal way, ill fix it to follow the guidelines :)
-> printf: Shouldn't (normally) escape my hands
-> deifne: It was temporary; I'm moving it to a patch option
CobraA1
Route Supervisor
Route Supervisor
Posts: 480
Joined: 07 Nov 2003 17:52
Location: USA

Post by CobraA1 »

Using trains as logic circuits :shock:.

Now that's something I've never seen done before.
"If a man does not keep pace with his companions, perhaps it is because he hears a different drummer. Let him step to the music he hears, however measured or far away" --Henry David Thoreau
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 13 guests