From e2b2b44c56f55520c8cc43cf361c83a12e60f7b0 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 3 Feb 2005 03:40:56 +0100 Subject: [PATCH] rnd-20050203-1-src * improved fallback handling when configured artwork is not available (now using default artwork instead of exiting when files not found) --- ChangeLog | 4 + src/conftime.h | 2 +- src/init.c | 43 +++++++++ src/libgame/gadgets.c | 6 +- src/libgame/misc.c | 199 +++++++++++++++++++++++++++++++++++++++++- src/libgame/system.h | 1 + 6 files changed, 252 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8272f962..efa565d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-02-02 + * improved fallback handling when configured artwork is not available + (now using default artwork instead of exiting when files not found) + 2005-02-01 * fixed bug on level selection screen when dragging scrollbar diff --git a/src/conftime.h b/src/conftime.h index cc7d4af4..fd10b145 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2005-02-01 23:09]" +#define COMPILE_DATE_STRING "[2005-02-03 03:27]" diff --git a/src/init.c b/src/init.c index 8e8694ef..988ab57e 100644 --- a/src/init.c +++ b/src/init.c @@ -1010,6 +1010,49 @@ static void set_graphic_parameters(int graphic, int graphic_copy_from) int anim_frames_per_line = 1; int i; +#if 1 +#if 1 + + /* !!! NEW ARTWORK FALLBACK CODE !!! NEARLY UNTESTED !!! */ + /* if fallback to default artwork is done, also use the default parameters */ + if (image->fallback_to_default) + { +#if 0 + printf("::: FALLBACK for %d\n", graphic_copy_from); +#endif + + parameter_raw = image->default_parameter; + } + +#else + + /* !!! ARTWORK FALLBACK CODE !!! NEARLY UNTESTED !!! */ + /* (better try to set a "fallback -> use default parameters" flag) */ + if (src_bitmap) + { + int len_source_filename = strlen(src_bitmap->source_filename); + int len_default_filename = strlen(image->default_filename); + int pos_basename = len_source_filename - len_default_filename; + char *source_basename = &src_bitmap->source_filename[pos_basename]; + +#if 0 + printf("::: src_bitmap->source_filename -> '%s'\n", + src_bitmap->source_filename); + printf("::: image->default_filename -> '%s'\n", + image->default_filename); + printf("::: image->filename -> '%s'\n", + image->filename); +#endif + + /* check if there was a fallback to the default artwork file */ + if (strcmp(image->filename, image->default_filename) != 0 && + pos_basename >= 0 && + strcmp(source_basename, image->default_filename) == 0) + parameter_raw = image->default_parameter; + } +#endif +#endif + /* get integer values from string parameters */ for (i = 0; i < NUM_GFX_ARGS; i++) { diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 50dc8531..a134b049 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -1068,7 +1068,11 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) getFontCharSource(font_nr, FONT_ASCII_CURSOR, &src_bitmap, &src_x, &src_y); src_x += font_width / 2; src_y += font_height / 2; - gi->selectbox.inverse_color = GetPixel(src_bitmap, src_x, src_y); + + /* there may be esoteric cases with missing or too small font bitmap */ + if (src_bitmap != NULL && + src_x < src_bitmap->width && src_y < src_bitmap->height) + gi->selectbox.inverse_color = GetPixel(src_bitmap, src_x, src_y); /* always start with closed selectbox */ gi->selectbox.open = FALSE; diff --git a/src/libgame/misc.c b/src/libgame/misc.c index b72aa3c5..2a132858 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1745,6 +1745,9 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, setString(&file_list[i].default_parameter[j], suffix_list[j].value); setString(&file_list[i].parameter[j], suffix_list[j].value); } + + file_list[i].redefined = FALSE; + file_list[i].fallback_to_default = FALSE; } } @@ -1919,6 +1922,9 @@ static void add_dynamic_file_list_entry(struct FileInfo **list, new_list_entry->filename = NULL; new_list_entry->parameter = checked_calloc(parameter_array_size); + new_list_entry->redefined = FALSE; + new_list_entry->fallback_to_default = FALSE; + read_token_parameters(extra_file_hash, suffix_list, new_list_entry); } @@ -2376,6 +2382,7 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) setString(&file_list[i].parameter[j], file_list[i].default_parameter[j]); file_list[i].redefined = FALSE; + file_list[i].fallback_to_default = FALSE; } /* free previous dynamic artwork file array */ @@ -2444,6 +2451,116 @@ static void deleteArtworkListEntry(struct ArtworkListInfo *artwork_info, } } +#if 1 +static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, + struct ListNodeInfo **listnode, + struct FileInfo *file_list_entry) +{ + char *init_text[] = + { + "Loading graphics:", + "Loading sounds:", + "Loading music:" + }; + + ListNode *node; + char *basename = file_list_entry->filename; + char *filename = getCustomArtworkFilename(basename, artwork_info->type); + + if (filename == NULL) + { + Error(ERR_WARN, "cannot find artwork file '%s'", basename); + + basename = file_list_entry->default_filename; + + /* dynamic artwork has no default filename / skip empty default artwork */ + if (basename == NULL || strcmp(basename, UNDEFINED_FILENAME) == 0) + return; + + file_list_entry->fallback_to_default = TRUE; + + Error(ERR_WARN, "trying default artwork file '%s'", basename); + + filename = getCustomArtworkFilename(basename, artwork_info->type); + + if (filename == NULL) + { + int error_mode = ERR_WARN; + + /* we can get away without sounds and music, but not without graphics */ + if (*listnode == NULL && artwork_info->type == ARTWORK_TYPE_GRAPHICS) + error_mode = ERR_EXIT; + + Error(error_mode, "cannot find default artwork file '%s'", basename); + + return; + } + } + + /* 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->content_list, filename)) != NULL) + { +#if 0 + printf("[artwork '%s' already exists (other list entry)]\n", filename); +#endif + + *listnode = (struct ListNodeInfo *)node->content; + (*listnode)->num_references++; + + return; + } + +#if 0 + printf("::: %s: '%s'\n", init_text[artwork_info->type], basename); +#endif + + DrawInitText(init_text[artwork_info->type], 120, FC_GREEN); + DrawInitText(basename, 150, FC_YELLOW); + + if ((*listnode = artwork_info->load_artwork(filename)) != NULL) + { +#if 0 + printf("[adding new artwork '%s']\n", filename); +#endif + + (*listnode)->num_references = 1; + addNodeToList(&artwork_info->content_list, (*listnode)->source_filename, + *listnode); + } + else + { + int error_mode = ERR_WARN; + +#if 1 + /* we can get away without sounds and music, but not without graphics */ + if (artwork_info->type == ARTWORK_TYPE_GRAPHICS) + error_mode = ERR_EXIT; +#endif + + Error(error_mode, "cannot load artwork file '%s'", basename); + return; + } +} + +#else + static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, struct ListNodeInfo **listnode, char *basename) @@ -2463,6 +2580,9 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, int error_mode = ERR_WARN; #if 1 + /* !!! NEW ARTWORK FALLBACK CODE !!! NEARLY UNTESTED !!! */ + /* before failing, try fallback to default artwork */ +#else /* we can get away without sounds and music, but not without graphics */ if (*listnode == NULL && artwork_info->type == ARTWORK_TYPE_GRAPHICS) error_mode = ERR_EXIT; @@ -2533,6 +2653,27 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, return; } } +#endif + +#if 1 +static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info, + struct ListNodeInfo **listnode, + struct FileInfo *file_list_entry) +{ +#if 0 + printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename); +#endif + + if (strcmp(file_list_entry->filename, UNDEFINED_FILENAME) == 0) + { + deleteArtworkListEntry(artwork_info, listnode); + return; + } + + replaceArtworkListEntry(artwork_info, listnode, file_list_entry); +} + +#else static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info, struct ListNodeInfo **listnode, @@ -2550,6 +2691,38 @@ static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info, replaceArtworkListEntry(artwork_info, listnode, basename); } +#endif + +#if 1 +static void LoadArtworkToList(struct ArtworkListInfo *artwork_info, + struct ListNodeInfo **listnode, + struct FileInfo *file_list_entry) +{ +#if 0 + if (artwork_info->artwork_list == NULL || + list_pos >= artwork_info->num_file_list_entries) + return; +#endif + +#if 0 + printf("loading artwork '%s' ... [%d]\n", + basename, getNumNodes(artwork_info->content_list)); +#endif + +#if 1 + LoadCustomArtwork(artwork_info, listnode, file_list_entry); +#else + LoadCustomArtwork(artwork_info, &artwork_info->artwork_list[list_pos], + basename); +#endif + +#if 0 + printf("loading artwork '%s' done [%d]\n", + basename, getNumNodes(artwork_info->content_list)); +#endif +} + +#else static void LoadArtworkToList(struct ArtworkListInfo *artwork_info, struct ListNodeInfo **listnode, @@ -2578,6 +2751,7 @@ static void LoadArtworkToList(struct ArtworkListInfo *artwork_info, basename, getNumNodes(artwork_info->content_list)); #endif } +#endif void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info) { @@ -2600,18 +2774,34 @@ void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info) printf("::: '%s' -> '%s'\n", file_list[i].token, file_list[i].filename); #endif +#if 1 + LoadArtworkToList(artwork_info, &artwork_info->artwork_list[i], + &file_list[i]); +#else LoadArtworkToList(artwork_info, &artwork_info->artwork_list[i], file_list[i].filename, i); +#endif #if 0 + /* !!! NEW ARTWORK FALLBACK CODE !!! NEARLY UNTESTED !!! */ if (artwork_info->artwork_list[i] == NULL && - strcmp(file_list[i].default_filename, file_list[i].filename) != 0) + strcmp(file_list[i].filename, UNDEFINED_FILENAME) != 0 && + strcmp(file_list[i].default_filename, file_list[i].filename) != 0 && + strcmp(file_list[i].default_filename, UNDEFINED_FILENAME) != 0) { Error(ERR_WARN, "trying default artwork file '%s'", file_list[i].default_filename); LoadArtworkToList(artwork_info, &artwork_info->artwork_list[i], file_list[i].default_filename, i); + + /* even the fallback to default artwork was not successful -- fail now */ + if (artwork_info->artwork_list[i] == NULL && + artwork_info->type == ARTWORK_TYPE_GRAPHICS) + Error(ERR_EXIT, "cannot find artwork file '%s' or default file '%s'", + file_list[i].filename, file_list[i].default_filename); + + file_list[i].fallback_to_default = TRUE; } #endif } @@ -2623,14 +2813,21 @@ void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info) for (i = 0; i < num_dynamic_file_list_entries; i++) { +#if 1 + LoadArtworkToList(artwork_info, &artwork_info->dynamic_artwork_list[i], + &dynamic_file_list[i]); +#else LoadArtworkToList(artwork_info, &artwork_info->dynamic_artwork_list[i], dynamic_file_list[i].filename, i); +#endif #if 0 printf("::: '%s', '0x%08x'\n", dynamic_file_list[i].filename, dynamic_file_list[i].default_filename); #endif + + /* dynamic artwork does not have default filename! */ } #if 0 diff --git a/src/libgame/system.h b/src/libgame/system.h index c0fc4360..0183b066 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -727,6 +727,7 @@ struct FileInfo char **parameter; /* array of file parameters */ boolean redefined; + boolean fallback_to_default; }; struct SetupFileList -- 2.34.1