Re: Bitvectors

From: Mike Stilson (mike@velgarian.sytes.net)
Date: 01/04/02


On Fri, Jan 04, 2002 at 11:41:10AM -0600, David Cole wrote:
>> What about changing it to an array in char_specials_saved
>> (affected_by[4]) then change the definitions to
>>
>> #define AFF_FLAGGED(ch, num, flag) (IS_SET(AFF_FLAGS(ch), (num)), (flag))
>> #define AFF_FLAGS(ch, num) ((ch)->char_specials_saved.affected_by[(num)])
>> #define IS_AFFECTED(ch, num, flag) (AFF_FLAGGED((ch), (num), (skill))
>>
>In all honestly I liked to use the array, it looked allot cleaner & an more
>friendly. I was looking through the Vision source code, and I believe it
>used arrays, was very well done, and looked pretty simple. However my

No idea.  never looked at the vision source.
Actually to make it cleaner I'd change it all around to either bitfields
or at least change AFF_xxx from something like 1<<x to enums and then a
function to determine the correct array to use, but that'd be a helluva
lot of recoding.

>knowledge with arrays is rough at best, and I couldn't quit seem to grasp
>how to make it work with ASCII pfiles, It keep complaining about me using
>AFF_FLAGS(ch) = PFILE_AFF_FLAGGED (Something to that affect).

(note: I'd rather replace the hard-coded '4' with a define like:
#define NUM_AFF_ARRAYS 4 or something but anyway...

for(i=0;i<4;i++) AFF_FLAGS(ch, i) = PFILE_AFF_FLAGGED or whatever.
It'd need to match the macros above.

>Have you used this method with having acsii pfiles? If so, how did you over
>come the above?

I use a database for mine, but it'd be trivial.
(repeat for 1,2,3)
(pseudo-code from memory)

write:
fbprintf(fl, "Afff:\n");
for(i=0;i<4;i++) fbprintf(fl, %Ld\n", AFF_FLAGS(ch, i));

read:
if str_cmp(tag, 'Afff') {
        i = 0;
        while(i < 4) {
                fbgetline(fl, line);
                AFF_FLAGS(ch, i++) = atol(line);
        }
}

Of course, you could also define them as unsigned long long int's if
your compiler supports it and use 64 bits/flag, but that was discussed
at length in other threads.


-mike

--
   +---------------------------------------------------------------+
   | 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