Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old November 13, 2009, 21:05   #1
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 927
Donated: $10
will_asher is on a distinguished road
tiny little unimportant DJA bug that's been bugging me

There's a very unimportant bug that's been getting on my nerves and it involves a piece of code which is gibberish to me so I'm asking for help:

The "C" line in p_race text lists recommended classes for that race. The recommended classes show up in a brighter color in the birth menu, but this doesn't work. No recommended classes below the alchemist (class index 7) ever show up in a brighter color.

The relevant piece of code (I think) is this little function in birth.c
Code:
/* CLASS */
static void display_class(menu_type *menu, int oid, bool cursor,
							int row, int col, int width)
{
	byte attr = curs_attrs[0 != (rp_ptr->choice & (1L << oid))][0 != cursor];
	c_put_str(attr, c_name + c_info[oid].name, row, col);
}
I have no idea what (1L << oid) means so I can't fix the bug.

I looked in init.c where it reads the C: line in p_race.txt and it uses a similar thing:
Code:
		/* Hack - Parse this entry */
		pr_ptr->choice |= (1 << atoi(s));
Does this put a limit on how many C: entries there can be?
"atoi" isn't defined as a function anywhere so I assume it's an innate C thing that I haven't learned.
__________________
Will_Asher

Play DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home
will_asher is offline   Reply With Quote
Old November 13, 2009, 22:30   #2
d_m
Angband Devteam member
 
d_m's Avatar
 
Join Date: Aug 2008
Location: Philadelphia, PA, USA
Age: 39
Posts: 1,516
d_m is on a distinguished road
Here's the idea:

Code:
1 << 1 == 2
1 << 2 == 4
1 << 3 == 8
...
1 << 8 == 256
the "L" means that 1 is long, so it has more bits. This is important because if you shift the bit over too far it will fall off the end (I think).

Also, atoi is translating a string representation of a number into an int.

Code:
atoi("10") == 10
atoi("3") == 3
Hope this helps.
__________________
linux->xterm->screen->pmacs
d_m is offline   Reply With Quote
Old November 13, 2009, 22:40   #3
PowerDiver
Prophet
 
Join Date: Mar 2008
Posts: 2,712
PowerDiver is on a distinguished road
Quote:
Originally Posted by will_asher View Post
I looked in init.c where it reads the C: line in p_race.txt and it uses a similar thing:
Code:
		/* Hack - Parse this entry */
		pr_ptr->choice |= (1 << atoi(s));
Does this put a limit on how many C: entries there can be?
That's the bug. For some absurd reason, there are lots of things defined as bytes or chars that should not be. That variable is only 8 bits, so if you have more than 8 choices it will not work.

The simple change is to define choice to be a different size, say unsigned int, but that may break savefile compatibility if the value is written and reloaded from the savefile.
PowerDiver is offline   Reply With Quote
Old November 13, 2009, 22:55   #4
d_m
Angband Devteam member
 
d_m's Avatar
 
Join Date: Aug 2008
Location: Philadelphia, PA, USA
Age: 39
Posts: 1,516
d_m is on a distinguished road
Quote:
Originally Posted by PowerDiver View Post
That's the bug. For some absurd reason, there are lots of things defined as bytes or chars that should not be. That variable is only 8 bits, so if you have more than 8 choices it will not work.
Angband does *love* bit-encodings. I guess 640k should be enough for anyone, huh?
__________________
linux->xterm->screen->pmacs
d_m is offline   Reply With Quote
Old November 13, 2009, 23:34   #5
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 927
Donated: $10
will_asher is on a distinguished road
Thanks, it works as it should now.
BTW, 'choice' isn't used in savefiles, but I've already broken savefiles in other ways.
__________________
Will_Asher

Play DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home
will_asher is offline   Reply With Quote
Old November 13, 2009, 23:59   #6
PowerDiver
Prophet
 
Join Date: Mar 2008
Posts: 2,712
PowerDiver is on a distinguished road
Quote:
Originally Posted by d_m View Post
Angband does *love* bit-encodings. I guess 640k should be enough for anyone, huh?
It's one thing to try to save space in a structure that is used 1000 times. But to worry about space in a variable that is only used once is insane. It makes more sense to use a long than a byte if you think anyone might ever want to extend things in the future.
PowerDiver is offline   Reply With Quote
Old November 14, 2009, 09:46   #7
Magnate
Angband Devteam member
 
Join Date: May 2007
Location: London, UK
Posts: 5,057
Magnate is on a distinguished road
Send a message via MSN to Magnate Send a message via Yahoo to Magnate
Quote:
Originally Posted by PowerDiver View Post
It's one thing to try to save space in a structure that is used 1000 times. But to worry about space in a variable that is only used once is insane. It makes more sense to use a long than a byte if you think anyone might ever want to extend things in the future.
Don't forget the age of the codebase. Angband wasn't written from scratch - I'm not even sure if Moria was, but even if it was we're talking mid-eighties here. In those days you saved space in every variable, however rarely it was used.
Magnate is offline   Reply With Quote
Old November 30, 2009, 20:21   #8
konijn_
Hellband maintainer
 
konijn_'s Avatar
 
Join Date: Jul 2007
Location: New York, the Big Apple
Age: 42
Posts: 367
Donated: $120
konijn_ is on a distinguished road
Quote:
Originally Posted by Magnate View Post
Don't forget the age of the codebase. Angband wasn't written from scratch - I'm not even sure if Moria was, but even if it was we're talking mid-eighties here. In those days you saved space in every variable, however rarely it was used.
Plus, bitflags are inherently cool

T.
__________________
* Are you ready for something else ? Hellband 0.8.8 is out! *
konijn_ is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DJA: Tossing around ideas will_asher Variants 61 April 4, 2011 02:02
Tiny 3.1 bug Zikke Vanilla 1 January 8, 2009 22:41


All times are GMT +1. The time now is 15:25.


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