Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: [Patch] Special testing
Home

[Freeciv-Dev] Re: [Patch] Special testing

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: [Patch] Special testing
From: Petr Baudis <pasky@xxxxxxxxxxx>
Date: Sun, 17 Feb 2002 14:00:11 +0100

Dear diary, on Sun, Feb 17, 2002 at 11:59:36AM CET, I got a letter,
where Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> told me, that...
> > > Index: client/gui-gtk/mapview.c
> > > ===================================================================
> > > RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
> > > retrieving revision 1.117
> > > diff -u -r1.117 mapview.c
> > > --- client/gui-gtk/mapview.c      2002/02/12 08:42:23     1.117
> > > +++ client/gui-gtk/mapview.c      2002/02/16 16:19:06
> > > @@ -2239,19 +2239,19 @@
> > >                    offset_x, offset_y_unit,
> > >                    width, height_unit, fog);
> > >    }
> > > -  if (BOOL_VAL(special & S_AIRBASE) && draw_fortress_airbase)
> > > +  if (contains_special(special, S_AIRBASE) && draw_fortress_airbase)
> > >      pixmap_put_overlay_tile_draw(pm,
> > >                            canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
> > >                            sprites.tx.airbase,
> > >                            offset_x, offset_y_unit,
> > >                            width, height_unit, fog);
> > > -  if (BOOL_VAL(special & S_FALLOUT) && draw_pollution)
> > > +  if (contains_special(special, S_FALLOUT) && draw_pollution)
> > >      pixmap_put_overlay_tile_draw(pm,
> > >                            canvas_x, canvas_y,
> > >                            sprites.tx.fallout,
> > >                            offset_x, offset_y,
> > >                            width, height, fog);
> > > -  if (BOOL_VAL(special & S_POLLUTION) && draw_pollution)
> > > +  if (contains_special(special, S_POLLUTION) && draw_pollution)
> > >      pixmap_put_overlay_tile_draw(pm,
> > >                            canvas_x, canvas_y,
> > >                            sprites.tx.pollution,
> > > @@ -2287,7 +2287,7 @@
> > >                              width, height_unit, fog);
> > >    }
> > >  
> > > -  if (BOOL_VAL(special & S_FORTRESS) && draw_fortress_airbase)
> > > +  if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)
> > >      pixmap_put_overlay_tile_draw(pm,
> > >                            canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
> > >                            sprites.tx.fortress,
> > 
> > As the variable 'special' is used here only in these ifs, we can as well
> > use map_has_special ;-).
> 
> But this will require extra lookups. It is also in a hot-path: the
> drawing code.

I don't think it would affect performance measurably... But I won't die if this
will stay as it is ;)).

> > > Index: common/city.c
> > > ===================================================================
> > > RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
> > > retrieving revision 1.144
> > > diff -u -r1.144 city.c
> > > --- common/city.c 2002/02/14 15:17:08     1.144
> > > +++ common/city.c 2002/02/16 16:19:18
> > > @@ -517,20 +517,20 @@
> > >    enum tile_special_type spec_t = map_get_special(x, y);
> > >    enum tile_terrain_type tile_t = map_get_terrain(x, y);
> > >  
> > > -  if (BOOL_VAL(spec_t & S_SPECIAL_1))
> > > +  if (contains_special(spec_t, S_SPECIAL_1))
> > >      s = get_tile_type(tile_t)->shield_special_1;
> > > -  else if (BOOL_VAL(spec_t & S_SPECIAL_2))
> > > +  else if (contains_special(spec_t, S_SPECIAL_2))
> > >      s = get_tile_type(tile_t)->shield_special_2;
> > >    else
> > >      s = get_tile_type(tile_t)->shield;
> > >  
> > > -  if (BOOL_VAL(spec_t & S_MINE))
> > > +  if (contains_special(spec_t, S_MINE))
> > >      s += (get_tile_type(tile_t))->mining_shield_incr;
> > > -  if (BOOL_VAL(spec_t & S_RAILROAD))
> > > +  if (contains_special(spec_t, S_RAILROAD))
> > >      s+=(s*terrain_control.rail_shield_bonus)/100;
> > > -  if (BOOL_VAL(spec_t & S_POLLUTION))
> > > +  if (contains_special(spec_t, S_POLLUTION))
> > >      s-=(s*terrain_control.pollution_shield_penalty)/100; /* The shields 
> > > here are icky */
> > > -  if (BOOL_VAL(spec_t & S_FALLOUT))
> > > +  if (contains_special(spec_t, S_FALLOUT))
> > >      s-=(s*terrain_control.fallout_shield_penalty)/100;
> > >    return s;
> > >  }
> > ..and the rest of diffs in this file..
> > 
> > As apparent from the context, you can use map_has_special() here as well.
> 
> Same as above.

Here the performance affection is probably even much smaller.

> > > Index: server/unittools.c
> > > ===================================================================
> > > RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
> > > retrieving revision 1.158
> > > diff -u -r1.158 unittools.c
> > > --- server/unittools.c    2002/02/14 15:17:41     1.158
> > > +++ server/unittools.c    2002/02/16 16:19:34
> > > @@ -1547,7 +1547,7 @@
> > >  
> > >    if ((is_allied_city_tile(map_get_tile(x, y), pplayer)
> > >         && !is_non_allied_unit_tile(map_get_tile(x, y), pplayer))
> > > -      || (BOOL_VAL(plrtile->special & S_AIRBASE)
> > > +      || (contains_special(plrtile->special, S_AIRBASE)
> > 
> > tile_has_special()
> > 
> > > @@ -2569,7 +2569,7 @@
> > >   map_get_player_tile(x, y, unit_owner(ptrans));
> > >      bool is_refuel_point =
> > >   is_allied_city_tile(map_get_tile(x, y), unit_owner(ptrans))
> > > - || (BOOL_VAL(plrtile->special & S_AIRBASE)
> > > + || (contains_special(plrtile->special, S_AIRBASE)
> > 
> > tile_has_special()
> 
> It is a player_tile and not a (map_)tile.

Aha, sorry then ;).

-- 

                                Petr "Pasky" Baudis

* elinks maintainer                * IPv6 guy (XS26 co-coordinator)
* IRCnet operator                  * FreeCiv AI hacker
.
No one can feel as helpless as the owner of a sick goldfish.
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/


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