Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12591) Make FTWL compile and run again
Home

[Freeciv-Dev] (PR#12591) Make FTWL compile and run again

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12591) Make FTWL compile and run again
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Tue, 22 Mar 2005 12:01:31 -0800
Reply-to: bugs@xxxxxxxxxxx

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


List of changes:
 - re-enable ftwl in configure.ac
 - add some new functions with almost empty body
 - rename tile_list to tile_list2 since there is a new tile_list in
 the common code
 - disable the city description functions because there are now drawn
 in the common code
 - add new text functions for the canvas
 - optimize the blitting function. The previous version couldn't
 really be fast.
 - add an option to measure blitting speed by cycles

Problems:
 - city descriptions are not drawn correctly
 - the feature of city size depending city names is not supported by
 the common code
 - graphic artifacts in the mapview (*points* to common code)

        Raimar

-- 
 email: i-freeciv-lists@xxxxxxxxxxxxx
 1 + 1 = 3, for large values of 1

Index: configure.ac
===================================================================
RCS file: /home/freeciv/CVS/freeciv/configure.ac,v
retrieving revision 1.97
diff -u -u -r1.97 configure.ac
--- configure.ac        19 Mar 2005 23:04:35 -0000      1.97
+++ configure.ac        22 Mar 2005 19:50:01 -0000
@@ -66,6 +66,7 @@
   no)    client=no ;;
   xaw3d)  client=xaw
          WITH_XAW3D=1 ;;
+  ftwl)   client=ftwl ;;
   gtk)    client=gtk-2.0 ;;
   gtk2)   client=gtk-2.0 ;;
   gtk2.0) client=gtk-2.0 ;;
Index: client/gui-ftwl/connectdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/connectdlg.c,v
retrieving revision 1.4
diff -u -u -r1.4 connectdlg.c
--- client/gui-ftwl/connectdlg.c        20 Sep 2004 21:51:13 -0000      1.4
+++ client/gui-ftwl/connectdlg.c        22 Mar 2005 19:50:04 -0000
@@ -251,3 +251,11 @@
 {
   close_connection_dialog();
 }
+
+/**************************************************************************
+  ...
+**************************************************************************/
+void gui_set_rulesets(int num_rulesets, char **rulesets)
+{
+    /* PORTME */
+}
Index: client/gui-ftwl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/gui_main.c,v
retrieving revision 1.11
diff -u -u -r1.11 gui_main.c
--- client/gui-ftwl/gui_main.c  5 Mar 2005 23:51:06 -0000       1.11
+++ client/gui-ftwl/gui_main.c  22 Mar 2005 19:50:04 -0000
@@ -306,3 +306,17 @@
 {
   /* PORTME */
 }
+
+/****************************************************************************
+  Enqueue a callback to be called during an idle moment.  The 'callback'
+  function should be called sometimes soon, and passed the 'data' pointer
+  as its data.
+****************************************************************************/
+void add_idle_callback(void (callback)(void *), void *data)
+{
+  /* PORTME */
+
+  /* This is a reasonable fallback if it's not ported. */
+  freelog(LOG_DEBUG, "Unimplemented add_idle_callback.");
+  (callback)(data);
+}
Index: client/gui-ftwl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/mapview.c,v
retrieving revision 1.16
diff -u -u -r1.16 mapview.c
--- client/gui-ftwl/mapview.c   2 Mar 2005 18:22:59 -0000       1.16
+++ client/gui-ftwl/mapview.c   22 Mar 2005 19:50:05 -0000
@@ -21,6 +21,7 @@
 #include "game.h"
 #include "log.h"
 #include "map.h"
+#include "movement.h"
 #include "registry.h"
 #include "support.h"
 
@@ -72,18 +73,18 @@
 
 static double min_drag_time = 1.0 / (float) MAX_DRAG_FPS;
 
-#define MAX_TILE_LIST_ITEMS    20
+#define MAX_TILE_LIST2_ITEMS   20
 #define MAX_ACTION_DEFS                60
 #define MAX_CITY_DESCR_STYLES  MAX_CITY_SIZE
 
-enum tile_list_item_type {
+enum tile_list2_item_type {
   TLI_TERRAIN,
   TLI_CITY,
   TLI_UNIT
 };
 
-struct tile_list_item {
-  enum tile_list_item_type type;
+struct tile_list2_item {
+  enum tile_list2_item_type type;
   struct osda *unselected;
   struct osda *selected;
   struct sw_widget *button;
@@ -93,11 +94,11 @@
   char *info_text;
 };
 
-static struct tile_list {
+static struct tile_list2 {
   int items;
   int selected;
-  struct tile_list_item item[MAX_TILE_LIST_ITEMS];
-} tile_list;
+  struct tile_list2_item item[MAX_TILE_LIST2_ITEMS];
+} tile_list2;
 
 static struct ct_tooltip *tooltip_template = NULL;
 
@@ -138,25 +139,7 @@
   } style[MAX_CITY_DESCR_STYLES];
 } city_descr_styles;
 
-/**************************************************************************
-  Find the appropriate city description theme style.  This depends on 
-  the size of the city, and enables us to have different visual styles
-  for city descriptions depending on their sizes.
-**************************************************************************/
-static struct city_descr_style *find_city_descr_style(struct city *pcity)
-{
-  int i;
-
-  for (i = 0; i < city_descr_styles.styles; i++) {
-    if (pcity->size >= city_descr_styles.style[i].min_size &&
-       pcity->size <= city_descr_styles.style[i].max_size) {
-      return &city_descr_styles.style[i];
-    }
-  }
-  freelog(LOG_ERROR, "No matching city description style found for %s "
-          "which is of size %d", pcity->name, pcity->size);
-  return &city_descr_styles.style[0];
-}
+static struct ct_string *text_templates[FONT_COUNT];
 
 /**************************************************************************
   Typically an info box is provided to tell the player about the state
@@ -334,6 +317,39 @@
 }
 #endif
 
+/* Disabled for now */
+#if 0
+/**************************************************************************
+  Find the appropriate city description theme style.  This depends on 
+  the size of the city, and enables us to have different visual styles
+  for city descriptions depending on their sizes.
+**************************************************************************/
+static struct city_descr_style *find_city_descr_style(struct city *pcity)
+{
+  int i;
+
+  for (i = 0; i < city_descr_styles.styles; i++) {
+    if (pcity->size >= city_descr_styles.style[i].min_size &&
+       pcity->size <= city_descr_styles.style[i].max_size) {
+      return &city_descr_styles.style[i];
+    }
+  }
+  freelog(LOG_ERROR, "No matching city description style found for %s "
+          "which is of size %d", pcity->name, pcity->size);
+  return &city_descr_styles.style[0];
+}
+
+/**************************************************************************
+  If necessary, clear the city descriptions out of the buffer.
+**************************************************************************/
+void prepare_show_city_descriptions(void)
+{
+  widget_list_iterate(city_descr_windows, widget) {
+    widget_list_unlink(city_descr_windows, widget);
+    sw_widget_destroy(widget);
+  } widget_list_iterate_end;
+}
+
 /**************************************************************************
   Draw a description for the given city.  (canvas_x, canvas_y) is the
   canvas position of the city itself.
@@ -422,6 +438,7 @@
   widget_list_prepend(city_descr_windows, window);
   /* PORTME */
 }
+#endif
 
 /**************************************************************************
   Draw some or all of a sprite onto the mapview or citydialog canvas.
@@ -580,17 +597,6 @@
 }
 
 /**************************************************************************
-  If necessary, clear the city descriptions out of the buffer.
-**************************************************************************/
-void prepare_show_city_descriptions(void)
-{
-  widget_list_iterate(city_descr_windows, widget) {
-    widget_list_unlink(city_descr_windows, widget);
-    sw_widget_destroy(widget);
-  } widget_list_iterate_end;
-}
-
-/**************************************************************************
   Draw a cross-hair overlay on a tile.
 **************************************************************************/
 void put_cross_overlay_tile(struct tile *ptile)
@@ -674,14 +680,14 @@
   return result;
 }
 
-static void tile_list_select(int new_index);
+static void tile_list2_select(int new_index);
 
 /**************************************************************************
   ...
 **************************************************************************/
-static void tile_list_select_callback(struct sw_widget *widget, void *data)
+static void tile_list2_select_callback(struct sw_widget *widget, void *data)
 {
-    tile_list_select((int)data);
+    tile_list2_select((int)data);
 }
 
 /**************************************************************************
@@ -690,13 +696,13 @@
 
   FIXME: The number '35' below should be calculated from tile width.
 **************************************************************************/
-static void tile_list_select(int new_index)
+static void tile_list2_select(int new_index)
 {
   int i;
-  tile_list.selected = new_index;
+  tile_list2.selected = new_index;
 
-  for (i = 0; i < tile_list.items; i++) {
-    struct tile_list_item *item = &tile_list.item[i];
+  for (i = 0; i < tile_list2.items; i++) {
+    struct tile_list2_item *item = &tile_list2.item[i];
     struct osda *osda = i == new_index ? item->selected : item->unselected;
     struct osda *background_faces[4];
     int j;
@@ -715,7 +721,7 @@
     sw_widget_set_position(item->button, detaildisplay_pos.x + i * 35,
                            detaildisplay_pos.y);
     sw_button_set_callback(item->button,
-                          tile_list_select_callback, (void *)i);
+                          tile_list2_select_callback, (void *)i);
     sw_widget_set_tooltip(item->button,
                          ct_tooltip_clone1(tooltip_template,
                                            item->tooltip));
@@ -727,7 +733,7 @@
 /**************************************************************************
   ...
 **************************************************************************/
-static void update_focus_tile_list(void)
+static void update_focus_tile_list2(void)
 {
   int i;
   struct tile *ptile;
@@ -742,19 +748,19 @@
     }
   } unit_list_iterate_end;
 
-  for (i = 0; i < tile_list.items; i++) {
-    sw_widget_destroy(tile_list.item[i].button);
-    be_free_osda(tile_list.item[i].selected);
-    be_free_osda(tile_list.item[i].unselected);
+  for (i = 0; i < tile_list2.items; i++) {
+    sw_widget_destroy(tile_list2.item[i].button);
+    be_free_osda(tile_list2.item[i].selected);
+    be_free_osda(tile_list2.item[i].unselected);
   }
 
-  tile_list.items = 0;
-  tile_list.selected = -1;
+  tile_list2.items = 0;
+  tile_list2.selected = -1;
 
   {
-    struct tile_list_item *item = &tile_list.item[tile_list.items];
+    struct tile_list2_item *item = &tile_list2.item[tile_list2.items];
 
-    tile_list.items++;
+    tile_list2.items++;
 
     item->type = TLI_TERRAIN;
     item->unselected = terrain_to_osda(ptile);
@@ -766,9 +772,9 @@
 
   if (map_get_city(ptile)) {
     struct city *pcity=map_get_city(ptile);
-    struct tile_list_item *item = &tile_list.item[tile_list.items];
+    struct tile_list2_item *item = &tile_list2.item[tile_list2.items];
 
-    tile_list.items++;
+    tile_list2.items++;
 
     item->type = TLI_CITY;
     item->unselected = city_to_osda(pcity);
@@ -780,9 +786,9 @@
   }
 
   unit_list_iterate(ptile->units, punit) {
-    struct tile_list_item *item = &tile_list.item[tile_list.items];
+    struct tile_list2_item *item = &tile_list2.item[tile_list2.items];
 
-    tile_list.items++;
+    tile_list2.items++;
 
     item->type = TLI_UNIT;
     item->unselected = unit_to_osda(punit);
@@ -794,11 +800,11 @@
     item->info_text = mystrdup(mapview_get_unit_info_text(punit));
   } unit_list_iterate_end;
 
-  if (tile_list.items > 1) {
+  if (tile_list2.items > 1) {
     /* Take the city or unit */
-    tile_list_select(1);
+    tile_list2_select(1);
   } else {
-    tile_list_select(0);
+    tile_list2_select(0);
   }
 }
 
@@ -831,7 +837,7 @@
 
   if (button == BE_MB_LEFT) {
     set_focus_tile(ptile);
-    update_focus_tile_list();
+    update_focus_tile_list2();
   } else if (button == BE_MB_MIDDLE) {
     //popit(ev, xtile, ytile);
   } else if (button == BE_MB_RIGHT) {
@@ -1165,6 +1171,12 @@
             && max_size <= MAX_CITY_SIZE);
       assert(border_width >= 0 && border_width <= 1);
 
+      /* HACK */
+      if (i == 0) {
+       text_templates[FONT_CITY_NAME] = name;
+       text_templates[FONT_CITY_PROD] = prod;
+      }
+
       city_descr_styles.style[city_descr_styles.styles].min_size = min_size;
       city_descr_styles.style[city_descr_styles.styles].max_size = max_size;
       city_descr_styles.style[city_descr_styles.styles].border_width =
@@ -1215,7 +1227,7 @@
              game.player_ptr->economic.science);
       return buffer;
   } else if (strcmp(id, "focus_item") == 0) {
-      return tile_list.item[tile_list.selected].info_text;
+      return tile_list2.item[tile_list2.selected].info_text;
 #if 0      
       my_snprintf(buffer, sizeof(buffer),
                  _("Population: %s "
@@ -1277,7 +1289,7 @@
 
   read_properties();
 
-  tile_list.items = 0;
+  tile_list2.items = 0;
   drag_timer = new_timer(TIMER_USER, TIMER_ACTIVE);
 }
 
@@ -1375,7 +1387,7 @@
 **************************************************************************/
 static void fill_actions(void)
 {
-  struct tile_list_item *item = &tile_list.item[tile_list.selected];  
+  struct tile_list2_item *item = &tile_list2.item[tile_list2.selected];  
 
   actions_shown.actions = 0;
 
@@ -1620,9 +1632,9 @@
   focus_tile = ptile;
 
   if (old) {
-    refresh_tile_mapcanvas(old, TRUE);
+      refresh_tile_mapcanvas(old, FALSE, TRUE);
   }
-  refresh_tile_mapcanvas(focus_tile, TRUE);
+  refresh_tile_mapcanvas(focus_tile, FALSE, TRUE);
 }
 
 /****************************************************************************
@@ -1635,7 +1647,7 @@
   focus_tile = NULL;
 
   if (map_exists() && old) {
-    refresh_tile_mapcanvas(old, TRUE);
+      refresh_tile_mapcanvas(old, FALSE, TRUE);
   }
 }
 
@@ -1646,3 +1658,51 @@
 {
   return focus_tile;
 }
+
+/****************************************************************************
+  Return the size of the given text in the given font.  This size should
+  include the ascent and descent of the text.  Either of width or height
+  may be NULL in which case those values simply shouldn't be filled out.
+****************************************************************************/
+void get_text_size(int *width, int *height,
+                  enum client_font font, const char *text)
+{
+  struct ct_size size;
+  struct ct_string *string = ct_string_clone3(text_templates[font], text);
+
+  be_string_get_size(&size, string);
+
+  if (width) {
+    *width = size.width;
+  }
+  if (height) {
+    *height = size.height;
+  }
+}
+
+/****************************************************************************
+  Draw the text onto the canvas in the given color and font.  The canvas
+  position does not account for the ascent of the text; this function must
+  take care of this manually.  The text will not be NULL but may be empty.
+****************************************************************************/
+void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
+                    enum client_font font, enum color_std color,
+                    const char *text)
+{
+    struct ct_point position={canvas_x, canvas_y};
+    struct ct_string *string=ct_string_clone4(text_templates[font],
+                                             text,color);
+    tr_draw_string(pcanvas->osda,&position,string);
+    ct_string_destroy(string);
+}
+
+/****************************************************************************
+  Called by the tileset code to set the font size that should be used to
+  draw the city names and productions.
+****************************************************************************/
+void set_city_names_font_sizes(int my_city_names_font_size,
+                              int my_city_productions_font_size)
+{
+  freelog(LOG_ERROR, "Ignore set_city_names_font_sizes call.");
+  /* PORTME */
+}
Index: client/gui-ftwl/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/pages.c,v
retrieving revision 1.3
diff -u -u -r1.3 pages.c
--- client/gui-ftwl/pages.c     5 Feb 2005 07:15:36 -0000       1.3
+++ client/gui-ftwl/pages.c     22 Mar 2005 19:50:05 -0000
@@ -18,20 +18,9 @@
 #include "pages.h"
 
 /**************************************************************************
-  Sets the "page" that the client should show.  See documentation in
-  pages_g.h.
+  Does a toplevel window page transition.
 **************************************************************************/
 void set_client_page(enum client_pages page)
 {
   /* PORTME */
 }
-
-/****************************************************************************
-  Set the list of available rulesets.  The default ruleset should be
-  "default", and if the user changes this then set_ruleset() should be
-  called.
-****************************************************************************/
-void gui_set_rulesets(char rulesets[][64], int ruleset_count)
-{
-  /* PORTME */
-}
Index: utility/ftwl/be_common_24.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/be_common_24.c,v
retrieving revision 1.6
diff -u -u -r1.6 be_common_24.c
--- utility/ftwl/be_common_24.c 9 Oct 2004 11:59:38 -0000       1.6
+++ utility/ftwl/be_common_24.c 22 Mar 2005 19:50:14 -0000
@@ -28,7 +28,8 @@
 #include <ft2build.h>
 #include FT_FREETYPE_H
 
-#define DISABLE_TRANSPARENCY 0
+#define ENABLE_TRANSPARENCY    1
+#define DO_CYCLE_MEASUREMENTS  0
 
 /* Blend the RGB values of two pixel 3-byte pixel arrays
  * based on a source alpha value. */
@@ -68,34 +69,57 @@
   MIN_OPACITY means the pixel should not be drawn.  MAX_OPACITY means
   the pixels should not be blended.
 *************************************************************************/
-static void image_blit_masked_trans(const struct ct_size *size,
-                                   const struct image *src,
-                                   const struct ct_point *src_pos,
-                                   struct image *dest,
-                                   const struct ct_point *dest_pos)
+/* non static to prevent inlining */
+void image_blit_masked_trans(const struct ct_size *size,
+                            const struct image *src,
+                            const struct ct_point *src_pos,
+                            struct image *dest,
+                            const struct ct_point *dest_pos);
+void image_blit_masked_trans(const struct ct_size *size,
+                            const struct image *src,
+                            const struct ct_point *src_pos,
+                            struct image *dest,
+                            const struct ct_point *dest_pos)
 {
   int x, y;
 
-  for (y = 0; y < size->height; y++) {
-    for (x = 0; x < size->width; x++) {
-      int src_x = x + src_pos->x;
-      int src_y = y + src_pos->y;
-      int dest_x = x + dest_pos->x;
-      int dest_y = y + dest_pos->y;
-      unsigned char *psrc = IMAGE_GET_ADDRESS(src, src_x, src_y);
-      unsigned char *pdest = IMAGE_GET_ADDRESS(dest, dest_x, dest_y);
+  unsigned char *psrc = IMAGE_GET_ADDRESS(src, src_pos->x,
+                                         src_pos->y);
+  unsigned char *pdest = IMAGE_GET_ADDRESS(dest, dest_pos->x,
+                                          dest_pos->y);
+  int w = size->width;
+  int h = size->height;
+  int extra_src = (src->width - size->width) * 4;
+  int extra_dest = (dest->width - size->width) * 4;
+
+  //printf("BLITTING %dx%d",size->width,size->height);
+
+  for (y = h; y > 0; y--) {
+    for (x = w; x > 0; x--) {
       unsigned char mask_value = psrc[3];
 
-      IMAGE_CHECK(src, src_x, src_y);
-      if (mask_value != MIN_OPACITY
-          && mask_value != MAX_OPACITY
-          && !DISABLE_TRANSPARENCY) {
-        /* We need to perform transparency */
-        ALPHA_BLEND(pdest, psrc[3], psrc);
-      } else if (mask_value != MIN_OPACITY) {
-        memcpy(pdest, psrc, 4);
-      } /* never copy MAX_OPACITY pixels - that is why they exist! */
+#if ENABLE_TRANSPARENCY
+      if(mask_value == MAX_OPACITY) {
+       memcpy(pdest, psrc, 4);
+      } else if(mask_value == MIN_OPACITY) {
+       /* 
+        * Empty since we never copy MAX_OPACITY pixels - that is why
+        * they exist! 
+        */
+      } else {
+       /* We need to perform transparency */
+       ALPHA_BLEND(pdest, psrc[3], psrc);
+      }
+#else
+      if (mask_value != MIN_OPACITY) {
+       memcpy(pdest, psrc, 4);
+      }
+#endif
+      psrc += 4;
+      pdest += 4;
     }
+    psrc += extra_src;
+    pdest += extra_dest;
   }
 }
 
@@ -155,8 +179,31 @@
 
   clip_two_regions(dest, src, &real_size, &real_dest_pos, &real_src_pos);
 
-  image_blit_masked_trans(&real_size, src, &real_src_pos, dest,
-                          &real_dest_pos);
+  if (DO_CYCLE_MEASUREMENTS) {
+#define rdtscll(val) __asm__ __volatile__ ("rdtsc" : "=A" (val))
+    unsigned long long start, end;
+    static unsigned long long total_clocks = 0, total_pixels = 0;
+    static int total_blits = 0;
+
+    rdtscll(start);
+
+    image_blit_masked_trans(&real_size, src, &real_src_pos, dest,
+                           &real_dest_pos);
+
+    rdtscll(end);
+    printf("BLITTING %dx%d %dx%d->%dx%d %lld %d\n", real_size.width,
+          real_size.height, src->width, src->height, dest->width, dest->height,
+          end - start, real_size.width * real_size.height);
+    total_clocks += (end - start);
+    total_pixels += (real_size.width * real_size.height);
+    total_blits++;
+    if ((total_blits % 1000) == 0) {
+      printf("%f cycles per pixel\n", (float) total_clocks / total_pixels);
+    }
+  } else {
+    image_blit_masked_trans(&real_size, src, &real_src_pos, dest,
+                           &real_dest_pos);
+  }
 }
 
 /*************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12591) Make FTWL compile and run again, Raimar Falke <=