32 #include "../Noise/Noise.h"
53 template <
int SizeX,
int SizeZ = SizeX>
79 template<
int N,
int... S>
91 template<
class Gen,
class... Args>
100 m_args(
std::make_tuple<Args...>(
std::forward<Args>(a_args)...))
104 template <
class LhsGen>
107 return construct_impl<LhsGen>(std::forward<LhsGen>(a_Lhs),
typename sGens<
sizeof...(Args)>::type());
114 template <
class LhsGen,
int... S>
117 return std::make_shared<Gen>(std::get<S>(
m_args)..., std::forward<LhsGen>(a_Lhs));
122 template<
class T,
class RhsGen,
class... Args>
125 return a_Rhs.
construct(
static_cast<std::shared_ptr<typename T::IntGenType>
>(a_Lhs));
128 template<
class Gen,
class... Args>
131 return cIntGenFactory<Gen, Args...>(std::forward<Args>(a_Args)...);
137 template <
int SizeX,
int SizeZ = SizeX>
157 return ((rnd & 1) == 0) ? a_Val1 : a_Val2;
161 int ChooseRandomOne(
int a_RndX,
int a_RndZ,
int a_Val1,
int a_Val2,
int a_Val3,
int a_Val4)
166 case 0:
return a_Val1;
167 case 1:
return a_Val2;
168 case 2:
return a_Val3;
169 default:
return a_Val4;
179 template <
int Range,
int SizeX,
int SizeZ = SizeX>
195 for (
int z = 0; z < SizeZ; z++)
197 int BaseZ = a_MinZ + z;
198 for (
int x = 0; x < SizeX; x++)
213 template <
int SizeX,
int SizeZ = SizeX>
230 for (
int z = 0; z < SizeZ; z++)
232 int BaseZ = a_MinZ + z;
233 for (
int x = 0; x < SizeX; x++)
241 if ((a_MinX <= 0) && (a_MinZ <= 0) && (a_MinX + SizeX > 0) && (a_MinZ + SizeZ > 0))
258 template <
int SizeX,
int SizeZ = SizeX>
271 using Underlying = std::shared_ptr<cIntGen<m_LowerSizeX, m_LowerSizeZ>>;
284 int lowerMinX = a_MinX >> 1;
285 int lowerMinZ = a_MinZ >> 1;
290 int cache[lowStepX * lowStepZ];
295 int idx = (z * 2) * lowStepX;
302 int ValX1Z1 = lowerData[x + 1 + (z + 1) *
m_LowerSizeX];
303 int RndX = (x + lowerMinX) * 2;
304 int RndZ = (z + lowerMinZ) * 2;
316 for (
int z = 0; z < SizeZ; ++z)
318 memcpy(a_Values + z * SizeX, cache + (z + (a_MinZ & 1)) * lowStepX + (a_MinX & 1), SizeX *
sizeof(
int));
332 template <
int SizeX,
int SizeZ = SizeX>
343 using Underlying = std::shared_ptr<cIntGen<m_LowerSizeX, m_LowerSizeZ>>;
357 m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerData);
361 for (
int z = 0; z < SizeZ; z++)
363 int NoiseZ = a_MinZ + z;
364 for (
int x = 0; x < SizeX; x++)
372 if ((left == right) && (above == below))
374 if (((
Super::m_Noise.IntNoise2DInt(a_MinX + x, NoiseZ) / 7) % 2) == 0)
396 a_Values[x + z * SizeX] = val;
410 template <
int SizeX,
int SizeZ = SizeX>
421 using Underlying = std::shared_ptr<cIntGen<m_UnderlyingSizeX, m_UnderlyingSizeZ>>;
433 static const int ToBeach[] =
479 m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerValues);
482 for (
int z = 0; z < SizeZ; z++)
484 for (
int x = 0; x < SizeX; x++)
496 val = ToBeach[
static_cast<size_t>((val % 128)) %
ARRAYCOUNT(ToBeach)];
499 a_Values[x + z * SizeX] = val;
514 template <
int SizeX,
int SizeZ = SizeX>
536 for (
int z = 0; z < SizeZ; z++)
538 for (
int x = 0; x < SizeX; x++)
540 if (a_Values[x + z * SizeX] ==
bgOcean)
564 template <
int SizeX,
int SizeZ = SizeX>
575 using Underlying = std::shared_ptr<cIntGen<m_UnderlyingSizeX, m_UnderlyingSizeZ>>;
591 for (
int z = 0; z < SizeZ; z++)
593 for (
int x = 0; x < SizeX; x++)
632 a_Values[x + z * SizeX] = val;
643 switch (a_BiomeGroup)
666 template <
int SizeX,
int SizeZ = SizeX>
687 static const int oceanBiomes[] =
693 static const int rareOceanBiomes[] =
698 static const int desertBiomes[] =
703 static const int rareDesertBiomes[] =
708 static const int temperateBiomes[] =
713 static const int rareTemperateBiomes[] =
718 static const int mountainBiomes[] =
723 static const int rareMountainBiomes[] =
728 static const int iceBiomes[] =
734 static const int rareIceBiomes[] =
741 {
static_cast<int>(
ARRAYCOUNT(oceanBiomes)), oceanBiomes},
742 {
static_cast<int>(
ARRAYCOUNT(desertBiomes)), desertBiomes},
743 {
static_cast<int>(
ARRAYCOUNT(temperateBiomes)), temperateBiomes},
744 {
static_cast<int>(
ARRAYCOUNT(mountainBiomes)), mountainBiomes},
745 {
static_cast<int>(
ARRAYCOUNT(iceBiomes)), iceBiomes},
750 {
static_cast<int>(
ARRAYCOUNT(rareOceanBiomes)), rareOceanBiomes},
751 {
static_cast<int>(
ARRAYCOUNT(rareDesertBiomes)), rareDesertBiomes},
752 {
static_cast<int>(
ARRAYCOUNT(rareTemperateBiomes)), rareTemperateBiomes},
753 {
static_cast<int>(
ARRAYCOUNT(rareMountainBiomes)), rareMountainBiomes},
754 {
static_cast<int>(
ARRAYCOUNT(rareIceBiomes)), rareIceBiomes},
761 for (
int z = 0; z < SizeZ; z++)
763 int IdxZ = z * SizeX;
764 for (
int x = 0; x < SizeX; x++)
766 size_t val =
static_cast<size_t>(a_Values[x + IdxZ]);
769 biomesInGroups[val %
ARRAYCOUNT(biomesInGroups)];
771 a_Values[x + IdxZ] = Biomes.
Biomes[rnd % Biomes.
Count];
794 template <
int SizeX,
int SizeZ = SizeX>
821 for (
int z = 0; z < SizeZ; z++)
823 int idxZ = z * SizeX;
824 for (
int x = 0; x < SizeX; x++)
827 if (a_Values[idx] ==
m_From)
832 a_Values[idx] =
m_To;
861 template <
int SizeX,
int SizeZ = SizeX>
882 m_Biomes->GetInts(a_MinX, a_MinZ, a_Values);
884 m_Rivers->GetInts(a_MinX, a_MinZ, riverData);
887 for (
int z = 0; z < SizeZ; z++)
889 int idxZ = z * SizeX;
890 for (
int x = 0; x < SizeX; x++)
929 template <
int SizeX,
int SizeZ = SizeX>
940 using Underlying = std::shared_ptr<cIntGen<UnderlyingSizeX, UnderlyingSizeZ>>;
957 for (
int z = 0; z < SizeZ; z++)
959 for (
int x = 0; x < SizeX; x++)
967 if ((val == Above) && (val == Below) && (val == Left) && (val == Right))
975 a_Values[x + z * SizeX] = val;
990 template <
int SizeX,
int SizeZ = SizeX>
1001 using Underlying = std::shared_ptr<cIntGen<UnderlyingSizeX, UnderlyingSizeZ>>;
1020 for (
int z = 0; z < SizeZ; z++)
1022 for (
int x = 0; x < SizeX; x++)
1027 a_Values[x + z * SizeX] = val;
1036 int NumOceanNeighbors = 0;
1039 NumOceanNeighbors += 1;
1043 NumOceanNeighbors += 1;
1047 NumOceanNeighbors += 1;
1051 NumOceanNeighbors += 1;
1056 (NumOceanNeighbors >= 3) &&
1064 a_Values[x + z * SizeX] = val;
1085 template <
int SizeX,
int SizeZ = SizeX>
1111 for (
int z = 0; z < SizeZ; z++)
1113 for (
int x = 0; x < SizeX; x++)
1139 template <
int SizeX,
int SizeZ = SizeX>
1164 for (
int z = 0; z < SizeZ; z++)
1166 for (
int x = 0; x < SizeX; x++)
1171 int idx = x + SizeX * z;
1172 a_Values[idx] = a_Values[idx] |
bgfRare;
1192 template <
int SizeX,
int SizeZ = SizeX>
1219 for (
int idx = 0; idx < SizeX * SizeZ; ++idx)
1221 if (alterations[idx] == 0)
1228 int val = a_Values[idx];
1247 a_Values[idx] = val;
1261 template <
int SizeX,
int SizeZ = SizeX>
1272 using Underlying = std::shared_ptr<cIntGen<m_LowerSizeX, m_LowerSizeZ>>;
1285 typename Underlying::element_type::Values lowerValues;
1286 m_Underlying->GetInts(a_MinX - 1, a_MinZ - 1, lowerValues);
1289 for (
int z = 0; z < SizeZ; z++)
1291 for (
int x = 0; x < SizeX; x++)
1293 int biome = lowerValues[x + 1 + (z + 1) *
m_LowerSizeX];
1295 int below = lowerValues[x + 1 + (z + 2) *
m_LowerSizeX];
1297 int right = lowerValues[x + 2 + (z + 1) *
m_LowerSizeX];
1365 a_Values[x + z * SizeX] = biome;
1425 template <
int SizeX,
int SizeZ = SizeX>
1452 for (
int idx = 0; idx < SizeX * SizeZ; ++idx)
1454 if (alterations[idx] == 0)
1460 switch (a_Values[idx])
bool IsBiomeNoDownfall(EMCSBiome a_Biome)
Returns true if the biome has no downfall - deserts and savannas.
bool IsBiomeVeryCold(EMCSBiome a_Biome)
Returns true if the biome is very cold (has snow on ground everywhere, turns top water to ice,...
bool IsBiomeOcean(int a_Biome)
Returns true if the biome is an ocean biome.
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
cIntGenFactory< Gen, Args... > MakeIntGen(Args &&... a_Args)
const int bgOcean
Constants representing the biome group designators.
std::shared_ptr< RhsGen > operator|(std::shared_ptr< T > a_Lhs, cIntGenFactory< RhsGen, Args... > a_Rhs)
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Interface that all the generator classes provide.
virtual ~cIntGen()
Force a virtual destructor in all descendants.
virtual void GetInts(int a_MinX, int a_MinZ, Values &a_Values)=0
Generates the array of templated size into a_Values, based on given min coords.
int[SizeX *SizeZ] Values
Holds the array of values generated by this class (descendant).
std::shared_ptr< Gen > construct_impl(LhsGen &&a_Lhs, sSeq< S... >)
std::tuple< Args... > m_args
cIntGenFactory(Args &&... a_args)
std::shared_ptr< Gen > construct(LhsGen &&a_Lhs)
Provides additional cNoise member and its helper functions.
int ChooseRandomOne(int a_RndX, int a_RndZ, int a_Val1, int a_Val2)
Chooses one of a_Val1 or a_Val2, based on m_Noise and the coordinates for querying the noise.
cIntGenWithNoise(int a_Seed)
int ChooseRandomOne(int a_RndX, int a_RndZ, int a_Val1, int a_Val2, int a_Val3, int a_Val4)
Chooses one of a_ValN, based on m_Noise and the coordinates for querying the noise.
Generates a 2D array of random integers in the specified range [0 .
cIntGenChoice(int a_Seed)
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
Decides between the ocean and landmass biomes.
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
cIntGenLandOcean(int a_Seed, int a_Threshold)
Zooms the underlying value array to twice the size.
static const int m_LowerSizeZ
Underlying m_UnderlyingGen
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
cIntGenZoom(int a_Seed, Underlying a_UnderlyingGen)
std::shared_ptr< cIntGen< m_LowerSizeX, m_LowerSizeZ > > Underlying
static const int m_LowerSizeX
Smoothes out some artifacts generated by the zooming - mostly single-pixel values.
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
std::shared_ptr< cIntGen< m_LowerSizeX, m_LowerSizeZ > > Underlying
static const int m_LowerSizeX
static const int m_LowerSizeZ
cIntGenSmooth(int a_Seed, Underlying a_Underlying)
Converts land biomes at the edge of an ocean into the respective beach biome.
cIntGenBeaches(Underlying a_Underlying)
std::shared_ptr< cIntGen< m_UnderlyingSizeX, m_UnderlyingSizeZ > > Underlying
static const int m_UnderlyingSizeX
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
static const int m_UnderlyingSizeZ
Generates the underlying numbers and then randomly changes some ocean group pixels into random land b...
cIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying)
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
int m_Chance
Chance, in permille, of an island being generated in ocean.
A filter that adds an edge biome group between two biome groups that need an edge between them.
std::shared_ptr< cIntGen< m_UnderlyingSizeX, m_UnderlyingSizeZ > > Underlying
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
bool isDesertCompatible(int a_BiomeGroup)
cIntGenBiomeGroupEdges(Underlying a_Underlying)
static const int m_UnderlyingSizeX
static const int m_UnderlyingSizeZ
Turns biome group indices into real biomes.
cIntGenBiomes(int a_Seed, Underlying a_Underlying)
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
Underlying m_Underlying
The underlying int generator.
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
Randomly replaces pixels of one value to another value, using the given chance.
int m_To
The destination value to which to replace.
int m_From
The original value to be replaced.
cIntGenReplaceRandomly(int a_From, int a_To, int a_Chance, int a_Seed, Underlying a_Underlying)
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
int m_Chance
Chance, in permille, of replacing the value.
Mixer that joins together finalized biomes and rivers.
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
cIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers)
Generates a river based on the underlying data.
cIntGenRiver(int a_Seed, Underlying a_Underlying)
static const int UnderlyingSizeZ
static const int UnderlyingSizeX
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
std::shared_ptr< cIntGen< UnderlyingSizeX, UnderlyingSizeZ > > Underlying
Turns some of the oceans into the specified biome.
int m_ToValue
The value to change the ocean into.
static const int UnderlyingSizeZ
int m_Chance
Chance, in permille, of changing the biome.
static const int UnderlyingSizeX
std::shared_ptr< cIntGen< UnderlyingSizeX, UnderlyingSizeZ > > Underlying
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
cIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying)
Changes random pixels of the underlying data to the specified value.
cIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying)
int m_ToValue
The value to which to set the pixel.
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
int m_Chance
Chance, in permille, of changing each pixel.
Adds a "rare" flag to random biome groups, based on the given chance.
Underlying m_Underlying
The underlying generator.
cIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying)
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
int m_Chance
Chance, in permille, of changing each pixel into the rare biome group.
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
Changes biomes in the parent data into an alternate versions (usually "hill" variants),...
cIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes)
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
Adds an edge between two specifically incompatible biomes, such as mesa and forest.
static const int m_LowerSizeZ
static const int m_LowerSizeX
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
cIntGenBiomeEdges(int a_Seed, Underlying a_Underlying)
bool isJungleCompatible(int a_Biome)
bool isMesaCompatible(int a_Biome)
std::shared_ptr< cIntGen< m_LowerSizeX, m_LowerSizeZ > > Underlying
Changes biomes in the parent data into their alternate versions ("M" variants), in such places that h...
cIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying)
virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values &a_Values) override
Generates the array of templated size into a_Values, based on given min coords.
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
int IntNoise2DInt(int a_X, int a_Y) const