summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-01-11 17:39:43 +0100
committerGitHub <noreply@github.com>2021-01-11 17:39:43 +0100
commiteeb63b8901a9c049f1bb594abb9ce9b4a9c47620 (patch)
treeb07daae788f918b83eeb0bdbd51e49292f1c8d88 /src/Generating
parentFixed switch-ups regarding some slab and stair recipes (#5099) (diff)
downloadcuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.gz
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.bz2
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.lz
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.xz
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.tar.zst
cuberite-eeb63b8901a9c049f1bb594abb9ce9b4a9c47620.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/ComposableGenerator.cpp39
-rw-r--r--src/Generating/FinishGen.cpp4
-rw-r--r--src/Generating/FinishGen.h5
-rw-r--r--src/Generating/PrefabPiecePool.cpp40
-rw-r--r--src/Generating/PrefabPiecePool.h4
5 files changed, 28 insertions, 64 deletions
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index 8b7d998d0..5b75402b8 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -430,10 +430,8 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
else if (NoCaseCompare(finisher, "DirtPockets") == 0)
{
auto gen = std::make_shared<cFinishGenOrePockets>(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches());
- if (gen->Initialize(a_IniFile, "DirtPockets"))
- {
- m_FinishGens.push_back(gen);
- }
+ gen->Initialize(a_IniFile, "DirtPockets");
+ m_FinishGens.push_back(gen);
}
else if (NoCaseCompare(finisher, "DistortedMembraneOverhangs") == 0)
{
@@ -508,15 +506,6 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenNetherClumpFoliage(m_Seed)));
}
- else if (NoCaseCompare(*itr, "NetherForts") == 0)
- {
- LOGINFO("The NetherForts finisher is obsolete, you should use \"PieceStructures: NetherFort\" instead.");
- auto gen = std::make_shared<cPieceStructuresGen>(m_Seed);
- if (gen->Initialize("NetherFort", seaLevel, m_BiomeGen, m_CompositedHeightCache))
- {
- m_FinishGens.push_back(gen);
- }
- }
else if (NoCaseCompare(finisher, "NetherOreNests") == 0)
{
m_FinishGens.push_back(std::make_shared<cFinishGenOreNests>(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres()));
@@ -528,10 +517,8 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
else if (NoCaseCompare(finisher, "OrePockets") == 0)
{
auto gen = std::make_shared<cFinishGenOrePockets>(m_Seed + 2, cFinishGenOrePockets::DefaultOverworldOres());
- if (gen->Initialize(a_IniFile, "OrePockets"))
- {
- m_FinishGens.push_back(gen);
- }
+ gen->Initialize(a_IniFile, "OrePockets");
+ m_FinishGens.push_back(gen);
}
else if (NoCaseCompare(finisher, "OverworldClumpFlowers") == 0)
{
@@ -561,15 +548,6 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenPreSimulator(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava)));
}
- else if (NoCaseCompare(finisher, "RainbowRoads") == 0)
- {
- LOGINFO("The RainbowRoads finisher is obsolete, you should use \"PieceStructures: RainbowRoads\" instead.");
- auto gen = std::make_shared<cPieceStructuresGen>(m_Seed);
- if (gen->Initialize("RainbowRoads", seaLevel, m_BiomeGen, m_CompositedHeightCache))
- {
- m_FinishGens.push_back(gen);
- }
- }
else if (NoCaseCompare(finisher, "Ravines") == 0)
{
m_FinishGens.push_back(cFinishGenPtr(new cStructGenRavines(m_Seed, 128)));
@@ -645,15 +623,6 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
m_FinishGens.push_back(cFinishGenPtr(new cStructGenTrees(m_Seed, m_BiomeGen, m_ShapeGen, m_CompositionGen)));
}
- else if (NoCaseCompare(finisher, "UnderwaterBases") == 0)
- {
- LOGINFO("The UnderwaterBases finisher is obsolete, you should use \"PieceStructures: UnderwaterBases\" instead.");
- auto gen = std::make_shared<cPieceStructuresGen>(m_Seed);
- if (gen->Initialize("UnderwaterBases", seaLevel, m_BiomeGen, m_CompositedHeightCache))
- {
- m_FinishGens.push_back(gen);
- }
- }
else if (NoCaseCompare(finisher, "Villages") == 0)
{
int GridSize = a_IniFile.GetValueSetI("Generator", "VillageGridSize", 384);
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index 10bd4eac9..6e3f8b446 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -1985,7 +1985,7 @@ void cFinishGenOreNests::GenerateOre(
////////////////////////////////////////////////////////////////////////////////
// cFinishGenOrePockets:
-bool cFinishGenOrePockets::Initialize(cIniFile & a_IniFile, const AString & a_GenName)
+void cFinishGenOrePockets::Initialize(cIniFile & a_IniFile, const AString & a_GenName)
{
// Read the OreInfos configuration:
auto valueName = a_GenName + "Blocks";
@@ -2003,8 +2003,6 @@ bool cFinishGenOrePockets::Initialize(cIniFile & a_IniFile, const AString & a_Ge
// Read the optional seed configuration (but do not store the default):
valueName = a_GenName + "Seed";
SetSeed(a_IniFile.GetValueI("Generator", valueName, m_Noise.GetSeed()));
-
- return true;
}
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index d6458e4fc..76b58e60d 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -589,9 +589,8 @@ public:
{}
/** Reads the configuration from the specified INI file.
- a_GenName is the name of the generator (this class may be used for OrePockets and DirtPockets, each has a different default).
- Returns true on success, false and logs errors to console on failure. */
- bool Initialize(cIniFile & a_IniFile, const AString & a_GenName);
+ a_GenName is the name of the generator (this class may be used for OrePockets and DirtPockets, each has a different default). */
+ void Initialize(cIniFile & a_IniFile, const AString & a_GenName);
protected:
diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp
index e52bb1621..28355660c 100644
--- a/src/Generating/PrefabPiecePool.cpp
+++ b/src/Generating/PrefabPiecePool.cpp
@@ -78,15 +78,6 @@ cPrefabPiecePool::cPrefabPiecePool(
-cPrefabPiecePool::cPrefabPiecePool(const AString & a_FileName, bool a_LogWarnings)
-{
- LoadFromFile(a_FileName, a_LogWarnings);
-}
-
-
-
-
-
cPrefabPiecePool::~cPrefabPiecePool()
{
Clear();
@@ -174,21 +165,28 @@ bool cPrefabPiecePool::LoadFromString(const AString & a_Contents, const AString
// If the contents start with GZip signature, ungzip and retry:
if (a_Contents.substr(0, 3) == "\x1f\x8b\x08")
{
- AString Uncompressed;
- auto res = UncompressStringGZIP(a_Contents.data(), a_Contents.size(), Uncompressed);
- if (res == Z_OK)
+ try
{
- return LoadFromString(Uncompressed, a_FileName, a_LogWarnings);
+ const auto Extracted = Compression::Extractor().ExtractGZip(
+ {
+ reinterpret_cast<const std::byte *>(a_Contents.data()), a_Contents.size()
+ });
+
+ // Here we do an extra std::string conversion, hardly efficient, but...
+ // Better would be refactor into LoadFromByteView for the GZip decompression path, and getting cFile to support std::byte.
+ // ...so it'll do for now.
+
+ return LoadFromString(std::string(Extracted.GetStringView()), a_FileName, a_LogWarnings);
}
- else
+ catch (const std::exception & Oops)
{
- CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s: %d", a_FileName.c_str(), res);
+ CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s. %s", a_FileName.c_str(), Oops.what());
return false;
}
}
// Search the first 8 KiB of the file for the format auto-detection string:
- auto Header = a_Contents.substr(0, 8192);
+ const auto Header = a_Contents.substr(0, 8 KiB);
if (Header.find("CubesetFormatVersion =") != AString::npos)
{
return LoadFromCubeset(a_Contents, a_FileName, a_LogWarnings);
@@ -391,10 +389,14 @@ std::unique_ptr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1(
SchematicFileName = a_FileName.substr(0, PathEnd) + SchematicFileName;
}
cBlockArea area;
- if (!cSchematicFileSerializer::LoadFromSchematicFile(area, SchematicFileName))
+ try
+ {
+ cSchematicFileSerializer::LoadFromSchematicFile(area, SchematicFileName);
+ }
+ catch (const std::exception & Oops)
{
- CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s.",
- SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str()
+ CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s. %s",
+ SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str(), Oops.what()
);
return nullptr;
}
diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h
index 84aba92d1..6bbb7ac13 100644
--- a/src/Generating/PrefabPiecePool.h
+++ b/src/Generating/PrefabPiecePool.h
@@ -44,10 +44,6 @@ public:
int a_DefaultStartingPieceHeight = -1
);
- /** Creates a pool and loads the contents of the specified file into it.
- If a_LogWarnings is true, logs a warning to console when loading fails. */
- cPrefabPiecePool(const AString & a_FileName, bool a_LogWarnings);
-
/** Destroys the pool, freeing all pieces. */
virtual ~cPrefabPiecePool() override;