From ee77075cb6fd777079e0cc4fea6d6bb6f08b6e77 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 19 Sep 2016 08:25:39 +0200 Subject: [PATCH] cache get_race calls --- src/kernel/config.c | 1 + src/kernel/skills.c | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index d78362f3c..dc61e643b 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -140,6 +140,7 @@ int NMRTimeout(void) race_t old_race(const struct race * rc) { race_t i; + // TODO: this sucks so bad! for (i = 0; i != MAXRACES; ++i) { if (get_race(i) == rc) return i; } diff --git a/src/kernel/skills.c b/src/kernel/skills.c index caae7b836..e773424ab 100644 --- a/src/kernel/skills.c +++ b/src/kernel/skills.c @@ -104,16 +104,22 @@ int value, int flags) int skill_mod(const race * rc, skill_t sk, const struct terrain_type *terrain) { int result = 0; + static int rc_cache; + static race *rc_dwarf, *rc_insect; + if (rc_changed(&rc_cache)) { + rc_dwarf = get_race(RC_DWARF); + rc_insect = get_race(RC_INSECT); + } result = rc->bonus[sk]; - if (rc == get_race(RC_DWARF)) { + if (rc == rc_dwarf) { if (sk == SK_TACTICS) { if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION)) ++result; } } - else if (rc == get_race(RC_INSECT)) { + else if (rc == rc_insect) { if (terrain == newterrain(T_MOUNTAIN) || fval(terrain, ARCTIC_REGION)) --result; else if (terrain == newterrain(T_DESERT) || terrain == newterrain(T_SWAMP)) @@ -126,19 +132,25 @@ int skill_mod(const race * rc, skill_t sk, const struct terrain_type *terrain) int rc_skillmod(const struct race *rc, const region * r, skill_t sk) { int mods = 0; - if (!skill_enabled(sk)) { return 0; } if (r) { mods = skill_mod(rc, sk, r->terrain); } - if (rc == get_race(RC_ELF) && r && r_isforest(r)) { - if (sk == SK_PERCEPTION || sk == SK_STEALTH) { - ++mods; + if (r && r_isforest(r)) { + static int rc_cache; + static race * rc_elf; + if (rc_changed(&rc_cache)) { + rc_elf = get_race(RC_ELF); } - else if (sk == SK_TACTICS) { - mods += 2; + if (rc == rc_elf) { + if (sk == SK_PERCEPTION || sk == SK_STEALTH) { + ++mods; + } + else if (sk == SK_TACTICS) { + mods += 2; + } } } return mods;