sever extracolors from utf8map and ENHANCED_SYMBOLS

move the custom color data into its own field in the glyphmap
and disassociate it from the unicode/utf8 stuff.

move the glyphcache stuff during options processing and parsing
into new file glyphs.c and out of utf8map.c, and make it
general, and not part of ENHANCED_SYMBOLS.

Do the groundwork for allowing glyph color customizations to
work when any symset is loaded and not restrict it only to
the enhanced1 H_UTF8 symsets.

The customizations in effect are still affiliated with a particular
symset.

Also closes #1224, but the PR itself references a data structure
made obsolete by this commit. The curses comment from the PR was
added into the code.

The PR also made several suggestions, but only the first
one has been included in this commit (and no longer based on
the handler), that being:
"allow defining colors if other symbol handling modes are used
(possibly limited to the standard 16 colors)."

FredrIQ also wrote the following suggestions in PR#1224:

Something I was also contemplating, unrelated to implementation of this
support in curses, would be the ability for the following:

allow defining colors if other symbol handling modes are used (possibly limited to the standard 16 colors)
allow defining attributes (for example: glyph:G_pet_female_kitten:U+0066/red/underline)
allow specifying glyphs as wildcards for defining global color/attribute changes

Something I also want to see are keywords for "don't change the current defined data". If this
were to be added, you could for example do this:
OPTIONS=glyph:G_*_fox:U+0064/blue
OPTIONS=glyph:G_statue_*:basechar/gray/underline
for "make all foxes use a blue color, make all statues gray with underline" without needing
to specify the relevant character for every statue. This ("basechar", "basefg", etc)
should perhaps also be added for MENUCOLORS and statushilites, so that you can, for
example, underline all items being worn without needing to specify a bunch of
near-duplicate rules for combining BUC colors + underline worn items
as per #1064
This commit is contained in:
nhmall
2024-03-23 15:33:00 -04:00
parent ef17c7ac2b
commit ba00dc9066
36 changed files with 1799 additions and 1589 deletions

View File

@@ -911,9 +911,7 @@ static const struct early_opt earlyopts[] = {
#ifndef NODUMPENUMS
{ ARG_DUMPENUMS, "dumpenums", 9, FALSE },
#endif
#ifdef ENHANCED_SYMBOLS
{ ARG_DUMPGLYPHIDS, "dumpglyphids", 12, FALSE },
#endif
#ifdef WIN32
{ ARG_WINDOWS, "windows", 4, TRUE },
#endif
@@ -1012,11 +1010,9 @@ argcheck(int argc, char *argv[], enum earlyarg e_arg)
dump_enums();
return 2;
#endif
#ifdef ENHANCED_SYMBOLS
case ARG_DUMPGLYPHIDS:
dump_glyphids();
return 2;
#endif
#ifdef CRASHREPORT
case ARG_BIDSHOW:
crashreport_bidshow();
@@ -1113,7 +1109,7 @@ timet_delta(time_t etim, time_t stim) /* end and start times */
return (long) difftime(etim, stim);
}
#if !defined(NODUMPENUMS) || defined(ENHANCED_SYMBOLS)
#if !defined(NODUMPENUMS)
/* monsdump[] and objdump[] are also used in utf8map.c */
#define DUMP_ENUMS
@@ -1277,13 +1273,11 @@ dump_enums(void)
}
#endif /* NODUMPENUMS */
#ifdef ENHANCED_SYMBOLS
void
dump_glyphids(void)
{
dump_all_glyphids(stdout);
}
#endif /* ENHANCED_SYMBOLS */
#endif /* !NODUMPENUMS || ENHANCED_SYMBOLS */
#endif /* !NODUMPENUMS */
/*allmain.c*/

View File

@@ -219,6 +219,8 @@ static struct nethack_color colortable[] = {
{ rgb_color, 154, 138, "white", "#FFFFFF", 255, 255, 255 },
};
static const char hex[] = "00112233445566778899aAbBcCdDeEfF";
int32
colortable_to_int32(struct nethack_color *cte)
{
@@ -782,4 +784,231 @@ wc_color_name(int32 colorindx)
return result;
}
boolean
onlyhexdigits(const char *buf)
{
const char *dp = buf;
for (dp = buf; *dp; ++dp) {
if (!(strchr(hex, *dp) || *dp == '-'))
return FALSE;
}
return TRUE;
}
int32_t
rgbstr_to_int32(const char *rgbstr)
{
int r, g, b, milestone = 0;
char *cp, *c_r, *c_g, *c_b;
int32_t rgb = 0;
char buf[BUFSZ];
boolean dash = FALSE;
Snprintf(buf, sizeof buf, "%s",
rgbstr ? rgbstr : "");
if (*buf && onlyhexdigits(buf)) {
r = g = b = 0;
c_g = c_b = (char *) 0;
c_r = cp = buf;
while (*cp) {
if (digit(*cp) || *cp == '-') {
if (*cp == '-') {
*cp = '\0';
milestone++;
dash = TRUE;
}
cp++;
if (dash) {
if (milestone < 2)
c_g = cp;
else
c_b = cp;
dash = FALSE;
}
} else {
return -1L;
}
}
/* sanity checks */
if (c_r && c_g && c_b
&& (strlen(c_r) > 0 && strlen(c_r) < 4)
&& (strlen(c_g) > 0 && strlen(c_g) < 4)
&& (strlen(c_b) > 0 && strlen(c_b) < 4)) {
r = atoi(c_r);
g = atoi(c_g);
b = atoi(c_b);
rgb = (r << 16) | (g << 8) | (b << 0);
return rgb;
}
} else if (*buf) {
/* perhaps an enhanced color name was used instead of rgb value? */
if ((rgb = check_enhanced_colors(buf)) != -1) {
return rgb;
}
}
return -1;
}
int
set_map_nhcolor(glyph_map *gmap, uint32 nhcolor)
{
glyph_map *tmpgm = gmap;
if (!tmpgm)
return 0;
gmap->nhcolor = nhcolor;
return 1;
}
static struct {
int index;
uint32 value;
} color_256_definitions[] = {
/* color values are from unnethack */
{ 16, 0x000000 }, { 17, 0x00005f }, { 18, 0x000087 },
{ 19, 0x0000af }, { 20, 0x0000d7 }, { 21, 0x0000ff },
{ 22, 0x005f00 }, { 23, 0x005f5f }, { 24, 0x005f87 },
{ 25, 0x005faf }, { 26, 0x005fd7 }, { 27, 0x005fff },
{ 28, 0x008700 }, { 29, 0x00875f }, { 30, 0x008787 },
{ 31, 0x0087af }, { 32, 0x0087d7 }, { 33, 0x0087ff },
{ 34, 0x00af00 }, { 35, 0x00af5f }, { 36, 0x00af87 },
{ 37, 0x00afaf }, { 38, 0x00afd7 }, { 39, 0x00afff },
{ 40, 0x00d700 }, { 41, 0x00d75f }, { 42, 0x00d787 },
{ 43, 0x00d7af }, { 44, 0x00d7d7 }, { 45, 0x00d7ff },
{ 46, 0x00ff00 }, { 47, 0x00ff5f }, { 48, 0x00ff87 },
{ 49, 0x00ffaf }, { 50, 0x00ffd7 }, { 51, 0x00ffff },
{ 52, 0x5f0000 }, { 53, 0x5f005f }, { 54, 0x5f0087 },
{ 55, 0x5f00af }, { 56, 0x5f00d7 }, { 57, 0x5f00ff },
{ 58, 0x5f5f00 }, { 59, 0x5f5f5f }, { 60, 0x5f5f87 },
{ 61, 0x5f5faf }, { 62, 0x5f5fd7 }, { 63, 0x5f5fff },
{ 64, 0x5f8700 }, { 65, 0x5f875f }, { 66, 0x5f8787 },
{ 67, 0x5f87af }, { 68, 0x5f87d7 }, { 69, 0x5f87ff },
{ 70, 0x5faf00 }, { 71, 0x5faf5f }, { 72, 0x5faf87 },
{ 73, 0x5fafaf }, { 74, 0x5fafd7 }, { 75, 0x5fafff },
{ 76, 0x5fd700 }, { 77, 0x5fd75f }, { 78, 0x5fd787 },
{ 79, 0x5fd7af }, { 80, 0x5fd7d7 }, { 81, 0x5fd7ff },
{ 82, 0x5fff00 }, { 83, 0x5fff5f }, { 84, 0x5fff87 },
{ 85, 0x5fffaf }, { 86, 0x5fffd7 }, { 87, 0x5fffff },
{ 88, 0x870000 }, { 89, 0x87005f }, { 90, 0x870087 },
{ 91, 0x8700af }, { 92, 0x8700d7 }, { 93, 0x8700ff },
{ 94, 0x875f00 }, { 95, 0x875f5f }, { 96, 0x875f87 },
{ 97, 0x875faf }, { 98, 0x875fd7 }, { 99, 0x875fff },
{ 100, 0x878700 }, { 101, 0x87875f }, { 102, 0x878787 },
{ 103, 0x8787af }, { 104, 0x8787d7 }, { 105, 0x8787ff },
{ 106, 0x87af00 }, { 107, 0x87af5f }, { 108, 0x87af87 },
{ 109, 0x87afaf }, { 110, 0x87afd7 }, { 111, 0x87afff },
{ 112, 0x87d700 }, { 113, 0x87d75f }, { 114, 0x87d787 },
{ 115, 0x87d7af }, { 116, 0x87d7d7 }, { 117, 0x87d7ff },
{ 118, 0x87ff00 }, { 119, 0x87ff5f }, { 120, 0x87ff87 },
{ 121, 0x87ffaf }, { 122, 0x87ffd7 }, { 123, 0x87ffff },
{ 124, 0xaf0000 }, { 125, 0xaf005f }, { 126, 0xaf0087 },
{ 127, 0xaf00af }, { 128, 0xaf00d7 }, { 129, 0xaf00ff },
{ 130, 0xaf5f00 }, { 131, 0xaf5f5f }, { 132, 0xaf5f87 },
{ 133, 0xaf5faf }, { 134, 0xaf5fd7 }, { 135, 0xaf5fff },
{ 136, 0xaf8700 }, { 137, 0xaf875f }, { 138, 0xaf8787 },
{ 139, 0xaf87af }, { 140, 0xaf87d7 }, { 141, 0xaf87ff },
{ 142, 0xafaf00 }, { 143, 0xafaf5f }, { 144, 0xafaf87 },
{ 145, 0xafafaf }, { 146, 0xafafd7 }, { 147, 0xafafff },
{ 148, 0xafd700 }, { 149, 0xafd75f }, { 150, 0xafd787 },
{ 151, 0xafd7af }, { 152, 0xafd7d7 }, { 153, 0xafd7ff },
{ 154, 0xafff00 }, { 155, 0xafff5f }, { 156, 0xafff87 },
{ 157, 0xafffaf }, { 158, 0xafffd7 }, { 159, 0xafffff },
{ 160, 0xd70000 }, { 161, 0xd7005f }, { 162, 0xd70087 },
{ 163, 0xd700af }, { 164, 0xd700d7 }, { 165, 0xd700ff },
{ 166, 0xd75f00 }, { 167, 0xd75f5f }, { 168, 0xd75f87 },
{ 169, 0xd75faf }, { 170, 0xd75fd7 }, { 171, 0xd75fff },
{ 172, 0xd78700 }, { 173, 0xd7875f }, { 174, 0xd78787 },
{ 175, 0xd787af }, { 176, 0xd787d7 }, { 177, 0xd787ff },
{ 178, 0xd7af00 }, { 179, 0xd7af5f }, { 180, 0xd7af87 },
{ 181, 0xd7afaf }, { 182, 0xd7afd7 }, { 183, 0xd7afff },
{ 184, 0xd7d700 }, { 185, 0xd7d75f }, { 186, 0xd7d787 },
{ 187, 0xd7d7af }, { 188, 0xd7d7d7 }, { 189, 0xd7d7ff },
{ 190, 0xd7ff00 }, { 191, 0xd7ff5f }, { 192, 0xd7ff87 },
{ 193, 0xd7ffaf }, { 194, 0xd7ffd7 }, { 195, 0xd7ffff },
{ 196, 0xff0000 }, { 197, 0xff005f }, { 198, 0xff0087 },
{ 199, 0xff00af }, { 200, 0xff00d7 }, { 201, 0xff00ff },
{ 202, 0xff5f00 }, { 203, 0xff5f5f }, { 204, 0xff5f87 },
{ 205, 0xff5faf }, { 206, 0xff5fd7 }, { 207, 0xff5fff },
{ 208, 0xff8700 }, { 209, 0xff875f }, { 210, 0xff8787 },
{ 211, 0xff87af }, { 212, 0xff87d7 }, { 213, 0xff87ff },
{ 214, 0xffaf00 }, { 215, 0xffaf5f }, { 216, 0xffaf87 },
{ 217, 0xffafaf }, { 218, 0xffafd7 }, { 219, 0xffafff },
{ 220, 0xffd700 }, { 221, 0xffd75f }, { 222, 0xffd787 },
{ 223, 0xffd7af }, { 224, 0xffd7d7 }, { 225, 0xffd7ff },
{ 226, 0xffff00 }, { 227, 0xffff5f }, { 228, 0xffff87 },
{ 229, 0xffffaf }, { 230, 0xffffd7 }, { 231, 0xffffff },
{ 232, 0x080808 }, { 233, 0x121212 }, { 234, 0x1c1c1c },
{ 235, 0x262626 }, { 236, 0x303030 }, { 237, 0x3a3a3a },
{ 238, 0x444444 }, { 239, 0x4e4e4e }, { 240, 0x585858 },
{ 241, 0x626262 }, { 242, 0x6c6c6c }, { 243, 0x767676 },
{ 244, 0x808080 }, { 245, 0x8a8a8a }, { 246, 0x949494 },
{ 247, 0x9e9e9e }, { 248, 0xa8a8a8 }, { 249, 0xb2b2b2 },
{ 250, 0xbcbcbc }, { 251, 0xc6c6c6 }, { 252, 0xd0d0d0 },
{ 253, 0xdadada }, { 254, 0xe4e4e4 }, { 255, 0xeeeeee },
};
/** Calculate the color distance between two colors.
*
* Algorithm taken from UnNetHack which took it from
* https://www.compuphase.com/cmetric.htm
**/
int
color_distance(uint32_t rgb1, uint32_t rgb2)
{
int r1 = (rgb1 >> 16) & 0xFF;
int g1 = (rgb1 >> 8) & 0xFF;
int b1 = (rgb1) & 0xFF;
int r2 = (rgb2 >> 16) & 0xFF;
int g2 = (rgb2 >> 8) & 0xFF;
int b2 = (rgb2) & 0xFF;
int rmean = (r1 + r2) / 2;
int r = r1 - r2;
int g = g1 - g2;
int b = b1 - b2;
return ((((512 + rmean) * r * r) >> 8) + 4 * g * g
+ (((767 - rmean) * b * b) >> 8));
}
boolean
closest_color(uint32 lcolor, uint32 *closecolor, int *clridx)
{
int i, color_index = -1, similar = INT_MAX, current;
boolean retbool = FALSE;
for (i = 0; i < SIZE(color_256_definitions); i++) {
/* look for an exact match */
if (lcolor == color_256_definitions[i].value) {
color_index = i;
break;
}
/* find a close color match */
current = color_distance(lcolor, color_256_definitions[i].value);
if (current < similar) {
color_index = i;
similar = current;
}
}
if (closecolor && clridx && color_index >= 0) {
*closecolor = color_256_definitions[color_index].value;
*clridx = color_256_definitions[color_index].index;
retbool = TRUE;
}
return retbool;
}
uint32
get_nhcolor_from_256_index(int idx)
{
uint32 retcolor = NO_COLOR | NH_BASIC_COLOR;
if (IndexOk(idx, color_256_definitions))
retcolor = color_256_definitions[idx].value;
return retcolor;
}
/*coloratt.c*/

View File

@@ -756,9 +756,7 @@ static const struct instance_globals_s g_init_s = {
{ 0, 0 }, /* save_dlevel */
/* symbols.c */
{ DUMMY }, /* symset */
#ifdef ENHANCED_SYMBOLS
{ { 0 } }, /* symset_customizations */
#endif
{ { 0 }, { 0 } }, /* symset_customizations */
DUMMY, /* showsyms */
/* files.c */
0, /* symset_count */

View File

@@ -1565,15 +1565,19 @@ see_traps(void)
}
}
/* glyph, ttychar, { glyphflags, { sym.color, sym.symidx },
tileidx, u } */
/* glyph, ttychar, framecolor,
{ glyphflags, { NO_COLOR, sym.symidx }, nhcolor, tileidx, u } */
static glyph_info no_ginfo = {
NO_GLYPH, ' ', NO_COLOR, { MG_BADXY, { NO_COLOR, 0 }, 0
NO_GLYPH, ' ', NO_COLOR,
{ MG_BADXY, { NO_COLOR, 0 },
0,
0
#ifdef ENHANCED_SYMBOLS
, 0
, 0
#endif
}
};
#ifndef UNBUFFERED_GLYPHINFO
/* Note that the 'glyph' argument is not used in the expansion
* of this !UNBUFFERED_GLYPHINFO (default) variation, but is
@@ -1590,16 +1594,17 @@ staticfn glyph_info *glyphinfo_at(coordxy, coordxy, int);
#ifdef TILES_IN_GLYPHMAP
extern const glyph_info nul_glyphinfo; /* tile.c */
#else
/* glyph, ttychar, { glyphflags, { sym.color, sym.symidx },
/* glyph, ttychar, framecolor, { glyphflags, { sym.symidx }, nhcolor,
tileidx, 0} */
const glyph_info nul_glyphinfo = {
NO_GLYPH, ' ', NO_COLOR,
{ /* glyph_map */
MG_UNEXPL,
{ NO_COLOR, SYM_UNEXPLORED + SYM_OFF_X },
0
0,
0
#ifdef ENHANCED_SYMBOLS
, 0
, 0
#endif
}
};
@@ -1609,9 +1614,11 @@ const glyph_info nul_glyphinfo = {
extern glyph_map glyphmap[MAX_GLYPH]; /* from tile.c */
#else
glyph_map glyphmap[MAX_GLYPH] = {
{ 0U, { 0, 0}, 0
{ 0U, { NO_COLOR, 0 },
0,
0
#ifdef ENHANCED_SYMBOLS
, 0
, 0
#endif
}
};
@@ -1819,6 +1826,8 @@ show_glyph(coordxy x, coordxy y, int glyph)
boolean show_glyph_change = FALSE;
int oldglyph;
//if (glyph == 3972 || glyph == 3988)
// __debugbreak();
/*
* Check for bad positions and glyphs.
*/
@@ -1965,6 +1974,7 @@ show_glyph(coordxy x, coordxy y, int glyph)
but that triggers full redraw so doesn't matter here); still,
be thorough and check everything */
|| gg.gbuf[y][x].glyphinfo.ttychar != glyphinfo.ttychar
|| gg.gbuf[y][x].glyphinfo.gm.nhcolor != glyphinfo.gm.nhcolor
|| gg.gbuf[y][x].glyphinfo.gm.glyphflags != glyphinfo.gm.glyphflags
|| gg.gbuf[y][x].glyphinfo.gm.sym.color != glyphinfo.gm.sym.color
|| gg.gbuf[y][x].glyphinfo.gm.tileidx != glyphinfo.gm.tileidx
@@ -2014,11 +2024,14 @@ show_glyph(coordxy x, coordxy y, int glyph)
static gbuf_entry nul_gbuf = {
0, /* gnew */
{ GLYPH_UNEXPLORED, (unsigned) ' ', NO_COLOR, /* glyphinfo.glyph */
{ GLYPH_UNEXPLORED, (unsigned) ' ', NO_COLOR,
/* glyphinfo.glyph, glyphinfo.ttychar */
/* glyphinfo.gm */
{ MG_UNEXPL, { (unsigned) NO_COLOR, 0 }, 0
{ MG_UNEXPL, { NO_COLOR, 0 },
0,
0
#ifdef ENHANCED_SYMBOLS
, 0
, 0
#endif
}
}
@@ -2045,10 +2058,12 @@ clear_glyph_buffer(void)
|| giptr->gm.sym.color != nul_gbuf.glyphinfo.gm.sym.color
|| giptr->gm.glyphflags
!= nul_gbuf.glyphinfo.gm.glyphflags
|| giptr->gm.nhcolor != nul_gbuf.glyphinfo.gm.nhcolor
|| giptr->gm.tileidx != nul_gbuf.glyphinfo.gm.tileidx)
#else
nul_gbuf.gnew = (giptr->ttychar != ' '
|| giptr->gm.sym.color != NO_COLOR
|| giptr->gm.nhcolor != 0
|| (giptr->gm.glyphflags & ~MG_UNEXPL) != 0)
#endif
? 1 : 0;
@@ -2084,10 +2099,12 @@ row_refresh(coordxy start, coordxy stop, coordxy y)
force = (giptr->ttychar != nul_gbuf.glyphinfo.ttychar
|| giptr->gm.sym.color != nul_gbuf.glyphinfo.gm.sym.color
|| giptr->gm.glyphflags != nul_gbuf.glyphinfo.gm.glyphflags
|| giptr->gm.nhcolor != nul_gbuf.glyphinfo.gm.nhcolor
|| giptr->gm.tileidx != nul_gbuf.glyphinfo.gm.tileidx)
#else
force = (giptr->ttychar != ' '
|| giptr->gm.sym.color != NO_COLOR
|| giptr->gm.gm.nhcolor != 0
|| (giptr->gm.glyphflags & ~MG_UNEXPL) != 0)
#endif
? 1 : 0;
@@ -2097,7 +2114,7 @@ row_refresh(coordxy start, coordxy stop, coordxy y)
get_bkglyph_and_framecolor(x, y, &bkglyphinfo.glyph,
&bkglyphinfo.framecolor);
if (force || glyph != GLYPH_UNEXPLORED
|| bkglyphinfo.framecolor != NO_COLOR) {
|| bkglyphinfo.gm.nhcolor != NO_COLOR) {
print_glyph(WIN_MAP, x, y,
Glyphinfo_at(x, y, glyph), &bkglyphinfo);
}
@@ -2161,7 +2178,8 @@ flush_screen(int cursor_on_u)
gbuf_entry *gptr = &gg.gbuf[y][x = gg.gbuf_start[y]];
for (; x <= gg.gbuf_stop[y]; gptr++, x++) {
get_bkglyph_and_framecolor(x, y, &bkglyph, &bkglyphinfo.framecolor);
get_bkglyph_and_framecolor(x, y, &bkglyph,
&bkglyphinfo.framecolor);
if (gptr->gnew
|| (gw.wsettings.map_frame_color != NO_COLOR
&& bkglyphinfo.framecolor != NO_COLOR)) {

1184
src/glyphs.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1771,9 +1771,7 @@ optfn_glyph(
int optidx UNUSED, int req, boolean negated,
char *opts, char *op)
{
#ifdef ENHANCED_SYMBOLS
int glyph;
#endif
if (req == do_init) {
return optn_ok;
@@ -1790,10 +1788,8 @@ optfn_glyph(
return optn_err;
/* strip leading/trailing spaces, condense internal ones (3.6.2) */
mungspaces(op);
#ifdef ENHANCED_SYMBOLS
if (!glyphrep_to_custom_map_entries(op, &glyph))
return optn_err;
#endif
return optn_ok;
}
if (req == get_val) {
@@ -4077,19 +4073,12 @@ optfn_symset(
if (req == do_handler) {
int reslt;
if (gs.symset[PRIMARYSET].handling == H_UTF8) {
#ifdef ENHANCED_SYMBOLS
if (!glyphid_cache_status())
fill_glyphid_cache();
#endif
}
if (!glyphid_cache_status())
fill_glyphid_cache();
reslt = handler_symset(optidx);
if (gs.symset[PRIMARYSET].handling == H_UTF8) {
#ifdef ENHANCED_SYMBOLS
if (glyphid_cache_status())
free_glyphid_cache();
#endif
}
if (glyphid_cache_status())
free_glyphid_cache();
/* apply_customizations(gc.currentgraphics); */
return reslt;
}
return optn_ok;
@@ -6928,11 +6917,9 @@ initoptions_init(void)
gc.cmdline_windowsys = NULL;
}
#ifdef ENHANCED_SYMBOLS
/* make any symbol parsing quicker */
if (!glyphid_cache_status())
fill_glyphid_cache();
#endif
/* set up the command parsing */
reset_commands(TRUE); /* init */
@@ -7201,11 +7188,9 @@ initoptions_finish(void)
&& !opt_set_in_config[opt_bgcolors])
iflags.bgcolors = FALSE;
#ifdef ENHANCED_SYMBOLS
if (glyphid_cache_status())
free_glyphid_cache();
apply_customizations_to_symset(gc.currentgraphics);
#endif
apply_customizations(gc.currentgraphics);
go.opt_initial = FALSE;
/*

View File

@@ -1168,6 +1168,7 @@ freedynamicdata(void)
msgtype_free();
savedsym_free();
tmp_at(DISP_FREEMEM, 0); /* temporary display effects */
purge_all_custom_entries();
#ifdef FREE_ALL_MEMORY
#define free_current_level() savelev(&tnhfp, -1)
#define freeobjchn(X) (saveobjchn(&tnhfp, &X), X = 0)

View File

@@ -7,9 +7,6 @@
staticfn void savedsym_add(const char *, const char *, int);
staticfn struct _savedsym *savedsym_find(const char *, int);
#ifdef ENHANCED_SYMBOLS
staticfn void purge_custom_entries(enum graphics_sets which_set);
#endif
extern const uchar def_r_oc_syms[MAXOCLASSES]; /* drawing.c */
@@ -346,8 +343,9 @@ clear_symsetentry(int which_set, boolean name_too)
isn't using UTF8, discard the data for that */
if (old_handling == H_UTF8 && gs.symset[other_set].handling != H_UTF8)
free_all_glyphmap_u();
purge_custom_entries(which_set);
#endif
purge_custom_entries(which_set);
clear_all_glyphmap_colors();
}
/* called from windmain.c */
@@ -357,7 +355,7 @@ symset_is_compatible(
unsigned long wincap2)
{
#ifdef ENHANCED_SYMBOLS
#define WC2_utf8_bits (WC2_U_UTF8STR | WC2_U_24BITCOLOR)
#define WC2_utf8_bits (WC2_U_UTF8STR)
if (handling == H_UTF8 && ((wincap2 & WC2_utf8_bits) != WC2_utf8_bits))
return FALSE;
#undef WC2_bits
@@ -462,8 +460,10 @@ parse_sym_line(char *buf, int which_set)
/* find the '=' or ':' */
bufp = strchr(buf, '=');
altp = strchr(buf, ':');
if (!bufp || (altp && altp < bufp))
bufp = altp;
if (!bufp) {
if (strncmpi(buf, "finish", 6) == 0) {
/* end current graphics set */
@@ -480,15 +480,15 @@ parse_sym_line(char *buf, int which_set)
if (*bufp == ' ')
++bufp;
symp = match_sym(buf);
if (!symp && buf[0] == 'G' && buf[1] == '_') {
#ifdef ENHANCED_SYMBOLS
if (gc.chosen_symset_start) {
is_glyph = match_glyph(buf);
} else {
is_glyph = TRUE; /* report error only once */
}
#ifdef ENHANCED_SYMBOLS
enhanced_unavailable = FALSE;
#else
enhanced_unavailable = TRUE;
#endif
@@ -627,8 +627,8 @@ parse_sym_line(char *buf, int which_set)
} else {
/* Not SYM_CONTROL */
if (gs.symset[which_set].handling != H_UTF8) {
val = sym_val(bufp);
if (gc.chosen_symset_start) {
val = sym_val(bufp);
if (which_set == PRIMARYSET) {
update_primary_symset(symp, val);
} else if (which_set == ROGUESET) {
@@ -643,6 +643,9 @@ parse_sym_line(char *buf, int which_set)
#endif
}
}
} else if (gc.chosen_symset_start) {
/* glyph, not symbol */
glyphrep_to_custom_map_entries(buf, &glyph);
}
#ifndef ENHANCED_SYMBOLS
nhUse(glyph);
@@ -677,6 +680,7 @@ load_symset(const char *s, int which_set)
if (read_sym_file(which_set)) {
switch_symbols(TRUE);
apply_customizations(gc.currentgraphics);
} else {
clear_symsetentry(which_set, TRUE);
return 0;
@@ -816,24 +820,20 @@ parsesymbols(char *opts, int which_set)
mungspaces(strval);
symp = match_sym(symname);
#ifdef ENHANCED_SYMBOLS
if (!symp && symname[0] == 'G' && symname[1] == '_') {
is_glyph = match_glyph(symname);
}
#endif
if (!symp && !is_glyph)
return FALSE;
if (symp) {
if (symp->range && symp->range != SYM_CONTROL) {
if (gs.symset[which_set].handling == H_UTF8
|| (lowc(strval[0]) == 'u' && strval[1] == '+')) {
#ifdef ENHANCED_SYMBOLS
char buf[BUFSZ];
int glyph;
Snprintf(buf, sizeof buf, "%s:%s", opts, strval);
glyphrep_to_custom_map_entries(buf, &glyph);
#endif /* ENHANCED_SYMBOLS */
} else {
val = sym_val(strval);
if (which_set == ROGUESET)
@@ -1066,17 +1066,13 @@ do_symset(boolean rogueflag)
if (gs.symset[which_set].name) {
/* non-default symbols */
int ok;
#ifdef ENHANCED_SYMBOLS
if (!glyphid_cache_status()) {
fill_glyphid_cache();
}
#endif
ok = read_sym_file(which_set);
#ifdef ENHANCED_SYMBOLS
if (glyphid_cache_status()) {
free_glyphid_cache();
}
#endif
if (ok) {
ready_to_switch = TRUE;
} else {
@@ -1093,173 +1089,24 @@ do_symset(boolean rogueflag)
assign_graphics(ROGUESET);
} else if (!rogueflag)
assign_graphics(PRIMARYSET);
#ifdef ENHANCED_SYMBOLS
apply_customizations_to_symset(rogueflag ? ROGUESET : PRIMARYSET);
#endif
apply_customizations(rogueflag ? ROGUESET : PRIMARYSET);
preference_update("symset");
return TRUE;
}
#ifdef ENHANCED_SYMBOLS
extern glyph_map glyphmap[MAX_GLYPH];
void
clear_all_glyphmap_colors(void)
{
int glyph;
for (glyph = 0; glyph < MAX_GLYPH; ++glyph) {
if (glyphmap[glyph].nhcolor)
glyphmap[glyph].nhcolor = 0;
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
struct customization_detail *find_display_sym_customization(
const char *customization_name, const struct symparse *symparse,
enum graphics_sets which_set);
struct customization_detail *find_matching_symset_customiz(
const char *customization_name, int custtype,
enum graphics_sets which_set);
struct customization_detail *find_display_urep_customization(
const char *customization_name, int glyphidx,
enum graphics_sets which_set);
extern glyph_map glyphmap[MAX_GLYPH];
staticfn void shuffle_customizations(void);
void
apply_customizations_to_symset(enum graphics_sets which_set)
{
glyph_map *gmap;
struct customization_detail *details;
if (gs.symset[which_set].handling == H_UTF8
&& gs.sym_customizations[which_set].count
&& gs.sym_customizations[which_set].details) {
/* These UTF-8 customizations get applied to the glyphmap array,
not to symset entries */
details = gs.sym_customizations[which_set].details;
while (details) {
gmap = &glyphmap[details->content.urep.glyphidx];
(void) set_map_u(gmap,
details->content.urep.u.utf32ch,
details->content.urep.u.utf8str,
details->content.urep.u.ucolor);
details = details->next;
}
shuffle_customizations();
}
}
/* Shuffle the customizations to match shuffled object descriptions,
* so a red potion isn't displayed with a blue customization, and so on.
*/
staticfn void
shuffle_customizations(void)
{
static const int offsets[2] = { GLYPH_OBJ_OFF, GLYPH_OBJ_PILETOP_OFF };
int j;
for (j = 0; j < SIZE(offsets); j++) {
glyph_map *obj_glyphs = glyphmap + offsets[j];
int i;
struct unicode_representation *tmp_u[NUM_OBJECTS];
int duplicate[NUM_OBJECTS];
for (i = 0; i < NUM_OBJECTS; i++) {
duplicate[i] = -1;
tmp_u[i] = (struct unicode_representation *) 0;
}
for (i = 0; i < NUM_OBJECTS; i++) {
int idx = objects[i].oc_descr_idx;
/*
* Shuffling gem appearances can cause the same oc_descr_idx to
* appear more than once. Detect this condition and ensure that
* each pointer points to a unique allocation.
*/
if (duplicate[idx] >= 0) {
/* Current structure already appears in tmp_u */
struct unicode_representation *other = tmp_u[duplicate[idx]];
tmp_u[i] = (struct unicode_representation *)
alloc(sizeof *tmp_u[i]);
*tmp_u[i] = *other;
if (other->utf8str != NULL) {
tmp_u[i]->utf8str = (uint8 *)
dupstr((const char *) other->utf8str);
}
} else {
tmp_u[i] = obj_glyphs[idx].u;
if (obj_glyphs[idx].u != NULL) {
duplicate[idx] = i;
obj_glyphs[idx].u = NULL;
}
}
}
for (i = 0; i < NUM_OBJECTS; i++) {
/* Some glyphmaps may not have been transferred */
if (obj_glyphs[i].u != NULL) {
free(obj_glyphs[i].u->utf8str);
free(obj_glyphs[i].u);
}
obj_glyphs[i].u = tmp_u[i];
}
}
}
struct customization_detail *
find_matching_symset_customiz(
const char *customization_name,
int custtype,
enum graphics_sets which_set)
{
struct symset_customization *gdc = &gs.sym_customizations[which_set];
if ((gdc->custtype == custtype)
&& (strcmp(customization_name, gdc->customization_name) != 0))
return gdc->details;
return (struct customization_detail *) 0;
}
staticfn void
purge_custom_entries(enum graphics_sets which_set)
{
struct symset_customization *gdc = &gs.sym_customizations[which_set];
struct customization_detail *details = gdc->details, *next;
while (details) {
next = details->next;
if (gdc->custtype == custom_ureps) {
if (details->content.urep.u.utf8str)
free(details->content.urep.u.utf8str);
details->content.urep.u.utf8str = (uint8 *) 0;
details->content.urep.u.ucolor = 0L;
details->content.urep.u.u256coloridx = 0L;
} else if (gdc->custtype == custom_symbols) {
details->content.sym.symparse = (struct symparse *) 0;
details->content.sym.val = 0;
}
free(details);
details = next;
}
gdc->details = 0;
gdc->details_end = 0;
if (gdc->customization_name) {
free((genericptr_t) gdc->customization_name);
gdc->customization_name = 0;
}
gdc->count = 0;
}
struct customization_detail *
find_display_sym_customization(
const char *customization_name,
const struct symparse *symparse,
enum graphics_sets which_set)
{
struct symset_customization *gdc = &gs.sym_customizations[which_set];
struct customization_detail *symdetails;
if ((gdc->custtype == custom_symbols)
&& (strcmp(customization_name, gdc->customization_name) == 0)) {
symdetails = gdc->details;
while (symdetails) {
if (symdetails->content.sym.symparse == symparse)
return symdetails;
symdetails = symdetails->next;
}
}
return (struct customization_detail *) 0;
}
#endif /* ENHANCED_SYMBOLS */
/*symbols.c*/

File diff suppressed because it is too large Load Diff