X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=8026ab9d510a6d1cc898a446c4dcde3d1e44314b;hb=9ec014a4e4a6a2332bb45c6cea8cccc46c64c6ae;hp=cf6987dbb83eda0ce3bbdd4325ac0b8818cd13b7;hpb=84a3ee86461e2311032274e0b7d7a857e02a76ab;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index cf6987db..8026ab9d 100644 --- a/src/init.c +++ b/src/init.c @@ -28,9 +28,11 @@ #include "conf_e2g.c" /* include auto-generated data structure definitions */ #include "conf_esg.c" /* include auto-generated data structure definitions */ +#include "conf_fnt.c" /* include auto-generated data structure definitions */ +#define CONFIG_TOKEN_FONT_INITIAL "font.initial" -static Bitmap *bitmap_font_initial = NULL; +struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS]; static void InitGlobal(); static void InitSetup(); @@ -47,6 +49,7 @@ static void InitMusic(); static void InitGfx(); static void InitGfxBackground(); static void InitGadgets(); +static void InitFontGraphicInfo(); static void InitElementSmallImages(); static void InitElementGraphicInfo(); static void InitElementSpecialGraphicInfo(); @@ -161,11 +164,11 @@ static void InitArtworkInfo() static void InitArtworkConfig() { - static char *element_prefix[MAX_NUM_ELEMENTS + 1]; - static char *sound_class_prefix[MAX_NUM_ELEMENTS + 1]; - static char *action_suffix[NUM_ACTIONS + 1]; - static char *direction_suffix[NUM_DIRECTIONS + 1]; - static char *special_suffix[NUM_SPECIAL_GFX_ARGS + 1]; + static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1]; + static char *sound_id_prefix[MAX_NUM_ELEMENTS + 1]; + static char *action_id_suffix[NUM_ACTIONS + 1]; + static char *direction_id_suffix[NUM_DIRECTIONS + 1]; + static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1]; static char *dummy[1] = { NULL }; static char *ignore_image_tokens[] = { @@ -175,24 +178,37 @@ static void InitArtworkConfig() "global.num_toons", NULL }; + static char *ignore_sound_tokens[] = + { + "name", + "sort_priority", + NULL + }; int i; + for (i=0; i len_font_token && + strncmp(image_config[i].token, font_token, len_font_token) == 0) + { + if (strcmp(&image_config[i].token[len_font_token], ".x") == 0) + font_initial[j].src_x = atoi(image_config[i].value); + else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0) + font_initial[j].src_y = atoi(image_config[i].value); + else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0) + font_initial[j].width = atoi(image_config[i].value); + else if (strcmp(&image_config[i].token[len_font_token],".height") == 0) + font_initial[j].height = atoi(image_config[i].value); + } + } + } if (filename_font_initial == NULL) /* should not happen */ - Error(ERR_EXIT, "cannot get filename for '%s'", config_token_font_initial); + Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); /* initialize screen properties */ InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE, @@ -486,7 +520,10 @@ void InitGfx() bitmap_font_initial = LoadCustomImage(filename_font_initial); - InitFontInfo(bitmap_font_initial, NULL, NULL, NULL, NULL); + for (j=0; j < NUM_INITIAL_FONTS; j++) + font_initial[j].bitmap = bitmap_font_initial; + + InitFontGraphicInfo(); DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); @@ -694,7 +731,130 @@ void InitElementSmallImages() /* initialize images from dynamic configuration */ for (i=0; i < num_property_mappings; i++) - CreateImageWithSmallImages(property_mapping[i].artwork_index); + if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS) + CreateImageWithSmallImages(property_mapping[i].artwork_index); +} + +static int getFontBitmapID(int font_nr) +{ + if (game_status == LEVELED) + return font_info[font_nr].special_bitmap_id[GFX_SPECIAL_ARG_EDITOR]; + else + return font_nr; +} + +void InitFontGraphicInfo() +{ + static struct FontBitmapInfo *font_bitmap_info = NULL; + struct PropertyMapping *property_mapping = getImageListPropertyMapping(); + int num_property_mappings = getImageListPropertyMappingSize(); + int num_font_bitmaps = NUM_FONTS; + int i, j; + + if (graphic_info == NULL) /* still at startup phase */ + { + InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID); + + return; + } + + /* ---------- initialize font graphic definitions ---------- */ + + /* always start with reliable default values (normal font graphics) */ + for (i=0; i < NUM_FONTS; i++) + font_info[i].graphic = FONT_INITIAL_1; + + /* initialize normal font/graphic mapping from static configuration */ + for (i=0; font_to_graphic[i].font_nr > -1; i++) + { + int font_nr = font_to_graphic[i].font_nr; + int special = font_to_graphic[i].special; + int graphic = font_to_graphic[i].graphic; + + if (special != -1) + continue; + + font_info[font_nr].graphic = graphic; + } + + /* always start with reliable default values (special font graphics) */ + for (i=0; i < NUM_FONTS; i++) + { + for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++) + { + font_info[i].special_graphic[j] = font_info[i].graphic; + font_info[i].special_bitmap_id[j] = i; + } + } + + /* initialize special font/graphic mapping from static configuration */ + for (i=0; font_to_graphic[i].font_nr > -1; i++) + { + int font_nr = font_to_graphic[i].font_nr; + int special = font_to_graphic[i].special; + int graphic = font_to_graphic[i].graphic; + + if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS) + { + font_info[font_nr].special_graphic[special] = graphic; + font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps; + num_font_bitmaps++; + } + } + + /* initialize special element/graphic mapping from dynamic configuration */ + for (i=0; i < num_property_mappings; i++) + { + int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS; + int special = property_mapping[i].ext3_index; + int graphic = property_mapping[i].artwork_index; + + if (font_nr < 0) + continue; + + if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS) + { + font_info[font_nr].special_graphic[special] = graphic; + font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps; + num_font_bitmaps++; + } + } + + /* ---------- initialize font bitmap array ---------- */ + + if (font_bitmap_info != NULL) + free(font_bitmap_info); + + font_bitmap_info = + checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo)); + + /* ---------- initialize font bitmap definitions ---------- */ + + for (i=0; i < NUM_FONTS; i++) + { + if (i < NUM_INITIAL_FONTS) + { + font_bitmap_info[i] = font_initial[i]; + continue; + } + + for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++) + { + int font_bitmap_id = font_info[i].special_bitmap_id[j]; + int graphic = font_info[i].special_graphic[j]; + + /* copy font relevant information from graphics information */ + font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap; + font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x; + font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y; + font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width; + font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height; + font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x; + font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y; + } + } + + InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID); } void InitElementGraphicInfo() @@ -715,16 +875,6 @@ void InitElementGraphicInfo() } } -#if 0 - for (i=EL_CHAR_START; i<=EL_CHAR_END; i++) - element_info[i].graphic[ACTION_DEFAULT] = - IMG_CHAR_START + (i - EL_CHAR_START); - - for (i=EL_CUSTOM_START; i<=EL_CUSTOM_END; i++) - element_info[i].graphic[ACTION_DEFAULT] = - IMG_CUSTOM_START + (i - EL_CUSTOM_START); -#endif - /* initialize normal element/graphic mapping from static configuration */ for (i=0; element_to_graphic[i].element > -1; i++) { @@ -751,7 +901,7 @@ void InitElementGraphicInfo() int special = property_mapping[i].ext3_index; int graphic = property_mapping[i].artwork_index; - if (special != -1) + if (element >= MAX_NUM_ELEMENTS || special != -1) continue; if (action < 0) @@ -820,14 +970,13 @@ void InitElementSpecialGraphicInfo() { struct PropertyMapping *property_mapping = getImageListPropertyMapping(); int num_property_mappings = getImageListPropertyMappingSize(); - int i; + int i, j; /* always start with reliable default values */ - for (i=0; i -1; i++) @@ -841,10 +990,7 @@ void InitElementSpecialGraphicInfo() if (base_redefined && !special_redefined) continue; - if (special == GFX_SPECIAL_ARG_EDITOR) - element_info[element].editor_graphic = graphic; - else if (special == GFX_SPECIAL_ARG_PREVIEW) - element_info[element].preview_graphic = graphic; + element_info[element].special_graphic[special] = graphic; } /* initialize special element/graphic mapping from dynamic configuration */ @@ -854,10 +1000,11 @@ void InitElementSpecialGraphicInfo() int special = property_mapping[i].ext3_index; int graphic = property_mapping[i].artwork_index; - if (special == GFX_SPECIAL_ARG_EDITOR) - element_info[element].editor_graphic = graphic; - else if (special == GFX_SPECIAL_ARG_PREVIEW) - element_info[element].preview_graphic = graphic; + if (element >= MAX_NUM_ELEMENTS) + continue; + + if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS) + element_info[element].special_graphic[special] = graphic; } } @@ -973,17 +1120,22 @@ static void set_graphic_parameters(int graphic, char **parameter_raw) /* this is only used for toon animations */ graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET]; graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY]; + + /* this is only used for drawing font characters */ + graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET]; + graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET]; } static void InitGraphicInfo() { - static boolean clipmasks_initialized = FALSE; int fallback_graphic = IMG_CHAR_EXCLAM; struct FileInfo *fallback_image = getImageListEntry(fallback_graphic); Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic); int num_images = getImageListSize(); int i; + #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) + static boolean clipmasks_initialized = FALSE; Pixmap src_pixmap; XGCValues clip_gc_values; unsigned long clip_gc_valuemask; @@ -1105,6 +1257,7 @@ static void InitGraphicInfo() clip_gc_values.graphics_exposures = False; clip_gc_values.clip_mask = graphic_info[i].clip_mask; clip_gc_valuemask = GCGraphicsExposures | GCClipMask; + graphic_info[i].clip_gc = XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values); #endif @@ -1113,9 +1266,9 @@ static void InitGraphicInfo() #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) if (copy_clipmask_gc) XFreeGC(display, copy_clipmask_gc); -#endif clipmasks_initialized = TRUE; +#endif } static void InitElementSoundInfo() @@ -1335,7 +1488,6 @@ void InitElementProperties() static int ep_solid[] = { - EL_STEELWALL, EL_WALL, EL_WALL_GROWING, EL_WALL_GROWING_X, @@ -1369,16 +1521,43 @@ void InitElementProperties() EL_BD_MAGIC_WALL_DEAD, EL_GAMEOFLIFE, EL_BIOMAZE, - EL_ACIDPOOL_TOPLEFT, - EL_ACIDPOOL_TOPRIGHT, - EL_ACIDPOOL_BOTTOMLEFT, - EL_ACIDPOOL_BOTTOM, - EL_ACIDPOOL_BOTTOMRIGHT, EL_SP_CHIP_SINGLE, EL_SP_CHIP_LEFT, EL_SP_CHIP_RIGHT, EL_SP_CHIP_UPPER, EL_SP_CHIP_LOWER, + EL_SP_TERMINAL, + EL_SP_TERMINAL_ACTIVE, + EL_SP_EXIT_CLOSED, + EL_SP_EXIT_OPEN, + EL_INVISIBLE_WALL, + EL_INVISIBLE_WALL_ACTIVE, + EL_SWITCHGATE_SWITCH_UP, + EL_SWITCHGATE_SWITCH_DOWN, + EL_TIMEGATE_SWITCH, + EL_TIMEGATE_SWITCH_ACTIVE, + EL_EMC_WALL_PILLAR_UPPER, + EL_EMC_WALL_PILLAR_MIDDLE, + EL_EMC_WALL_PILLAR_LOWER, + EL_EMC_WALL4, + EL_EMC_WALL5, + EL_EMC_WALL6, + EL_EMC_WALL7, + EL_EMC_WALL8, + EL_WALL_PEARL, + EL_WALL_CRYSTAL, + + /* the following elements are a direct copy of "indestructible" elements, + except "EL_ACID", which is "indestructible", but not "solid"! */ +#if 0 + EL_ACID, +#endif + EL_STEELWALL, + EL_ACIDPOOL_TOPLEFT, + EL_ACIDPOOL_TOPRIGHT, + EL_ACIDPOOL_BOTTOMLEFT, + EL_ACIDPOOL_BOTTOM, + EL_ACIDPOOL_BOTTOMRIGHT, EL_SP_HARD_GRAY, EL_SP_HARD_GREEN, EL_SP_HARD_BLUE, @@ -1390,14 +1569,8 @@ void InitElementProperties() EL_SP_HARD_BASE4, EL_SP_HARD_BASE5, EL_SP_HARD_BASE6, - EL_SP_TERMINAL, - EL_SP_TERMINAL_ACTIVE, - EL_SP_EXIT_CLOSED, - EL_SP_EXIT_OPEN, EL_INVISIBLE_STEELWALL, EL_INVISIBLE_STEELWALL_ACTIVE, - EL_INVISIBLE_WALL, - EL_INVISIBLE_WALL_ACTIVE, EL_CONVEYOR_BELT1_SWITCH_LEFT, EL_CONVEYOR_BELT1_SWITCH_MIDDLE, EL_CONVEYOR_BELT1_SWITCH_RIGHT, @@ -1410,12 +1583,8 @@ void InitElementProperties() EL_CONVEYOR_BELT4_SWITCH_LEFT, EL_CONVEYOR_BELT4_SWITCH_MIDDLE, EL_CONVEYOR_BELT4_SWITCH_RIGHT, - EL_SWITCHGATE_SWITCH_UP, - EL_SWITCHGATE_SWITCH_DOWN, EL_LIGHT_SWITCH, EL_LIGHT_SWITCH_ACTIVE, - EL_TIMEGATE_SWITCH, - EL_TIMEGATE_SWITCH_ACTIVE, EL_SIGN_EXCLAMATION, EL_SIGN_RADIOACTIVITY, EL_SIGN_STOP, @@ -1433,17 +1602,7 @@ void InitElementProperties() EL_EMC_STEELWALL2, EL_EMC_STEELWALL3, EL_EMC_STEELWALL4, - EL_EMC_WALL_PILLAR_UPPER, - EL_EMC_WALL_PILLAR_MIDDLE, - EL_EMC_WALL_PILLAR_LOWER, - EL_EMC_WALL4, - EL_EMC_WALL5, - EL_EMC_WALL6, - EL_EMC_WALL7, - EL_EMC_WALL8, EL_CRYSTAL, - EL_WALL_PEARL, - EL_WALL_CRYSTAL, EL_GATE1, EL_GATE2, EL_GATE3, @@ -1482,7 +1641,7 @@ void InitElementProperties() }; static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid); - static int ep_massive[] = + static int ep_indestructible[] = { EL_STEELWALL, EL_ACID, @@ -1572,7 +1731,7 @@ void InitElementProperties() EL_TUBE_RIGHT_UP, EL_TUBE_RIGHT_DOWN }; - static int ep_massive_num = SIZEOF_ARRAY_INT(ep_massive); + static int ep_indestructible_num = SIZEOF_ARRAY_INT(ep_indestructible); static int ep_slippery[] = { @@ -2330,7 +2489,7 @@ void InitElementProperties() EP_BIT_SCHLUESSEL, EP_BIT_PFORTE, EP_BIT_SOLID, - EP_BIT_MASSIVE, + EP_BIT_INDESTRUCTIBLE, EP_BIT_SLIPPERY, EP_BIT_ENEMY, EP_BIT_MAUER, @@ -2371,7 +2530,7 @@ void InitElementProperties() ep_schluessel, ep_pforte, ep_solid, - ep_massive, + ep_indestructible, ep_slippery, ep_enemy, ep_mauer, @@ -2412,7 +2571,7 @@ void InitElementProperties() &ep_schluessel_num, &ep_pforte_num, &ep_solid_num, - &ep_massive_num, + &ep_indestructible_num, &ep_slippery_num, &ep_enemy_num, &ep_mauer_num, @@ -2570,9 +2729,6 @@ void CloseAllAndExit(int exit_value) FreeAllImages(); FreeTileClipmasks(); - if (bitmap_font_initial) - FreeBitmap(bitmap_font_initial); - CloseVideoDisplay(); ClosePlatformDependantStuff();