[Freeciv-Dev] (PR#10163) merge fill_xxx_sprite_array
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10163 >
This patch merges fill_unit_sprite_array and fill_tile_sprite_array into
fill_sprite_array.
The function takes a tile (ptile and coordinates), unit, and city. The
caller may pass one or all of these. For instance put_unit only gives a
unit. put_one_tile and put_one_tile_iso pass all three.
After this is is trivial to write put_city and put_terrain functions.
All this, and it still manages to remove 11 lines of code ;-).
jason
? drawn_sprites.diff
? freeciv.spec
? ftwl.diff
? settler_recursion_crash
? client/tilespec.diff
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.146
diff -u -r1.146 mapview_common.c
--- client/mapview_common.c 17 Sep 2004 06:35:42 -0000 1.146
+++ client/mapview_common.c 17 Sep 2004 08:12:01 -0000
@@ -829,7 +829,8 @@
struct canvas *pcanvas, int canvas_x, int canvas_y)
{
struct drawn_sprite drawn_sprites[40];
- int count = fill_unit_sprite_array(drawn_sprites, punit, FALSE, TRUE);
+ int count = fill_sprite_array(drawn_sprites, -1, -1, NULL,
+ punit, NULL, FALSE);
canvas_y += (UNIT_TILE_HEIGHT - NORMAL_TILE_HEIGHT);
put_drawn_sprites(pcanvas, canvas_x, canvas_y,
@@ -1237,7 +1238,10 @@
if (normalize_map_pos(&map_x, &map_y)
&& tile_get_known(map_x, map_y) != TILE_UNKNOWN) {
struct drawn_sprite tile_sprs[80];
- int count = fill_tile_sprite_array(tile_sprs, map_x, map_y, citymode);
+ int count = fill_sprite_array(tile_sprs, map_x, map_y,
+ map_get_tile(map_x, map_y),
+ get_drawable_unit(map_x, map_y, citymode),
+ map_get_city(map_x, map_y), citymode);
put_drawn_sprites(pcanvas, canvas_x, canvas_y,
count, tile_sprs, FALSE);
@@ -1384,24 +1388,11 @@
int canvas_x, int canvas_y, bool citymode)
{
struct drawn_sprite tile_sprs[80];
- int count;
- bool fog;
-
- count = fill_tile_sprite_array(tile_sprs, map_x, map_y, citymode);
-
- if (count == -1) { /* tile is unknown */
- canvas_fill_sprite_area(pcanvas, sprites.black_tile, COLOR_STD_BLACK,
- canvas_x, canvas_y);
- return;
- }
-
- /* Replace with check for is_normal_tile later */
- if (!normalize_map_pos(&map_x, &map_y)) {
- assert(0);
- return;
- }
-
- fog = tile_get_known(map_x, map_y) == TILE_KNOWN_FOGGED && draw_fog_of_war;
+ struct tile *ptile = map_get_tile(map_x, map_y);
+ int count = fill_sprite_array(tile_sprs, map_x, map_y, ptile,
+ get_drawable_unit(map_x, map_y, citymode),
+ ptile->city, citymode);
+ bool fog = ptile->known == TILE_KNOWN_FOGGED && draw_fog_of_war;
/*** Draw terrain and specials ***/
put_drawn_sprites(pcanvas, canvas_x, canvas_y, count, tile_sprs, fog);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.198
diff -u -r1.198 tilespec.c
--- client/tilespec.c 17 Sep 2004 06:35:43 -0000 1.198
+++ client/tilespec.c 17 Sep 2004 08:12:01 -0000
@@ -1944,8 +1944,9 @@
/**********************************************************************
Fill in the sprite array for the unit
***********************************************************************/
-int fill_unit_sprite_array(struct drawn_sprite *sprs, struct unit *punit,
- bool stack, bool backdrop)
+static int fill_unit_sprite_array(struct drawn_sprite *sprs,
+ struct unit *punit,
+ bool stack, bool backdrop)
{
struct drawn_sprite *save_sprs = sprs;
int ihp;
@@ -2604,34 +2605,34 @@
}
-/**********************************************************************
-Fill in the sprite array for the tile at position (abs_x0,abs_y0).
-Does not fill in the city or unit; that have to be done seperatly in
-isometric view. Also, no fog here.
-
-A return of -1 means the tile should be black.
-
-The sprites are drawn in the following order:
- 1) basic terrain type + irrigation/farmland (+ river hack)
- 2) road/railroad
- 3) specials
- 4) mine
- 5) huts
-***********************************************************************/
-int fill_tile_sprite_array(struct drawn_sprite *sprs,
- int map_x, int map_y, bool citymode)
+/****************************************************************************
+ Fill in the sprite array for the given tile, city, and unit.
+
+ ptile, if specified, gives the tile. If specified the terrain and specials
+ will be drawn for this tile. In this case (map_x,map_y) should give the
+ location of the tile.
+
+ punit, if specified, gives the unit. For tile drawing this should
+ generally be get_drawable_unit(); otherwise it can be any unit.
+
+ pcity, if specified, gives the city. For tile drawing this should
+ generally be ptile->city; otherwise it can be any city.
+
+ citymode specifies whether this is part of a citydlg. If so some drawing
+ is done differently.
+****************************************************************************/
+int fill_sprite_array(struct drawn_sprite *sprs,
+ int map_x, int map_y, struct tile *ptile,
+ struct unit *punit, struct city *pcity,
+ bool citymode)
{
Terrain_type_id ttype, ttype_near[8];
enum tile_special_type tspecial, tspecial_near[8];
int tileno, dir;
- struct tile *ptile = map_get_tile(map_x, map_y);
- struct city *pcity = ptile->city;
- struct unit *punit = get_drawable_unit(map_x, map_y, citymode);
struct unit *pfocus = get_unit_in_focus();
struct drawn_sprite *save_sprs = sprs;
- bool unit_only = FALSE, city_only = FALSE;
- if (tile_get_known(map_x, map_y) == TILE_UNKNOWN) {
+ if (ptile && ptile->known == TILE_UNKNOWN) {
ADD_BG(COLOR_STD_BLACK);
return sprs - save_sprs;
}
@@ -2647,11 +2648,11 @@
ADD_BG(COLOR_STD_BACKGROUND);
}
- build_tile_data(map_x, map_y,
- &ttype, &tspecial, ttype_near, tspecial_near);
-
/* Terrain and specials. */
- if (!unit_only && !city_only) {
+ if (ptile) {
+ build_tile_data(map_x, map_y,
+ &ttype, &tspecial, ttype_near, tspecial_near);
+
sprs += fill_terrain_sprite_array(sprs, map_x, map_y, ttype_near);
if (is_ocean(ttype) && draw_terrain) {
@@ -2707,13 +2708,13 @@
}
}
- if (is_isometric) {
+ if (ptile && is_isometric) {
/* Add grid. In classic view this is done later. */
ADD_GRID(map_x, map_y, citymode);
}
/* City. Some city sprites are drawn later. */
- if (pcity && draw_cities && !unit_only) {
+ if (pcity && draw_cities) {
if (!solid_color_behind_units) {
ADD_SPRITE(get_city_nation_flag_sprite(pcity),
DRAW_FULL, TRUE, flag_offset_x, flag_offset_y);
@@ -2731,7 +2732,7 @@
}
}
- if (!unit_only && !city_only) {
+ if (ptile) {
if (draw_fortress_airbase && contains_special(tspecial, S_AIRBASE)) {
ADD_SPRITE_FULL(sprites.tx.airbase);
}
@@ -2751,7 +2752,7 @@
}
/* City size. Drawing this under fog makes it hard to read. */
- if (pcity && draw_cities && !unit_only) {
+ if (pcity && draw_cities) {
if (pcity->size >= 10) {
ADD_SPRITE(sprites.city.size_tens[pcity->size / 10], DRAW_FULL,
FALSE, 0, 0);
@@ -2760,15 +2761,14 @@
FALSE, 0, 0);
}
- if (punit && !city_only
- && (draw_units || (punit == pfocus && draw_focus_unit))) {
- bool stacked = (unit_list_size(&map_get_tile(map_x, map_y)->units) > 1);
- bool backdrop = !pcity && !unit_only;
+ if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
+ bool stacked = ptile && (unit_list_size(&ptile->units) > 1);
+ bool backdrop = !pcity;
sprs += fill_unit_sprite_array(sprs, punit, stacked, backdrop);
}
- if (!unit_only && !city_only) {
+ if (ptile) {
if (is_isometric && draw_fortress_airbase
&& contains_special(tspecial, S_FORTRESS)) {
/* Draw fortress front in iso-view (non-iso view only has a fortress
@@ -2777,7 +2777,7 @@
}
}
- if (!is_isometric) {
+ if (ptile && !is_isometric) {
/* Add grid. In iso-view this is done earlier. */
ADD_GRID(map_x, map_y, citymode);
}
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.87
diff -u -r1.87 tilespec.h
--- client/tilespec.h 17 Sep 2004 06:35:43 -0000 1.87
+++ client/tilespec.h 17 Sep 2004 08:12:02 -0000
@@ -79,10 +79,10 @@
/* Gfx support */
-int fill_tile_sprite_array(struct drawn_sprite *sprs,
- int map_x, int map_y, bool citymode);
-int fill_unit_sprite_array(struct drawn_sprite *sprs, struct unit *punit,
- bool stack, bool backdrop);
+int fill_sprite_array(struct drawn_sprite *sprs,
+ int map_x, int map_y, struct tile *ptile,
+ struct unit *punit, struct city *pcity,
+ bool citymode);
enum color_std player_color(struct player *pplayer);
enum color_std overview_tile_color(int x, int y);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#10163) merge fill_xxx_sprite_array,
Jason Short <=
|
|