Quick Term_erase question.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaulBlay
    Knight
    • Jan 2009
    • 657

    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.
    Last edited by PaulBlay; May 27, 2009, 20:34.
    Currently turning (Angband) Japanese.
  • Pete Mack
    Prophet
    • Apr 2007
    • 6883

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

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

    Comment

    • PaulBlay
      Knight
      • Jan 2009
      • 657

      #3
      Originally posted by Pete Mack
      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.

      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.
      Currently turning (Angband) Japanese.

      Comment

      • Pete Mack
        Prophet
        • Apr 2007
        • 6883

        #4
        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++);

        Comment

        • Nick
          Vanilla maintainer
          • Apr 2007
          • 9639

          #5
          Originally posted by PaulBlay
          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.
          One for the Dark Lord on his dark throne
          In the Land of Mordor where the Shadows lie.

          Comment

          • PaulBlay
            Knight
            • Jan 2009
            • 657

            #6
            Originally posted by Nick
            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.

            Originally posted by Nick
            or you may have a neater way of doing it.
            That seems unlikely.
            Currently turning (Angband) Japanese.

            Comment

            • zaimoni
              Knight
              • Apr 2007
              • 590

              #7
              Originally posted by PaulBlay
              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.
              Zaiband: end the "I shouldn't have survived that" experience. V3.0.6 fork on Hg.
              Zaiband 3.0.10 ETA Mar. 7 2011 (Yes, schedule slipped. Latest testing indicates not enough assert() calls to allow release.)
              Z.C++: pre-alpha C/C++ compiler system (usable preprocessor). Also on Hg. Z.C++ 0.0.10 ETA December 31 2011

              Comment

              • PaulBlay
                Knight
                • Jan 2009
                • 657

                #8
                Originally posted by zaimoni
                (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.

                [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.
                Currently turning (Angband) Japanese.

                Comment

                Working...
                😀
                😂
                🥰
                😘
                🤢
                😎
                😞
                😡
                👍
                👎