summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/ray.cc
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-31 09:08:37 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-01 21:45:24 +0100
commit2130c831446f0b7f2487a4704503901bf1e375e7 (patch)
treea7b601a88b936ccf45d579cd0e8d43caad6d9b14 /crawl-ref/source/ray.cc
parenta062c664e4802851fba4cc5a001e49a61698f4a3 (diff)
downloadcrawl-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.cc32
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()