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: Bursig Rafal <bursig@xxxxxxxxx>
Date: Thu, 18 Sep 2003 14:43:26 +0200

Dnia 2003.09.18 14:02, Jason Short napisał(a):
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).

Dear Jason.

I don't say that you can't use it only ask...
Please THINK when you use such TERRAIN(x, y) marcros.
Those macros should be used only when we have't "index" variable defined in loop, current init_warmap() in good example. I don't know what CPU you have but my pice of silicon must make this multiply each time you use such macros.

I don't protest again replacing array[x][y] with array[index], I protest again using macros that hide index operations.

I say more we shouldn't make such macros that hide use of
map_pos_to_index(map_x, map_y) or index_to_map_pos(&map_x, &map_y, index) this let us optimise better our code.

Rafal



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