summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-11-08 01:25:43 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-11-08 01:41:41 +0100
commitb33014e5510ddaf3a5088c934bbb53aa406b451c (patch)
treedde4379a3ad2a0b8eb10179029d4acac6aa88a76
parentdbb39bdfc8ddc1c4b06b07f09d626791e46ed4bb (diff)
downloadcrawl-ref-b33014e5510ddaf3a5088c934bbb53aa406b451c.tar.gz
crawl-ref-b33014e5510ddaf3a5088c934bbb53aa406b451c.zip
Replace bounds_func with circle_def.
The various LOS objects and functions now accept a circle_def instead of a bounds_func. This is a little less generic, but should eventually help with iterating over coordinates in any los_def.
-rw-r--r--crawl-ref/source/directn.cc2
-rw-r--r--crawl-ref/source/exclude.cc6
-rw-r--r--crawl-ref/source/los.cc31
-rw-r--r--crawl-ref/source/los.h14
-rw-r--r--crawl-ref/source/los_def.cc26
-rw-r--r--crawl-ref/source/los_def.h10
-rw-r--r--crawl-ref/source/losparam.cc12
-rw-r--r--crawl-ref/source/losparam.h43
-rw-r--r--crawl-ref/source/mon-behv.cc3
-rw-r--r--crawl-ref/source/spells1.cc3
10 files changed, 51 insertions, 99 deletions
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index efd865515b..f4a9a8d535 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -1306,7 +1306,7 @@ void direction(dist& moves, targetting_type restricts,
case CMD_TARGET_CYCLE_BEAM:
show_beam = true;
have_beam = find_ray(you.pos(), moves.target, ray,
- opc_solid, bds_default, show_beam);
+ opc_solid, BDS_DEFAULT, show_beam);
beam_target = moves.target;
need_beam_redraw = true;
break;
diff --git a/crawl-ref/source/exclude.cc b/crawl-ref/source/exclude.cc
index 630d549d2b..228a8fcf67 100644
--- a/crawl-ref/source/exclude.cc
+++ b/crawl-ref/source/exclude.cc
@@ -108,7 +108,7 @@ struct opacity_excl : opacity_func
};
static opacity_excl opc_excl;
-// Note: bounds_radius gives a circle with square radius r*r+1;
+// Note: circle_def(r, C_ROUND) gives a circle with square radius r*r+1;
// this doesn't work well for radius 0, but then we want to
// skip LOS calculation in that case anyway since it doesn't
// currently short-cut for small bounds. So radius 0 is special-cased.
@@ -116,7 +116,7 @@ static opacity_excl opc_excl;
travel_exclude::travel_exclude(const coord_def &p, int r,
bool autoexcl, monster_type mons, bool vaultexcl)
: pos(p), radius(r),
- los(los_def(p, opc_excl, bounds_radius(r))),
+ los(los_def(p, opc_excl, circle_def(r, C_ROUND))),
uptodate(false), autoex(autoexcl), mon(mons), vault(vaultexcl)
{
set_los();
@@ -128,7 +128,7 @@ void travel_exclude::set_los()
if (radius > 0)
{
// Radius might have been changed, and this is cheap.
- los.set_bounds(bounds_radius(radius));
+ los.set_bounds(circle_def(radius, C_ROUND));
los.update();
}
}
diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc
index a6d33791e3..f3c57856b6 100644
--- a/crawl-ref/source/los.cc
+++ b/crawl-ref/source/los.cc
@@ -49,6 +49,7 @@
#include "bitary.h"
#include "coord.h"
+#include "coord-circle.h"
#include "coordit.h"
#include "debug.h"
#include "externs.h"
@@ -63,11 +64,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;
+// For the LOS code to work correctly, any LOS shape that
+// is used needs to be contained in bds_precalc.
+const circle_def bds_precalc = circle_def(LOS_MAX_RANGE, C_ROUND);
// These determine what rays are cast in the precomputation,
// and affect start-up time significantly.
@@ -165,7 +164,7 @@ struct los_ray : public ray_def
}
// Shoot a ray from the given start point (accx, accy) with the given
- // slope, bounded by the pre-calc bounds function.
+ // slope, bounded by the pre-calc bounds shape.
// Returns the cells it travels through, excluding the origin.
// Returns an empty vector if this was a bad ray.
std::vector<coord_def> footprint()
@@ -189,7 +188,7 @@ struct los_ray : public ray_def
break;
}
c = copy.pos();
- if (!bds_precalc(c))
+ if (!bds_precalc.contains(c))
break;
cs.push_back(c);
ASSERT((c - old).rdist() == 1);
@@ -572,14 +571,14 @@ void cellray::calc_params()
// opc has been translated for this quadrant.
// XXX: Allow finding ray of minimum opacity.
bool _find_ray_se(const coord_def& target, ray_def& ray,
- const opacity_func& opc, const bounds_func& bds,
+ const opacity_func& opc, const circle_def& bds,
bool cycle)
{
ASSERT(target.x >= 0 && target.y >= 0 && !target.origin());
- if (!bds(target))
+ if (!bds.contains(target))
return false;
- ASSERT(bds_precalc(target));
+ ASSERT(bds_precalc.contains(target));
// Ensure the precalculations have been done.
raycast();
@@ -651,7 +650,7 @@ struct opacity_trans : opacity_func
// assume that ray is appropriately filled in, and look for the next
// ray. We only ever use ray.cycle_idx.
bool find_ray(const coord_def& source, const coord_def& target,
- ray_def& ray, const opacity_func& opc, const bounds_func &bds,
+ ray_def& ray, const opacity_func& opc, const circle_def &bds,
bool cycle)
{
if (target == source || !map_bounds(source) || !map_bounds(target))
@@ -681,7 +680,7 @@ bool find_ray(const coord_def& source, const coord_def& target,
}
bool exists_ray(const coord_def& source, const coord_def& target,
- const opacity_func& opc, const bounds_func &bds)
+ const opacity_func& opc, const circle_def &bds)
{
ray_def ray;
return (find_ray(source, target, ray, opc, bds));
@@ -884,17 +883,17 @@ struct los_param_funcs : public los_param
{
coord_def center;
const opacity_func& opc;
- const bounds_func& bounds;
+ const circle_def& bounds;
los_param_funcs(const coord_def& c,
- const opacity_func& o, const bounds_func& b)
+ const opacity_func& o, const circle_def& b)
: center(c), opc(o), bounds(b)
{
}
bool los_bounds(const coord_def& p) const
{
- return (map_bounds(p + center) && bounds(p));
+ return (map_bounds(p + center) && bounds.contains(p));
}
unsigned appearance(const coord_def& p) const
@@ -909,7 +908,7 @@ struct los_param_funcs : public los_param
};
void losight(env_show_grid& sh, const coord_def& center,
- const opacity_func& opc, const bounds_func& bounds)
+ const opacity_func& opc, const circle_def& bounds)
{
losight(sh, los_param_funcs(center, opc, bounds));
}
diff --git a/crawl-ref/source/los.h b/crawl-ref/source/los.h
index 5947edb4a4..fd24d16cf1 100644
--- a/crawl-ref/source/los.h
+++ b/crawl-ref/source/los.h
@@ -6,9 +6,12 @@
#ifndef LOS_H
#define LOS_H
-#include "los_def.h"
+#include "coord-circle.h"
#include "losparam.h"
+class circle_def;
+struct ray_def;
+
#define EPSILON_VALUE 0.00001
bool double_is_zero(const double x);
@@ -16,13 +19,14 @@ bool double_is_zero(const double x);
void set_los_radius(int r);
int get_los_radius_sq(); // XXX
-struct ray_def;
+#define BDS_DEFAULT (circle_def())
+
bool find_ray(const coord_def& source, const coord_def& target,
ray_def& ray, const opacity_func &opc = opc_solid,
- const bounds_func &bds = bds_default, bool cycle = false);
+ const circle_def &bds = BDS_DEFAULT, bool cycle = false);
bool exists_ray(const coord_def& source, const coord_def& target,
const opacity_func &opc = opc_solid,
- const bounds_func &bds = bds_default);
+ const circle_def &bds = BDS_DEFAULT);
dungeon_feature_type ray_blocker(const coord_def& source, const coord_def& target);
void fallback_ray(const coord_def& source, const coord_def& target,
@@ -38,7 +42,7 @@ bool cell_see_cell(const coord_def& p1, const coord_def& p2);
void clear_rays_on_exit();
void losight(env_show_grid& sh, const coord_def& center,
const opacity_func &opc = opc_default,
- const bounds_func &bds = bds_default);
+ const circle_def &bds = BDS_DEFAULT);
void losight(env_show_grid& sh, const los_param& param);
void calc_show_los();
diff --git a/crawl-ref/source/los_def.cc b/crawl-ref/source/los_def.cc
index 08144fe23b..b01938cf6f 100644
--- a/crawl-ref/source/los_def.cc
+++ b/crawl-ref/source/los_def.cc
@@ -5,34 +5,36 @@
#include "AppHdr.h"
-#include "los.h"
+#include "los_def.h"
+
+#include "coord-circle.h"
los_def::los_def()
- : show(0), opc(opc_default.clone()), bds(bds_default.clone())
+ : show(0), opc(opc_default.clone()), bds(BDS_DEFAULT)
{
}
los_def::los_def(const coord_def& c, const opacity_func &o,
- const bounds_func &b)
- : show(0), center(c), opc(o.clone()), bds(b.clone())
+ const circle_def &b)
+ : show(0), center(c), opc(o.clone()), bds(b)
{
}
los_def::los_def(const los_def& los)
: show(los.show), center(los.center),
- opc(los.opc->clone()), bds(los.bds->clone())
+ opc(los.opc->clone()), bds(los.bds)
{
}
los_def& los_def::operator=(const los_def& los)
{
- init(los.center, *los.opc, *los.bds);
+ init(los.center, *los.opc, los.bds);
show = los.show;
return (*this);
}
void los_def::init(const coord_def &c, const opacity_func &o,
- const bounds_func &b)
+ const circle_def &b)
{
show.init(0);
set_center(c);
@@ -43,12 +45,11 @@ void los_def::init(const coord_def &c, const opacity_func &o,
los_def::~los_def()
{
delete opc;
- delete bds;
}
void los_def::update()
{
- losight(show, center, *opc, *bds);
+ losight(show, center, *opc, bds);
}
void los_def::set_center(const coord_def& c)
@@ -62,15 +63,14 @@ void los_def::set_opacity(const opacity_func &o)
opc = o.clone();
}
-void los_def::set_bounds(const bounds_func &b)
+void los_def::set_bounds(const circle_def &b)
{
- delete bds;
- bds = b.clone();
+ bds = b;
}
bool los_def::in_bounds(const coord_def& p) const
{
- return ((*bds)(p));
+ return (bds.contains(p));
}
bool los_def::see_cell(const coord_def& p) const
diff --git a/crawl-ref/source/los_def.h b/crawl-ref/source/los_def.h
index 25e197218f..42ac3b58ee 100644
--- a/crawl-ref/source/los_def.h
+++ b/crawl-ref/source/los_def.h
@@ -1,6 +1,8 @@
#ifndef LOS_DEF_H
#define LOS_DEF_H
+#include "coord-circle.h"
+#include "los.h"
#include "losparam.h"
class los_def
@@ -8,20 +10,20 @@ class los_def
env_show_grid show;
coord_def center;
opacity_func const * opc;
- bounds_func const * bds;
+ circle_def bds;
public:
los_def();
los_def(const coord_def& c, const opacity_func &o = opc_default,
- const bounds_func &b = bds_default);
+ const circle_def &b = BDS_DEFAULT);
los_def(const los_def& l);
~los_def();
los_def& operator=(const los_def& l);
void init(const coord_def& center, const opacity_func& o,
- const bounds_func& b);
+ const circle_def& b);
void set_center(const coord_def& center);
void set_opacity(const opacity_func& o);
- void set_bounds(const bounds_func& b);
+ void set_bounds(const circle_def& b);
void update();
bool in_bounds(const coord_def& p) const;
diff --git a/crawl-ref/source/losparam.cc b/crawl-ref/source/losparam.cc
index a6c696c60d..68e6aa2e18 100644
--- a/crawl-ref/source/losparam.cc
+++ b/crawl-ref/source/losparam.cc
@@ -62,15 +62,3 @@ opacity_type opacity_monmove::operator()(const coord_def& p) const
else
return (OPC_CLEAR);
}
-
-// LOS bounded by fixed presquared radius.
-bool bounds_radius_sq::operator()(const coord_def& p) const
-{
- return (p.abs() <= radius_sq);
-}
-
-// LOS bounded by current global LOS radius.
-bool bounds_cur_los_radius::operator()(const coord_def& p) const
-{
- return (p.abs() <= get_los_radius_sq());
-}
diff --git a/crawl-ref/source/losparam.h b/crawl-ref/source/losparam.h
index 1986e460a5..31a7f4bc1a 100644
--- a/crawl-ref/source/losparam.h
+++ b/crawl-ref/source/losparam.h
@@ -24,20 +24,12 @@ struct opacity_func
virtual opacity_func* clone() const = 0;
};
-struct bounds_func
-{
- virtual ~bounds_func() {}
- virtual bool operator()(const coord_def& p) const = 0;
- virtual bounds_func* clone() const = 0;
-};
-
#define CLONE(typename) \
typename* clone() const \
{ \
return (new typename(*this)); \
}
-
// Default LOS rules.
struct opacity_default : opacity_func
{
@@ -82,41 +74,6 @@ struct opacity_monmove : opacity_func
opacity_type operator()(const coord_def& p) const;
};
-// LOS bounded by fixed presquared radius.
-struct bounds_radius_sq : bounds_func
-{
- int radius_sq;
- bounds_radius_sq(int r_sq)
- : radius_sq(r_sq) {}
-
- CLONE(bounds_radius_sq)
-
- bool operator()(const coord_def& p) const;
-};
-
-// LOS bounded by fixed radius.
-struct bounds_radius : bounds_radius_sq
-{
- bounds_radius(int r)
- : bounds_radius_sq(r * r + 1)
- {
- }
-
- CLONE(bounds_radius)
-};
-
-static bounds_radius bds_deflos = bounds_radius(LOS_RADIUS);
-static bounds_radius bds_maxlos = bounds_radius(LOS_MAX_RADIUS);
-
-// LOS bounded by current global LOS radius.
-struct bounds_cur_los_radius : bounds_func
-{
- CLONE(bounds_cur_los_radius)
-
- bool operator()(const coord_def& p) const;
-};
-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
// relative coordinates (-8,-8)..(8,8) and real coordinates,
diff --git a/crawl-ref/source/mon-behv.cc b/crawl-ref/source/mon-behv.cc
index 671c8eec1e..f9c97804fb 100644
--- a/crawl-ref/source/mon-behv.cc
+++ b/crawl-ref/source/mon-behv.cc
@@ -691,7 +691,8 @@ static bool _choose_random_patrol_target_grid(monsters *mon)
const int rad = (intel >= I_ANIMAL || !patrol_seen) ? LOS_RADIUS : 5;
const bool is_smart = (intel >= I_NORMAL);
- los_def patrol(mon->patrol_point, opacity_monmove(*mon), bounds_radius(rad));
+ los_def patrol(mon->patrol_point, opacity_monmove(*mon),
+ circle_def(rad, C_ROUND));
patrol.update();
los_def lm(mon->pos(), opacity_monmove(*mon));
if (is_smart || !patrol_seen)
diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc
index 2f798cadf1..b32934ed84 100644
--- a/crawl-ref/source/spells1.cc
+++ b/crawl-ref/source/spells1.cc
@@ -334,7 +334,8 @@ bool _lightning_los(const coord_def& source, const coord_def& target)
{
// XXX: currently bounded by circular LOS radius;
// XXX: adapt opacity -- allow passing clouds.
- return (exists_ray(source, target, opc_solid, bds_maxlos));
+ return (exists_ray(source, target, opc_solid,
+ circle_def(LOS_MAX_RADIUS, C_ROUND)));
}
void cast_chain_lightning(int pow, const actor *caster)