diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-16 17:03:06 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-16 20:17:48 +0200 |
commit | 564dac43f50543729d004dc1dfe905e81321837d (patch) | |
tree | 2615c2205a951f823f9d2dd4dd5a56763fe70517 | |
parent | 6c3f2bb24979f61b40a3a666d17059e0e874e92f (diff) | |
download | crawl-ref-564dac43f50543729d004dc1dfe905e81321837d.tar.gz crawl-ref-564dac43f50543729d004dc1dfe905e81321837d.zip |
On the way to a simplified losight interface.
Added a function
void losight(env_show_grid& sh, const coord_def& center,
opacity_func opc, bounds_func bounds)
with sensible defaults for opc and bounds.
It's not necessary to abstract away the geometry as I initially
did with los_param.
-rw-r--r-- | crawl-ref/source/los.cc | 36 | ||||
-rw-r--r-- | crawl-ref/source/los.h | 5 | ||||
-rw-r--r-- | crawl-ref/source/losparam.cc | 20 | ||||
-rw-r--r-- | crawl-ref/source/losparam.h | 6 |
4 files changed, 65 insertions, 2 deletions
diff --git a/crawl-ref/source/los.cc b/crawl-ref/source/los.cc index a1723cd72b..896ad452c9 100644 --- a/crawl-ref/source/los.cc +++ b/crawl-ref/source/los.cc @@ -859,6 +859,40 @@ void losight(env_show_grid& sh, const los_param& dat) sh(o+sh_o) = dat.appearance(o); } +struct los_param_funcs : public los_param +{ + coord_def center; + opacity_func opc; + bounds_func bounds; + + los_param_funcs(const coord_def& c, + opacity_func o, bounds_func b) + : center(c), opc(o), bounds(b) + { + } + + bool los_bounds(const coord_def& p) const + { + return (map_bounds(p + center) && bounds(p)); + } + + unsigned appearance(const coord_def& p) const + { + return (grid_appearance(p + center)); + } + + opacity_type opacity(const coord_def& p) const + { + return (opc(p + center)); + } +}; + +void losight(env_show_grid& sh, const coord_def& center, + opacity_func opc, bounds_func bounds) +{ + losight(sh, los_param_funcs(center, opc, bounds)); +} + void losight_permissive(env_show_grid &sh, const coord_def& center) { for (int x = -ENV_SHOW_OFFSET; x <= ENV_SHOW_OFFSET; ++x) @@ -875,7 +909,7 @@ void calc_show_los() if (!crawl_state.arena && !crawl_state.arena_suspended) { // Must be done first. - losight(env.show, los_param_base(you.pos())); + losight(env.show, you.pos()); // What would be visible, if all of the translucent walls were // made opaque. diff --git a/crawl-ref/source/los.h b/crawl-ref/source/los.h index 045534ac4e..7e70bd7a08 100644 --- a/crawl-ref/source/los.h +++ b/crawl-ref/source/los.h @@ -31,7 +31,10 @@ int num_feats_between(const coord_def& source, const coord_def& target, bool cell_see_cell(const coord_def& p1, const coord_def& p2); void clear_rays_on_exit(); -void losight(env_show_grid& sh, const los_param& dat); +void losight(env_show_grid& sh, const coord_def& center, + opacity_func opc = &opc_default, + bounds_func bounds = &bounds_los_radius); +void losight(env_show_grid& sh, const los_param& param); void calc_show_los(); bool see_grid( const env_show_grid &show, diff --git a/crawl-ref/source/losparam.cc b/crawl-ref/source/losparam.cc index 833ee04003..47c995f5bd 100644 --- a/crawl-ref/source/losparam.cc +++ b/crawl-ref/source/losparam.cc @@ -14,6 +14,26 @@ REVISION("$Rev$"); #include "stuff.h" #include "terrain.h" +opacity_type opc_default(const coord_def& p) +{ + int m; + dungeon_feature_type f = env.grid(p); + if (grid_is_opaque(f)) + return OPC_OPAQUE; + else if (is_opaque_cloud(env.cgrid(p))) + return OPC_HALF; + else if (f == DNGN_TREES) + return OPC_HALF; + else if ((m = mgrd(p)) != NON_MONSTER && menv[m].type == MONS_BUSH) + return OPC_HALF; + else + return OPC_CLEAR; +} + +bool bounds_los_radius(const coord_def& p) +{ + return (p.abs() <= get_los_radius_squared()); +} /* los_param_trans */ diff --git a/crawl-ref/source/losparam.h b/crawl-ref/source/losparam.h index 6dfac41dde..8953c1883e 100644 --- a/crawl-ref/source/losparam.h +++ b/crawl-ref/source/losparam.h @@ -15,6 +15,12 @@ enum opacity_type NUM_OPACITIES }; +typedef opacity_type (*opacity_func)(const coord_def&); +typedef bool (*bounds_func)(const coord_def&); + +opacity_type opc_default(const coord_def&); +bool bounds_los_radius(const coord_def& p); + // 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, |