Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#7280) Tile pointer in unit struct
Home

[Freeciv-Dev] Re: (PR#7280) Tile pointer in unit struct

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: a-l@xxxxxxx
Subject: [Freeciv-Dev] Re: (PR#7280) Tile pointer in unit struct
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Wed, 21 Jan 2004 00:08:24 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7280 >

On Tue, Jan 20, 2004 at 09:24:10AM -0800, Arnstein Lindgard wrote:
> 
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=7280 >
> 
> I added a tile pointer to the unit struct, and applied some grep
> dexterity.
> 
> + Old syntax:
> 
>   "map_get_tile(punit->x, punit->y)"
>   "map_get_city(punit->x, punit->y)"
>   "map_get_continent(punit->x, punit->y)"
>   "map_get_terrain(punit->x, punit->y)"
> 
>   New syntax:
> 
>   "punit->tile"
>   "punit->tile->city"
>   "punit->tile->continent"
>   "punit->tile->terrain"
> 
> + A unit's tile pointer is updated in move_unit(), where x and y are
>   also updated. Plus one instance when loading a savegame.
> 
> + Reduce instances of map_get_tile() from 366 to 323 in source.
> + Reduce instances of map_get_city() from 189 to 106 in source.
> 
> + Despite of that, profiling shows the number of actual function
>   calls are only reduced by 0.06% and 2% respectively.
> 
> + Reduce instances of map_get_continent() from 81 to 66 in source.
> + Reduce instances of map_get_terrain() from 178 to 163 in source.
> 
> + Identical autogames. Only small speed improvement.
> 
> I prefere the new syntax because it's it's shorter to write, and I
> would like to use those functions only when working in coordinates
> like with tile iterators. The relationship between unit's (x,y) and
> tilepointer can be handled in one place.

I dislike it because:
 - it is redundant
 - provide more than two ways to solve a thing
 - showns internal data

The last point could be solved by having functions/macros like:

  unit_tile(punit)
  unit_tile_city(punit)

which than use or don't use a cached tile pointer. So what about a
single new function/macro unit_tile(punit) and than writing
unit_tile(punit)->city?

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Using only the operating-system that came with your computer is just
  like only playing the demo-disc that came with your CD-player."




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