diff options
author | Adam Borowski <kilobyte@angband.pl> | 2011-05-28 17:49:48 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2011-05-28 19:30:15 +0200 |
commit | d5c05a159120175ffa18901d935d6f0eea2d8705 (patch) | |
tree | d6b34b18b54e7d3b428263682f18df62887561b5 /crawl-ref/source/losglobal.cc | |
parent | 56006b34e124e78e0dd1b21f52b92610b4c310c2 (diff) | |
download | crawl-ref-d5c05a159120175ffa18901d935d6f0eea2d8705.tar.gz crawl-ref-d5c05a159120175ffa18901d935d6f0eea2d8705.zip |
Optimize invalidate_los_around().
It's the biggest CPU hog on the sprint rest test, especially its unwoken
version.
Changes:
1. no use of iterators (the other biggest hog, which one deserves the title
is unclear due to them being entangled)
2. a π/4 optimization: no need to clear corners of a rectangle
Diffstat (limited to 'crawl-ref/source/losglobal.cc')
-rw-r--r-- | crawl-ref/source/losglobal.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/crawl-ref/source/losglobal.cc b/crawl-ref/source/losglobal.cc index 4d1e1d7c1b..2c634da1c4 100644 --- a/crawl-ref/source/losglobal.cc +++ b/crawl-ref/source/losglobal.cc @@ -5,6 +5,7 @@ #include "coord.h" #include "coordit.h" #include "fixedarray.h" +#include "libutil.h" #include "los_def.h" typedef uint8_t losfield_t; @@ -50,12 +51,14 @@ static void _save_los(los_def* los, los_type l) // Opacity at p has changed. void invalidate_los_around(const coord_def& p) { - const coord_def tl = p - coord_def(LOS_MAX_RANGE, LOS_MAX_RANGE); - const coord_def br = p + coord_def(0, LOS_MAX_RANGE); - // We're wiping out a little more than required here. - for (rectangle_iterator ri(tl, br); ri; ++ri) - if (map_bounds(*ri)) - memset(globallos[ri->x][ri->y], LOS_FLAG_INVALID, sizeof(halflos_t)); + int x1 = std::max(p.x - LOS_MAX_RANGE, 0); + int y1 = std::max(p.y - LOS_MAX_RANGE, 0); + int x2 = std::min(p.x, GXM - 1); + int y2 = std::min(p.y + LOS_MAX_RANGE, GYM - 1); + for (int y = y1; y <= y2; y++) + for (int x = x1; x <= x2; x++) + if (sqr(p.x - x) + sqr(p.y - y) <= sqr(LOS_MAX_RANGE) + 1) + memset(globallos[x][y], LOS_FLAG_INVALID, sizeof(halflos_t)); } void invalidate_los() |