Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2002:
[Freeciv-Dev] Re: bitvector unit flags/roles patch
Home

[Freeciv-Dev] Re: bitvector unit flags/roles patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: bitvector unit flags/roles patch
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 May 2002 12:56:22 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

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"


[Prev in Thread] Current Thread [Next in Thread]