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/ProtIntGen.h | 225 ++++++++++++++++++++++++-------------------- 1 file changed, 125 insertions(+), 100 deletions(-) (limited to 'src/Generating/ProtIntGen.h') diff --git a/src/Generating/ProtIntGen.h b/src/Generating/ProtIntGen.h index 24cdafa15..22cd35c53 100644 --- a/src/Generating/ProtIntGen.h +++ b/src/Generating/ProtIntGen.h @@ -51,7 +51,7 @@ protected: public: /** Type of the generic interface used for storing links to the underlying generators. */ - typedef std::shared_ptr Underlying; + using Underlying = std::shared_ptr; /** Force a virtual destructor in all descendants. @@ -67,13 +67,14 @@ public: /** Provides additional cNoise member and its helper functions. */ -class cProtIntGenWithNoise : +class cProtIntGenWithNoise: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: - cProtIntGenWithNoise(int a_Seed) : + + cProtIntGenWithNoise(int a_Seed): m_Noise(a_Seed) { } @@ -107,14 +108,15 @@ protected: /** Generates a 2D array of random integers in the specified range [0 .. Range). */ -class cProtIntGenChoice : +class cProtIntGenChoice: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenChoice(int a_Seed, int a_Range) : - super(a_Seed), + + cProtIntGenChoice(int a_Seed, int a_Range): + Super(a_Seed), m_Range(a_Range) { } @@ -127,7 +129,7 @@ public: int BaseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - a_Values[x + a_SizeX * z] = (super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7) % m_Range; + a_Values[x + a_SizeX * z] = (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7) % m_Range; } } // for z } @@ -143,14 +145,15 @@ protected: /** Decides between the ocean and landmass biomes. 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. */ -class cProtIntGenLandOcean : +class cProtIntGenLandOcean: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenLandOcean(int a_Seed, int a_Threshold) : - super(a_Seed), + + cProtIntGenLandOcean(int a_Seed, int a_Threshold): + Super(a_Seed), m_Threshold(a_Threshold) { } @@ -163,7 +166,7 @@ public: int BaseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - int rnd = (super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7); + int rnd = (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7); a_Values[x + a_SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 101) % bgLandOceanMax + 1) : 0; } } @@ -186,14 +189,15 @@ protected: /** Zooms the underlying value array to twice the size. Uses random-neighbor for the pixels in-between. This means that the zoome out image is randomly distorted. Applying zoom several times provides all the distortion that the generators need. */ -class cProtIntGenZoom : +class cProtIntGenZoom: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenZoom(int a_Seed, Underlying a_UnderlyingGen) : - super(a_Seed), + + cProtIntGenZoom(int a_Seed, Underlying a_UnderlyingGen): + Super(a_Seed), m_UnderlyingGen(a_UnderlyingGen) { } @@ -230,9 +234,9 @@ public: int RndX = (static_cast(x) + lowerMinX) * 2; int RndZ = (static_cast(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; @@ -256,14 +260,15 @@ 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. */ -class cProtIntGenSmooth : +class cProtIntGenSmooth: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenSmooth(int a_Seed, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenSmooth(int a_Seed, Underlying a_Underlying): + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -293,7 +298,7 @@ public: if ((left == right) && (above == below)) { - if (((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 2) == 0) + if (((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 2) == 0) { val = left; } @@ -329,13 +334,14 @@ protected: /** Averages the values of the underlying 2 * 2 neighbors. */ -class cProtIntGenAvgValues : +class cProtIntGenAvgValues: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: - cProtIntGenAvgValues(Underlying a_Underlying) : + + cProtIntGenAvgValues(Underlying a_Underlying): m_Underlying(a_Underlying) { } @@ -373,13 +379,14 @@ protected: /** Averages the values of the underlying 4 * 4 neighbors. */ -class cProtIntGenAvg4Values : +class cProtIntGenAvg4Values: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: - cProtIntGenAvg4Values(Underlying a_Underlying) : + + cProtIntGenAvg4Values(Underlying a_Underlying): m_Underlying(a_Underlying) { } @@ -423,13 +430,14 @@ protected: /** Averages the values of the underlying 3 * 3 neighbors with custom weight. */ template -class cProtIntGenWeightAvg : +class cProtIntGenWeightAvg: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: - cProtIntGenWeightAvg(Underlying a_Underlying) : + + cProtIntGenWeightAvg(Underlying a_Underlying): m_Underlying(a_Underlying) { } @@ -470,14 +478,15 @@ protected: /** Replaces random values of the underlying data with random integers in the specified range [Min .. Min + Range). */ -class cProtIntGenRndChoice : +class cProtIntGenRndChoice: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenRndChoice(int a_Seed, int a_ChancePct, int a_Min, int a_Range, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenRndChoice(int a_Seed, int a_ChancePct, int a_Min, int a_Range, Underlying a_Underlying): + Super(a_Seed), m_ChancePct(a_ChancePct), m_Min(a_Min), m_Range(a_Range), @@ -497,9 +506,9 @@ public: int BaseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - if (((super::m_Noise.IntNoise2DInt(BaseZ, a_MinX + static_cast(x)) / 13) % 101) < m_ChancePct) + if (((Super::m_Noise.IntNoise2DInt(BaseZ, a_MinX + static_cast(x)) / 13) % 101) < m_ChancePct) { - a_Values[x + a_SizeX * z] = m_Min + (super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7) % m_Range; + a_Values[x + a_SizeX * z] = m_Min + (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), BaseZ) / 7) % m_Range; } } // for x } // for z @@ -517,14 +526,15 @@ protected: /** Adds a random value in range [-a_HalfRange, +a_HalfRange] to each of the underlying values. */ -class cProtIntGenAddRnd : +class cProtIntGenAddRnd: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenAddRnd(int a_Seed, int a_HalfRange, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenAddRnd(int a_Seed, int a_HalfRange, Underlying a_Underlying): + Super(a_Seed), m_Range(a_HalfRange * 2 + 1), m_HalfRange(a_HalfRange), m_Underlying(a_Underlying) @@ -543,7 +553,7 @@ public: int NoiseZ = a_MinZ + static_cast(z); for (size_t x = 0; x < a_SizeX; x++) { - int noiseVal = ((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % m_Range) - m_HalfRange; + int noiseVal = ((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % m_Range) - m_HalfRange; a_Values[x + z * a_SizeX] += noiseVal; } } @@ -560,14 +570,15 @@ protected: /** Replaces random underlying values with the average of the neighbors. */ -class cProtIntGenRndAvg : +class cProtIntGenRndAvg: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenRndAvg(int a_Seed, int a_AvgChancePct, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenRndAvg(int a_Seed, int a_AvgChancePct, Underlying a_Underlying): + Super(a_Seed), m_AvgChancePct(a_AvgChancePct), m_Underlying(a_Underlying) { @@ -590,7 +601,7 @@ public: for (size_t x = 0; x < a_SizeX; x++) { size_t idxLower = x + 1 + lowerSizeX * (z + 1); - if (((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 100) > m_AvgChancePct) + if (((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 100) > m_AvgChancePct) { // Average the 4 neighbors: a_Values[x + z * a_SizeX] = ( @@ -617,14 +628,15 @@ protected: /** Replaces random underlying values with a random value in between the max and min of the neighbors. */ -class cProtIntGenRndBetween : +class cProtIntGenRndBetween: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenRndBetween(int a_Seed, int a_AvgChancePct, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenRndBetween(int a_Seed, int a_AvgChancePct, Underlying a_Underlying): + Super(a_Seed), m_AvgChancePct(a_AvgChancePct), m_Underlying(a_Underlying) { @@ -647,12 +659,12 @@ public: for (size_t x = 0; x < a_SizeX; x++) { size_t idxLower = x + 1 + lowerSizeX * (z + 1); - if (((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 100) > m_AvgChancePct) + if (((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ) / 7) % 100) > m_AvgChancePct) { // Chose a value in between the min and max neighbor: int min = std::min(std::min(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::min(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); int max = std::max(std::max(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::max(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); - a_Values[x + z * a_SizeX] = min + ((super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ + 10) / 7) % (max - min + 1)); + a_Values[x + z * a_SizeX] = min + ((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), NoiseZ + 10) / 7) % (max - min + 1)); } else { @@ -673,13 +685,14 @@ protected: /** Converts land biomes at the edge of an ocean into the respective beach biome. */ -class cProtIntGenBeaches : +class cProtIntGenBeaches: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: - cProtIntGenBeaches(Underlying a_Underlying) : + + cProtIntGenBeaches(Underlying a_Underlying): m_Underlying(a_Underlying) { } @@ -772,17 +785,18 @@ protected: /** Generates the underlying numbers and then randomly changes some ocean group pixels into random land biome group pixels, based on the predefined chance. */ -class cProtIntGenAddIslands : +class cProtIntGenAddIslands: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - typedef std::shared_ptr Underlying; + using Underlying = std::shared_ptr; - cProtIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying): + Super(a_Seed), m_Chance(a_Chance), m_Underlying(a_Underlying) { @@ -798,7 +812,7 @@ public: { if (a_Values[x + z * a_SizeX] == bgOcean) { - int rnd = super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), a_MinZ + static_cast(z)) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(a_MinX + static_cast(x), a_MinZ + static_cast(z)) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = (rnd / 1003) % bgLandOceanMax; @@ -820,13 +834,14 @@ protected: /** A filter that adds an edge biome group between two biome groups that need an edge between them. */ -class cProtIntGenBiomeGroupEdges : +class cProtIntGenBiomeGroupEdges: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: - cProtIntGenBiomeGroupEdges(Underlying a_Underlying) : + + cProtIntGenBiomeGroupEdges(Underlying a_Underlying): m_Underlying(a_Underlying) { } @@ -917,14 +932,15 @@ protected: /** Turns biome group indices into real biomes. For each pixel, takes its biome group and chooses a random biome from that group; replaces the value with that biome. */ -class cProtIntGenBiomes : +class cProtIntGenBiomes: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenBiomes(int a_Seed, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenBiomes(int a_Seed, Underlying a_Underlying): + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -1017,7 +1033,7 @@ public: const cBiomesInGroups & Biomes = (val > bgfRare) ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : biomesInGroups[static_cast(val) % ARRAYCOUNT(biomesInGroups)]; - int rnd = (super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7); + int rnd = (Super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7); a_Values[x + IdxZ] = Biomes.Biomes[rnd % Biomes.Count]; } } @@ -1041,17 +1057,18 @@ protected: /** Randomly replaces pixels of one value to another value, using the given chance. */ -class cProtIntGenReplaceRandomly : +class cProtIntGenReplaceRandomly: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - typedef std::shared_ptr Underlying; + using Underlying = std::shared_ptr; - cProtIntGenReplaceRandomly(int a_Seed, int a_From, int a_To, int a_Chance, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenReplaceRandomly(int a_Seed, int a_From, int a_To, int a_Chance, Underlying a_Underlying): + Super(a_Seed), m_From(a_From), m_To(a_To), m_Chance(a_Chance), @@ -1074,7 +1091,7 @@ public: size_t idx = x + idxZ; if (a_Values[idx] == m_From) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[idx] = m_To; @@ -1109,9 +1126,10 @@ regular river or frozen river, based on the biome. */ class cProtIntGenMixRivers: public cProtIntGen { - typedef cProtIntGen super; + using Super = cProtIntGen; public: + cProtIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers): m_Biomes(a_Biomes), m_Rivers(a_Rivers) @@ -1173,11 +1191,12 @@ data changes from one pixel to its neighbor. */ class cProtIntGenRiver: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: + cProtIntGenRiver(int a_Seed, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -1229,11 +1248,12 @@ The biome is only placed if at least 3 of its neighbors are ocean and only with class cProtIntGenAddToOcean: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: + cProtIntGenAddToOcean(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) @@ -1288,7 +1308,7 @@ public: // If at least 3 ocean neighbors and the chance is right, change: if ( (NumOceanNeighbors >= 3) && - ((super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7) % 1000 < m_Chance) + ((Super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7) % 1000 < m_Chance) ) { a_Values[x + z * a_SizeX] = m_ToValue; @@ -1316,14 +1336,15 @@ protected: /** Changes random pixels of the underlying data to the specified value. */ -class cProtIntGenSetRandomly : +class cProtIntGenSetRandomly: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: - cProtIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying) : - super(a_Seed), + + cProtIntGenSetRandomly(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) @@ -1341,7 +1362,7 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = m_ToValue; @@ -1368,11 +1389,12 @@ protected: class cProtIntGenRareBiomeGroups: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: + cProtIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Chance(a_Chance), m_Underlying(a_Underlying) { @@ -1389,7 +1411,7 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int rnd = super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; + int rnd = Super::m_Noise.IntNoise2DInt(static_cast(x) + a_MinX, static_cast(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { size_t idx = x + a_SizeX * z; @@ -1416,11 +1438,12 @@ that have their alterations set. */ class cProtIntGenAlternateBiomes: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: + cProtIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes): - super(a_Seed), + Super(a_Seed), m_Alterations(a_Alterations), m_BaseBiomes(a_BaseBiomes) { @@ -1481,11 +1504,12 @@ protected: class cProtIntGenBiomeEdges: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: + cProtIntGenBiomeEdges(int a_Seed, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -1640,11 +1664,12 @@ have their alterations set. */ class cProtIntGenMBiomes: public cProtIntGenWithNoise { - typedef cProtIntGenWithNoise super; + using Super = cProtIntGenWithNoise; public: + cProtIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying): - super(a_Seed), + Super(a_Seed), m_Underlying(a_Underlying), m_Alteration(a_Alteration) { -- cgit v1.2.3