X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=a760cbf51223c3c3a42d8a01bdafb2933cdfa5bf;hb=9fb817132a5f07e7dce091dbb01e1d6a8dc40f17;hp=83d01ab6d529d75b9c80edfc4de8c0ca7d07a63f;hpb=d225818b7c89b2b60e52ac228e47ce303b5d8ef8;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 83d01ab6..a760cbf5 100644 --- a/src/init.c +++ b/src/init.c @@ -153,8 +153,10 @@ void InitGadgets() inline void InitElementSmallImagesScaledUp(int graphic) { - CreateImageWithSmallImages(graphic, graphic_info[graphic].scale_up_factor, - graphic_info[graphic].tile_size); + struct GraphicInfo *g = &graphic_info[graphic]; + + // create small and game tile sized bitmaps (and scale up, if needed) + CreateImageWithSmallImages(graphic, g->scale_up_factor, g->tile_size); } void InitElementSmallImages() @@ -208,6 +210,17 @@ void InitScaledImages() ScaleImage(i, graphic_info[i].scale_up_factor); } +void InitBitmapPointers() +{ + int num_images = getImageListSize(); + int i; + + // standard size bitmap may have changed -- update default bitmap pointer + for (i = 0; i < num_images; i++) + if (graphic_info[i].bitmaps) + graphic_info[i].bitmap = graphic_info[i].bitmaps[IMG_BITMAP_STANDARD]; +} + #if 1 /* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */ void SetBitmaps_EM(Bitmap **em_bitmap) @@ -947,13 +960,36 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) { char *value = getHashEntry(element_token_hash, value_raw); + if (value == NULL) + { + Error(ERR_INFO_LINE, "-"); + Error(ERR_INFO, "warning: error found in config file:"); + Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); + Error(ERR_INFO, "error: invalid element token '%s'", value_raw); + Error(ERR_INFO, "custom graphic rejected for this element/action"); + Error(ERR_INFO, "fallback done to undefined element for this graphic"); + Error(ERR_INFO_LINE, "-"); + } + return (value != NULL ? atoi(value) : EL_UNDEFINED); } else if (type == TYPE_GRAPHIC) { char *value = getHashEntry(graphic_token_hash, value_raw); + int fallback_graphic = IMG_CHAR_EXCLAM; - return (value != NULL ? atoi(value) : IMG_UNDEFINED); + if (value == NULL) + { + Error(ERR_INFO_LINE, "-"); + Error(ERR_INFO, "warning: error found in config file:"); + Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); + Error(ERR_INFO, "error: invalid graphic token '%s'", value_raw); + Error(ERR_INFO, "custom graphic rejected for this element/action"); + Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); + Error(ERR_INFO_LINE, "-"); + } + + return (value != NULL ? atoi(value) : fallback_graphic); } return -1; @@ -976,9 +1012,10 @@ static int get_scaled_graphic_height(int graphic) } static void set_graphic_parameters_ext(int graphic, int *parameter, - Bitmap *src_bitmap) + Bitmap **src_bitmaps) { struct GraphicInfo *g = &graphic_info[graphic]; + Bitmap *src_bitmap = (src_bitmaps ? src_bitmaps[IMG_BITMAP_STANDARD] : NULL); int anim_frames_per_row = 1, anim_frames_per_col = 1; int anim_frames_per_line = 1; @@ -1014,6 +1051,7 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->class = 0; g->style = STYLE_DEFAULT; + g->bitmaps = src_bitmaps; g->bitmap = src_bitmap; /* optional zoom factor for scaling up the image to a larger size */ @@ -1047,11 +1085,17 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->height = get_scaled_graphic_height(graphic); } + /* optional width and height of each animation frame */ + if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE) + g->width = parameter[GFX_ARG_WIDTH]; + if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE) + g->height = parameter[GFX_ARG_HEIGHT]; + /* optional x and y tile position of animation frame sequence */ if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE) - g->src_x = parameter[GFX_ARG_XPOS] * TILEX; + g->src_x = parameter[GFX_ARG_XPOS] * g->width; if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE) - g->src_y = parameter[GFX_ARG_YPOS] * TILEY; + g->src_y = parameter[GFX_ARG_YPOS] * g->height; /* optional x and y pixel position of animation frame sequence */ if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE) @@ -1059,12 +1103,6 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE) g->src_y = parameter[GFX_ARG_Y]; - /* optional width and height of each animation frame */ - if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE) - g->width = parameter[GFX_ARG_WIDTH]; - if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE) - g->height = parameter[GFX_ARG_HEIGHT]; - if (src_bitmap) { if (g->width <= 0) @@ -1263,7 +1301,7 @@ static void set_graphic_parameters(int graphic) { struct FileInfo *image = getImageListEntryFromImageID(graphic); char **parameter_raw = image->parameter; - Bitmap *src_bitmap = getBitmapFromImageID(graphic); + Bitmap **src_bitmaps = getBitmapsFromImageID(graphic); int parameter[NUM_GFX_ARGS]; int i; @@ -1277,7 +1315,7 @@ static void set_graphic_parameters(int graphic) image_config_suffix[i].token, image_config_suffix[i].type); - set_graphic_parameters_ext(graphic, parameter, src_bitmap); + set_graphic_parameters_ext(graphic, parameter, src_bitmaps); UPDATE_BUSY_STATE(); } @@ -1307,7 +1345,7 @@ static void set_cloned_graphic_parameters(int graphic) Error(ERR_INFO, "custom graphic rejected for this element/action"); if (graphic == fallback_graphic) - Error(ERR_EXIT, "fatal error: no fallback graphic available"); + Error(ERR_EXIT, "no fallback graphic available"); Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); Error(ERR_INFO_LINE, "-"); @@ -1453,7 +1491,7 @@ static void InitGraphicInfo() Error(ERR_INFO, "custom graphic rejected for this element/action"); if (i == fallback_graphic) - Error(ERR_EXIT, "fatal error: no fallback graphic available"); + Error(ERR_EXIT, "no fallback graphic available"); Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); Error(ERR_INFO_LINE, "-"); @@ -1482,7 +1520,7 @@ static void InitGraphicInfo() Error(ERR_INFO, "custom graphic rejected for this element/action"); if (i == fallback_graphic) - Error(ERR_EXIT, "fatal error: no fallback graphic available"); + Error(ERR_EXIT, "no fallback graphic available"); Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); Error(ERR_INFO_LINE, "-"); @@ -1887,6 +1925,8 @@ static void ReinitializeGraphics() print_timestamp_time("InitElementSmallImages"); InitScaledImages(); /* scale all other images, if needed */ print_timestamp_time("InitScaledImages"); + InitBitmapPointers(); /* set standard size bitmap pointers */ + print_timestamp_time("InitBitmapPointers"); InitFontGraphicInfo(); /* initialize text drawing functions */ print_timestamp_time("InitFontGraphicInfo"); @@ -4438,6 +4478,33 @@ static void InitGlobal() font_info[i].token_name, int2str(i, 0)); + /* set default filenames for all cloned graphics in static configuration */ + for (i = 0; image_config[i].token != NULL; i++) + { + if (strEqual(image_config[i].value, UNDEFINED_FILENAME)) + { + char *token = image_config[i].token; + char *token_clone_from = getStringCat2(token, ".clone_from"); + char *token_cloned = getHashEntry(image_config_hash, token_clone_from); + + if (token_cloned != NULL) + { + char *value_cloned = getHashEntry(image_config_hash, token_cloned); + + if (value_cloned != NULL) + { + /* set default filename in static configuration */ + image_config[i].value = value_cloned; + + /* set default filename in image config hash */ + setHashEntry(image_config_hash, token, value_cloned); + } + } + + free(token_clone_from); + } + } + /* always start with reliable default values (all elements) */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) ActiveElement[i] = i; @@ -4667,6 +4734,12 @@ void Execute_Command(char *command) Error(ERR_EXIT, "image target directory '%s' not found or not writable", global.create_images_dir); } + else if (strPrefix(command, "create CE image ")) + { + CreateCustomElementImages(&command[16]); + + exit(0); + } #if DEBUG #if defined(TARGET_SDL2) @@ -4947,6 +5020,9 @@ void InitGfxBuffers() InitGfxScrollbufferInfo(FXSIZE, FYSIZE); InitGfxClipRegion(FALSE, -1, -1, -1, -1); + /* required if door size definitions have changed */ + InitGraphicCompatibilityInfo_Doors(); + InitGfxBuffers_EM(); InitGfxBuffers_SP(); } @@ -4999,6 +5075,7 @@ void InitGfx() InitGfxBuffers(); InitGfxCustomArtworkInfo(); + InitGfxOtherSettings(); bitmap_font_initial = LoadCustomImage(filename_font_initial); @@ -5009,12 +5086,11 @@ void InitGfx() font_height = getFontHeight(FC_RED); - DrawInitTextAlways(getProgramInitString(), 20, FC_YELLOW); - DrawInitTextAlways(PROGRAM_COPYRIGHT_STRING, 50, FC_RED); - DrawInitTextAlways(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, - FC_RED); + DrawInitText(getProgramInitString(), 20, FC_YELLOW); + DrawInitText(PROGRAM_COPYRIGHT_STRING, 50, FC_RED); + DrawInitText(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, FC_RED); - DrawInitTextAlways("Loading graphics", 120, FC_GREEN); + DrawInitText("Loading graphics", 120, FC_GREEN); /* initialize busy animation with default values */ int parameter[NUM_GFX_ARGS]; @@ -5061,11 +5137,15 @@ void InitGfx() if (filename_anim_initial == NULL) /* should not happen */ Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_GLOBAL_BUSY); - anim_initial.bitmap = LoadCustomImage(filename_anim_initial); + anim_initial.bitmaps = + checked_calloc(sizeof(Bitmap *) * NUM_IMG_BITMAP_POINTERS); + + anim_initial.bitmaps[IMG_BITMAP_STANDARD] = + LoadCustomImage(filename_anim_initial); graphic_info = &anim_initial; /* graphic == 0 => anim_initial */ - set_graphic_parameters_ext(0, parameter, anim_initial.bitmap); + set_graphic_parameters_ext(0, parameter, anim_initial.bitmaps); graphic_info = graphic_info_last; @@ -5565,6 +5645,9 @@ void DisplayExitMessage(char *format, va_list ap) redraw_mask = REDRAW_ALL; + /* force drawing exit message even if screen updates are currently limited */ + LimitScreenUpdates(FALSE); + BackToFront(); /* deactivate toons on error message screen */ @@ -5590,6 +5673,10 @@ void OpenAll() print_timestamp_time("[init global stuff]"); + InitSetup(); + + print_timestamp_time("[init setup/config stuff (1)]"); + if (options.execute_command) Execute_Command(options.execute_command); @@ -5604,10 +5691,6 @@ void OpenAll() exit(0); /* never reached, server loops forever */ } - InitSetup(); - - print_timestamp_time("[init setup/config stuff (1)]"); - InitGameInfo(); print_timestamp_time("[init setup/config stuff (2)]"); InitPlayerInfo();