rnd-20061030-2-src
authorHolger Schemel <info@artsoft.org>
Mon, 30 Oct 2006 10:19:57 +0000 (11:19 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:53:38 +0000 (10:53 +0200)
src/conftime.h
src/libgame/misc.c
src/libgame/misc.h
src/libgame/setup.c

index d52d0e34fe45539c7da35bd383481a022c60c11b..c5080b7a04308377e455916f15aee7c896cd0f09 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2006-10-29 20:25]"
+#define COMPILE_DATE_STRING "[2006-10-30 11:14]"
index 3bbf74a75ad58af039a922e253a342f81aa523d4..0115b5d9fb95f3ca633032656bcb0673138a62f0 100644 (file)
@@ -498,36 +498,45 @@ char *getBasePath(char *filename)
 /* various string functions                                                  */
 /* ------------------------------------------------------------------------- */
 
-char *getPath2(char *path1, char *path2)
+char *getStringCat2WithSeparator(char *s1, char *s2, char *sep)
 {
-  char *sep = STRING_PATH_SEPARATOR;
-  char *complete_path = checked_malloc(strlen(path1) + 1 +
-                                      strlen(path2) + 1);
+  char *complete_string = checked_malloc(strlen(s1) + strlen(sep) +
+                                        strlen(s2) + 1);
 
-  sprintf(complete_path, "%s%s%s", path1, sep, path2);
+  sprintf(complete_string, "%s%s%s", s1, sep, s2);
 
-  return complete_path;
+  return complete_string;
 }
 
-char *getPath3(char *path1, char *path2, char *path3)
+char *getStringCat3WithSeparator(char *s1, char *s2, char *s3, char *sep)
 {
-  char *sep = STRING_PATH_SEPARATOR;
-  char *complete_path = checked_malloc(strlen(path1) + 1 +
-                                      strlen(path2) + 1 +
-                                      strlen(path3) + 1);
+  char *complete_string = checked_malloc(strlen(s1) + strlen(sep) +
+                                        strlen(s2) + strlen(sep) +
+                                        strlen(s3) + 1);
 
-  sprintf(complete_path, "%s%s%s%s%s", path1, sep, path2, sep, path3);
+  sprintf(complete_string, "%s%s%s%s%s", s1, sep, s2, sep, s3);
 
-  return complete_path;
+  return complete_string;
 }
 
 char *getStringCat2(char *s1, char *s2)
 {
-  char *complete_string = checked_malloc(strlen(s1) + strlen(s2) + 1);
+  return getStringCat2WithSeparator(s1, s2, "");
+}
+
+char *getStringCat3(char *s1, char *s2, char *s3)
+{
+  return getStringCat3WithSeparator(s1, s2, s3, "");
+}
 
-  sprintf(complete_string, "%s%s", s1, s2);
+char *getPath2(char *path1, char *path2)
+{
+  return getStringCat2WithSeparator(path1, path2, STRING_PATH_SEPARATOR);
+}
 
-  return complete_string;
+char *getPath3(char *path1, char *path2, char *path3)
+{
+  return getStringCat3WithSeparator(path1, path2, path3, STRING_PATH_SEPARATOR);
 }
 
 char *getStringCopy(char *s)
index 009350c025afb7eb9c1823f29bf8c0759a110c7e..a42a75846b8184ab05aceb5f816e7fde42d4ceda 100644 (file)
@@ -94,9 +94,12 @@ char *getBasePath(char *);
 char *getBaseName(char *);
 char *getBaseNamePtr(char *);
 
+char *getStringCat2WithSeparator(char *, char *, char *);
+char *getStringCat3WithSeparator(char *, char *, char *, char *);
+char *getStringCat2(char *, char *);
+char *getStringCat3(char *, char *, char *);
 char *getPath2(char *, char *);
 char *getPath3(char *, char *, char*);
-char *getStringCat2(char *, char *);
 char *getStringCopy(char *);
 char *getStringToLower(char *);
 void setString(char **, char *);
index d599d1c794c0082a0715aeb9fc42a3f1a11b07ff..cb3b73f18611b40b131bcfe9ef71097f85467454 100644 (file)
@@ -1810,6 +1810,24 @@ static struct TokenInfo levelinfo_tokens[] =
   { TYPE_BOOLEAN,      &ldi.skip_levels,       "skip_levels"           }
 };
 
+static struct TokenInfo artworkinfo_tokens[] =
+{
+  /* artwork directory info */
+  { TYPE_STRING,       &ldi.identifier,        "identifier"            },
+  { TYPE_STRING,       &ldi.subdir,            "subdir"                },
+  { TYPE_STRING,       &ldi.name,              "name"                  },
+  { TYPE_STRING,       &ldi.name_sorting,      "name_sorting"          },
+  { TYPE_STRING,       &ldi.author,            "author"                },
+  { TYPE_INTEGER,      &ldi.sort_priority,     "sort_priority"         },
+  { TYPE_STRING,       &ldi.basepath,          "basepath"              },
+  { TYPE_STRING,       &ldi.fullpath,          "fullpath"              },
+  { TYPE_BOOLEAN,      &ldi.in_user_dir,       "in_user_dir"           },
+  { TYPE_INTEGER,      &ldi.color,             "color"                 },
+  { TYPE_STRING,       &ldi.class_desc,        "class_desc"            },
+
+  { -1,                        NULL,                   NULL                    },
+};
+
 static void setTreeInfoToDefaults(TreeInfo *ti, int type)
 {
   ti->type = type;
@@ -2554,6 +2572,20 @@ static TreeInfo *getDummyArtworkInfo(int type)
 
 void LoadArtworkInfo()
 {
+#if 1
+  if (level_artwork_info_hash == NULL)
+  {
+    char *filename = getPath2(getSetupDir(), "test.conf");
+
+    level_artwork_info_hash = loadSetupFileHash(filename);
+
+    if (level_artwork_info_hash == NULL)
+      level_artwork_info_hash = newSetupFileHash();
+
+    free(filename);
+  }
+#endif
+
   DrawInitText("Looking for custom artwork:", 120, FC_GREEN);
 
   LoadArtworkInfoFromArtworkDir(&artwork.gfx_first, NULL,
@@ -2644,10 +2676,84 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
       char *path = getPath2(getLevelDirFromTreeInfo(level_node),
                            ARTWORK_DIRECTORY((*artwork_node)->type));
 
+#if 0
+      printf("::: looking in directory '%s' for '%s' ...\n",
+            path, ARTWORK_DIRECTORY((*artwork_node)->type));
+#endif
+
+#if 1
+      char *type_string = ARTWORK_DIRECTORY((*artwork_node)->type);
+      char *identifier = level_node->subdir;
+      char *type_identifier = getStringCat2WithSeparator(type_string,
+                                                        identifier, ".");
+      char *cache_entry = getHashEntry(level_artwork_info_hash,
+                                      type_identifier);
+      boolean cached = (cache_entry != NULL && strEqual(cache_entry, "true"));
+
+      if (cached)
+      {
+       int i;
+
+       printf("::: LOADING existing hash entry for '%s' ...\n",
+              identifier);
+
+       char *type_dir = ARTWORK_DIRECTORY((*artwork_node)->type);
+       TreeInfo *artwork_new = newTreeInfo();
+
+       setTreeInfoToDefaults(artwork_new, (*artwork_node)->type);
+
+       /* set all structure fields according to the token/value pairs */
+       ldi = *artwork_new;
+       for (i = 0; artworkinfo_tokens[i].type != -1; i++)
+       {
+         char *token = getStringCat3WithSeparator(type_dir, identifier,
+                                                  artworkinfo_tokens[i].text,
+                                                  ".");
+         char *value = getHashEntry(level_artwork_info_hash, token);
+
+         printf("::: - '%s' => '%s'\n", token, value);
+
+         setSetupInfo(artworkinfo_tokens, i, value);
+
+         /* check if cache entry for this item is invalid or incomplete */
+         if (value == NULL)
+         {
+           printf("::: - WARNING: cache entry '%s' invalid\n", token);
+
+           cached = FALSE;
+         }
+
+         checked_free(token);
+       }
+       *artwork_new = ldi;
+
+#if 0
+       if (artwork_new->name_sorting == NULL)
+       {
+         printf("::: BOOOM!\n");
+         exit(10);
+       }
+#endif
+
+       if (cached)
+         pushTreeInfo(artwork_node, artwork_new);
+       else
+         freeTreeInfo(artwork_new);
+      }
+
+      if (!cached)
+       LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,
+                                     (*artwork_node)->type);
+#else
       LoadArtworkInfoFromArtworkDir(artwork_node, NULL, path,
                                    (*artwork_node)->type);
+#endif
 
+#if 1
+      if (!cached && topnode_last != *artwork_node)
+#else
       if (topnode_last != *artwork_node)
+#endif
       {
        free((*artwork_node)->identifier);
        free((*artwork_node)->name);
@@ -2659,9 +2765,44 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node,
 
        (*artwork_node)->sort_priority = level_node->sort_priority;
        (*artwork_node)->color = LEVELCOLOR((*artwork_node));
+
+#if 1
+       {
+         int i;
+
+         printf("::: adding hash entry for set '%s' ...\n", type_identifier);
+
+         setHashEntry(level_artwork_info_hash, type_identifier, "true");
+
+         ldi = **artwork_node;
+         for (i = 0; artworkinfo_tokens[i].type != -1; i++)
+         {
+           char *token = getStringCat2WithSeparator(type_identifier,
+                                                    artworkinfo_tokens[i].text,
+                                                    ".");
+           char *value = getSetupValue(artworkinfo_tokens[i].type,
+                                       artworkinfo_tokens[i].value);
+           if (value != NULL)
+           {
+             setHashEntry(level_artwork_info_hash, token, value);
+
+             printf("::: - setting '%s' => '%s'\n\n",
+                    token, value);
+           }
+
+           if (strEqual(artworkinfo_tokens[i].text, "name_sorting"))
+             printf("::: - '%s' => '%s' => '%s'\n",
+                    identifier, token,
+                    (*artwork_node)->name_sorting);
+
+           checked_free(token);
+         }
+       }
+#endif
       }
 
       free(path);
+      free(type_identifier);
     }
 
     if (level_node->node_group != NULL)
@@ -2675,24 +2816,18 @@ void LoadLevelArtworkInfo()
 {
   DrawInitText("Looking for custom level artwork:", 120, FC_GREEN);
 
-#if 0
-  if (level_artwork_info_hash == NULL)
-  {
-    char *filename = getPath2(getSetupDir(), "test.conf");
+  LoadArtworkInfoFromLevelInfo(&artwork.gfx_first, leveldir_first_all);
+  LoadArtworkInfoFromLevelInfo(&artwork.snd_first, leveldir_first_all);
+  LoadArtworkInfoFromLevelInfo(&artwork.mus_first, leveldir_first_all);
 
-    level_artwork_info_hash = loadSetupFileHash(filename);
+#if 1
+  char *filename = getPath2(getSetupDir(), "test.conf");
 
-    if (level_artwork_info_hash == NULL)
-      level_artwork_info_hash = newSetupFileHash();
+  saveSetupFileHash(level_artwork_info_hash, filename);
 
-    free(filename);
-  }
+  free(filename);
 #endif
 
-  LoadArtworkInfoFromLevelInfo(&artwork.gfx_first, leveldir_first_all);
-  LoadArtworkInfoFromLevelInfo(&artwork.snd_first, leveldir_first_all);
-  LoadArtworkInfoFromLevelInfo(&artwork.mus_first, leveldir_first_all);
-
   /* needed for reloading level artwork not known at ealier stage */
 
   if (!strEqual(artwork.gfx_current_identifier, setup.graphics_set))
@@ -2832,6 +2967,9 @@ char *getSetupValue(int type, void *value)
       break;
 
     case TYPE_STRING:
+      if (*(char **)value == NULL)
+       return NULL;
+
       strcpy(value_string, *(char **)value);
       break;