[New Feature] Patch for selective transparency (+catenary)

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

Post Reply

Do you think that this feature is usefull?

Yes
25
96%
No
1
4%
 
Total votes: 26

User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

[New Feature] Patch for selective transparency (+catenary)

Post by Wolf01 »

i thought that a new "transparent" feature should be useful
make transparent things in different times is a good idea:
- when i want to see my new station (with newstations.grf) built in the middle of the city
- when i want to build junctions/signals and catenary doesn't allow me to see what i'm doing (not already done yet)
- now with magic bridges i want to see what i'm building below a bridge without making all other things transparent, but bridges only and maybe fully transparent (not already done the bridge invisibility)

the options are (selectable on the file menu like rollercoaster tycoon):
- make transparent trees
- make transparent houses
- make transparent industries
- make transparent player's buildings (now CATENARY!, stations, bridges etc)

keys:
X toggle transparency for all things
CTRL+X make player's buildings transparent (also catenary)
SHIFT+X cycle transparent selection (try it, it's hard to explain, but is only a bit shift)

i don't know well the code, so if it isn't optimized or placed uncorrectly don't blame me

in the post below you can find the diff and the executable (win32) with the english.lng (i hope that needs only that)

Credits:
peter1138 for suggestions on the code
Hackykid for suggestions on the code
the #OpenTTD chan for the help
Attachments
bin_w32.zip
(685.03 KiB) Downloaded 218 times
transparency_5348.diff
06-22-06 little bugfix
(16.92 KiB) Downloaded 257 times
Last edited by Wolf01 on 24 Jun 2006 08:27, edited 8 times in total.
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

06-22-06 new bugfixing:
- newspaper popup don't reset the transparency bits
- X key reset then toggle transparency for all items together
Hazelrah
Traffic Manager
Traffic Manager
Posts: 196
Joined: 13 Apr 2005 05:41

Post by Hazelrah »

Can I bother you for a screenshot of the interface?

-Hazelrah
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

here are some pictures
Attachments
transp3.PNG
transp3.PNG (307.03 KiB) Viewed 1171 times
transp2.PNG
transp2.PNG (13.37 KiB) Viewed 5833 times
transp1.PNG
transp1.PNG (14.99 KiB) Viewed 5833 times
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

another little bugfixing... i played a little with conditions and bits for the shifting :P
oh, i forget, i changed 2 pictures with others which explain better why i made the patch
User avatar
mart3p
Tycoon
Tycoon
Posts: 1030
Joined: 31 Oct 2005 21:00
Location: UK

Post by mart3p »

If just been trying your transparency patch.

Firstly I get a compile error with MSVC 2005

Code: Select all

c:\...\openttd\trunk\elrail.c(251) : error C2275: 'uint32' : illegal use of this type as an expression
I changed:

Code: Select all

uint32 pylon;
if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
	for (k = 0; k < DIR_END; k++) {
	...
To:

Code: Select all

if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
	uint32 pylon;
	for (k = 0; k < DIR_END; k++) {
	...
and it then compiles ok.

It seems to work well and I think it will be very useful. I've already cast my vote. :)

I have one suggestion, I think the menu item "Transparent buildings" should be "Transparent stations". "Transparent station buildings" would be better but is probably too long.

Edit: I also noticed you have a few problems with tabs in your patch, see screenshot. There are also a few tabs where they shouldn’t be in english.txt.

The program in the screenshot is Notepad2. It is a very useful alternative to Windows Notepad. It has built in colour coding support for diff and patch files (as well as many other file types). It will also optionally display tabs and spaces as shown. It is open source and available for download here.
Attachments
Transparency.png
Transparency.png (30.24 KiB) Viewed 5729 times
Image
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

mart3p wrote:If just been trying your transparency patch.

Firstly I get a compile error with MSVC 2005[...]
and it then compiles ok.
Thank you for the bugfix :D
It seems to work well and I think it will be very useful. I've already cast my vote. :)

I have one suggestion, I think the menu item "Transparent buildings" should be "Transparent stations". "Transparent station buildings" would be better but is probably too long.
Uhm, that menu item make transparent all the buildable things, not only stations, but bridges, waypoints, stations, catenary, depots... maybe "Trasparent buildable" or "Transparent constructions" may be better
Edit: I also noticed you have a few problems with tabs in your patch, see screenshot. There are also a few tabs where they shouldn’t be in english.txt.

The program in the screenshot is Notepad2. It is a very useful alternative to Windows Notepad. It has built in colour coding support for diff and patch files (as well as many other file types). It will also optionally display tabs and spaces as shown. It is open source and available for download here.
i know, i'm using devc++ which has some problems with tabs, i already thought to switch to notepad++
ok, i correct that bugs and then i upload the new version
User avatar
White Rabbit
Tycoon
Tycoon
Posts: 1734
Joined: 22 Jun 2005 19:15

Post by White Rabbit »

Those transparent options only come into effect after pressing X, right?
Image
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

the X key has the old behaviour, only now resets all the transparency before toggle to avoid this: 0101 -> 1010
so if you have 1010 and press X is re-set to 0000 and then you can toggle all transparencies together 0000 -> 1111
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

Code: Select all

case 'X': //toggle all transparent (as normal behaviour)
	if (GB(_display_opt,7,4)==0) {
		_display_opt ^= 1920; //11110000000
	} else { //re sets the transparency to visible for all things
		_display_opt &= 127;
		_transp_opt &= 127; //reset also the temp variable for the shift
	}
	MarkWholeScreenDirty();
	break;
i have this code, it should toggle the first 4 bits on the left (BBBBxxxxxxx)
it sets to 0 the 4 bits if at least one of them is 1 and sets all 4 to 1 if are all 0

i don't know why doesn't work, it must work!


i have some problems also here:

Code: Select all

case 'X' | WKC_SHIFT: //cycle transparency
	_temp_bit=0;
	if (_transp_opt&(1<<10)) _temp_bit=1;
	_transp_opt=_transp_opt<<1;
	if (!_temp_bit) _transp_opt+=128;
	_transp_opt&=1920;
        _display_opt ^= _transp_opt;
	MarkWholeScreenDirty();
	break;
this must shift the previous 4 bits like:
0000xxxxxxx
0001xxxxxxx
0011xxxxxxx
0111xxxxxxx
1111xxxxxxx
1110xxxxxxx
1100xxxxxxx
1000xxxxxxx
0000xxxxxxx
and it mustn't touch bits marked as x
but also this doesn't work and i don't know why too (it does nothing at all)

thanks for any help :P
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post by DaleStan »

The first looks fine to me; a trace would be your friend there. But I would use hex (0x780/0x7F), since I think that's easier for a human reader than decimal.


As for the second, I might try:
static int lookup[16]={1,3,-1,7,-1,-1,-1,0xF,0,-1,-1,-1,8,-1,0xC,0xE}; // -1 indcates invalid entry.
...
SB(_display_opt,7,4,lookup[GB(_display_opt,7,4)]);

(This is assuming that SB works the way I think it does; I've got people waiting for this computer, so I shouldn't look that up right now.)
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
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

i thought about the second code with a friend of mine

Code: Select all

case 'X' | WKC_SHIFT: //cycle transparency
   _temp_bit=0;
   _transp_opt&=1920; //reset the non used bits before shift
   if (_transp_opt&(1<<10)) _temp_bit=1;
   _transp_opt=_transp_opt<<1;
   if (!_temp_bit) _transp_opt+=128;
   _transp_opt&=1920;
   _display_opt&=~1920; //reset the four transparency bits for the merge
   _display_opt |= _transp_opt; //merge the 2 variables
   MarkWholeScreenDirty();
   break;
but i want to know why if i change more times the same piece of code, the code of the key shortcut this time, in the game it stops to work (for example if i copy the code to reset the transparency bits it doesn't work)
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

ok i found that was my fault, i had troubles installing the compiled files :P
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1791
Joined: 30 Mar 2005 09:43

Post by peter1138 »

Have just posted an update for this patch in the MiniIN thread:

http://www.tt-forums.net/viewtopic.php?p=460382#460382
He's like, some kind of OpenTTD developer.
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

thank you for the optimization :D
but the behaviour for toggle transparency is not what i wanted, i want that is like the old behaviour because you have to reset it manually with your patch
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 13 guests