The 32 bit limit.

From: Niese-Petersen (Tenp@cris.com)
Date: 12/18/96


Ok.. People have been asking about the 32 bit limit on different flags,
so I write a quick idea to get around it [at least the main handling]...

I'll make my example out from room flags, just so you get the idea.

room_data.room_flags got defines like:

#define	ROOM_DARK	(1 << 0)
#define ROOM_DEATH	(1 << 1)
etc..

Now.. do this instead:
Make the "int room_flags" to an array (of how many 32 bit blocks you want),
lets say "int room_flags[4]" in the structure room_data.

Now make all the room_flag defines like this:

#define ROOM_DARK		0
#define ROOM_DEATH		1
#define ROOM_NOMOB		2
etc..

Next step is to make some defines to handle the bits and array.

/* Defines to find INT and MOD for flag */
/* These two are not only for room_flags, but can be used generically */
#define ARRAY_BIT_INT(x)  ((x) / 32)
#define ARRAY_BIT_MOD(x)  ((x) % 32)

/* Defines to test, set, remove and toggle room_flags */
/* (a, x)  a = structure [room_data]  x = ROOM_xxx  */
#define IS_SET_BIT_RF(a, x)  (IS_SET(a.room_flags[ARRAY_BIT_INT(x)], \
			      (1 << ARRAY_BIT_MOD(x))))
#define SET_BIT_RF(a, x) (SET_BIT(a.room_flags[ARRAY_BIT_INT(x)], \
			  (1 << ARRAY_BIT_MOD(x))))
#define REMOVE_BIT_RF(a, x) (REMOVE_BIT(a.room_flags[ARRAY_BIT_INT(x)], \
			     (1 << ARRAY_BIT_MOD(x))))
#define TOGGLE_BIT_RF(a, x) (TOGGLE_BIT(a.room_flags[ARRAY_BIT_INT(x)], \
			     (1 << ARRAY_BIT_MOD(x))))



That's general it. The rest is up to you folks, so the rest of the code
works. But an array with 4, 32 blocks of bits, give you ofcoz 4 times 32,
which is 128 "bits".. 

Enjoy..


Erik Niese-Petersen
Aka Quint the typo dane.
Realms of Darkness IMP 

PS. All this is directly made outta the mind, and not tested, so you were
warned.  :)





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