[Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesia
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://RT::WebBaseURL.not.configured:80/Ticket/Display.html?id=10047 >
Here is a new version of the tiles patch.
First I went back over all the code in common, cleaning it up a bit. I
saved this diff (tiles-5), but skipped it here.
Then I tore back into the core of the code. I removed normalize_map_pos
and is_real_map_pos! I wanted to get rid of is_normal_map_pos but there
were too many users to do it immediately.
In the place of these functions go a new set: map_pos_to_tile and
map_pos_to_tile_unchecked. map_pos_to_tile is basically the same as the
current normalize_map_pos, except that it returns the tile for the
position after wrapping it. map_pos_to_tile_unchecked just does a
straight tile lookup - it's much faster and is used in iterators and
such which already check realness using is_border_map_pos.
There are also native and index versions of these two functions. The
are all just wrappers for each other of course.
The result is some _much_ prettier code. Here is an example from mapgen.c:
Old:
{
int xo, yo;
rand_map_pos(&xo, &yo);
MAP_TO_NATIVE_POS(&xon, &yon, xo, yo);
}
for (yn = pstate->n, xn = pstate->w;
yn < pstate->s && xn < pstate->e;
yn++, xn++) {
int map_x, map_y;
NATIVE_TO_MAP_POS(&map_x, &map_y,
xn + xon - pstate->w, yn + yon - pstate->n);
if (!normalize_map_pos(&map_x, &map_y)) {
return FALSE;
}
if (hnat(xn, yn) != 0 && is_near_land(map_x, map_y)) {
return FALSE;
}
}
New:
ptile = rand_map_pos();
for (yn = pstate->n, xn = pstate->w;
yn < pstate->s && xn < pstate->e;
yn++, xn++) {
struct tile *ptile = native_pos_to_tile(xn + ptile->nat_x - pstate->w,
yn + ptile->nat_y - pstate->n);
if (!ptile) {
return FALSE;
}
if (hmap(ptile) != 0 && is_near_land(ptile)) {
return FALSE;
}
}
because we can now work equally in all coordinate systems this operation
is much easier. (Natural coordinates aren't done this way and still
require an explicit conversion. This could be changed of course).
I'm quite happy with the changes. However it's still not finalized; I
didn't test this version very much (the mapview code needs some testing).
jason
tiles-6.diff.bz2
Description: application/bzip
- [Freeciv-Dev] Re: (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Per I. Mathisen, 2004/09/25
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Jason Short via RT, 2004/09/26
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Jason Short via RT, 2004/09/27
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates,
Jason Short via RT <=
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Marcelo Burda, 2004/09/28
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Jason Short via RT, 2004/09/28
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Jason Short via RT, 2004/09/28
- [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates, Jason Short via RT, 2004/09/28
|
|