Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] Re: (PR#11433) Fog of War rendering improvement
Home

[Freeciv-Dev] Re: (PR#11433) Fog of War rendering improvement

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#11433) Fog of War rendering improvement
From: "Andreas Røsdal" <andrearo@xxxxxxxxxxxx>
Date: Thu, 9 Dec 2004 08:32:25 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11433 >

This updated patch uses a bit less memory.

Andreas Røsdal
diff -ruN -X freeciv-cvs-Dec-08/diff_ignore 
freeciv-cvs-Dec-08/client/gui-gtk-2.0/mapview.c 
freeciv-fow/client/gui-gtk-2.0/mapview.c
--- freeciv-cvs-Dec-08/client/gui-gtk-2.0/mapview.c     2004-11-01 
04:39:45.000000000 +0100
+++ freeciv-fow/client/gui-gtk-2.0/mapview.c    2004-12-09 17:26:24.000000000 
+0100
@@ -877,22 +877,49 @@
     return;
   }
 
-  pixmap_put_sprite(pixmap, canvas_x, canvas_y, ssprite,
-                   0, 0, ssprite->width, ssprite->height);
-
-  /* I imagine this could be done more efficiently. Some pixels We first
-     draw from the sprite, and then draw black afterwards. It would be much
-     faster to just draw every second pixel black in the first place. */
   if (fog) {
+    int x, y;
+    GdkImage* ftile = gdk_drawable_get_image(ssprite->pixmap,
+                                             0, 0,
+                                             ssprite->width,
+                                             ssprite->height);
+    /* Iterate over all pixels, reducing brightness by 50%. */
+    for (x = 0; x < ssprite->width; x++) {
+      for (y = 0; y < ssprite->height; y++) {
+        guint32 pixel =  gdk_image_get_pixel(ftile, x, y);
+
+        guint8 red = (((pixel & ftile->visual->red_mask) << 
+             (32 - ftile->visual->red_shift 
+              - ftile->visual->red_prec)) >> 24) / 2; 
+        guint8 green = (((pixel & ftile->visual->green_mask) <<
+             (32 - ftile->visual->green_shift 
+              - ftile->visual->green_prec)) >> 24) / 2;
+        guint8 blue = (((pixel & ftile->visual->blue_mask) <<
+             (32 - ftile->visual->blue_shift 
+              - ftile->visual->blue_prec)) >> 24) / 2;
+        guint32 result = red << ftile->visual->red_shift
+                        | green << ftile->visual->green_shift          
+                        | blue << ftile->visual->blue_shift;
+
+        gdk_image_put_pixel(ftile, x , y, result);
+      }
+    }
+
     gdk_gc_set_clip_origin(fill_tile_gc, canvas_x, canvas_y);
     gdk_gc_set_clip_mask(fill_tile_gc, ssprite->mask);
-    gdk_gc_set_foreground(fill_tile_gc, colors_standard[COLOR_STD_BLACK]);
     gdk_gc_set_ts_origin(fill_tile_gc, canvas_x, canvas_y);
-    gdk_gc_set_stipple(fill_tile_gc, black50);
 
-    gdk_draw_rectangle(pixmap, fill_tile_gc, TRUE,
-                      canvas_x, canvas_y, ssprite->width, ssprite->height);
+    gdk_draw_image(pixmap, fill_tile_gc,
+                   ftile,
+                   0, 0,
+                   canvas_x, canvas_y,
+                   ssprite->width, ssprite->height);
+    g_object_unref(ftile);
     gdk_gc_set_clip_mask(fill_tile_gc, NULL);
+
+  } else {
+    pixmap_put_sprite(pixmap, canvas_x, canvas_y, ssprite,
+                      0, 0, ssprite->width, ssprite->height);
   }
 }
 

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