glyph_to_cmap() usage
I was looking to see what the impact of converting glyph_to_cmap() to a function might have and noticed a couple of places where the macro edition is passed a non-trivial argument. Since it evaluates that argument many times, there is hidden overhead. Fetch the glyph once and pass that to glyph_to_cmap(). This will no longer be very useful--but won't need to be reverted--if PR #1022 gets incorporated. do_positionbar() has bugs (only matters for MS-DOS).
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.7 allmain.c $NHDT-Date: 1685863328 2023/06/04 07:22:08 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.218 $ */
|
/* NetHack 3.7 allmain.c $NHDT-Date: 1688415115 2023/07/03 20:11:55 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.219 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/*-Copyright (c) Robert Patrick Rankin, 2012. */
|
/*-Copyright (c) Robert Patrick Rankin, 2012. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -830,22 +830,32 @@ welcome(boolean new_game) /* false => restoring an old game */
|
|||||||
static void
|
static void
|
||||||
do_positionbar(void)
|
do_positionbar(void)
|
||||||
{
|
{
|
||||||
|
/* FIXME: this will break if any coordinate is too big for (char);
|
||||||
|
the sys/msdos/vid*.c code uses (unsigned char) which is less
|
||||||
|
vulnerable but not guaranteed to be able to hold coordxy values;
|
||||||
|
also, there doesn't appear to be any need for this to be static,
|
||||||
|
nor to contain pairs of (> or <) and x; it could just be a full
|
||||||
|
line of spaces and > or < characters with update_positionbar()
|
||||||
|
revised to reconstruct the x values for non-space characters */
|
||||||
static char pbar[COLNO];
|
static char pbar[COLNO];
|
||||||
char *p;
|
char *p;
|
||||||
stairway *stway = gs.stairs;
|
stairway *stway;
|
||||||
|
coordxy x, y;
|
||||||
|
int glyph, symbol;
|
||||||
|
|
||||||
p = pbar;
|
p = pbar;
|
||||||
/* TODO: use the same method as getpos() so objects don't cover stairs */
|
/* TODO: use the same method as getpos() so objects don't cover stairs */
|
||||||
while (stway) {
|
/* FIXME: traversing 'stairs' list ignores mimics that pose as stairs */
|
||||||
int x = stway->sx;
|
for (stway = gs.stairs; stway; stway = stway->next) {
|
||||||
int y = stway->sy;
|
x = stway->sx;
|
||||||
int glyph = glyph_to_cmap(gl.level.locations[x][y].glyph);
|
y = stway->sy;
|
||||||
|
glyph = levl[x][y].glyph;
|
||||||
|
symbol = glyph_to_cmap(glyph);
|
||||||
|
|
||||||
if (is_cmap_stairs(glyph)) {
|
if (is_cmap_stairs(symbol)) {
|
||||||
*p++ = (stway->up ? '<' : '>');
|
*p++ = (stway->up ? '<' : '>');
|
||||||
*p++ = stway->sx;
|
*p++ = (char) x;
|
||||||
}
|
}
|
||||||
stway = stway->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hero location */
|
/* hero location */
|
||||||
|
|||||||
30
src/do.c
30
src/do.c
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.7 do.c $NHDT-Date: 1685863330 2023/06/04 07:22:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.355 $ */
|
/* NetHack 3.7 do.c $NHDT-Date: 1688415121 2023/07/03 20:12:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.357 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/*-Copyright (c) Derek S. Ray, 2015. */
|
/*-Copyright (c) Derek S. Ray, 2015. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -1057,9 +1057,8 @@ int
|
|||||||
dodown(void)
|
dodown(void)
|
||||||
{
|
{
|
||||||
struct trap *trap = 0;
|
struct trap *trap = 0;
|
||||||
stairway *stway = stairway_at(u.ux, u.uy);
|
stairway *stway;
|
||||||
boolean stairs_down = (stway && !stway->up && !stway->isladder),
|
boolean stairs_down, ladder_down;
|
||||||
ladder_down = (stway && !stway->up && stway->isladder);
|
|
||||||
|
|
||||||
set_move_cmd(DIR_DOWN, 0);
|
set_move_cmd(DIR_DOWN, 0);
|
||||||
|
|
||||||
@@ -1069,6 +1068,13 @@ dodown(void)
|
|||||||
if (stucksteed(TRUE)) {
|
if (stucksteed(TRUE)) {
|
||||||
return ECMD_OK;
|
return ECMD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stairs_down = ladder_down = FALSE;
|
||||||
|
if ((stway = stairway_at(u.ux, u.uy)) != 0 && !stway->up) {
|
||||||
|
stairs_down = !stway->isladder;
|
||||||
|
ladder_down = !stairs_down;
|
||||||
|
}
|
||||||
|
|
||||||
/* Levitation might be blocked, but player can still use '>' to
|
/* Levitation might be blocked, but player can still use '>' to
|
||||||
turn off controlled levitation */
|
turn off controlled levitation */
|
||||||
if (HLevitation || ELevitation) {
|
if (HLevitation || ELevitation) {
|
||||||
@@ -1096,16 +1102,18 @@ dodown(void)
|
|||||||
if (BLevitation) {
|
if (BLevitation) {
|
||||||
; /* weren't actually floating after all */
|
; /* weren't actually floating after all */
|
||||||
} else if (Blind) {
|
} else if (Blind) {
|
||||||
|
/* glyph_to_cmap() is a macro which expands its argument many
|
||||||
|
times; use this to do part of its work just once */
|
||||||
|
int glyph_at_uxuy = levl[u.ux][u.uy].glyph;
|
||||||
|
|
||||||
/* Avoid alerting player to an unknown stair or ladder.
|
/* Avoid alerting player to an unknown stair or ladder.
|
||||||
* Changes the message for a covered, known staircase
|
* Changes the message for a covered, known staircase
|
||||||
* too; staircase knowledge is not stored anywhere.
|
* too; staircase knowledge is not stored anywhere.
|
||||||
*/
|
*/
|
||||||
if (stairs_down)
|
if (stairs_down)
|
||||||
stairs_down =
|
stairs_down = (glyph_to_cmap(glyph_at_uxuy) == S_dnstair);
|
||||||
(glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair);
|
|
||||||
else if (ladder_down)
|
else if (ladder_down)
|
||||||
ladder_down =
|
ladder_down = (glyph_to_cmap(glyph_at_uxuy) == S_dnladder);
|
||||||
(glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder);
|
|
||||||
}
|
}
|
||||||
if (Is_airlevel(&u.uz))
|
if (Is_airlevel(&u.uz))
|
||||||
You("are floating in the %s.", surface(u.ux, u.uy));
|
You("are floating in the %s.", surface(u.ux, u.uy));
|
||||||
@@ -1113,9 +1121,9 @@ dodown(void)
|
|||||||
You("are floating in %s.",
|
You("are floating in %s.",
|
||||||
is_pool(u.ux, u.uy) ? "the water" : "a bubble of air");
|
is_pool(u.ux, u.uy) ? "the water" : "a bubble of air");
|
||||||
else
|
else
|
||||||
floating_above(stairs_down ? "stairs" : ladder_down
|
floating_above(stairs_down ? "stairs"
|
||||||
? "ladder"
|
: ladder_down ? "ladder"
|
||||||
: surface(u.ux, u.uy));
|
: surface(u.ux, u.uy));
|
||||||
return ECMD_OK; /* didn't move */
|
return ECMD_OK; /* didn't move */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user