rnd-20020903-1-src
authorHolger Schemel <info@artsoft.org>
Tue, 3 Sep 2002 19:23:59 +0000 (21:23 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:38:13 +0000 (10:38 +0200)
15 files changed:
src/conftime.h
src/game.c
src/init.c
src/libgame/image.c
src/libgame/image.h
src/libgame/misc.c
src/libgame/misc.h
src/libgame/setup.c
src/libgame/setup.h
src/libgame/sound.c
src/libgame/sound.h
src/libgame/system.h
src/libgame/types.h
src/main.c
src/main.h

index 74e0118a05928f6a0ac8f70aeee773e81657fe6c..45532d5fc0ae5259c560b7d4373f74292a55db82 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2002-08-25 02:44]"
+#define COMPILE_DATE_STRING "[2002-09-03 21:23]"
index bc31c194de0672b1a07164c40710502c6d7562ca..f64d25931c19c3860f4e13126d5532ccefb0703a 100644 (file)
@@ -153,7 +153,7 @@ static struct
   { NULL,              0,                      0 },
 };
 static int element_action_sound[NUM_LEVEL_ELEMENTS][NUM_SND_ACTIONS];
-static boolean is_loop_sound[NUM_SOUND_EFFECTS];
+static boolean is_loop_sound[NUM_SOUND_CONFIG_ENTRIES];
 
 #define IS_LOOP_SOUND(x)       (is_loop_sound[x])
 
@@ -507,7 +507,7 @@ void DrawGameDoorValues()
 
 void InitGameSound()
 {
-  int sound_effect_properties[NUM_SOUND_EFFECTS];
+  int sound_effect_properties[NUM_SOUND_CONFIG_ENTRIES];
   int i, j;
 
 #if 0
@@ -518,9 +518,9 @@ void InitGameSound()
     for (j=0; j<NUM_LEVEL_ELEMENTS; j++)
       element_action_sound[j][i] = -1;
 
-  for (i=0; i<NUM_SOUND_EFFECTS; i++)
+  for (i=0; i<NUM_SOUND_CONFIG_ENTRIES; i++)
   {
-    int len_effect_text = strlen(sound_effects[i].text);
+    int len_effect_text = strlen(sound_config[i].token);
 
     sound_effect_properties[i] = SND_ACTION_UNKNOWN;
     is_loop_sound[i] = FALSE;
@@ -533,7 +533,7 @@ void InitGameSound()
       int len_action_text = strlen(sound_action_properties[j].text);
 
       if (len_action_text < len_effect_text &&
-         strcmp(&sound_effects[i].text[len_effect_text - len_action_text],
+         strcmp(&sound_config[i].token[len_effect_text - len_action_text],
                 sound_action_properties[j].text) == 0)
       {
        sound_effect_properties[i] = sound_action_properties[j].value;
@@ -554,9 +554,9 @@ void InitGameSound()
        int len_class_text = strlen(element_info[j].sound_class_name);
 
        if (len_class_text + 1 < len_effect_text &&
-           strncmp(sound_effects[i].text,
+           strncmp(sound_config[i].token,
                    element_info[j].sound_class_name, len_class_text) == 0 &&
-           sound_effects[i].text[len_class_text] == '.')
+           sound_config[i].token[len_class_text] == '.')
        {
          int sound_action_value = sound_effect_properties[i];
 
@@ -6482,8 +6482,8 @@ boolean PlaceBomb(struct PlayerInfo *player)
 
 void PlaySoundLevel(int x, int y, int nr)
 {
-  static int loop_sound_frame[NUM_SOUND_EFFECTS];
-  static int loop_sound_volume[NUM_SOUND_EFFECTS];
+  static int loop_sound_frame[NUM_SOUND_CONFIG_ENTRIES];
+  static int loop_sound_volume[NUM_SOUND_CONFIG_ENTRIES];
   int sx = SCREENX(x), sy = SCREENY(y);
   int volume, stereo_position;
   int max_distance = 8;
index a06bd295bd99e5e53e82f37004be90b32498624e..53066410638a70567b0d43e9615353c4291bd3ef 100644 (file)
@@ -46,13 +46,15 @@ static void InitLevelInfo(void);
 static void InitArtworkInfo(void);
 static void InitLevelArtworkInfo(void);
 static void InitNetworkServer(void);
+static void InitImageConfig();
 static void InitMixer(void);
 static void InitSound(void);
 static void InitGfx(void);
 static void InitGfxBackground(void);
 static void InitGadgets(void);
-static void InitElementInfo(void);
 static void InitElementProperties(void);
+static void InitElementInfo(void);
+static void InitGraphicInfo(void);
 static void Execute_Debug_Command(char *);
 
 void OpenAll(void)
@@ -85,6 +87,7 @@ void OpenAll(void)
   InitArtworkInfo();           /* needed before loading gfx, sound & music */
 
   InitCounter();
+  InitImageConfig();
   InitMixer();
   InitJoysticks();
   InitRND(NEW_RANDOMIZE);
@@ -96,8 +99,9 @@ void OpenAll(void)
   InitEventFilter(FilterMouseMotionEvents);
 
   InitGfx();
-  InitElementInfo();
   InitElementProperties();     /* initializes IS_CHAR() for el2gfx() */
+  InitElementInfo();
+  InitGraphicInfo();
 
   InitLevelInfo();
   InitLevelArtworkInfo();
@@ -170,10 +174,15 @@ void InitNetworkServer()
 #endif
 }
 
+static void InitImageConfig()
+{
+  InitImageList(image_config, NUM_IMAGE_CONFIG_ENTRIES);
+}
+
 static void InitMixer()
 {
   OpenAudio();
-  InitSoundList(sound_effects, NUM_SOUND_EFFECTS);
+  InitSoundList(sound_config, NUM_SOUND_CONFIG_ENTRIES);
 
   StartMixer();
 }
@@ -2070,10 +2079,10 @@ void Execute_Debug_Command(char *command)
     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
     printf("\n");
 
-    for (i=0; i<NUM_SOUND_EFFECTS; i++)
+    for (i=0; i<NUM_SOUND_CONFIG_ENTRIES; i++)
       printf("# %s\n",
-            getFormattedSetupEntry(sound_effects[i].text,
-                                   sound_effects[i].default_filename));
+            getFormattedSetupEntry(sound_config[i].token,
+                                   sound_config[i].default_filename));
   }
   else if (strcmp(command, "create musicinfo.conf") == 0)
   {
index 8299ad2b400e1ec20907442d04f575582d9ac830..13cfce001e50e03caf5a01eee2241bbfccc4b9b5 100644 (file)
 #include "misc.h"
 
 
+/* ========================================================================= */
+/* PLATFORM SPECIFIC IMAGE FUNCTIONS                                         */
+/* ========================================================================= */
+
 #if defined(TARGET_X11)
 
 /* for MS-DOS/Allegro, exclude all except newImage() and freeImage() */
@@ -635,3 +639,28 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename,
 
 #endif /* PLATFORM_UNIX */
 #endif /* TARGET_X11 */
+
+
+/* ========================================================================= */
+/* PLATFORM INDEPENDANT IMAGE FUNCTIONS                                      */
+/* ========================================================================= */
+
+struct ImageInfo
+{
+  char *source_filename;
+  int num_references;
+};
+typedef struct ImageInfo ImageInfo;
+
+static ImageInfo **ImageList = NULL;
+static struct ArtworkConfigInfo *image_config = NULL;
+static int num_images = 0;
+
+void InitImageList(struct ArtworkConfigInfo *config_list, int num_list_entries)
+{
+  if (ImageList == NULL)
+    ImageList = checked_calloc(num_list_entries * sizeof(ImageInfo *));
+
+  image_config = config_list;
+  num_images = num_list_entries;
+}
index 6f473beeaf1c48b69b7b907dc2853c441affa216..7900bd81d1ff83327e26a4ff81ba37f1d6de5729 100644 (file)
@@ -71,4 +71,7 @@ int Read_PCX_to_Pixmap(Display *, Window, GC, char *, Pixmap *, Pixmap *);
 
 #endif /* TARGET_X11 */
 
+
+void InitImageList(struct ArtworkConfigInfo *, int);
+
 #endif /* IMAGE_H */
index 8bc69396cb464a0ad20b666dbced14501277c85e..6db94000c6a955dc0c053639f310fef91b8e0c70 100644 (file)
@@ -29,6 +29,7 @@
 #include "misc.h"
 #include "setup.h"
 #include "random.h"
+#include "text.h"
 
 
 #if defined(PLATFORM_MSDOS)
@@ -1212,6 +1213,86 @@ char getCharFromKey(Key key)
 }
 
 
+/* ========================================================================= */
+/* functions for generic lists                                               */
+/* ========================================================================= */
+
+ListNode *newListNode()
+{
+  return checked_calloc(sizeof(ListNode));
+}
+
+void addNodeToList(ListNode **node_first, char *key, void *content)
+{
+  ListNode *node_new = newListNode();
+
+#if 0
+  printf("LIST: adding node with key '%s'\n", key);
+#endif
+
+  node_new->key = getStringCopy(key);
+  node_new->content = content;
+  node_new->next = *node_first;
+  *node_first = node_new;
+}
+
+void deleteNodeFromList(ListNode **node_first, char *key,
+                       void (*destructor_function)(void *))
+{
+  if (node_first == NULL || *node_first == NULL)
+    return;
+
+#if 0
+  printf("[CHECKING LIST KEY '%s' == '%s']\n",
+        (*node_first)->key, key);
+#endif
+
+  if (strcmp((*node_first)->key, key) == 0)
+  {
+#if 0
+    printf("[DELETING LIST ENTRY]\n");
+#endif
+
+    free((*node_first)->key);
+    if (destructor_function)
+      destructor_function((*node_first)->content);
+    *node_first = (*node_first)->next;
+  }
+  else
+    deleteNodeFromList(&(*node_first)->next, key, destructor_function);
+}
+
+ListNode *getNodeFromKey(ListNode *node_first, char *key)
+{
+  if (node_first == NULL)
+    return NULL;
+
+  if (strcmp(node_first->key, key) == 0)
+    return node_first;
+  else
+    return getNodeFromKey(node_first->next, key);
+}
+
+int getNumNodes(ListNode *node_first)
+{
+  return (node_first ? 1 + getNumNodes(node_first->next) : 0);
+}
+
+void dumpList(ListNode *node_first)
+{
+  ListNode *node = node_first;
+
+  while (node)
+  {
+    printf("['%s' (%d)]\n", node->key,
+          ((struct ArtworkListNodeInfo *)node->content)->num_references);
+    node = node->next;
+  }
+
+  printf("[%d nodes]\n", getNumNodes(node_first));
+}
+
+
 /* ========================================================================= */
 /* functions for checking filenames                                          */
 /* ========================================================================= */
@@ -1263,6 +1344,220 @@ boolean FileIsArtworkType(char *basename, int type)
   return FALSE;
 }
 
+/* ========================================================================= */
+/* functions for loading artwork configuration information                   */
+/* ========================================================================= */
+
+static void LoadArtworkConfig(struct ArtworkListInfo *artwork_info)
+{
+  int num_list_entries = artwork_info->num_list_entries;
+  struct ArtworkConfigInfo *config_list = artwork_info->config_list;
+  char *filename = getCustomArtworkConfigFilename(artwork_info->type);
+  struct SetupFileList *setup_file_list;
+  int i;
+
+#if 0
+  printf("GOT CUSTOM ARTWORK CONFIG FILE '%s'\n", filename);
+#endif
+
+  /* always start with reliable default values */
+  for (i=0; i<num_list_entries; i++)
+    config_list[i].filename = NULL;
+
+  if (filename == NULL)
+    return;
+
+  if ((setup_file_list = loadSetupFileList(filename)))
+  {
+    for (i=0; i<num_list_entries; i++)
+      config_list[i].filename =
+       getStringCopy(getTokenValue(setup_file_list, config_list[i].token));
+
+    freeSetupFileList(setup_file_list);
+
+#if 0
+    for (i=0; i<num_list_entries; i++)
+    {
+      printf("'%s' ", config_list[i].token);
+      if (config_list[i].filename)
+       printf("-> '%s'\n", config_list[i].filename);
+      else
+       printf("-> UNDEFINED [-> '%s']\n", config_list[i].default_filename);
+    }
+#endif
+  }
+}
+
+void deleteArtworkListEntry(struct ArtworkListInfo *artwork_info,
+                           struct ArtworkListNodeInfo **listnode)
+{
+  if (*listnode)
+  {
+    char *filename = (*listnode)->source_filename;
+
+#if 0
+    printf("[decrementing reference counter of artwork '%s']\n", filename);
+#endif
+
+    if (--(*listnode)->num_references <= 0)
+    {
+#if 0
+      printf("[deleting artwork '%s']\n", filename);
+#endif
+
+      deleteNodeFromList(&artwork_info->file_list, filename,
+                        artwork_info->free_artwork);
+    }
+
+    *listnode = NULL;
+  }
+}
+
+static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info,
+                                   struct ArtworkListNodeInfo **listnode,
+                                   char *filename)
+{
+  ListNode *node;
+
+  /* check if the old and the new artwork file are the same */
+  if (*listnode && strcmp((*listnode)->source_filename, filename) == 0)
+  {
+    /* The old and new artwork are the same (have the same filename and path).
+       This usually means that this artwork does not exist in this artwork set
+       and a fallback to the existing artwork is done. */
+
+#if 0
+    printf("[artwork '%s' already exists (same list entry)]\n", filename);
+#endif
+
+    return;
+  }
+
+  /* delete existing artwork file entry */
+  deleteArtworkListEntry(artwork_info, listnode);
+
+  /* check if the new artwork file already exists in the list of artworks */
+  if ((node = getNodeFromKey(artwork_info->file_list, filename)) != NULL)
+  {
+#if 0
+      printf("[artwork '%s' already exists (other list entry)]\n", filename);
+#endif
+
+      *listnode = (struct ArtworkListNodeInfo *)node->content;
+      (*listnode)->num_references++;
+  }
+  else if ((*listnode = artwork_info->load_artwork(filename)) != NULL)
+  {
+    (*listnode)->num_references = 1;
+    addNodeToList(&artwork_info->file_list, (*listnode)->source_filename,
+                 *listnode);
+  }
+}
+
+static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info,
+                             struct ArtworkListNodeInfo **listnode,
+                             char *basename)
+{
+  char *filename = getCustomArtworkFilename(basename, artwork_info->type);
+
+#if 0
+  printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename);
+#endif
+
+  if (strcmp(basename, UNDEFINED_FILENAME) == 0)
+  {
+    deleteArtworkListEntry(artwork_info, listnode);
+    return;
+  }
+
+  if (filename == NULL)
+  {
+    Error(ERR_WARN, "cannot find artwork file '%s'", basename);
+    return;
+  }
+
+  replaceArtworkListEntry(artwork_info, listnode, filename);
+}
+
+void LoadArtworkToList(struct ArtworkListInfo *artwork_info,
+                      char *basename, int list_pos)
+{
+  if (artwork_info->artwork_list == NULL ||
+      list_pos >= artwork_info->num_list_entries)
+    return;
+
+#if 0
+  printf("loading artwork '%s' ...  [%d]\n",
+        basename, getNumNodes(artwork_info->file_list));
+#endif
+
+  LoadCustomArtwork(artwork_info, &artwork_info->artwork_list[list_pos],
+                   basename);
+
+#if 0
+  printf("loading artwork '%s' done [%d]\n",
+        basename, getNumNodes(artwork_info->file_list));
+#endif
+}
+
+void ReloadCustomArtworkFiles(struct ArtworkListInfo *artwork_info)
+{
+  static struct
+  {
+    char *text;
+    boolean do_it;
+  }
+  draw_init[] =
+  {
+    { "",                      FALSE },
+    { "Loading graphics:",     TRUE },
+    { "Loading sounds:",       TRUE },
+    { "Loading music:",                TRUE }
+  };
+
+  int num_list_entries = artwork_info->num_list_entries;
+  struct ArtworkConfigInfo *config_list = artwork_info->config_list;
+  int i;
+
+#if 0
+  Delay(5000);
+#endif
+
+#if 0
+  printf("DEBUG: reloading sounds '%s' ...\n",artwork.snd_current_identifier);
+#endif
+
+  LoadArtworkConfig(artwork_info);
+
+  if (draw_init[artwork_info->type].do_it)
+    DrawInitText(draw_init[artwork_info->type].text, 120, FC_GREEN);
+
+#if 0
+  printf("DEBUG: reloading %d sounds ...\n", num_list_entries);
+#endif
+
+  for(i=0; i<num_list_entries; i++)
+  {
+    if (draw_init[artwork_info->type].do_it)
+      DrawInitText(config_list[i].token, 150, FC_YELLOW);
+
+    if (config_list[i].filename)
+      LoadArtworkToList(artwork_info, config_list[i].filename, i);
+    else
+      LoadArtworkToList(artwork_info, config_list[i].default_filename, i);
+  }
+
+  draw_init[artwork_info->type].do_it = FALSE;
+
+  /*
+  printf("list size == %d\n", getNumNodes(artwork_info->file_list));
+  */
+
+#if 0
+  dumpList(artwork_info->file_list);
+#endif
+}
+
 
 /* ========================================================================= */
 /* functions only needed for non-Unix (non-command-line) systems             */
index e7dd846f9ef6c517f350004ee79e59eea8bc8bce..7f8c2fd6bc868651ed3955a7c5e91983198e720a 100644 (file)
@@ -113,11 +113,25 @@ Key getKeyFromKeyName(char *);
 Key getKeyFromX11KeyName(char *);
 char getCharFromKey(Key);
 
+
+ListNode *newListNode(void);
+void addNodeToList(ListNode **, char *, void *);
+void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
+ListNode *getNodeFromKey(ListNode *, char *);
+int getNumNodes(ListNode *);
+
+
 boolean FileIsGraphic(char *);
 boolean FileIsSound(char *);
 boolean FileIsMusic(char *);
 boolean FileIsArtworkType(char *, int);
 
+/*
+void LoadArtworkConfig(struct ArtworkListInfo *);
+*/
+void ReloadCustomArtworkFiles(struct ArtworkListInfo *);
+
+
 #if !defined(PLATFORM_UNIX)
 void initErrorFile();
 FILE *openErrorFile();
index f140d8fdd8a6b189379a83f0c0fbf75267dea17c..943c063a1ab8d48665feb5701a465d6727feaa96 100644 (file)
@@ -341,13 +341,13 @@ static char *getLevelArtworkDir(int type)
   char *artwork_path;
 
   if (leveldir_current == NULL)
-    return NOT_AVAILABLE;
+    return UNDEFINED_FILENAME;
 
   artwork_path =
     (type == TREE_TYPE_GRAPHICS_DIR ? leveldir_current->graphics_path :
      type == TREE_TYPE_SOUNDS_DIR   ? leveldir_current->sounds_path :
      type == TREE_TYPE_MUSIC_DIR    ? leveldir_current->music_path :
-     NOT_AVAILABLE);
+     UNDEFINED_FILENAME);
 
   return artwork_path;
 }
@@ -510,9 +510,19 @@ char *getCustomSoundFilename(char *basename)
   return NULL;         /* cannot find specified artwork file anywhere */
 }
 
-char *getCustomSoundConfigFilename()
+char *getCustomArtworkFilename(char *basename, int type)
 {
-  return getCustomSoundFilename(SOUNDSINFO_FILENAME);
+  if (type == ARTWORK_TYPE_GRAPHICS)
+    return getCustomImageFilename(basename);
+  else if (type == ARTWORK_TYPE_SOUNDS)
+    return getCustomSoundFilename(basename);
+  else
+    return UNDEFINED_FILENAME;
+}
+
+char *getCustomArtworkConfigFilename(int type)
+{
+  return getCustomArtworkFilename(ARTWORKINFO_FILENAME(type), type);
 }
 
 char *getCustomMusicDirectory(void)
@@ -1299,9 +1309,9 @@ static void setTreeInfoToDefaults(TreeInfo *ldi, int type)
     ldi->graphics_set = NULL;
     ldi->sounds_set = NULL;
     ldi->music_set = NULL;
-    ldi->graphics_path = getStringCopy(NOT_AVAILABLE);
-    ldi->sounds_path = getStringCopy(NOT_AVAILABLE);
-    ldi->music_path = getStringCopy(NOT_AVAILABLE);
+    ldi->graphics_path = getStringCopy(UNDEFINED_FILENAME);
+    ldi->sounds_path = getStringCopy(UNDEFINED_FILENAME);
+    ldi->music_path = getStringCopy(UNDEFINED_FILENAME);
     ldi->levels = 0;
     ldi->first_level = 0;
     ldi->last_level = 0;
@@ -1852,16 +1862,16 @@ static TreeInfo *getDummyArtworkInfo(int type)
 
   setTreeInfoToDefaults(artwork_new, type);
 
-  artwork_new->filename = getStringCopy(NOT_AVAILABLE);
-  artwork_new->fullpath = getStringCopy(NOT_AVAILABLE);
-  artwork_new->basepath = getStringCopy(NOT_AVAILABLE);
+  artwork_new->filename = getStringCopy(UNDEFINED_FILENAME);
+  artwork_new->fullpath = getStringCopy(UNDEFINED_FILENAME);
+  artwork_new->basepath = getStringCopy(UNDEFINED_FILENAME);
 
   if (artwork_new->name != NULL)
     free(artwork_new->name);
 
-  artwork_new->identifier   = getStringCopy(NOT_AVAILABLE);
-  artwork_new->name         = getStringCopy(NOT_AVAILABLE);
-  artwork_new->name_sorting = getStringCopy(NOT_AVAILABLE);
+  artwork_new->identifier   = getStringCopy(UNDEFINED_FILENAME);
+  artwork_new->name         = getStringCopy(UNDEFINED_FILENAME);
+  artwork_new->name_sorting = getStringCopy(UNDEFINED_FILENAME);
 
   return artwork_new;
 }
index 3a5021beeb4f3893a798eb1fde5a48dfcf367e7d..657467f40f5c8909854e2a748bee2466684cb2cf 100644 (file)
@@ -179,7 +179,8 @@ char *getSetupFilename(void);
 char *getImageFilename(char *);
 char *getCustomImageFilename(char *);
 char *getCustomSoundFilename(char *);
-char *getCustomSoundConfigFilename(void);
+char *getCustomArtworkFilename(char *, int);
+char *getCustomArtworkConfigFilename(int);
 char *getCustomMusicDirectory(void);
 
 void InitTapeDirectory(char *);
index a242713161fd2dd111f19257c8078a76f414ccdf..d31bc586cb5c9c8a46622eb6aca0f219ecaa4d9b 100644 (file)
@@ -152,22 +152,9 @@ struct SoundControl
 };
 typedef struct SoundControl SoundControl;
 
-struct ListNode
-{
-  char *key;
-  void *content;
-  struct ListNode *next;
-};
-typedef struct ListNode ListNode;
-
-static ListNode *newListNode(void);
-static void addNodeToList(ListNode **, char *, void *);
-static void deleteNodeFromList(ListNode **, char *, void (*function)(void *));
-static ListNode *getNodeFromKey(ListNode *, char *);
-static int getNumNodes(ListNode *);
+static struct ArtworkListInfo sound_info;
 
-
-static struct SoundEffectInfo *sound_effect;
+static struct ArtworkConfigInfo *sound_config = NULL;
 static ListNode *SoundFileList = NULL;
 static SoundInfo **Sound = NULL;
 static MusicInfo **Music = NULL;
@@ -1550,7 +1537,7 @@ static int ulaw_to_linear(unsigned char ulawbyte)
 #define CHUNK_ID_LEN            4       /* IFF style chunk id length */
 #define WAV_HEADER_SIZE                16      /* size of WAV file header */
 
-static SoundInfo *Load_WAV(char *filename)
+static void *Load_WAV(char *filename)
 {
   SoundInfo *snd_info;
 #if defined(AUDIO_UNIX_NATIVE)
@@ -1824,13 +1811,21 @@ static void LoadCustomSound(SoundInfo **snd_info, char *basename)
   replaceSoundEntry(snd_info, filename);
 }
 
-void InitSoundList(struct SoundEffectInfo *sounds_list, int num_list_entries)
+void InitSoundList(struct ArtworkConfigInfo *config_list, int num_list_entries)
 {
   if (Sound == NULL)
     Sound = checked_calloc(num_list_entries * sizeof(SoundInfo *));
 
-  sound_effect = sounds_list;
+  sound_config = config_list;
   num_sounds = num_list_entries;
+
+  sound_info.type = ARTWORK_TYPE_SOUNDS;
+  sound_info.num_list_entries = num_list_entries;
+  sound_info.config_list = config_list;
+  sound_info.artwork_list = (struct ArtworkListNodeInfo **)Sound;
+  sound_info.file_list = NULL;
+  sound_info.load_artwork = Load_WAV;
+  sound_info.free_artwork = FreeSound;
 }
 
 void LoadSoundToList(char *basename, int list_pos)
@@ -2053,119 +2048,12 @@ void StopSoundExt(int nr, int state)
   HandleSoundRequest(snd_ctrl);
 }
 
-ListNode *newListNode()
-{
-  return checked_calloc(sizeof(ListNode));
-}
-
-void addNodeToList(ListNode **node_first, char *key, void *content)
-{
-  ListNode *node_new = newListNode();
-
-#if 0
-  printf("LIST: adding node with key '%s'\n", key);
-#endif
-
-  node_new->key = getStringCopy(key);
-  node_new->content = content;
-  node_new->next = *node_first;
-  *node_first = node_new;
-}
-
-void deleteNodeFromList(ListNode **node_first, char *key,
-                       void (*destructor_function)(void *))
-{
-  if (node_first == NULL || *node_first == NULL)
-    return;
-
-#if 0
-  printf("[CHECKING LIST KEY '%s' == '%s']\n",
-        (*node_first)->key, key);
-#endif
-
-  if (strcmp((*node_first)->key, key) == 0)
-  {
-#if 0
-    printf("[DELETING LIST ENTRY]\n");
-#endif
-
-    free((*node_first)->key);
-    if (destructor_function)
-      destructor_function((*node_first)->content);
-    *node_first = (*node_first)->next;
-  }
-  else
-    deleteNodeFromList(&(*node_first)->next, key, destructor_function);
-}
-
-ListNode *getNodeFromKey(ListNode *node_first, char *key)
-{
-  if (node_first == NULL)
-    return NULL;
-
-  if (strcmp(node_first->key, key) == 0)
-    return node_first;
-  else
-    return getNodeFromKey(node_first->next, key);
-}
-
-int getNumNodes(ListNode *node_first)
-{
-  return (node_first ? 1 + getNumNodes(node_first->next) : 0);
-}
-
-void dumpList(ListNode *node_first)
-{
-  ListNode *node = node_first;
-
-  while (node)
-  {
-    printf("['%s' (%d)]\n", node->key,
-          ((SoundInfo *)node->content)->num_references);
-    node = node->next;
-  }
-
-  printf("[%d nodes]\n", getNumNodes(node_first));
-}
-
-static void LoadSoundsInfo()
+#if 1
+static void ReloadCustomSounds()
 {
-  char *filename = getCustomSoundConfigFilename();
-  struct SetupFileList *setup_file_list;
-  int i;
-
-#if 0
-  printf("GOT CUSTOM SOUND CONFIG FILE '%s'\n", filename);
-#endif
-
-  /* always start with reliable default values */
-  for (i=0; i<num_sounds; i++)
-    sound_effect[i].filename = NULL;
-
-  if (filename == NULL)
-    return;
-
-  if ((setup_file_list = loadSetupFileList(filename)))
-  {
-    for (i=0; i<num_sounds; i++)
-      sound_effect[i].filename =
-       getStringCopy(getTokenValue(setup_file_list, sound_effect[i].text));
-
-    freeSetupFileList(setup_file_list);
-
-#if 0
-    for (i=0; i<num_sounds; i++)
-    {
-      printf("'%s' ", sound_effect[i].text);
-      if (sound_effect[i].filename)
-       printf("-> '%s'\n", sound_effect[i].filename);
-      else
-       printf("-> UNDEFINED [-> '%s']\n", sound_effect[i].default_filename);
-    }
-#endif
-  }
+  ReloadCustomArtworkFiles(&sound_info);
 }
-
+#else
 static void ReloadCustomSounds()
 {
   static boolean draw_init_text = TRUE;                /* only draw at startup */
@@ -2175,7 +2063,7 @@ static void ReloadCustomSounds()
   printf("DEBUG: reloading sounds '%s' ...\n",artwork.snd_current_identifier);
 #endif
 
-  LoadSoundsInfo();
+  LoadArtworkConfig(&sound_info);
 
   if (draw_init_text)
     DrawInitText("Loading sounds:", 120, FC_GREEN);
@@ -2187,12 +2075,12 @@ static void ReloadCustomSounds()
   for(i=0; i<num_sounds; i++)
   {
     if (draw_init_text)
-      DrawInitText(sound_effect[i].text, 150, FC_YELLOW);
+      DrawInitText(sound_config[i].token, 150, FC_YELLOW);
 
-    if (sound_effect[i].filename)
-      LoadSoundToList(sound_effect[i].filename, i);
+    if (sound_config[i].filename)
+      LoadSoundToList(sound_config[i].filename, i);
     else
-      LoadSoundToList(sound_effect[i].default_filename, i);
+      LoadSoundToList(sound_config[i].default_filename, i);
   }
 
   draw_init_text = FALSE;
@@ -2205,6 +2093,7 @@ static void ReloadCustomSounds()
   dumpList(SoundFileList);
 #endif
 }
+#endif
 
 static void ReloadCustomMusic()
 {
index ec5a2a8b8c2a0a13d7382cb4a7e5a6dd73dfe72f..a018ec91d23e0798a3b032ade7b1395e6ad8b5b2 100644 (file)
 #define SOUND_MIDDLE                   (SOUND_MAX_LEFT2RIGHT / 2)
 
 /* value for undefined sound effect filename */
-#define SND_FILE_UNDEFINED             "NONE"
-
-
-struct SoundEffectInfo
-{
-  char *text;
-  char *default_filename;
-
-  char *filename;
-};
+#define SND_FILE_UNDEFINED             UNDEFINED_FILENAME
 
 
 /* general sound functions */
@@ -148,7 +139,7 @@ void StopMusic(void);
 void StopSound(int);
 void StopSounds(void);
 void StopSoundExt(int, int);
-void InitSoundList(struct SoundEffectInfo *, int);
+void InitSoundList(struct ArtworkConfigInfo *, int);
 void InitReloadSounds(char *);
 void InitReloadMusic(char *);
 void FreeAllSounds(void);
index 920e464cfa12a5af0ab296bc879c4bbfdc6c88c0..4bd6305ab6b10ea4729d8e8364df2e25396dc042 100644 (file)
 /* default text for non-existant artwork */
 #define NOT_AVAILABLE          "(not available)"
 
+/* default value for undefined filename */
+#define UNDEFINED_FILENAME     "[NONE]"
+
 /* default name for new levels */
 #define NAMELESS_LEVEL_NAME    "nameless level"
 
@@ -358,10 +361,14 @@ struct SetupInfo
 };
 
 #define TREE_TYPE_GENERIC              0
-#define TREE_TYPE_LEVEL_DIR            1
-#define TREE_TYPE_GRAPHICS_DIR         2
-#define TREE_TYPE_SOUNDS_DIR           3
-#define TREE_TYPE_MUSIC_DIR            4
+#define TREE_TYPE_GRAPHICS_DIR         1
+#define TREE_TYPE_SOUNDS_DIR           2
+#define TREE_TYPE_MUSIC_DIR            3
+#define TREE_TYPE_LEVEL_DIR            4
+
+#define ARTWORK_TYPE_GRAPHICS          TREE_TYPE_GRAPHICS_DIR
+#define ARTWORK_TYPE_SOUNDS            TREE_TYPE_SOUNDS_DIR
+#define ARTWORK_TYPE_MUSIC             TREE_TYPE_MUSIC_DIR
 
 struct TreeInfo
 {
@@ -429,6 +436,31 @@ struct ArtworkInfo
   char *mus_current_identifier;
 };
 
+struct ArtworkConfigInfo
+{
+  char *token;
+  char *default_filename;
+
+  char *filename;
+};
+
+struct ArtworkListNodeInfo
+{
+  char *source_filename;
+  int num_references;
+};
+
+struct ArtworkListInfo
+{
+  int type;                                    /* type of artwork */
+  int num_list_entries;
+  struct ArtworkConfigInfo *config_list;       /* static config list */
+  struct ArtworkListNodeInfo **artwork_list;   /* static artwork list */
+  ListNode *file_list;                         /* dynamic artwork list */
+  void *(*load_artwork)(char *);               /* constructor function */
+  void (*free_artwork)(void *);                        /* destructor function */
+};
+
 
 /* ========================================================================= */
 /* exported variables                                                        */
index 2ee05af0c7e961cbe16555889488fb1f7d708712..1c527d09faed9d414877114d847be9e1a0eaa419 100644 (file)
@@ -46,4 +46,13 @@ typedef unsigned char byte;
 #define SIZEOF_ARRAY(array, type)      (sizeof(array) / sizeof(type))
 #define SIZEOF_ARRAY_INT(array)                SIZEOF_ARRAY(array, int)
 
+
+struct ListNode
+{
+  char *key;
+  void *content;
+  struct ListNode *next;
+};
+typedef struct ListNode ListNode;
+
 #endif /* TYPES_H */
index 08d246b8a2c6504ec641585c96105abddb29044b..51fa055d2aeaea7ed6755ed0c0665c6d45d14351 100644 (file)
@@ -136,7 +136,30 @@ char *sound_name[NUM_SOUNDS] =
   "gate.wav"
 };
 
-struct SoundEffectInfo sound_effects[] =
+struct ArtworkConfigInfo image_config[] =
+{
+  /* graphics for Boulder Dash style elements and actions */
+  { "bd_empty_space.digging",          "empty.pcx"             },
+  { "bd_sand.digging",                 "schlurf.pcx"           },
+  { "bd_diamond.collecting",           "pong.pcx"              },
+  { "bd_diamond.impact",               "pling.pcx"             },
+  { "bd_rock.pushing",                 "pusch.pcx"             },
+  { "bd_rock.impact",                  "klopf.pcx"             },
+  { "bd_magic_wall.activating",                "quirk.pcx"             },
+  { "bd_magic_wall.changing",          "quirk.pcx"             },
+  { "bd_magic_wall.running",           "miep.pcx"              },
+  { "bd_amoeba.waiting",               "amoebe.pcx"            },
+  { "bd_amoeba.creating",              "amoebe.pcx"            },
+  { "bd_amoeba.turning_to_gem",                "pling.pcx"             },
+  { "bd_amoeba.turning_to_rock",       "klopf.pcx"             },
+  { "bd_butterfly.moving",             "klapper.pcx"           },
+  { "bd_butterfly.waiting",            "klapper.pcx"           },
+  { "bd_firefly.moving",               "roehr.pcx"             },
+  { "bd_firefly.waiting",              "roehr.pcx"             },
+  { "bd_exit.entering",                        "buing.pcx"             },
+};
+
+struct ArtworkConfigInfo sound_config[] =
 {
   /* sounds for Boulder Dash style elements and actions */
   { "bd_empty_space.digging",          "empty.wav"             },
index 8e37a2be4838ab9c05dc3d28c623a4ee9f4ec136..fb8d277c198c8a4357f6d2c7fbc628570c7378ea 100644 (file)
@@ -415,7 +415,7 @@ extern struct GameInfo              game;
 extern struct GlobalInfo       global;
 extern struct ElementInfo      element_info[];
 extern struct GraphicInfo      graphic_info[];
-extern struct SoundEffectInfo  sound_effects[];
+extern struct ArtworkConfigInfo        image_config[], sound_config[];
 
 /* often used screen positions */
 #define SX                     8
@@ -1458,7 +1458,30 @@ extern struct SoundEffectInfo    sound_effects[];
 #define NUM_SOUNDS             55
 
 
-/* values for sound effects */
+/* values for image configuration */
+#define GFX_BD_EMPTY_SPACE_DIGGING             0
+#define GFX_BD_SAND_DIGGING                    1
+#define GFX_BD_DIAMOND_COLLECTING              2
+#define GFX_BD_DIAMOND_IMPACT                  3
+#define GFX_BD_ROCK_PUSHING                    4
+#define GFX_BD_ROCK_IMPACT                     5
+#define GFX_BD_MAGIC_WALL_ACTIVATING           6
+#define GFX_BD_MAGIC_WALL_CHANGING             7
+#define GFX_BD_MAGIC_WALL_RUNNING              8
+#define GFX_BD_AMOEBA_WAITING                  9
+#define GFX_BD_AMOEBA_CREATING                 10
+#define GFX_BD_AMOEBA_TURNING_TO_GEM           11
+#define GFX_BD_AMOEBA_TURNING_TO_ROCK          12
+#define GFX_BD_BUTTERFLY_MOVING                        13
+#define GFX_BD_BUTTERFLY_WAITING               14
+#define GFX_BD_FIREFLY_MOVING                  15
+#define GFX_BD_FIREFLY_WAITING                 16
+#define GFX_BD_EXIT_ENTERING                   17
+
+#define NUM_IMAGE_CONFIG_ENTRIES               18
+
+
+/* values for sound configuration */
 #define SND_BD_EMPTY_SPACE_DIGGING             0
 #define SND_BD_SAND_DIGGING                    1
 #define SND_BD_DIAMOND_COLLECTING              2
@@ -1629,7 +1652,7 @@ extern struct SoundEffectInfo     sound_effects[];
 #define SND_MENU_HALL_OF_FAME                  167
 #define SND_MENU_INFO_SCREEN                   168
 
-#define NUM_SOUND_EFFECTS                      169
+#define NUM_SOUND_CONFIG_ENTRIES               169
 
 
 /* values for game_status */