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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7280) Tile pointer in unit struct
From: "Arnstein Lindgard" <a-l@xxxxxxx>
Date: Tue, 20 Jan 2004 09:24:10 -0800
Reply-to: rt@xxxxxxxxxxx

<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.


Arnstein

Attachment: tilepointer.diff.bz2
Description: BZip2 compressed data


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7280) Tile pointer in unit struct, Arnstein Lindgard <=