summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dgn-proclayouts.cc
diff options
context:
space:
mode:
authorBrendan Hickey <brendan@bhickey.net>2012-09-13 08:52:24 -0700
committerBrendan Hickey <brendan@bhickey.net>2012-12-30 19:06:12 -0800
commit653d2261a17b481d03bff741c0eadf65257e2ad4 (patch)
tree82e0bedf791582b45f3834a432aab2694ce5e724 /crawl-ref/source/dgn-proclayouts.cc
parentc3c62dc86dcbaf4d851d81f23506767dbc2c38ee (diff)
downloadcrawl-ref-653d2261a17b481d03bff741c0eadf65257e2ad4.tar.gz
crawl-ref-653d2261a17b481d03bff741c0eadf65257e2ad4.zip
Worley Layout with Changepoints
A WorleyLayout that selects between two other layouts. It calculates the lower bound on when the feature can change so that the whole dungeon doesn't get recomputed on every turn.
Diffstat (limited to 'crawl-ref/source/dgn-proclayouts.cc')
-rw-r--r--crawl-ref/source/dgn-proclayouts.cc37
1 files changed, 30 insertions, 7 deletions
diff --git a/crawl-ref/source/dgn-proclayouts.cc b/crawl-ref/source/dgn-proclayouts.cc
index bd12593951..a5d440090f 100644
--- a/crawl-ref/source/dgn-proclayouts.cc
+++ b/crawl-ref/source/dgn-proclayouts.cc
@@ -1,17 +1,40 @@
/**
* @file
* @brief Procedurally generated dungeon layouts.
-**/
+ **/
#include <cmath>
#include "dgn-proclayouts.h"
+#include "cellular.h"
ProceduralSample
-ColumnLayout::operator()(const coord_def &p, const uint32_t offset)
+ColumnLayout::operator()(const coord_def &p, const uint32_t offset) const
{
- int x = abs(p.x) % (_col_width + _col_space);
- int y = abs(p.y) % (_row_width + _row_space);
- if (x < _col_width && y < _row_width)
- return ProceduralSample(p, DNGN_ROCK_WALL, -1);
- return ProceduralSample(p, DNGN_FLOOR, -1);
+ int x = abs(p.x) % (_col_width + _col_space);
+ int y = abs(p.y) % (_row_width + _row_space);
+ if (x < _col_width && y < _row_width)
+ return ProceduralSample(p, DNGN_ROCK_WALL, -1);
+ return ProceduralSample(p, DNGN_FLOOR, -1);
+}
+
+ProceduralSample
+WorleyLayout::operator()(const coord_def &p, const uint32_t offset) const
+{
+ const double scale = 100.0;
+ double x = p.x / 5.0;
+ double y = p.y / 5.0;
+ double z = offset / scale;
+ worley::noise_datum n = worley::noise(x, y, z);
+ ProceduralSample sampleA = a(p, offset);
+ ProceduralSample sampleB = b(p, offset);
+
+ const uint32_t changepoint = offset +
+ max(1, (int) floor((n.distance[1] - n.distance[0]) * scale));
+ if (n.id[0] % 2)
+ return ProceduralSample(p,
+ sampleA.feat(),
+ min(changepoint, sampleA.changepoint()));
+ return ProceduralSample(p,
+ sampleB.feat(),
+ min(changepoint, sampleB.changepoint()));
}