From 28112f6099b94dff010198d6b3cbf33d40219a7e Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Sat, 10 Oct 2009 12:26:58 +0200 Subject: Move shoot_ray into ray_def. --- crawl-ref/source/los.cc | 14 +++++++------- crawl-ref/source/ray.cc | 48 ++++++++++++++++++++++++------------------------ crawl-ref/source/ray.h | 5 ++++- 3 files changed, 35 insertions(+), 32 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc index d8a24b1582..a7be8eca4d 100644 --- a/crawl-ref/source/los.cc +++ b/crawl-ref/source/los.cc @@ -54,7 +54,10 @@ void clear_rays_on_exit() delete[] los_blockrays; } -int _los_radius_squared = LOS_RADIUS * LOS_RADIUS + 1; +// pre-squared LOS radius +#define LOS_RADIUS2 (LOS_RADIUS * LOS_RADIUS + 1) + +int _los_radius_squared = LOS_RADIUS2; void setLOSRadius(int newLR) { @@ -201,7 +204,9 @@ static std::vector _find_nonduped_cellrays() static bool _register_ray( double accx, double accy, double slope ) { int xpos[LOS_MAX_RANGE * 2 + 1], ypos[LOS_MAX_RANGE * 2 + 1]; - int raylen = shoot_ray(accx, accy, slope, LOS_MAX_RANGE, xpos, ypos); + ray_def ray = ray_def(accx, accy, slope, 0); + // find out which cells the ray passes through + int raylen = ray.footprint(LOS_RADIUS2, xpos, ypos); // Early out if ray already exists. if (_is_duplicate_ray(raylen, xpos, ypos)) @@ -217,11 +222,6 @@ static bool _register_ray( double accx, double accy, double slope ) // Register the fullray. raylengths.push_back(raylen); - ray_def ray; - ray.accx = accx; - ray.accy = accy; - ray.slope = slope; - ray.quadrant = 0; fullrays.push_back(ray); return (true); diff --git a/crawl-ref/source/ray.cc b/crawl-ref/source/ray.cc index a4bb3b21f0..5db398f4e4 100644 --- a/crawl-ref/source/ray.cc +++ b/crawl-ref/source/ray.cc @@ -80,30 +80,8 @@ static int _find_next_intercept(double* accx, double* accy, const double slope) return rc; } -// Shoot a ray from the given start point (accx, accy) with the given -// slope, bounded by LOS radius. Store the visited cells in -// xpos[] and ypos[], and return the number of cells visited. -int shoot_ray(double accx, double accy, const double slope, - int maxrange, int xpos[], int ypos[]) -{ - int curx, cury; - int cellnum; - for (cellnum = 0; true; ++cellnum) - { - _find_next_intercept(&accx, &accy, slope); - curx = static_cast(accx); - cury = static_cast(accy); - if (curx*curx + cury*cury > get_los_radius_squared()) - break; - - xpos[cellnum] = curx; - ypos[cellnum] = cury; - } - return cellnum; -} - -ray_def::ray_def() - : accx(0.0), accy(0.0), slope(0.0), quadrant(0), fullray_idx(-1) +ray_def::ray_def(double ax, double ay, double s, int q, int idx) + : accx(ax), accy(ay), slope(s), quadrant(q), fullray_idx(idx) { } @@ -340,3 +318,25 @@ int ray_def::raw_advance() } } +// 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 +// return the number of cells visited. +int ray_def::footprint(int radius2, int xpos[], int ypos[]) +{ + int curx, cury; + int cellnum; + for (cellnum = 0; true; ++cellnum) + { + _find_next_intercept(&accx, &accy, slope); + curx = static_cast(accx); + cury = static_cast(accy); + if (curx*curx + cury*cury > radius2) + break; + + xpos[cellnum] = curx; + ypos[cellnum] = cury; + } + return cellnum; +} + diff --git a/crawl-ref/source/ray.h b/crawl-ref/source/ray.h index 8816c20171..acea3a33c1 100644 --- a/crawl-ref/source/ray.h +++ b/crawl-ref/source/ray.h @@ -20,7 +20,8 @@ public: int fullray_idx; // for cycling: where did we come from? public: - ray_def(); + ray_def(double accx = 0.0, double accy = 0.0, double slope = 0.0, + int quadrant = 0, int fullray_idx = -1); int x() const { return static_cast(accx); } int y() const { return static_cast(accy); } coord_def pos() const { return coord_def(x(), y()); } @@ -31,6 +32,8 @@ public: void advance_and_bounce(); void regress(); + int footprint(int radius2, int xpos[], int ypos[]); + // Gets/sets the slope in terms of degrees, with 0 = east, 90 = north, // 180 = west, 270 = south, 360 = east, -90 = south, etc double get_degrees() const; -- cgit v1.2.3-54-g00ecf