[Freeciv-Dev] (PR#12441) draw goto length as part of the tilespec code
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12441 >
This patch moves drawing of goto length from mapview_common into
tilespec.c. It's pretty straightforward but possibly a little slower
(could easily be optimized). A new GOTO layer is added which should
later get more use.
-jason
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.206
diff -u -r1.206 mapview_common.c
--- client/mapview_common.c 5 Mar 2005 23:51:05 -0000 1.206
+++ client/mapview_common.c 6 Mar 2005 01:19:21 -0000
@@ -856,46 +856,6 @@
}
/**************************************************************************
- Draw the length of the path on top of the tile.
-**************************************************************************/
-static void put_path_length(void)
-{
- if (goto_is_active()) {
- int length = get_goto_turns();
- int units = length % NUM_TILES_DIGITS;
- int tens = (length / 10) % NUM_TILES_DIGITS;
- int canvas_x, canvas_y;
- struct tile *ptile;
-
- ptile = get_line_dest();
- length = get_goto_turns();
-
- if (length >= 100) {
- static bool reported = FALSE;
-
- if (!reported) {
- freelog(LOG_ERROR,
- _("Paths longer than 99 turns are not supported.\n"
- "Report this bug to bugs@xxxxxxxxxxx."));
- reported = TRUE;
- }
- tens = units = 9;
- }
-
- if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
- if (sprites.path.turns[units]) {
- canvas_put_sprite_full(mapview.store, canvas_x, canvas_y,
- sprites.path.turns[units]);
- }
- if (tens > 0 && sprites.path.turns_tens[tens]) {
- canvas_put_sprite_full(mapview.store, canvas_x, canvas_y,
- sprites.path.turns_tens[tens]);
- }
- }
- }
-}
-
-/**************************************************************************
Draw an array of drawn sprites onto the canvas.
**************************************************************************/
static void put_drawn_sprites(struct canvas *pcanvas,
@@ -1326,9 +1286,6 @@
}
} gui_rect_iterate_end;
- /* Put goto target. */
- put_path_length();
-
show_city_descriptions(canvas_x, canvas_y, width, height);
if (!full) {
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.258
diff -u -r1.258 tilespec.c
--- client/tilespec.c 5 Mar 2005 23:51:05 -0000 1.258
+++ client/tilespec.c 6 Mar 2005 01:19:22 -0000
@@ -50,6 +50,7 @@
#include "civclient.h" /* for get_client_state() */
#include "climap.h" /* for tile_get_known() */
#include "control.h" /* for fill_xxx */
+#include "goto.h"
#include "options.h" /* for fill_xxx */
#include "tilespec.h"
@@ -3131,6 +3132,46 @@
}
/****************************************************************************
+ Fill in the given sprite array with any needed goto sprites.
+****************************************************************************/
+static int fill_goto_sprite_array(struct tileset *t,
+ struct drawn_sprite *sprs,
+ const struct tile *ptile,
+ const struct tile_edge *pedge,
+ const struct tile_corner *pcorner)
+{
+ struct drawn_sprite *saved_sprs = sprs;
+
+ if (!goto_is_active()) {
+ return 0;
+ }
+ if (ptile && ptile == get_line_dest()) {
+ int length = get_goto_turns();
+ int units = length % NUM_TILES_DIGITS;
+ int tens = (length / 10) % NUM_TILES_DIGITS;
+
+ if (length >= 100) {
+ static bool reported = FALSE;
+
+ if (!reported) {
+ freelog(LOG_ERROR,
+ _("Paths longer than 99 turns are not supported.\n"
+ "Report this bug to bugs@xxxxxxxxxxx."));
+ reported = TRUE;
+ }
+ tens = units = 9;
+ }
+
+ ADD_SPRITE_SIMPLE(sprites.path.turns[units]);
+ if (tens > 0) {
+ ADD_SPRITE_SIMPLE(sprites.path.turns[tens]);
+ }
+ }
+
+ return sprs - saved_sprs;
+}
+
+/****************************************************************************
Fill in the sprite array for the given tile, city, and unit.
ptile, if specified, gives the tile. If specified the terrain and specials
@@ -3394,6 +3435,10 @@
}
break;
+ case LAYER_GOTO:
+ sprs += fill_goto_sprite_array(t, sprs, ptile, pedge, pcorner);
+ break;
+
case LAYER_COUNT:
assert(0);
break;
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.121
diff -u -r1.121 tilespec.h
--- client/tilespec.h 5 Mar 2005 23:51:05 -0000 1.121
+++ client/tilespec.h 6 Mar 2005 01:19:22 -0000
@@ -92,6 +92,7 @@
LAYER_SPECIAL3,
LAYER_GRID2,
LAYER_OVERLAYS,
+ LAYER_GOTO,
LAYER_COUNT
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12441) draw goto length as part of the tilespec code,
Jason Short <=
|
|