Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] PATCH: another simple topology cleanup (PR#1015)
Home

[Freeciv-Dev] PATCH: another simple topology cleanup (PR#1015)

[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] PATCH: another simple topology cleanup (PR#1015)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Mon, 15 Oct 2001 04:05:13 -0700 (PDT)

This patch makes some more more-or-less innocuous changes, replacing the
old-style code with the new normalize_map_pos, is_real_tile,
square_iterate, and the like.  This time the changes are done in the
client.

I haven't checked, but I'm pretty sure this overlaps entirely with
Gaute's patch to make is_real_tile replacements.

Also, the square_iterate in control.c is necessary for the check_map_pos
patch to work correctly.

jason
? rc
? old
? topology
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.60
diff -u -r1.60 control.c
--- client/control.c    2001/09/15 15:31:19     1.60
+++ client/control.c    2001/10/11 22:06:57
@@ -594,15 +594,11 @@
 **************************************************************************/
 void request_move_unit_direction(struct unit *punit, int dx, int dy)
 {
-  int dest_x, dest_y;
+  int dest_x = punit->x + dx, dest_y = punit->y + dy;
   struct unit req_unit;
 
-  dest_x = map_adjust_x(punit->x+dx);
-  dest_y = punit->y+dy; /* Not adjusted since if it needed to be adjusted it
-                          would mean that we tried to move off the map... */
-
   /* Catches attempts to move off map */
-  if (!is_real_tile(dest_x, dest_y))
+  if (!normalize_map_pos(&dest_x, &dest_y))
     return;
 
   req_unit = *punit;
@@ -1062,17 +1058,14 @@
   punit->hp=pinfo->hp;
   unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit);
 
-  for(y=punit->y-2; y<punit->y+3; ++y) { 
-    if(y<0 || y>=map.ysize)
-      continue;
-    for(x=punit->x-2; x<punit->x+3; ++x) { 
-      unit_list_iterate(map_get_tile(x, y)->units, pu)
+  square_iterate(punit->x, punit->y, 2, x, y) {
+      unit_list_iterate(map_get_tile(x, y)->units, pu) {
        if(unit_flag(pu, F_PARTIAL_INVIS)) {
-         refresh_tile_mapcanvas(map_adjust_x(pu->x), y, 1);
+         /* Do we really want to update more than once? */
+         refresh_tile_mapcanvas(x, y, 1);
        }
-      unit_list_iterate_end
-    }
-  }
+      } unit_list_iterate_end;
+  } square_iterate_end;
   
   if(!pinfo->carried && tile_is_known(punit->x,punit->y) == TILE_KNOWN)
     refresh_tile_mapcanvas(punit->x, punit->y, 1);
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.78
diff -u -r1.78 dialogs.c
--- client/gui-gtk/dialogs.c    2001/09/15 15:31:20     1.78
+++ client/gui-gtk/dialogs.c    2001/10/11 22:06:58
@@ -312,7 +312,7 @@
   GtkWidget *notify_dialog_shell, *notify_command, *notify_goto_command;
   GtkWidget *notify_label;
   
-  if (y < 0 || y >= map.ysize) {
+  if (!is_real_tile(x, y)) {
     popup_notify_dialog(_("Message:"), headline, lines);
     return;
   }
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.103
diff -u -r1.103 mapview.c
--- client/gui-gtk/mapview.c    2001/10/05 09:47:41     1.103
+++ client/gui-gtk/mapview.c    2001/10/11 22:07:00
@@ -226,7 +226,7 @@
 
   if (!citymode) {
     /* put any goto lines on the tile. */
-    if (y >= 0 && y < map.ysize) {
+    if (is_real_tile(x, y)) {
       int dir;
       for (dir = 0; dir < 8; dir++) {
        if (get_drawn(x, y, dir)) {
@@ -341,11 +341,7 @@
 
     /* If we are outside the map find the nearest tile, with distance as
        seen on the map. */
-    if (*map_y < 0) {
-      *map_y = 0;
-    } else if (*map_y >= map.ysize) {
-      *map_y = map.ysize - 1;
-    }
+    nearest_real_pos(map_x, map_y);
 
     *map_x %= map.xsize;
     if (*map_x < 0)
@@ -638,12 +634,12 @@
 }
 
 /**************************************************************************
-...
+This function is now identical in all GUI's except BeOS.
 **************************************************************************/
 void refresh_tile_mapcanvas(int x, int y, int write_to_screen)
 {
-  x = map_adjust_x(x);
-  y = map_adjust_y(y);
+  if (!normalize_map_pos(&x, &y))
+    return;
 
   if (tile_visible_mapcanvas(x, y)) {
     update_map_canvas(x, y, 1, 1, write_to_screen);
@@ -1550,12 +1546,11 @@
       }
     }
   } else { /* is_isometric */
-    int x, y;
     int x1, y1;
     for (x1 = 0; x1 < map_canvas_store_twidth; x1++) {
-      x = (map_view_x0 + x1) % map.xsize;
       for (y1 = 0; y1 < map_canvas_store_theight; y1++) {
-       y = map_view_y0 + y1;
+        int x = map_view_x0 + x1;
+       int y = map_view_y0 + y1;
        if (normalize_map_pos(&x, &y)) {
          show_desc_at_tile(x, y);
        }
Index: client/gui-mui/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/graphics.c,v
retrieving revision 1.15
diff -u -r1.15 graphics.c
--- client/gui-mui/graphics.c   2001/09/23 16:09:36     1.15
+++ client/gui-mui/graphics.c   2001/10/11 22:07:01
@@ -979,7 +979,7 @@
 
   if (!citymode) {
     /* put any goto lines on the tile. */
-    if (y >= 0 && y < map.ysize) {
+    if (is_real_tile(x, y)) {
       int dir;
       for (dir = 0; dir < 8; dir++) {
        if (get_drawn(x, y, dir)) {
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.66
diff -u -r1.66 mapclass.c
--- client/gui-mui/mapclass.c   2001/10/04 20:23:33     1.66
+++ client/gui-mui/mapclass.c   2001/10/11 22:07:02
@@ -562,12 +562,11 @@
         }
       }
     } else { /* is_isometric */
-      int x, y;
       int x1, y1;
       for (x1 = 0; x1 < map_canvas_store_twidth; x1++) {
-        x = (map_view_x0 + x1) % map.xsize;
         for (y1 = 0; y1 < map_canvas_store_theight; y1++) {
-         y = map_view_y0 + y1;
+          int x = map_view_x0 + x1;
+         int y = map_view_y0 + y1;
          if (normalize_map_pos(&x, &y)) {
            show_desc_at_tile(o, data, x, y);
          }
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.32
diff -u -r1.32 mapview.c
--- client/gui-mui/mapview.c    2001/09/15 21:25:08     1.32
+++ client/gui-mui/mapview.c    2001/10/11 22:07:03
@@ -372,16 +372,15 @@
 }
 
 /**************************************************************************
- GUI Independ (with new access functions)
+This function is now identical in all GUI's except BeOS.
 **************************************************************************/
 void refresh_tile_mapcanvas(int x, int y, int write_to_screen)
 {
-  x = map_adjust_x(x);
-  y = map_adjust_y(y);
+  if (!normalize_map_pos(&x, &y))
+    return;
 
-  if (tile_visible_mapcanvas(x, y))
-  {
-    update_map_canvas(x,y, 1, 1, write_to_screen);
+  if (tile_visible_mapcanvas(x, y)) {
+    update_map_canvas(x, y, 1, 1, write_to_screen);
   }
   overview_update_tile(x, y);
 }
@@ -490,11 +489,7 @@
 
     /* If we are outside the map find the nearest tile, with distance as
        seen on the map. */
-    if (*map_y < 0) {
-      *map_y = 0;
-    } else if (*map_y >= map.ysize) {
-      *map_y = map.ysize - 1;
-    }
+    nearest_real_pos(map_x, map_y);
 
     *map_x %= map.xsize;
     if (*map_x < 0)
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.5
diff -u -r1.5 mapview.c
--- client/gui-win32/mapview.c  2001/09/23 16:09:37     1.5
+++ client/gui-win32/mapview.c  2001/10/11 22:07:04
@@ -360,7 +360,7 @@
 
   if (!citymode) {
     /* put any goto lines on the tile. */
-    if (y >= 0 && y < map.ysize) {
+    if (is_real_tile(x, y)) {
       int dir;
       for (dir = 0; dir < 8; dir++) {
         if (get_drawn(x, y, dir)) {
@@ -1009,12 +1009,11 @@
       }
     }
   } else { /* is_isometric */
-    int x, y;
     int x1, y1;
     for (x1 = 0; x1 < map_view_width; x1++) {
-      x = (map_view_x + x1) % map.xsize;
       for (y1 = 0; y1 < map_view_width; y1++) {
-        y = map_view_y + y1;
+        int x = map_view_x + x1;
+        int y = map_view_y + y1;
         if (normalize_map_pos(&x, &y)) {
           show_desc_at_tile(hdc, x, y);
         }
@@ -1208,18 +1207,17 @@
 }
 
 /**************************************************************************
-
+This function is now identical in all GUI's except BeOS.
 **************************************************************************/
-void
-refresh_tile_mapcanvas(int x, int y, int write_to_screen)
+void refresh_tile_mapcanvas(int x, int y, int write_to_screen)
 {
-  x=map_adjust_x(x);
-  y=map_adjust_y(y);
-  
-  if(tile_visible_mapcanvas(x, y)) {
-    update_map_canvas(x,y, 1, 1, write_to_screen);
+  if (!normalize_map_pos(&x, &y))
+    return;
+
+  if (tile_visible_mapcanvas(x, y)) {
+    update_map_canvas(x, y, 1, 1, write_to_screen);
   }
-  overview_update_tile(x, y);   
+  overview_update_tile(x, y);
 }
 
 /**************************************************************************
@@ -1339,11 +1337,7 @@
 
     /* If we are outside the map find the nearest tile, with distance as
        seen on the map. */
-    if (*map_y < 0) {
-      *map_y = 0;
-    } else if (*map_y >= map.ysize) {
-      *map_y = map.ysize - 1;
-    }
+    nearest_real_pos(map_x, map_y);
 
     *map_x %= map.xsize;
     if (*map_x < 0)
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.57
diff -u -r1.57 dialogs.c
--- client/gui-xaw/dialogs.c    2001/09/15 15:31:23     1.57
+++ client/gui-xaw/dialogs.c    2001/10/11 22:07:05
@@ -311,7 +311,7 @@
   Widget notify_headline, notify_label;
   Dimension width, width2, width_1, width_2;
   
-  if (y < 0 || y >= map.ysize) {
+  if (!is_real_tile(x, y)) {
     popup_notify_dialog("Message:", headline, lines);
     return;
   }
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.83
diff -u -r1.83 mapview.c
--- client/gui-xaw/mapview.c    2001/10/04 20:23:34     1.83
+++ client/gui-xaw/mapview.c    2001/10/11 22:07:06
@@ -388,14 +388,14 @@
 }
 
 /**************************************************************************
-...
+This function is now identical in all GUI's except BeOS.
 **************************************************************************/
 void refresh_tile_mapcanvas(int x, int y, int write_to_screen)
 {
-  x=map_adjust_x(x);
-  y=map_adjust_y(y);
+  if (!normalize_map_pos(&x, &y))
+    return;
 
-  if(tile_visible_mapcanvas(x, y)) {
+  if (tile_visible_mapcanvas(x, y)) {
     update_map_canvas(x, y, 1, 1, write_to_screen);
   }
   overview_update_tile(x, y);
@@ -820,12 +820,12 @@
   if (!draw_city_names && !draw_city_productions)
     return;
 
-  for(y=0; y<map_canvas_store_theight; ++y) { 
-    int ry=map_view_y0+y;
-    if (ry >= map.ysize)
-      break;
+  for(y=0; y<map_canvas_store_theight; ++y) {
     for(x=0; x<map_canvas_store_twidth; ++x) { 
-      int rx=(map_view_x0+x)%map.xsize;
+      int rx = map_view_x0 + x;
+      int ry = map_view_y0 + y;
+      if (!normalize_map_pos(&rx, &ry))
+        continue;
       struct city *pcity;
       if((pcity=map_get_city(rx, ry))) {
 
@@ -1100,7 +1100,7 @@
 
   if (!citymode) {
     /* put any goto lines on the tile. */
-    if (y >= 0 && y < map.ysize) {
+    if (is_real_tile(x, y)) {
       int dir;
       for (dir = 0; dir < 8; dir++) {
        if (get_drawn(x, y, dir)) {

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