diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua index 648a5711b..19156b537 100644 --- a/src/CheckBasicStyle.lua +++ b/src/CheckBasicStyle.lua @@ -101,9 +101,9 @@ local g_ViolationPatterns = {"&&[^(]+!=", "Add parenthesis around comparison"}, {"!=[^)]+||", "Add parenthesis around comparison"}, {"||[^(]+!=", "Add parenthesis around comparison"}, - {"<[^)T][^)]*&&", "Add parenthesis around comparison"}, -- Must take special care of templates: "template fn(Args && ...)" - {"&&[^(]+<", "Add parenthesis around comparison"}, - {"<[^)T][^)]*||", "Add parenthesis around comparison"}, -- Must take special care of templates: "template fn(Args && ...)" + {"<[^)>]*&&", "Add parenthesis around comparison"}, -- Must take special care of templates: "template fn(Args && ...)" + -- Cannot check a < following a && due to functions of the form x fn(y&& a, z c) + {"<[^)>]*||", "Add parenthesis around comparison"}, -- Must take special care of templates: "template fn(Args && ...)" {"||[^(]+<", "Add parenthesis around comparison"}, -- Cannot check ">" because of "obj->m_Flag &&". Check at least ">=": {">=[^)]+&&", "Add parenthesis around comparison"}, diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 265db30ad..867155ad2 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, @@ -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 b25e378c0..854563f41 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,70 @@ 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; + +}; + +// Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer + +template +struct sSeq +{ +}; + +template +struct sGens : sGens +{ +}; + +template +struct sGens<0, S...> +{ + typedef sSeq type; }; +template +class cIntGenFactory +{ + +public: + + typedef Gen Generator; + + cIntGenFactory(Args&&... a_args) : + m_args(std::make_tuple(std::forward(a_args)...)) + { + } + + template + std::shared_ptr construct(LhsGen&& a_Lhs) + { + return construct_impl(std::forward(a_Lhs), typename sGens::type()); + } + + +private: + std::tuple m_args; + + template + std::shared_ptr construct_impl(LhsGen&& a_Lhs, sSeq) + { + return std::make_shared(std::get(m_args)..., std::forward(a_Lhs)); + } + +}; + +template +std::shared_ptr operator| (std::shared_ptr a_Lhs, cIntGenFactory a_Rhs) +{ + return a_Rhs.construct(static_cast>(a_Lhs)); +} + +template +cIntGenFactory MakeIntGen(Args&&... a_Args) +{ + return cIntGenFactory(std::forward(a_Args)...); +} @@ -688,7 +754,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)];