diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-31 09:08:37 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-11-01 21:45:24 +0100 |
commit | 2130c831446f0b7f2487a4704503901bf1e375e7 (patch) | |
tree | a7b601a88b936ccf45d579cd0e8d43caad6d9b14 /crawl-ref/source/ray.cc | |
parent | a062c664e4802851fba4cc5a001e49a61698f4a3 (diff) | |
download | crawl-ref-2130c831446f0b7f2487a4704503901bf1e375e7.tar.gz crawl-ref-2130c831446f0b7f2487a4704503901bf1e375e7.zip |
Change corner handling.
ray_def should now deal with hitting corners gracefully, though the
raycasting will still discard such rays. If a ray hits a corner
between two diamonds, it will stay there, and calling ray_def::pos
will arbitrarily give one of the squares -- this is not optimal,
but these rays shouldn't usually show up anyway.
Diffstat (limited to 'crawl-ref/source/ray.cc')
-rw-r--r-- | crawl-ref/source/ray.cc | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc index e6952f2102..bbf812009f 100644 --- a/crawl-ref/source/ray.cc +++ b/crawl-ref/source/ray.cc @@ -20,16 +20,42 @@ static int ifloor(double d) coord_def ray_def::pos() const { - // TODO: Assert we're in a central diamond. + // XXX: pretty arbitrary if we're just on a corner. int x = ifloor(r.start.x); int y = ifloor(r.start.y); return (coord_def(x, y)); } +// Return false if we passed or hit a corner. bool ray_def::advance() { - return (geom::nextcell(r, diamonds, true) - && geom::nextcell(r, diamonds, false)); + if (on_corner) + { + on_corner = false; + geom::movehalfcell(r, diamonds); + } + else + { + // Starting inside a diamond. + bool c = !geom::nextcell(r, diamonds); + + if (c) + { + // r is now on a corner, going from diamond to diamond. + geom::movehalfcell(r, diamonds); + return (false); + } + } + // Now inside a non-diamond. + + if (geom::nextcell(r, diamonds)) + return (true); + else + { + // r is now on a corner, going from non-diamond to non-diamond. + on_corner = true; + return (false); + } } void ray_def::advance_and_bounce() |