Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] Re: remove map_adjust_[xy] invocations (PR#1130)
Home

[Freeciv-Dev] Re: remove map_adjust_[xy] invocations (PR#1130)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: remove map_adjust_[xy] invocations (PR#1130)
From: Jason Short <vze2zq63@xxxxxxxxxxx>
Date: Tue, 18 Dec 2001 14:29:16 -0500
Reply-to: jdorje@xxxxxxxxxxxx

This is an update of the map_adjust patch for current CVS.

All of the old comments still apply.

jason

? jason.gz
? old
? topology
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.110
diff -u -r1.110 mapview.c
--- client/gui-gtk/mapview.c    2001/12/13 15:42:25     1.110
+++ client/gui-gtk/mapview.c    2001/12/18 19:27:33
@@ -584,7 +584,7 @@
 void move_unit_map_canvas(struct unit *punit, int x0, int y0, int dx, int dy)
 {
   static struct timer *anim_timer = NULL; 
-  int dest_x, dest_y;
+  int dest_x, dest_y, is_real;
 
   /* only works for adjacent-square moves */
   if ((dx < -1) || (dx > 1) || (dy < -1) || (dy > 1) ||
@@ -597,8 +597,10 @@
     update_unit_info_label(punit);
   }
 
-  dest_x = map_adjust_x(x0+dx);
-  dest_y = map_adjust_y(y0+dy);
+  dest_x = x0 + dx;
+  dest_y = y0 + dy;
+  is_real = normalize_map_pos(&dest_x, &dest_y);
+  assert(is_real);
 
   if (player_can_see_unit(game.player_ptr, punit) &&
       (tile_visible_mapcanvas(x0, y0) ||
@@ -1252,16 +1254,16 @@
     }
 
   } else { /* is_isometric */
-    int x_itr, y_itr;
+    int map_x, map_y;
     int canvas_x, canvas_y;
-
-    for (y_itr=y; y_itr<y+height; y_itr++) {
-      for (x_itr=x; x_itr<x+width; x_itr++) {
-       int map_x = map_adjust_x(x_itr);
-       int map_y = y_itr; /* not adjusted;, we want to draw black tiles */
 
-       get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y);
-       if (tile_visible_mapcanvas(map_x, map_y)) {
+    for (map_y=y; map_y<y+height; map_y++) {
+      for (map_x=x; map_x<x+width; map_x++) {
+       /*
+        * We don't normalize until later because we want to draw
+        * black tiles for unreal positions.
+        */
+       if (get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y)) {
          pixmap_put_tile(map_canvas_store,
                          map_x, map_y,
                          canvas_x, canvas_y, 0);
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.70
diff -u -r1.70 mapclass.c
--- client/gui-mui/mapclass.c   2001/12/08 15:15:52     1.70
+++ client/gui-mui/mapclass.c   2001/12/18 19:27:35
@@ -1436,16 +1436,19 @@
              /* A diagonal scrolling has happened */
              int newwidth = xget(o, MUIA_Map_HorizVisible);
              int newheight = xget(o, MUIA_Map_VertVisible);
-             int x_itr,y_itr,map_x,map_y,canvas_x,canvas_y;
+             int map_x,map_y;
 
              /* Draw the upper or lower complete free horiz space */
-             for (y_itr = y; y_itr < y + height; y_itr++) {
-               for (x_itr = data->horiz_first; x_itr < x + newwidth; x_itr++) {
-                 map_x = map_adjust_x(x_itr);
-                 map_y = y_itr;
- 
-                 get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y);
-                 put_tile(data->map_layer->rp, 
map_x,map_y,canvas_x,canvas_y,0);
+             for (map_y = y; map_y < y + height; map_y++) {
+               for (map_x = data->horiz_first; map_x < x + newwidth; map_x++) {
+                 /*
+                  * We don't normalize until later because we want to draw
+                  * black tiles for unreal positions.
+                  */
+                 int canvas_x, canvas_y;
+                 if (get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y)) {
+                   put_tile(data->map_layer->rp, 
map_x,map_y,canvas_x,canvas_y,0);
+                 }
                }
              }
 
@@ -1583,16 +1586,15 @@
        }
       } else
       {
-       int x_itr, y_itr;
-       int canvas_x, canvas_y;
-
-       for (y_itr=y; y_itr<y+height; y_itr++) {
-         for (x_itr=x; x_itr<x+width; x_itr++) {
-           int map_x = map_adjust_x(x_itr);
-           int map_y = y_itr; /* not adjusted;, we want to draw black tiles */
-
-           get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y);
-           if (tile_visible_mapcanvas(map_x, map_y)) {
+        int map_x, map_y;
+       for (map_y=y; map_y<y+height; map_y++) {
+         for (map_x=x; map_x<x+width; map_x++) {
+           /*
+            * We don't normalize until later because we want to draw
+            * black tiles for unreal positions.
+            */
+           int canvas_x, canvas_y;
+           if (get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y)) {
              put_tile(data->map_layer->rp,map_x, map_y, canvas_x, canvas_y, 0);
            }
          }
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.37
diff -u -r1.37 mapview.c
--- client/gui-mui/mapview.c    2001/12/13 15:42:26     1.37
+++ client/gui-mui/mapview.c    2001/12/18 19:27:36
@@ -434,7 +434,7 @@
 **************************************************************************/
 void move_unit_map_canvas(struct unit *punit, int x0, int y0, int dx, int dy)
 {
-  int dest_x, dest_y;
+  int dest_x, dest_y, is_real;
   /* only works for adjacent-square moves */
   if ((dx < -1) || (dx > 1) || (dy < -1) || (dy > 1) ||
       ((dx == 0) && (dy == 0))) {
@@ -446,8 +446,10 @@
     update_unit_info_label(punit);
   }
 
-  dest_x = map_adjust_x(x0+dx);
-  dest_y = map_adjust_y(y0+dy);
+  dest_x = x0 + dx;
+  dest_y = y0 + dy;
+  is_real = normalize_map_pos(&dest_x, &dest_y);
+  assert(is_real);
 
   if (player_can_see_unit(game.player_ptr, punit) &&
       (tile_visible_mapcanvas(x0, y0) ||
Index: client/gui-mui/overviewclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/overviewclass.c,v
retrieving revision 1.14
diff -u -r1.14 overviewclass.c
--- client/gui-mui/overviewclass.c      2001/08/05 14:44:59     1.14
+++ client/gui-mui/overviewclass.c      2001/12/18 19:27:36
@@ -109,6 +109,9 @@
 
 static VOID Overview_HandleMouse(Object * o, struct Overview_Data *data, LONG 
x, LONG y)
 {
+  /* For now we only ascertain that the _center_ position is real. */
+  nearest_real_pos(&x, &y);
+
   x = ((x - _mleft(o)) % _mwidth(o))/data->ov_ScaleX;
   y = (y - _mtop(o))/data->ov_ScaleY;
 
@@ -122,13 +125,6 @@
     y -= data->rect_height / 2;
   }
 
-  x = map_adjust_x(x);
-
-  if (y < 0)
-    y = 0;
-  if (y + data->rect_height > data->ov_MapHeight)
-    y = data->ov_MapHeight - data->rect_height;
-
   if (data->rect_left != x || data->rect_top != y)
   {
     SetAttrs(o,
@@ -262,16 +258,26 @@
   {
     LONG x1,x2,y1,y2,scalex,scaley;
     BOOL twoparts;
+    int is_real;
 
     scalex = data->ov_ScaleX;
     scaley = data->ov_ScaleY;
 
-    x1 = _mleft(o) + map_adjust_x(data->rect_left) * scalex;
-    x2 = _mleft(o) + map_adjust_x(data->rect_left + data->rect_width) * scalex;
+    /* This makes little sense to me. */
+    x1 = data->rect_left;
+    y1 = data->rect_top;
+    is_real = normalize_map_pos(&x1, &y1);
+    assert(is_real);
+    x1 = _mleft(o) + x1 * scalex;
+    y1 = _mtop(o) + y1 * scaley;
+
+    x2 = data->rect_left + data->rect_width;
+    y2 = data->rect_top + data->rect_height;
+    is_real = normalize_map_pos(&x2, &y2);
+    assert(is_real);
+    x2 = _mleft(o) + x2 * scalex;
+    y2 = _mtop(o) + y2 * scaley - 1;
 
-    y1 = _mtop(o) + data->rect_top * scaley;
-    y2 = y1 + data->rect_height * scaley - 1;
-
     if (x2 < x1)
       twoparts = TRUE;
     else
@@ -510,6 +516,7 @@
       {
        /* Refresh Single */
        LONG x,y,rx1,rx2,ry1,ry2,pix_x,pix_y;
+       int is_real;
 
        x = data->x;
        y = data->y;
@@ -521,11 +528,16 @@
        RectFill(_rp(o), pix_x, pix_y, pix_x + scalex - 1, pix_y + scaley - 1);
 
         /* Check if the view rectangle has been overwritten */
-       rx1 = map_adjust_x(data->rect_left);
-       rx2 = map_adjust_x(data->rect_left + data->rect_width - 1);
-       ry1 = data->rect_top;
-       ry2 = ry1 + data->rect_height - 1;
-
+        rx1 = data->rect_left;
+        ry1 = data->rect_top;
+        is_real = normalize_map_pos(&rx1, &ry1);
+        assert(is_real);
+
+       rx2 = data->rect_left + data->rect_width - 1;
+       ry2 = data->rect_top + data->rect_height - 1;
+       is_real = normalize_map_pos(&rx2, Yry2);
+       assert(is_real);
+       
         if (((x == rx1 || x == rx2) && (y >= ry1 && y <= ry2)) ||
             ((y == ry1 || y == ry2) && (x >= rx1 && x <= rx2))) {
          Overview_DrawRect(o,data);
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.46
diff -u -r1.46 mapctrl.c
--- client/gui-xaw/mapctrl.c    2001/10/14 15:28:37     1.46
+++ client/gui-xaw/mapctrl.c    2001/12/18 19:27:37
@@ -238,16 +238,18 @@
 **************************************************************************/
 void mapctrl_btn_wakeup(XEvent *event)
 {
-  int xtile, ytile;
+  int map_x, map_y, is_real;
   XButtonEvent *ev=&event->xbutton;
 
   if(get_client_state()!=CLIENT_GAME_RUNNING_STATE)
     return;
 
-  xtile=map_adjust_x(map_view_x0+ev->x/NORMAL_TILE_WIDTH);
-  ytile=map_adjust_y(map_view_y0+ev->y/NORMAL_TILE_HEIGHT);
+  map_x=map_view_x0+ev->x/NORMAL_TILE_WIDTH;
+  map_y=map_view_y0+ev->y/NORMAL_TILE_HEIGHT;
+  is_real = normalize_map_pos(&map_x, &map_y);
+  assert(is_real);
 
-  wakeup_sentried_units(xtile,ytile);
+  wakeup_sentried_units(map_x,map_y);
 }
 
 /**************************************************************************
@@ -308,12 +310,13 @@
 **************************************************************************/
 void update_line(int window_x, int window_y)
 {
-  int x, y, old_x, old_y;
- 
   if ((hover_state == HOVER_GOTO || hover_state == HOVER_PATROL)
       && draw_goto_line) {
-    x = map_adjust_x(map_view_x0 + window_x/NORMAL_TILE_WIDTH);
-    y = map_adjust_y(map_view_y0 + window_y/NORMAL_TILE_HEIGHT);
+    int old_x, old_y;
+    int x = map_view_x0 + window_x/NORMAL_TILE_WIDTH;
+    int y = map_view_y0 + window_y/NORMAL_TILE_HEIGHT;
+    int is_real = normalize_map_pos(&x, &y);
+    assert(is_real);
  
     get_line_dest(&old_x, &old_y);
     if (old_x != x || old_y != y) {
@@ -358,10 +361,10 @@
   if(get_client_state()!=CLIENT_GAME_RUNNING_STATE)
     return;
 
-  map_x = ev->x / NORMAL_TILE_WIDTH;
-  map_y = ev->y / NORMAL_TILE_HEIGHT;
-  map_x = map_adjust_x(map_view_x0 + map_x);
-  map_y = map_adjust_y(map_view_y0 + map_y);
+  map_x = map_view_x0 + ev->x / NORMAL_TILE_WIDTH;
+  map_y = map_view_y0 + ev->y / NORMAL_TILE_HEIGHT;
+  is_valid = normalize_map_pos(&map_x, &map_y);
+  assert(is_valid);
 
   if (!(pcity = find_city_near_tile(map_x, map_y)))
     return;
@@ -394,15 +397,17 @@
 **************************************************************************/
 void mapctrl_key_city_workers(XEvent *event)
 {
-  int x,y;
+  int x,y, is_real;
   XButtonEvent *ev=&event->xbutton;
   struct city *pcity;
 
   if(get_client_state()!=CLIENT_GAME_RUNNING_STATE)
     return;
 
-  x=ev->x/NORMAL_TILE_WIDTH; y=ev->y/NORMAL_TILE_HEIGHT;
-  x=map_adjust_x(map_view_x0+x); y=map_adjust_y(map_view_y0+y);
+  x=map_view_x0 + ev->x/NORMAL_TILE_WIDTH;
+  y=map_view_y0 + ev->y/NORMAL_TILE_HEIGHT;
+  is_real = normalize_map_pos(&x, &y);
+  assert(is_real);
 
   pcity = find_city_near_tile(x,y);
   if(pcity==NULL) return;
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.90
diff -u -r1.90 mapview.c
--- client/gui-xaw/mapview.c    2001/12/13 15:42:28     1.90
+++ client/gui-xaw/mapview.c    2001/12/18 19:27:37
@@ -387,7 +387,7 @@
 void move_unit_map_canvas(struct unit *punit, int x0, int y0, int dx, int dy)
 {
   static struct timer *anim_timer = NULL; 
-  int dest_x, dest_y;
+  int dest_x, dest_y, is_real;
 
   /* only works for adjacent-square moves */
   if ((dx < -1) || (dx > 1) || (dy < -1) || (dy > 1) ||
@@ -395,8 +395,10 @@
     return;
   }
 
-  dest_x = map_adjust_x(x0+dx);
-  dest_y = map_adjust_y(y0+dy);
+  dest_x = x0 + dx;
+  dest_y = y0 + dy;
+  is_real = normalize_map_pos(&dest_x, &dest_y);
+  assert(is_real);
 
   if (player_can_see_unit(game.player_ptr, punit) &&
       (tile_visible_mapcanvas(x0, y0) ||
@@ -451,8 +453,11 @@
 **************************************************************************/
 void get_center_tile_mapcanvas(int *x, int *y)
 {
-  *x = map_adjust_x(map_view_x0+map_canvas_store_twidth/2);
-  *y = map_adjust_y(map_view_y0+map_canvas_store_theight/2);
+  int is_real;
+  *x = map_view_x0+map_canvas_store_twidth/2;
+  *y = map_view_y0+map_canvas_store_theight/2;
+  is_real = normalize_map_pos(x, y);
+  assert(is_real);
 }
 
 /**************************************************************************
@@ -679,16 +684,15 @@
 void update_map_canvas(int x, int y, int width, int height, 
                       int write_to_screen)
 {
-  int x_itr, y_itr;
-  int canvas_x, canvas_y;
-
-  for (y_itr=y; y_itr<y+height; y_itr++) {
-    for (x_itr=x; x_itr<x+width; x_itr++) {
-      int map_x = map_adjust_x(x_itr);
-      int map_y = y_itr;
-      get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y);
+  int map_x, map_y, canvas_x, canvas_y;
 
-      if (tile_visible_mapcanvas(map_x, map_y)) {
+  for (map_y=y; map_y<y+height; map_y++) {
+    for (map_x=x; map_x<x+width; map_x++) {
+      /*
+       * We don't normalize until later because we want to draw
+       * black tiles for unreal positions.
+       */
+      if (get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y)) {
        pixmap_put_tile(map_canvas_store, map_x, map_y,
                        canvas_x, canvas_y, 0);
       }
@@ -1094,12 +1098,11 @@
 **************************************************************************/
 void put_cross_overlay_tile(int x,int y)
 {
-  int canvas_x, canvas_y;
-  x=map_adjust_x(x);
-  y=map_adjust_y(y);
-  get_canvas_xy(x, y, &canvas_x, &canvas_y);
+  int canvas_x, canvas_y, is_real;
+  is_real = normalize_map_pos(&x, &y);
+  assert(is_real);
 
-  if (tile_visible_mapcanvas(x, y)) {
+  if (get_canvas_xy(x, y, &canvas_x, &canvas_y)) {
     pixmap_put_overlay_tile(XtWindow(map_canvas), canvas_x, canvas_y,
                            sprites.user.attention);
   }
@@ -1188,7 +1191,7 @@
 void scrollbar_scroll_callback(Widget w, XtPointer client_data,
                             XtPointer position_val)
 {
-  int position=(int)position_val;
+  int position=(int)position_val, is_real;
 
 
   if(get_client_state()!=CLIENT_GAME_RUNNING_STATE)
@@ -1206,10 +1209,9 @@
     else if(position<0 && map_view_y0>0)
       map_view_y0--;
   }
-
-  map_view_x0=map_adjust_x(map_view_x0);
-  map_view_y0=map_adjust_y(map_view_y0);
 
+  is_real = normalize_map_pos(&map_view_x0, &map_view_y0);
+  assert(is_real);
 
   update_map_canvas_visible();
   update_map_canvas_scrollbars();

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: remove map_adjust_[xy] invocations (PR#1130), Jason Short <=