From 2bd967fe8a451b594a23c9ab98c056c4bad144e9 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 7 Dec 2023 22:47:57 -0800 Subject: [PATCH] a few fewer update_inventory() calls A couple of things I noticed while running umpteen tests for tty perm_invent. Remove the update_inventory() from unmul(), and limit the one that deals with seeing inventory when recovering from blindness. Just a drop in the bucket overall, and the screen updates nearly instantly for update_inventory() except when debugging perm_invent so players aren't likely to notice this. --- src/do_wear.c | 41 ++++++++++++++++++++++++++++------------- src/hack.c | 5 ++--- src/invent.c | 7 +++++-- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/do_wear.c b/src/do_wear.c index e421badc2..1b3f4450a 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 do_wear.c $NHDT-Date: 1650875489 2022/04/25 08:31:29 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.156 $ */ +/* NetHack 3.7 do_wear.c $NHDT-Date: 1702017586 2023/12/08 06:39:46 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.175 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2012. */ /* NetHack may be freely redistributed. See license for details. */ @@ -213,8 +213,11 @@ Boots_on(void) default: impossible(unknown_type, c_boots, uarmf->otyp); } - if (uarmf) /* could be Null here (levitation boots put on over a sink) */ + /* uarmf could be Null here (levitation boots put on over a sink) */ + if (uarmf && !uarmf->known) { uarmf->known = 1; /* boots' +/- evident because of status line AC */ + update_inventory(); + } return 0; } @@ -332,8 +335,10 @@ Cloak_on(void) default: impossible(unknown_type, c_cloak, uarmc->otyp); } - if (uarmc) /* no known instance of !uarmc here but play it safe */ + if (uarmc && !uarmc->known) { /* no known instance of !uarmc here */ uarmc->known = 1; /* cloak's +/- evident because of status line AC */ + update_inventory(); + } return 0; } @@ -461,8 +466,10 @@ Helmet_on(void) impossible(unknown_type, c_helmet, uarmh->otyp); } /* uarmh could be Null due to uchangealign() */ - if (uarmh) + if (uarmh && !uarmh->known) { uarmh->known = 1; /* helmet's +/- evident because of status line AC */ + update_inventory(); + } return 0; } @@ -544,8 +551,10 @@ Gloves_on(void) default: impossible(unknown_type, c_gloves, uarmg->otyp); } - if (uarmg) /* no known instance of !uarmg here but play it safe */ + if (!uarmg->known) { uarmg->known = 1; /* gloves' +/- evident because of status line AC */ + update_inventory(); + } return 0; } @@ -667,8 +676,10 @@ Shield_on(void) default: impossible(unknown_type, c_shield, uarms->otyp); } - if (uarms) /* no known instance of !uarms here but play it safe */ + if (!uarms->known) { uarms->known = 1; /* shield's +/- evident because of status line AC */ + update_inventory(); + } return 0; } @@ -708,8 +719,10 @@ Shirt_on(void) default: impossible(unknown_type, c_shirt, uarmu->otyp); } - if (uarmu) /* no known instances of !uarmu here but play it safe */ + if (!uarmu->known) { uarmu->known = 1; /* shirt's +/- evident because of status line AC */ + update_inventory(); + } return 0; } @@ -827,10 +840,12 @@ Armor_on(void) { if (!uarm) /* no known instances of !uarm here but play it safe */ return 0; - uarm->known = 1; /* suit's +/- evident because of status line AC */ - + if (!uarm->known) { + uarm->known = 1; /* suit's +/- evident because of status line AC */ + update_inventory(); + } dragon_armor_handling(uarm, TRUE, TRUE); - /* gold DSM requires special handling since it emits light when worn; + /* gold DSM requires extra handling since it emits light when worn; do that after the special armor handling */ if (artifact_light(uarm) && !uarm->lamplit) { begin_burn(uarm, FALSE); @@ -1117,7 +1132,7 @@ adjust_attrib(struct obj *obj, int which, int val) } void -Ring_on(register struct obj *obj) +Ring_on(struct obj *obj) { long oldprop = u.uprops[objects[obj->otyp].oc_oprop].extrinsic; boolean observable; @@ -1412,8 +1427,8 @@ Blindf_off(struct obj *otmp) /* called in moveloop()'s prologue to set side-effects of worn start-up items; also used by poly_obj() when a worn item gets transformed */ void -set_wear(struct obj *obj) /* if null, do all worn items; - * otherwise just obj itself */ +set_wear( + struct obj *obj) /* if Null, do all worn items; otherwise just obj */ { gi.initial_don = !obj; diff --git a/src/hack.c b/src/hack.c index 92914e172..5dac90956 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 hack.c $NHDT-Date: 1695932717 2023/09/28 20:25:17 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.410 $ */ +/* NetHack 3.7 hack.c $NHDT-Date: 1702017600 2023/12/08 06:40:00 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.422 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3766,6 +3766,7 @@ unmul(const char *msg_override) gn.nomovemsg = 0; u.usleep = 0; gm.multi_reason = NULL, gm.multireasonbuf[0] = '\0'; + if (ga.afternmv) { int (*f)(void) = ga.afternmv; @@ -3773,8 +3774,6 @@ unmul(const char *msg_override) encumbrance hack for levitation--see weight_cap()) */ ga.afternmv = (int (*)(void)) 0; (void) (*f)(); - /* for finishing Armor/Boots/&c_on() */ - update_inventory(); } } diff --git a/src/invent.c b/src/invent.c index c4b1b4962..29f2a3ad1 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 invent.c $NHDT-Date: 1700869704 2023/11/24 23:48:24 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.476 $ */ +/* NetHack 3.7 invent.c $NHDT-Date: 1702017603 2023/12/08 06:40:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.484 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2611,6 +2611,7 @@ void learn_unseen_invent(void) { struct obj *otmp; + boolean invupdated = FALSE; if (Blind) return; /* sanity check */ @@ -2618,6 +2619,7 @@ learn_unseen_invent(void) for (otmp = gi.invent; otmp; otmp = otmp->nobj) { if (otmp->dknown && (otmp->bknown || !Role_if(PM_CLERIC))) continue; /* already seen */ + invupdated = TRUE; /* xname() will set dknown, perhaps bknown (for priest[ess]); result from xname() is immediately released for re-use */ maybereleaseobuf(xname(otmp)); @@ -2626,7 +2628,8 @@ learn_unseen_invent(void) * handle deferred discovery here. */ } - update_inventory(); + if (invupdated) + update_inventory(); } /* persistent inventory window is maintained by interface code;