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(-) (limited to 'src/Generating') 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 From bdea6c92b32630856449962ee331fb475627e8d0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 1 Mar 2015 14:51:07 +0000 Subject: Fixed Style Still fails CheckBasicStyle.lua dua to issue with rvalue references and templates --- src/Generating/BioGen.cpp | 2 +- src/Generating/IntGen.h | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index a3cc20247..a830f6a43 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -942,7 +942,7 @@ public: { auto FinalRivers = - std::make_shared>(a_Seed + 12) + std::make_shared>(a_Seed + 12) >> MakeIntGen>(a_Seed + 11) >> MakeIntGen>(a_Seed + 6) >> MakeIntGen>(a_Seed + 5) diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index be005b314..4fce3ba08 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -71,14 +71,17 @@ public: }; template -struct PackToInt { - enum { +struct PackToInt +{ + enum + { value = size - sizeof...(Args), }; }; template -class cIntGenFactory { +class cIntGenFactory +{ public: @@ -88,13 +91,10 @@ public: m_args(std::make_tuple(std::forward(a_args)...)) { } - - //X >> Y - //Y(X) - //cIntGenFactory, int>::construct > > - - template - std::shared_ptr construct(LhsGen&& lhs) { + + template + std::shared_ptr construct(LhsGen&& lhs) + { return std::make_shared(std::get::value>(m_args)..., std::forward(lhs)); } @@ -104,12 +104,14 @@ private: }; template -std::shared_ptr operator>> (std::shared_ptr lhs, cIntGenFactory rhs) { +std::shared_ptr operator>> (std::shared_ptr lhs, cIntGenFactory rhs) +{ return rhs.construct(static_cast>(lhs)); } template -cIntGenFactory MakeIntGen(Args&&... args) { +cIntGenFactory MakeIntGen(Args&&... args) +{ return cIntGenFactory(std::forward(args)...); } -- cgit v1.2.3 From ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 10 Mar 2015 22:19:03 +0000 Subject: Fixed Sequence Generator for IntGen --- src/Generating/BioGen.cpp | 6 +++--- src/Generating/IntGen.h | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index a830f6a43..c9561cc09 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -1000,9 +1000,9 @@ public: std::make_shared> (a_Seed + 101, bgIce, bgTemperate, 150, std::make_shared> (a_Seed + 2000, 200, std::make_shared> (a_Seed + 9, 50, bgOcean, - std::make_shared> (a_Seed + 10, - std::make_shared> (a_Seed + 100, 30 - ))))))))))))))))))))))))))))))); + std::make_shared> (a_Seed + 100, 30) + >> MakeIntGen> (a_Seed + 10) + ))))))))))))))))))))))))))))); m_Gen = std::make_shared>(a_Seed, diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index 4fce3ba08..1ffc15c6b 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -70,15 +70,20 @@ public: }; -template -struct PackToInt -{ - enum - { - value = size - sizeof...(Args), - }; +// Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer + +template +struct seq { }; + +template +struct gens : gens { }; + +template +struct gens<0, S...> { + typedef seq type; }; + template class cIntGenFactory { @@ -91,16 +96,23 @@ public: m_args(std::make_tuple(std::forward(a_args)...)) { } - + template std::shared_ptr construct(LhsGen&& lhs) { - return std::make_shared(std::get::value>(m_args)..., std::forward(lhs)); + return construct_impl(std::forward(lhs), typename gens::type()); } + private: std::tuple m_args; + template + std::shared_ptr construct_impl(LhsGen&& lhs, seq) + { + return std::make_shared(std::get(m_args)..., std::forward(lhs)); + } + }; template -- cgit v1.2.3 From 8646e95b6f91942e7741830dc057daa0e9a40aed Mon Sep 17 00:00:00 2001 From: tycho Date: Wed, 11 Mar 2015 10:39:49 +0000 Subject: Fixed style and removed false positives Relaxed the rules for < followed by an && and removed rule for < following an && --- src/Generating/IntGen.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index 1ffc15c6b..fac500fa8 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -73,14 +73,19 @@ public: // Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer template -struct seq { }; +struct seq +{ +}; template -struct gens : gens { }; +struct gens : gens +{ +}; template -struct gens<0, S...> { - typedef seq type; +struct gens<0, S...> +{ + typedef seq type; }; -- cgit v1.2.3 From 430cbb8c832af71d3a7200e6db80bf08681a7b26 Mon Sep 17 00:00:00 2001 From: tycho Date: Wed, 11 Mar 2015 10:42:45 +0000 Subject: Changed pipeline character from >> to | --- src/Generating/BioGen.cpp | 28 ++++++++++++++-------------- src/Generating/IntGen.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index c9561cc09..9a7ba4d05 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -943,19 +943,19 @@ public: auto FinalRivers = 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); + | 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, @@ -1001,7 +1001,7 @@ public: std::make_shared> (a_Seed + 2000, 200, std::make_shared> (a_Seed + 9, 50, bgOcean, std::make_shared> (a_Seed + 100, 30) - >> MakeIntGen> (a_Seed + 10) + | MakeIntGen> (a_Seed + 10) ))))))))))))))))))))))))))))); m_Gen = diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index fac500fa8..113c2de15 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -121,7 +121,7 @@ private: }; template -std::shared_ptr operator>> (std::shared_ptr lhs, cIntGenFactory rhs) +std::shared_ptr operator| (std::shared_ptr lhs, cIntGenFactory rhs) { return rhs.construct(static_cast>(lhs)); } -- cgit v1.2.3 From 7089b6803055791a60b1d2f80e0490154bc64e5c Mon Sep 17 00:00:00 2001 From: worktycho Date: Sat, 21 Mar 2015 19:45:01 +0000 Subject: Style fixes --- src/Generating/IntGen.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index 113c2de15..854563f41 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -72,20 +72,20 @@ public: // Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer -template -struct seq +template +struct sSeq { }; -template -struct gens : gens +template +struct sGens : sGens { }; -template -struct gens<0, S...> +template +struct sGens<0, S...> { - typedef seq type; + typedef sSeq type; }; @@ -103,9 +103,9 @@ public: } template - std::shared_ptr construct(LhsGen&& lhs) + std::shared_ptr construct(LhsGen&& a_Lhs) { - return construct_impl(std::forward(lhs), typename gens::type()); + return construct_impl(std::forward(a_Lhs), typename sGens::type()); } @@ -113,23 +113,23 @@ private: std::tuple m_args; template - std::shared_ptr construct_impl(LhsGen&& lhs, seq) + std::shared_ptr construct_impl(LhsGen&& a_Lhs, sSeq) { - return std::make_shared(std::get(m_args)..., std::forward(lhs)); + return std::make_shared(std::get(m_args)..., std::forward(a_Lhs)); } }; template -std::shared_ptr operator| (std::shared_ptr lhs, cIntGenFactory rhs) +std::shared_ptr operator| (std::shared_ptr a_Lhs, cIntGenFactory a_Rhs) { - return rhs.construct(static_cast>(lhs)); + return a_Rhs.construct(static_cast>(a_Lhs)); } template -cIntGenFactory MakeIntGen(Args&&... args) +cIntGenFactory MakeIntGen(Args&&... a_Args) { - return cIntGenFactory(std::forward(args)...); + return cIntGenFactory(std::forward(a_Args)...); } -- cgit v1.2.3