[circle][code] Re: Bitvectors

From: Count Kase (countkase@hotmail.com)
Date: 01/05/02


I think I found stuff broken...

"Henrik Stuart" <hstuart@geocities.com> wrote:
::Snip::
>    Warning: mailer code contained herein. Might explode without notice
>    if you like to complain about lines not being wrapped at exactly 79
>    characters. :o)
>
>    I know a lot of people already have responded to this,
>    but still think there is a nicer solution to it - ok, it might not
>    look as pretty with the #define's, but it works wonderfully (at
>    least that's what I've been able to see from 5 minutes of testing,
>    heh).
>
>    Instead of all the #define AFF_BLEH (1 << 3) etc., define affects
>    as #define AFF_BLEH 3, basically like you define skills/spells. Add
>    a #define at the bottom #define NUM_AFFECTS 200 (or however many
>    you have). Then just above the struct with affected_by add this:
>
>    #define NUM_AFFECT_VECTORS     (NUM_AFFECTS % (sizeof(long) * 8))

I think you need to increment the value of NUM_AFFECT_VECTORS
otherwise the array affected_by will almost always be an entry short
almost all of the time. also shouldn't that be a divison and not a modulos.
>
>    This is how many bitvectors you need to have in your array. Then in
>    the struct change: long affected_by; to long
>    affected_by[NUM_AFFECT_VECTORS];
>
::snip::
How about say this implentation instead:

#define NUM_AFFECT_VECTORS     (1+NUM_AFFECTS/32)
affected_by[NUM_AFFECT_VECTORS];

#define SET_AFFECT(ch,flag) (((ch)->char_specials.saved.\
   affected_by[((flag) /32)]) = (1 << ((flag) %32)))
#define TOGGLE_AFFECT(ch,flag) (((ch)->char_specials.saved.\
   affected_by[((flag) /32)]) ^= (1 << ((flag) %32)))
#define REMOVE_AFFECT(ch,flag) (((ch)->char_specials.saved.\
   affected_by[((flag) /32)]) &= ~(1 << ((flag) %32)))

Why 32 because I said so, also because the a long tends to be 32 bits on the
platforms I use. the code should only err to a larger array roughly 3+(1/8)%
of the time. also the extended disclaimer applies. this *should* work, but
don't count on it.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT