[Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Fri, Oct 05, 2001 at 12:15:26PM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:
> The following simple patch cleans up the smooth_map() function as
> discussed of freeciv-dev.
>
> jason
> ? rc
> ? profile.sh
> Index: server/mapgen.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
> retrieving revision 1.72
> diff -u -r1.72 mapgen.c
> --- server/mapgen.c 2001/09/30 21:55:34 1.72
> +++ server/mapgen.c 2001/10/05 19:13:23
> @@ -31,7 +31,7 @@
> #include "mapgen.h"
>
> /* Wrapper for easy access. It's a macro so it can be a lvalue. */
> -#define hmap(x,y) (height_map[(y) * map.xsize + map_adjust_x(x)])
> +#define hmap(x,y) (height_map[map_inx(x, y)])
>
> static void make_huts(int number);
> static void add_specials(int prob);
> @@ -1333,38 +1333,40 @@
> }
>
> /**************************************************************************
> - smooth_map should be viewed as a corrosion function on the map, it levels
> - out the differences in the heightmap.
> + smooth_map should be viewed as a corrosion function on the map, it
> + levels out the differences in the heightmap.
> **************************************************************************/
> static void smooth_map(void)
> {
> - int mx,my,px,py;
> - int a;
> -
> + int* new_hmap = fc_malloc(sizeof(int) * map.xsize * map.ysize);
> +
> + /* We make a new height map and then copy it back over the old one.
> + Care must be taken so that the new height map uses the exact
> + same storage structure as the real one - it must be the same
> + size and use the same indexing. --JDS */
> +
> whole_map_iterate(x, y) {
> - my = map_adjust_y(y - 1);
> - py = map_adjust_y(y + 1);
> - mx = map_adjust_x(x - 1);
> - px = map_adjust_x(x + 1);
> - a = hmap(x, y) * 2;
> -
> - a += hmap(px, my);
> - a += hmap(mx, my);
> - a += hmap(mx, py);
> - a += hmap(px, py);
> + int a = hmap(x, y) * 2; /* double-count this tile */
> + int dir;
>
> - a += hmap(x, my);
> - a += hmap(mx, y);
> + /* what about a new macro, adjc_nearest_iterate? */
> + for (dir=0; dir<8; dir++) {
> + int dx, dy, x2, y2;
> + DIRSTEP(dx, dy, dir); /* can't use MAPSTEP */
> + x2 = x + dx, y2 = y + dy;
> + nearest_real_pos(&x2, &y2);
What about taking a real adjc_iterate macro and count the real tiles?
Substitute "/10" by this count. Both methods (your patch and ignoring
un-real tiles) aren't wrong. They just differ. And we have already
changed the output of this method.
> - a += hmap(x, py);
> - a += hmap(px, y);
> + a += hmap(x2, y2);
> + }
>
> - a += myrand(60);
> - a -= 30;
> + a += myrand(60) - 30;
> if (a < 0)
> a = 0;
> - hmap(x, y) = a / 10;
> + new_hmap[map_inx(x, y)] = a / 10;
> } whole_map_iterate_end;
> +
> + memcpy(height_map, new_hmap, sizeof(int) * map.xsize * map.ysize);
> + free(new_hmap);
> }
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
reality.sys corrupt. Reboot Universe? (y,n,q)
- [Freeciv-Dev] PATCH: fix for smooth_map (PR#991), jdorje, 2001/10/05
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991),
Raimar Falke <=
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Jason Dorje Short, 2001/10/05
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Raimar Falke, 2001/10/05
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Jason Dorje Short, 2001/10/07
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Jason Dorje Short, 2001/10/07
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Raimar Falke, 2001/10/08
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Greg Wooledge, 2001/10/08
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Jason Dorje Short, 2001/10/08
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Jason Dorje Short, 2001/10/08
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Raimar Falke, 2001/10/08
- [Freeciv-Dev] Re: PATCH: fix for smooth_map (PR#991), Jason Dorje Short, 2001/10/08
|
|