summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
committerBardur Arantsson <bardur@scientician.net>2016-09-17 09:58:14 +0200
commit46f69654774b0eb51bd4706cf7fd9d11fbc8eec8 (patch)
tree5d51b4219565162716280423a4962ce3db6dab88 /src
parentbef0f98085526b80b316580bb5a07fcd8b1af2c5 (diff)
Remove monster_race::total_visible temporary state
Diffstat (limited to 'src')
-rw-r--r--src/monster_race.hpp2
-rw-r--r--src/xtra1.cc37
2 files changed, 21 insertions, 18 deletions
diff --git a/src/monster_race.hpp b/src/monster_race.hpp
index 58c49e1f..eb398a3d 100644
--- a/src/monster_race.hpp
+++ b/src/monster_race.hpp
@@ -77,8 +77,6 @@ struct monster_race
bool_ on_saved = 0; /* Is the (unique) on a saved level ? */
- byte total_visible = 0; /* Amount of this race that are visible */
-
obj_theme drops; /* The drops type */
};
diff --git a/src/xtra1.cc b/src/xtra1.cc
index 066bd0fb..ae37bd90 100644
--- a/src/xtra1.cc
+++ b/src/xtra1.cc
@@ -1353,10 +1353,13 @@ static void fix_object(void)
static void fix_m_list(void)
{
- int i, j;
+ // Mirror of the r_info array, index by index. We use a
+ // statically allocated value to avoid frequent allocations.
+ static auto r_total_visible =
+ std::vector<u16b>(max_r_idx, 0);
/* Scan windows */
- for (j = 0; j < 8; j++)
+ for (std::size_t j = 0; j < 8; j++)
{
term *old = Term;
@@ -1389,18 +1392,17 @@ static void fix_m_list(void)
}
/* reset visible count */
- for (i = 1; i < max_r_idx; i++)
+ for (std::size_t i = 1; i < max_r_idx; i++)
{
- monster_race *r_ptr = &r_info[i];
-
- r_ptr->total_visible = 0;
+ r_total_visible[i] = 0;
}
/* Count up the number visible in each race */
- for (i = 1; i < m_max; i++)
+ for (std::size_t i = 1; i < static_cast<u16b>(m_max); i++)
{
- monster_type *m_ptr = &m_list[i];
- monster_race *r_ptr = &r_info[m_ptr->r_idx];
+ auto const m_ptr = &m_list[i];
+ auto const r_ptr = &r_info[m_ptr->r_idx];
+ auto total_visible = &r_total_visible[m_ptr->r_idx];
/* Skip dead monsters */
if (m_ptr->hp < 0) continue;
@@ -1420,7 +1422,7 @@ static void fix_m_list(void)
}
/* Increase for this race */
- r_ptr->total_visible++;
+ (*total_visible)++;
/* Increase total Count */
c++;
@@ -1435,15 +1437,19 @@ static void fix_m_list(void)
c_prt(TERM_WHITE, format("You can see %d monster%s", c, (c > 1 ? "s:" : ":")), 0, 0);
- for (i = 1; i < max_r_idx; i++)
+ for (std::size_t i = 1; i < max_r_idx; i++)
{
- monster_race *r_ptr = &r_info[i];
+ auto const r_ptr = &r_info[i];
+ auto const total_visible = r_total_visible[i];
/* Default Colour */
byte attr = TERM_SLATE;
/* Only visible monsters */
- if (!r_ptr->total_visible) continue;
+ if (!total_visible)
+ {
+ continue;
+ }
/* Uniques */
if (r_ptr->flags & RF_UNIQUE)
@@ -1469,15 +1475,14 @@ static void fix_m_list(void)
if (!(r_ptr->flags & RF_UNIQUE)) attr = TERM_GREEN;
}
-
/* Dump the monster name */
- if (r_ptr->total_visible == 1)
+ if (total_visible == 1)
{
c_prt(attr, r_ptr->name, (num % (h - 1)) + 1, (num / (h - 1) * 26));
}
else
{
- c_prt(attr, format("%s (x%d)", r_ptr->name, r_ptr->total_visible), (num % (h - 1)) + 1, (num / (h - 1)) * 26);
+ c_prt(attr, format("%s (x%d)", r_ptr->name, total_visible), (num % (h - 1)) + 1, (num / (h - 1)) * 26);
}
num++;