diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-17 15:36:38 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-17 16:45:17 +0200 |
commit | 47332d4cd5e3297f9c80cac5e6cc83790920cf28 (patch) | |
tree | 725ad62d4d811b962fd949edb0f9154c14c62854 /crawl-ref | |
parent | 2f62da4f8d850459676d780980dbabb7f25a1488 (diff) | |
download | crawl-ref-47332d4cd5e3297f9c80cac5e6cc83790920cf28.tar.gz crawl-ref-47332d4cd5e3297f9c80cac5e6cc83790920cf28.zip |
Clean up LOS precalculation settings.
The maximal boundary within which losight/find_ray will work is
now clearly defined at the start of los.cc. By default, it's
the circle with radius LOS_MAX_RADIUS == LOS_RADIUS.
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/defines.h | 7 | ||||
-rw-r--r-- | crawl-ref/source/los.cc | 21 | ||||
-rw-r--r-- | crawl-ref/source/los.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/losparam.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/losparam.h | 7 |
5 files changed, 23 insertions, 15 deletions
diff --git a/crawl-ref/source/defines.h b/crawl-ref/source/defines.h index 2ef5a2fee9..a5ca761886 100644 --- a/crawl-ref/source/defines.h +++ b/crawl-ref/source/defines.h @@ -107,7 +107,12 @@ const int LABYRINTH_BORDER = 4; #define Y_ABYSS_CENTER (Y_ABYSS_1 + Y_ABYSS_WIDTH / 2) #define LOS_RADIUS 8 -#define ENV_SHOW_OFFSET (LOS_RADIUS + 1) +#define LOS_RADIUS_SQ (LOS_RADIUS * LOS_RADIUS + 1) +#define LOS_MAX_RADIUS LOS_RADIUS +#define LOS_MAX_RADIUS_SQ (LOS_MAX_RADIUS * LOS_MAX_RADIUS + 1) +#define LOS_MAX_RADIUS LOS_RADIUS +#define LOS_MAX_RANGE LOS_MAX_RADIUS +#define ENV_SHOW_OFFSET (LOS_MAX_RANGE + 1) #define ENV_SHOW_DIAMETER (ENV_SHOW_OFFSET * 2 + 1) #define VIEW_BASE_WIDTH 33 // FIXME: never used diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc index ad0798f697..7c00a0b3e4 100644 --- a/crawl-ref/source/los.cc +++ b/crawl-ref/source/los.cc @@ -58,8 +58,13 @@ REVISION("$Rev$"); #include "stuff.h" #include "terrain.h" -#define LONGSIZE (sizeof(unsigned long)*8) -#define LOS_MAX_RANGE 9 +// This determines which cells are considered out of range during +// precalculations (only positive quadrant used). +// For the LOS code to work correctly, any bounds function that +// is used needs to satisfy +// bds_func(p) == true ==> bds_precalc(p) == true +// This used to be the entire LOS_MAX_RANGE rectangle. +const bounds_func& bds_precalc = bds_maxlos; // These determine what rays are cast in the precomputation, // and affect start-up time significantly. @@ -125,9 +130,7 @@ void clear_rays_on_exit() } // Pre-squared LOS radius. -#define LOS_RADIUS2 (LOS_RADIUS * LOS_RADIUS + 1) - -int _los_radius_squared = LOS_RADIUS2; +int _los_radius_squared = LOS_RADIUS_SQ; void setLOSRadius(int newLR) { @@ -158,9 +161,9 @@ struct los_ray : public ray_def } // Shoot a ray from the given start point (accx, accy) with the given - // slope, bounded by the given pre-squared LOS radius. + // slope, bounded by the pre-calc bounds function. // Returns the cells it travels through, excluding the origin. - std::vector<coord_def> footprint(int radius2) + std::vector<coord_def> footprint() { std::vector<coord_def> cs; los_ray copy = *this; @@ -170,7 +173,7 @@ struct los_ray : public ray_def { copy.raw_advance_pos(); c = copy.pos(); - if (c.abs() > radius2) + if (!bds_precalc(c)) break; cs.push_back(c); } @@ -374,7 +377,7 @@ static std::vector<int> _find_minimal_cellrays() static void _register_ray(double accx, double accy, double slope) { los_ray ray = los_ray(accx, accy, slope); - std::vector<coord_def> coords = ray.footprint(LOS_RADIUS2); + std::vector<coord_def> coords = ray.footprint(); if (_is_duplicate_ray(coords)) return; diff --git a/crawl-ref/source/los.h b/crawl-ref/source/los.h index 7fcc406878..3b84c3bb76 100644 --- a/crawl-ref/source/los.h +++ b/crawl-ref/source/los.h @@ -13,7 +13,6 @@ bool double_is_zero(const double x); - void setLOSRadius(int newLR); int get_los_radius_squared(); // XXX diff --git a/crawl-ref/source/losparam.cc b/crawl-ref/source/losparam.cc index 52a2856c80..b281aa7df9 100644 --- a/crawl-ref/source/losparam.cc +++ b/crawl-ref/source/losparam.cc @@ -63,7 +63,7 @@ bool bounds_radius_sq::operator()(const coord_def& p) const } // LOS bounded by current global LOS radius. -bool bounds_los_radius::operator()(const coord_def& p) const +bool bounds_cur_los_radius::operator()(const coord_def& p) const { return (p.abs() <= get_los_radius_squared()); } diff --git a/crawl-ref/source/losparam.h b/crawl-ref/source/losparam.h index 82dee24519..8818f3a7d8 100644 --- a/crawl-ref/source/losparam.h +++ b/crawl-ref/source/losparam.h @@ -60,14 +60,15 @@ struct bounds_radius_sq : bounds_func : radius_sq(r_sq) {} bool operator()(const coord_def& p) const; }; -static bounds_radius_sq bds_maxlos(LOS_RADIUS); +static bounds_radius_sq bds_deflos = bounds_radius_sq(LOS_RADIUS_SQ); +static bounds_radius_sq bds_maxlos = bounds_radius_sq(LOS_MAX_RADIUS_SQ); // LOS bounded by current global LOS radius. -struct bounds_los_radius : bounds_func +struct bounds_cur_los_radius : bounds_func { bool operator()(const coord_def& p) const; }; -static bounds_los_radius bds_default; +static bounds_cur_los_radius bds_default; // Subclasses of this are passed to losight() to modify the // LOS calculation. Implementations will have to translate between |