Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2401) unification of undraw_segment
Home

[Freeciv-Dev] (PR#2401) unification of undraw_segment

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2401) unification of undraw_segment
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 24 Nov 2002 22:35:54 -0800
Reply-to: rt@xxxxxxxxxxxxxx

This patch moves undraw_segment() into mapview_common.

The code doesn't need any changes because of the move; it is 
functionally identical under all GUIs [1].  However, I needed to fix the 
formatting, so I went ahead and cleaned it up a little.  In the process, 
I caught some "magic" directional code that I had never noticed before.

This function hard-codes the width of the segment as 1 pixel in the 
non-iso case.  The "inefficient" method the iso case uses does not 
hard-code this information, and is probably faster anyway because it 
only uses one screen write (though it may be cover a larger area).  But 
this is a separate issue.

[1] Except XAW has no iso case, of course, and MUI which uses a simpler 
(and less complete) algorithm.

jason

? client/output
? client/undraw_segment.diff
Index: client//mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.19
diff -u -r1.19 mapview_common.c
--- client//mapview_common.c    2002/11/24 11:43:39     1.19
+++ client//mapview_common.c    2002/11/25 06:23:08
@@ -23,6 +23,7 @@
 
 #include "mapview_g.h"
 
+#include "goto.h"
 #include "mapview_common.h"
 #include "tilespec.h"
 
@@ -406,6 +407,52 @@
          get_canvas_xy(x, y, &canvas_x, &canvas_y);
          show_city_desc(pcity, canvas_x, canvas_y);
        }
+      }
+    }
+  }
+}
+
+/**************************************************************************
+  Remove the line from src_x, src_y in the given direction, and redraw
+  the change if necessary.
+**************************************************************************/
+void undraw_segment(int src_x, int src_y, int dir)
+{
+  int dest_x, dest_y;
+
+  /* If we walk on a path twice it looks just like walking on it once. */
+  decrement_drawn(src_x, src_y, dir);
+  if (get_drawn(src_x, src_y, dir) > 0) {
+    return;
+  }
+
+  if (!MAPSTEP(dest_x, dest_y, src_x, src_y, dir)) {
+    assert(0);
+  }
+
+  if (is_isometric) {
+    /* somewhat inefficient */
+    update_map_canvas(MIN(src_x, dest_x), MIN(src_y, dest_y),
+                     src_x == dest_x ? 1 : 2,
+                     src_y == dest_y ? 1 : 2,
+                     TRUE);
+  } else {
+    refresh_tile_mapcanvas(src_x, src_y, TRUE);
+    refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
+
+    if (NORMAL_TILE_WIDTH % 2 == 0 || NORMAL_TILE_HEIGHT % 2 == 0) {
+      if (dir == DIR8_NORTHEAST) {
+       /* Since the tile doesn't have a middle we draw an extra pixel
+        * on the adjacent tile when drawing in this direction. */
+       if (!MAPSTEP(dest_x, dest_y, src_x, src_y, DIR8_EAST)) {
+         assert(0);
+       }
+       refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
+      } else if (dir == DIR8_SOUTHWEST) {      /* the same */
+       if (!MAPSTEP(dest_x, dest_y, src_x, src_y, DIR8_SOUTH)) {
+         assert(0);
+       }
+       refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
       }
     }
   }
Index: client//mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.13
diff -u -r1.13 mapview_common.h
--- client//mapview_common.h    2002/11/24 11:43:39     1.13
+++ client//mapview_common.h    2002/11/25 06:23:08
@@ -59,6 +59,8 @@
 void update_map_canvas_visible(void);
 
 void show_city_descriptions(void);
+
+void undraw_segment(int src_x, int src_y, int dir);
                                
 struct city *find_city_near_tile(int x, int y);
 
Index: client//gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.136
diff -u -r1.136 mapview.c
--- client//gui-gtk/mapview.c   2002/11/24 11:43:40     1.136
+++ client//gui-gtk/mapview.c   2002/11/25 06:23:09
@@ -1745,63 +1745,6 @@
 }
 
 /**************************************************************************
-remove the line from src_x,src_y -> dest_x,dest_y on both map_canvas and
-map_canvas_store.
-**************************************************************************/
-void undraw_segment(int src_x, int src_y, int dir)
-{
-  int dest_x, dest_y, is_real;
-
-  is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
-  assert(is_real);
-
-  if (is_isometric) {
-    assert(get_drawn(src_x, src_y, dir));
-    decrement_drawn(src_x, src_y, dir);
-
-    /* somewhat inefficient */
-    if (!get_drawn(src_x, src_y, dir)) {
-      update_map_canvas(MIN(src_x, dest_x), MIN(src_y, dest_y),
-                       src_x == dest_x ? 1 : 2,
-                       src_y == dest_y ? 1 : 2,
-                       TRUE);
-    }
-  } else {
-    int drawn = get_drawn(src_x, src_y, dir);
-
-    assert(drawn > 0);
-    /* If we walk on a path twice it looks just like walking on it once. */
-    if (drawn > 1) {
-      decrement_drawn(src_x, src_y, dir);
-      return;
-    }
-
-    decrement_drawn(src_x, src_y, dir);
-    refresh_tile_mapcanvas(src_x, src_y, TRUE);
-    refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-    if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) {
-      int is_real;
-
-      if (dir == DIR8_NORTHEAST) {
-       /* Since the tile doesn't have a middle we draw an extra pixel
-          on the adjacent tile when drawing in this direction. */
-       dest_x = src_x + 1;
-       dest_y = src_y;
-       is_real = normalize_map_pos(&dest_x, &dest_y);
-       assert(is_real);
-       refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-      } else if (dir == DIR8_SOUTHWEST) {      /* the same */
-       dest_x = src_x;
-       dest_y = src_y + 1;
-       is_real = normalize_map_pos(&dest_x, &dest_y);
-       assert(is_real);
-       refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-      }
-    }
-  }
-}
-
-/**************************************************************************
 Not used in isometric view.
 **************************************************************************/
 static void put_line(GdkDrawable *pm, int x, int y, int dir)
Index: client//gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.24
diff -u -r1.24 mapview.c
--- client//gui-gtk-2.0/mapview.c       2002/11/24 11:43:40     1.24
+++ client//gui-gtk-2.0/mapview.c       2002/11/25 06:23:10
@@ -1813,63 +1813,6 @@
 }
 
 /**************************************************************************
-remove the line from src_x,src_y -> dest_x,dest_y on both map_canvas and
-map_canvas_store.
-**************************************************************************/
-void undraw_segment(int src_x, int src_y, int dir)
-{
-  int dest_x, dest_y, is_real;
-
-  is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
-  assert(is_real);
-
-  if (is_isometric) {
-    assert(get_drawn(src_x, src_y, dir));
-    decrement_drawn(src_x, src_y, dir);
-
-    /* somewhat inefficient */
-    if (!get_drawn(src_x, src_y, dir)) {
-      update_map_canvas(MIN(src_x, dest_x), MIN(src_y, dest_y),
-                       src_x == dest_x ? 1 : 2,
-                       src_y == dest_y ? 1 : 2,
-                       TRUE);
-    }
-  } else {
-    int drawn = get_drawn(src_x, src_y, dir);
-
-    assert(drawn > 0);
-    /* If we walk on a path twice it looks just like walking on it once. */
-    if (drawn > 1) {
-      decrement_drawn(src_x, src_y, dir);
-      return;
-    }
-
-    decrement_drawn(src_x, src_y, dir);
-    refresh_tile_mapcanvas(src_x, src_y, TRUE);
-    refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-    if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) {
-      int is_real;
-
-      if (dir == DIR8_NORTHEAST) {
-       /* Since the tile doesn't have a middle we draw an extra pixel
-          on the adjacent tile when drawing in this direction. */
-       dest_x = src_x + 1;
-       dest_y = src_y;
-       is_real = normalize_map_pos(&dest_x, &dest_y);
-       assert(is_real);
-       refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-      } else if (dir == DIR8_SOUTHWEST) {      /* the same */
-       dest_x = src_x;
-       dest_y = src_y + 1;
-       is_real = normalize_map_pos(&dest_x, &dest_y);
-       assert(is_real);
-       refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-      }
-    }
-  }
-}
-
-/**************************************************************************
 Not used in isometric view.
 **************************************************************************/
 static void put_line(GdkDrawable *pm, int x, int y, int dir)
Index: client//gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.82
diff -u -r1.82 mapclass.c
--- client//gui-mui/mapclass.c  2002/11/24 11:43:40     1.82
+++ client//gui-mui/mapclass.c  2002/11/25 06:23:11
@@ -2048,18 +2048,6 @@
   return 0;
 }
 
-static ULONG Map_UndrawSegment(struct IClass *cl, Object *o, struct 
MUIP_Map_DrawSegment *msg)
-{
-  struct Map_Data *data = (struct Map_Data *) INST_DATA(cl, o);
-  data->update = 9;
-  data->segment_src_x = msg->src_x;
-  data->segment_src_y = msg->src_y;
-  data->segment_dir = msg->dir;
-  MUI_Redraw(o, MADF_DRAWUPDATE);
-  return 0;
-}
-
-
 DISPATCHERPROTO(Map_Dispatcher)
 {
   switch (msg->MethodID)
@@ -2112,8 +2100,6 @@
     return Map_DrawMushroom(cl, obj, (struct MUIP_Map_DrawMushroom *)msg);
   case MUIM_Map_DrawSegment:
     return Map_DrawSegment(cl, obj, (struct MUIP_Map_DrawSegment *)msg);
-  case MUIM_Map_UndrawSegment:
-    return Map_UndrawSegment(cl, obj, (struct MUIP_Map_DrawSegment *)msg);
   }
 
   return (DoSuperMethodA(cl, obj, msg));
Index: client//gui-mui/mapclass.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.h,v
retrieving revision 1.15
diff -u -r1.15 mapclass.h
--- client//gui-mui/mapclass.h  2001/02/22 22:37:50     1.15
+++ client//gui-mui/mapclass.h  2002/11/25 06:23:11
@@ -66,7 +66,6 @@
 #define MUIM_Map_PutCrossTile           (0x7878792)
 #define MUIM_Map_ExplodeUnit            (0x7878793)
 #define MUIM_Map_DrawSegment            (0x7878794)
-#define MUIM_Map_UndrawSegment          (0x7878795)
 
 struct MUIP_Map_Refresh         {ULONG MethodID; LONG x; LONG y; LONG width; 
LONG height;
                                  LONG write_to_screen;};
Index: client//gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.49
diff -u -r1.49 mapview.c
--- client//gui-mui/mapview.c   2002/11/24 11:43:40     1.49
+++ client//gui-mui/mapview.c   2002/11/25 06:23:12
@@ -554,15 +554,6 @@
 }
 
 /**************************************************************************
-remove the line from src_x,src_y -> dest_x,dest_y on both map_canvas and
-map_canvas_store.
-**************************************************************************/
-void undraw_segment(int src_x, int src_y, int dir)
-{
-  DoMethod(main_map_area, MUIM_Map_UndrawSegment, src_x, src_y, dir);
-}
-
-/**************************************************************************
   This function is called when the tileset is changed.
 **************************************************************************/
 void tileset_changed(void)
Index: client//gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.38
diff -u -r1.38 mapview.c
--- client//gui-win32/mapview.c 2002/11/24 11:43:40     1.38
+++ client//gui-win32/mapview.c 2002/11/25 06:23:13
@@ -1972,63 +1972,6 @@
   }
 }
 
-
-/**************************************************************************
-remove the line from src_x,src_y -> dest_x,dest_y on both map_canvas and
-map_canvas_store.
-**************************************************************************/
-void undraw_segment(int src_x, int src_y, int dir)
-{
-  int dest_x, dest_y, is_real;
-
-  is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
-  assert(is_real);
-
-  if (is_isometric) {
-    assert(get_drawn(src_x, src_y, dir));
-    decrement_drawn(src_x, src_y, dir);
-
-    /* somewhat inefficient */
-    if (!get_drawn(src_x, src_y, dir)) {
-      update_map_canvas(MIN(src_x, dest_x), MIN(src_y, dest_y),
-                        src_x == dest_x ? 1 : 2,
-                        src_y == dest_y ? 1 : 2,
-                        TRUE);
-    }
-  } else {
-    int drawn = get_drawn(src_x, src_y, dir);
-
-    assert(drawn > 0);
-    /* If we walk on a path twice it looks just like walking on it once. */
-    if (drawn > 1) {
-      decrement_drawn(src_x, src_y, dir);
-      return;
-    }
-
-    decrement_drawn(src_x, src_y, dir);
-    refresh_tile_mapcanvas(src_x, src_y, TRUE);
-    refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-    
-    if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) {
-      if (dir == DIR8_NORTHEAST) { /* Since the tle doesn't have a middle we 
draw an extra pi
-xel
-                         on the adjacent tile when drawing in this direction. 
*/
-        dest_x = src_x + 1;
-        dest_y = src_y;
-        is_real = normalize_map_pos(&dest_x, &dest_y);
-       assert(is_real);
-        refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-      } else if (dir == DIR8_SOUTHWEST) { /* the same */
-        dest_x = src_x;
-        dest_y = src_y + 1;
-        is_real = normalize_map_pos(&dest_x, &dest_y);
-       assert(is_real);
-        refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-      }
-    }
-  }
-}
-
 /**************************************************************************
   This function is called when the tileset is changed.
 **************************************************************************/
Index: client//gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.109
diff -u -r1.109 mapview.c
--- client//gui-xaw/mapview.c   2002/11/24 11:43:40     1.109
+++ client//gui-xaw/mapview.c   2002/11/25 06:23:13
@@ -1205,49 +1205,6 @@
 }
 
 /**************************************************************************
-This is somewhat inefficient, but I simply can't feel any performance
-penalty so I will be lazy...
-**************************************************************************/
-void undraw_segment(int src_x, int src_y, int dir)
-{
-  int dest_x, dest_y, is_real;
-  int drawn = get_drawn(src_x, src_y, dir);
-
-  is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
-  assert(is_real);
-
-  assert(drawn > 0);
-  /* If we walk on a path twice it looks just like walking on it once. */
-  if (drawn > 1) {
-    decrement_drawn(src_x, src_y, dir);
-    return;
-  }
-
-  decrement_drawn(src_x, src_y, dir);
-  refresh_tile_mapcanvas(src_x, src_y, TRUE);
-  refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-  if (NORMAL_TILE_WIDTH%2 == 0 || NORMAL_TILE_HEIGHT%2 == 0) {
-    int is_real;
-
-    if (dir == DIR8_NORTHEAST) {
-      /* Since the tile doesn't have a middle we draw an extra pixel
-         on the adjacent tile when drawing in this direction. */
-      dest_x = src_x + 1;
-      dest_y = src_y;
-      is_real = normalize_map_pos(&dest_x, &dest_y);
-      assert(is_real);
-      refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-    } else if (dir == DIR8_SOUTHWEST) {        /* the same */
-      dest_x = src_x;
-      dest_y = src_y + 1;
-      is_real = normalize_map_pos(&dest_x, &dest_y);
-      assert(is_real);
-      refresh_tile_mapcanvas(dest_x, dest_y, TRUE);
-    }
-  }
-}
-
-/**************************************************************************
   This function is called when the tileset is changed.
 **************************************************************************/
 void tileset_changed(void)
Index: client//include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.25
diff -u -r1.25 mapview_g.h
--- client//include/mapview_g.h 2002/11/24 11:43:41     1.25
+++ client//include/mapview_g.h 2002/11/25 06:23:13
@@ -56,7 +56,6 @@
 void refresh_overview_viewrect(void);
 
 void draw_segment(int src_x, int src_y, int dir);
-void undraw_segment(int src_x, int src_y, int dir);
 
 void tileset_changed(void);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2401) unification of undraw_segment, Jason Short via RT <=