[Freeciv-Dev] Re: bitvector unit flags/roles patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Tue, May 14, 2002 at 12:07:11AM +0200, Per I. Mathisen wrote:
> Since we have run out of unit flags, I have made this patch which doubles
> the number of available flags, and makes it easy to increase the number
> should that be necessary again. It is based on bitvector macros written by
> Vasco, and many thanks to Vasco for vital debug aid while writing it. (All
> remaining bugs are my fault, of course.)
>
> Please look closely at this patch, since I've stared myself blind at it
> and many a bug could lurk beneath the surface.
>
> Autogame behaviour is identical to pre-patch.
> - int flags;
> - int roles; /* a client-side-ai might be interested */
> + bv_set flags;
> + bv_set roles;
> #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
>
> +/**** BIT ARRAYS ****/
> +#define BV_SETSIZE 64 /* this number MUST be >= 8! */
> +
> +typedef unsigned char uint_8;
> +#define _BV_DELT(b) ((b) >> 0x3)
> +#define _BV_MASK(b) (1 << ((b) & 0x7))
> +#define _BV_BITS(s) ((s)->bits)
> +
> +typedef struct bv_set {
> + uint_8 bits[_BV_DELT(BV_SETSIZE)];
> +} bv_set;
It should be possible to have different sized bitsets. So that is
reads:
+ bv_set(LAST_FLAG) flags;
This will also allow the use of such bit sets in other parts of the
code.
> +bool unit_type_flag_or_role(Unit_Type_id id, int flag_or_role)
...
> -static void precalc_one(int i, bool (*func_has)(Unit_Type_id, int))
> +static void precalc_one(int i)
...
> Unit_Type_id best_role_unit(struct city *pcity, int role)
Please don't do this. In the long run I want to make this
typesafe. This means to split best_role_unit and co into two sets of
functions.
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"I heard if you play the NT-4.0-CD backwards, you get a satanic message."
"That's nothing, if you play it forward, it installs NT-4.0"
|
|