|
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Go to the documentation of this file.
32 #include "../Noise/Noise.h"
53 template <
int SizeX,
int SizeZ = SizeX>
68 virtual void GetInts(
int a_MinX,
int a_MinZ,
Values & a_Values) = 0;
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])
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.
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< Gen > construct_impl(LhsGen &&a_Lhs, sSeq< S... >)
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.
cIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying)
static const int m_LowerSizeX
Interface that all the generator classes provide.
Underlying m_UnderlyingGen
cIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying)
std::shared_ptr< RhsGen > operator|(std::shared_ptr< T > a_Lhs, cIntGenFactory< RhsGen, Args... > a_Rhs)
bool isDesertCompatible(int a_BiomeGroup)
Decides between the ocean and landmass biomes.
cIntGenWithNoise(int a_Seed)
const int bgOcean
Constants representing the biome group designators.
int m_To
The destination value to which to replace.
static const int m_LowerSizeX
bool IsBiomeNoDownfall(EMCSBiome a_Biome)
Returns true if the biome has no downfall - deserts and savannas.
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.
Turns some of the oceans into the specified biome.
static const int UnderlyingSizeX
static const int m_LowerSizeZ
std::shared_ptr< Gen > construct(LhsGen &&a_Lhs)
std::shared_ptr< cIntGen< m_UnderlyingSizeX, m_UnderlyingSizeZ > > Underlying
cIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes)
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
Generates a 2D array of random integers in the specified range [0 .
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
Turns biome group indices into real biomes.
Underlying m_Underlying
The underlying generator.
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::tuple< Args... > m_args
static const int m_LowerSizeZ
int m_Chance
Chance, in permille, of changing the biome.
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.
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.
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.
cIntGenBeaches(Underlying a_Underlying)
bool isJungleCompatible(int a_Biome)
std::shared_ptr< cIntGen< m_LowerSizeX, m_LowerSizeZ > > 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_From
The original value to be replaced.
cIntGenFactory< Gen, Args... > MakeIntGen(Args &&... a_Args)
static const int UnderlyingSizeZ
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
Adds a "rare" flag to random biome groups, based on the given chance.
static const int m_UnderlyingSizeZ
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 IsBiomeOcean(int a_Biome)
Returns true if the biome is an ocean biome.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
cIntGenZoom(int a_Seed, Underlying a_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.
cIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers)
static const int UnderlyingSizeZ
Randomly replaces pixels of one value to another value, using the given chance.
int m_Chance
Chance, in permille, of changing each pixel.
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 IntNoise2DInt(int a_X, int a_Y) const
Adds an edge between two specifically incompatible biomes, such as mesa and forest.
cIntGenFactory(Args &&... a_args)
Underlying m_Underlying
The underlying int generator.
Changes random pixels of the underlying data to the specified value.
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 UnderlyingSizeX
cIntGenRareBiomeGroups(int a_Seed, int a_Chance, 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.
int m_Chance
Chance, in permille, of an island being generated in ocean.
cIntGenLandOcean(int a_Seed, int a_Threshold)
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.
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Zooms the underlying value array to twice the size.
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
Generates a river based on the underlying data.
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.
std::shared_ptr< cIntGen< m_LowerSizeX, m_LowerSizeZ > > Underlying
static const int m_LowerSizeZ
Changes biomes in the parent data into an alternate versions (usually "hill" variants),...
cIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying)
int m_ToValue
The value to change the ocean into.
cIntGenSmooth(int a_Seed, Underlying a_Underlying)
A filter that adds an edge biome group between two biome groups that need an edge between them.
static const int m_UnderlyingSizeZ
int[SizeX *SizeZ] Values
Holds the array of values generated by this class (descendant).
static const int m_UnderlyingSizeX
Mixer that joins together finalized biomes and rivers.
cIntGenBiomeGroupEdges(Underlying a_Underlying)
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...
static const int m_UnderlyingSizeX
cIntGenReplaceRandomly(int a_From, int a_To, int a_Chance, int a_Seed, Underlying a_Underlying)
int m_Chance
Chance, in permille, of replacing the value.
std::shared_ptr< cIntGen< m_UnderlyingSizeX, m_UnderlyingSizeZ > > Underlying
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
Generates the underlying numbers and then randomly changes some ocean group pixels into random land b...
cIntGenRiver(int a_Seed, Underlying a_Underlying)
Converts land biomes at the edge of an ocean into the respective beach biome.
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.
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
std::shared_ptr< cIntGen< SizeX, SizeZ > > Underlying
bool isMesaCompatible(int a_Biome)
bool IsBiomeVeryCold(EMCSBiome a_Biome)
Returns true if the biome is very cold (has snow on ground everywhere, turns top water to ice,...
cIntGenBiomeEdges(int a_Seed, Underlying a_Underlying)
Provides additional cNoise member and its helper functions.
cIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying)
int m_ToValue
The value to which to set the pixel.
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.
virtual ~cIntGen()
Force a virtual destructor in all descendants.
cIntGenBiomes(int a_Seed, Underlying a_Underlying)
Smoothes out some artifacts generated by the zooming - mostly single-pixel values.