1
0
Fork 0

QtBiomeVisualiser: Added a prototyping int generator flavor.

This generator is easier to manipulate, since it doesn't require rewriting the sizes in the template parameters. On the other hand, it doesn't optimize so well, so it's a bit slower.
This commit is contained in:
Mattes D 2014-10-30 16:24:35 +01:00
parent 93f33b7d4e
commit 8c04abf9aa
6 changed files with 1256 additions and 53 deletions

View File

@ -15,6 +15,7 @@ static const QString s_GeneratorNames[] =
QString("Constant"),
QString("DistortedVoronoi"),
QString("Grown"),
QString("GrownProt"),
QString("MultiStepMap"),
QString("TwoLevel"),
QString("Voronoi"),

View File

@ -59,6 +59,8 @@ HEADERS += \
Globals.h \
BiomeView.h \
../../src/Generating/BioGen.h \
../../src/Generating/IntGen.h \
../../src/Generating/ProtIntGen.h \
../../src/VoronoiMap.h \
../../src/Noise.h \
../../src/StringUtils.h \

View File

@ -6,6 +6,7 @@
#include "Globals.h"
#include "BioGen.h"
#include "IntGen.h"
#include "ProtIntGen.h"
#include "../IniFile.h"
#include "../LinearUpscale.h"
@ -927,9 +928,9 @@ public:
cBioGenGrown(int a_Seed)
{
auto FinalRivers =
std::make_shared<cIntGenSmooth<8>> (a_Seed + 1,
std::make_shared<cIntGenRiver <10>> (a_Seed + 2,
std::make_shared<cIntGenZoom <12>> (a_Seed + 3,
std::make_shared<cIntGenSmooth<6>> (a_Seed + 1,
std::make_shared<cIntGenZoom <8>> (a_Seed + 3,
std::make_shared<cIntGenRiver <6>> (a_Seed + 2,
std::make_shared<cIntGenSmooth<8>> (a_Seed + 4,
std::make_shared<cIntGenZoom <10>> (a_Seed + 5,
std::make_shared<cIntGenZoom <7>> (a_Seed + 6,
@ -942,10 +943,10 @@ public:
))))))))))));
auto FinalBiomes =
std::make_shared<cIntGenSmooth <8>> (a_Seed + 1008,
std::make_shared<cIntGenZoom <10>>(a_Seed + 15,
std::make_shared<cIntGenSmooth <7>> (a_Seed + 1000,
std::make_shared<cIntGenZoom <9>> (a_Seed + 16,
std::make_shared<cIntGenSmooth <6>> (a_Seed + 1008,
std::make_shared<cIntGenZoom <8>>(a_Seed + 15,
std::make_shared<cIntGenSmooth <6>> (a_Seed + 1000,
std::make_shared<cIntGenZoom <8>> (a_Seed + 16,
std::make_shared<cIntGenBeaches <6>> (
std::make_shared<cIntGenSmooth <8>> (a_Seed + 1002,
std::make_shared<cIntGenZoom <10>>(a_Seed + 1,
@ -953,7 +954,8 @@ public:
std::make_shared<cIntGenZoom <9>> (a_Seed + 2,
std::make_shared<cIntGenAddIslands <6>> (a_Seed + 2004, 10,
std::make_shared<cIntGenZoom <6>> (a_Seed + 4,
std::make_shared<cIntGenAddToOcean <5>> (a_Seed + 9, 50, biMushroomIsland,
std::make_shared<cIntGenAddToOcean <5>> (a_Seed + 9, 10, biMushroomIsland,
std::make_shared<cIntGenReplaceRandomly<7>> (biIcePlains, biIcePlainsSpikes, 5, a_Seed + 99,
std::make_shared<cIntGenZoom <7>> (a_Seed + 8,
std::make_shared<cIntGenAddToOcean <5>> (a_Seed + 10, 500, biDeepOcean,
std::make_shared<cIntGenBiomes <7>> (a_Seed + 3000,
@ -961,22 +963,26 @@ public:
std::make_shared<cIntGenBiomeGroupEdges<5>> (
std::make_shared<cIntGenSmooth <7>> (a_Seed + 1003,
std::make_shared<cIntGenZoom <9>> (a_Seed + 7,
std::make_shared<cIntGenSetRandomly <6>> (a_Seed + 8, 50, bgOcean,
std::make_shared<cIntGenReplaceRandomly<6>> (bgJungle, bgTemperate, 50, a_Seed + 100,
std::make_shared<cIntGenReplaceRandomly<6>> (bgIce, bgTemperate, 50, a_Seed + 101,
std::make_shared<cIntGenReplaceRandomly<6>> (bgDesert, bgMesa, 30, a_Seed + 102,
std::make_shared<cIntGenAddIslands <6>> (a_Seed + 2000, 70,
std::make_shared<cIntGenSetRandomly <6>> (a_Seed + 9, 50, bgOcean,
std::make_shared<cIntGenSmooth <6>> (a_Seed + 1004,
std::make_shared<cIntGenZoom <8>> (a_Seed + 10,
std::make_shared<cIntGenLandOcean <6>> (a_Seed + 100, 65
)))))))))))))))))))))))));
)))))))))))))))))))))))))))));
m_Gen =
std::make_shared<cIntGenSmooth <16>>(a_Seed,
std::make_shared<cIntGenZoom <18>>(a_Seed,
std::make_shared<cIntGenSmooth <11>>(a_Seed,
std::make_shared<cIntGenZoom <13>>(a_Seed,
std::make_shared<cIntGenMixRivers<8>> (
std::make_shared<cIntGenZoom <11>>(a_Seed,
std::make_shared<cIntGenSmooth <7>>(a_Seed,
std::make_shared<cIntGenZoom <9>>(a_Seed,
std::make_shared<cIntGenMixRivers<6>> (
FinalBiomes, FinalRivers
)))));
))))));
}
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override
@ -1000,6 +1006,94 @@ protected:
////////////////////////////////////////////////////////////////////////////////
// cBioGenGrown:
class cBioGenProtGrown:
public cBiomeGen
{
public:
cBioGenProtGrown(int a_Seed)
{
auto FinalRivers =
std::make_shared<cProtIntGenSmooth>(a_Seed + 1,
std::make_shared<cProtIntGenZoom >(a_Seed + 3,
std::make_shared<cProtIntGenRiver >(a_Seed + 2,
std::make_shared<cProtIntGenSmooth>(a_Seed + 4,
std::make_shared<cProtIntGenZoom >(a_Seed + 5,
std::make_shared<cProtIntGenZoom >(a_Seed + 6,
std::make_shared<cProtIntGenZoom >(a_Seed + 7,
std::make_shared<cProtIntGenZoom >(a_Seed + 8,
std::make_shared<cProtIntGenZoom >(a_Seed + 9,
std::make_shared<cProtIntGenZoom >(a_Seed + 10,
std::make_shared<cProtIntGenZoom >(a_Seed + 11,
std::make_shared<cProtIntGenChoice>(a_Seed + 12, 2
))))))))))));
auto FinalBiomes =
std::make_shared<cProtIntGenSmooth >(a_Seed + 1008,
std::make_shared<cProtIntGenZoom >(a_Seed + 15,
std::make_shared<cProtIntGenSmooth >(a_Seed + 1000,
std::make_shared<cProtIntGenZoom >(a_Seed + 16,
std::make_shared<cProtIntGenBeaches >(
std::make_shared<cProtIntGenSmooth >(a_Seed + 1002,
std::make_shared<cProtIntGenZoom >(a_Seed + 1,
std::make_shared<cProtIntGenSmooth >(a_Seed + 1002,
std::make_shared<cProtIntGenZoom >(a_Seed + 2,
std::make_shared<cProtIntGenAddIslands >(a_Seed + 2004, 10,
std::make_shared<cProtIntGenZoom >(a_Seed + 4,
std::make_shared<cProtIntGenAddToOcean >(a_Seed + 9, 10, biMushroomIsland,
std::make_shared<cProtIntGenReplaceRandomly>(biIcePlains, biIcePlainsSpikes, 5, a_Seed + 99,
std::make_shared<cProtIntGenZoom >(a_Seed + 8,
std::make_shared<cProtIntGenAddToOcean >(a_Seed + 10, 500, biDeepOcean,
std::make_shared<cProtIntGenBiomes >(a_Seed + 3000,
std::make_shared<cProtIntGenZoom >(a_Seed + 5,
std::make_shared<cProtIntGenBiomeGroupEdges>(
std::make_shared<cProtIntGenSmooth >(a_Seed + 1003,
std::make_shared<cProtIntGenZoom >(a_Seed + 7,
std::make_shared<cProtIntGenSetRandomly >(a_Seed + 8, 50, bgOcean,
std::make_shared<cProtIntGenReplaceRandomly>(bgJungle, bgTemperate, 50, a_Seed + 100,
std::make_shared<cProtIntGenReplaceRandomly>(bgIce, bgTemperate, 50, a_Seed + 101,
std::make_shared<cProtIntGenReplaceRandomly>(bgDesert, bgMesa, 30, a_Seed + 102,
std::make_shared<cProtIntGenAddIslands >(a_Seed + 2000, 70,
std::make_shared<cProtIntGenSetRandomly >(a_Seed + 9, 50, bgOcean,
std::make_shared<cProtIntGenSmooth >(a_Seed + 1004,
std::make_shared<cProtIntGenZoom >(a_Seed + 10,
std::make_shared<cProtIntGenLandOcean >(a_Seed + 100, 65
)))))))))))))))))))))))))))));
m_Gen =
std::make_shared<cProtIntGenSmooth >(a_Seed,
std::make_shared<cProtIntGenZoom >(a_Seed,
std::make_shared<cProtIntGenZoom >(a_Seed,
std::make_shared<cProtIntGenSmooth >(a_Seed,
std::make_shared<cProtIntGenZoom >(a_Seed,
std::make_shared<cProtIntGenMixRivers>(
FinalBiomes, FinalRivers
))))));
}
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override
{
int vals[16 * 16];
m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, 16, 16, vals);
for (int z = 0; z < cChunkDef::Width; z++)
{
for (int x = 0; x < cChunkDef::Width; x++)
{
cChunkDef::SetBiome(a_Biomes, x, z, (EMCSBiome)vals[x + cChunkDef::Width * z]);
}
}
}
protected:
std::shared_ptr<cProtIntGen> m_Gen;
};
////////////////////////////////////////////////////////////////////////////////
// cBiomeGen:
@ -1040,6 +1134,10 @@ cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool &
{
res = new cBioGenGrown(a_Seed);
}
else if (NoCaseCompare(BiomeGenName, "grownprot") == 0)
{
res = new cBioGenProtGrown(a_Seed);
}
else
{
if (NoCaseCompare(BiomeGenName, "multistepmap") != 0)

View File

@ -54,6 +54,7 @@ SET (HDRS
PieceGenerator.h
Prefab.h
PrefabPiecePool.h
ProtIntGen.h
RainbowRoadsGen.h
Ravines.h
RoughRavines.h

View File

@ -36,13 +36,14 @@ by using templates.
/** Constants representing the biome group designators. */
const int bgOcean = 0;
const int bgDesert = 1;
const int bgTemperate = 2;
const int bgMountains = 3;
const int bgJungle = 4;
const int bgIce = 5;
const int bgMax = 5; // Maximum biome group value
const int bgOcean = 0;
const int bgDesert = 1;
const int bgTemperate = 2;
const int bgMountains = 3;
const int bgJungle = 4;
const int bgIce = 5;
const int bgLandOceanMax = 5; // Maximum biome group value generated in the landOcean generator
const int bgMesa = 6;
@ -167,7 +168,7 @@ public:
for (int x = 0; x < SizeX; x++)
{
int rnd = (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7);
a_Values[x + SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 128) % bgMax + 1) : 0;
a_Values[x + SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 128) % bgLandOceanMax + 1) : 0;
}
}
@ -462,7 +463,7 @@ public:
int rnd = super::m_Noise.IntNoise2DInt(a_MinX + x, a_MinZ + z) / 7;
if (rnd % 100 < m_Threshold)
{
a_Values[x + z * SizeX] = (rnd / 100) % bgMax;
a_Values[x + z * SizeX] = (rnd / 100) % bgLandOceanMax;
}
}
}
@ -521,16 +522,16 @@ public:
case bgDesert:
{
if (
!IsDesertCompatible(Above) ||
!IsDesertCompatible(Below) ||
!IsDesertCompatible(Left) ||
!IsDesertCompatible(Right)
!isDesertCompatible(Above) ||
!isDesertCompatible(Below) ||
!isDesertCompatible(Left) ||
!isDesertCompatible(Right)
)
{
v = bgTemperate;
}
break;
}
} // case bgDesert
// Ice should not neighbor deserts; change to temperate:
case bgIce:
@ -545,21 +546,36 @@ public:
v = bgTemperate;
}
break;
}
} // case bgIce
// Jungle should not neighbor Desert or Ice; change to temperate:
case bgJungle:
{
if (
!IsJungleCompatible(Above) ||
!IsJungleCompatible(Below) ||
!IsJungleCompatible(Left) ||
!IsJungleCompatible(Right)
!isJungleCompatible(Above) ||
!isJungleCompatible(Below) ||
!isJungleCompatible(Left) ||
!isJungleCompatible(Right)
)
{
v = bgTemperate;
}
}
} // case bgJungle
// Mesa should neighbor only oceans and deserts; change to desert when another:
case bgMesa:
{
if (
!isMesaCompatible(Above) ||
!isMesaCompatible(Below) ||
!isMesaCompatible(Left) ||
!isMesaCompatible(Right)
)
{
v = bgDesert;
}
break;
} // case bgDesert
}
a_Values[x + z * SizeX] = v;
} // for x
@ -570,14 +586,32 @@ protected:
Underlying m_Underlying;
inline bool IsDesertCompatible(int a_BiomeGroup)
inline bool isDesertCompatible(int a_BiomeGroup)
{
return ((a_BiomeGroup == bgOcean) || (a_BiomeGroup == bgDesert) || (a_BiomeGroup == bgTemperate));
switch (a_BiomeGroup)
{
case bgOcean:
case bgDesert:
case bgTemperate:
case bgMesa:
{
return true;
}
default:
{
return false;
}
}
}
inline bool IsJungleCompatible(int a_BiomeGroup)
inline bool isJungleCompatible(int a_BiomeGroup)
{
return ((a_BiomeGroup != bgDesert) && (a_BiomeGroup != bgIce));
return ((a_BiomeGroup != bgDesert) && (a_BiomeGroup != bgMesa) && (a_BiomeGroup != bgIce));
}
inline bool isMesaCompatible(int a_BiomeGroup)
{
return ((a_BiomeGroup == bgOcean) || (a_BiomeGroup == bgDesert));
}
};
@ -605,44 +639,50 @@ public:
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[] =
static const int oceanBiomes[] =
{
biOcean, // biDeepOcean,
};
static const int DesertBiomes[] =
static const int desertBiomes[] =
{
biDesert, biDesert, biSavanna, biPlains,
biDesert, biDesert, biDesert, biDesert, biDesert, biDesert, biSavanna, biSavanna, biPlains,
};
static const int TemperateBiomes[] =
static const int temperateBiomes[] =
{
biForest, biRoofedForest, biExtremeHills, biPlains, biBirchForest, biSwampland,
biForest, biForest, biRoofedForest, biExtremeHills, biPlains, biBirchForest, biSwampland,
};
static const int MountainBiomes[] =
static const int mountainBiomes[] =
{
biExtremeHills, biForest, biTaiga, biPlains,
};
static const int JungleBiomes[] =
static const int jungleBiomes[] =
{
biJungle, biJungle, biForest,
biJungle, biJungle, biJungle, biForest,
};
static const int IceBiomes[] =
static const int iceBiomes[] =
{
biIcePlains, biIcePlains, biColdTaiga,
biIcePlains, biIcePlains, biIcePlains, biIcePlains, biColdTaiga,
};
static const int mesaBiomes[] =
{
biMesa, biMesaPlateau,
};
static const cBiomesInGroups BiomesInGroups[] =
{
{ static_cast<int>(ARRAYCOUNT(OceanBiomes)), OceanBiomes},
{ static_cast<int>(ARRAYCOUNT(DesertBiomes)), DesertBiomes},
{ static_cast<int>(ARRAYCOUNT(TemperateBiomes)), TemperateBiomes},
{ static_cast<int>(ARRAYCOUNT(MountainBiomes)), MountainBiomes},
{ static_cast<int>(ARRAYCOUNT(JungleBiomes)), JungleBiomes},
{ static_cast<int>(ARRAYCOUNT(IceBiomes)), IceBiomes},
/* bgOcean */ { static_cast<int>(ARRAYCOUNT(oceanBiomes)), oceanBiomes},
/* bgDesert */ { static_cast<int>(ARRAYCOUNT(desertBiomes)), desertBiomes},
/* bgTemperate */ { static_cast<int>(ARRAYCOUNT(temperateBiomes)), temperateBiomes},
/* bgMountains */ { static_cast<int>(ARRAYCOUNT(mountainBiomes)), mountainBiomes},
/* bgJungle */ { static_cast<int>(ARRAYCOUNT(jungleBiomes)), jungleBiomes},
/* bgIce */ { static_cast<int>(ARRAYCOUNT(iceBiomes)), iceBiomes},
/* bgMesa */ { static_cast<int>(ARRAYCOUNT(mesaBiomes)), mesaBiomes},
};
// Generate the underlying values, representing biome groups:
@ -951,3 +991,56 @@ protected:
/** Changes random pixels of the underlying data to the specified value. */
template <int SizeX, int SizeZ = SizeX>
class cIntGenSetRandomly :
public cIntGenWithNoise<SizeX, SizeZ>
{
typedef cIntGenWithNoise<SizeX, SizeZ> super;
public:
typedef std::shared_ptr<cIntGen<SizeX, SizeZ>> Underlying;
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)
{
}
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);
// Change random pixels to bgOcean:
for (int z = 0; z < SizeZ; z++)
{
for (int x = 0; x < SizeX; x++)
{
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;
}
}
}
}
protected:
/** Chance, in permille, of changing each pixel. */
int m_Chance;
/** The value to which to set the pixel. */
int m_ToValue;
Underlying m_Underlying;
};

1008
src/Generating/ProtIntGen.h Normal file

File diff suppressed because it is too large Load Diff