Sort the glyph cache and search it with bsearch
Also, recognize G_slime_mold and G_piletop_slime_mold when the fruit has been set.
This commit is contained in:
@@ -148,13 +148,18 @@ extern void perror(const char *);
|
|||||||
#ifdef POSIX_TYPES
|
#ifdef POSIX_TYPES
|
||||||
extern void qsort(genericptr_t, size_t, size_t,
|
extern void qsort(genericptr_t, size_t, size_t,
|
||||||
int (*)(const genericptr, const genericptr));
|
int (*)(const genericptr, const genericptr));
|
||||||
|
extern genericptr_t bsearch(const genericptr, const genericptr, size_t, size_t,
|
||||||
|
int (*)(const genericptr, const genericptr));
|
||||||
#else
|
#else
|
||||||
#if defined(BSD) || defined(ULTRIX)
|
#if defined(BSD) || defined(ULTRIX)
|
||||||
extern int qsort();
|
extern int qsort();
|
||||||
|
extern genericptr_t bsearch();
|
||||||
#else
|
#else
|
||||||
#if !defined(LATTICE) && !defined(AZTEC_50)
|
#if !defined(LATTICE) && !defined(AZTEC_50)
|
||||||
extern void qsort(genericptr_t, size_t, size_t,
|
extern void qsort(genericptr_t, size_t, size_t,
|
||||||
int (*)(const genericptr, const genericptr));
|
int (*)(const genericptr, const genericptr));
|
||||||
|
extern genericptr_t bsearch(const genericptr, const genericptr, size_t, size_t,
|
||||||
|
int (*)(const genericptr, const genericptr));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ struct glyphid_cache_t {
|
|||||||
int glyphnum;
|
int glyphnum;
|
||||||
char *id;
|
char *id;
|
||||||
};
|
};
|
||||||
struct glyphid_cache_t *glyphid_cache;
|
static struct glyphid_cache_t *glyphid_cache;
|
||||||
struct find_struct glyphcache_find, to_custom_symbol_find;
|
struct find_struct glyphcache_find, to_custom_symbol_find;
|
||||||
static void to_custom_symset_entry_callback(int glyph,
|
static void to_custom_symset_entry_callback(int glyph,
|
||||||
struct find_struct *findwhat);
|
struct find_struct *findwhat);
|
||||||
@@ -44,6 +44,8 @@ static int glyph_find_core(const char *id, struct find_struct *findwhat);
|
|||||||
static char *fix_glyphname(char *str);
|
static char *fix_glyphname(char *str);
|
||||||
static int32_t rgbstr_to_int32(const char *rgbstr);
|
static int32_t rgbstr_to_int32(const char *rgbstr);
|
||||||
boolean closest_color(uint32_t lcolor, uint32_t *closecolor, int *clridx);
|
boolean closest_color(uint32_t lcolor, uint32_t *closecolor, int *clridx);
|
||||||
|
static int glyphid_sort_compare(const void *p1, const void *p2);
|
||||||
|
static int glyphid_search_compare(const void *p1, const void *p2);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
to_custom_symset_entry_callback(int glyph, struct find_struct *findwhat)
|
to_custom_symset_entry_callback(int glyph, struct find_struct *findwhat)
|
||||||
@@ -335,6 +337,26 @@ void fill_glyphid_cache(void)
|
|||||||
glyphid_cache = (struct glyphid_cache_t *) 0;
|
glyphid_cache = (struct glyphid_cache_t *) 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (glyphid_cache) {
|
||||||
|
for (glyph = 0; glyph < MAX_GLYPH; ++glyph) {
|
||||||
|
if (glyphid_cache[glyph].id != NULL) {
|
||||||
|
lcase(glyphid_cache[glyph].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qsort(glyphid_cache, MAX_GLYPH, sizeof(glyphid_cache[0]),
|
||||||
|
glyphid_sort_compare);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
glyphid_sort_compare(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
const struct glyphid_cache_t *elem1 = (const struct glyphid_cache_t *) p1;
|
||||||
|
const struct glyphid_cache_t *elem2 = (const struct glyphid_cache_t *) p2;
|
||||||
|
const char *id1 = elem1->id ? elem1->id : "";
|
||||||
|
const char *id2 = elem2->id ? elem2->id : "";
|
||||||
|
|
||||||
|
return strcmp(id1, id2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_glyphid_cache(void)
|
void free_glyphid_cache(void)
|
||||||
@@ -601,18 +623,28 @@ parse_id(const char *id, struct find_struct *findwhat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_G || filling_cache || dump_ids) {
|
if (is_G || filling_cache || dump_ids) {
|
||||||
/* individual matching glyph entries */
|
if (!filling_cache && id && glyphid_cache) {
|
||||||
for (glyph = 0; glyph < MAX_GLYPH; ++glyph) {
|
char *id_l;
|
||||||
if (!filling_cache && id && glyphid_cache) {
|
const struct glyphid_cache_t *gptr;
|
||||||
if (!glyphid_cache[glyph].id) /* skipped during cache fill */
|
|
||||||
continue;
|
id_l = dupstr(id);
|
||||||
if (!strcmpi(id, glyphid_cache[glyph].id)) {
|
lcase(id_l);
|
||||||
findwhat->findtype = find_glyph;
|
gptr = (const struct glyphid_cache_t *)
|
||||||
findwhat->val = glyph;
|
bsearch(id_l, glyphid_cache, MAX_GLYPH,
|
||||||
findwhat->loadsyms_offset = 0;
|
sizeof(glyphid_cache[0]),
|
||||||
return 1;
|
glyphid_search_compare);
|
||||||
}
|
free(id_l);
|
||||||
|
if (gptr != NULL) {
|
||||||
|
findwhat->findtype = find_glyph;
|
||||||
|
findwhat->val = gptr->glyphnum;
|
||||||
|
findwhat->loadsyms_offset = 0;
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* individual matching glyph entries */
|
||||||
|
for (glyph = 0; glyph < MAX_GLYPH; ++glyph) {
|
||||||
skip_base = FALSE;
|
skip_base = FALSE;
|
||||||
skip_this_one = FALSE;
|
skip_this_one = FALSE;
|
||||||
buf[0][0] = buf[1][0] = buf[2][0] = buf[3][0] = buf[4][0] =
|
buf[0][0] = buf[1][0] = buf[2][0] = buf[3][0] = buf[4][0] =
|
||||||
@@ -700,6 +732,8 @@ parse_id(const char *id, struct find_struct *findwhat)
|
|||||||
(i == SCR_BLANK_PAPER) ? "blank scroll"
|
(i == SCR_BLANK_PAPER) ? "blank scroll"
|
||||||
: (i == SPE_BLANK_PAPER)
|
: (i == SPE_BLANK_PAPER)
|
||||||
? "blank spellbook"
|
? "blank spellbook"
|
||||||
|
: (i == SLIME_MOLD)
|
||||||
|
? "slime mold"
|
||||||
: obj_descr[i].oc_name);
|
: obj_descr[i].oc_name);
|
||||||
Snprintf(buf[1], sizeof buf[1], "%s%s%s",
|
Snprintf(buf[1], sizeof buf[1], "%s%s%s",
|
||||||
glyph_is_normal_piletop_obj(glyph)
|
glyph_is_normal_piletop_obj(glyph)
|
||||||
@@ -839,8 +873,8 @@ parse_id(const char *id, struct find_struct *findwhat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* not glyphid_cache */
|
}
|
||||||
}
|
} /* not glyphid_cache */
|
||||||
} else if (is_S) {
|
} else if (is_S) {
|
||||||
/* cmap entries */
|
/* cmap entries */
|
||||||
for (i = 0; i < cmap_count; ++i) {
|
for (i = 0; i < cmap_count; ++i) {
|
||||||
@@ -878,6 +912,16 @@ parse_id(const char *id, struct find_struct *findwhat)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
glyphid_search_compare(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
const char *key = (const char *) p1;
|
||||||
|
const struct glyphid_cache_t *elem = (const struct glyphid_cache_t *) p2;
|
||||||
|
const char *str = elem->id ? elem->id : "";
|
||||||
|
|
||||||
|
return strcmp(key, str);
|
||||||
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int index;
|
int index;
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
|
|||||||
Reference in New Issue
Block a user