From 3f61255fe145fe6a4f38f5d57e3475b7753915a7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 1 Mar 2015 14:27:01 +0000 Subject: Added pipelining syntax for generators --- src/Generating/BioGen.cpp | 30 ++++++++++++++--------------- src/Generating/IntGen.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 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> (a_Seed + 1, - std::make_shared> (a_Seed + 2, - std::make_shared> (a_Seed + 3, - std::make_shared> (a_Seed + 4, - std::make_shared> (a_Seed + 5, - std::make_shared> (a_Seed + 8, - std::make_shared> (a_Seed + 5, - std::make_shared> (a_Seed + 9, - std::make_shared> (a_Seed + 5, - std::make_shared> (a_Seed + 10, - std::make_shared> (a_Seed + 5, - std::make_shared> (a_Seed + 6, - std::make_shared> (a_Seed + 11, - std::make_shared>(a_Seed + 12 - )))))))))))))); + + std::make_shared>(a_Seed + 12) + >> MakeIntGen>(a_Seed + 11) + >> MakeIntGen>(a_Seed + 6) + >> MakeIntGen>(a_Seed + 5) + >> MakeIntGen>(a_Seed + 10) + >> MakeIntGen>(a_Seed + 5) + >> MakeIntGen>(a_Seed + 9) + >> MakeIntGen>(a_Seed + 5) + >> MakeIntGen>(a_Seed + 8) + >> MakeIntGen>(a_Seed + 5) + >> MakeIntGen>(a_Seed + 4) + >> MakeIntGen>(a_Seed + 3) + >> MakeIntGen>(a_Seed + 2) + >> MakeIntGen>(a_Seed + 1); auto alteration = std::make_shared>(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 + @@ -53,6 +55,9 @@ template class cIntGen { public: + + typedef cIntGen 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 +struct PackToInt { + enum { + value = size - sizeof...(Args), + }; +}; + +template +class cIntGenFactory { + +public: + + typedef Gen Generator; + + cIntGenFactory(Args&&... a_args) : + m_args(std::make_tuple(std::forward(a_args)...)) + { + } + + //X >> Y + //Y(X) + //cIntGenFactory, int>::construct > > + + template + std::shared_ptr construct(LhsGen&& lhs) { + return std::make_shared(std::get::value>(m_args)..., std::forward(lhs)); + } + +private: + std::tuple m_args; + }; +template +std::shared_ptr operator>> (std::shared_ptr lhs, cIntGenFactory rhs) { + return rhs.construct(static_cast>(lhs)); +} +template +cIntGenFactory MakeIntGen(Args&&... args) { + return cIntGenFactory(std::forward(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)]; -- cgit v1.2.3