Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8559) extend drawn_sprite to include more drawing elem
Home

[Freeciv-Dev] (PR#8559) extend drawn_sprite to include more drawing elem

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8559) extend drawn_sprite to include more drawing elements
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 Apr 2004 18:50:47 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8559 >

The drawn_sprite struct is filled out by the tilespec code and tells the 
mapview code how and where to draw a sprite.

[aside]
Fundamentally these pieces of code belong together.  The mapview drawing 
code and tilespec drawing code should eventually be merged, possibly 
into a new file drawing.[ch].  Doing so now isn't feasible, though, 
because this code is so fragmented.  However at some point I see a 
single drawing function doing all the backend work.  Possibly something 
like:

static void draw_element(struct canvas *pcanvas,
                          int canvas_x, int canvas_y,
                          int offset_x, int offset_y,
                          int width, int height,
                          struct tile *ptile,
                          struct city *pcity,
                          struct unit *punit);

At this point the drawn_sprite struct would no longer be needed, nor 
would the fill_***_sprite_array functions.  tilespec.[ch] would include 
only tileset loading code, not drawing code.  mapview_common would still 
include a lot of code (including animation) but would also lose its 
drawing code.
[/aside]

The mapview drawing code also draws some extra elements that aren't 
covered by drawn_sprite.  This includes the map grid and, in iso-view, 
additional sprites that are drawn on top of the map grid.  It includes 
all sprites that cover the full UNIT_TILE_HEIGHT area.

This patch integrates most of these elements into the drawn_sprite 
struct (which is now a bit of a misnomer; perhaps it should be 
drawn_element) and thus moves a lot of code out of the GUI function 
pixmap_put_tile_iso.

There are three new values in the drawn sprite:

- A "type".  The type may either be a SPRITE (just a sprite) or the GRID 
(which means to draw the map grid).  (I thought of having a general 
callback function for the second case, but this is probably overkill at 
this point.)

- A "style".  This applies only to sprites.  "NORMAL" sprites are simply 
drawn as before.  "FULL" sprites are drawn using the full unit area in 
iso-view.

- A "foggable" boolean value.  A few sprites (those with text on them) 
are never drawn fogged.  By setting foggable to FALSE for these the 
mapview drawing code knows not to fog them.

This patch is a step toward the goal of having more unified drawing 
code, since it removes many hundreds of lines of code.  For the most 
part this patch only touches iso-view.  Non-iso view can be modified in 
a similar way but it won't give as much benefit since non-iso drawing is 
already fairly unified.

jason

? cma_weirdness
? diff
? data/civ3
? data/womoks
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.159
diff -u -r1.159 tilespec.c
--- client/tilespec.c   20 Apr 2004 06:30:31 -0000      1.159
+++ client/tilespec.c   21 Apr 2004 01:34:52 -0000
@@ -1434,13 +1434,17 @@
   return sprites.city.tile[style][city_styles[style].tiles_num+1];
 }
 
-#define ADD_SPRITE(s, x_offset, y_offset) \
+#define ADD_SPRITE(s, draw_style, draw_fog, x_offset, y_offset)        \
   (assert(s != NULL),                     \
+   sprs->type = DRAWN_SPRITE,             \
+   sprs->style = draw_style,              \
    sprs->sprite = s,                      \
+   sprs->foggable = draw_fog,             \
    sprs->offset_x = x_offset,             \
    sprs->offset_y = y_offset,             \
    sprs++)
-#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, 0, 0)
+#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, DRAW_NORMAL, TRUE, 0, 0)
+#define ADD_SPRITE_FULL(s) ADD_SPRITE(s, DRAW_FULL, TRUE, 0, 0)
 
 /**********************************************************************
   Fill in the sprite array for the city
@@ -1453,7 +1457,7 @@
   *solid_bg = FALSE;
 
   if (!solid_color_behind_units) {
-    ADD_SPRITE(get_city_nation_flag_sprite(pcity),
+    ADD_SPRITE(get_city_nation_flag_sprite(pcity), DRAW_FULL, TRUE,
               flag_offset_x, flag_offset_y);
   } else {
     *solid_bg = TRUE;
@@ -1498,30 +1502,6 @@
   return sprs - save_sprs;
 }
 
-/**********************************************************************
-  Fill in the sprite array for the city
-  (small because things have to be done later in isometric view.)
-***********************************************************************/
-int fill_city_sprite_array_iso(struct drawn_sprite *sprs, struct city *pcity)
-{
-  struct drawn_sprite *save_sprs = sprs;
-
-  ADD_SPRITE(get_city_nation_flag_sprite(pcity),
-            flag_offset_x, flag_offset_y);
-
-  if (pcity->client.occupied) {
-    ADD_SPRITE_SIMPLE(get_city_occupied_sprite(pcity));
-  }
-
-  ADD_SPRITE_SIMPLE(get_city_sprite(pcity));
-
-  if (pcity->client.unhappy) {
-    ADD_SPRITE_SIMPLE(sprites.city.disorder);
-  }
-
-  return sprs - save_sprs;
-}
-
 /**************************************************************************
   Assemble some data that is used in building the tile sprite arrays.
     (map_x, map_y) : the (normalized) map position
@@ -1572,20 +1552,20 @@
   if (is_isometric) {
     if (backdrop) {
       ADD_SPRITE(get_unit_nation_flag_sprite(punit),
-                flag_offset_x, flag_offset_y);
+                DRAW_FULL, TRUE, flag_offset_x, flag_offset_y);
     }
   } else {
     if (backdrop) {
       if (!solid_color_behind_units) {
        ADD_SPRITE(get_unit_nation_flag_sprite(punit),
-                  flag_offset_x, flag_offset_y);
+                  DRAW_FULL, TRUE, flag_offset_x, flag_offset_y);
       } else {
        *solid_bg = TRUE;
       }
     }
   }
 
-  ADD_SPRITE_SIMPLE(unit_type(punit)->sprite);
+  ADD_SPRITE_FULL(unit_type(punit)->sprite);
 
   if(punit->activity!=ACTIVITY_IDLE) {
     struct Sprite *s = NULL;
@@ -1637,38 +1617,38 @@
       break;
     }
 
-    ADD_SPRITE_SIMPLE(s);
+    ADD_SPRITE_FULL(s);
   }
 
   if (punit->ai.control && punit->activity != ACTIVITY_EXPLORE) {
     if (is_military_unit(punit)) {
-      ADD_SPRITE_SIMPLE(sprites.unit.auto_attack);
+      ADD_SPRITE_FULL(sprites.unit.auto_attack);
     } else {
-      ADD_SPRITE_SIMPLE(sprites.unit.auto_settler);
+      ADD_SPRITE_FULL(sprites.unit.auto_settler);
     }
   }
 
   if (punit->connecting) {
-    ADD_SPRITE_SIMPLE(sprites.unit.connect);
+    ADD_SPRITE_FULL(sprites.unit.connect);
   }
 
   if (unit_has_orders(punit)) {
     if (punit->orders.repeat) {
-      ADD_SPRITE_SIMPLE(sprites.unit.patrol);
+      ADD_SPRITE_FULL(sprites.unit.patrol);
     } else {
-      ADD_SPRITE_SIMPLE(sprites.unit.go_to);
+      ADD_SPRITE_FULL(sprites.unit.go_to);
     }
   }
 
   if (stack || punit->occupy) {
-    ADD_SPRITE_SIMPLE(sprites.unit.stack);
+    ADD_SPRITE_FULL(sprites.unit.stack);
   } else {
-    ADD_SPRITE_SIMPLE(sprites.unit.vet_lev[punit->veteran]);
+    ADD_SPRITE_FULL(sprites.unit.vet_lev[punit->veteran]);
   }
  
   ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / unit_type(punit)->hp;
   ihp = CLIP(0, ihp, NUM_TILES_HP_BAR-1);
-  ADD_SPRITE_SIMPLE(sprites.unit.hp_bar[ihp]);
+  ADD_SPRITE_FULL(sprites.unit.hp_bar[ihp]);
 
   return sprs - save_sprs;
 }
@@ -1993,7 +1973,7 @@
        continue;
       }
 
-      ADD_SPRITE(sprites.terrain[other]->blend[dir],
+      ADD_SPRITE(sprites.terrain[other]->blend[dir], DRAW_NORMAL, TRUE,
                 offsets[dir][0], offsets[dir][1]);
     }
   }
@@ -2069,7 +2049,8 @@
          int x = (is_isometric ? iso_offsets[i][0] : noniso_offsets[i][0]);
          int y = (is_isometric ? iso_offsets[i][1] : noniso_offsets[i][1]);
 
-         ADD_SPRITE(draw->layer[l].cells[array_index][i], x, y);
+         ADD_SPRITE(draw->layer[l].cells[array_index][i],
+                    DRAW_NORMAL, TRUE, x, y);
        }
       }
 #undef MATCH
@@ -2096,7 +2077,7 @@
          int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
 
          if (UNKNOWN(dir)) {
-           ADD_SPRITE(sprites.tx.darkness[dir],
+           ADD_SPRITE(sprites.tx.darkness[dir], DRAW_NORMAL, TRUE,
                       offsets[dir][0], offsets[dir][1]);
          }
        }
@@ -2173,6 +2154,8 @@
   int tileno, dir;
   struct tile *ptile = map_get_tile(x, y);
   struct city *pcity = ptile->city;
+  struct unit *punit = get_drawable_unit(x, y, citymode);
+  struct unit *pfocus = get_unit_in_focus();
   struct drawn_sprite *save_sprs = sprs;
 
   *solid_bg = FALSE;
@@ -2236,16 +2219,54 @@
     if (contains_special(tspecial, S_HUT) && draw_specials) {
       ADD_SPRITE_SIMPLE(sprites.tx.village);
     }
+  }
+
+  /* Add grid. */
+  sprs->type = DRAWN_GRID;
+  sprs++;
 
-#if 0
-    /* These are drawn later in isometric view (on top of city.) */
-    if (contains_special(tspecial, S_POLLUTION)) {
-      ADD_SPRITE_SIMPLE(sprites.tx.pollution);
+  if (pcity && draw_cities) {
+    ADD_SPRITE(get_city_nation_flag_sprite(pcity),
+              DRAW_FULL, TRUE, flag_offset_x, flag_offset_y);
+    if (pcity->client.occupied) {
+      ADD_SPRITE_FULL(get_city_occupied_sprite(pcity));
     }
-    if (contains_special(tspecial, S_FALLOUT)) {
-      ADD_SPRITE_SIMPLE(sprites.tx.fallout);
+    ADD_SPRITE_FULL(get_city_sprite(pcity));
+    if (pcity->client.unhappy) {
+      ADD_SPRITE_FULL(sprites.city.disorder);
     }
-#endif
+  }
+
+  if (draw_fortress_airbase && contains_special(tspecial, S_AIRBASE)) {
+    ADD_SPRITE_FULL(sprites.tx.airbase);
+  }
+
+  if (draw_pollution && contains_special(tspecial, S_POLLUTION)) {
+    ADD_SPRITE_SIMPLE(sprites.tx.pollution);
+  }
+  if (draw_pollution && contains_special(tspecial, S_FALLOUT)) {
+    ADD_SPRITE_SIMPLE(sprites.tx.fallout);
+  }
+
+  /* City size.  Drawing this under fog makes it hard to read. */
+  if (pcity && draw_cities) {
+    if (pcity->size >= 10) {
+      ADD_SPRITE(sprites.city.size_tens[pcity->size / 10], DRAW_FULL,
+                FALSE, 0, 0);
+    }
+    ADD_SPRITE(sprites.city.size[pcity->size % 10], DRAW_FULL,
+              FALSE, 0, 0);
+  }
+
+  if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
+    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
+    bool backdrop = !pcity;
+
+    sprs += fill_unit_sprite_array(sprs, punit, solid_bg, stacked, backdrop);
+  }
+
+  if (draw_fortress_airbase && contains_special(tspecial, S_FORTRESS)) {
+    ADD_SPRITE_FULL(sprites.tx.fortress);
   }
 
   return sprs - save_sprs;
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.61
diff -u -r1.61 tilespec.h
--- client/tilespec.h   20 Apr 2004 06:30:31 -0000      1.61
+++ client/tilespec.h   21 Apr 2004 01:34:52 -0000
@@ -27,6 +27,20 @@
 struct player;
 
 struct drawn_sprite {
+  enum {
+    DRAWN_SPRITE,      /* Draw a sprite. */
+    DRAWN_GRID         /* Draw the map grid now. */
+  } type;
+
+  enum {
+    /* Only applicable in iso-view.  "Full" sprites overlap into the top
+     * half-tile of UNIT_TILE_HEIGHT. */
+    DRAW_NORMAL,
+    DRAW_FULL
+  } style;
+
+  /* These files only apply for DRAWN_SPRITE. */
+  bool foggable;       /* Set to FALSE for sprites that are never fogged. */
   struct Sprite *sprite;
   int offset_x, offset_y;      /* offset from tile origin */
 };
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.214
diff -u -r1.214 mapview.c
--- client/gui-gtk/mapview.c    15 Apr 2004 19:36:01 -0000      1.214
+++ client/gui-gtk/mapview.c    21 Apr 2004 01:34:52 -0000
@@ -942,27 +942,6 @@
 /**************************************************************************
 Only used for isometric view.
 **************************************************************************/
-static void put_city_pixmap_draw(struct city *pcity, GdkPixmap *pm,
-                                int canvas_x, int canvas_y,
-                                int offset_x, int offset_y_unit,
-                                int width, int height_unit,
-                                bool fog)
-{
-  struct drawn_sprite sprites[80];
-  int count = fill_city_sprite_array_iso(sprites, pcity);
-  int i;
-
-  for (i=0; i<count; i++) {
-    if (sprites[i].sprite) {
-      pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &sprites[i],
-                             offset_x, offset_y_unit, width, height_unit,
-                             fog);
-    }
-  }
-}
-/**************************************************************************
-Only used for isometric view.
-**************************************************************************/
 static void pixmap_put_black_tile_iso(GdkDrawable *pm,
                                      int canvas_x, int canvas_y,
                                      int offset_x, int offset_y,
@@ -992,11 +971,8 @@
                                enum draw_type draw)
 {
   struct drawn_sprite tile_sprs[80];
-  struct city *pcity;
-  struct unit *punit, *pfocus;
-  enum tile_special_type special;
   int count, i;
-  bool solid_bg, fog, tile_hilited;
+  bool solid_bg, fog;
   struct canvas canvas_store = {pm};
 
   if (!width || !(height || height_unit))
@@ -1016,11 +992,6 @@
   normalize_map_pos(&x, &y);
 
   fog = tile_get_known(x, y) == TILE_KNOWN_FOGGED && draw_fog_of_war;
-  pcity = map_get_city(x, y);
-  punit = get_drawable_unit(x, y, citymode);
-  pfocus = get_unit_in_focus();
-  special = map_get_special(x, y);
-  tile_hilited = (map_get_tile(x,y)->client.hilite != HILITE_NONE);
 
   if (solid_bg) {
     gdk_gc_set_clip_origin(fill_bg_gc, canvas_x, canvas_y);
@@ -1048,74 +1019,30 @@
 
   /*** Draw terrain and specials ***/
   for (i = 0; i < count; i++) {
-    if (tile_sprs[i].sprite)
-      pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &tile_sprs[i],
-                             offset_x, offset_y, width, height, fog);
-    else
-      freelog(LOG_ERROR, "sprite is NULL");
-  }
-
-  /*** Grid (map grid, borders, coastline, etc.) ***/
-  tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y, draw, citymode);
-
-  /*** City and various terrain improvements ***/
-  if (pcity && draw_cities) {
-    put_city_pixmap_draw(pcity, pm,
-                        canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-                        offset_x, offset_y_unit,
-                        width, height_unit, fog);
-  }
-  if (contains_special(special, S_AIRBASE) && draw_fortress_airbase)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.tx.airbase,
-                                offset_x, offset_y_unit,
-                                width, height_unit, fog);
-  if (contains_special(special, S_FALLOUT) && draw_pollution)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y,
-                                sprites.tx.fallout,
-                                offset_x, offset_y,
-                                width, height, fog);
-  if (contains_special(special, S_POLLUTION) && draw_pollution)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y,
-                                sprites.tx.pollution,
-                                offset_x, offset_y,
-                                width, height, fog);
-
-  /*** city size ***/
-  /* Not fogged as it would be unreadable */
-  if (pcity && draw_cities) {
-    if (pcity->size>=10)
-      pixmap_put_overlay_tile_draw(pm, canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                  sprites.city.size_tens[pcity->size/10],
-                                  offset_x, offset_y_unit,
-                                  width, height_unit, 0);
-
-    pixmap_put_overlay_tile_draw(pm, canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.city.size[pcity->size%10],
-                                offset_x, offset_y_unit,
-                                width, height_unit, 0);
-  }
-
-  /*** Unit ***/
-  if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
-    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
-    bool backdrop = !pcity;
-
-    put_unit(punit, stacked, backdrop, &canvas_store,
-            canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-            offset_x, offset_y_unit,
-            width, height_unit);
+    switch (tile_sprs[i].type) {
+    case DRAWN_SPRITE:
+      switch (tile_sprs[i].style) {
+      case DRAW_NORMAL:
+       pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &tile_sprs[i],
+                               offset_x, offset_y, width, height,
+                               fog && tile_sprs[i].foggable);
+       break;
+      case DRAW_FULL:
+       pixmap_put_drawn_sprite(pm, canvas_x,
+                               canvas_y - NORMAL_TILE_HEIGHT / 2,
+                               &tile_sprs[i], offset_x, offset_y_unit,
+                               width, height_unit,
+                               fog && tile_sprs[i].foggable);
+       break;
+      }
+      break;
+    case DRAWN_GRID:
+      /*** Grid (map grid, borders, coastline, etc.) ***/
+      tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y,
+                    draw, citymode);
+      break;
+    }
   }
-
-  if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.tx.fortress,
-                                offset_x, offset_y_unit,
-                                width, height_unit, fog);
 }
 
 /**************************************************************************
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.119
diff -u -r1.119 mapview.c
--- client/gui-gtk-2.0/mapview.c        15 Apr 2004 19:36:01 -0000      1.119
+++ client/gui-gtk-2.0/mapview.c        21 Apr 2004 01:34:52 -0000
@@ -1054,27 +1054,6 @@
 /**************************************************************************
 Only used for isometric view.
 **************************************************************************/
-static void put_city_pixmap_draw(struct city *pcity, GdkPixmap *pm,
-                                int canvas_x, int canvas_y,
-                                int offset_x, int offset_y_unit,
-                                int width, int height_unit,
-                                bool fog)
-{
-  struct drawn_sprite sprites[80];
-  int count = fill_city_sprite_array_iso(sprites, pcity);
-  int i;
-
-  for (i=0; i<count; i++) {
-    if (sprites[i].sprite) {
-      pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &sprites[i],
-                             offset_x, offset_y_unit, width, height_unit,
-                             fog);
-    }
-  }
-}
-/**************************************************************************
-Only used for isometric view.
-**************************************************************************/
 static void pixmap_put_black_tile_iso(GdkDrawable *pm,
                                      int canvas_x, int canvas_y,
                                      int offset_x, int offset_y,
@@ -1104,11 +1083,8 @@
                                enum draw_type draw)
 {
   struct drawn_sprite tile_sprs[80];
-  struct city *pcity;
-  struct unit *punit, *pfocus;
-  enum tile_special_type special;
   int count, i;
-  bool solid_bg, fog, tile_hilited;
+  bool solid_bg, fog;
   struct canvas canvas_store = {.type = CANVAS_PIXMAP, .v.pixmap = pm};
 
   if (!width || !(height || height_unit))
@@ -1128,11 +1104,6 @@
   normalize_map_pos(&x, &y);
 
   fog = tile_get_known(x, y) == TILE_KNOWN_FOGGED && draw_fog_of_war;
-  pcity = map_get_city(x, y);
-  punit = get_drawable_unit(x, y, citymode);
-  pfocus = get_unit_in_focus();
-  special = map_get_special(x, y);
-  tile_hilited = (map_get_tile(x,y)->client.hilite != HILITE_NONE);
 
   if (solid_bg) {
     gdk_gc_set_clip_origin(fill_bg_gc, canvas_x, canvas_y);
@@ -1160,74 +1131,30 @@
 
   /*** Draw terrain and specials ***/
   for (i = 0; i < count; i++) {
-    if (tile_sprs[i].sprite)
-      pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &tile_sprs[i],
-                             offset_x, offset_y, width, height, fog);
-    else
-      freelog(LOG_ERROR, "sprite is NULL");
-  }
-
-  /*** Grid (map grid, borders, coastline, etc.) ***/
-  tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y, draw, citymode);
-
-  /*** City and various terrain improvements ***/
-  if (pcity && draw_cities) {
-    put_city_pixmap_draw(pcity, pm,
-                        canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-                        offset_x, offset_y_unit,
-                        width, height_unit, fog);
-  }
-  if (contains_special(special, S_AIRBASE) && draw_fortress_airbase)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.tx.airbase,
-                                offset_x, offset_y_unit,
-                                width, height_unit, fog);
-  if (contains_special(special, S_FALLOUT) && draw_pollution)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y,
-                                sprites.tx.fallout,
-                                offset_x, offset_y,
-                                width, height, fog);
-  if (contains_special(special, S_POLLUTION) && draw_pollution)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y,
-                                sprites.tx.pollution,
-                                offset_x, offset_y,
-                                width, height, fog);
-
-  /*** city size ***/
-  /* Not fogged as it would be unreadable */
-  if (pcity && draw_cities) {
-    if (pcity->size>=10)
-      pixmap_put_overlay_tile_draw(pm, canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                  sprites.city.size_tens[pcity->size/10],
-                                  offset_x, offset_y_unit,
-                                  width, height_unit, 0);
-
-    pixmap_put_overlay_tile_draw(pm, canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.city.size[pcity->size%10],
-                                offset_x, offset_y_unit,
-                                width, height_unit, 0);
-  }
-
-  /*** Unit ***/
-  if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
-    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
-    bool backdrop = !pcity;
-
-    put_unit(punit, stacked, backdrop, &canvas_store,
-            canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-            offset_x, offset_y_unit,
-            width, height_unit);
+    switch (tile_sprs[i].type) {
+    case DRAWN_SPRITE:
+      switch (tile_sprs[i].style) {
+      case DRAW_NORMAL:
+       pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &tile_sprs[i],
+                               offset_x, offset_y, width, height,
+                               fog && tile_sprs[i].foggable);
+       break;
+      case DRAW_FULL:
+       pixmap_put_drawn_sprite(pm, canvas_x,
+                               canvas_y - NORMAL_TILE_HEIGHT / 2,
+                               &tile_sprs[i], offset_x, offset_y_unit,
+                               width, height_unit,
+                               fog && tile_sprs[i].foggable);
+       break;
+      }
+      break;
+    case DRAWN_GRID:
+      /*** Grid (map grid, borders, coastline, etc.) ***/
+      tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y,
+                    draw, citymode);
+      break;
+    }
   }
-
-  if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)
-    pixmap_put_overlay_tile_draw(pm,
-                                canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.tx.fortress,
-                                offset_x, offset_y_unit,
-                                width, height_unit, fog);
 }
 
 /**************************************************************************
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.111
diff -u -r1.111 mapview.c
--- client/gui-win32/mapview.c  15 Apr 2004 19:36:01 -0000      1.111
+++ client/gui-win32/mapview.c  21 Apr 2004 01:34:53 -0000
@@ -911,32 +911,6 @@
   
 }
 
-
-
-/**************************************************************************
-Only used for isometric view.
-**************************************************************************/
-static void put_city_pixmap_draw(struct city *pcity,HDC hdc,
-                                 int canvas_x, int canvas_y,
-                                 int offset_x, int offset_y_unit,
-                                 int width, int height_unit,
-                                bool fog)
-{
-  struct drawn_sprite sprites[80];
-  int count = fill_city_sprite_array_iso(sprites, pcity);
-  int i;
-
-  for (i=0; i<count; i++) {
-    if (sprites[i].sprite) {
-      pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, &sprites[i],
-                                   offset_x, offset_y_unit,
-                                   width, height_unit,
-                                   fog);
-    }
-  }
-}
-
-
 /**************************************************************************
 Only used for isometric view.
 **************************************************************************/
@@ -948,10 +922,7 @@
                                 enum draw_type draw)
 {
   struct drawn_sprite tile_sprs[80];
-  struct city *pcity;
-  struct unit *punit, *pfocus;
   struct canvas canvas_store={hdc,NULL};
-  enum tile_special_type special;
   int count, i;
   bool fog, solid_bg, is_real;
 
@@ -968,10 +939,6 @@
   is_real = normalize_map_pos(&x, &y);
   assert(is_real);
   fog = tile_get_known(x, y) == TILE_KNOWN_FOGGED && draw_fog_of_war;
-  pcity = map_get_city(x, y);
-  punit = get_drawable_unit(x, y, citymode);
-  pfocus = get_unit_in_focus();
-  special = map_get_special(x, y);
 
   if (solid_bg) {
     HPEN oldpen;
@@ -994,103 +961,28 @@
 
   /*** Draw terrain and specials ***/
   for (i = 0; i < count; i++) {
-    if (tile_sprs[i].sprite)
-      pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, &tile_sprs[i],
-                                   offset_x, offset_y, width, height, fog);
-    else
-      freelog(LOG_ERROR, "sprite is NULL");
-  }
-
-  /*** Grid (map grid, borders, coastline, etc.) ***/
-  tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y, draw, citymode);
-
-  if (draw_coastline && !draw_terrain) {
-    enum tile_terrain_type t1 = map_get_terrain(x, y), t2;
-    int x1, y1;
-    HPEN old;
-    old=SelectObject(hdc,pen_std[COLOR_STD_OCEAN]);
-    x1=x;
-    y1=y-1;
-    if (normalize_map_pos(&x1,&y1)) { 
-      t2=map_get_terrain(x1,y1);
-      if (draw & D_M_R && (is_ocean(t1) ^ is_ocean(t2))) {
-       MoveToEx(hdc,canvas_x+NORMAL_TILE_WIDTH/2,canvas_y,NULL);
-       LineTo(hdc,canvas_x+NORMAL_TILE_WIDTH,
-              canvas_y+NORMAL_TILE_HEIGHT/2);
+    switch (tile_sprs[i].type) {
+    case DRAWN_SPRITE:
+      switch (tile_sprs[i].style) {
+      case DRAW_NORMAL:
+       pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, &tile_sprs[i],
+                               offset_x, offset_y, width, height,
+                               fog && tile_sprs[i].foggable);
+       break;
+      case DRAW_FULL:
+       pixmap_put_drawn_sprite(hdc,
+                               canvas_x, canvas_y - NORMAL_TILE_HEIGHT / 2,
+                               &tile_sprs[i],
+                               offset_x, offset_y_unit, width, height_unit,
+                               fog && tile_sprs[i].foggable);
+       break;
       }
+    case DRAWN_GRID:
+      /*** Grid (map grid, borders, coastline, etc.) ***/
+      tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y,
+                    draw, citymode);
     }
-    x1=x-1; 
-    y1=y;
-    if (normalize_map_pos(&x1, &y1)) {
-      t2 = map_get_terrain(x1, y1);
-      if (draw & D_M_L && (is_ocean(t1) ^ is_ocean(t2))) {
-       MoveToEx(hdc,canvas_x,canvas_y+NORMAL_TILE_HEIGHT/2,NULL);
-       LineTo(hdc,canvas_x+NORMAL_TILE_WIDTH/2,canvas_y); 
-      }
-    }
-  }
-  
-  /*** City and various terrain improvements ***/
-  if (pcity && draw_cities) {
-    put_city_pixmap_draw(pcity, hdc,
-                        canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-                         offset_x, offset_y_unit,
-                         width, height_unit, fog);
-  }
-  
-  if (contains_special(special, S_AIRBASE) && draw_fortress_airbase)
-    pixmap_put_overlay_tile_draw(hdc,
-                                 canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                 sprites.tx.airbase,
-                                 offset_x, offset_y_unit,
-                                 width, height_unit, fog);
-  if (contains_special(special, S_FALLOUT) && draw_pollution)
-    pixmap_put_overlay_tile_draw(hdc,
-                                 canvas_x, canvas_y,
-                                 sprites.tx.fallout,
-                                 offset_x, offset_y,
-                                 width, height, fog);
-  if (contains_special(special, S_POLLUTION) && draw_pollution)
-    pixmap_put_overlay_tile_draw(hdc,
-                                 canvas_x, canvas_y,
-                                 sprites.tx.pollution,
-                                 offset_x, offset_y,
-                                 width, height, fog);
-  
-  /*** city size ***/
-  /* Not fogged as it would be unreadable */
-  if (pcity && draw_cities) {
-    if (pcity->size>=10)
-      pixmap_put_overlay_tile_draw(hdc, 
-                                  canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                   sprites.city.size_tens[pcity->size/10],
-                                   offset_x, offset_y_unit,
-                                  width, height_unit, 0);
-
-    pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                sprites.city.size[pcity->size%10],
-                                 offset_x, offset_y_unit,
-                                 width, height_unit, 0);  
-  }
-
-    /*** Unit ***/
-  if (punit && (draw_units || (punit == pfocus && draw_focus_unit))) {
-    bool stacked = (unit_list_size(&map_get_tile(x, y)->units) > 1);
-    bool backdrop = !pcity;
-
-    put_unit(punit, stacked, backdrop, &canvas_store,
-             canvas_x, canvas_y - NORMAL_TILE_HEIGHT/2,
-             offset_x, offset_y_unit,
-             width, height_unit);
   }
-  
-  if (contains_special(special, S_FORTRESS) && draw_fortress_airbase)
-    pixmap_put_overlay_tile_draw(hdc,
-                                 canvas_x, canvas_y-NORMAL_TILE_HEIGHT/2,
-                                 sprites.tx.fortress,
-                                 offset_x, offset_y_unit,
-                                 width, height_unit, fog);
-  
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8559) extend drawn_sprite to include more drawing elements, Jason Short <=