diff options
author | Adam Borowski <kilobyte@angband.pl> | 2013-12-02 02:03:47 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2013-12-02 02:22:08 +0100 |
commit | 6fd8ddcea0225b68007cf2f9e0e64365600a3c38 (patch) | |
tree | bf7b108cdb065f23ef317412413e7d80f8d88d2f /crawl-ref/source/losglobal.cc | |
parent | 0ffbeb2a502a78c189c54ef8bf310e763afd21b7 (diff) | |
download | crawl-ref-6fd8ddcea0225b68007cf2f9e0e64365600a3c38.tar.gz crawl-ref-6fd8ddcea0225b68007cf2f9e0e64365600a3c38.zip |
Plug one case that relied on the exact order of radius_iterator.
This plugging is quick and dirty, we can optimize it later. This part
of the code is performance sensitive. Even this plugging is much faster
than the old radius_iterator though: it did the full square, did double
squaring for every position in it, etc.
Diffstat (limited to 'crawl-ref/source/losglobal.cc')
-rw-r--r-- | crawl-ref/source/losglobal.cc | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/crawl-ref/source/losglobal.cc b/crawl-ref/source/losglobal.cc index e7142e28df..7619f01b13 100644 --- a/crawl-ref/source/losglobal.cc +++ b/crawl-ref/source/losglobal.cc @@ -36,17 +36,26 @@ static losfield_t* _lookup_globallos(const coord_def& p, const coord_def& q) static void _save_los(los_def* los, los_type l) { const coord_def o = los->get_center(); - for (radius_iterator ri(o, LOS_MAX_RANGE, C_ROUND); ri; ++ri) - { - losfield_t* flags = _lookup_globallos(o, *ri); - if (!flags) - continue; - *flags |= l << LOS_KNOWN; - if (los->see_cell(*ri)) - *flags |= l; - else - *flags &= ~l; - } + int y1 = o.y - LOS_MAX_RANGE; + int y2 = o.y + LOS_MAX_RANGE; + int x1 = o.x - LOS_MAX_RANGE; + int x2 = o.x + LOS_MAX_RANGE; + for (int y = y1; y <= y2; y++) + for (int x = x1; x <= x2; x++) + { + if (sqr(o.x - x) + sqr(o.y - y) > sqr(LOS_MAX_RANGE) + 1) + continue; + + coord_def ri(x, y); + losfield_t* flags = _lookup_globallos(o, ri); + if (!flags) + continue; + *flags |= l << LOS_KNOWN; + if (los->see_cell(ri)) + *flags |= l; + else + *flags &= ~l; + } } // Opacity at p has changed. |