Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8760) nation flags
Home

[Freeciv-Dev] (PR#8760) nation flags

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8760) nation flags
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 22 May 2004 02:43:27 -0700
Reply-to: rt@xxxxxxxxxxx

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

> [jdorje - Mon May 17 18:52:20 2004]:

> So I've written a patch that implements the solution I suggested long 
> ago.  Tileset specfiles can include PNG files directly, one file per 
> tag, without the need for a grid.  That is instead of

Here's an updated patch.

This includes only the code changes.  This isn't of much use without the
data changes; you can't even test it.  Of course the data changes are
still included in the previous patch.  Sort of.

jason

? convert.sh
? eff
? flags
? spec.diff
? data/flags
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.169
diff -u -r1.169 tilespec.c
--- client/tilespec.c   21 May 2004 18:45:45 -0000      1.169
+++ client/tilespec.c   22 May 2004 09:41:58 -0000
@@ -137,8 +137,14 @@
  */
 struct small_sprite {
   int ref_count;
-  int x, y, width, height;
+
+  /* The sprite is in this file. */
+  char *file;
+
+  /* Or, the sprite is in this file at the location. */
   struct specfile *sf;
+  int x, y, width, height;
+
   struct Sprite *sprite;
 };
 
@@ -430,13 +436,39 @@
   tilespec_reread(option->p_string_value);
 }
 
+static struct Sprite *load_gfx_file(const char *gfx_filename)
+{
+  const char **gfx_fileexts = gfx_fileextensions(), *gfx_fileext;
+  struct Sprite *s;
+
+  /* Try out all supported file extensions to find one that works. */
+  while ((gfx_fileext = *gfx_fileexts++)) {
+    char *real_full_name;
+    char full_name[strlen(gfx_filename) + strlen(gfx_fileext) + 2];
+
+    sprintf(full_name, "%s.%s", gfx_filename, gfx_fileext);
+    if ((real_full_name = datafilename(full_name))) {
+      freelog(LOG_DEBUG, "trying to load gfx file %s", real_full_name);
+      s = load_gfxfile(real_full_name);
+      if (!s) {
+       freelog(LOG_VERBOSE, "loading the gfx file %s failed",
+               real_full_name);
+      } else {
+       return s;
+      }
+    }
+  }
+
+  return NULL;
+}
+
 /**************************************************************************
   Ensure that the big sprite of the given spec file is loaded.
 **************************************************************************/
 static void ensure_big_sprite(struct specfile *sf)
 {
   struct section_file the_file, *file = &the_file;
-  const char *gfx_filename, *gfx_current_fileext, **gfx_fileexts;
+  const char *gfx_filename;
 
   if (sf->big_sprite) {
     /* Looks like it's already loaded. */
@@ -456,26 +488,9 @@
     exit(EXIT_FAILURE);
   }
 
-  gfx_fileexts = gfx_fileextensions();
   gfx_filename = secfile_lookup_str(file, "file.gfx");
 
-  /* Try out all supported file extensions to find one that works. */
-  while (!sf->big_sprite && (gfx_current_fileext = *gfx_fileexts++)) {
-    char *real_full_name;
-    char *full_name =
-       fc_malloc(strlen(gfx_filename) + strlen(gfx_current_fileext) + 2);
-    sprintf(full_name, "%s.%s", gfx_filename, gfx_current_fileext);
-
-    if ((real_full_name = datafilename(full_name))) {
-      freelog(LOG_DEBUG, "trying to load gfx file %s", real_full_name);
-      sf->big_sprite = load_gfxfile(real_full_name);
-      if (!sf->big_sprite) {
-       freelog(LOG_VERBOSE, "loading the gfx file %s failed",
-               real_full_name);
-      }
-    }
-    free(full_name);
-  }
+  sf->big_sprite = load_gfx_file(gfx_filename);
 
   if (!sf->big_sprite) {
     freelog(LOG_FATAL, _("Couldn't load gfx file for the spec file %s"),
@@ -507,13 +522,8 @@
 
   /* currently unused */
   (void) section_file_lookup(file, "info.artists");
-  (void) secfile_lookup_str(file, "file.gfx");
 
   gridnames = secfile_get_secnames_prefix(file, "grid_", &num_grids);
-  if (num_grids == 0) {
-    freelog(LOG_FATAL, "spec %s has no grid_* sections", sf->file_name);
-    exit(EXIT_FAILURE);
-  }
 
   for (i = 0; i < num_grids; i++) {
     int j, k;
@@ -555,6 +565,7 @@
       y1 = y_top_left + (dy + pixel_border) * row;
 
       ss->ref_count = 0;
+      ss->file = NULL;
       ss->x = x1;
       ss->y = y1;
       ss->width = dx;
@@ -583,6 +594,37 @@
   free(gridnames);
   gridnames = NULL;
 
+  i = -1;
+  while (secfile_lookup_str_default(file, NULL, "extra.sprites%d.tag", ++i)) {
+    struct small_sprite *ss = fc_malloc(sizeof(*ss));
+    char **tags;
+    char *filename;
+    int num_tags, k;
+
+    tags
+      = secfile_lookup_str_vec(file, &num_tags, "extra.sprites%d.tag", i);
+    filename = secfile_lookup_str(file, "extra.sprites%d.file", i);
+
+    ss->ref_count = 0;
+    ss->file = mystrdup(filename);
+    ss->sf = NULL;
+    ss->sprite = NULL;
+
+    small_sprite_list_insert(&sf->small_sprites, ss);
+
+    if (!duplicates_ok) {
+      for (k = 0; k < num_tags; k++) {
+       if (!hash_insert(sprite_hash, mystrdup(tags[k]), ss)) {
+         freelog(LOG_ERROR, "warning: already have a sprite for %s", tags[k]);
+       }
+      }
+    } else {
+      for (k = 0; k < num_tags; k++) {
+       (void) hash_replace(sprite_hash, mystrdup(tags[k]), ss);
+      }
+    }
+  }
+
   section_file_check_unused(file, sf->file_name);
   section_file_free(file);
 }
@@ -2547,6 +2589,9 @@
 
   small_sprite_list_iterate(small_sprites, ss) {
     small_sprite_list_unlink(&small_sprites, ss);
+    if (ss->file) {
+      free(ss->file);
+    }
     assert(ss->sprite == NULL);
     free(ss);
   } small_sprite_list_iterate_end;
@@ -2601,10 +2646,19 @@
   if (!ss->sprite) {
     /* If the sprite hasn't been loaded already, then load it. */
     assert(ss->ref_count == 0);
-    ensure_big_sprite(ss->sf);
-    ss->sprite =
-      crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width, ss->height,
-                 NULL, -1, -1);
+    if (ss->file) {
+      ss->sprite = load_gfx_file(ss->file);
+      if (!ss->sprite) {
+       freelog(LOG_FATAL, _("Couldn't load gfx file %s for sprite %s"),
+               ss->file, tag_name);
+       exit(EXIT_FAILURE);
+      }
+    } else {
+      ensure_big_sprite(ss->sf);
+      ss->sprite =
+       crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width, ss->height,
+                   NULL, -1, -1);
+    }
   }
 
   /* Track the reference count so we know when to free the sprite. */

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