From: Holger Schemel Date: Fri, 27 Apr 2007 18:40:57 +0000 (+0200) Subject: rnd-20070427-3-src X-Git-Tag: 3.2.4^2~23 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=30f635b58c076871cee2630ce15ffd7019764b2e;p=rocksndiamonds.git rnd-20070427-3-src * added use of hashes created from static lists (element tokens, image config, font tokens) to speed up lookup of configuration parameters * fixed bug where element and graphic config token lookup was mixed up --- diff --git a/ChangeLog b/ChangeLog index 3908154e..9141158e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-04-27 + * added use of hashes created from static lists (element tokens, image + config, font tokens) to speed up lookup of configuration parameters + * fixed bug where element and graphic config token lookup was mixed up + 2007-04-26 * added "busy" animation when initializing program and loading artwork * added initialization profiling for program startup (debugging only) diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 751876b5..139b61b4 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -43,8 +43,8 @@ struct ConfigTypeInfo image_config_suffix[] = { ".delay", "1", TYPE_INTEGER }, { ".anim_mode", ARG_UNDEFINED, TYPE_STRING }, { ".global_sync", "false", TYPE_BOOLEAN }, - { ".crumbled_like", ARG_UNDEFINED, TYPE_TOKEN }, - { ".diggable_like", ARG_UNDEFINED, TYPE_TOKEN }, + { ".crumbled_like", ARG_UNDEFINED, TYPE_ELEMENT }, + { ".diggable_like", ARG_UNDEFINED, TYPE_ELEMENT }, { ".border_size", ARG_UNDEFINED, TYPE_INTEGER }, { ".step_offset", "4", TYPE_INTEGER }, { ".step_delay", "1", TYPE_INTEGER }, @@ -59,7 +59,7 @@ struct ConfigTypeInfo image_config_suffix[] = { ".post_delay_random", ARG_UNDEFINED, TYPE_INTEGER }, { ".name", ARG_UNDEFINED, TYPE_STRING }, { ".scale_up_factor", ARG_UNDEFINED, TYPE_INTEGER }, - { ".clone_from", ARG_UNDEFINED, TYPE_TOKEN }, + { ".clone_from", ARG_UNDEFINED, TYPE_GRAPHIC }, { ".fade_mode", ARG_UNDEFINED, TYPE_INTEGER }, { ".fade_delay", ARG_UNDEFINED, TYPE_INTEGER }, { ".post_delay", ARG_UNDEFINED, TYPE_INTEGER }, diff --git a/src/conftime.h b/src/conftime.h index 757f0637..7d91c5ce 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2007-04-27 03:49" +#define COMPILE_DATE_STRING "2007-04-27 20:23" diff --git a/src/files.c b/src/files.c index 01c166e1..df605364 100644 --- a/src/files.c +++ b/src/files.c @@ -1694,8 +1694,8 @@ static int getFileTypeFromBasename(char *basename) return LEVEL_FILE_TYPE_SP; /* check for typical filename of a Diamond Caves II level package file */ - if (strEqualSuffix(basename, ".dc") || - strEqualSuffix(basename, ".dc2")) + if (strSuffix(basename, ".dc") || + strSuffix(basename, ".dc2")) return LEVEL_FILE_TYPE_DC; /* ---------- try to determine file type from filesize ---------- */ @@ -5767,7 +5767,7 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, fgets(magic_bytes, num_magic_bytes + 1, file); /* check "magic bytes" for correct file format */ - if (!strEqualPrefix(magic_bytes, "DC2")) + if (!strPrefix(magic_bytes, "DC2")) { level->no_valid_file = TRUE; @@ -5777,8 +5777,8 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, return; } - if (strEqualPrefix(magic_bytes, "DC2Win95") || - strEqualPrefix(magic_bytes, "DC2Win98")) + if (strPrefix(magic_bytes, "DC2Win95") || + strPrefix(magic_bytes, "DC2Win98")) { int position_first_level = 0x00fa; int extra_bytes = 4; @@ -8651,12 +8651,19 @@ void LoadCustomElementDescriptions() static int getElementFromToken(char *token) { +#if 1 + char *value = getHashEntry(element_token_hash, token); + + if (value != NULL) + return atoi(value); +#else int i; /* !!! OPTIMIZE THIS BY USING HASH !!! */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) if (strEqual(token, element_info[i].token_name)) return i; +#endif Error(ERR_WARN, "unknown element token '%s'", token); @@ -8700,9 +8707,12 @@ static int get_token_parameter_value(char *token, char *value_raw) void InitMenuDesignSettings_Static() { +#if 0 static SetupFileHash *image_config_hash = NULL; +#endif int i; +#if 0 if (image_config_hash == NULL) { image_config_hash = newSetupFileHash(); @@ -8712,6 +8722,7 @@ void InitMenuDesignSettings_Static() image_config[i].token, image_config[i].value); } +#endif #if 1 /* always start with reliable default values from static default config */ diff --git a/src/init.c b/src/init.c index bd166639..7a70610e 100644 --- a/src/init.c +++ b/src/init.c @@ -39,7 +39,7 @@ #define CONFIG_TOKEN_GLOBAL_BUSY "global.busy" #define DEBUG_PRINT_INIT_TIMESTAMPS TRUE -#define DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH 5 +#define DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH 3 static struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS]; @@ -97,7 +97,7 @@ static void print_init_timestamp(char *message) static int counter_nr = 0; int max_depth = DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH; - if (strEqualPrefix(message, "INIT")) + if (strPrefix(message, "INIT")) { if (counter_nr + 1 < max_depth) { @@ -109,19 +109,20 @@ static void print_init_timestamp(char *message) debug_print_timestamp(counter_nr, NULL); } - else if (strEqualPrefix(message, "DONE")) + else if (strPrefix(message, "DONE")) { counter_nr--; - if (counter_nr + 1 < max_depth) + if (counter_nr + 1 < max_depth || + (counter_nr == 0 && max_depth == 1)) { last_message = &message[4]; debug_print_timestamp(counter_nr, message); } } - else if (!strEqualPrefix(message, "TIME") || - !strEqualSuffix(message, last_message)) + else if (!strPrefix(message, "TIME") || + !strSuffix(message, last_message)) { if (counter_nr < max_depth) debug_print_timestamp(counter_nr, message); @@ -306,12 +307,19 @@ static int getFontBitmapID(int font_nr) static int getFontFromToken(char *token) { +#if 1 + char *value = getHashEntry(font_token_hash, token); + + if (value != NULL) + return atoi(value); +#else int i; /* !!! OPTIMIZE THIS BY USING HASH !!! */ for (i = 0; i < NUM_FONTS; i++) if (strEqual(token, font_info[i].token_name)) return i; +#endif /* if font not found, use reliable default value */ return FONT_INITIAL_1; @@ -1132,15 +1140,31 @@ void InitElementSpecialGraphicInfo() static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) { - int i; - int x = 0; - - if (type != TYPE_TOKEN) + if (type != TYPE_ELEMENT && type != TYPE_GRAPHIC) return get_parameter_value(value_raw, suffix, type); if (strEqual(value_raw, ARG_UNDEFINED)) return ARG_UNDEFINED_VALUE; +#if 1 + if (type == TYPE_ELEMENT) + { + char *value = getHashEntry(element_token_hash, value_raw); + + return (value != NULL ? atoi(value) : EL_UNDEFINED); + } + else if (type == TYPE_GRAPHIC) + { + char *value = getHashEntry(graphic_token_hash, value_raw); + + return (value != NULL ? atoi(value) : IMG_UNDEFINED); + } + +#else + + int i; + int x = 0; + /* !!! THIS IS BUGGY !!! NOT SURE IF YOU GET ELEMENT ID OR GRAPHIC ID !!! */ /* !!! (possible reason why ".clone_from" with elements doesn't work) !!! */ @@ -1164,6 +1188,7 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) x++; } +#endif return -1; } @@ -4798,6 +4823,7 @@ void InitElementPropertiesAfterLoading(int engine_version) static void InitGlobal() { + int graphic; int i; for (i = 0; i < MAX_NUM_ELEMENTS + 1; i++) @@ -4815,6 +4841,37 @@ static void InitGlobal() #endif } + /* create hash from image config list */ + image_config_hash = newSetupFileHash(); + for (i = 0; image_config[i].token != NULL; i++) + setHashEntry(image_config_hash, + image_config[i].token, + image_config[i].value); + + /* create hash from element token list */ + element_token_hash = newSetupFileHash(); + for (i = 0; element_name_info[i].token_name != NULL; i++) + setHashEntry(element_token_hash, + element_name_info[i].token_name, + int2str(i, 0)); + + /* create hash from graphic token list */ + graphic_token_hash = newSetupFileHash(); + for (graphic = 0, i = 0; image_config[i].token != NULL; i++) + if (strSuffix(image_config[i].value, ".pcx") || + strSuffix(image_config[i].value, ".wav") || + strEqual(image_config[i].value, UNDEFINED_FILENAME)) + setHashEntry(graphic_token_hash, + image_config[i].token, + int2str(graphic++, 0)); + + /* create hash from font token list */ + font_token_hash = newSetupFileHash(); + for (i = 0; font_info[i].token_name != NULL; i++) + setHashEntry(font_token_hash, + font_info[i].token_name, + int2str(i, 0)); + /* always start with reliable default values (all elements) */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) ActiveElement[i] = i; diff --git a/src/libgame/misc.c b/src/libgame/misc.c index bfb2164e..a20948d5 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -607,7 +607,7 @@ boolean strEqualN(char *s1, char *s2, int n) strncmp(s1, s2, n) == 0); } -boolean strEqualPrefix(char *s, char *prefix) +boolean strPrefix(char *s, char *prefix) { return (s == NULL && prefix == NULL ? TRUE : s == NULL && prefix != NULL ? FALSE : @@ -615,7 +615,7 @@ boolean strEqualPrefix(char *s, char *prefix) strncmp(s, prefix, strlen(prefix)) == 0); } -boolean strEqualSuffix(char *s, char *suffix) +boolean strSuffix(char *s, char *suffix) { return (s == NULL && suffix == NULL ? TRUE : s == NULL && suffix != NULL ? FALSE : @@ -1888,7 +1888,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type) FADE_MODE_DEFAULT); } #if 1 - else if (strEqualPrefix(suffix, ".font")) /* (may also be ".font_xyz") */ + else if (strPrefix(suffix, ".font")) /* (may also be ".font_xyz") */ #else else if (strEqualN(suffix, ".font", 5)) /* (may also be ".font_xyz") */ #endif diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 36544b4d..29aaee70 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -108,8 +108,8 @@ char *getStringToLower(char *); void setString(char **, char *); boolean strEqual(char *, char *); boolean strEqualN(char *, char *, int); -boolean strEqualPrefix(char *, char *); -boolean strEqualSuffix(char *, char *); +boolean strPrefix(char *, char *); +boolean strSuffix(char *, char *); void GetOptions(char **, void (*print_usage_function)(void)); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 571cdbcc..02a815ab 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -27,24 +27,24 @@ #define TYPE_KEY_X11 (1 << 5) #define TYPE_INTEGER (1 << 6) #define TYPE_STRING (1 << 7) -#define TYPE_TOKEN (1 << 8) +#define TYPE_ELEMENT (1 << 8) +#define TYPE_GRAPHIC (1 << 9) /* additional values for setup screen */ -#define TYPE_ENTER_SCREEN (1 << 9) -#define TYPE_LEAVE_SCREEN (1 << 10) -#define TYPE_ENTER_MENU (1 << 11) -#define TYPE_LEAVE_MENU (1 << 12) -#define TYPE_ENTER_LIST (1 << 13) -#define TYPE_LEAVE_LIST (1 << 14) -#define TYPE_EMPTY (1 << 15) -#define TYPE_KEYTEXT (1 << 16) - -#define TYPE_GHOSTED (1 << 17) -#define TYPE_QUERY (1 << 18) +#define TYPE_ENTER_SCREEN (1 << 10) +#define TYPE_LEAVE_SCREEN (1 << 11) +#define TYPE_ENTER_MENU (1 << 12) +#define TYPE_LEAVE_MENU (1 << 13) +#define TYPE_ENTER_LIST (1 << 14) +#define TYPE_LEAVE_LIST (1 << 15) +#define TYPE_EMPTY (1 << 16) +#define TYPE_KEYTEXT (1 << 17) + +#define TYPE_GHOSTED (1 << 18) +#define TYPE_QUERY (1 << 19) /* additional values for internal purposes */ -#define TYPE_BITFIELD (1 << 19) -#define TYPE_ELEMENT (1 << 20) +#define TYPE_BITFIELD (1 << 20) #define TYPE_CONTENT (1 << 21) #define TYPE_ELEMENT_LIST (1 << 22) #define TYPE_CONTENT_LIST (1 << 23) @@ -61,7 +61,8 @@ TYPE_KEY_X11 | \ TYPE_INTEGER | \ TYPE_STRING | \ - TYPE_TOKEN) + TYPE_ELEMENT | \ + TYPE_GRAPHIC) #define TYPE_SKIP_ENTRY (TYPE_EMPTY | \ TYPE_KEY | \ diff --git a/src/main.c b/src/main.c index 5813fbd6..4971e8c7 100644 --- a/src/main.c +++ b/src/main.c @@ -128,6 +128,10 @@ struct MusicInfo *music_info = NULL; struct MusicFileInfo *music_file_info = NULL; struct HelpAnimInfo *helpanim_info = NULL; SetupFileHash *helptext_info = NULL; +SetupFileHash *image_config_hash = NULL; +SetupFileHash *element_token_hash = NULL; +SetupFileHash *graphic_token_hash = NULL; +SetupFileHash *font_token_hash = NULL; /* ------------------------------------------------------------------------- */ @@ -5481,6 +5485,8 @@ struct FontInfo font_info[NUM_FONTS + 1] = { "font.game_info" }, { "font.info.elements" }, { "font.info.levelset" }, + + { NULL } }; diff --git a/src/main.h b/src/main.h index bc09a36d..7e5ff0df 100644 --- a/src/main.h +++ b/src/main.h @@ -2794,6 +2794,10 @@ extern struct MusicInfo *music_info; extern struct MusicFileInfo *music_file_info; extern struct HelpAnimInfo *helpanim_info; extern SetupFileHash *helptext_info; +extern SetupFileHash *image_config_hash; +extern SetupFileHash *element_token_hash; +extern SetupFileHash *graphic_token_hash; +extern SetupFileHash *font_token_hash; extern struct ConfigTypeInfo image_config_suffix[]; extern struct ConfigTypeInfo sound_config_suffix[]; extern struct ConfigTypeInfo music_config_suffix[];