Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: PATCH: cleanup in fill_tile_sprite_array (PR#1016)
Home

[Freeciv-Dev] Re: PATCH: cleanup in fill_tile_sprite_array (PR#1016)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: PATCH: cleanup in fill_tile_sprite_array (PR#1016)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Oct 2001 20:00:29 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Mon, Oct 15, 2001 at 11:33:41AM -0400, Jason Dorje Short wrote:
> Raimar Falke wrote:
> > 
> > On Mon, Oct 15, 2001 at 04:59:30AM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx 
> > wrote:
> > > The attached patch cleans up fill_tile_sprite_array and
> > > fill_tile_sprite_array_iso.  The new code still has some ugliness to it
> > > (I'm not sure how to get rid of this...), but should be safe with the
> > > check_map_pos changes and should also be topology-independent (which
> > > some of the old code was not).
> > 

> +/**********************************************************************
> +Converts from a dir8 (8-direction) direction to a dir4 (cardinal
> +direction) value.
> +***********************************************************************/
> +enum direction4 dir8_to_dir4(enum direction8 dir8)
> +{
> +  switch (dir8) {
> +    case DIR8_NORTH: return DIR4_NORTH;
> +    case DIR8_SOUTH: return DIR4_SOUTH;
> +    case DIR8_EAST:  return DIR4_EAST;
> +    case DIR8_WEST:  return DIR4_WEST;
> +    default:
> +      freelog(LOG_FATAL, "dir8_to_dir4: bad direction %d.", dir8);
> +      assert(0);

+ exit(1) or divide by zero.

> +      return DIR4_NORTH; /* best we can do */
> +  }
> +}
> +


> @@ -1573,10 +1551,17 @@
>    if(ptile->known==TILE_KNOWN_FOGGED && draw_fog_of_war) *sprs++ = 
> sprites.tx.fog;
>  
>    if(!citymode) {
> -    tileno = INDEX_NSEW((tile_is_known(abs_x0, abs_y0-1)==TILE_UNKNOWN),
> -                        (tile_is_known(abs_x0, abs_y0+1)==TILE_UNKNOWN),
> -                        (tile_is_known(abs_x0+1, abs_y0)==TILE_UNKNOWN),
> -                        (tile_is_known(abs_x0-1, abs_y0)==TILE_UNKNOWN));
> +    /* This is an ugly hack.  We're looking to find tileno, the set of BIT 
> masks
> +       for the directions that are unknown (black) */
> +    tileno = 0;
> +    adjc_dir_iterate(abs_x0, abs_y0, x, y, dir8) {
> +      if (!DIR_IS_CARDINAL(dir8))
> +     continue;
> +      if (tile_is_known(x, y) != TILE_UNKNOWN)
> +        tileno |= DIR4_BITS[dir8_to_dir4(dir8)];
> +    } adjc_dir_iterate_end;
> +    tileno = ~tileno & (BIT_NORTH | BIT_SOUTH | BIT_EAST | BIT_WEST);

What about

       int tmp[4];
       memset(tmp,0,sizeof(tmp));
> +    tileno = 0;
> +    adjc_dir_iterate(abs_x0, abs_y0, x, y, dir8) {
> +      if (!DIR_IS_CARDINAL(dir8))
> +     continue;
> +      if (tile_is_known(x, y) != TILE_UNKNOWN)
> +        tmp[dir8_to_dir4(dir8)]=1
> +    } adjc_dir_iterate_end;
> +    tileno = INDEX_NSEW(tmp[DIR4_NORTH],tmp[....));

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 A life? Cool! Where can I download one?


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