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: Mon, 17 May 2004 11:52:21 -0700
Reply-to: rt@xxxxxxxxxxx

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

Again we have a buildup of new nation rulesets.

As discused extensively before, the problem with adding new rulesets is 
that you have to add a flag.  This flag is usually in its own graphics 
file, but the current data structure means it has to be integrated into 
the flags.png file.  And this is ugly because the ruleset author 
probably isn't a tileset author and doesn't know much about editing such 
files.

This is better than it used to be, because at least now we only have one 
flags.png.  But it's still a problem.

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

   [file]
   gfx = "misc/flags"

   [grid_main]

   x_top_left = 0
   y_top_left = 0
   dx = 30
   dy = 30

   tiles = { "row", "column", "tag"
     0,  0, "f.italy"
     0,  1, "f.iraq_old"
     ; ... etc. ...
   }

we would have

   [extra]
   sprites = {"tag", "file"
     "f.italy", "flags/italy"
     "f.iraq_old", "flags/iraq_old"
     ; ... etc. ...
   }

and then the flags would be put into (for instance) data/flags/italy.png.

There is some question of where these files should go.  The original 
design suggested a new "graphics" directory to hold all graphics 
(graphics/flags)?  Or maybe they should go into the existing misc 
directory (misc/flags)?  Or maybe just into their own new directory 
(flags)?  This isn't a big deal except inasmuch as it's hard to move the 
files around later.  Note that bigger tilesets (128x64) may not be able 
to effectively use the existing flags.

The attached patch includes the code changes needed to have the 
extra.sprites functionality above.  In addition to get it to work we 
will have to:

- Copy data/graphics/trident/flags/*.png into data/flags.
- Rename these files with s/^f.//.
- Create some new Makefile.am files.

jason

? eff
? flags
? data/diff
? data/flags
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.167
diff -u -r1.167 tilespec.c
--- client/tilespec.c   5 May 2004 20:39:15 -0000       1.167
+++ client/tilespec.c   17 May 2004 18:45:39 -0000
@@ -138,8 +138,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;
 };
 
@@ -431,13 +437,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. */
@@ -457,26 +489,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"),
@@ -508,13 +523,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;
@@ -556,6 +566,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;
@@ -584,6 +595,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);
 }
@@ -2549,6 +2591,9 @@
   specfile_list_iterate(specfiles, sf) {
     small_sprite_list_iterate(sf->small_sprites, ss) {
       small_sprite_list_unlink(&sf->small_sprites, ss);
+      if (ss->file) {
+       free(ss->file);
+      }
       assert(ss->sprite == NULL);
       free(ss);
     } small_sprite_list_iterate_end;
@@ -2602,10 +2647,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. */
Index: data/misc/flags.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/flags.spec,v
retrieving revision 1.1
diff -u -r1.1 flags.spec
--- data/misc/flags.spec        27 Feb 2004 00:14:01 -0000      1.1
+++ data/misc/flags.spec        17 May 2004 18:45:42 -0000
@@ -18,98 +18,89 @@
     Jan Heidefuss <jan_heidefuss@xxxxxxxx> (Bavarian)
     Ivan kosak <ivan.kosak@xxxxxxxxx> (Croatia,Slovenia,Serbia)
 "
-
-[file]
-gfx = "misc/flags"
-
-[grid_main]
-
-x_top_left = 0
-y_top_left = 0
-dx = 30
-dy = 30
-
-tiles = { "row", "column", "tag"
-  0,  0, "f.italy"
-  0,  1, "f.iraq_old"
-  0,  2, "f.germany"
-  0,  3, "f.egypt"
-  0,  4, "f.usa"
-  0,  5, "f.greece"
-  0,  6, "f.india"
-  0,  7, "f.russia"
-  0,  8, "f.rwanda"       ; for Zulu
-  0,  9, "f.france"
-  0, 10, "f.mexico"
-  0, 11, "f.china"
-  0, 12, "f.united_kingdom"
-  0, 13, "f.mongolia"
-  1,  0, "f.denmark"
-  1,  1, "f.australia"
-  1,  2, "f.brasil"
-  1,  3, "f.soviet"
-  1,  4, "f.japan"
-  1,  5, "f.spain"
-  1,  6, "f.finland"
-  1,  7, "f.hungary"
-  1,  8, "f.poland"
-  1,  9, "f.iran"
-  1, 10, "f.peru"
-  1, 11, "f.turkey"
-  1, 12, "f.tunisia"
-  1, 13, "f.arab"         ; Saudi Arabia
-  2,  0, "f.south_africa" ; Republic of South Africa, for Zulus
-  2,  1, "f.sweden"
-  2,  2, "f.netherlands", 
-        "f.holland"      ; backward compatibility
-  2,  3, "f.syria"
-  2,  4, "f.macedonia"
-  2,  5, "f.ukraine"
-  2,  6, "f.cheyenne"
-  2,  7, "f.norway"
-  2,  8, "f.portugal"
-  2,  9, "f.czech"
-  2, 10, "f.england"
-  2, 11, "f.scotland"
-  2, 12, "f.unknown"      ; useful for alternates
-  2, 13, "f.barbarian"
-  3,  0, "f.europe"
-  3,  1, "f.canada"
-  3,  2, "f.korea"
-  3,  3, "f.israel"
-  3,  4, "f.ireland"
-  3,  5, "f.belgium"
-  3,  6, "f.iceland"
-  3,  7, "f.pakistan"
-  3,  8, "f.greenland"
-  3,  9, "f.austria"
-  3, 10, "f.argentina"
-  3, 11, "f.united_nations"
-  3, 12, "f.nato"
-  3, 13, "f.vietnam"
-  4,  0, "f.thailand"
-  4,  1, "f.olympic"
-  4,  2, "f.krev"
-  4,  3, "f.wales"
-  4,  4, "f.lithuania"
-  4,  5, "f.kenya"
-  4,  6, "f.dunedain"
-  4,  7, "f.bulgaria"
-  4,  8, "f.armenia"
-  4,  9, "f.azerbaijan"
-  4, 10, "f.boer"         ; old south african
-  4, 11, "f.mordor"
-  4, 12, "f.bavarian"
-  4, 13, "f.rome"         ; Roman republic flag
-  5,  0, "f.cornwall"
-  5,  1, "f.philippines"
-  5,  2, "f.estonia"
-  5,  3, "f.latvia"
-  5,  4, "f.silesia"
-  5,  5, "f.singapore"
-  5,  6, "f.chile"
-  5,  7, "f.catalan"
-  5,  8, "f.croatia"
-  5,  9, "f.slovenia"
-  5, 10, "f.serbia"
-}
+[extra]
+sprites =
+       {       "tag", "file"
+               "f.arab", "flags/arab"                  ; Saudi Arabia
+               "f.argentina", "flags/argentina"
+               "f.armenia", "flags/armenia"
+               "f.australia", "flags/australia"
+               "f.austria", "flags/austria"
+               "f.azerbaijan", "flags/azerbaijan"
+               "f.barbarian", "flags/barbarian"
+               "f.bavarian", "flags/bavarian"
+               "f.belgium", "flags/belgium"
+               "f.boer", "flags/boer"                  ; old south african
+               "f.brasil", "flags/brasil"
+               "f.bulgaria", "flags/bulgaria"
+               "f.canada", "flags/canada"
+               "f.catalan", "flags/catalan"
+               "f.cheyenne", "flags/cheyenne"
+               "f.chile", "flags/chile"
+               "f.china", "flags/china"
+               "f.cornwall", "flags/cornwall"
+               "f.croatia", "flags/croatia"
+               "f.czech", "flags/czech"
+               "f.denmark", "flags/denmark"
+               "f.dunedain", "flags/dunedain"
+               "f.egypt", "flags/egypt"
+               "f.england", "flags/england"
+               "f.estonia", "flags/estonia"
+               "f.europe", "flags/europe"
+               "f.finland", "flags/finland"
+               "f.france", "flags/france"
+               "f.germany", "flags/germany"
+               "f.greece", "flags/greece"
+               "f.greenland", "flags/greenland"
+               "f.holland", "flags/netherlands"        ; backward compatabiliy
+               "f.hungary", "flags/hungary"
+               "f.iceland", "flags/iceland"
+               "f.india", "flags/india"
+               "f.iran", "flags/iran"
+               "f.iraq_old", "flags/iraq_old"
+               "f.ireland", "flags/ireland"
+               "f.israel", "flags/israel"
+               "f.italy", "flags/italy"
+               "f.japan", "flags/japan"
+               "f.kenya", "flags/kenya"
+               "f.korea", "flags/korea"
+               "f.krev", "flags/krev"
+               "f.latvia", "flags/latvia"
+               "f.lithuania", "flags/lithuania"
+               "f.macedonia", "flags/macedonia"
+               "f.mexico", "flags/mexico"
+               "f.mongolia", "flags/mongolia"
+               "f.mordor", "flags/mordor"
+               "f.nato", "flags/nato"
+               "f.netherlands", "flags/netherlands"
+               "f.norway", "flags/norway"
+               "f.olympic", "flags/olympic"
+               "f.pakistan", "flags/pakistan"
+               "f.peru", "flags/peru"
+               "f.philippines", "flags/philippines"
+               "f.poland", "flags/poland"
+               "f.portugal", "flags/portugal"
+               "f.rome", "flags/rome"                  ; Roman republic flag
+               "f.russia", "flags/russia"
+               "f.rwanda", "flags/rwanda"              ; Alternate Zulu
+               "f.scotland", "flags/scotland"
+               "f.serbia", "flags/serbia"
+               "f.silesia", "flags/silesia"
+               "f.singapore", "flags/singapore"
+               "f.slovenia", "flags/slovenia"
+               "f.south_africa", "flags/south_africa"  ; for Zulus
+               "f.soviet", "flags/soviet"
+               "f.spain", "flags/spain"
+               "f.sweden", "flags/sweden"
+               "f.syria", "flags/syria"
+               "f.thailand", "flags/thailand"
+               "f.tunisia", "flags/tunisia"
+               "f.turkey", "flags/turkey"
+               "f.ukraine", "flags/ukraine"
+               "f.united_kingdom", "flags/united_kingdom"
+               "f.united_nations", "flags/united_nations"
+               "f.unknown", "flags/unknown"            ; useful for alternates
+               "f.usa", "flags/usa"
+               "f.vietnam", "flags/vietnam"
+               "f.wales", "flags/wales"
+       }

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