diff options
author | Robert Vollmert <rvollmert@gmx.net> | 2009-10-25 17:54:10 +0100 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2009-10-26 16:43:04 +0100 |
commit | 4cead2d3ab94322f080e143e9786b76f953ac85e (patch) | |
tree | 07c287e82e323b8373bccbdf1fdf57664f2eeefb /crawl-ref/source/losparam.h | |
parent | cc1219315e2533f36b5e1f131fffa77041b919e6 (diff) | |
download | crawl-ref-4cead2d3ab94322f080e143e9786b76f953ac85e.tar.gz crawl-ref-4cead2d3ab94322f080e143e9786b76f953ac85e.zip |
Rewrite los_def to handle function parameters sensibly.
Previously, it was holding on to pointers to objects it
didn't own, causing various bugs.
los_def now copies the opacity_func and bounds_func
parameters. Making them copyable required introducing
opacity_func::clone(). Also implement los_def
copy constructor and copy assignment operator.
Finally, update travel exclusions and monster
patrolling to these changes.
Diffstat (limited to 'crawl-ref/source/losparam.h')
-rw-r--r-- | crawl-ref/source/losparam.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/crawl-ref/source/losparam.h b/crawl-ref/source/losparam.h index b2d378192b..d6bc6a6b55 100644 --- a/crawl-ref/source/losparam.h +++ b/crawl-ref/source/losparam.h @@ -19,8 +19,9 @@ enum opacity_type struct opacity_func { - virtual ~opacity_func() {} virtual opacity_type operator()(const coord_def& p) const = 0; + virtual ~opacity_func() {} + virtual opacity_func* clone() const = 0; // XXX: to be able to call from gdb. virtual opacity_type call(const coord_def& p) const @@ -33,6 +34,7 @@ struct bounds_func { virtual ~bounds_func() {} virtual bool operator()(const coord_def& p) const = 0; + virtual bounds_func* clone() const = 0; // XXX: to be able to call from gdb. virtual bool call(const coord_def& p) const @@ -41,9 +43,18 @@ struct bounds_func } }; +#define CLONE(typename) \ + typename* clone() const \ + { \ + return (new typename(*this)); \ + } + + // Default LOS rules. struct opacity_default : opacity_func { + CLONE(opacity_default) + opacity_type operator()(const coord_def& p) const; }; static opacity_default opc_default; @@ -52,6 +63,8 @@ static opacity_default opc_default; // In particular, clouds don't affect the result. struct opacity_fullyopaque : opacity_func { + CLONE(opacity_fullyopaque) + opacity_type operator()(const coord_def& p) const; }; static opacity_fullyopaque opc_fullyopaque; @@ -60,6 +73,8 @@ static opacity_fullyopaque opc_fullyopaque; // XXX: Are trees, bushes solid? struct opacity_solid : opacity_func { + CLONE(opacity_solid) + opacity_type operator()(const coord_def& p) const; }; static opacity_solid opc_solid; @@ -74,6 +89,8 @@ struct opacity_monmove : opacity_func { } + CLONE(opacity_monmove) + opacity_type operator()(const coord_def& p) const; }; @@ -83,6 +100,9 @@ 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; }; @@ -93,6 +113,8 @@ struct bounds_radius : bounds_radius_sq : bounds_radius_sq(r * r + 1) { } + + CLONE(bounds_radius) }; static bounds_radius bds_deflos = bounds_radius(LOS_RADIUS); @@ -101,6 +123,8 @@ 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; |