Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Remove map_adjust_[xy] invocations from server (PR#1003)
Home

[Freeciv-Dev] Remove map_adjust_[xy] invocations from server (PR#1003)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Remove map_adjust_[xy] invocations from server (PR#1003)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Thu, 11 Oct 2001 14:06:33 -0700 (PDT)

This is basically a resubmission of my earlier map_adjust-3 patch, which
was seemingly rejected (I think there was some miscommunication there).

It substitutes in is_real_tile, normalize_map_pos, and is_normal_map_pos
in place of topology-specific code that does the same thing.


The only issue I believe is that I replace

  x2 = map_adjust_x(x);
  y2 = y;

with

  x2 = x, y2=y;
  assert(is_real_tile(x2, y2));
  normalize_map_pos(&x2, &y2);

alternately, a MACRO can be used to make this check (which I think is
what Raimar wants), perhaps something like

#define CHECK_MAP_POS(x, y)
{
  assert(is_real_tile(x, y));
  nearest_real_pos(&x, &y);
}

or

#define CHECK_MAP_POS(x, y)
{
  int is_real = normalize_map_pos(&x, &y);
  assert(is_real);
}

I'm happy with just about any solution here, so long as it asserts
is_real when in debugging mode.  Running nearest_real_pos will be
slightly safer in NDEBUG mode.  The second macro is slightly faster than
my current code.

Note the similarity between either of these macros and check_coords. 
The difference is that check_coords expects the parameters to be normal,
whereas this code only expects them to be real.

jason
? rc
? old
? topology
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.96
diff -u -r1.96 map.h
--- common/map.h        2001/10/09 16:26:46     1.96
+++ common/map.h        2001/10/11 21:02:32
@@ -402,8 +402,7 @@
   int x_itr, y_itr, dir_itr, MACRO_border;                                    \
   int MACRO_center_x = (center_x);                                            \
   int MACRO_center_y = (center_y);                                            \
-  assert(0 <= MACRO_center_y && MACRO_center_y < map.ysize                    \
-         && 0 <= MACRO_center_x && MACRO_center_x < map.xsize);               \
+  assert(is_normal_map_pos(MACRO_center_x, MACRO_center_y));                  \
   MACRO_border = (MACRO_center_y == 0                                         \
                   || MACRO_center_x == 0                                      \
                   || MACRO_center_y == map.ysize-1                            \
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.34
diff -u -r1.34 barbarian.c
--- server/barbarian.c  2001/08/30 13:00:15     1.34
+++ server/barbarian.c  2001/10/11 21:02:33
@@ -152,7 +152,7 @@
 **************************************************************************/
 static int is_free_land(int x, int y, struct player *who)
 {
-  if( y < 0 || y >= map.ysize ||
+  if( !is_real_tile(x, y) ||
       map_get_terrain(x,y) == T_OCEAN ||
       is_non_allied_unit_tile(map_get_tile(x, y), who) )
     return 0;
@@ -165,7 +165,7 @@
 **************************************************************************/
 static int is_free_sea(int x, int y, struct player *who)
 {
-  if( y < 0 || y >= map.ysize ||
+  if( !is_real_tile(x, y) ||
       map_get_terrain(x,y) != T_OCEAN ||
       is_non_allied_unit_tile(map_get_tile(x, y), who) )
     return 0;
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.74
diff -u -r1.74 mapgen.c
--- server/mapgen.c     2001/10/11 12:37:06     1.74
+++ server/mapgen.c     2001/10/11 21:02:34
@@ -802,7 +802,7 @@
       if (terrain_is_clean(x,y)) {
        if (map_get_terrain(x, y) != T_RIVER &&
            !(map_get_special(x, y) & S_RIVER)) {
-         map_set_terrain(map_adjust_x(x), y, T_HILLS);
+         map_set_terrain(x, y, T_HILLS);
        }
        cartesian_adjacent_iterate(x, y, x1, y1) {
          if (myrand(100) > 66 &&
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.200
diff -u -r1.200 plrhand.c
--- server/plrhand.c    2001/10/08 12:02:08     1.200
+++ server/plrhand.c    2001/10/11 21:02:35
@@ -870,7 +870,7 @@
   genmsg.event = event;
 
   conn_list_iterate(*dest, pconn) {
-    if (y >= 0 && y < map.ysize && server_state >= RUN_GAME_STATE
+    if (is_real_tile(x, y) && server_state >= RUN_GAME_STATE
        && ((pconn->player==NULL && pconn->observer)
            || (pconn->player!=NULL && map_get_known(x, y, pconn->player)))) {
       genmsg.x = x;
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.12
diff -u -r1.12 sanitycheck.c
--- server/sanitycheck.c        2001/09/30 21:27:10     1.12
+++ server/sanitycheck.c        2001/10/11 21:02:35
@@ -128,8 +128,7 @@
        assert(unit_owner(punit) == pplayer);
       } unit_list_iterate_end;
 
-      assert(pcity->x < map.xsize && pcity->x >= 0);
-      assert(pcity->y < map.ysize && pcity->y >= 0);
+      assert(is_normal_map_pos(pcity->x, pcity->y));
 
       assert(map_get_terrain(pcity->x, pcity->y) != T_OCEAN);
 
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.111
diff -u -r1.111 settlers.c
--- server/settlers.c   2001/10/04 20:23:37     1.111
+++ server/settlers.c   2001/10/11 21:02:36
@@ -404,10 +404,10 @@
  (via goto)
 **************************************************************************/
 static int is_already_assigned(struct unit *myunit, struct player *pplayer, 
int x, int y)
-{ 
-  x=map_adjust_x(x);
-  y=map_adjust_y(y);
-  if (same_pos(myunit->x, myunit->y, x, y) || 
+{
+  assert(is_real_tile(x, y));
+  normalize_map_pos(&x, &y);
+  if (same_pos(myunit->x, myunit->y, x, y) ||
       same_pos(myunit->goto_dest_x, myunit->goto_dest_y, x, y)) {
 /* I'm still not sure this is exactly right -- Syela */
     unit_list_iterate(map_get_tile(x, y)->units, punit)
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.140
diff -u -r1.140 unittools.c
--- server/unittools.c  2001/10/06 11:54:31     1.140
+++ server/unittools.c  2001/10/11 21:02:38
@@ -1627,12 +1627,11 @@
   punit->id=get_next_id_number();
   idex_register_unit(punit);
   punit->owner=pplayer->player_no;
-  punit->x = map_adjust_x(x); /* was = x, caused segfaults -- Syela */
-  punit->y=y;
-  if (y < 0 || y >= map.ysize) {
-    freelog(LOG_ERROR, "Whoa!  Creating %s at illegal loc (%d, %d)",
-           get_unit_type(type)->name, x, y);
-  }
+
+  assert(is_real_tile(x, y));
+  normalize_map_pos(&x, &y);
+  punit->x = x, punit->y = y;
+
   punit->goto_dest_x=0;
   punit->goto_dest_y=0;
   

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