Traffic lights (r17455)

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

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Alpha 2] Traffic lights

Post by Zephyris »

Very nice work! Soooo, road vehicle accidents next? :wink:

And nice to see my graphics in action, OpenGFX and GRVTS! :D

t0mcioo
Engineer
Engineer
Posts: 11
Joined: 14 Oct 2007 00:52
Location: Ireland, Poland
Contact:

Re: [Alpha 1.1 released] Traffic lights

Post by t0mcioo »

Soeb wrote:Can help, thanks. However I can't understand which part is for "red" state, which for "green" state.
I'm not quite sure but:
- on junction it was only one semaphore - on middle of road
- the red state was when 'flyers' where full visable (pointin perpendicular road where is driver / red light)
- green state was when they where not (pointing same / reverse road where is driver / green ligh).
- it was working like this: when signal was about to change, policeman was using level to rotate top part by 90deg (glases and 'flyers').
~/ ):( gallery
"...sometimes the sound of goodbye is louder than any drum beat..."

User avatar
DeletedUser5
Transport Coordinator
Transport Coordinator
Posts: 277
Joined: 07 Oct 2007 15:10

Re: [Alpha 2] Traffic lights

Post by DeletedUser5 »

Works good but there are few stupid things like vehicle can stop on junction because the light turned there to red.

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [Alpha 2] Traffic lights

Post by Roujin »

Zephyris: nope, sorry :P maybe in faaaaar future (if at all :P)

Yep, those grfs are nice, I like them a lot ;)


Soeb: can you explain what you mean? I didn't really understand it... maybe also provide a screenshot of what you mean?
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

User avatar
DeletedUser5
Transport Coordinator
Transport Coordinator
Posts: 277
Joined: 07 Oct 2007 15:10

Re: [Alpha 2] Traffic lights

Post by DeletedUser5 »

Me too.

I meant that vehicle stops on junction because lights on its way turned red. However it shouldn't because it's already on junction.

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Alpha 2] Traffic lights

Post by Zephyris »

I think he means that the lights dont act as signals - to block entry to the junction tile - they also make any vehicles on the junction tile stop... Havn't seen it myself tho...

Trond
Tycoon
Tycoon
Posts: 973
Joined: 25 Jan 2008 07:32
Location: Gamle Ørnenuten

Re: [Alpha 2] Traffic lights

Post by Trond »

Just started a game to check out these lights with the latest alpha. So, I put up light anywhere I could in a city and started a car running randomly around. After a while, the city started a random road construction... In a junction where I already had a trafficlight... Is that wanted behavior?

Other than that, wow, looks pretty cool! Very nice to see the lights changing, cars stopping etc.

Edit: Oh also, when a city puts up lights, I can remove them... Is that really wanted?
..: Trond :.. because you deserve it! Image

The whole problem with the world is that fools and fanatics are always so certain of themselves,
and wiser people so full of doubts.
Bertrand Russell

MyGRFs: Norwegian Funny Town Names 4 | LOTR & WoW Town Names 2 | Islandic Town Names 1 | Random Norwegian Town Names
Favorites: GRFCrawler | ISR | WIKI | Now Playing: OpenTTD 1.3.2 w/YAPP 3.0-RC3.9ish

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [Alpha 2] Traffic lights

Post by Roujin »

@Soeb & Zephyris: I couldn't observe this, are you sure about that?

or, Soeb, did you mean that they stop too far into the crossing when they have a red light (see screenshot with North American road set, which has stopping lines)? Then that's something I can't (or rather do not want to) do much about, as my TL junctions act like closed level crossings. Meaning if I change where roadvehs stop at my TLs, it will also change for level crossings. And I don't want to change too much on other stuff.
rv stopping a bit far into the junction
rv stopping a bit far into the junction
TL rv stopping.png (91.1 KiB) Viewed 5507 times
---
@Trond:

The random road construction appears anywhere in a city, randomly. In fact, that feature is pretty independent from the traffic lights, except for the fact that during road construction on crossings, traffic lights may be put up with a given chance.

You can also adjust the patch to your likings, e.g. turn off the random road construction, if you don't like it (or make it less probable, or more probable if you want). The four patch settings I introduced should be pretty much self explaining.
Edit: Oh also, when a city puts up lights, I can remove them... Is that really wanted?
At the moment, it is intended behavior, yes. At the final stage of this patch, you should only be allowed to place/remove signals if you're the owner of the road piece below. But I didn't implement this yet as it's more convenient for testing without that restriction. ;)


edit: here's a rediff for newest revision. Nothing changed, though.
Attachments
trafficlights_alpha2_r12318.diff
traffic lights alpha 2 for r12318
(36.31 KiB) Downloaded 151 times
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

Trond
Tycoon
Tycoon
Posts: 973
Joined: 25 Jan 2008 07:32
Location: Gamle Ørnenuten

Re: [Alpha 2] Traffic lights

Post by Trond »

Yeah, I noticed the patchsettings, and maxed out that random road construction to see how it works :) And it works really well I would say, looks good to! I'm gonna continue using this untill it gets accepted to trunk, cause this is a really nice one :)

Edit: I will use it after its accepted to trunk also :lol: only then I dont have to patch it myself :D
..: Trond :.. because you deserve it! Image

The whole problem with the world is that fools and fanatics are always so certain of themselves,
and wiser people so full of doubts.
Bertrand Russell

MyGRFs: Norwegian Funny Town Names 4 | LOTR & WoW Town Names 2 | Islandic Town Names 1 | Random Norwegian Town Names
Favorites: GRFCrawler | ISR | WIKI | Now Playing: OpenTTD 1.3.2 w/YAPP 3.0-RC3.9ish

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [Alpha 2] Traffic lights

Post by Roujin »

I expect that this stays as a patch (= not in trunk) for a while for some reasons:
- 0.6.0 is on the way. During preparation for a stable release, the devs won't include patches with new features because they bear the risk of new bugs. They want to get the game as bugfree as possible for the stable release. After the release, they might be more open towards new features.
- how I store the stuff in the map array. I don't like what I'm doing there myself. If it were to be included in trunk, I guess that would have to change.

After these two are solved, it's still the question if the devs like the feature. ;) Only if that's all fulfilled, you may see it in trunk sometime.

edit: Thinking about it, I might release the random road construction as a standalone. That one is such a minor codechange that it might just be accepted into trunk. If the feature is being liked, that is.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Alpha 2] Traffic lights

Post by Zephyris »

how I store the stuff in the map array. I don't like what I'm doing there myself. If it were to be included in trunk, I guess that would have to change.
Sadly I agree, but there must be somewhere else with free bits!

User avatar
DeletedUser5
Transport Coordinator
Transport Coordinator
Posts: 277
Joined: 07 Oct 2007 15:10

Re: [Alpha 2] Traffic lights

Post by DeletedUser5 »

No it wasn't the thing I meant.

Let's say it like that:
I build traffics lights in whole town than run on bus. I was watching it for a while and noticed that sometimes when bus goes onto the T junction and then goes for example to right ( the road ends there ) so it stops there. In my opinion it shouldn't.
Attachments
Muntfingley Transport, 24th Oct 1950.png
Muntfingley Transport, 24th Oct 1950.png (134.06 KiB) Viewed 5450 times

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Alpha 2] Traffic lights

Post by Zephyris »

The behaviour there is that the vehicle has exited the junction, been forced to turn by lack of road, but has been met by a red light on reentering the junction. I believe the same can happen on a dead end level crossing - hence the origin of this bug...

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [Alpha 2] Traffic lights

Post by Roujin »

Zephyris wrote:
how I store the stuff in the map array. I don't like what I'm doing there myself. If it were to be included in trunk, I guess that would have to change.
Sadly I agree, but there must be somewhere else with free bits!
Nah, for road tiles, it's completely stuffed. (see docs/landscape_grid.html) These three bits were the only ones I could somehow use. Unless I would throw out the reserved bits for a third road type (road type as in normal, tram). But I doubt the devs would like that either.
Other than the map array, one could use a pool for storing stuff. But then we would still need to store a pointer in the map array. Nah, this isn't going anywhere... :?

---
@Soeb: Ah, I see. Well, technically the bus is turning at the edge of the tile and before entering the tile again, checks if it is allowed to. Since there's a red light, it isn't. So it waits until it gets green again.

I don't think that's relevant enough to justify big changes in code. Firstly, that's a weird crossing you have there because one of the ways ends just after the crossing. Secondly, even if there is such a crossing, it would be quite rare for a vehicle to head into this direction (if it has proper orders).

edit: @Zephyris: yeah, it should be the same for dead end level crossing as I reused the code for level crossings.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

User avatar
DeletedUser5
Transport Coordinator
Transport Coordinator
Posts: 277
Joined: 07 Oct 2007 15:10

Re: [Alpha 2] Traffic lights

Post by DeletedUser5 »

It wasn't weird for that vehicle. And sometimes towns build junctions like that ( it was generated not created ). Let's say town will build junction with traffic lights like that, and on one of ends there will be road reconstruction. Vehicle will go there and loose some time because of that.

User avatar
Zephyris
Tycoon
Tycoon
Posts: 2831
Joined: 16 May 2007 16:59

Re: [Alpha 2] Traffic lights

Post by Zephyris »

Is it necessary to store the traffic light state in the map array? You could use a single bit to store whether it is a road tile with traffic lights, then drive the colour change off the tile refresh cycle...

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [Alpha 2] Traffic lights

Post by Roujin »

Then how are the vehicles supposed to know if they may drive or not? I have to store the state of the crossing somewhere.. :?
And what if I load an existing game? If the current state of a TL crossing isn't saved in the savegame, after loading all TLs are in one state (all off or say x green y red) regardless of what they were when the game was saved.

Nah, I'm pretty sure the states must be stored somewhere. Another thing that comes to my mind just now is multiplayer consistency: What if a player joins a running multiplayer game with TLs placed somewhere. How should he (= his client) know which state the TLs are in? He cannot just assume they are in (for example) x green y red because it will lead to different flow of traffic on his client compared to the server/other clients, eventually leading to desync.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: [Alpha 2] Traffic lights

Post by Roujin »

Small update: made a new version (alpha 2.1) without random road construction, as I've made a seperate patch for that.

edit: rediff for r12436
trafficlights_alpha2.1_r12436.diff
traffic lights alpha 2.1 for r12436
(without random road construction)
(35.73 KiB) Downloaded 133 times
Attachments
trafficlights_alpha2.1_r12320.diff
traffic lights alpha 2.1 for r12320
(without random road construction)
(35.71 KiB) Downloaded 172 times
Last edited by Roujin on 26 Mar 2008 23:58, edited 1 time in total.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage

Falco00
Engineer
Engineer
Posts: 4
Joined: 28 Feb 2008 12:56

Re: [Alpha 2] Traffic lights

Post by Falco00 »

Roujin wrote:Then how are the vehicles supposed to know if they may drive or not? I have to store the state of the crossing somewhere.. :?
And what if I load an existing game? If the current state of a TL crossing isn't saved in the savegame, after loading all TLs are in one state (all off or say x green y red) regardless of what they were when the game was saved.

Nah, I'm pretty sure the states must be stored somewhere. Another thing that comes to my mind just now is multiplayer consistency: What if a player joins a running multiplayer game with TLs placed somewhere. How should he (= his client) know which state the TLs are in? He cannot just assume they are in (for example) x green y red because it will lead to different flow of traffic on his client compared to the server/other clients, eventually leading to desync.
How about basing all the trafic light states on the game time. Every even tick vehicles from the x direction have a green light and uneven for the y direction. This way you dont have to store anything in the map. Only thing is that all trafic lights will show the same behaviour this way but im sure you can come up with some algorithm to make it appear random.

[edit]ohh sounds a lot like what Zephyris just posted.

DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: [Alpha 2] Traffic lights

Post by DaleStan »

Zephyris wrote:Is it necessary to store the traffic light state in the map array? You could use a single bit to store whether it is a road tile with traffic lights, then drive the colour change off the tile refresh cycle...
Roujin wrote:Then how are the vehicles supposed to know if they may drive or not?
Using the same information that drives the light state. If _game_ticks % 16 is 0..6, signal is green for X-direction, and X-direction vehicles may pass. If _game_ticks % 16 is 7, signal shows yellow in X direction.
If _game_ticks % 16 is 8..14 and 15, same as above, but for Y-direction instead.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Google Adsense [Bot] and 7 guests