Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays
Home

[Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Freeciv-dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: (PR#6182) remove some static map-sized arrays
From: Jason Short <jshort@xxxxxxxxxxxxxx>
Date: Thu, 18 Sep 2003 08:02:48 -0400
Reply-to: jdorje@xxxxxxxxxxxxxxxxxxxxx

Bursig Rafal wrote:
Sorry this msg was rejected by RT then I sent it to list


There are two remaining MAP_MAX_WIDTH * MAP_MAX_HEIGHT arrays: in
settlers.c.

These present problems when increasing MAP_MAX_WIDTH and
MAP_MAX_HEIGHT. They also break under gen-topologies. And of course they waste memory in general.

The attached patch replaces them with dynamic arrays, as is used
everywhere else.  Autogames are identical and slightly faster
(probably because of the direct memset to territory).

And I say that this will be slower that current code.

current we have static double array (
static nearness territory[MAP_MAX_WIDTH][MAP_MAX_HEIGHT]
and any access from map position is simple , just call territory[x1]
[y1] or minimap[x1][y1].

when we make this change we must made conversion from (x1,y1) -> index each time when we call TERRITORY(x1, y1) or MINIMAP(x1, y1)

this is make by calling
#define TERRITORY(map_x, map_y) territory[map_pos_to_index(map_x, map_y)]

#define MINIMAP(map_x, map_y) minimap[map_pos_to_index(map_x,  map_y)]

where #define map_pos_to_index(map_x, map_y)        \
  (CHECK_MAP_POS((map_x), (map_y)),           \
   (map_x) + (map_y) * map.xsize)

in this way you add one "*" operation when you want get terrain[][] or minimap[][]

I think you should look at the assembly generated by the code before jumping to that conclusion. There is a multiplication necessary for a terrain[][] access already. The only difference is that now we're multiplying by a variable (map.xsize) rather than a constant (MAP_MAX_WIDTH).

jason



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