diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-11 18:31:07 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-11 21:30:30 +0200 |
commit | 4783b4ed0e228b3de642d71c6554ffcf60ab7858 (patch) | |
tree | 65d566003743095bd5ac2549b089f95df8326c27 /crawl-ref/source/ray.cc | |
parent | bc91b96ff7b72ed86e02274adf9404b54ae2922c (diff) | |
download | crawl-ref-4783b4ed0e228b3de642d71c6554ffcf60ab7858.tar.gz crawl-ref-4783b4ed0e228b3de642d71c6554ffcf60ab7858.zip |
More ray_def simplification.
Diffstat (limited to 'crawl-ref/source/ray.cc')
-rw-r--r-- | crawl-ref/source/ray.cc | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc index 0ce4daa57e..804090b4dc 100644 --- a/crawl-ref/source/ray.cc +++ b/crawl-ref/source/ray.cc @@ -240,7 +240,7 @@ int ray_def::advance(bool shortest_possible, const coord_def *target) // note that slope must be nonnegative! // returns 0 if the advance was in x, 1 if it was in y, 2 if it was // the diagonal -int ray_def::_find_next_intercept() +int ray_def::raw_advance_0() { // handle perpendiculars if (double_is_zero(slope)) @@ -302,44 +302,30 @@ int ray_def::_find_next_intercept() return rc; } +/* + * Mirror ray into quadrant 0 or back. + * this.quadrant itself is not touched (used for the flip back). + */ +void ray_def::flip() +{ + int signx[] = {1, -1, -1, 1}; + int signy[] = {1, 1, -1, -1}; + accx *= signx[quadrant]; + accy *= signy[quadrant]; +} + int ray_def::raw_advance() { int rc; - switch (quadrant) - { - case 0: - // going down-right - rc = _find_next_intercept(); - break; - case 1: - // going down-left - accx *= -1; - rc = _find_next_intercept(); - accx *= -1; - break; - case 2: - // going up-left - accx *= -1; - accy *= -1; - rc = _find_next_intercept(); - accx *= -1; - accy *= -1; - break; - case 3: - // going up-right - accy *= -1; - rc = _find_next_intercept(); - accy *= -1; - break; - default: - rc = -1; - } + flip(); + rc = raw_advance_0(); + flip(); return rc; } // Shoot a ray from the given start point (accx, accy) with the given // slope, bounded by the given pre-squared LOS radius. -// Store the visited cells in xpos[] and ypos[], and +// Store the visited cells in pos[], and // return the number of cells visited. int ray_def::footprint(int radius2, coord_def cpos[]) const { @@ -348,7 +334,7 @@ int ray_def::footprint(int radius2, coord_def cpos[]) const int cellnum; for (cellnum = 0; true; ++cellnum) { - copy._find_next_intercept(); + copy.raw_advance(); c = copy.pos(); if (c.abs() > radius2) break; |