summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
Diffstat (limited to 'src/Generating')
-rw-r--r--src/Generating/BioGen.cpp30
-rw-r--r--src/Generating/IntGen.h49
2 files changed, 63 insertions, 16 deletions
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp
index 378ece6a3..a3cc20247 100644
--- a/src/Generating/BioGen.cpp
+++ b/src/Generating/BioGen.cpp
@@ -941,21 +941,21 @@ public:
cBioGenGrown(int a_Seed)
{
auto FinalRivers =
- std::make_shared<cIntGenSmooth<8>> (a_Seed + 1,
- std::make_shared<cIntGenZoom <10>> (a_Seed + 2,
- std::make_shared<cIntGenRiver <7>> (a_Seed + 3,
- std::make_shared<cIntGenZoom <9>> (a_Seed + 4,
- std::make_shared<cIntGenSmooth<6>> (a_Seed + 5,
- std::make_shared<cIntGenZoom <8>> (a_Seed + 8,
- std::make_shared<cIntGenSmooth<6>> (a_Seed + 5,
- std::make_shared<cIntGenZoom <8>> (a_Seed + 9,
- std::make_shared<cIntGenSmooth<6>> (a_Seed + 5,
- std::make_shared<cIntGenZoom <8>> (a_Seed + 10,
- std::make_shared<cIntGenSmooth<6>> (a_Seed + 5,
- std::make_shared<cIntGenSmooth<8>> (a_Seed + 6,
- std::make_shared<cIntGenZoom <10>> (a_Seed + 11,
- std::make_shared<cIntGenChoice<2, 7>>(a_Seed + 12
- ))))))))))))));
+
+ std::make_shared<cIntGenChoice<2, 7>>(a_Seed + 12)
+ >> MakeIntGen<cIntGenZoom <10>>(a_Seed + 11)
+ >> MakeIntGen<cIntGenSmooth<8>>(a_Seed + 6)
+ >> MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5)
+ >> MakeIntGen<cIntGenZoom <8>>(a_Seed + 10)
+ >> MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5)
+ >> MakeIntGen<cIntGenZoom <8>>(a_Seed + 9)
+ >> MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5)
+ >> MakeIntGen<cIntGenZoom <8>>(a_Seed + 8)
+ >> MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5)
+ >> MakeIntGen<cIntGenZoom <9>>(a_Seed + 4)
+ >> MakeIntGen<cIntGenRiver <7>>(a_Seed + 3)
+ >> MakeIntGen<cIntGenZoom <10>>(a_Seed + 2)
+ >> MakeIntGen<cIntGenSmooth<8>>(a_Seed + 1);
auto alteration =
std::make_shared<cIntGenZoom <8>>(a_Seed,
diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h
index b25e378c0..be005b314 100644
--- a/src/Generating/IntGen.h
+++ b/src/Generating/IntGen.h
@@ -31,6 +31,8 @@ by using templates.
#include "../BiomeDef.h"
+#include <tuple>
+
@@ -53,6 +55,9 @@ template <int SizeX, int SizeZ = SizeX>
class cIntGen
{
public:
+
+ typedef cIntGen<SizeX, SizeZ> IntGenType;
+
/** Force a virtual destructor in all descendants.
Descendants contain virtual functions and are referred to via pointer-to-base, so they need a virtual destructor. */
virtual ~cIntGen() {}
@@ -62,9 +67,51 @@ public:
/** Generates the array of templated size into a_Values, based on given min coords. */
virtual void GetInts(int a_MinX, int a_MinZ, Values & a_Values) = 0;
+
+};
+
+template<size_t size, class... Args>
+struct PackToInt {
+ enum {
+ value = size - sizeof...(Args),
+ };
+};
+
+template<class Gen, class... Args>
+class cIntGenFactory {
+
+public:
+
+ typedef Gen Generator;
+
+ cIntGenFactory(Args&&... a_args) :
+ m_args(std::make_tuple<Args...>(std::forward<Args>(a_args)...))
+ {
+ }
+
+ //X >> Y
+ //Y(X)
+ //cIntGenFactory<cIntGenZoom<10, 10>, int>::construct<std::shared_ptr<cIntGenChoice<2, 7, 7> > >
+
+ template<class LhsGen>
+ std::shared_ptr<Gen> construct(LhsGen&& lhs) {
+ return std::make_shared<Gen>(std::get<PackToInt<sizeof...(Args), Args>::value>(m_args)..., std::forward<LhsGen>(lhs));
+ }
+
+private:
+ std::tuple<Args...> m_args;
+
};
+template<class T, class RhsGen, class... Args>
+std::shared_ptr<RhsGen> operator>> (std::shared_ptr<T> lhs, cIntGenFactory<RhsGen, Args...> rhs) {
+ return rhs.construct(static_cast<std::shared_ptr<typename T::IntGenType>>(lhs));
+}
+template<class Gen, class... Args>
+cIntGenFactory<Gen, Args...> MakeIntGen(Args&&... args) {
+ return cIntGenFactory<Gen, Args...>(std::forward<Args>(args)...);
+}
@@ -688,7 +735,7 @@ public:
int IdxZ = z * SizeX;
for (int x = 0; x < SizeX; x++)
{
- int val = a_Values[x + IdxZ];
+ size_t val = (size_t)a_Values[x + IdxZ];
const cBiomesInGroups & Biomes = (val > bgfRare) ?
rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] :
biomesInGroups[val % ARRAYCOUNT(biomesInGroups)];