Re[2]: Increasing sizes of bit vectors

From: Gary Barnett (gbarnett@polarnet.com)
Date: 01/17/97


At [Fri, 17 Jan 1997 13:12:51 -0500 (EST)]
Niese-Petersen <Tenp@cris.com> wrote:

>  On Fri, 17 Jan 1997, Sammy wrote:
>  
>  > 
>  > On Thu, 16 Jan 1997, Niese-Petersen wrote:
>  > 
>  > - On Fri, 17 Jan 1997, Chris Warren wrote:
>  > - 
>  > - > I think this may have been covered before, but I can't remember....
>  > - > My problem is this.... I *NEED* 42 ITEM_XXXXX extra flags. Now I was
>  > - > wondering if it would be possible to change...
>  > - 
>  > -   I am working on an idea for more than the 32 bitvectors, with help
>  > - of an array.  It's not a small process, but worth it I think.
>  > - Hopefully I get time this coming weekend to test, what I have done 
>  > - so far.
>  > -   The obj files will be a job tho, since it got to read more than on
>  > - bit field.  But then again, an obj. converter is always good to code
>  > - and have for later use :)
>  > 
>  > How about this:
>  > 
>  > Change long room_flags to long room_flags[2], and do the same with all
>  > other bitvectors.
>  > 
>  > Change all your ROOM defines from binary to decimal like this:
>  > 
>  > #define ROOM_DARK	0
>  > #define ROOM_DEATH	1
>  > #define ROOM_NOMOB	2
>  > #define ROOM_INDOORS	3  // etc... and do the same for other bitvectors
>  > 
>  > change your flag macros to these:
>  > 
>  > #define SET_BIT(var, bit) ((var)[(bit)/32] |= 1 << ((bit) % 32))
>  > #define TOGGLE_BIT(var, bit) ((var)[(bit)/32] ^= 1 << ((bit) % 32))
>  > #define REMOVE_BIT(var, bit) ((var)[(bit)/32] &= ~(1 << ((bit) % 32)))
>  > #define IS_SET(flag, bit) ((flag)[(bit)/32] & 1 << ((bit) % 32))
>  > 
>  > Now you can use up to 64 flags in each bitvector.  You'll have to change
>  > the pfile, but you can keep the world files the same if you modify
>  > asciiflag_conv to allow 64 flags.  You can get 64 flags using lowercase,
>  > then uppercase, then digits, then one more character, like a '+'.  Note
>  > that this will make worldfile bitvectors in integer format unusable, so
>  > you'll have to convert any old style bitvecotrs to ascii bitvectors first.
>  > 
>  > Another problem is that you can't set, remove, or toggle multiple flags,
>  > so:
>  > 
>  > SET_BIT(PLR_FLAGS(ch), PLR_WRITING | PLR_MAILING);
>  > 
>  > Must be changed to:
>  > 
>  > SET_BIT(PLR_FLAGS(ch), PLR_WRITING);
>  > SET_BIT(PLR_FLAGS(ch), PLR_WRITING);
>  > 
>  > If you've got olc, you'll need to make some changes there too.
>  > 
>  > Oh and sprinttypes, and any other functions/macros that deal with
>  > bitvectors will need small mods.
>  > 
>  
>  Well what a surprice. Just the idea I wrote about a month ago, plus what I
>  was talking about [read above] ..
>  
>  When I do get my code tested, it will have possibility for 128 flags, in
>  most bitvector flags.
>  
>  
>  Erik Niese-Petersen
>  AKA Quint the typo dane
>  Realms of Darkness IMP

This approach would seem to be obvious. The fact that it hasn't been
suggested on the list makes me wonder if there are 'well' known problems
with it?

  bool mybool[HOW_MANY]; /* added to whatever struct you need */

GET_WHATEVER(ch, x) ((ch)->wherever.mybool[x]) seems to work
quite effectively for me. And the upper limit is significantly higher
than any one variable will allow :-)

--Mallory


+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



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