From: Holger Schemel Date: Mon, 20 Jan 2003 14:41:12 +0000 (+0100) Subject: rnd-20030120-1-src X-Git-Tag: 3.0.0^2~168 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=ba0568bc8d5b8b3d081691b8e987f2b66a4c13e6;p=rocksndiamonds.git rnd-20030120-1-src --- diff --git a/src/conftime.h b/src/conftime.h index c86c2ea5..1098a8e6 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-01-19 19:22]" +#define COMPILE_DATE_STRING "[2003-01-20 15:37]" diff --git a/src/init.c b/src/init.c index 2b7836e2..41743eac 100644 --- a/src/init.c +++ b/src/init.c @@ -184,21 +184,23 @@ static void InitArtworkInfo() static void InitArtworkConfig() { - static struct ConfigInfo action_suffix[NUM_ACTIONS + 1]; - static struct ConfigInfo direction_suffix[NUM_DIRECTIONS + 1]; - static struct ConfigInfo empty[1]; + static char *element_prefix[MAX_NUM_ELEMENTS + 1]; + static char *action_suffix[NUM_ACTIONS + 1]; + static char *direction_suffix[NUM_DIRECTIONS + 1]; + static char *dummy[1] = { NULL }; int i; + for (i=0; itype = ARTWORK_TYPE_GRAPHICS; + /* ---------- initialize file list and suffix lists ---------- */ + image_info->num_file_list_entries = num_file_list_entries; image_info->num_suffix_list_entries = 0; for (i=0; config_suffix_list[i].token != NULL; i++) image_info->num_suffix_list_entries++; - image_info->num_ext1_suffix_list_entries = 0; - for (i=0; ext1_suffix_list[i].token != NULL; i++) - image_info->num_ext1_suffix_list_entries++; - - image_info->num_ext2_suffix_list_entries = 0; - for (i=0; ext2_suffix_list[i].token != NULL; i++) - image_info->num_ext2_suffix_list_entries++; - image_info->file_list = getFileListFromConfigList(config_list, config_suffix_list, num_file_list_entries); image_info->suffix_list = config_suffix_list; - image_info->ext1_suffix_list = ext1_suffix_list; - image_info->ext2_suffix_list = ext2_suffix_list; + + /* ---------- initialize base prefix and suffixes lists ---------- */ + + image_info->num_base_prefixes = 0; + for (i=0; base_prefixes[i] != NULL; i++) + image_info->num_base_prefixes++; + + image_info->num_ext1_suffixes = 0; + for (i=0; ext1_suffixes[i] != NULL; i++) + image_info->num_ext1_suffixes++; + + image_info->num_ext2_suffixes = 0; + for (i=0; ext2_suffixes[i] != NULL; i++) + image_info->num_ext2_suffixes++; + + image_info->base_prefixes = base_prefixes; + image_info->ext1_suffixes = ext1_suffixes; + image_info->ext2_suffixes = ext2_suffixes; image_info->custom_setup_list = NULL; + /* ---------- initialize artwork reference and content lists ---------- */ + image_info->artwork_list = checked_calloc(num_file_list_entries * sizeof(ImageInfo *)); image_info->content_list = NULL; + /* ---------- initialize artwork loading/freeing functions ---------- */ + image_info->load_artwork = Load_PCX; image_info->free_artwork = FreeImage; } diff --git a/src/libgame/image.h b/src/libgame/image.h index 0bc0b4b3..ccb1c8d8 100644 --- a/src/libgame/image.h +++ b/src/libgame/image.h @@ -77,7 +77,7 @@ Bitmap *getBitmapFromImageID(int); char *getTokenFromImageID(int); char *getImageConfigFilename(); void InitImageList(struct ConfigInfo *, int, struct ConfigInfo *, - struct ConfigInfo *, struct ConfigInfo *); + char **, char **, char **); void ReloadCustomImages(); void FreeAllImages(); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 5b083e41..53562589 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1595,6 +1595,7 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, num_file_list_entries_found = list_pos + 1; if (num_file_list_entries_found != num_file_list_entries) { + Error(ERR_RETURN_LINE, "-"); Error(ERR_RETURN, "inconsistant config list information:"); Error(ERR_RETURN, "- should be: %d (according to 'src/conf_gfx.h')", num_file_list_entries); @@ -1606,17 +1607,94 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, return file_list; } +#define SUFFIX_NO_MATCH 0 +#define SUFFIX_MATCH (1 << 0) +#define SUFFIX_MATCH_COMPLETE (1 << 1) + +static int token_suffix_match(char *token, char *suffix, int start_pos) +{ + int len_token = strlen(token); + int len_suffix = strlen(suffix); + + if (start_pos + len_suffix > len_token) + return SUFFIX_NO_MATCH; + + if (strncmp(&token[start_pos], suffix, len_suffix) != 0) + return SUFFIX_NO_MATCH; + + if (token[start_pos + len_suffix] == '\0') + return SUFFIX_MATCH_COMPLETE; + + if (token[start_pos + len_suffix] == '.') + return SUFFIX_MATCH; + + return SUFFIX_NO_MATCH; +} + +#define KNOWN_TOKEN_VALUE "[KNOWN_TOKEN]" + +static void read_token_parameters(struct SetupFileList *setup_file_list, + struct ConfigInfo *suffix_list, + struct FileInfo *file_list_entry) +{ + /* check for config token that is the base token without any suffixes */ + char *filename = getTokenValue(setup_file_list, file_list_entry->token); + char *known_token_value = KNOWN_TOKEN_VALUE; + int i; + + if (filename != NULL) + { + /* when file definition found, set all parameters to default values */ + for (i=0; suffix_list[i].token != NULL; i++) + file_list_entry->parameter[i] = + get_parameter_value(suffix_list[i].type, suffix_list[i].value); + + file_list_entry->filename = getStringCopy(filename); + + /* mark config file token as well known from default config */ + setTokenValue(setup_file_list, file_list_entry->token, known_token_value); + } + else + file_list_entry->filename = + getStringCopy(file_list_entry->default_filename); + + /* check for config tokens that can be build by base token and suffixes */ + for (i=0; suffix_list[i].token != NULL; i++) + { + char *token = getStringCat2(file_list_entry->token, suffix_list[i].token); + char *value = getTokenValue(setup_file_list, token); + + if (value != NULL) + { + file_list_entry->parameter[i] = + get_parameter_value(suffix_list[i].type, value); + + /* mark config file token as well known from default config */ + setTokenValue(setup_file_list, token, known_token_value); + } + + free(token); + } +} + void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) { struct FileInfo *file_list = artwork_info->file_list; struct ConfigInfo *suffix_list = artwork_info->suffix_list; + char **base_prefixes = artwork_info->base_prefixes; + char **ext1_suffixes = artwork_info->ext1_suffixes; + char **ext2_suffixes = artwork_info->ext2_suffixes; int num_file_list_entries = artwork_info->num_file_list_entries; int num_suffix_list_entries = artwork_info->num_suffix_list_entries; + int num_base_prefixes = artwork_info->num_base_prefixes; + int num_ext1_suffixes = artwork_info->num_ext1_suffixes; + int num_ext2_suffixes = artwork_info->num_ext2_suffixes; char *filename = getCustomArtworkConfigFilename(artwork_info->type); struct SetupFileList *setup_file_list; struct SetupFileList *extra_file_list = NULL; - char *known_token_value = "[KNOWN_TOKEN]"; - int i, j; + struct SetupFileList *list; + char *known_token_value = KNOWN_TOKEN_VALUE; + int i, j, k; #if 0 printf("GOT CUSTOM ARTWORK CONFIG FILE '%s'\n", filename); @@ -1639,85 +1717,95 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) if ((setup_file_list = loadSetupFileList(filename)) == NULL) return; + /* read parameters for all known config file tokens */ for (i=0; inext) + { + if (strcmp(list->value, known_token_value) != 0) + { + if (extra_file_list == NULL) + extra_file_list = newSetupFileList(list->token, list->value); + else + setTokenValue(extra_file_list, list->token, list->value); } - else - file_list[i].filename = getStringCopy(file_list[i].default_filename); + } - /* check for config tokens that can be build by base token and suffixes */ - for (j=0; jnext) + Error(ERR_RETURN, "- unknown token: '%s'", list->token); - free(token); + Error(ERR_RETURN_LINE, "-"); } - } - /* set some additional tokens to "known" */ - setTokenValue(setup_file_list, "name", known_token_value); - setTokenValue(setup_file_list, "sort_priority", known_token_value); + /* now try to determine valid, dynamically defined config tokens */ - if (options.verbose && !IS_CHILD_PROCESS(audio.mixer_pid)) - { - boolean unknown_tokens_found = FALSE; - - /* check each token in config file if it is defined in default config */ - while (setup_file_list != NULL) + for (list = extra_file_list; list != NULL; list = list->next) { - if (strcmp(setup_file_list->value, known_token_value) != 0) + char *token = list->token; + + for (i=0; itoken, - setup_file_list->value); - else - setTokenValue(extra_file_list, setup_file_list->token, - setup_file_list->value); - - if (!unknown_tokens_found) - { - Error(ERR_RETURN_LINE, "-"); - Error(ERR_RETURN, "warning: unknown token(s) found in config file:"); - Error(ERR_RETURN, "- config file: '%s'", filename); + char *base_prefix = base_prefixes[i]; + int start_pos = 0; + int match = token_suffix_match(token, base_prefix, start_pos); - unknown_tokens_found = TRUE; + if (match == SUFFIX_MATCH_COMPLETE) + { + printf("--- found complete token '%s'\n", token); + } + else if (match == SUFFIX_MATCH) + { + int len_base_prefix = strlen(base_prefix); + + for (j=0; jtoken); } - - setup_file_list = setup_file_list->next; } - - if (unknown_tokens_found) - Error(ERR_RETURN_LINE, "-"); } - freeSetupFileList(setup_file_list); - freeSetupFileList(extra_file_list); #if 0 diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 460bed15..004c4458 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -1772,42 +1772,56 @@ struct FileInfo *getCurrentSoundList() void InitSoundList(struct ConfigInfo *config_list, int num_file_list_entries, struct ConfigInfo *config_suffix_list, - struct ConfigInfo *ext1_suffix_list, - struct ConfigInfo *ext2_suffix_list) + char **base_prefixes, + char **ext1_suffixes, + char **ext2_suffixes) { int i; sound_info = checked_calloc(sizeof(struct ArtworkListInfo)); - sound_info->type = ARTWORK_TYPE_SOUNDS; + /* ---------- initialize file list and suffix lists ---------- */ + sound_info->num_file_list_entries = num_file_list_entries; sound_info->num_suffix_list_entries = 0; for (i=0; config_suffix_list[i].token != NULL; i++) sound_info->num_suffix_list_entries++; - sound_info->num_ext1_suffix_list_entries = 0; - for (i=0; ext1_suffix_list[i].token != NULL; i++) - sound_info->num_ext1_suffix_list_entries++; - - sound_info->num_ext2_suffix_list_entries = 0; - for (i=0; ext2_suffix_list[i].token != NULL; i++) - sound_info->num_ext2_suffix_list_entries++; - sound_info->file_list = getFileListFromConfigList(config_list, config_suffix_list, num_file_list_entries); sound_info->suffix_list = config_suffix_list; - sound_info->ext1_suffix_list = ext1_suffix_list; - sound_info->ext2_suffix_list = ext2_suffix_list; + + /* ---------- initialize base prefix and suffixes lists ---------- */ + + sound_info->num_base_prefixes = 0; + for (i=0; base_prefixes[i] != NULL; i++) + sound_info->num_base_prefixes++; + + sound_info->num_ext1_suffixes = 0; + for (i=0; ext1_suffixes[i] != NULL; i++) + sound_info->num_ext1_suffixes++; + + sound_info->num_ext2_suffixes = 0; + for (i=0; ext2_suffixes[i] != NULL; i++) + sound_info->num_ext2_suffixes++; + + sound_info->base_prefixes = base_prefixes; + sound_info->ext1_suffixes = ext1_suffixes; + sound_info->ext2_suffixes = ext2_suffixes; sound_info->custom_setup_list = NULL; + /* ---------- initialize artwork reference and content lists ---------- */ + sound_info->artwork_list = checked_calloc(num_file_list_entries * sizeof(SoundInfo *)); sound_info->content_list = NULL; + /* ---------- initialize artwork loading/freeing functions ---------- */ + sound_info->load_artwork = Load_WAV; sound_info->free_artwork = FreeSound; diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 9e495961..89e54059 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -144,7 +144,7 @@ void StopSounds(void); void StopSoundExt(int, int); struct FileInfo *getCurrentSoundList(); void InitSoundList(struct ConfigInfo *, int, struct ConfigInfo *, - struct ConfigInfo *, struct ConfigInfo *); + char **, char **, char **); void InitReloadCustomSounds(char *); void InitReloadCustomMusic(char *); void FreeAllSounds(void); diff --git a/src/libgame/system.h b/src/libgame/system.h index fa722636..6ff9c39f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -206,7 +206,7 @@ #define VERSION_PATCH(x) ((x) % 100) /* functions for parent/child process identification */ -#define IS_PARENT_PROCESS(pid) ((pid) > 0) +#define IS_PARENT_PROCESS(pid) ((pid) > 0 || (pid) == -1) #define IS_CHILD_PROCESS(pid) ((pid) == 0) @@ -517,17 +517,20 @@ struct ArtworkListInfo int num_file_list_entries; int num_suffix_list_entries; - int num_ext1_suffix_list_entries; - int num_ext2_suffix_list_entries; struct FileInfo *file_list; /* static artwork file array */ struct ConfigInfo *suffix_list; /* parameter suffixes array */ - struct ConfigInfo *ext1_suffix_list; /* property suffixes array 1 */ - struct ConfigInfo *ext2_suffix_list; /* property suffixes array 2 */ + + int num_base_prefixes; + int num_ext1_suffixes; + int num_ext2_suffixes; + + char **base_prefixes; /* base token prefixes array */ + char **ext1_suffixes; /* property suffixes array 1 */ + char **ext2_suffixes; /* property suffixes array 2 */ struct SetupFileList *custom_setup_list; /* additional definitions */ struct ListNodeInfo **artwork_list; /* static artwork node array */ - struct ListNode *content_list; /* dynamic artwork node list */ void *(*load_artwork)(char *); /* constructor function */ diff --git a/src/main.h b/src/main.h index 423058b4..aab0040c 100644 --- a/src/main.h +++ b/src/main.h @@ -1027,7 +1027,7 @@ struct GlobalInfo struct ElementInfo { - char *token_name; /* element token used in config files */ + char *token_name; /* element token prefix used in config files */ char *sound_class_name; /* classification for custom sound effects */ char *editor_description; /* short description for level editor */