+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)
{ ".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 },
{ ".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 },
-#define COMPILE_DATE_STRING "2007-04-27 03:49"
+#define COMPILE_DATE_STRING "2007-04-27 20:23"
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 ---------- */
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;
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;
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);
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();
image_config[i].token,
image_config[i].value);
}
+#endif
#if 1
/* always start with reliable default values from static default config */
#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];
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)
{
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);
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;
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) !!! */
x++;
}
+#endif
return -1;
}
static void InitGlobal()
{
+ int graphic;
int i;
for (i = 0; i < MAX_NUM_ELEMENTS + 1; i++)
#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;
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 :
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 :
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
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));
#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)
TYPE_KEY_X11 | \
TYPE_INTEGER | \
TYPE_STRING | \
- TYPE_TOKEN)
+ TYPE_ELEMENT | \
+ TYPE_GRAPHIC)
#define TYPE_SKIP_ENTRY (TYPE_EMPTY | \
TYPE_KEY | \
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;
/* ------------------------------------------------------------------------- */
{ "font.game_info" },
{ "font.info.elements" },
{ "font.info.levelset" },
+
+ { NULL }
};
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[];