Re: Adding Mob Action Bitvectors

From: Michael Buselli (mhbusell@midway.uchicago.edu)
Date: 04/06/96


     Sorry, but I believe the code you gave below to be incorrect.  Here's
what you should do:

#define eIS_SET(bitvector, pos)  \
        ((bitvector)[(pos) / 32] &  (1 << ((pos) % 32)))
#define eSET_BIT(bitvector, pos) \
        ((bitvector)[(pos) / 32] |= (1 << ((pos) % 32)))

and so on...  The difference is that I'm using the modulus division so 
that the bitshift is correct.  This assumes that value of (pos) is 0, 1, 
2, etc. instead of 1 << 0, 1 << 1, 1 << 2, etc. like bits are defined now.

     I personally have affected_by[4] in my code, as well as act[2] and
pref[2] due to expansion.  I don't use the above macros, however, because
I want to continue using | to join my flags.  You should use a macro for
those numbers.  I.e., my code says affected_by[AFF_VECTS] instead of
affected_by[4].  Then when you need to increase the number, you can just
change the macro... easier for me than you because I'm using ascii player
files and my mud is almost to the point that increasing those numbers
requires no change elsewhere in the code.  But as each month goes by I see
my mud look less and less like the circle 3 beta pl4 that I started with 
way back in December 94 anyway...

Michael Buselli
m-buselli@uchicago.edu
http://student-www.uchicago.edu/users/mhbusell/

--
On Fri, 5 Apr 1996, Wout Mertens wrote:
[parts snipped from various places below]
> How about making the flags just the bit position, eg 0, 1, 2, 3 etc
> And then:
> 
> #define eIS_SET(bitarray, pos) (((pos)<32? bitarray[0] : bitarray[1]) & \
>          1<<(pos))
> or even (for a LOT of flags)
> #define eIS_SET(bitarray, pos) (bitarray[pos/32] & 1<<pos)
> 
> etc
> Where bitarray is the necessary number of ints, of course.
> The second one might even be faster, considering that a SHL AX, 5 isn't 
> too costly... go with that one :) (Hope that your compiler is smart enough
> to know that '/32' == '>> 5', else just put pos>>5 aah what the hell I'm 
> babbling)
> 
> continuing:
> #define eSET(bitarray, pos) (bitarray[(pos)/32] |= 1<<(pos))
> #define eTOGGLE(...) (... ^= ...)



This archive was generated by hypermail 2b30 : 12/18/00 PST