Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] Re: (PR#9509) Unknown area drawing problem
Home

[Freeciv-Dev] Re: (PR#9509) Unknown area drawing problem

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mstefek@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#9509) Unknown area drawing problem
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 26 Jul 2004 10:57:17 -0700
Reply-to: rt@xxxxxxxxxxx

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

Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9509 >
> 
>>[mstefek@xxxxxxxxx - Mon Jul 26 14:40:44 2004]:
>>
>>Take a look at the attached image.
>>It's newest CVS and trident tileset.
> 
> 
> I can't reproduce this, but looking at the code I can see why it
> happens.  Darkness is always drawn on top of the first layer (between
> first and second layers of terrain); this causes it to show behind the
> 3d terrain in isotrident.  But in trident the second layer is still 2d
> so the darkness needs to be drawn on top of it.

This patch should fix it.  I'm not sure if this is the best way to do 
it, and I can't test it (since I haven't been able to get the problem in 
the first place).

jason

Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.190
diff -u -r1.190 tilespec.c
--- client/tilespec.c   26 Jul 2004 03:07:39 -0000      1.190
+++ client/tilespec.c   26 Jul 2004 17:54:16 -0000
@@ -115,6 +115,7 @@
    * there's darkness in _each_ of the cardinal directions. */
   DARKNESS15 = 3
 } darkness_style;
+int darkness_layer;
 
 struct specfile;
 
@@ -847,6 +848,12 @@
     freelog(LOG_FATAL, _("Invalid darkness style set in tileset."));
     exit(EXIT_FAILURE);
   }
+  darkness_layer = secfile_lookup_int(file, "tilespec.darkness_layer");
+  if (darkness_layer < 0) {
+    freelog(LOG_FATAL, "Invalid darkness layer set in tileset.");
+    exit(EXIT_FAILURE);
+  }
+
   flag_offset_x = secfile_lookup_int_default(file, 0,
                                             "tilespec.flag_offset_x");
   flag_offset_y = secfile_lookup_int_default(file, 0,
@@ -2428,6 +2435,61 @@
 }
 
 /****************************************************************************
+  Fill in the sprite array with darkness for the tile.
+****************************************************************************/
+static int fill_darkness_sprite_array(struct drawn_sprite *sprs,
+                                     int map_x, int map_y)
+{
+  struct drawn_sprite *saved_sprs = sprs;
+  int dir, adjc_x, adjc_y;
+
+#define UNKNOWN(dir)                                        \
+  (MAPSTEP(adjc_x, adjc_y, map_x, map_y, DIR4_TO_DIR8[dir]) \
+   && tile_get_known(adjc_x, adjc_y) == TILE_UNKNOWN)
+
+  switch (darkness_style) {
+  case DARKNESS0:
+    break;
+  case DARKNESS1:
+    for (dir = 0; dir < 4; dir++) {
+      const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
+      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], DRAW_NORMAL, TRUE,
+                  offsets[dir][0], offsets[dir][1]);
+      }
+    }
+    break;
+  case DARKNESS4:
+    for (dir = 0; dir < 4; dir++) {
+      if (UNKNOWN(dir)) {
+       ADD_SPRITE_SIMPLE(sprites.tx.darkness[dir]);
+      }
+    }
+    break;
+  case DARKNESS15:
+    /* We're looking to find the INDEX_NSEW for the directions that
+     * are unknown.  We want to mark unknown tiles so that an unreal
+     * tile will be given the same marking as our current tile - that
+     * way we won't get the "unknown" dither along the edge of the
+     * map. */
+    {
+      int tileno = INDEX_NSEW(UNKNOWN(DIR4_NORTH), UNKNOWN(DIR4_SOUTH),
+                             UNKNOWN(DIR4_EAST), UNKNOWN(DIR4_WEST));
+
+      if (tileno != 0) {
+       ADD_SPRITE_SIMPLE(sprites.tx.darkness[tileno]);
+      }
+    }
+    break;
+  }
+#undef UNKNOWN
+
+  return sprs - saved_sprs;
+}
+
+/****************************************************************************
   Add sprites for the base terrain to the sprite list.  This doesn't
   include specials or rivers.
 ****************************************************************************/
@@ -2440,7 +2502,7 @@
   struct tile *ptile = map_get_tile(map_x, map_y);
   enum tile_terrain_type ttype = ptile->terrain;
   struct terrain_drawing_data *draw = sprites.terrain[ttype];
-  int l, dir, adjc_x, adjc_y;
+  int l;
 
   if (!draw_terrain) {
     return 0;
@@ -2542,56 +2604,18 @@
 
     /* Add darkness on top of the first layer.  Note that darkness is always
      * drawn, even in citymode, etc. */
-    if (l == 0) {
-#define UNKNOWN(dir)                                        \
-  (MAPSTEP(adjc_x, adjc_y, map_x, map_y, DIR4_TO_DIR8[dir]) \
-   && tile_get_known(adjc_x, adjc_y) == TILE_UNKNOWN)
-
-      switch (darkness_style) {
-      case DARKNESS0:
-       break;
-      case DARKNESS1:
-       for (dir = 0; dir < 4; dir++) {
-         const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
-         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], DRAW_NORMAL, TRUE,
-                      offsets[dir][0], offsets[dir][1]);
-         }
-       }
-       break;
-      case DARKNESS4:
-       for (dir = 0; dir < 4; dir++) {
-         if (UNKNOWN(dir)) {
-           ADD_SPRITE_SIMPLE(sprites.tx.darkness[dir]);
-         }
-       }
-       break;
-      case DARKNESS15:
-       /* We're looking to find the INDEX_NSEW for the directions that
-        * are unknown.  We want to mark unknown tiles so that an unreal
-        * tile will be given the same marking as our current tile - that
-        * way we won't get the "unknown" dither along the edge of the
-        * map. */
-       {
-         int tileno = INDEX_NSEW(UNKNOWN(DIR4_NORTH), UNKNOWN(DIR4_SOUTH),
-                                 UNKNOWN(DIR4_EAST), UNKNOWN(DIR4_WEST));
-
-         if (tileno != 0) {
-           ADD_SPRITE_SIMPLE(sprites.tx.darkness[tileno]);
-         }
-       }
-       break;
-      }
-#undef UNKNOWN
+    if (l == darkness_layer) {
+      sprs += fill_darkness_sprite_array(sprs, map_x, map_y);
     }
   }
 
+  if (l >= darkness_layer) {
+    sprs += fill_darkness_sprite_array(sprs, map_x, map_y);
+  }
+
   return sprs - saved_sprs;
 }
 
-
 /**********************************************************************
 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
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.20
diff -u -r1.20 isotrident.tilespec
--- data/isotrident.tilespec    27 Jun 2004 16:52:17 -0000      1.20
+++ data/isotrident.tilespec    26 Jul 2004 17:54:16 -0000
@@ -26,7 +26,8 @@
 
 ; Use darkness style 1 (single-sprite)
 darkness_style = 1
- 
+darkness_layer = 0
+
 ; offset the flags by this amount when drawing units
 flag_offset_x = 17
 flag_offset_y = 11
Index: data/trident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident.tilespec,v
retrieving revision 1.24
diff -u -r1.24 trident.tilespec
--- data/trident.tilespec       24 Jul 2004 06:21:12 -0000      1.24
+++ data/trident.tilespec       26 Jul 2004 17:54:16 -0000
@@ -26,7 +26,8 @@
 
 ; Use darkness style 3 (15 sprites)
 darkness_style = 3
- 
+darkness_layer = 1
+
 ; offset the flags by this amount when drawing units
 flag_offset_x = 0
 flag_offset_y = 0

[Prev in Thread] Current Thread [Next in Thread]