From 9ee47e59995f858ec531b3ee467f131594e4ba1f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 13 Apr 2020 18:38:06 +0200 Subject: Using Super. --- src/Generating/IntGen.h | 235 ++++++++++++++++++++++++++---------------------- 1 file changed, 130 insertions(+), 105 deletions(-) (limited to 'src/Generating/IntGen.h') diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index ae46b2de2..3b9f3b027 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -55,14 +55,14 @@ class cIntGen { public: - typedef cIntGen IntGenType; + using IntGenType = cIntGen; /** 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() {} /** Holds the array of values generated by this class (descendant). */ - typedef int Values[SizeX * SizeZ]; + using Values = int[SizeX * SizeZ]; /** 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; @@ -84,7 +84,7 @@ struct sGens : sGens template struct sGens<0, S...> { - typedef sSeq type; + using type = sSeq; }; @@ -94,7 +94,7 @@ class cIntGenFactory public: - typedef Gen Generator; + using Generator = Gen; cIntGenFactory(Args&&... a_args) : m_args(std::make_tuple(std::forward(a_args)...)) @@ -135,13 +135,14 @@ cIntGenFactory MakeIntGen(Args&&... a_Args) /** Provides additional cNoise member and its helper functions. */ template -class cIntGenWithNoise : +class cIntGenWithNoise: public cIntGen { - typedef cIntGen super; + using Super = cIntGen; public: - cIntGenWithNoise(int a_Seed) : + + cIntGenWithNoise(int a_Seed): m_Noise(a_Seed) { } @@ -176,26 +177,27 @@ protected: /** Generates a 2D array of random integers in the specified range [0 .. Range). */ template -class cIntGenChoice : +class cIntGenChoice: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - cIntGenChoice(int a_Seed) : - super(a_Seed) + + cIntGenChoice(int a_Seed): + Super(a_Seed) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { for (int z = 0; z < SizeZ; z++) { int BaseZ = a_MinZ + z; for (int x = 0; x < SizeX; x++) { - a_Values[x + SizeX * z] = (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7) % Range; + a_Values[x + SizeX * z] = (Super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7) % Range; } } // for z } @@ -209,27 +211,28 @@ public: Has a threshold (in percent) of how much land, the larger the threshold, the more land. Generates 0 for ocean, biome group ID for landmass. */ template -class cIntGenLandOcean : +class cIntGenLandOcean: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - cIntGenLandOcean(int a_Seed, int a_Threshold) : - super(a_Seed), + + cIntGenLandOcean(int a_Seed, int a_Threshold): + Super(a_Seed), m_Threshold(a_Threshold) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { for (int z = 0; z < SizeZ; z++) { int BaseZ = a_MinZ + z; for (int x = 0; x < SizeX; x++) { - int rnd = (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7); + int rnd = (Super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7); a_Values[x + SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 101) % bgLandOceanMax + 1) : 0; } } @@ -253,27 +256,29 @@ protected: This means that the zoome out image is randomly distorted. Applying zoom several times provides all the distortion that the generators need. */ template -class cIntGenZoom : +class cIntGenZoom: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; protected: + static const int m_LowerSizeX = (SizeX / 2) + 2; static const int m_LowerSizeZ = (SizeZ / 2) + 2; public: - typedef std::shared_ptr> Underlying; + using Underlying = std::shared_ptr>; - cIntGenZoom(int a_Seed, Underlying a_UnderlyingGen) : - super(a_Seed), + + cIntGenZoom(int a_Seed, Underlying a_UnderlyingGen): + Super(a_Seed), m_UnderlyingGen(a_UnderlyingGen) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying data with half the resolution: int lowerMinX = a_MinX >> 1; @@ -298,9 +303,9 @@ public: int RndX = (x + lowerMinX) * 2; int RndZ = (z + lowerMinZ) * 2; cache[idx] = PrevZ0; - cache[idx + lowStepX] = super::ChooseRandomOne(RndX, RndZ + 1, PrevZ0, PrevZ1); - cache[idx + 1] = super::ChooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); - cache[idx + 1 + lowStepX] = super::ChooseRandomOne(RndX, RndZ, PrevZ0, ValX1Z0, PrevZ1, ValX1Z1); + cache[idx + lowStepX] = Super::ChooseRandomOne(RndX, RndZ + 1, PrevZ0, PrevZ1); + cache[idx + 1] = Super::ChooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); + cache[idx + 1 + lowStepX] = Super::ChooseRandomOne(RndX, RndZ, PrevZ0, ValX1Z0, PrevZ1, ValX1Z1); idx += 2; PrevZ0 = ValX1Z0; PrevZ1 = ValX1Z1; @@ -325,25 +330,27 @@ protected: /** Smoothes out some artifacts generated by the zooming - mostly single-pixel values. Compares each pixel to its neighbors and if the neighbors are equal, changes the pixel to their value. */ template -class cIntGenSmooth : +class cIntGenSmooth: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; + static const int m_LowerSizeX = SizeX + 2; static const int m_LowerSizeZ = SizeZ + 2; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; - cIntGenSmooth(int a_Seed, Underlying a_Underlying) : - super(a_Seed), + cIntGenSmooth(int a_Seed, Underlying a_Underlying): + Super(a_Seed), m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying values: int lowerData[m_LowerSizeX * m_LowerSizeZ]; @@ -364,7 +371,7 @@ public: if ((left == right) && (above == below)) { - if (((super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % 2) == 0) + if (((Super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % 2) == 0) { val = left; } @@ -401,24 +408,26 @@ protected: /** Converts land biomes at the edge of an ocean into the respective beach biome. */ template -class cIntGenBeaches : +class cIntGenBeaches: public cIntGen { - typedef cIntGen super; + using Super = cIntGen; + static const int m_UnderlyingSizeX = SizeX + 2; static const int m_UnderlyingSizeZ = SizeZ + 2; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; - cIntGenBeaches(Underlying a_Underlying) : + cIntGenBeaches(Underlying a_Underlying): m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Map for biome -> its beach: static const int ToBeach[] = @@ -503,24 +512,25 @@ protected: /** Generates the underlying numbers and then randomly changes some ocean group pixels into random land biome group pixels, based on the predefined chance. */ template -class cIntGenAddIslands : +class cIntGenAddIslands: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; - cIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying) : - super(a_Seed), + cIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying): + Super(a_Seed), m_Chance(a_Chance), m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { m_Underlying->GetInts(a_MinX, a_MinZ, a_Values); for (int z = 0; z < SizeZ; z++) @@ -529,7 +539,7 @@ public: { if (a_Values[x + z * SizeX] == bgOcean) { - int rnd = super::m_Noise.IntNoise2DInt(a_MinX + x, a_MinZ + z) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(a_MinX + x, a_MinZ + z) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * SizeX] = (rnd / 1003) % bgLandOceanMax; @@ -552,25 +562,26 @@ protected: /** A filter that adds an edge biome group between two biome groups that need an edge between them. */ template -class cIntGenBiomeGroupEdges : +class cIntGenBiomeGroupEdges: public cIntGen { - typedef cIntGen super; + using Super = cIntGen; static const int m_UnderlyingSizeX = SizeX + 2; static const int m_UnderlyingSizeZ = SizeZ + 2; public: - typedef std::shared_ptr> Underlying; + using Underlying = std::shared_ptr>; - cIntGenBiomeGroupEdges(Underlying a_Underlying) : + + cIntGenBiomeGroupEdges(Underlying a_Underlying): m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) { // Generate the underlying biome groups: int lowerValues[m_UnderlyingSizeX * m_UnderlyingSizeZ]; @@ -653,23 +664,24 @@ protected: For each pixel, takes its biome group and chooses a random biome from that group; replaces the value with that biome. */ template -class cIntGenBiomes : +class cIntGenBiomes: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; - cIntGenBiomes(int a_Seed, Underlying a_Underlying) : - super(a_Seed), + cIntGenBiomes(int a_Seed, Underlying a_Underlying): + Super(a_Seed), m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Define the per-biome-group biomes: static const int oceanBiomes[] = @@ -755,7 +767,7 @@ public: const cBiomesInGroups & Biomes = (val > bgfRare) ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : biomesInGroups[val % ARRAYCOUNT(biomesInGroups)]; - int rnd = (super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7); + int rnd = (Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7); a_Values[x + IdxZ] = Biomes.Biomes[rnd % Biomes.Count]; } } @@ -780,17 +792,18 @@ protected: /** Randomly replaces pixels of one value to another value, using the given chance. */ template -class cIntGenReplaceRandomly : +class cIntGenReplaceRandomly: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; - cIntGenReplaceRandomly(int a_From, int a_To, int a_Chance, int a_Seed, Underlying a_Underlying) : - super(a_Seed), + cIntGenReplaceRandomly(int a_From, int a_To, int a_Chance, int a_Seed, Underlying a_Underlying): + Super(a_Seed), m_From(a_From), m_To(a_To), m_Chance(a_Chance), @@ -799,7 +812,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_Values); @@ -813,7 +826,7 @@ public: int idx = x + idxZ; if (a_Values[idx] == m_From) { - int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[idx] = m_To; @@ -849,10 +862,11 @@ template class cIntGenMixRivers: public cIntGen { - typedef cIntGen super; + using Super = cIntGen; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers): @@ -862,11 +876,11 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying data: m_Biomes->GetInts(a_MinX, a_MinZ, a_Values); - typename super::Values riverData; + typename Super::Values riverData; m_Rivers->GetInts(a_MinX, a_MinZ, riverData); // Mix the values: @@ -916,22 +930,24 @@ template class cIntGenRiver: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; + static const int UnderlyingSizeX = SizeX + 2; static const int UnderlyingSizeZ = SizeZ + 2; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenRiver(int a_Seed, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying data: int Cache[UnderlyingSizeX * UnderlyingSizeZ]; @@ -975,16 +991,18 @@ template class cIntGenAddToOcean: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; + static const int UnderlyingSizeX = SizeX + 2; static const int UnderlyingSizeZ = SizeZ + 2; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Chance(a_Chance), m_ToValue(a_ToValue), m_Underlying(a_Underlying) @@ -992,7 +1010,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying data: int Cache[UnderlyingSizeX * UnderlyingSizeZ]; @@ -1036,7 +1054,7 @@ public: // If at least 3 ocean neighbors and the chance is right, change: if ( (NumOceanNeighbors >= 3) && - ((super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7) % 1000 < m_Chance) + ((Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7) % 1000 < m_Chance) ) { a_Values[x + z * SizeX] = m_ToValue; @@ -1065,16 +1083,18 @@ protected: /** Changes random pixels of the underlying data to the specified value. */ template -class cIntGenSetRandomly : +class cIntGenSetRandomly: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; - cIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying) : - super(a_Seed), + using Underlying = std::shared_ptr>; + + + cIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying): + Super(a_Seed), m_Chance(a_Chance), m_ToValue(a_ToValue), m_Underlying(a_Underlying) @@ -1082,7 +1102,7 @@ public: } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_Values); @@ -1092,7 +1112,7 @@ public: { for (int x = 0; x < SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * SizeX] = m_ToValue; @@ -1120,21 +1140,22 @@ template class cIntGenRareBiomeGroups: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Chance(a_Chance), m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_Values); @@ -1144,7 +1165,7 @@ public: { for (int x = 0; x < SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { int idx = x + SizeX * z; @@ -1172,25 +1193,26 @@ template class cIntGenAlternateBiomes: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes): - super(a_Seed), + Super(a_Seed), m_Alterations(a_Alterations), m_BaseBiomes(a_BaseBiomes) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the base biomes and the alterations: m_BaseBiomes->GetInts(a_MinX, a_MinZ, a_Values); - typename super::Values alterations; + typename Super::Values alterations; m_Alterations->GetInts(a_MinX, a_MinZ, alterations); // Change the biomes into their alternate versions: @@ -1240,22 +1262,24 @@ template class cIntGenBiomeEdges: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; + static const int m_LowerSizeX = SizeX + 2; static const int m_LowerSizeZ = SizeZ + 2; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenBiomeEdges(int a_Seed, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Underlying(a_Underlying) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying biomes: typename Underlying::element_type::Values lowerValues; @@ -1402,25 +1426,26 @@ template class cIntGenMBiomes: public cIntGenWithNoise { - typedef cIntGenWithNoise super; + using Super = cIntGenWithNoise; public: - typedef std::shared_ptr> Underlying; + + using Underlying = std::shared_ptr>; cIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Underlying(a_Underlying), m_Alteration(a_Alteration) { } - virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Generate the underlying biomes and the alterations: m_Underlying->GetInts(a_MinX, a_MinZ, a_Values); - typename super::Values alterations; + typename Super::Values alterations; m_Alteration->GetInts(a_MinX, a_MinZ, alterations); // Wherever alterations are nonzero, change into alternate biome, if available: -- cgit v1.2.3