Angband Forums

Angband Forums (http://angband.oook.cz/forum/index.php)
-   Development (http://angband.oook.cz/forum/forumdisplay.php?f=10)
-   -   Quick Term_erase question. (http://angband.oook.cz/forum/showthread.php?t=1934)

PaulBlay May 27, 2009 21:15

Quick Term_erase question.
 
And the question is ... what's this bit in aid of?

Code:

        if ((n > 0) && (scr_cc[x] == (char) -1) && (scr_aa[x] == 255))
        {
                x--;
                n++;
        }

Apart from not understanding it and wanting to my problem is that I am using wchar_t not char for text so that "(char) -1" and "255" might well not be compatible with the rest of the code now.

Incidentally, if I was going to guess, I'd suspect it might have something to do with BIGTILE mode? (Maybe not).

[EDIT] Yeah, looks like it's BIGTILE stuff. I think I've got a handle on it, but I guess I'll end up changing some code for this.

Pete Mack May 28, 2009 07:08

Ain't that some nice 80's-style code. Sweet!

It's stepping back the pad character of a tile in double-wide mode.

PaulBlay May 28, 2009 07:34

Quote:

Originally Posted by Pete Mack (Post 19604)
Ain't that some nice 80's-style code. Sweet!

Tell me about it. There don't seem to be any #defines for attribute values so you just have to hope somebody left a comment or hope your psychic powers are up to stuff. :D

Quote:

It's stepping back the pad character of a tile in double-wide mode.
Yeah, I figured it was something like that. I'm going to have to do similar stuff for handling double-width characters as well.

Pete Mack May 28, 2009 07:39

I can write it more efficiently, if you like. The if statement is unnecessarily verbose.
Code:

        (n > 0) && (scr_cc[x] == (char) -1) && (scr_aa[x] == 255) && (x--, n++);

Nick May 28, 2009 12:24

Quote:

Originally Posted by PaulBlay (Post 19607)
Yeah, I figured it was something like that. I'm going to have to do similar stuff for handling double-width characters as well.

Andrew Doull has extended this for double and triple tiles - which I stole for FA. Working that out and debugging edge effect issues was a lot of fun :) You may find it useful to look at one of those implementations (Un or FA or O110u), or you may have a neater way of doing it.

PaulBlay May 28, 2009 12:28

Quote:

Originally Posted by Nick (Post 19611)
Andrew Doull has extended this for double and triple tiles - which I stole for FA.

Thanks, I'll probably have a look at that later.

Quote:

Originally Posted by Nick (Post 19611)
or you may have a neater way of doing it.

That seems unlikely. :p

zaimoni May 28, 2009 14:58

Quote:

Originally Posted by PaulBlay (Post 19585)
And the question is ... what's this bit in aid of?

Code:

        if ((n > 0) && (scr_cc[x] == (char) -1) && (scr_aa[x] == 255))
        {
                x--;
                n++;
        }

Apart from not understanding it and wanting to my problem is that I am using wchar_t not char for text so that "(char) -1" and "255" might well not be compatible with the rest of the code now.

(char)(-1) is just plain living dangerously. It's a warning silencer because char isn't guaranteed to be equivalent to signed char.

scr_aa originally was unsigned char; 255 is UCHAR_MAX assuming CHAR_BIT is 8 (which the entire V codebase does, I put a preprocessor test for this into Zaiband to trigger a preprocessing error on such unsupported systems).

If you're not using a proper UNICODE library, try WCHAR_MAX (C++) or WINT_MAX (C) in place of 255/UCHAR_MAX. [Note that the standards do *not* guarantee any particular encoding for wchar_t/wint_t . As usual, Solaris will give you a porting sunburn.] Note that you will want to use a proper UNICODE library, because Linux will railroad you into UTF-8 while Windows demands you use UCS-2 in practice.

PaulBlay May 28, 2009 15:19

Quote:

Originally Posted by zaimoni (Post 19614)
(char)(-1) is just plain living dangerously. It's a warning silencer because char isn't guaranteed to be equivalent to signed char.

scr_aa originally was unsigned char; 255 is UCHAR_MAX assuming CHAR_BIT is 8 (which the entire V codebase does, I put a preprocessor test for this into Zaiband to trigger a preprocessing error on such unsupported systems).

If you're not using a proper UNICODE library, try WCHAR_MAX (C++) or WINT_MAX (C) in place of 255/UCHAR_MAX.

I can see I'm going to have to stare blankly at the Term* functions for a few days for it to seep in. :rolleyes:

Quote:

[Note that the standards do *not* guarantee any particular encoding for wchar_t/wint_t . As usual, Solaris will give you a porting sunburn.] Note that you will want to use a proper UNICODE library, because Linux will railroad you into UTF-8 while Windows demands you use UCS-2 in practice.
My, admittedly simplistic, reasoning is that it's going to be hard enough to get everything working in Windows XP - I'll worry about the rest after I get that far. This is after all as much about practice getting my hands dirty with C++ as it is anything else as I'm very much a novice.


All times are GMT +1. The time now is 23:28.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.