From fa4dda377d089568cde045b81c8ce1700cf60916 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 1 Apr 2015 16:38:56 +0300 Subject: [PATCH] Move isqrt into hacklib, other minor fixage --- include/extern.h | 3 ++- src/hacklib.c | 8 ++++++++ src/sp_lev.c | 9 +-------- src/spell.c | 24 ------------------------ 4 files changed, 11 insertions(+), 33 deletions(-) diff --git a/include/extern.h b/include/extern.h index 00d10a98f..4e2780c6b 100644 --- a/include/extern.h +++ b/include/extern.h @@ -828,6 +828,7 @@ E char *FDECL(sitoa, (int)); E int FDECL(sgn, (int)); E int FDECL(rounddiv, (long,int)); E int FDECL(dist2, (int,int,int,int)); +E int FDECL(isqrt, (int)); E int FDECL(distmin, (int,int,int,int)); E boolean FDECL(online2, (int,int,int,int)); E boolean FDECL(pmatch, (const char *,const char *)); @@ -1138,7 +1139,7 @@ E void FDECL(dodoor, (int,int,struct mkroom *)); E void FDECL(mktrap, (int,int,struct mkroom *,coord*)); E void FDECL(mkstairs, (XCHAR_P,XCHAR_P,CHAR_P,struct mkroom *)); E void NDECL(mkinvokearea); -E void FDECL(mineralize, (int, int, int, int, boolean)); +E void FDECL(mineralize, (int, int, int, int, BOOLEAN_P)); /* ### mkmap.c ### */ diff --git a/src/hacklib.c b/src/hacklib.c index 4fdbceb80..a9c31d42d 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -432,6 +432,14 @@ dist2(x0, y0, x1, y1) /* square of euclidean distance between pair of pts */ return dx * dx + dy * dy; } +/* Integer square root function without using floating point. + * This could be replaced by a faster algorithm, but has not been because: + * + the simple algorithm is easy to read + * + this algorithm does not require 64-bit support + * + in current usage, the values passed to isqrt() are not really that + * large, so the performance difference is negligible + * + isqrt() is used in only few places, which are not bottle-necks + */ int isqrt(val) int val; diff --git a/src/sp_lev.c b/src/sp_lev.c index 6e42b2c31..09005a32e 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -1303,6 +1303,7 @@ struct mkroom *croom; if (mtmp) { x = mtmp->mx, y = mtmp->my; /* sanity precaution */ + m->x = x, m->y = y; /* handle specific attributes for some special monsters */ if (m->name.str) mtmp = christen_monst(mtmp, m->name.str); @@ -2067,7 +2068,6 @@ struct mkroom *mkr; { boolean okroom; struct mkroom *aroom; - short i; xchar rtype = (!r->chance || rn2(100) < r->chance) ? r->rtype : OROOM; if(mkr) { @@ -2915,7 +2915,6 @@ void spo_room(coder) struct sp_coder *coder; { - int isbigrm = FALSE; if (coder->n_subroom > MAX_NESTED_ROOMS) panic("Too deeply nested rooms?!"); else { @@ -2950,8 +2949,6 @@ spo_room(coder) /*tmproom.irregular = (OV_i(flags) & (1 << 1));*/ tmproom.joined = !(OV_i(flags) & (1 << 2)); - isbigrm = ((tmproom.w * tmproom.h) > 20); - opvar_free(x); opvar_free(y); opvar_free(w); @@ -4162,7 +4159,6 @@ spo_map(coder) struct opvar *mpxs, *mpys, *mpmap, *mpa, *mpkeepr, *mpzalign; xchar halign, valign; xchar tmpxstart, tmpystart, tmpxsize, tmpysize; - int tryct = 0; unpacked_coord upc; if (!OV_pop_i(mpxs) || @@ -4172,8 +4168,6 @@ spo_map(coder) !OV_pop_i(mpzalign) || !OV_pop_c(mpa)) return; -redo_maploc: - tmpmazepart.xsize = OV_i(mpxs); tmpmazepart.ysize = OV_i(mpys); tmpmazepart.zaligntyp = OV_i(mpzalign); @@ -4281,7 +4275,6 @@ redo_maploc: xsize = tmpxsize; ysize = tmpysize; } -skipmap: opvar_free(mpxs); opvar_free(mpys); opvar_free(mpmap); diff --git a/src/spell.c b/src/spell.c index 5ce0a6015..2ccf7eea6 100644 --- a/src/spell.c +++ b/src/spell.c @@ -42,7 +42,6 @@ STATIC_DCL int NDECL(throwspell); STATIC_DCL void NDECL(cast_protection); STATIC_DCL void FDECL(spell_backfire, (int)); STATIC_DCL const char *FDECL(spelltypemnemonic, (int)); -STATIC_DCL int FDECL(isqrt, (int)); /* The roles[] table lists the role-specific values for tuning * percent_success(). @@ -1433,29 +1432,6 @@ int *spell_no; return FALSE; } -/* Integer square root function without using floating point. - * This could be replaced by a faster algorithm, but has not been because: - * + the simple algorithm is easy to read - * + this algorithm does not require 64-bit support - * + in current usage, the values passed to isqrt() are not really that - * large, so the performance difference is negligible - * + isqrt() is used in only one place - * + that one place is not a bottle-neck - */ -STATIC_OVL int -isqrt(val) -int val; -{ - int rt = 0; - int odd = 1; - while(val >= odd) { - val = val-odd; - odd = odd+2; - rt = rt + 1; - } - return rt; -} - STATIC_OVL int percent_success(spell) int spell; -- 2.50.1