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, 29 May 2004 01:31:22 -0700
Reply-to: rt@xxxxxxxxxxx

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

Here is an updated patch.  I believe the code is ready for inclusion;
please review it.  The data portion of the diff is also included. 
However you still have to move the graphics files as described earlier
in the ticket.

jason

? diff
? ferries
? flags
? data/flags
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.170
diff -u -r1.170 tilespec.c
--- client/tilespec.c   22 May 2004 18:12:21 -0000      1.170
+++ client/tilespec.c   29 May 2004 08:28:46 -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;
 };
 
@@ -428,12 +434,40 @@
 }
 
 /**************************************************************************
+  Loads the given graphics file (found in the data path) into a newly
+  allocated sprite.
+**************************************************************************/
+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) {
+       return s;
+      }
+    }
+  }
+
+  freelog(LOG_VERBOSE, "Could not load gfx file %s.", gfx_filename);
+  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. */
@@ -453,26 +487,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"),
@@ -504,13 +521,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;
@@ -552,6 +564,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;
@@ -580,6 +593,38 @@
   free(gridnames);
   gridnames = NULL;
 
+  /* Load "extra" sprites.  Each sprite is one file. */
+  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(&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);
 }
@@ -2544,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;
@@ -2598,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. */
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        29 May 2004 08:28:46 -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]