diff options
author | worktycho <work.tycho@gmail.com> | 2015-03-21 22:08:33 +0100 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2015-03-21 22:08:33 +0100 |
commit | d02c908670f8e329a3e0ddea56cf775b13701bc2 (patch) | |
tree | 8bb99a77f6dca9bc1beb7ff3776fd29cba8b31ce | |
parent | Changed linked world name variables and setters / getters. (diff) | |
parent | Style fixes (diff) | |
download | cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.tar cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.tar.gz cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.tar.bz2 cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.tar.lz cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.tar.xz cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.tar.zst cuberite-d02c908670f8e329a3e0ddea56cf775b13701bc2.zip |
Diffstat (limited to '')
-rw-r--r-- | src/CheckBasicStyle.lua | 6 | ||||
-rw-r--r-- | src/Generating/BioGen.cpp | 36 | ||||
-rw-r--r-- | src/Generating/IntGen.h | 68 |
3 files changed, 88 insertions, 22 deletions
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 <T> fn(Args && ...)" - {"&&[^(]+<", "Add parenthesis around comparison"}, - {"<[^)T][^)]*||", "Add parenthesis around comparison"}, -- Must take special care of templates: "template <T> fn(Args && ...)" + {"<[^)>]*&&", "Add parenthesis around comparison"}, -- Must take special care of templates: "template <T> fn(Args && ...)" + -- Cannot check a < following a && due to functions of the form x fn(y&& a, z<b> c) + {"<[^)>]*||", "Add parenthesis around comparison"}, -- Must take special care of templates: "template <T> 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<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, @@ -1000,9 +1000,9 @@ public: std::make_shared<cIntGenReplaceRandomly<6>> (a_Seed + 101, bgIce, bgTemperate, 150, std::make_shared<cIntGenAddIslands <6>> (a_Seed + 2000, 200, std::make_shared<cIntGenSetRandomly <6>> (a_Seed + 9, 50, bgOcean, - std::make_shared<cIntGenZoom <6>> (a_Seed + 10, - std::make_shared<cIntGenLandOcean <5>> (a_Seed + 100, 30 - ))))))))))))))))))))))))))))))); + std::make_shared<cIntGenLandOcean <5>> (a_Seed + 100, 30) + | MakeIntGen<cIntGenZoom <6>> (a_Seed + 10) + ))))))))))))))))))))))))))))); m_Gen = std::make_shared<cIntGenSmooth <16>>(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 <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,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<int... > +struct sSeq +{ +}; + +template<int N, int... S> +struct sGens : sGens<N - 1, N - 1, S...> +{ +}; + +template<int... S> +struct sGens<0, S...> +{ + typedef sSeq<S...> type; +}; + + +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)...)) + { + } + + template <class LhsGen> + std::shared_ptr<Gen> construct(LhsGen&& a_Lhs) + { + return construct_impl<LhsGen>(std::forward<LhsGen>(a_Lhs), typename sGens<sizeof...(Args)>::type()); + } + + +private: + std::tuple<Args...> m_args; + + template <class LhsGen, int... S> + std::shared_ptr<Gen> construct_impl(LhsGen&& a_Lhs, sSeq<S...>) + { + return std::make_shared<Gen>(std::get<S>(m_args)..., std::forward<LhsGen>(a_Lhs)); + } + }; +template<class T, class RhsGen, class... Args> +std::shared_ptr<RhsGen> operator| (std::shared_ptr<T> a_Lhs, cIntGenFactory<RhsGen, Args...> a_Rhs) +{ + return a_Rhs.construct(static_cast<std::shared_ptr<typename T::IntGenType>>(a_Lhs)); +} +template<class Gen, class... Args> +cIntGenFactory<Gen, Args...> MakeIntGen(Args&&... a_Args) +{ + return cIntGenFactory<Gen, Args...>(std::forward<Args>(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)]; |