[Freeciv-Dev] (PR#2452) add_segment and remove_segment
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#2452) add_segment and remove_segment |
From: |
"Jason Short via RT" <rt@xxxxxxxxxxxxxx> |
Date: |
Fri, 29 Nov 2002 10:08:26 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
This function removes a little of the logic from mapview and
mapview_common and puts it back into the goto code where it belongs. It
also hides a bit more of the goto interface, since such is now possible.
Two new functions, add_segment and remove_segment, are done to do the
work of the current draw_segment and undraw_segment. Thise functions
increment/decrement the number of segments on the tile, and call
[un]draw_segment to make a graphical update if necessary.
jason
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.41
diff -u -r1.41 goto.c
--- client/goto.c 2002/11/14 09:14:51 1.41
+++ client/goto.c 2002/11/29 18:05:19
@@ -32,6 +32,9 @@
static void undraw_line(void);
+static void increment_drawn(int src_x, int src_y, enum direction8 dir);
+static void decrement_drawn(int src_x, int src_y, enum direction8 dir);
+
/**************************************************************************
Various stuff for the goto routes
**************************************************************************/
@@ -456,6 +459,30 @@
}
/**************************************************************************
+ Increments the number of segments at the location, and draws the
+ segment if necessary.
+**************************************************************************/
+static void add_segment(int src_x, int src_y, enum direction8 dir)
+{
+ increment_drawn(src_x, src_y, dir);
+ if (get_drawn(src_x, src_y, dir) == 1) {
+ draw_segment(src_x, src_y, dir);
+ }
+}
+
+/**************************************************************************
+ Decrements the number of segments at the location, and clears the
+ segment if necessary.
+**************************************************************************/
+static void remove_segment(int src_x, int src_y, enum direction8 dir)
+{
+ decrement_drawn(src_x, src_y, dir);
+ if (get_drawn(src_x, src_y, dir) == 0) {
+ undraw_segment(src_x, src_y, dir);
+ }
+}
+
+/**************************************************************************
Insert a point and draw the line on the map.
Will extend the array if needed.
**************************************************************************/
@@ -488,7 +515,7 @@
dir = get_direction_for_step(old_x, old_y, x, y);
- draw_segment(old_x, old_y, dir);
+ add_segment(old_x, old_y, dir);
/* insert into array */
goto_array[goto_array_index].x = x;
@@ -646,7 +673,7 @@
/**********************************************************************
...
***********************************************************************/
-void increment_drawn(int x, int y, int dir)
+static void increment_drawn(int x, int y, enum direction8 dir)
{
/* don't overflow unsigned char. */
assert(*get_drawn_char(x, y, dir) < 255);
@@ -656,7 +683,7 @@
/**********************************************************************
...
***********************************************************************/
-void decrement_drawn(int x, int y, int dir)
+static void decrement_drawn(int x, int y, enum direction8 dir)
{
assert(*get_drawn_char(x, y, dir) > 0);
*get_drawn_char(x, y, dir) -= 1;
@@ -702,7 +729,7 @@
/* undraw the line segment */
dir = get_direction_for_step(line_x, line_y, dest_x, dest_y);
- undraw_segment(line_x, line_y, dir);
+ remove_segment(line_x, line_y, dir);
assert(goto_array_index > 0);
goto_array_index--;
Index: client/goto.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v
retrieving revision 1.6
diff -u -r1.6 goto.h
--- client/goto.h 2002/09/28 01:36:20 1.6
+++ client/goto.h 2002/11/29 18:05:19
@@ -36,8 +36,6 @@
void draw_line(int dest_x, int dest_y);
int get_drawn(int x, int y, int dir);
-void increment_drawn(int x, int y, int dir);
-void decrement_drawn(int x, int y, int dir);
void send_patrol_route(struct unit *punit);
void send_goto_route(struct unit *punit);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.21
diff -u -r1.21 mapview_common.c
--- client/mapview_common.c 2002/11/29 10:01:58 1.21
+++ client/mapview_common.c 2002/11/29 18:05:19
@@ -468,13 +468,7 @@
{
int dest_x, dest_y;
- assert(get_drawn(src_x, src_y, dir) > 0);
-
- /* 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;
- }
+ assert(get_drawn(src_x, src_y, dir) == 0);
if (!MAPSTEP(dest_x, dest_y, src_x, src_y, dir)) {
assert(0);
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.139
diff -u -r1.139 mapview.c
--- client/gui-gtk/mapview.c 2002/11/29 10:01:58 1.139
+++ client/gui-gtk/mapview.c 2002/11/29 18:05:19
@@ -1656,25 +1656,16 @@
**************************************************************************/
void draw_segment(int src_x, int src_y, int dir)
{
+ assert(get_drawn(src_x, src_y, dir) > 0);
+
if (is_isometric) {
- increment_drawn(src_x, src_y, dir);
- if (get_drawn(src_x, src_y, dir) > 1) {
- return;
- } else {
- really_draw_segment(src_x, src_y, dir, TRUE, FALSE);
- }
+ really_draw_segment(src_x, src_y, dir, TRUE, FALSE);
} else {
int dest_x, dest_y, is_real;
is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
assert(is_real);
- /* A previous line already marks the place */
- if (get_drawn(src_x, src_y, dir)) {
- increment_drawn(src_x, src_y, dir);
- return;
- }
-
if (tile_visible_mapcanvas(src_x, src_y)) {
put_line(map_canvas_store, src_x, src_y, dir);
put_line(map_canvas->window, src_x, src_y, dir);
@@ -1683,8 +1674,6 @@
put_line(map_canvas_store, dest_x, dest_y, DIR_REVERSE(dir));
put_line(map_canvas->window, dest_x, dest_y, DIR_REVERSE(dir));
}
-
- increment_drawn(src_x, src_y, 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.27
diff -u -r1.27 mapview.c
--- client/gui-gtk-2.0/mapview.c 2002/11/29 10:01:58 1.27
+++ client/gui-gtk-2.0/mapview.c 2002/11/29 18:05:20
@@ -1724,25 +1724,16 @@
**************************************************************************/
void draw_segment(int src_x, int src_y, int dir)
{
+ assert(get_drawn(src_x, src_y, dir) > 0);
+
if (is_isometric) {
- increment_drawn(src_x, src_y, dir);
- if (get_drawn(src_x, src_y, dir) > 1) {
- return;
- } else {
- really_draw_segment(src_x, src_y, dir, TRUE, FALSE);
- }
+ really_draw_segment(src_x, src_y, dir, TRUE, FALSE);
} else {
int dest_x, dest_y, is_real;
is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
assert(is_real);
- /* A previous line already marks the place */
- if (get_drawn(src_x, src_y, dir)) {
- increment_drawn(src_x, src_y, dir);
- return;
- }
-
if (tile_visible_mapcanvas(src_x, src_y)) {
put_line(map_canvas_store, src_x, src_y, dir);
put_line(map_canvas->window, src_x, src_y, dir);
@@ -1751,8 +1742,6 @@
put_line(map_canvas_store, dest_x, dest_y, DIR_REVERSE(dir));
put_line(map_canvas->window, dest_x, dest_y, DIR_REVERSE(dir));
}
-
- increment_drawn(src_x, src_y, dir);
}
}
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.83
diff -u -r1.83 mapclass.c
--- client/gui-mui/mapclass.c 2002/11/29 10:01:58 1.83
+++ client/gui-mui/mapclass.c 2002/11/29 18:05:20
@@ -1224,17 +1224,13 @@
int dir = data->segment_dir;
APTR cliphandle = MUI_AddClipping(muiRenderInfo(o), _mleft(o),
_mtop(o), _mwidth(o), _mheight(o));
+ assert(get_drawn(src_x, src_y, dir) > 0);
+
if (is_isometric) {
- increment_drawn(src_x, src_y, dir);
- if (get_drawn(src_x, src_y, dir) > 1) {
- MUI_RemoveClipping(muiRenderInfo(o), cliphandle);
- return 0;
- } else {
- really_draw_segment(data->map_layer->rp, 0, 0, src_x, src_y, dir,
- FALSE);
- really_draw_segment(_rp(o), _mleft(o), _mtop(o), src_x, src_y,
- dir, FALSE);
- }
+ really_draw_segment(data->map_layer->rp, 0, 0, src_x, src_y, dir,
+ FALSE);
+ really_draw_segment(_rp(o), _mleft(o), _mtop(o), src_x, src_y,
+ dir, FALSE);
} else {
int dest_x, dest_y, is_real;
@@ -1242,20 +1238,15 @@
assert(is_real);
/* A previous line already marks the place */
- if (get_drawn(src_x, src_y, dir)) {
- increment_drawn(src_x, src_y, dir);
- } else {
- if (tile_visible_mapcanvas(src_x, src_y)) {
- put_line(data->map_layer->rp, 0,0,src_x, src_y, dir);
- put_line(_rp(o), _mleft(o),_mtop(o),src_x, src_y, dir);
- }
- if (tile_visible_mapcanvas(dest_x, dest_y)) {
- put_line(data->map_layer->rp, 0, 0,
- dest_x, dest_y, DIR_REVERSE(dir));
- put_line(_rp(o), _mleft(o), _mtop(o),
- dest_x, dest_y, DIR_REVERSE(dir));
- }
- increment_drawn(src_x, src_y, dir);
+ if (tile_visible_mapcanvas(src_x, src_y)) {
+ put_line(data->map_layer->rp, 0, 0, src_x, src_y, dir);
+ put_line(_rp(o), _mleft(o), _mtop(o), src_x, src_y, dir);
+ }
+ if (tile_visible_mapcanvas(dest_x, dest_y)) {
+ put_line(data->map_layer->rp, 0, 0,
+ dest_x, dest_y, DIR_REVERSE(dir));
+ put_line(_rp(o), _mleft(o), _mtop(o),
+ dest_x, dest_y, DIR_REVERSE(dir));
}
}
@@ -1265,63 +1256,7 @@
if (data->update == 9)
{
- /* Undraw Segment */
- int src_x = data->segment_src_x;
- int src_y = data->segment_src_y;
- int dir = data->segment_dir;
- APTR cliphandle = MUI_AddClipping(muiRenderInfo(o), _mleft(o),
_mtop(o), _mwidth(o), _mheight(o));
-
- 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);
- } else {
- 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); /* !! */
- }
- }
- }
- }
-
- MUI_RemoveClipping(muiRenderInfo(o), cliphandle);
- return 0;
+ /* now handled by undraw_segment in mapview_common */
}
if (data->update == 2)
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.41
diff -u -r1.41 mapview.c
--- client/gui-win32/mapview.c 2002/11/29 10:01:58 1.41
+++ client/gui-win32/mapview.c 2002/11/29 18:05:21
@@ -1878,21 +1878,16 @@
void draw_segment(int src_x, int src_y, int dir)
{
HDC hdc;
-
-
+
+ assert(get_drawn(src_x, src_y, dir) > 0);
+
if (is_isometric) {
- increment_drawn(src_x, src_y, dir);
- if (get_drawn(src_x, src_y, dir) > 1) {
- return;
- } else {
- HBITMAP old;
- HDC mapstoredc;
- mapstoredc=CreateCompatibleDC(NULL);
- old=SelectObject(mapstoredc,mapstorebitmap);
- really_draw_segment(mapstoredc,src_x, src_y, dir, TRUE, FALSE);
- SelectObject(mapstoredc,old);
- DeleteDC(mapstoredc);
- }
+ HDC mapstoredc = CreateCompatibleDC(NULL);
+ HBITMAP old = SelectObject(mapstoredc, mapstorebitmap);
+
+ really_draw_segment(mapstoredc, src_x, src_y, dir, TRUE, FALSE);
+ SelectObject(mapstoredc, old);
+ DeleteDC(mapstoredc);
} else {
int dest_x, dest_y, is_real;
HBITMAP old;
@@ -1900,11 +1895,6 @@
is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
assert(is_real);
- /* A previous line already marks the place */
- if (get_drawn(src_x, src_y, dir)) {
- increment_drawn(src_x, src_y, dir);
- return;
- }
mapstoredc=CreateCompatibleDC(NULL);
old=SelectObject(mapstoredc,mapstorebitmap);
hdc=GetDC(map_window);
@@ -1919,7 +1909,6 @@
ReleaseDC(map_window,hdc);
SelectObject(mapstoredc,old);
DeleteDC(mapstoredc);
- increment_drawn(src_x, src_y, dir);
}
}
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.111
diff -u -r1.111 mapview.c
--- client/gui-xaw/mapview.c 2002/11/29 10:01:58 1.111
+++ client/gui-xaw/mapview.c 2002/11/29 18:05:21
@@ -1168,15 +1168,11 @@
{
int dest_x, dest_y, is_real;
+ assert(get_drawn(src_x, src_y, dir) > 0);
+
is_real = MAPSTEP(dest_x, dest_y, src_x, src_y, dir);
assert(is_real);
- /* A previous line already marks the place */
- if (get_drawn(src_x, src_y, dir)) {
- increment_drawn(src_x, src_y, dir);
- return;
- }
-
if (tile_visible_mapcanvas(src_x, src_y)) {
put_line(map_canvas_store, src_x, src_y, dir);
put_line(XtWindow(map_canvas), src_x, src_y, dir);
@@ -1186,8 +1182,6 @@
put_line(map_canvas_store, dest_x, dest_y, DIR_REVERSE(dir));
put_line(XtWindow(map_canvas), dest_x, dest_y, DIR_REVERSE(dir));
}
-
- increment_drawn(src_x, src_y, dir);
}
/**************************************************************************
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2452) add_segment and remove_segment,
Jason Short via RT <=
|
|