summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dgn-proclayouts.h
diff options
context:
space:
mode:
authorBrendan Hickey <brendan@bhickey.net>2013-03-05 20:47:36 -0800
committerBrendan Hickey <brendan@bhickey.net>2013-03-05 20:47:36 -0800
commite58ea8d632696e3d9636991f63af282153febfdc (patch)
treebea11298a7cdbe3f062bdaecca8e9345a653772e /crawl-ref/source/dgn-proclayouts.h
parente31d4bde2647598477ee61b5cd3935f44eb72ed4 (diff)
downloadcrawl-ref-e58ea8d632696e3d9636991f63af282153febfdc.tar.gz
crawl-ref-e58ea8d632696e3d9636991f63af282153febfdc.zip
Clamp Layout
A procedural layout wrapper that clamps a layout to change no more frequently than some limiting parameter. If you underestimate how rapidly the underlying layout changes, aliasing will occur.
Diffstat (limited to 'crawl-ref/source/dgn-proclayouts.h')
-rw-r--r--crawl-ref/source/dgn-proclayouts.h91
1 files changed, 63 insertions, 28 deletions
diff --git a/crawl-ref/source/dgn-proclayouts.h b/crawl-ref/source/dgn-proclayouts.h
index 343e954557..5cbefe3288 100644
--- a/crawl-ref/source/dgn-proclayouts.h
+++ b/crawl-ref/source/dgn-proclayouts.h
@@ -20,7 +20,9 @@ dungeon_feature_type sanitize_feature(dungeon_feature_type feature,
class ProceduralSample
{
public:
- ProceduralSample(const coord_def _c, const dungeon_feature_type _ft, const uint32_t _cp, map_mask_type _m = MMT_NONE) :
+ ProceduralSample(const coord_def _c,
+ const dungeon_feature_type _ft,
+ const uint32_t _cp, map_mask_type _m = MMT_NONE) :
c(_c), ft(_ft), cp(_cp), m(_m) {}
coord_def coord() const { return c; }
dungeon_feature_type feat() const { return ft; }
@@ -29,11 +31,12 @@ class ProceduralSample
private:
coord_def c;
dungeon_feature_type ft;
- // A lower bound estimate of when this feat can change in terms of absolute abyss depth.
- // If you say that a feature might change by depth 1000, it will get checked at depth 1000.
- // Then it will get pushed back into the terrain queue with the new depth estimate.
- // If you overestimate the time between shifts, this will introduce bad behavior when a game is
- // loaded. [bh]
+ // A lower bound estimate of when this feat can change in terms of
+ // absolute abyss depth. If you say that a feature might change by
+ // depth 1000, it will get checked at depth 1000. Then it will get
+ // pushed back into the terrain queue with the new depth estimate.
+ // If you overestimate the time between shifts, this will introduce
+ // bad behavior when a game is loaded. [bh]
uint32_t cp;
map_mask_type m;
};
@@ -41,7 +44,8 @@ class ProceduralSample
class ProceduralSamplePQCompare
{
public:
- bool operator() (const ProceduralSample &lhs, const ProceduralSample &rhs)
+ bool operator() (const ProceduralSample &lhs,
+ const ProceduralSample &rhs)
{
return lhs.changepoint() > rhs.changepoint();
}
@@ -50,7 +54,8 @@ class ProceduralSamplePQCompare
class ProceduralLayout
{
public:
- virtual ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const = 0;
+ virtual ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const = 0;
virtual ~ProceduralLayout() { }
};
@@ -68,7 +73,8 @@ class ColumnLayout : public ProceduralLayout
_row_space = (rs < 0 ? cs : rs);
}
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
int _col_width, _col_space, _row_width, _row_space;
};
@@ -77,7 +83,8 @@ class DiamondLayout : public ProceduralLayout
{
public:
DiamondLayout(int _w, int _s) : w(_w) , s(_s) { }
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
uint32_t w, s;
};
@@ -86,9 +93,12 @@ class DiamondLayout : public ProceduralLayout
class WorleyLayout : public ProceduralLayout
{
public:
- WorleyLayout(uint32_t _seed, vector<const ProceduralLayout*> _layouts, const float _scale = 2.0)
- : seed(_seed), layouts(_layouts), scale(_scale) {}
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ WorleyLayout(uint32_t _seed,
+ vector<const ProceduralLayout*> _layouts,
+ const float _scale = 2.0) :
+ seed(_seed), layouts(_layouts), scale(_scale) {}
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
const uint32_t seed;
const vector<const ProceduralLayout*> layouts;
@@ -96,16 +106,18 @@ class WorleyLayout : public ProceduralLayout
};
// A pseudo-random layout with variable density.
-// By default, 45% of the area is wall. Densities in excess of 50% (500) are very
-// likely to create isolated bubbles. See http://en.wikipedia.org/wiki/Percolation_theory
-// for additional information.
+// By default, 45% of the area is wall. Densities in excess of 50% (500)
+// are very likely to create isolated bubbles.
+// See http://en.wikipedia.org/wiki/Percolation_theory for additional
+// information.
// This layout is depth invariant.
class ChaosLayout : public ProceduralLayout
{
public:
- ChaosLayout(uint32_t _seed, uint32_t _density = 450)
- : seed(_seed), baseDensity(_density) {}
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ ChaosLayout(uint32_t _seed, uint32_t _density = 450) :
+ seed(_seed), baseDensity(_density) {}
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
const uint32_t seed;
const uint32_t baseDensity;
@@ -115,9 +127,10 @@ class ChaosLayout : public ProceduralLayout
class RoilingChaosLayout : public ProceduralLayout
{
public:
- RoilingChaosLayout(uint32_t _seed, uint32_t _density = 450)
- : seed(_seed), density(_density) {}
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ RoilingChaosLayout(uint32_t _seed, uint32_t _density = 450) :
+ seed(_seed), density(_density) {}
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
const uint32_t seed;
const uint32_t density;
@@ -128,14 +141,17 @@ class WastesLayout : public ProceduralLayout
{
public:
WastesLayout() { };
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
};
class RiverLayout : public ProceduralLayout
{
public:
- RiverLayout(uint32_t _seed, const ProceduralLayout &_layout) : seed(_seed), layout(_layout) {}
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ RiverLayout(uint32_t _seed, const ProceduralLayout &_layout) :
+ seed(_seed), layout(_layout) {}
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
const uint32_t seed;
const ProceduralLayout &layout;
@@ -146,7 +162,8 @@ class NewAbyssLayout : public ProceduralLayout
{
public:
NewAbyssLayout(uint32_t _seed) : seed(_seed) {}
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
const uint32_t seed;
};
@@ -156,12 +173,30 @@ class NewAbyssLayout : public ProceduralLayout
class LevelLayout : public ProceduralLayout
{
public:
- LevelLayout(level_id id, uint32_t _seed, const ProceduralLayout &_layout);
- ProceduralSample operator()(const coord_def &p, const uint32_t offset = 0) const;
+ LevelLayout(level_id id, uint32_t _seed,
+ const ProceduralLayout &_layout);
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
private:
feature_grid grid;
uint32_t seed;
const ProceduralLayout &layout;
};
+// Clamps another layout so that it changes no more frequently than specified
+// by the clamp parameter. This is useful if you can't find a good analytic
+// bound on how rapidly your layout changes. If you provide a high valued clamp
+// to a fast changing layout, aliasing will occur.
+class ClampLayout : public ProceduralLayout
+{
+ public:
+ ClampLayout(const ProceduralLayout &_layout, int _clamp) :
+ layout(_layout), clamp(_clamp) {}
+ ProceduralSample operator()(const coord_def &p,
+ const uint32_t offset = 0) const;
+ private:
+ const ProceduralLayout &layout;
+ const int clamp;
+};
+
#endif /* PROC_LAYOUTS_H */