[Freeciv-Dev] (PR#8668) get_drawn should return boolean
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8668 >
> [jdorje - Tue May 04 17:43:50 2004]:
>
> The get_drawn function should return a boolean. In fact AFAIK it's not
> possible for a tile/direction to be drawn on twice. We should leave the
> functionality in the backend for safety but the callers need only know
> about the boolean state.
Here's a patch. It also improves increment_drawn/decrement_drawn slightly.
jason
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.68
diff -u -r1.68 goto.c
--- client/goto.c 18 Feb 2004 02:26:35 -0000 1.68
+++ client/goto.c 5 May 2004 21:51:55 -0000
@@ -640,13 +640,19 @@
**************************************************************************/
static void increment_drawn(int src_x, int src_y, enum direction8 dir)
{
+ unsigned char *count = get_drawn_char(src_x, src_y, dir);
+
freelog(LOG_DEBUG, "increment_drawn(src=(%d,%d) dir=%s)",
src_x, src_y, dir_get_name(dir));
- /* don't overflow unsigned char. */
- assert(*get_drawn_char(src_x, src_y, dir) < 255);
- *get_drawn_char(src_x, src_y, dir) += 1;
- if (get_drawn(src_x, src_y, dir) == 1) {
+ if (*count < 255) {
+ (*count)++;
+ } else {
+ /* don't overflow unsigned char. */
+ assert(*count < 255);
+ }
+
+ if (*count == 1) {
draw_segment(src_x, src_y, dir);
}
}
@@ -657,13 +663,19 @@
**************************************************************************/
static void decrement_drawn(int src_x, int src_y, enum direction8 dir)
{
+ unsigned char *count = get_drawn_char(src_x, src_y, dir);
+
freelog(LOG_DEBUG, "decrement_drawn(src=(%d,%d) dir=%s)",
src_x, src_y, dir_get_name(dir));
- /* don't underflow unsigned char. */
- assert(*get_drawn_char(src_x, src_y, dir) > 0);
- *get_drawn_char(src_x, src_y, dir) -= 1;
- if (get_drawn(src_x, src_y, dir) == 0) {
+ if (*count > 0) {
+ (*count)--;
+ } else {
+ /* don't underflow unsigned char. */
+ assert(*count > 0);
+ }
+
+ if (*count == 0) {
undraw_segment(src_x, src_y, dir);
}
}
@@ -671,7 +683,7 @@
/**********************************************************************
Part of the public interface. Needed by mapview.
***********************************************************************/
-int get_drawn(int x, int y, int dir)
+bool is_drawn_line(int x, int y, int dir)
{
int dummy_x, dummy_y;
@@ -679,7 +691,7 @@
return 0;
}
- return *get_drawn_char(x, y, dir);
+ return (*get_drawn_char(x, y, dir) != 0);
}
/**************************************************************************
Index: client/goto.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v
retrieving revision 1.11
diff -u -r1.11 goto.h
--- client/goto.h 20 Jan 2004 21:52:07 -0000 1.11
+++ client/goto.h 5 May 2004 21:51:55 -0000
@@ -27,7 +27,7 @@
bool goto_pop_waypoint(void);
void draw_line(int dest_x, int dest_y);
-int get_drawn(int x, int y, int dir);
+bool is_drawn_line(int x, int y, int dir);
void request_orders_cleared(struct unit *punit);
void send_goto_path(struct unit *punit, struct pf_path *path);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.111
diff -u -r1.111 mapview_common.c
--- client/mapview_common.c 4 May 2004 17:40:26 -0000 1.111
+++ client/mapview_common.c 5 May 2004 21:51:56 -0000
@@ -1067,7 +1067,7 @@
enum direction8 dir;
for (dir = 0; dir < 8; dir++) {
- if (get_drawn(map_x, map_y, dir) != 0) {
+ if (is_drawn_line(map_x, map_y, dir)) {
draw_segment(map_x, map_y, dir);
}
}
@@ -1078,7 +1078,7 @@
int line_x = map_x - 1, line_y = map_y;
if (normalize_map_pos(&line_x, &line_y)
- && get_drawn(line_x, line_y, DIR8_NORTHEAST) != 0) {
+ && is_drawn_line(line_x, line_y, DIR8_NORTHEAST)) {
draw_segment(line_x, line_y, DIR8_NORTHEAST);
}
}
@@ -1316,7 +1316,7 @@
gui_rect_iterate(gui_x0, gui_y0, width, height, map_x, map_y, draw) {
if (normalize_map_pos(&map_x, &map_y)) {
adjc_dir_iterate(map_x, map_y, adjc_x, adjc_y, dir) {
- if (get_drawn(map_x, map_y, dir)) {
+ if (is_drawn_line(map_x, map_y, dir)) {
draw_segment(map_x, map_y, dir);
}
} adjc_dir_iterate_end;
@@ -1569,7 +1569,7 @@
{
int dest_x, dest_y;
- assert(get_drawn(src_x, src_y, dir) == 0);
+ assert(!is_drawn_line(src_x, src_y, dir));
if (!MAPSTEP(dest_x, dest_y, src_x, src_y, dir)) {
assert(0);
Index: client/gui-mui/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/graphics.c,v
retrieving revision 1.32
diff -u -r1.32 graphics.c
--- client/gui-mui/graphics.c 17 Feb 2003 02:11:26 -0000 1.32
+++ client/gui-mui/graphics.c 5 May 2004 21:51:56 -0000
@@ -973,7 +973,7 @@
if (is_real_map_pos(x, y)) {
int dir;
for (dir = 0; dir < 8; dir++) {
- if (get_drawn(x, y, dir)) {
+ if (is_drawn_line(x, y, dir)) {
put_line(rp, 0,0,x, y, dir);
}
}
@@ -984,7 +984,7 @@
int line_x = x - 1;
int line_y = y;
if (normalize_map_pos(&line_x, &line_y)
- && get_drawn(line_x, line_y, 2)) {
+ && is_drawn_line(line_x, line_y, 2)) {
/* it is really only one pixel in the top right corner */
put_line(rp, 0,0,line_x, line_y, 2);
}
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.97
diff -u -r1.97 mapclass.c
--- client/gui-mui/mapclass.c 21 Feb 2004 22:15:03 -0000 1.97
+++ client/gui-mui/mapclass.c 5 May 2004 21:51:57 -0000
@@ -1157,7 +1157,7 @@
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);
+ assert(is_drawn_line(src_x, src_y, dir) > 0);
if (is_isometric) {
really_draw_segment(data->map_layer->rp, 0, 0, src_x, src_y, dir,
@@ -1368,7 +1368,7 @@
int y1 = y_itr;
if (normalize_map_pos(&x1, &y1)) {
adjc_dir_iterate(x1, y1, x2, y2, dir) {
- if (get_drawn(x1, y1, dir)) {
+ if (is_drawn_line(x1, y1, dir)) {
really_draw_segment(data->map_layer->rp, 0, 0, x1, y1,
dir, TRUE);
}
|
|