From 28f0f8708f4b4f8c4f39f1b23bc5fc7e0fed7579 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 3 Sep 2002 21:23:59 +0200 Subject: [PATCH] rnd-20020903-1-src --- src/conftime.h | 2 +- src/game.c | 18 +-- src/init.c | 21 ++- src/libgame/image.c | 29 +++++ src/libgame/image.h | 3 + src/libgame/misc.c | 295 +++++++++++++++++++++++++++++++++++++++++++ src/libgame/misc.h | 14 ++ src/libgame/setup.c | 36 ++++-- src/libgame/setup.h | 3 +- src/libgame/sound.c | 157 ++++------------------- src/libgame/sound.h | 13 +- src/libgame/system.h | 40 +++++- src/libgame/types.h | 9 ++ src/main.c | 25 +++- src/main.h | 29 ++++- 15 files changed, 511 insertions(+), 183 deletions(-) diff --git a/src/conftime.h b/src/conftime.h index 74e0118a..45532d5f 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2002-08-25 02:44]" +#define COMPILE_DATE_STRING "[2002-09-03 21:23]" diff --git a/src/game.c b/src/game.c index bc31c194..f64d2593 100644 --- a/src/game.c +++ b/src/game.c @@ -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; jkey = 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 '%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; itype].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 */ diff --git a/src/libgame/misc.h b/src/libgame/misc.h index e7dd846f..7f8c2fd6 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -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(); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index f140d8fd..943c063a 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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; } diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 3a5021be..657467f4 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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 *); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index a2427131..d31bc586 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -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 '%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